Enable jqhtml data caching with automatic ES6 class registration

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-12-07 18:24:12 +00:00
parent c4a338fe7c
commit 12e676f317
54 changed files with 3187 additions and 1007 deletions

363
node_modules/terser-webpack-plugin/dist/utils.js generated vendored Executable file → Normal file
View File

@@ -1,12 +1,12 @@
"use strict";
/** @typedef {import("@jridgewell/trace-mapping").SourceMapInput} SourceMapInput */
/** @typedef {import("./index.js").ExtractCommentsOptions} ExtractCommentsOptions */
/** @typedef {import("./index.js").ExtractCommentsFunction} ExtractCommentsFunction */
/** @typedef {import("./index.js").ExtractCommentsCondition} ExtractCommentsCondition */
/** @typedef {import("./index.js").Input} Input */
/** @typedef {import("./index.js").MinimizedResult} MinimizedResult */
/** @typedef {import("./index.js").CustomOptions} CustomOptions */
/** @typedef {import("./index.js").RawSourceMap} RawSourceMap */
/**
* @template T
@@ -17,7 +17,7 @@
* @typedef {Array<string>} ExtractedComments
*/
const notSettled = Symbol(`not-settled`);
const notSettled = Symbol("not-settled");
/**
* @template T
@@ -27,19 +27,15 @@ const notSettled = Symbol(`not-settled`);
/**
* Run tasks with limited concurrency.
* @template T
* @param {number} limit - Limit of tasks that run at once.
* @param {Task<T>[]} tasks - List of tasks to run.
* @param {number} limit Limit of tasks that run at once.
* @param {Task<T>[]} tasks List of tasks to run.
* @returns {Promise<T[]>} A promise that fulfills to an array of the results
*/
function throttleAll(limit, tasks) {
if (!Number.isInteger(limit) || limit < 1) {
throw new TypeError(`Expected \`limit\` to be a finite number > 0, got \`${limit}\` (${typeof limit})`);
}
if (!Array.isArray(tasks) || !tasks.every(task => typeof task === `function`)) {
throw new TypeError(`Expected \`tasks\` to be a list of functions returning a promise`);
}
return new Promise((resolve, reject) => {
const result = Array(tasks.length).fill(notSettled);
const result = Array.from({
length: tasks.length
}).fill(notSettled);
const entries = tasks.entries();
const next = () => {
const {
@@ -48,46 +44,51 @@ function throttleAll(limit, tasks) {
} = entries.next();
if (done) {
const isLast = !result.includes(notSettled);
if (isLast) resolve( /** @type{T[]} **/result);
if (isLast) resolve(result);
return;
}
const [index, task] = value;
/**
* @param {T} x
* @param {T} resultValue Result value
*/
const onFulfilled = x => {
result[index] = x;
const onFulfilled = resultValue => {
result[index] = resultValue;
next();
};
task().then(onFulfilled, reject);
};
Array(limit).fill(0).forEach(next);
for (let i = 0; i < limit; i++) {
next();
}
});
}
/* istanbul ignore next */
/**
* @param {Input} input
* @param {SourceMapInput | undefined} sourceMap
* @param {CustomOptions} minimizerOptions
* @param {ExtractCommentsOptions | undefined} extractComments
* @return {Promise<MinimizedResult>}
* @param {Input} input input
* @param {RawSourceMap=} sourceMap source map
* @param {CustomOptions=} minimizerOptions options
* @param {ExtractCommentsOptions=} extractComments extract comments option
* @returns {Promise<MinimizedResult>} minimized result
*/
async function terserMinify(input, sourceMap, minimizerOptions, extractComments) {
// eslint-disable-next-line jsdoc/no-restricted-syntax
/**
* @param {any} value
* @returns {boolean}
* @param {unknown} value value
* @returns {value is object} true when value is object or function
*/
const isObject = value => {
const type = typeof value;
// eslint-disable-next-line no-eq-null, eqeqeq
return value != null && (type === "object" || type === "function");
};
/**
* @param {import("terser").MinifyOptions & { sourceMap: undefined } & ({ output: import("terser").FormatOptions & { beautify: boolean } } | { format: import("terser").FormatOptions & { beautify: boolean } })} terserOptions
* @param {ExtractedComments} extractedComments
* @returns {ExtractCommentsFunction}
* @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
*/
const buildComments = (terserOptions, extractedComments) => {
/** @type {{ [index: string]: ExtractCommentsCondition }} */
@@ -119,7 +120,7 @@ async function terserMinify(input, sourceMap, minimizerOptions, extractComments)
}
// Ensure that both conditions are functions
["preserve", "extract"].forEach(key => {
for (const key of ["preserve", "extract"]) {
/** @type {undefined | string} */
let regexStr;
/** @type {undefined | RegExp} */
@@ -149,7 +150,7 @@ async function terserMinify(input, sourceMap, minimizerOptions, extractComments)
condition[key] = /** @type {ExtractCommentsFunction} */
(astNode, comment) => /** @type {RegExp} */regex.test(comment.value);
}
});
}
// Redefine the comments function to extract and preserve
// comments according to the two conditions
@@ -168,58 +169,63 @@ async function terserMinify(input, sourceMap, minimizerOptions, extractComments)
};
/**
* @param {PredefinedOptions<import("terser").MinifyOptions> & import("terser").MinifyOptions} [terserOptions={}]
* @returns {import("terser").MinifyOptions & { sourceMap: undefined } & { compress: import("terser").CompressOptions } & ({ output: import("terser").FormatOptions & { beautify: boolean } } | { format: import("terser").FormatOptions & { beautify: boolean } })}
* @param {PredefinedOptions<import("terser").MinifyOptions> & import("terser").MinifyOptions=} terserOptions terser options
* @returns {import("terser").MinifyOptions & { sourceMap: import("terser").SourceMapOptions | undefined } & { compress: import("terser").CompressOptions } & ({ output: import("terser").FormatOptions & { beautify: boolean } } | { format: import("terser").FormatOptions & { beautify: boolean } })} built terser options
*/
const buildTerserOptions = (terserOptions = {}) => {
// Need deep copy objects to avoid https://github.com/terser/terser/issues/366
const buildTerserOptions = (terserOptions = {}) => (
// Need deep copy objects to avoid https://github.com/terser/terser/issues/366
{
...terserOptions,
compress: typeof terserOptions.compress === "boolean" ? terserOptions.compress ? {} : false : {
...terserOptions.compress
},
// ecma: terserOptions.ecma,
// ie8: terserOptions.ie8,
// keep_classnames: terserOptions.keep_classnames,
// keep_fnames: terserOptions.keep_fnames,
mangle:
// eslint-disable-next-line no-eq-null, eqeqeq
terserOptions.mangle == null ? true : typeof terserOptions.mangle === "boolean" ? terserOptions.mangle : {
...terserOptions.mangle
},
// module: terserOptions.module,
// nameCache: { ...terserOptions.toplevel },
// the `output` option is deprecated
...(terserOptions.format ? {
format: {
beautify: false,
...terserOptions.format
}
} : {
output: {
beautify: false,
...terserOptions.output
}
}),
parse: {
...terserOptions.parse
},
// safari10: terserOptions.safari10,
// Ignoring sourceMap from options
sourceMap: undefined
// toplevel: terserOptions.toplevel
});
let minify;
try {
({
minify
} = require("terser"));
} catch (err) {
return {
...terserOptions,
compress: typeof terserOptions.compress === "boolean" ? terserOptions.compress ? {} : false : {
...terserOptions.compress
},
// ecma: terserOptions.ecma,
// ie8: terserOptions.ie8,
// keep_classnames: terserOptions.keep_classnames,
// keep_fnames: terserOptions.keep_fnames,
mangle: terserOptions.mangle == null ? true : typeof terserOptions.mangle === "boolean" ? terserOptions.mangle : {
...terserOptions.mangle
},
// module: terserOptions.module,
// nameCache: { ...terserOptions.toplevel },
// the `output` option is deprecated
...(terserOptions.format ? {
format: {
beautify: false,
...terserOptions.format
}
} : {
output: {
beautify: false,
...terserOptions.output
}
}),
parse: {
...terserOptions.parse
},
// safari10: terserOptions.safari10,
// Ignoring sourceMap from options
// eslint-disable-next-line no-undefined
sourceMap: undefined
// toplevel: terserOptions.toplevel
errors: [( /** @type {Error} */err)]
};
};
}
// eslint-disable-next-line global-require
const {
minify
} = require("terser");
// Copy `terser` options
const terserOptions = buildTerserOptions(minimizerOptions);
// Let terser generate a SourceMap
if (sourceMap) {
// @ts-ignore
terserOptions.sourceMap = {
asObject: true
};
@@ -248,55 +254,55 @@ async function terserMinify(input, sourceMap, minimizerOptions, extractComments)
[filename]: code
}, terserOptions);
return {
code: ( /** @type {string} **/result.code),
// @ts-ignore
// eslint-disable-next-line no-undefined
map: result.map ? ( /** @type {SourceMapInput} **/result.map) : undefined,
code: ( /** @type {string} * */result.code),
map: result.map ? ( /** @type {RawSourceMap} * */result.map) : undefined,
extractedComments
};
}
/**
* @returns {string | undefined}
* @returns {string | undefined} the minimizer version
*/
terserMinify.getMinimizerVersion = () => {
let packageJson;
try {
// eslint-disable-next-line global-require
packageJson = require("terser/package.json");
} catch (error) {
} catch (_err) {
// Ignore
}
return packageJson && packageJson.version;
};
/**
* @returns {boolean | undefined}
* @returns {boolean | undefined} true if worker thread is supported, false otherwise
*/
terserMinify.supportsWorkerThreads = () => true;
/* istanbul ignore next */
/**
* @param {Input} input
* @param {SourceMapInput | undefined} sourceMap
* @param {CustomOptions} minimizerOptions
* @param {ExtractCommentsOptions | undefined} extractComments
* @return {Promise<MinimizedResult>}
* @param {Input} input input
* @param {RawSourceMap=} sourceMap source map
* @param {CustomOptions=} minimizerOptions options
* @param {ExtractCommentsOptions=} extractComments extract comments option
* @returns {Promise<MinimizedResult>} minimized result
*/
async function uglifyJsMinify(input, sourceMap, minimizerOptions, extractComments) {
// eslint-disable-next-line jsdoc/no-restricted-syntax
/**
* @param {any} value
* @returns {boolean}
* @param {unknown} value value
* @returns {value is object} true when value is object or function
*/
const isObject = value => {
const type = typeof value;
// eslint-disable-next-line no-eq-null, eqeqeq
return value != null && (type === "object" || type === "function");
};
/**
* @param {import("uglify-js").MinifyOptions & { sourceMap: undefined } & { output: import("uglify-js").OutputOptions & { beautify: boolean }}} uglifyJsOptions
* @param {ExtractedComments} extractedComments
* @returns {ExtractCommentsFunction}
* @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
*/
const buildComments = (uglifyJsOptions, extractedComments) => {
/** @type {{ [index: string]: ExtractCommentsCondition }} */
@@ -321,7 +327,7 @@ async function uglifyJsMinify(input, sourceMap, minimizerOptions, extractComment
}
// Ensure that both conditions are functions
["preserve", "extract"].forEach(key => {
for (const key of ["preserve", "extract"]) {
/** @type {undefined | string} */
let regexStr;
/** @type {undefined | RegExp} */
@@ -351,7 +357,7 @@ async function uglifyJsMinify(input, sourceMap, minimizerOptions, extractComment
condition[key] = /** @type {ExtractCommentsFunction} */
(astNode, comment) => /** @type {RegExp} */regex.test(comment.value);
}
});
}
// Redefine the comments function to extract and preserve
// comments according to the two conditions
@@ -370,14 +376,16 @@ async function uglifyJsMinify(input, sourceMap, minimizerOptions, extractComment
};
/**
* @param {PredefinedOptions<import("uglify-js").MinifyOptions> & import("uglify-js").MinifyOptions} [uglifyJsOptions={}]
* @returns {import("uglify-js").MinifyOptions & { sourceMap: undefined } & { output: import("uglify-js").OutputOptions & { beautify: boolean }}}
* @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
*/
const buildUglifyJsOptions = (uglifyJsOptions = {}) => {
// eslint-disable-next-line no-param-reassign
delete minimizerOptions.ecma;
// eslint-disable-next-line no-param-reassign
delete minimizerOptions.module;
if (typeof uglifyJsOptions.ecma !== "undefined") {
delete uglifyJsOptions.ecma;
}
if (typeof uglifyJsOptions.module !== "undefined") {
delete uglifyJsOptions.module;
}
// Need deep copy objects to avoid https://github.com/terser/terser/issues/366
return {
@@ -389,7 +397,9 @@ async function uglifyJsMinify(input, sourceMap, minimizerOptions, extractComment
compress: typeof uglifyJsOptions.compress === "boolean" ? uglifyJsOptions.compress : {
...uglifyJsOptions.compress
},
mangle: uglifyJsOptions.mangle == null ? true : typeof uglifyJsOptions.mangle === "boolean" ? uglifyJsOptions.mangle : {
mangle:
// eslint-disable-next-line no-eq-null, eqeqeq
uglifyJsOptions.mangle == null ? true : typeof uglifyJsOptions.mangle === "boolean" ? uglifyJsOptions.mangle : {
...uglifyJsOptions.mangle
},
output: {
@@ -397,7 +407,7 @@ async function uglifyJsMinify(input, sourceMap, minimizerOptions, extractComment
...uglifyJsOptions.output
},
// Ignoring sourceMap from options
// eslint-disable-next-line no-undefined
sourceMap: undefined
// toplevel: uglifyJsOptions.toplevel
// nameCache: { ...uglifyJsOptions.toplevel },
@@ -405,25 +415,29 @@ async function uglifyJsMinify(input, sourceMap, minimizerOptions, extractComment
// keep_fnames: uglifyJsOptions.keep_fnames,
};
};
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
const {
minify
} = require("uglify-js");
let minify;
try {
({
minify
} = require("uglify-js"));
} catch (err) {
return {
errors: [( /** @type {Error} */err)]
};
}
// Copy `uglify-js` options
const uglifyJsOptions = buildUglifyJsOptions(minimizerOptions);
// Let terser generate a SourceMap
if (sourceMap) {
// @ts-ignore
uglifyJsOptions.sourceMap = true;
}
/** @type {ExtractedComments} */
const extractedComments = [];
// @ts-ignore
// @ts-expect-error wrong types in uglify-js
uglifyJsOptions.output.comments = buildComments(uglifyJsOptions, extractedComments);
const [[filename, code]] = Object.entries(input);
const result = await minify({
@@ -431,7 +445,6 @@ async function uglifyJsMinify(input, sourceMap, minimizerOptions, extractComment
}, uglifyJsOptions);
return {
code: result.code,
// eslint-disable-next-line no-undefined
map: result.map ? JSON.parse(result.map) : undefined,
errors: result.error ? [result.error] : [],
warnings: result.warnings || [],
@@ -440,65 +453,70 @@ async function uglifyJsMinify(input, sourceMap, minimizerOptions, extractComment
}
/**
* @returns {string | undefined}
* @returns {string | undefined} the minimizer version
*/
uglifyJsMinify.getMinimizerVersion = () => {
let packageJson;
try {
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
packageJson = require("uglify-js/package.json");
} catch (error) {
} catch (_err) {
// Ignore
}
return packageJson && packageJson.version;
};
/**
* @returns {boolean | undefined}
* @returns {boolean | undefined} true if worker thread is supported, false otherwise
*/
uglifyJsMinify.supportsWorkerThreads = () => true;
/* istanbul ignore next */
/**
* @param {Input} input
* @param {SourceMapInput | undefined} sourceMap
* @param {CustomOptions} minimizerOptions
* @return {Promise<MinimizedResult>}
* @param {Input} input input
* @param {RawSourceMap=} sourceMap source map
* @param {CustomOptions=} minimizerOptions options
* @returns {Promise<MinimizedResult>} minimized result
*/
async function swcMinify(input, sourceMap, minimizerOptions) {
/**
* @param {PredefinedOptions<import("@swc/core").JsMinifyOptions> & import("@swc/core").JsMinifyOptions} [swcOptions={}]
* @returns {import("@swc/core").JsMinifyOptions & { sourceMap: undefined } & { compress: import("@swc/core").TerserCompressOptions }}
* @param {PredefinedOptions<import("@swc/core").JsMinifyOptions> & import("@swc/core").JsMinifyOptions=} swcOptions swc options
* @returns {import("@swc/core").JsMinifyOptions & { sourceMap: undefined | boolean } & { compress: import("@swc/core").TerserCompressOptions }} built swc options
*/
const buildSwcOptions = (swcOptions = {}) => {
// Need deep copy objects to avoid https://github.com/terser/terser/issues/366
return {
...swcOptions,
compress: typeof swcOptions.compress === "boolean" ? swcOptions.compress ? {} : false : {
...swcOptions.compress
},
mangle: swcOptions.mangle == null ? true : typeof swcOptions.mangle === "boolean" ? swcOptions.mangle : {
...swcOptions.mangle
},
// ecma: swcOptions.ecma,
// keep_classnames: swcOptions.keep_classnames,
// keep_fnames: swcOptions.keep_fnames,
// module: swcOptions.module,
// safari10: swcOptions.safari10,
// toplevel: swcOptions.toplevel
// eslint-disable-next-line no-undefined
sourceMap: undefined
};
};
const buildSwcOptions = (swcOptions = {}) => (
// Need deep copy objects to avoid https://github.com/terser/terser/issues/366
{
...swcOptions,
compress: typeof swcOptions.compress === "boolean" ? swcOptions.compress ? {} : false : {
...swcOptions.compress
},
mangle:
// eslint-disable-next-line no-eq-null, eqeqeq
swcOptions.mangle == null ? true : typeof swcOptions.mangle === "boolean" ? swcOptions.mangle : {
...swcOptions.mangle
},
// ecma: swcOptions.ecma,
// keep_classnames: swcOptions.keep_classnames,
// keep_fnames: swcOptions.keep_fnames,
// module: swcOptions.module,
// safari10: swcOptions.safari10,
// toplevel: swcOptions.toplevel
sourceMap: undefined
});
let swc;
try {
swc = require("@swc/core");
} catch (err) {
return {
errors: [( /** @type {Error} */err)]
};
}
// eslint-disable-next-line import/no-extraneous-dependencies, global-require
const swc = require("@swc/core");
// Copy `swc` options
const swcOptions = buildSwcOptions(minimizerOptions);
// Let `swc` generate a SourceMap
if (sourceMap) {
// @ts-ignore
swcOptions.sourceMap = true;
}
if (swcOptions.compress) {
@@ -529,45 +547,40 @@ async function swcMinify(input, sourceMap, minimizerOptions) {
}
/**
* @returns {string | undefined}
* @returns {string | undefined} the minimizer version
*/
swcMinify.getMinimizerVersion = () => {
let packageJson;
try {
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
packageJson = require("@swc/core/package.json");
} catch (error) {
} catch (_err) {
// Ignore
}
return packageJson && packageJson.version;
};
/**
* @returns {boolean | undefined}
* @returns {boolean | undefined} true if worker thread is supported, false otherwise
*/
swcMinify.supportsWorkerThreads = () => false;
/* istanbul ignore next */
/**
* @param {Input} input
* @param {SourceMapInput | undefined} sourceMap
* @param {CustomOptions} minimizerOptions
* @return {Promise<MinimizedResult>}
* @param {Input} input input
* @param {RawSourceMap=} sourceMap source map
* @param {CustomOptions=} minimizerOptions options
* @returns {Promise<MinimizedResult>} minimized result
*/
async function esbuildMinify(input, sourceMap, minimizerOptions) {
/**
* @param {PredefinedOptions<import("esbuild").TransformOptions> & import("esbuild").TransformOptions} [esbuildOptions={}]
* @returns {import("esbuild").TransformOptions}
* @param {PredefinedOptions<import("esbuild").TransformOptions> & import("esbuild").TransformOptions=} esbuildOptions esbuild options
* @returns {import("esbuild").TransformOptions} built esbuild options
*/
const buildEsbuildOptions = (esbuildOptions = {}) => {
// eslint-disable-next-line no-param-reassign
delete esbuildOptions.ecma;
if (esbuildOptions.module) {
// eslint-disable-next-line no-param-reassign
esbuildOptions.format = "esm";
}
// eslint-disable-next-line no-param-reassign
delete esbuildOptions.module;
// Need deep copy objects to avoid https://github.com/terser/terser/issues/366
@@ -578,9 +591,14 @@ async function esbuildMinify(input, sourceMap, minimizerOptions) {
sourcemap: false
};
};
// eslint-disable-next-line import/no-extraneous-dependencies, global-require
const esbuild = require("esbuild");
let esbuild;
try {
esbuild = require("esbuild");
} catch (err) {
return {
errors: [( /** @type {Error} */err)]
};
}
// Copy `esbuild` options
const esbuildOptions = buildEsbuildOptions(minimizerOptions);
@@ -595,7 +613,6 @@ async function esbuildMinify(input, sourceMap, minimizerOptions) {
const result = await esbuild.transform(code, esbuildOptions);
return {
code: result.code,
// eslint-disable-next-line no-undefined
map: result.map ? JSON.parse(result.map) : undefined,
warnings: result.warnings.length > 0 ? result.warnings.map(item => {
const plugin = item.pluginName ? `\nPlugin Name: ${item.pluginName}` : "";
@@ -607,28 +624,32 @@ async function esbuildMinify(input, sourceMap, minimizerOptions) {
}
/**
* @returns {string | undefined}
* @returns {string | undefined} the minimizer version
*/
esbuildMinify.getMinimizerVersion = () => {
let packageJson;
try {
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
packageJson = require("esbuild/package.json");
} catch (error) {
} catch (_err) {
// Ignore
}
return packageJson && packageJson.version;
};
/**
* @returns {boolean | undefined}
* @returns {boolean | undefined} true if worker thread is supported, false otherwise
*/
esbuildMinify.supportsWorkerThreads = () => false;
/**
* @template T
* @param fn {(function(): any) | undefined}
* @returns {function(): T}
* @typedef {() => T} FunctionReturning
*/
/**
* @template T
* @param {FunctionReturning<T>} fn memorized function
* @returns {FunctionReturning<T>} new function
*/
function memoize(fn) {
let cache = false;
@@ -638,20 +659,20 @@ function memoize(fn) {
if (cache) {
return result;
}
result = /** @type {function(): any} */fn();
result = fn();
cache = true;
// Allow to clean up memory for fn
// and all dependent resources
// eslint-disable-next-line no-undefined, no-param-reassign
/** @type {FunctionReturning<T> | undefined} */
fn = undefined;
return result;
return /** @type {T} */result;
};
}
module.exports = {
throttleAll,
esbuildMinify,
memoize,
terserMinify,
uglifyJsMinify,
swcMinify,
esbuildMinify
terserMinify,
throttleAll,
uglifyJsMinify
};