1
0
mirror of https://github.com/S2-/minifyfromhtml.git synced 2025-08-03 04:10:04 +02:00

update node modules

This commit is contained in:
s2
2021-05-07 15:56:33 +02:00
parent d81e8e9fb8
commit 3ec373077c
550 changed files with 84712 additions and 15991 deletions

1862
node_modules/terser/lib/ast.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

477
node_modules/terser/lib/cli.js generated vendored Normal file
View File

@@ -0,0 +1,477 @@
import { minify, _default_options } from "../main.js";
import { parse } from "./parse.js";
import {
AST_Assign,
AST_Array,
AST_Constant,
AST_Node,
AST_PropAccess,
AST_RegExp,
AST_Sequence,
AST_Symbol,
AST_Token,
walk
} from "./ast.js";
import { OutputStream } from "./output.js";
export async function run_cli({ program, packageJson, fs, path }) {
const skip_keys = new Set([ "cname", "parent_scope", "scope", "uses_eval", "uses_with" ]);
var files = {};
var options = {
compress: false,
mangle: false
};
const default_options = await _default_options();
program.version(packageJson.name + " " + packageJson.version);
program.parseArgv = program.parse;
program.parse = undefined;
if (process.argv.includes("ast")) program.helpInformation = describe_ast;
else if (process.argv.includes("options")) program.helpInformation = function() {
var text = [];
for (var option in default_options) {
text.push("--" + (option === "sourceMap" ? "source-map" : option) + " options:");
text.push(format_object(default_options[option]));
text.push("");
}
return text.join("\n");
};
program.option("-p, --parse <options>", "Specify parser options.", parse_js());
program.option("-c, --compress [options]", "Enable compressor/specify compressor options.", parse_js());
program.option("-m, --mangle [options]", "Mangle names/specify mangler options.", parse_js());
program.option("--mangle-props [options]", "Mangle properties/specify mangler options.", parse_js());
program.option("-f, --format [options]", "Format options.", parse_js());
program.option("-b, --beautify [options]", "Alias for --format.", parse_js());
program.option("-o, --output <file>", "Output file (default STDOUT).");
program.option("--comments [filter]", "Preserve copyright comments in the output.");
program.option("--config-file <file>", "Read minify() options from JSON file.");
program.option("-d, --define <expr>[=value]", "Global definitions.", parse_js("define"));
program.option("--ecma <version>", "Specify ECMAScript release: 5, 2015, 2016 or 2017...");
program.option("-e, --enclose [arg[,...][:value[,...]]]", "Embed output in a big function with configurable arguments and values.");
program.option("--ie8", "Support non-standard Internet Explorer 8.");
program.option("--keep-classnames", "Do not mangle/drop class names.");
program.option("--keep-fnames", "Do not mangle/drop function names. Useful for code relying on Function.prototype.name.");
program.option("--module", "Input is an ES6 module");
program.option("--name-cache <file>", "File to hold mangled name mappings.");
program.option("--rename", "Force symbol expansion.");
program.option("--no-rename", "Disable symbol expansion.");
program.option("--safari10", "Support non-standard Safari 10.");
program.option("--source-map [options]", "Enable source map/specify source map options.", parse_js());
program.option("--timings", "Display operations run time on STDERR.");
program.option("--toplevel", "Compress and/or mangle variables in toplevel scope.");
program.option("--wrap <name>", "Embed everything as a function with “exports” corresponding to “name” globally.");
program.arguments("[files...]").parseArgv(process.argv);
if (program.configFile) {
options = JSON.parse(read_file(program.configFile));
}
if (!program.output && program.sourceMap && program.sourceMap.url != "inline") {
fatal("ERROR: cannot write source map to STDOUT");
}
[
"compress",
"enclose",
"ie8",
"mangle",
"module",
"safari10",
"sourceMap",
"toplevel",
"wrap"
].forEach(function(name) {
if (name in program) {
options[name] = program[name];
}
});
if ("ecma" in program) {
if (program.ecma != (program.ecma | 0)) fatal("ERROR: ecma must be an integer");
const ecma = program.ecma | 0;
if (ecma > 5 && ecma < 2015)
options.ecma = ecma + 2009;
else
options.ecma = ecma;
}
if (program.format || program.beautify) {
const chosenOption = program.format || program.beautify;
options.format = typeof chosenOption === "object" ? chosenOption : {};
}
if (program.comments) {
if (typeof options.format != "object") options.format = {};
options.format.comments = typeof program.comments == "string" ? (program.comments == "false" ? false : program.comments) : "some";
}
if (program.define) {
if (typeof options.compress != "object") options.compress = {};
if (typeof options.compress.global_defs != "object") options.compress.global_defs = {};
for (var expr in program.define) {
options.compress.global_defs[expr] = program.define[expr];
}
}
if (program.keepClassnames) {
options.keep_classnames = true;
}
if (program.keepFnames) {
options.keep_fnames = true;
}
if (program.mangleProps) {
if (program.mangleProps.domprops) {
delete program.mangleProps.domprops;
} else {
if (typeof program.mangleProps != "object") program.mangleProps = {};
if (!Array.isArray(program.mangleProps.reserved)) program.mangleProps.reserved = [];
}
if (typeof options.mangle != "object") options.mangle = {};
options.mangle.properties = program.mangleProps;
}
if (program.nameCache) {
options.nameCache = JSON.parse(read_file(program.nameCache, "{}"));
}
if (program.output == "ast") {
options.format = {
ast: true,
code: false
};
}
if (program.parse) {
if (!program.parse.acorn && !program.parse.spidermonkey) {
options.parse = program.parse;
} else if (program.sourceMap && program.sourceMap.content == "inline") {
fatal("ERROR: inline source map only works with built-in parser");
}
}
if (~program.rawArgs.indexOf("--rename")) {
options.rename = true;
} else if (!program.rename) {
options.rename = false;
}
let convert_path = name => name;
if (typeof program.sourceMap == "object" && "base" in program.sourceMap) {
convert_path = function() {
var base = program.sourceMap.base;
delete options.sourceMap.base;
return function(name) {
return path.relative(base, name);
};
}();
}
let filesList;
if (options.files && options.files.length) {
filesList = options.files;
delete options.files;
} else if (program.args.length) {
filesList = program.args;
}
if (filesList) {
simple_glob(filesList).forEach(function(name) {
files[convert_path(name)] = read_file(name);
});
} else {
await new Promise((resolve) => {
var chunks = [];
process.stdin.setEncoding("utf8");
process.stdin.on("data", function(chunk) {
chunks.push(chunk);
}).on("end", function() {
files = [ chunks.join("") ];
resolve();
});
process.stdin.resume();
});
}
await run_cli();
function convert_ast(fn) {
return AST_Node.from_mozilla_ast(Object.keys(files).reduce(fn, null));
}
async function run_cli() {
var content = program.sourceMap && program.sourceMap.content;
if (content && content !== "inline") {
options.sourceMap.content = read_file(content, content);
}
if (program.timings) options.timings = true;
try {
if (program.parse) {
if (program.parse.acorn) {
files = convert_ast(function(toplevel, name) {
return require("acorn").parse(files[name], {
ecmaVersion: 2018,
locations: true,
program: toplevel,
sourceFile: name,
sourceType: options.module || program.parse.module ? "module" : "script"
});
});
} else if (program.parse.spidermonkey) {
files = convert_ast(function(toplevel, name) {
var obj = JSON.parse(files[name]);
if (!toplevel) return obj;
toplevel.body = toplevel.body.concat(obj.body);
return toplevel;
});
}
}
} catch (ex) {
fatal(ex);
}
let result;
try {
result = await minify(files, options);
} catch (ex) {
if (ex.name == "SyntaxError") {
print_error("Parse error at " + ex.filename + ":" + ex.line + "," + ex.col);
var col = ex.col;
var lines = files[ex.filename].split(/\r?\n/);
var line = lines[ex.line - 1];
if (!line && !col) {
line = lines[ex.line - 2];
col = line.length;
}
if (line) {
var limit = 70;
if (col > limit) {
line = line.slice(col - limit);
col = limit;
}
print_error(line.slice(0, 80));
print_error(line.slice(0, col).replace(/\S/g, " ") + "^");
}
}
if (ex.defs) {
print_error("Supported options:");
print_error(format_object(ex.defs));
}
fatal(ex);
return;
}
if (program.output == "ast") {
if (!options.compress && !options.mangle) {
result.ast.figure_out_scope({});
}
console.log(JSON.stringify(result.ast, function(key, value) {
if (value) switch (key) {
case "thedef":
return symdef(value);
case "enclosed":
return value.length ? value.map(symdef) : undefined;
case "variables":
case "functions":
case "globals":
return value.size ? collect_from_map(value, symdef) : undefined;
}
if (skip_keys.has(key)) return;
if (value instanceof AST_Token) return;
if (value instanceof Map) return;
if (value instanceof AST_Node) {
var result = {
_class: "AST_" + value.TYPE
};
if (value.block_scope) {
result.variables = value.block_scope.variables;
result.functions = value.block_scope.functions;
result.enclosed = value.block_scope.enclosed;
}
value.CTOR.PROPS.forEach(function(prop) {
result[prop] = value[prop];
});
return result;
}
return value;
}, 2));
} else if (program.output == "spidermonkey") {
try {
const minified = await minify(result.code, {
compress: false,
mangle: false,
format: {
ast: true,
code: false
}
});
console.log(JSON.stringify(minified.ast.to_mozilla_ast(), null, 2));
} catch (ex) {
fatal(ex);
return;
}
} else if (program.output) {
fs.writeFileSync(program.output, result.code);
if (options.sourceMap && options.sourceMap.url !== "inline" && result.map) {
fs.writeFileSync(program.output + ".map", result.map);
}
} else {
console.log(result.code);
}
if (program.nameCache) {
fs.writeFileSync(program.nameCache, JSON.stringify(options.nameCache));
}
if (result.timings) for (var phase in result.timings) {
print_error("- " + phase + ": " + result.timings[phase].toFixed(3) + "s");
}
}
function fatal(message) {
if (message instanceof Error) message = message.stack.replace(/^\S*?Error:/, "ERROR:");
print_error(message);
process.exit(1);
}
// A file glob function that only supports "*" and "?" wildcards in the basename.
// Example: "foo/bar/*baz??.*.js"
// Argument `glob` may be a string or an array of strings.
// Returns an array of strings. Garbage in, garbage out.
function simple_glob(glob) {
if (Array.isArray(glob)) {
return [].concat.apply([], glob.map(simple_glob));
}
if (glob && glob.match(/[*?]/)) {
var dir = path.dirname(glob);
try {
var entries = fs.readdirSync(dir);
} catch (ex) {}
if (entries) {
var pattern = "^" + path.basename(glob)
.replace(/[.+^$[\]\\(){}]/g, "\\$&")
.replace(/\*/g, "[^/\\\\]*")
.replace(/\?/g, "[^/\\\\]") + "$";
var mod = process.platform === "win32" ? "i" : "";
var rx = new RegExp(pattern, mod);
var results = entries.filter(function(name) {
return rx.test(name);
}).map(function(name) {
return path.join(dir, name);
});
if (results.length) return results;
}
}
return [ glob ];
}
function read_file(path, default_value) {
try {
return fs.readFileSync(path, "utf8");
} catch (ex) {
if ((ex.code == "ENOENT" || ex.code == "ENAMETOOLONG") && default_value != null) return default_value;
fatal(ex);
}
}
function parse_js(flag) {
return function(value, options) {
options = options || {};
try {
walk(parse(value, { expression: true }), node => {
if (node instanceof AST_Assign) {
var name = node.left.print_to_string();
var value = node.right;
if (flag) {
options[name] = value;
} else if (value instanceof AST_Array) {
options[name] = value.elements.map(to_string);
} else if (value instanceof AST_RegExp) {
value = value.value;
options[name] = new RegExp(value.source, value.flags);
} else {
options[name] = to_string(value);
}
return true;
}
if (node instanceof AST_Symbol || node instanceof AST_PropAccess) {
var name = node.print_to_string();
options[name] = true;
return true;
}
if (!(node instanceof AST_Sequence)) throw node;
function to_string(value) {
return value instanceof AST_Constant ? value.getValue() : value.print_to_string({
quote_keys: true
});
}
});
} catch(ex) {
if (flag) {
fatal("Error parsing arguments for '" + flag + "': " + value);
} else {
options[value] = null;
}
}
return options;
};
}
function symdef(def) {
var ret = (1e6 + def.id) + " " + def.name;
if (def.mangled_name) ret += " " + def.mangled_name;
return ret;
}
function collect_from_map(map, callback) {
var result = [];
map.forEach(function (def) {
result.push(callback(def));
});
return result;
}
function format_object(obj) {
var lines = [];
var padding = "";
Object.keys(obj).map(function(name) {
if (padding.length < name.length) padding = Array(name.length + 1).join(" ");
return [ name, JSON.stringify(obj[name]) ];
}).forEach(function(tokens) {
lines.push(" " + tokens[0] + padding.slice(tokens[0].length - 2) + tokens[1]);
});
return lines.join("\n");
}
function print_error(msg) {
process.stderr.write(msg);
process.stderr.write("\n");
}
function describe_ast() {
var out = OutputStream({ beautify: true });
function doitem(ctor) {
out.print("AST_" + ctor.TYPE);
const props = ctor.SELF_PROPS.filter(prop => !/^\$/.test(prop));
if (props.length > 0) {
out.space();
out.with_parens(function() {
props.forEach(function(prop, i) {
if (i) out.space();
out.print(prop);
});
});
}
if (ctor.documentation) {
out.space();
out.print_string(ctor.documentation);
}
if (ctor.SUBCLASSES.length > 0) {
out.space();
out.with_block(function() {
ctor.SUBCLASSES.forEach(function(ctor) {
out.indent();
doitem(ctor);
out.newline();
});
});
}
}
doitem(AST_Node);
return out + "\n";
}
}

