swc
swc copied to clipboard
Private static class field access breakage with "externalHelpers": true
Describe the bug
swc generates erroneous code for private static class field access when the externalHelpers
configuration option is enabled.
Running the compiled input code (attached) throws an error originating from @swc/helpers
:
TypeError: Private static access of wrong provenance
at _classCheckPrivateStaticAccess (file:///private/var/folders/c5/w8h8xdfd7xgc946qctjlcs440000gp/T/tmp.lw8GWgIA/node_modules/@swc/helpers/src/_class_check_private_static_access.mjs:3:11)
at _classStaticPrivateFieldSpecGet (file:///private/var/folders/c5/w8h8xdfd7xgc946qctjlcs440000gp/T/tmp.lw8GWgIA/node_modules/@swc/helpers/src/_class_static_private_field_spec_get.mjs:7:3)
at Function.instance (file:///private/var/folders/c5/w8h8xdfd7xgc946qctjlcs440000gp/T/tmp.lw8GWgIA/index.build.mjs:14:24)
at file:///private/var/folders/c5/w8h8xdfd7xgc946qctjlcs440000gp/T/tmp.lw8GWgIA/index.build.mjs:24:16
at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12)
I presume this line is the culprit as the import is identical to the one above (./_class_check_private_static_access.mjs
). The error does not happen when the helpers are inlined, so there must be a difference between the external and inlined helpers.
Input code
class A {
static #INSTANCE = new A();
static instance() {
console.trace("A.instance");
return A.#INSTANCE;
}
}
console.info(A.instance())
Config
{
"jsc": {
"externalHelpers": true
}
}
Playground link
No response
Expected behavior
The code doesn't throw an error.
Actual behavior
The code throws an error.
Version
@swc/core 1.2.224, @swc/helpers 0.4.3
Additional context
No response