Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

zenparsing commented Jan 7, 2016

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

@zenparsing

This comment has been minimized.

Copy link
Owner Author

zenparsing commented Jan 7, 2016

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

@bmeck

This comment has been minimized.

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

This comment has been minimized.

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
You can’t perform that action at this time.