7760
node_modules/terser/lib/compress/index.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

308
node_modules/terser/lib/equivalent-to.js generated vendored Normal file
View File

@@ -0,0 +1,308 @@
import {
AST_Array,
AST_Atom,
AST_Await,
AST_BigInt,
AST_Binary,
AST_Block,
AST_Call,
AST_Catch,
AST_Chain,
AST_Class,
AST_ClassProperty,
AST_ConciseMethod,
AST_Conditional,
AST_Debugger,
AST_Definitions,
AST_Destructuring,
AST_Directive,
AST_Do,
AST_Dot,
AST_EmptyStatement,
AST_Expansion,
AST_Export,
AST_Finally,
AST_For,
AST_ForIn,
AST_ForOf,
AST_If,
AST_Import,
AST_ImportMeta,
AST_Jump,
AST_LabeledStatement,
AST_Lambda,
AST_LoopControl,
AST_NameMapping,
AST_NewTarget,
AST_Node,
AST_Number,
AST_Object,
AST_ObjectGetter,
AST_ObjectKeyVal,
AST_ObjectProperty,
AST_ObjectSetter,
AST_PrefixedTemplateString,
AST_PropAccess,
AST_RegExp,
AST_Sequence,
AST_SimpleStatement,
AST_String,
AST_Super,
AST_Switch,
AST_SwitchBranch,
AST_Symbol,
AST_TemplateSegment,
AST_TemplateString,
AST_This,
AST_Toplevel,
AST_Try,
AST_Unary,
AST_VarDef,
AST_While,
AST_With,
AST_Yield
} from "./ast.js";
const shallow_cmp = (node1, node2) => {
return (
node1 === null && node2 === null
|| node1.TYPE === node2.TYPE && node1.shallow_cmp(node2)
);
};
export const equivalent_to = (tree1, tree2) => {
if (!shallow_cmp(tree1, tree2)) return false;
const walk_1_state = [tree1];
const walk_2_state = [tree2];
const walk_1_push = walk_1_state.push.bind(walk_1_state);
const walk_2_push = walk_2_state.push.bind(walk_2_state);
while (walk_1_state.length && walk_2_state.length) {
const node_1 = walk_1_state.pop();
const node_2 = walk_2_state.pop();
if (!shallow_cmp(node_1, node_2)) return false;
node_1._children_backwards(walk_1_push);
node_2._children_backwards(walk_2_push);
if (walk_1_state.length !== walk_2_state.length) {
// Different number of children
return false;
}
}
return walk_1_state.length == 0 && walk_2_state.length == 0;
};
// Creates a shallow compare function
const mkshallow = (props) => {
const comparisons = Object
.keys(props)
.map(key => {
if (props[key] === "eq") {
return `this.${key} === other.${key}`;
} else if (props[key] === "exist") {
return `(this.${key} == null ? other.${key} == null : this.${key} === other.${key})`;
} else {
throw new Error(`mkshallow: Unexpected instruction: ${props[key]}`);
}
})
.join(" && ");
return new Function("other", "return " + comparisons);
};
const pass_through = () => true;
AST_Node.prototype.shallow_cmp = function () {
throw new Error("did not find a shallow_cmp function for " + this.constructor.name);
};
AST_Debugger.prototype.shallow_cmp = pass_through;
AST_Directive.prototype.shallow_cmp = mkshallow({ value: "eq" });
AST_SimpleStatement.prototype.shallow_cmp = pass_through;
AST_Block.prototype.shallow_cmp = pass_through;
AST_EmptyStatement.prototype.shallow_cmp = pass_through;
AST_LabeledStatement.prototype.shallow_cmp = mkshallow({ "label.name": "eq" });
AST_Do.prototype.shallow_cmp = pass_through;
AST_While.prototype.shallow_cmp = pass_through;
AST_For.prototype.shallow_cmp = mkshallow({
init: "exist",
condition: "exist",
step: "exist"
});
AST_ForIn.prototype.shallow_cmp = pass_through;
AST_ForOf.prototype.shallow_cmp = pass_through;
AST_With.prototype.shallow_cmp = pass_through;
AST_Toplevel.prototype.shallow_cmp = pass_through;
AST_Expansion.prototype.shallow_cmp = pass_through;
AST_Lambda.prototype.shallow_cmp = mkshallow({
is_generator: "eq",
async: "eq"
});
AST_Destructuring.prototype.shallow_cmp = mkshallow({
is_array: "eq"
});
AST_PrefixedTemplateString.prototype.shallow_cmp = pass_through;
AST_TemplateString.prototype.shallow_cmp = pass_through;
AST_TemplateSegment.prototype.shallow_cmp = mkshallow({
"value": "eq"
});
AST_Jump.prototype.shallow_cmp = pass_through;
AST_LoopControl.prototype.shallow_cmp = pass_through;
AST_Await.prototype.shallow_cmp = pass_through;
AST_Yield.prototype.shallow_cmp = mkshallow({
is_star: "eq"
});
AST_If.prototype.shallow_cmp = mkshallow({
alternative: "exist"
});
AST_Switch.prototype.shallow_cmp = pass_through;
AST_SwitchBranch.prototype.shallow_cmp = pass_through;
AST_Try.prototype.shallow_cmp = mkshallow({
bcatch: "exist",
bfinally: "exist"
});
AST_Catch.prototype.shallow_cmp = mkshallow({
argname: "exist"
});
AST_Finally.prototype.shallow_cmp = pass_through;
AST_Definitions.prototype.shallow_cmp = pass_through;
AST_VarDef.prototype.shallow_cmp = mkshallow({
value: "exist"
});
AST_NameMapping.prototype.shallow_cmp = pass_through;
AST_Import.prototype.shallow_cmp = mkshallow({
imported_name: "exist",
imported_names: "exist"
});
AST_ImportMeta.prototype.shallow_cmp = pass_through;
AST_Export.prototype.shallow_cmp = mkshallow({
exported_definition: "exist",
exported_value: "exist",
exported_names: "exist",
module_name: "eq",
is_default: "eq",
});
AST_Call.prototype.shallow_cmp = pass_through;
AST_Sequence.prototype.shallow_cmp = pass_through;
AST_PropAccess.prototype.shallow_cmp = pass_through;
AST_Chain.prototype.shallow_cmp = pass_through;
AST_Dot.prototype.shallow_cmp = mkshallow({
property: "eq"
});
AST_Unary.prototype.shallow_cmp = mkshallow({
operator: "eq"
});
AST_Binary.prototype.shallow_cmp = mkshallow({
operator: "eq"
});
AST_Conditional.prototype.shallow_cmp = pass_through;
AST_Array.prototype.shallow_cmp = pass_through;
AST_Object.prototype.shallow_cmp = pass_through;
AST_ObjectProperty.prototype.shallow_cmp = pass_through;
AST_ObjectKeyVal.prototype.shallow_cmp = mkshallow({
key: "eq"
});
AST_ObjectSetter.prototype.shallow_cmp = mkshallow({
static: "eq"
});
AST_ObjectGetter.prototype.shallow_cmp = mkshallow({
static: "eq"
});
AST_ConciseMethod.prototype.shallow_cmp = mkshallow({
static: "eq",
is_generator: "eq",
async: "eq",
});
AST_Class.prototype.shallow_cmp = mkshallow({
name: "exist",
extends: "exist",
});
AST_ClassProperty.prototype.shallow_cmp = mkshallow({
static: "eq"
});
AST_Symbol.prototype.shallow_cmp = mkshallow({
name: "eq"
});
AST_NewTarget.prototype.shallow_cmp = pass_through;
AST_This.prototype.shallow_cmp = pass_through;
AST_Super.prototype.shallow_cmp = pass_through;
AST_String.prototype.shallow_cmp = mkshallow({
value: "eq"
});
AST_Number.prototype.shallow_cmp = mkshallow({
value: "eq"
});
AST_BigInt.prototype.shallow_cmp = mkshallow({
value: "eq"
});
AST_RegExp.prototype.shallow_cmp = function (other) {
return (
this.value.flags === other.value.flags
&& this.value.source === other.value.source
);
};
AST_Atom.prototype.shallow_cmp = pass_through;

285
node_modules/terser/lib/minify.js generated vendored Normal file
View File

