detecting JS language mode for tools

Mark S. Miller erights at
Fri Jan 24 12:22:48 PST 2014

Assuming the current system for a moment, and discussing only conventions:

It is true that a "use strict" at the top of every *.js file does have
the virtue of making it clear, both to tools and humans, that the
remainder is strict code, even in one doesn't know if the file is to be
loaded as a module or a script. Historically, we've recommended
against a bare "use strict" at the top of script files
in order to avoid the concatenation hazard. Instead, we recommend that
script files have an outer strict IIFE. This still seems sensible when
there's genuine ambiguity about whether it is a module or a script.

OTOH, if the author knows it is a module and simply wants to
disambiguate to tools that it is strict, then the author knows there's
no concatenation hazard and a bare "use strict" at the top would be
fine. And, of course, if there are any export or import statements in
there, then it cannot be a script, and it cannot be contained in an IIFE.

Btw, the conventional name for the opposite of strict is "sloppy"
rather than "loose".

On Fri, Jan 24, 2014 at 8:48 AM, John Lenz <concavelenz at> wrote:

> For static language parsers there seems to be a bit of a dilemma with ES6
> modules.  I would appreciate a correct or hint.
> Here is my understanding:
>   - standard scripts as we know them today will parse in the browser as
> "loose" code
>   - scripts with the standard "use strict" will parse as "strict" with
> access to all ES6 goodness
>   - scripts loaded as modules will parse as "strict" even without the "use
> strict" annotation.
> Is this true?  If so, it seems like a tooling hazard and "use strict" on
> modules should at least be the encouraged convention.
> _______________________________________________
> es-discuss mailing list
> es-discuss at

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

More information about the es-discuss mailing list