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

Add support for modules #98

Open
JeanJPNM opened this issue Oct 11, 2022 · 3 comments
Open

Add support for modules #98

JeanJPNM opened this issue Oct 11, 2022 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@JeanJPNM
Copy link
Collaborator

Because fery few other compilers did that. Also, this requires changes on the sourcemapping format and the name handling and resolution.

@JeanJPNM JeanJPNM added the enhancement New feature or request label Oct 16, 2022
@JeanJPNM JeanJPNM added the help wanted Extra attention is needed label Feb 20, 2023
@Sharlottes
Copy link

Because fery few other compilers did that.

yes, so we need to make a kinds of "macro" like C's #include or "bundler" like webpack

@hsaturn
Copy link

hsaturn commented Mar 29, 2024

I (very) often need this feature with mlogjs !

Why not just include a file (at the parser level) ?
import 'module.js';

This would just read the concatenate module.js to the rest of the file (the compiler should even not know that a module was imported).

(I'm not an expert at all in javascript)

@JeanJPNM
Copy link
Collaborator Author

JeanJPNM commented Apr 1, 2024

Why not just include a file (at the parser level) ?

Because mlogjs doesn't actually do the parsing by itself, it uses babel to parse the code and then traverses the AST (Abstract Syntax Tree) that babel generated.

The are a few things that are in the way of implementing modules:

  • Implementing a module resolution algorithm (needs the path of the input file and needs to give the compiler access to the file system, instead of just giving it to the CLI)
  • Implementing import views (see this stackoverflow answer)
  • Updating the sourcemaps feature to handle multiple files
  • Make all of it compatible with the web environment so that it works on the online editor

And while module support is within my priorities, I find it more important to implement the optimizer first, as that will eliminate many bugs in the current implementation and possibly make handling modules more straightforward in some aspects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants