diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 22:41:29 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 22:41:29 +0800 |
| commit | af842b8362016d0ac572de8c5810b67258df8bd7 (patch) | |
| tree | f904a9294f8d1780a60e6630cf6fd4b494aa7878 /node_modules/source-map/lib/util.js | |
| parent | bd9536ee06890c07456337fec3e7a916e03d8f6e (diff) | |
updates
Diffstat (limited to 'node_modules/source-map/lib/util.js')
| -rw-r--r-- | node_modules/source-map/lib/util.js | 160 |
1 files changed, 51 insertions, 109 deletions
diff --git a/node_modules/source-map/lib/util.js b/node_modules/source-map/lib/util.js index 35bd93d6..3ca92e56 100644 --- a/node_modules/source-map/lib/util.js +++ b/node_modules/source-map/lib/util.js @@ -20,17 +20,17 @@ function getArg(aArgs, aName, aDefaultValue) { return aArgs[aName]; } else if (arguments.length === 3) { return aDefaultValue; - } + } else { throw new Error('"' + aName + '" is a required argument.'); - + } } exports.getArg = getArg; -const urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/; -const dataUrlRegexp = /^data:.+\,.+$/; +var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/; +var dataUrlRegexp = /^data:.+\,.+$/; function urlParse(aUrl) { - const match = aUrl.match(urlRegexp); + var match = aUrl.match(urlRegexp); if (!match) { return null; } @@ -45,19 +45,19 @@ function urlParse(aUrl) { exports.urlParse = urlParse; function urlGenerate(aParsedUrl) { - let url = ""; + var url = ''; if (aParsedUrl.scheme) { - url += aParsedUrl.scheme + ":"; + url += aParsedUrl.scheme + ':'; } - url += "//"; + url += '//'; if (aParsedUrl.auth) { - url += aParsedUrl.auth + "@"; + url += aParsedUrl.auth + '@'; } if (aParsedUrl.host) { url += aParsedUrl.host; } if (aParsedUrl.port) { - url += ":" + aParsedUrl.port; + url += ":" + aParsedUrl.port } if (aParsedUrl.path) { url += aParsedUrl.path; @@ -66,43 +66,6 @@ function urlGenerate(aParsedUrl) { } exports.urlGenerate = urlGenerate; -const MAX_CACHED_INPUTS = 32; - -/** - * Takes some function `f(input) -> result` and returns a memoized version of - * `f`. - * - * We keep at most `MAX_CACHED_INPUTS` memoized results of `f` alive. The - * memoization is a dumb-simple, linear least-recently-used cache. - */ -function lruMemoize(f) { - const cache = []; - - return function(input) { - for (let i = 0; i < cache.length; i++) { - if (cache[i].input === input) { - const temp = cache[0]; - cache[0] = cache[i]; - cache[i] = temp; - return cache[0].result; - } - } - - const result = f(input); - - cache.unshift({ - input, - result, - }); - - if (cache.length > MAX_CACHED_INPUTS) { - cache.pop(); - } - - return result; - }; -} - /** * Normalizes a path, or the path portion of a URL: * @@ -114,45 +77,26 @@ function lruMemoize(f) { * * @param aPath The path or url to normalize. */ -const normalize = lruMemoize(function normalize(aPath) { - let path = aPath; - const url = urlParse(aPath); +function normalize(aPath) { + var path = aPath; + var url = urlParse(aPath); if (url) { if (!url.path) { return aPath; } path = url.path; } - const isAbsolute = exports.isAbsolute(path); - - // Split the path into parts between `/` characters. This is much faster than - // using `.split(/\/+/g)`. - const parts = []; - let start = 0; - let i = 0; - while (true) { - start = i; - i = path.indexOf("/", start); - if (i === -1) { - parts.push(path.slice(start)); - break; - } else { - parts.push(path.slice(start, i)); - while (i < path.length && path[i] === "/") { - i++; - } - } - } + var isAbsolute = exports.isAbsolute(path); - let up = 0; - for (i = parts.length - 1; i >= 0; i--) { - const part = parts[i]; - if (part === ".") { + var parts = path.split(/\/+/); + for (var part, up = 0, i = parts.length - 1; i >= 0; i--) { + part = parts[i]; + if (part === '.') { parts.splice(i, 1); - } else if (part === "..") { + } else if (part === '..') { up++; } else if (up > 0) { - if (part === "") { + if (part === '') { // The first part is blank if the path is absolute. Trying to go // above the root is a no-op. Therefore we can remove all '..' parts // directly after the root. @@ -164,10 +108,10 @@ const normalize = lruMemoize(function normalize(aPath) { } } } - path = parts.join("/"); + path = parts.join('/'); - if (path === "") { - path = isAbsolute ? "/" : "."; + if (path === '') { + path = isAbsolute ? '/' : '.'; } if (url) { @@ -175,7 +119,7 @@ const normalize = lruMemoize(function normalize(aPath) { return urlGenerate(url); } return path; -}); +} exports.normalize = normalize; /** @@ -201,10 +145,10 @@ function join(aRoot, aPath) { if (aPath === "") { aPath = "."; } - const aPathUrl = urlParse(aPath); - const aRootUrl = urlParse(aRoot); + var aPathUrl = urlParse(aPath); + var aRootUrl = urlParse(aRoot); if (aRootUrl) { - aRoot = aRootUrl.path || "/"; + aRoot = aRootUrl.path || '/'; } // `join(foo, '//www.example.org')` @@ -225,9 +169,9 @@ function join(aRoot, aPath) { return urlGenerate(aRootUrl); } - const joined = aPath.charAt(0) === "/" + var joined = aPath.charAt(0) === '/' ? aPath - : normalize(aRoot.replace(/\/+$/, "") + "/" + aPath); + : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath); if (aRootUrl) { aRootUrl.path = joined; @@ -237,8 +181,8 @@ function join(aRoot, aPath) { } exports.join = join; -exports.isAbsolute = function(aPath) { - return aPath.charAt(0) === "/" || urlRegexp.test(aPath); +exports.isAbsolute = function (aPath) { + return aPath.charAt(0) === '/' || urlRegexp.test(aPath); }; /** @@ -252,15 +196,15 @@ function relative(aRoot, aPath) { aRoot = "."; } - aRoot = aRoot.replace(/\/$/, ""); + aRoot = aRoot.replace(/\/$/, ''); // It is possible for the path to be above the root. In this case, simply // checking whether the root is a prefix of the path won't work. Instead, we // need to remove components from the root one by one, until either we find // a prefix that fits, or we run out of components to remove. - let level = 0; - while (aPath.indexOf(aRoot + "/") !== 0) { - const index = aRoot.lastIndexOf("/"); + var level = 0; + while (aPath.indexOf(aRoot + '/') !== 0) { + var index = aRoot.lastIndexOf("/"); if (index < 0) { return aPath; } @@ -281,12 +225,12 @@ function relative(aRoot, aPath) { } exports.relative = relative; -const supportsNullProto = (function() { - const obj = Object.create(null); - return !("__proto__" in obj); +var supportsNullProto = (function () { + var obj = Object.create(null); + return !('__proto__' in obj); }()); -function identity(s) { +function identity (s) { return s; } @@ -301,7 +245,7 @@ function identity(s) { */ function toSetString(aStr) { if (isProtoString(aStr)) { - return "$" + aStr; + return '$' + aStr; } return aStr; @@ -322,13 +266,12 @@ function isProtoString(s) { return false; } - const length = s.length; + var length = s.length; if (length < 9 /* "__proto__".length */) { return false; } - /* eslint-disable no-multi-spaces */ if (s.charCodeAt(length - 1) !== 95 /* '_' */ || s.charCodeAt(length - 2) !== 95 /* '_' */ || s.charCodeAt(length - 3) !== 111 /* 'o' */ || @@ -340,9 +283,8 @@ function isProtoString(s) { s.charCodeAt(length - 9) !== 95 /* '_' */) { return false; } - /* eslint-enable no-multi-spaces */ - for (let i = length - 10; i >= 0; i--) { + for (var i = length - 10; i >= 0; i--) { if (s.charCodeAt(i) !== 36 /* '$' */) { return false; } @@ -360,7 +302,7 @@ function isProtoString(s) { * stubbed out mapping. */ function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) { - let cmp = strcmp(mappingA.source, mappingB.source); + var cmp = strcmp(mappingA.source, mappingB.source); if (cmp !== 0) { return cmp; } @@ -399,7 +341,7 @@ exports.compareByOriginalPositions = compareByOriginalPositions; * mapping with a stubbed out mapping. */ function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) { - let cmp = mappingA.generatedLine - mappingB.generatedLine; + var cmp = mappingA.generatedLine - mappingB.generatedLine; if (cmp !== 0) { return cmp; } @@ -453,7 +395,7 @@ function strcmp(aStr1, aStr2) { * the generated positions are compared. */ function compareByGeneratedPositionsInflated(mappingA, mappingB) { - let cmp = mappingA.generatedLine - mappingB.generatedLine; + var cmp = mappingA.generatedLine - mappingB.generatedLine; if (cmp !== 0) { return cmp; } @@ -488,7 +430,7 @@ exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflate * JSON. */ function parseSourceMapInput(str) { - return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, "")); + return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, '')); } exports.parseSourceMapInput = parseSourceMapInput; @@ -497,12 +439,12 @@ exports.parseSourceMapInput = parseSourceMapInput; * URL, and the source map's URL. */ function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) { - sourceURL = sourceURL || ""; + sourceURL = sourceURL || ''; if (sourceRoot) { // This follows what Chrome does. - if (sourceRoot[sourceRoot.length - 1] !== "/" && sourceURL[0] !== "/") { - sourceRoot += "/"; + if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') { + sourceRoot += '/'; } // The spec says: // Line 4: An optional source root, useful for relocating source @@ -527,13 +469,13 @@ function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) { // “sourceRoot”, the sources are resolved relative to the // SourceMap (like resolving script src in a html document). if (sourceMapURL) { - const parsed = urlParse(sourceMapURL); + var parsed = urlParse(sourceMapURL); if (!parsed) { throw new Error("sourceMapURL could not be parsed"); } if (parsed.path) { // Strip the last path component, but keep the "/". - const index = parsed.path.lastIndexOf("/"); + var index = parsed.path.lastIndexOf('/'); if (index >= 0) { parsed.path = parsed.path.substring(0, index + 1); } |
