From a800356ad089c81a4bc25a90d58bc0071ebe7a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Sat, 21 Nov 2015 14:48:23 +0000 Subject: [PATCH] Implement new.target --- lib/ast.js | 4 ++++ lib/output.js | 3 +++ lib/parse.js | 8 ++++++++ test/compress/harmony.js | 8 ++++++++ 4 files changed, 23 insertions(+) diff --git a/lib/ast.js b/lib/ast.js index faae55fd..c315c4a1 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -1003,6 +1003,10 @@ var AST_Symbol = DEFNODE("Symbol", "scope name thedef", { $documentation: "Base class for all symbols", }); +var AST_NewTarget = DEFNODE("NewTarget", null, { + $documentation: "A reference to new.target" +}); + var AST_SymbolAccessor = DEFNODE("SymbolAccessor", null, { $documentation: "The name of a property accessor (setter/getter function)" }, AST_Symbol); diff --git a/lib/output.js b/lib/output.js index d1ebdeee..74d88d25 100644 --- a/lib/output.js +++ b/lib/output.js @@ -1219,6 +1219,9 @@ function OutputStream(options) { }); else output.print("{}"); }); + DEFPRINT(AST_NewTarget, function(self, output) { + output.print("new.target"); + }); DEFPRINT(AST_ObjectKeyVal, function(self, output){ var key = self.key; var quote = self.quote; diff --git a/lib/parse.js b/lib/parse.js index 9341ad39..8f03435f 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1292,6 +1292,14 @@ function parse($TEXT, options) { var new_ = function(allow_calls) { var start = S.token; expect_token("operator", "new"); + if (is("punc", ".")) { + next(); + expect_token("name"); + return subscripts(new AST_NewTarget({ + start : start, + end : prev() + }), allow_calls); + } var newexp = expr_atom(false), args; if (is("punc", "(")) { next(); diff --git a/test/compress/harmony.js b/test/compress/harmony.js index 1d18301d..e53f9458 100644 --- a/test/compress/harmony.js +++ b/test/compress/harmony.js @@ -251,6 +251,14 @@ class_name_can_be_preserved: { } } +new_target: { + input: { + new.target; + new.target.name; + } + expect_exact: "new.target;new.target.name;" +} + number_literals: { input: { 0b1001;