@@ -0,0 +1,285 @@
"use strict";
/* eslint-env browser, es6, node */
import {
defaults,
map_from_object,
map_to_object,
HOP,
} from "./utils/index.js";
import { AST_Toplevel, AST_Node } from "./ast.js";
import { parse } from "./parse.js";
import { OutputStream } from "./output.js";
import { Compressor } from "./compress/index.js";
import { base54 } from "./scope.js";
import { SourceMap } from "./sourcemap.js";
import {
mangle_properties,
reserve_quoted_keys,
} from "./propmangle.js";
var to_ascii = typeof atob == "undefined" ? function(b64) {
return Buffer.from(b64, "base64").toString();
} : atob;
var to_base64 = typeof btoa == "undefined" ? function(str) {
return Buffer.from(str).toString("base64");
} : btoa;
function read_source_map(code) {
var match = /(?:^|[^.])\/\/# sourceMappingURL=data:application\/json(;[\w=-]*)?;base64,([+/0-9A-Za-z]*=*)\s*$/.exec(code);
if (!match) {
console.warn("inline source map not found");
return null;
}
return to_ascii(match[2]);
}
function set_shorthand(name, options, keys) {
if (options[name]) {
keys.forEach(function(key) {
if (options[key]) {
if (typeof options[key] != "object") options[key] = {};
if (!(name in options[key])) options[key][name] = options[name];
}
});
}
}
function init_cache(cache) {
if (!cache) return;
if (!("props" in cache)) {
cache.props = new Map();
} else if (!(cache.props instanceof Map)) {
cache.props = map_from_object(cache.props);
}
}
function cache_to_json(cache) {
return {
props: map_to_object(cache.props)
};
}
async function minify(files, options) {
options = defaults(options, {
compress: {},
ecma: undefined,
enclose: false,
ie8: false,
keep_classnames: undefined,
keep_fnames: false,
mangle: {},
module: false,
nameCache: null,
output: null,
format: null,
parse: {},
rename: undefined,
safari10: false,
sourceMap: false,
spidermonkey: false,
timings: false,
toplevel: false,
warnings: false,
wrap: false,
}, true);
var timings = options.timings && {
start: Date.now()
};
if (options.keep_classnames === undefined) {
options.keep_classnames = options.keep_fnames;
}
if (options.rename === undefined) {
options.rename = options.compress && options.mangle;
}
if (options.output && options.format) {
throw new Error("Please only specify either output or format option, preferrably format.");
}
options.format = options.format || options.output || {};
set_shorthand("ecma", options, [ "parse", "compress", "format" ]);
set_shorthand("ie8", options, [ "compress", "mangle", "format" ]);
set_shorthand("keep_classnames", options, [ "compress", "mangle" ]);
set_shorthand("keep_fnames", options, [ "compress", "mangle" ]);
set_shorthand("module", options, [ "parse", "compress", "mangle" ]);
set_shorthand("safari10", options, [ "mangle", "format" ]);
set_shorthand("toplevel", options, [ "compress", "mangle" ]);
set_shorthand("warnings", options, [ "compress" ]); // legacy
var quoted_props;
if (options.mangle) {
options.mangle = defaults(options.mangle, {
cache: options.nameCache && (options.nameCache.vars || {}),
eval: false,
ie8: false,
keep_classnames: false,
keep_fnames: false,
module: false,
properties: false,
reserved: [],
safari10: false,
toplevel: false,
}, true);
if (options.mangle.properties) {
if (typeof options.mangle.properties != "object") {
options.mangle.properties = {};
}
if (options.mangle.properties.keep_quoted) {
quoted_props = options.mangle.properties.reserved;
if (!Array.isArray(quoted_props)) quoted_props = [];
options.mangle.properties.reserved = quoted_props;
}
if (options.nameCache && !("cache" in options.mangle.properties)) {
options.mangle.properties.cache = options.nameCache.props || {};
}
}
init_cache(options.mangle.cache);
init_cache(options.mangle.properties.cache);
}
if (options.sourceMap) {
options.sourceMap = defaults(options.sourceMap, {
asObject: false,
content: null,
filename: null,
includeSources: false,
root: null,
url: null,
}, true);
}
if (timings) timings.parse = Date.now();
var toplevel;
if (files instanceof AST_Toplevel) {
toplevel = files;
} else {
if (typeof files == "string" || (options.parse.spidermonkey && !Array.isArray(files))) {
files = [ files ];
}
options.parse = options.parse || {};
options.parse.toplevel = null;
if (options.parse.spidermonkey) {
options.parse.toplevel = AST_Node.from_mozilla_ast(Object.keys(files).reduce(function(toplevel, name) {
if (!toplevel) return files[name];
toplevel.body = toplevel.body.concat(files[name].body);
return toplevel;
}, null));
} else {
delete options.parse.spidermonkey;
for (var name in files) if (HOP(files, name)) {
options.parse.filename = name;
options.parse.toplevel = parse(files[name], options.parse);
if (options.sourceMap && options.sourceMap.content == "inline") {
if (Object.keys(files).length > 1)
throw new Error("inline source map only works with singular input");
options.sourceMap.content = read_source_map(files[name]);
}
}
}
toplevel = options.parse.toplevel;
}
if (quoted_props && options.mangle.properties.keep_quoted !== "strict") {
reserve_quoted_keys(toplevel, quoted_props);
}
if (options.wrap) {
toplevel = toplevel.wrap_commonjs(options.wrap);
}
if (options.enclose) {
toplevel = toplevel.wrap_enclose(options.enclose);
}
if (timings) timings.rename = Date.now();
// disable rename on harmony due to expand_names bug in for-of loops
// https://github.com/mishoo/UglifyJS2/issues/2794
if (0 && options.rename) {
toplevel.figure_out_scope(options.mangle);
toplevel.expand_names(options.mangle);
}
if (timings) timings.compress = Date.now();
if (options.compress) {
toplevel = new Compressor(options.compress, {
mangle_options: options.mangle
}).compress(toplevel);
}
if (timings) timings.scope = Date.now();
if (options.mangle) toplevel.figure_out_scope(options.mangle);
if (timings) timings.mangle = Date.now();
if (options.mangle) {
base54.reset();
toplevel.compute_char_frequency(options.mangle);
toplevel.mangle_names(options.mangle);
}
if (timings) timings.properties = Date.now();
if (options.mangle && options.mangle.properties) {
toplevel = mangle_properties(toplevel, options.mangle.properties);
}
if (timings) timings.format = Date.now();
var result = {};
if (options.format.ast) {
result.ast = toplevel;
}
if (options.format.spidermonkey) {
result.ast = toplevel.to_mozilla_ast();
}
if (!HOP(options.format, "code") || options.format.code) {
if (options.sourceMap) {
options.format.source_map = await SourceMap({
file: options.sourceMap.filename,
orig: options.sourceMap.content,
root: options.sourceMap.root
});
if (options.sourceMap.includeSources) {
if (files instanceof AST_Toplevel) {
throw new Error("original source content unavailable");
} else for (var name in files) if (HOP(files, name)) {
options.format.source_map.get().setSourceContent(name, files[name]);
}
}
}
delete options.format.ast;
delete options.format.code;
delete options.format.spidermonkey;
var stream = OutputStream(options.format);
toplevel.print(stream);
result.code = stream.get();
if (options.sourceMap) {
if(options.sourceMap.asObject) {
result.map = options.format.source_map.get().toJSON();
} else {
result.map = options.format.source_map.toString();
}
if (options.sourceMap.url == "inline") {
var sourceMap = typeof result.map === "object" ? JSON.stringify(result.map) : result.map;
result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(sourceMap);
} else if (options.sourceMap.url) {
result.code += "\n//# sourceMappingURL=" + options.sourceMap.url;
}
}
}
if (options.nameCache && options.mangle) {
if (options.mangle.cache) options.nameCache.vars = cache_to_json(options.mangle.cache);
if (options.mangle.properties && options.mangle.properties.cache) {
options.nameCache.props = cache_to_json(options.mangle.properties.cache);
}
}
if (options.format && options.format.source_map) {
options.format.source_map.destroy();
}
if (timings) {
timings.end = Date.now();
result.timings = {
parse: 1e-3 * (timings.rename - timings.parse),
rename: 1e-3 * (timings.compress - timings.rename),
compress: 1e-3 * (timings.scope - timings.compress),
scope: 1e-3 * (timings.mangle - timings.scope),
mangle: 1e-3 * (timings.properties - timings.mangle),
properties: 1e-3 * (timings.format - timings.properties),
format: 1e-3 * (timings.end - timings.format),
total: 1e-3 * (timings.end - timings.start)
};
}
return result;
}
export {
minify,
to_ascii,
};

1334
node_modules/terser/lib/mozilla-ast.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

2283
node_modules/terser/lib/output.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

3344
node_modules/terser/lib/parse.js generated vendored Normal file

File diff suppressed because one or more lines are too long

353
node_modules/terser/lib/propmangle.js generated vendored Normal file
View File

@@ -0,0 +1,353 @@
/***********************************************************************
A JavaScript tokenizer / parser / beautifier / compressor.
https://github.com/mishoo/UglifyJS2
-------------------------------- (C) ---------------------------------
Author: Mihai Bazon
<mihai.bazon@gmail.com>
http://mihai.bazon.net/blog
Distributed under the BSD license:
Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
***********************************************************************/
"use strict";
/* global global, self */
import {
defaults,
push_uniq,
} from "./utils/index.js";
import { base54 } from "./scope.js";
import {
AST_Binary,
AST_Call,
AST_ClassPrivateProperty,
AST_Conditional,
AST_Dot,
AST_DotHash,
AST_ObjectKeyVal,
AST_ObjectProperty,
AST_PrivateMethod,
AST_Sequence,
AST_String,
AST_Sub,
TreeTransformer,
TreeWalker,
} from "./ast.js";
import { domprops } from "../tools/domprops.js";
function find_builtins(reserved) {
domprops.forEach(add);
// Compatibility fix for some standard defined globals not defined on every js environment
var new_globals = ["Symbol", "Map", "Promise", "Proxy", "Reflect", "Set", "WeakMap", "WeakSet"];
var objects = {};
var global_ref = typeof global === "object" ? global : self;
new_globals.forEach(function (new_global) {
objects[new_global] = global_ref[new_global] || new Function();
});
[
"null",
"true",
"false",
"NaN",
"Infinity",
"-Infinity",
"undefined",
].forEach(add);
[ Object, Array, Function, Number,
String, Boolean, Error, Math,
Date, RegExp, objects.Symbol, ArrayBuffer,
DataView, decodeURI, decodeURIComponent,
encodeURI, encodeURIComponent, eval, EvalError,
Float32Array, Float64Array, Int8Array, Int16Array,
Int32Array, isFinite, isNaN, JSON, objects.Map, parseFloat,
parseInt, objects.Promise, objects.Proxy, RangeError, ReferenceError,
objects.Reflect, objects.Set, SyntaxError, TypeError, Uint8Array,
Uint8ClampedArray, Uint16Array, Uint32Array, URIError,
objects.WeakMap, objects.WeakSet
].forEach(function(ctor) {
Object.getOwnPropertyNames(ctor).map(add);
if (ctor.prototype) {
Object.getOwnPropertyNames(ctor.prototype).map(add);
}
});
function add(name) {
reserved.add(name);
}
}
function reserve_quoted_keys(ast, reserved) {
function add(name) {
push_uniq(reserved, name);
}
ast.walk(new TreeWalker(function(node) {
if (node instanceof AST_ObjectKeyVal && node.quote) {
add(node.key);
} else if (node instanceof AST_ObjectProperty && node.quote) {
add(node.key.name);
} else if (node instanceof AST_Sub) {
addStrings(node.property, add);
}
}));
}
function addStrings(node, add) {
node.walk(new TreeWalker(function(node) {
if (node instanceof AST_Sequence) {
addStrings(node.tail_node(), add);
} else if (node instanceof AST_String) {
add(node.value);
} else if (node instanceof AST_Conditional) {
addStrings(node.consequent, add);
addStrings(node.alternative, add);
}
return true;
}));
}
function mangle_properties(ast, options) {
options = defaults(options, {
builtins: false,
cache: null,
debug: false,
keep_quoted: false,
only_cache: false,
regex: null,
reserved: null,
undeclared: false,
}, true);
var reserved_option = options.reserved;
if (!Array.isArray(reserved_option)) reserved_option = [reserved_option];
var reserved = new Set(reserved_option);
if (!options.builtins) find_builtins(reserved);
var cname = -1;
var cprivate = -1;
var cache;
var private_cache = new Map();
if (options.cache) {
cache = options.cache.props;
cache.forEach(function(mangled_name) {
reserved.add(mangled_name);
});
} else {
cache = new Map();
}
var regex = options.regex && new RegExp(options.regex);
// note debug is either false (disabled), or a string of the debug suffix to use (enabled).
// note debug may be enabled as an empty string, which is falsey. Also treat passing 'true'
// the same as passing an empty string.
var debug = options.debug !== false;
var debug_name_suffix;
if (debug) {
debug_name_suffix = (options.debug === true ? "" : options.debug);
}
var names_to_mangle = new Set();
var unmangleable = new Set();
var private_properties = new Set();
var keep_quoted_strict = options.keep_quoted === "strict";
// step 1: find candidates to mangle
ast.walk(new TreeWalker(function(node) {
if (
node instanceof AST_ClassPrivateProperty
|| node instanceof AST_PrivateMethod
) {
private_properties.add(node.key.name);
} else if (node instanceof AST_DotHash) {
private_properties.add(node.property);
} else if (node instanceof AST_ObjectKeyVal) {
if (typeof node.key == "string" &&
(!keep_quoted_strict || !node.quote)) {
add(node.key);
}
} else if (node instanceof AST_ObjectProperty) {
// setter or getter, since KeyVal is handled above
if (!keep_quoted_strict || !node.key.end.quote) {
add(node.key.name);
}
} else if (node instanceof AST_Dot) {
var declared = !!options.undeclared;
if (!declared) {
var root = node;
while (root.expression) {
root = root.expression;
}
declared = !(root.thedef && root.thedef.undeclared);
}
if (declared &&
(!keep_quoted_strict || !node.quote)) {
add(node.property);
}
} else if (node instanceof AST_Sub) {
if (!keep_quoted_strict) {
addStrings(node.property, add);
}
} else if (node instanceof AST_Call
&& node.expression.print_to_string() == "Object.defineProperty") {
addStrings(node.args[1], add);
} else if (node instanceof AST_Binary && node.operator === "in") {
addStrings(node.left, add);
}
}));
// step 2: transform the tree, renaming properties
return ast.transform(new TreeTransformer(function(node) {
if (
node instanceof AST_ClassPrivateProperty
|| node instanceof AST_PrivateMethod
) {
node.key.name = mangle_private(node.key.name);
} else if (node instanceof AST_DotHash) {
node.property = mangle_private(node.property);
} else if (node instanceof AST_ObjectKeyVal) {
if (typeof node.key == "string" &&
(!keep_quoted_strict || !node.quote)) {
node.key = mangle(node.key);
}
} else if (node instanceof AST_ObjectProperty) {
// setter, getter, method or class field
if (!keep_quoted_strict || !node.key.end.quote) {
node.key.name = mangle(node.key.name);
}
} else if (node instanceof AST_Dot) {
if (!keep_quoted_strict || !node.quote) {
node.property = mangle(node.property);
}
} else if (!options.keep_quoted && node instanceof AST_Sub) {
node.property = mangleStrings(node.property);
} else if (node instanceof AST_Call
&& node.expression.print_to_string() == "Object.defineProperty") {
node.args[1] = mangleStrings(node.args[1]);
} else if (node instanceof AST_Binary && node.operator === "in") {
node.left = mangleStrings(node.left);
}
}));
// only function declarations after this line
function can_mangle(name) {
if (unmangleable.has(name)) return false;
if (reserved.has(name)) return false;
if (options.only_cache) {
return cache.has(name);
}
if (/^-?[0-9]+(\.[0-9]+)?(e[+-][0-9]+)?$/.test(name)) return false;
return true;
}
function should_mangle(name) {
if (regex && !regex.test(name)) return false;
if (reserved.has(name)) return false;
return cache.has(name)
|| names_to_mangle.has(name);
}
function add(name) {
if (can_mangle(name))
names_to_mangle.add(name);
if (!should_mangle(name)) {
unmangleable.add(name);
}
}
function mangle(name) {
if (!should_mangle(name)) {
return name;
}
var mangled = cache.get(name);
if (!mangled) {
if (debug) {
// debug mode: use a prefix and suffix to preserve readability, e.g. o.foo -> o._$foo$NNN_.
var debug_mangled = "_$" + name + "$" + debug_name_suffix + "_";
if (can_mangle(debug_mangled)) {
mangled = debug_mangled;
}
}
// either debug mode is off, or it is on and we could not use the mangled name
if (!mangled) {
do {
mangled = base54(++cname);
} while (!can_mangle(mangled));
}
cache.set(name, mangled);
}
return mangled;
}
function mangle_private(name) {
let mangled = private_cache.get(name);
if (!mangled) {
mangled = base54(++cprivate);
private_cache.set(name, mangled);
}
return mangled;
}
function mangleStrings(node) {
return node.transform(new TreeTransformer(function(node) {
if (node instanceof AST_Sequence) {
var last = node.expressions.length - 1;
node.expressions[last] = mangleStrings(node.expressions[last]);
} else if (node instanceof AST_String) {
node.value = mangle(node.value);
} else if (node instanceof AST_Conditional) {
node.consequent = mangleStrings(node.consequent);
node.alternative = mangleStrings(node.alternative);
}
return node;
}));
}
}
export {
reserve_quoted_keys,
mangle_properties,
};

