diff --git a/src/expression.js b/src/expression.js index 84bb04a540..fe186f68b1 100644 --- a/src/expression.js +++ b/src/expression.js @@ -382,7 +382,14 @@ const empty = [] pp.parseNew = function() { let node = this.startNode() - this.next() + let meta = this.parseIdent(true) + if (this.options.ecmaVersion >= 6 && this.eat(tt.dot)) { + node.meta = meta + node.property = this.parseIdent(true) + if (node.property.name !== "target") + this.raise(node.property.start, "The only valid meta property for new is new.target") + return this.finishNode(node, "MetaProperty") + } let start = this.markPosition() node.callee = this.parseSubscripts(this.parseExprAtom(), start, true) if (this.eat(tt.parenL)) node.arguments = this.parseExprList(tt.parenR, false) diff --git a/src/loose/expression.js b/src/loose/expression.js index b0286fb58d..80aac911eb 100644 --- a/src/loose/expression.js +++ b/src/loose/expression.js @@ -269,7 +269,12 @@ lp.parseExprAtom = function() { lp.parseNew = function() { let node = this.startNode(), startIndent = this.curIndent, line = this.curLineStart - this.next() + let meta = this.parseIdent(true) + if (this.options.ecmaVersion >= 6 && this.eat(tt.dot)) { + node.meta = meta + node.property = this.parseIdent(true) + return this.finishNode(node, "MetaProperty") + } let start = this.storeCurrentPos() node.callee = this.parseSubscripts(this.parseExprAtom(), start, true, startIndent, line) if (this.tok.type == tt.parenL) { diff --git a/test/tests-harmony.js b/test/tests-harmony.js index 5eec5cbf5e..e536094291 100644 --- a/test/tests-harmony.js +++ b/test/tests-harmony.js @@ -15579,3 +15579,18 @@ testFail("'use strict'; ({eval = defValue} = obj)", "Assigning to eval in strict testFail("[...eval] = arr", "Assigning to eval in strict mode (1:4)", {ecmaVersion: 6, sourceType: "module"}); testFail("function* y({yield}) {}", "Binding yield (1:13)", {ecmaVersion: 6}); + +test("new.target", { + type: "Program", + body: [{ + type: "ExpressionStatement", + expression: { + type: "MetaProperty", + meta: {type: "Identifier", name: "new"}, + property: {type: "Identifier", name: "target"} + } + }], + sourceType: "script" +}, {ecmaVersion: 6}); + +testFail("new.prop", "The only valid meta property for new is new.target (1:4)", {ecmaVersion: 6});