treated as a module if ...

Allen Wirfs-Brock allen at
Mon Jul 6 19:08:11 UTC 2015

On Jul 6, 2015, at 7:32 AM, John Barton wrote:

> On Sun, Jul 5, 2015 at 8:46 AM, Domenic Denicola <d at> wrote:
> To be explicit: there is no way to look at a string of JavaScript text and tell whether it should be treated as a module or a script. In many instances the same string can be treated as both.
> The decision is made by the execution environment.
> I don't think Domenic meant that the standard explicitly states that the execution environment may choose the parse method.  Rather that the context of loading the code determines the parsing method.
> I believe that the current status is that the standard describes the two parsing methods but says nothing about when they will be applied. We do know that <script> tags always parse as Script.  Of course, modules imported by import statements are parsed as Module.   Sadly, as far as I know, there is no standard way to import a ES2015 root module. The discussions on modules imply that there will be an explicit "loader" import function that will parse as Module and there has been discussion of <script type="module"> and <module> but these proposals are moving slowly if at all.

In other words, every tools (including command line based execution engines) that parse ES2015 source code really needs  to make provisions for the user to identify how each source file will be parsed. It might be with a command line flag or by interpreting extensions, or some other way.

For example, traceur ( ) defaults to parsing source files as modules but provides a command line switch for identify file that need to be parsed as scripts:

traceur --script main.js mod1.js mod2.js

apparently will parse main.js as a script and mod1.js and mod2.js as modules.

It would be nice for a common command line convention to emerge that all js source level tools followed.  How about tool developer put your head together and decide on something.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list