994
node_modules/terser/lib/scope.js generated vendored Normal file
View File

@@ -0,0 +1,994 @@
/***********************************************************************
A JavaScript tokenizer / parser / beautifier / compressor.
https://github.com/mishoo/UglifyJS2
-------------------------------- (C) ---------------------------------
Author: Mihai Bazon
<mihai.bazon@gmail.com>
http://mihai.bazon.net/blog
Distributed under the BSD license:
Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
***********************************************************************/
"use strict";
import {
defaults,
keep_name,
mergeSort,
push_uniq,
make_node,
return_false,
return_this,
return_true,
string_template,
} from "./utils/index.js";
import {
AST_Arrow,
AST_Block,
AST_Call,
AST_Catch,
AST_Class,
AST_Conditional,
AST_DefClass,
AST_Defun,
AST_Destructuring,
AST_Dot,
AST_DotHash,
AST_Export,
AST_For,
AST_ForIn,
AST_Function,
AST_Import,
AST_IterationStatement,
AST_Label,
AST_LabeledStatement,
AST_LabelRef,
AST_Lambda,
AST_LoopControl,
AST_NameMapping,
AST_Node,
AST_Scope,
AST_Sequence,
AST_String,
AST_Sub,
AST_Switch,
AST_SwitchBranch,
AST_Symbol,
AST_SymbolBlockDeclaration,
AST_SymbolCatch,
AST_SymbolClass,
AST_SymbolConst,
AST_SymbolDefClass,
AST_SymbolDefun,
AST_SymbolExport,
AST_SymbolFunarg,
AST_SymbolImport,
AST_SymbolLambda,
AST_SymbolLet,
AST_SymbolMethod,
AST_SymbolRef,
AST_SymbolVar,
AST_Toplevel,
AST_VarDef,
AST_With,
TreeWalker,
walk
} from "./ast.js";
import {
RESERVED_WORDS,
js_error,
} from "./parse.js";
const MASK_EXPORT_DONT_MANGLE = 1 << 0;
const MASK_EXPORT_WANT_MANGLE = 1 << 1;
let function_defs = null;
let unmangleable_names = null;
class SymbolDef {
constructor(scope, orig, init) {
this.name = orig.name;
this.orig = [ orig ];
this.init = init;
this.eliminated = 0;
this.assignments = 0;
this.scope = scope;
this.replaced = 0;
this.global = false;
this.export = 0;
this.mangled_name = null;
this.undeclared = false;
this.id = SymbolDef.next_id++;
this.chained = false;
this.direct_access = false;
this.escaped = 0;
this.recursive_refs = 0;
this.references = [];
this.should_replace = undefined;
this.single_use = false;
this.fixed = false;
Object.seal(this);
}
fixed_value() {
if (!this.fixed || this.fixed instanceof AST_Node) return this.fixed;
return this.fixed();
}
unmangleable(options) {
if (!options) options = {};
if (
function_defs &&
function_defs.has(this.id) &&
keep_name(options.keep_fnames, this.orig[0].name)
) return true;
return this.global && !options.toplevel
|| (this.export & MASK_EXPORT_DONT_MANGLE)
|| this.undeclared
|| !options.eval && this.scope.pinned()
|| (this.orig[0] instanceof AST_SymbolLambda
|| this.orig[0] instanceof AST_SymbolDefun) && keep_name(options.keep_fnames, this.orig[0].name)
|| this.orig[0] instanceof AST_SymbolMethod
|| (this.orig[0] instanceof AST_SymbolClass
|| this.orig[0] instanceof AST_SymbolDefClass) && keep_name(options.keep_classnames, this.orig[0].name);
}
mangle(options) {
const cache = options.cache && options.cache.props;
if (this.global && cache && cache.has(this.name)) {
this.mangled_name = cache.get(this.name);
} else if (!this.mangled_name && !this.unmangleable(options)) {
var s = this.scope;
var sym = this.orig[0];
if (options.ie8 && sym instanceof AST_SymbolLambda)
s = s.parent_scope;
const redefinition = redefined_catch_def(this);
this.mangled_name = redefinition
? redefinition.mangled_name || redefinition.name
: s.next_mangled(options, this);
if (this.global && cache) {
cache.set(this.name, this.mangled_name);
}
}
}
}
SymbolDef.next_id = 1;
function redefined_catch_def(def) {
if (def.orig[0] instanceof AST_SymbolCatch
&& def.scope.is_block_scope()
) {
return def.scope.get_defun_scope().variables.get(def.name);
}
}
AST_Scope.DEFMETHOD("figure_out_scope", function(options, { parent_scope = null, toplevel = this } = {}) {
options = defaults(options, {
cache: null,
ie8: false,
safari10: false,
});
if (!(toplevel instanceof AST_Toplevel)) {
throw new Error("Invalid toplevel scope");
}
// pass 1: setup scope chaining and handle definitions
var scope = this.parent_scope = parent_scope;
var labels = new Map();
var defun = null;
var in_destructuring = null;
var for_scopes = [];
var tw = new TreeWalker((node, descend) => {
if (node.is_block_scope()) {
const save_scope = scope;
node.block_scope = scope = new AST_Scope(node);
scope._block_scope = true;
// AST_Try in the AST sadly *is* (not has) a body itself,
// and its catch and finally branches are children of the AST_Try itself
const parent_scope = node instanceof AST_Catch
? save_scope.parent_scope
: save_scope;
scope.init_scope_vars(parent_scope);
scope.uses_with = save_scope.uses_with;
scope.uses_eval = save_scope.uses_eval;
if (options.safari10) {
if (node instanceof AST_For || node instanceof AST_ForIn) {
for_scopes.push(scope);
}
}
if (node instanceof AST_Switch) {
// XXX: HACK! Ensure the switch expression gets the correct scope (the parent scope) and the body gets the contained scope
// AST_Switch has a scope within the body, but it itself "is a block scope"
// This means the switched expression has to belong to the outer scope
// while the body inside belongs to the switch itself.
// This is pretty nasty and warrants an AST change similar to AST_Try (read above)
const the_block_scope = scope;
scope = save_scope;
node.expression.walk(tw);
scope = the_block_scope;
for (let i = 0; i < node.body.length; i++) {
node.body[i].walk(tw);
}
} else {
descend();
}
scope = save_scope;
return true;
}
if (node instanceof AST_Destructuring) {
const save_destructuring = in_destructuring;
in_destructuring = node;
descend();
in_destructuring = save_destructuring;
return true;
}
if (node instanceof AST_Scope) {
node.init_scope_vars(scope);
var save_scope = scope;
var save_defun = defun;
var save_labels = labels;
defun = scope = node;
labels = new Map();
descend();
scope = save_scope;
defun = save_defun;
labels = save_labels;
return true; // don't descend again in TreeWalker
}
if (node instanceof AST_LabeledStatement) {
var l = node.label;
if (labels.has(l.name)) {
throw new Error(string_template("Label {name} defined twice", l));
}
labels.set(l.name, l);
descend();
labels.delete(l.name);
return true; // no descend again
}
if (node instanceof AST_With) {
for (var s = scope; s; s = s.parent_scope)
s.uses_with = true;
return;
}
if (node instanceof AST_Symbol) {
node.scope = scope;
}
if (node instanceof AST_Label) {
node.thedef = node;
node.references = [];
}
if (node instanceof AST_SymbolLambda) {
defun.def_function(node, node.name == "arguments" ? undefined : defun);
} else if (node instanceof AST_SymbolDefun) {
// Careful here, the scope where this should be defined is
// the parent scope. The reason is that we enter a new
// scope when we encounter the AST_Defun node (which is
// instanceof AST_Scope) but we get to the symbol a bit
// later.
mark_export((node.scope = defun.parent_scope.get_defun_scope()).def_function(node, defun), 1);
} else if (node instanceof AST_SymbolClass) {
mark_export(defun.def_variable(node, defun), 1);
} else if (node instanceof AST_SymbolImport) {
scope.def_variable(node);
} else if (node instanceof AST_SymbolDefClass) {
// This deals with the name of the class being available
// inside the class.
mark_export((node.scope = defun.parent_scope).def_function(node, defun), 1);
} else if (
node instanceof AST_SymbolVar
|| node instanceof AST_SymbolLet
|| node instanceof AST_SymbolConst
|| node instanceof AST_SymbolCatch
) {
var def;
if (node instanceof AST_SymbolBlockDeclaration) {
def = scope.def_variable(node, null);
} else {
def = defun.def_variable(node, node.TYPE == "SymbolVar" ? null : undefined);
}
if (!def.orig.every((sym) => {
if (sym === node) return true;
if (node instanceof AST_SymbolBlockDeclaration) {
return sym instanceof AST_SymbolLambda;
}
return !(sym instanceof AST_SymbolLet || sym instanceof AST_SymbolConst);
})) {
js_error(
`"${node.name}" is redeclared`,
node.start.file,
node.start.line,
node.start.col,
node.start.pos
);
}
if (!(node instanceof AST_SymbolFunarg)) mark_export(def, 2);
if (defun !== scope) {
node.mark_enclosed();
var def = scope.find_variable(node);
if (node.thedef !== def) {
node.thedef = def;
node.reference();
}
}
} else if (node instanceof AST_LabelRef) {
var sym = labels.get(node.name);
if (!sym) throw new Error(string_template("Undefined label {name} [{line},{col}]", {
name: node.name,
line: node.start.line,
col: node.start.col
}));
node.thedef = sym;
}
if (!(scope instanceof AST_Toplevel) && (node instanceof AST_Export || node instanceof AST_Import)) {
js_error(
`"${node.TYPE}" statement may only appear at the top level`,
node.start.file,
node.start.line,
node.start.col,
node.start.pos
);
}
});
this.walk(tw);
function mark_export(def, level) {
if (in_destructuring) {
var i = 0;
do {
level++;
} while (tw.parent(i++) !== in_destructuring);
}
var node = tw.parent(level);
if (def.export = node instanceof AST_Export ? MASK_EXPORT_DONT_MANGLE : 0) {
var exported = node.exported_definition;
if ((exported instanceof AST_Defun || exported instanceof AST_DefClass) && node.is_default) {
def.export = MASK_EXPORT_WANT_MANGLE;
}
}
}
// pass 2: find back references and eval
const is_toplevel = this instanceof AST_Toplevel;
if (is_toplevel) {
this.globals = new Map();
}
var tw = new TreeWalker(node => {
if (node instanceof AST_LoopControl && node.label) {
node.label.thedef.references.push(node);
return true;
}
if (node instanceof AST_SymbolRef) {
var name = node.name;
if (name == "eval" && tw.parent() instanceof AST_Call) {
for (var s = node.scope; s && !s.uses_eval; s = s.parent_scope) {
s.uses_eval = true;
}
}
var sym;
if (tw.parent() instanceof AST_NameMapping && tw.parent(1).module_name
|| !(sym = node.scope.find_variable(name))) {
sym = toplevel.def_global(node);
if (node instanceof AST_SymbolExport) sym.export = MASK_EXPORT_DONT_MANGLE;
} else if (sym.scope instanceof AST_Lambda && name == "arguments") {
sym.scope.uses_arguments = true;
}
node.thedef = sym;
node.reference();
if (node.scope.is_block_scope()
&& !(sym.orig[0] instanceof AST_SymbolBlockDeclaration)) {
node.scope = node.scope.get_defun_scope();
}
return true;
}
// ensure mangling works if catch reuses a scope variable
var def;
if (node instanceof AST_SymbolCatch && (def = redefined_catch_def(node.definition()))) {
var s = node.scope;
while (s) {
push_uniq(s.enclosed, def);
if (s === def.scope) break;
s = s.parent_scope;
}
}
});
this.walk(tw);
// pass 3: work around IE8 and Safari catch scope bugs
if (options.ie8 || options.safari10) {
walk(this, node => {
if (node instanceof AST_SymbolCatch) {
var name = node.name;
var refs = node.thedef.references;
var scope = node.scope.get_defun_scope();
var def = scope.find_variable(name)
|| toplevel.globals.get(name)
|| scope.def_variable(node);
refs.forEach(function(ref) {
ref.thedef = def;
ref.reference();
});
node.thedef = def;
node.reference();
return true;
}
});
}
// pass 4: add symbol definitions to loop scopes
// Safari/Webkit bug workaround - loop init let variable shadowing argument.
// https://github.com/mishoo/UglifyJS2/issues/1753
// https://bugs.webkit.org/show_bug.cgi?id=171041
if (options.safari10) {
for (const scope of for_scopes) {
scope.parent_scope.variables.forEach(function(def) {
push_uniq(scope.enclosed, def);
});
}
}
});
AST_Toplevel.DEFMETHOD("def_global", function(node) {
var globals = this.globals, name = node.name;
if (globals.has(name)) {
return globals.get(name);
} else {
var g = new SymbolDef(this, node);
g.undeclared = true;
g.global = true;
globals.set(name, g);
return g;
}
});
AST_Scope.DEFMETHOD("init_scope_vars", function(parent_scope) {
this.variables = new Map(); // map name to AST_SymbolVar (variables defined in this scope; includes functions)
this.functions = new Map(); // map name to AST_SymbolDefun (functions defined in this scope)
this.uses_with = false; // will be set to true if this or some nested scope uses the `with` statement
this.uses_eval = false; // will be set to true if this or nested scope uses the global `eval`
this.parent_scope = parent_scope; // the parent scope
this.enclosed = []; // a list of variables from this or outer scope(s) that are referenced from this or inner scopes
this.cname = -1; // the current index for mangling functions/variables
});
AST_Scope.DEFMETHOD("conflicting_def", function (name) {
return (
this.enclosed.find(def => def.name === name)
|| this.variables.has(name)
|| (this.parent_scope && this.parent_scope.conflicting_def(name))
);
});
AST_Scope.DEFMETHOD("conflicting_def_shallow", function (name) {
return (
this.enclosed.find(def => def.name === name)
|| this.variables.has(name)
);
});
AST_Scope.DEFMETHOD("add_child_scope", function (scope) {
// `scope` is going to be moved into `this` right now.
// Update the required scopes' information
if (scope.parent_scope === this) return;
scope.parent_scope = this;
// TODO uses_with, uses_eval, etc
const scope_ancestry = (() => {
const ancestry = [];
let cur = this;
do {
ancestry.push(cur);
} while ((cur = cur.parent_scope));
ancestry.reverse();
return ancestry;
})();
const new_scope_enclosed_set = new Set(scope.enclosed);
const to_enclose = [];
for (const scope_topdown of scope_ancestry) {
to_enclose.forEach(e => push_uniq(scope_topdown.enclosed, e));
for (const def of scope_topdown.variables.values()) {
if (new_scope_enclosed_set.has(def)) {
push_uniq(to_enclose, def);
push_uniq(scope_topdown.enclosed, def);
}
}
}
});
function find_scopes_visible_from(scopes) {
const found_scopes = new Set();
for (const scope of new Set(scopes)) {
(function bubble_up(scope) {
if (scope == null || found_scopes.has(scope)) return;
found_scopes.add(scope);
bubble_up(scope.parent_scope);
})(scope);
}
return [...found_scopes];
}
// Creates a symbol during compression
AST_Scope.DEFMETHOD("create_symbol", function(SymClass, {
source,
tentative_name,
scope,
conflict_scopes = [scope],
init = null
} = {}) {
let symbol_name;
conflict_scopes = find_scopes_visible_from(conflict_scopes);
if (tentative_name) {
// Implement hygiene (no new names are conflicting with existing names)
tentative_name =
symbol_name =
tentative_name.replace(/(?:^[^a-z_$]|[^a-z0-9_$])/ig, "_");
let i = 0;
while (conflict_scopes.find(s => s.conflicting_def_shallow(symbol_name))) {
symbol_name = tentative_name + "$" + i++;
}
}
if (!symbol_name) {
throw new Error("No symbol name could be generated in create_symbol()");
}
const symbol = make_node(SymClass, source, {
name: symbol_name,
scope
});
this.def_variable(symbol, init || null);
symbol.mark_enclosed();
return symbol;
});
AST_Node.DEFMETHOD("is_block_scope", return_false);
AST_Class.DEFMETHOD("is_block_scope", return_false);
AST_Lambda.DEFMETHOD("is_block_scope", return_false);
AST_Toplevel.DEFMETHOD("is_block_scope", return_false);
AST_SwitchBranch.DEFMETHOD("is_block_scope", return_false);
AST_Block.DEFMETHOD("is_block_scope", return_true);
AST_Scope.DEFMETHOD("is_block_scope", function () {
return this._block_scope || false;
});
AST_IterationStatement.DEFMETHOD("is_block_scope", return_true);
AST_Lambda.DEFMETHOD("init_scope_vars", function() {
AST_Scope.prototype.init_scope_vars.apply(this, arguments);
this.uses_arguments = false;
this.def_variable(new AST_SymbolFunarg({
name: "arguments",
start: this.start,
end: this.end
}));
});
AST_Arrow.DEFMETHOD("init_scope_vars", function() {
AST_Scope.prototype.init_scope_vars.apply(this, arguments);
this.uses_arguments = false;
});
AST_Symbol.DEFMETHOD("mark_enclosed", function() {
var def = this.definition();
var s = this.scope;
while (s) {
push_uniq(s.enclosed, def);
if (s === def.scope) break;
s = s.parent_scope;
}
});
AST_Symbol.DEFMETHOD("reference", function() {
this.definition().references.push(this);
this.mark_enclosed();
});
AST_Scope.DEFMETHOD("find_variable", function(name) {
if (name instanceof AST_Symbol) name = name.name;
return this.variables.get(name)
|| (this.parent_scope && this.parent_scope.find_variable(name));
});
AST_Scope.DEFMETHOD("def_function", function(symbol, init) {
var def = this.def_variable(symbol, init);
if (!def.init || def.init instanceof AST_Defun) def.init = init;
this.functions.set(symbol.name, def);
return def;
});
AST_Scope.DEFMETHOD("def_variable", function(symbol, init) {
var def = this.variables.get(symbol.name);
if (def) {
def.orig.push(symbol);
if (def.init && (def.scope !== symbol.scope || def.init instanceof AST_Function)) {
def.init = init;
}
} else {
def = new SymbolDef(this, symbol, init);
this.variables.set(symbol.name, def);
def.global = !this.parent_scope;
}
return symbol.thedef = def;
});
function next_mangled(scope, options) {
var ext = scope.enclosed;
out: while (true) {
var m = base54(++scope.cname);
if (RESERVED_WORDS.has(m)) continue; // skip over "do"
// https://github.com/mishoo/UglifyJS2/issues/242 -- do not
// shadow a name reserved from mangling.
if (options.reserved.has(m)) continue;
// Functions with short names might collide with base54 output
// and therefore cause collisions when keep_fnames is true.
if (unmangleable_names && unmangleable_names.has(m)) continue out;
// we must ensure that the mangled name does not shadow a name
// from some parent scope that is referenced in this or in
// inner scopes.
for (let i = ext.length; --i >= 0;) {
const def = ext[i];
const name = def.mangled_name || (def.unmangleable(options) && def.name);
if (m == name) continue out;
}
return m;
}
}
AST_Scope.DEFMETHOD("next_mangled", function(options) {
return next_mangled(this, options);
});
AST_Toplevel.DEFMETHOD("next_mangled", function(options) {
let name;
const mangled_names = this.mangled_names;
do {
name = next_mangled(this, options);
} while (mangled_names.has(name));
return name;
});
AST_Function.DEFMETHOD("next_mangled", function(options, def) {
// #179, #326
// in Safari strict mode, something like (function x(x){...}) is a syntax error;
// a function expression's argument cannot shadow the function expression's name
var tricky_def = def.orig[0] instanceof AST_SymbolFunarg && this.name && this.name.definition();
// the function's mangled_name is null when keep_fnames is true
var tricky_name = tricky_def ? tricky_def.mangled_name || tricky_def.name : null;
while (true) {
var name = next_mangled(this, options);
if (!tricky_name || tricky_name != name)
return name;
}
});
AST_Symbol.DEFMETHOD("unmangleable", function(options) {
var def = this.definition();
return !def || def.unmangleable(options);
});
// labels are always mangleable
AST_Label.DEFMETHOD("unmangleable", return_false);
AST_Symbol.DEFMETHOD("unreferenced", function() {
return !this.definition().references.length && !this.scope.pinned();
});
AST_Symbol.DEFMETHOD("definition", function() {
return this.thedef;
});
AST_Symbol.DEFMETHOD("global", function() {
return this.thedef.global;
});
AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options) {
options = defaults(options, {
eval : false,
ie8 : false,
keep_classnames: false,
keep_fnames : false,
module : false,
reserved : [],
toplevel : false,
});
if (options.module) options.toplevel = true;
if (!Array.isArray(options.reserved)
&& !(options.reserved instanceof Set)
) {
options.reserved = [];
}
options.reserved = new Set(options.reserved);
// Never mangle arguments
options.reserved.add("arguments");
return options;
});
AST_Toplevel.DEFMETHOD("mangle_names", function(options) {
options = this._default_mangler_options(options);
// We only need to mangle declaration nodes. Special logic wired
// into the code generator will display the mangled name if it's
// present (and for AST_SymbolRef-s it'll use the mangled name of
// the AST_SymbolDeclaration that it points to).
var lname = -1;
var to_mangle = [];
if (options.keep_fnames) {
function_defs = new Set();
}
const mangled_names = this.mangled_names = new Set();
if (options.cache) {
this.globals.forEach(collect);
if (options.cache.props) {
options.cache.props.forEach(function(mangled_name) {
mangled_names.add(mangled_name);
});
}
}
var tw = new TreeWalker(function(node, descend) {
if (node instanceof AST_LabeledStatement) {
// lname is incremented when we get to the AST_Label
var save_nesting = lname;
descend();
lname = save_nesting;
return true; // don't descend again in TreeWalker
}
if (node instanceof AST_Scope) {
node.variables.forEach(collect);
return;
}
if (node.is_block_scope()) {
node.block_scope.variables.forEach(collect);
return;
}
if (
function_defs
&& node instanceof AST_VarDef
&& node.value instanceof AST_Lambda
&& !node.value.name
&& keep_name(options.keep_fnames, node.name.name)
) {
function_defs.add(node.name.definition().id);
return;
}
if (node instanceof AST_Label) {
let name;
do {
name = base54(++lname);
} while (RESERVED_WORDS.has(name));
node.mangled_name = name;
return true;
}
if (!(options.ie8 || options.safari10) && node instanceof AST_SymbolCatch) {
to_mangle.push(node.definition());
return;
}
});
this.walk(tw);
if (options.keep_fnames || options.keep_classnames) {
unmangleable_names = new Set();
// Collect a set of short names which are unmangleable,
// for use in avoiding collisions in next_mangled.
to_mangle.forEach(def => {
if (def.name.length < 6 && def.unmangleable(options)) {
unmangleable_names.add(def.name);
}
});
}
to_mangle.forEach(def => { def.mangle(options); });
function_defs = null;
unmangleable_names = null;
function collect(symbol) {
const should_mangle = !options.reserved.has(symbol.name)
&& !(symbol.export & MASK_EXPORT_DONT_MANGLE);
if (should_mangle) {
to_mangle.push(symbol);
}
}
});
AST_Toplevel.DEFMETHOD("find_colliding_names", function(options) {
const cache = options.cache && options.cache.props;
const avoid = new Set();
options.reserved.forEach(to_avoid);
this.globals.forEach(add_def);
this.walk(new TreeWalker(function(node) {
if (node instanceof AST_Scope) node.variables.forEach(add_def);
if (node instanceof AST_SymbolCatch) add_def(node.definition());
}));
return avoid;
function to_avoid(name) {
avoid.add(name);
}
function add_def(def) {
var name = def.name;
if (def.global && cache && cache.has(name)) name = cache.get(name);
else if (!def.unmangleable(options)) return;
to_avoid(name);
}
});
AST_Toplevel.DEFMETHOD("expand_names", function(options) {
base54.reset();
base54.sort();
options = this._default_mangler_options(options);
var avoid = this.find_colliding_names(options);
var cname = 0;
this.globals.forEach(rename);
this.walk(new TreeWalker(function(node) {
if (node instanceof AST_Scope) node.variables.forEach(rename);
if (node instanceof AST_SymbolCatch) rename(node.definition());
}));
function next_name() {
var name;
do {
name = base54(cname++);
} while (avoid.has(name) || RESERVED_WORDS.has(name));
return name;
}
function rename(def) {
if (def.global && options.cache) return;
if (def.unmangleable(options)) return;
if (options.reserved.has(def.name)) return;
const redefinition = redefined_catch_def(def);
const name = def.name = redefinition ? redefinition.name : next_name();
def.orig.forEach(function(sym) {
sym.name = name;
});
def.references.forEach(function(sym) {
sym.name = name;
});
}
});
AST_Node.DEFMETHOD("tail_node", return_this);
AST_Sequence.DEFMETHOD("tail_node", function() {
return this.expressions[this.expressions.length - 1];
});
AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options) {
options = this._default_mangler_options(options);
try {
AST_Node.prototype.print = function(stream, force_parens) {
this._print(stream, force_parens);
if (this instanceof AST_Symbol && !this.unmangleable(options)) {
base54.consider(this.name, -1);
} else if (options.properties) {
if (this instanceof AST_DotHash) {
base54.consider("#" + this.property, -1);
} else if (this instanceof AST_Dot) {
base54.consider(this.property, -1);
} else if (this instanceof AST_Sub) {
skip_string(this.property);
}
}
};
base54.consider(this.print_to_string(), 1);
} finally {
AST_Node.prototype.print = AST_Node.prototype._print;
}
base54.sort();
function skip_string(node) {
if (node instanceof AST_String) {
base54.consider(node.value, -1);
} else if (node instanceof AST_Conditional) {
skip_string(node.consequent);
skip_string(node.alternative);
} else if (node instanceof AST_Sequence) {
skip_string(node.tail_node());
}
}
});
const base54 = (() => {
const leading = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_".split("");
const digits = "0123456789".split("");
let chars;
let frequency;
function reset() {
frequency = new Map();
leading.forEach(function(ch) {
frequency.set(ch, 0);
});
digits.forEach(function(ch) {
frequency.set(ch, 0);
});
}
base54.consider = function(str, delta) {
for (var i = str.length; --i >= 0;) {
frequency.set(str[i], frequency.get(str[i]) + delta);
}
};
function compare(a, b) {
return frequency.get(b) - frequency.get(a);
}
base54.sort = function() {
chars = mergeSort(leading, compare).concat(mergeSort(digits, compare));
};
base54.reset = reset;
reset();
function base54(num) {
var ret = "", base = 54;
num++;
do {
num--;
ret += chars[num % base];
num = Math.floor(num / base);
base = 64;
} while (num > 0);
return ret;
}
return base54;
})();
export {
base54,
SymbolDef,
};

