@@ -1069,8 +1069,8 @@ _isImports_, _conditions_)
1069
1069
> 10. If _url_ ends in _".js"_, then
1070
1070
> 1. If _packageType_ is not **null**, then
1071
1071
> 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
1074
1074
> 1. Return _"module"_.
1075
1075
> 3. Return _"commonjs"_.
1076
1076
> 11. If _url_ does not have any extension, then
@@ -1107,6 +1107,17 @@ _isImports_, _conditions_)
1107
1107
> 1. Throw an _Invalid Package Configuration_ error.
1108
1108
> 4. Return the parsed JSON source of the file at _pjsonURL_.
1109
1109
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
+
1110
1121
### Customizing ESM specifier resolution algorithm
1111
1122
1112
1123
[Module customization hooks][] provide a mechanism for customizing the ESM
0 commit comments