Skip to content

Commit f5241e2

Browse files
GeoffreyBoothmarco-ippolito
authored andcommittedMay 3, 2024
doc: add spec for contains module syntax
PR-URL: #52059 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com>
1 parent caec996 commit f5241e2

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed
 

‎doc/api/esm.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -1069,8 +1069,8 @@ _isImports_, _conditions_)
10691069
> 10. If _url_ ends in _".js"_, then
10701070
> 1. If _packageType_ is not **null**, then
10711071
> 1. Return _packageType_.
1072-
> 2. If `--experimental-detect-module` is enabled and the source of
1073-
> module contains static import or export syntax, then
1072+
> 2. If `--experimental-detect-module` is enabled and the result of
1073+
> **DETECT\_MODULE\_SYNTAX**(_source_) is true, then
10741074
> 1. Return _"module"_.
10751075
> 3. Return _"commonjs"_.
10761076
> 11. If _url_ does not have any extension, then
@@ -1107,6 +1107,17 @@ _isImports_, _conditions_)
11071107
> 1. Throw an _Invalid Package Configuration_ error.
11081108
> 4. Return the parsed JSON source of the file at _pjsonURL_.
11091109
1110+
**DETECT\_MODULE\_SYNTAX**(_source_)
1111+
1112+
> 1. Parse _source_ as an ECMAScript module.
1113+
> 2. If the parse is successful, then
1114+
> 1. If _source_ contains top-level `await`, static `import` or `export`
1115+
> statements, or `import.meta`, return **true**.
1116+
> 2. If _source_ contains a top-level lexical declaration (`const`, `let`,
1117+
> or `class`) of any of the CommonJS wrapper variables (`require`,
1118+
> `exports`, `module`, `__filename`, or `__dirname`) then return **true**.
1119+
> 3. Else return **false**.
1120+
11101121
### Customizing ESM specifier resolution algorithm
11111122
11121123
[Module customization hooks][] provide a mechanism for customizing the ESM

0 commit comments

Comments
 (0)
Please sign in to comment.