Skip to content

Commit 79f919e

Browse files
authored
Fixes stack overflow when exporting a lot in commonjs (#38994)
* Fixes stack overflow when exporting a lot in commonjs Fixes #38691 * Add missing test files
1 parent 237b6f6 commit 79f919e

File tree

5 files changed

+50123
-1
lines changed

5 files changed

+50123
-1
lines changed

src/compiler/transformers/module/module.ts

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

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

0 commit comments

Comments
 (0)