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

Dynamic Imports: import() must produce a SyntaxError #5270

Closed
rwaldron opened this issue Jun 5, 2018 · 6 comments
Closed

Dynamic Imports: import() must produce a SyntaxError #5270

rwaldron opened this issue Jun 5, 2018 · 6 comments

Comments

@rwaldron
Copy link

rwaldron commented Jun 5, 2018

While writing Test262 tests for dynamic import, I discovered the following incompatibility:

import()

Should produce a SyntaxError, given the grammar:

import ( AssignmentExpression )

Does not expand to import()

@fatcerberus
Copy link
Contributor

This already appears to produce a SyntaxError.

// test.js
import();
print("This can't happen.");

Output

D:\temp>spherun test.js
miniSphere X.X.X JS game engine (x64)
a lightweight JavaScript-powered game engine
(c) 2015-2018 Fat Cerberus

GAME CRASH: error at '@/test.js':2:8
SyntaxError: Syntax error
   2 import();

@rwaldron
Copy link
Author

rwaldron commented Jun 6, 2018

Ok, I've narrowed it down further... this only happens when the -ESModule flag is present. Incidentally, that flag appears to cause other strangeness:

rwaldron in ~/js
$ echo "import();print('must not be reached');" >> dynamic-import.js
rwaldron in ~/js
$ cat dynamic-import.js
import();print('must not be reached');
rwaldron in ~/js
$ ch dynamic-import.js
SyntaxError: Syntax error
  at code (dynamic-import.js:1:7)
rwaldron in ~/js
$ ch -ESModule dynamic-import.js
rwaldron in ~/js

There's no output at all for ch -ESModule dynamic-import.js, which makes me think I might be doing something wrong here. I will close this for now and re-open if necessary.

@rwaldron rwaldron closed this as completed Jun 6, 2018
@fatcerberus
Copy link
Contributor

fatcerberus commented Jun 6, 2018

I see no change if I rename my test file to test.mjs (miniSphere will run it as a module), I still get a SyntaxError without reaching the print().

I think I see the problem though: ch -ESModule filename.js doesn't run the file as a module, it just enables module support while still loading the script as traditional code (I hit this pitfall myself in the past). You instead need to write a shim that does:

WScript.LoadScriptFile('module.mjs', 'module');  // execute root module

And then run the shim.

No idea why you get no output in that case though, that's kind of weird.

@rwaldron
Copy link
Author

rwaldron commented Jun 6, 2018

Lol, I just came back to post this same update. Thanks for preemptively confirming :D

@rhuanjl
Copy link
Collaborator

rhuanjl commented Jun 6, 2018

-ESModule isn't a flag that does anything in master.

-ESDynamicImport is the flag to enable import() - without it any dynamic import is a syntax error

@fatcerberus
Copy link
Contributor

@rhuanjl Right, this issue was specifically about import() (with no specifier) incorrectly NOT being a syntax error; I’ve already verified that it is.

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

3 participants