support shorthand method name in object literal (#4264)

This commit is contained in:
Alex Lam S.L
2020-11-08 05:17:53 +00:00
committed by GitHub
parent b82de04775
commit 1cbd07e789
2 changed files with 53 additions and 16 deletions

View File

@@ -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();