From 1cbd07e7897bcbb879921c63b9794f7a278ca5a6 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 8 Nov 2020 05:17:53 +0000 Subject: support shorthand method name in object literal (#4264) --- lib/parse.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'lib/parse.js') diff --git a/lib/parse.js b/lib/parse.js index 78311f89..84b14439 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1342,6 +1342,20 @@ function parse($TEXT, options) { var start = S.token; var type = start.type; var name = as_property_name(); + if (is("punc", "(")) { + var func_start = S.token; + var func = function_(AST_Function); + func.start = func_start; + func.end = prev(); + a.push(new AST_ObjectKeyVal({ + start: start, + quote: start.quote, + key: "" + name, + value: func, + end: prev(), + })); + continue; + } if (!is("punc", ":") && type == "name") switch (name) { case "get": a.push(new AST_ObjectGetter({ @@ -1379,11 +1393,11 @@ function parse($TEXT, options) { } expect(":"); a.push(new AST_ObjectKeyVal({ - start : start, - quote : start.quote, - key : "" + name, - value : expression(false), - end : prev() + start: start, + quote: start.quote, + key: "" + name, + value: expression(false), + end: prev(), })); } next(); -- cgit v1.2.3