mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-16 00:48:31 +01:00
176e83a79f
Deleted legacy files, neatened args in other ported ops
57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
/**
|
|
* @author n1474335 [n1474335@gmail.com]
|
|
* @copyright Crown Copyright 2016
|
|
* @license Apache-2.0
|
|
*/
|
|
|
|
import Operation from "../Operation";
|
|
import * as esprima from "esprima";
|
|
import escodegen from "escodegen";
|
|
import esmangle from "esmangle";
|
|
|
|
/**
|
|
* JavaScript Minify operation
|
|
*/
|
|
class JavaScriptMinify extends Operation {
|
|
|
|
/**
|
|
* JavaScriptMinify constructor
|
|
*/
|
|
constructor() {
|
|
super();
|
|
|
|
this.name = "JavaScript Minify";
|
|
this.module = "Code";
|
|
this.description = "Compresses JavaScript code.";
|
|
this.inputType = "string";
|
|
this.outputType = "string";
|
|
this.args = [];
|
|
}
|
|
|
|
/**
|
|
* @param {string} input
|
|
* @param {Object[]} args
|
|
* @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;
|
|
}
|
|
|
|
}
|
|
|
|
export default JavaScriptMinify;
|