-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Closed
Labels
Spec: DecoratorsoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issue
Description
Current Behavior
This class extend from HTMLImport run perfectly (it's very simple):
class Counter extends HTMLElement {
constructor() {
super();
}
}
window.customElements.define('my-counter', Counter);
const counter = new Counter();Now, I use @littledan example decorator:
// Define the class as a custom element with the given tag name
function defineElement(tagName) {
// In order for a decorator to take an argument, it takes that argument
// in the outer function and returns a different function that's called
// when actually decorating the class (manual currying).
return function(classDescriptor) {
let { kind, elements } = classDescriptor;
console.assert(kind == "class");
return {
kind,
elements,
// This callback is called once the class is otherwise fully defined
finisher(klass) {
window.customElements.define(tagName, klass);
}
};
};
}
@defineElement('my-counter')
class Counter extends HTMLElement {
constructor() {
super();
}
}
const counter = new Counter();When that code is transformed with the new Decorator plugin (thank @nicolo-ribaudo) and run it on a browser, this error is displayed:
Uncaught TypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
at new Counter (<anonymous>:100:73)
at <anonymous>:116:15
Expected behavior/code
The decoration don't change the Custom Element behavior and must be run without problems.
Babel Configuration (.babelrc.js)
const presets = [ "@babel/preset-env" ];
const plugins = [
[ "@babel/plugin-proposal-decorators", { "legacy": false, decoratorsBeforeExport: false } ]
];
module.exports = { presets, plugins };Environment
- Babel version(s): 7.1.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Spec: DecoratorsoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issue