From ddd30eeaaad77662edb7c0de5e500379e81e8095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Wed, 5 Aug 2015 11:49:31 +0100 Subject: [PATCH 1/2] Uglifyjs already supports super as an implicit global! Just adding a test to indicate that. --- test/compress/super.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 test/compress/super.js diff --git a/test/compress/super.js b/test/compress/super.js new file mode 100644 index 00000000..d297a84e --- /dev/null +++ b/test/compress/super.js @@ -0,0 +1,9 @@ + +super_can_be_parsed: { + input: { + super(1,2); + super.meth(); + } + expect_exact: "super(1,2);super.meth();" +} + From e80ed38772db814040e2cc7c2fe6840a82939b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Fri, 7 Aug 2015 02:44:53 +0100 Subject: [PATCH 2/2] Super! --- lib/ast.js | 4 ++++ lib/output.js | 3 +++ lib/parse.js | 5 ++++- lib/scope.js | 2 ++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/ast.js b/lib/ast.js index 7caccfd3..078f748e 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -940,6 +940,10 @@ var AST_This = DEFNODE("This", null, { $documentation: "The `this` symbol", }, AST_Symbol); +var AST_Super = DEFNODE("Super", null, { + $documentation: "The `super` symbol", +}, AST_Symbol); + var AST_Constant = DEFNODE("Constant", null, { $documentation: "Base class for all constants", getValue: function() { diff --git a/lib/output.js b/lib/output.js index 28c1facd..275cf9b6 100644 --- a/lib/output.js +++ b/lib/output.js @@ -1151,6 +1151,9 @@ function OutputStream(options) { DEFPRINT(AST_This, function(self, output){ output.print("this"); }); + DEFPRINT(AST_Super, function(self, output){ + output.print("super"); + }); DEFPRINT(AST_Constant, function(self, output){ output.print(self.getValue()); }); diff --git a/lib/parse.js b/lib/parse.js index 7b175a7e..269bb235 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1361,7 +1361,9 @@ function parse($TEXT, options) { function _make_symbol(type) { var name = S.token.value; - return new (name == "this" ? AST_This : type)({ + return new (name == "this" ? AST_This : + name == "super" ? AST_Super : + type)({ name : String(name), start : S.token, end : S.token @@ -1481,6 +1483,7 @@ function parse($TEXT, options) { function is_assignable(expr) { if (!options.strict) return true; if (expr instanceof AST_This) return false; + if (expr instanceof AST_Super) return false; return (expr instanceof AST_PropAccess || expr instanceof AST_Symbol); }; diff --git a/lib/scope.js b/lib/scope.js index a251f55b..55d7c4e9 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -472,6 +472,8 @@ AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options){ base54.consider("new"); else if (node instanceof AST_This) base54.consider("this"); + else if (node instanceof AST_Super) + base54.consider("super"); else if (node instanceof AST_Try) base54.consider("try"); else if (node instanceof AST_Catch)