Skip to content

Commit f1949ac

Browse files
doc: add spec for contains module syntax
PR-URL: #52059 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Guy Bedford <[email protected]>
1 parent f9755f6 commit f1949ac

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

doc/api/esm.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,8 +1085,8 @@ _isImports_, _conditions_)
10851085
> 10. If _url_ ends in _".js"_, then
10861086
> 1. If _packageType_ is not **null**, then
10871087
> 1. Return _packageType_.
1088-
> 2. If `--experimental-detect-module` is enabled and the source of
1089-
> module contains static import or export syntax, then
1088+
> 2. If `--experimental-detect-module` is enabled and the result of
1089+
> **DETECT\_MODULE\_SYNTAX**(_source_) is true, then
10901090
> 1. Return _"module"_.
10911091
> 3. Return _"commonjs"_.
10921092
> 11. If _url_ does not have any extension, then
@@ -1123,6 +1123,17 @@ _isImports_, _conditions_)
11231123
> 1. Throw an _Invalid Package Configuration_ error.
11241124
> 4. Return the parsed JSON source of the file at _pjsonURL_.
11251125
1126+
**DETECT\_MODULE\_SYNTAX**(_source_)
1127+
1128+
> 1. Parse _source_ as an ECMAScript module.
1129+
> 2. If the parse is successful, then
1130+
> 1. If _source_ contains top-level `await`, static `import` or `export`
1131+
> statements, or `import.meta`, return **true**.
1132+
> 2. If _source_ contains a top-level lexical declaration (`const`, `let`,
1133+
> or `class`) of any of the CommonJS wrapper variables (`require`,
1134+
> `exports`, `module`, `__filename`, or `__dirname`) then return **true**.
1135+
> 3. Else return **false**.
1136+
11261137
### Customizing ESM specifier resolution algorithm
11271138
11281139
[Module customization hooks][] provide a mechanism for customizing the ESM

0 commit comments

Comments
 (0)