490
node_modules/terser/lib/size.js generated vendored Normal file
View File

@@ -0,0 +1,490 @@
import {
AST_Accessor,
AST_Array,
AST_Arrow,
AST_Await,
AST_BigInt,
AST_Binary,
AST_Block,
AST_Break,
AST_Call,
AST_Case,
AST_Class,
AST_ClassPrivateProperty,
AST_ClassProperty,
AST_ConciseMethod,
AST_Conditional,
AST_Const,
AST_Continue,
AST_Debugger,
AST_Default,
AST_Defun,
AST_Destructuring,
AST_Directive,
AST_Do,
AST_Dot,
AST_DotHash,
AST_EmptyStatement,
AST_Expansion,
AST_Export,
AST_False,
AST_For,
AST_ForIn,
AST_Function,
AST_Hole,
AST_If,
AST_Import,
AST_ImportMeta,
AST_Infinity,
AST_LabeledStatement,
AST_Let,
AST_NameMapping,
AST_NaN,
AST_New,
AST_NewTarget,
AST_Node,
AST_Null,
AST_Number,
AST_Object,
AST_ObjectKeyVal,
AST_ObjectGetter,
AST_ObjectSetter,
AST_PrivateGetter,
AST_PrivateMethod,
AST_PrivateSetter,
AST_RegExp,
AST_Return,
AST_Sequence,
AST_String,
AST_Sub,
AST_Super,
AST_Switch,
AST_Symbol,
AST_SymbolClassProperty,
AST_SymbolExportForeign,
AST_SymbolImportForeign,
AST_SymbolRef,
AST_SymbolDeclaration,
AST_TemplateSegment,
AST_TemplateString,
AST_This,
AST_Throw,
AST_Toplevel,
AST_True,
AST_Try,
AST_Catch,
AST_Finally,
AST_Unary,
AST_Undefined,
AST_Var,
AST_VarDef,
AST_While,
AST_With,
AST_Yield,
walk_parent
} from "./ast.js";
import { first_in_statement } from "./utils/first_in_statement.js";
let mangle_options = undefined;
AST_Node.prototype.size = function (compressor, stack) {
mangle_options = compressor && compressor.mangle_options;
let size = 0;
walk_parent(this, (node, info) => {
size += node._size(info);
// Braceless arrow functions have fake "return" statements
if (node instanceof AST_Arrow && node.is_braceless()) {
size += node.body[0].value._size(info);
return true;
}
}, stack || (compressor && compressor.stack));
// just to save a bit of memory
mangle_options = undefined;
return size;
};
AST_Node.prototype._size = () => 0;
AST_Debugger.prototype._size = () => 8;
AST_Directive.prototype._size = function () {
// TODO string encoding stuff
return 2 + this.value.length;
};
const list_overhead = (array) => array.length && array.length - 1;
AST_Block.prototype._size = function () {
return 2 + list_overhead(this.body);
};
AST_Toplevel.prototype._size = function() {
return list_overhead(this.body);
};
AST_EmptyStatement.prototype._size = () => 1;
AST_LabeledStatement.prototype._size = () => 2; // x:
AST_Do.prototype._size = () => 9;
AST_While.prototype._size = () => 7;
AST_For.prototype._size = () => 8;
AST_ForIn.prototype._size = () => 8;
// AST_ForOf inherits ^
AST_With.prototype._size = () => 6;
AST_Expansion.prototype._size = () => 3;
const lambda_modifiers = func =>
(func.is_generator ? 1 : 0) + (func.async ? 6 : 0);
AST_Accessor.prototype._size = function () {
return lambda_modifiers(this) + 4 + list_overhead(this.argnames) + list_overhead(this.body);
};
AST_Function.prototype._size = function (info) {
const first = !!first_in_statement(info);
return (first * 2) + lambda_modifiers(this) + 12 + list_overhead(this.argnames) + list_overhead(this.body);
};
AST_Defun.prototype._size = function () {
return lambda_modifiers(this) + 13 + list_overhead(this.argnames) + list_overhead(this.body);
};
AST_Arrow.prototype._size = function () {
let args_and_arrow = 2 + list_overhead(this.argnames);
if (
!(
this.argnames.length === 1
&& this.argnames[0] instanceof AST_Symbol
)
) {
args_and_arrow += 2;
}
const body_overhead = this.is_braceless() ? 0 : list_overhead(this.body) + 2;
return lambda_modifiers(this) + args_and_arrow + body_overhead;
};
AST_Destructuring.prototype._size = () => 2;
AST_TemplateString.prototype._size = function () {
return 2 + (Math.floor(this.segments.length / 2) * 3); /* "${}" */
};
AST_TemplateSegment.prototype._size = function () {
return this.value.length;
};
AST_Return.prototype._size = function () {
return this.value ? 7 : 6;
};
AST_Throw.prototype._size = () => 6;
AST_Break.prototype._size = function () {
return this.label ? 6 : 5;
};
AST_Continue.prototype._size = function () {
return this.label ? 9 : 8;
};
AST_If.prototype._size = () => 4;
AST_Switch.prototype._size = function () {
return 8 + list_overhead(this.body);
};
AST_Case.prototype._size = function () {
return 5 + list_overhead(this.body);
};
AST_Default.prototype._size = function () {
return 8 + list_overhead(this.body);
};
AST_Try.prototype._size = function () {
return 3 + list_overhead(this.body);
};
AST_Catch.prototype._size = function () {
let size = 7 + list_overhead(this.body);
if (this.argname) {
size += 2;
}
return size;
};
AST_Finally.prototype._size = function () {
return 7 + list_overhead(this.body);
};
/*#__INLINE__*/
const def_size = (size, def) => size + list_overhead(def.definitions);
AST_Var.prototype._size = function () {
return def_size(4, this);
};
AST_Let.prototype._size = function () {
return def_size(4, this);
};
AST_Const.prototype._size = function () {
return def_size(6, this);
};
AST_VarDef.prototype._size = function () {
return this.value ? 1 : 0;
};
AST_NameMapping.prototype._size = function () {
// foreign name isn't mangled
return this.name ? 4 : 0;
};
AST_Import.prototype._size = function () {
// import
let size = 6;
if (this.imported_name) size += 1;
// from
if (this.imported_name || this.imported_names) size += 5;
// braces, and the commas
if (this.imported_names) {
size += 2 + list_overhead(this.imported_names);
}
return size;
};
AST_ImportMeta.prototype._size = () => 11;
AST_Export.prototype._size = function () {
let size = 7 + (this.is_default ? 8 : 0);
if (this.exported_value) {
size += this.exported_value._size();
}
if (this.exported_names) {
// Braces and commas
size += 2 + list_overhead(this.exported_names);
}
if (this.module_name) {
// "from "
size += 5;
}
return size;
};
AST_Call.prototype._size = function () {
if (this.optional) {
return 4 + list_overhead(this.args);
}
return 2 + list_overhead(this.args);
};
AST_New.prototype._size = function () {
return 6 + list_overhead(this.args);
};
AST_Sequence.prototype._size = function () {
return list_overhead(this.expressions);
};
AST_Dot.prototype._size = function () {
if (this.optional) {
return this.property.length + 2;
}
return this.property.length + 1;
};
AST_DotHash.prototype._size = function () {
if (this.optional) {
return this.property.length + 3;
}
return this.property.length + 2;
};
AST_Sub.prototype._size = function () {
return this.optional ? 4 : 2;
};
AST_Unary.prototype._size = function () {
if (this.operator === "typeof") return 7;
if (this.operator === "void") return 5;
return this.operator.length;
};
AST_Binary.prototype._size = function (info) {
if (this.operator === "in") return 4;
let size = this.operator.length;
if (
(this.operator === "+" || this.operator === "-")
&& this.right instanceof AST_Unary && this.right.operator === this.operator
) {
// 1+ +a > needs space between the +
size += 1;
}
if (this.needs_parens(info)) {
size += 2;
}
return size;
};
AST_Conditional.prototype._size = () => 3;
AST_Array.prototype._size = function () {
return 2 + list_overhead(this.elements);
};
AST_Object.prototype._size = function (info) {
let base = 2;
if (first_in_statement(info)) {
base += 2; // parens
}
return base + list_overhead(this.properties);
};
/*#__INLINE__*/
const key_size = key =>
typeof key === "string" ? key.length : 0;
AST_ObjectKeyVal.prototype._size = function () {
return key_size(this.key) + 1;
};
/*#__INLINE__*/
const static_size = is_static => is_static ? 7 : 0;
AST_ObjectGetter.prototype._size = function () {
return 5 + static_size(this.static) + key_size(this.key);
};
AST_ObjectSetter.prototype._size = function () {
return 5 + static_size(this.static) + key_size(this.key);
};
AST_ConciseMethod.prototype._size = function () {
return static_size(this.static) + key_size(this.key) + lambda_modifiers(this);
};
AST_PrivateMethod.prototype._size = function () {
return AST_ConciseMethod.prototype._size.call(this) + 1;
};
AST_PrivateGetter.prototype._size = AST_PrivateSetter.prototype._size = function () {
return AST_ConciseMethod.prototype._size.call(this) + 4;
};
AST_Class.prototype._size = function () {
return (
(this.name ? 8 : 7)
+ (this.extends ? 8 : 0)
);
};
AST_ClassProperty.prototype._size = function () {
return (
static_size(this.static)
+ (typeof this.key === "string" ? this.key.length + 2 : 0)
+ (this.value ? 1 : 0)
);
};
AST_ClassPrivateProperty.prototype._size = function () {
return AST_ClassProperty.prototype._size.call(this) + 1;
};
AST_Symbol.prototype._size = function () {
return !mangle_options || this.definition().unmangleable(mangle_options)
? this.name.length
: 1;
};
// TODO take propmangle into account
AST_SymbolClassProperty.prototype._size = function () {
return this.name.length;
};
AST_SymbolRef.prototype._size = AST_SymbolDeclaration.prototype._size = function () {
const { name, thedef } = this;
if (thedef && thedef.global) return name.length;
if (name === "arguments") return 9;
return AST_Symbol.prototype._size.call(this);
};
AST_NewTarget.prototype._size = () => 10;
AST_SymbolImportForeign.prototype._size = function () {
return this.name.length;
};
AST_SymbolExportForeign.prototype._size = function () {
return this.name.length;
};
AST_This.prototype._size = () => 4;
AST_Super.prototype._size = () => 5;
AST_String.prototype._size = function () {
return this.value.length + 2;
};
AST_Number.prototype._size = function () {
const { value } = this;
if (value === 0) return 1;
if (value > 0 && Math.floor(value) === value) {
return Math.floor(Math.log10(value) + 1);
}
return value.toString().length;
};
AST_BigInt.prototype._size = function () {
return this.value.length;
};
AST_RegExp.prototype._size = function () {
return this.value.toString().length;
};
AST_Null.prototype._size = () => 4;
AST_NaN.prototype._size = () => 3;
AST_Undefined.prototype._size = () => 6; // "void 0"
AST_Hole.prototype._size = () => 0; // comma is taken into account
AST_Infinity.prototype._size = () => 8;
AST_True.prototype._size = () => 4;
AST_False.prototype._size = () => 5;
AST_Await.prototype._size = () => 6;
AST_Yield.prototype._size = () => 6;

