Skip to content

Exported variable declaration with destructured object literal and CommonJS module target #32656

Closed
@ark120202

Description

@ark120202

TypeScript Version: 3.6.0-dev.20190801

Search Terms:

destructuring, variable declatation, binding pattern, export, commonjs

Code

export const { x, ...rest } = { x: 'x', y: 'y' }

Expected behavior:

Similarly to array destructuring, make _a a temporary local identifier:

var _a;
exports.x = (_a = { x: 'x', y: 'y' }, _a.x), exports.rest = __rest(_a, ["x"]);

Actual behavior:

exports._a = { x: 'x', y: 'y' }, exports.x = _a.x, exports.rest = __rest(_a, ["x"]);

Which fails at runtime because _a is not defined.

Playground Link:

https://www.typescriptlang.org/play/?target=1#code/KYDwDg9gTgLgBAYwgOwM7wN5xAGjgOkKmHTgF84BeOLEALjgHIRG8BPBxtx8gWACggA

Related Issues:

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions