Skip to content

experimentalImportSupport: Fix exported names under relabelling and rest spread (#1772)#1772

Closed
robhogan wants to merge 1 commit into
mainfrom
export-D111013897
Closed

experimentalImportSupport: Fix exported names under relabelling and rest spread (#1772)#1772
robhogan wants to merge 1 commit into
mainfrom
export-D111013897

Conversation

@robhogan

@robhogan robhogan commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary:

Fixes #1460

Fixes two related bugs in Metro's experimentalImportSupport.

Exports with inline relabelling

export const { A: B } = {};

Currently transforms to

const { A: B } = {};
exports.A = A;

Which is invalid: A is a reference error.

After this diff

const { A: B } = {};
exports.A = B;

Exports with spreads

Currently both of these fail to transform:

Object spread

export const {A, ...others} = {A: 'A', B: 'B', C: 'C'};

Plugin throws TypeError: Cannot read properties of undefined (reading 'name') when attempting to iterate over the object for key: val pairs.

Array spread

export const [A, ...others] = ['A', 'B', 'C'];

Plugin throws Property name expected type of string but got undefined after extracting an undefined name and then attempting to use it at as prop of exports.

After this diff

const {A, ...others} = {A: 'A', B: 'B', C: 'C'};
exports.A = A;
exports.others = others;

and

const [A, ...others] = ['A', 'B', 'C'];
exports.A = A;
exports.others = others;

Spec

Almost goes without saying in this case - exported variable declarations should expose the declaration's bound names. ECMA-262 defines those names through Static Semantics: BoundNames, including BindingPattern forms: https://tc39.es/ecma262/#sec-static-semantics-boundnames

Implementation

Metro had naive ObjectPattern/ArrayPattern extraction that read object keys or array elements directly.

This fixes the same issues Expo did in #38058 and #38118, but uses Babel's own getBindingIdentifiers for a simpler implementation.

Changelog

 - **[Experimental]**: experimentalImportSupport: Fix exports renamed by destructuring, and support exports of rest spreads.

Reviewed By: GijsWeterings, huntie

Differential Revision: D111013897

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 9, 2026
@meta-codesync

meta-codesync Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

@robhogan has exported this pull request. If you are a Meta employee, you can view the originating Diff in D111013897.

…est spread (#1772)

Summary:

Fixes #1460

Fixes two related bugs in Metro's `experimentalImportSupport`.

## Exports with inline relabelling

```js
export const { A: B } = {};
```

**Currently transforms to**

```js
const { A: B } = {};
exports.A = A;
```

Which is invalid: `A` is a reference error.

**After this diff**

```js
const { A: B } = {};
exports.A = B;
```

## Exports with spreads

Currently both of these fail to transform:

**Object spread**
```js
export const {A, ...others} = {A: 'A', B: 'B', C: 'C'};
```

Plugin throws `TypeError: Cannot read properties of undefined (reading 'name')` when attempting to iterate over the object for key: val pairs.

**Array spread**
```js
export const [A, ...others] = ['A', 'B', 'C'];
```

Plugin throws `Property name expected type of string but got undefined` after extracting an `undefined` name and then attempting to use it at as prop of `exports`.

**After this diff**

```js
const {A, ...others} = {A: 'A', B: 'B', C: 'C'};
exports.A = A;
exports.others = others;
```
and

```js
const [A, ...others] = ['A', 'B', 'C'];
exports.A = A;
exports.others = others;
```

## Spec
Almost goes without saying in this case - exported variable declarations should expose the declaration's bound names. ECMA-262 defines those names through Static Semantics: `BoundNames`, including `BindingPattern` forms: https://tc39.es/ecma262/#sec-static-semantics-boundnames

## Implementation

Metro had naive `ObjectPattern`/`ArrayPattern` extraction that read object keys or array elements directly.

This fixes the same issues Expo did in [#38058](expo/expo#38058) and [#38118](expo/expo#38118), but uses Babel's own `getBindingIdentifiers` for a simpler implementation.

## Changelog
```
 - **[Experimental]**: experimentalImportSupport: Fix exports renamed by destructuring, and support exports of rest spreads.
```

Reviewed By: GijsWeterings, huntie

Differential Revision: D111013897
@meta-codesync meta-codesync Bot changed the title experimentalImportSupport: Fix exported names under relabelling and rest spread experimentalImportSupport: Fix exported names under relabelling and rest spread (#1772) Jul 9, 2026
@meta-codesync meta-codesync Bot force-pushed the export-D111013897 branch from 455bb9e to d0d73f6 Compare July 9, 2026 21:11
@meta-codesync meta-codesync Bot closed this in 0dc5030 Jul 9, 2026
@meta-codesync

meta-codesync Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

This pull request has been merged in 0dc5030.

@meta-codesync meta-codesync Bot added the Merged label Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

experimentalImportSupport has wrong exports for destructured object

1 participant