Fix helpers emit for .cjs files in ESM module mode#61814
Merged
andrewbranch merged 3 commits intomicrosoft:mainfrom Jun 6, 2025
Merged
Fix helpers emit for .cjs files in ESM module mode#61814andrewbranch merged 3 commits intomicrosoft:mainfrom
andrewbranch merged 3 commits intomicrosoft:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
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,
andrewbranch
commented
Jun 4, 2025
Comment on lines
+14
to
+15
| return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
| return tslib_1.__generator(this, function (_a) { |
Member
Author
There was a problem hiding this comment.
Before the change, emit was missing the tslib_1. on these
andrewbranch
commented
Jun 4, 2025
| impliedModuleKind !== ModuleKind.CommonJS && | ||
| ((moduleKind >= ModuleKind.ES2015 && moduleKind <= ModuleKind.ESNext) || | ||
| impliedModuleKind === ModuleKind.ESNext || | ||
| impliedModuleKind === undefined && moduleKind === ModuleKind.Preserve) |
Member
Author
There was a problem hiding this comment.
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.
andrewbranch
commented
Jun 4, 2025
weswigham
approved these changes
Jun 5, 2025
weswigham
approved these changes
Jun 6, 2025
This was referenced Jun 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Noticed this while refactoring some code in Corsa.