fix corner cases with static modifier (#5599)
This commit is contained in:
@@ -1056,13 +1056,13 @@ function parse($TEXT, options) {
|
||||
return stat;
|
||||
}
|
||||
|
||||
function has_modifier(name) {
|
||||
function has_modifier(name, no_nlb) {
|
||||
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;
|
||||
if (no_nlb && has_newline_before(token)) return;
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -1092,7 +1092,7 @@ function parse($TEXT, options) {
|
||||
}
|
||||
var start = S.token;
|
||||
var fixed = !!has_modifier("static");
|
||||
var async = has_modifier("async");
|
||||
var async = has_modifier("async", true);
|
||||
if (is("operator", "*")) {
|
||||
next();
|
||||
var internal = is("name") && /^#/.test(S.token.value);
|
||||
|
||||
@@ -241,6 +241,94 @@ class_super: {
|
||||
node_version: ">=4"
|
||||
}
|
||||
|
||||
static_newline_1: {
|
||||
input: {
|
||||
class A {
|
||||
static
|
||||
P
|
||||
}
|
||||
console.log("P" in A, "static" in A);
|
||||
console.log("P" in new A(), "static" in new A());
|
||||
}
|
||||
expect_exact: 'class A{static P}console.log("P"in A,"static"in A);console.log("P"in new A,"static"in new A);'
|
||||
expect_stdout: [
|
||||
"true false",
|
||||
"false false",
|
||||
]
|
||||
node_version: ">=12"
|
||||
}
|
||||
|
||||
static_newline_2: {
|
||||
input: {
|
||||
class A {
|
||||
static
|
||||
static
|
||||
P
|
||||
}
|
||||
console.log("P" in A, "static" in A);
|
||||
console.log("P" in new A(), "static" in new A());
|
||||
}
|
||||
expect_exact: 'class A{static static;P}console.log("P"in A,"static"in A);console.log("P"in new A,"static"in new A);'
|
||||
expect_stdout: [
|
||||
"false true",
|
||||
"true false",
|
||||
]
|
||||
node_version: ">=12"
|
||||
}
|
||||
|
||||
static_newline_3: {
|
||||
input: {
|
||||
class A {
|
||||
static
|
||||
static
|
||||
static
|
||||
P
|
||||
}
|
||||
console.log("P" in A, "static" in A);
|
||||
console.log("P" in new A(), "static" in new A());
|
||||
}
|
||||
expect_exact: 'class A{static static;static P}console.log("P"in A,"static"in A);console.log("P"in new A,"static"in new A);'
|
||||
expect_stdout: [
|
||||
"true true",
|
||||
"false false",
|
||||
]
|
||||
node_version: ">=12"
|
||||
}
|
||||
|
||||
static_newline_4: {
|
||||
input: {
|
||||
class A {
|
||||
static
|
||||
static
|
||||
static
|
||||
static
|
||||
P
|
||||
}
|
||||
console.log("P" in A, "static" in A);
|
||||
console.log("P" in new A(), "static" in new A());
|
||||
}
|
||||
expect_exact: 'class A{static static;static static;P}console.log("P"in A,"static"in A);console.log("P"in new A,"static"in new A);'
|
||||
expect_stdout: [
|
||||
"false true",
|
||||
"true false",
|
||||
]
|
||||
node_version: ">=12"
|
||||
}
|
||||
|
||||
static_newline_init: {
|
||||
input: {
|
||||
class A {
|
||||
static
|
||||
{
|
||||
console.log("PASS");
|
||||
}
|
||||
}
|
||||
}
|
||||
expect_exact: 'class A{static{console.log("PASS")}}'
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=16"
|
||||
}
|
||||
|
||||
static_init: {
|
||||
input: {
|
||||
var a = "foo";
|
||||
|
||||
Reference in New Issue
Block a user