Skip to content

Commit 8cfa37e

Browse files
authored
fix corner case in semicolons (#5881)
fixes #5880
1 parent 008edfb commit 8cfa37e

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

lib/ast.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,9 +965,12 @@ var AST_ClassProperty = DEFNODE("ClassProperty", "key private static value", {
965965
if (this.key != null) throw new Error("key must be null");
966966
} else if (typeof this.key != "string") {
967967
if (!(this.key instanceof AST_Node)) throw new Error("key must be string or AST_Node");
968+
if (this.private) throw new Error("computed key cannot be private");
968969
must_be_expression(this, "key");
970+
} else if (this.private) {
971+
if (!/^#/.test(this.key)) throw new Error("private key must prefix with #");
969972
}
970-
if(this.value != null) {
973+
if (this.value != null) {
971974
if (!(this.value instanceof AST_Node)) throw new Error("value must be AST_Node");
972975
}
973976
},
@@ -976,7 +979,7 @@ var AST_ClassProperty = DEFNODE("ClassProperty", "key private static value", {
976979
var AST_ClassField = DEFNODE("ClassField", null, {
977980
$documentation: "A `class` field",
978981
_validate: function() {
979-
if(this.value != null) must_be_expression(this, "value");
982+
if (this.value != null) must_be_expression(this, "value");
980983
},
981984
}, AST_ClassProperty);
982985

lib/output.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,12 @@ function OutputStream(options) {
12511251
output.print("=");
12521252
output.space();
12531253
self.value.print(output);
1254+
} else switch (self.key) {
1255+
case "get":
1256+
case "set":
1257+
case "static":
1258+
output.force_semicolon();
1259+
return;
12541260
}
12551261
output.semicolon();
12561262
});

test/compress/classes.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4177,3 +4177,52 @@ issue_5878_4: {
41774177
expect_stdout: "function"
41784178
node_version: ">=4"
41794179
}
4180+
4181+
issue_5880_1: {
4182+
beautify = {
4183+
semicolons: false,
4184+
}
4185+
input: {
4186+
new class {
4187+
get;
4188+
p = console.log("PASS");
4189+
}();
4190+
}
4191+
expect_exact: 'new class{get;p=console.log("PASS")}\n'
4192+
expect_stdout: "PASS"
4193+
node_version: ">=12"
4194+
}
4195+
4196+
issue_5880_2: {
4197+
beautify = {
4198+
semicolons: false,
4199+
}
4200+
input: {
4201+
class A {
4202+
set;
4203+
static {
4204+
console.log("PASS");
4205+
}
4206+
}
4207+
}
4208+
expect_exact: 'class A{set;static{console.log("PASS")}}'
4209+
expect_stdout: "PASS"
4210+
node_version: ">=16"
4211+
}
4212+
4213+
issue_5880_3: {
4214+
beautify = {
4215+
semicolons: false,
4216+
}
4217+
input: {
4218+
new class {
4219+
static;
4220+
f() {
4221+
console.log("PASS");
4222+
}
4223+
}().f();
4224+
}
4225+
expect_exact: '(new class{static;f(){console.log("PASS")}}).f()\n'
4226+
expect_stdout: "PASS"
4227+
node_version: ">=12"
4228+
}

test/sandbox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ exports.patch_module_statements = function(code, module) {
7373
} while (code.indexOf(name) >= 0);
7474
return header.slice(0, -1) + " " + name + header.slice(-1);
7575
}).replace(/\bimport\.meta\b/g, function() {
76-
return '({ url: "https://example.com/path/index.html" })';
76+
return 'Object.create({ url: "https://example.com/path/index.html" })';
7777
}).replace(/\bimport\b(?:\s*([^\s('"][^('"]*)\bfrom\b)?\s*(['"]).*?\2(?:$|\n|;)/g, function(match, symbols) {
7878
if (symbols) {
7979
if (!/^[{*]/.test(symbols)) symbols = "default:" + symbols;

0 commit comments

Comments
 (0)