tc39/proposal-modules-pragma

Name: proposal-modules-pragma

Owner: Ecma TC39

Description: Proposal to recognize a `"use module";` pragma

Created: 2017-05-15 21:31:15.0

Updated: 2018-04-21 12:10:34.0

Pushed: 2017-05-29 08:42:15.0

Homepage: https://tc39.github.io/proposal-modules-pragma/

Size: 21

Language: HTML

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

ECMAScript proposal: "use module";

Status

This proposal is in stage 1 of the TC39 process.

Motivation

Since the Script and Module syntaxes have some overlap (in particular, most modules with no import or export declarations are valid scripts), there are situations where either a host environment or simply a human reader may not be able to infer whether a piece of code is intended to be a script vs a module.

Some host environments may offer out-of-band mechanisms for specifying the mode, such as HTML attributes (<script type=module>), configuration parameters ("module": "main.js"), command-line switches (node -m), or file extensions (.mjs). However, an in-band pragma for enforcing the mode can be useful for a number of reasons:

Finally, the fact that this is a pragma means that ecosystems where there is no formal or conceptual ambiguity – in particular, ecosystems that author entirely using modules – do not need to pollute their source code.

Alternatives

Today, programmers can use a programming pattern to enforce that a file is a module:

rt {};

This syntax has no effect except to force a parsing error if a host environment attempts to parse it as a script.

This is suboptimal for readability, since it does not clearly convey what its intended effect is. And it's also not applicable to the problem of enforcing that a source file is intended to be parsed as a script.

Specification

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.