Skip to content

Commit

Permalink
Don't rename names in array patterns. We were mistakenly treating the…
Browse files Browse the repository at this point in the history
…m as properties.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=169704631
  • Loading branch information
tbreisacher authored and blickly committed Sep 22, 2017
1 parent fff2168 commit 62d3242
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/com/google/javascript/jscomp/RenameProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,19 +365,21 @@ public void visit(NodeTraversal t, Node n, Node parent) {
// Get the object pattern within the destructuring on the lhs
n = n.getFirstChild();

// Iterate through all the nodes in the object pattern
for (Node key = n.getFirstChild(); key != null; key = key.getNext()) {
if (key.isComputedProp()) {
// We don't want to rename computed properties
continue;
} else if (key.isQuotedString()) {
// Ensure that we never rename some other property in a way
// that could conflict with this quoted key.
quotedNames.add(key.getString());
} else if (compiler.getCodingConvention().blockRenamingForProperty(key.getString())) {
externedNames.add(key.getString());
} else {
maybeMarkCandidate(key);
if (n.isObjectPattern()) {
// Iterate through all the nodes in the object pattern
for (Node key = n.getFirstChild(); key != null; key = key.getNext()) {
if (key.isComputedProp()) {
// We don't want to rename computed properties
continue;
} else if (key.isQuotedString()) {
// Ensure that we never rename some other property in a way
// that could conflict with this quoted key.
quotedNames.add(key.getString());
} else if (compiler.getCodingConvention().blockRenamingForProperty(key.getString())) {
externedNames.add(key.getString());
} else {
maybeMarkCandidate(key);
}
}
}
break;
Expand Down
4 changes: 4 additions & 0 deletions test/com/google/javascript/jscomp/RenamePropertiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ public void testPrototypePropertyForArrowFunction() {
"Bar.prototype = {2: () => {}, a: () => {}}; bar[2]();");
}

public void testArrayDestructuring() {
testSame("var [first, second] = someArray");
}

public void testDestructuredProperties() {
// using destructuring shorthand
test("var { foo, bar } = { foo: 1, bar: 2 }", "var { b:foo, a:bar } = { b:1, a:2 }");
Expand Down

0 comments on commit 62d3242

Please sign in to comment.