Skip to content

Instantly share code, notes, and snippets.

@zenparsing
Last active January 7, 2016 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zenparsing/a74c69130c74332f7f6f to your computer and use it in GitHub Desktop.
Save zenparsing/a74c69130c74332f7f6f to your computer and use it in GitHub Desktop.
Issues with Automatic Module Detection
// OK if a script, but not ok if a "module".
// We'll have to remember this error and location as we parse.
with (x) {}
// The export declaration means that we need to throw a parse error
// using the location of the "with" statement.
export const A = "a";
// V8 doesn't remember strict mode errors like this, and the V8 team has
// previously objected to features which seem to require it.
// Am I a module or script?
// This could be either. To assume it's a script violates the ECMAScript specification.
@zenparsing
Copy link
Author

Well, it's not really a "violation" to assume something is a module or script, that's too strong.

@zenparsing
Copy link
Author

It's just that the language allows "modules" to not have import and export statements, and so should Node.

@bmeck
Copy link

bmeck commented Jan 7, 2016

  1. we can always double parse to get this.
    a. if v8 doesn't want to record a single Error object (they won't ever need 2) thats pretty lame, but I bet it is less effort than porting all of npm's stuff
    b. workable already so non-blocker
  2. node, the host env, not ecma262 will assume if it can be parsed as a script, it is a script, else check if it is a module

should v8 provide a single call that will let us check both of these without a double parse, all the nicer.

Also all these "goals" in the grammar are just for parsing, not for execution so we aren't going to cause side effects.

@bmeck
Copy link

bmeck commented Jan 7, 2016

@zenparsing, would require some opt in to force things to be a module, could use a pragma. also spec people should stop using pragmas and goals.

is there any effect really w/o import/export except making it strict mode?

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