File tree 4 files changed +24
-0
lines changed
test/unit/module-create-require
4 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -1082,6 +1082,20 @@ export default async function analyze(
1082
1082
if ( returned ) setKnownBinding ( fnName . name , { value : BOUND_REQUIRE } ) ;
1083
1083
}
1084
1084
}
1085
+ // Support module.createRequire
1086
+ if (
1087
+ node . type === 'CallExpression' &&
1088
+ node . callee . type === 'MemberExpression' &&
1089
+ node . callee . object . type === 'Identifier' &&
1090
+ node . callee . object . name === 'module' &&
1091
+ node . callee . property . type === 'Identifier' &&
1092
+ node . callee . property . name === 'createRequire'
1093
+ ) {
1094
+ if ( parent . type === 'VariableDeclarator' ) {
1095
+ const requireName = parent . id . name ;
1096
+ setKnownBinding ( requireName , { value : BOUND_REQUIRE } ) ;
1097
+ }
1098
+ }
1085
1099
} ,
1086
1100
async leave ( _node , _parent ) {
1087
1101
const node : Node = _node as any ;
Original file line number Diff line number Diff line change
1
+ import * as module from 'node:module' ;
2
+
3
+ const req = module . createRequire ( import . meta. url ) ;
4
+ const lib = req ( './lib.node' ) ;
Original file line number Diff line number Diff line change
1
+ // Native module for testing
Original file line number Diff line number Diff line change
1
+ [
2
+ "package.json" ,
3
+ "test/unit/module-create-require/input.js" ,
4
+ "test/unit/module-create-require/lib.node"
5
+ ]
You can’t perform that action at this time.
0 commit comments