"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var minimize_exports = {};
__export(minimize_exports, {
  getJSMinifyOptions: () => getJSMinifyOptions
});
module.exports = __toCommonJS(minimize_exports);
var import_mergeChainedOptions = require("./mergeChainedOptions");
function applyRemoveConsole(options, config) {
  if (!options.terserOptions) {
    options.terserOptions = {};
  }
  const { removeConsole } = config.performance;
  const compressOptions = typeof options.terserOptions.compress === "boolean" ? {} : options.terserOptions.compress || {};
  if (removeConsole === true) {
    options.terserOptions.compress = {
      ...compressOptions,
      drop_console: true
    };
  } else if (Array.isArray(removeConsole)) {
    const pureFuncs = removeConsole.map((method) => `console.${method}`);
    options.terserOptions.compress = {
      ...compressOptions,
      pure_funcs: pureFuncs
    };
  }
  return options;
}
async function getJSMinifyOptions(config) {
  const DEFAULT_OPTIONS = {
    terserOptions: {
      mangle: {
        // not need in rspack(swc)
        // https://github.com/swc-project/swc/discussions/3373
        safari10: true
      },
      format: {
        ascii_only: config.output.charset === "ascii"
      }
    }
  };
  switch (config.output.legalComments) {
    case "inline":
      DEFAULT_OPTIONS.extractComments = false;
      break;
    case "linked":
      DEFAULT_OPTIONS.extractComments = true;
      break;
    case "none":
      DEFAULT_OPTIONS.terserOptions.format.comments = false;
      DEFAULT_OPTIONS.extractComments = false;
      break;
    default:
      break;
  }
  const mergedOptions = (0, import_mergeChainedOptions.mergeChainedOptions)({
    defaults: DEFAULT_OPTIONS,
    // @ts-expect-error
    options: config.tools.terser
  });
  const finalOptions = applyRemoveConsole(mergedOptions, config);
  return finalOptions;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getJSMinifyOptions
});