114
node_modules/terser/lib/sourcemap.js generated vendored Normal file
View File

@@ -0,0 +1,114 @@
/***********************************************************************
A JavaScript tokenizer / parser / beautifier / compressor.
https://github.com/mishoo/UglifyJS2
-------------------------------- (C) ---------------------------------
Author: Mihai Bazon
<mihai.bazon@gmail.com>
http://mihai.bazon.net/blog
Distributed under the BSD license:
Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
***********************************************************************/
"use strict";
import MOZ_SourceMap from "source-map";
import {
defaults,
} from "./utils/index.js";
// a small wrapper around fitzgen's source-map library
async function SourceMap(options) {
options = defaults(options, {
file : null,
root : null,
orig : null,
orig_line_diff : 0,
dest_line_diff : 0,
});
var orig_map;
var generator = new MOZ_SourceMap.SourceMapGenerator({
file : options.file,
sourceRoot : options.root
});
if (options.orig) {
orig_map = await new MOZ_SourceMap.SourceMapConsumer(options.orig);
orig_map.sources.forEach(function(source) {
var sourceContent = orig_map.sourceContentFor(source, true);
if (sourceContent) {
generator.setSourceContent(source, sourceContent);
}
});
}
function add(source, gen_line, gen_col, orig_line, orig_col, name) {
if (orig_map) {
var info = orig_map.originalPositionFor({
line: orig_line,
column: orig_col
});
if (info.source === null) {
return;
}
source = info.source;
orig_line = info.line;
orig_col = info.column;
name = info.name || name;
}
generator.addMapping({
generated : { line: gen_line + options.dest_line_diff, column: gen_col },
original : { line: orig_line + options.orig_line_diff, column: orig_col },
source : source,
name : name
});
}
return {
add : add,
get : function() { return generator; },
toString : function() { return generator.toString(); },
destroy : function () {
if (orig_map && orig_map.destroy) {
orig_map.destroy();
}
}
};
}
export {
SourceMap,
};

