-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Labels
Description
The class is missing the [Symbol.metadata] field if the class itself is not decorated.
Test code:
// Shim the "Symbol.metadata" symbol
Symbol.metadata ??= Symbol('Symbol.metadata');
const track = (_, context) => {
(context.metadata.names ||= []).push(context.name);
};
class Foo {
@track foo = 1;
@track bar = 2;
}
// Should print ["foo", "bar"], but prints undefined
console.log('Foo', Foo[Symbol.metadata]?.names);
const fix = (_, context) => {}
@fix
class Bar {
@track foo = 1;
@track bar = 2;
}
// Prints ["foo", "bar"]
console.log('Bar', Bar[Symbol.metadata]?.names);esbuild output:
Foo undefined
Bar [ 'foo', 'bar' ]
tsc output:
Foo [ 'foo', 'bar' ]
Bar [ 'foo', 'bar' ]
The @fix decorator fixes the code because esbuild stores metadata in the _init2 array and adds it to the Class[Symbol.metadata] field only when the class is replaced:
Bar = __decorateElement(_init2, 0, "Bar", _Bar_decorators, Bar);jkonowitch, belgattitude and story75