Skip to content

WIP: Support .mjs #5026

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

Closed
wants to merge 3 commits into from
Closed

Conversation

GeoffreyBooth
Copy link
Collaborator

Fixes #5018, providing a way for the command-line compiler to output .mjs files. The method implemented in this PR simply looks at the filename of the source CoffeeScript file(s), and if the source has an extension of .mcoffee or .litmcoffee (or .mcoffee.md) it is saved with an .mjs extension.

This PR also finally removes the --join CLI option, which was deprecated back in version 1.8.0 in 2014.


TODO: Need to figure out how to test this, and support ES module tests in general. Using the Node 10 nightly as of 2018-04-01, ES modules still aren’t yet supported except behind the --experimental-modules flag, though Node 10 final shouldn’t require the flag. Even aside from that, I don’t see how to get Node to support ES modules when parsing a string, e.g.:

✦ node -v
v10.0.0-nightly2018033128b622cb08

✦ src='import path from "path"; console.log(path.sep);'

✦ node --experimental-modules --eval $src
[eval]:1
import path from "path"; console.log(path.sep);
       ^^^^

SyntaxError: Unexpected identifier
    at new Script (vm.js:53:7)
    at createScript (vm.js:181:10)
    at Object.runInThisContext (vm.js:229:10)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (internal/modules/cjs/loader.js:678:30)
    at evalScript (internal/bootstrap/node.js:539:27)
    at startup (internal/bootstrap/node.js:201:9)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)

✦ echo $src > test.mjs

✦ node --experimental-modules test.mjs
(node:74878) ExperimentalWarning: The ESM module loader is experimental.
/

The way our tests currently work, CoffeeScript compiles the test code into a string and asks Node to eval the string. This doesn’t look like it’ll work for an import statement, though, since apparently the only way to enable support for import statements in Node is to explicitly load an .mjs file. So if I wanted to get the tests to work today, it appears I would need to write the output JS string to disk as an .mjs file, then spawn Node to evaluate it.

@GeoffreyBooth
Copy link
Collaborator Author

Closing for now as the future of .mjs looks uncertain.

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

Successfully merging this pull request may close these issues.

1 participant