Skip to content

Commit fd269ba

Browse files
refactor: code
1 parent 406e7cb commit fd269ba

10 files changed

Lines changed: 698 additions & 616 deletions

File tree

package-lock.json

Lines changed: 673 additions & 529 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const {
3131

3232
// eslint-disable-next-line jsdoc/reject-any-type
3333
/** @typedef {any} EXPECTED_ANY */
34+
// eslint-disable-next-line jsdoc/require-property
35+
/** @typedef {object} EXPECTED_OBJECT */
3436

3537
/**
3638
* @callback ExtractCommentsFunction

src/utils.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
/** @typedef {import("./index.js").MinimizedResult} MinimizedResult */
66
/** @typedef {import("./index.js").CustomOptions} CustomOptions */
77
/** @typedef {import("./index.js").RawSourceMap} RawSourceMap */
8-
/** @typedef {import("@swc/core").JsMinifyOptions & { extractComments?: false | true | "some" | "all" | { regex: string } }} SwcMinifyOptionsWithExtractComments */
9-
/** @typedef {import("@swc/core").Output & { extractedComments?: string[] }} SwcMinifyOutput */
8+
/** @typedef {import("./index.js").EXPECTED_OBJECT} EXPECTED_OBJECT */
109

1110
/**
1211
* @template T
@@ -81,7 +80,7 @@ async function terserMinify(
8180
) {
8281
/**
8382
* @param {unknown} value value
84-
* @returns {boolean} true when value is object or function
83+
* @returns {value is EXPECTED_OBJECT} true when value is object or function
8584
*/
8685
const isObject = (value) => {
8786
const type = typeof value;
@@ -617,9 +616,9 @@ async function swcMinify(input, sourceMap, minimizerOptions, extractComments) {
617616
}
618617

619618
if (extractCommentsOptions && isObject(extractCommentsOptions)) {
620-
const { condition = "some" } = /** @type {{ condition?: unknown }} */ (
621-
extractCommentsOptions
622-
);
619+
const { condition = "some" } =
620+
/** @type {{ condition?: unknown }} */
621+
(extractCommentsOptions);
623622

624623
if (typeof condition === "boolean") {
625624
return {
@@ -660,7 +659,7 @@ async function swcMinify(input, sourceMap, minimizerOptions, extractComments) {
660659

661660
/**
662661
* @param {PredefinedOptions<import("@swc/core").JsMinifyOptions> & import("@swc/core").JsMinifyOptions=} swcOptions swc options
663-
* @returns {SwcMinifyOptionsWithExtractComments & { sourceMap: undefined | boolean } & { compress: import("@swc/core").TerserCompressOptions }} built swc options
662+
* @returns {import("@swc/core").JsMinifyOptions & { extractComments?: false | true | "some" | "all" | { regex: string } } & { sourceMap: undefined | boolean } & { compress: import("@swc/core").TerserCompressOptions }} built swc options
664663
*/
665664
const buildSwcOptions = (swcOptions = {}) =>
666665
// Need deep copy objects to avoid https://github.com/terser/terser/issues/366
@@ -719,9 +718,8 @@ async function swcMinify(input, sourceMap, minimizerOptions, extractComments) {
719718
}
720719

721720
if (normalizedExtractComments.extractComments !== false) {
722-
/** @type {SwcMinifyOptionsWithExtractComments} */ (
723-
swcOptions
724-
).extractComments = normalizedExtractComments.extractComments;
721+
/** @type {import("@swc/core").JsMinifyOptions & { extractComments?: false | true | "some" | "all" | { regex: string } }} */
722+
(swcOptions).extractComments = normalizedExtractComments.extractComments;
725723
}
726724

727725
if (swcOptions.compress) {
@@ -740,9 +738,9 @@ async function swcMinify(input, sourceMap, minimizerOptions, extractComments) {
740738
}
741739

742740
const [[filename, code]] = Object.entries(input);
743-
const result = /** @type {SwcMinifyOutput} */ (
744-
await swc.minify(code, swcOptions)
745-
);
741+
const result =
742+
/** @type {import("@swc/core").Output & { extractedComments?: string[] }} */
743+
(await swc.minify(code, swcOptions));
746744

747745
let map;
748746

test/__snapshots__/minify-option.test.js.snap

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ Array [
1515
]
1616
`;
1717

18-
exports[`minify option should report an error when the \`extractComments\` option for \`swcMinify\` uses a function condition: assets 1`] = `
19-
Object {
20-
"203.203.js": "Error: ENOENT: no such file or directory, open 'test/helpers/dist/203.203.js'",
21-
"main.js": "Error: ENOENT: no such file or directory, open 'test/helpers/dist/main.js'",
22-
}
23-
`;
24-
2518
exports[`minify option should report an error when the \`extractComments\` option for \`swcMinify\` uses a function condition: errors 1`] = `
2619
Array [
2720
"Error: 203.203.js from Terser plugin
@@ -168,13 +161,13 @@ exports[`minify option should work using when the \`minify\` option is \`esbuild
168161
169162
exports[`minify option should work using when the \`minify\` option is \`jsonMinify\` and allows to set \`JSON.stringify\` options: assets 1`] = `
170163
Object {
171-
"[hash].json": "{
164+
"71be2c5d019f14d29bdd.json": "{
172165
\\"foo\\": \\"bar\\",
173166
\\"bar\\": [
174167
\\"baz\\"
175168
]
176169
}",
177-
"main.js": "(()=>{var t={437(t,r,e){\\"use strict\\";t.exports=e.p+\\"[hash].json\\"}},r={};function e(o){var n=r[o];if(void 0!==n)return n.exports;var c=r[o]={exports:{}};return t[o](c,c.exports,e),c.exports}e.m=t,e.g=function(){if(\\"object\\"==typeof globalThis)return globalThis;try{return this||new Function(\\"return this\\")()}catch(t){if(\\"object\\"==typeof window)return window}}(),e.o=(t,r)=>Object.prototype.hasOwnProperty.call(t,r),(()=>{var t;e.g.importScripts&&(t=e.g.location+\\"\\");var r=e.g.document;if(!t&&r&&(r.currentScript&&\\"SCRIPT\\"===r.currentScript.tagName.toUpperCase()&&(t=r.currentScript.src),!t)){var o=r.getElementsByTagName(\\"script\\");if(o.length)for(var n=o.length-1;n>-1&&(!t||!/^http(s?):/.test(t));)t=o[n--].src}if(!t)throw new Error(\\"Automatic publicPath is not supported in this browser\\");t=t.replace(/^blob:/,\\"\\").replace(/#.*$/,\\"\\").replace(/\\\\?.*$/,\\"\\").replace(/\\\\/[^\\\\/]+$/,\\"/\\"),e.p=t})(),e.b=\\"undefined\\"!=typeof document&&document.baseURI||self.location.href,console.log(new URL(e(437),e.b))})();",
170+
"main.js": "(()=>{var t={437(t,r,e){\\"use strict\\";t.exports=e.p+\\"71be2c5d019f14d29bdd.json\\"}},r={};function e(o){var n=r[o];if(void 0!==n)return n.exports;var c=r[o]={exports:{}};return t[o](c,c.exports,e),c.exports}e.m=t,e.g=function(){if(\\"object\\"==typeof globalThis)return globalThis;try{return this||new Function(\\"return this\\")()}catch(t){if(\\"object\\"==typeof window)return window}}(),e.o=(t,r)=>Object.prototype.hasOwnProperty.call(t,r),(()=>{var t;e.g.importScripts&&(t=e.g.location+\\"\\");var r=e.g.document;if(!t&&r&&(r.currentScript&&\\"SCRIPT\\"===r.currentScript.tagName.toUpperCase()&&(t=r.currentScript.src),!t)){var o=r.getElementsByTagName(\\"script\\");if(o.length)for(var n=o.length-1;n>-1&&(!t||!/^http(s?):/.test(t));)t=o[n--].src}if(!t)throw new Error(\\"Automatic publicPath is not supported in this browser\\");t=t.replace(/^blob:/,\\"\\").replace(/#.*$/,\\"\\").replace(/\\\\?.*$/,\\"\\").replace(/\\\\/[^\\\\/]+$/,\\"/\\"),e.p=t})(),e.b=\\"undefined\\"!=typeof document&&document.baseURI||self.location.href,console.log(new URL(e(437),e.b))})();",
178171
}
179172
`;
180173
@@ -186,8 +179,8 @@ exports[`minify option should work using when the \`minify\` option is \`jsonMin
186179
187180
exports[`minify option should work using when the \`minify\` option is \`jsonMinify\`: assets 1`] = `
188181
Object {
189-
"[hash].json": "{\\"foo\\":\\"bar\\",\\"bar\\":[\\"baz\\"]}",
190-
"main.js": "(()=>{var t={437(t,r,e){\\"use strict\\";t.exports=e.p+\\"[hash].json\\"}},r={};function e(o){var n=r[o];if(void 0!==n)return n.exports;var c=r[o]={exports:{}};return t[o](c,c.exports,e),c.exports}e.m=t,e.g=function(){if(\\"object\\"==typeof globalThis)return globalThis;try{return this||new Function(\\"return this\\")()}catch(t){if(\\"object\\"==typeof window)return window}}(),e.o=(t,r)=>Object.prototype.hasOwnProperty.call(t,r),(()=>{var t;e.g.importScripts&&(t=e.g.location+\\"\\");var r=e.g.document;if(!t&&r&&(r.currentScript&&\\"SCRIPT\\"===r.currentScript.tagName.toUpperCase()&&(t=r.currentScript.src),!t)){var o=r.getElementsByTagName(\\"script\\");if(o.length)for(var n=o.length-1;n>-1&&(!t||!/^http(s?):/.test(t));)t=o[n--].src}if(!t)throw new Error(\\"Automatic publicPath is not supported in this browser\\");t=t.replace(/^blob:/,\\"\\").replace(/#.*$/,\\"\\").replace(/\\\\?.*$/,\\"\\").replace(/\\\\/[^\\\\/]+$/,\\"/\\"),e.p=t})(),e.b=\\"undefined\\"!=typeof document&&document.baseURI||self.location.href,console.log(new URL(e(437),e.b))})();",
182+
"60491a50c1e5dd7216b6.json": "{\\"foo\\":\\"bar\\",\\"bar\\":[\\"baz\\"]}",
183+
"main.js": "(()=>{var t={437(t,r,e){\\"use strict\\";t.exports=e.p+\\"60491a50c1e5dd7216b6.json\\"}},r={};function e(o){var n=r[o];if(void 0!==n)return n.exports;var c=r[o]={exports:{}};return t[o](c,c.exports,e),c.exports}e.m=t,e.g=function(){if(\\"object\\"==typeof globalThis)return globalThis;try{return this||new Function(\\"return this\\")()}catch(t){if(\\"object\\"==typeof window)return window}}(),e.o=(t,r)=>Object.prototype.hasOwnProperty.call(t,r),(()=>{var t;e.g.importScripts&&(t=e.g.location+\\"\\");var r=e.g.document;if(!t&&r&&(r.currentScript&&\\"SCRIPT\\"===r.currentScript.tagName.toUpperCase()&&(t=r.currentScript.src),!t)){var o=r.getElementsByTagName(\\"script\\");if(o.length)for(var n=o.length-1;n>-1&&(!t||!/^http(s?):/.test(t));)t=o[n--].src}if(!t)throw new Error(\\"Automatic publicPath is not supported in this browser\\");t=t.replace(/^blob:/,\\"\\").replace(/#.*$/,\\"\\").replace(/\\\\?.*$/,\\"\\").replace(/\\\\/[^\\\\/]+$/,\\"/\\"),e.p=t})(),e.b=\\"undefined\\"!=typeof document&&document.baseURI||self.location.href,console.log(new URL(e(437),e.b))})();",
191184
}
192185
`;
193186
@@ -442,17 +435,8 @@ exports[`minify option should work using when the \`minify\` option is \`swcMini
442435
443436
exports[`minify option should work using when the \`minify\` option is \`swcMinify\` and keep legal comments when extract comments is disabled: assets 1`] = `
444437
Object {
445-
"203.203.js": "(self.webpackChunkterser_webpack_plugin=self.webpackChunkterser_webpack_plugin||[]).push([[203],{203(e){/*! Legal Comment *//** @license Copyright 2112 Moon. **/e.exports=Math.random()}}]);",
446-
"main.js": "(()=>{var e,t,r,o={855(e,t,r){r.e(203).then(r.t.bind(r,203,23)),/*! Legal Comment *//**
447-
* @preserve Copyright 2009 SomeThirdParty.
448-
* Here is the full license text and copyright
449-
* notice for this file. Note that the notice can span several
450-
* lines and is only terminated by the closing star and slash:
451-
*//**
452-
* Utility functions for the foo package.
453-
* @license Apache-2.0
454-
*//*! Legal Foo */// @lic
455-
e.exports=Math.random()}},n={};function a(e){var t=n[e];if(void 0!==t)return t.exports;var r=n[e]={exports:{}};return o[e](r,r.exports,a),r.exports}a.m=o,c=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,a.t=function(e,t){if(1&t&&(e=this(e)),8&t||\\"object\\"==typeof e&&e&&(4&t&&e.__esModule||16&t&&\\"function\\"==typeof e.then))return e;var r=Object.create(null);a.r(r);var o={};i=i||[null,c({}),c([]),c(c)];for(var n=2&t&&e;(\\"object\\"==typeof n||\\"function\\"==typeof n)&&!~i.indexOf(n);n=c(n))Object.getOwnPropertyNames(n).forEach(t=>o[t]=()=>e[t]);return o.default=()=>e,a.d(r,o),r},a.d=(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},a.f={},a.e=e=>Promise.all(Object.keys(a.f).reduce((t,r)=>(a.f[r](e,t),t),[])),a.u=e=>\\"\\"+e+\\".\\"+e+\\".js\\",a.g=function(){if(\\"object\\"==typeof globalThis)return globalThis;try{return this||Function(\\"return this\\")()}catch(e){if(\\"object\\"==typeof window)return window}}(),a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),u={},a.l=(e,t,r,o)=>{if(u[e])return void u[e].push(t);if(void 0!==r)for(var n,i,c=document.getElementsByTagName(\\"script\\"),p=0;p<c.length;p++){var l=c[p];if(l.getAttribute(\\"src\\")==e||l.getAttribute(\\"data-webpack\\")==\\"terser-webpack-plugin:\\"+r){n=l;break}}n||(i=!0,(n=document.createElement(\\"script\\")).charset=\\"utf-8\\",a.nc&&n.setAttribute(\\"nonce\\",a.nc),n.setAttribute(\\"data-webpack\\",\\"terser-webpack-plugin:\\"+r),n.src=e),u[e]=[t];var s=(t,r)=>{n.onerror=n.onload=null,clearTimeout(f);var o=u[e];if(delete u[e],n.parentNode&&n.parentNode.removeChild(n),o&&o.forEach(e=>e(r)),t)return t(r)},f=setTimeout(s.bind(null,void 0,{type:\\"timeout\\",target:n}),12e4);n.onerror=s.bind(null,n.onerror),n.onload=s.bind(null,n.onload),i&&document.head.appendChild(n)},a.r=e=>{\\"u\\">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:\\"Module\\"}),Object.defineProperty(e,\\"__esModule\\",{value:!0})},a.g.importScripts&&(p=a.g.location+\\"\\");var i,c,u,p,l=a.g.document;if(!p&&l&&(l.currentScript&&\\"SCRIPT\\"===l.currentScript.tagName.toUpperCase()&&(p=l.currentScript.src),!p)){var s=l.getElementsByTagName(\\"script\\");if(s.length)for(var f=s.length-1;f>-1&&(!p||!/^http(s?):/.test(p));)p=s[f--].src}if(!p)throw Error(\\"Automatic publicPath is not supported in this browser\\");a.p=p=p.replace(/^blob:/,\\"\\").replace(/#.*$/,\\"\\").replace(/\\\\?.*$/,\\"\\").replace(/\\\\/[^\\\\/]+$/,\\"/\\"),e={792:0},a.f.j=(t,r)=>{var o=a.o(e,t)?e[t]:void 0;if(0!==o)if(o)r.push(o[2]);else{var n=new Promise((r,n)=>o=e[t]=[r,n]);r.push(o[2]=n);var i=a.p+a.u(t),c=Error();a.l(i,r=>{if(a.o(e,t)&&(0!==(o=e[t])&&(e[t]=void 0),o)){var n=r&&(\\"load\\"===r.type?\\"missing\\":r.type),i=r&&r.target&&r.target.src;c.message=\\"Loading chunk \\"+t+\` failed.
438+
"203.203.js": "(self.webpackChunkterser_webpack_plugin=self.webpackChunkterser_webpack_plugin||[]).push([[203],{203(e){e.exports=Math.random()}}]);",
439+
"main.js": "(()=>{var e,t,r,o={855(e,t,r){r.e(203).then(r.t.bind(r,203,23)),e.exports=Math.random()}},n={};function a(e){var t=n[e];if(void 0!==t)return t.exports;var r=n[e]={exports:{}};return o[e](r,r.exports,a),r.exports}a.m=o,c=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,a.t=function(e,t){if(1&t&&(e=this(e)),8&t||\\"object\\"==typeof e&&e&&(4&t&&e.__esModule||16&t&&\\"function\\"==typeof e.then))return e;var r=Object.create(null);a.r(r);var o={};i=i||[null,c({}),c([]),c(c)];for(var n=2&t&&e;(\\"object\\"==typeof n||\\"function\\"==typeof n)&&!~i.indexOf(n);n=c(n))Object.getOwnPropertyNames(n).forEach(t=>o[t]=()=>e[t]);return o.default=()=>e,a.d(r,o),r},a.d=(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},a.f={},a.e=e=>Promise.all(Object.keys(a.f).reduce((t,r)=>(a.f[r](e,t),t),[])),a.u=e=>\\"\\"+e+\\".\\"+e+\\".js\\",a.g=function(){if(\\"object\\"==typeof globalThis)return globalThis;try{return this||Function(\\"return this\\")()}catch(e){if(\\"object\\"==typeof window)return window}}(),a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),u={},a.l=(e,t,r,o)=>{if(u[e])return void u[e].push(t);if(void 0!==r)for(var n,i,c=document.getElementsByTagName(\\"script\\"),p=0;p<c.length;p++){var l=c[p];if(l.getAttribute(\\"src\\")==e||l.getAttribute(\\"data-webpack\\")==\\"terser-webpack-plugin:\\"+r){n=l;break}}n||(i=!0,(n=document.createElement(\\"script\\")).charset=\\"utf-8\\",a.nc&&n.setAttribute(\\"nonce\\",a.nc),n.setAttribute(\\"data-webpack\\",\\"terser-webpack-plugin:\\"+r),n.src=e),u[e]=[t];var s=(t,r)=>{n.onerror=n.onload=null,clearTimeout(f);var o=u[e];if(delete u[e],n.parentNode&&n.parentNode.removeChild(n),o&&o.forEach(e=>e(r)),t)return t(r)},f=setTimeout(s.bind(null,void 0,{type:\\"timeout\\",target:n}),12e4);n.onerror=s.bind(null,n.onerror),n.onload=s.bind(null,n.onload),i&&document.head.appendChild(n)},a.r=e=>{\\"u\\">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:\\"Module\\"}),Object.defineProperty(e,\\"__esModule\\",{value:!0})},a.g.importScripts&&(p=a.g.location+\\"\\");var i,c,u,p,l=a.g.document;if(!p&&l&&(l.currentScript&&\\"SCRIPT\\"===l.currentScript.tagName.toUpperCase()&&(p=l.currentScript.src),!p)){var s=l.getElementsByTagName(\\"script\\");if(s.length)for(var f=s.length-1;f>-1&&(!p||!/^http(s?):/.test(p));)p=s[f--].src}if(!p)throw Error(\\"Automatic publicPath is not supported in this browser\\");a.p=p=p.replace(/^blob:/,\\"\\").replace(/#.*$/,\\"\\").replace(/\\\\?.*$/,\\"\\").replace(/\\\\/[^\\\\/]+$/,\\"/\\"),e={792:0},a.f.j=(t,r)=>{var o=a.o(e,t)?e[t]:void 0;if(0!==o)if(o)r.push(o[2]);else{var n=new Promise((r,n)=>o=e[t]=[r,n]);r.push(o[2]=n);var i=a.p+a.u(t),c=Error();a.l(i,r=>{if(a.o(e,t)&&(0!==(o=e[t])&&(e[t]=void 0),o)){var n=r&&(\\"load\\"===r.type?\\"missing\\":r.type),i=r&&r.target&&r.target.src;c.message=\\"Loading chunk \\"+t+\` failed.
456440
(\`+n+\\": \\"+i+\\")\\",c.name=\\"ChunkLoadError\\",c.type=n,c.request=i,o[1](c)}},\\"chunk-\\"+t,t)}},t=(t,r)=>{var o,n,[i,c,u]=r,p=0;if(i.some(t=>0!==e[t])){for(o in c)a.o(c,o)&&(a.m[o]=c[o]);u&&u(a)}for(t&&t(r);p<i.length;p++)n=i[p],a.o(e,n)&&e[n]&&e[n][0](),e[n]=0},(r=self.webpackChunkterser_webpack_plugin=self.webpackChunkterser_webpack_plugin||[]).forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r)),a(855)})();",
457441
}
458442
`;

test/helpers/normalizeBuildOutput.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/helpers/readAsset.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
11
import path from "path";
22

3-
/**
4-
* @param {string} value value
5-
* @returns {string} value without cwd
6-
*/
7-
function removeCWD(value) {
8-
const isWin = process.platform === "win32";
9-
let normalizedValue = value;
10-
let cwd = process.cwd();
11-
12-
if (isWin) {
13-
normalizedValue = normalizedValue.replace(/\\/g, "/");
14-
cwd = cwd.replace(/\\/g, "/");
15-
}
16-
17-
const cwdPrefix = `${cwd}/`;
18-
19-
return normalizedValue.split(cwdPrefix).join("");
20-
}
21-
223
/**
234
* @param {string} asset asset name
245
* @param {import("webpack").Compiler} compiler compiler
@@ -41,7 +22,7 @@ export default (asset, compiler, stats) => {
4122
try {
4223
data = usedFs.readFileSync(path.join(outputPath, targetFile)).toString();
4324
} catch (error) {
44-
data = removeCWD(error.toString());
25+
data = error.toString();
4526
}
4627

4728
return data;

test/helpers/readAssets.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import normalizeBuildOutput from "./normalizeBuildOutput";
21
import readAsset from "./readAsset";
32

43
/**
@@ -10,9 +9,7 @@ export default function readAssets(compiler, stats) {
109
const assets = {};
1110

1211
for (const asset of Object.keys(stats.compilation.assets)) {
13-
assets[normalizeBuildOutput(asset)] = normalizeBuildOutput(
14-
readAsset(asset, compiler, stats),
15-
);
12+
assets[asset] = readAsset(asset, compiler, stats);
1613
}
1714

1815
return assets;

test/minify-option.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ describe("minify option", () => {
736736

737737
new TerserPlugin({
738738
minify: TerserPlugin.swcMinify,
739-
extractComments: false,
739+
extractComments: /moon/,
740740
}).apply(compiler);
741741

742742
const stats = await compile(compiler);
@@ -762,7 +762,6 @@ describe("minify option", () => {
762762

763763
const stats = await compile(compiler);
764764

765-
expect(readsAssets(compiler, stats)).toMatchSnapshot("assets");
766765
expect(getErrors(stats)).toMatchSnapshot("errors");
767766
expect(getWarnings(stats)).toMatchSnapshot("warnings");
768767
});

types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ declare namespace TerserPlugin {
8585
Rule,
8686
Rules,
8787
EXPECTED_ANY,
88+
EXPECTED_OBJECT,
8889
ExtractCommentsFunction,
8990
ExtractCommentsCondition,
9091
ExtractCommentsFilename,
@@ -131,6 +132,7 @@ type TraceMap = import("@jridgewell/trace-mapping").TraceMap;
131132
type Rule = RegExp | string;
132133
type Rules = Rule[] | Rule;
133134
type EXPECTED_ANY = any;
135+
type EXPECTED_OBJECT = object;
134136
type ExtractCommentsFunction = (
135137
astNode: EXPECTED_ANY,
136138
comment: {

types/utils.d.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,7 @@ export type Input = import("./index.js").Input;
1010
export type MinimizedResult = import("./index.js").MinimizedResult;
1111
export type CustomOptions = import("./index.js").CustomOptions;
1212
export type RawSourceMap = import("./index.js").RawSourceMap;
13-
export type SwcMinifyOptionsWithExtractComments =
14-
import("@swc/core").JsMinifyOptions & {
15-
extractComments?:
16-
| false
17-
| true
18-
| "some"
19-
| "all"
20-
| {
21-
regex: string;
22-
};
23-
};
24-
export type SwcMinifyOutput = import("@swc/core").Output & {
25-
extractedComments?: string[];
26-
};
13+
export type EXPECTED_OBJECT = import("./index.js").EXPECTED_OBJECT;
2714
export type PredefinedOptions<T> = import("./index.js").PredefinedOptions<T>;
2815
export type ExtractedComments = string[];
2916
/**

0 commit comments

Comments
 (0)