You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The decorators code in production build with optimization works as it is in serve mode.
😯 Current Behavior
The decorators code in production build runs into the following error:
Uncaught TypeError: Function expected
at s (index.61afe2c3.js:1:121)
at __esDecorate (index.61afe2c3.js:1:831)
at index.ts:11:1
at index.61afe2c3.js:1:1354
at index.ts:11:7
💁 Possible Solution
It's possibly a bug of the optimizer. It seems the optimizer will omit class private static field initialization, leaving it as a simple arrow function IIFE, and this context in arrow function will be scoped to wnidow.
// part of code in parcel serveconstCustomElement=(tag)=>{return(ctor,context)=>{context.addInitializer(function(){customElements.define(tag,this);});returnctor;};};letA=(()=>{let_classDecorators=[CustomElement("component-a")];let_classDescriptor;let_classExtraInitializers=[];let_classThis;varA=classextendsHTMLElement{static #_ =(()=>{// ^^^^^^^^^ seems to be removed in optimized code__esDecorate(null,_classDescriptor={value: this},_classDecorators,{kind: "class",name: this.name},null,_classExtraInitializers);A=_classThis=_classDescriptor.value;__runInitializers(_classThis,_classExtraInitializers);})();constructor(){super();this.innerHTML="Component A is working";}};returnA=_classThis;})();console.log(newA().tagName);
// part of code in parcel buildconstCustomElement=e=>(t,n)=>(n.addInitializer((function(){customElements.define(e,this)})),t);letA=(()=>{lete,t,n=[CustomElement("component-a")],i=[];HTMLElement,// ^^^^^^^^^^^ Is it "class extends HTMLElement"? Even the entire class body has been omitted...(()=>{__esDecorate(null,e={value: this// ^^^^ "this" is the window object, leading to the error},n,{kind: "class",name: this.name},null,i),t=e.value,__runInitializers(t,i)})();returnt})();console.log((newA).tagName);
🔦 Context
I'm trying to use the ECMA Decorators introduced in TypeScript 5.0 with parcel. It seems parcel does not support new decorators in TypeScript 5.0 currently, so I added @parcel/transformer-typescript-tsc for the decorator syntax without experimentalDecorators enabled.
It works well with parcel serve, but the code in production build crashes when optimization is enabled (by default). I tried to disable optimization with --no-optimize, and the code in production build worked well, but publishing build without optimization is discouraged.
🐛 bug report
The ECMA Decorators introduced in TypeScript 5.0 crashes in production build with optimization enabled.
🎛 Configuration (.babelrc, package.json, cli command)
Detailed configuration can be found in the minimum example to reproduce:
https://github.com/DarrenDanielDay/parcel-issue-typescript-5-decorators
🤔 Expected Behavior
The decorators code in production build with optimization works as it is in serve mode.
😯 Current Behavior
The decorators code in production build runs into the following error:
💁 Possible Solution
It's possibly a bug of the optimizer. It seems the optimizer will omit class private static field initialization, leaving it as a simple
arrow function IIFE
, andthis
context in arrow function will be scoped townidow
.🔦 Context
I'm trying to use the ECMA Decorators introduced in TypeScript 5.0 with parcel. It seems parcel does not support new decorators in TypeScript 5.0 currently, so I added
@parcel/transformer-typescript-tsc
for the decorator syntax withoutexperimentalDecorators
enabled.It works well with
parcel serve
, but the code in production build crashes when optimization is enabled (by default). I tried to disable optimization with--no-optimize
, and the code in production build worked well, but publishing build without optimization is discouraged.💻 Code Sample
https://github.com/DarrenDanielDay/parcel-issue-typescript-5-decorators
🌍 Your Environment
The text was updated successfully, but these errors were encountered: