Skip to content

Commit

Permalink
doc: add spec for contains module syntax
Browse files Browse the repository at this point in the history
PR-URL: #52059
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Guy Bedford <[email protected]>
  • Loading branch information
GeoffreyBooth authored and marco-ippolito committed May 3, 2024
1 parent caec996 commit f5241e2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -1069,8 +1069,8 @@ _isImports_, _conditions_)
> 10. If _url_ ends in _".js"_, then
> 1. If _packageType_ is not **null**, then
> 1. Return _packageType_.
> 2. If `--experimental-detect-module` is enabled and the source of
> module contains static import or export syntax, then
> 2. If `--experimental-detect-module` is enabled and the result of
> **DETECT\_MODULE\_SYNTAX**(_source_) is true, then
> 1. Return _"module"_.
> 3. Return _"commonjs"_.
> 11. If _url_ does not have any extension, then
Expand Down Expand Up @@ -1107,6 +1107,17 @@ _isImports_, _conditions_)
> 1. Throw an _Invalid Package Configuration_ error.
> 4. Return the parsed JSON source of the file at _pjsonURL_.
**DETECT\_MODULE\_SYNTAX**(_source_)
> 1. Parse _source_ as an ECMAScript module.
> 2. If the parse is successful, then
> 1. If _source_ contains top-level `await`, static `import` or `export`
> statements, or `import.meta`, return **true**.
> 2. If _source_ contains a top-level lexical declaration (`const`, `let`,
> or `class`) of any of the CommonJS wrapper variables (`require`,
> `exports`, `module`, `__filename`, or `__dirname`) then return **true**.
> 3. Else return **false**.
### Customizing ESM specifier resolution algorithm
[Module customization hooks][] provide a mechanism for customizing the ESM
Expand Down

0 comments on commit f5241e2

Please sign in to comment.