Skip to content

Commit

Permalink
Fixes stack overflow when exporting a lot in commonjs (#38994)
Browse files Browse the repository at this point in the history
* Fixes stack overflow when exporting a lot in commonjs

Fixes #38691

* Add missing test files
  • Loading branch information
ericanderson committed Sep 4, 2020
1 parent 237b6f6 commit 79f919e
Show file tree
Hide file tree
Showing 5 changed files with 50,123 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/compiler/transformers/module/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,19 @@ namespace ts {
append(statements, createUnderscoreUnderscoreESModule());
}
if (length(currentModuleInfo.exportedNames)) {
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)));
const chunkSize = 50;
for (let i=0; i<currentModuleInfo.exportedNames!.length; i += chunkSize) {
append(
statements,
factory.createExpressionStatement(
reduceLeft(
currentModuleInfo.exportedNames!.slice(i, i + chunkSize),
(prev, nextId) => factory.createAssignment(factory.createPropertyAccessExpression(factory.createIdentifier("exports"), factory.createIdentifier(idText(nextId))), prev),
factory.createVoidZero() as Expression
)
)
);
}
}

append(statements, visitNode(currentModuleInfo.externalHelpersImportDeclaration, sourceElementVisitor, isStatement));
Expand Down
Loading

0 comments on commit 79f919e

Please sign in to comment.