Fix CommonJS rewrites in shorthand destructuring defaults#4111
Merged
Conversation
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix imported identifier destructuring default not rewritten
Fix CommonJS rewrites in shorthand destructuring defaults
May 30, 2026
jakebailey
approved these changes
Jun 1, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes CommonJS emit rewriting for imported/exported identifiers used in shorthand destructuring default initializers (e.g. ({ a = imported } = {})), preventing runtime ReferenceErrors by ensuring name substitution runs in that expression position.
Changes:
- Update identifier reference detection to treat
ShorthandPropertyAssignment.ObjectAssignmentInitializeras an expression reference position. - Add a new compiler emit regression test covering both imported and exported identifiers in shorthand destructuring defaults.
- Add the corresponding reference baseline verifying emitted CommonJS output rewrites to
require(...)/exports.*references.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
internal/transformers/utilities.go |
Extends IsIdentifierReference so identifier substitution applies within shorthand destructuring default initializers. |
testdata/tests/cases/compiler/commonjsShorthandDestructuringDefaultImportExport.ts |
Adds a targeted compiler test for shorthand destructuring defaults referencing imports/exports under CommonJS. |
testdata/baselines/reference/compiler/commonjsShorthandDestructuringDefaultImportExport.js |
Adds the reference baseline asserting correct rewritten CommonJS emit. |
RyanCavanaugh
approved these changes
Jun 2, 2026
Member
RyanCavanaugh
left a comment
There was a problem hiding this comment.
Very disturbing to not have Strada test for this!
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.
Imported and exported identifiers used inside shorthand destructuring default initializers were emitted unchanged in CommonJS output, causing runtime
ReferenceErrors.Identifier reference detection
ShorthandPropertyAssignment.ObjectAssignmentInitializeras an expression reference position.Regression coverage
now emits: