Skip to content
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

[Discussion] Consider generating sub-types into separate files as well #18

Open
kevinresol opened this issue Mar 31, 2020 · 3 comments
Open

Comments

@kevinresol
Copy link
Collaborator

// Main.hx
import Foo;
class Main {
  static function main() {
    trace(Bar);
    dynamicImport(Foo -> trace(Foo);
  }
}

// Foo.hx
class Foo() {}
class Bar() {}

The above code will not enjoy code splitting because of the generated static import for sub-type Bar:

import {Bar} from './Foo';

Could this be improved by generating sub-types into separate files too? Are there any implications?

@benmerckx
Copy link
Owner

One of my use cases for genes is (eventually) publishing some generated js code. To have the best interop (and ease documentation) having the same structure is quite useful.

Your scenario I think is actually more of a limitation of javascript tree shaking. If the bundler was "smarter" it should be able to split these (but none do, I tested some similar things).

But, the way things currently work, it shouldn't be too hard to add a flag to force every type to get their own module, which would allow your use case too.

@benmerckx
Copy link
Owner

Another option is to produce a warning if you're using dynamicImport but a type from the same module is imported outside of the callback.

@kevinresol
Copy link
Collaborator Author

Information like that would be useful too 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants