@@ -1085,8 +1085,8 @@ _isImports_, _conditions_)
1085
1085
> 10. If _url_ ends in _".js"_, then
1086
1086
> 1. If _packageType_ is not **null**, then
1087
1087
> 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
1090
1090
> 1. Return _"module"_.
1091
1091
> 3. Return _"commonjs"_.
1092
1092
> 11. If _url_ does not have any extension, then
@@ -1123,6 +1123,17 @@ _isImports_, _conditions_)
1123
1123
> 1. Throw an _Invalid Package Configuration_ error.
1124
1124
> 4. Return the parsed JSON source of the file at _pjsonURL_.
1125
1125
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
+
1126
1137
### Customizing ESM specifier resolution algorithm
1127
1138
1128
1139
[Module customization hooks][] provide a mechanism for customizing the ESM
0 commit comments