Skip to content

Commit

Permalink
Add NodeUtil precedence case for ES6 new.target
Browse files Browse the repository at this point in the history
This will fix the case where jscomp throws an exception whilst compiling ES6 code that uses new.target.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=172368097
  • Loading branch information
fmarvin authored and lauraharker committed Oct 16, 2017
1 parent d110cac commit 84502f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/com/google/javascript/jscomp/NodeUtil.java
Expand Up @@ -1612,6 +1612,7 @@ static int precedence(Token type) {
case CALL:
case GETELEM:
case GETPROP:
case NEW_TARGET:
// Data values
case ARRAYLIT:
case ARRAY_PATTERN:
Expand Down
16 changes: 16 additions & 0 deletions test/com/google/javascript/jscomp/CodePrinterTest.java
Expand Up @@ -2770,6 +2770,22 @@ public void testEs6ArrowFunctionSetsOriginalNameForArguments() {
checkWithOriginalName(code, expectedCode, compilerOptions);
}

public void testEs6NewTargetBare() {
languageMode = LanguageMode.ECMASCRIPT_2015;
assertPrintSame("new.target.prototype");
}

public void testEs6NewTargetPrototype() {
languageMode = LanguageMode.ECMASCRIPT_2015;
assertPrintSame("var callable=Object.setPrototypeOf(obj,new.target.prototype)");
}

public void testEs6NewTargetConditional() {
languageMode = LanguageMode.ECMASCRIPT_2015;
assertPrint("if (!new.target) throw 'Must be called with new!';",
"if(!new.target)throw\"Must be called with new!\";");
}

public void testGoogScope() {
// TODO(mknichel): Function declarations need to be rewritten to match the original source
// instead of being assigned to a local variable with duplicate JS Doc.
Expand Down

0 comments on commit 84502f2

Please sign in to comment.