Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7d3c07f5a |
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -1 +0,0 @@
|
|||||||
*.js text eol=lf
|
|
||||||
25
.github/ISSUE_TEMPLATE.md
vendored
25
.github/ISSUE_TEMPLATE.md
vendored
@@ -1,25 +0,0 @@
|
|||||||
**Bug report or feature request?**
|
|
||||||
|
|
||||||
<!-- Note: sub-optimal but correct code is not a bug -->
|
|
||||||
|
|
||||||
**Uglify version (`uglifyjs -V`)**
|
|
||||||
|
|
||||||
**JavaScript input**
|
|
||||||
|
|
||||||
<!--
|
|
||||||
A complete parsable JS program exhibiting the issue with
|
|
||||||
UglifyJS alone - without third party tools or libraries.
|
|
||||||
Ideally the input should be as small as possible.
|
|
||||||
Post a link to a gist if necessary.
|
|
||||||
|
|
||||||
Issues without a reproducible test case will be closed.
|
|
||||||
-->
|
|
||||||
|
|
||||||
**The `uglifyjs` CLI command executed or `minify()` options used.**
|
|
||||||
|
|
||||||
**JavaScript output or error produced.**
|
|
||||||
|
|
||||||
<!--
|
|
||||||
Note: `uglify-js` only supports JavaScript.
|
|
||||||
Those wishing to minify ES6+ should transpile first.
|
|
||||||
-->
|
|
||||||
48
.github/workflows/ci.yml
vendored
48
.github/workflows/ci.yml
vendored
@@ -1,48 +0,0 @@
|
|||||||
name: CI
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
push:
|
|
||||||
branches: [ master ]
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
node: [ "0.8", "0.10", "0.12", "4", "6", "8", "10", "12", latest ]
|
|
||||||
os: [ ubuntu-latest, windows-latest ]
|
|
||||||
script: [ compress, mocha, release/benchmark, release/jetstream ]
|
|
||||||
exclude:
|
|
||||||
- node: "0.8"
|
|
||||||
script: release/benchmark
|
|
||||||
- node: "0.8"
|
|
||||||
script: release/jetstream
|
|
||||||
name: ${{ matrix.node }} ${{ matrix.os }} ${{ matrix.script }}
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
env:
|
|
||||||
NODE: ${{ matrix.node }}
|
|
||||||
TYPE: ${{ matrix.script }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: tmp
|
|
||||||
key: tmp ${{ matrix.script }}
|
|
||||||
- name: Perform tests
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
git clone --branch v1.5.4 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
|
||||||
while ! timeout 60 bash -c '. ~/.nvs/nvs.sh add $NODE && nvs use $NODE'; do
|
|
||||||
cd ~/.nvs
|
|
||||||
while !(git clean -xdf); do echo "'git clean' failed - retrying..."; done
|
|
||||||
cd -
|
|
||||||
done
|
|
||||||
. ~/.nvs/nvs.sh --version
|
|
||||||
nvs use $NODE
|
|
||||||
node --version
|
|
||||||
npm config set audit false
|
|
||||||
npm config set optional false
|
|
||||||
npm config set save false
|
|
||||||
npm config set strict-ssl false
|
|
||||||
npm config set update-notifier false
|
|
||||||
npm --version
|
|
||||||
while !(npm install); do echo "'npm install' failed - retrying..."; done
|
|
||||||
node test/$TYPE
|
|
||||||
44
.github/workflows/ufuzz.yml
vendored
44
.github/workflows/ufuzz.yml
vendored
@@ -1,44 +0,0 @@
|
|||||||
name: Fuzzing
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
schedule:
|
|
||||||
- cron: "*/5 * * * *"
|
|
||||||
env:
|
|
||||||
BASE_URL: https://api.github.com/repos/${{ github.repository }}
|
|
||||||
CAUSE: ${{ github.event_name }}
|
|
||||||
RUN_NUM: ${{ github.run_number }}
|
|
||||||
TOKEN: ${{ github.token }}
|
|
||||||
jobs:
|
|
||||||
ufuzz:
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ ubuntu-latest, windows-latest ]
|
|
||||||
name: ${{ matrix.os }}
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Perform fuzzing
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
git clone --branch v1.5.4 --depth 1 https://github.com/jasongin/nvs.git ~/.nvs
|
|
||||||
while ! timeout 60 bash -c '. ~/.nvs/nvs.sh add 8 && nvs use 8'; do
|
|
||||||
cd ~/.nvs
|
|
||||||
while !(git clean -xdf); do echo "'git clean' failed - retrying..."; done
|
|
||||||
cd -
|
|
||||||
done
|
|
||||||
. ~/.nvs/nvs.sh --version
|
|
||||||
nvs use 8
|
|
||||||
node --version
|
|
||||||
npm config set audit false
|
|
||||||
npm config set optional false
|
|
||||||
npm config set save false
|
|
||||||
npm config set strict-ssl false
|
|
||||||
npm config set update-notifier false
|
|
||||||
npm --version
|
|
||||||
while !(npm install); do echo "'npm install' failed - retrying..."; done
|
|
||||||
if [[ $CAUSE == "schedule" ]]; then
|
|
||||||
node test/ufuzz/job $BASE_URL $TOKEN $RUN_NUM
|
|
||||||
else
|
|
||||||
node test/ufuzz/job 5000
|
|
||||||
fi
|
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,2 @@
|
|||||||
/node_modules/
|
|
||||||
/npm-debug.log
|
|
||||||
tmp/
|
tmp/
|
||||||
|
node_modules/
|
||||||
|
|||||||
6
.travis.yml
Normal file
6
.travis.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
language: node_js
|
||||||
|
before_install: "npm install -g npm"
|
||||||
|
node_js:
|
||||||
|
- "0.8"
|
||||||
|
- "0.10"
|
||||||
|
- "0.11"
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
Contributing
|
|
||||||
============
|
|
||||||
|
|
||||||
## Documentation
|
|
||||||
|
|
||||||
Every new feature and API change should be accompanied by a README additon.
|
|
||||||
|
|
||||||
## Testing
|
|
||||||
|
|
||||||
All features and bugs should have tests that verify the fix. You can run all
|
|
||||||
tests using `npm test`.
|
|
||||||
|
|
||||||
The most common type of test are tests that verify input and output of the
|
|
||||||
Uglify transforms. These tests exist in `test/compress`. New tests can be added
|
|
||||||
either to an existing file or in a new file `issue-xxx.js`.
|
|
||||||
|
|
||||||
Tests that cannot be expressed as a simple AST can be found in `test/mocha`.
|
|
||||||
|
|
||||||
## Code style
|
|
||||||
|
|
||||||
- File encoding must be `UTF-8`.
|
|
||||||
- `LF` is always used as a line ending.
|
|
||||||
- Statements end with semicolons.
|
|
||||||
- Indentation uses 4 spaces, switch `case` 2 spaces.
|
|
||||||
- Identifiers use `snake_case`.
|
|
||||||
- Strings use double quotes (`"`).
|
|
||||||
- Use a trailing comma for multiline array and object literals to minimize diffs.
|
|
||||||
- The Uglify code only uses ES5, even in the `harmony` branch.
|
|
||||||
- Line length should be at most 80 cols, except when it is easier to read a
|
|
||||||
longer line.
|
|
||||||
- If both sides of a comparison are of the same type, `==` and `!=` are used.
|
|
||||||
- Multiline conditions place `&&` and `||` first on the line.
|
|
||||||
|
|
||||||
**Example feature**
|
|
||||||
|
|
||||||
```js
|
|
||||||
OPT(AST_Debugger, function(self, compressor) {
|
|
||||||
if (compressor.option("drop_debugger"))
|
|
||||||
return make_node(AST_EmptyStatement, self);
|
|
||||||
return self;
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
**Example test case**
|
|
||||||
|
|
||||||
```js
|
|
||||||
drop_debugger: {
|
|
||||||
options = {
|
|
||||||
drop_debugger: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
debugger;
|
|
||||||
if (foo) debugger;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
if (foo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
UglifyJS is released under the BSD license:
|
UglifyJS is released under the BSD license:
|
||||||
|
|
||||||
Copyright 2012-2019 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
Copyright 2012-2013 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions
|
modification, are permitted provided that the following conditions
|
||||||
|
|||||||
882
bin/uglifyjs
882
bin/uglifyjs
@@ -3,522 +3,478 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
require("../tools/exit");
|
|
||||||
|
|
||||||
var fs = require("fs");
|
|
||||||
var info = require("../package.json");
|
|
||||||
var path = require("path");
|
|
||||||
var UglifyJS = require("../tools/node");
|
var UglifyJS = require("../tools/node");
|
||||||
|
var sys = require("util");
|
||||||
|
var yargs = require("yargs");
|
||||||
|
var fs = require("fs");
|
||||||
|
var path = require("path");
|
||||||
|
var async = require("async");
|
||||||
|
var acorn;
|
||||||
|
var ARGS = yargs
|
||||||
|
.usage("$0 input1.js [input2.js ...] [options]\n\
|
||||||
|
Use a single dash to read input from the standard input.\
|
||||||
|
\n\n\
|
||||||
|
NOTE: by default there is no mangling/compression.\n\
|
||||||
|
Without [options] it will simply parse input files and dump the AST\n\
|
||||||
|
with whitespace and comments discarded. To achieve compression and\n\
|
||||||
|
mangling you need to use `-c` and `-m`.\
|
||||||
|
")
|
||||||
|
.describe("source-map", "Specify an output file where to generate source map.")
|
||||||
|
.describe("source-map-root", "The path to the original source to be included in the source map.")
|
||||||
|
.describe("source-map-url", "The path to the source map to be added in //# sourceMappingURL. Defaults to the value passed with --source-map.")
|
||||||
|
.describe("source-map-include-sources", "Pass this flag if you want to include the content of source files in the source map as sourcesContent property.")
|
||||||
|
.describe("in-source-map", "Input source map, useful if you're compressing JS that was generated from some other original code.")
|
||||||
|
.describe("screw-ie8", "Pass this flag if you don't care about full compliance with Internet Explorer 6-8 quirks (by default UglifyJS will try to be IE-proof).")
|
||||||
|
.describe("expr", "Parse a single expression, rather than a program (for parsing JSON)")
|
||||||
|
.describe("p", "Skip prefix for original filenames that appear in source maps. \
|
||||||
|
For example -p 3 will drop 3 directories from file names and ensure they are relative paths. \
|
||||||
|
You can also specify -p relative, which will make UglifyJS figure out itself the relative paths between original sources, \
|
||||||
|
the source map and the output file.")
|
||||||
|
.describe("o", "Output file (default STDOUT).")
|
||||||
|
.describe("b", "Beautify output/specify output options.")
|
||||||
|
.describe("m", "Mangle names/pass mangler options.")
|
||||||
|
.describe("r", "Reserved names to exclude from mangling.")
|
||||||
|
.describe("c", "Enable compressor/pass compressor options. \
|
||||||
|
Pass options like -c hoist_vars=false,if_return=false. \
|
||||||
|
Use -c with no argument to use the default compression options.")
|
||||||
|
.describe("d", "Global definitions")
|
||||||
|
.describe("e", "Embed everything in a big function, with a configurable parameter/argument list.")
|
||||||
|
|
||||||
var skip_keys = [ "cname", "inlined", "parent_scope", "scope", "uses_eval", "uses_with" ];
|
.describe("comments", "Preserve copyright comments in the output. \
|
||||||
var files = {};
|
By default this works like Google Closure, keeping JSDoc-style comments that contain \"@license\" or \"@preserve\". \
|
||||||
var options = {};
|
You can optionally pass one of the following arguments to this flag:\n\
|
||||||
var short_forms = {
|
- \"all\" to keep all comments\n\
|
||||||
b: "beautify",
|
- a valid JS regexp (needs to start with a slash) to keep only comments that match.\n\
|
||||||
c: "compress",
|
\
|
||||||
d: "define",
|
Note that currently not *all* comments can be kept when compression is on, \
|
||||||
e: "enclose",
|
because of dead code removal or cascading statements into sequences.")
|
||||||
h: "help",
|
|
||||||
m: "mangle",
|
.describe("preamble", "Preamble to prepend to the output. You can use this to insert a \
|
||||||
o: "output",
|
comment, for example for licensing information. This will not be \
|
||||||
O: "output-opts",
|
parsed, but the source map will adjust for its presence.")
|
||||||
p: "parse",
|
|
||||||
v: "version",
|
.describe("stats", "Display operations run time on STDERR.")
|
||||||
V: "version",
|
.describe("acorn", "Use Acorn for parsing.")
|
||||||
|
.describe("spidermonkey", "Assume input files are SpiderMonkey AST format (as JSON).")
|
||||||
|
.describe("self", "Build itself (UglifyJS2) as a library (implies --wrap=UglifyJS --export-all)")
|
||||||
|
.describe("wrap", "Embed everything in a big function, making the “exports” and “global” variables available. \
|
||||||
|
You need to pass an argument to this option to specify the name that your module will take when included in, say, a browser.")
|
||||||
|
.describe("export-all", "Only used when --wrap, this tells UglifyJS to add code to automatically export all globals.")
|
||||||
|
.describe("lint", "Display some scope warnings")
|
||||||
|
.describe("v", "Verbose")
|
||||||
|
.describe("V", "Print version number and exit.")
|
||||||
|
.describe("noerr", "Don't throw an error for unknown options in -c, -b or -m.")
|
||||||
|
.describe("bare-returns", "Allow return outside of functions. Useful when minifying CommonJS modules.")
|
||||||
|
.describe("keep-fnames", "Do not mangle/drop function names. Useful for code relying on Function.prototype.name.")
|
||||||
|
.describe("quotes", "Quote style (0 - auto, 1 - single, 2 - double, 3 - original)")
|
||||||
|
|
||||||
|
.alias("p", "prefix")
|
||||||
|
.alias("o", "output")
|
||||||
|
.alias("v", "verbose")
|
||||||
|
.alias("b", "beautify")
|
||||||
|
.alias("m", "mangle")
|
||||||
|
.alias("c", "compress")
|
||||||
|
.alias("d", "define")
|
||||||
|
.alias("r", "reserved")
|
||||||
|
.alias("V", "version")
|
||||||
|
.alias("e", "enclose")
|
||||||
|
.alias("q", "quotes")
|
||||||
|
|
||||||
|
.string("source-map")
|
||||||
|
.string("source-map-root")
|
||||||
|
.string("source-map-url")
|
||||||
|
.string("b")
|
||||||
|
.string("m")
|
||||||
|
.string("c")
|
||||||
|
.string("d")
|
||||||
|
.string("e")
|
||||||
|
.string("comments")
|
||||||
|
.string("wrap")
|
||||||
|
.string("p")
|
||||||
|
|
||||||
|
.boolean("expr")
|
||||||
|
.boolean("source-map-include-sources")
|
||||||
|
.boolean("screw-ie8")
|
||||||
|
.boolean("export-all")
|
||||||
|
.boolean("self")
|
||||||
|
.boolean("v")
|
||||||
|
.boolean("stats")
|
||||||
|
.boolean("acorn")
|
||||||
|
.boolean("spidermonkey")
|
||||||
|
.boolean("lint")
|
||||||
|
.boolean("V")
|
||||||
|
.boolean("noerr")
|
||||||
|
.boolean("bare-returns")
|
||||||
|
.boolean("keep-fnames")
|
||||||
|
|
||||||
|
.wrap(80)
|
||||||
|
|
||||||
|
.argv
|
||||||
|
;
|
||||||
|
|
||||||
|
normalize(ARGS);
|
||||||
|
|
||||||
|
if (ARGS.noerr) {
|
||||||
|
UglifyJS.DefaultsError.croak = function(msg, defs) {
|
||||||
|
sys.error("WARN: " + msg);
|
||||||
};
|
};
|
||||||
var args = process.argv.slice(2);
|
|
||||||
var paths = [];
|
|
||||||
var output, nameCache;
|
|
||||||
var specified = {};
|
|
||||||
while (args.length) {
|
|
||||||
var arg = args.shift();
|
|
||||||
if (arg[0] != "-") {
|
|
||||||
paths.push(arg);
|
|
||||||
} else if (arg == "--") {
|
|
||||||
paths = paths.concat(args);
|
|
||||||
break;
|
|
||||||
} else if (arg[1] == "-") {
|
|
||||||
process_option(arg.slice(2));
|
|
||||||
} else [].forEach.call(arg.slice(1), function(letter, index, arg) {
|
|
||||||
if (!(letter in short_forms)) fatal("invalid option -" + letter);
|
|
||||||
process_option(short_forms[letter], index + 1 < arg.length);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function process_option(name, no_value) {
|
if (ARGS.version || ARGS.V) {
|
||||||
specified[name] = true;
|
var json = require("../package.json");
|
||||||
switch (name) {
|
sys.puts(json.name + ' ' + json.version);
|
||||||
case "help":
|
process.exit(0);
|
||||||
switch (read_value()) {
|
|
||||||
case "ast":
|
|
||||||
print(UglifyJS.describe_ast());
|
|
||||||
break;
|
|
||||||
case "options":
|
|
||||||
var text = [];
|
|
||||||
var toplevels = [];
|
|
||||||
var padding = "";
|
|
||||||
var defaults = UglifyJS.default_options();
|
|
||||||
for (var name in defaults) {
|
|
||||||
var option = defaults[name];
|
|
||||||
if (option && typeof option == "object") {
|
|
||||||
text.push("--" + ({
|
|
||||||
output: "beautify",
|
|
||||||
sourceMap: "source-map",
|
|
||||||
}[name] || name) + " options:");
|
|
||||||
text.push(format_object(option));
|
|
||||||
text.push("");
|
|
||||||
} else {
|
|
||||||
if (padding.length < name.length) padding = Array(name.length + 1).join(" ");
|
|
||||||
toplevels.push([ {
|
|
||||||
keep_fnames: "keep-fnames",
|
|
||||||
nameCache: "name-cache",
|
|
||||||
}[name] || name, option ]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
toplevels.forEach(function(tokens) {
|
|
||||||
text.push("--" + tokens[0] + padding.slice(tokens[0].length - 2) + tokens[1]);
|
|
||||||
});
|
|
||||||
print(text.join("\n"));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
print([
|
|
||||||
"Usage: uglifyjs [files...] [options]",
|
|
||||||
"",
|
|
||||||
"Options:",
|
|
||||||
" -h, --help Print usage information.",
|
|
||||||
" `--help options` for details on available options.",
|
|
||||||
" -v, -V, --version Print version number.",
|
|
||||||
" -p, --parse <options> Specify parser options.",
|
|
||||||
" -c, --compress [options] Enable compressor/specify compressor options.",
|
|
||||||
" -m, --mangle [options] Mangle names/specify mangler options.",
|
|
||||||
" --mangle-props [options] Mangle properties/specify mangler options.",
|
|
||||||
" -b, --beautify [options] Beautify output/specify output options.",
|
|
||||||
" -O, --output-opts <options> Output options (beautify disabled).",
|
|
||||||
" -o, --output <file> Output file (default STDOUT).",
|
|
||||||
" --comments [filter] Preserve copyright comments in the output.",
|
|
||||||
" --config-file <file> Read minify() options from JSON file.",
|
|
||||||
" -d, --define <expr>[=value] Global definitions.",
|
|
||||||
" -e, --enclose [arg[,...][:value[,...]]] Embed everything in a big function, with configurable argument(s) & value(s).",
|
|
||||||
" --ie8 Support non-standard Internet Explorer 8.",
|
|
||||||
" --keep-fnames Do not mangle/drop function names. Useful for code relying on Function.prototype.name.",
|
|
||||||
" --name-cache <file> File to hold mangled name mappings.",
|
|
||||||
" --rename Force symbol expansion.",
|
|
||||||
" --no-rename Disable symbol expansion.",
|
|
||||||
" --self Build UglifyJS as a library (implies --wrap UglifyJS)",
|
|
||||||
" --source-map [options] Enable source map/specify source map options.",
|
|
||||||
" --timings Display operations run time on STDERR.",
|
|
||||||
" --toplevel Compress and/or mangle variables in toplevel scope.",
|
|
||||||
" --validate Perform validation during AST manipulations.",
|
|
||||||
" --verbose Print diagnostic messages.",
|
|
||||||
" --warn Print warning messages.",
|
|
||||||
" --wrap <name> Embed everything as a function with “exports” corresponding to “name” globally.",
|
|
||||||
" --reduce-test Reduce a standalone test case (assumes cloned repository).",
|
|
||||||
].join("\n"));
|
|
||||||
}
|
|
||||||
process.exit();
|
|
||||||
case "version":
|
|
||||||
print(info.name + " " + info.version);
|
|
||||||
process.exit();
|
|
||||||
case "config-file":
|
|
||||||
var config = JSON.parse(read_file(read_value(true)));
|
|
||||||
if (config.mangle && config.mangle.properties && config.mangle.properties.regex) {
|
|
||||||
config.mangle.properties.regex = UglifyJS.parse(config.mangle.properties.regex, {
|
|
||||||
expression: true,
|
|
||||||
}).value;
|
|
||||||
}
|
|
||||||
for (var key in config) if (!(key in options)) options[key] = config[key];
|
|
||||||
break;
|
|
||||||
case "compress":
|
|
||||||
case "mangle":
|
|
||||||
options[name] = parse_js(read_value(), options[name]);
|
|
||||||
break;
|
|
||||||
case "source-map":
|
|
||||||
options.sourceMap = parse_js(read_value(), options.sourceMap);
|
|
||||||
break;
|
|
||||||
case "enclose":
|
|
||||||
options[name] = read_value();
|
|
||||||
break;
|
|
||||||
case "ie8":
|
|
||||||
case "timings":
|
|
||||||
case "toplevel":
|
|
||||||
case "validate":
|
|
||||||
options[name] = true;
|
|
||||||
break;
|
|
||||||
case "keep-fnames":
|
|
||||||
options.keep_fnames = true;
|
|
||||||
break;
|
|
||||||
case "wrap":
|
|
||||||
options[name] = read_value(true);
|
|
||||||
break;
|
|
||||||
case "verbose":
|
|
||||||
options.warnings = "verbose";
|
|
||||||
break;
|
|
||||||
case "warn":
|
|
||||||
if (!options.warnings) options.warnings = true;
|
|
||||||
break;
|
|
||||||
case "beautify":
|
|
||||||
options.output = parse_js(read_value(), options.output);
|
|
||||||
if (!("beautify" in options.output)) options.output.beautify = true;
|
|
||||||
break;
|
|
||||||
case "output-opts":
|
|
||||||
options.output = parse_js(read_value(true), options.output);
|
|
||||||
break;
|
|
||||||
case "comments":
|
|
||||||
if (typeof options.output != "object") options.output = {};
|
|
||||||
options.output.comments = read_value();
|
|
||||||
if (options.output.comments === true) options.output.comments = "some";
|
|
||||||
break;
|
|
||||||
case "define":
|
|
||||||
if (typeof options.compress != "object") options.compress = {};
|
|
||||||
options.compress.global_defs = parse_js(read_value(true), options.compress.global_defs, "define");
|
|
||||||
break;
|
|
||||||
case "mangle-props":
|
|
||||||
if (typeof options.mangle != "object") options.mangle = {};
|
|
||||||
options.mangle.properties = parse_js(read_value(), options.mangle.properties);
|
|
||||||
break;
|
|
||||||
case "name-cache":
|
|
||||||
nameCache = read_value(true);
|
|
||||||
options.nameCache = JSON.parse(read_file(nameCache, "{}"));
|
|
||||||
break;
|
|
||||||
case "output":
|
|
||||||
output = read_value(true);
|
|
||||||
break;
|
|
||||||
case "parse":
|
|
||||||
options.parse = parse_js(read_value(true), options.parse);
|
|
||||||
break;
|
|
||||||
case "rename":
|
|
||||||
options.rename = true;
|
|
||||||
break;
|
|
||||||
case "no-rename":
|
|
||||||
options.rename = false;
|
|
||||||
break;
|
|
||||||
case "reduce-test":
|
|
||||||
case "self":
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fatal("invalid option --" + name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function read_value(required) {
|
if (ARGS.ast_help) {
|
||||||
if (no_value || !args.length || args[0][0] == "-") {
|
var desc = UglifyJS.describe_ast();
|
||||||
if (required) fatal("missing option argument for --" + name);
|
sys.puts(typeof desc == "string" ? desc : JSON.stringify(desc, null, 2));
|
||||||
return true;
|
process.exit(0);
|
||||||
}
|
}
|
||||||
return args.shift();
|
|
||||||
|
if (ARGS.h || ARGS.help) {
|
||||||
|
sys.puts(yargs.help());
|
||||||
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ARGS.acorn) {
|
||||||
|
acorn = require("acorn");
|
||||||
}
|
}
|
||||||
if (!output && options.sourceMap && options.sourceMap.url != "inline") fatal("cannot write source map to STDOUT");
|
|
||||||
if (specified["beautify"] && specified["output-opts"]) fatal("--beautify cannot be used with --output-opts");
|
var COMPRESS = getOptions("c", true);
|
||||||
[ "compress", "mangle" ].forEach(function(name) {
|
var MANGLE = getOptions("m", true);
|
||||||
if (!(name in options)) options[name] = false;
|
var BEAUTIFY = getOptions("b", true);
|
||||||
});
|
|
||||||
if (options.mangle && options.mangle.properties) {
|
if (ARGS.d) {
|
||||||
if (options.mangle.properties.domprops) {
|
if (COMPRESS) COMPRESS.global_defs = getOptions("d");
|
||||||
delete options.mangle.properties.domprops;
|
|
||||||
} else {
|
|
||||||
if (typeof options.mangle.properties != "object") options.mangle.properties = {};
|
|
||||||
if (!Array.isArray(options.mangle.properties.reserved)) options.mangle.properties.reserved = [];
|
|
||||||
require("../tools/domprops").forEach(function(name) {
|
|
||||||
UglifyJS.push_uniq(options.mangle.properties.reserved, name);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ARGS.r) {
|
||||||
|
if (MANGLE) MANGLE.except = ARGS.r.replace(/^\s+|\s+$/g).split(/\s*,+\s*/);
|
||||||
}
|
}
|
||||||
if (output == "ast") options.output = {
|
|
||||||
ast: true,
|
if (ARGS.quotes === true) {
|
||||||
code: false,
|
ARGS.quotes = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
var OUTPUT_OPTIONS = {
|
||||||
|
beautify : BEAUTIFY ? true : false,
|
||||||
|
preamble : ARGS.preamble || null,
|
||||||
|
quote_style : ARGS.quotes != null ? ARGS.quotes : 0
|
||||||
};
|
};
|
||||||
if (options.parse && (options.parse.acorn || options.parse.spidermonkey)
|
|
||||||
&& options.sourceMap && options.sourceMap.content == "inline") {
|
if (ARGS.screw_ie8) {
|
||||||
fatal("inline source map only works with built-in parser");
|
if (COMPRESS) COMPRESS.screw_ie8 = true;
|
||||||
}
|
if (MANGLE) MANGLE.screw_ie8 = true;
|
||||||
if (options.warnings) {
|
OUTPUT_OPTIONS.screw_ie8 = true;
|
||||||
UglifyJS.AST_Node.log_function(print_error, options.warnings == "verbose");
|
|
||||||
delete options.warnings;
|
|
||||||
}
|
|
||||||
var convert_path = function(name) {
|
|
||||||
return name;
|
|
||||||
};
|
|
||||||
if (typeof options.sourceMap == "object" && "base" in options.sourceMap) {
|
|
||||||
convert_path = function() {
|
|
||||||
var base = options.sourceMap.base;
|
|
||||||
delete options.sourceMap.base;
|
|
||||||
return function(name) {
|
|
||||||
return path.relative(base, name);
|
|
||||||
};
|
|
||||||
}();
|
|
||||||
}
|
|
||||||
if (specified["self"]) {
|
|
||||||
if (paths.length) UglifyJS.AST_Node.warn("Ignoring input files since --self was passed");
|
|
||||||
if (!options.wrap) options.wrap = "UglifyJS";
|
|
||||||
paths = UglifyJS.FILES;
|
|
||||||
}
|
|
||||||
if (paths.length) {
|
|
||||||
simple_glob(paths).forEach(function(name) {
|
|
||||||
files[convert_path(name)] = read_file(name);
|
|
||||||
});
|
|
||||||
run();
|
|
||||||
} else {
|
|
||||||
var chunks = [];
|
|
||||||
process.stdin.setEncoding("utf8");
|
|
||||||
process.stdin.on("data", function(chunk) {
|
|
||||||
chunks.push(chunk);
|
|
||||||
}).on("end", function() {
|
|
||||||
files = [ chunks.join("") ];
|
|
||||||
run();
|
|
||||||
});
|
|
||||||
process.stdin.resume();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function convert_ast(fn) {
|
if (ARGS.keep_fnames) {
|
||||||
return UglifyJS.AST_Node.from_mozilla_ast(Object.keys(files).reduce(fn, null));
|
if (COMPRESS) COMPRESS.keep_fnames = true;
|
||||||
|
if (MANGLE) MANGLE.keep_fnames = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function run() {
|
if (BEAUTIFY)
|
||||||
var content = options.sourceMap && options.sourceMap.content;
|
UglifyJS.merge(OUTPUT_OPTIONS, BEAUTIFY);
|
||||||
if (content && content != "inline") {
|
|
||||||
UglifyJS.AST_Node.info("Using input source map: " + content);
|
if (ARGS.comments) {
|
||||||
options.sourceMap.content = read_file(content, content);
|
if (/^\/.*\/[a-zA-Z]*$/.test(ARGS.comments)) {
|
||||||
}
|
var regex_pos = ARGS.comments.lastIndexOf("/");
|
||||||
try {
|
try {
|
||||||
if (options.parse) {
|
OUTPUT_OPTIONS.comments = new RegExp(ARGS.comments.substr(1, regex_pos - 1), ARGS.comments.substr(regex_pos + 1));
|
||||||
if (options.parse.acorn) {
|
} catch (e) {
|
||||||
files = convert_ast(function(toplevel, name) {
|
sys.error("ERROR: Invalid --comments: " + e.message);
|
||||||
return require("acorn").parse(files[name], {
|
|
||||||
locations: true,
|
|
||||||
program: toplevel,
|
|
||||||
sourceFile: name
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else if (options.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;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
} else if (ARGS.comments == "all") {
|
||||||
} catch (ex) {
|
OUTPUT_OPTIONS.comments = true;
|
||||||
fatal(ex);
|
|
||||||
}
|
|
||||||
var result;
|
|
||||||
if (specified["reduce-test"]) {
|
|
||||||
// load on demand - assumes cloned repository
|
|
||||||
var reduce_test = require("../test/reduce");
|
|
||||||
if (Object.keys(files).length != 1) fatal("can only test on a single file");
|
|
||||||
result = reduce_test(files[Object.keys(files)[0]], options, {
|
|
||||||
log: print_error,
|
|
||||||
verbose: true,
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
result = UglifyJS.minify(files, options);
|
OUTPUT_OPTIONS.comments = function(node, comment) {
|
||||||
}
|
var text = comment.value;
|
||||||
if (result.error) {
|
var type = comment.type;
|
||||||
var ex = result.error;
|
if (type == "comment2") {
|
||||||
if (ex.name == "SyntaxError") {
|
// multiline comment
|
||||||
print_error("Parse error at " + ex.filename + ":" + ex.line + "," + ex.col);
|
return /@preserve|@license|@cc_on/i.test(text);
|
||||||
var file = files[ex.filename];
|
|
||||||
if (file) {
|
|
||||||
var col = ex.col;
|
|
||||||
var lines = file.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, " ") + "^");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ex.defs) {
|
|
||||||
print_error("Supported options:");
|
|
||||||
print_error(format_object(ex.defs));
|
|
||||||
}
|
|
||||||
fatal(ex);
|
|
||||||
} else if (output == "ast") {
|
|
||||||
if (!options.compress && !options.mangle) {
|
|
||||||
var toplevel = result.ast;
|
|
||||||
if (!(toplevel instanceof UglifyJS.AST_Toplevel)) {
|
|
||||||
if (!(toplevel instanceof UglifyJS.AST_Statement)) toplevel = new UglifyJS.AST_SimpleStatement({
|
|
||||||
body: toplevel,
|
|
||||||
});
|
|
||||||
toplevel = new UglifyJS.AST_Toplevel({
|
|
||||||
body: [ toplevel ],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
toplevel.figure_out_scope({});
|
|
||||||
}
|
|
||||||
print(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() ? value.map(symdef) : undefined;
|
|
||||||
}
|
|
||||||
if (skip_key(key)) return;
|
|
||||||
if (value instanceof UglifyJS.AST_Token) return;
|
|
||||||
if (value instanceof UglifyJS.Dictionary) return;
|
|
||||||
if (value instanceof UglifyJS.AST_Node) {
|
|
||||||
var result = {
|
|
||||||
_class: "AST_" + value.TYPE
|
|
||||||
};
|
|
||||||
value.CTOR.PROPS.forEach(function(prop) {
|
|
||||||
result[prop] = value[prop];
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}, 2));
|
|
||||||
} else if (output == "spidermonkey") {
|
|
||||||
print(JSON.stringify(UglifyJS.minify(result.code, {
|
|
||||||
compress: false,
|
|
||||||
mangle: false,
|
|
||||||
output: {
|
|
||||||
ast: true,
|
|
||||||
code: false
|
|
||||||
},
|
|
||||||
}).ast.to_mozilla_ast(), null, 2));
|
|
||||||
} else if (output) {
|
|
||||||
fs.writeFileSync(output, result.code);
|
|
||||||
if (result.map) fs.writeFileSync(output + ".map", result.map);
|
|
||||||
} else {
|
|
||||||
print(result.code);
|
|
||||||
}
|
|
||||||
if (nameCache) fs.writeFileSync(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) {
|
var files = ARGS._.slice();
|
||||||
if (message instanceof Error) {
|
|
||||||
message = message.stack.replace(/^\S*?Error:/, "ERROR:")
|
if (ARGS.self) {
|
||||||
} else {
|
if (files.length > 0) {
|
||||||
message = "ERROR: " + message;
|
sys.error("WARN: Ignoring input files since --self was passed");
|
||||||
}
|
}
|
||||||
print_error(message);
|
files = UglifyJS.FILES;
|
||||||
|
if (!ARGS.wrap) ARGS.wrap = "UglifyJS";
|
||||||
|
ARGS.export_all = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ORIG_MAP = ARGS.in_source_map;
|
||||||
|
|
||||||
|
if (ORIG_MAP) {
|
||||||
|
ORIG_MAP = JSON.parse(fs.readFileSync(ORIG_MAP));
|
||||||
|
if (files.length == 0) {
|
||||||
|
sys.error("INFO: Using file from the input source map: " + ORIG_MAP.file);
|
||||||
|
files = [ ORIG_MAP.file ];
|
||||||
|
}
|
||||||
|
if (ARGS.source_map_root == null) {
|
||||||
|
ARGS.source_map_root = ORIG_MAP.sourceRoot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (files.length == 0) {
|
||||||
|
files = [ "-" ];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (files.indexOf("-") >= 0 && ARGS.source_map) {
|
||||||
|
sys.error("ERROR: Source map doesn't work with input from STDIN");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A file glob function that only supports "*" and "?" wildcards in the basename.
|
if (files.filter(function(el){ return el == "-" }).length > 1) {
|
||||||
// Example: "foo/bar/*baz??.*.js"
|
sys.error("ERROR: Can read a single file from STDIN (two or more dashes specified)");
|
||||||
// Argument `glob` may be a string or an array of strings.
|
process.exit(1);
|
||||||
// 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.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.sort().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) {
|
var STATS = {};
|
||||||
|
var OUTPUT_FILE = ARGS.o;
|
||||||
|
var TOPLEVEL = null;
|
||||||
|
var P_RELATIVE = ARGS.p && ARGS.p == "relative";
|
||||||
|
var SOURCES_CONTENT = {};
|
||||||
|
|
||||||
|
var SOURCE_MAP = ARGS.source_map ? UglifyJS.SourceMap({
|
||||||
|
file: P_RELATIVE ? path.relative(path.dirname(ARGS.source_map), OUTPUT_FILE) : OUTPUT_FILE,
|
||||||
|
root: ARGS.source_map_root,
|
||||||
|
orig: ORIG_MAP,
|
||||||
|
}) : null;
|
||||||
|
|
||||||
|
OUTPUT_OPTIONS.source_map = SOURCE_MAP;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return fs.readFileSync(path, "utf8");
|
var output = UglifyJS.OutputStream(OUTPUT_OPTIONS);
|
||||||
|
var compressor = COMPRESS && UglifyJS.Compressor(COMPRESS);
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
if (ex.code == "ENOENT" && default_value != null) return default_value;
|
if (ex instanceof UglifyJS.DefaultsError) {
|
||||||
fatal(ex);
|
sys.error(ex.msg);
|
||||||
|
sys.error("Supported options:");
|
||||||
|
sys.error(sys.inspect(ex.defs));
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse_js(value, options, flag) {
|
async.eachLimit(files, 1, function (file, cb) {
|
||||||
if (!options || typeof options != "object") options = {};
|
read_whole_file(file, function (err, code) {
|
||||||
if (typeof value == "string") try {
|
if (err) {
|
||||||
UglifyJS.parse(value, {
|
sys.error("ERROR: can't read file: " + file);
|
||||||
expression: true
|
process.exit(1);
|
||||||
}).walk(new UglifyJS.TreeWalker(function(node) {
|
}
|
||||||
if (node instanceof UglifyJS.AST_Assign) {
|
if (ARGS.p != null) {
|
||||||
var name = node.left.print_to_string();
|
if (P_RELATIVE) {
|
||||||
var value = node.right;
|
file = path.relative(path.dirname(ARGS.source_map), file).replace(/\\/g, '/');
|
||||||
if (flag) {
|
|
||||||
options[name] = value;
|
|
||||||
} else if (value instanceof UglifyJS.AST_Array) {
|
|
||||||
options[name] = value.elements.map(to_string);
|
|
||||||
} else {
|
} else {
|
||||||
options[name] = to_string(value);
|
var p = parseInt(ARGS.p, 10);
|
||||||
|
if (!isNaN(p)) {
|
||||||
|
file = file.replace(/^\/+/, "").split(/\/+/).slice(ARGS.p).join("/");
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (node instanceof UglifyJS.AST_Symbol || node instanceof UglifyJS.AST_PropAccess) {
|
|
||||||
var name = node.print_to_string();
|
|
||||||
options[name] = true;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (!(node instanceof UglifyJS.AST_Sequence)) throw node;
|
SOURCES_CONTENT[file] = code;
|
||||||
|
time_it("parse", function(){
|
||||||
function to_string(value) {
|
if (ARGS.spidermonkey) {
|
||||||
return value instanceof UglifyJS.AST_Constant ? value.value : value.print_to_string({
|
var program = JSON.parse(code);
|
||||||
quote_keys: true
|
if (!TOPLEVEL) TOPLEVEL = program;
|
||||||
|
else TOPLEVEL.body = TOPLEVEL.body.concat(program.body);
|
||||||
|
}
|
||||||
|
else if (ARGS.acorn) {
|
||||||
|
TOPLEVEL = acorn.parse(code, {
|
||||||
|
locations : true,
|
||||||
|
sourceFile : file,
|
||||||
|
program : TOPLEVEL
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
try {
|
||||||
|
TOPLEVEL = UglifyJS.parse(code, {
|
||||||
|
filename : file,
|
||||||
|
toplevel : TOPLEVEL,
|
||||||
|
expression : ARGS.expr,
|
||||||
|
bare_returns : ARGS.bare_returns,
|
||||||
|
});
|
||||||
|
} catch(ex) {
|
||||||
|
if (ex instanceof UglifyJS.JS_Parse_Error) {
|
||||||
|
sys.error("Parse error at " + file + ":" + ex.line + "," + ex.col);
|
||||||
|
sys.error(ex.message);
|
||||||
|
sys.error(ex.stack);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
cb();
|
||||||
|
});
|
||||||
|
}, function () {
|
||||||
|
if (ARGS.acorn || ARGS.spidermonkey) time_it("convert_ast", function(){
|
||||||
|
TOPLEVEL = UglifyJS.AST_Node.from_mozilla_ast(TOPLEVEL);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (ARGS.wrap) {
|
||||||
|
TOPLEVEL = TOPLEVEL.wrap_commonjs(ARGS.wrap, ARGS.export_all);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ARGS.enclose) {
|
||||||
|
var arg_parameter_list = ARGS.enclose;
|
||||||
|
if (arg_parameter_list === true) {
|
||||||
|
arg_parameter_list = [];
|
||||||
|
}
|
||||||
|
else if (!(arg_parameter_list instanceof Array)) {
|
||||||
|
arg_parameter_list = [arg_parameter_list];
|
||||||
|
}
|
||||||
|
TOPLEVEL = TOPLEVEL.wrap_enclose(arg_parameter_list);
|
||||||
|
}
|
||||||
|
|
||||||
|
var SCOPE_IS_NEEDED = COMPRESS || MANGLE || ARGS.lint;
|
||||||
|
|
||||||
|
if (SCOPE_IS_NEEDED) {
|
||||||
|
time_it("scope", function(){
|
||||||
|
TOPLEVEL.figure_out_scope({ screw_ie8: ARGS.screw_ie8 });
|
||||||
|
if (ARGS.lint) {
|
||||||
|
TOPLEVEL.scope_warnings();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (COMPRESS) {
|
||||||
|
time_it("squeeze", function(){
|
||||||
|
TOPLEVEL = TOPLEVEL.transform(compressor);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SCOPE_IS_NEEDED) {
|
||||||
|
time_it("scope", function(){
|
||||||
|
TOPLEVEL.figure_out_scope({ screw_ie8: ARGS.screw_ie8 });
|
||||||
|
if (MANGLE) {
|
||||||
|
TOPLEVEL.compute_char_frequency(MANGLE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MANGLE) time_it("mangle", function(){
|
||||||
|
TOPLEVEL.mangle_names(MANGLE);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (ARGS.source_map_include_sources) {
|
||||||
|
for (var file in SOURCES_CONTENT) {
|
||||||
|
if (SOURCES_CONTENT.hasOwnProperty(file)) {
|
||||||
|
SOURCE_MAP.get().setSourceContent(file, SOURCES_CONTENT[file]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
time_it("generate", function(){
|
||||||
|
TOPLEVEL.print(output);
|
||||||
|
});
|
||||||
|
|
||||||
|
output = output.get();
|
||||||
|
|
||||||
|
if (SOURCE_MAP) {
|
||||||
|
fs.writeFileSync(ARGS.source_map, SOURCE_MAP, "utf8");
|
||||||
|
var source_map_url = ARGS.source_map_url || (
|
||||||
|
P_RELATIVE
|
||||||
|
? path.relative(path.dirname(OUTPUT_FILE), ARGS.source_map)
|
||||||
|
: ARGS.source_map
|
||||||
|
);
|
||||||
|
output += "\n//# sourceMappingURL=" + source_map_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (OUTPUT_FILE) {
|
||||||
|
fs.writeFileSync(OUTPUT_FILE, output, "utf8");
|
||||||
|
} else {
|
||||||
|
sys.print(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ARGS.stats) {
|
||||||
|
sys.error(UglifyJS.string_template("Timing information (compressed {count} files):", {
|
||||||
|
count: files.length
|
||||||
}));
|
}));
|
||||||
|
for (var i in STATS) if (STATS.hasOwnProperty(i)) {
|
||||||
|
sys.error(UglifyJS.string_template("- {name}: {time}s", {
|
||||||
|
name: i,
|
||||||
|
time: (STATS[i] / 1000).toFixed(3)
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/* -----[ functions ]----- */
|
||||||
|
|
||||||
|
function normalize(o) {
|
||||||
|
for (var i in o) if (o.hasOwnProperty(i) && /-/.test(i)) {
|
||||||
|
o[i.replace(/-/g, "_")] = o[i];
|
||||||
|
delete o[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getOptions(x, constants) {
|
||||||
|
x = ARGS[x];
|
||||||
|
if (!x) return null;
|
||||||
|
var ret = {};
|
||||||
|
if (x !== true) {
|
||||||
|
var ast;
|
||||||
|
try {
|
||||||
|
ast = UglifyJS.parse(x, { expression: true });
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
if (flag) {
|
if (ex instanceof UglifyJS.JS_Parse_Error) {
|
||||||
fatal("cannot parse arguments for '" + flag + "': " + value);
|
sys.error("Error parsing arguments in: " + x);
|
||||||
} else {
|
process.exit(1);
|
||||||
options[value] = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return options;
|
ast.walk(new UglifyJS.TreeWalker(function(node){
|
||||||
|
if (node instanceof UglifyJS.AST_Seq) return; // descend
|
||||||
|
if (node instanceof UglifyJS.AST_Assign) {
|
||||||
|
var name = node.left.print_to_string({ beautify: false }).replace(/-/g, "_");
|
||||||
|
var value = node.right;
|
||||||
|
if (constants)
|
||||||
|
value = new Function("return (" + value.print_to_string() + ")")();
|
||||||
|
ret[name] = value;
|
||||||
|
return true; // no descend
|
||||||
}
|
}
|
||||||
|
if (node instanceof UglifyJS.AST_Symbol || node instanceof UglifyJS.AST_Binary) {
|
||||||
function skip_key(key) {
|
var name = node.print_to_string({ beautify: false }).replace(/-/g, "_");
|
||||||
return skip_keys.indexOf(key) >= 0;
|
ret[name] = true;
|
||||||
|
return true; // no descend
|
||||||
|
}
|
||||||
|
sys.error(node.TYPE)
|
||||||
|
sys.error("Error parsing arguments in: " + x);
|
||||||
|
process.exit(1);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function symdef(def) {
|
|
||||||
var ret = (1e6 + def.id) + " " + def.name;
|
|
||||||
if (def.mangled_name) ret += " " + def.mangled_name;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
function format_object(obj) {
|
function read_whole_file(filename, cb) {
|
||||||
var lines = [];
|
if (filename == "-") {
|
||||||
var padding = "";
|
var chunks = [];
|
||||||
Object.keys(obj).map(function(name) {
|
process.stdin.setEncoding('utf-8');
|
||||||
if (padding.length < name.length) padding = Array(name.length + 1).join(" ");
|
process.stdin.on('data', function (chunk) {
|
||||||
return [ name, JSON.stringify(obj[name]) ];
|
chunks.push(chunk);
|
||||||
}).forEach(function(tokens) {
|
}).on('end', function () {
|
||||||
lines.push(" " + tokens[0] + padding.slice(tokens[0].length - 2) + tokens[1]);
|
cb(null, chunks.join(""));
|
||||||
});
|
});
|
||||||
return lines.join("\n");
|
process.openStdin();
|
||||||
|
} else {
|
||||||
|
fs.readFile(filename, "utf-8", cb);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function print_error(msg) {
|
function time_it(name, cont) {
|
||||||
process.stderr.write(msg);
|
var t1 = new Date().getTime();
|
||||||
process.stderr.write("\n");
|
var ret = cont();
|
||||||
|
if (ARGS.stats) {
|
||||||
|
var spent = new Date().getTime() - t1;
|
||||||
|
if (STATS[name]) STATS[name] += spent;
|
||||||
|
else STATS[name] = spent;
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
function print(txt) {
|
|
||||||
process.stdout.write(txt);
|
|
||||||
process.stdout.write("\n");
|
|
||||||
}
|
}
|
||||||
|
|||||||
1027
lib/ast.js
1027
lib/ast.js
File diff suppressed because it is too large
Load Diff
9723
lib/compress.js
9723
lib/compress.js
File diff suppressed because it is too large
Load Diff
263
lib/minify.js
263
lib/minify.js
@@ -1,263 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
var to_ascii, to_base64;
|
|
||||||
if (typeof Buffer == "undefined") {
|
|
||||||
to_ascii = atob;
|
|
||||||
to_base64 = btoa;
|
|
||||||
} else if (typeof Buffer.alloc == "undefined") {
|
|
||||||
to_ascii = function(b64) {
|
|
||||||
return new Buffer(b64, "base64").toString();
|
|
||||||
};
|
|
||||||
to_base64 = function(str) {
|
|
||||||
return new Buffer(str).toString("base64");
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
to_ascii = function(b64) {
|
|
||||||
return Buffer.from(b64, "base64").toString();
|
|
||||||
};
|
|
||||||
to_base64 = function(str) {
|
|
||||||
return Buffer.from(str).toString("base64");
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function read_source_map(name, toplevel) {
|
|
||||||
var comments = toplevel.end.comments_after;
|
|
||||||
for (var i = comments.length; --i >= 0;) {
|
|
||||||
var comment = comments[i];
|
|
||||||
if (comment.type != "comment1") break;
|
|
||||||
var match = /^# ([^\s=]+)=(\S+)\s*$/.exec(comment.value);
|
|
||||||
if (!match) break;
|
|
||||||
if (match[1] == "sourceMappingURL") {
|
|
||||||
match = /^data:application\/json(;.*?)?;base64,(\S+)$/.exec(match[2]);
|
|
||||||
if (!match) break;
|
|
||||||
return to_ascii(match[2]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AST_Node.warn("inline source map not found: " + name);
|
|
||||||
}
|
|
||||||
|
|
||||||
function parse_source_map(content) {
|
|
||||||
try {
|
|
||||||
return JSON.parse(content);
|
|
||||||
} catch (ex) {
|
|
||||||
throw new Error("invalid input source map: " + content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 Dictionary();
|
|
||||||
} else if (!(cache.props instanceof Dictionary)) {
|
|
||||||
cache.props = Dictionary.fromObject(cache.props);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function to_json(cache) {
|
|
||||||
return {
|
|
||||||
props: cache.props.toObject()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function minify(files, options) {
|
|
||||||
try {
|
|
||||||
options = defaults(options, {
|
|
||||||
compress: {},
|
|
||||||
enclose: false,
|
|
||||||
ie8: false,
|
|
||||||
keep_fnames: false,
|
|
||||||
mangle: {},
|
|
||||||
nameCache: null,
|
|
||||||
output: {},
|
|
||||||
parse: {},
|
|
||||||
rename: undefined,
|
|
||||||
sourceMap: false,
|
|
||||||
timings: false,
|
|
||||||
toplevel: false,
|
|
||||||
validate: false,
|
|
||||||
warnings: false,
|
|
||||||
wrap: false,
|
|
||||||
}, true);
|
|
||||||
if (options.validate) AST_Node.enable_validation();
|
|
||||||
var timings = options.timings && {
|
|
||||||
start: Date.now()
|
|
||||||
};
|
|
||||||
if (options.rename === undefined) {
|
|
||||||
options.rename = options.compress && options.mangle;
|
|
||||||
}
|
|
||||||
set_shorthand("ie8", options, [ "compress", "mangle", "output" ]);
|
|
||||||
set_shorthand("keep_fnames", options, [ "compress", "mangle" ]);
|
|
||||||
set_shorthand("toplevel", options, [ "compress", "mangle" ]);
|
|
||||||
var quoted_props;
|
|
||||||
if (options.mangle) {
|
|
||||||
options.mangle = defaults(options.mangle, {
|
|
||||||
cache: options.nameCache && (options.nameCache.vars || {}),
|
|
||||||
eval: false,
|
|
||||||
ie8: false,
|
|
||||||
keep_fnames: false,
|
|
||||||
properties: false,
|
|
||||||
reserved: [],
|
|
||||||
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, {
|
|
||||||
content: null,
|
|
||||||
filename: null,
|
|
||||||
includeSources: false,
|
|
||||||
names: true,
|
|
||||||
root: null,
|
|
||||||
url: null,
|
|
||||||
}, true);
|
|
||||||
}
|
|
||||||
var warnings = [];
|
|
||||||
if (options.warnings) AST_Node.log_function(function(warning) {
|
|
||||||
warnings.push(warning);
|
|
||||||
}, options.warnings == "verbose");
|
|
||||||
if (timings) timings.parse = Date.now();
|
|
||||||
var toplevel;
|
|
||||||
if (files instanceof AST_Toplevel) {
|
|
||||||
toplevel = files;
|
|
||||||
} else {
|
|
||||||
if (typeof files == "string") {
|
|
||||||
files = [ files ];
|
|
||||||
}
|
|
||||||
options.parse = options.parse || {};
|
|
||||||
options.parse.toplevel = null;
|
|
||||||
var source_map_content = options.sourceMap && options.sourceMap.content;
|
|
||||||
if (typeof source_map_content == "string" && source_map_content != "inline") {
|
|
||||||
source_map_content = parse_source_map(source_map_content);
|
|
||||||
}
|
|
||||||
if (source_map_content) options.sourceMap.orig = Object.create(null);
|
|
||||||
for (var name in files) if (HOP(files, name)) {
|
|
||||||
options.parse.filename = name;
|
|
||||||
options.parse.toplevel = toplevel = parse(files[name], options.parse);
|
|
||||||
if (source_map_content == "inline") {
|
|
||||||
var inlined_content = read_source_map(name, toplevel);
|
|
||||||
if (inlined_content) {
|
|
||||||
options.sourceMap.orig[name] = parse_source_map(inlined_content);
|
|
||||||
}
|
|
||||||
} else if (source_map_content) {
|
|
||||||
options.sourceMap.orig[name] = source_map_content;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (quoted_props) {
|
|
||||||
reserve_quoted_keys(toplevel, quoted_props);
|
|
||||||
}
|
|
||||||
[ "enclose", "wrap" ].forEach(function(action) {
|
|
||||||
var option = options[action];
|
|
||||||
if (!option) return;
|
|
||||||
var orig = toplevel.print_to_string().slice(0, -1);
|
|
||||||
toplevel = toplevel[action](option);
|
|
||||||
files[toplevel.start.file] = toplevel.print_to_string().replace(orig, "");
|
|
||||||
});
|
|
||||||
if (options.validate) toplevel.validate_ast();
|
|
||||||
if (timings) timings.rename = Date.now();
|
|
||||||
if (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).compress(toplevel);
|
|
||||||
if (options.validate) toplevel.validate_ast();
|
|
||||||
}
|
|
||||||
if (timings) timings.scope = Date.now();
|
|
||||||
if (options.mangle) toplevel.figure_out_scope(options.mangle);
|
|
||||||
if (timings) timings.mangle = Date.now();
|
|
||||||
if (options.mangle) {
|
|
||||||
toplevel.compute_char_frequency(options.mangle);
|
|
||||||
toplevel.mangle_names(options.mangle);
|
|
||||||
}
|
|
||||||
if (timings) timings.properties = Date.now();
|
|
||||||
if (options.mangle && options.mangle.properties) mangle_properties(toplevel, options.mangle.properties);
|
|
||||||
if (timings) timings.output = Date.now();
|
|
||||||
var result = {};
|
|
||||||
if (options.output.ast) {
|
|
||||||
result.ast = toplevel;
|
|
||||||
}
|
|
||||||
if (!HOP(options.output, "code") || options.output.code) {
|
|
||||||
if (options.sourceMap) {
|
|
||||||
options.output.source_map = SourceMap(options.sourceMap);
|
|
||||||
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.output.source_map.setSourceContent(name, files[name]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
delete options.output.ast;
|
|
||||||
delete options.output.code;
|
|
||||||
var stream = OutputStream(options.output);
|
|
||||||
toplevel.print(stream);
|
|
||||||
result.code = stream.get();
|
|
||||||
if (options.sourceMap) {
|
|
||||||
result.map = options.output.source_map.toString();
|
|
||||||
var url = options.sourceMap.url;
|
|
||||||
if (url) {
|
|
||||||
result.code = result.code.replace(/\n\/\/# sourceMappingURL=\S+\s*$/, "");
|
|
||||||
if (url == "inline") {
|
|
||||||
result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(result.map);
|
|
||||||
} else {
|
|
||||||
result.code += "\n//# sourceMappingURL=" + url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (options.nameCache && options.mangle) {
|
|
||||||
if (options.mangle.cache) options.nameCache.vars = to_json(options.mangle.cache);
|
|
||||||
if (options.mangle.properties && options.mangle.properties.cache) {
|
|
||||||
options.nameCache.props = to_json(options.mangle.properties.cache);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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.output - timings.properties),
|
|
||||||
output: 1e-3 * (timings.end - timings.output),
|
|
||||||
total: 1e-3 * (timings.end - timings.start)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (warnings.length) {
|
|
||||||
result.warnings = warnings;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
} catch (ex) {
|
|
||||||
return { error: ex };
|
|
||||||
} finally {
|
|
||||||
AST_Node.disable_validation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
|
||||||
A JavaScript tokenizer / parser / beautifier / compressor.
|
A JavaScript tokenizer / parser / beautifier / compressor.
|
||||||
https://github.com/mishoo/UglifyJS
|
https://github.com/mishoo/UglifyJS2
|
||||||
|
|
||||||
-------------------------------- (C) ---------------------------------
|
-------------------------------- (C) ---------------------------------
|
||||||
|
|
||||||
@@ -44,53 +44,21 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
(function(){
|
(function(){
|
||||||
function normalize_directives(body) {
|
|
||||||
var in_directive = true;
|
|
||||||
for (var i = 0; i < body.length; i++) {
|
|
||||||
if (in_directive && body[i] instanceof AST_Statement && body[i].body instanceof AST_String) {
|
|
||||||
body[i] = new AST_Directive({
|
|
||||||
start: body[i].start,
|
|
||||||
end: body[i].end,
|
|
||||||
value: body[i].body.value
|
|
||||||
});
|
|
||||||
} else if (in_directive && !(body[i] instanceof AST_Statement && body[i].body instanceof AST_String)) {
|
|
||||||
in_directive = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
var MOZ_TO_ME = {
|
var MOZ_TO_ME = {
|
||||||
Program: function(M) {
|
|
||||||
return new AST_Toplevel({
|
|
||||||
start: my_start_token(M),
|
|
||||||
end: my_end_token(M),
|
|
||||||
body: normalize_directives(M.body.map(from_moz))
|
|
||||||
});
|
|
||||||
},
|
|
||||||
FunctionDeclaration: function(M) {
|
|
||||||
return new AST_Defun({
|
|
||||||
start: my_start_token(M),
|
|
||||||
end: my_end_token(M),
|
|
||||||
name: from_moz(M.id),
|
|
||||||
argnames: M.params.map(from_moz),
|
|
||||||
body: normalize_directives(from_moz(M.body).body)
|
|
||||||
});
|
|
||||||
},
|
|
||||||
FunctionExpression: function(M) {
|
|
||||||
return new AST_Function({
|
|
||||||
start: my_start_token(M),
|
|
||||||
end: my_end_token(M),
|
|
||||||
name: from_moz(M.id),
|
|
||||||
argnames: M.params.map(from_moz),
|
|
||||||
body: normalize_directives(from_moz(M.body).body)
|
|
||||||
});
|
|
||||||
},
|
|
||||||
ExpressionStatement: function(M) {
|
ExpressionStatement: function(M) {
|
||||||
|
var expr = M.expression;
|
||||||
|
if (expr.type === "Literal" && typeof expr.value === "string") {
|
||||||
|
return new AST_Directive({
|
||||||
|
start: my_start_token(M),
|
||||||
|
end: my_end_token(M),
|
||||||
|
value: expr.value
|
||||||
|
});
|
||||||
|
}
|
||||||
return new AST_SimpleStatement({
|
return new AST_SimpleStatement({
|
||||||
start: my_start_token(M),
|
start: my_start_token(M),
|
||||||
end: my_end_token(M),
|
end: my_end_token(M),
|
||||||
body: from_moz(M.expression)
|
body: from_moz(expr)
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
TryStatement: function(M) {
|
TryStatement: function(M) {
|
||||||
@@ -108,28 +76,23 @@
|
|||||||
},
|
},
|
||||||
Property: function(M) {
|
Property: function(M) {
|
||||||
var key = M.key;
|
var key = M.key;
|
||||||
|
var name = key.type == "Identifier" ? key.name : key.value;
|
||||||
var args = {
|
var args = {
|
||||||
start : my_start_token(key),
|
start : my_start_token(key),
|
||||||
end : my_end_token(M.value),
|
end : my_end_token(M.value),
|
||||||
key : "" + key[key.type == "Identifier" ? "name" : "value"],
|
key : name,
|
||||||
value : from_moz(M.value)
|
value : from_moz(M.value)
|
||||||
};
|
};
|
||||||
if (M.kind == "init") return new AST_ObjectKeyVal(args);
|
switch (M.kind) {
|
||||||
args.key = new AST_SymbolAccessor({
|
case "init":
|
||||||
name: args.key
|
return new AST_ObjectKeyVal(args);
|
||||||
});
|
case "set":
|
||||||
args.value = new AST_Accessor(args.value);
|
args.value.name = from_moz(key);
|
||||||
if (M.kind == "get") return new AST_ObjectGetter(args);
|
return new AST_ObjectSetter(args);
|
||||||
if (M.kind == "set") return new AST_ObjectSetter(args);
|
case "get":
|
||||||
},
|
args.value.name = from_moz(key);
|
||||||
ArrayExpression: function(M) {
|
return new AST_ObjectGetter(args);
|
||||||
return new AST_Array({
|
}
|
||||||
start : my_start_token(M),
|
|
||||||
end : my_end_token(M),
|
|
||||||
elements : M.elements.map(function(elem) {
|
|
||||||
return elem === null ? new AST_Hole() : from_moz(elem);
|
|
||||||
})
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
ObjectExpression: function(M) {
|
ObjectExpression: function(M) {
|
||||||
return new AST_Object({
|
return new AST_Object({
|
||||||
@@ -142,11 +105,7 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
SequenceExpression: function(M) {
|
SequenceExpression: function(M) {
|
||||||
return new AST_Sequence({
|
return AST_Seq.from_array(M.expressions.map(from_moz));
|
||||||
start : my_start_token(M),
|
|
||||||
end : my_end_token(M),
|
|
||||||
expressions: M.expressions.map(from_moz)
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
MemberExpression: function(M) {
|
MemberExpression: function(M) {
|
||||||
return new (M.computed ? AST_Sub : AST_Dot)({
|
return new (M.computed ? AST_Sub : AST_Dot)({
|
||||||
@@ -165,7 +124,7 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
VariableDeclaration: function(M) {
|
VariableDeclaration: function(M) {
|
||||||
return new AST_Var({
|
return new (M.kind === "const" ? AST_Const : AST_Var)({
|
||||||
start : my_start_token(M),
|
start : my_start_token(M),
|
||||||
end : my_end_token(M),
|
end : my_end_token(M),
|
||||||
definitions : M.declarations.map(from_moz)
|
definitions : M.declarations.map(from_moz)
|
||||||
@@ -177,17 +136,6 @@
|
|||||||
end : my_end_token(M)
|
end : my_end_token(M)
|
||||||
};
|
};
|
||||||
if (val === null) return new AST_Null(args);
|
if (val === null) return new AST_Null(args);
|
||||||
var rx = M.regex;
|
|
||||||
if (rx && rx.pattern) {
|
|
||||||
// RegExpLiteral as per ESTree AST spec
|
|
||||||
args.value = new RegExp(rx.pattern, rx.flags);
|
|
||||||
args.value.raw_source = rx.pattern;
|
|
||||||
return new AST_RegExp(args);
|
|
||||||
} else if (rx) {
|
|
||||||
// support legacy RegExp
|
|
||||||
args.value = M.regex && M.raw ? M.raw : val;
|
|
||||||
return new AST_RegExp(args);
|
|
||||||
}
|
|
||||||
switch (typeof val) {
|
switch (typeof val) {
|
||||||
case "string":
|
case "string":
|
||||||
args.value = val;
|
args.value = val;
|
||||||
@@ -197,12 +145,15 @@
|
|||||||
return new AST_Number(args);
|
return new AST_Number(args);
|
||||||
case "boolean":
|
case "boolean":
|
||||||
return new (val ? AST_True : AST_False)(args);
|
return new (val ? AST_True : AST_False)(args);
|
||||||
|
default:
|
||||||
|
args.value = val;
|
||||||
|
return new AST_RegExp(args);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Identifier: function(M) {
|
Identifier: function(M) {
|
||||||
var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2];
|
var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2];
|
||||||
return new ( p.type == "LabeledStatement" ? AST_Label
|
return new ( p.type == "LabeledStatement" ? AST_Label
|
||||||
: p.type == "VariableDeclarator" && p.id === M ? AST_SymbolVar
|
: p.type == "VariableDeclarator" && p.id === M ? (p.kind == "const" ? AST_SymbolConst : AST_SymbolVar)
|
||||||
: p.type == "FunctionExpression" ? (p.id === M ? AST_SymbolLambda : AST_SymbolFunarg)
|
: p.type == "FunctionExpression" ? (p.id === M ? AST_SymbolLambda : AST_SymbolFunarg)
|
||||||
: p.type == "FunctionDeclaration" ? (p.id === M ? AST_SymbolDefun : AST_SymbolFunarg)
|
: p.type == "FunctionDeclaration" ? (p.id === M ? AST_SymbolDefun : AST_SymbolFunarg)
|
||||||
: p.type == "CatchClause" ? AST_SymbolCatch
|
: p.type == "CatchClause" ? AST_SymbolCatch
|
||||||
@@ -212,14 +163,7 @@
|
|||||||
end : my_end_token(M),
|
end : my_end_token(M),
|
||||||
name : M.name
|
name : M.name
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
ThisExpression: function(M) {
|
|
||||||
return new AST_This({
|
|
||||||
start : my_start_token(M),
|
|
||||||
end : my_end_token(M),
|
|
||||||
name : "this",
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
MOZ_TO_ME.UpdateExpression =
|
MOZ_TO_ME.UpdateExpression =
|
||||||
@@ -234,6 +178,7 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
map("Program", AST_Toplevel, "body@body");
|
||||||
map("EmptyStatement", AST_EmptyStatement);
|
map("EmptyStatement", AST_EmptyStatement);
|
||||||
map("BlockStatement", AST_BlockStatement, "body@body");
|
map("BlockStatement", AST_BlockStatement, "body@body");
|
||||||
map("IfStatement", AST_If, "test>condition, consequent>body, alternate>alternative");
|
map("IfStatement", AST_If, "test>condition, consequent>body, alternate>alternative");
|
||||||
@@ -249,9 +194,13 @@
|
|||||||
map("ForStatement", AST_For, "init>init, test>condition, update>step, body>body");
|
map("ForStatement", AST_For, "init>init, test>condition, update>step, body>body");
|
||||||
map("ForInStatement", AST_ForIn, "left>init, right>object, body>body");
|
map("ForInStatement", AST_ForIn, "left>init, right>object, body>body");
|
||||||
map("DebuggerStatement", AST_Debugger);
|
map("DebuggerStatement", AST_Debugger);
|
||||||
|
map("FunctionDeclaration", AST_Defun, "id>name, params@argnames, body%body");
|
||||||
map("VariableDeclarator", AST_VarDef, "id>name, init>value");
|
map("VariableDeclarator", AST_VarDef, "id>name, init>value");
|
||||||
map("CatchClause", AST_Catch, "param>argname, body%body");
|
map("CatchClause", AST_Catch, "param>argname, body%body");
|
||||||
|
|
||||||
|
map("ThisExpression", AST_This);
|
||||||
|
map("ArrayExpression", AST_Array, "elements@elements");
|
||||||
|
map("FunctionExpression", AST_Function, "id>name, params@argnames, body%body");
|
||||||
map("BinaryExpression", AST_Binary, "operator=operator, left>left, right>right");
|
map("BinaryExpression", AST_Binary, "operator=operator, left>left, right>right");
|
||||||
map("LogicalExpression", AST_Binary, "operator=operator, left>left, right>right");
|
map("LogicalExpression", AST_Binary, "operator=operator, left>left, right>right");
|
||||||
map("AssignmentExpression", AST_Assign, "operator=operator, left>left, right>right");
|
map("AssignmentExpression", AST_Assign, "operator=operator, left>left, right>right");
|
||||||
@@ -259,28 +208,6 @@
|
|||||||
map("NewExpression", AST_New, "callee>expression, arguments@args");
|
map("NewExpression", AST_New, "callee>expression, arguments@args");
|
||||||
map("CallExpression", AST_Call, "callee>expression, arguments@args");
|
map("CallExpression", AST_Call, "callee>expression, arguments@args");
|
||||||
|
|
||||||
def_to_moz(AST_Toplevel, function To_Moz_Program(M) {
|
|
||||||
return to_moz_scope("Program", M);
|
|
||||||
});
|
|
||||||
|
|
||||||
def_to_moz(AST_Defun, function To_Moz_FunctionDeclaration(M) {
|
|
||||||
return {
|
|
||||||
type: "FunctionDeclaration",
|
|
||||||
id: to_moz(M.name),
|
|
||||||
params: M.argnames.map(to_moz),
|
|
||||||
body: to_moz_scope("BlockStatement", M)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
def_to_moz(AST_Function, function To_Moz_FunctionExpression(M) {
|
|
||||||
return {
|
|
||||||
type: "FunctionExpression",
|
|
||||||
id: to_moz(M.name),
|
|
||||||
params: M.argnames.map(to_moz),
|
|
||||||
body: to_moz_scope("BlockStatement", M)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
def_to_moz(AST_Directive, function To_Moz_Directive(M) {
|
def_to_moz(AST_Directive, function To_Moz_Directive(M) {
|
||||||
return {
|
return {
|
||||||
type: "ExpressionStatement",
|
type: "ExpressionStatement",
|
||||||
@@ -328,15 +255,15 @@
|
|||||||
def_to_moz(AST_Definitions, function To_Moz_VariableDeclaration(M) {
|
def_to_moz(AST_Definitions, function To_Moz_VariableDeclaration(M) {
|
||||||
return {
|
return {
|
||||||
type: "VariableDeclaration",
|
type: "VariableDeclaration",
|
||||||
kind: "var",
|
kind: M instanceof AST_Const ? "const" : "var",
|
||||||
declarations: M.definitions.map(to_moz)
|
declarations: M.definitions.map(to_moz)
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
def_to_moz(AST_Sequence, function To_Moz_SequenceExpression(M) {
|
def_to_moz(AST_Seq, function To_Moz_SequenceExpression(M) {
|
||||||
return {
|
return {
|
||||||
type: "SequenceExpression",
|
type: "SequenceExpression",
|
||||||
expressions: M.expressions.map(to_moz)
|
expressions: M.to_array().map(to_moz)
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -368,13 +295,6 @@
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
def_to_moz(AST_Array, function To_Moz_ArrayExpression(M) {
|
|
||||||
return {
|
|
||||||
type: "ArrayExpression",
|
|
||||||
elements: M.elements.map(to_moz)
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
def_to_moz(AST_Object, function To_Moz_ObjectExpression(M) {
|
def_to_moz(AST_Object, function To_Moz_ObjectExpression(M) {
|
||||||
return {
|
return {
|
||||||
type: "ObjectExpression",
|
type: "ObjectExpression",
|
||||||
@@ -383,10 +303,11 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
def_to_moz(AST_ObjectProperty, function To_Moz_Property(M) {
|
def_to_moz(AST_ObjectProperty, function To_Moz_Property(M) {
|
||||||
var key = {
|
var key = (
|
||||||
type: "Literal",
|
is_identifier(M.key)
|
||||||
value: M.key instanceof AST_SymbolAccessor ? M.key.name : M.key
|
? {type: "Identifier", name: M.key}
|
||||||
};
|
: {type: "Literal", value: M.key}
|
||||||
|
);
|
||||||
var kind;
|
var kind;
|
||||||
if (M instanceof AST_ObjectKeyVal) {
|
if (M instanceof AST_ObjectKeyVal) {
|
||||||
kind = "init";
|
kind = "init";
|
||||||
@@ -409,25 +330,7 @@
|
|||||||
var def = M.definition();
|
var def = M.definition();
|
||||||
return {
|
return {
|
||||||
type: "Identifier",
|
type: "Identifier",
|
||||||
name: def && def.mangled_name || M.name
|
name: def ? def.mangled_name || def.name : M.name
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
def_to_moz(AST_This, function To_Moz_ThisExpression() {
|
|
||||||
return { type: "ThisExpression" };
|
|
||||||
});
|
|
||||||
|
|
||||||
def_to_moz(AST_RegExp, function To_Moz_RegExpLiteral(M) {
|
|
||||||
var flags = M.value.toString().match(/[gimuy]*$/)[0];
|
|
||||||
var value = "/" + M.value.raw_source + "/" + flags;
|
|
||||||
return {
|
|
||||||
type: "Literal",
|
|
||||||
value: value,
|
|
||||||
raw: value,
|
|
||||||
regex: {
|
|
||||||
pattern: M.value.raw_source,
|
|
||||||
flags: flags
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -440,15 +343,13 @@
|
|||||||
prefix: true,
|
prefix: true,
|
||||||
argument: {
|
argument: {
|
||||||
type: "Literal",
|
type: "Literal",
|
||||||
value: -value,
|
value: -value
|
||||||
raw: M.start.raw
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
type: "Literal",
|
type: "Literal",
|
||||||
value: value,
|
value: value
|
||||||
raw: M.start.raw
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -468,12 +369,6 @@
|
|||||||
|
|
||||||
/* -----[ tools ]----- */
|
/* -----[ tools ]----- */
|
||||||
|
|
||||||
function raw_token(moznode) {
|
|
||||||
if (moznode.type == "Literal") {
|
|
||||||
return moznode.raw != null ? moznode.raw : moznode.value + "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function my_start_token(moznode) {
|
function my_start_token(moznode) {
|
||||||
var loc = moznode.loc, start = loc && loc.start;
|
var loc = moznode.loc, start = loc && loc.start;
|
||||||
var range = moznode.range;
|
var range = moznode.range;
|
||||||
@@ -484,10 +379,9 @@
|
|||||||
pos : range ? range[0] : moznode.start,
|
pos : range ? range[0] : moznode.start,
|
||||||
endline : start && start.line,
|
endline : start && start.line,
|
||||||
endcol : start && start.column,
|
endcol : start && start.column,
|
||||||
endpos : range ? range[0] : moznode.start,
|
endpos : range ? range[0] : moznode.start
|
||||||
raw : raw_token(moznode),
|
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
function my_end_token(moznode) {
|
function my_end_token(moznode) {
|
||||||
var loc = moznode.loc, end = loc && loc.end;
|
var loc = moznode.loc, end = loc && loc.end;
|
||||||
@@ -499,14 +393,13 @@
|
|||||||
pos : range ? range[1] : moznode.end,
|
pos : range ? range[1] : moznode.end,
|
||||||
endline : end && end.line,
|
endline : end && end.line,
|
||||||
endcol : end && end.column,
|
endcol : end && end.column,
|
||||||
endpos : range ? range[1] : moznode.end,
|
endpos : range ? range[1] : moznode.end
|
||||||
raw : raw_token(moznode),
|
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
function map(moztype, mytype, propmap) {
|
function map(moztype, mytype, propmap) {
|
||||||
var moz_to_me = "function From_Moz_" + moztype + "(M){\n";
|
var moz_to_me = "function From_Moz_" + moztype + "(M){\n";
|
||||||
moz_to_me += "return new U2." + mytype.name + "({\n" +
|
moz_to_me += "return new " + mytype.name + "({\n" +
|
||||||
"start: my_start_token(M),\n" +
|
"start: my_start_token(M),\n" +
|
||||||
"end: my_end_token(M)";
|
"end: my_end_token(M)";
|
||||||
|
|
||||||
@@ -549,15 +442,15 @@
|
|||||||
//me_to_moz = parse(me_to_moz).print_to_string({ beautify: true });
|
//me_to_moz = parse(me_to_moz).print_to_string({ beautify: true });
|
||||||
//console.log(moz_to_me);
|
//console.log(moz_to_me);
|
||||||
|
|
||||||
moz_to_me = new Function("U2", "my_start_token", "my_end_token", "from_moz", "return(" + moz_to_me + ")")(
|
moz_to_me = new Function("my_start_token", "my_end_token", "from_moz", "return(" + moz_to_me + ")")(
|
||||||
exports, my_start_token, my_end_token, from_moz
|
my_start_token, my_end_token, from_moz
|
||||||
);
|
);
|
||||||
me_to_moz = new Function("to_moz", "to_moz_block", "to_moz_scope", "return(" + me_to_moz + ")")(
|
me_to_moz = new Function("to_moz", "to_moz_block", "return(" + me_to_moz + ")")(
|
||||||
to_moz, to_moz_block, to_moz_scope
|
to_moz, to_moz_block
|
||||||
);
|
);
|
||||||
MOZ_TO_ME[moztype] = moz_to_me;
|
MOZ_TO_ME[moztype] = moz_to_me;
|
||||||
def_to_moz(mytype, me_to_moz);
|
def_to_moz(mytype, me_to_moz);
|
||||||
}
|
};
|
||||||
|
|
||||||
var FROM_MOZ_STACK = null;
|
var FROM_MOZ_STACK = null;
|
||||||
|
|
||||||
@@ -566,28 +459,13 @@
|
|||||||
var ret = node != null ? MOZ_TO_ME[node.type](node) : null;
|
var ret = node != null ? MOZ_TO_ME[node.type](node) : null;
|
||||||
FROM_MOZ_STACK.pop();
|
FROM_MOZ_STACK.pop();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
};
|
||||||
|
|
||||||
AST_Node.from_mozilla_ast = function(node){
|
AST_Node.from_mozilla_ast = function(node){
|
||||||
var save_stack = FROM_MOZ_STACK;
|
var save_stack = FROM_MOZ_STACK;
|
||||||
FROM_MOZ_STACK = [];
|
FROM_MOZ_STACK = [];
|
||||||
var ast = from_moz(node);
|
var ast = from_moz(node);
|
||||||
FROM_MOZ_STACK = save_stack;
|
FROM_MOZ_STACK = save_stack;
|
||||||
ast.walk(new TreeWalker(function(node) {
|
|
||||||
if (node instanceof AST_LabelRef) {
|
|
||||||
for (var level = 0, parent; parent = this.parent(level); level++) {
|
|
||||||
if (parent instanceof AST_Scope) break;
|
|
||||||
if (parent instanceof AST_LabeledStatement && parent.label.name == node.name) {
|
|
||||||
node.thedef = parent.label;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!node.thedef) {
|
|
||||||
var s = node.start;
|
|
||||||
js_error("Undefined label " + node.name, s.file, s.line, s.col, s.pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
return ast;
|
return ast;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -607,33 +485,23 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return moznode;
|
return moznode;
|
||||||
}
|
};
|
||||||
|
|
||||||
function def_to_moz(mytype, handler) {
|
function def_to_moz(mytype, handler) {
|
||||||
mytype.DEFMETHOD("to_mozilla_ast", function() {
|
mytype.DEFMETHOD("to_mozilla_ast", function() {
|
||||||
return set_moz_loc(this, handler(this));
|
return set_moz_loc(this, handler(this));
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
function to_moz(node) {
|
function to_moz(node) {
|
||||||
return node != null ? node.to_mozilla_ast() : null;
|
return node != null ? node.to_mozilla_ast() : null;
|
||||||
}
|
};
|
||||||
|
|
||||||
function to_moz_block(node) {
|
function to_moz_block(node) {
|
||||||
return {
|
return {
|
||||||
type: "BlockStatement",
|
type: "BlockStatement",
|
||||||
body: node.body.map(to_moz)
|
body: node.body.map(to_moz)
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
function to_moz_scope(type, node) {
|
|
||||||
var body = node.body.map(to_moz);
|
|
||||||
if (node.body[0] instanceof AST_SimpleStatement && node.body[0].body instanceof AST_String) {
|
|
||||||
body.unshift(to_moz(new AST_EmptyStatement(node.body[0])));
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
type: type,
|
|
||||||
body: body
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
1405
lib/output.js
1405
lib/output.js
File diff suppressed because it is too large
Load Diff
853
lib/parse.js
853
lib/parse.js
File diff suppressed because it is too large
Load Diff
@@ -1,260 +0,0 @@
|
|||||||
/***********************************************************************
|
|
||||||
|
|
||||||
A JavaScript tokenizer / parser / beautifier / compressor.
|
|
||||||
https://github.com/mishoo/UglifyJS
|
|
||||||
|
|
||||||
-------------------------------- (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";
|
|
||||||
|
|
||||||
var builtins = function() {
|
|
||||||
var names = [];
|
|
||||||
// NaN will be included due to Number.NaN
|
|
||||||
[
|
|
||||||
"null",
|
|
||||||
"true",
|
|
||||||
"false",
|
|
||||||
"Infinity",
|
|
||||||
"-Infinity",
|
|
||||||
"undefined",
|
|
||||||
].forEach(add);
|
|
||||||
[
|
|
||||||
Array,
|
|
||||||
Boolean,
|
|
||||||
Date,
|
|
||||||
Error,
|
|
||||||
Function,
|
|
||||||
Math,
|
|
||||||
Number,
|
|
||||||
Object,
|
|
||||||
RegExp,
|
|
||||||
String,
|
|
||||||
].forEach(function(ctor) {
|
|
||||||
Object.getOwnPropertyNames(ctor).map(add);
|
|
||||||
if (ctor.prototype) {
|
|
||||||
Object.getOwnPropertyNames(new ctor()).map(add);
|
|
||||||
Object.getOwnPropertyNames(ctor.prototype).map(add);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return makePredicate(names);
|
|
||||||
|
|
||||||
function add(name) {
|
|
||||||
names.push(name);
|
|
||||||
}
|
|
||||||
}();
|
|
||||||
|
|
||||||
function reserve_quoted_keys(ast, reserved) {
|
|
||||||
ast.walk(new TreeWalker(function(node) {
|
|
||||||
if (node instanceof AST_ObjectKeyVal) {
|
|
||||||
if (node.quote) add(node.key);
|
|
||||||
} else if (node instanceof AST_Sub) {
|
|
||||||
addStrings(node.property, add);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
function add(name) {
|
|
||||||
push_uniq(reserved, name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function addStrings(node, add) {
|
|
||||||
if (node instanceof AST_Conditional) {
|
|
||||||
addStrings(node.consequent, add);
|
|
||||||
addStrings(node.alternative, add);
|
|
||||||
} else if (node instanceof AST_Sequence) {
|
|
||||||
addStrings(node.tail_node(), add);
|
|
||||||
} else if (node instanceof AST_String) {
|
|
||||||
add(node.value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function mangle_properties(ast, options) {
|
|
||||||
options = defaults(options, {
|
|
||||||
builtins: false,
|
|
||||||
cache: null,
|
|
||||||
debug: false,
|
|
||||||
keep_quoted: false,
|
|
||||||
regex: null,
|
|
||||||
reserved: null,
|
|
||||||
}, true);
|
|
||||||
|
|
||||||
var reserved = Object.create(options.builtins ? null : builtins);
|
|
||||||
if (Array.isArray(options.reserved)) options.reserved.forEach(function(name) {
|
|
||||||
reserved[name] = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
var cname = -1;
|
|
||||||
var cache;
|
|
||||||
if (options.cache) {
|
|
||||||
cache = options.cache.props;
|
|
||||||
cache.each(function(name) {
|
|
||||||
reserved[name] = true;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
cache = new Dictionary();
|
|
||||||
}
|
|
||||||
|
|
||||||
var regex = 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_suffix;
|
|
||||||
if (debug) debug_suffix = options.debug === true ? "" : options.debug;
|
|
||||||
|
|
||||||
var names_to_mangle = Object.create(null);
|
|
||||||
var unmangleable = Object.create(reserved);
|
|
||||||
|
|
||||||
// step 1: find candidates to mangle
|
|
||||||
ast.walk(new TreeWalker(function(node) {
|
|
||||||
if (node instanceof AST_Binary) {
|
|
||||||
if (node.operator == "in") addStrings(node.left, add);
|
|
||||||
} else if (node.TYPE == "Call") {
|
|
||||||
var exp = node.expression;
|
|
||||||
if (exp instanceof AST_Dot) switch (exp.property) {
|
|
||||||
case "defineProperty":
|
|
||||||
case "getOwnPropertyDescriptor":
|
|
||||||
if (node.args.length < 2) break;
|
|
||||||
exp = exp.expression;
|
|
||||||
if (!(exp instanceof AST_SymbolRef)) break;
|
|
||||||
if (exp.name != "Object") break;
|
|
||||||
if (!exp.definition().undeclared) break;
|
|
||||||
addStrings(node.args[1], add);
|
|
||||||
break;
|
|
||||||
case "hasOwnProperty":
|
|
||||||
if (node.args.length < 1) break;
|
|
||||||
addStrings(node.args[0], add);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if (node instanceof AST_Dot) {
|
|
||||||
add(node.property);
|
|
||||||
} else if (node instanceof AST_ObjectKeyVal) {
|
|
||||||
add(node.key);
|
|
||||||
} else if (node instanceof AST_ObjectProperty) {
|
|
||||||
// setter or getter, since KeyVal is handled above
|
|
||||||
add(node.key.name);
|
|
||||||
} else if (node instanceof AST_Sub) {
|
|
||||||
addStrings(node.property, add);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
// step 2: renaming properties
|
|
||||||
ast.walk(new TreeWalker(function(node) {
|
|
||||||
if (node instanceof AST_Binary) {
|
|
||||||
if (node.operator == "in") mangleStrings(node.left);
|
|
||||||
} else if (node.TYPE == "Call") {
|
|
||||||
var exp = node.expression;
|
|
||||||
if (exp instanceof AST_Dot) switch (exp.property) {
|
|
||||||
case "defineProperty":
|
|
||||||
case "getOwnPropertyDescriptor":
|
|
||||||
if (node.args.length < 2) break;
|
|
||||||
exp = exp.expression;
|
|
||||||
if (!(exp instanceof AST_SymbolRef)) break;
|
|
||||||
if (exp.name != "Object") break;
|
|
||||||
if (!exp.definition().undeclared) break;
|
|
||||||
mangleStrings(node.args[1]);
|
|
||||||
break;
|
|
||||||
case "hasOwnProperty":
|
|
||||||
if (node.args.length < 1) break;
|
|
||||||
mangleStrings(node.args[0]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if (node instanceof AST_Dot) {
|
|
||||||
node.property = mangle(node.property);
|
|
||||||
} else if (node instanceof AST_ObjectKeyVal) {
|
|
||||||
node.key = mangle(node.key);
|
|
||||||
} else if (node instanceof AST_ObjectProperty) {
|
|
||||||
// setter or getter
|
|
||||||
node.key.name = mangle(node.key.name);
|
|
||||||
} else if (node instanceof AST_Sub) {
|
|
||||||
if (!options.keep_quoted) mangleStrings(node.property);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
// only function declarations after this line
|
|
||||||
|
|
||||||
function can_mangle(name) {
|
|
||||||
if (unmangleable[name]) return false;
|
|
||||||
if (/^-?[0-9]+(\.[0-9]+)?(e[+-][0-9]+)?$/.test(name)) return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function should_mangle(name) {
|
|
||||||
if (reserved[name]) return false;
|
|
||||||
if (regex && !regex.test(name)) return false;
|
|
||||||
return cache.has(name) || names_to_mangle[name];
|
|
||||||
}
|
|
||||||
|
|
||||||
function add(name) {
|
|
||||||
if (can_mangle(name)) names_to_mangle[name] = true;
|
|
||||||
if (!should_mangle(name)) unmangleable[name] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
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_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 mangleStrings(node) {
|
|
||||||
if (node instanceof AST_Sequence) {
|
|
||||||
mangleStrings(node.expressions.tail_node());
|
|
||||||
} else if (node instanceof AST_String) {
|
|
||||||
node.value = mangle(node.value);
|
|
||||||
} else if (node instanceof AST_Conditional) {
|
|
||||||
mangleStrings(node.consequent);
|
|
||||||
mangleStrings(node.alternative);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
840
lib/scope.js
840
lib/scope.js
File diff suppressed because it is too large
Load Diff
183
lib/sourcemap.js
183
lib/sourcemap.js
@@ -1,7 +1,7 @@
|
|||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
|
||||||
A JavaScript tokenizer / parser / beautifier / compressor.
|
A JavaScript tokenizer / parser / beautifier / compressor.
|
||||||
https://github.com/mishoo/UglifyJS
|
https://github.com/mishoo/UglifyJS2
|
||||||
|
|
||||||
-------------------------------- (C) ---------------------------------
|
-------------------------------- (C) ---------------------------------
|
||||||
|
|
||||||
@@ -43,149 +43,50 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var vlq_char = characters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
|
// a small wrapper around fitzgen's source-map library
|
||||||
var vlq_bits = vlq_char.reduce(function(map, ch, bits) {
|
|
||||||
map[ch] = bits;
|
|
||||||
return map;
|
|
||||||
}, Object.create(null));
|
|
||||||
|
|
||||||
function vlq_decode(indices, str) {
|
|
||||||
var value = 0;
|
|
||||||
var shift = 0;
|
|
||||||
for (var i = 0, j = 0; i < str.length; i++) {
|
|
||||||
var bits = vlq_bits[str[i]];
|
|
||||||
value += (bits & 31) << shift;
|
|
||||||
if (bits & 32) {
|
|
||||||
shift += 5;
|
|
||||||
} else {
|
|
||||||
indices[j++] += value & 1 ? 0x80000000 | -(value >> 1) : value >> 1;
|
|
||||||
value = shift = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return j;
|
|
||||||
}
|
|
||||||
|
|
||||||
function vlq_encode(num) {
|
|
||||||
var result = "";
|
|
||||||
num = Math.abs(num) << 1 | num >>> 31;
|
|
||||||
do {
|
|
||||||
var bits = num & 31;
|
|
||||||
if (num >>>= 5) bits |= 32;
|
|
||||||
result += vlq_char[bits];
|
|
||||||
} while (num);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
function create_array_map() {
|
|
||||||
var map = Object.create(null);
|
|
||||||
var array = [];
|
|
||||||
array.index = function(name) {
|
|
||||||
if (!HOP(map, name)) {
|
|
||||||
map[name] = array.length;
|
|
||||||
array.push(name);
|
|
||||||
}
|
|
||||||
return map[name];
|
|
||||||
};
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
|
|
||||||
function SourceMap(options) {
|
function SourceMap(options) {
|
||||||
var sources = create_array_map();
|
options = defaults(options, {
|
||||||
var sources_content = options.includeSources && Object.create(null);
|
file : null,
|
||||||
var names = create_array_map();
|
root : null,
|
||||||
var mappings = "";
|
orig : null,
|
||||||
if (options.orig) Object.keys(options.orig).forEach(function(name) {
|
|
||||||
var map = options.orig[name];
|
|
||||||
var indices = [ 0, 0, 1, 0, 0 ];
|
|
||||||
options.orig[name] = {
|
|
||||||
names: map.names,
|
|
||||||
mappings: map.mappings.split(/;/).map(function(line) {
|
|
||||||
indices[0] = 0;
|
|
||||||
return line.split(/,/).map(function(segment) {
|
|
||||||
return indices.slice(0, vlq_decode(indices, segment));
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
sources: map.sources,
|
|
||||||
};
|
|
||||||
if (!sources_content || !map.sourcesContent) return;
|
|
||||||
for (var i = 0; i < map.sources.length; i++) {
|
|
||||||
var content = map.sourcesContent[i];
|
|
||||||
if (content) sources_content[map.sources[i]] = content;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
var prev_source;
|
|
||||||
var generated_line = 1;
|
|
||||||
var generated_column = 0;
|
|
||||||
var source_index = 0;
|
|
||||||
var original_line = 1;
|
|
||||||
var original_column = 0;
|
|
||||||
var name_index = 0;
|
|
||||||
return {
|
|
||||||
add: options.orig ? function(source, gen_line, gen_col, orig_line, orig_col, name) {
|
|
||||||
var map = options.orig[source];
|
|
||||||
if (map) {
|
|
||||||
var segments = map.mappings[orig_line - 1];
|
|
||||||
if (!segments) return;
|
|
||||||
var indices;
|
|
||||||
for (var i = 0; i < segments.length; i++) {
|
|
||||||
var col = segments[i][0];
|
|
||||||
if (orig_col >= col) indices = segments[i];
|
|
||||||
if (orig_col <= col) break;
|
|
||||||
}
|
|
||||||
if (!indices || indices.length < 4) {
|
|
||||||
source = null;
|
|
||||||
} else {
|
|
||||||
source = map.sources[indices[1]];
|
|
||||||
orig_line = indices[2];
|
|
||||||
orig_col = indices[3];
|
|
||||||
if (indices.length > 4) name = map.names[indices[4]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
add(source, gen_line, gen_col, orig_line, orig_col, name);
|
|
||||||
} : add,
|
|
||||||
setSourceContent: sources_content ? function(source, content) {
|
|
||||||
sources_content[source] = content;
|
|
||||||
} : noop,
|
|
||||||
toString: function() {
|
|
||||||
return JSON.stringify({
|
|
||||||
version: 3,
|
|
||||||
file: options.filename || undefined,
|
|
||||||
sourceRoot: options.root || undefined,
|
|
||||||
sources: sources,
|
|
||||||
sourcesContent: sources_content ? sources.map(function(source) {
|
|
||||||
return sources_content[source] || null;
|
|
||||||
}) : undefined,
|
|
||||||
names: names,
|
|
||||||
mappings: mappings,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
orig_line_diff : 0,
|
||||||
|
dest_line_diff : 0,
|
||||||
|
});
|
||||||
|
var orig_map = options.orig && new MOZ_SourceMap.SourceMapConsumer(options.orig);
|
||||||
|
var generator;
|
||||||
|
if (orig_map) {
|
||||||
|
generator = MOZ_SourceMap.SourceMapGenerator.fromSourceMap(orig_map);
|
||||||
|
} else {
|
||||||
|
generator = new MOZ_SourceMap.SourceMapGenerator({
|
||||||
|
file : options.file,
|
||||||
|
sourceRoot : options.root
|
||||||
|
});
|
||||||
|
}
|
||||||
function add(source, gen_line, gen_col, orig_line, orig_col, name) {
|
function add(source, gen_line, gen_col, orig_line, orig_col, name) {
|
||||||
if (prev_source == null && source == null) return;
|
if (orig_map) {
|
||||||
prev_source = source;
|
var info = orig_map.originalPositionFor({
|
||||||
if (generated_line < gen_line) {
|
line: orig_line,
|
||||||
generated_column = 0;
|
column: orig_col
|
||||||
do {
|
});
|
||||||
mappings += ";";
|
if (info.source === null) {
|
||||||
} while (++generated_line < gen_line);
|
return;
|
||||||
} else if (mappings) {
|
|
||||||
mappings += ",";
|
|
||||||
}
|
|
||||||
mappings += vlq_encode(gen_col - generated_column);
|
|
||||||
generated_column = gen_col;
|
|
||||||
if (source == null) return;
|
|
||||||
var src_idx = sources.index(source);
|
|
||||||
mappings += vlq_encode(src_idx - source_index);
|
|
||||||
source_index = src_idx;
|
|
||||||
mappings += vlq_encode(orig_line - original_line);
|
|
||||||
original_line = orig_line;
|
|
||||||
mappings += vlq_encode(orig_col - original_column);
|
|
||||||
original_column = orig_col;
|
|
||||||
if (options.names && name != null) {
|
|
||||||
var name_idx = names.index(name);
|
|
||||||
mappings += vlq_encode(name_idx - name_index);
|
|
||||||
name_index = name_idx;
|
|
||||||
}
|
}
|
||||||
|
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 JSON.stringify(generator.toJSON()); }
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|||||||
273
lib/transform.js
273
lib/transform.js
@@ -1,7 +1,7 @@
|
|||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
|
||||||
A JavaScript tokenizer / parser / beautifier / compressor.
|
A JavaScript tokenizer / parser / beautifier / compressor.
|
||||||
https://github.com/mishoo/UglifyJS
|
https://github.com/mishoo/UglifyJS2
|
||||||
|
|
||||||
-------------------------------- (C) ---------------------------------
|
-------------------------------- (C) ---------------------------------
|
||||||
|
|
||||||
@@ -43,6 +43,8 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
// Tree transformer helpers.
|
||||||
|
|
||||||
function TreeTransformer(before, after) {
|
function TreeTransformer(before, after) {
|
||||||
TreeWalker.call(this);
|
TreeWalker.call(this);
|
||||||
this.before = before;
|
this.before = before;
|
||||||
@@ -50,136 +52,167 @@ function TreeTransformer(before, after) {
|
|||||||
}
|
}
|
||||||
TreeTransformer.prototype = new TreeWalker;
|
TreeTransformer.prototype = new TreeWalker;
|
||||||
|
|
||||||
(function(DEF) {
|
(function(undefined){
|
||||||
function do_list(list, tw) {
|
|
||||||
return List(list, function(node) {
|
|
||||||
return node.transform(tw, true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
DEF(AST_Node, noop);
|
function _(node, descend) {
|
||||||
DEF(AST_LabeledStatement, function(self, tw) {
|
|
||||||
self.label = self.label.transform(tw);
|
|
||||||
self.body = self.body.transform(tw);
|
|
||||||
});
|
|
||||||
DEF(AST_SimpleStatement, function(self, tw) {
|
|
||||||
self.body = self.body.transform(tw);
|
|
||||||
});
|
|
||||||
DEF(AST_Block, function(self, tw) {
|
|
||||||
self.body = do_list(self.body, tw);
|
|
||||||
});
|
|
||||||
DEF(AST_Do, function(self, tw) {
|
|
||||||
self.body = self.body.transform(tw);
|
|
||||||
self.condition = self.condition.transform(tw);
|
|
||||||
});
|
|
||||||
DEF(AST_While, function(self, tw) {
|
|
||||||
self.condition = self.condition.transform(tw);
|
|
||||||
self.body = self.body.transform(tw);
|
|
||||||
});
|
|
||||||
DEF(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(AST_ForIn, function(self, tw) {
|
|
||||||
self.init = self.init.transform(tw);
|
|
||||||
self.object = self.object.transform(tw);
|
|
||||||
self.body = self.body.transform(tw);
|
|
||||||
});
|
|
||||||
DEF(AST_With, function(self, tw) {
|
|
||||||
self.expression = self.expression.transform(tw);
|
|
||||||
self.body = self.body.transform(tw);
|
|
||||||
});
|
|
||||||
DEF(AST_Exit, function(self, tw) {
|
|
||||||
if (self.value) self.value = self.value.transform(tw);
|
|
||||||
});
|
|
||||||
DEF(AST_LoopControl, function(self, tw) {
|
|
||||||
if (self.label) self.label = self.label.transform(tw);
|
|
||||||
});
|
|
||||||
DEF(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(AST_Switch, function(self, tw) {
|
|
||||||
self.expression = self.expression.transform(tw);
|
|
||||||
self.body = do_list(self.body, tw);
|
|
||||||
});
|
|
||||||
DEF(AST_Case, function(self, tw) {
|
|
||||||
self.expression = self.expression.transform(tw);
|
|
||||||
self.body = do_list(self.body, tw);
|
|
||||||
});
|
|
||||||
DEF(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(AST_Catch, function(self, tw) {
|
|
||||||
if (self.argname) self.argname = self.argname.transform(tw);
|
|
||||||
self.body = do_list(self.body, tw);
|
|
||||||
});
|
|
||||||
DEF(AST_Definitions, function(self, tw) {
|
|
||||||
self.definitions = do_list(self.definitions, tw);
|
|
||||||
});
|
|
||||||
DEF(AST_VarDef, function(self, tw) {
|
|
||||||
self.name = self.name.transform(tw);
|
|
||||||
if (self.value) self.value = self.value.transform(tw);
|
|
||||||
});
|
|
||||||
DEF(AST_Lambda, function(self, tw) {
|
|
||||||
if (self.name) self.name = self.name.transform(tw);
|
|
||||||
self.argnames = do_list(self.argnames, tw);
|
|
||||||
self.body = do_list(self.body, tw);
|
|
||||||
});
|
|
||||||
DEF(AST_Call, function(self, tw) {
|
|
||||||
self.expression = self.expression.transform(tw);
|
|
||||||
self.args = do_list(self.args, tw);
|
|
||||||
});
|
|
||||||
DEF(AST_Sequence, function(self, tw) {
|
|
||||||
self.expressions = do_list(self.expressions, tw);
|
|
||||||
});
|
|
||||||
DEF(AST_Dot, function(self, tw) {
|
|
||||||
self.expression = self.expression.transform(tw);
|
|
||||||
});
|
|
||||||
DEF(AST_Sub, function(self, tw) {
|
|
||||||
self.expression = self.expression.transform(tw);
|
|
||||||
self.property = self.property.transform(tw);
|
|
||||||
});
|
|
||||||
DEF(AST_Unary, function(self, tw) {
|
|
||||||
self.expression = self.expression.transform(tw);
|
|
||||||
});
|
|
||||||
DEF(AST_Binary, function(self, tw) {
|
|
||||||
self.left = self.left.transform(tw);
|
|
||||||
self.right = self.right.transform(tw);
|
|
||||||
});
|
|
||||||
DEF(AST_Conditional, function(self, tw) {
|
|
||||||
self.condition = self.condition.transform(tw);
|
|
||||||
self.consequent = self.consequent.transform(tw);
|
|
||||||
self.alternative = self.alternative.transform(tw);
|
|
||||||
});
|
|
||||||
DEF(AST_Array, function(self, tw) {
|
|
||||||
self.elements = do_list(self.elements, tw);
|
|
||||||
});
|
|
||||||
DEF(AST_Object, function(self, tw) {
|
|
||||||
self.properties = do_list(self.properties, tw);
|
|
||||||
});
|
|
||||||
DEF(AST_ObjectProperty, function(self, tw) {
|
|
||||||
self.value = self.value.transform(tw);
|
|
||||||
});
|
|
||||||
})(function(node, descend) {
|
|
||||||
node.DEFMETHOD("transform", function(tw, in_list){
|
node.DEFMETHOD("transform", function(tw, in_list){
|
||||||
var x, y;
|
var x, y;
|
||||||
tw.push(this);
|
tw.push(this);
|
||||||
if (tw.before) x = tw.before(this, descend, in_list);
|
if (tw.before) x = tw.before(this, descend, in_list);
|
||||||
if (typeof x === "undefined") {
|
if (x === undefined) {
|
||||||
|
if (!tw.after) {
|
||||||
x = this;
|
x = this;
|
||||||
descend(x, tw);
|
descend(x, tw);
|
||||||
if (tw.after) {
|
} else {
|
||||||
|
tw.stack[tw.stack.length - 1] = x = this.clone();
|
||||||
|
descend(x, tw);
|
||||||
y = tw.after(x, in_list);
|
y = tw.after(x, in_list);
|
||||||
if (typeof y !== "undefined") x = y;
|
if (y !== undefined) x = y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tw.pop();
|
tw.pop();
|
||||||
return x;
|
return x;
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
function do_list(list, tw) {
|
||||||
|
return MAP(list, function(node){
|
||||||
|
return node.transform(tw, true);
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
_(AST_Node, noop);
|
||||||
|
|
||||||
|
_(AST_LabeledStatement, function(self, tw){
|
||||||
|
self.label = self.label.transform(tw);
|
||||||
|
self.body = self.body.transform(tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_SimpleStatement, function(self, tw){
|
||||||
|
self.body = self.body.transform(tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_Block, function(self, tw){
|
||||||
|
self.body = do_list(self.body, tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_DWLoop, function(self, tw){
|
||||||
|
self.condition = self.condition.transform(tw);
|
||||||
|
self.body = self.body.transform(tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(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);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_ForIn, function(self, tw){
|
||||||
|
self.init = self.init.transform(tw);
|
||||||
|
self.object = self.object.transform(tw);
|
||||||
|
self.body = self.body.transform(tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_With, function(self, tw){
|
||||||
|
self.expression = self.expression.transform(tw);
|
||||||
|
self.body = self.body.transform(tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_Exit, function(self, tw){
|
||||||
|
if (self.value) self.value = self.value.transform(tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_LoopControl, function(self, tw){
|
||||||
|
if (self.label) self.label = self.label.transform(tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(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);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_Switch, function(self, tw){
|
||||||
|
self.expression = self.expression.transform(tw);
|
||||||
|
self.body = do_list(self.body, tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_Case, function(self, tw){
|
||||||
|
self.expression = self.expression.transform(tw);
|
||||||
|
self.body = do_list(self.body, tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(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);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_Catch, function(self, tw){
|
||||||
|
self.argname = self.argname.transform(tw);
|
||||||
|
self.body = do_list(self.body, tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_Definitions, function(self, tw){
|
||||||
|
self.definitions = do_list(self.definitions, tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_VarDef, function(self, tw){
|
||||||
|
self.name = self.name.transform(tw);
|
||||||
|
if (self.value) self.value = self.value.transform(tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_Lambda, function(self, tw){
|
||||||
|
if (self.name) self.name = self.name.transform(tw);
|
||||||
|
self.argnames = do_list(self.argnames, tw);
|
||||||
|
self.body = do_list(self.body, tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_Call, function(self, tw){
|
||||||
|
self.expression = self.expression.transform(tw);
|
||||||
|
self.args = do_list(self.args, tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_Seq, function(self, tw){
|
||||||
|
self.car = self.car.transform(tw);
|
||||||
|
self.cdr = self.cdr.transform(tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_Dot, function(self, tw){
|
||||||
|
self.expression = self.expression.transform(tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_Sub, function(self, tw){
|
||||||
|
self.expression = self.expression.transform(tw);
|
||||||
|
self.property = self.property.transform(tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_Unary, function(self, tw){
|
||||||
|
self.expression = self.expression.transform(tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_Binary, function(self, tw){
|
||||||
|
self.left = self.left.transform(tw);
|
||||||
|
self.right = self.right.transform(tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_Conditional, function(self, tw){
|
||||||
|
self.condition = self.condition.transform(tw);
|
||||||
|
self.consequent = self.consequent.transform(tw);
|
||||||
|
self.alternative = self.alternative.transform(tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_Array, function(self, tw){
|
||||||
|
self.elements = do_list(self.elements, tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_Object, function(self, tw){
|
||||||
|
self.properties = do_list(self.properties, tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
_(AST_ObjectProperty, function(self, tw){
|
||||||
|
self.value = self.value.transform(tw);
|
||||||
|
});
|
||||||
|
|
||||||
|
})();
|
||||||
|
|||||||
290
lib/utils.js
290
lib/utils.js
@@ -1,7 +1,7 @@
|
|||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
|
||||||
A JavaScript tokenizer / parser / beautifier / compressor.
|
A JavaScript tokenizer / parser / beautifier / compressor.
|
||||||
https://github.com/mishoo/UglifyJS
|
https://github.com/mishoo/UglifyJS2
|
||||||
|
|
||||||
-------------------------------- (C) ---------------------------------
|
-------------------------------- (C) ---------------------------------
|
||||||
|
|
||||||
@@ -43,136 +43,226 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
function array_to_hash(a) {
|
||||||
|
var ret = Object.create(null);
|
||||||
|
for (var i = 0; i < a.length; ++i)
|
||||||
|
ret[a[i]] = true;
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
|
||||||
|
function slice(a, start) {
|
||||||
|
return Array.prototype.slice.call(a, start || 0);
|
||||||
|
};
|
||||||
|
|
||||||
function characters(str) {
|
function characters(str) {
|
||||||
return str.split("");
|
return str.split("");
|
||||||
}
|
};
|
||||||
|
|
||||||
function member(name, array) {
|
function member(name, array) {
|
||||||
return array.indexOf(name) >= 0;
|
for (var i = array.length; --i >= 0;)
|
||||||
}
|
if (array[i] == name)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
function find_if(func, array) {
|
function find_if(func, array) {
|
||||||
for (var i = array.length; --i >= 0;) if (func(array[i])) return array[i];
|
for (var i = 0, n = array.length; i < n; ++i) {
|
||||||
|
if (func(array[i]))
|
||||||
|
return array[i];
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function repeat_string(str, i) {
|
function repeat_string(str, i) {
|
||||||
if (i <= 0) return "";
|
if (i <= 0) return "";
|
||||||
if (i == 1) return str;
|
if (i == 1) return str;
|
||||||
var d = repeat_string(str, i >> 1);
|
var d = repeat_string(str, i >> 1);
|
||||||
d += d;
|
d += d;
|
||||||
return i & 1 ? d + str : d;
|
if (i & 1) d += str;
|
||||||
}
|
return d;
|
||||||
|
};
|
||||||
function configure_error_stack(fn) {
|
|
||||||
Object.defineProperty(fn.prototype, "stack", {
|
|
||||||
get: function() {
|
|
||||||
var err = new Error(this.message);
|
|
||||||
err.name = this.name;
|
|
||||||
try {
|
|
||||||
throw err;
|
|
||||||
} catch (e) {
|
|
||||||
return e.stack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function DefaultsError(msg, defs) {
|
function DefaultsError(msg, defs) {
|
||||||
this.message = msg;
|
Error.call(this, msg);
|
||||||
|
this.msg = msg;
|
||||||
this.defs = defs;
|
this.defs = defs;
|
||||||
}
|
};
|
||||||
DefaultsError.prototype = Object.create(Error.prototype);
|
DefaultsError.prototype = Object.create(Error.prototype);
|
||||||
DefaultsError.prototype.constructor = DefaultsError;
|
DefaultsError.prototype.constructor = DefaultsError;
|
||||||
DefaultsError.prototype.name = "DefaultsError";
|
|
||||||
configure_error_stack(DefaultsError);
|
DefaultsError.croak = function(msg, defs) {
|
||||||
|
throw new DefaultsError(msg, defs);
|
||||||
|
};
|
||||||
|
|
||||||
function defaults(args, defs, croak) {
|
function defaults(args, defs, croak) {
|
||||||
if (croak) for (var i in args) {
|
if (args === true)
|
||||||
if (HOP(args, i) && !HOP(defs, i)) throw new DefaultsError("`" + i + "` is not a supported option", defs);
|
args = {};
|
||||||
}
|
var ret = args || {};
|
||||||
for (var i in args) {
|
if (croak) for (var i in ret) if (ret.hasOwnProperty(i) && !defs.hasOwnProperty(i))
|
||||||
if (HOP(args, i)) defs[i] = args[i];
|
DefaultsError.croak("`" + i + "` is not a supported option", defs);
|
||||||
}
|
for (var i in defs) if (defs.hasOwnProperty(i)) {
|
||||||
return defs;
|
ret[i] = (args && args.hasOwnProperty(i)) ? args[i] : defs[i];
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
|
||||||
function merge(obj, ext) {
|
function merge(obj, ext) {
|
||||||
var count = 0;
|
for (var i in ext) if (ext.hasOwnProperty(i)) {
|
||||||
for (var i in ext) if (HOP(ext, i)) {
|
|
||||||
obj[i] = ext[i];
|
obj[i] = ext[i];
|
||||||
count++;
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
return obj;
|
||||||
|
};
|
||||||
|
|
||||||
function noop() {}
|
function noop() {};
|
||||||
function return_false() { return false; }
|
|
||||||
function return_true() { return true; }
|
|
||||||
function return_this() { return this; }
|
|
||||||
function return_null() { return null; }
|
|
||||||
|
|
||||||
var List = (function() {
|
var MAP = (function(){
|
||||||
function List(a, f) {
|
function MAP(a, f, backwards) {
|
||||||
var ret = [];
|
var ret = [], top = [], i;
|
||||||
for (var i = 0; i < a.length; i++) {
|
function doit() {
|
||||||
var val = f(a[i], i);
|
var val = f(a[i], i);
|
||||||
if (val === skip) continue;
|
var is_last = val instanceof Last;
|
||||||
|
if (is_last) val = val.v;
|
||||||
|
if (val instanceof AtTop) {
|
||||||
|
val = val.v;
|
||||||
if (val instanceof Splice) {
|
if (val instanceof Splice) {
|
||||||
ret.push.apply(ret, val.v);
|
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 {
|
} else {
|
||||||
ret.push(val);
|
ret.push(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return is_last;
|
||||||
}
|
|
||||||
List.is_op = function(val) {
|
|
||||||
return val === skip || val instanceof Splice;
|
|
||||||
};
|
};
|
||||||
List.splice = function(val) {
|
if (a instanceof Array) {
|
||||||
return new Splice(val);
|
if (backwards) {
|
||||||
};
|
for (i = a.length; --i >= 0;) if (doit()) break;
|
||||||
var skip = List.skip = {};
|
ret.reverse();
|
||||||
function Splice(val) {
|
top.reverse();
|
||||||
this.v = val;
|
} else {
|
||||||
|
for (i = 0; i < a.length; ++i) if (doit()) break;
|
||||||
}
|
}
|
||||||
return List;
|
}
|
||||||
|
else {
|
||||||
|
for (i in a) if (a.hasOwnProperty(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 push_uniq(array, el) {
|
function push_uniq(array, el) {
|
||||||
if (array.indexOf(el) < 0) return array.push(el);
|
if (array.indexOf(el) < 0)
|
||||||
}
|
array.push(el);
|
||||||
|
};
|
||||||
|
|
||||||
function string_template(text, props) {
|
function string_template(text, props) {
|
||||||
return text.replace(/\{(.+?)\}/g, function(str, p){
|
return text.replace(/\{(.+?)\}/g, function(str, p){
|
||||||
return props && props[p];
|
return props[p];
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
function remove(array, el) {
|
function remove(array, el) {
|
||||||
var index = array.indexOf(el);
|
for (var i = array.length; --i >= 0;) {
|
||||||
if (index >= 0) array.splice(index, 1);
|
if (array[i] === el) array.splice(i, 1);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function makePredicate(words) {
|
function mergeSort(array, cmp) {
|
||||||
if (!Array.isArray(words)) words = words.split(" ");
|
if (array.length < 2) return array.slice();
|
||||||
var map = Object.create(null);
|
function merge(a, b) {
|
||||||
words.forEach(function(word) {
|
var r = [], ai = 0, bi = 0, i = 0;
|
||||||
map[word] = true;
|
while (ai < a.length && bi < b.length) {
|
||||||
});
|
cmp(a[ai], b[bi]) <= 0
|
||||||
return map;
|
? 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 set_difference(a, b) {
|
||||||
|
return a.filter(function(el){
|
||||||
|
return b.indexOf(el) < 0;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
function set_intersection(a, b) {
|
||||||
|
return a.filter(function(el){
|
||||||
|
return b.indexOf(el) >= 0;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// this function is taken from Acorn [1], written by Marijn Haverbeke
|
||||||
|
// [1] https://github.com/marijnh/acorn
|
||||||
|
function makePredicate(words) {
|
||||||
|
if (!(words instanceof Array)) words = words.split(" ");
|
||||||
|
var f = "", cats = [];
|
||||||
|
out: for (var i = 0; i < words.length; ++i) {
|
||||||
|
for (var j = 0; j < cats.length; ++j)
|
||||||
|
if (cats[j][0].length == words[i].length) {
|
||||||
|
cats[j].push(words[i]);
|
||||||
|
continue out;
|
||||||
|
}
|
||||||
|
cats.push([words[i]]);
|
||||||
|
}
|
||||||
|
function compareTo(arr) {
|
||||||
|
if (arr.length == 1) return f += "return str === " + JSON.stringify(arr[0]) + ";";
|
||||||
|
f += "switch(str){";
|
||||||
|
for (var i = 0; i < arr.length; ++i) f += "case " + JSON.stringify(arr[i]) + ":";
|
||||||
|
f += "return true}return false;";
|
||||||
|
}
|
||||||
|
// When there are more than three length categories, an outer
|
||||||
|
// switch first dispatches on the lengths, to save on comparisons.
|
||||||
|
if (cats.length > 3) {
|
||||||
|
cats.sort(function(a, b) {return b.length - a.length;});
|
||||||
|
f += "switch(str.length){";
|
||||||
|
for (var i = 0; i < cats.length; ++i) {
|
||||||
|
var cat = cats[i];
|
||||||
|
f += "case " + cat[0].length + ":";
|
||||||
|
compareTo(cat);
|
||||||
|
}
|
||||||
|
f += "}";
|
||||||
|
// Otherwise, simply generate a flat `switch` statement.
|
||||||
|
} else {
|
||||||
|
compareTo(words);
|
||||||
|
}
|
||||||
|
return new Function("str", f);
|
||||||
|
};
|
||||||
|
|
||||||
function all(array, predicate) {
|
function all(array, predicate) {
|
||||||
for (var i = array.length; --i >= 0;)
|
for (var i = array.length; --i >= 0;)
|
||||||
if (!predicate(array[i], i))
|
if (!predicate(array[i]))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
};
|
||||||
|
|
||||||
function Dictionary() {
|
function Dictionary() {
|
||||||
this._values = Object.create(null);
|
this._values = Object.create(null);
|
||||||
this._size = 0;
|
this._size = 0;
|
||||||
}
|
};
|
||||||
Dictionary.prototype = {
|
Dictionary.prototype = {
|
||||||
set: function(key, val) {
|
set: function(key, val) {
|
||||||
if (!this.has(key)) ++this._size;
|
if (!this.has(key)) ++this._size;
|
||||||
@@ -196,12 +286,6 @@ Dictionary.prototype = {
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
has: function(key) { return ("$" + key) in this._values },
|
has: function(key) { return ("$" + key) in this._values },
|
||||||
all: function(predicate) {
|
|
||||||
for (var i in this._values)
|
|
||||||
if (!predicate(this._values[i], i.substr(1)))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
each: function(f) {
|
each: function(f) {
|
||||||
for (var i in this._values)
|
for (var i in this._values)
|
||||||
f(this._values[i], i.substr(1));
|
f(this._values[i], i.substr(1));
|
||||||
@@ -214,47 +298,5 @@ Dictionary.prototype = {
|
|||||||
for (var i in this._values)
|
for (var i in this._values)
|
||||||
ret.push(f(this._values[i], i.substr(1)));
|
ret.push(f(this._values[i], i.substr(1)));
|
||||||
return ret;
|
return ret;
|
||||||
},
|
}
|
||||||
clone: function() {
|
|
||||||
var ret = new Dictionary();
|
|
||||||
for (var i in this._values)
|
|
||||||
ret._values[i] = this._values[i];
|
|
||||||
ret._size = this._size;
|
|
||||||
return ret;
|
|
||||||
},
|
|
||||||
toObject: function() { return this._values }
|
|
||||||
};
|
};
|
||||||
Dictionary.fromObject = function(obj) {
|
|
||||||
var dict = new Dictionary();
|
|
||||||
dict._size = merge(dict._values, obj);
|
|
||||||
return dict;
|
|
||||||
};
|
|
||||||
|
|
||||||
function HOP(obj, prop) {
|
|
||||||
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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) {
|
|
||||||
var node = stack.parent(-1);
|
|
||||||
for (var i = 0, p; p = stack.parent(i++); node = p) {
|
|
||||||
if (p.TYPE == "Call") {
|
|
||||||
if (p.expression === node) continue;
|
|
||||||
} else if (p instanceof AST_Binary) {
|
|
||||||
if (p.left === node) continue;
|
|
||||||
} else if (p instanceof AST_Conditional) {
|
|
||||||
if (p.condition === node) continue;
|
|
||||||
} else if (p instanceof AST_PropAccess) {
|
|
||||||
if (p.expression === node) continue;
|
|
||||||
} else if (p instanceof AST_Sequence) {
|
|
||||||
if (p.expressions[0] === node) continue;
|
|
||||||
} else if (p instanceof AST_Statement) {
|
|
||||||
return p.body === node;
|
|
||||||
} else if (p instanceof AST_UnaryPostfix) {
|
|
||||||
if (p.expression === node) continue;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
77
package.json
77
package.json
@@ -1,56 +1,37 @@
|
|||||||
{
|
{
|
||||||
"name": "uglify-js",
|
"name": "uglify-js",
|
||||||
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
|
||||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
"homepage": "http://lisperator.net/uglifyjs",
|
||||||
"license": "BSD-2-Clause",
|
|
||||||
"version": "3.11.2",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=0.8.0"
|
|
||||||
},
|
|
||||||
"maintainers": [
|
|
||||||
"Alex Lam <alexlamsl@gmail.com>",
|
|
||||||
"Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)"
|
|
||||||
],
|
|
||||||
"repository": "mishoo/UglifyJS",
|
|
||||||
"main": "tools/node.js",
|
"main": "tools/node.js",
|
||||||
|
"version": "2.4.17",
|
||||||
|
"engines": { "node" : ">=0.4.0" },
|
||||||
|
"maintainers": [{
|
||||||
|
"name": "Mihai Bazon",
|
||||||
|
"email": "mihai.bazon@gmail.com",
|
||||||
|
"web": "http://lisperator.net/"
|
||||||
|
}],
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/mishoo/UglifyJS2.git"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"async" : "~0.2.6",
|
||||||
|
"source-map" : "0.1.34",
|
||||||
|
"yargs": "~1.3.3",
|
||||||
|
"uglify-to-browserify": "~1.0.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"acorn": "~0.6.0",
|
||||||
|
"escodegen": "~1.3.3",
|
||||||
|
"esfuzz": "~0.3.1",
|
||||||
|
"estraverse": "~1.5.1"
|
||||||
|
},
|
||||||
|
"browserify": {
|
||||||
|
"transform": [ "uglify-to-browserify" ]
|
||||||
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"uglifyjs" : "bin/uglifyjs"
|
"uglifyjs" : "bin/uglifyjs"
|
||||||
},
|
},
|
||||||
"files": [
|
"license": "BSD",
|
||||||
"bin",
|
"scripts": {"test": "node test/run-tests.js"}
|
||||||
"lib",
|
|
||||||
"tools",
|
|
||||||
"LICENSE"
|
|
||||||
],
|
|
||||||
"devDependencies": {
|
|
||||||
"acorn": "~7.1.0",
|
|
||||||
"semver": "~6.3.0"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "node test/compress.js && node test/mocha.js"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"cli",
|
|
||||||
"compress",
|
|
||||||
"compressor",
|
|
||||||
"ecma",
|
|
||||||
"ecmascript",
|
|
||||||
"es",
|
|
||||||
"es5",
|
|
||||||
"javascript",
|
|
||||||
"js",
|
|
||||||
"jsmin",
|
|
||||||
"min",
|
|
||||||
"minification",
|
|
||||||
"minifier",
|
|
||||||
"minify",
|
|
||||||
"optimize",
|
|
||||||
"optimizer",
|
|
||||||
"pack",
|
|
||||||
"packer",
|
|
||||||
"parse",
|
|
||||||
"parser",
|
|
||||||
"uglifier",
|
|
||||||
"uglify"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,97 +0,0 @@
|
|||||||
#! /usr/bin/env node
|
|
||||||
// -*- js -*-
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var createHash = require("crypto").createHash;
|
|
||||||
var fetch = require("./fetch");
|
|
||||||
var spawn = require("child_process").spawn;
|
|
||||||
var zlib = require("zlib");
|
|
||||||
var args = process.argv.slice(2);
|
|
||||||
if (!args.length) args.push("-mc");
|
|
||||||
args.unshift("bin/uglifyjs");
|
|
||||||
args.push("--timings");
|
|
||||||
var urls = [
|
|
||||||
"https://code.jquery.com/jquery-3.4.1.js",
|
|
||||||
"https://code.angularjs.org/1.7.8/angular.js",
|
|
||||||
"https://unpkg.com/mathjs@6.2.3/dist/math.js",
|
|
||||||
"https://unpkg.com/react@15.3.2/dist/react.js",
|
|
||||||
"https://cdnjs.cloudflare.com/ajax/libs/d3/5.12.0/d3.js",
|
|
||||||
"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js",
|
|
||||||
"https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.js",
|
|
||||||
"https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.12.2/ember.prod.js",
|
|
||||||
"https://raw.githubusercontent.com/kangax/html-minifier/v4.0.0/dist/htmlminifier.js",
|
|
||||||
];
|
|
||||||
var results = {};
|
|
||||||
var remaining = 2 * urls.length;
|
|
||||||
function done() {
|
|
||||||
if (!--remaining) {
|
|
||||||
var failures = [];
|
|
||||||
var sum = { input: 0, output: 0, gzip: 0 };
|
|
||||||
urls.forEach(function(url) {
|
|
||||||
var info = results[url];
|
|
||||||
console.log();
|
|
||||||
console.log(url);
|
|
||||||
console.log(info.log);
|
|
||||||
console.log("Original:", info.input, "bytes");
|
|
||||||
console.log("Uglified:", info.output, "bytes");
|
|
||||||
console.log("GZipped: ", info.gzip, "bytes");
|
|
||||||
console.log("SHA1 sum:", info.sha1);
|
|
||||||
if (info.code) {
|
|
||||||
failures.push(url);
|
|
||||||
}
|
|
||||||
sum.input += info.input;
|
|
||||||
sum.output += info.output;
|
|
||||||
sum.gzip += info.gzip;
|
|
||||||
});
|
|
||||||
if (failures.length) {
|
|
||||||
console.error("Benchmark failed:");
|
|
||||||
failures.forEach(function(url) {
|
|
||||||
console.error(url);
|
|
||||||
});
|
|
||||||
process.exit(1);
|
|
||||||
} else {
|
|
||||||
console.log();
|
|
||||||
console.log("Subtotal");
|
|
||||||
console.log();
|
|
||||||
console.log("Original:", sum.input, "bytes");
|
|
||||||
console.log("Uglified:", sum.output, "bytes");
|
|
||||||
console.log("GZipped: ", sum.gzip, "bytes");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
urls.forEach(function(url) {
|
|
||||||
results[url] = {
|
|
||||||
input: 0,
|
|
||||||
output: 0,
|
|
||||||
gzip: 0,
|
|
||||||
log: ""
|
|
||||||
};
|
|
||||||
fetch(url, function(err, res) {
|
|
||||||
if (err) throw err;
|
|
||||||
var uglifyjs = spawn(process.argv[0], args, { silent: true });
|
|
||||||
res.on("data", function(data) {
|
|
||||||
results[url].input += data.length;
|
|
||||||
}).pipe(uglifyjs.stdin);
|
|
||||||
var sha1 = createHash("sha1");
|
|
||||||
uglifyjs.stdout.on("data", function(data) {
|
|
||||||
results[url].output += data.length;
|
|
||||||
}).pipe(zlib.createGzip({
|
|
||||||
level: zlib.Z_BEST_COMPRESSION
|
|
||||||
})).on("data", function(data) {
|
|
||||||
results[url].gzip += data.length;
|
|
||||||
sha1.update(data);
|
|
||||||
}).on("end", function() {
|
|
||||||
results[url].sha1 = sha1.digest("hex");
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
uglifyjs.stderr.setEncoding("utf8");
|
|
||||||
uglifyjs.stderr.on("data", function(data) {
|
|
||||||
results[url].log += data;
|
|
||||||
});
|
|
||||||
uglifyjs.on("exit", function(code) {
|
|
||||||
results[url].code = code;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
460
test/compress.js
460
test/compress.js
@@ -1,460 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
require("../tools/exit");
|
|
||||||
|
|
||||||
var assert = require("assert");
|
|
||||||
var child_process = require("child_process");
|
|
||||||
var fs = require("fs");
|
|
||||||
var path = require("path");
|
|
||||||
var sandbox = require("./sandbox");
|
|
||||||
var semver = require("semver");
|
|
||||||
var U = require("./node");
|
|
||||||
|
|
||||||
var file = process.argv[2];
|
|
||||||
var dir = path.resolve(path.dirname(module.filename), "compress");
|
|
||||||
if (file) {
|
|
||||||
var minify_options = require("./ufuzz/options.json").map(JSON.stringify);
|
|
||||||
log("--- {file}", { file: file });
|
|
||||||
var tests = parse_test(path.resolve(dir, file));
|
|
||||||
process.exit(Object.keys(tests).filter(function(name) {
|
|
||||||
return !test_case(tests[name]);
|
|
||||||
}).length);
|
|
||||||
} else {
|
|
||||||
var files = fs.readdirSync(dir).filter(function(name) {
|
|
||||||
return /\.js$/i.test(name);
|
|
||||||
});
|
|
||||||
var failures = 0;
|
|
||||||
var failed_files = Object.create(null);
|
|
||||||
(function next() {
|
|
||||||
var file = files.shift();
|
|
||||||
if (file) {
|
|
||||||
child_process.spawn(process.argv[0], [ process.argv[1], file ], {
|
|
||||||
stdio: [ "ignore", 1, 2 ]
|
|
||||||
}).on("exit", function(code) {
|
|
||||||
if (code) {
|
|
||||||
failures += code;
|
|
||||||
failed_files[file] = code;
|
|
||||||
}
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
} else if (failures) {
|
|
||||||
console.error();
|
|
||||||
console.error("!!! Failed " + failures + " test case(s).");
|
|
||||||
console.error("!!! " + Object.keys(failed_files).join(", "));
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
|
|
||||||
function evaluate(code) {
|
|
||||||
if (code instanceof U.AST_Node) code = make_code(code, { beautify: true });
|
|
||||||
return new Function("return(" + code + ")")();
|
|
||||||
}
|
|
||||||
|
|
||||||
function log() {
|
|
||||||
console.log("%s", tmpl.apply(null, arguments));
|
|
||||||
}
|
|
||||||
|
|
||||||
function make_code(ast, options) {
|
|
||||||
var stream = U.OutputStream(options);
|
|
||||||
ast.print(stream);
|
|
||||||
return stream.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
function parse_test(file) {
|
|
||||||
var script = fs.readFileSync(file, "utf8");
|
|
||||||
// TODO try/catch can be removed after fixing https://github.com/mishoo/UglifyJS/issues/348
|
|
||||||
try {
|
|
||||||
var ast = U.parse(script, {
|
|
||||||
filename: file
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Caught error while parsing tests in " + file);
|
|
||||||
console.error(e);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
var tests = Object.create(null);
|
|
||||||
var tw = new U.TreeWalker(function(node, descend) {
|
|
||||||
if (node instanceof U.AST_LabeledStatement
|
|
||||||
&& tw.parent() instanceof U.AST_Toplevel) {
|
|
||||||
var name = node.label.name;
|
|
||||||
if (name in tests) {
|
|
||||||
throw new Error('Duplicated test name "' + name + '" in ' + file);
|
|
||||||
}
|
|
||||||
tests[name] = get_one_test(name, node.body);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!(node instanceof U.AST_Toplevel)) croak(node);
|
|
||||||
});
|
|
||||||
ast.walk(tw);
|
|
||||||
return tests;
|
|
||||||
|
|
||||||
function croak(node) {
|
|
||||||
throw new Error(tmpl("Can't understand test file {file} [{line},{col}]\n{code}", {
|
|
||||||
file: file,
|
|
||||||
line: node.start.line,
|
|
||||||
col: node.start.col,
|
|
||||||
code: make_code(node, { beautify: false })
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
function read_string(stat) {
|
|
||||||
if (stat.TYPE == "SimpleStatement") {
|
|
||||||
var body = stat.body;
|
|
||||||
switch(body.TYPE) {
|
|
||||||
case "String":
|
|
||||||
return body.value;
|
|
||||||
case "Array":
|
|
||||||
return body.elements.map(function(element) {
|
|
||||||
if (element.TYPE !== "String")
|
|
||||||
throw new Error("Should be array of strings");
|
|
||||||
return element.value;
|
|
||||||
}).join("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new Error("Should be string or array of strings");
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_one_test(name, block) {
|
|
||||||
var test = { name: name, options: {} };
|
|
||||||
var tw = new U.TreeWalker(function(node, descend) {
|
|
||||||
if (node instanceof U.AST_Assign) {
|
|
||||||
if (!(node.left instanceof U.AST_SymbolRef)) {
|
|
||||||
croak(node);
|
|
||||||
}
|
|
||||||
var name = node.left.name;
|
|
||||||
test[name] = evaluate(node.right);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (node instanceof U.AST_LabeledStatement) {
|
|
||||||
var label = node.label;
|
|
||||||
assert.ok([
|
|
||||||
"input",
|
|
||||||
"expect",
|
|
||||||
"expect_exact",
|
|
||||||
"expect_warnings",
|
|
||||||
"expect_stdout",
|
|
||||||
"node_version",
|
|
||||||
].indexOf(label.name) >= 0, tmpl("Unsupported label {name} [{line},{col}]", {
|
|
||||||
name: label.name,
|
|
||||||
line: label.start.line,
|
|
||||||
col: label.start.col
|
|
||||||
}));
|
|
||||||
var stat = node.body;
|
|
||||||
if (label.name == "expect_exact" || label.name == "node_version") {
|
|
||||||
test[label.name] = read_string(stat);
|
|
||||||
} else if (label.name == "expect_stdout") {
|
|
||||||
var body = stat.body;
|
|
||||||
if (body instanceof U.AST_Boolean) {
|
|
||||||
test[label.name] = body.value;
|
|
||||||
} else if (body instanceof U.AST_Call) {
|
|
||||||
var ctor = global[body.expression.name];
|
|
||||||
assert.ok(ctor === Error || ctor.prototype instanceof Error, tmpl("Unsupported expect_stdout format [{line},{col}]", {
|
|
||||||
line: label.start.line,
|
|
||||||
col: label.start.col
|
|
||||||
}));
|
|
||||||
test[label.name] = ctor.apply(null, body.args.map(function(node) {
|
|
||||||
assert.ok(node instanceof U.AST_Constant, tmpl("Unsupported expect_stdout format [{line},{col}]", {
|
|
||||||
line: label.start.line,
|
|
||||||
col: label.start.col
|
|
||||||
}));
|
|
||||||
return node.value;
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
test[label.name] = read_string(stat) + "\n";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
test[label.name] = stat;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
block.walk(tw);
|
|
||||||
return test;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to reminify original input with standard options
|
|
||||||
// to see if it matches expect_stdout.
|
|
||||||
function reminify(orig_options, input_code, input_formatted, stdout) {
|
|
||||||
for (var i = 0; i < minify_options.length; i++) {
|
|
||||||
var options = JSON.parse(minify_options[i]);
|
|
||||||
if (options.compress) [
|
|
||||||
"keep_fargs",
|
|
||||||
"keep_fnames",
|
|
||||||
].forEach(function(name) {
|
|
||||||
if (name in orig_options) {
|
|
||||||
options.compress[name] = orig_options[name];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
var options_formatted = JSON.stringify(options, null, 4);
|
|
||||||
options.validate = true;
|
|
||||||
var result = U.minify(input_code, options);
|
|
||||||
if (result.error) {
|
|
||||||
log([
|
|
||||||
"!!! failed input reminify",
|
|
||||||
"---INPUT---",
|
|
||||||
"{input}",
|
|
||||||
"---OPTIONS---",
|
|
||||||
"{options}",
|
|
||||||
"--ERROR---",
|
|
||||||
"{error}",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
].join("\n"), {
|
|
||||||
input: input_formatted,
|
|
||||||
options: options_formatted,
|
|
||||||
error: result.error,
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
var toplevel = sandbox.has_toplevel(options);
|
|
||||||
var expected = stdout[toplevel ? 1 : 0];
|
|
||||||
var actual = run_code(result.code, toplevel);
|
|
||||||
if (typeof expected != "string" && typeof actual != "string" && expected.name == actual.name) {
|
|
||||||
actual = expected;
|
|
||||||
}
|
|
||||||
if (!sandbox.same_stdout(expected, actual)) {
|
|
||||||
log([
|
|
||||||
"!!! failed running reminified input",
|
|
||||||
"---INPUT---",
|
|
||||||
"{input}",
|
|
||||||
"---OPTIONS---",
|
|
||||||
"{options}",
|
|
||||||
"---OUTPUT---",
|
|
||||||
"{output}",
|
|
||||||
"---EXPECTED {expected_type}---",
|
|
||||||
"{expected}",
|
|
||||||
"---ACTUAL {actual_type}---",
|
|
||||||
"{actual}",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
].join("\n"), {
|
|
||||||
input: input_formatted,
|
|
||||||
options: options_formatted,
|
|
||||||
output: result.code,
|
|
||||||
expected_type: typeof expected == "string" ? "STDOUT" : "ERROR",
|
|
||||||
expected: expected,
|
|
||||||
actual_type: typeof actual == "string" ? "STDOUT" : "ERROR",
|
|
||||||
actual: actual,
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_code(code, toplevel) {
|
|
||||||
var result = sandbox.run_code(code, toplevel);
|
|
||||||
return typeof result == "string" ? result.replace(/\u001b\[\d+m/g, "") : result;
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_case(test) {
|
|
||||||
log(" Running test [{name}]", { name: test.name });
|
|
||||||
U.AST_Node.enable_validation();
|
|
||||||
var output_options = test.beautify || {};
|
|
||||||
var expect;
|
|
||||||
if (test.expect) {
|
|
||||||
expect = make_code(to_toplevel(test.expect, test.mangle), output_options);
|
|
||||||
} else {
|
|
||||||
expect = test.expect_exact;
|
|
||||||
}
|
|
||||||
var input = to_toplevel(test.input, test.mangle);
|
|
||||||
var input_code = make_code(input);
|
|
||||||
var input_formatted = make_code(test.input, {
|
|
||||||
beautify: true,
|
|
||||||
comments: "all",
|
|
||||||
keep_quoted_props: true,
|
|
||||||
quote_style: 3,
|
|
||||||
});
|
|
||||||
try {
|
|
||||||
input.validate_ast();
|
|
||||||
U.parse(input_code);
|
|
||||||
} catch (ex) {
|
|
||||||
log([
|
|
||||||
"!!! Cannot parse input",
|
|
||||||
"---INPUT---",
|
|
||||||
"{input}",
|
|
||||||
"--PARSE ERROR--",
|
|
||||||
"{error}",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
].join("\n"), {
|
|
||||||
input: input_formatted,
|
|
||||||
error: ex,
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
var warnings_emitted = [];
|
|
||||||
if (test.expect_warnings) {
|
|
||||||
var expected_warnings = make_code(test.expect_warnings, {
|
|
||||||
beautify: false,
|
|
||||||
quote_style: 2, // force double quote to match JSON
|
|
||||||
});
|
|
||||||
U.AST_Node.log_function(function(text) {
|
|
||||||
warnings_emitted.push(text);
|
|
||||||
}, /"INFO: /.test(expected_warnings));
|
|
||||||
}
|
|
||||||
if (test.mangle && test.mangle.properties && test.mangle.properties.keep_quoted) {
|
|
||||||
var quoted_props = test.mangle.properties.reserved;
|
|
||||||
if (!Array.isArray(quoted_props)) quoted_props = [];
|
|
||||||
test.mangle.properties.reserved = quoted_props;
|
|
||||||
U.reserve_quoted_keys(input, quoted_props);
|
|
||||||
}
|
|
||||||
if (test.rename) {
|
|
||||||
input.figure_out_scope(test.mangle);
|
|
||||||
input.expand_names(test.mangle);
|
|
||||||
}
|
|
||||||
var cmp = new U.Compressor(test.options, true);
|
|
||||||
var output = cmp.compress(input);
|
|
||||||
output.figure_out_scope(test.mangle);
|
|
||||||
if (test.mangle) {
|
|
||||||
output.compute_char_frequency(test.mangle);
|
|
||||||
output.mangle_names(test.mangle);
|
|
||||||
if (test.mangle.properties) U.mangle_properties(output, test.mangle.properties);
|
|
||||||
}
|
|
||||||
var output_code = make_code(output, output_options);
|
|
||||||
if (expect != output_code) {
|
|
||||||
log([
|
|
||||||
"!!! failed",
|
|
||||||
"---INPUT---",
|
|
||||||
"{input}",
|
|
||||||
"---OUTPUT---",
|
|
||||||
"{output}",
|
|
||||||
"---EXPECTED---",
|
|
||||||
"{expected}",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
].join("\n"), {
|
|
||||||
input: input_formatted,
|
|
||||||
output: output_code,
|
|
||||||
expected: expect
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// expect == output
|
|
||||||
try {
|
|
||||||
output.validate_ast();
|
|
||||||
U.parse(output_code);
|
|
||||||
} catch (ex) {
|
|
||||||
log([
|
|
||||||
"!!! Test matched expected result but cannot parse output",
|
|
||||||
"---INPUT---",
|
|
||||||
"{input}",
|
|
||||||
"---OUTPUT---",
|
|
||||||
"{output}",
|
|
||||||
"--REPARSE ERROR--",
|
|
||||||
"{error}",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
].join("\n"), {
|
|
||||||
input: input_formatted,
|
|
||||||
output: output_code,
|
|
||||||
error: ex,
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (test.expect_warnings) {
|
|
||||||
warnings_emitted = warnings_emitted.map(function(input) {
|
|
||||||
return input.split(process.cwd() + path.sep).join("").split(path.sep).join("/");
|
|
||||||
});
|
|
||||||
var actual_warnings = JSON.stringify(warnings_emitted);
|
|
||||||
if (expected_warnings != actual_warnings) {
|
|
||||||
log([
|
|
||||||
"!!! failed",
|
|
||||||
"---INPUT---",
|
|
||||||
"{input}",
|
|
||||||
"---EXPECTED WARNINGS---",
|
|
||||||
"{expected_warnings}",
|
|
||||||
"---ACTUAL WARNINGS---",
|
|
||||||
"{actual_warnings}",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
].join("\n"), {
|
|
||||||
input: input_formatted,
|
|
||||||
expected_warnings: expected_warnings,
|
|
||||||
actual_warnings: actual_warnings,
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (test.expect_stdout && (!test.node_version || semver.satisfies(process.version, test.node_version))) {
|
|
||||||
var stdout = [ run_code(input_code), run_code(input_code, true) ];
|
|
||||||
var toplevel = sandbox.has_toplevel({
|
|
||||||
compress: test.options,
|
|
||||||
mangle: test.mangle
|
|
||||||
});
|
|
||||||
var actual = stdout[toplevel ? 1 : 0];
|
|
||||||
if (test.expect_stdout === true) {
|
|
||||||
test.expect_stdout = actual;
|
|
||||||
}
|
|
||||||
if (!sandbox.same_stdout(test.expect_stdout, actual)) {
|
|
||||||
log([
|
|
||||||
"!!! Invalid input or expected stdout",
|
|
||||||
"---INPUT---",
|
|
||||||
"{input}",
|
|
||||||
"---EXPECTED {expected_type}---",
|
|
||||||
"{expected}",
|
|
||||||
"---ACTUAL {actual_type}---",
|
|
||||||
"{actual}",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
].join("\n"), {
|
|
||||||
input: input_formatted,
|
|
||||||
expected_type: typeof test.expect_stdout == "string" ? "STDOUT" : "ERROR",
|
|
||||||
expected: test.expect_stdout,
|
|
||||||
actual_type: typeof actual == "string" ? "STDOUT" : "ERROR",
|
|
||||||
actual: actual,
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
actual = run_code(output_code, toplevel);
|
|
||||||
if (!sandbox.same_stdout(test.expect_stdout, actual)) {
|
|
||||||
log([
|
|
||||||
"!!! failed",
|
|
||||||
"---INPUT---",
|
|
||||||
"{input}",
|
|
||||||
"---EXPECTED {expected_type}---",
|
|
||||||
"{expected}",
|
|
||||||
"---ACTUAL {actual_type}---",
|
|
||||||
"{actual}",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
].join("\n"), {
|
|
||||||
input: input_formatted,
|
|
||||||
expected_type: typeof test.expect_stdout == "string" ? "STDOUT" : "ERROR",
|
|
||||||
expected: test.expect_stdout,
|
|
||||||
actual_type: typeof actual == "string" ? "STDOUT" : "ERROR",
|
|
||||||
actual: actual,
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!reminify(test.options, input_code, input_formatted, stdout)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function tmpl() {
|
|
||||||
return U.string_template.apply(null, arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
function to_toplevel(input, mangle_options) {
|
|
||||||
if (!(input instanceof U.AST_BlockStatement)) throw new Error("Unsupported input syntax");
|
|
||||||
var directive = true;
|
|
||||||
var offset = input.start.line;
|
|
||||||
var tokens = [];
|
|
||||||
var toplevel = new U.AST_Toplevel(input.transform(new U.TreeTransformer(function(node) {
|
|
||||||
if (U.push_uniq(tokens, node.start)) node.start.line -= offset;
|
|
||||||
if (!directive || node === input) return;
|
|
||||||
if (node instanceof U.AST_SimpleStatement && node.body instanceof U.AST_String) {
|
|
||||||
return new U.AST_Directive(node.body);
|
|
||||||
} else {
|
|
||||||
directive = false;
|
|
||||||
}
|
|
||||||
})));
|
|
||||||
toplevel.figure_out_scope(mangle_options);
|
|
||||||
return toplevel;
|
|
||||||
}
|
|
||||||
67
test/compress/angular-inject.js
vendored
Normal file
67
test/compress/angular-inject.js
vendored
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
ng_inject_defun: {
|
||||||
|
options = {
|
||||||
|
angular: true
|
||||||
|
};
|
||||||
|
input: {
|
||||||
|
/*@ngInject*/
|
||||||
|
function Controller(dependency) {
|
||||||
|
return dependency;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function Controller(dependency) {
|
||||||
|
return dependency;
|
||||||
|
}
|
||||||
|
Controller.$inject=['dependency']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ng_inject_assignment: {
|
||||||
|
options = {
|
||||||
|
angular: true
|
||||||
|
};
|
||||||
|
input: {
|
||||||
|
/*@ngInject*/
|
||||||
|
var Controller = function(dependency) {
|
||||||
|
return dependency;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var Controller = function(dependency) {
|
||||||
|
return dependency;
|
||||||
|
}
|
||||||
|
Controller.$inject=['dependency']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ng_inject_inline: {
|
||||||
|
options = {
|
||||||
|
angular: true
|
||||||
|
};
|
||||||
|
input: {
|
||||||
|
angular.module('a').
|
||||||
|
factory('b',
|
||||||
|
/*@ngInject*/
|
||||||
|
function(dependency) {
|
||||||
|
return dependency;
|
||||||
|
}).
|
||||||
|
directive('c',
|
||||||
|
/*@ngInject*/
|
||||||
|
function(anotherDependency) {
|
||||||
|
return anotherDependency;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
angular.module('a').
|
||||||
|
factory('b',[
|
||||||
|
'dependency',
|
||||||
|
function(dependency) {
|
||||||
|
return dependency;
|
||||||
|
}]).
|
||||||
|
directive('c',[
|
||||||
|
'anotherDependency',
|
||||||
|
function(anotherDependency) {
|
||||||
|
return anotherDependency;
|
||||||
|
}])
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,785 +0,0 @@
|
|||||||
replace_index: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
evaluate: true,
|
|
||||||
properties: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var arguments = [];
|
|
||||||
console.log(arguments[0]);
|
|
||||||
(function() {
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(a, b) {
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(arguments) {
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
(function() {
|
|
||||||
var arguments;
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var arguments = [];
|
|
||||||
console.log(arguments[0]);
|
|
||||||
(function() {
|
|
||||||
console.log(arguments[1], arguments[1], arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(a, b) {
|
|
||||||
console.log(b, b, arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(arguments) {
|
|
||||||
console.log(arguments[1], arguments[1], arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
(function() {
|
|
||||||
var arguments;
|
|
||||||
console.log(arguments[1], arguments[1], arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"undefined",
|
|
||||||
"42 42 undefined",
|
|
||||||
"42 42 undefined",
|
|
||||||
"a a undefined",
|
|
||||||
"42 42 undefined",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
replace_index_strict: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
evaluate: true,
|
|
||||||
properties: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
(function() {
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(a, b) {
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
(function() {
|
|
||||||
console.log(arguments[1], arguments[1], arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(a, b) {
|
|
||||||
console.log(b, b, arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"42 42 undefined",
|
|
||||||
"42 42 undefined",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
replace_index_keep_fargs: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
evaluate: true,
|
|
||||||
keep_fargs: false,
|
|
||||||
properties: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var arguments = [];
|
|
||||||
console.log(arguments[0]);
|
|
||||||
(function() {
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(a, b) {
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(arguments) {
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
(function() {
|
|
||||||
var arguments;
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var arguments = [];
|
|
||||||
console.log(arguments[0]);
|
|
||||||
(function(argument_0, argument_1) {
|
|
||||||
console.log(argument_1, argument_1, arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(a, b) {
|
|
||||||
console.log(b, b, arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(arguments) {
|
|
||||||
console.log(arguments[1], arguments[1], arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
(function() {
|
|
||||||
var arguments;
|
|
||||||
console.log(arguments[1], arguments[1], arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"undefined",
|
|
||||||
"42 42 undefined",
|
|
||||||
"42 42 undefined",
|
|
||||||
"a a undefined",
|
|
||||||
"42 42 undefined",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
replace_index_keep_fargs_strict: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
evaluate: true,
|
|
||||||
keep_fargs: false,
|
|
||||||
properties: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
(function() {
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(a, b) {
|
|
||||||
console.log(arguments[1], arguments["1"], arguments["foo"]);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
(function(argument_0, argument_1) {
|
|
||||||
console.log(argument_1, argument_1, arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
(function(a, b) {
|
|
||||||
console.log(b, b, arguments.foo);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"42 42 undefined",
|
|
||||||
"42 42 undefined",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
modified: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(a, b) {
|
|
||||||
var c = arguments[0];
|
|
||||||
var d = arguments[1];
|
|
||||||
var a = "foo";
|
|
||||||
b++;
|
|
||||||
arguments[0] = "moo";
|
|
||||||
arguments[1] *= 2;
|
|
||||||
console.log(a, b, c, d, arguments[0], arguments[1]);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(a, b) {
|
|
||||||
var c = a;
|
|
||||||
var d = b;
|
|
||||||
var a = "foo";
|
|
||||||
b++;
|
|
||||||
a = "moo";
|
|
||||||
b *= 2;
|
|
||||||
console.log(a, b, c, d, a, b);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect_stdout: "moo 86 bar 42 moo 86"
|
|
||||||
}
|
|
||||||
|
|
||||||
modified_strict: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
(function(a, b) {
|
|
||||||
var c = arguments[0];
|
|
||||||
var d = arguments[1];
|
|
||||||
var a = "foo";
|
|
||||||
b++;
|
|
||||||
arguments[0] = "moo";
|
|
||||||
arguments[1] *= 2;
|
|
||||||
console.log(a, b, c, d, arguments[0], arguments[1]);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
(function(a, b) {
|
|
||||||
var c = arguments[0];
|
|
||||||
var d = arguments[1];
|
|
||||||
var a = "foo";
|
|
||||||
b++;
|
|
||||||
arguments[0] = "moo";
|
|
||||||
arguments[1] *= 2;
|
|
||||||
console.log(a, b, c, d, arguments[0], arguments[1]);
|
|
||||||
})("bar", 42);
|
|
||||||
}
|
|
||||||
expect_stdout: "foo 43 bar 42 moo 84"
|
|
||||||
}
|
|
||||||
|
|
||||||
duplicate_argname: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(a, b, a) {
|
|
||||||
console.log(a, b, arguments[0], arguments[1], arguments[2]);
|
|
||||||
})("foo", 42, "bar");
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(a, b, a) {
|
|
||||||
console.log(a, b, arguments[0], b, a);
|
|
||||||
})("foo", 42, "bar");
|
|
||||||
}
|
|
||||||
expect_stdout: "bar 42 foo 42 bar"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3273: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(a) {
|
|
||||||
console.log(arguments[0], a);
|
|
||||||
arguments[0]++;
|
|
||||||
console.log(arguments[0], a);
|
|
||||||
})(0);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(a) {
|
|
||||||
console.log(a, a);
|
|
||||||
a++;
|
|
||||||
console.log(a, a);
|
|
||||||
})(0);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"0 0",
|
|
||||||
"1 1",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3273_no_call_arg: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(a) {
|
|
||||||
arguments[0] = "FAIL";
|
|
||||||
console.log(a);
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(a) {
|
|
||||||
arguments[0] = "FAIL";
|
|
||||||
console.log(a);
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_stdout: "undefined"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3273_reduce_vars: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(a) {
|
|
||||||
console.log(arguments[0], a);
|
|
||||||
arguments[0]++;
|
|
||||||
console.log(arguments[0], a);
|
|
||||||
})(0);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(a) {
|
|
||||||
console.log(a, a);
|
|
||||||
a++;
|
|
||||||
console.log(a, a);
|
|
||||||
})(0);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"0 0",
|
|
||||||
"1 1",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3273_local_strict: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(a) {
|
|
||||||
"use strict";
|
|
||||||
console.log(arguments[0], a);
|
|
||||||
arguments[0]++;
|
|
||||||
console.log(arguments[0], a);
|
|
||||||
})(0);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(a) {
|
|
||||||
"use strict";
|
|
||||||
console.log(arguments[0], a);
|
|
||||||
arguments[0]++;
|
|
||||||
console.log(arguments[0], a);
|
|
||||||
})(0);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"0 0",
|
|
||||||
"1 0",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3273_local_strict_reduce_vars: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(a) {
|
|
||||||
"use strict";
|
|
||||||
console.log(arguments[0], a);
|
|
||||||
arguments[0]++;
|
|
||||||
console.log(arguments[0], a);
|
|
||||||
})(0);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(a) {
|
|
||||||
"use strict";
|
|
||||||
console.log(arguments[0], a);
|
|
||||||
arguments[0]++;
|
|
||||||
console.log(arguments[0], a);
|
|
||||||
})(0);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"0 0",
|
|
||||||
"1 0",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3273_global_strict: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
(function(a) {
|
|
||||||
console.log(arguments[0], a);
|
|
||||||
arguments[0]++;
|
|
||||||
console.log(arguments[0], a);
|
|
||||||
})(0);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
(function(a) {
|
|
||||||
console.log(arguments[0], a);
|
|
||||||
arguments[0]++;
|
|
||||||
console.log(arguments[0], a);
|
|
||||||
})(0);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"0 0",
|
|
||||||
"1 0",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3273_global_strict_reduce_vars: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
(function(a) {
|
|
||||||
console.log(arguments[0], a);
|
|
||||||
arguments[0]++;
|
|
||||||
console.log(arguments[0], a);
|
|
||||||
})(0);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
(function(a) {
|
|
||||||
console.log(arguments[0], a);
|
|
||||||
arguments[0]++;
|
|
||||||
console.log(arguments[0], a);
|
|
||||||
})(0);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"0 0",
|
|
||||||
"1 0",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3273_keep_fargs_false: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
keep_fargs: false,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
"use strict";
|
|
||||||
arguments[0]++;
|
|
||||||
console.log(arguments[0]);
|
|
||||||
})(0);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(argument_0) {
|
|
||||||
"use strict";
|
|
||||||
argument_0++;
|
|
||||||
console.log(argument_0);
|
|
||||||
})(0);
|
|
||||||
}
|
|
||||||
expect_stdout: "1"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3273_keep_fargs_strict: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
keep_fargs: "strict",
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
"use strict";
|
|
||||||
arguments[0]++;
|
|
||||||
console.log(arguments[0]);
|
|
||||||
})(0);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(argument_0) {
|
|
||||||
"use strict";
|
|
||||||
argument_0++;
|
|
||||||
console.log(argument_0);
|
|
||||||
})(0);
|
|
||||||
}
|
|
||||||
expect_stdout: "1"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3282_1: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
keep_fargs: false,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(t) {
|
|
||||||
return function() {
|
|
||||||
t();
|
|
||||||
};
|
|
||||||
})(function() {
|
|
||||||
'use strict';
|
|
||||||
function e() {
|
|
||||||
return arguments[0];
|
|
||||||
}
|
|
||||||
e();
|
|
||||||
e();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function() {
|
|
||||||
return function() {
|
|
||||||
(function() {
|
|
||||||
"use strict";
|
|
||||||
function e() {
|
|
||||||
return arguments[0];
|
|
||||||
}
|
|
||||||
e();
|
|
||||||
e();
|
|
||||||
})();
|
|
||||||
};
|
|
||||||
})()();
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3282_1_passes: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
passes: 2,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
keep_fargs: false,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(t) {
|
|
||||||
return function() {
|
|
||||||
t();
|
|
||||||
};
|
|
||||||
})(function() {
|
|
||||||
'use strict';
|
|
||||||
function e() {
|
|
||||||
return arguments[0];
|
|
||||||
}
|
|
||||||
e();
|
|
||||||
e();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function() {
|
|
||||||
return function() {
|
|
||||||
(function() {
|
|
||||||
"use strict";
|
|
||||||
function e(argument_0) {
|
|
||||||
return argument_0;
|
|
||||||
}
|
|
||||||
e();
|
|
||||||
e();
|
|
||||||
})();
|
|
||||||
};
|
|
||||||
})()();
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3282_2: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
keep_fargs: false,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(f) {
|
|
||||||
f();
|
|
||||||
})(function() {
|
|
||||||
return (function(t) {
|
|
||||||
return function() {
|
|
||||||
t();
|
|
||||||
};
|
|
||||||
})(function() {
|
|
||||||
'use strict';
|
|
||||||
function e() {
|
|
||||||
return arguments[0];
|
|
||||||
}
|
|
||||||
e();
|
|
||||||
e();
|
|
||||||
})();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function() {
|
|
||||||
(function() {
|
|
||||||
return function(t) {
|
|
||||||
return function() {
|
|
||||||
t();
|
|
||||||
};
|
|
||||||
}(function() {
|
|
||||||
"use strict";
|
|
||||||
function e() {
|
|
||||||
return arguments[0];
|
|
||||||
}
|
|
||||||
e();
|
|
||||||
e();
|
|
||||||
})();
|
|
||||||
})();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3282_2_passes: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
passes: 2,
|
|
||||||
reduce_vars: true,
|
|
||||||
keep_fargs: false,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(f) {
|
|
||||||
f();
|
|
||||||
})(function() {
|
|
||||||
return (function(t) {
|
|
||||||
return function() {
|
|
||||||
t();
|
|
||||||
};
|
|
||||||
})(function() {
|
|
||||||
'use strict';
|
|
||||||
function e() {
|
|
||||||
return arguments[0];
|
|
||||||
}
|
|
||||||
e();
|
|
||||||
e();
|
|
||||||
})();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function() {
|
|
||||||
(function() {
|
|
||||||
return function(t) {
|
|
||||||
return function() {
|
|
||||||
t();
|
|
||||||
};
|
|
||||||
}(function() {
|
|
||||||
"use strict";
|
|
||||||
function e(argument_0) {
|
|
||||||
return argument_0;
|
|
||||||
}
|
|
||||||
e();
|
|
||||||
e();
|
|
||||||
})();
|
|
||||||
})();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3420_1: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
keep_fargs: "strict",
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function() {
|
|
||||||
return function() {
|
|
||||||
return arguments[0];
|
|
||||||
};
|
|
||||||
}().length);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(function() {
|
|
||||||
return function() {
|
|
||||||
return arguments[0];
|
|
||||||
};
|
|
||||||
}().length);
|
|
||||||
}
|
|
||||||
expect_stdout: "0"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3420_2: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
keep_fargs: "strict",
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo = function() {
|
|
||||||
delete arguments[0];
|
|
||||||
};
|
|
||||||
foo();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var foo = function() {
|
|
||||||
delete arguments[0];
|
|
||||||
};
|
|
||||||
foo();
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3420_3: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
keep_fargs: "strict",
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
var foo = function() {
|
|
||||||
delete arguments[0];
|
|
||||||
};
|
|
||||||
foo();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
var foo = function() {
|
|
||||||
delete arguments[0];
|
|
||||||
};
|
|
||||||
foo();
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3420_4: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
keep_fargs: "strict",
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
!function() {
|
|
||||||
console.log(arguments[0]);
|
|
||||||
delete arguments[0];
|
|
||||||
console.log(arguments[0]);
|
|
||||||
}(42);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
!function(argument_0) {
|
|
||||||
console.log(argument_0);
|
|
||||||
delete arguments[0];
|
|
||||||
console.log(arguments[0]);
|
|
||||||
}(42);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"42",
|
|
||||||
"undefined",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3420_5: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
keep_fargs: "strict",
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
!function() {
|
|
||||||
console.log(arguments[0]);
|
|
||||||
delete arguments[0];
|
|
||||||
console.log(arguments[0]);
|
|
||||||
}(42);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
!function(argument_0) {
|
|
||||||
console.log(argument_0);
|
|
||||||
delete arguments[0];
|
|
||||||
console.log(arguments[0]);
|
|
||||||
}(42);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"42",
|
|
||||||
"undefined",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3420_6: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
keep_fargs: "strict",
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function() {
|
|
||||||
return delete arguments[0];
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(function() {
|
|
||||||
return delete arguments[0];
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect_stdout: "true"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3420_7: {
|
|
||||||
options = {
|
|
||||||
arguments: true,
|
|
||||||
keep_fargs: "strict",
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
console.log(function() {
|
|
||||||
return delete arguments[0];
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
console.log(function() {
|
|
||||||
return delete arguments[0];
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect_stdout: "true"
|
|
||||||
}
|
|
||||||
@@ -15,26 +15,16 @@ holes_and_undefined: {
|
|||||||
|
|
||||||
constant_join: {
|
constant_join: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
|
||||||
strings: true,
|
|
||||||
unsafe : true,
|
unsafe : true,
|
||||||
}
|
evaluate : true
|
||||||
|
};
|
||||||
input: {
|
input: {
|
||||||
var a = [ "foo", "bar", "baz" ].join("");
|
var a = [ "foo", "bar", "baz" ].join("");
|
||||||
var a1 = [ "foo", "bar", "baz" ].join();
|
var a1 = [ "foo", "bar", "baz" ].join();
|
||||||
var a2 = [ "foo", "bar", "baz" ].join(null);
|
|
||||||
var a3 = [ "foo", "bar", "baz" ].join(void 0);
|
|
||||||
var a4 = [ "foo", , "baz" ].join();
|
|
||||||
var a5 = [ "foo", null, "baz" ].join();
|
|
||||||
var a6 = [ "foo", void 0, "baz" ].join();
|
|
||||||
var b = [ "foo", 1, 2, 3, "bar" ].join("");
|
var b = [ "foo", 1, 2, 3, "bar" ].join("");
|
||||||
var c = [ boo(), "foo", 1, 2, 3, "bar", bar() ].join("");
|
var c = [ boo(), "foo", 1, 2, 3, "bar", bar() ].join("");
|
||||||
var c1 = [ boo(), bar(), "foo", 1, 2, 3, "bar", bar() ].join("");
|
var c1 = [ boo(), bar(), "foo", 1, 2, 3, "bar", bar() ].join("");
|
||||||
var c2 = [ 1, 2, "foo", "bar", baz() ].join("");
|
var c2 = [ 1, 2, "foo", "bar", baz() ].join("");
|
||||||
var c3 = [ boo() + bar() + "foo", 1, 2, 3, "bar", bar() + "foo" ].join("");
|
|
||||||
var c4 = [ 1, 2, null, undefined, "foo", "bar", baz() ].join("");
|
|
||||||
var c5 = [ boo() + bar() + "foo", 1, 2, 3, "bar", bar() + "foo" ].join();
|
|
||||||
var c6 = [ 1, 2, null, undefined, "foo", "bar", baz() ].join();
|
|
||||||
var d = [ "foo", 1 + 2 + "bar", "baz" ].join("-");
|
var d = [ "foo", 1 + 2 + "bar", "baz" ].join("-");
|
||||||
var e = [].join(foo + bar);
|
var e = [].join(foo + bar);
|
||||||
var f = [].join("");
|
var f = [].join("");
|
||||||
@@ -43,19 +33,10 @@ constant_join: {
|
|||||||
expect: {
|
expect: {
|
||||||
var a = "foobarbaz";
|
var a = "foobarbaz";
|
||||||
var a1 = "foo,bar,baz";
|
var a1 = "foo,bar,baz";
|
||||||
var a2 = "foonullbarnullbaz";
|
|
||||||
var a3 = "foo,bar,baz";
|
|
||||||
var a4 = "foo,,baz";
|
|
||||||
var a5 = "foo,,baz";
|
|
||||||
var a6 = "foo,,baz";
|
|
||||||
var b = "foo123bar";
|
var b = "foo123bar";
|
||||||
var c = boo() + "foo123bar" + bar();
|
var c = boo() + "foo123bar" + bar();
|
||||||
var c1 = "" + boo() + bar() + "foo123bar" + bar();
|
var c1 = "" + boo() + bar() + "foo123bar" + bar();
|
||||||
var c2 = "12foobar" + baz();
|
var c2 = "12foobar" + baz();
|
||||||
var c3 = boo() + bar() + "foo123bar" + bar() + "foo";
|
|
||||||
var c4 = "12foobar" + baz();
|
|
||||||
var c5 = [ boo() + bar() + "foo", 1, 2, 3, "bar", bar() + "foo" ].join();
|
|
||||||
var c6 = [ "1,2,,,foo,bar", baz() ].join();
|
|
||||||
var d = "foo-3bar-baz";
|
var d = "foo-3bar-baz";
|
||||||
var e = [].join(foo + bar);
|
var e = [].join(foo + bar);
|
||||||
var f = "";
|
var f = "";
|
||||||
@@ -65,10 +46,9 @@ constant_join: {
|
|||||||
|
|
||||||
constant_join_2: {
|
constant_join_2: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
|
||||||
strings: true,
|
|
||||||
unsafe : true,
|
unsafe : true,
|
||||||
}
|
evaluate : true
|
||||||
|
};
|
||||||
input: {
|
input: {
|
||||||
var a = [ "foo", "bar", boo(), "baz", "x", "y" ].join("");
|
var a = [ "foo", "bar", boo(), "baz", "x", "y" ].join("");
|
||||||
var b = [ "foo", "bar", boo(), "baz", "x", "y" ].join("-");
|
var b = [ "foo", "bar", boo(), "baz", "x", "y" ].join("-");
|
||||||
@@ -92,265 +72,3 @@ constant_join_2: {
|
|||||||
var f = "strstr" + variable + "foobarmoo" + foo;
|
var f = "strstr" + variable + "foobarmoo" + foo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constant_join_3: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
strings: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var foo, bar, baz;
|
|
||||||
var a = [ null ].join();
|
|
||||||
var b = [ , ].join();
|
|
||||||
var c = [ , 1, , 3 ].join();
|
|
||||||
var d = [ foo ].join();
|
|
||||||
var e = [ foo, null, undefined, bar ].join("-");
|
|
||||||
var f = [ foo, bar ].join("");
|
|
||||||
var g = [ null, "foo", null, bar + "baz" ].join("");
|
|
||||||
var h = [ null, "foo", null, bar + "baz" ].join("-");
|
|
||||||
var i = [ "foo" + bar, null, baz + "moo" ].join("");
|
|
||||||
var j = [ foo + "bar", baz ].join("");
|
|
||||||
var k = [ foo, "bar" + baz ].join("");
|
|
||||||
var l = [ foo, bar + "baz" ].join("");
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var foo, bar, baz;
|
|
||||||
var a = "";
|
|
||||||
var b = "";
|
|
||||||
var c = ",1,,3";
|
|
||||||
var d = "" + foo;
|
|
||||||
var e = [ foo, "-", bar ].join("-");
|
|
||||||
var f = "" + foo + bar;
|
|
||||||
var g = "foo" + bar + "baz";
|
|
||||||
var h = [ "-foo-", bar + "baz" ].join("-");
|
|
||||||
var i = "foo" + bar + baz + "moo";
|
|
||||||
var j = foo + "bar" + baz;
|
|
||||||
var k = foo + "bar" + baz;
|
|
||||||
var l = foo + (bar + "baz");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for_loop: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
unsafe: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f0() {
|
|
||||||
var a = [1, 2, 3];
|
|
||||||
var b = 0;
|
|
||||||
for (var i = 0; i < a.length; i++)
|
|
||||||
b += a[i];
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
function f1() {
|
|
||||||
var a = [1, 2, 3];
|
|
||||||
var b = 0;
|
|
||||||
for (var i = 0, len = a.length; i < len; i++)
|
|
||||||
b += a[i];
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
function f2() {
|
|
||||||
var a = [1, 2, 3];
|
|
||||||
for (var i = 0; i < a.length; i++)
|
|
||||||
a[i]++;
|
|
||||||
return a[2];
|
|
||||||
}
|
|
||||||
console.log(f0(), f1(), f2());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f0() {
|
|
||||||
var a = [1, 2, 3];
|
|
||||||
var b = 0;
|
|
||||||
for (var i = 0; i < 3; i++)
|
|
||||||
b += a[i];
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
function f1() {
|
|
||||||
var a = [1, 2, 3];
|
|
||||||
var b = 0;
|
|
||||||
for (var i = 0; i < 3; i++)
|
|
||||||
b += a[i];
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
function f2() {
|
|
||||||
var a = [1, 2, 3];
|
|
||||||
for (var i = 0; i < a.length; i++)
|
|
||||||
a[i]++;
|
|
||||||
return a[2];
|
|
||||||
}
|
|
||||||
console.log(f0(), f1(), f2());
|
|
||||||
}
|
|
||||||
expect_stdout: "6 6 4"
|
|
||||||
}
|
|
||||||
|
|
||||||
index: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
unsafe: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = [ 1, 2 ];
|
|
||||||
console.log(a[0], a[1]);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(1, 2);
|
|
||||||
}
|
|
||||||
expect_stdout: "1 2"
|
|
||||||
}
|
|
||||||
|
|
||||||
length: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
unsafe: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = [ 1, 2 ];
|
|
||||||
console.log(a.length);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(2);
|
|
||||||
}
|
|
||||||
expect_stdout: "2"
|
|
||||||
}
|
|
||||||
|
|
||||||
index_length: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
unsafe: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = [ 1, 2 ];
|
|
||||||
console.log(a[0], a.length);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(1, 2);
|
|
||||||
}
|
|
||||||
expect_stdout: "1 2"
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor_bad: {
|
|
||||||
options = {
|
|
||||||
unsafe: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
try {
|
|
||||||
Array(NaN);
|
|
||||||
console.log("FAIL1");
|
|
||||||
} catch (ex) {
|
|
||||||
try {
|
|
||||||
new Array(NaN);
|
|
||||||
console.log("FAIL2");
|
|
||||||
} catch (ex) {
|
|
||||||
console.log("PASS");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Array(3.14);
|
|
||||||
console.log("FAIL1");
|
|
||||||
} catch (ex) {
|
|
||||||
try {
|
|
||||||
new Array(3.14);
|
|
||||||
console.log("FAIL2");
|
|
||||||
} catch (ex) {
|
|
||||||
console.log("PASS");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
try {
|
|
||||||
Array(NaN);
|
|
||||||
console.log("FAIL1");
|
|
||||||
} catch (ex) {
|
|
||||||
try {
|
|
||||||
Array(NaN);
|
|
||||||
console.log("FAIL2");
|
|
||||||
} catch (ex) {
|
|
||||||
console.log("PASS");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Array(3.14);
|
|
||||||
console.log("FAIL1");
|
|
||||||
} catch (ex) {
|
|
||||||
try {
|
|
||||||
Array(3.14);
|
|
||||||
console.log("FAIL2");
|
|
||||||
} catch (ex) {
|
|
||||||
console.log("PASS");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
]
|
|
||||||
expect_warnings: [
|
|
||||||
"WARN: Invalid array length: 3.14 [test/compress/arrays.js:13,12]",
|
|
||||||
"WARN: Invalid array length: 3.14 [test/compress/arrays.js:17,16]",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor_good: {
|
|
||||||
options = {
|
|
||||||
unsafe: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(Array());
|
|
||||||
console.log(Array(0));
|
|
||||||
console.log(Array(1));
|
|
||||||
console.log(Array(6));
|
|
||||||
console.log(Array(7));
|
|
||||||
console.log(Array(1, 2));
|
|
||||||
console.log(Array(false));
|
|
||||||
console.log(Array("foo"));
|
|
||||||
console.log(Array(Array));
|
|
||||||
console.log(new Array());
|
|
||||||
console.log(new Array(0));
|
|
||||||
console.log(new Array(1));
|
|
||||||
console.log(new Array(6));
|
|
||||||
console.log(new Array(7));
|
|
||||||
console.log(new Array(1, 2));
|
|
||||||
console.log(new Array(false));
|
|
||||||
console.log(new Array("foo"));
|
|
||||||
console.log(new Array(Array));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log([]);
|
|
||||||
console.log([]);
|
|
||||||
console.log([,]);
|
|
||||||
console.log([,,,,,,]);
|
|
||||||
console.log(Array(7));
|
|
||||||
console.log([ 1, 2 ]);
|
|
||||||
console.log([ false ]);
|
|
||||||
console.log([ "foo" ]);
|
|
||||||
console.log(Array(Array));
|
|
||||||
console.log([]);
|
|
||||||
console.log([]);
|
|
||||||
console.log([,]);
|
|
||||||
console.log([,,,,,,]);
|
|
||||||
console.log(Array(7));
|
|
||||||
console.log([ 1, 2 ]);
|
|
||||||
console.log([ false ]);
|
|
||||||
console.log([ "foo" ]);
|
|
||||||
console.log(Array(Array));
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
expect_warnings: []
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
ascii_only_true: {
|
|
||||||
options = {}
|
|
||||||
beautify = {
|
|
||||||
ascii_only : true,
|
|
||||||
ie8 : false,
|
|
||||||
beautify : false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
return "\x000\x001\x007\x008\x00" +
|
|
||||||
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" +
|
|
||||||
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" +
|
|
||||||
"\x20\x21\x22\x23 ... \x7d\x7e\x7f\x80\x81 ... \xfe\xff\u0fff\uffff";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: 'function f(){return"\\x000\\x001\\x007\\x008\\0"+"\\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07\\b\\t\\n\\v\\f\\r\\x0e\\x0f"+"\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17\\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f"+\' !"# ... }~\\x7f\\x80\\x81 ... \\xfe\\xff\\u0fff\\uffff\'}'
|
|
||||||
}
|
|
||||||
|
|
||||||
ascii_only_false: {
|
|
||||||
options = {}
|
|
||||||
beautify = {
|
|
||||||
ascii_only : false,
|
|
||||||
ie8 : false,
|
|
||||||
beautify : false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
return "\x000\x001\x007\x008\x00" +
|
|
||||||
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" +
|
|
||||||
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" +
|
|
||||||
"\x20\x21\x22\x23 ... \x7d\x7e\x7f\x80\x81 ... \xfe\xff\u0fff\uffff";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: 'function f(){return"\\x000\\x001\\x007\\x008\\0"+"\\0\x01\x02\x03\x04\x05\x06\x07\\b\\t\\n\\v\\f\\r\x0e\x0f"+"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"+\' !"# ... }~\x7f\x80\x81 ... \xfe\xff\u0fff\uffff\'}'
|
|
||||||
}
|
|
||||||
@@ -1,233 +0,0 @@
|
|||||||
asm_mixed: {
|
|
||||||
options = {
|
|
||||||
assignments: true,
|
|
||||||
booleans: true,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
drop_debugger: true,
|
|
||||||
evaluate: true,
|
|
||||||
hoist_funs: true,
|
|
||||||
hoist_vars: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
keep_fargs: true,
|
|
||||||
keep_fnames: false,
|
|
||||||
loops: true,
|
|
||||||
negate_iife: true,
|
|
||||||
properties: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
// adapted from http://asmjs.org/spec/latest/
|
|
||||||
function asm_GeometricMean(stdlib, foreign, buffer) {
|
|
||||||
"use asm";
|
|
||||||
var exp = stdlib.Math.exp;
|
|
||||||
var log = stdlib.Math.log;
|
|
||||||
var values = new stdlib.Float64Array(buffer);
|
|
||||||
function logSum(start, end) {
|
|
||||||
start = start|0;
|
|
||||||
end = end|0;
|
|
||||||
var sum = 0.0, p = 0, q = 0;
|
|
||||||
// asm.js forces byte addressing of the heap by requiring shifting by 3
|
|
||||||
for (p = start << 3, q = end << 3; (p|0) < (q|0); p = (p + 8)|0) {
|
|
||||||
sum = sum + +log(values[p>>3]);
|
|
||||||
}
|
|
||||||
return +sum;
|
|
||||||
}
|
|
||||||
function geometricMean(start, end) {
|
|
||||||
start = start|0;
|
|
||||||
end = end|0;
|
|
||||||
return +exp(+logSum(start, end) / +((end - start)|0));
|
|
||||||
}
|
|
||||||
return { geometricMean: geometricMean };
|
|
||||||
}
|
|
||||||
function no_asm_GeometricMean(stdlib, foreign, buffer) {
|
|
||||||
var exp = stdlib.Math.exp;
|
|
||||||
var log = stdlib.Math.log;
|
|
||||||
var values = new stdlib.Float64Array(buffer);
|
|
||||||
function logSum(start, end) {
|
|
||||||
start = start|0;
|
|
||||||
end = end|0;
|
|
||||||
var sum = 0.0, p = 0, q = 0;
|
|
||||||
// asm.js forces byte addressing of the heap by requiring shifting by 3
|
|
||||||
for (p = start << 3, q = end << 3; (p|0) < (q|0); p = (p + 8)|0) {
|
|
||||||
sum = sum + +log(values[p>>3]);
|
|
||||||
}
|
|
||||||
return +sum;
|
|
||||||
}
|
|
||||||
function geometricMean(start, end) {
|
|
||||||
start = start|0;
|
|
||||||
end = end|0;
|
|
||||||
return +exp(+logSum(start, end) / +((end - start)|0));
|
|
||||||
}
|
|
||||||
return { geometricMean: geometricMean };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function asm_GeometricMean(stdlib, foreign, buffer) {
|
|
||||||
"use asm";
|
|
||||||
var exp = stdlib.Math.exp;
|
|
||||||
var log = stdlib.Math.log;
|
|
||||||
var values = new stdlib.Float64Array(buffer);
|
|
||||||
function logSum(start, end) {
|
|
||||||
start = start | 0;
|
|
||||||
end = end | 0;
|
|
||||||
var sum = 0.0, p = 0, q = 0;
|
|
||||||
for (p = start << 3, q = end << 3; (p | 0) < (q | 0); p = p + 8 | 0) {
|
|
||||||
sum = sum + +log(values[p >> 3]);
|
|
||||||
}
|
|
||||||
return +sum;
|
|
||||||
}
|
|
||||||
function geometricMean(start, end) {
|
|
||||||
start = start | 0;
|
|
||||||
end = end | 0;
|
|
||||||
return +exp(+logSum(start, end) / +(end - start | 0));
|
|
||||||
}
|
|
||||||
return { geometricMean: geometricMean };
|
|
||||||
}
|
|
||||||
function no_asm_GeometricMean(stdlib, foreign, buffer) {
|
|
||||||
function logSum(start, end) {
|
|
||||||
start |= 0, end |= 0;
|
|
||||||
for (var sum = 0, p = 0, q = 0, p = start << 3, q = end << 3; (0 | p) < (0 | q); p = p + 8 | 0) sum += +log(values[p >> 3]);
|
|
||||||
return +sum;
|
|
||||||
}
|
|
||||||
function geometricMean(start, end) {
|
|
||||||
return start |= 0, end |= 0, +exp(+logSum(start, end) / (end - start | 0));
|
|
||||||
}
|
|
||||||
var exp = stdlib.Math.exp, log = stdlib.Math.log, values = new stdlib.Float64Array(buffer);
|
|
||||||
return { geometricMean: geometricMean };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
asm_toplevel: {
|
|
||||||
options = {}
|
|
||||||
input: {
|
|
||||||
"use asm";
|
|
||||||
0.0;
|
|
||||||
function f() {
|
|
||||||
0.0;
|
|
||||||
(function(){
|
|
||||||
0.0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
0.0;
|
|
||||||
}
|
|
||||||
expect_exact: '"use asm";0.0;function f(){0.0;(function(){0.0})}0.0;'
|
|
||||||
}
|
|
||||||
|
|
||||||
asm_function_expression: {
|
|
||||||
options = {}
|
|
||||||
input: {
|
|
||||||
0.0;
|
|
||||||
var a = function() {
|
|
||||||
"use asm";
|
|
||||||
0.0;
|
|
||||||
}
|
|
||||||
function f() {
|
|
||||||
0.0;
|
|
||||||
return function(){
|
|
||||||
"use asm";
|
|
||||||
0.0;
|
|
||||||
}
|
|
||||||
0.0;
|
|
||||||
}
|
|
||||||
0.0;
|
|
||||||
}
|
|
||||||
expect_exact: '0;var a=function(){"use asm";0.0};function f(){0;return function(){"use asm";0.0};0}0;'
|
|
||||||
}
|
|
||||||
|
|
||||||
asm_nested_functions: {
|
|
||||||
options = {}
|
|
||||||
input: {
|
|
||||||
0.0;
|
|
||||||
function a() {
|
|
||||||
"use asm";
|
|
||||||
0.0;
|
|
||||||
}
|
|
||||||
0.0;
|
|
||||||
function b() {
|
|
||||||
0.0;
|
|
||||||
function c(){
|
|
||||||
"use asm";
|
|
||||||
0.0;
|
|
||||||
}
|
|
||||||
0.0;
|
|
||||||
function d(){
|
|
||||||
0.0;
|
|
||||||
}
|
|
||||||
0.0;
|
|
||||||
}
|
|
||||||
0.0;
|
|
||||||
}
|
|
||||||
expect_exact: '0;function a(){"use asm";0.0}0;function b(){0;function c(){"use asm";0.0}0;function d(){0}0}0;'
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3636_1: {
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
function n(stdlib, foreign, buffer) {
|
|
||||||
"use asm";
|
|
||||||
function add(x, y) {
|
|
||||||
x = x | 0;
|
|
||||||
y = y | 0;
|
|
||||||
return x + y | 0;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
add: add
|
|
||||||
};
|
|
||||||
}
|
|
||||||
console.log(new n().add("foo", 42));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function n(o, e, u) {
|
|
||||||
"use asm";
|
|
||||||
function d(n, o) {
|
|
||||||
n = n | 0;
|
|
||||||
o = o | 0;
|
|
||||||
return n + o | 0;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
add: d
|
|
||||||
};
|
|
||||||
}
|
|
||||||
console.log(new n().add("foo", 42));
|
|
||||||
}
|
|
||||||
expect_stdout: "42"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3636_2: {
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
var n = function(stdlib, foreign, buffer) {
|
|
||||||
"use asm";
|
|
||||||
function add(x, y) {
|
|
||||||
x = x | 0;
|
|
||||||
y = y | 0;
|
|
||||||
return x + y | 0;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
add: add
|
|
||||||
};
|
|
||||||
};
|
|
||||||
console.log(new n().add("foo", 42));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var n = function(n, o, e) {
|
|
||||||
"use asm";
|
|
||||||
function r(n, o) {
|
|
||||||
n = n | 0;
|
|
||||||
o = o | 0;
|
|
||||||
return n + o | 0;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
add: r
|
|
||||||
};
|
|
||||||
};
|
|
||||||
console.log(new n().add("foo", 42));
|
|
||||||
}
|
|
||||||
expect_stdout: "42"
|
|
||||||
}
|
|
||||||
@@ -1,463 +0,0 @@
|
|||||||
op_equals_left_local_var: {
|
|
||||||
options = {
|
|
||||||
assignments: true,
|
|
||||||
evaluate: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var x;
|
|
||||||
|
|
||||||
x = x + 3;
|
|
||||||
x = x - 3;
|
|
||||||
x = x / 3;
|
|
||||||
x = x * 3;
|
|
||||||
x = x >> 3;
|
|
||||||
x = x << 3;
|
|
||||||
x = x >>> 3;
|
|
||||||
x = x | 3;
|
|
||||||
x = x ^ 3;
|
|
||||||
x = x % 3;
|
|
||||||
x = x & 3;
|
|
||||||
|
|
||||||
x = x + g();
|
|
||||||
x = x - g();
|
|
||||||
x = x / g();
|
|
||||||
x = x * g();
|
|
||||||
x = x >> g();
|
|
||||||
x = x << g();
|
|
||||||
x = x >>> g();
|
|
||||||
x = x | g();
|
|
||||||
x = x ^ g();
|
|
||||||
x = x % g();
|
|
||||||
x = x & g();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var x;
|
|
||||||
|
|
||||||
x += 3;
|
|
||||||
x -= 3;
|
|
||||||
x /= 3;
|
|
||||||
x *= 3;
|
|
||||||
x >>= 3;
|
|
||||||
x <<= 3;
|
|
||||||
x >>>= 3;
|
|
||||||
x |= 3;
|
|
||||||
x ^= 3;
|
|
||||||
x %= 3;
|
|
||||||
x &= 3;
|
|
||||||
|
|
||||||
x += g();
|
|
||||||
x -= g();
|
|
||||||
x /= g();
|
|
||||||
x *= g();
|
|
||||||
x >>= g();
|
|
||||||
x <<= g();
|
|
||||||
x >>>= g();
|
|
||||||
x |= g();
|
|
||||||
x ^= g();
|
|
||||||
x %= g();
|
|
||||||
x &= g();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
op_equals_right_local_var: {
|
|
||||||
options = {
|
|
||||||
assignments: true,
|
|
||||||
evaluate: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var x;
|
|
||||||
|
|
||||||
x = (x -= 2) ^ x;
|
|
||||||
|
|
||||||
x = 3 + x;
|
|
||||||
x = 3 - x;
|
|
||||||
x = 3 / x;
|
|
||||||
x = 3 * x;
|
|
||||||
x = 3 >> x;
|
|
||||||
x = 3 << x;
|
|
||||||
x = 3 >>> x;
|
|
||||||
x = 3 | x;
|
|
||||||
x = 3 ^ x;
|
|
||||||
x = 3 % x;
|
|
||||||
x = 3 & x;
|
|
||||||
|
|
||||||
x = g() + x;
|
|
||||||
x = g() - x;
|
|
||||||
x = g() / x;
|
|
||||||
x = g() * x;
|
|
||||||
x = g() >> x;
|
|
||||||
x = g() << x;
|
|
||||||
x = g() >>> x;
|
|
||||||
x = g() | x;
|
|
||||||
x = g() ^ x;
|
|
||||||
x = g() % x;
|
|
||||||
x = g() & x;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var x;
|
|
||||||
|
|
||||||
x = (x -= 2) ^ x;
|
|
||||||
|
|
||||||
x = 3 + x;
|
|
||||||
x = 3 - x;
|
|
||||||
x = 3 / x;
|
|
||||||
x *= 3;
|
|
||||||
x = 3 >> x;
|
|
||||||
x = 3 << x;
|
|
||||||
x = 3 >>> x;
|
|
||||||
x |= 3;
|
|
||||||
x ^= 3;
|
|
||||||
x = 3 % x;
|
|
||||||
x &= 3;
|
|
||||||
|
|
||||||
x = g() + x;
|
|
||||||
x = g() - x;
|
|
||||||
x = g() / x;
|
|
||||||
x = g() * x;
|
|
||||||
x = g() >> x;
|
|
||||||
x = g() << x;
|
|
||||||
x = g() >>> x;
|
|
||||||
x = g() | x;
|
|
||||||
x = g() ^ x;
|
|
||||||
x = g() % x;
|
|
||||||
x = g() & x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
op_equals_left_global_var: {
|
|
||||||
options = {
|
|
||||||
assignments: true,
|
|
||||||
evaluate: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
x = x + 3;
|
|
||||||
x = x - 3;
|
|
||||||
x = x / 3;
|
|
||||||
x = x * 3;
|
|
||||||
x = x >> 3;
|
|
||||||
x = x << 3;
|
|
||||||
x = x >>> 3;
|
|
||||||
x = x | 3;
|
|
||||||
x = x ^ 3;
|
|
||||||
x = x % 3;
|
|
||||||
x = x & 3;
|
|
||||||
|
|
||||||
x = x + g();
|
|
||||||
x = x - g();
|
|
||||||
x = x / g();
|
|
||||||
x = x * g();
|
|
||||||
x = x >> g();
|
|
||||||
x = x << g();
|
|
||||||
x = x >>> g();
|
|
||||||
x = x | g();
|
|
||||||
x = x ^ g();
|
|
||||||
x = x % g();
|
|
||||||
x = x & g();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
x += 3;
|
|
||||||
x -= 3;
|
|
||||||
x /= 3;
|
|
||||||
x *= 3;
|
|
||||||
x >>= 3;
|
|
||||||
x <<= 3;
|
|
||||||
x >>>= 3;
|
|
||||||
x |= 3;
|
|
||||||
x ^= 3;
|
|
||||||
x %= 3;
|
|
||||||
x &= 3;
|
|
||||||
|
|
||||||
x += g();
|
|
||||||
x -= g();
|
|
||||||
x /= g();
|
|
||||||
x *= g();
|
|
||||||
x >>= g();
|
|
||||||
x <<= g();
|
|
||||||
x >>>= g();
|
|
||||||
x |= g();
|
|
||||||
x ^= g();
|
|
||||||
x %= g();
|
|
||||||
x &= g();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
op_equals_right_global_var: {
|
|
||||||
options = {
|
|
||||||
assignments: true,
|
|
||||||
evaluate: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
x = (x -= 2) ^ x;
|
|
||||||
|
|
||||||
x = 3 + x;
|
|
||||||
x = 3 - x;
|
|
||||||
x = 3 / x;
|
|
||||||
x = 3 * x;
|
|
||||||
x = 3 >> x;
|
|
||||||
x = 3 << x;
|
|
||||||
x = 3 >>> x;
|
|
||||||
x = 3 | x;
|
|
||||||
x = 3 ^ x;
|
|
||||||
x = 3 % x;
|
|
||||||
x = 3 & x;
|
|
||||||
|
|
||||||
x = g() + x;
|
|
||||||
x = g() - x;
|
|
||||||
x = g() / x;
|
|
||||||
x = g() * x;
|
|
||||||
x = g() >> x;
|
|
||||||
x = g() << x;
|
|
||||||
x = g() >>> x;
|
|
||||||
x = g() | x;
|
|
||||||
x = g() ^ x;
|
|
||||||
x = g() % x;
|
|
||||||
x = g() & x;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
x = (x -= 2) ^ x;
|
|
||||||
|
|
||||||
x = 3 + x;
|
|
||||||
x = 3 - x;
|
|
||||||
x = 3 / x;
|
|
||||||
x *= 3;
|
|
||||||
x = 3 >> x;
|
|
||||||
x = 3 << x;
|
|
||||||
x = 3 >>> x;
|
|
||||||
x |= 3;
|
|
||||||
x ^= 3;
|
|
||||||
x = 3 % x;
|
|
||||||
x &= 3;
|
|
||||||
|
|
||||||
x = g() + x;
|
|
||||||
x = g() - x;
|
|
||||||
x = g() / x;
|
|
||||||
x = g() * x;
|
|
||||||
x = g() >> x;
|
|
||||||
x = g() << x;
|
|
||||||
x = g() >>> x;
|
|
||||||
x = g() | x;
|
|
||||||
x = g() ^ x;
|
|
||||||
x = g() % x;
|
|
||||||
x = g() & x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
increment_decrement_1: {
|
|
||||||
options = {
|
|
||||||
assignments: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function(a) {
|
|
||||||
a += 1;
|
|
||||||
a -= 1;
|
|
||||||
return a;
|
|
||||||
}(42));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(function(a){
|
|
||||||
++a;
|
|
||||||
--a;
|
|
||||||
return a;
|
|
||||||
}(42));
|
|
||||||
}
|
|
||||||
expect_stdout: "42"
|
|
||||||
}
|
|
||||||
|
|
||||||
increment_decrement_2: {
|
|
||||||
options = {
|
|
||||||
assignments: true,
|
|
||||||
passes: 2,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function(a) {
|
|
||||||
a = a + 1;
|
|
||||||
a = a - 1;
|
|
||||||
a += 1;
|
|
||||||
a -= 1;
|
|
||||||
return a;
|
|
||||||
}(42));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(function(a){
|
|
||||||
++a;
|
|
||||||
--a;
|
|
||||||
++a;
|
|
||||||
--a;
|
|
||||||
return a;
|
|
||||||
}(42));
|
|
||||||
}
|
|
||||||
expect_stdout: "42"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3375_1: {
|
|
||||||
options = {
|
|
||||||
assignments: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function p(o) {
|
|
||||||
console.log(typeof o, o);
|
|
||||||
}
|
|
||||||
p(function(b) {
|
|
||||||
var a = b += 1;
|
|
||||||
--b;
|
|
||||||
return a;
|
|
||||||
}("object"));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function p(o) {
|
|
||||||
console.log(typeof o, o);
|
|
||||||
}
|
|
||||||
p(function(b) {
|
|
||||||
var a = b += 1;
|
|
||||||
--b;
|
|
||||||
return a;
|
|
||||||
}("object"));
|
|
||||||
}
|
|
||||||
expect_stdout: "string object1"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3375_2: {
|
|
||||||
options = {
|
|
||||||
assignments: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function p(o) {
|
|
||||||
console.log(typeof o, o);
|
|
||||||
}
|
|
||||||
p(function(b) {
|
|
||||||
var a = b -= 1;
|
|
||||||
--b;
|
|
||||||
return a;
|
|
||||||
}("object"));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function p(o) {
|
|
||||||
console.log(typeof o, o);
|
|
||||||
}
|
|
||||||
p(function(b) {
|
|
||||||
var a = --b;
|
|
||||||
--b;
|
|
||||||
return a;
|
|
||||||
}("object"));
|
|
||||||
}
|
|
||||||
expect_stdout: "number NaN"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3427: {
|
|
||||||
options = {
|
|
||||||
assignments: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
var a;
|
|
||||||
a || (a = {});
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3429_1: {
|
|
||||||
options = {
|
|
||||||
assignments: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = "PASS";
|
|
||||||
(function(b) {
|
|
||||||
b && (b = a = "FAIL");
|
|
||||||
})();
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = "PASS";
|
|
||||||
(function(b) {
|
|
||||||
b = b && (a = "FAIL");
|
|
||||||
})();
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3429_2: {
|
|
||||||
options = {
|
|
||||||
assignments: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a;
|
|
||||||
(function(b) {
|
|
||||||
b || (b = a = "FAIL");
|
|
||||||
})(42);
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a;
|
|
||||||
(function(b) {
|
|
||||||
b = b || (a = "FAIL");
|
|
||||||
})(42);
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_stdout: "undefined"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3949_1: {
|
|
||||||
options = {
|
|
||||||
assignments: true,
|
|
||||||
evaluate: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = 42;
|
|
||||||
function f() {
|
|
||||||
var b = a;
|
|
||||||
b = b >> 2;
|
|
||||||
return 100 + b;
|
|
||||||
}
|
|
||||||
console.log(f());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = 42;
|
|
||||||
function f() {
|
|
||||||
var b = a;
|
|
||||||
b >>= 2;
|
|
||||||
return 100 + b;
|
|
||||||
}
|
|
||||||
console.log(f());
|
|
||||||
}
|
|
||||||
expect_stdout: "110"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3949_2: {
|
|
||||||
options = {
|
|
||||||
assignments: true,
|
|
||||||
evaluate: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = 42;
|
|
||||||
function f() {
|
|
||||||
var b = a;
|
|
||||||
b = 5 & b;
|
|
||||||
return 100 + b;
|
|
||||||
}
|
|
||||||
console.log(f());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = 42;
|
|
||||||
function f() {
|
|
||||||
var b = a;
|
|
||||||
b &= 5;
|
|
||||||
return 100 + b;
|
|
||||||
}
|
|
||||||
console.log(f());
|
|
||||||
}
|
|
||||||
expect_stdout: "100"
|
|
||||||
}
|
|
||||||
@@ -1,155 +0,0 @@
|
|||||||
iife_boolean_context: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
evaluate: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function() {
|
|
||||||
return Object(1) || false;
|
|
||||||
}() ? "PASS" : "FAIL");
|
|
||||||
console.log(function() {
|
|
||||||
return [].length || true;
|
|
||||||
}() ? "PASS" : "FAIL");
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(function() {
|
|
||||||
return Object(1);
|
|
||||||
}() ? "PASS" : "FAIL");
|
|
||||||
console.log(function() {
|
|
||||||
return [].length, 1;
|
|
||||||
}() ? "PASS" : "FAIL");
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
]
|
|
||||||
expect_warnings: [
|
|
||||||
"WARN: Dropping side-effect-free || [test/compress/booleans.js:2,19]",
|
|
||||||
"WARN: Boolean || always true [test/compress/booleans.js:5,19]",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3465_1: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function(a) {
|
|
||||||
return typeof a;
|
|
||||||
}() ? "PASS" : "FAIL");
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(function(a) {
|
|
||||||
return 1;
|
|
||||||
}() ? "PASS" : "FAIL");
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3465_2: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function f(a) {
|
|
||||||
if (!a) console.log(f(42));
|
|
||||||
return typeof a;
|
|
||||||
}() ? "PASS" : "FAIL");
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(function f(a) {
|
|
||||||
if (!a) console.log(f(42));
|
|
||||||
return typeof a;
|
|
||||||
}() ? "PASS" : "FAIL");
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"number",
|
|
||||||
"PASS",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3465_3: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
passes: 2,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function f(a) {
|
|
||||||
return typeof a;
|
|
||||||
}() ? "PASS" : "FAIL");
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(function(a) {
|
|
||||||
return 1;
|
|
||||||
}() ? "PASS" : "FAIL");
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2737_2: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
inline: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(bar) {
|
|
||||||
for (;bar();) break;
|
|
||||||
})(function qux() {
|
|
||||||
return console.log("PASS"), qux;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(bar) {
|
|
||||||
for (;bar();) break;
|
|
||||||
})(function() {
|
|
||||||
return console.log("PASS"), 1;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3658: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
evaluate: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function f() {
|
|
||||||
console || f();
|
|
||||||
return "PASS";
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(function f() {
|
|
||||||
console || f();
|
|
||||||
return "PASS";
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3690: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function(a) {
|
|
||||||
return function() {
|
|
||||||
return a = [ this ];
|
|
||||||
}() ? "PASS" : "FAIL";
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(function(a) {
|
|
||||||
return function() {
|
|
||||||
return 1;
|
|
||||||
}() ? "PASS" : "FAIL";
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,495 +0,0 @@
|
|||||||
comparisons: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var obj1, obj2;
|
|
||||||
var result1 = obj1 <= obj2;
|
|
||||||
var result2 = obj1 < obj2;
|
|
||||||
var result3 = obj1 >= obj2;
|
|
||||||
var result4 = obj1 > obj2;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var obj1, obj2;
|
|
||||||
var result1 = obj1 <= obj2;
|
|
||||||
var result2 = obj1 < obj2;
|
|
||||||
var result3 = obj2 <= obj1;
|
|
||||||
var result4 = obj2 < obj1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe_comps: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
unsafe_comps: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var obj1, obj2;
|
|
||||||
obj1 <= obj2 ? f1() : g1();
|
|
||||||
obj1 < obj2 ? f2() : g2();
|
|
||||||
obj1 >= obj2 ? f3() : g3();
|
|
||||||
obj1 > obj2 ? f4() : g4();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var obj1, obj2;
|
|
||||||
(obj2 < obj1 ? g1 : f1)();
|
|
||||||
(obj1 < obj2 ? f2 : g2)();
|
|
||||||
(obj1 < obj2 ? g3 : f3)();
|
|
||||||
(obj2 < obj1 ? f4 : g4)();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dont_change_in_or_instanceof_expressions: {
|
|
||||||
input: {
|
|
||||||
1 in 1;
|
|
||||||
null in null;
|
|
||||||
1 instanceof 1;
|
|
||||||
null instanceof null;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
1 in 1;
|
|
||||||
null in null;
|
|
||||||
1 instanceof 1;
|
|
||||||
null instanceof null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self_comparison_1: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
a === a;
|
|
||||||
a !== b;
|
|
||||||
b.c === a.c;
|
|
||||||
b.c !== b.c;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
a == a;
|
|
||||||
a !== b;
|
|
||||||
b.c === a.c;
|
|
||||||
b.c != b.c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self_comparison_2: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {}
|
|
||||||
var o = {};
|
|
||||||
console.log(f != f, o === o);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f() {}
|
|
||||||
var o = {};
|
|
||||||
console.log(false, true);
|
|
||||||
}
|
|
||||||
expect_stdout: "false true"
|
|
||||||
}
|
|
||||||
|
|
||||||
self_comparison_3: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a;
|
|
||||||
function f() {
|
|
||||||
var b = a;
|
|
||||||
a = null;
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
for (var i = 0; i < 2; i++)
|
|
||||||
console.log(f() === f());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a;
|
|
||||||
function f() {
|
|
||||||
var b = a;
|
|
||||||
a = null;
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
for (var i = 0; i < 2; i++)
|
|
||||||
console.log(f() === f());
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"false",
|
|
||||||
"true",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
self_comparison_4: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
comparisons: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = {};
|
|
||||||
console.log(o == o, o != o);
|
|
||||||
console.log(o === o, o !== o);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(!0, !1);
|
|
||||||
console.log(!0, !1);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"true false",
|
|
||||||
"true false",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2857_1: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f1(a) {
|
|
||||||
a === undefined || a === null;
|
|
||||||
a === undefined || a !== null;
|
|
||||||
a !== undefined || a === null;
|
|
||||||
a !== undefined || a !== null;
|
|
||||||
a === undefined && a === null;
|
|
||||||
a === undefined && a !== null;
|
|
||||||
a !== undefined && a === null;
|
|
||||||
a !== undefined && a !== null;
|
|
||||||
}
|
|
||||||
function f2(a) {
|
|
||||||
a === null || a === undefined;
|
|
||||||
a === null || a !== undefined;
|
|
||||||
a !== null || a === undefined;
|
|
||||||
a !== null || a !== undefined;
|
|
||||||
a === null && a === undefined;
|
|
||||||
a === null && a !== undefined;
|
|
||||||
a !== null && a === undefined;
|
|
||||||
a !== null && a !== undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f1(a) {
|
|
||||||
null == a;
|
|
||||||
void 0 === a || null !== a;
|
|
||||||
void 0 !== a || null === a;
|
|
||||||
void 0 !== a || null !== a;
|
|
||||||
void 0 === a && null === a;
|
|
||||||
void 0 === a && null !== a;
|
|
||||||
void 0 !== a && null === a;
|
|
||||||
null != a;
|
|
||||||
}
|
|
||||||
function f2(a) {
|
|
||||||
null == a;
|
|
||||||
null === a || void 0 !== a;
|
|
||||||
null !== a || void 0 === a;
|
|
||||||
null !== a || void 0 !== a;
|
|
||||||
null === a && void 0 === a;
|
|
||||||
null === a && void 0 !== a;
|
|
||||||
null !== a && void 0 === a;
|
|
||||||
null != a;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2857_2: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(a, p) {
|
|
||||||
a === undefined || a === null || p;
|
|
||||||
a === undefined || a !== null || p;
|
|
||||||
a !== undefined || a === null || p;
|
|
||||||
a !== undefined || a !== null || p;
|
|
||||||
a === undefined && a === null || p;
|
|
||||||
a === undefined && a !== null || p;
|
|
||||||
a !== undefined && a === null || p;
|
|
||||||
a !== undefined && a !== null || p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(a, p) {
|
|
||||||
null == a || p;
|
|
||||||
void 0 === a || null !== a || p;
|
|
||||||
void 0 !== a || null === a || p;
|
|
||||||
void 0 !== a || null !== a || p;
|
|
||||||
void 0 === a && null === a || p;
|
|
||||||
void 0 === a && null !== a || p;
|
|
||||||
void 0 !== a && null === a || p;
|
|
||||||
null != a || p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2857_3: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(a, p) {
|
|
||||||
a === undefined || a === null && p;
|
|
||||||
a === undefined || a !== null && p;
|
|
||||||
a !== undefined || a === null && p;
|
|
||||||
a !== undefined || a !== null && p;
|
|
||||||
a === undefined && a === null && p;
|
|
||||||
a === undefined && a !== null && p;
|
|
||||||
a !== undefined && a === null && p;
|
|
||||||
a !== undefined && a !== null && p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(a, p) {
|
|
||||||
void 0 === a || null === a && p;
|
|
||||||
void 0 === a || null !== a && p;
|
|
||||||
void 0 !== a || null === a && p;
|
|
||||||
void 0 !== a || null !== a && p;
|
|
||||||
void 0 === a && null === a && p;
|
|
||||||
void 0 === a && null !== a && p;
|
|
||||||
void 0 !== a && null === a && p;
|
|
||||||
null != a && p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2857_4: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(a, p) {
|
|
||||||
p || a === undefined || a === null;
|
|
||||||
p || a === undefined || a !== null;
|
|
||||||
p || a !== undefined || a === null;
|
|
||||||
p || a !== undefined || a !== null;
|
|
||||||
p || a === undefined && a === null;
|
|
||||||
p || a === undefined && a !== null;
|
|
||||||
p || a !== undefined && a === null;
|
|
||||||
p || a !== undefined && a !== null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(a, p) {
|
|
||||||
p || null == a;
|
|
||||||
p || void 0 === a || null !== a;
|
|
||||||
p || void 0 !== a || null === a;
|
|
||||||
p || void 0 !== a || null !== a;
|
|
||||||
p || void 0 === a && null === a;
|
|
||||||
p || void 0 === a && null !== a;
|
|
||||||
p || void 0 !== a && null === a;
|
|
||||||
p || null != a;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2857_5: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(a, p) {
|
|
||||||
p && a === undefined || a === null;
|
|
||||||
p && a === undefined || a !== null;
|
|
||||||
p && a !== undefined || a === null;
|
|
||||||
p && a !== undefined || a !== null;
|
|
||||||
p && a === undefined && a === null;
|
|
||||||
p && a === undefined && a !== null;
|
|
||||||
p && a !== undefined && a === null;
|
|
||||||
p && a !== undefined && a !== null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(a, p) {
|
|
||||||
p && void 0 === a || null === a;
|
|
||||||
p && void 0 === a || null !== a;
|
|
||||||
p && void 0 !== a || null === a;
|
|
||||||
p && void 0 !== a || null !== a;
|
|
||||||
p && void 0 === a && null === a;
|
|
||||||
p && void 0 === a && null !== a;
|
|
||||||
p && void 0 !== a && null === a;
|
|
||||||
p && null != a;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2857_6: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
pure_getters: "strict",
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(a) {
|
|
||||||
if (({}).b === undefined || {}.b === null)
|
|
||||||
return a.b !== undefined && a.b !== null;
|
|
||||||
}
|
|
||||||
console.log(f({
|
|
||||||
a: [ null ],
|
|
||||||
get b() {
|
|
||||||
return this.a.shift();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(a) {
|
|
||||||
if (null == {}.b)
|
|
||||||
return void 0 !== a.b && null !== a.b;
|
|
||||||
}
|
|
||||||
console.log(f({
|
|
||||||
a: [ null ],
|
|
||||||
get b() {
|
|
||||||
return this.a.shift();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
expect_stdout: "true"
|
|
||||||
}
|
|
||||||
|
|
||||||
is_boolean_unsafe: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(/foo/.test("bar") === [].isPrototypeOf({}));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(/foo/.test("bar") == [].isPrototypeOf({}));
|
|
||||||
}
|
|
||||||
expect_stdout: "true"
|
|
||||||
}
|
|
||||||
|
|
||||||
is_number_unsafe: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(Math.acos(42) !== "foo".charCodeAt(4));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(Math.acos(42) != "foo".charCodeAt(4));
|
|
||||||
}
|
|
||||||
expect_stdout: "true"
|
|
||||||
}
|
|
||||||
|
|
||||||
is_boolean_var: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function(a, b) {
|
|
||||||
for (var i = 0, c = !b; i < a.length; i++)
|
|
||||||
if (!a[i] === c)
|
|
||||||
return i;
|
|
||||||
}([ false, true ], 42));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(function(a, b) {
|
|
||||||
for (var i = 0, c = !b; i < a.length; i++)
|
|
||||||
if (!a[i] == c)
|
|
||||||
return i;
|
|
||||||
}([ false, true ], 42));
|
|
||||||
}
|
|
||||||
expect_stdout: "1"
|
|
||||||
}
|
|
||||||
|
|
||||||
is_defined: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function a() {
|
|
||||||
return void 0 === a;
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(function a() {
|
|
||||||
return a, false;
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect_stdout: "false"
|
|
||||||
expect_warnings: [
|
|
||||||
"WARN: Expression always defined [test/compress/comparisons.js:2,19]",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe_indexOf: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
comparisons: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = Object.keys({ foo: 42 });
|
|
||||||
if (a.indexOf("bar") < 0) console.log("PASS");
|
|
||||||
if (0 > a.indexOf("bar")) console.log("PASS");
|
|
||||||
if (a.indexOf("foo") >= 0) console.log("PASS");
|
|
||||||
if (0 <= a.indexOf("foo")) console.log("PASS");
|
|
||||||
if (a.indexOf("foo") > -1) console.log("PASS");
|
|
||||||
if (-1 < a.indexOf("foo")) console.log("PASS");
|
|
||||||
if (a.indexOf("bar") == -1) console.log("PASS");
|
|
||||||
if (-1 == a.indexOf("bar")) console.log("PASS");
|
|
||||||
if (a.indexOf("bar") === -1) console.log("PASS");
|
|
||||||
if (-1 === a.indexOf("bar")) console.log("PASS");
|
|
||||||
if (a.indexOf("foo") != -1) console.log("PASS");
|
|
||||||
if (-1 != a.indexOf("foo")) console.log("PASS");
|
|
||||||
if (a.indexOf("foo") !== -1) console.log("PASS");
|
|
||||||
if (-1 !== a.indexOf("foo")) console.log("PASS");
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = Object.keys({ foo: 42 });
|
|
||||||
if (!~a.indexOf("bar")) console.log("PASS");
|
|
||||||
if (!~a.indexOf("bar")) console.log("PASS");
|
|
||||||
if (~a.indexOf("foo")) console.log("PASS");
|
|
||||||
if (~a.indexOf("foo")) console.log("PASS");
|
|
||||||
if (~a.indexOf("foo")) console.log("PASS");
|
|
||||||
if (~a.indexOf("foo")) console.log("PASS");
|
|
||||||
if (!~a.indexOf("bar")) console.log("PASS");
|
|
||||||
if (!~a.indexOf("bar")) console.log("PASS");
|
|
||||||
if (!~a.indexOf("bar")) console.log("PASS");
|
|
||||||
if (!~a.indexOf("bar")) console.log("PASS");
|
|
||||||
if (~a.indexOf("foo")) console.log("PASS");
|
|
||||||
if (~a.indexOf("foo")) console.log("PASS");
|
|
||||||
if (~a.indexOf("foo")) console.log("PASS");
|
|
||||||
if (~a.indexOf("foo")) console.log("PASS");
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
"PASS",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3413: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
evaluate: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var b;
|
|
||||||
void 0 !== ("" < b || void 0) || console.log("PASS");
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var b;
|
|
||||||
void 0 !== ("" < b || void 0) || console.log("PASS");
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
concat_1: {
|
concat_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true
|
||||||
}
|
};
|
||||||
input: {
|
input: {
|
||||||
var a = "foo" + "bar" + x() + "moo" + "foo" + y() + "x" + "y" + "z" + q();
|
var a = "foo" + "bar" + x() + "moo" + "foo" + y() + "x" + "y" + "z" + q();
|
||||||
var b = "foo" + 1 + x() + 2 + "boo";
|
var b = "foo" + 1 + x() + 2 + "boo";
|
||||||
@@ -11,9 +11,6 @@ concat_1: {
|
|||||||
var d = 1 + x() + 2 + 3 + "boo";
|
var d = 1 + x() + 2 + 3 + "boo";
|
||||||
|
|
||||||
var e = 1 + x() + 2 + "X" + 3 + "boo";
|
var e = 1 + x() + 2 + "X" + 3 + "boo";
|
||||||
|
|
||||||
// be careful with concatentation with "\0" with octal-looking strings.
|
|
||||||
var f = "\0" + 360 + "\0" + 8 + "\0";
|
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var a = "foobar" + x() + "moofoo" + y() + "xyz" + q();
|
var a = "foobar" + x() + "moofoo" + y() + "xyz" + q();
|
||||||
@@ -21,271 +18,5 @@ concat_1: {
|
|||||||
var c = 1 + x() + 2 + "boo";
|
var c = 1 + x() + 2 + "boo";
|
||||||
var d = 1 + x() + 2 + 3 + "boo";
|
var d = 1 + x() + 2 + 3 + "boo";
|
||||||
var e = 1 + x() + 2 + "X3boo";
|
var e = 1 + x() + 2 + "X3boo";
|
||||||
var f = "\x00360\x008\0";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
concat_2: {
|
|
||||||
options = {
|
|
||||||
strings: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(
|
|
||||||
1 + (2 + 3),
|
|
||||||
1 + (2 + "3"),
|
|
||||||
1 + ("2" + 3),
|
|
||||||
1 + ("2" + "3"),
|
|
||||||
"1" + (2 + 3),
|
|
||||||
"1" + (2 + "3"),
|
|
||||||
"1" + ("2" + 3),
|
|
||||||
"1" + ("2" + "3")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(
|
|
||||||
1 + (2 + 3),
|
|
||||||
1 + (2 + "3"),
|
|
||||||
1 + "2" + 3,
|
|
||||||
1 + "2" + "3",
|
|
||||||
"1" + (2 + 3),
|
|
||||||
"1" + 2 + "3",
|
|
||||||
"1" + "2" + 3,
|
|
||||||
"1" + "2" + "3"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
concat_3: {
|
|
||||||
options = {
|
|
||||||
strings: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(
|
|
||||||
1 + 2 + (3 + 4 + 5),
|
|
||||||
1 + 2 + (3 + 4 + "5"),
|
|
||||||
1 + 2 + (3 + "4" + 5),
|
|
||||||
1 + 2 + (3 + "4" + "5"),
|
|
||||||
1 + 2 + ("3" + 4 + 5),
|
|
||||||
1 + 2 + ("3" + 4 + "5"),
|
|
||||||
1 + 2 + ("3" + "4" + 5),
|
|
||||||
1 + 2 + ("3" + "4" + "5")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(
|
|
||||||
1 + 2 + (3 + 4 + 5),
|
|
||||||
1 + 2 + (3 + 4 + "5"),
|
|
||||||
1 + 2 + (3 + "4") + 5,
|
|
||||||
1 + 2 + (3 + "4") + "5",
|
|
||||||
1 + 2 + "3" + 4 + 5,
|
|
||||||
1 + 2 + "3" + 4 + "5",
|
|
||||||
1 + 2 + "3" + "4" + 5,
|
|
||||||
1 + 2 + "3" + "4" + "5"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
concat_4: {
|
|
||||||
options = {
|
|
||||||
strings: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(
|
|
||||||
1 + "2" + (3 + 4 + 5),
|
|
||||||
1 + "2" + (3 + 4 + "5"),
|
|
||||||
1 + "2" + (3 + "4" + 5),
|
|
||||||
1 + "2" + (3 + "4" + "5"),
|
|
||||||
1 + "2" + ("3" + 4 + 5),
|
|
||||||
1 + "2" + ("3" + 4 + "5"),
|
|
||||||
1 + "2" + ("3" + "4" + 5),
|
|
||||||
1 + "2" + ("3" + "4" + "5")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(
|
|
||||||
1 + "2" + (3 + 4 + 5),
|
|
||||||
1 + "2" + (3 + 4) + "5",
|
|
||||||
1 + "2" + 3 + "4" + 5,
|
|
||||||
1 + "2" + 3 + "4" + "5",
|
|
||||||
1 + "2" + "3" + 4 + 5,
|
|
||||||
1 + "2" + "3" + 4 + "5",
|
|
||||||
1 + "2" + "3" + "4" + 5,
|
|
||||||
1 + "2" + "3" + "4" + "5"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
concat_5: {
|
|
||||||
options = {
|
|
||||||
strings: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(
|
|
||||||
"1" + 2 + (3 + 4 + 5),
|
|
||||||
"1" + 2 + (3 + 4 + "5"),
|
|
||||||
"1" + 2 + (3 + "4" + 5),
|
|
||||||
"1" + 2 + (3 + "4" + "5"),
|
|
||||||
"1" + 2 + ("3" + 4 + 5),
|
|
||||||
"1" + 2 + ("3" + 4 + "5"),
|
|
||||||
"1" + 2 + ("3" + "4" + 5),
|
|
||||||
"1" + 2 + ("3" + "4" + "5")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(
|
|
||||||
"1" + 2 + (3 + 4 + 5),
|
|
||||||
"1" + 2 + (3 + 4) + "5",
|
|
||||||
"1" + 2 + 3 + "4" + 5,
|
|
||||||
"1" + 2 + 3 + "4" + "5",
|
|
||||||
"1" + 2 + "3" + 4 + 5,
|
|
||||||
"1" + 2 + "3" + 4 + "5",
|
|
||||||
"1" + 2 + "3" + "4" + 5,
|
|
||||||
"1" + 2 + "3" + "4" + "5"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
concat_6: {
|
|
||||||
options = {
|
|
||||||
strings: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(
|
|
||||||
"1" + "2" + (3 + 4 + 5),
|
|
||||||
"1" + "2" + (3 + 4 + "5"),
|
|
||||||
"1" + "2" + (3 + "4" + 5),
|
|
||||||
"1" + "2" + (3 + "4" + "5"),
|
|
||||||
"1" + "2" + ("3" + 4 + 5),
|
|
||||||
"1" + "2" + ("3" + 4 + "5"),
|
|
||||||
"1" + "2" + ("3" + "4" + 5),
|
|
||||||
"1" + "2" + ("3" + "4" + "5")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(
|
|
||||||
"1" + "2" + (3 + 4 + 5),
|
|
||||||
"1" + "2" + (3 + 4) + "5",
|
|
||||||
"1" + "2" + 3 + "4" + 5,
|
|
||||||
"1" + "2" + 3 + "4" + "5",
|
|
||||||
"1" + "2" + "3" + 4 + 5,
|
|
||||||
"1" + "2" + "3" + 4 + "5",
|
|
||||||
"1" + "2" + "3" + "4" + 5,
|
|
||||||
"1" + "2" + "3" + "4" + "5"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
concat_7: {
|
|
||||||
options = {
|
|
||||||
strings: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(
|
|
||||||
"" + 1,
|
|
||||||
"" + "1",
|
|
||||||
"" + 1 + 2,
|
|
||||||
"" + 1 + "2",
|
|
||||||
"" + "1" + 2,
|
|
||||||
"" + "1" + "2",
|
|
||||||
"" + (x += "foo")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(
|
|
||||||
"" + 1,
|
|
||||||
"1",
|
|
||||||
"" + 1 + 2,
|
|
||||||
1 + "2",
|
|
||||||
"1" + 2,
|
|
||||||
"1" + "2",
|
|
||||||
x += "foo"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
concat_8: {
|
|
||||||
options = {
|
|
||||||
strings: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(
|
|
||||||
1 + "",
|
|
||||||
"1" + "",
|
|
||||||
1 + 2 + "",
|
|
||||||
1 + "2" + "",
|
|
||||||
"1" + 2 + "",
|
|
||||||
"1" + "2" + "",
|
|
||||||
(x += "foo") + ""
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(
|
|
||||||
1 + "",
|
|
||||||
"1",
|
|
||||||
1 + 2 + "",
|
|
||||||
1 + "2",
|
|
||||||
"1" + 2,
|
|
||||||
"1" + "2",
|
|
||||||
x += "foo"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
concat_9: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
evaluate: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
strings: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = "foo";
|
|
||||||
console.log(
|
|
||||||
12 + (34 + a),
|
|
||||||
null + (34 + a),
|
|
||||||
12 + (null + a),
|
|
||||||
false + (34 + a),
|
|
||||||
12 + (false + a),
|
|
||||||
"bar" + (34 + a),
|
|
||||||
12 + ("bar" + a)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = "foo";
|
|
||||||
console.log(
|
|
||||||
"1234" + a,
|
|
||||||
"null34" + a,
|
|
||||||
"12null" + a,
|
|
||||||
!1 + (34 + a),
|
|
||||||
12 + (!1 + a),
|
|
||||||
"bar34" + a,
|
|
||||||
"12bar" + a
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3689: {
|
|
||||||
options = {
|
|
||||||
strings: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function(a) {
|
|
||||||
return a + ("" + (a[0] = 0));
|
|
||||||
}([]));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(function(a) {
|
|
||||||
return a + ("" + (a[0] = 0));
|
|
||||||
}([]));
|
|
||||||
}
|
|
||||||
expect_stdout: "00"
|
|
||||||
}
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
|||||||
keep_debugger: {
|
keep_debugger: {
|
||||||
options = {
|
options = {
|
||||||
drop_debugger: false,
|
drop_debugger: false
|
||||||
}
|
};
|
||||||
input: {
|
input: {
|
||||||
debugger;
|
debugger;
|
||||||
}
|
}
|
||||||
@@ -12,8 +12,8 @@ keep_debugger: {
|
|||||||
|
|
||||||
drop_debugger: {
|
drop_debugger: {
|
||||||
options = {
|
options = {
|
||||||
drop_debugger: true,
|
drop_debugger: true
|
||||||
}
|
};
|
||||||
input: {
|
input: {
|
||||||
debugger;
|
debugger;
|
||||||
if (foo) debugger;
|
if (foo) debugger;
|
||||||
|
|||||||
@@ -1,131 +0,0 @@
|
|||||||
simple_statement_is_not_a_directive: {
|
|
||||||
input: {
|
|
||||||
"use strict"
|
|
||||||
.split(" ")
|
|
||||||
.forEach(function(s) {
|
|
||||||
console.log(s);
|
|
||||||
});
|
|
||||||
console.log(!this); // is strict mode?
|
|
||||||
(function() {
|
|
||||||
"directive"
|
|
||||||
""
|
|
||||||
"use strict"
|
|
||||||
"hello world"
|
|
||||||
.split(" ")
|
|
||||||
.forEach(function(s) {
|
|
||||||
console.log(s);
|
|
||||||
});
|
|
||||||
console.log(!this); // is strict mode?
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict".split(" ").forEach(function(s) {
|
|
||||||
console.log(s);
|
|
||||||
});
|
|
||||||
console.log(!this);
|
|
||||||
(function() {
|
|
||||||
"directive";
|
|
||||||
"";
|
|
||||||
"use strict";
|
|
||||||
"hello world".split(" ").forEach(function(s) {
|
|
||||||
console.log(s);
|
|
||||||
});
|
|
||||||
console.log(!this);
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"use",
|
|
||||||
"strict",
|
|
||||||
"false",
|
|
||||||
"hello",
|
|
||||||
"world",
|
|
||||||
"true",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
drop_lone_use_strict: {
|
|
||||||
options = {
|
|
||||||
directives: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f1() {
|
|
||||||
"use strict";
|
|
||||||
}
|
|
||||||
function f2() {
|
|
||||||
"use strict";
|
|
||||||
function f3() {
|
|
||||||
"use strict";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(function f4() {
|
|
||||||
"use strict";
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f1() {
|
|
||||||
}
|
|
||||||
function f2() {
|
|
||||||
}
|
|
||||||
(function() {})();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3166: {
|
|
||||||
options = {
|
|
||||||
directives: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"foo";
|
|
||||||
"use strict";
|
|
||||||
function f() {
|
|
||||||
"use strict";
|
|
||||||
"bar";
|
|
||||||
"use asm";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
function f() {
|
|
||||||
"use asm";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
valid_after_invalid_1: {
|
|
||||||
input: {
|
|
||||||
console.log(typeof function() {
|
|
||||||
"use\x20strict";
|
|
||||||
"use strict";
|
|
||||||
return this;
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(typeof function() {
|
|
||||||
"use\x20strict";
|
|
||||||
"use strict";
|
|
||||||
return this;
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect_stdout: "undefined"
|
|
||||||
}
|
|
||||||
|
|
||||||
valid_after_invalid_2: {
|
|
||||||
options = {
|
|
||||||
directives: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(typeof function() {
|
|
||||||
"use\x20strict";
|
|
||||||
"use strict";
|
|
||||||
return this;
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(typeof function() {
|
|
||||||
"use strict";
|
|
||||||
return this;
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect_stdout: "undefined"
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
drop_console_1: {
|
drop_console_1: {
|
||||||
options = {}
|
options = {};
|
||||||
input: {
|
input: {
|
||||||
console.log('foo');
|
console.log('foo');
|
||||||
console.log.apply(console, arguments);
|
console.log.apply(console, arguments);
|
||||||
@@ -10,10 +10,8 @@ drop_console_1: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drop_console_2: {
|
drop_console_1: {
|
||||||
options = {
|
options = { drop_console: true };
|
||||||
drop_console: true,
|
|
||||||
}
|
|
||||||
input: {
|
input: {
|
||||||
console.log('foo');
|
console.log('foo');
|
||||||
console.log.apply(console, arguments);
|
console.log.apply(console, arguments);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,232 +0,0 @@
|
|||||||
must_replace: {
|
|
||||||
options = {
|
|
||||||
global_defs: {
|
|
||||||
D: "foo bar",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(D);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log("foo bar");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repeated_nodes: {
|
|
||||||
options = {
|
|
||||||
global_defs: {
|
|
||||||
"@N": "rand()",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(N, N);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(rand(), rand());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keyword: {
|
|
||||||
options = {
|
|
||||||
global_defs: {
|
|
||||||
undefined: 0,
|
|
||||||
NaN: 1,
|
|
||||||
Infinity: 2,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(undefined, NaN, Infinity);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(0, 1, 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
object: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
global_defs: {
|
|
||||||
CONFIG: {
|
|
||||||
DEBUG: [ 0 ],
|
|
||||||
VALUE: 42,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
side_effects: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(CONFIG) {
|
|
||||||
// CONFIG not global - do not replace
|
|
||||||
return CONFIG.VALUE;
|
|
||||||
}
|
|
||||||
function g() {
|
|
||||||
var CONFIG = { VALUE: 1 };
|
|
||||||
// CONFIG not global - do not replace
|
|
||||||
return CONFIG.VALUE;
|
|
||||||
}
|
|
||||||
function h() {
|
|
||||||
return CONFIG.VALUE;
|
|
||||||
}
|
|
||||||
if (CONFIG.DEBUG[0])
|
|
||||||
console.debug("foo");
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(CONFIG) {
|
|
||||||
return CONFIG.VALUE;
|
|
||||||
}
|
|
||||||
function g() {
|
|
||||||
var CONFIG = { VALUE: 1 };
|
|
||||||
return CONFIG.VALUE;
|
|
||||||
}
|
|
||||||
function h() {
|
|
||||||
return 42;
|
|
||||||
}
|
|
||||||
if (0)
|
|
||||||
console.debug("foo");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
expanded: {
|
|
||||||
options = {
|
|
||||||
global_defs: {
|
|
||||||
"CONFIG.DEBUG": [ 0 ],
|
|
||||||
"CONFIG.VALUE": 42,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(CONFIG) {
|
|
||||||
// CONFIG not global - do not replace
|
|
||||||
return CONFIG.VALUE;
|
|
||||||
}
|
|
||||||
function g() {
|
|
||||||
var CONFIG = { VALUE: 1 };
|
|
||||||
// CONFIG not global - do not replace
|
|
||||||
return CONFIG.VALUE;
|
|
||||||
}
|
|
||||||
function h() {
|
|
||||||
return CONFIG.VALUE;
|
|
||||||
}
|
|
||||||
if (CONFIG.DEBUG[0])
|
|
||||||
console.debug("foo");
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(CONFIG) {
|
|
||||||
return CONFIG.VALUE;
|
|
||||||
}
|
|
||||||
function g() {
|
|
||||||
var CONFIG = { VALUE: 1 };
|
|
||||||
return CONFIG.VALUE;
|
|
||||||
}
|
|
||||||
function h() {
|
|
||||||
return 42;
|
|
||||||
}
|
|
||||||
if ([0][0])
|
|
||||||
console.debug("foo");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mixed: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
global_defs: {
|
|
||||||
"CONFIG.VALUE": 42,
|
|
||||||
"FOO.BAR": "moo",
|
|
||||||
},
|
|
||||||
properties: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var FOO = { BAR: 0 };
|
|
||||||
console.log(FOO.BAR);
|
|
||||||
console.log(++CONFIG.DEBUG);
|
|
||||||
console.log(++CONFIG.VALUE);
|
|
||||||
console.log(++CONFIG["VAL" + "UE"]);
|
|
||||||
console.log(++DEBUG[CONFIG.VALUE]);
|
|
||||||
CONFIG.VALUE.FOO = "bar";
|
|
||||||
console.log(CONFIG);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var FOO = { BAR: 0 };
|
|
||||||
console.log("moo");
|
|
||||||
console.log(++CONFIG.DEBUG);
|
|
||||||
console.log(++CONFIG.VALUE);
|
|
||||||
console.log(++CONFIG.VALUE);
|
|
||||||
console.log(++DEBUG[42]);
|
|
||||||
CONFIG.VALUE.FOO = "bar";
|
|
||||||
console.log(CONFIG);
|
|
||||||
}
|
|
||||||
expect_warnings: [
|
|
||||||
"WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:4,22]",
|
|
||||||
"WARN: global_defs CONFIG.VALUE redefined [test/compress/global_defs.js:7,8]",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1801: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
global_defs: {
|
|
||||||
"CONFIG.FOO.BAR": true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(CONFIG.FOO.BAR);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(!0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1986: {
|
|
||||||
options = {
|
|
||||||
global_defs: {
|
|
||||||
"@alert": "console.log",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
alert(42);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(42);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2167: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
global_defs: {
|
|
||||||
"@isDevMode": "function(){}",
|
|
||||||
},
|
|
||||||
passes: 2,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
if (isDevMode()) {
|
|
||||||
greetOverlord();
|
|
||||||
}
|
|
||||||
doWork();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
doWork();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3217: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
global_defs: {
|
|
||||||
"@o": "{fn:function(){var a=42;console.log(a)}}",
|
|
||||||
},
|
|
||||||
inline: true,
|
|
||||||
properties: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
o.fn();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(42);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,111 +0,0 @@
|
|||||||
statements: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: false,
|
|
||||||
hoist_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
var a = 1;
|
|
||||||
var b = 2;
|
|
||||||
var c = 3;
|
|
||||||
function g() {}
|
|
||||||
return g(a, b, c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f() {
|
|
||||||
var a = 1, b = 2, c = 3;
|
|
||||||
function g() {}
|
|
||||||
return g(a, b, c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
statements_funs: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
hoist_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
var a = 1;
|
|
||||||
var b = 2;
|
|
||||||
var c = 3;
|
|
||||||
function g() {}
|
|
||||||
return g(a, b, c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f() {
|
|
||||||
function g() {}
|
|
||||||
var a = 1, b = 2, c = 3;
|
|
||||||
return g(a, b, c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sequences: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: false,
|
|
||||||
hoist_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
var a = 1, b = 2;
|
|
||||||
function g() {}
|
|
||||||
var c = 3;
|
|
||||||
return g(a, b, c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f() {
|
|
||||||
var c, a = 1, b = 2;
|
|
||||||
function g() {}
|
|
||||||
c = 3;
|
|
||||||
return g(a, b, c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sequences_funs: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
hoist_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
var a = 1, b = 2;
|
|
||||||
function g() {}
|
|
||||||
var c = 3;
|
|
||||||
return g(a, b, c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f() {
|
|
||||||
function g() {}
|
|
||||||
var a = 1, b = 2, c = 3;
|
|
||||||
return g(a, b, c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_2295: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
hoist_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function foo(o) {
|
|
||||||
var a = o.a;
|
|
||||||
if (a) return a;
|
|
||||||
var a = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function foo(o) {
|
|
||||||
var a = o.a;
|
|
||||||
if (a) return a;
|
|
||||||
a = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
html_comment_in_expression: {
|
|
||||||
input: {
|
|
||||||
(function(a, b) {
|
|
||||||
console.log(a < !--b && a-- > b, a, b);
|
|
||||||
})(1, 2);
|
|
||||||
}
|
|
||||||
expect_exact: "(function(a,b){console.log(a<! --b&&a-- >b,a,b)})(1,2);"
|
|
||||||
expect_stdout: "false 1 1"
|
|
||||||
}
|
|
||||||
|
|
||||||
html_comment_in_less_than: {
|
|
||||||
input: {
|
|
||||||
(function(a, b, c) {
|
|
||||||
console.log(
|
|
||||||
a < !--b,
|
|
||||||
a < !--b + c,
|
|
||||||
a + b < !--c,
|
|
||||||
a, b, c
|
|
||||||
);
|
|
||||||
})(1, 2, 3);
|
|
||||||
}
|
|
||||||
expect_exact: "(function(a,b,c){console.log(a<! --b,a<! --b+c,a+b<! --c,a,b,c)})(1,2,3);"
|
|
||||||
expect_stdout: "false true false 1 0 2"
|
|
||||||
}
|
|
||||||
|
|
||||||
html_comment_in_left_shift: {
|
|
||||||
input: {
|
|
||||||
(function(a, b, c) {
|
|
||||||
console.log(
|
|
||||||
a << !--b,
|
|
||||||
a << !--b + c,
|
|
||||||
a + b << !--c,
|
|
||||||
a, b, c
|
|
||||||
);
|
|
||||||
})(1, 2, 3);
|
|
||||||
}
|
|
||||||
expect_exact: "(function(a,b,c){console.log(a<<! --b,a<<! --b+c,a+b<<! --c,a,b,c)})(1,2,3);"
|
|
||||||
expect_stdout: "1 16 1 1 0 2"
|
|
||||||
}
|
|
||||||
|
|
||||||
html_comment_in_greater_than: {
|
|
||||||
input: {
|
|
||||||
(function(a, b, c) {
|
|
||||||
console.log(
|
|
||||||
a-- > b,
|
|
||||||
a-- > b + c,
|
|
||||||
a + b-- > c,
|
|
||||||
a, b, c
|
|
||||||
);
|
|
||||||
})(1, 2, 3);
|
|
||||||
}
|
|
||||||
expect_exact: "(function(a,b,c){console.log(a-- >b,a-- >b+c,a+b-- >c,a,b,c)})(1,2,3);"
|
|
||||||
expect_stdout: "false false false -1 1 3"
|
|
||||||
}
|
|
||||||
|
|
||||||
html_comment_in_greater_than_or_equal: {
|
|
||||||
input: {
|
|
||||||
(function(a, b, c) {
|
|
||||||
console.log(
|
|
||||||
a-- >= b,
|
|
||||||
a-- >= b + c,
|
|
||||||
a + b-- >= c,
|
|
||||||
a, b, c
|
|
||||||
);
|
|
||||||
})(1, 2, 3);
|
|
||||||
}
|
|
||||||
expect_exact: "(function(a,b,c){console.log(a-- >=b,a-- >=b+c,a+b-- >=c,a,b,c)})(1,2,3);"
|
|
||||||
expect_stdout: "false false false -1 1 3"
|
|
||||||
}
|
|
||||||
|
|
||||||
html_comment_in_right_shift: {
|
|
||||||
input: {
|
|
||||||
(function(a, b, c) {
|
|
||||||
console.log(
|
|
||||||
a-- >> b,
|
|
||||||
a-- >> b + c,
|
|
||||||
a + b-- >> c,
|
|
||||||
a, b, c
|
|
||||||
);
|
|
||||||
})(1, 2, 3);
|
|
||||||
}
|
|
||||||
expect_exact: "(function(a,b,c){console.log(a-- >>b,a-- >>b+c,a+b-- >>c,a,b,c)})(1,2,3);"
|
|
||||||
expect_stdout: "0 0 0 -1 1 3"
|
|
||||||
}
|
|
||||||
|
|
||||||
html_comment_in_zero_fill_right_shift: {
|
|
||||||
input: {
|
|
||||||
(function(a, b, c) {
|
|
||||||
console.log(
|
|
||||||
a-- >>> b,
|
|
||||||
a-- >>> b + c,
|
|
||||||
a + b-- >>> c,
|
|
||||||
a, b, c
|
|
||||||
);
|
|
||||||
})(1, 2, 3);
|
|
||||||
}
|
|
||||||
expect_exact: "(function(a,b,c){console.log(a-- >>>b,a-- >>>b+c,a+b-- >>>c,a,b,c)})(1,2,3);"
|
|
||||||
expect_stdout: "0 0 0 -1 1 3"
|
|
||||||
}
|
|
||||||
|
|
||||||
html_comment_in_string_literal: {
|
|
||||||
input: {
|
|
||||||
console.log("<!--HTML-->comment in<!--string literal-->".length);
|
|
||||||
}
|
|
||||||
expect_exact: 'console.log("\\x3c!--HTML--\\x3ecomment in\\x3c!--string literal--\\x3e".length);'
|
|
||||||
expect_stdout: "42"
|
|
||||||
}
|
|
||||||
2861
test/compress/ie8.js
2861
test/compress/ie8.js
File diff suppressed because it is too large
Load Diff
@@ -1,750 +0,0 @@
|
|||||||
if_return_1: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
if_return: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(x) {
|
|
||||||
if (x) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(x){if(x)return!0}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if_return_2: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
if_return: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(x, y) {
|
|
||||||
if (x)
|
|
||||||
return 3;
|
|
||||||
if (y)
|
|
||||||
return c();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(x,y){return x?3:y?c():void 0}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if_return_3: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
if_return: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(x) {
|
|
||||||
a();
|
|
||||||
if (x) {
|
|
||||||
b();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(x){if(a(),x)return b(),!1}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if_return_4: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
if_return: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(x, y) {
|
|
||||||
a();
|
|
||||||
if (x) return 3;
|
|
||||||
b();
|
|
||||||
if (y) return c();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(x,y){return a(),x?3:(b(),y?c():void 0)}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if_return_5: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
if_return: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
if (x)
|
|
||||||
return;
|
|
||||||
return 7;
|
|
||||||
if (y)
|
|
||||||
return j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(){if(!x)return 7}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if_return_6: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
if_return: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(x) {
|
|
||||||
return x ? true : void 0;
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
// suboptimal
|
|
||||||
function f(x){return!!x||void 0}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if_return_7: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
if_return: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(x) {
|
|
||||||
if (x) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
foo();
|
|
||||||
bar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(x){if(x)return!0;foo(),bar()}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if_return_8: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
if_return: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(e) {
|
|
||||||
if (2 == e) return foo();
|
|
||||||
if (3 == e) return bar();
|
|
||||||
if (4 == e) return baz();
|
|
||||||
fail(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
function g(e) {
|
|
||||||
if (a(e)) return foo();
|
|
||||||
if (b(e)) return bar();
|
|
||||||
if (c(e)) return baz();
|
|
||||||
fail(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
function h(e) {
|
|
||||||
if (a(e)) return foo();
|
|
||||||
else if (b(e)) return bar();
|
|
||||||
else if (c(e)) return baz();
|
|
||||||
else fail(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
function i(e) {
|
|
||||||
if (a(e)) return foo();
|
|
||||||
else if (b(e)) return bar();
|
|
||||||
else if (c(e)) return baz();
|
|
||||||
fail(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(e){return 2==e?foo():3==e?bar():4==e?baz():void fail(e)}
|
|
||||||
function g(e){return a(e)?foo():b(e)?bar():c(e)?baz():void fail(e)}
|
|
||||||
function h(e){return a(e)?foo():b(e)?bar():c(e)?baz():void fail(e)}
|
|
||||||
function i(e){return a(e)?foo():b(e)?bar():c(e)?baz():void fail(e)}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1089: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
if_return: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function x() {
|
|
||||||
var f = document.getElementById("fname");
|
|
||||||
if (f.files[0].size > 12345) {
|
|
||||||
alert("alert");
|
|
||||||
f.focus();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function x() {
|
|
||||||
var f = document.getElementById("fname");
|
|
||||||
if (12345 < f.files[0].size)
|
|
||||||
return alert("alert"), f.focus(), !1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1437: {
|
|
||||||
options = {
|
|
||||||
conditionals: false,
|
|
||||||
if_return: true,
|
|
||||||
sequences: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function x() {
|
|
||||||
if (a())
|
|
||||||
return b();
|
|
||||||
if (c())
|
|
||||||
return d();
|
|
||||||
else
|
|
||||||
e();
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function x() {
|
|
||||||
if (a())
|
|
||||||
return b();
|
|
||||||
if (c())
|
|
||||||
return d();
|
|
||||||
else
|
|
||||||
e()
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1437_conditionals: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
if_return: true,
|
|
||||||
sequences: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function x() {
|
|
||||||
if (a())
|
|
||||||
return b();
|
|
||||||
if (c())
|
|
||||||
return d();
|
|
||||||
else
|
|
||||||
e();
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function x() {
|
|
||||||
return a() ? b() : c() ? d() : (e(), f(), void 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_512: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
if_return: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function a() {
|
|
||||||
if (b()) {
|
|
||||||
c();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function a() {
|
|
||||||
if (!b()) throw e;
|
|
||||||
c();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if_var_return: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
sequences: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
var a;
|
|
||||||
return;
|
|
||||||
var b;
|
|
||||||
}
|
|
||||||
function g() {
|
|
||||||
var a;
|
|
||||||
if (u()) {
|
|
||||||
var b;
|
|
||||||
return v();
|
|
||||||
var c;
|
|
||||||
}
|
|
||||||
var d;
|
|
||||||
if (w()) {
|
|
||||||
var e;
|
|
||||||
return x();
|
|
||||||
var f;
|
|
||||||
} else {
|
|
||||||
var g;
|
|
||||||
y();
|
|
||||||
var h;
|
|
||||||
}
|
|
||||||
var i;
|
|
||||||
z();
|
|
||||||
var j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f() {
|
|
||||||
var a, b;
|
|
||||||
}
|
|
||||||
function g() {
|
|
||||||
var a, b, c, d, e, f, g, h, i, j;
|
|
||||||
return u() ? v() : w() ? x() : (y(), z(), void 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if_if_return_return: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
if_return: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(a, b) {
|
|
||||||
if (a) {
|
|
||||||
if (b)
|
|
||||||
return b;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
g();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(a, b) {
|
|
||||||
if (a)
|
|
||||||
return b || void 0;
|
|
||||||
g();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if_body_return_1: {
|
|
||||||
options = {
|
|
||||||
if_return: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var c = "PASS";
|
|
||||||
function f(a, b) {
|
|
||||||
if (a) {
|
|
||||||
if (b) throw new Error(c);
|
|
||||||
return 42;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
console.log(f(0, 0));
|
|
||||||
console.log(f(0, 1));
|
|
||||||
console.log(f(1, 0));
|
|
||||||
try {
|
|
||||||
f(1, 1);
|
|
||||||
console.log("FAIL");
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var c = "PASS";
|
|
||||||
function f(a, b) {
|
|
||||||
if (a) {
|
|
||||||
if (b) throw new Error(c);
|
|
||||||
return 42;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
console.log(f(0, 0));
|
|
||||||
console.log(f(0, 1));
|
|
||||||
console.log(f(1, 0));
|
|
||||||
try {
|
|
||||||
f(1, 1);
|
|
||||||
console.log("FAIL");
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"true",
|
|
||||||
"true",
|
|
||||||
"42",
|
|
||||||
"PASS",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
if_body_return_2: {
|
|
||||||
options = {
|
|
||||||
if_return: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var c = "PASS";
|
|
||||||
function f(a, b) {
|
|
||||||
if (0 + a) {
|
|
||||||
if (b) throw new Error(c);
|
|
||||||
return 42;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
console.log(f(0, 0));
|
|
||||||
console.log(f(0, 1));
|
|
||||||
console.log(f(1, 0));
|
|
||||||
try {
|
|
||||||
f(1, 1);
|
|
||||||
console.log("FAIL");
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var c = "PASS";
|
|
||||||
function f(a, b) {
|
|
||||||
if (0 + a) {
|
|
||||||
if (b) throw new Error(c);
|
|
||||||
return 42;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
console.log(f(0, 0));
|
|
||||||
console.log(f(0, 1));
|
|
||||||
console.log(f(1, 0));
|
|
||||||
try {
|
|
||||||
f(1, 1);
|
|
||||||
console.log("FAIL");
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"true",
|
|
||||||
"true",
|
|
||||||
"42",
|
|
||||||
"PASS",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
if_body_return_3: {
|
|
||||||
options = {
|
|
||||||
if_return: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var c = "PASS";
|
|
||||||
function f(a, b) {
|
|
||||||
if (1 == a) {
|
|
||||||
if (b) throw new Error(c);
|
|
||||||
return 42;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
console.log(f(0, 0));
|
|
||||||
console.log(f(0, 1));
|
|
||||||
console.log(f(1, 0));
|
|
||||||
try {
|
|
||||||
f(1, 1);
|
|
||||||
console.log("FAIL");
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var c = "PASS";
|
|
||||||
function f(a, b) {
|
|
||||||
if (1 != a) return true;
|
|
||||||
if (b) throw new Error(c);
|
|
||||||
return 42;
|
|
||||||
}
|
|
||||||
console.log(f(0, 0));
|
|
||||||
console.log(f(0, 1));
|
|
||||||
console.log(f(1, 0));
|
|
||||||
try {
|
|
||||||
f(1, 1);
|
|
||||||
console.log("FAIL");
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"true",
|
|
||||||
"true",
|
|
||||||
"42",
|
|
||||||
"PASS",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_3600: {
|
|
||||||
options = {
|
|
||||||
if_return: true,
|
|
||||||
inline: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var c = 0;
|
|
||||||
(function() {
|
|
||||||
if ([ ][c++]); else return;
|
|
||||||
return void function() {
|
|
||||||
var b = --b, a = c = 42;
|
|
||||||
return c;
|
|
||||||
}();
|
|
||||||
})();
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var c = 0;
|
|
||||||
(function() {
|
|
||||||
if ([][c++]) b = --b, c = 42;
|
|
||||||
var b;
|
|
||||||
})();
|
|
||||||
console.log(c);
|
|
||||||
}
|
|
||||||
expect_stdout: "1"
|
|
||||||
}
|
|
||||||
|
|
||||||
iife_if_return_simple: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
if_return: true,
|
|
||||||
inline: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
if (console)
|
|
||||||
return console.log("PASS");
|
|
||||||
console.log("FAIL");
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console ? console.log("PASS") : console.log("FAIL");
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
nested_if_break: {
|
|
||||||
options = {
|
|
||||||
if_return: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
for (var i = 0; i < 3; i++)
|
|
||||||
L1: if ("number" == typeof i) {
|
|
||||||
if (0 === i) break L1;
|
|
||||||
console.log(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
for (var i = 0; i < 3; i++)
|
|
||||||
L1: if ("number" == typeof i)
|
|
||||||
if (0 !== i) console.log(i);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"1",
|
|
||||||
"2",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
nested_if_continue: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
loops: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(n) {
|
|
||||||
var i = 0;
|
|
||||||
do {
|
|
||||||
if ("number" == typeof n) {
|
|
||||||
if (0 === n) {
|
|
||||||
console.log("even", i);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (1 === n) {
|
|
||||||
console.log("odd", i);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
} while (0 <= (n -= 2));
|
|
||||||
}
|
|
||||||
f(37);
|
|
||||||
f(42);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(n) {
|
|
||||||
for (var i = 0;
|
|
||||||
"number" == typeof n
|
|
||||||
&& (0 !== n
|
|
||||||
? 1 !== n
|
|
||||||
? i++
|
|
||||||
: console.log("odd", i)
|
|
||||||
: console.log("even", i)),
|
|
||||||
0 <= (n -= 2););
|
|
||||||
}
|
|
||||||
f(37);
|
|
||||||
f(42);
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"odd 18",
|
|
||||||
"even 21",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
nested_if_return: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
if_return: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
if (A) {
|
|
||||||
if (B)
|
|
||||||
return B;
|
|
||||||
if (C)
|
|
||||||
return D;
|
|
||||||
if (E)
|
|
||||||
return F;
|
|
||||||
if (G)
|
|
||||||
return H;
|
|
||||||
if (I) {
|
|
||||||
if (J)
|
|
||||||
return K;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (L) {
|
|
||||||
if (M)
|
|
||||||
return;
|
|
||||||
return N;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f() {
|
|
||||||
if (A)
|
|
||||||
return B || (C ? D : E ? F : G ? H : I ? J ? K : void 0 : L && !M ? N : void 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_866_1: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
if_return: true,
|
|
||||||
sequences: false,
|
|
||||||
};
|
|
||||||
input: {
|
|
||||||
function f(a) {
|
|
||||||
if (a)
|
|
||||||
return "";
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(a) {
|
|
||||||
if (a)
|
|
||||||
return "";
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_866_2: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
if_return: true,
|
|
||||||
sequences: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
if (a)
|
|
||||||
if (b)
|
|
||||||
c;
|
|
||||||
else
|
|
||||||
return d;
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function() {
|
|
||||||
if (a) {
|
|
||||||
if (!b)
|
|
||||||
return d;
|
|
||||||
c;
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,310 +0,0 @@
|
|||||||
non_hoisted_function_after_return: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
hoist_funs: false,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
keep_fargs: true,
|
|
||||||
loops: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function foo(x) {
|
|
||||||
if (x) {
|
|
||||||
return bar();
|
|
||||||
not_called1();
|
|
||||||
} else {
|
|
||||||
return baz();
|
|
||||||
not_called2();
|
|
||||||
}
|
|
||||||
function bar() { return 7; }
|
|
||||||
return not_reached;
|
|
||||||
function UnusedFunction() {}
|
|
||||||
function baz() { return 8; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function foo(x) {
|
|
||||||
return (x ? bar : baz)();
|
|
||||||
function bar() { return 7 }
|
|
||||||
function baz() { return 8 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_warnings: [
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:4,16]",
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:7,16]",
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:10,12]",
|
|
||||||
"WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:11,21]"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
non_hoisted_function_after_return_2a: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
collapse_vars: false,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
hoist_funs: false,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
keep_fargs: true,
|
|
||||||
loops: true,
|
|
||||||
passes: 2,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function foo(x) {
|
|
||||||
if (x) {
|
|
||||||
return bar(1);
|
|
||||||
var a = not_called(1);
|
|
||||||
} else {
|
|
||||||
return bar(2);
|
|
||||||
var b = not_called(2);
|
|
||||||
}
|
|
||||||
var c = bar(3);
|
|
||||||
function bar(x) { return 7 - x; }
|
|
||||||
function nope() {}
|
|
||||||
return b || c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function foo(x) {
|
|
||||||
return bar(x ? 1 : 2);
|
|
||||||
function bar(x) {
|
|
||||||
return 7 - x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_warnings: [
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:4,16]",
|
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:4,16]",
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:7,16]",
|
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:7,16]",
|
|
||||||
"WARN: Dropping unused variable a [test/compress/issue-1034.js:4,20]",
|
|
||||||
"WARN: Dropping unused function nope [test/compress/issue-1034.js:11,21]",
|
|
||||||
"INFO: pass 0: last_count: Infinity, count: 36",
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:9,12]",
|
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:9,12]",
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:12,12]",
|
|
||||||
"INFO: Dropping unused variable b [test/compress/issue-1034.js:7,20]",
|
|
||||||
"INFO: Dropping unused variable c [test/compress/issue-1034.js:9,16]",
|
|
||||||
"INFO: pass 1: last_count: 36, count: 18",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
non_hoisted_function_after_return_2b: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
collapse_vars: false,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
hoist_funs: false,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
keep_fargs: true,
|
|
||||||
loops: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function foo(x) {
|
|
||||||
if (x) {
|
|
||||||
return bar(1);
|
|
||||||
} else {
|
|
||||||
return bar(2);
|
|
||||||
var b;
|
|
||||||
}
|
|
||||||
var c = bar(3);
|
|
||||||
function bar(x) {
|
|
||||||
return 7 - x;
|
|
||||||
}
|
|
||||||
return b || c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function foo(x) {
|
|
||||||
return bar(x ? 1 : 2);
|
|
||||||
function bar(x) { return 7 - x; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_warnings: [
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:6,16]",
|
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:6,16]",
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:8,12]",
|
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:8,12]",
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:12,12]",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
non_hoisted_function_after_return_strict: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
hoist_funs: false,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
keep_fargs: true,
|
|
||||||
loops: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
function foo(x) {
|
|
||||||
if (x) {
|
|
||||||
return bar();
|
|
||||||
not_called1();
|
|
||||||
} else {
|
|
||||||
return baz();
|
|
||||||
not_called2();
|
|
||||||
}
|
|
||||||
function bar() { return 7; }
|
|
||||||
return not_reached;
|
|
||||||
function UnusedFunction() {}
|
|
||||||
function baz() { return 8; }
|
|
||||||
}
|
|
||||||
console.log(foo(0), foo(1));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
function foo(x) {
|
|
||||||
return (x ? bar : baz)();
|
|
||||||
function bar() { return 7 }
|
|
||||||
function baz() { return 8 }
|
|
||||||
}
|
|
||||||
console.log(foo(0), foo(1));
|
|
||||||
}
|
|
||||||
expect_stdout: "8 7"
|
|
||||||
expect_warnings: [
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:5,16]",
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:8,16]",
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:11,12]",
|
|
||||||
"WARN: Dropping unused function UnusedFunction [test/compress/issue-1034.js:12,21]",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
non_hoisted_function_after_return_2a_strict: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
collapse_vars: false,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
hoist_funs: false,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
keep_fargs: true,
|
|
||||||
loops: true,
|
|
||||||
passes: 2,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
function foo(x) {
|
|
||||||
if (x) {
|
|
||||||
return bar(1);
|
|
||||||
var a = not_called(1);
|
|
||||||
} else {
|
|
||||||
return bar(2);
|
|
||||||
var b = not_called(2);
|
|
||||||
}
|
|
||||||
var c = bar(3);
|
|
||||||
function bar(x) { return 7 - x; }
|
|
||||||
function nope() {}
|
|
||||||
return b || c;
|
|
||||||
}
|
|
||||||
console.log(foo(0), foo(1));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
function foo(x) {
|
|
||||||
return bar(x ? 1 : 2);
|
|
||||||
function bar(x) {
|
|
||||||
return 7 - x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.log(foo(0), foo(1));
|
|
||||||
}
|
|
||||||
expect_stdout: "5 6"
|
|
||||||
expect_warnings: [
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:5,16]",
|
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:5,16]",
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:8,16]",
|
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:8,16]",
|
|
||||||
"WARN: Dropping unused variable a [test/compress/issue-1034.js:5,20]",
|
|
||||||
"WARN: Dropping unused function nope [test/compress/issue-1034.js:12,21]",
|
|
||||||
"INFO: pass 0: last_count: Infinity, count: 47",
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:10,12]",
|
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:10,12]",
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:13,12]",
|
|
||||||
"INFO: Dropping unused variable b [test/compress/issue-1034.js:8,20]",
|
|
||||||
"INFO: Dropping unused variable c [test/compress/issue-1034.js:10,16]",
|
|
||||||
"INFO: pass 1: last_count: 47, count: 29",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
non_hoisted_function_after_return_2b_strict: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
collapse_vars: false,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
hoist_funs: false,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
keep_fargs: true,
|
|
||||||
loops: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
function foo(x) {
|
|
||||||
if (x) {
|
|
||||||
return bar(1);
|
|
||||||
} else {
|
|
||||||
return bar(2);
|
|
||||||
var b;
|
|
||||||
}
|
|
||||||
var c = bar(3);
|
|
||||||
function bar(x) {
|
|
||||||
return 7 - x;
|
|
||||||
}
|
|
||||||
return b || c;
|
|
||||||
}
|
|
||||||
console.log(foo(0), foo(1));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
function foo(x) {
|
|
||||||
return bar(x ? 1 : 2);
|
|
||||||
function bar(x) { return 7 - x; }
|
|
||||||
}
|
|
||||||
console.log(foo(0), foo(1));
|
|
||||||
}
|
|
||||||
expect_stdout: "5 6"
|
|
||||||
expect_warnings: [
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:7,16]",
|
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:7,16]",
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:9,12]",
|
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:9,12]",
|
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:13,12]",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
const_pragma: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
input: {
|
|
||||||
/** @const */ var goog = goog || {};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var goog = goog || {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// for completeness' sake
|
|
||||||
not_const: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
input: {
|
|
||||||
var goog = goog || {};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var goog = goog || {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
25
test/compress/issue-105.js
Normal file
25
test/compress/issue-105.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
typeof_eq_undefined: {
|
||||||
|
options = {
|
||||||
|
comparisons: true
|
||||||
|
};
|
||||||
|
input: { a = typeof b.c != "undefined" }
|
||||||
|
expect: { a = "undefined" != typeof b.c }
|
||||||
|
}
|
||||||
|
|
||||||
|
typeof_eq_undefined_unsafe: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
unsafe: true
|
||||||
|
};
|
||||||
|
input: { a = typeof b.c != "undefined" }
|
||||||
|
expect: { a = void 0 !== b.c }
|
||||||
|
}
|
||||||
|
|
||||||
|
typeof_eq_undefined_unsafe2: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
unsafe: true
|
||||||
|
};
|
||||||
|
input: { a = "undefined" != typeof b.c }
|
||||||
|
expect: { a = void 0 !== b.c }
|
||||||
|
}
|
||||||
@@ -1,164 +0,0 @@
|
|||||||
multiple_functions: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: false,
|
|
||||||
if_return: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
( function() {
|
|
||||||
if ( !window ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
function f() {}
|
|
||||||
function g() {}
|
|
||||||
} )();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
( function() {
|
|
||||||
// NOTE: other compression steps will reduce this
|
|
||||||
// down to just `window`.
|
|
||||||
if ( !window );
|
|
||||||
function f() {}
|
|
||||||
function g() {}
|
|
||||||
} )();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
single_function: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: false,
|
|
||||||
if_return: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
( function() {
|
|
||||||
if ( !window ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
function f() {}
|
|
||||||
} )();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
( function() {
|
|
||||||
if ( !window );
|
|
||||||
function f() {}
|
|
||||||
} )();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
deeply_nested: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: false,
|
|
||||||
if_return: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
( function() {
|
|
||||||
if ( !window ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
function f() {}
|
|
||||||
function g() {}
|
|
||||||
if ( !document ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
function h() {}
|
|
||||||
} )();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
( function() {
|
|
||||||
// NOTE: other compression steps will reduce this
|
|
||||||
// down to just `window`.
|
|
||||||
if ( window )
|
|
||||||
if ( !document );
|
|
||||||
function f() {}
|
|
||||||
function g() {}
|
|
||||||
function h() {}
|
|
||||||
} )();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
not_hoisted_when_already_nested: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: false,
|
|
||||||
if_return: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
( function() {
|
|
||||||
if ( !window ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ( foo ) function f() {}
|
|
||||||
} )();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
( function() {
|
|
||||||
if ( window )
|
|
||||||
if ( foo ) function f() {}
|
|
||||||
} )();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
defun_if_return: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: false,
|
|
||||||
if_return: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function e() {
|
|
||||||
function f() {}
|
|
||||||
if (!window) return;
|
|
||||||
else function g() {}
|
|
||||||
function h() {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function e() {
|
|
||||||
function f() {}
|
|
||||||
if (window) function g() {}
|
|
||||||
function h() {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
defun_hoist_funs: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: true,
|
|
||||||
if_return: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function e() {
|
|
||||||
function f() {}
|
|
||||||
if (!window) return;
|
|
||||||
else function g() {}
|
|
||||||
function h() {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function e() {
|
|
||||||
function f() {}
|
|
||||||
function g() {}
|
|
||||||
function h() {}
|
|
||||||
if (window);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
defun_else_if_return: {
|
|
||||||
options = {
|
|
||||||
hoist_funs: false,
|
|
||||||
if_return: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function e() {
|
|
||||||
function f() {}
|
|
||||||
if (window) function g() {}
|
|
||||||
else return;
|
|
||||||
function h() {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function e() {
|
|
||||||
function f() {}
|
|
||||||
if (window) function g() {}
|
|
||||||
function h() {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,309 +0,0 @@
|
|||||||
with_in_global_scope: {
|
|
||||||
options = {
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = 42;
|
|
||||||
with(o) {
|
|
||||||
var foo = 'something'
|
|
||||||
}
|
|
||||||
doSomething(o);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var o=42;
|
|
||||||
with(o)
|
|
||||||
var foo = "something";
|
|
||||||
doSomething(o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
with_in_function_scope: {
|
|
||||||
options = {
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function foo() {
|
|
||||||
var o = 42;
|
|
||||||
with(o) {
|
|
||||||
var foo = "something"
|
|
||||||
}
|
|
||||||
doSomething(o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function foo() {
|
|
||||||
var o=42;
|
|
||||||
with(o)
|
|
||||||
var foo = "something";
|
|
||||||
doSomething(o)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
compress_with_with_in_other_scope: {
|
|
||||||
options = {
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function foo() {
|
|
||||||
var o = 42;
|
|
||||||
with(o) {
|
|
||||||
var foo = "something"
|
|
||||||
}
|
|
||||||
doSomething(o);
|
|
||||||
}
|
|
||||||
function bar() {
|
|
||||||
var unused = 42;
|
|
||||||
return something();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function foo() {
|
|
||||||
var o = 42;
|
|
||||||
with(o)
|
|
||||||
var foo = "something";
|
|
||||||
doSomething(o)
|
|
||||||
}
|
|
||||||
function bar() {
|
|
||||||
return something()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
with_using_existing_variable_outside_scope: {
|
|
||||||
options = {
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
var o = {};
|
|
||||||
var unused = {}; // Doesn't get removed because upper scope uses with
|
|
||||||
function foo() {
|
|
||||||
with(o) {
|
|
||||||
var foo = "something"
|
|
||||||
}
|
|
||||||
doSomething(o);
|
|
||||||
}
|
|
||||||
foo()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f() {
|
|
||||||
var o = {};
|
|
||||||
var unused = {};
|
|
||||||
function foo() {
|
|
||||||
with(o)
|
|
||||||
var foo = "something";
|
|
||||||
doSomething(o)
|
|
||||||
}
|
|
||||||
foo()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
check_drop_unused_in_peer_function: {
|
|
||||||
options = {
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function outer() {
|
|
||||||
var o = {};
|
|
||||||
var unused = {}; // should be kept
|
|
||||||
function foo() { // should be kept
|
|
||||||
function not_in_use() {
|
|
||||||
var nested_unused = "foo"; // should be dropped
|
|
||||||
return 24;
|
|
||||||
}
|
|
||||||
var unused = {}; // should be kept
|
|
||||||
with (o) {
|
|
||||||
var foo = "something";
|
|
||||||
}
|
|
||||||
doSomething(o);
|
|
||||||
}
|
|
||||||
function bar() {
|
|
||||||
var unused = {}; // should be dropped
|
|
||||||
doSomethingElse();
|
|
||||||
}
|
|
||||||
foo();
|
|
||||||
bar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function outer() {
|
|
||||||
var o = {};
|
|
||||||
var unused = {}; // should be kept
|
|
||||||
function foo() { // should be kept
|
|
||||||
function not_in_use() {
|
|
||||||
return 24;
|
|
||||||
}
|
|
||||||
var unused = {}; // should be kept
|
|
||||||
with (o)
|
|
||||||
var foo = "something";
|
|
||||||
doSomething(o);
|
|
||||||
}
|
|
||||||
function bar() {
|
|
||||||
doSomethingElse();
|
|
||||||
}
|
|
||||||
foo();
|
|
||||||
bar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Infinity_not_in_with_scope: {
|
|
||||||
options = {
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = { Infinity: "FAIL" };
|
|
||||||
var vInfinity = "Infinity";
|
|
||||||
vInfinity = Infinity;
|
|
||||||
console.log(vInfinity);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var o = { Infinity: "FAIL" };
|
|
||||||
var vInfinity = "Infinity";
|
|
||||||
vInfinity = 1/0;
|
|
||||||
console.log(vInfinity);
|
|
||||||
}
|
|
||||||
expect_stdout: "Infinity"
|
|
||||||
}
|
|
||||||
|
|
||||||
Infinity_in_with_scope: {
|
|
||||||
options = {
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = { Infinity: "PASS" };
|
|
||||||
var vInfinity = "Infinity";
|
|
||||||
with (o) { vInfinity = Infinity; }
|
|
||||||
console.log(vInfinity);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var o = { Infinity: "PASS" };
|
|
||||||
var vInfinity = "Infinity";
|
|
||||||
with (o) vInfinity = Infinity;
|
|
||||||
console.log(vInfinity);
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
assorted_Infinity_NaN_undefined_in_with_scope: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
hoist_funs: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
keep_fargs: true,
|
|
||||||
keep_infinity: false,
|
|
||||||
sequences: false,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var f = console.log;
|
|
||||||
var o = {
|
|
||||||
undefined : 3,
|
|
||||||
NaN : 4,
|
|
||||||
Infinity : 5,
|
|
||||||
};
|
|
||||||
if (o) {
|
|
||||||
f(undefined, void 0);
|
|
||||||
f(NaN, 0/0);
|
|
||||||
f(Infinity, 1/0);
|
|
||||||
f(-Infinity, -(1/0));
|
|
||||||
f(2 + 7 + undefined, 2 + 7 + void 0);
|
|
||||||
}
|
|
||||||
with (o) {
|
|
||||||
f(undefined, void 0);
|
|
||||||
f(NaN, 0/0);
|
|
||||||
f(Infinity, 1/0);
|
|
||||||
f(-Infinity, -(1/0));
|
|
||||||
f(2 + 7 + undefined, 2 + 7 + void 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var f = console.log, o = {
|
|
||||||
undefined : 3,
|
|
||||||
NaN : 4,
|
|
||||||
Infinity : 5
|
|
||||||
};
|
|
||||||
if (o) {
|
|
||||||
f(void 0, void 0);
|
|
||||||
f(NaN, NaN);
|
|
||||||
f(1/0, 1/0);
|
|
||||||
f(-1/0, -1/0);
|
|
||||||
f(NaN, NaN);
|
|
||||||
}
|
|
||||||
with (o) {
|
|
||||||
f(undefined, void 0);
|
|
||||||
f(NaN, 0/0);
|
|
||||||
f(Infinity, 1/0);
|
|
||||||
f(-Infinity, -1/0);
|
|
||||||
f(9 + undefined, 9 + void 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
assorted_Infinity_NaN_undefined_in_with_scope_keep_infinity: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
hoist_funs: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
keep_fargs: true,
|
|
||||||
keep_infinity: true,
|
|
||||||
sequences: false,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var f = console.log;
|
|
||||||
var o = {
|
|
||||||
undefined : 3,
|
|
||||||
NaN : 4,
|
|
||||||
Infinity : 5,
|
|
||||||
};
|
|
||||||
if (o) {
|
|
||||||
f(undefined, void 0);
|
|
||||||
f(NaN, 0/0);
|
|
||||||
f(Infinity, 1/0);
|
|
||||||
f(-Infinity, -(1/0));
|
|
||||||
f(2 + 7 + undefined, 2 + 7 + void 0);
|
|
||||||
}
|
|
||||||
with (o) {
|
|
||||||
f(undefined, void 0);
|
|
||||||
f(NaN, 0/0);
|
|
||||||
f(Infinity, 1/0);
|
|
||||||
f(-Infinity, -(1/0));
|
|
||||||
f(2 + 7 + undefined, 2 + 7 + void 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var f = console.log, o = {
|
|
||||||
undefined : 3,
|
|
||||||
NaN : 4,
|
|
||||||
Infinity : 5
|
|
||||||
};
|
|
||||||
if (o) {
|
|
||||||
f(void 0, void 0);
|
|
||||||
f(NaN, NaN);
|
|
||||||
f(Infinity, 1/0);
|
|
||||||
f(-Infinity, -1/0);
|
|
||||||
f(NaN, NaN);
|
|
||||||
}
|
|
||||||
with (o) {
|
|
||||||
f(undefined, void 0);
|
|
||||||
f(NaN, 0/0);
|
|
||||||
f(Infinity, 1/0);
|
|
||||||
f(-Infinity, -1/0);
|
|
||||||
f(9 + undefined, 9 + void 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
@@ -1,62 +1,11 @@
|
|||||||
keep_name_of_getter: {
|
keep_name_of_getter: {
|
||||||
options = {
|
options = { unused: true };
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: { a = { get foo () {} } }
|
input: { a = { get foo () {} } }
|
||||||
expect: { a = { get foo () {} } }
|
expect: { a = { get foo () {} } }
|
||||||
}
|
}
|
||||||
|
|
||||||
keep_name_of_setter: {
|
keep_name_of_setter: {
|
||||||
options = {
|
options = { unused: true };
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: { a = { set foo () {} } }
|
input: { a = { set foo () {} } }
|
||||||
expect: { a = { set foo () {} } }
|
expect: { a = { set foo () {} } }
|
||||||
}
|
}
|
||||||
|
|
||||||
setter_with_operator_keys: {
|
|
||||||
input: {
|
|
||||||
var tokenCodes = {
|
|
||||||
get instanceof(){
|
|
||||||
return test0;
|
|
||||||
},
|
|
||||||
set instanceof(value){
|
|
||||||
test0 = value;
|
|
||||||
},
|
|
||||||
set typeof(value){
|
|
||||||
test1 = value;
|
|
||||||
},
|
|
||||||
get typeof(){
|
|
||||||
return test1;
|
|
||||||
},
|
|
||||||
set else(value){
|
|
||||||
test2 = value;
|
|
||||||
},
|
|
||||||
get else(){
|
|
||||||
return test2;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var tokenCodes = {
|
|
||||||
get instanceof(){
|
|
||||||
return test0;
|
|
||||||
},
|
|
||||||
set instanceof(value){
|
|
||||||
test0 = value;
|
|
||||||
},
|
|
||||||
set typeof(value){
|
|
||||||
test1 = value;
|
|
||||||
},
|
|
||||||
get typeof(){
|
|
||||||
return test1;
|
|
||||||
},
|
|
||||||
set else(value){
|
|
||||||
test2 = value;
|
|
||||||
},
|
|
||||||
get else(){
|
|
||||||
return test2;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
mangle_keep_fnames_false: {
|
|
||||||
options = {
|
|
||||||
keep_fargs: true,
|
|
||||||
keep_fnames: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
keep_fnames : false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
function total() {
|
|
||||||
return function n(a, b, c) {
|
|
||||||
return a + b + c;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
function total() {
|
|
||||||
return function t(n, r, u) {
|
|
||||||
return n + r + u;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_keep_fnames_true: {
|
|
||||||
options = {
|
|
||||||
keep_fargs: true,
|
|
||||||
keep_fnames: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
keep_fnames : true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
function total() {
|
|
||||||
return function n(a, b, c) {
|
|
||||||
return a + b + c;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
function total() {
|
|
||||||
return function n(t, r, u) {
|
|
||||||
return t + r + u;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,183 +0,0 @@
|
|||||||
pure_function_calls: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
evaluate: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
negate_iife: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
// pure top-level IIFE will be dropped
|
|
||||||
// @__PURE__ - comment
|
|
||||||
(function() {
|
|
||||||
console.log("iife0");
|
|
||||||
})();
|
|
||||||
|
|
||||||
// pure top-level IIFE assigned to unreferenced var will not be dropped
|
|
||||||
var iife1 = /*@__PURE__*/(function() {
|
|
||||||
console.log("iife1");
|
|
||||||
function iife1() {}
|
|
||||||
return iife1;
|
|
||||||
})();
|
|
||||||
|
|
||||||
(function(){
|
|
||||||
// pure IIFE in function scope assigned to unreferenced var will be dropped
|
|
||||||
var iife2 = /*#__PURE__*/(function() {
|
|
||||||
console.log("iife2");
|
|
||||||
function iife2() {}
|
|
||||||
return iife2;
|
|
||||||
})();
|
|
||||||
})();
|
|
||||||
|
|
||||||
// comment #__PURE__ comment
|
|
||||||
bar(), baz(), quux();
|
|
||||||
a.b(), /* @__PURE__ */ c.d.e(), f.g();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var iife1 = function() {
|
|
||||||
console.log("iife1");
|
|
||||||
function iife1() {}
|
|
||||||
return iife1;
|
|
||||||
}();
|
|
||||||
|
|
||||||
baz(), quux();
|
|
||||||
a.b(), f.g();
|
|
||||||
}
|
|
||||||
expect_warnings: [
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:3,8]",
|
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:3,8]",
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:16,37]",
|
|
||||||
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:16,16]",
|
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:14,8]",
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:24,8]",
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:25,31]",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
pure_function_calls_toplevel: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
evaluate: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
negate_iife: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
// pure top-level IIFE will be dropped
|
|
||||||
// @__PURE__ - comment
|
|
||||||
(function() {
|
|
||||||
console.log("iife0");
|
|
||||||
})();
|
|
||||||
|
|
||||||
// pure top-level IIFE assigned to unreferenced var will be dropped
|
|
||||||
var iife1 = /*@__PURE__*/(function() {
|
|
||||||
console.log("iife1");
|
|
||||||
function iife1() {}
|
|
||||||
return iife1;
|
|
||||||
})();
|
|
||||||
|
|
||||||
(function(){
|
|
||||||
// pure IIFE in function scope assigned to unreferenced var will be dropped
|
|
||||||
var iife2 = /*#__PURE__*/(function() {
|
|
||||||
console.log("iife2");
|
|
||||||
function iife2() {}
|
|
||||||
return iife2;
|
|
||||||
})();
|
|
||||||
})();
|
|
||||||
|
|
||||||
// pure top-level calls will be dropped regardless of the leading comments position
|
|
||||||
var MyClass = /*#__PURE__*//*@class*/(function(){
|
|
||||||
function MyClass() {}
|
|
||||||
MyClass.prototype.method = function() {};
|
|
||||||
return MyClass;
|
|
||||||
})();
|
|
||||||
|
|
||||||
// comment #__PURE__ comment
|
|
||||||
bar(), baz(), quux();
|
|
||||||
a.b(), /* @__PURE__ */ c.d.e(), f.g();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
baz(), quux();
|
|
||||||
a.b(), f.g();
|
|
||||||
}
|
|
||||||
expect_warnings: [
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:3,8]",
|
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:3,8]",
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:16,37]",
|
|
||||||
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:16,16]",
|
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:14,8]",
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:31,8]",
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:32,31]",
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:8,33]",
|
|
||||||
"WARN: Dropping unused variable iife1 [test/compress/issue-1261.js:8,12]",
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:24,45]",
|
|
||||||
"WARN: Dropping unused variable MyClass [test/compress/issue-1261.js:24,12]",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
should_warn: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
conditionals: true,
|
|
||||||
evaluate: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
/* @__PURE__ */(function(){x})(), void/* @__PURE__ */(function(){y})();
|
|
||||||
/* @__PURE__ */(function(){x})() || true ? foo() : bar();
|
|
||||||
true || /* @__PURE__ */(function(){y})() ? foo() : bar();
|
|
||||||
/* @__PURE__ */(function(){x})() && false ? foo() : bar();
|
|
||||||
false && /* @__PURE__ */(function(){y})() ? foo() : bar();
|
|
||||||
/* @__PURE__ */(function(){x})() + "foo" ? bar() : baz();
|
|
||||||
"foo" + /* @__PURE__ */(function(){y})() ? bar() : baz();
|
|
||||||
/* @__PURE__ */(function(){x})() ? foo() : foo();
|
|
||||||
[/* @__PURE__ */(function(){x})()] ? foo() : bar();
|
|
||||||
!{ foo: /* @__PURE__ */(function(){x})() } ? bar() : baz();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
foo();
|
|
||||||
foo();
|
|
||||||
bar();
|
|
||||||
bar();
|
|
||||||
bar();
|
|
||||||
bar();
|
|
||||||
foo();
|
|
||||||
foo();
|
|
||||||
baz();
|
|
||||||
}
|
|
||||||
expect_warnings: [
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:1,61]",
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:1,23]",
|
|
||||||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:1,23]",
|
|
||||||
"WARN: Boolean || always true [test/compress/issue-1261.js:2,23]",
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:2,23]",
|
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:2,23]",
|
|
||||||
"WARN: Condition left of || always true [test/compress/issue-1261.js:3,8]",
|
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:3,8]",
|
|
||||||
"WARN: Boolean && always false [test/compress/issue-1261.js:4,23]",
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:4,23]",
|
|
||||||
"WARN: Condition always false [test/compress/issue-1261.js:4,23]",
|
|
||||||
"WARN: Condition left of && always false [test/compress/issue-1261.js:5,8]",
|
|
||||||
"WARN: Condition always false [test/compress/issue-1261.js:5,8]",
|
|
||||||
"WARN: + in boolean context always true [test/compress/issue-1261.js:6,23]",
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:6,23]",
|
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:6,23]",
|
|
||||||
"WARN: + in boolean context always true [test/compress/issue-1261.js:7,8]",
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:7,31]",
|
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:7,8]",
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:8,23]",
|
|
||||||
"WARN: Condition always true [test/compress/issue-1261.js:9,8]",
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:9,24]",
|
|
||||||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:10,31]",
|
|
||||||
"WARN: Condition always false [test/compress/issue-1261.js:10,8]",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
string_plus_optimization: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
hoist_funs: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function foo(anything) {
|
|
||||||
function throwing_function() {
|
|
||||||
throw "nope";
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
console.log('0' + throwing_function() ? "yes" : "no");
|
|
||||||
} catch (ex) {
|
|
||||||
console.log(ex);
|
|
||||||
}
|
|
||||||
console.log('0' + anything ? "yes" : "no");
|
|
||||||
console.log(anything + '0' ? "Yes" : "No");
|
|
||||||
console.log('' + anything);
|
|
||||||
console.log(anything + '');
|
|
||||||
}
|
|
||||||
foo();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function foo(anything) {
|
|
||||||
function throwing_function() {
|
|
||||||
throw "nope";
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
console.log((throwing_function(), "yes"));
|
|
||||||
} catch (ex) {
|
|
||||||
console.log(ex);
|
|
||||||
}
|
|
||||||
console.log("yes");
|
|
||||||
console.log("Yes");
|
|
||||||
console.log('' + anything);
|
|
||||||
console.log(anything + '');
|
|
||||||
}
|
|
||||||
foo();
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
issue_1321_no_debug: {
|
|
||||||
mangle = {
|
|
||||||
properties: {
|
|
||||||
keep_quoted: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var x = {};
|
|
||||||
x.foo = 1;
|
|
||||||
x["a"] = 2 * x.foo;
|
|
||||||
console.log(x.foo, x["a"]);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var x = {};
|
|
||||||
x.x = 1;
|
|
||||||
x["a"] = 2 * x.x;
|
|
||||||
console.log(x.x, x["a"]);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1321_debug: {
|
|
||||||
mangle = {
|
|
||||||
properties: {
|
|
||||||
debug: "",
|
|
||||||
keep_quoted: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var x = {};
|
|
||||||
x.foo = 1;
|
|
||||||
x["_$foo$_"] = 2 * x.foo;
|
|
||||||
console.log(x.foo, x["_$foo$_"]);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var x = {};
|
|
||||||
x.x = 1;
|
|
||||||
x["_$foo$_"] = 2 * x.x;
|
|
||||||
console.log(x.x, x["_$foo$_"]);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1321_with_quoted: {
|
|
||||||
mangle = {
|
|
||||||
properties: {
|
|
||||||
keep_quoted: false,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var x = {};
|
|
||||||
x.foo = 1;
|
|
||||||
x["a"] = 2 * x.foo;
|
|
||||||
console.log(x.foo, x["a"]);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var x = {};
|
|
||||||
x.x = 1;
|
|
||||||
x["o"] = 2 * x.x;
|
|
||||||
console.log(x.x, x["o"]);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
tranformation_sort_order_equal: {
|
tranformation_sort_order_equal: {
|
||||||
options = {
|
options = {
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
}
|
};
|
||||||
|
|
||||||
input: { (a = parseInt('100')) == a }
|
input: { (a = parseInt('100')) == a }
|
||||||
expect: { (a = parseInt('100')) == a }
|
expect: { (a = parseInt('100')) == a }
|
||||||
@@ -24,7 +24,7 @@ tranformation_sort_order_equal: {
|
|||||||
tranformation_sort_order_unequal: {
|
tranformation_sort_order_unequal: {
|
||||||
options = {
|
options = {
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
}
|
};
|
||||||
|
|
||||||
input: { (a = parseInt('100')) != a }
|
input: { (a = parseInt('100')) != a }
|
||||||
expect: { (a = parseInt('100')) != a }
|
expect: { (a = parseInt('100')) != a }
|
||||||
@@ -33,7 +33,7 @@ tranformation_sort_order_unequal: {
|
|||||||
tranformation_sort_order_lesser_or_equal: {
|
tranformation_sort_order_lesser_or_equal: {
|
||||||
options = {
|
options = {
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
}
|
};
|
||||||
|
|
||||||
input: { (a = parseInt('100')) <= a }
|
input: { (a = parseInt('100')) <= a }
|
||||||
expect: { (a = parseInt('100')) <= a }
|
expect: { (a = parseInt('100')) <= a }
|
||||||
@@ -41,7 +41,7 @@ tranformation_sort_order_lesser_or_equal: {
|
|||||||
tranformation_sort_order_greater_or_equal: {
|
tranformation_sort_order_greater_or_equal: {
|
||||||
options = {
|
options = {
|
||||||
comparisons: true,
|
comparisons: true,
|
||||||
}
|
};
|
||||||
|
|
||||||
input: { (a = parseInt('100')) >= a }
|
input: { (a = parseInt('100')) >= a }
|
||||||
expect: { (a = parseInt('100')) >= a }
|
expect: { (a = parseInt('100')) >= a }
|
||||||
|
|||||||
@@ -1,151 +0,0 @@
|
|||||||
level_zero: {
|
|
||||||
options = {
|
|
||||||
keep_fnames: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
keep_fnames: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(x) {
|
|
||||||
function n(a) {
|
|
||||||
return a * a;
|
|
||||||
}
|
|
||||||
return function() {
|
|
||||||
return x;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(r) {
|
|
||||||
function n(n) {
|
|
||||||
return n * n;
|
|
||||||
}
|
|
||||||
return function() {
|
|
||||||
return r;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
level_one: {
|
|
||||||
options = {
|
|
||||||
keep_fnames: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
keep_fnames: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(x) {
|
|
||||||
return function() {
|
|
||||||
function n(a) {
|
|
||||||
return a * a;
|
|
||||||
}
|
|
||||||
return x(n);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(r) {
|
|
||||||
return function() {
|
|
||||||
function n(n) {
|
|
||||||
return n * n;
|
|
||||||
}
|
|
||||||
return r(n);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
level_two: {
|
|
||||||
options = {
|
|
||||||
keep_fnames: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
keep_fnames: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(x) {
|
|
||||||
return function() {
|
|
||||||
function r(a) {
|
|
||||||
return a * a;
|
|
||||||
}
|
|
||||||
return function() {
|
|
||||||
function n(a) {
|
|
||||||
return a * a;
|
|
||||||
}
|
|
||||||
return x(n);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(t) {
|
|
||||||
return function() {
|
|
||||||
function r(n) {
|
|
||||||
return n * n;
|
|
||||||
}
|
|
||||||
return function() {
|
|
||||||
function n(n) {
|
|
||||||
return n * n;
|
|
||||||
}
|
|
||||||
return t(n);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
level_three: {
|
|
||||||
options = {
|
|
||||||
keep_fnames: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
keep_fnames: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(x) {
|
|
||||||
return function() {
|
|
||||||
function r(a) {
|
|
||||||
return a * a;
|
|
||||||
}
|
|
||||||
return [
|
|
||||||
function() {
|
|
||||||
function t(a) {
|
|
||||||
return a * a;
|
|
||||||
}
|
|
||||||
return t;
|
|
||||||
},
|
|
||||||
function() {
|
|
||||||
function n(a) {
|
|
||||||
return a * a;
|
|
||||||
}
|
|
||||||
return x(n);
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(t) {
|
|
||||||
return function() {
|
|
||||||
function r(n) {
|
|
||||||
return n * n;
|
|
||||||
}
|
|
||||||
return [
|
|
||||||
function() {
|
|
||||||
function t(n) {
|
|
||||||
return n * n;
|
|
||||||
}
|
|
||||||
return t;
|
|
||||||
},
|
|
||||||
function() {
|
|
||||||
function n(n) {
|
|
||||||
return n * n;
|
|
||||||
}
|
|
||||||
return t(n);
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
// tests assume that variable `undefined` not redefined and has `void 0` as value
|
|
||||||
|
|
||||||
unsafe_undefined: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
if_return: true,
|
|
||||||
unsafe_undefined: true,
|
|
||||||
}
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
function f(undefined) {
|
|
||||||
return function() {
|
|
||||||
if (a)
|
|
||||||
return b;
|
|
||||||
if (c)
|
|
||||||
return d;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(n) {
|
|
||||||
return function() {
|
|
||||||
return a ? b : c ? d : n;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keep_fnames: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
if_return: true,
|
|
||||||
unsafe_undefined: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
keep_fnames: true
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(undefined) {
|
|
||||||
return function() {
|
|
||||||
function n(a) {
|
|
||||||
return a * a;
|
|
||||||
}
|
|
||||||
if (a)
|
|
||||||
return b;
|
|
||||||
if (c)
|
|
||||||
return d;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(r) {
|
|
||||||
return function() {
|
|
||||||
function n(n) {
|
|
||||||
return n * n;
|
|
||||||
}
|
|
||||||
return a ? b : c ? d : r;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
typeof_eq_undefined: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
typeofs: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = typeof b != "undefined";
|
|
||||||
b = typeof a != "undefined";
|
|
||||||
var c = typeof d.e !== "undefined";
|
|
||||||
var f = "undefined" === typeof g;
|
|
||||||
g = "undefined" === typeof f;
|
|
||||||
var h = "undefined" == typeof i.j;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = "undefined" != typeof b;
|
|
||||||
b = void 0 !== a;
|
|
||||||
var c = void 0 !== d.e;
|
|
||||||
var f = "undefined" == typeof g;
|
|
||||||
g = void 0 === f;
|
|
||||||
var h = void 0 === i.j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typeof_eq_undefined_ie8: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
ie8: true,
|
|
||||||
typeofs: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = typeof b != "undefined";
|
|
||||||
b = typeof a != "undefined";
|
|
||||||
var c = typeof d.e !== "undefined";
|
|
||||||
var f = "undefined" === typeof g;
|
|
||||||
g = "undefined" === typeof f;
|
|
||||||
var h = "undefined" == typeof i.j;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = "undefined" != typeof b;
|
|
||||||
b = void 0 !== a;
|
|
||||||
var c = "undefined" != typeof d.e;
|
|
||||||
var f = "undefined" == typeof g;
|
|
||||||
g = void 0 === f;
|
|
||||||
var h = "undefined" == typeof i.j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
undefined_redefined: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
typeofs: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(undefined) {
|
|
||||||
var n = 1;
|
|
||||||
return typeof n == "undefined";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: "function f(undefined){var n=1;return void 0===n}"
|
|
||||||
}
|
|
||||||
|
|
||||||
undefined_redefined_mangle: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
typeofs: true,
|
|
||||||
}
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
function f(undefined) {
|
|
||||||
var n = 1;
|
|
||||||
return typeof n == "undefined";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: "function f(n){var r=1;return void 0===r}"
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
else_with_empty_block: {
|
|
||||||
options = {}
|
|
||||||
input: {
|
|
||||||
if (x)
|
|
||||||
yes();
|
|
||||||
else {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: "if(x)yes();"
|
|
||||||
}
|
|
||||||
|
|
||||||
else_with_empty_statement: {
|
|
||||||
options = {}
|
|
||||||
input: {
|
|
||||||
if (x)
|
|
||||||
yes();
|
|
||||||
else
|
|
||||||
;
|
|
||||||
}
|
|
||||||
expect_exact: "if(x)yes();"
|
|
||||||
}
|
|
||||||
|
|
||||||
conditional_false_stray_else_in_loop: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: false,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
hoist_vars: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
loops: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
for (var i = 1; i <= 4; ++i) {
|
|
||||||
if (i <= 2) continue;
|
|
||||||
console.log(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: "for(var i=1;i<=4;++i)if(!(i<=2))console.log(i);"
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
inner_reference: {
|
|
||||||
options = {
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
!function f(a) {
|
|
||||||
return a && f(a - 1) + a;
|
|
||||||
}(42);
|
|
||||||
!function g(a) {
|
|
||||||
return a;
|
|
||||||
}(42);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
!function f(a) {
|
|
||||||
return a && f(a - 1) + a;
|
|
||||||
}(42);
|
|
||||||
!void 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
screw_ie8: {
|
|
||||||
options = {
|
|
||||||
ie8: false,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
ie8: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
try { throw "foo"; } catch (x) { console.log(x); }
|
|
||||||
}
|
|
||||||
expect_exact: 'try{throw"foo"}catch(o){console.log(o)}'
|
|
||||||
expect_stdout: [
|
|
||||||
"foo"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
support_ie8: {
|
|
||||||
options = {
|
|
||||||
ie8: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
try { throw "foo"; } catch (x) { console.log(x); }
|
|
||||||
}
|
|
||||||
expect_exact: 'try{throw"foo"}catch(x){console.log(x)}'
|
|
||||||
expect_stdout: "foo"
|
|
||||||
}
|
|
||||||
|
|
||||||
safe_undefined: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
if_return: true,
|
|
||||||
unsafe: false,
|
|
||||||
}
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
var a, c;
|
|
||||||
console.log(function(undefined) {
|
|
||||||
return function() {
|
|
||||||
if (a)
|
|
||||||
return b;
|
|
||||||
if (c)
|
|
||||||
return d;
|
|
||||||
};
|
|
||||||
}(1)());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a, c;
|
|
||||||
console.log(function(n) {
|
|
||||||
return function() {
|
|
||||||
return a ? b : c ? d : void 0;
|
|
||||||
};
|
|
||||||
}(1)());
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe_undefined: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
if_return: true,
|
|
||||||
unsafe_undefined: true,
|
|
||||||
}
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
var a, c;
|
|
||||||
console.log(function(undefined) {
|
|
||||||
return function() {
|
|
||||||
if (a)
|
|
||||||
return b;
|
|
||||||
if (c)
|
|
||||||
return d;
|
|
||||||
};
|
|
||||||
}()());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a, c;
|
|
||||||
console.log(function(n) {
|
|
||||||
return function() {
|
|
||||||
return a ? b : c ? d : n;
|
|
||||||
};
|
|
||||||
}()());
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
chained_evaluation_1: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
evaluate: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
var a = 1;
|
|
||||||
(function() {
|
|
||||||
var b = a, c;
|
|
||||||
c = f(b);
|
|
||||||
c.bar = b;
|
|
||||||
})();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function() {
|
|
||||||
(function() {
|
|
||||||
f(1).bar = 1;
|
|
||||||
})();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
chained_evaluation_2: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
evaluate: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
var a = "long piece of string";
|
|
||||||
(function() {
|
|
||||||
var b = a, c;
|
|
||||||
c = f(b);
|
|
||||||
c.bar = b;
|
|
||||||
})();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function() {
|
|
||||||
(function() {
|
|
||||||
var b = "long piece of string";
|
|
||||||
f(b).bar = b;
|
|
||||||
})();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
chained_evaluation_3: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
evaluate: 10,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
var a = "long piece of string";
|
|
||||||
(function() {
|
|
||||||
var b = a, c;
|
|
||||||
c = f(b);
|
|
||||||
c.bar = b;
|
|
||||||
})();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function() {
|
|
||||||
(function() {
|
|
||||||
f("long piece of string").bar = "long piece of string";
|
|
||||||
})();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
issue_1639_1: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
conditionals: true,
|
|
||||||
evaluate: true,
|
|
||||||
join_vars: true,
|
|
||||||
loops: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = 100, b = 10;
|
|
||||||
var L1 = 5;
|
|
||||||
while (--L1 > 0) {
|
|
||||||
if ((--b), false) {
|
|
||||||
if (b) {
|
|
||||||
var ignore = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.log(a, b);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
for (var a = 100, b = 10, L1 = 5, ignore; --L1 > 0;) {
|
|
||||||
--b;
|
|
||||||
}
|
|
||||||
console.log(a, b);
|
|
||||||
}
|
|
||||||
expect_stdout: "100 6"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1639_2: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
conditionals: true,
|
|
||||||
evaluate: true,
|
|
||||||
join_vars: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = 100, b = 10;
|
|
||||||
function f19() {
|
|
||||||
if (++a, false)
|
|
||||||
if (a)
|
|
||||||
if (++a);
|
|
||||||
}
|
|
||||||
f19();
|
|
||||||
console.log(a, b);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = 100, b = 10;
|
|
||||||
function f19() {
|
|
||||||
++a, 1;
|
|
||||||
}
|
|
||||||
f19(),
|
|
||||||
console.log(a, b);
|
|
||||||
}
|
|
||||||
expect_stdout: "101 10"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1639_3: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
conditionals: true,
|
|
||||||
evaluate: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = 100, b = 10;
|
|
||||||
a++ && false && a ? 0 : 0;
|
|
||||||
console.log(a, b);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = 100, b = 10;
|
|
||||||
a++,
|
|
||||||
console.log(a, b);
|
|
||||||
}
|
|
||||||
expect_stdout: "101 10"
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
f7: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
drop_debugger: true,
|
|
||||||
evaluate: true,
|
|
||||||
hoist_funs: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
loops: true,
|
|
||||||
negate_iife: true,
|
|
||||||
passes: 3,
|
|
||||||
properties: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
beautify: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = 100, b = 10;
|
|
||||||
function f22464() {
|
|
||||||
var brake146670 = 5;
|
|
||||||
while (((b = a) ? !a : ~a ? null : b += a) && --brake146670 > 0) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f22464();
|
|
||||||
console.log(a, b);
|
|
||||||
}
|
|
||||||
expect_exact: [
|
|
||||||
"console.log(100, 100);",
|
|
||||||
]
|
|
||||||
expect_stdout: "100 100"
|
|
||||||
}
|
|
||||||
@@ -1,166 +0,0 @@
|
|||||||
side_effects_catch: {
|
|
||||||
options = {
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
function g() {
|
|
||||||
try {
|
|
||||||
throw 0;
|
|
||||||
} catch (e) {
|
|
||||||
console.log("PASS");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g();
|
|
||||||
}
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f() {
|
|
||||||
(function() {
|
|
||||||
try {
|
|
||||||
throw 0;
|
|
||||||
} catch (e) {
|
|
||||||
console.log("PASS");
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
side_effects_else: {
|
|
||||||
options = {
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(x) {
|
|
||||||
function g() {
|
|
||||||
if (x);
|
|
||||||
else console.log("PASS");
|
|
||||||
}
|
|
||||||
g();
|
|
||||||
}
|
|
||||||
f(0);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(x) {
|
|
||||||
(function() {
|
|
||||||
if (x);
|
|
||||||
else console.log("PASS");
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
f(0);
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
side_effects_finally: {
|
|
||||||
options = {
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
function g() {
|
|
||||||
try {
|
|
||||||
x();
|
|
||||||
} catch (e) {
|
|
||||||
} finally {
|
|
||||||
console.log("PASS");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g();
|
|
||||||
}
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f() {
|
|
||||||
(function() {
|
|
||||||
try {
|
|
||||||
x();
|
|
||||||
} catch (e) {
|
|
||||||
} finally {
|
|
||||||
console.log("PASS");
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
side_effects_label: {
|
|
||||||
options = {
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(x) {
|
|
||||||
function g() {
|
|
||||||
L: {
|
|
||||||
console.log("PASS");
|
|
||||||
break L;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g();
|
|
||||||
}
|
|
||||||
f(0);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f(x) {
|
|
||||||
(function() {
|
|
||||||
L: {
|
|
||||||
console.log("PASS");
|
|
||||||
break L;
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
f(0);
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
side_effects_switch: {
|
|
||||||
options = {
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
function g() {
|
|
||||||
switch (0) {
|
|
||||||
default:
|
|
||||||
case console.log("PASS"):
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g();
|
|
||||||
}
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f() {
|
|
||||||
(function() {
|
|
||||||
switch (0) {
|
|
||||||
default:
|
|
||||||
case console.log("PASS"):
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
@@ -1,439 +0,0 @@
|
|||||||
mangle_catch: {
|
|
||||||
options = {
|
|
||||||
ie8: false,
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
ie8: false,
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = "FAIL";
|
|
||||||
try {
|
|
||||||
throw 1;
|
|
||||||
} catch (args) {
|
|
||||||
a = "PASS";
|
|
||||||
}
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_exact: 'var a="FAIL";try{throw 1}catch(o){a="PASS"}console.log(a);'
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_ie8: {
|
|
||||||
options = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = "FAIL";
|
|
||||||
try {
|
|
||||||
throw 1;
|
|
||||||
} catch (args) {
|
|
||||||
a = "PASS";
|
|
||||||
}
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_exact: 'var a="FAIL";try{throw 1}catch(args){a="PASS"}console.log(a);'
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_var: {
|
|
||||||
options = {
|
|
||||||
ie8: false,
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
ie8: false,
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = "FAIL";
|
|
||||||
try {
|
|
||||||
throw 1;
|
|
||||||
} catch (args) {
|
|
||||||
var a = "PASS";
|
|
||||||
}
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_exact: 'var a="FAIL";try{throw 1}catch(o){var a="PASS"}console.log(a);'
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_var_ie8: {
|
|
||||||
options = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = "FAIL";
|
|
||||||
try {
|
|
||||||
throw 1;
|
|
||||||
} catch (args) {
|
|
||||||
var a = "PASS";
|
|
||||||
}
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_exact: 'var a="FAIL";try{throw 1}catch(args){var a="PASS"}console.log(a);'
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_toplevel: {
|
|
||||||
options = {
|
|
||||||
ie8: false,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
ie8: false,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = "FAIL";
|
|
||||||
try {
|
|
||||||
throw 1;
|
|
||||||
} catch (args) {
|
|
||||||
a = "PASS";
|
|
||||||
}
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_exact: 'var c="FAIL";try{throw 1}catch(o){c="PASS"}console.log(c);'
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_ie8_toplevel: {
|
|
||||||
options = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = "FAIL";
|
|
||||||
try {
|
|
||||||
throw 1;
|
|
||||||
} catch (args) {
|
|
||||||
a = "PASS";
|
|
||||||
}
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_exact: 'var o="FAIL";try{throw 1}catch(c){o="PASS"}console.log(o);'
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_var_toplevel: {
|
|
||||||
options = {
|
|
||||||
ie8: false,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
ie8: false,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = "FAIL";
|
|
||||||
try {
|
|
||||||
throw 1;
|
|
||||||
} catch (args) {
|
|
||||||
var a = "PASS";
|
|
||||||
}
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_exact: 'var r="FAIL";try{throw 1}catch(o){var r="PASS"}console.log(r);'
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_var_ie8_toplevel: {
|
|
||||||
options = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = "FAIL";
|
|
||||||
try {
|
|
||||||
throw 1;
|
|
||||||
} catch (args) {
|
|
||||||
var a = "PASS";
|
|
||||||
}
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_exact: 'var o="FAIL";try{throw 1}catch(r){var o="PASS"}console.log(o);'
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_redef_1: {
|
|
||||||
options = {
|
|
||||||
ie8: false,
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
ie8: false,
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = "PASS";
|
|
||||||
try {
|
|
||||||
throw "FAIL1";
|
|
||||||
} catch (a) {
|
|
||||||
var a = "FAIL2";
|
|
||||||
}
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_exact: 'var a="PASS";try{throw"FAIL1"}catch(a){var a="FAIL2"}console.log(a);'
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_redef_1_ie8: {
|
|
||||||
options = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = "PASS";
|
|
||||||
try {
|
|
||||||
throw "FAIL1";
|
|
||||||
} catch (a) {
|
|
||||||
var a = "FAIL2";
|
|
||||||
}
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_exact: 'var a="PASS";try{throw"FAIL1"}catch(a){var a="FAIL2"}console.log(a);'
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_redef_1_toplevel: {
|
|
||||||
options = {
|
|
||||||
ie8: false,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
ie8: false,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = "PASS";
|
|
||||||
try {
|
|
||||||
throw "FAIL1";
|
|
||||||
} catch (a) {
|
|
||||||
var a = "FAIL2";
|
|
||||||
}
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_exact: 'var o="PASS";try{throw"FAIL1"}catch(o){var o="FAIL2"}console.log(o);'
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_redef_1_ie8_toplevel: {
|
|
||||||
options = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = "PASS";
|
|
||||||
try {
|
|
||||||
throw "FAIL1";
|
|
||||||
} catch (a) {
|
|
||||||
var a = "FAIL2";
|
|
||||||
}
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_exact: 'var o="PASS";try{throw"FAIL1"}catch(o){var o="FAIL2"}console.log(o);'
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_redef_2: {
|
|
||||||
options = {
|
|
||||||
ie8: false,
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
ie8: false,
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
try {
|
|
||||||
throw "FAIL1";
|
|
||||||
} catch (a) {
|
|
||||||
var a = "FAIL2";
|
|
||||||
}
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_exact: 'try{throw"FAIL1"}catch(a){var a="FAIL2"}console.log(a);'
|
|
||||||
expect_stdout: "undefined"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_redef_2_ie8: {
|
|
||||||
options = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
try {
|
|
||||||
throw "FAIL1";
|
|
||||||
} catch (a) {
|
|
||||||
var a = "FAIL2";
|
|
||||||
}
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_exact: 'try{throw"FAIL1"}catch(a){var a="FAIL2"}console.log(a);'
|
|
||||||
expect_stdout: "undefined"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_redef_2_toplevel: {
|
|
||||||
options = {
|
|
||||||
ie8: false,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
ie8: false,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
try {
|
|
||||||
throw "FAIL1";
|
|
||||||
} catch (a) {
|
|
||||||
var a = "FAIL2";
|
|
||||||
}
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_exact: 'try{throw"FAIL1"}catch(o){var o="FAIL2"}console.log(o);'
|
|
||||||
expect_stdout: "undefined"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_redef_2_ie8_toplevel: {
|
|
||||||
options = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
try {
|
|
||||||
throw "FAIL1";
|
|
||||||
} catch (a) {
|
|
||||||
var a = "FAIL2";
|
|
||||||
}
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_exact: 'try{throw"FAIL1"}catch(o){var o="FAIL2"}console.log(o);'
|
|
||||||
expect_stdout: "undefined"
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_redef_3: {
|
|
||||||
mangle = {
|
|
||||||
ie8: false,
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = "PASS";
|
|
||||||
try {
|
|
||||||
throw 0;
|
|
||||||
} catch (o) {
|
|
||||||
(function() {
|
|
||||||
function f() {
|
|
||||||
o = "FAIL";
|
|
||||||
}
|
|
||||||
f(), f();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
console.log(o);
|
|
||||||
}
|
|
||||||
expect_exact: 'var o="PASS";try{throw 0}catch(o){(function(){function c(){o="FAIL"}c(),c()})()}console.log(o);'
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_redef_3_toplevel: {
|
|
||||||
mangle = {
|
|
||||||
ie8: false,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = "PASS";
|
|
||||||
try {
|
|
||||||
throw 0;
|
|
||||||
} catch (o) {
|
|
||||||
(function() {
|
|
||||||
function f() {
|
|
||||||
o = "FAIL";
|
|
||||||
}
|
|
||||||
f(), f();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
console.log(o);
|
|
||||||
}
|
|
||||||
expect_exact: 'var c="PASS";try{throw 0}catch(c){(function(){function o(){c="FAIL"}o(),o()})()}console.log(c);'
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_redef_3_ie8: {
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = "PASS";
|
|
||||||
try {
|
|
||||||
throw 0;
|
|
||||||
} catch (o) {
|
|
||||||
(function() {
|
|
||||||
function f() {
|
|
||||||
o = "FAIL";
|
|
||||||
}
|
|
||||||
f(), f();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
console.log(o);
|
|
||||||
}
|
|
||||||
expect_exact: 'var o="PASS";try{throw 0}catch(o){(function(){function c(){o="FAIL"}c(),c()})()}console.log(o);'
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
mangle_catch_redef_3_ie8_toplevel: {
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = "PASS";
|
|
||||||
try {
|
|
||||||
throw 0;
|
|
||||||
} catch (o) {
|
|
||||||
(function() {
|
|
||||||
function f() {
|
|
||||||
o = "FAIL";
|
|
||||||
}
|
|
||||||
f(), f();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
console.log(o);
|
|
||||||
}
|
|
||||||
expect_exact: 'var c="PASS";try{throw 0}catch(c){(function(){function o(){c="FAIL"}o(),o()})()}console.log(c);'
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
function_iife_catch: {
|
|
||||||
mangle = {
|
|
||||||
ie8: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(n) {
|
|
||||||
!function() {
|
|
||||||
try {
|
|
||||||
throw 0;
|
|
||||||
} catch (n) {
|
|
||||||
var a = 1;
|
|
||||||
console.log(n, a);
|
|
||||||
}
|
|
||||||
}();
|
|
||||||
}
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
expect_exact: "function f(o){!function(){try{throw 0}catch(o){var c=1;console.log(o,c)}}()}f();"
|
|
||||||
expect_stdout: "0 1"
|
|
||||||
}
|
|
||||||
|
|
||||||
function_iife_catch_ie8: {
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f(n) {
|
|
||||||
!function() {
|
|
||||||
try {
|
|
||||||
throw 0;
|
|
||||||
} catch (n) {
|
|
||||||
var a = 1;
|
|
||||||
console.log(n, a);
|
|
||||||
}
|
|
||||||
}();
|
|
||||||
}
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
expect_exact: "function f(c){!function(){try{throw 0}catch(c){var o=1;console.log(c,o)}}()}f();"
|
|
||||||
expect_stdout: "0 1"
|
|
||||||
}
|
|
||||||
|
|
||||||
function_catch_catch: {
|
|
||||||
mangle = {
|
|
||||||
ie8: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = 0;
|
|
||||||
function f() {
|
|
||||||
try {
|
|
||||||
throw 1;
|
|
||||||
} catch (c) {
|
|
||||||
try {
|
|
||||||
throw 2;
|
|
||||||
} catch (o) {
|
|
||||||
var o = 3;
|
|
||||||
console.log(o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.log(o);
|
|
||||||
}
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
expect_exact: "var o=0;function f(){try{throw 1}catch(o){try{throw 2}catch(c){var c=3;console.log(c)}}console.log(c)}f();"
|
|
||||||
expect_stdout: [
|
|
||||||
"3",
|
|
||||||
"undefined",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
function_catch_catch_ie8: {
|
|
||||||
mangle = {
|
|
||||||
ie8: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var o = 0;
|
|
||||||
function f() {
|
|
||||||
try {
|
|
||||||
throw 1;
|
|
||||||
} catch (c) {
|
|
||||||
try {
|
|
||||||
throw 2;
|
|
||||||
} catch (o) {
|
|
||||||
var o = 3;
|
|
||||||
console.log(o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.log(o);
|
|
||||||
}
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
expect_exact: "var o=0;function f(){try{throw 1}catch(c){try{throw 2}catch(o){var o=3;console.log(o)}}console.log(o)}f();"
|
|
||||||
expect_stdout: [
|
|
||||||
"3",
|
|
||||||
"undefined",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
case_1: {
|
|
||||||
options = {
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
switches: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = 0, b = 1;
|
|
||||||
switch (true) {
|
|
||||||
case a || true:
|
|
||||||
default:
|
|
||||||
b = 2;
|
|
||||||
case true:
|
|
||||||
}
|
|
||||||
console.log(a, b);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = 0, b = 1;
|
|
||||||
switch (true) {
|
|
||||||
case a || true:
|
|
||||||
b = 2;
|
|
||||||
}
|
|
||||||
console.log(a, b);
|
|
||||||
}
|
|
||||||
expect_stdout: "0 2"
|
|
||||||
}
|
|
||||||
|
|
||||||
case_2: {
|
|
||||||
options = {
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
switches: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = 0, b = 1;
|
|
||||||
switch (0) {
|
|
||||||
default:
|
|
||||||
b = 2;
|
|
||||||
case a:
|
|
||||||
a = 3;
|
|
||||||
case 0:
|
|
||||||
}
|
|
||||||
console.log(a, b);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = 0, b = 1;
|
|
||||||
switch (0) {
|
|
||||||
case a:
|
|
||||||
a = 3;
|
|
||||||
}
|
|
||||||
console.log(a, b);
|
|
||||||
}
|
|
||||||
expect_stdout: "3 1"
|
|
||||||
}
|
|
||||||
@@ -1,245 +0,0 @@
|
|||||||
mangle_props: {
|
|
||||||
mangle = {
|
|
||||||
properties: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var obj = {
|
|
||||||
undefined: 1,
|
|
||||||
NaN: 2,
|
|
||||||
Infinity: 3,
|
|
||||||
"-Infinity": 4,
|
|
||||||
null: 5,
|
|
||||||
};
|
|
||||||
console.log(
|
|
||||||
obj[void 0],
|
|
||||||
obj[undefined],
|
|
||||||
obj["undefined"],
|
|
||||||
obj[0/0],
|
|
||||||
obj[NaN],
|
|
||||||
obj["NaN"],
|
|
||||||
obj[1/0],
|
|
||||||
obj[Infinity],
|
|
||||||
obj["Infinity"],
|
|
||||||
obj[-1/0],
|
|
||||||
obj[-Infinity],
|
|
||||||
obj["-Infinity"],
|
|
||||||
obj[null],
|
|
||||||
obj["null"]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var obj = {
|
|
||||||
undefined: 1,
|
|
||||||
NaN: 2,
|
|
||||||
Infinity: 3,
|
|
||||||
"-Infinity": 4,
|
|
||||||
null: 5,
|
|
||||||
};
|
|
||||||
console.log(
|
|
||||||
obj[void 0],
|
|
||||||
obj[void 0],
|
|
||||||
obj["undefined"],
|
|
||||||
obj[0/0],
|
|
||||||
obj[NaN],
|
|
||||||
obj["NaN"],
|
|
||||||
obj[1/0],
|
|
||||||
obj[1/0],
|
|
||||||
obj["Infinity"],
|
|
||||||
obj[-1/0],
|
|
||||||
obj[-(1/0)],
|
|
||||||
obj["-Infinity"],
|
|
||||||
obj[null],
|
|
||||||
obj["null"]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect_stdout: "1 1 1 2 2 2 3 3 3 4 4 4 5 5"
|
|
||||||
}
|
|
||||||
|
|
||||||
numeric_literal: {
|
|
||||||
mangle = {
|
|
||||||
properties: true,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
beautify: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var obj = {
|
|
||||||
0: 0,
|
|
||||||
"-0": 1,
|
|
||||||
42: 2,
|
|
||||||
"42": 3,
|
|
||||||
0x25: 4,
|
|
||||||
"0x25": 5,
|
|
||||||
1E42: 6,
|
|
||||||
"1E42": 7,
|
|
||||||
"1e+42": 8,
|
|
||||||
};
|
|
||||||
console.log(obj[-0], obj[-""], obj["-0"]);
|
|
||||||
console.log(obj[42], obj["42"]);
|
|
||||||
console.log(obj[0x25], obj["0x25"], obj[37], obj["37"]);
|
|
||||||
console.log(obj[1E42], obj["1E42"], obj["1e+42"]);
|
|
||||||
}
|
|
||||||
expect_exact: [
|
|
||||||
'var obj = {',
|
|
||||||
' 0: 0,',
|
|
||||||
' "-0": 1,',
|
|
||||||
' 42: 2,',
|
|
||||||
' 42: 3,',
|
|
||||||
' 37: 4,',
|
|
||||||
' o: 5,',
|
|
||||||
' 1e42: 6,',
|
|
||||||
' b: 7,',
|
|
||||||
' 1e42: 8',
|
|
||||||
'};',
|
|
||||||
'',
|
|
||||||
'console.log(obj[-0], obj[-""], obj["-0"]);',
|
|
||||||
'',
|
|
||||||
'console.log(obj[42], obj["42"]);',
|
|
||||||
'',
|
|
||||||
'console.log(obj[37], obj["o"], obj[37], obj["37"]);',
|
|
||||||
'',
|
|
||||||
'console.log(obj[1e42], obj["b"], obj["1e+42"]);',
|
|
||||||
]
|
|
||||||
expect_stdout: [
|
|
||||||
"0 0 1",
|
|
||||||
"3 3",
|
|
||||||
"4 5 4 4",
|
|
||||||
"8 7 8",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
identifier: {
|
|
||||||
mangle = {
|
|
||||||
properties: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var obj = {
|
|
||||||
abstract: 1,
|
|
||||||
boolean: 2,
|
|
||||||
byte: 3,
|
|
||||||
char: 4,
|
|
||||||
class: 5,
|
|
||||||
double: 6,
|
|
||||||
enum: 7,
|
|
||||||
export: 8,
|
|
||||||
extends: 9,
|
|
||||||
final: 10,
|
|
||||||
float: 11,
|
|
||||||
goto: 12,
|
|
||||||
implements: 13,
|
|
||||||
import: 14,
|
|
||||||
int: 15,
|
|
||||||
interface: 16,
|
|
||||||
let: 17,
|
|
||||||
long: 18,
|
|
||||||
native: 19,
|
|
||||||
package: 20,
|
|
||||||
private: 21,
|
|
||||||
protected: 22,
|
|
||||||
public: 23,
|
|
||||||
short: 24,
|
|
||||||
static: 25,
|
|
||||||
super: 26,
|
|
||||||
synchronized: 27,
|
|
||||||
this: 28,
|
|
||||||
throws: 29,
|
|
||||||
transient: 30,
|
|
||||||
volatile: 31,
|
|
||||||
yield: 32,
|
|
||||||
false: 33,
|
|
||||||
null: 34,
|
|
||||||
true: 35,
|
|
||||||
break: 36,
|
|
||||||
case: 37,
|
|
||||||
catch: 38,
|
|
||||||
const: 39,
|
|
||||||
continue: 40,
|
|
||||||
debugger: 41,
|
|
||||||
default: 42,
|
|
||||||
delete: 43,
|
|
||||||
do: 44,
|
|
||||||
else: 45,
|
|
||||||
finally: 46,
|
|
||||||
for: 47,
|
|
||||||
function: 48,
|
|
||||||
if: 49,
|
|
||||||
in: 50,
|
|
||||||
instanceof: 51,
|
|
||||||
new: 52,
|
|
||||||
return: 53,
|
|
||||||
switch: 54,
|
|
||||||
throw: 55,
|
|
||||||
try: 56,
|
|
||||||
typeof: 57,
|
|
||||||
var: 58,
|
|
||||||
void: 59,
|
|
||||||
while: 60,
|
|
||||||
with: 61,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var obj = {
|
|
||||||
e: 1,
|
|
||||||
t: 2,
|
|
||||||
n: 3,
|
|
||||||
a: 4,
|
|
||||||
i: 5,
|
|
||||||
o: 6,
|
|
||||||
r: 7,
|
|
||||||
l: 8,
|
|
||||||
s: 9,
|
|
||||||
c: 10,
|
|
||||||
f: 11,
|
|
||||||
u: 12,
|
|
||||||
d: 13,
|
|
||||||
h: 14,
|
|
||||||
p: 15,
|
|
||||||
b: 16,
|
|
||||||
v: 17,
|
|
||||||
w: 18,
|
|
||||||
y: 19,
|
|
||||||
g: 20,
|
|
||||||
m: 21,
|
|
||||||
k: 22,
|
|
||||||
x: 23,
|
|
||||||
j: 24,
|
|
||||||
z: 25,
|
|
||||||
q: 26,
|
|
||||||
A: 27,
|
|
||||||
B: 28,
|
|
||||||
C: 29,
|
|
||||||
D: 30,
|
|
||||||
F: 31,
|
|
||||||
G: 32,
|
|
||||||
false: 33,
|
|
||||||
null: 34,
|
|
||||||
true: 35,
|
|
||||||
H: 36,
|
|
||||||
I: 37,
|
|
||||||
J: 38,
|
|
||||||
K: 39,
|
|
||||||
L: 40,
|
|
||||||
M: 41,
|
|
||||||
N: 42,
|
|
||||||
O: 43,
|
|
||||||
P: 44,
|
|
||||||
Q: 45,
|
|
||||||
R: 46,
|
|
||||||
S: 47,
|
|
||||||
T: 48,
|
|
||||||
U: 49,
|
|
||||||
V: 50,
|
|
||||||
W: 51,
|
|
||||||
X: 52,
|
|
||||||
Y: 53,
|
|
||||||
Z: 54,
|
|
||||||
$: 55,
|
|
||||||
_: 56,
|
|
||||||
ee: 57,
|
|
||||||
te: 58,
|
|
||||||
ne: 59,
|
|
||||||
ae: 60,
|
|
||||||
ie: 61,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
unary_prefix: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function() {
|
|
||||||
var x = -(2 / 3);
|
|
||||||
return x;
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect_exact: "console.log(-2/3);"
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
@@ -1,138 +0,0 @@
|
|||||||
iife_for: {
|
|
||||||
options = {
|
|
||||||
negate_iife: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
function g() {
|
|
||||||
L: for (;;) break L;
|
|
||||||
}
|
|
||||||
g();
|
|
||||||
}
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
!function() {
|
|
||||||
!function() {
|
|
||||||
L: for (;;) break L;
|
|
||||||
}();
|
|
||||||
}();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
iife_for_in: {
|
|
||||||
options = {
|
|
||||||
negate_iife: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
function g() {
|
|
||||||
L: for (var a in x) break L;
|
|
||||||
}
|
|
||||||
g();
|
|
||||||
}
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
!function() {
|
|
||||||
!function() {
|
|
||||||
L: for (var a in x) break L;
|
|
||||||
}();
|
|
||||||
}();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
iife_do: {
|
|
||||||
options = {
|
|
||||||
negate_iife: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
function g() {
|
|
||||||
L: do {
|
|
||||||
break L;
|
|
||||||
} while (1);
|
|
||||||
}
|
|
||||||
g();
|
|
||||||
}
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
!function() {
|
|
||||||
!function() {
|
|
||||||
L: do {
|
|
||||||
break L;
|
|
||||||
} while (1);
|
|
||||||
}();
|
|
||||||
}();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
iife_while: {
|
|
||||||
options = {
|
|
||||||
negate_iife: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
function g() {
|
|
||||||
L: while (1) break L;
|
|
||||||
}
|
|
||||||
g();
|
|
||||||
}
|
|
||||||
f();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
!function() {
|
|
||||||
!function() {
|
|
||||||
L: while (1) break L;
|
|
||||||
}();
|
|
||||||
}();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
label_do: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
loops: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
L: do {
|
|
||||||
continue L;
|
|
||||||
} while (0);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
L: do {
|
|
||||||
continue L;
|
|
||||||
} while (0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
label_while: {
|
|
||||||
options = {
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
loops: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
L: while (0) continue L;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: "function f(){L:0}"
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
operator: {
|
|
||||||
input: {
|
|
||||||
a. //comment
|
|
||||||
typeof
|
|
||||||
}
|
|
||||||
expect_exact: "a.typeof;"
|
|
||||||
}
|
|
||||||
|
|
||||||
name: {
|
|
||||||
input: {
|
|
||||||
a. //comment
|
|
||||||
b
|
|
||||||
}
|
|
||||||
expect_exact: "a.b;"
|
|
||||||
}
|
|
||||||
|
|
||||||
keyword: {
|
|
||||||
input: {
|
|
||||||
a. //comment
|
|
||||||
default
|
|
||||||
}
|
|
||||||
expect_exact: "a.default;"
|
|
||||||
}
|
|
||||||
|
|
||||||
atom: {
|
|
||||||
input: {
|
|
||||||
a. //comment
|
|
||||||
true
|
|
||||||
}
|
|
||||||
expect_exact: "a.true;"
|
|
||||||
}
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
do_not_update_lhs: {
|
|
||||||
options = {
|
|
||||||
global_defs: {
|
|
||||||
DEBUG: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
DEBUG++;
|
|
||||||
DEBUG += 1;
|
|
||||||
DEBUG = 1;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
DEBUG++;
|
|
||||||
DEBUG += 1;
|
|
||||||
DEBUG = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
do_update_rhs: {
|
|
||||||
options = {
|
|
||||||
global_defs: {
|
|
||||||
DEBUG: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
MY_DEBUG = DEBUG;
|
|
||||||
MY_DEBUG += DEBUG;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
MY_DEBUG = 0;
|
|
||||||
MY_DEBUG += 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mixed: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
global_defs: {
|
|
||||||
DEBUG: 0,
|
|
||||||
ENV: 1,
|
|
||||||
FOO: 2,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var ENV = 3;
|
|
||||||
var FOO = 4;
|
|
||||||
f(ENV * 10);
|
|
||||||
--FOO;
|
|
||||||
DEBUG = 1;
|
|
||||||
DEBUG++;
|
|
||||||
DEBUG += 1;
|
|
||||||
f(DEBUG);
|
|
||||||
x = DEBUG;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var ENV = 3;
|
|
||||||
var FOO = 4;
|
|
||||||
f(10);
|
|
||||||
--FOO;
|
|
||||||
DEBUG = 1;
|
|
||||||
DEBUG++;
|
|
||||||
DEBUG += 1;
|
|
||||||
f(0);
|
|
||||||
x = 0;
|
|
||||||
}
|
|
||||||
expect_warnings: [
|
|
||||||
"WARN: global_defs ENV redefined [test/compress/issue-208.js:1,12]",
|
|
||||||
"WARN: global_defs FOO redefined [test/compress/issue-208.js:2,12]",
|
|
||||||
"WARN: global_defs FOO redefined [test/compress/issue-208.js:4,10]",
|
|
||||||
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:5,8]",
|
|
||||||
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:6,8]",
|
|
||||||
"WARN: global_defs DEBUG redefined [test/compress/issue-208.js:7,8]",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
return_with_no_value_in_if_body: {
|
return_with_no_value_in_if_body: {
|
||||||
options = {
|
options = { conditionals: true };
|
||||||
conditionals: true,
|
|
||||||
}
|
|
||||||
input: {
|
input: {
|
||||||
function foo(bar) {
|
function foo(bar) {
|
||||||
if (bar) {
|
if (bar) {
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
insert_semicolon: {
|
|
||||||
beautify = {
|
|
||||||
beautify: true,
|
|
||||||
comments: "all",
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a
|
|
||||||
/* foo */ var b
|
|
||||||
}
|
|
||||||
expect_exact: [
|
|
||||||
"var a",
|
|
||||||
"/* foo */;",
|
|
||||||
"",
|
|
||||||
"var b;",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
unary_postfix: {
|
|
||||||
beautify = {
|
|
||||||
beautify: true,
|
|
||||||
comments: "all",
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
a
|
|
||||||
/* foo */++b
|
|
||||||
}
|
|
||||||
expect_exact: [
|
|
||||||
"a",
|
|
||||||
"/* foo */;",
|
|
||||||
"",
|
|
||||||
"++b;",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
issue_267: {
|
issue_267: {
|
||||||
options = {
|
options = { comparisons: true };
|
||||||
comparisons: true,
|
|
||||||
}
|
|
||||||
input: {
|
input: {
|
||||||
x = a % b / b * c * 2;
|
x = a % b / b * c * 2;
|
||||||
x = a % b * 2
|
x = a % b * 2
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
issue_269_1: {
|
issue_269_1: {
|
||||||
options = {
|
options = {unsafe: true};
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
input: {
|
||||||
var x = {};
|
f(
|
||||||
console.log(
|
|
||||||
String(x),
|
String(x),
|
||||||
Number(x),
|
Number(x),
|
||||||
Boolean(x),
|
Boolean(x),
|
||||||
@@ -15,42 +12,32 @@ issue_269_1: {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var x = {};
|
f(
|
||||||
console.log(
|
x + '', +x, !!x,
|
||||||
x + "", +x, !!x,
|
'', 0, false
|
||||||
"", 0, false
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_269_dangers: {
|
issue_269_dangers: {
|
||||||
options = {
|
options = {unsafe: true};
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
input: {
|
||||||
var x = {};
|
f(
|
||||||
console.log(
|
|
||||||
String(x, x),
|
String(x, x),
|
||||||
Number(x, x),
|
Number(x, x),
|
||||||
Boolean(x, x)
|
Boolean(x, x)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var x = {};
|
f(String(x, x), Number(x, x), Boolean(x, x));
|
||||||
console.log(String(x, x), Number(x, x), Boolean(x, x));
|
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_269_in_scope: {
|
issue_269_in_scope: {
|
||||||
options = {
|
options = {unsafe: true};
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
input: {
|
||||||
var String, Number, Boolean;
|
var String, Number, Boolean;
|
||||||
var x = {};
|
f(
|
||||||
console.log(
|
|
||||||
String(x),
|
String(x),
|
||||||
Number(x, x),
|
Number(x, x),
|
||||||
Boolean(x)
|
Boolean(x)
|
||||||
@@ -58,54 +45,22 @@ issue_269_in_scope: {
|
|||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var String, Number, Boolean;
|
var String, Number, Boolean;
|
||||||
var x = {};
|
f(String(x), Number(x, x), Boolean(x));
|
||||||
console.log(String(x), Number(x, x), Boolean(x));
|
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
strings_concat: {
|
strings_concat: {
|
||||||
options = {
|
options = {unsafe: true};
|
||||||
strings: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
input: {
|
||||||
var x = {};
|
f(
|
||||||
console.log(
|
String(x + 'str'),
|
||||||
String(x + "str"),
|
String('str' + x)
|
||||||
String("str" + x)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var x = {};
|
f(
|
||||||
console.log(
|
x + 'str',
|
||||||
x + "str",
|
'str' + x
|
||||||
"str" + x
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
regexp: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
unsafe: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
RegExp("foo");
|
|
||||||
RegExp("bar", "ig");
|
|
||||||
RegExp(foo);
|
|
||||||
RegExp("bar", ig);
|
|
||||||
RegExp("should", "fail");
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
/foo/;
|
|
||||||
/bar/ig;
|
|
||||||
RegExp(foo);
|
|
||||||
RegExp("bar", ig);
|
|
||||||
RegExp("should", "fail");
|
|
||||||
}
|
|
||||||
expect_warnings: [
|
|
||||||
'WARN: Error converting RegExp("should","fail") [test/compress/issue-269.js:5,8]',
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
warn: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
passes: 2,
|
|
||||||
properties: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
toplevel: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
return g();
|
|
||||||
}
|
|
||||||
function g() {
|
|
||||||
return g["call" + "er"].arguments;
|
|
||||||
}
|
|
||||||
// 3
|
|
||||||
console.log(f(1, 2, 3).length);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
// TypeError: Cannot read property 'arguments' of null
|
|
||||||
console.log(function g() {
|
|
||||||
return g.caller.arguments;
|
|
||||||
}().length);
|
|
||||||
}
|
|
||||||
expect_warnings: [
|
|
||||||
"WARN: Function.prototype.arguments not supported [test/compress/issue-2719.js:5,19]",
|
|
||||||
"WARN: Function.prototype.caller not supported [test/compress/issue-2719.js:5,19]",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,498 +0,0 @@
|
|||||||
collapse_vars_constants: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f1(x) {
|
|
||||||
var a = 4, b = x.prop, c = 5, d = sideeffect1(), e = sideeffect2();
|
|
||||||
return b + (function() { return d - a * e - c; })();
|
|
||||||
}
|
|
||||||
function f2(x) {
|
|
||||||
var a = 4, b = x.prop, c = 5, not_used = sideeffect1(), e = sideeffect2();
|
|
||||||
return b + (function() { return -a * e - c; })();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f1(x) {
|
|
||||||
var b = x.prop, d = sideeffect1(), e = sideeffect2();
|
|
||||||
return b + (d - 4 * e - 5);
|
|
||||||
}
|
|
||||||
function f2(x) {
|
|
||||||
var b = x.prop;
|
|
||||||
sideeffect1();
|
|
||||||
return b + (-4 * sideeffect2() - 5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
modified: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
inline: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f5(b) {
|
|
||||||
var a = function() {
|
|
||||||
return b;
|
|
||||||
}();
|
|
||||||
return b++ + a;
|
|
||||||
}
|
|
||||||
console.log(f5(1));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f5(b) {
|
|
||||||
var a = b;
|
|
||||||
return b++ + a;
|
|
||||||
}
|
|
||||||
console.log(f5(1));
|
|
||||||
}
|
|
||||||
expect_stdout: "2"
|
|
||||||
}
|
|
||||||
|
|
||||||
ref_scope: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
inline: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function() {
|
|
||||||
var a = 1, b = 2, c = 3;
|
|
||||||
var a = c++, b = b /= a;
|
|
||||||
return function() {
|
|
||||||
return a;
|
|
||||||
}() + b;
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(function() {
|
|
||||||
var a = 1, b = 2, c = 3;
|
|
||||||
b = b /= a = c++;
|
|
||||||
return a + b;
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
safe_undefined: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
if_return: true,
|
|
||||||
inline: true,
|
|
||||||
unsafe: false,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
mangle = {}
|
|
||||||
input: {
|
|
||||||
var a, c;
|
|
||||||
console.log(function(undefined) {
|
|
||||||
return function() {
|
|
||||||
if (a)
|
|
||||||
return b;
|
|
||||||
if (c)
|
|
||||||
return d;
|
|
||||||
};
|
|
||||||
}(1)());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a, c;
|
|
||||||
console.log(a ? b : c ? d : void 0);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
negate_iife_3: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
expression: true,
|
|
||||||
inline: true,
|
|
||||||
negate_iife: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(){ return t })() ? console.log(true) : console.log(false);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
t ? console.log(true) : console.log(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
negate_iife_3_off: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
expression: true,
|
|
||||||
inline: true,
|
|
||||||
negate_iife: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(){ return t })() ? console.log(true) : console.log(false);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
t ? console.log(true) : console.log(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
negate_iife_4: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
expression: true,
|
|
||||||
inline: true,
|
|
||||||
negate_iife: true,
|
|
||||||
sequences: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(){ return t })() ? console.log(true) : console.log(false);
|
|
||||||
(function(){
|
|
||||||
console.log("something");
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
t ? console.log(true) : console.log(false), void console.log("something");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
negate_iife_5: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
expression: true,
|
|
||||||
inline: true,
|
|
||||||
negate_iife: true,
|
|
||||||
sequences: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
if ((function(){ return t })()) {
|
|
||||||
foo(true);
|
|
||||||
} else {
|
|
||||||
bar(false);
|
|
||||||
}
|
|
||||||
(function(){
|
|
||||||
console.log("something");
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
t ? foo(true) : bar(false), void console.log("something");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
negate_iife_5_off: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
expression: true,
|
|
||||||
inline: true,
|
|
||||||
negate_iife: false,
|
|
||||||
sequences: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
if ((function(){ return t })()) {
|
|
||||||
foo(true);
|
|
||||||
} else {
|
|
||||||
bar(false);
|
|
||||||
}
|
|
||||||
(function(){
|
|
||||||
console.log("something");
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
t ? foo(true) : bar(false), void console.log("something");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1254_negate_iife_true: {
|
|
||||||
options = {
|
|
||||||
expression: true,
|
|
||||||
inline: true,
|
|
||||||
negate_iife: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
return function() {
|
|
||||||
console.log('test')
|
|
||||||
};
|
|
||||||
})()();
|
|
||||||
}
|
|
||||||
expect_exact: 'void console.log("test");'
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1254_negate_iife_nested: {
|
|
||||||
options = {
|
|
||||||
expression: true,
|
|
||||||
inline: true,
|
|
||||||
negate_iife: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
return function() {
|
|
||||||
console.log('test')
|
|
||||||
};
|
|
||||||
})()()()()();
|
|
||||||
}
|
|
||||||
expect_exact: '(void console.log("test"))()()();'
|
|
||||||
}
|
|
||||||
|
|
||||||
negate_iife_issue_1073: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
negate_iife: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
sequences: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
new (function(a) {
|
|
||||||
return function Foo() {
|
|
||||||
this.x = a;
|
|
||||||
console.log(this);
|
|
||||||
};
|
|
||||||
}(7))();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
new function() {
|
|
||||||
this.x = 7,
|
|
||||||
console.log(this);
|
|
||||||
}();
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1288_side_effects: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
negate_iife: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
if (w) ;
|
|
||||||
else {
|
|
||||||
(function f() {})();
|
|
||||||
}
|
|
||||||
if (!x) {
|
|
||||||
(function() {
|
|
||||||
x = {};
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
if (y)
|
|
||||||
(function() {})();
|
|
||||||
else
|
|
||||||
(function(z) {
|
|
||||||
return z;
|
|
||||||
})(0);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
w;
|
|
||||||
x || (x = {});
|
|
||||||
y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inner_var_for_in_1: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
var a = 1, b = 2;
|
|
||||||
for (b in (function() {
|
|
||||||
return x(a, b, c);
|
|
||||||
})()) {
|
|
||||||
var c = 3, d = 4;
|
|
||||||
x(a, b, c, d);
|
|
||||||
}
|
|
||||||
x(a, b, c, d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f() {
|
|
||||||
var a = 1, b = 2;
|
|
||||||
for (b in x(1, b, c)) {
|
|
||||||
var c = 3, d = 4;
|
|
||||||
x(1, b, c, d);
|
|
||||||
}
|
|
||||||
x(1, b, c, d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1595_3: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
inline: true,
|
|
||||||
passes: 2,
|
|
||||||
reduce_funcs: true,
|
|
||||||
reduce_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function f(a) {
|
|
||||||
return g(a + 1);
|
|
||||||
})(2);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
g(3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1758: {
|
|
||||||
options = {
|
|
||||||
inline: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function(c) {
|
|
||||||
var undefined = 42;
|
|
||||||
return function() {
|
|
||||||
c--;
|
|
||||||
c--, c.toString();
|
|
||||||
return;
|
|
||||||
}();
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(function(c) {
|
|
||||||
var undefined = 42;
|
|
||||||
return c--, c--, void c.toString();
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect_stdout: "undefined"
|
|
||||||
}
|
|
||||||
wrap_iife: {
|
|
||||||
options = {
|
|
||||||
inline: true,
|
|
||||||
negate_iife: false,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
wrap_iife: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
return function() {
|
|
||||||
console.log('test')
|
|
||||||
};
|
|
||||||
})()();
|
|
||||||
}
|
|
||||||
expect_exact: 'void console.log("test");'
|
|
||||||
}
|
|
||||||
|
|
||||||
wrap_iife_in_expression: {
|
|
||||||
options = {
|
|
||||||
inline: true,
|
|
||||||
negate_iife: false,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
wrap_iife: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
foo = (function() {
|
|
||||||
return bar();
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_exact: 'foo=bar();'
|
|
||||||
}
|
|
||||||
|
|
||||||
wrap_iife_in_return_call: {
|
|
||||||
options = {
|
|
||||||
inline: true,
|
|
||||||
negate_iife: false,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
wrap_iife: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
return (function() {
|
|
||||||
console.log('test')
|
|
||||||
})();
|
|
||||||
})()();
|
|
||||||
}
|
|
||||||
expect_exact: '(void console.log("test"))();'
|
|
||||||
}
|
|
||||||
|
|
||||||
pure_annotation_1: {
|
|
||||||
options = {
|
|
||||||
inline: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
/*@__PURE__*/(function() {
|
|
||||||
console.log("hello");
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect_exact: ""
|
|
||||||
}
|
|
||||||
|
|
||||||
pure_annotation_2: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
inline: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
/*@__PURE__*/(function(n) {
|
|
||||||
console.log("hello", n);
|
|
||||||
}(42));
|
|
||||||
}
|
|
||||||
expect_exact: ""
|
|
||||||
}
|
|
||||||
|
|
||||||
drop_fargs: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
inline: true,
|
|
||||||
keep_fargs: false,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = 1;
|
|
||||||
!function(a_1) {
|
|
||||||
a++;
|
|
||||||
}(a++ + (a && a.var));
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = 1;
|
|
||||||
++a && a.var, a++;
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_stdout: "3"
|
|
||||||
}
|
|
||||||
|
|
||||||
keep_fargs: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
inline: true,
|
|
||||||
keep_fargs: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = 1;
|
|
||||||
!function(a_1) {
|
|
||||||
a++;
|
|
||||||
}(a++ + (a && a.var));
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = 1;
|
|
||||||
++a && a.var, a++;
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_stdout: "3"
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
comparison_with_undefined: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
a == undefined;
|
|
||||||
a != undefined;
|
|
||||||
a === undefined;
|
|
||||||
a !== undefined;
|
|
||||||
|
|
||||||
undefined == a;
|
|
||||||
undefined != a;
|
|
||||||
undefined === a;
|
|
||||||
undefined !== a;
|
|
||||||
|
|
||||||
void 0 == a;
|
|
||||||
void 0 != a;
|
|
||||||
void 0 === a;
|
|
||||||
void 0 !== a;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
null == a;
|
|
||||||
null != a;
|
|
||||||
void 0 === a;
|
|
||||||
void 0 !== a;
|
|
||||||
|
|
||||||
null == a;
|
|
||||||
null != a;
|
|
||||||
void 0 === a;
|
|
||||||
void 0 !== a;
|
|
||||||
|
|
||||||
null == a;
|
|
||||||
null != a;
|
|
||||||
void 0 === a;
|
|
||||||
void 0 !== a;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
inline_script_off: {
|
|
||||||
beautify = {
|
|
||||||
inline_script: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log("</sCrIpT>");
|
|
||||||
}
|
|
||||||
expect_exact: 'console.log("</sCrIpT>");'
|
|
||||||
expect_stdout: "</sCrIpT>"
|
|
||||||
}
|
|
||||||
|
|
||||||
inline_script_on: {
|
|
||||||
beautify = {
|
|
||||||
inline_script: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log("</sCrIpT>");
|
|
||||||
}
|
|
||||||
expect_exact: 'console.log("<\\/sCrIpT>");'
|
|
||||||
expect_stdout: "</sCrIpT>"
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
collapse: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f1() {
|
|
||||||
var a;
|
|
||||||
a = typeof b === 'function' ? b() : b;
|
|
||||||
return a !== undefined && c();
|
|
||||||
}
|
|
||||||
function f2(b) {
|
|
||||||
var a;
|
|
||||||
b = c();
|
|
||||||
a = typeof b === 'function' ? b() : b;
|
|
||||||
return 'stirng' == typeof a && d();
|
|
||||||
}
|
|
||||||
function f3(c) {
|
|
||||||
var a;
|
|
||||||
a = b(a / 2);
|
|
||||||
if (a < 0) {
|
|
||||||
a++;
|
|
||||||
++c;
|
|
||||||
return c / 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function f4(c) {
|
|
||||||
var a;
|
|
||||||
a = b(a / 2);
|
|
||||||
if (a < 0) {
|
|
||||||
a++;
|
|
||||||
c++;
|
|
||||||
return c / 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f1() {
|
|
||||||
return void 0 !== ('function' === typeof b ? b() : b) && c();
|
|
||||||
}
|
|
||||||
function f2(b) {
|
|
||||||
return 'stirng' == typeof ('function' === typeof (b = c()) ? b() : b) && d();
|
|
||||||
}
|
|
||||||
function f3(c) {
|
|
||||||
var a;
|
|
||||||
if ((a = b(a / 2)) < 0) return a++, ++c / 2;
|
|
||||||
}
|
|
||||||
function f4(c) {
|
|
||||||
var a;
|
|
||||||
if ((a = b(a / 2)) < 0) return a++, ++c / 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
mangle: {
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var e = eval, x = 42;
|
|
||||||
(function() {
|
|
||||||
console.log(e("typeof x"));
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var e = eval, x = 42;
|
|
||||||
(function() {
|
|
||||||
console.log(e("typeof x"));
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
compress: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
inline: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(function() {
|
|
||||||
var a = 42;
|
|
||||||
return eval("typeof a");
|
|
||||||
}(), function(e) {
|
|
||||||
var a = null;
|
|
||||||
return e("typeof a");
|
|
||||||
}(eval), function(eval) {
|
|
||||||
var a = false;
|
|
||||||
return eval("typeof a");
|
|
||||||
}(eval), function(f) {
|
|
||||||
var a = "STRING";
|
|
||||||
var eval = f;
|
|
||||||
return eval("typeof a");
|
|
||||||
}(eval), function(g) {
|
|
||||||
var a = eval;
|
|
||||||
function eval() {
|
|
||||||
return g;
|
|
||||||
}
|
|
||||||
return eval()("typeof a");
|
|
||||||
}(eval));
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(function() {
|
|
||||||
var a = 42;
|
|
||||||
return eval("typeof a");
|
|
||||||
}(), (0, eval)("typeof a"), function(eval) {
|
|
||||||
var a = false;
|
|
||||||
return eval("typeof a");
|
|
||||||
}(eval), function(f) {
|
|
||||||
var a = "STRING";
|
|
||||||
var eval = f;
|
|
||||||
return eval("typeof a");
|
|
||||||
}(eval), function(g) {
|
|
||||||
var a = eval;
|
|
||||||
function eval() {
|
|
||||||
return g;
|
|
||||||
}
|
|
||||||
return eval()("typeof a");
|
|
||||||
}(eval));
|
|
||||||
}
|
|
||||||
expect_stdout: "number undefined boolean string undefined"
|
|
||||||
}
|
|
||||||
|
|
||||||
call_arg_1: {
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var z = "foo";
|
|
||||||
(function() {
|
|
||||||
var z = false;
|
|
||||||
(function(e) {
|
|
||||||
var z = 42;
|
|
||||||
e("console.log(typeof z)");
|
|
||||||
})(eval);
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var z = "foo";
|
|
||||||
(function() {
|
|
||||||
var o = false;
|
|
||||||
(function(o) {
|
|
||||||
var a = 42;
|
|
||||||
o("console.log(typeof z)");
|
|
||||||
})(eval);
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
call_arg_2: {
|
|
||||||
mangle = {
|
|
||||||
toplevel: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function eval() {
|
|
||||||
console.log("PASS");
|
|
||||||
}
|
|
||||||
var z = "foo";
|
|
||||||
(function() {
|
|
||||||
var z = false;
|
|
||||||
(function(e) {
|
|
||||||
var z = 42;
|
|
||||||
e("console.log(typeof z)");
|
|
||||||
})(eval);
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function n() {
|
|
||||||
console.log("PASS");
|
|
||||||
}
|
|
||||||
var o = "foo";
|
|
||||||
(function() {
|
|
||||||
var o = false;
|
|
||||||
(function(o) {
|
|
||||||
var n = 42;
|
|
||||||
o("console.log(typeof z)");
|
|
||||||
})(n);
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
issue_44_valid_ast_1: {
|
issue_44_valid_ast_1: {
|
||||||
options = {
|
options = { unused: true };
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
input: {
|
||||||
function a(b) {
|
function a(b) {
|
||||||
for (var i = 0, e = b.qoo(); ; i++) {}
|
for (var i = 0, e = b.qoo(); ; i++) {}
|
||||||
@@ -16,9 +14,7 @@ issue_44_valid_ast_1: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
issue_44_valid_ast_2: {
|
issue_44_valid_ast_2: {
|
||||||
options = {
|
options = { unused: true };
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
input: {
|
||||||
function a(b) {
|
function a(b) {
|
||||||
if (foo) for (var i = 0, e = b.qoo(); ; i++) {}
|
if (foo) for (var i = 0, e = b.qoo(); ; i++) {}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
keep_continue: {
|
keep_continue: {
|
||||||
options = {
|
options = {
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
evaluate: true,
|
evaluate: true
|
||||||
}
|
};
|
||||||
input: {
|
input: {
|
||||||
while (a) {
|
while (a) {
|
||||||
if (b) {
|
if (b) {
|
||||||
|
|||||||
@@ -1,157 +1,25 @@
|
|||||||
NaN_and_Infinity_must_have_parens: {
|
NaN_and_Infinity_must_have_parens: {
|
||||||
options = {}
|
options = {};
|
||||||
input: {
|
input: {
|
||||||
Infinity.toString();
|
Infinity.toString();
|
||||||
NaN.toString();
|
NaN.toString();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
(1/0).toString();
|
|
||||||
NaN.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NaN_and_Infinity_should_not_be_replaced_when_they_are_redefined: {
|
|
||||||
options = {}
|
|
||||||
input: {
|
|
||||||
var Infinity, NaN;
|
|
||||||
Infinity.toString();
|
|
||||||
NaN.toString();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var Infinity, NaN;
|
|
||||||
Infinity.toString();
|
|
||||||
NaN.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NaN_and_Infinity_must_have_parens_evaluate: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(123456789 / 0).toString();
|
|
||||||
(+"foo").toString();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(1/0).toString();
|
|
||||||
NaN.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NaN_and_Infinity_should_not_be_replaced_when_they_are_redefined_evaluate: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var Infinity, NaN;
|
|
||||||
(123456789 / 0).toString();
|
|
||||||
(+"foo").toString();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var Infinity, NaN;
|
|
||||||
(1/0).toString();
|
(1/0).toString();
|
||||||
(0/0).toString();
|
(0/0).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
beautify_off_1: {
|
NaN_and_Infinity_should_not_be_replaced_when_they_are_redefined: {
|
||||||
options = {
|
options = {};
|
||||||
evaluate: true,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
beautify: false,
|
|
||||||
}
|
|
||||||
input: {
|
input: {
|
||||||
var NaN;
|
var Infinity, NaN;
|
||||||
console.log(
|
Infinity.toString();
|
||||||
null,
|
NaN.toString();
|
||||||
undefined,
|
|
||||||
Infinity,
|
|
||||||
NaN,
|
|
||||||
Infinity * undefined,
|
|
||||||
Infinity.toString(),
|
|
||||||
NaN.toString(),
|
|
||||||
(Infinity * undefined).toString()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
expect_exact: "var NaN;console.log(null,void 0,1/0,NaN,0/0,(1/0).toString(),NaN.toString(),(0/0).toString());"
|
expect: {
|
||||||
expect_stdout: true
|
var Infinity, NaN;
|
||||||
|
Infinity.toString();
|
||||||
|
NaN.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
beautify_off_2: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
beautify: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(
|
|
||||||
null.toString(),
|
|
||||||
undefined.toString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect_exact: "console.log(null.toString(),(void 0).toString());"
|
|
||||||
}
|
|
||||||
|
|
||||||
beautify_on_1: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
beautify: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var NaN;
|
|
||||||
console.log(
|
|
||||||
null,
|
|
||||||
undefined,
|
|
||||||
Infinity,
|
|
||||||
NaN,
|
|
||||||
Infinity * undefined,
|
|
||||||
Infinity.toString(),
|
|
||||||
NaN.toString(),
|
|
||||||
(Infinity * undefined).toString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect_exact: [
|
|
||||||
"var NaN;",
|
|
||||||
"",
|
|
||||||
"console.log(null, void 0, 1 / 0, NaN, 0 / 0, (1 / 0).toString(), NaN.toString(), (0 / 0).toString());",
|
|
||||||
]
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
beautify_on_2: {
|
|
||||||
options = {
|
|
||||||
evaluate: true,
|
|
||||||
}
|
|
||||||
beautify = {
|
|
||||||
beautify: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(
|
|
||||||
null.toString(),
|
|
||||||
undefined.toString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
expect_exact: "console.log(null.toString(), (void 0).toString());"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1724: {
|
|
||||||
input: {
|
|
||||||
var a = 0;
|
|
||||||
++a % Infinity | Infinity ? a++ : 0;
|
|
||||||
console.log(a);
|
|
||||||
}
|
|
||||||
expect_exact: "var a=0;++a%(1/0)|1/0?a++:0;console.log(a);"
|
|
||||||
expect_stdout: "2"
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1725: {
|
|
||||||
input: {
|
|
||||||
([].length === 0) % Infinity ? console.log("PASS") : console.log("FAIL");
|
|
||||||
}
|
|
||||||
expect_exact: '(0===[].length)%(1/0)?console.log("PASS"):console.log("FAIL");'
|
|
||||||
expect_stdout: "PASS"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
issue_611: {
|
issue_611: {
|
||||||
options = {
|
options = {
|
||||||
sequences: true,
|
sequences: true,
|
||||||
side_effects: true,
|
side_effects: true
|
||||||
}
|
};
|
||||||
input: {
|
input: {
|
||||||
define(function() {
|
define(function() {
|
||||||
function fn() {}
|
function fn() {}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
wrongly_optimized: {
|
wrongly_optimized: {
|
||||||
options = {
|
options = {
|
||||||
booleans: true,
|
|
||||||
conditionals: true,
|
conditionals: true,
|
||||||
evaluate: true,
|
booleans: true,
|
||||||
}
|
evaluate: true
|
||||||
|
};
|
||||||
input: {
|
input: {
|
||||||
function func() {
|
function func() {
|
||||||
foo();
|
foo();
|
||||||
@@ -16,6 +16,7 @@ wrongly_optimized: {
|
|||||||
function func() {
|
function func() {
|
||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
func(), 1, bar();
|
// TODO: optimize to `func(), bar()`
|
||||||
|
(func(), 0) || bar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,323 +0,0 @@
|
|||||||
cond_5: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
expression: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
if (some_condition()) {
|
|
||||||
if (some_other_condition()) {
|
|
||||||
do_something();
|
|
||||||
} else {
|
|
||||||
alternate();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
alternate();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (some_condition()) {
|
|
||||||
if (some_other_condition()) {
|
|
||||||
do_something();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(some_condition() && some_other_condition() ? do_something : alternate)();
|
|
||||||
if (some_condition() && some_other_condition()) do_something();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dead_code_const_annotation_regex: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
expression: true,
|
|
||||||
loops: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var unused;
|
|
||||||
// @constraint this shouldn't be a constant
|
|
||||||
var CONST_FOO_ANN = false;
|
|
||||||
if (CONST_FOO_ANN) {
|
|
||||||
console.log("reachable");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var unused;
|
|
||||||
var CONST_FOO_ANN = !1;
|
|
||||||
if (CONST_FOO_ANN) console.log('reachable');
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
drop_console_2: {
|
|
||||||
options = {
|
|
||||||
drop_console: true,
|
|
||||||
expression: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log('foo');
|
|
||||||
console.log.apply(console, arguments);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
// with regular compression these will be stripped out as well
|
|
||||||
void 0;
|
|
||||||
void 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
drop_value: {
|
|
||||||
options = {
|
|
||||||
expression: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(1, [2, foo()], 3, {a:1, b:bar()});
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
foo(), {a:1, b:bar()};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wrongly_optimized: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
expression: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function func() {
|
|
||||||
foo();
|
|
||||||
}
|
|
||||||
if (func() || true) {
|
|
||||||
bar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function func() {
|
|
||||||
foo();
|
|
||||||
}
|
|
||||||
func(), 1;
|
|
||||||
bar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
negate_iife_1: {
|
|
||||||
options = {
|
|
||||||
expression: true,
|
|
||||||
negate_iife: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(){ stuff() })();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(){ stuff() })();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
negate_iife_3: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
expression: true,
|
|
||||||
negate_iife: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(){ return t })() ? console.log(true) : console.log(false);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(){ return t })() ? console.log(true) : console.log(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
negate_iife_3_off: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
expression: true,
|
|
||||||
negate_iife: false,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(){ return t })() ? console.log(true) : console.log(false);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(){ return t })() ? console.log(true) : console.log(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
negate_iife_4: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
expression: true,
|
|
||||||
negate_iife: true,
|
|
||||||
sequences: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(){ return t })() ? console.log(true) : console.log(false);
|
|
||||||
(function(){
|
|
||||||
console.log("something");
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
!function(){ return t }() ? console.log(false) : console.log(true), function(){
|
|
||||||
console.log("something");
|
|
||||||
}();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
negate_iife_5: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
expression: true,
|
|
||||||
negate_iife: true,
|
|
||||||
sequences: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
if ((function(){ return t })()) {
|
|
||||||
foo(true);
|
|
||||||
} else {
|
|
||||||
bar(false);
|
|
||||||
}
|
|
||||||
(function(){
|
|
||||||
console.log("something");
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
!function(){ return t }() ? bar(false) : foo(true), function(){
|
|
||||||
console.log("something");
|
|
||||||
}();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
negate_iife_5_off: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
expression: true,
|
|
||||||
negate_iife: false,
|
|
||||||
sequences: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
if ((function(){ return t })()) {
|
|
||||||
foo(true);
|
|
||||||
} else {
|
|
||||||
bar(false);
|
|
||||||
}
|
|
||||||
(function(){
|
|
||||||
console.log("something");
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
!function(){ return t }() ? bar(false) : foo(true), function(){
|
|
||||||
console.log("something");
|
|
||||||
}();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1254_negate_iife_true: {
|
|
||||||
options = {
|
|
||||||
expression: true,
|
|
||||||
negate_iife: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
return function() {
|
|
||||||
console.log('test')
|
|
||||||
};
|
|
||||||
})()();
|
|
||||||
}
|
|
||||||
expect_exact: '(function(){return function(){console.log("test")}})()();'
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_1254_negate_iife_nested: {
|
|
||||||
options = {
|
|
||||||
expression: true,
|
|
||||||
negate_iife: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function() {
|
|
||||||
return function() {
|
|
||||||
console.log('test')
|
|
||||||
};
|
|
||||||
})()()()()();
|
|
||||||
}
|
|
||||||
expect_exact: '(function(){return function(){console.log("test")}})()()()()();'
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
conditional: {
|
|
||||||
options = {
|
|
||||||
expression: true,
|
|
||||||
pure_funcs: [
|
|
||||||
"pure"
|
|
||||||
],
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
pure(1 | a() ? 2 & b() : 7 ^ c());
|
|
||||||
pure(1 | a() ? 2 & b() : 5);
|
|
||||||
pure(1 | a() ? 4 : 7 ^ c());
|
|
||||||
pure(1 | a() ? 4 : 5);
|
|
||||||
pure(3 ? 2 & b() : 7 ^ c());
|
|
||||||
pure(3 ? 2 & b() : 5);
|
|
||||||
pure(3 ? 4 : 7 ^ c());
|
|
||||||
pure(3 ? 4 : 5);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
1 | a() ? b() : c();
|
|
||||||
1 | a() && b();
|
|
||||||
1 | a() || c();
|
|
||||||
a();
|
|
||||||
3 ? b() : c();
|
|
||||||
3 && b();
|
|
||||||
3 || c();
|
|
||||||
pure(3 ? 4 : 5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
limit_1: {
|
|
||||||
options = {
|
|
||||||
expression: true,
|
|
||||||
sequences: 3,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
a;
|
|
||||||
b;
|
|
||||||
c;
|
|
||||||
d;
|
|
||||||
e;
|
|
||||||
f;
|
|
||||||
g;
|
|
||||||
h;
|
|
||||||
i;
|
|
||||||
j;
|
|
||||||
k;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
// Turned into a single return statement
|
|
||||||
// so it can no longer be split into lines
|
|
||||||
a,b,c,d,e,f,g,h,i,j,k;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
iife: {
|
|
||||||
options = {
|
|
||||||
expression: true,
|
|
||||||
sequences: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
x = 42;
|
|
||||||
(function a() {})();
|
|
||||||
!function b() {}();
|
|
||||||
~function c() {}();
|
|
||||||
+function d() {}();
|
|
||||||
-function e() {}();
|
|
||||||
void function f() {}();
|
|
||||||
typeof function g() {}();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
x = 42, function a() {}(), function b() {}(), function c() {}(),
|
|
||||||
function d() {}(), function e() {}(), function f() {}(), typeof function g() {}();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
dont_reuse_prop: {
|
|
||||||
mangle = {
|
|
||||||
properties: {
|
|
||||||
regex: /asd/,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"aaaaaaaaaabbbbb";
|
|
||||||
var obj = {};
|
|
||||||
obj.a = 123;
|
|
||||||
obj.asd = 256;
|
|
||||||
console.log(obj.a);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"aaaaaaaaaabbbbb";
|
|
||||||
var obj = {};
|
|
||||||
obj.a = 123;
|
|
||||||
obj.b = 256;
|
|
||||||
console.log(obj.a);
|
|
||||||
}
|
|
||||||
expect_stdout: "123"
|
|
||||||
}
|
|
||||||
|
|
||||||
unmangleable_props_should_always_be_reserved: {
|
|
||||||
mangle = {
|
|
||||||
properties: {
|
|
||||||
regex: /asd/,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"aaaaaaaaaabbbbb";
|
|
||||||
var obj = {};
|
|
||||||
obj.asd = 256;
|
|
||||||
obj.a = 123;
|
|
||||||
console.log(obj.a);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"aaaaaaaaaabbbbb";
|
|
||||||
var obj = {};
|
|
||||||
obj.b = 256;
|
|
||||||
obj.a = 123;
|
|
||||||
console.log(obj.a);
|
|
||||||
}
|
|
||||||
expect_stdout: "123"
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
negate_booleans_1: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var a = !a || !b || !c || !d || !e || !f;
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var a = !(a && b && c && d && e && f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
negate_booleans_2: {
|
|
||||||
options = {
|
|
||||||
comparisons: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
var match = !x && // should not touch this one
|
|
||||||
(!z || c) &&
|
|
||||||
(!k || d) &&
|
|
||||||
the_stuff();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
var match = !x &&
|
|
||||||
(!z || c) &&
|
|
||||||
(!k || d) &&
|
|
||||||
the_stuff();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
remove_sequence: {
|
|
||||||
options = {
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(0, 1, eval)();
|
|
||||||
(0, 1, logThis)();
|
|
||||||
(0, 1, _decorators.logThis)();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(0, eval)();
|
|
||||||
logThis();
|
|
||||||
(0, _decorators.logThis)();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
remove_redundant_sequence_items: {
|
|
||||||
options = {
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
(0, 1, eval)();
|
|
||||||
(0, 1, logThis)();
|
|
||||||
(0, 1, _decorators.logThis)();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
(0, eval)();
|
|
||||||
logThis();
|
|
||||||
(0, _decorators.logThis)();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dont_remove_this_binding_sequence: {
|
|
||||||
options = {
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
(0, eval)();
|
|
||||||
(0, logThis)();
|
|
||||||
(0, _decorators.logThis)();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
(0, eval)();
|
|
||||||
logThis();
|
|
||||||
(0, _decorators.logThis)();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
dont_mangle_arguments: {
|
|
||||||
mangle = {
|
|
||||||
};
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
drop_debugger: true,
|
|
||||||
evaluate: true,
|
|
||||||
hoist_funs: true,
|
|
||||||
hoist_vars: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
keep_fargs: true,
|
|
||||||
keep_fnames: false,
|
|
||||||
loops: true,
|
|
||||||
negate_iife: false,
|
|
||||||
properties: true,
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(){
|
|
||||||
var arguments = arguments, not_arguments = 9;
|
|
||||||
console.log(not_arguments, arguments);
|
|
||||||
})(5,6,7);
|
|
||||||
}
|
|
||||||
expect_exact: "(function(){var arguments=arguments,o=9;console.log(o,arguments)})(5,6,7);"
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
keep_var_for_in: {
|
|
||||||
options = {
|
|
||||||
hoist_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(obj){
|
|
||||||
var foo = 5;
|
|
||||||
for (var i in obj)
|
|
||||||
return foo;
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(obj){
|
|
||||||
var i, foo = 5;
|
|
||||||
for (i in obj)
|
|
||||||
return foo;
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,163 +0,0 @@
|
|||||||
this_binding_conditionals: {
|
|
||||||
options = {
|
|
||||||
conditionals: true,
|
|
||||||
evaluate: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
"use strict";
|
|
||||||
(1 && a)();
|
|
||||||
(0 || a)();
|
|
||||||
(0 || 1 && a)();
|
|
||||||
(1 ? a : 0)();
|
|
||||||
|
|
||||||
(1 && a.b)();
|
|
||||||
(0 || a.b)();
|
|
||||||
(0 || 1 && a.b)();
|
|
||||||
(1 ? a.b : 0)();
|
|
||||||
|
|
||||||
(1 && a[b])();
|
|
||||||
(0 || a[b])();
|
|
||||||
(0 || 1 && a[b])();
|
|
||||||
(1 ? a[b] : 0)();
|
|
||||||
|
|
||||||
(1 && eval)();
|
|
||||||
(0 || eval)();
|
|
||||||
(0 || 1 && eval)();
|
|
||||||
(1 ? eval : 0)();
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
"use strict";
|
|
||||||
a();
|
|
||||||
a();
|
|
||||||
a();
|
|
||||||
a();
|
|
||||||
|
|
||||||
(0, a.b)();
|
|
||||||
(0, a.b)();
|
|
||||||
(0, a.b)();
|
|
||||||
(0, a.b)();
|
|
||||||
|
|
||||||
(0, a[b])();
|
|
||||||
(0, a[b])();
|
|
||||||
(0, a[b])();
|
|
||||||
(0, a[b])();
|
|
||||||
|
|
||||||
(0, eval)();
|
|
||||||
(0, eval)();
|
|
||||||
(0, eval)();
|
|
||||||
(0, eval)();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this_binding_collapse_vars: {
|
|
||||||
options = {
|
|
||||||
collapse_vars: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f() {
|
|
||||||
"use strict";
|
|
||||||
var c = a; c();
|
|
||||||
var d = a.b; d();
|
|
||||||
var e = eval; e();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f() {
|
|
||||||
"use strict";
|
|
||||||
a();
|
|
||||||
(0, a.b)();
|
|
||||||
(0, eval)();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this_binding_side_effects: {
|
|
||||||
options = {
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
(function(foo) {
|
|
||||||
(0, foo)();
|
|
||||||
(0, foo.bar)();
|
|
||||||
(0, eval)("console.log(foo);");
|
|
||||||
}());
|
|
||||||
(function(foo) {
|
|
||||||
"use strict";
|
|
||||||
(0, foo)();
|
|
||||||
(0, foo.bar)();
|
|
||||||
(0, eval)("console.log(foo);");
|
|
||||||
}());
|
|
||||||
(function(foo) {
|
|
||||||
var eval = console;
|
|
||||||
(0, foo)();
|
|
||||||
(0, foo.bar)();
|
|
||||||
(0, eval)("console.log(foo);");
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
(function(foo) {
|
|
||||||
foo();
|
|
||||||
(0, foo.bar)();
|
|
||||||
(0, eval)("console.log(foo);");
|
|
||||||
}());
|
|
||||||
(function(foo) {
|
|
||||||
"use strict";
|
|
||||||
foo();
|
|
||||||
(0, foo.bar)();
|
|
||||||
(0, eval)("console.log(foo);");
|
|
||||||
}());
|
|
||||||
(function(foo) {
|
|
||||||
var eval = console;
|
|
||||||
foo();
|
|
||||||
(0, foo.bar)();
|
|
||||||
eval("console.log(foo);");
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this_binding_sequences: {
|
|
||||||
options = {
|
|
||||||
sequences: true,
|
|
||||||
side_effects: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
console.log(typeof function() {
|
|
||||||
return eval("this");
|
|
||||||
}());
|
|
||||||
console.log(typeof function() {
|
|
||||||
"use strict";
|
|
||||||
return eval("this");
|
|
||||||
}());
|
|
||||||
console.log(typeof function() {
|
|
||||||
return (0, eval)("this");
|
|
||||||
}());
|
|
||||||
console.log(typeof function() {
|
|
||||||
"use strict";
|
|
||||||
return (0, eval)("this");
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
console.log(typeof function() {
|
|
||||||
return eval("this");
|
|
||||||
}()),
|
|
||||||
console.log(typeof function() {
|
|
||||||
"use strict";
|
|
||||||
return eval("this");
|
|
||||||
}()),
|
|
||||||
console.log(typeof function() {
|
|
||||||
return (0, eval)("this");
|
|
||||||
}()),
|
|
||||||
console.log(typeof function() {
|
|
||||||
"use strict";
|
|
||||||
return (0, eval)("this");
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
expect_stdout: [
|
|
||||||
"object",
|
|
||||||
"undefined",
|
|
||||||
"object",
|
|
||||||
"object",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
eval_collapse_vars: {
|
|
||||||
options = {
|
|
||||||
booleans: true,
|
|
||||||
collapse_vars: true,
|
|
||||||
comparisons: true,
|
|
||||||
conditionals: true,
|
|
||||||
dead_code: true,
|
|
||||||
evaluate: true,
|
|
||||||
hoist_funs: true,
|
|
||||||
if_return: true,
|
|
||||||
join_vars: true,
|
|
||||||
keep_fargs: true,
|
|
||||||
loops: true,
|
|
||||||
properties: true,
|
|
||||||
sequences: false,
|
|
||||||
side_effects: true,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f1() {
|
|
||||||
var e = 7;
|
|
||||||
var s = "abcdef";
|
|
||||||
var i = 2;
|
|
||||||
var eval = console.log.bind(console);
|
|
||||||
var x = s.charAt(i++);
|
|
||||||
var y = s.charAt(i++);
|
|
||||||
var z = s.charAt(i++);
|
|
||||||
eval(x, y, z, e);
|
|
||||||
}
|
|
||||||
function p1() { var a = foo(), b = bar(), eval = baz(); return a + b + eval; }
|
|
||||||
function p2() { var a = foo(), b = bar(), eval = baz; return a + b + eval(); }
|
|
||||||
(function f2(eval) {
|
|
||||||
var a = 2;
|
|
||||||
console.log(a - 5);
|
|
||||||
eval("console.log(a);");
|
|
||||||
})(eval);
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f1() {
|
|
||||||
var e = 7,
|
|
||||||
s = "abcdef",
|
|
||||||
i = 2,
|
|
||||||
eval = console.log.bind(console),
|
|
||||||
x = s.charAt(i++),
|
|
||||||
y = s.charAt(i++),
|
|
||||||
z = s.charAt(i++);
|
|
||||||
eval(x, y, z, e);
|
|
||||||
}
|
|
||||||
function p1() { return foo() + bar() + baz(); }
|
|
||||||
function p2() { var a = foo(), b = bar(), eval = baz; return a + b + eval(); }
|
|
||||||
(function f2(eval) {
|
|
||||||
var a = 2;
|
|
||||||
console.log(a - 5);
|
|
||||||
eval("console.log(a);");
|
|
||||||
})(eval);
|
|
||||||
}
|
|
||||||
expect_stdout: true
|
|
||||||
}
|
|
||||||
|
|
||||||
eval_unused: {
|
|
||||||
options = {
|
|
||||||
keep_fargs: false,
|
|
||||||
unused: true,
|
|
||||||
}
|
|
||||||
input: {
|
|
||||||
function f1(a, eval, c, d, e) {
|
|
||||||
return a('c') + eval;
|
|
||||||
}
|
|
||||||
function f2(a, b, c, d, e) {
|
|
||||||
return a + eval('c');
|
|
||||||
}
|
|
||||||
function f3(a, eval, c, d, e) {
|
|
||||||
return a + eval('c');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect: {
|
|
||||||
function f1(a, eval) {
|
|
||||||
return a('c') + eval;
|
|
||||||
}
|
|
||||||
function f2(a, b, c, d, e) {
|
|
||||||
return a + eval('c');
|
|
||||||
}
|
|
||||||
function f3(a, eval, c, d, e) {
|
|
||||||
return a + eval('c');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
eval_mangle: {
|
|
||||||
mangle = {
|
|
||||||
};
|
|
||||||
input: {
|
|
||||||
function f1(a, eval, c, d, e) {
|
|
||||||
return a('c') + eval;
|
|
||||||
}
|
|
||||||
function f2(a, b, c, d, e) {
|
|
||||||
return a + eval('c');
|
|
||||||
}
|
|
||||||
function f3(a, eval, c, d, e) {
|
|
||||||
return a + eval('c');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect_exact: 'function f1(n,c,e,a,f){return n("c")+c}function f2(a,b,c,d,e){return a+eval("c")}function f3(a,eval,c,d,e){return a+eval("c")}'
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user