WXL
3 天以前 3bd962a6d7f61239c020e2dbbeb7341e5b842dd1
node_modules/terser-webpack-plugin/dist/utils.js
@@ -14,7 +14,7 @@
 */
/**
 * @typedef {Array<string>} ExtractedComments
 * @typedef {string[]} ExtractedComments
 */
const notSettled = Symbol("not-settled");
@@ -86,7 +86,7 @@
  };
  /**
   * @param {import("terser").MinifyOptions & { sourceMap: import("terser").SourceMapOptions | undefined  } & ({ output: import("terser").FormatOptions & { beautify: boolean } } | { format: import("terser").FormatOptions & { beautify: boolean } })} terserOptions terser options
   * @param {import("terser").MinifyOptions & { sourceMap: import("terser").SourceMapOptions | undefined } & ({ output: import("terser").FormatOptions & { beautify: boolean } } | { format: import("terser").FormatOptions & { beautify: boolean } })} terserOptions terser options
   * @param {ExtractedComments} extractedComments extracted comments
   * @returns {ExtractCommentsFunction} function to extract comments
   */
@@ -143,7 +143,7 @@
          }
          regexStr = /** @type {string} */condition[key];
          condition[key] = /** @type {ExtractCommentsFunction} */
          (astNode, comment) => new RegExp( /** @type {string} */regexStr).test(comment.value);
          (astNode, comment) => new RegExp(/** @type {string} */regexStr).test(comment.value);
          break;
        default:
          regex = /** @type {RegExp} */condition[key];
@@ -155,7 +155,7 @@
    // Redefine the comments function to extract and preserve
    // comments according to the two conditions
    return (astNode, comment) => {
      if ( /** @type {{ extract: ExtractCommentsFunction }} */
      if (/** @type {{ extract: ExtractCommentsFunction }} */
      condition.extract(astNode, comment)) {
        const commentText = comment.type === "comment2" ? `/*${comment.value}*/` : `//${comment.value}`;
@@ -217,7 +217,7 @@
    } = require("terser"));
  } catch (err) {
    return {
      errors: [( /** @type {Error} */err)]
      errors: [(/** @type {Error} */err)]
    };
  }
@@ -254,8 +254,8 @@
    [filename]: code
  }, terserOptions);
  return {
    code: ( /** @type {string} * */result.code),
    map: result.map ? ( /** @type {RawSourceMap} * */result.map) : undefined,
    code: (/** @type {string} * */result.code),
    map: result.map ? (/** @type {RawSourceMap} * */result.map) : undefined,
    extractedComments
  };
}
@@ -300,7 +300,7 @@
  };
  /**
   * @param {import("uglify-js").MinifyOptions & { sourceMap: boolean | import("uglify-js").SourceMapOptions | undefined } & { output: import("uglify-js").OutputOptions & { beautify: boolean }}} uglifyJsOptions uglify-js options
   * @param {import("uglify-js").MinifyOptions & { sourceMap: boolean | import("uglify-js").SourceMapOptions | undefined } & { output: import("uglify-js").OutputOptions & { beautify: boolean } }} uglifyJsOptions uglify-js options
   * @param {ExtractedComments} extractedComments extracted comments
   * @returns {ExtractCommentsFunction} extract comments function
   */
@@ -350,7 +350,7 @@
          }
          regexStr = /** @type {string} */condition[key];
          condition[key] = /** @type {ExtractCommentsFunction} */
          (astNode, comment) => new RegExp( /** @type {string} */regexStr).test(comment.value);
          (astNode, comment) => new RegExp(/** @type {string} */regexStr).test(comment.value);
          break;
        default:
          regex = /** @type {RegExp} */condition[key];
@@ -362,7 +362,7 @@
    // Redefine the comments function to extract and preserve
    // comments according to the two conditions
    return (astNode, comment) => {
      if ( /** @type {{ extract: ExtractCommentsFunction }} */
      if (/** @type {{ extract: ExtractCommentsFunction }} */
      condition.extract(astNode, comment)) {
        const commentText = comment.type === "comment2" ? `/*${comment.value}*/` : `//${comment.value}`;
@@ -377,7 +377,7 @@
  /**
   * @param {PredefinedOptions<import("uglify-js").MinifyOptions> & import("uglify-js").MinifyOptions=} uglifyJsOptions uglify-js options
   * @returns {import("uglify-js").MinifyOptions & { sourceMap: boolean | import("uglify-js").SourceMapOptions | undefined } & { output: import("uglify-js").OutputOptions & { beautify: boolean }}} uglify-js options
   * @returns {import("uglify-js").MinifyOptions & { sourceMap: boolean | import("uglify-js").SourceMapOptions | undefined } & { output: import("uglify-js").OutputOptions & { beautify: boolean } }} uglify-js options
   */
  const buildUglifyJsOptions = (uglifyJsOptions = {}) => {
    if (typeof uglifyJsOptions.ecma !== "undefined") {
@@ -422,7 +422,7 @@
    } = require("uglify-js"));
  } catch (err) {
    return {
      errors: [( /** @type {Error} */err)]
      errors: [(/** @type {Error} */err)]
    };
  }
@@ -508,7 +508,7 @@
    swc = require("@swc/core");
  } catch (err) {
    return {
      errors: [( /** @type {Error} */err)]
      errors: [(/** @type {Error} */err)]
    };
  }
@@ -596,7 +596,7 @@
    esbuild = require("esbuild");
  } catch (err) {
    return {
      errors: [( /** @type {Error} */err)]
      errors: [(/** @type {Error} */err)]
    };
  }
@@ -641,6 +641,26 @@
 */
esbuildMinify.supportsWorkerThreads = () => false;
/* istanbul ignore next */
/**
 * @param {Input} input input
 * @param {RawSourceMap=} sourceMap source map
 * @param {CustomOptions=} minimizerOptions options
 * @returns {Promise<MinimizedResult>} minimized result
 */
async function jsonMinify(input, sourceMap, minimizerOptions) {
  const options = /** @type {{ replacer?: Parameters<typeof JSON.stringify>[1], space?: Parameters<typeof JSON.stringify>[2] }} */
  minimizerOptions;
  const [[, code]] = Object.entries(input);
  const result = JSON.stringify(JSON.parse(code), options.replacer, options.space);
  return {
    code: result
  };
}
jsonMinify.getMinimizerVersion = () => "1.0.0";
jsonMinify.supportsWorker = () => false;
jsonMinify.supportsWorkerThreads = () => false;
/**
 * @template T
 * @typedef {() => T} FunctionReturning
@@ -670,6 +690,7 @@
}
module.exports = {
  esbuildMinify,
  jsonMinify,
  memoize,
  swcMinify,
  terserMinify,