| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6c34ad6 commit b743f2c
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,10 +13,6 @@ const { | |||
| 13 | 13 | ||
| 14 | 14 | const { pathToFileURL } = require('url'); | |
| 15 | 15 | ||
| 16 | - const { | ||
| 17 | - stripShebangOrBOM, | ||
| 18 | - } = require('internal/modules/cjs/helpers'); | ||
| 19 | - | ||
| 20 | 16 | const { | |
| 21 | 17 | Module: { | |
| 22 | 18 | _resolveFilename: resolveCJSModuleName, | |
@@ -68,5 +64,5 @@ function checkSyntax(source, filename) { | |||
| 68 | 64 | } | |
| 69 | 65 | } | |
| 70 | 66 | ||
| 71 | - wrapSafe(filename, stripShebangOrBOM(source)); | ||
| 67 | + wrapSafe(filename, source); | ||
| 72 | 68 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -111,37 +111,6 @@ function stripBOM(content) { | |||
| 111 | 111 | return content; | |
| 112 | 112 | } | |
| 113 | 113 | ||
| 114 | - /** | ||
| 115 | - * Find end of shebang line and slice it off | ||
| 116 | - */ | ||
| 117 | - function stripShebang(content) { | ||
| 118 | - // Remove shebang | ||
| 119 | - if (content.charAt(0) === '#' && content.charAt(1) === '!') { | ||
| 120 | - // Find end of shebang line and slice it off | ||
| 121 | - let index = content.indexOf('\n', 2); | ||
| 122 | - if (index === -1) | ||
| 123 | - return ''; | ||
| 124 | - if (content.charAt(index - 1) === '\r') | ||
| 125 | - index--; | ||
| 126 | - // Note that this actually includes the newline character(s) in the | ||
| 127 | - // new output. This duplicates the behavior of the regular expression | ||
| 128 | - // that was previously used to replace the shebang line. | ||
| 129 | - content = content.slice(index); | ||
| 130 | - } | ||
| 131 | - return content; | ||
| 132 | - } | ||
| 133 | - | ||
| 134 | - // Strip either the shebang or UTF BOM of a file. | ||
| 135 | - // Note that this only processes one. If both occur in | ||
| 136 | - // either order, the one that comes second is not | ||
| 137 | - // significant. | ||
| 138 | - function stripShebangOrBOM(content) { | ||
| 139 | - if (content.charCodeAt(0) === 0xFEFF) { | ||
| 140 | - return content.slice(1); | ||
| 141 | - } | ||
| 142 | - return stripShebang(content); | ||
| 143 | - } | ||
| 144 | - | ||
| 145 | 114 | const builtinLibs = [ | |
| 146 | 115 | 'assert', 'async_hooks', 'buffer', 'child_process', 'cluster', 'crypto', | |
| 147 | 116 | 'dgram', 'dns', 'domain', 'events', 'fs', 'http', 'http2', 'https', 'net', | |
@@ -208,6 +177,4 @@ module.exports = { | |||
| 208 | 177 | makeRequireFunction, | |
| 209 | 178 | normalizeReferrerURL, | |
| 210 | 179 | stripBOM, | |
| 211 | - stripShebang, | ||
| 212 | - stripShebangOrBOM, | ||
| 213 | 180 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,7 +51,7 @@ const { | |||
| 51 | 51 | makeRequireFunction, | |
| 52 | 52 | normalizeReferrerURL, | |
| 53 | 53 | stripBOM, | |
| 54 | - stripShebangOrBOM, | ||
| 54 | + loadNativeModule | ||
| 55 | 55 | } = require('internal/modules/cjs/helpers'); | |
| 56 | 56 | const { getOptionValue } = require('internal/options'); | |
| 57 | 57 | const enableSourceMaps = getOptionValue('--enable-source-maps'); | |
@@ -961,9 +961,9 @@ function wrapSafe(filename, content) { | |||
| 961 | 961 | }); | |
| 962 | 962 | } | |
| 963 | 963 | ||
| 964 | - let compiledWrapper; | ||
| 964 | + let compiled; | ||
| 965 | 965 | try { | |
| 966 | - compiledWrapper = compileFunction( | ||
| 966 | + compiled = compileFunction( | ||
| 967 | 967 | content, | |
| 968 | 968 | filename, | |
| 969 | 969 | 0, | |
@@ -981,36 +981,39 @@ function wrapSafe(filename, content) { | |||
| 981 | 981 | ] | |
| 982 | 982 | ); | |
| 983 | 983 | } catch (err) { | |
| 984 | - enrichCJSError(err); | ||
| 984 | + if (experimentalModules) { | ||
| 985 | + enrichCJSError(err); | ||
| 986 | + } | ||
| 985 | 987 | throw err; | |
| 986 | 988 | } | |
| 987 | 989 | ||
| 988 | 990 | if (experimentalModules) { | |
| 989 | 991 | const { callbackMap } = internalBinding('module_wrap'); | |
| 990 | - callbackMap.set(compiledWrapper, { | ||
| 992 | + callbackMap.set(compiled.cacheKey, { | ||
| 991 | 993 | importModuleDynamically: async (specifier) => { | |
| 992 | 994 | const loader = await asyncESM.loaderPromise; | |
| 993 | 995 | return loader.import(specifier, normalizeReferrerURL(filename)); | |
| 994 | 996 | } | |
| 995 | 997 | }); | |
| 996 | 998 | } | |
| 997 | 999 | ||
| 998 | - return compiledWrapper; | ||
| 1000 | + return compiled.function; | ||
| 999 | 1001 | } | |
| 1000 | 1002 | ||
| 1001 | 1003 | // Run the file contents in the correct scope or sandbox. Expose | |
| 1002 | 1004 | // the correct helper variables (require, module, exports) to | |
| 1003 | 1005 | // the file. | |
| 1004 | 1006 | // Returns exception, if any. | |
| 1005 | 1007 | Module.prototype._compile = function(content, filename) { | |
| 1008 | + let moduleURL; | ||
| 1009 | + let redirects; | ||
| 1006 | 1010 | if (manifest) { | |
| 1007 | - const moduleURL = pathToFileURL(filename); | ||
| 1011 | + moduleURL = pathToFileURL(filename); | ||
| 1012 | + redirects = manifest.getRedirector(moduleURL); | ||
| 1008 | 1013 | manifest.assertIntegrity(moduleURL, content); | |
| 1009 | 1014 | } | |
| 1010 | 1015 | ||
| 1011 | - // Strip after manifest integrity check | ||
| 1012 | - content = stripShebangOrBOM(content); | ||
| 1013 | - | ||
| 1016 | + maybeCacheSourceMap(filename, content, this); | ||
| 1014 | 1017 | const compiledWrapper = wrapSafe(filename, content); | |
| 1015 | 1018 | ||
| 1016 | 1019 | var inspectorWrapper = null; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,7 +12,8 @@ const { | |||
| 12 | 12 | const { Buffer } = require('buffer'); | |
| 13 | 13 | ||
| 14 | 14 | const { | |
| 15 | - stripBOM | ||
| 15 | + stripBOM, | ||
| 16 | + loadNativeModule | ||
| 16 | 17 | } = require('internal/modules/cjs/helpers'); | |
| 17 | 18 | const CJSModule = require('internal/modules/cjs/loader').Module; | |
| 18 | 19 | const internalURLModule = require('internal/url'); | |
@@ -78,9 +79,8 @@ translators.set('module', async function moduleStrategy(url) { | |||
| 78 | 79 | const source = `${await getSource(url)}`; | |
| 79 | 80 | maybeCacheSourceMap(url, source); | |
| 80 | 81 | debug(`Translating StandardModule ${url}`); | |
| 81 | - const { ModuleWrap, callbackMap } = internalBinding('module_wrap'); | ||
| 82 | 82 | const module = new ModuleWrap(source, url); | |
| 83 | - callbackMap.set(module, { | ||
| 83 | + moduleWrap.callbackMap.set(module, { | ||
| 84 | 84 | initializeImportMeta, | |
| 85 | 85 | importModuleDynamically, | |
| 86 | 86 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + #!shebang | ||
| 2 | + #!shebang | ||
| 3 | + module.exports = 42; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -355,7 +355,7 @@ assert.strictEqual(require('../fixtures/utf8-bom.json'), 42); | |||
| 355 | 355 | // Loading files with BOM + shebang. | |
| 356 | 356 | // See https://github.com/nodejs/node/issues/27767 | |
| 357 | 357 | assert.throws(() => { | |
| 358 | - require('../fixtures/utf8-bom-shebang.js'); | ||
| 358 | + require('../fixtures/utf8-bom-shebang-shebang.js'); | ||
| 359 | 359 | }, { name: 'SyntaxError' }); | |
| 360 | 360 | assert.strictEqual(require('../fixtures/utf8-shebang-bom.js'), 42); | |
| 361 | 361 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments