Skip to content

Fix CommonJS rewrites in shorthand destructuring defaults#4111

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-destructuring-default-initializer
Draft

Fix CommonJS rewrites in shorthand destructuring defaults#4111
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-destructuring-default-initializer

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 30, 2026

Imported and exported identifiers used inside shorthand destructuring default initializers were emitted unchanged in CommonJS output, causing runtime ReferenceErrors.

  • Identifier reference detection

    • Treat ShorthandPropertyAssignment.ObjectAssignmentInitializer as an expression reference position.
    • This allows existing CommonJS substitution logic to rewrite imported/exported identifiers there.
  • Regression coverage

    • Added a compiler emit test covering both imported and exported identifiers in shorthand destructuring defaults.
import { imported } from "./b";
export const exported = 2;
let a, b;
({ a = imported, b = exported } = {});

now emits:

({ a = b_1.imported, b = exports.exported } = {});

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
Copilot AI requested a review from jakebailey May 30, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Imported/exported identifier used as a shorthand destructuring default initializer is not rewritten

2 participants