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": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz",
|
||||
"integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU="
|
||||
"integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=",
|
||||
"dev": true
|
||||
},
|
||||
"ansi-colors": {
|
||||
"version": "3.2.4",
|
||||
@ -2809,8 +2810,7 @@
|
||||
"buffer-from": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
|
||||
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
|
||||
"dev": true
|
||||
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A=="
|
||||
},
|
||||
"buffer-indexof": {
|
||||
"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": {
|
||||
"version": "6.2.2",
|
||||
"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",
|
||||
"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": {
|
||||
"version": "6.1.1",
|
||||
"resolved": "https://registry.npmjs.org/espree/-/espree-6.1.1.tgz",
|
||||
@ -5235,23 +5137,6 @@
|
||||
"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": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.2.0.tgz",
|
||||
@ -12156,10 +12041,9 @@
|
||||
}
|
||||
},
|
||||
"source-map-support": {
|
||||
"version": "0.5.13",
|
||||
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.13.tgz",
|
||||
"integrity": "sha512-SHSKFHadjVA5oR4PPqhtAVdcBWwRYVd6g6cAXnIbRiIwc2EhPrTuKUBdSLvlEKyIP3GCf89fltvcZiP9MMFA1w==",
|
||||
"dev": true,
|
||||
"version": "0.5.16",
|
||||
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.16.tgz",
|
||||
"integrity": "sha512-efyLRJDr68D9hBBNIPWFjhpFzURh+KJykQwvMyW5UiZzYwoF6l4YMMDIJJEyFWxWCqfyxLzz6tSfUFR+kXXsVQ==",
|
||||
"requires": {
|
||||
"buffer-from": "^1.0.0",
|
||||
"source-map": "^0.6.0"
|
||||
@ -12809,10 +12693,9 @@
|
||||
}
|
||||
},
|
||||
"terser": {
|
||||
"version": "4.2.1",
|
||||
"resolved": "https://registry.npmjs.org/terser/-/terser-4.2.1.tgz",
|
||||
"integrity": "sha512-cGbc5utAcX4a9+2GGVX4DsenG6v0x3glnDi5hx8816X1McEAwPlPgRtXPJzSBsbpILxZ8MQMT0KvArLuE0HP5A==",
|
||||
"dev": true,
|
||||
"version": "4.3.9",
|
||||
"resolved": "https://registry.npmjs.org/terser/-/terser-4.3.9.tgz",
|
||||
"integrity": "sha512-NFGMpHjlzmyOtPL+fDw3G7+6Ueh/sz4mkaUYa4lJCxOPTNzd0Uj0aZJOmsDYoSQyfuVoWDMSWTPU3huyOm2zdA==",
|
||||
"requires": {
|
||||
"commander": "^2.20.0",
|
||||
"source-map": "~0.6.1",
|
||||
|
@ -106,7 +106,6 @@
|
||||
"es6-promisify": "^6.0.2",
|
||||
"escodegen": "^1.12.0",
|
||||
"esm": "^3.2.25",
|
||||
"esmangle": "^1.0.1",
|
||||
"esprima": "^4.0.1",
|
||||
"exif-parser": "^0.1.12",
|
||||
"file-saver": "^2.0.2",
|
||||
@ -144,6 +143,7 @@
|
||||
"sortablejs": "^1.9.0",
|
||||
"split.js": "^1.5.11",
|
||||
"ssdeep.js": "0.0.2",
|
||||
"terser": "^4.3.9",
|
||||
"tesseract.js": "^2.0.0-alpha.15",
|
||||
"ua-parser-js": "^0.7.20",
|
||||
"utf8": "^3.0.0",
|
||||
|
@ -4,10 +4,9 @@
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import Operation from "../Operation.mjs";
|
||||
import * as esprima from "esprima";
|
||||
import escodegen from "escodegen";
|
||||
import esmangle from "esmangle";
|
||||
import Terser from "terser";
|
||||
|
||||
/**
|
||||
* JavaScript Minify operation
|
||||
@ -34,22 +33,11 @@ class JavaScriptMinify extends Operation {
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
let result = "";
|
||||
const AST = esprima.parseScript(input),
|
||||
optimisedAST = esmangle.optimize(AST, null),
|
||||
mangledAST = esmangle.mangle(optimisedAST);
|
||||
|
||||
result = escodegen.generate(mangledAST, {
|
||||
format: {
|
||||
renumber: true,
|
||||
hexadecimal: true,
|
||||
escapeless: true,
|
||||
compact: true,
|
||||
semicolons: false,
|
||||
parentheses: false
|
||||
}
|
||||
});
|
||||
return result;
|
||||
const result = Terser.minify(input);
|
||||
if (result.error) {
|
||||
throw new OperationError(`Error minifying JavaScript. (${result.error})`);
|
||||
}
|
||||
return result.code;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user