@@ -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