318
node_modules/terser/lib/transform.js generated vendored Normal file
View File

@@ -0,0 +1,318 @@
/***********************************************************************
A JavaScript tokenizer / parser / beautifier / compressor.
https://github.com/mishoo/UglifyJS2
-------------------------------- (C) ---------------------------------
Author: Mihai Bazon
<mihai.bazon@gmail.com>
http://mihai.bazon.net/blog
Distributed under the BSD license:
Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
***********************************************************************/
"use strict";
import {
AST_Array,
AST_Await,
AST_Binary,
AST_Block,
AST_Call,
AST_Case,
AST_Catch,
AST_Chain,
AST_Class,
AST_Conditional,
AST_Definitions,
AST_Destructuring,
AST_Do,
AST_Dot,
AST_Exit,
AST_Expansion,
AST_Export,
AST_For,
AST_ForIn,
AST_If,
AST_Import,
AST_LabeledStatement,
AST_Lambda,
AST_LoopControl,
AST_NameMapping,
AST_Node,
AST_Number,
AST_Object,
AST_ObjectProperty,
AST_PrefixedTemplateString,
AST_Sequence,
AST_SimpleStatement,
AST_Sub,
AST_Switch,
AST_TemplateString,
AST_Try,
AST_Unary,
AST_VarDef,
AST_While,
AST_With,
AST_Yield,
} from "./ast.js";
import {
MAP,
noop,
} from "./utils/index.js";
function def_transform(node, descend) {
node.DEFMETHOD("transform", function(tw, in_list) {
let transformed = undefined;
tw.push(this);
if (tw.before) transformed = tw.before(this, descend, in_list);
if (transformed === undefined) {
transformed = this;
descend(transformed, tw);
if (tw.after) {
const after_ret = tw.after(transformed, in_list);
if (after_ret !== undefined) transformed = after_ret;
}
}
tw.pop();
return transformed;
});
}
function do_list(list, tw) {
return MAP(list, function(node) {
return node.transform(tw, true);
});
}
def_transform(AST_Node, noop);
def_transform(AST_LabeledStatement, function(self, tw) {
self.label = self.label.transform(tw);
self.body = self.body.transform(tw);
});
def_transform(AST_SimpleStatement, function(self, tw) {
self.body = self.body.transform(tw);
});
def_transform(AST_Block, function(self, tw) {
self.body = do_list(self.body, tw);
});
def_transform(AST_Do, function(self, tw) {
self.body = self.body.transform(tw);
self.condition = self.condition.transform(tw);
});
def_transform(AST_While, function(self, tw) {
self.condition = self.condition.transform(tw);
self.body = self.body.transform(tw);
});
def_transform(AST_For, function(self, tw) {
if (self.init) self.init = self.init.transform(tw);
if (self.condition) self.condition = self.condition.transform(tw);
if (self.step) self.step = self.step.transform(tw);
self.body = self.body.transform(tw);
});
def_transform(AST_ForIn, function(self, tw) {
self.init = self.init.transform(tw);
self.object = self.object.transform(tw);
self.body = self.body.transform(tw);
});
def_transform(AST_With, function(self, tw) {
self.expression = self.expression.transform(tw);
self.body = self.body.transform(tw);
});
def_transform(AST_Exit, function(self, tw) {
if (self.value) self.value = self.value.transform(tw);
});
def_transform(AST_LoopControl, function(self, tw) {
if (self.label) self.label = self.label.transform(tw);
});
def_transform(AST_If, function(self, tw) {
self.condition = self.condition.transform(tw);
self.body = self.body.transform(tw);
if (self.alternative) self.alternative = self.alternative.transform(tw);
});
def_transform(AST_Switch, function(self, tw) {
self.expression = self.expression.transform(tw);
self.body = do_list(self.body, tw);
});
def_transform(AST_Case, function(self, tw) {
self.expression = self.expression.transform(tw);
self.body = do_list(self.body, tw);
});
def_transform(AST_Try, function(self, tw) {
self.body = do_list(self.body, tw);
if (self.bcatch) self.bcatch = self.bcatch.transform(tw);
if (self.bfinally) self.bfinally = self.bfinally.transform(tw);
});
def_transform(AST_Catch, function(self, tw) {
if (self.argname) self.argname = self.argname.transform(tw);
self.body = do_list(self.body, tw);
});
def_transform(AST_Definitions, function(self, tw) {
self.definitions = do_list(self.definitions, tw);
});
def_transform(AST_VarDef, function(self, tw) {
self.name = self.name.transform(tw);
if (self.value) self.value = self.value.transform(tw);
});
def_transform(AST_Destructuring, function(self, tw) {
self.names = do_list(self.names, tw);
});
def_transform(AST_Lambda, function(self, tw) {
if (self.name) self.name = self.name.transform(tw);
self.argnames = do_list(self.argnames, tw);
if (self.body instanceof AST_Node) {
self.body = self.body.transform(tw);
} else {
self.body = do_list(self.body, tw);
}
});
def_transform(AST_Call, function(self, tw) {
self.expression = self.expression.transform(tw);
self.args = do_list(self.args, tw);
});
def_transform(AST_Sequence, function(self, tw) {
const result = do_list(self.expressions, tw);
self.expressions = result.length
? result
: [new AST_Number({ value: 0 })];
});
def_transform(AST_Dot, function(self, tw) {
self.expression = self.expression.transform(tw);
});
def_transform(AST_Sub, function(self, tw) {
self.expression = self.expression.transform(tw);
self.property = self.property.transform(tw);
});
def_transform(AST_Chain, function(self, tw) {
self.expression = self.expression.transform(tw);
});
def_transform(AST_Yield, function(self, tw) {
if (self.expression) self.expression = self.expression.transform(tw);
});
def_transform(AST_Await, function(self, tw) {
self.expression = self.expression.transform(tw);
});
def_transform(AST_Unary, function(self, tw) {
self.expression = self.expression.transform(tw);
});
def_transform(AST_Binary, function(self, tw) {
self.left = self.left.transform(tw);
self.right = self.right.transform(tw);
});
def_transform(AST_Conditional, function(self, tw) {
self.condition = self.condition.transform(tw);
self.consequent = self.consequent.transform(tw);
self.alternative = self.alternative.transform(tw);
});
def_transform(AST_Array, function(self, tw) {
self.elements = do_list(self.elements, tw);
});
def_transform(AST_Object, function(self, tw) {
self.properties = do_list(self.properties, tw);
});
def_transform(AST_ObjectProperty, function(self, tw) {
if (self.key instanceof AST_Node) {
self.key = self.key.transform(tw);
}
if (self.value) self.value = self.value.transform(tw);
});
def_transform(AST_Class, function(self, tw) {
if (self.name) self.name = self.name.transform(tw);
if (self.extends) self.extends = self.extends.transform(tw);
self.properties = do_list(self.properties, tw);
});
def_transform(AST_Expansion, function(self, tw) {
self.expression = self.expression.transform(tw);
});
def_transform(AST_NameMapping, function(self, tw) {
self.foreign_name = self.foreign_name.transform(tw);
self.name = self.name.transform(tw);
});
def_transform(AST_Import, function(self, tw) {
if (self.imported_name) self.imported_name = self.imported_name.transform(tw);
if (self.imported_names) do_list(self.imported_names, tw);
self.module_name = self.module_name.transform(tw);
});
def_transform(AST_Export, function(self, tw) {
if (self.exported_definition) self.exported_definition = self.exported_definition.transform(tw);
if (self.exported_value) self.exported_value = self.exported_value.transform(tw);
if (self.exported_names) do_list(self.exported_names, tw);
if (self.module_name) self.module_name = self.module_name.transform(tw);
});
def_transform(AST_TemplateString, function(self, tw) {
self.segments = do_list(self.segments, tw);
});
def_transform(AST_PrefixedTemplateString, function(self, tw) {
self.prefix = self.prefix.transform(tw);
self.template_string = self.template_string.transform(tw);
});

