@@ -51,7 +51,7 @@ const {
5151 makeRequireFunction,
5252 normalizeReferrerURL,
5353 stripBOM,
54- stripShebangOrBOM ,
54+ loadNativeModule
5555} = require ( 'internal/modules/cjs/helpers' ) ;
5656const { getOptionValue } = require ( 'internal/options' ) ;
5757const enableSourceMaps = getOptionValue ( '--enable-source-maps' ) ;
@@ -961,9 +961,9 @@ function wrapSafe(filename, content) {
961961} ) ;
962962}
963963
964- let compiledWrapper ;
964+ let compiled ;
965965try {
966- compiledWrapper = compileFunction (
966+ compiled = compileFunction (
967967content ,
968968filename ,
9699690 ,
@@ -981,36 +981,39 @@ function wrapSafe(filename, content) {
981981]
982982) ;
983983} catch ( err ) {
984- enrichCJSError ( err ) ;
984+ if ( experimentalModules ) {
985+ enrichCJSError ( err ) ;
986+ }
985987throw err ;
986988}
987989
988990if ( experimentalModules ) {
989991const { callbackMap } = internalBinding ( 'module_wrap' ) ;
990- callbackMap . set ( compiledWrapper , {
992+ callbackMap . set ( compiled . cacheKey , {
991993importModuleDynamically : async ( specifier ) => {
992994const loader = await asyncESM . loaderPromise ;
993995return loader . import ( specifier , normalizeReferrerURL ( filename ) ) ;
994996}
995997} ) ;
996998}
997999
998- return compiledWrapper ;
1000+ return compiled . function ;
9991001}
10001002
10011003// Run the file contents in the correct scope or sandbox. Expose
10021004// the correct helper variables (require, module, exports) to
10031005// the file.
10041006// Returns exception, if any.
10051007Module . prototype . _compile = function ( content , filename ) {
1008+ let moduleURL ;
1009+ let redirects ;
10061010if ( manifest ) {
1007- const moduleURL = pathToFileURL ( filename ) ;
1011+ moduleURL = pathToFileURL ( filename ) ;
1012+ redirects = manifest . getRedirector ( moduleURL ) ;
10081013manifest . assertIntegrity ( moduleURL , content ) ;
10091014}
10101015
1011- // Strip after manifest integrity check
1012- content = stripShebangOrBOM ( content ) ;
1013-
1016+ maybeCacheSourceMap ( filename , content , this ) ;
10141017const compiledWrapper = wrapSafe ( filename , content ) ;
10151018
10161019var inspectorWrapper = null ;
0 commit comments