Hoist named class/function expressions assigned to module.exports in JS declaration emit#3796
Open
inq wants to merge 2 commits into
Open
Hoist named class/function expressions assigned to module.exports in JS declaration emit#3796inq wants to merge 2 commits into
inq wants to merge 2 commits into
Conversation
…JS declaration emit
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes JS declaration emit for CommonJS module.exports = class/function Name { ... } by hoisting named class/function expressions into top-level declarations, avoiding the _default fallback and matching upstream TypeScript baselines more closely.
Changes:
- Teach
transformExportAssignmentto synthesize and transform a top-levelclass/functiondeclaration when the exported expression is a named class/function expression. - Update submodule reference baselines to reflect the corrected
export = Name+ hoisted declaration output. - Reduce/adjust
submoduleTriageddiffs by removing prior_default-based emit and associated DTS errors.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/transformers/declarations/transform.go | Hoists named class/function expressions assigned via export assignment into synthesized declarations and exports the name. |
| testdata/baselines/reference/submoduleTriaged/conformance/jsDeclarationsExportAssignedVisibility(target=es2015).js.diff | Updates triaged diff to reflect new hoisted declaration shape (removing prior _default-based mismatch). |
| testdata/baselines/reference/submoduleTriaged/conformance/jsDeclarationsExportAssignedClassExpressionShadowing(target=es2015).js.diff | Updates triaged diff to reflect corrected export = Q behavior for named class expression export assignment. |
| testdata/baselines/reference/submoduleTriaged/conformance/jsDeclarationsExportAssignedClassExpression(target=es2015).js.diff | Updates triaged diff to reflect export = Thing + hoisted declare class Thing output. |
| testdata/baselines/reference/submoduleTriaged/compiler/jsDeclarationEmitExportAssignedFunctionWithExtraTypedefsMembers.js.diff | Updates triaged diff to reflect export = loader + hoisted declare function loader output. |
| testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedVisibility(target=es2015).js | Updates reference baseline output for visibility test to match new hoisted declaration behavior (and removes prior DTS errors section). |
| testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionShadowing(target=es2015).js | Updates reference baseline output for shadowing case to match new hoisted declaration behavior. |
| testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpression(target=es2015).js | Updates reference baseline output for class expression export assignment to export = Thing; declare class Thing .... |
| testdata/baselines/reference/submodule/compiler/jsDeclarationEmitExportAssignedFunctionWithExtraTypedefsMembers.js | Updates reference baseline output for named function expression export assignment to export = loader; declare function loader .... |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Bug
module.exports = class Thing {...}was falling to the_defaultfallback intransformExportAssignment, emittingdeclare const _default: ...; export = _default;.Fix
export = Thing; declare class Thing {...}by feeding a converted declaration through the existingtransformClassDeclaration/transformFunctionDeclarationviaSetOriginal. Reduces 4submoduleTriagedbaselines.