diff --git a/lib/ast.js b/lib/ast.js index d9afcff4..32d8486f 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -473,6 +473,10 @@ var AST_Arrow = DEFNODE("Arrow", null, { $documentation: "An ES6 Arrow function ((a) => b)" }, AST_Lambda); +var AST_ConciseMethod = DEFNODE("ConciseMethod", null, { + $documentation: "An ES6 concise method inside an object or class" +}, AST_Lambda); + var AST_Defun = DEFNODE("Defun", null, { $documentation: "A function definition" }, AST_Lambda); diff --git a/lib/output.js b/lib/output.js index f8929020..bdab47c6 100644 --- a/lib/output.js +++ b/lib/output.js @@ -832,6 +832,9 @@ function OutputStream(options) { } if (needs_parens) { output.print(")") } }); + DEFPRINT(AST_ConciseMethod, function(self, output){ + self._do_print(output, true /* do not print "function" */); + }); /* -----[ exits ]----- */ AST_Exit.DEFMETHOD("_do_print", function(output, kind){ diff --git a/lib/parse.js b/lib/parse.js index 95e44914..9fd4dcdf 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1446,6 +1446,16 @@ function parse($TEXT, options) { var type = start.type; var name = as_property_name(); if (type == "name" && !is("punc", ":")) { + if (is("punc", "(")) { + a.push(new AST_ConciseMethod({ + start : start, + name : new AST_Symbol({ name: name }), // TODO what symbol is this really? + argnames : params_or_seq_().as_params(croak), + body : _function_body(true), + end : prev() + })) + continue; + } if (name == "get") { a.push(new AST_ObjectGetter({ start : start, diff --git a/test/compress/harmony.js b/test/compress/harmony.js index 54be70d4..718a547a 100644 --- a/test/compress/harmony.js +++ b/test/compress/harmony.js @@ -132,6 +132,22 @@ destructuring_arguments: { } } +concise_methods: { + input: { + x = { + foo(a, b) { + return x; + } + } + y = { + foo([{a}]) { + return a; + } + } + } + expect_exact: "x={foo(a,b){return x}};y={foo([{a}]){return a}};" +} + number_literals: { input: { 0b1001;