support mangle.properties on class (#4838)
This commit is contained in:
@@ -81,7 +81,9 @@ var builtins = function() {
|
|||||||
|
|
||||||
function reserve_quoted_keys(ast, reserved) {
|
function reserve_quoted_keys(ast, reserved) {
|
||||||
ast.walk(new TreeWalker(function(node) {
|
ast.walk(new TreeWalker(function(node) {
|
||||||
if (node instanceof AST_ObjectProperty) {
|
if (node instanceof AST_ClassProperty) {
|
||||||
|
if (node.start && node.start.quote) add(node.key);
|
||||||
|
} else if (node instanceof AST_ObjectProperty) {
|
||||||
if (node.start && node.start.quote) add(node.key);
|
if (node.start && node.start.quote) add(node.key);
|
||||||
} else if (node instanceof AST_Sub) {
|
} else if (node instanceof AST_Sub) {
|
||||||
addStrings(node.property, add);
|
addStrings(node.property, add);
|
||||||
@@ -163,6 +165,8 @@ function mangle_properties(ast, options) {
|
|||||||
addStrings(node.args[0], add);
|
addStrings(node.args[0], add);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else if (node instanceof AST_ClassProperty) {
|
||||||
|
if (typeof node.key == "string") add(node.key);
|
||||||
} else if (node instanceof AST_Dot) {
|
} else if (node instanceof AST_Dot) {
|
||||||
add(node.property);
|
add(node.property);
|
||||||
} else if (node instanceof AST_ObjectProperty) {
|
} else if (node instanceof AST_ObjectProperty) {
|
||||||
@@ -193,6 +197,8 @@ function mangle_properties(ast, options) {
|
|||||||
mangleStrings(node.args[0]);
|
mangleStrings(node.args[0]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else if (node instanceof AST_ClassProperty) {
|
||||||
|
if (typeof node.key == "string") node.key = mangle(node.key);
|
||||||
} else if (node instanceof AST_Dot) {
|
} else if (node instanceof AST_Dot) {
|
||||||
node.property = mangle(node.property);
|
node.property = mangle(node.property);
|
||||||
} else if (node instanceof AST_ObjectProperty) {
|
} else if (node instanceof AST_ObjectProperty) {
|
||||||
@@ -222,9 +228,7 @@ function mangle_properties(ast, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mangle(name) {
|
function mangle(name) {
|
||||||
if (!should_mangle(name)) {
|
if (!should_mangle(name)) return name;
|
||||||
return name;
|
|
||||||
}
|
|
||||||
var mangled = cache.get(name);
|
var mangled = cache.get(name);
|
||||||
if (!mangled) {
|
if (!mangled) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
@@ -236,6 +240,7 @@ function mangle_properties(ast, options) {
|
|||||||
if (!mangled) do {
|
if (!mangled) do {
|
||||||
mangled = base54(++cname);
|
mangled = base54(++cname);
|
||||||
} while (!can_mangle(mangled));
|
} while (!can_mangle(mangled));
|
||||||
|
if (/^#/.test(name)) mangled = "#" + mangled;
|
||||||
cache.set(name, mangled);
|
cache.set(name, mangled);
|
||||||
}
|
}
|
||||||
return mangled;
|
return mangled;
|
||||||
|
|||||||
@@ -1400,3 +1400,45 @@ issue_4829_2: {
|
|||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
node_version: ">=4"
|
node_version: ">=4"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mangle_properties: {
|
||||||
|
mangle = {
|
||||||
|
properties: {
|
||||||
|
keep_quoted: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
class A {
|
||||||
|
static #P = "PASS";
|
||||||
|
static get Q() {
|
||||||
|
return this.#P;
|
||||||
|
}
|
||||||
|
#p(n) {
|
||||||
|
return (this["q"] = n) * this.r;
|
||||||
|
}
|
||||||
|
set q(v) {
|
||||||
|
this.r = v + 1;
|
||||||
|
}
|
||||||
|
r = this.#p(6);
|
||||||
|
}
|
||||||
|
console.log(A.Q, new A().r);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
class A {
|
||||||
|
static #t = "PASS";
|
||||||
|
static get s() {
|
||||||
|
return this.#t;
|
||||||
|
}
|
||||||
|
#i(t) {
|
||||||
|
return (this["q"] = t) * this.e;
|
||||||
|
}
|
||||||
|
set q(t) {
|
||||||
|
this.e = t + 1;
|
||||||
|
}
|
||||||
|
e = this.#i(6);
|
||||||
|
}
|
||||||
|
console.log(A.s, new A().e);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS 42"
|
||||||
|
node_version: ">=14.6"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user