-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Description
Describe the bug
There is a stage 2.7 TC39 proposal that would break the way transpilers transform static blocks to private fields, if the static block freezes the class: tc39/proposal-nonextensible-applies-to-private#1.
It'd be great to get all the transpilers updated to be compatible, just in case.
Input code
class A {
static #foo = 1;
static { Object.freeze(this); }
}Config
{
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": false
},
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": true,
"env": {
"targets": "chrome 90"
}
}Link to the code that reproduces this issue
SWC Info output
No response
Expected behavior
See Babel PR for example: babel/babel#17443
Given this input:
class C {
static #FOO = "#FOO";
static {
C.#FOO = #BAR in C;
}
static #BAR = C.#FOO;
static {
Object.freeze(C);
}
}Something like
var lastBlocks;
class C {
static #FOO = "#FOO";
static #BAR = (() => {
C.#FOO = #BAR in C;
})(), lastBlocks = (() => {
Object.freeze(C);
}), C.#FOO;
}
lastBlocks();Actual behavior
For this code:
class A {
static #foo = 1;
static { Object.freeze(this); }
}SWC generates
class A {
static #foo = 1;
static #_ = Object.freeze(this);
}which with that proposal will throw because it's trying to add #_ to a frozen object.
Version
1.13.2
Additional context
No response
Reactions are currently unavailable