Update JavaScript Minify operation to support ES6.
This commit is contained in:
parent
734962ac22
commit
462f619f43
135
package-lock.json
generated
135
package-lock.json
generated
@ -1807,7 +1807,8 @@
|
|||||||
"amdefine": {
|
"amdefine": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz",
|
||||||
"integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU="
|
"integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=",
|
||||||
|
"dev": true
|
||||||
},
|
},
|
||||||
"ansi-colors": {
|
"ansi-colors": {
|
||||||
"version": "3.2.4",
|
"version": "3.2.4",
|
||||||
@ -2809,8 +2810,7 @@
|
|||||||
"buffer-from": {
|
"buffer-from": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
|
||||||
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
|
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"buffer-indexof": {
|
"buffer-indexof": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
@ -4923,21 +4923,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"escope": {
|
|
||||||
"version": "1.0.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/escope/-/escope-1.0.3.tgz",
|
|
||||||
"integrity": "sha1-dZ3OhJbEJI/sLQyq9BCLzz8af10=",
|
|
||||||
"requires": {
|
|
||||||
"estraverse": "^2.0.0"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"estraverse": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/estraverse/-/estraverse-2.0.0.tgz",
|
|
||||||
"integrity": "sha1-WuRpYyQ2ACBmdMyySgnhZnT83KE="
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"eslint": {
|
"eslint": {
|
||||||
"version": "6.2.2",
|
"version": "6.2.2",
|
||||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-6.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/eslint/-/eslint-6.2.2.tgz",
|
||||||
@ -5110,89 +5095,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz",
|
"resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz",
|
||||||
"integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA=="
|
"integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA=="
|
||||||
},
|
},
|
||||||
"esmangle": {
|
|
||||||
"version": "1.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/esmangle/-/esmangle-1.0.1.tgz",
|
|
||||||
"integrity": "sha1-2bs3uPjq+/Tm1O1reqKVarvTxMI=",
|
|
||||||
"requires": {
|
|
||||||
"escodegen": "~1.3.2",
|
|
||||||
"escope": "~1.0.1",
|
|
||||||
"esprima": "~1.1.1",
|
|
||||||
"esshorten": "~1.1.0",
|
|
||||||
"estraverse": "~1.5.0",
|
|
||||||
"esutils": "~ 1.0.0",
|
|
||||||
"optionator": "~0.3.0",
|
|
||||||
"source-map": "~0.1.33"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"escodegen": {
|
|
||||||
"version": "1.3.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/escodegen/-/escodegen-1.3.3.tgz",
|
|
||||||
"integrity": "sha1-8CQBb1qI4Eb9EgBQVek5gC5sXyM=",
|
|
||||||
"requires": {
|
|
||||||
"esprima": "~1.1.1",
|
|
||||||
"estraverse": "~1.5.0",
|
|
||||||
"esutils": "~1.0.0",
|
|
||||||
"source-map": "~0.1.33"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"esprima": {
|
|
||||||
"version": "1.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/esprima/-/esprima-1.1.1.tgz",
|
|
||||||
"integrity": "sha1-W28VR/TRAuZw4UDFCb5ncdautUk="
|
|
||||||
},
|
|
||||||
"estraverse": {
|
|
||||||
"version": "1.5.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/estraverse/-/estraverse-1.5.1.tgz",
|
|
||||||
"integrity": "sha1-hno+jlip+EYYr7bC3bzZFrfLr3E="
|
|
||||||
},
|
|
||||||
"esutils": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/esutils/-/esutils-1.0.0.tgz",
|
|
||||||
"integrity": "sha1-gVHTWOIMisx/t0XnRywAJf5JZXA="
|
|
||||||
},
|
|
||||||
"fast-levenshtein": {
|
|
||||||
"version": "1.0.7",
|
|
||||||
"resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-1.0.7.tgz",
|
|
||||||
"integrity": "sha1-AXjc3uAjuSkFGTrwlZ6KdjnP3Lk="
|
|
||||||
},
|
|
||||||
"levn": {
|
|
||||||
"version": "0.2.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/levn/-/levn-0.2.5.tgz",
|
|
||||||
"integrity": "sha1-uo0znQykphDjo/FFucr0iAcVUFQ=",
|
|
||||||
"requires": {
|
|
||||||
"prelude-ls": "~1.1.0",
|
|
||||||
"type-check": "~0.3.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"optionator": {
|
|
||||||
"version": "0.3.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/optionator/-/optionator-0.3.0.tgz",
|
|
||||||
"integrity": "sha1-lxWotfXnWGz/BsgkngOc1zZNP1Q=",
|
|
||||||
"requires": {
|
|
||||||
"deep-is": "~0.1.2",
|
|
||||||
"fast-levenshtein": "~1.0.0",
|
|
||||||
"levn": "~0.2.4",
|
|
||||||
"prelude-ls": "~1.1.0",
|
|
||||||
"type-check": "~0.3.1",
|
|
||||||
"wordwrap": "~0.0.2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"source-map": {
|
|
||||||
"version": "0.1.43",
|
|
||||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.1.43.tgz",
|
|
||||||
"integrity": "sha1-wkvBRspRfBRx9drL4lcbK3+eM0Y=",
|
|
||||||
"requires": {
|
|
||||||
"amdefine": ">=0.0.4"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"wordwrap": {
|
|
||||||
"version": "0.0.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz",
|
|
||||||
"integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc="
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"espree": {
|
"espree": {
|
||||||
"version": "6.1.1",
|
"version": "6.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/espree/-/espree-6.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/espree/-/espree-6.1.1.tgz",
|
||||||
@ -5235,23 +5137,6 @@
|
|||||||
"estraverse": "^4.1.0"
|
"estraverse": "^4.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"esshorten": {
|
|
||||||
"version": "1.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/esshorten/-/esshorten-1.1.1.tgz",
|
|
||||||
"integrity": "sha1-F0+Wt8wmfkaHLYFOfbfCkL3/Yak=",
|
|
||||||
"requires": {
|
|
||||||
"escope": "~1.0.1",
|
|
||||||
"estraverse": "~4.1.1",
|
|
||||||
"esutils": "~2.0.2"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"estraverse": {
|
|
||||||
"version": "4.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.1.1.tgz",
|
|
||||||
"integrity": "sha1-9srKcokzqFDvkGYdDheYK6RxEaI="
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"estraverse": {
|
"estraverse": {
|
||||||
"version": "4.2.0",
|
"version": "4.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.2.0.tgz",
|
||||||
@ -12156,10 +12041,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"source-map-support": {
|
"source-map-support": {
|
||||||
"version": "0.5.13",
|
"version": "0.5.16",
|
||||||
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.13.tgz",
|
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.16.tgz",
|
||||||
"integrity": "sha512-SHSKFHadjVA5oR4PPqhtAVdcBWwRYVd6g6cAXnIbRiIwc2EhPrTuKUBdSLvlEKyIP3GCf89fltvcZiP9MMFA1w==",
|
"integrity": "sha512-efyLRJDr68D9hBBNIPWFjhpFzURh+KJykQwvMyW5UiZzYwoF6l4YMMDIJJEyFWxWCqfyxLzz6tSfUFR+kXXsVQ==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"buffer-from": "^1.0.0",
|
"buffer-from": "^1.0.0",
|
||||||
"source-map": "^0.6.0"
|
"source-map": "^0.6.0"
|
||||||
@ -12809,10 +12693,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"terser": {
|
"terser": {
|
||||||
"version": "4.2.1",
|
"version": "4.3.9",
|
||||||
"resolved": "https://registry.npmjs.org/terser/-/terser-4.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/terser/-/terser-4.3.9.tgz",
|
||||||
"integrity": "sha512-cGbc5utAcX4a9+2GGVX4DsenG6v0x3glnDi5hx8816X1McEAwPlPgRtXPJzSBsbpILxZ8MQMT0KvArLuE0HP5A==",
|
"integrity": "sha512-NFGMpHjlzmyOtPL+fDw3G7+6Ueh/sz4mkaUYa4lJCxOPTNzd0Uj0aZJOmsDYoSQyfuVoWDMSWTPU3huyOm2zdA==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"commander": "^2.20.0",
|
"commander": "^2.20.0",
|
||||||
"source-map": "~0.6.1",
|
"source-map": "~0.6.1",
|
||||||
|
@ -106,7 +106,6 @@
|
|||||||
"es6-promisify": "^6.0.2",
|
"es6-promisify": "^6.0.2",
|
||||||
"escodegen": "^1.12.0",
|
"escodegen": "^1.12.0",
|
||||||
"esm": "^3.2.25",
|
"esm": "^3.2.25",
|
||||||
"esmangle": "^1.0.1",
|
|
||||||
"esprima": "^4.0.1",
|
"esprima": "^4.0.1",
|
||||||
"exif-parser": "^0.1.12",
|
"exif-parser": "^0.1.12",
|
||||||
"file-saver": "^2.0.2",
|
"file-saver": "^2.0.2",
|
||||||
@ -144,6 +143,7 @@
|
|||||||
"sortablejs": "^1.9.0",
|
"sortablejs": "^1.9.0",
|
||||||
"split.js": "^1.5.11",
|
"split.js": "^1.5.11",
|
||||||
"ssdeep.js": "0.0.2",
|
"ssdeep.js": "0.0.2",
|
||||||
|
"terser": "^4.3.9",
|
||||||
"tesseract.js": "^2.0.0-alpha.15",
|
"tesseract.js": "^2.0.0-alpha.15",
|
||||||
"ua-parser-js": "^0.7.20",
|
"ua-parser-js": "^0.7.20",
|
||||||
"utf8": "^3.0.0",
|
"utf8": "^3.0.0",
|
||||||
|
@ -4,10 +4,9 @@
|
|||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import OperationError from "../errors/OperationError.mjs";
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
import * as esprima from "esprima";
|
import Terser from "terser";
|
||||||
import escodegen from "escodegen";
|
|
||||||
import esmangle from "esmangle";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JavaScript Minify operation
|
* JavaScript Minify operation
|
||||||
@ -34,22 +33,11 @@ class JavaScriptMinify extends Operation {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
let result = "";
|
const result = Terser.minify(input);
|
||||||
const AST = esprima.parseScript(input),
|
if (result.error) {
|
||||||
optimisedAST = esmangle.optimize(AST, null),
|
throw new OperationError(`Error minifying JavaScript. (${result.error})`);
|
||||||
mangledAST = esmangle.mangle(optimisedAST);
|
}
|
||||||
|
return result.code;
|
||||||
result = escodegen.generate(mangledAST, {
|
|
||||||
format: {
|
|
||||||
renumber: true,
|
|
||||||
hexadecimal: true,
|
|
||||||
escapeless: true,
|
|
||||||
compact: true,
|
|
||||||
semicolons: false,
|
|
||||||
parentheses: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user