Skip to content

Commit

Permalink
Simplified minify.options.mangle to boolean that cannot touch top-l…
Browse files Browse the repository at this point in the history
…evel names
  • Loading branch information
adamlui committed May 13, 2024
1 parent b3ca2b0 commit 43f94a9
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions node.js/src/minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function minify(input, options = {}) {
options = { ...defaultOptions, ...options }; // merge validated options w/ missing default ones

// Minify JS based on input
const minifyOptions = { mangle: options.mangle };
const minifyOptions = { mangle: options.mangle ? { toplevel: false } : false };
if (fs.existsSync(input)) { // minify based on path arg
if (input.endsWith('.js')) { // file path passed
if (options.verbose) console.info(`minify() » ** Minifying ${input}...`);
Expand Down Expand Up @@ -192,22 +192,9 @@ function validateOptions(options, defaultOptions, docURL, exampleCall) {
if (key != 'isRecursing' && !Object.prototype.hasOwnProperty.call(defaultOptions, key)) {
console.error(`${ logPrefix }ERROR: \`${key}\` is an invalid option.`);
printValidOptions(); printDocURL(); return false;
} else if (booleanOptions.includes(key)) {
if (key == 'mangle') {
const printMangleErr = () => console.error(
`${ logPrefix }ERROR: [mangle] option can only be \`true\`, \`false\`,`
+ ' or an object w/ key [toplevel] set to `true` or `false`.');
if (typeof options.mangle == 'object')
for (const mangleKey in options.mangle) {
if (!['toplevel'].includes(mangleKey) || typeof options.mangle[mangleKey] != 'boolean') {
printMangleErr(); printDocURL(); return false; }
}
else if (typeof options.mangle != 'boolean') {
printMangleErr(); printDocURL(); return false; }
} else if (typeof options[key] != 'boolean') {
console.error(`${ logPrefix }ERROR: [${key}] option can only be \`true\` or \`false\`.`);
printDocURL(); return false;
}
} else if (booleanOptions.includes(key) && typeof options[key] != 'boolean') {
console.error(`${ logPrefix }ERROR: [${key}] option can only be \`true\` or \`false\`.`);
printDocURL(); return false;
} else if (integerOptions.includes(key)) {
options[key] = parseInt(options[key], 10);
if (isNaN(options[key]) || options[key] < 1) {
Expand Down

0 comments on commit 43f94a9

Please sign in to comment.