Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 5768 #5811

Merged
merged 2 commits into from Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -73,23 +73,53 @@ export default function () {
if (node[REASSIGN_REMAP_SKIP]) return;

const left = path.get("left");
if (!left.isIdentifier()) return;
if (left.isIdentifier()) {
const name = left.node.name;
const exports = this.exports[name];
if (!exports) return;

const name = left.node.name;
const exports = this.exports[name];
if (!exports) return;
// redeclared in this scope
if (this.scope.getBinding(name) !== path.scope.getBinding(name)) return;

// redeclared in this scope
if (this.scope.getBinding(name) !== path.scope.getBinding(name)) return;
node[REASSIGN_REMAP_SKIP] = true;

node[REASSIGN_REMAP_SKIP] = true;
for (const reid of exports) {
node = buildExportsAssignment(reid, node).expression;
}

for (const reid of exports) {
node = buildExportsAssignment(reid, node).expression;
path.replaceWith(node);
this.requeueInParent(path);
}
else if (left.isObjectPattern()) {
for (const property of left.node.properties) {
const name = property.value.name;

path.replaceWith(node);
this.requeueInParent(path);
const exports = this.exports[name];
if (!exports) continue;

// redeclared in this scope
if (this.scope.getBinding(name) !== path.scope.getBinding(name)) return;

node[REASSIGN_REMAP_SKIP] = true;

path.insertAfter(buildExportsAssignment(t.identifier(name), t.identifier(name)));
}
}
else if (left.isArrayPattern()) {
for (const element of left.node.elements) {
const name = element.name;

const exports = this.exports[name];
if (!exports) continue;

// redeclared in this scope
if (this.scope.getBinding(name) !== path.scope.getBinding(name)) return;

node[REASSIGN_REMAP_SKIP] = true;

path.insertAfter(buildExportsAssignment(t.identifier(name), t.identifier(name)));
}
}
},

UpdateExpression(path) {
Expand Down
@@ -0,0 +1,14 @@
export let x = 0;
export let y = 0;

export function f1 () {
({x} = { x: 1 });
}

export function f2 () {
({x, y} = { x: 2, y: 3 });
}

export function f3 () {
[x, y, z] = [3, 4, 5]
}
@@ -0,0 +1,27 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.f1 = f1;
exports.f2 = f2;
exports.f3 = f3;
let x = exports.x = 0;
let y = exports.y = 0;

function f1() {
({ x } = { x: 1 });
exports.x = x;
}

function f2() {
({ x, y } = { x: 2, y: 3 });
exports.y = y;
exports.x = x;
}

function f3() {
[x, y, z] = [3, 4, 5];
exports.y = y;
exports.x = x;
}