Skip to content

Commit

Permalink
Enable "disambiguate private properties" for ES6+ output. This is a l…
Browse files Browse the repository at this point in the history
…ittle used pass but easy to do.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178011962
  • Loading branch information
concavelenz authored and blickly committed Dec 5, 2017
1 parent 0c04342 commit 4641404
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/com/google/javascript/jscomp/DefaultPassConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2460,6 +2460,11 @@ protected FeatureSet featureSet() {
protected CompilerPass create(AbstractCompiler compiler) {
return new DisambiguatePrivateProperties(compiler);
}

@Override
protected FeatureSet featureSet() {
return ES8_MODULES;
}
};

/** Disambiguate property names based on type information. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package com.google.javascript.jscomp;

import com.google.javascript.jscomp.CompilerOptions.LanguageMode;

/**
* Unit test for the Compiler DisambiguatPrivateeProperties pass.
*
Expand Down Expand Up @@ -77,9 +75,21 @@ public void testNoRenaming1() {
testSame("({prop_: 1});");
testSame("({get prop_(){ return 1} });");
testSame("({set prop_(a){ this.a = 1} });");
setAcceptedLanguage(LanguageMode.ECMASCRIPT_2015);
}

public void testNoRenamingES6() {

testSame("({get ['prop_'](){ return 1} });");
testSame("({set ['prop_'](a){ this.a = 1} });");
testSame("({'prop_'(a){ this.a = 1} });");
testSame("({'prop_'(){} });");
testSame("({['prop_'](){} });");

useGoogleCodingConvention = false;

// Not when the coding convention doesn't understand it.
testSame("({prop_(){ return 1} });");
testSame("class A{method_(){return 1} }");
testSame("class C { method_(){return 1} }");
}

public void testRenaming1() {
Expand All @@ -100,23 +110,37 @@ public void testRenaming1() {
test(
"({set prop_(a){ this.a = 1} });",
"({set prop_$0(a){ this.a = 1} });");
setAcceptedLanguage(LanguageMode.ECMASCRIPT_2015);
}

public void testRenamingES6() {
test(
"({prop_(){ return 1} });",
"({prop_$0(){ return 1} });");
test(
"class A{method_(){return 1} }",
"class A{method_$0(){return 1} }");
"class C { method_(){return 1} }",
"class C { method_$0(){return 1} }");

test(
"class C { static method_(){return 1} }",
"class C { static method_$0(){return 1} }");

test(
"class C { async method_(){} }",
"class C { async method_$0(){} }");

test(
"class C { *method_(){} }",
"class C { *method_$0(){} }");
}


public void testNoRenameIndirectProps() {
useGoogleCodingConvention = true;

testSame("({}).superClass_;");
testSame("({superClass_: 1});");
testSame("({get superClass_(){ return 1} });");
testSame("({set superClass_(a){this.a = 1} });");
setAcceptedLanguage(LanguageMode.ECMASCRIPT_2015);
testSame("({superClass_(){ return 1} });");
}
}

0 comments on commit 4641404

Please sign in to comment.