Comments (6)
@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 (Cannot access 'Foo' before initialization
). (Some minifiers like Terser and SWC will "helpfully" fix it for you though. 🙃)
In particular, when we compile could we just change
export { Foo as default }
toexport default class Foo {}
or would that cause side effects?
Maybe, but I wonder if it's better to just leave things alone, since otherwise we could cause other unforeseen problems.
from lwc.
This issue has been linked to a new work item: W-15135580
from lwc.
I think to solve this, a bare-minimum solution would be:
- Detect usage of
export { Foo as default }
- Check the same JS module to see if there is a
class Foo extends LightningElement {}
(The solution would likely be in @lwc/babel-plugin-component
.)
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 }
from lwc.
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
from lwc.
What are the behavioral differences (in ESM land, outside the LWC context) between export default const Foo = ...
vs export { default as Foo }
? In particular, when we compile could we just change export { Foo as default }
to export default class Foo {}
or would that cause side effects?
from lwc.
Hi @nolanlawson i would like to contribute and help fix more bugs please let me know where i can be helpful.
from lwc.
Related Issues (20)
- Remove remaining vestiges of `jest` types
- `lwc:spread` applies props rather than attributes HOT 2
- Migrate from yarn to pnpm HOT 2
- Remove misleading warning when using `@wire` on a getter or a setter HOT 1
- Consider removing `setHooks`
- Light DOM slot forwarding fails to render for duplicated slot names HOT 1
- `@wire` on getter/setter ignores implementation
- Synthetic shadow + duplicate slots + slot forwarding: `Failed to execute 'removeChild' on 'Node'`
- Static-optimize `on` event listener object HOT 2
- lwc:external Expressions inside lit-element render() is not rendered. HOT 1
- Prettier should not mutate `expected.js` files
- Esbuild plugin to build LWC apps HOT 2
- Optimize locally-scoped event listeners HOT 1
- Make duplicate slots in light DOM behave like native shadow DOM slots, or disallow duplicates entirely HOT 2
- Ignore hydration mismatches during SSR rendering as well as `connectedCallback` HOT 3
- Enhance performance timings with the DevTools extensibility API
- Add ability to hide date format and help text element shown inline beneath the lightning-input field HOT 2
- Cater for the omission of if:false when replacing if:true with lwc:true HOT 1
- Add mutation triggers to DevTools performance timings HOT 2
- Custom Events support in `lwc:spread` throws unknown public property error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lwc.