-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useDefineForClassFields
not respected in decorators for es2022
#2220
Comments
useDefineForClassFields
not respected for es2022
useDefineForClassFields
not respected in decorators for es2022
workaround for // web-dev-server.config.js
export default {
plugins: [
esbuildPlugin({ ts: true, target: 'es2020' }),
]
} |
I couldn't reproduce this in my local test, here's what I did: > cat a.ts
import { LitElement, html } from 'lit';
import { customElement, query } from 'lit/decorators.js';
@customElement('pfe-avatar')
export class PfeAvatar extends LitElement {
@query('canvas') private canvas?: HTMLCanvasElement;
render() {
return html`
<canvas part="canvas"></canvas>
`;
}
}
> cat tsconfig.json
{
"compilerOptions": {
"module": "es2022",
"target": "es2022",
"useDefineForClassFields": false,
"experimentalDecorators": true,
"declaration": true,
"moduleResolution": "Node",
"preserveValueImports": true,
"strict": true
}
}
> esbuild --version
0.14.38
> esbuild a.ts
...
export let PfeAvatar = class extends LitElement {
render() {
return html`
<canvas part="canvas"></canvas>
`;
}
};
... As you can see, there's no |
I also had trouble reproducing I'll investigate whether this is a web-dev-server issue |
this is actually the same issue like #2219 |
I have the same issue. After setting the |
The only way I can reproduce this is to delete I'm guessing your problem is that somehow the Regardless of where the problem is, a workaround is using - @query('canvas') private canvas?: HTMLCanvasElement;
+ @query('canvas') declare private canvas?: HTMLCanvasElement; That tells TypeScript (and therefore esbuild) that the class field initializer should not be emitted. |
I'm closing this issue because I believe esbuild is behaving correctly here, this issue does not have a reproducible test case, and no follow-up reply was posted. |
When
useDefineForClassFields
is set, typescript-decorated fields should not be output as ecmascript fields, as this will most likely break the resulting code. For example, lit decorators requireuseDefineForClassFields
to be false, and rely on typescript compiling them to helper calls instead of ecmascript class fieldstsconfig.json
Input:
Output:
Expected:
Diff:
Compare to tsc output:
In other words, I expect esbuild to not add the
canvas;
javascript class fieldThis also occurs with
"target": "es2020"
The text was updated successfully, but these errors were encountered: