ariya/esprima — pull request #290 by jeffmo (2014-10-20 21:17:11+00:00)
Title: Add options.isModule

Currently esprima will parse module syntax (massive thanks to https://github.com/ariya/esprima/pull/287 !!), but it doesn't differentiate between module code and non-module code.

To remain spec-compliant, differentiating these two contexts is important for two reasons:
1) Module code is implicitly strict mode
2) Module code allows for `ExportDeclaration` and `ImportDeclaration` at the top-level, whereas non-modules do not

This change adds an `isModule` flag to the options object (passed to `esprima.parse()`) to indicate whether the source is intended to represent a module vs a non-module (aka "script"). The option defaults to `false` to remain backward compatible (and since 99.9% of JS code in the world is a non-module, so this is a pretty sane default).

cc @caridy

https://code.google.com/p/esprima/issues/detail?id=598