Code Monkey home page Code Monkey logo

Comments (6)

nolanlawson avatar nolanlawson commented on September 27, 2024 1

@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 } to export 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.

git2gus avatar git2gus commented on September 27, 2024

This issue has been linked to a new work item: W-15135580

from lwc.

nolanlawson avatar nolanlawson commented on September 27, 2024

I think to solve this, a bare-minimum solution would be:

  1. Detect usage of export { Foo as default }
  2. 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.

nolanlawson avatar nolanlawson commented on September 27, 2024

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.

wjhsf avatar wjhsf commented on September 27, 2024

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.

HermanBide avatar HermanBide commented on September 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.