Skip to content

Commit

Permalink
fix corner cases with static modifier (#5599)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl authored Aug 4, 2022
1 parent 884842c commit 41b65af
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
Expand Down
88 changes: 88 additions & 0 deletions test/compress/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 41b65af

Please sign in to comment.