fix corner case with class (#4713)
This commit is contained in:
22
lib/parse.js
22
lib/parse.js
@@ -1053,6 +1053,16 @@ function parse($TEXT, options) {
|
|||||||
return stat;
|
return stat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function has_modifier(name) {
|
||||||
|
if (!is("name", name)) return;
|
||||||
|
var token = peek();
|
||||||
|
if (!token) return;
|
||||||
|
if (is_token(token, "operator", "=")) return;
|
||||||
|
if (token.type == "punc" && /^[(;}]$/.test(token.value)) return;
|
||||||
|
if (has_newline_before(token)) return;
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
function class_(ctor) {
|
function class_(ctor) {
|
||||||
var was_async = S.in_async;
|
var was_async = S.in_async;
|
||||||
var was_gen = S.in_generator;
|
var was_gen = S.in_generator;
|
||||||
@@ -1078,16 +1088,8 @@ function parse($TEXT, options) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var start = S.token;
|
var start = S.token;
|
||||||
var fixed = is("name", "static");
|
var fixed = !!has_modifier("static");
|
||||||
if (fixed) next();
|
var async = has_modifier("async");
|
||||||
var async = is("name", "async") && peek();
|
|
||||||
if (async) {
|
|
||||||
if (async.type == "punc" && /^[(=;}]$/.test(async.value) || has_newline_before(async)) {
|
|
||||||
async = false;
|
|
||||||
} else {
|
|
||||||
async = next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (is("operator", "*")) {
|
if (is("operator", "*")) {
|
||||||
next();
|
next();
|
||||||
var internal = is("name") && /^#/.test(S.token.value);
|
var internal = is("name") && /^#/.test(S.token.value);
|
||||||
|
|||||||
@@ -82,6 +82,19 @@ fields: {
|
|||||||
node_version: ">=12"
|
node_version: ">=12"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
modifier_as_field_name: {
|
||||||
|
input: {
|
||||||
|
for (var k in new class { async; static = 42 })
|
||||||
|
console.log(k);
|
||||||
|
}
|
||||||
|
expect_exact: "for(var k in new class{async;static=42})console.log(k);"
|
||||||
|
expect_stdout: [
|
||||||
|
"async",
|
||||||
|
"static",
|
||||||
|
]
|
||||||
|
node_version: ">=12"
|
||||||
|
}
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
input: {
|
input: {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|||||||
Reference in New Issue
Block a user