-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fix helpers emit for .cjs files in ESM module mode #61814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix helpers emit for .cjs files in ESM module mode #61814
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes the helpers emission for .cjs files when running in ESM module mode by refining the underlying logic and adding new test cases.
- Adds a new test case (ctsFileInEsnextHelpers.ts) and updates the expected baselines.
- Adjusts module specifier resolution by removing the fallback to the source file’s implied node format.
- Refines the condition for emitting external helper imports to better distinguish between CommonJS and ES module formats.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
tests/cases/compiler/ctsFileInEsnextHelpers.ts | Introduces a new test file for .cts files in ESM module mode. |
tests/baselines/reference/ctsFileInEsnextHelpers.* | Updates baseline outputs (types, symbols, JS, errors) to reflect the new helper emit fix. |
src/compiler/moduleSpecifiers.ts | Removes fallback to importingSourceFile.impliedNodeFormat, using overrideImportMode only. |
src/compiler/factory/utilities.ts | Adjusts the condition for creating external helpers import to avoid CJS emission in ESM mode. |
Comments suppressed due to low confidence (1)
src/compiler/moduleSpecifiers.ts:515
- Removing the fallback to 'importingSourceFile.impliedNodeFormat' might lead to undefined behavior when overrideImportMode is not set; consider explicitly handling the unset case to ensure the module specifier is resolved as intended.
options.overrideImportMode || importingSourceFile.impliedNodeFormat,
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_a) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before the change, emit was missing the tslib_1.
on these
impliedModuleKind !== ModuleKind.CommonJS && | ||
((moduleKind >= ModuleKind.ES2015 && moduleKind <= ModuleKind.ESNext) || | ||
impliedModuleKind === ModuleKind.ESNext || | ||
impliedModuleKind === undefined && moduleKind === ModuleKind.Preserve) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to simplify this condition in Corsa since we’re removing System, AMD, and UMD. Opting to make the minimal change here rather than try to clean up.
Noticed this while refactoring some code in Corsa.