Skip to content

Commit e51498e

Browse files
committed
Fixes stack overflow when exporting a lot in commonjs
Fixes #38691
1 parent a96c8ec commit e51498e

File tree

2 files changed

+10118
-1
lines changed

2 files changed

+10118
-1
lines changed

src/compiler/transformers/module/module.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,19 @@ namespace ts {
9797
append(statements, createUnderscoreUnderscoreESModule());
9898
}
9999
if (length(currentModuleInfo.exportedNames)) {
100-
append(statements, createExpressionStatement(reduceLeft(currentModuleInfo.exportedNames, (prev, nextId) => createAssignment(createPropertyAccess(createIdentifier("exports"), createIdentifier(idText(nextId))), prev), createVoidZero() as Expression)));
100+
const chunkSize = 50;
101+
for (let i=0; i<currentModuleInfo.exportedNames!.length; i += chunkSize) {
102+
append(
103+
statements,
104+
createExpressionStatement(
105+
reduceLeft(
106+
currentModuleInfo.exportedNames!.slice(i, i + chunkSize),
107+
(prev, nextId) => createAssignment(createPropertyAccess(createIdentifier("exports"), createIdentifier(idText(nextId))), prev),
108+
createVoidZero() as Expression
109+
)
110+
)
111+
);
112+
}
101113
}
102114

103115
append(statements, visitNode(currentModuleInfo.externalHelpersImportDeclaration, sourceElementVisitor, isStatement));

0 commit comments

Comments
 (0)