fix corner cases with static modifier (#5599)

This commit is contained in:
Alex Lam S.L
2022-08-04 19:48:21 +01:00
committed by GitHub
parent 884842cd6c
commit 41b65af6e2
2 changed files with 91 additions and 3 deletions

View File

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

View File

@@ -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";