Description
When using @swc/core with decoratorVersion: '2023-11' to lower TC39 standard (stage 3) decorators, static field initializers that reference super (e.g. static override styles = [...super.styles, extra]) produce code that calls _get() and _get_prototype_of() helpers — but those helpers are not inlined into the output and not imported from @swc/helpers. This causes a ReferenceError at runtime.
This issue was previously reported as #11780 and that issue is now closed, but the bug is still present in @swc/core@1.15.26.
Reproduction
import { LitElement, css } from 'lit';
import { customElement } from 'lit/decorators.js';
const myStyles = css`div { color: red }`;
@customElement('test-derived')
class TestDerived extends LitElement {
static override styles = [...super.styles, myStyles];
}
Transform config:
swc.transformSync(code, {
filename: 'test.ts',
jsc: {
parser: { syntax: 'typescript', decorators: true, decoratorsBeforeExport: true },
transform: { decoratorVersion: '2023-11' },
target: 'es2022',
},
});
Actual output (relevant excerpt)
function _identity(x) { return x; }
// _get and _get_prototype_of are NEVER defined or imported
let _dec, _initClass, _LitElement, _fieldValue;
_dec = customElement('test-derived'), _LitElement = LitElement;
let _TestDerived, _TestDerived_member;
new class extends _identity {
constructor(){
super(_TestDerived), _initClass(), _TestDerived_member = _TestDerived;
}
static [class TestDerived extends _LitElement {
static {
({ c: [_TestDerived, _initClass] } = _apply_decs_2311(this, [_dec], [], 0, void 0, _LitElement));
}
static {
_fieldValue = function() {
return [
..._get(_get_prototype_of(_TestDerived), "styles", this),
// ^^^^ ReferenceError: _get is not defined
myStyles
];
};
}
}];
styles = _fieldValue.call(this);
}();
Expected output
The _get and _get_prototype_of helpers should either be:
- Inlined alongside the other helpers (
_identity, _apply_decs_2311, etc.), or
- Imported from
@swc/helpers
Runtime symptom
When this pattern appears in a class that also has other static fields (e.g. Lit's static shadowRootOptions = { mode: 'open' }), the ReferenceError thrown during class initialization prevents all static fields from being set. In Lit components, this surfaces as:
Uncaught TypeError: Failed to execute 'attachShadow' on 'Element':
Failed to read the 'mode' property from 'ShadowRootInit': Required member is undefined.
Environment
Description
When using
@swc/corewithdecoratorVersion: '2023-11'to lower TC39 standard (stage 3) decorators, static field initializers that referencesuper(e.g.static override styles = [...super.styles, extra]) produce code that calls_get()and_get_prototype_of()helpers — but those helpers are not inlined into the output and not imported from@swc/helpers. This causes aReferenceErrorat runtime.This issue was previously reported as #11780 and that issue is now closed, but the bug is still present in
@swc/core@1.15.26.Reproduction
Transform config:
Actual output (relevant excerpt)
Expected output
The
_getand_get_prototype_ofhelpers should either be:_identity,_apply_decs_2311, etc.), or@swc/helpersRuntime symptom
When this pattern appears in a class that also has other static fields (e.g. Lit's
static shadowRootOptions = { mode: 'open' }), theReferenceErrorthrown during class initialization prevents all static fields from being set. In Lit components, this surfaces as:Environment
@swc/core: 1.15.26