mirror of
https://github.com/jlengrand/open-wc.git
synced 2026-03-10 15:51:31 +00:00
fix(dev-server-hmr): handle multiple assigned variables
This commit is contained in:
5
.changeset/silver-horses-divide.md
Normal file
5
.changeset/silver-horses-divide.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@open-wc/dev-server-hmr': patch
|
||||
---
|
||||
|
||||
handle multiple assigned variables
|
||||
@@ -169,7 +169,11 @@ function babelPluginWcHmr() {
|
||||
}
|
||||
|
||||
if (decoratedCustomElement.isIdentifier()) {
|
||||
maybeInjectRegister(callExpr.parentPath, decoratedCustomElement.node.name);
|
||||
let assignExpr = callExpr.parentPath;
|
||||
while (assignExpr && assignExpr.isAssignmentExpression()) {
|
||||
assignExpr = assignExpr.parentPath;
|
||||
}
|
||||
maybeInjectRegister(assignExpr, decoratedCustomElement.node.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,4 +112,21 @@ __$wc_hmr$__.register(import.meta.url, Foo);
|
||||
|
||||
Foo = __decorate([defineElement('x-foo')], Foo);`);
|
||||
});
|
||||
|
||||
it('compiled decorator with a double assigned variable', () => {
|
||||
const code = `
|
||||
function __decorate() {}
|
||||
let Foo = Foo_1 = class extends HTMLElement {};
|
||||
Foo = Foo_1 = __decorate([customElement('x-foo')], Foo);`;
|
||||
const result = transform(code, { decorators: [{ name: 'customElement' }] });
|
||||
|
||||
expect(result).to.equal(`${banner}
|
||||
function __decorate() {}
|
||||
|
||||
let Foo = Foo_1 = class extends HTMLElement {};
|
||||
|
||||
__$wc_hmr$__.register(import.meta.url, Foo);
|
||||
|
||||
Foo = Foo_1 = __decorate([customElement('x-foo')], Foo);`);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user