WXL
3 天以前 9bce51f651aad297ef9eb6df832bfdaf1de05d84
node_modules/webpack/lib/util/extractSourceMap.js
@@ -10,18 +10,13 @@
const { isAbsolute, join } = require("./fs");
/** @typedef {import("./fs").InputFileSystem} InputFileSystem */
/**
 * @typedef {(input: string | Buffer<ArrayBufferLike>, resourcePath: string, fs: InputFileSystem) => Promise<{source: string | Buffer<ArrayBufferLike>, sourceMap: string | RawSourceMap | undefined, fileDependencies: string[]}>} SourceMapExtractorFunction
 */
/** @typedef {string | Buffer<ArrayBufferLike>} StringOrBuffer */
/** @typedef {(input: StringOrBuffer, resourcePath: string, fs: InputFileSystem) => Promise<{ source: StringOrBuffer, sourceMap: string | RawSourceMap | undefined, fileDependencies: string[] }>} SourceMapExtractorFunction */
/** @typedef {import("webpack-sources").RawSourceMap} RawSourceMap */
/** @typedef {(resourcePath: string) => Promise<StringOrBuffer>} ReadResource */
/**
 * @typedef {(resourcePath: string) => Promise<string | Buffer<ArrayBufferLike>>} ReadResource
 */
/**
 * Defines the source mapping url type used by this module.
 * @typedef {object} SourceMappingURL
 * @property {string} sourceMappingURL
 * @property {string} replacementString
@@ -52,6 +47,7 @@
 */
function getSourceMappingURL(code) {
   const lines = code.split(/^/m);
   /** @type {RegExpMatchArray | null | undefined} */
   let match;
   for (let i = lines.length - 1; i >= 0; i--) {
@@ -104,13 +100,14 @@
 * @param {ReadResource} readResource read resource function
 * @param {string[]} possibleRequests array of possible file paths
 * @param {string} errorsAccumulator accumulated error messages
 * @returns {Promise<{path: string, data?: string}>} source content promise
 * @returns {Promise<{ path: string, data?: string }>} source content promise
 */
async function fetchPathsFromURL(
   readResource,
   possibleRequests,
   errorsAccumulator = ""
) {
   /** @type {StringOrBuffer} */
   let result;
   try {
@@ -146,7 +143,7 @@
 * @param {string} url source URL
 * @param {string=} sourceRoot source root directory
 * @param {boolean=} skipReading whether to skip reading file content
 * @returns {Promise<{sourceURL: string, sourceContent?: string | Buffer<ArrayBufferLike>}>} source content promise
 * @returns {Promise<{ sourceURL: string, sourceContent?: StringOrBuffer }>} source content promise
 */
async function fetchFromURL(
   readResource,
@@ -181,9 +178,11 @@
   if (isAbsolute(url)) {
      let sourceURL = path.normalize(url);
      /** @type {undefined | StringOrBuffer} */
      let sourceContent;
      if (!skipReading) {
         /** @type {string[]} */
         const possibleRequests = [sourceURL];
         if (url.startsWith("/")) {
@@ -203,6 +202,7 @@
   // 4. Relative path
   const sourceURL = getAbsolutePath(context, url, sourceRoot || "");
   /** @type {undefined | StringOrBuffer} */
   let sourceContent;
   if (!skipReading) {
@@ -214,10 +214,10 @@
/**
 * Extract source map from code content
 * @param {string | Buffer<ArrayBufferLike>} stringOrBuffer The input code content as string or buffer
 * @param {StringOrBuffer} stringOrBuffer The input code content as string or buffer
 * @param {string} resourcePath The path to the resource file
 * @param {ReadResource} readResource The read resource function
 * @returns {Promise<{source: string | Buffer<ArrayBufferLike>, sourceMap: string | RawSourceMap | undefined}>} Promise resolving to extracted source map information
 * @returns {Promise<{ source: StringOrBuffer, sourceMap: string | RawSourceMap | undefined }>} Promise resolving to extracted source map information
 */
async function extractSourceMap(stringOrBuffer, resourcePath, readResource) {
   const input =