50
node_modules/terser/lib/utils/first_in_statement.js generated vendored Normal file
View File

@@ -0,0 +1,50 @@
import {
AST_Binary,
AST_Conditional,
AST_Dot,
AST_Object,
AST_Sequence,
AST_Statement,
AST_Sub,
AST_UnaryPostfix,
AST_PrefixedTemplateString
} from "../ast.js";
// return true if the node at the top of the stack (that means the
// innermost node in the current output) is lexically the first in
// a statement.
function first_in_statement(stack) {
let node = stack.parent(-1);
for (let i = 0, p; p = stack.parent(i); i++) {
if (p instanceof AST_Statement && p.body === node)
return true;
if ((p instanceof AST_Sequence && p.expressions[0] === node) ||
(p.TYPE === "Call" && p.expression === node) ||
(p instanceof AST_PrefixedTemplateString && p.prefix === node) ||
(p instanceof AST_Dot && p.expression === node) ||
(p instanceof AST_Sub && p.expression === node) ||
(p instanceof AST_Conditional && p.condition === node) ||
(p instanceof AST_Binary && p.left === node) ||
(p instanceof AST_UnaryPostfix && p.expression === node)
) {
node = p;
} else {
return false;
}
}
}
// Returns whether the leftmost item in the expression is an object
function left_is_object(node) {
if (node instanceof AST_Object) return true;
if (node instanceof AST_Sequence) return left_is_object(node.expressions[0]);
if (node.TYPE === "Call") return left_is_object(node.expression);
if (node instanceof AST_PrefixedTemplateString) return left_is_object(node.prefix);
if (node instanceof AST_Dot || node instanceof AST_Sub) return left_is_object(node.expression);
if (node instanceof AST_Conditional) return left_is_object(node.condition);
if (node instanceof AST_Binary) return left_is_object(node.left);
if (node instanceof AST_UnaryPostfix) return left_is_object(node.expression);
return false;
}
export { first_in_statement, left_is_object };

304
node_modules/terser/lib/utils/index.js generated vendored Normal file
View File

@@ -0,0 +1,304 @@
/***********************************************************************
A JavaScript tokenizer / parser / beautifier / compressor.
https://github.com/mishoo/UglifyJS2
-------------------------------- (C) ---------------------------------
Author: Mihai Bazon
<mihai.bazon@gmail.com>
http://mihai.bazon.net/blog
Distributed under the BSD license:
Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
***********************************************************************/
"use strict";
function characters(str) {
return str.split("");
}
function member(name, array) {
return array.includes(name);
}
class DefaultsError extends Error {
constructor(msg, defs) {
super();
this.name = "DefaultsError";
this.message = msg;
this.defs = defs;
}
}
function defaults(args, defs, croak) {
if (args === true) {
args = {};
}
if (args != null && typeof args === "object") {
args = Object.assign({}, args);
}
const ret = args || {};
if (croak) for (const i in ret) if (HOP(ret, i) && !HOP(defs, i)) {
throw new DefaultsError("`" + i + "` is not a supported option", defs);
}
for (const i in defs) if (HOP(defs, i)) {
if (!args || !HOP(args, i)) {
ret[i] = defs[i];
} else if (i === "ecma") {
let ecma = args[i] | 0;
if (ecma > 5 && ecma < 2015) ecma += 2009;
ret[i] = ecma;
} else {
ret[i] = (args && HOP(args, i)) ? args[i] : defs[i];
}
}
return ret;
}
function noop() {}
function return_false() { return false; }
function return_true() { return true; }
function return_this() { return this; }
function return_null() { return null; }
var MAP = (function() {
function MAP(a, f, backwards) {
var ret = [], top = [], i;
function doit() {
var val = f(a[i], i);
var is_last = val instanceof Last;
if (is_last) val = val.v;
if (val instanceof AtTop) {
val = val.v;
if (val instanceof Splice) {
top.push.apply(top, backwards ? val.v.slice().reverse() : val.v);
} else {
top.push(val);
}
} else if (val !== skip) {
if (val instanceof Splice) {
ret.push.apply(ret, backwards ? val.v.slice().reverse() : val.v);
} else {
ret.push(val);
}
}
return is_last;
}
if (Array.isArray(a)) {
if (backwards) {
for (i = a.length; --i >= 0;) if (doit()) break;
ret.reverse();
top.reverse();
} else {
for (i = 0; i < a.length; ++i) if (doit()) break;
}
} else {
for (i in a) if (HOP(a, i)) if (doit()) break;
}
return top.concat(ret);
}
MAP.at_top = function(val) { return new AtTop(val); };
MAP.splice = function(val) { return new Splice(val); };
MAP.last = function(val) { return new Last(val); };
var skip = MAP.skip = {};
function AtTop(val) { this.v = val; }
function Splice(val) { this.v = val; }
function Last(val) { this.v = val; }
return MAP;
})();
function make_node(ctor, orig, props) {
if (!props) props = {};
if (orig) {
if (!props.start) props.start = orig.start;
if (!props.end) props.end = orig.end;
}
return new ctor(props);
}
function push_uniq(array, el) {
if (!array.includes(el))
array.push(el);
}
function string_template(text, props) {
return text.replace(/{(.+?)}/g, function(str, p) {
return props && props[p];
});
}
function remove(array, el) {
for (var i = array.length; --i >= 0;) {
if (array[i] === el) array.splice(i, 1);
}
}
function mergeSort(array, cmp) {
if (array.length < 2) return array.slice();
function merge(a, b) {
var r = [], ai = 0, bi = 0, i = 0;
while (ai < a.length && bi < b.length) {
cmp(a[ai], b[bi]) <= 0
? r[i++] = a[ai++]
: r[i++] = b[bi++];
}
if (ai < a.length) r.push.apply(r, a.slice(ai));
if (bi < b.length) r.push.apply(r, b.slice(bi));
return r;
}
function _ms(a) {
if (a.length <= 1)
return a;
var m = Math.floor(a.length / 2), left = a.slice(0, m), right = a.slice(m);
left = _ms(left);
right = _ms(right);
return merge(left, right);
}
return _ms(array);
}
function makePredicate(words) {
if (!Array.isArray(words)) words = words.split(" ");
return new Set(words.sort());
}
function map_add(map, key, value) {
if (map.has(key)) {
map.get(key).push(value);
} else {
map.set(key, [ value ]);
}
}
function map_from_object(obj) {
var map = new Map();
for (var key in obj) {
if (HOP(obj, key) && key.charAt(0) === "$") {
map.set(key.substr(1), obj[key]);
}
}
return map;
}
function map_to_object(map) {
var obj = Object.create(null);
map.forEach(function (value, key) {
obj["$" + key] = value;
});
return obj;
}
function HOP(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}
function keep_name(keep_setting, name) {
return keep_setting === true
|| (keep_setting instanceof RegExp && keep_setting.test(name));
}
var lineTerminatorEscape = {
"\0": "0",
"\n": "n",
"\r": "r",
"\u2028": "u2028",
"\u2029": "u2029",
};
function regexp_source_fix(source) {
// V8 does not escape line terminators in regexp patterns in node 12
// We'll also remove literal \0
return source.replace(/[\0\n\r\u2028\u2029]/g, function (match, offset) {
var escaped = source[offset - 1] == "\\"
&& (source[offset - 2] != "\\"
|| /(?:^|[^\\])(?:\\{2})*$/.test(source.slice(0, offset - 1)));
return (escaped ? "" : "\\") + lineTerminatorEscape[match];
});
}
const all_flags = "gimuy";
function sort_regexp_flags(flags) {
const existing_flags = new Set(flags.split(""));
let out = "";
for (const flag of all_flags) {
if (existing_flags.has(flag)) {
out += flag;
existing_flags.delete(flag);
}
}
if (existing_flags.size) {
// Flags Terser doesn't know about
existing_flags.forEach(flag => { out += flag; });
}
return out;
}
function has_annotation(node, annotation) {
return node._annotations & annotation;
}
function set_annotation(node, annotation) {
node._annotations |= annotation;
}
export {
characters,
defaults,
HOP,
keep_name,
make_node,
makePredicate,
map_add,
map_from_object,
map_to_object,
MAP,
member,
mergeSort,
noop,
push_uniq,
regexp_source_fix,
remove,
return_false,
return_null,
return_this,
return_true,
sort_regexp_flags,
string_template,
has_annotation,
set_annotation
};