Skip to content

Commit

Permalink
Ignore quoted strings in object patterns in DisambiguateProperties
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=221710632
  • Loading branch information
lauraharker authored and brad4d committed Nov 17, 2018
1 parent 1dd64fd commit 5fa22ee
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/com/google/javascript/jscomp/DisambiguateProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,11 @@ private void handleObjectPattern(Node pattern) {
continue;
}
Node stringKey = target.getStringKey();
if (stringKey.isQuotedString()) {
// Never rename quoted property accesses, e.g.
// const {'prop': localVar} = someObj;
continue;
}
String name = stringKey.getString();
Property prop = getProperty(name);
if (!prop.scheduleRenaming(stringKey, processProperty(prop, objectPatternType, null))
Expand Down
27 changes: 27 additions & 0 deletions test/com/google/javascript/jscomp/DisambiguatePropertiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3067,6 +3067,33 @@ public void testDisambiguatePropertyReference_objectPattern_stringKey_inDeclarat
"{prop=[[Foo], [function(new:Foo): undefined]]}");
}

@Test
public void testDontDisambiguatePropertyReference_objectPattern_withQuotedStringKey() {
testSets(
lines(
"class Foo {", //
" constructor() {",
" /** @const {number} */",
" this.prop = 3;",
" }",
"}",
"/** @type {string} */",
"Foo.prop = 'static property!';",
"const {'prop': prop} = {'prop': 3};"),
lines(
"class Foo {", //
" constructor() {",
" /** @const {number} */",
" this.Foo$prop = 3;",
" }",
"}",
"/** @type {string} */",
"Foo.function_new_Foo___undefined$prop = 'static property!';",
// we still rewrite the other 'prop' references, but ignore the quoted 'prop'
"const {'prop': prop} = {'prop': 3};"),
"{prop=[[Foo], [function(new:Foo): undefined]]}");
}

@Test
public void testDisambiguateCtorPropertyReference_objectPattern_stringKey_inDeclaration() {
testSets(
Expand Down

0 comments on commit 5fa22ee

Please sign in to comment.