From 07785d0003e0c1669f60e348decac85b07502cdb Mon Sep 17 00:00:00 2001 From: Anthony Van de Gejuchte Date: Sat, 25 Jun 2016 19:32:09 +0200 Subject: [PATCH] Throw error if new.target is like new.foo --- lib/parse.js | 2 +- test/mocha/new.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/parse.js b/lib/parse.js index f1fbf9e8..0cabd453 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1448,7 +1448,7 @@ function parse($TEXT, options) { expect_token("operator", "new"); if (is("punc", ".")) { next(); - expect_token("name"); + expect_token("name", "target"); return subscripts(new AST_NewTarget({ start : start, end : prev() diff --git a/test/mocha/new.js b/test/mocha/new.js index 083b9964..cc193d3d 100644 --- a/test/mocha/new.js +++ b/test/mocha/new.js @@ -85,4 +85,11 @@ describe("New", function() { ); } }); + + it("Should check target in new.target", function() { + assert.throws(function() {uglify.parse("new.blah")}, function(e) { + return e instanceof uglify.JS_Parse_Error + && e.message === "SyntaxError: Unexpected token name «blah», expected name «target»"; + }); + }); }); \ No newline at end of file