-
Notifications
You must be signed in to change notification settings - Fork 382
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
Component compiles incorrectly for export { ... as default }
ESM syntax
#4020
Comments
This issue has been linked to a new work item: W-15135580 |
I think to solve this, a bare-minimum solution would be:
(The solution would likely be in I think other, exotic patterns are not strictly necessary to support: // const Foo
const Foo = class extends LightningElement {}
export { Foo as default } // Foo imported from elsewhere
import { Foo } from './elsewhere.js'
export { Foo as default } // really zany
const Foo = (() => { return true && class extends LightningElement {} })()
export { Foo as default } |
export { ... as default }
ESM syntaxexport { ... as default }
ESM syntax
We can probably also support some other simple patterns: class Foo extends LightningElement {}
export default Foo Maybe even: const Foo = class extends LightningElement {}
export default Foo |
What are the behavioral differences (in ESM land, outside the LWC context) between |
@wjhsf We can't always safely change the ordering, because it matters in certain cases. For example: export default Foo
class Foo {} ^ This is a syntax error (
Maybe, but I wonder if it's better to just leave things alone, since otherwise we could cause other unforeseen problems. |
Hi @nolanlawson i would like to contribute and help fix more bugs please let me know where i can be helpful. |
Description
Consider this component:
Per ES module syntax, it is equivalent to this component:
However, the second one correctly renders, whereas the first does not. (Repro: 08c93cd .) The component appears to not be treated as a
LightningElement
per the@lwc/compiler
– it is simply treated as a plain JavaScript (non-LWC) module.Steps to Reproduce
08c93cd
Expected Results
is equivalent to
Actual Results
Nothing is rendered, and the component is not registered at runtime as a proper LightningElement.
Version
This issue exists in
master
today, as well as LWC v5.0.9 (Spring '24) and v3.0.4 (Winter '24). It even repros in LWC v2.11.8 (Summer '22). So this is a longstanding issue.Possible Solution
Use the
export default class ...
syntax instead.The text was updated successfully, but these errors were encountered: