pax_global_header00006660000000000000000000000064135106131230014505gustar00rootroot0000000000000052 comment=e73277e82cfe756a35e424564ce3ab5da559c1d6 terser-4.1.2/000077500000000000000000000000001351061312300130155ustar00rootroot00000000000000terser-4.1.2/.editorconfig000066400000000000000000000003351351061312300154730ustar00rootroot00000000000000# EditorConfig is awesome: http://EditorConfig.org root = true # Unix-style newlines with a newline ending every file [*] end_of_line = lf insert_final_newline = true charset = utf-8 indent_style = space indent_size = 4 terser-4.1.2/.gitattributes000066400000000000000000000000241351061312300157040ustar00rootroot00000000000000*.js text eol=lf terser-4.1.2/.github/000077500000000000000000000000001351061312300143555ustar00rootroot00000000000000terser-4.1.2/.github/ISSUE_TEMPLATE.md000066400000000000000000000016501351061312300170640ustar00rootroot00000000000000 **Bug report or Feature request?** **Version (complete output of `terser -V` or specific git commit)** **Complete CLI command or `minify()` options used** **`terser` input** **`terser` output or error** **Expected result** terser-4.1.2/.gitignore000066400000000000000000000000731351061312300150050ustar00rootroot00000000000000/.idea/ /node_modules/ /npm-debug.log tmp/ dist/ coverage/ terser-4.1.2/.travis.yml000066400000000000000000000003041351061312300151230ustar00rootroot00000000000000os: - linux - windows language: node_js node_js: - 6 - 8 - 10 - 12 env: - UGLIFYJS_TEST_ALL=1 TRAVIS=1 matrix: fast_finish: true cache: directories: - tmp - node_modules terser-4.1.2/CHANGELOG.md000066400000000000000000000067621351061312300146410ustar00rootroot00000000000000# Changelog ## v4.1.2 - The hotfix was hotfixed ## v4.1.1 - Fixed a bug where toplevel scopes were being mixed up with lambda scopes ## v4.1.0 - Internal functions were replaced by `Object.assign`, `Array.prototype.some`, `Array.prototype.find` and `Array.prototype.every`. - A serious issue where some ESM-native code was broken was fixed. - Performance improvements were made. - Support for BigInt was added. - Inline efficiency was improved. Functions are now being inlined more proactively instead of being inlined only after another Compressor pass. ## v4.0.2 (Hotfix release. Reverts unmapped segments PR [#342](https://github.com/terser-js/terser/pull/342), which will be put back on Terser when the upstream issue is resolved) ## v4.0.1 - Collisions between the arguments of inlined functions and names in the outer scope are now being avoided while inlining - Unmapped segments are now preserved when compressing a file which has source maps - Default values of functions are now correctly converted from Mozilla AST to Terser AST - JSON ⊂ ECMAScript spec (if you don't know what this is you don't need to) - Export AST_* classes to library users - Fixed issue with `collapse_vars` when functions are created with the same name as a variable which already exists - Added `MutationObserverInit` (Object with options for initialising a mutation observer) properties to the DOM property list - Custom `Error` subclasses are now internally used instead of old-school Error inheritance hacks. - Documentation fixes - Performance optimizations ## v4.0.0 - **breaking change**: The `variables` property of all scopes has become a standard JavaScript `Map` as opposed to the old bespoke `Dictionary` object. - Typescript definitions were fixed - `terser --help` was fixed - The public interface was cleaned up - Fixed optimisation of `Array` and `new Array` - Added the `keep_quoted=strict` mode to mangle_props, which behaves more like Google Closure Compiler by mangling all unquoted property names, instead of reserving quoted property names automatically. - Fixed parent functions' parameters being shadowed in some cases - Allowed Terser to run in a situation where there are custom functions attached to Object.prototype - And more bug fixes, optimisations and internal changes ## v3.17.0 - More DOM properties added to --mangle-properties's DOM property list - Closed issue where if 2 functions had the same argument name, Terser would not inline them together properly - Fixed issue with `hasOwnProperty.call` - You can now list files to minify in a Terser config file - Started replacing `new Array()` with an array literal - Started using ES6 capabilities like `Set` and the `includes` method for strings and arrays ## v3.16.1 - Fixed issue where Terser being imported with `import` would cause it not to work due to the `__esModule` property. (PR #254 was submitted, which was nice, but since it wasn't a pure commonJS approach I decided to go with my own solution) ## v3.16.0 - No longer leaves names like Array or Object or window as a SimpleStatement (statement which is just a single expression). - Add support for sections sourcemaps (IndexedSourceMapConsumer) - Drops node.js v4 and starts using commonJS - Is now built with rollup ## v3.15.0 - Inlined spread syntax (`[...[1, 2, 3], 4, 5] => [1, 2, 3, 4, 5]`) in arrays and objects. - Fixed typo in compressor warning - Fixed inline source map input bug - Fixed parsing of template literals with unnecessary escapes (Like `\\a`) terser-4.1.2/CONTRIBUTING.md000066400000000000000000000240231351061312300152470ustar00rootroot00000000000000# Contributing When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change. Please note we have a code of conduct, please follow it in all your interactions with the project. ## Pull Request Process 1. Ensure any install or build dependencies are removed before the end of the layer when doing a build. 2. Update the README.md with details of changes to the interface, this includes new environment variables, exposed ports, useful file locations and container parameters. 3. Increase the version numbers in any examples files and the README.md to the new version that this Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). 4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you. ## Code of Conduct ### Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. ### Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ### Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ### Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ### Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [INSERT EMAIL ADDRESS]. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ### Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] [homepage]: http://contributor-covenant.org [version]: http://contributor-covenant.org/version/1/4/) When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change. Please note we have a code of conduct, please follow it in all your interactions with the project. ## Pull Request Process 1. Ensure any install or build dependencies are removed before the end of the layer when doing a build. 2. Update the README.md with details of changes to the interface, this includes new environment variables, exposed ports, useful file locations and container parameters. 3. Increase the version numbers in any examples files and the README.md to the new version that this Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). 4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you. ## Code of Conduct ### Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. ### Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ### Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ### Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ### Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [INSERT EMAIL ADDRESS]. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ### Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] # Technical information ## Documentation Every new feature and API change should be accompanied by a README addition. ## Enabling dev mode Normally when you require terser or use the CLI, you get a compiled version. When developing terser, you want to use the files you're actually editing to make those tests pass. So, add to your .bashrc: `TERSER_NO_BUNDLE=1`. ## 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. - 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. - Code must pass the lint (`npm run lint`, or `npm run lint-fix` for auto-fix). **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); } } ``` [homepage]: http://contributor-covenant.org [version]: http://contributor-covenant.org/version/1/4/ terser-4.1.2/LICENSE000066400000000000000000000025041351061312300140230ustar00rootroot00000000000000UglifyJS is released under the BSD license: Copyright 2012-2018 (c) Mihai Bazon 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. terser-4.1.2/PATRONS.md000066400000000000000000000005251351061312300144670ustar00rootroot00000000000000# Our patrons These are the first-tier patrons from [Patreon](https://www.patreon.com/fabiosantoscode). My appreciation goes to everyone on this list for supporting the project! * 38elements * Alan Orozco * CKEditor * Mariusz Nowak * Nakshatra Mukhopadhyay * Philippe Léger * Piotrek Koszuliński * Serhiy Shyyko * Viktor Hubert terser-4.1.2/README.md000066400000000000000000001533501351061312300143030ustar00rootroot00000000000000terser ====== ![Terser](https://raw.githubusercontent.com/terser-js/terser/master/logo.png) A JavaScript parser and mangler/compressor toolkit for ES6+. *note*: You can support this project on patreon: patron. Check out [PATRONS.md](https://github.com/terser-js/terser/blob/master/PATRONS.md) for our first-tier patrons. Terser recommends you use RollupJS to bundle your modules, as that produces smaller code overall. *Beautification* has been undocumented and is *being removed* from terser, we recommend you use [prettier](https://npmjs.com/package/prettier). [![Build Status](https://travis-ci.org/terser-js/terser.svg?branch=master)](https://travis-ci.org/terser-js/terser) Find the changelog in [CHANGELOG.md](https://github.com/terser-js/terser/blob/master/CHANGELOG.md) A JavaScript parser, mangler/compressor and beautifier toolkit for ES6+. Why choose terser? ------------------ `uglify-es` is [no longer maintained](https://github.com/mishoo/UglifyJS2/issues/3156#issuecomment-392943058) and `uglify-js` does not support ES6+. **`terser`** is a fork of `uglify-es` that mostly retains API and CLI compatibility with `uglify-es` and `uglify-js@3`. Install ------- First make sure you have installed the latest version of [node.js](http://nodejs.org/) (You may need to restart your computer after this step). From NPM for use as a command line app: npm install terser -g From NPM for programmatic use: npm install terser # Command line usage terser [input files] [options] Terser can take multiple input files. It's recommended that you pass the input files first, then pass the options. Terser will parse input files in sequence and apply any compression options. The files are parsed in the same global scope, that is, a reference from a file to some variable/function declared in another file will be matched properly. If no input file is specified, Terser will read from STDIN. If you wish to pass your options before the input files, separate the two with a double dash to prevent input files being used as option arguments: terser --compress --mangle -- input.js ### Command line options ``` -h, --help Print usage information. `--help options` for details on available options. -V, --version Print version number. -p, --parse Specify parser options: `acorn` Use Acorn for parsing. `bare_returns` Allow return outside of functions. Useful when minifying CommonJS modules and Userscripts that may be anonymous function wrapped (IIFE) by the .user.js engine `caller`. `expression` Parse a single expression, rather than a program (for parsing JSON). `spidermonkey` Assume input files are SpiderMonkey AST format (as JSON). -c, --compress [options] Enable compressor/specify compressor options: `pure_funcs` List of functions that can be safely removed when their return values are not used. -m, --mangle [options] Mangle names/specify mangler options: `reserved` List of names that should not be mangled. --mangle-props [options] Mangle properties/specify mangler options: `builtins` Mangle property names that overlaps with standard JavaScript globals. `debug` Add debug prefix and suffix. `domprops` Mangle property names that overlaps with DOM properties. `keep_quoted` Only mangle unquoted properties, quoted properties are automatically reserved. `strict` disables quoted properties being automatically reserved. `regex` Only mangle matched property names. `reserved` List of names that should not be mangled. -b, --beautify [options] Specify output options: `preamble` Preamble to prepend to the output. You can use this to insert a comment, for example for licensing information. This will not be parsed, but the source map will adjust for its presence. `quote_style` Quote style: 0 - auto 1 - single 2 - double 3 - original `wrap_iife` Wrap IIFEs in parenthesis. Note: you may want to disable `negate_iife` under compressor options. -o, --output Output file path (default STDOUT). Specify `ast` or `spidermonkey` to write Terser or SpiderMonkey AST as JSON to STDOUT respectively. --comments [filter] Preserve copyright comments in the output. By default this works like Google Closure, keeping JSDoc-style comments that contain "@license" or "@preserve". You can optionally pass one of the following arguments to this flag: - "all" to keep all comments - a valid JS RegExp like `/foo/` or `/^!/` to keep only matching comments. Note that currently not *all* comments can be kept when compression is on, because of dead code removal or cascading statements into sequences. --config-file Read `minify()` options from JSON file. -d, --define [=value] Global definitions. --ecma Specify ECMAScript release: 5, 6, 7 or 8. -e, --enclose [arg[:value]] Embed output in a big function with configurable arguments and values. --ie8 Support non-standard Internet Explorer 8. Equivalent to setting `ie8: true` in `minify()` for `compress`, `mangle` and `output` options. By default Terser will not try to be IE-proof. --keep-classnames Do not mangle/drop class names. --keep-fnames Do not mangle/drop function names. Useful for code relying on Function.prototype.name. --module Input is an ES6 module. If `compress` or `mangle` is enabled then the `toplevel` option will be enabled. --name-cache File to hold mangled name mappings. --safari10 Support non-standard Safari 10/11. Equivalent to setting `safari10: true` in `minify()` for `mangle` and `output` options. By default `terser` will not work around Safari 10/11 bugs. --source-map [options] Enable source map/specify source map options: `base` Path to compute relative paths from input files. `content` Input source map, useful if you're compressing JS that was generated from some other original code. Specify "inline" if the source map is included within the sources. `filename` Name and/or location of the output source. `includeSources` Pass this flag if you want to include the content of source files in the source map as sourcesContent property. `root` Path to the original source to be included in the source map. `url` If specified, path to the source map to append in `//# sourceMappingURL`. --timings Display operations run time on STDERR. --toplevel Compress and/or mangle variables in top level scope. --verbose Print diagnostic messages. --warn Print warning messages. --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. ``` Specify `--output` (`-o`) to declare the output file. Otherwise the output goes to STDOUT. ## CLI source map options Terser can generate a source map file, which is highly useful for debugging your compressed JavaScript. To get a source map, pass `--source-map --output output.js` (source map will be written out to `output.js.map`). Additional options: - `--source-map "filename=''"` to specify the name of the source map. - `--source-map "root=''"` to pass the URL where the original files can be found. - `--source-map "url=''"` to specify the URL where the source map can be found. Otherwise Terser assumes HTTP `X-SourceMap` is being used and will omit the `//# sourceMappingURL=` directive. For example: terser js/file1.js js/file2.js \ -o foo.min.js -c -m \ --source-map "root='http://foo.com/src',url='foo.min.js.map'" The above will compress and mangle `file1.js` and `file2.js`, will drop the output in `foo.min.js` and the source map in `foo.min.js.map`. The source mapping will refer to `http://foo.com/src/js/file1.js` and `http://foo.com/src/js/file2.js` (in fact it will list `http://foo.com/src` as the source map root, and the original files as `js/file1.js` and `js/file2.js`). ### Composed source map When you're compressing JS code that was output by a compiler such as CoffeeScript, mapping to the JS code won't be too helpful. Instead, you'd like to map back to the original code (i.e. CoffeeScript). Terser has an option to take an input source map. Assuming you have a mapping from CoffeeScript → compiled JS, Terser can generate a map from CoffeeScript → compressed JS by mapping every token in the compiled JS to its original location. To use this feature pass `--source-map "content='/path/to/input/source.map'"` or `--source-map "content=inline"` if the source map is included inline with the sources. ## CLI compress options You need to pass `--compress` (`-c`) to enable the compressor. Optionally you can pass a comma-separated list of [compress options](#compress-options). Options are in the form `foo=bar`, or just `foo` (the latter implies a boolean option that you want to set `true`; it's effectively a shortcut for `foo=true`). Example: terser file.js -c toplevel,sequences=false ## CLI mangle options To enable the mangler you need to pass `--mangle` (`-m`). The following (comma-separated) options are supported: - `toplevel` (default `false`) -- mangle names declared in the top level scope. - `eval` (default `false`) -- mangle names visible in scopes where `eval` or `with` are used. When mangling is enabled but you want to prevent certain names from being mangled, you can declare those names with `--mangle reserved` — pass a comma-separated list of names. For example: terser ... -m reserved=['$','require','exports'] to prevent the `require`, `exports` and `$` names from being changed. ### CLI mangling property names (`--mangle-props`) **Note:** THIS **WILL** BREAK YOUR CODE. A good rule of thumb is not to use this unless you know exactly what you're doing and how this works and read this section until the end. Mangling property names is a separate step, different from variable name mangling. Pass `--mangle-props` to enable it. The least dangerous way to use this is to use the `regex` option like so: ``` terser example.js -c -m --mangle-props regex=/_$/ ``` This will mangle all properties that start with an underscore. So you can use it to mangle internal methods. By default, it will mangle all properties in the input code with the exception of built in DOM properties and properties in core JavaScript classes, which is what will break your code if you don't: 1. Control all the code you're mangling 2. Avoid using a module bundler, as they usually will call Terser on each file individually, making it impossible to pass mangled objects between modules. 3. Avoid calling functions like `defineProperty` or `hasOwnProperty`, because they refer to object properties using strings and will break your code if you don't know what you are doing. An example: ```javascript // example.js var x = { baz_: 0, foo_: 1, calc: function() { return this.foo_ + this.baz_; } }; x.bar_ = 2; x["baz_"] = 3; console.log(x.calc()); ``` Mangle all properties (except for JavaScript `builtins`) (**very** unsafe): ```bash $ terser example.js -c -m --mangle-props ``` ```javascript var x={o:0,_:1,l:function(){return this._+this.o}};x.t=2,x.o=3,console.log(x.l()); ``` Mangle all properties except for `reserved` properties (still very unsafe): ```bash $ terser example.js -c -m --mangle-props reserved=[foo_,bar_] ``` ```javascript var x={o:0,foo_:1,_:function(){return this.foo_+this.o}};x.bar_=2,x.o=3,console.log(x._()); ``` Mangle all properties matching a `regex` (not as unsafe but still unsafe): ```bash $ terser example.js -c -m --mangle-props regex=/_$/ ``` ```javascript var x={o:0,_:1,calc:function(){return this._+this.o}};x.l=2,x.o=3,console.log(x.calc()); ``` Combining mangle properties options: ```bash $ terser example.js -c -m --mangle-props regex=/_$/,reserved=[bar_] ``` ```javascript var x={o:0,_:1,calc:function(){return this._+this.o}};x.bar_=2,x.o=3,console.log(x.calc()); ``` In order for this to be of any use, we avoid mangling standard JS names by default (`--mangle-props builtins` to override). A default exclusion file is provided in `tools/domprops.json` which should cover most standard JS and DOM properties defined in various browsers. Pass `--mangle-props domprops` to disable this feature. A regular expression can be used to define which property names should be mangled. For example, `--mangle-props regex=/^_/` will only mangle property names that start with an underscore. When you compress multiple files using this option, in order for them to work together in the end we need to ensure somehow that one property gets mangled to the same name in all of them. For this, pass `--name-cache filename.json` and Terser will maintain these mappings in a file which can then be reused. It should be initially empty. Example: ```bash $ rm -f /tmp/cache.json # start fresh $ terser file1.js file2.js --mangle-props --name-cache /tmp/cache.json -o part1.js $ terser file3.js file4.js --mangle-props --name-cache /tmp/cache.json -o part2.js ``` Now, `part1.js` and `part2.js` will be consistent with each other in terms of mangled property names. Using the name cache is not necessary if you compress all your files in a single call to Terser. ### Mangling unquoted names (`--mangle-props keep_quoted`) Using quoted property name (`o["foo"]`) reserves the property name (`foo`) so that it is not mangled throughout the entire script even when used in an unquoted style (`o.foo`). Example: ```javascript // stuff.js var o = { "foo": 1, bar: 3 }; o.foo += o.bar; console.log(o.foo); ``` ```bash $ terser stuff.js --mangle-props keep_quoted -c -m ``` ```javascript var o={foo:1,o:3};o.foo+=o.o,console.log(o.foo); ``` ### Debugging property name mangling You can also pass `--mangle-props debug` in order to mangle property names without completely obscuring them. For example the property `o.foo` would mangle to `o._$foo$_` with this option. This allows property mangling of a large codebase while still being able to debug the code and identify where mangling is breaking things. ```bash $ terser stuff.js --mangle-props debug -c -m ``` ```javascript var o={_$foo$_:1,_$bar$_:3};o._$foo$_+=o._$bar$_,console.log(o._$foo$_); ``` You can also pass a custom suffix using `--mangle-props debug=XYZ`. This would then mangle `o.foo` to `o._$foo$XYZ_`. You can change this each time you compile a script to identify how a property got mangled. One technique is to pass a random number on every compile to simulate mangling changing with different inputs (e.g. as you update the input script with new properties), and to help identify mistakes like writing mangled keys to storage. # API Reference Assuming installation via NPM, you can load Terser in your application like this: ```javascript var Terser = require("terser"); ``` Browser loading is also supported: ```html ``` There is a single high level function, **`minify(code, options)`**, which will perform all minification [phases](#minify-options) in a configurable manner. By default `minify()` will enable the options [`compress`](#compress-options) and [`mangle`](#mangle-options). Example: ```javascript var code = "function add(first, second) { return first + second; }"; var result = Terser.minify(code); console.log(result.error); // runtime error, or `undefined` if no error console.log(result.code); // minified output: function add(n,d){return n+d} ``` You can `minify` more than one JavaScript file at a time by using an object for the first argument where the keys are file names and the values are source code: ```javascript var code = { "file1.js": "function add(first, second) { return first + second; }", "file2.js": "console.log(add(1 + 2, 3 + 4));" }; var result = Terser.minify(code); console.log(result.code); // function add(d,n){return d+n}console.log(add(3,7)); ``` The `toplevel` option: ```javascript var code = { "file1.js": "function add(first, second) { return first + second; }", "file2.js": "console.log(add(1 + 2, 3 + 4));" }; var options = { toplevel: true }; var result = Terser.minify(code, options); console.log(result.code); // console.log(3+7); ``` The `nameCache` option: ```javascript var options = { mangle: { toplevel: true, }, nameCache: {} }; var result1 = Terser.minify({ "file1.js": "function add(first, second) { return first + second; }" }, options); var result2 = Terser.minify({ "file2.js": "console.log(add(1 + 2, 3 + 4));" }, options); console.log(result1.code); // function n(n,r){return n+r} console.log(result2.code); // console.log(n(3,7)); ``` You may persist the name cache to the file system in the following way: ```javascript var cacheFileName = "/tmp/cache.json"; var options = { mangle: { properties: true, }, nameCache: JSON.parse(fs.readFileSync(cacheFileName, "utf8")) }; fs.writeFileSync("part1.js", Terser.minify({ "file1.js": fs.readFileSync("file1.js", "utf8"), "file2.js": fs.readFileSync("file2.js", "utf8") }, options).code, "utf8"); fs.writeFileSync("part2.js", Terser.minify({ "file3.js": fs.readFileSync("file3.js", "utf8"), "file4.js": fs.readFileSync("file4.js", "utf8") }, options).code, "utf8"); fs.writeFileSync(cacheFileName, JSON.stringify(options.nameCache), "utf8"); ``` An example of a combination of `minify()` options: ```javascript var code = { "file1.js": "function add(first, second) { return first + second; }", "file2.js": "console.log(add(1 + 2, 3 + 4));" }; var options = { toplevel: true, compress: { global_defs: { "@console.log": "alert" }, passes: 2 }, output: { beautify: false, preamble: "/* minified */" } }; var result = Terser.minify(code, options); console.log(result.code); // /* minified */ // alert(10);" ``` To produce warnings: ```javascript var code = "function f(){ var u; return 2 + 3; }"; var options = { warnings: true }; var result = Terser.minify(code, options); console.log(result.error); // runtime error, `undefined` in this case console.log(result.warnings); // [ 'Dropping unused variable u [0:1,18]' ] console.log(result.code); // function f(){return 5} ``` An error example: ```javascript var result = Terser.minify({"foo.js" : "if (0) else console.log(1);"}); console.log(JSON.stringify(result.error)); // {"message":"Unexpected token: keyword (else)","filename":"foo.js","line":1,"col":7,"pos":7} ``` Note: unlike `uglify-js@2.x`, the Terser API does not throw errors. To achieve a similar effect one could do the following: ```javascript var result = Terser.minify(code, options); if (result.error) throw result.error; ``` ## Minify options - `ecma` (default `undefined`) - pass `5`, `6`, `7` or `8` to override `parse`, `compress` and `output` options. - `warnings` (default `false`) — pass `true` to return compressor warnings in `result.warnings`. Use the value `"verbose"` for more detailed warnings. - `parse` (default `{}`) — pass an object if you wish to specify some additional [parse options](#parse-options). - `compress` (default `{}`) — pass `false` to skip compressing entirely. Pass an object to specify custom [compress options](#compress-options). - `mangle` (default `true`) — pass `false` to skip mangling names, or pass an object to specify [mangle options](#mangle-options) (see below). - `mangle.properties` (default `false`) — a subcategory of the mangle option. Pass an object to specify custom [mangle property options](#mangle-properties-options). - `module` (default `false`) — Use when minifying an ES6 module. "use strict" is implied and names can be mangled on the top scope. If `compress` or `mangle` is enabled then the `toplevel` option will be enabled. - `output` (default `null`) — pass an object if you wish to specify additional [output options](#output-options). The defaults are optimized for best compression. - `sourceMap` (default `false`) - pass an object if you wish to specify [source map options](#source-map-options). - `toplevel` (default `false`) - set to `true` if you wish to enable top level variable and function name mangling and to drop unused variables and functions. - `nameCache` (default `null`) - pass an empty object `{}` or a previously used `nameCache` object if you wish to cache mangled variable and property names across multiple invocations of `minify()`. Note: this is a read/write property. `minify()` will read the name cache state of this object and update it during minification so that it may be reused or externally persisted by the user. - `ie8` (default `false`) - set to `true` to support IE8. - `keep_classnames` (default: `undefined`) - pass `true` to prevent discarding or mangling of class names. Pass a regular expression to only keep class names matching that regex. - `keep_fnames` (default: `false`) - pass `true` to prevent discarding or mangling of function names. Pass a regular expression to only keep class names matching that regex. Useful for code relying on `Function.prototype.name`. If the top level minify option `keep_classnames` is `undefined` it will be overridden with the value of the top level minify option `keep_fnames`. - `safari10` (default: `false`) - pass `true` to work around Safari 10/11 bugs in loop scoping and `await`. See `safari10` options in [`mangle`](#mangle-options) and [`output`](#output-options) for details. ## Minify options structure ```javascript { parse: { // parse options }, compress: { // compress options }, mangle: { // mangle options properties: { // mangle property options } }, output: { // output options }, sourceMap: { // source map options }, ecma: 5, // specify one of: 5, 6, 7 or 8 keep_classnames: false, keep_fnames: false, ie8: false, module: false, nameCache: null, // or specify a name cache object safari10: false, toplevel: false, warnings: false, } ``` ### Source map options To generate a source map: ```javascript var result = Terser.minify({"file1.js": "var a = function() {};"}, { sourceMap: { filename: "out.js", url: "out.js.map" } }); console.log(result.code); // minified output console.log(result.map); // source map ``` Note that the source map is not saved in a file, it's just returned in `result.map`. The value passed for `sourceMap.url` is only used to set `//# sourceMappingURL=out.js.map` in `result.code`. The value of `filename` is only used to set `file` attribute (see [the spec][sm-spec]) in source map file. You can set option `sourceMap.url` to be `"inline"` and source map will be appended to code. You can also specify sourceRoot property to be included in source map: ```javascript var result = Terser.minify({"file1.js": "var a = function() {};"}, { sourceMap: { root: "http://example.com/src", url: "out.js.map" } }); ``` If you're compressing compiled JavaScript and have a source map for it, you can use `sourceMap.content`: ```javascript var result = Terser.minify({"compiled.js": "compiled code"}, { sourceMap: { content: "content from compiled.js.map", url: "minified.js.map" } }); // same as before, it returns `code` and `map` ``` If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.url`. ## Parse options - `bare_returns` (default `false`) -- support top level `return` statements - `ecma` (default: `8`) -- specify one of `5`, `6`, `7` or `8`. Note: this setting is not presently enforced except for ES8 optional trailing commas in function parameter lists and calls with `ecma` `8`. - `html5_comments` (default `true`) - `shebang` (default `true`) -- support `#!command` as the first line ## Compress options - `arrows` (default: `true`) -- Converts `()=>{return x}` to `()=>x`. Class and object literal methods will also be converted to arrow expressions if the resultant code is shorter: `m(){return x}` becomes `m:()=>x`. - `arguments` (default: `false`) -- replace `arguments[index]` with function parameter name whenever possible. - `booleans` (default: `true`) -- various optimizations for boolean context, for example `!!a ? b : c → a ? b : c` - `booleans_as_integers` (default: `false`) -- Turn booleans into 0 and 1, also makes comparisons with booleans use `==` and `!=` instead of `===` and `!==`. - `collapse_vars` (default: `true`) -- Collapse single-use non-constant variables, side effects permitting. - `comparisons` (default: `true`) -- apply certain optimizations to binary nodes, e.g. `!(a <= b) → a > b` (only when `unsafe_comps`), attempts to negate binary nodes, e.g. `a = !b && !c && !d && !e → a=!(b||c||d||e)` etc. - `computed_props` (default: `true`) -- Transforms constant computed properties into regular ones: `{["computed"]: 1}` is converted to `{computed: 1}`. - `conditionals` (default: `true`) -- apply optimizations for `if`-s and conditional expressions - `dead_code` (default: `true`) -- remove unreachable code - `defaults` (default: `true`) -- Pass `false` to disable most default enabled `compress` transforms. Useful when you only want to enable a few `compress` options while disabling the rest. - `directives` (default: `true`) -- remove redundant or non-standard directives - `drop_console` (default: `false`) -- Pass `true` to discard calls to `console.*` functions. If you wish to drop a specific function call such as `console.info` and/or retain side effects from function arguments after dropping the function call then use `pure_funcs` instead. - `drop_debugger` (default: `true`) -- remove `debugger;` statements - `ecma` (default: `5`) -- Pass `6` or greater to enable `compress` options that will transform ES5 code into smaller ES6+ equivalent forms. - `evaluate` (default: `true`) -- attempt to evaluate constant expressions - `expression` (default: `false`) -- Pass `true` to preserve completion values from terminal statements without `return`, e.g. in bookmarklets. - `global_defs` (default: `{}`) -- see [conditional compilation](#conditional-compilation) - `hoist_funs` (default: `false`) -- hoist function declarations - `hoist_props` (default: `true`) -- hoist properties from constant object and array literals into regular variables subject to a set of constraints. For example: `var o={p:1, q:2}; f(o.p, o.q);` is converted to `f(1, 2);`. Note: `hoist_props` works best with `mangle` enabled, the `compress` option `passes` set to `2` or higher, and the `compress` option `toplevel` enabled. - `hoist_vars` (default: `false`) -- hoist `var` declarations (this is `false` by default because it seems to increase the size of the output in general) - `if_return` (default: `true`) -- optimizations for if/return and if/continue - `inline` (default: `true`) -- inline calls to function with simple/`return` statement: - `false` -- same as `0` - `0` -- disabled inlining - `1` -- inline simple functions - `2` -- inline functions with arguments - `3` -- inline functions with arguments and variables - `true` -- same as `3` - `join_vars` (default: `true`) -- join consecutive `var` statements - `keep_classnames` (default: `false`) -- Pass `true` to prevent the compressor from discarding class names. Pass a regular expression to only keep class names matching that regex. See also: the `keep_classnames` [mangle option](#mangle). - `keep_fargs` (default: `true`) -- Prevents the compressor from discarding unused function arguments. You need this for code which relies on `Function.length`. - `keep_fnames` (default: `false`) -- Pass `true` to prevent the compressor from discarding function names. Pass a regular expression to only keep function names matching that regex. Useful for code relying on `Function.prototype.name`. See also: the `keep_fnames` [mangle option](#mangle). - `keep_infinity` (default: `false`) -- Pass `true` to prevent `Infinity` from being compressed into `1/0`, which may cause performance issues on Chrome. - `loops` (default: `true`) -- optimizations for `do`, `while` and `for` loops when we can statically determine the condition. - `module` (default `false`) -- Pass `true` when compressing an ES6 module. Strict mode is implied and the `toplevel` option as well. - `negate_iife` (default: `true`) -- negate "Immediately-Called Function Expressions" where the return value is discarded, to avoid the parens that the code generator would insert. - `passes` (default: `1`) -- The maximum number of times to run compress. In some cases more than one pass leads to further compressed code. Keep in mind more passes will take more time. - `properties` (default: `true`) -- rewrite property access using the dot notation, for example `foo["bar"] → foo.bar` - `pure_funcs` (default: `null`) -- You can pass an array of names and Terser will assume that those functions do not produce side effects. DANGER: will not check if the name is redefined in scope. An example case here, for instance `var q = Math.floor(a/b)`. If variable `q` is not used elsewhere, Terser will drop it, but will still keep the `Math.floor(a/b)`, not knowing what it does. You can pass `pure_funcs: [ 'Math.floor' ]` to let it know that this function won't produce any side effect, in which case the whole statement would get discarded. The current implementation adds some overhead (compression will be slower). - `pure_getters` (default: `"strict"`) -- If you pass `true` for this, Terser will assume that object property access (e.g. `foo.bar` or `foo["bar"]`) doesn't have any side effects. Specify `"strict"` to treat `foo.bar` as side-effect-free only when `foo` is certain to not throw, i.e. not `null` or `undefined`. - `reduce_funcs` (default: `true`) -- Allows single-use functions to be inlined as function expressions when permissible allowing further optimization. Enabled by default. Option depends on `reduce_vars` being enabled. Some code runs faster in the Chrome V8 engine if this option is disabled. Does not negatively impact other major browsers. - `reduce_vars` (default: `true`) -- Improve optimization on variables assigned with and used as constant values. - `sequences` (default: `true`) -- join consecutive simple statements using the comma operator. May be set to a positive integer to specify the maximum number of consecutive comma sequences that will be generated. If this option is set to `true` then the default `sequences` limit is `200`. Set option to `false` or `0` to disable. The smallest `sequences` length is `2`. A `sequences` value of `1` is grandfathered to be equivalent to `true` and as such means `200`. On rare occasions the default sequences limit leads to very slow compress times in which case a value of `20` or less is recommended. - `side_effects` (default: `true`) -- Pass `false` to disable potentially dropping functions marked as "pure". A function call is marked as "pure" if a comment annotation `/*@__PURE__*/` or `/*#__PURE__*/` immediately precedes the call. For example: `/*@__PURE__*/foo();` - `switches` (default: `true`) -- de-duplicate and remove unreachable `switch` branches - `toplevel` (default: `false`) -- drop unreferenced functions (`"funcs"`) and/or variables (`"vars"`) in the top level scope (`false` by default, `true` to drop both unreferenced functions and variables) - `top_retain` (default: `null`) -- prevent specific toplevel functions and variables from `unused` removal (can be array, comma-separated, RegExp or function. Implies `toplevel`) - `typeofs` (default: `true`) -- Transforms `typeof foo == "undefined"` into `foo === void 0`. Note: recommend to set this value to `false` for IE10 and earlier versions due to known issues. - `unsafe` (default: `false`) -- apply "unsafe" transformations ([details](#the-unsafe-compress-option)). - `unsafe_arrows` (default: `false`) -- Convert ES5 style anonymous function expressions to arrow functions if the function body does not reference `this`. Note: it is not always safe to perform this conversion if code relies on the the function having a `prototype`, which arrow functions lack. This transform requires that the `ecma` compress option is set to `6` or greater. - `unsafe_comps` (default: `false`) -- Reverse `<` and `<=` to `>` and `>=` to allow improved compression. This might be unsafe when an at least one of two operands is an object with computed values due the use of methods like `get`, or `valueOf`. This could cause change in execution order after operands in the comparison are switching. Compression only works if both `comparisons` and `unsafe_comps` are both set to true. - `unsafe_Function` (default: `false`) -- compress and mangle `Function(args, code)` when both `args` and `code` are string literals. - `unsafe_math` (default: `false`) -- optimize numerical expressions like `2 * x * 3` into `6 * x`, which may give imprecise floating point results. - `unsafe_methods` (default: false) -- Converts `{ m: function(){} }` to `{ m(){} }`. `ecma` must be set to `6` or greater to enable this transform. If `unsafe_methods` is a RegExp then key/value pairs with keys matching the RegExp will be converted to concise methods. Note: if enabled there is a risk of getting a "`` is not a constructor" TypeError should any code try to `new` the former function. - `unsafe_proto` (default: `false`) -- optimize expressions like `Array.prototype.slice.call(a)` into `[].slice.call(a)` - `unsafe_regexp` (default: `false`) -- enable substitutions of variables with `RegExp` values the same way as if they are constants. - `unsafe_undefined` (default: `false`) -- substitute `void 0` if there is a variable named `undefined` in scope (variable name will be mangled, typically reduced to a single character) - `unused` (default: `true`) -- drop unreferenced functions and variables (simple direct variable assignments do not count as references unless set to `"keep_assign"`) - `warnings` (default: `false`) -- display warnings when dropping unreachable code or unused declarations etc. ## Mangle options - `eval` (default `false`) -- Pass `true` to mangle names visible in scopes where `eval` or `with` are used. - `keep_classnames` (default `false`) -- Pass `true` to not mangle class names. Pass a regular expression to only keep class names matching that regex. See also: the `keep_classnames` [compress option](#compress-options). - `keep_fnames` (default `false`) -- Pass `true` to not mangle function names. Pass a regular expression to only keep class names matching that regex. Useful for code relying on `Function.prototype.name`. See also: the `keep_fnames` [compress option](#compress-options). - `module` (default `false`) -- Pass `true` an ES6 modules, where the toplevel scope is not the global scope. Implies `toplevel`. - `reserved` (default `[]`) -- Pass an array of identifiers that should be excluded from mangling. Example: `["foo", "bar"]`. - `toplevel` (default `false`) -- Pass `true` to mangle names declared in the top level scope. - `safari10` (default `false`) -- Pass `true` to work around the Safari 10 loop iterator [bug](https://bugs.webkit.org/show_bug.cgi?id=171041) "Cannot declare a let variable twice". See also: the `safari10` [output option](#output-options). Examples: ```javascript // test.js var globalVar; function funcName(firstLongName, anotherLongName) { var myVariable = firstLongName + anotherLongName; } ``` ```javascript var code = fs.readFileSync("test.js", "utf8"); Terser.minify(code).code; // 'function funcName(a,n){}var globalVar;' Terser.minify(code, { mangle: { reserved: ['firstLongName'] } }).code; // 'function funcName(firstLongName,a){}var globalVar;' Terser.minify(code, { mangle: { toplevel: true } }).code; // 'function n(n,a){}var a;' ``` ### Mangle properties options - `builtins` (default: `false`) — Use `true` to allow the mangling of builtin DOM properties. Not recommended to override this setting. - `debug` (default: `false`) — Mangle names with the original name still present. Pass an empty string `""` to enable, or a non-empty string to set the debug suffix. - `keep_quoted` (default: `false`) — Only mangle unquoted property names. - `true` -- Quoted property names are automatically reserved and any unquoted property names will not be mangled. - `"strict"` -- Advanced, all unquoted property names are mangled unless explicitly reserved. - `regex` (default: `null`) — Pass a [RegExp literal or pattern string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) to only mangle property matching the regular expression. - `reserved` (default: `[]`) — Do not mangle property names listed in the `reserved` array. ## Output options The code generator tries to output shortest code possible by default. In case you want beautified output, pass `--beautify` (`-b`). Optionally you can pass additional arguments that control the code output: - `ascii_only` (default `false`) -- escape Unicode characters in strings and regexps (affects directives with non-ascii characters becoming invalid) - `beautify` (default `true`) -- whether to actually beautify the output. Passing `-b` will set this to true, but you might need to pass `-b` even when you want to generate minified code, in order to specify additional arguments, so you can use `-b beautify=false` to override it. - `braces` (default `false`) -- always insert braces in `if`, `for`, `do`, `while` or `with` statements, even if their body is a single statement. - `comments` (default `false`) -- pass `true` or `"all"` to preserve all comments, `"some"` to preserve some comments, a regular expression string (e.g. `/^!/`) or a function. - `ecma` (default `5`) -- set output printing mode. Set `ecma` to `6` or greater to emit shorthand object properties - i.e.: `{a}` instead of `{a: a}`. The `ecma` option will only change the output in direct control of the beautifier. Non-compatible features in the abstract syntax tree will still be output as is. For example: an `ecma` setting of `5` will **not** convert ES6+ code to ES5. - `indent_level` (default `4`) - `indent_start` (default `0`) -- prefix all lines by that many spaces - `inline_script` (default `true`) -- escape HTML comments and the slash in occurrences of `` in strings - `keep_quoted_props` (default `false`) -- when turned on, prevents stripping quotes from property names in object literals. - `max_line_len` (default `false`) -- maximum line length (for minified code) - `preamble` (default `null`) -- when passed it must be a string and it will be prepended to the output literally. The source map will adjust for this text. Can be used to insert a comment containing licensing information, for example. - `quote_keys` (default `false`) -- pass `true` to quote all keys in literal objects - `quote_style` (default `0`) -- preferred quote style for strings (affects quoted property names and directives as well): - `0` -- prefers double quotes, switches to single quotes when there are more double quotes in the string itself. `0` is best for gzip size. - `1` -- always use single quotes - `2` -- always use double quotes - `3` -- always use the original quotes - `safari10` (default `false`) -- set this option to `true` to work around the [Safari 10/11 await bug](https://bugs.webkit.org/show_bug.cgi?id=176685). See also: the `safari10` [mangle option](#mangle-options). - `semicolons` (default `true`) -- separate statements with semicolons. If you pass `false` then whenever possible we will use a newline instead of a semicolon, leading to more readable output of minified code (size before gzip could be smaller; size after gzip insignificantly larger). - `shebang` (default `true`) -- preserve shebang `#!` in preamble (bash scripts) - `webkit` (default `false`) -- enable workarounds for WebKit bugs. PhantomJS users should set this option to `true`. - `wrap_iife` (default `false`) -- pass `true` to wrap immediately invoked function expressions. See [#640](https://github.com/mishoo/UglifyJS2/issues/640) for more details. # Miscellaneous ### Keeping copyright notices or other comments You can pass `--comments` to retain certain comments in the output. By default it will keep JSDoc-style comments that contain "@preserve", "@license" or "@cc_on" (conditional compilation for IE). You can pass `--comments all` to keep all the comments, or a valid JavaScript regexp to keep only comments that match this regexp. For example `--comments /^!/` will keep comments like `/*! Copyright Notice */`. Note, however, that there might be situations where comments are lost. For example: ```javascript function f() { /** @preserve Foo Bar */ function g() { // this function is never called } return something(); } ``` Even though it has "@preserve", the comment will be lost because the inner function `g` (which is the AST node to which the comment is attached to) is discarded by the compressor as not referenced. The safest comments where to place copyright information (or other info that needs to be kept in the output) are comments attached to toplevel nodes. ### The `unsafe` `compress` option It enables some transformations that *might* break code logic in certain contrived cases, but should be fine for most code. It assumes that standard built-in ECMAScript functions and classes have not been altered or replaced. You might want to try it on your own code; it should reduce the minified size. Some examples of the optimizations made when this option is enabled: - `new Array(1, 2, 3)` or `Array(1, 2, 3)` → `[ 1, 2, 3 ]` - `new Object()` → `{}` - `String(exp)` or `exp.toString()` → `"" + exp` - `new Object/RegExp/Function/Error/Array (...)` → we discard the `new` - `"foo bar".substr(4)` → `"bar"` ### Conditional compilation You can use the `--define` (`-d`) switch in order to declare global variables that Terser will assume to be constants (unless defined in scope). For example if you pass `--define DEBUG=false` then, coupled with dead code removal Terser will discard the following from the output: ```javascript if (DEBUG) { console.log("debug stuff"); } ``` You can specify nested constants in the form of `--define env.DEBUG=false`. Terser will warn about the condition being always false and about dropping unreachable code; for now there is no option to turn off only this specific warning, you can pass `warnings=false` to turn off *all* warnings. Another way of doing that is to declare your globals as constants in a separate file and include it into the build. For example you can have a `build/defines.js` file with the following: ```javascript var DEBUG = false; var PRODUCTION = true; // etc. ``` and build your code like this: terser build/defines.js js/foo.js js/bar.js... -c Terser will notice the constants and, since they cannot be altered, it will evaluate references to them to the value itself and drop unreachable code as usual. The build will contain the `const` declarations if you use them. If you are targeting < ES6 environments which does not support `const`, using `var` with `reduce_vars` (enabled by default) should suffice. ### Conditional compilation API You can also use conditional compilation via the programmatic API. With the difference that the property name is `global_defs` and is a compressor property: ```javascript var result = Terser.minify(fs.readFileSync("input.js", "utf8"), { compress: { dead_code: true, global_defs: { DEBUG: false } } }); ``` To replace an identifier with an arbitrary non-constant expression it is necessary to prefix the `global_defs` key with `"@"` to instruct Terser to parse the value as an expression: ```javascript Terser.minify("alert('hello');", { compress: { global_defs: { "@alert": "console.log" } } }).code; // returns: 'console.log("hello");' ``` Otherwise it would be replaced as string literal: ```javascript Terser.minify("alert('hello');", { compress: { global_defs: { "alert": "console.log" } } }).code; // returns: '"console.log"("hello");' ``` ### Using native Terser AST with `minify()` ```javascript // example: parse only, produce native Terser AST var result = Terser.minify(code, { parse: {}, compress: false, mangle: false, output: { ast: true, code: false // optional - faster if false } }); // result.ast contains native Terser AST ``` ```javascript // example: accept native Terser AST input and then compress and mangle // to produce both code and native AST. var result = Terser.minify(ast, { compress: {}, mangle: {}, output: { ast: true, code: true // optional - faster if false } }); // result.ast contains native Terser AST // result.code contains the minified code in string form. ``` ### Working with Terser AST Traversal and transformation of the native AST can be performed through [`TreeWalker`](https://github.com/fabiosantoscode/terser/blob/master/lib/ast.js) and [`TreeTransformer`](https://github.com/fabiosantoscode/terser/blob/master/lib/transform.js) respectively. Largely compatible native AST examples can be found in the original UglifyJS documentation. See: [tree walker](http://lisperator.net/uglifyjs/walk) and [tree transform](http://lisperator.net/uglifyjs/transform). ### ESTree / SpiderMonkey AST Terser has its own abstract syntax tree format; for [practical reasons](http://lisperator.net/blog/uglifyjs-why-not-switching-to-spidermonkey-ast/) we can't easily change to using the SpiderMonkey AST internally. However, Terser now has a converter which can import a SpiderMonkey AST. For example [Acorn][acorn] is a super-fast parser that produces a SpiderMonkey AST. It has a small CLI utility that parses one file and dumps the AST in JSON on the standard output. To use Terser to mangle and compress that: acorn file.js | terser -p spidermonkey -m -c The `-p spidermonkey` option tells Terser that all input files are not JavaScript, but JS code described in SpiderMonkey AST in JSON. Therefore we don't use our own parser in this case, but just transform that AST into our internal AST. ### Use Acorn for parsing More for fun, I added the `-p acorn` option which will use Acorn to do all the parsing. If you pass this option, Terser will `require("acorn")`. Acorn is really fast (e.g. 250ms instead of 380ms on some 650K code), but converting the SpiderMonkey tree that Acorn produces takes another 150ms so in total it's a bit more than just using Terser's own parser. [acorn]: https://github.com/ternjs/acorn [sm-spec]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k ### Terser Fast Minify Mode It's not well known, but whitespace removal and symbol mangling accounts for 95% of the size reduction in minified code for most JavaScript - not elaborate code transforms. One can simply disable `compress` to speed up Terser builds by 3 to 4 times. | d3.js | size | gzip size | time (s) | | --- | ---: | ---: | ---: | | original | 451,131 | 108,733 | - | | terser@3.7.5 mangle=false, compress=false | 316,600 | 85,245 | 0.82 | | terser@3.7.5 mangle=true, compress=false | 220,216 | 72,730 | 1.45 | | terser@3.7.5 mangle=true, compress=true | 212,046 | 70,954 | 5.87 | | babili@0.1.4 | 210,713 | 72,140 | 12.64 | | babel-minify@0.4.3 | 210,321 | 72,242 | 48.67 | | babel-minify@0.5.0-alpha.01eac1c3 | 210,421 | 72,238 | 14.17 | To enable fast minify mode from the CLI use: ``` terser file.js -m ``` To enable fast minify mode with the API use: ```js Terser.minify(code, { compress: false, mangle: true }); ``` #### Source maps and debugging Various `compress` transforms that simplify, rearrange, inline and remove code are known to have an adverse effect on debugging with source maps. This is expected as code is optimized and mappings are often simply not possible as some code no longer exists. For highest fidelity in source map debugging disable the `compress` option and just use `mangle`. ### Compiler assumptions To allow for better optimizations, the compiler makes various assumptions: - `.toString()` and `.valueOf()` don't have side effects, and for built-in objects they have not been overridden. - `undefined`, `NaN` and `Infinity` have not been externally redefined. - `arguments.callee`, `arguments.caller` and `Function.prototype.caller` are not used. - The code doesn't expect the contents of `Function.prototype.toString()` or `Error.prototype.stack` to be anything in particular. - Getting and setting properties on a plain object does not cause other side effects (using `.watch()` or `Proxy`). - Object properties can be added, removed and modified (not prevented with `Object.defineProperty()`, `Object.defineProperties()`, `Object.freeze()`, `Object.preventExtensions()` or `Object.seal()`). ### Build Tools and Adaptors using Terser https://www.npmjs.com/browse/depended/terser ### Replacing `uglify-es` with `terser` in a project using `yarn` A number of JS bundlers and uglify wrappers are still using buggy versions of `uglify-es` and have not yet upgraded to `terser`. If you are using `yarn` you can add the following alias to your project's `package.json` file: ```js "resolutions": { "uglify-es": "npm:terser" } ``` to use `terser` instead of `uglify-es` in all deeply nested dependencies without changing any code. Note: for this change to take effect you must run the following commands to remove the existing `yarn` lock file and reinstall all packages: ``` $ rm -rf node_modules yarn.lock $ yarn ``` # Reporting issues In the terser CLI we use [source-map-support](https://npmjs.com/source-map-support) to produce good error stacks. In your own app, you're expected to enable source-map-support (read their docs) to have nice stack traces that will make good issues. # README.md Patrons: *note*: You can support this project on patreon: patron. Check out [PATRONS.md](https://github.com/terser-js/terser/blob/master/PATRONS.md) for our first-tier patrons. These are the second-tier patrons. Great thanks for your support! * CKEditor ![](https://c10.patreonusercontent.com/3/eyJoIjoxMDAsInciOjEwMH0%3D/patreon-media/p/user/15452278/f8548dcf48d740619071e8d614459280/1?token-time=2145916800&token-hash=SIQ54PhIPHv3M7CVz9LxS8_8v4sOw4H304HaXsXj8MM%3D) * 38elements ![](https://c10.patreonusercontent.com/3/eyJ3IjoyMDB9/patreon-media/p/user/12501844/88e7fc5dd62d45c6a5626533bbd48cfb/1?token-time=2145916800&token-hash=c3AsQ5T0IQWic0zKxFHu-bGGQJkXQFvafvJ4bPerFR4%3D) terser-4.1.2/bin/000077500000000000000000000000001351061312300135655ustar00rootroot00000000000000terser-4.1.2/bin/uglifyjs000077500000000000000000000403141351061312300153510ustar00rootroot00000000000000#!/usr/bin/env node // -*- js -*- /* eslint-env node */ "use strict"; require("../tools/exit.js"); var fs = require("fs"); var info = require("../package.json"); var path = require("path"); var program = require("commander"); var bundle_path = __dirname + (process.env.TERSER_NO_BUNDLE ? "/../dist/bundle.js" : "/../dist/bundle.min.js"); var UglifyJS = require(bundle_path); try { require("source-map-support").install(); } catch (err) {} var skip_keys = [ "cname", "inlined", "parent_scope", "scope", "uses_eval", "uses_with" ]; var files = {}; var options = { compress: false, mangle: false }; program.version(info.name + " " + info.version); program.parseArgv = program.parse; program.parse = undefined; if (process.argv.includes("ast")) program.helpInformation = describe_ast; else if (process.argv.includes("options")) program.helpInformation = function() { var text = []; var options = UglifyJS.default_options(); for (var option in options) { text.push("--" + (option === "output" ? "beautify" : option === "sourceMap" ? "source-map" : option) + " options:"); text.push(format_object(options[option])); text.push(""); } return text.join("\n"); }; program.option("-p, --parse ", "Specify parser options.", parse_js()); program.option("-c, --compress [options]", "Enable compressor/specify compressor options.", parse_js()); program.option("-m, --mangle [options]", "Mangle names/specify mangler options.", parse_js()); program.option("--mangle-props [options]", "Mangle properties/specify mangler options.", parse_js()); program.option("-b, --beautify [options]", "Beautify output/specify output options.", parse_js()); program.option("-o, --output ", "Output file (default STDOUT)."); program.option("--comments [filter]", "Preserve copyright comments in the output."); program.option("--config-file ", "Read minify() options from JSON file."); program.option("-d, --define [=value]", "Global definitions.", parse_js("define")); program.option("--ecma ", "Specify ECMAScript release: 5, 6, 7 or 8."); program.option("-e, --enclose [arg[,...][:value[,...]]]", "Embed output in a big function with configurable arguments and values."); program.option("--ie8", "Support non-standard Internet Explorer 8."); program.option("--keep-classnames", "Do not mangle/drop class names."); program.option("--keep-fnames", "Do not mangle/drop function names. Useful for code relying on Function.prototype.name."); program.option("--module", "Input is an ES6 module"); program.option("--name-cache ", "File to hold mangled name mappings."); program.option("--rename", "Force symbol expansion."); program.option("--no-rename", "Disable symbol expansion."); program.option("--safari10", "Support non-standard Safari 10."); program.option("--source-map [options]", "Enable source map/specify source map options.", parse_js()); program.option("--timings", "Display operations run time on STDERR."); program.option("--toplevel", "Compress and/or mangle variables in toplevel scope."); program.option("--verbose", "Print diagnostic messages."); program.option("--warn", "Print warning messages."); program.option("--wrap ", "Embed everything as a function with “exports” corresponding to “name” globally."); program.arguments("[files...]").parseArgv(process.argv); if (program.configFile) { options = JSON.parse(read_file(program.configFile)); } if (!program.output && program.sourceMap && program.sourceMap.url != "inline") { fatal("ERROR: cannot write source map to STDOUT"); } [ "compress", "enclose", "ie8", "mangle", "module", "safari10", "sourceMap", "toplevel", "wrap" ].forEach(function(name) { if (name in program) { options[name] = program[name]; } }); if ("ecma" in program) { if (program.ecma != (program.ecma | 0)) fatal("ERROR: ecma must be an integer"); options.ecma = program.ecma | 0; } if (program.beautify) { options.output = typeof program.beautify == "object" ? program.beautify : {}; if (!("beautify" in options.output)) { options.output.beautify = true; } } if (program.comments) { if (typeof options.output != "object") options.output = {}; options.output.comments = typeof program.comments == "string" ? program.comments : "some"; } if (program.define) { if (typeof options.compress != "object") options.compress = {}; if (typeof options.compress.global_defs != "object") options.compress.global_defs = {}; for (var expr in program.define) { options.compress.global_defs[expr] = program.define[expr]; } } if (program.keepClassnames) { options.keep_classnames = true; } if (program.keepFnames) { options.keep_fnames = true; } if (program.mangleProps) { if (program.mangleProps.domprops) { delete program.mangleProps.domprops; } else { if (typeof program.mangleProps != "object") program.mangleProps = {}; if (!Array.isArray(program.mangleProps.reserved)) program.mangleProps.reserved = []; } if (typeof options.mangle != "object") options.mangle = {}; options.mangle.properties = program.mangleProps; } if (program.nameCache) { options.nameCache = JSON.parse(read_file(program.nameCache, "{}")); } if (program.output == "ast") { options.output = { ast: true, code: false }; } if (program.parse) { if (!program.parse.acorn && !program.parse.spidermonkey) { options.parse = program.parse; } else if (program.sourceMap && program.sourceMap.content == "inline") { fatal("ERROR: inline source map only works with built-in parser"); } } if (~program.rawArgs.indexOf("--rename")) { options.rename = true; } else if (!program.rename) { options.rename = false; } var convert_path = function(name) { return name; }; if (typeof program.sourceMap == "object" && "base" in program.sourceMap) { convert_path = function() { var base = program.sourceMap.base; delete options.sourceMap.base; return function(name) { return path.relative(base, name); }; }(); } if (program.verbose) { options.warnings = "verbose"; } else if (program.warn) { options.warnings = true; } let filesList; if (options.files && options.files.length) { filesList = options.files; delete options.files; } else if (program.args.length) { filesList = program.args; } if (filesList) { simple_glob(filesList).forEach(function(name) { files[convert_path(name)] = read_file(name); }); 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) { return UglifyJS.AST_Node.from_mozilla_ast(Object.keys(files).reduce(fn, null)); } function run() { UglifyJS.AST_Node.warn_function = function(msg) { print_error("WARN: " + msg); }; var content = program.sourceMap && program.sourceMap.content; if (content && content !== "inline") { options.sourceMap.content = read_file(content, content); } if (program.timings) options.timings = true; try { if (program.parse) { if (program.parse.acorn) { files = convert_ast(function(toplevel, name) { return require("acorn").parse(files[name], { ecmaVersion: 2018, locations: true, program: toplevel, sourceFile: name, sourceType: options.module || program.parse.module ? "module" : "script" }); }); } else if (program.parse.spidermonkey) { files = convert_ast(function(toplevel, name) { var obj = JSON.parse(files[name]); if (!toplevel) return obj; toplevel.body = toplevel.body.concat(obj.body); return toplevel; }); } } } catch (ex) { fatal(ex); } var result = UglifyJS.minify(files, options); if (result.error) { var ex = result.error; if (ex.name == "SyntaxError") { print_error("Parse error at " + ex.filename + ":" + ex.line + "," + ex.col); var col = ex.col; var lines = files[ex.filename].split(/\r?\n/); var line = lines[ex.line - 1]; if (!line && !col) { line = lines[ex.line - 2]; col = line.length; } if (line) { var limit = 70; if (col > limit) { line = line.slice(col - limit); col = limit; } print_error(line.slice(0, 80)); print_error(line.slice(0, col).replace(/\S/g, " ") + "^"); } } if (ex.defs) { print_error("Supported options:"); print_error(format_object(ex.defs)); } fatal(ex); } else if (program.output == "ast") { if (!options.compress && !options.mangle) { result.ast.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 ? collect_from_map(value, symdef) : undefined; } if (skip_key(key)) return; if (value instanceof UglifyJS.AST_Token) return; if (value instanceof Map) return; if (value instanceof UglifyJS.AST_Node) { var result = { _class: "AST_" + value.TYPE }; if (value.block_scope) { result.variables = value.block_scope.variables; result.functions = value.block_scope.functions; result.enclosed = value.block_scope.enclosed; } value.CTOR.PROPS.forEach(function(prop) { result[prop] = value[prop]; }); return result; } return value; }, 2)); } else if (program.output == "spidermonkey") { print(JSON.stringify(UglifyJS.minify(result.code, { compress: false, mangle: false, output: { ast: true, code: false } }).ast.to_mozilla_ast(), null, 2)); } else if (program.output) { fs.writeFileSync(program.output, result.code); if (result.map) { fs.writeFileSync(program.output + ".map", result.map); } } else { print(result.code); } if (program.nameCache) { fs.writeFileSync(program.nameCache, JSON.stringify(options.nameCache)); } if (result.timings) for (var phase in result.timings) { print_error("- " + phase + ": " + result.timings[phase].toFixed(3) + "s"); } } function fatal(message) { if (message instanceof Error) message = message.stack.replace(/^\S*?Error:/, "ERROR:"); print_error(message); process.exit(1); } // A file glob function that only supports "*" and "?" wildcards in the basename. // Example: "foo/bar/*baz??.*.js" // Argument `glob` may be a string or an array of strings. // Returns an array of strings. Garbage in, garbage out. function simple_glob(glob) { if (Array.isArray(glob)) { return [].concat.apply([], glob.map(simple_glob)); } if (glob && glob.match(/[*?]/)) { var dir = path.dirname(glob); try { var entries = fs.readdirSync(dir); } catch (ex) {} if (entries) { var pattern = "^" + path.basename(glob) .replace(/[.+^$[\]\\(){}]/g, "\\$&") .replace(/\*/g, "[^/\\\\]*") .replace(/\?/g, "[^/\\\\]") + "$"; var mod = process.platform === "win32" ? "i" : ""; var rx = new RegExp(pattern, mod); var results = entries.filter(function(name) { return rx.test(name); }).map(function(name) { return path.join(dir, name); }); if (results.length) return results; } } return [ glob ]; } function read_file(path, default_value) { try { return fs.readFileSync(path, "utf8"); } catch (ex) { if ((ex.code == "ENOENT" || ex.code == "ENAMETOOLONG") && default_value != null) return default_value; fatal(ex); } } function parse_js(flag) { return function(value, options) { options = options || {}; try { UglifyJS.parse(value, { expression: true }).walk(new UglifyJS.TreeWalker(function(node) { if (node instanceof UglifyJS.AST_Assign) { var name = node.left.print_to_string(); var value = node.right; if (flag) { options[name] = value; } else if (value instanceof UglifyJS.AST_Array) { options[name] = value.elements.map(to_string); } else { options[name] = to_string(value); } 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; function to_string(value) { return value instanceof UglifyJS.AST_Constant ? value.getValue() : value.print_to_string({ quote_keys: true }); } })); } catch(ex) { if (flag) { fatal("Error parsing arguments for '" + flag + "': " + value); } else { options[value] = null; } } return options; }; } function skip_key(key) { return skip_keys.includes(key); } function symdef(def) { var ret = (1e6 + def.id) + " " + def.name; if (def.mangled_name) ret += " " + def.mangled_name; return ret; } function collect_from_map(map, callback) { var result = []; map.forEach(function (def) { result.push(callback(def)); }); return result; } function format_object(obj) { var lines = []; var padding = ""; Object.keys(obj).map(function(name) { if (padding.length < name.length) padding = Array(name.length + 1).join(" "); return [ name, JSON.stringify(obj[name]) ]; }).forEach(function(tokens) { lines.push(" " + tokens[0] + padding.slice(tokens[0].length - 2) + tokens[1]); }); return lines.join("\n"); } function print_error(msg) { process.stderr.write(msg); process.stderr.write("\n"); } function print(txt) { process.stdout.write(txt); process.stdout.write("\n"); } function describe_ast() { var out = UglifyJS.OutputStream({ beautify: true }); function doitem(ctor) { out.print("AST_" + ctor.TYPE); var props = ctor.SELF_PROPS.filter(function(prop) { return !/^\$/.test(prop); }); if (props.length > 0) { out.space(); out.with_parens(function() { props.forEach(function(prop, i) { if (i) out.space(); out.print(prop); }); }); } if (ctor.documentation) { out.space(); out.print_string(ctor.documentation); } if (ctor.SUBCLASSES.length > 0) { out.space(); out.with_block(function() { ctor.SUBCLASSES.forEach(function(ctor, i) { out.indent(); doitem(ctor); out.newline(); }); }); } } doitem(UglifyJS.AST_Node); return out + "\n"; } terser-4.1.2/bin/uglifyjsnobundle000077500000000000000000000001451351061312300170760ustar00rootroot00000000000000#!/usr/bin/env node /* eslint-env node */ process.env.TERSER_NO_BUNDLE = "1"; require("./uglifyjs"); terser-4.1.2/dist/000077500000000000000000000000001351061312300137605ustar00rootroot00000000000000terser-4.1.2/dist/.gitkeep000066400000000000000000000000001351061312300153770ustar00rootroot00000000000000terser-4.1.2/lib/000077500000000000000000000000001351061312300135635ustar00rootroot00000000000000terser-4.1.2/lib/ast.js000066400000000000000000001315641351061312300147220ustar00rootroot00000000000000/*********************************************************************** A JavaScript tokenizer / parser / beautifier / compressor. https://github.com/mishoo/UglifyJS2 -------------------------------- (C) --------------------------------- Author: Mihai Bazon http://mihai.bazon.net/blog Distributed under the BSD license: Copyright 2012 (c) Mihai Bazon Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ "use strict"; import { HOP, MAP, noop, string_template, } from "./utils/index.js"; import { parse } from "./parse.js"; function DEFNODE(type, props, methods, base = AST_Node) { if (!props) props = []; else props = props.split(/\s+/); var self_props = props; if (base && base.PROPS) props = props.concat(base.PROPS); var code = "return function AST_" + type + "(props){ if (props) { "; for (var i = props.length; --i >= 0;) { code += "this." + props[i] + " = props." + props[i] + ";"; } var proto = base && new base; if (proto && proto.initialize || (methods && methods.initialize)) code += "this.initialize();"; code += "}}"; var ctor = new Function(code)(); if (proto) { ctor.prototype = proto; ctor.BASE = base; } if (base) base.SUBCLASSES.push(ctor); ctor.prototype.CTOR = ctor; ctor.PROPS = props || null; ctor.SELF_PROPS = self_props; ctor.SUBCLASSES = []; if (type) { ctor.prototype.TYPE = ctor.TYPE = type; } if (methods) for (i in methods) if (HOP(methods, i)) { if (i[0] === "$") { ctor[i.substr(1)] = methods[i]; } else { ctor.prototype[i] = methods[i]; } } ctor.DEFMETHOD = function(name, method) { this.prototype[name] = method; }; return ctor; } var AST_Token = DEFNODE("Token", "type value line col pos endline endcol endpos nlb comments_before comments_after file raw", { }, null); var AST_Node = DEFNODE("Node", "start end", { _clone: function(deep) { if (deep) { var self = this.clone(); return self.transform(new TreeTransformer(function(node) { if (node !== self) { return node.clone(true); } })); } return new this.CTOR(this); }, clone: function(deep) { return this._clone(deep); }, $documentation: "Base class of all AST nodes", $propdoc: { start: "[AST_Token] The first token of this node", end: "[AST_Token] The last token of this node" }, _walk: function(visitor) { return visitor._visit(this); }, walk: function(visitor) { return this._walk(visitor); // not sure the indirection will be any help } }, null); AST_Node.warn_function = null; AST_Node.warn = function(txt, props) { if (AST_Node.warn_function) AST_Node.warn_function(string_template(txt, props)); }; /* -----[ statements ]----- */ var AST_Statement = DEFNODE("Statement", null, { $documentation: "Base class of all statements", }); var AST_Debugger = DEFNODE("Debugger", null, { $documentation: "Represents a debugger statement", }, AST_Statement); var AST_Directive = DEFNODE("Directive", "value quote", { $documentation: "Represents a directive, like \"use strict\";", $propdoc: { value: "[string] The value of this directive as a plain string (it's not an AST_String!)", quote: "[string] the original quote character" }, }, AST_Statement); var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", { $documentation: "A statement consisting of an expression, i.e. a = 1 + 2", $propdoc: { body: "[AST_Node] an expression node (should not be instanceof AST_Statement)" }, _walk: function(visitor) { return visitor._visit(this, function() { this.body._walk(visitor); }); } }, AST_Statement); function walk_body(node, visitor) { var body = node.body; if (body instanceof AST_Node) { body._walk(visitor); } else for (var i = 0, len = body.length; i < len; i++) { body[i]._walk(visitor); } } function clone_block_scope(deep) { var clone = this._clone(deep); if (this.block_scope) { // TODO this is sometimes undefined during compression. // But it should always have a value! clone.block_scope = this.block_scope.clone(); } return clone; } var AST_Block = DEFNODE("Block", "body block_scope", { $documentation: "A body of statements (usually braced)", $propdoc: { body: "[AST_Statement*] an array of statements", block_scope: "[AST_Scope] the block scope" }, _walk: function(visitor) { return visitor._visit(this, function() { walk_body(this, visitor); }); }, clone: clone_block_scope }, AST_Statement); var AST_BlockStatement = DEFNODE("BlockStatement", null, { $documentation: "A block statement", }, AST_Block); var AST_EmptyStatement = DEFNODE("EmptyStatement", null, { $documentation: "The empty statement (empty block or simply a semicolon)" }, AST_Statement); var AST_StatementWithBody = DEFNODE("StatementWithBody", "body", { $documentation: "Base class for all statements that contain one nested body: `For`, `ForIn`, `Do`, `While`, `With`", $propdoc: { body: "[AST_Statement] the body; this should always be present, even if it's an AST_EmptyStatement" } }, AST_Statement); var AST_LabeledStatement = DEFNODE("LabeledStatement", "label", { $documentation: "Statement with a label", $propdoc: { label: "[AST_Label] a label definition" }, _walk: function(visitor) { return visitor._visit(this, function() { this.label._walk(visitor); this.body._walk(visitor); }); }, clone: function(deep) { var node = this._clone(deep); if (deep) { var label = node.label; var def = this.label; node.walk(new TreeWalker(function(node) { if (node instanceof AST_LoopControl && node.label && node.label.thedef === def) { node.label.thedef = label; label.references.push(node); } })); } return node; } }, AST_StatementWithBody); var AST_IterationStatement = DEFNODE("IterationStatement", "block_scope", { $documentation: "Internal class. All loops inherit from it.", $propdoc: { block_scope: "[AST_Scope] the block scope for this iteration statement." }, clone: clone_block_scope }, AST_StatementWithBody); var AST_DWLoop = DEFNODE("DWLoop", "condition", { $documentation: "Base class for do/while statements", $propdoc: { condition: "[AST_Node] the loop condition. Should not be instanceof AST_Statement" } }, AST_IterationStatement); var AST_Do = DEFNODE("Do", null, { $documentation: "A `do` statement", _walk: function(visitor) { return visitor._visit(this, function() { this.body._walk(visitor); this.condition._walk(visitor); }); } }, AST_DWLoop); var AST_While = DEFNODE("While", null, { $documentation: "A `while` statement", _walk: function(visitor) { return visitor._visit(this, function() { this.condition._walk(visitor); this.body._walk(visitor); }); } }, AST_DWLoop); var AST_For = DEFNODE("For", "init condition step", { $documentation: "A `for` statement", $propdoc: { init: "[AST_Node?] the `for` initialization code, or null if empty", condition: "[AST_Node?] the `for` termination clause, or null if empty", step: "[AST_Node?] the `for` update clause, or null if empty" }, _walk: function(visitor) { return visitor._visit(this, function() { if (this.init) this.init._walk(visitor); if (this.condition) this.condition._walk(visitor); if (this.step) this.step._walk(visitor); this.body._walk(visitor); }); } }, AST_IterationStatement); var AST_ForIn = DEFNODE("ForIn", "init object", { $documentation: "A `for ... in` statement", $propdoc: { init: "[AST_Node] the `for/in` initialization code", object: "[AST_Node] the object that we're looping through" }, _walk: function(visitor) { return visitor._visit(this, function() { this.init._walk(visitor); this.object._walk(visitor); this.body._walk(visitor); }); } }, AST_IterationStatement); var AST_ForOf = DEFNODE("ForOf", "await", { $documentation: "A `for ... of` statement", }, AST_ForIn); var AST_With = DEFNODE("With", "expression", { $documentation: "A `with` statement", $propdoc: { expression: "[AST_Node] the `with` expression" }, _walk: function(visitor) { return visitor._visit(this, function() { this.expression._walk(visitor); this.body._walk(visitor); }); } }, AST_StatementWithBody); /* -----[ scope and functions ]----- */ var AST_Scope = DEFNODE("Scope", "variables functions uses_with uses_eval parent_scope enclosed cname", { $documentation: "Base class for all statements introducing a lexical scope", $propdoc: { variables: "[Map/S] a map of name -> SymbolDef for all variables/functions defined in this scope", functions: "[Map/S] like `variables`, but only lists function declarations", uses_with: "[boolean/S] tells whether this scope uses the `with` statement", uses_eval: "[boolean/S] tells whether this scope contains a direct call to the global `eval`", parent_scope: "[AST_Scope?/S] link to the parent scope", enclosed: "[SymbolDef*/S] a list of all symbol definitions that are accessed from this scope or any subscopes", cname: "[integer/S] current index for mangling variables (used internally by the mangler)", }, get_defun_scope: function() { var self = this; while (self.is_block_scope()) { self = self.parent_scope; } return self; }, clone: function(deep) { var node = this._clone(deep); if (this.variables) node.variables = new Map(this.variables); if (this.functions) node.functions = new Map(this.functions); if (this.enclosed) node.enclosed = this.enclosed.slice(); return node; }, pinned: function() { return this.uses_eval || this.uses_with; } }, AST_Block); var AST_Toplevel = DEFNODE("Toplevel", "globals", { $documentation: "The toplevel scope", $propdoc: { globals: "[Map/S] a map of name -> SymbolDef for all undeclared names", }, wrap_commonjs: function(name) { var body = this.body; var wrapped_tl = "(function(exports){'$ORIG';})(typeof " + name + "=='undefined'?(" + name + "={}):" + name + ");"; wrapped_tl = parse(wrapped_tl); wrapped_tl = wrapped_tl.transform(new TreeTransformer(function(node) { if (node instanceof AST_Directive && node.value == "$ORIG") { return MAP.splice(body); } })); return wrapped_tl; }, wrap_enclose: function(args_values) { if (typeof args_values != "string") args_values = ""; var index = args_values.indexOf(":"); if (index < 0) index = args_values.length; var body = this.body; return parse([ "(function(", args_values.slice(0, index), '){"$ORIG"})(', args_values.slice(index + 1), ")" ].join("")).transform(new TreeTransformer(function(node) { if (node instanceof AST_Directive && node.value == "$ORIG") { return MAP.splice(body); } })); } }, AST_Scope); var AST_Expansion = DEFNODE("Expansion", "expression", { $documentation: "An expandible argument, such as ...rest, a splat, such as [1,2,...all], or an expansion in a variable declaration, such as var [first, ...rest] = list", $propdoc: { expression: "[AST_Node] the thing to be expanded" }, _walk: function(visitor) { var self = this; return visitor._visit(this, function() { self.expression.walk(visitor); }); } }); var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments is_generator async", { $documentation: "Base class for functions", $propdoc: { name: "[AST_SymbolDeclaration?] the name of this function", argnames: "[AST_SymbolFunarg|AST_Destructuring|AST_Expansion|AST_DefaultAssign*] array of function arguments, destructurings, or expanding arguments", uses_arguments: "[boolean/S] tells whether this function accesses the arguments array", is_generator: "[boolean] is this a generator method", async: "[boolean] is this method async", }, args_as_names: function () { var out = []; for (var i = 0; i < this.argnames.length; i++) { if (this.argnames[i] instanceof AST_Destructuring) { out = out.concat(this.argnames[i].all_symbols()); } else { out.push(this.argnames[i]); } } return out; }, _walk: function(visitor) { return visitor._visit(this, function() { if (this.name) this.name._walk(visitor); var argnames = this.argnames; for (var i = 0, len = argnames.length; i < len; i++) { argnames[i]._walk(visitor); } walk_body(this, visitor); }); } }, AST_Scope); var AST_Accessor = DEFNODE("Accessor", null, { $documentation: "A setter/getter function. The `name` property is always null." }, AST_Lambda); var AST_Function = DEFNODE("Function", "inlined", { $documentation: "A function expression" }, AST_Lambda); var AST_Arrow = DEFNODE("Arrow", "inlined", { $documentation: "An ES6 Arrow function ((a) => b)" }, AST_Lambda); var AST_Defun = DEFNODE("Defun", "inlined", { $documentation: "A function definition" }, AST_Lambda); /* -----[ DESTRUCTURING ]----- */ var AST_Destructuring = DEFNODE("Destructuring", "names is_array", { $documentation: "A destructuring of several names. Used in destructuring assignment and with destructuring function argument names", $propdoc: { "names": "[AST_Node*] Array of properties or elements", "is_array": "[Boolean] Whether the destructuring represents an object or array" }, _walk: function(visitor) { return visitor._visit(this, function() { this.names.forEach(function(name) { name._walk(visitor); }); }); }, all_symbols: function() { var out = []; this.walk(new TreeWalker(function (node) { if (node instanceof AST_Symbol) { out.push(node); } if (node instanceof AST_Expansion) { out.push(node.expression); } })); return out; } }); var AST_PrefixedTemplateString = DEFNODE("PrefixedTemplateString", "template_string prefix", { $documentation: "A templatestring with a prefix, such as String.raw`foobarbaz`", $propdoc: { template_string: "[AST_TemplateString] The template string", prefix: "[AST_SymbolRef|AST_PropAccess] The prefix, which can be a symbol such as `foo` or a dotted expression such as `String.raw`." }, _walk: function(visitor) { this.prefix._walk(visitor); this.template_string._walk(visitor); } }); var AST_TemplateString = DEFNODE("TemplateString", "segments", { $documentation: "A template string literal", $propdoc: { segments: "[AST_Node*] One or more segments, starting with AST_TemplateSegment. AST_Node may follow AST_TemplateSegment, but each AST_Node must be followed by AST_TemplateSegment." }, _walk: function(visitor) { return visitor._visit(this, function() { this.segments.forEach(function(seg) { seg._walk(visitor); }); }); } }); var AST_TemplateSegment = DEFNODE("TemplateSegment", "value raw", { $documentation: "A segment of a template string literal", $propdoc: { value: "Content of the segment", raw: "Raw content of the segment" } }); /* -----[ JUMPS ]----- */ var AST_Jump = DEFNODE("Jump", null, { $documentation: "Base class for “jumps” (for now that's `return`, `throw`, `break` and `continue`)" }, AST_Statement); var AST_Exit = DEFNODE("Exit", "value", { $documentation: "Base class for “exits” (`return` and `throw`)", $propdoc: { value: "[AST_Node?] the value returned or thrown by this statement; could be null for AST_Return" }, _walk: function(visitor) { return visitor._visit(this, this.value && function() { this.value._walk(visitor); }); } }, AST_Jump); var AST_Return = DEFNODE("Return", null, { $documentation: "A `return` statement" }, AST_Exit); var AST_Throw = DEFNODE("Throw", null, { $documentation: "A `throw` statement" }, AST_Exit); var AST_LoopControl = DEFNODE("LoopControl", "label", { $documentation: "Base class for loop control statements (`break` and `continue`)", $propdoc: { label: "[AST_LabelRef?] the label, or null if none", }, _walk: function(visitor) { return visitor._visit(this, this.label && function() { this.label._walk(visitor); }); } }, AST_Jump); var AST_Break = DEFNODE("Break", null, { $documentation: "A `break` statement" }, AST_LoopControl); var AST_Continue = DEFNODE("Continue", null, { $documentation: "A `continue` statement" }, AST_LoopControl); /* -----[ IF ]----- */ var AST_If = DEFNODE("If", "condition alternative", { $documentation: "A `if` statement", $propdoc: { condition: "[AST_Node] the `if` condition", alternative: "[AST_Statement?] the `else` part, or null if not present" }, _walk: function(visitor) { return visitor._visit(this, function() { this.condition._walk(visitor); this.body._walk(visitor); if (this.alternative) this.alternative._walk(visitor); }); } }, AST_StatementWithBody); /* -----[ SWITCH ]----- */ var AST_Switch = DEFNODE("Switch", "expression", { $documentation: "A `switch` statement", $propdoc: { expression: "[AST_Node] the `switch` “discriminant”" }, _walk: function(visitor) { return visitor._visit(this, function() { this.expression._walk(visitor); walk_body(this, visitor); }); } }, AST_Block); var AST_SwitchBranch = DEFNODE("SwitchBranch", null, { $documentation: "Base class for `switch` branches", }, AST_Block); var AST_Default = DEFNODE("Default", null, { $documentation: "A `default` switch branch", }, AST_SwitchBranch); var AST_Case = DEFNODE("Case", "expression", { $documentation: "A `case` switch branch", $propdoc: { expression: "[AST_Node] the `case` expression" }, _walk: function(visitor) { return visitor._visit(this, function() { this.expression._walk(visitor); walk_body(this, visitor); }); } }, AST_SwitchBranch); /* -----[ EXCEPTIONS ]----- */ var AST_Try = DEFNODE("Try", "bcatch bfinally", { $documentation: "A `try` statement", $propdoc: { bcatch: "[AST_Catch?] the catch block, or null if not present", bfinally: "[AST_Finally?] the finally block, or null if not present" }, _walk: function(visitor) { return visitor._visit(this, function() { walk_body(this, visitor); if (this.bcatch) this.bcatch._walk(visitor); if (this.bfinally) this.bfinally._walk(visitor); }); } }, AST_Block); var AST_Catch = DEFNODE("Catch", "argname", { $documentation: "A `catch` node; only makes sense as part of a `try` statement", $propdoc: { argname: "[AST_SymbolCatch|AST_Destructuring|AST_Expansion|AST_DefaultAssign] symbol for the exception" }, _walk: function(visitor) { return visitor._visit(this, function() { if (this.argname) this.argname._walk(visitor); walk_body(this, visitor); }); } }, AST_Block); var AST_Finally = DEFNODE("Finally", null, { $documentation: "A `finally` node; only makes sense as part of a `try` statement" }, AST_Block); /* -----[ VAR/CONST ]----- */ var AST_Definitions = DEFNODE("Definitions", "definitions", { $documentation: "Base class for `var` or `const` nodes (variable declarations/initializations)", $propdoc: { definitions: "[AST_VarDef*] array of variable definitions" }, _walk: function(visitor) { return visitor._visit(this, function() { var definitions = this.definitions; for (var i = 0, len = definitions.length; i < len; i++) { definitions[i]._walk(visitor); } }); } }, AST_Statement); var AST_Var = DEFNODE("Var", null, { $documentation: "A `var` statement" }, AST_Definitions); var AST_Let = DEFNODE("Let", null, { $documentation: "A `let` statement" }, AST_Definitions); var AST_Const = DEFNODE("Const", null, { $documentation: "A `const` statement" }, AST_Definitions); var AST_NameMapping = DEFNODE("NameMapping", "foreign_name name", { $documentation: "The part of the export/import statement that declare names from a module.", $propdoc: { foreign_name: "[AST_SymbolExportForeign|AST_SymbolImportForeign] The name being exported/imported (as specified in the module)", name: "[AST_SymbolExport|AST_SymbolImport] The name as it is visible to this module." }, _walk: function (visitor) { return visitor._visit(this, function() { this.foreign_name._walk(visitor); this.name._walk(visitor); }); } }); var AST_Import = DEFNODE("Import", "imported_name imported_names module_name", { $documentation: "An `import` statement", $propdoc: { imported_name: "[AST_SymbolImport] The name of the variable holding the module's default export.", imported_names: "[AST_NameMapping*] The names of non-default imported variables", module_name: "[AST_String] String literal describing where this module came from", }, _walk: function(visitor) { return visitor._visit(this, function() { if (this.imported_name) { this.imported_name._walk(visitor); } if (this.imported_names) { this.imported_names.forEach(function(name_import) { name_import._walk(visitor); }); } this.module_name._walk(visitor); }); } }); var AST_Export = DEFNODE("Export", "exported_definition exported_value is_default exported_names module_name", { $documentation: "An `export` statement", $propdoc: { exported_definition: "[AST_Defun|AST_Definitions|AST_DefClass?] An exported definition", exported_value: "[AST_Node?] An exported value", exported_names: "[AST_NameMapping*?] List of exported names", module_name: "[AST_String?] Name of the file to load exports from", is_default: "[Boolean] Whether this is the default exported value of this module" }, _walk: function (visitor) { visitor._visit(this, function () { if (this.exported_definition) { this.exported_definition._walk(visitor); } if (this.exported_value) { this.exported_value._walk(visitor); } if (this.exported_names) { this.exported_names.forEach(function(name_export) { name_export._walk(visitor); }); } if (this.module_name) { this.module_name._walk(visitor); } }); } }, AST_Statement); var AST_VarDef = DEFNODE("VarDef", "name value", { $documentation: "A variable declaration; only appears in a AST_Definitions node", $propdoc: { name: "[AST_Destructuring|AST_SymbolConst|AST_SymbolLet|AST_SymbolVar] name of the variable", value: "[AST_Node?] initializer, or null of there's no initializer" }, _walk: function(visitor) { return visitor._visit(this, function() { this.name._walk(visitor); if (this.value) this.value._walk(visitor); }); } }); /* -----[ OTHER ]----- */ var AST_Call = DEFNODE("Call", "expression args", { $documentation: "A function call expression", $propdoc: { expression: "[AST_Node] expression to invoke as function", args: "[AST_Node*] array of arguments" }, _walk: function(visitor) { return visitor._visit(this, function() { var args = this.args; for (var i = 0, len = args.length; i < len; i++) { args[i]._walk(visitor); } this.expression._walk(visitor); }); } }); var AST_New = DEFNODE("New", null, { $documentation: "An object instantiation. Derives from a function call since it has exactly the same properties" }, AST_Call); var AST_Sequence = DEFNODE("Sequence", "expressions", { $documentation: "A sequence expression (comma-separated expressions)", $propdoc: { expressions: "[AST_Node*] array of expressions (at least two)" }, _walk: function(visitor) { return visitor._visit(this, function() { this.expressions.forEach(function(node) { node._walk(visitor); }); }); } }); var AST_PropAccess = DEFNODE("PropAccess", "expression property", { $documentation: "Base class for property access expressions, i.e. `a.foo` or `a[\"foo\"]`", $propdoc: { expression: "[AST_Node] the “container” expression", property: "[AST_Node|string] the property to access. For AST_Dot this is always a plain string, while for AST_Sub it's an arbitrary AST_Node" } }); var AST_Dot = DEFNODE("Dot", "quote", { $documentation: "A dotted property access expression", $propdoc: { quote: "[string] the original quote character when transformed from AST_Sub", }, _walk: function(visitor) { return visitor._visit(this, function() { this.expression._walk(visitor); }); } }, AST_PropAccess); var AST_Sub = DEFNODE("Sub", null, { $documentation: "Index-style property access, i.e. `a[\"foo\"]`", _walk: function(visitor) { return visitor._visit(this, function() { this.expression._walk(visitor); this.property._walk(visitor); }); } }, AST_PropAccess); var AST_Unary = DEFNODE("Unary", "operator expression", { $documentation: "Base class for unary expressions", $propdoc: { operator: "[string] the operator", expression: "[AST_Node] expression that this unary operator applies to" }, _walk: function(visitor) { return visitor._visit(this, function() { this.expression._walk(visitor); }); } }); var AST_UnaryPrefix = DEFNODE("UnaryPrefix", null, { $documentation: "Unary prefix expression, i.e. `typeof i` or `++i`" }, AST_Unary); var AST_UnaryPostfix = DEFNODE("UnaryPostfix", null, { $documentation: "Unary postfix expression, i.e. `i++`" }, AST_Unary); var AST_Binary = DEFNODE("Binary", "operator left right", { $documentation: "Binary expression, i.e. `a + b`", $propdoc: { left: "[AST_Node] left-hand side expression", operator: "[string] the operator", right: "[AST_Node] right-hand side expression" }, _walk: function(visitor) { return visitor._visit(this, function() { this.left._walk(visitor); this.right._walk(visitor); }); } }); var AST_Conditional = DEFNODE("Conditional", "condition consequent alternative", { $documentation: "Conditional expression using the ternary operator, i.e. `a ? b : c`", $propdoc: { condition: "[AST_Node]", consequent: "[AST_Node]", alternative: "[AST_Node]" }, _walk: function(visitor) { return visitor._visit(this, function() { this.condition._walk(visitor); this.consequent._walk(visitor); this.alternative._walk(visitor); }); } }); var AST_Assign = DEFNODE("Assign", null, { $documentation: "An assignment expression — `a = b + 5`", }, AST_Binary); var AST_DefaultAssign = DEFNODE("DefaultAssign", null, { $documentation: "A default assignment expression like in `(a = 3) => a`" }, AST_Binary); /* -----[ LITERALS ]----- */ var AST_Array = DEFNODE("Array", "elements", { $documentation: "An array literal", $propdoc: { elements: "[AST_Node*] array of elements" }, _walk: function(visitor) { return visitor._visit(this, function() { var elements = this.elements; for (var i = 0, len = elements.length; i < len; i++) { elements[i]._walk(visitor); } }); } }); var AST_Object = DEFNODE("Object", "properties", { $documentation: "An object literal", $propdoc: { properties: "[AST_ObjectProperty*] array of properties" }, _walk: function(visitor) { return visitor._visit(this, function() { var properties = this.properties; for (var i = 0, len = properties.length; i < len; i++) { properties[i]._walk(visitor); } }); } }); var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", { $documentation: "Base class for literal object properties", $propdoc: { key: "[string|AST_Node] property name. For ObjectKeyVal this is a string. For getters, setters and computed property this is an AST_Node.", value: "[AST_Node] property value. For getters and setters this is an AST_Accessor." }, _walk: function(visitor) { return visitor._visit(this, function() { if (this.key instanceof AST_Node) this.key._walk(visitor); this.value._walk(visitor); }); } }); var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", "quote", { $documentation: "A key: value object property", $propdoc: { quote: "[string] the original quote character" } }, AST_ObjectProperty); var AST_ObjectSetter = DEFNODE("ObjectSetter", "quote static", { $propdoc: { quote: "[string|undefined] the original quote character, if any", static: "[boolean] whether this is a static setter (classes only)" }, $documentation: "An object setter property", }, AST_ObjectProperty); var AST_ObjectGetter = DEFNODE("ObjectGetter", "quote static", { $propdoc: { quote: "[string|undefined] the original quote character, if any", static: "[boolean] whether this is a static getter (classes only)" }, $documentation: "An object getter property", }, AST_ObjectProperty); var AST_ConciseMethod = DEFNODE("ConciseMethod", "quote static is_generator async", { $propdoc: { quote: "[string|undefined] the original quote character, if any", static: "[boolean] is this method static (classes only)", is_generator: "[boolean] is this a generator method", async: "[boolean] is this method async", }, $documentation: "An ES6 concise method inside an object or class" }, AST_ObjectProperty); var AST_Class = DEFNODE("Class", "name extends properties inlined", { $propdoc: { name: "[AST_SymbolClass|AST_SymbolDefClass?] optional class name.", extends: "[AST_Node]? optional parent class", properties: "[AST_ObjectProperty*] array of properties" }, $documentation: "An ES6 class", _walk: function(visitor) { return visitor._visit(this, function() { if (this.name) { this.name._walk(visitor); } if (this.extends) { this.extends._walk(visitor); } this.properties.forEach(function(prop) { prop._walk(visitor); }); }); }, }, AST_Scope); var AST_DefClass = DEFNODE("DefClass", null, { $documentation: "A class definition", }, AST_Class); var AST_ClassExpression = DEFNODE("ClassExpression", null, { $documentation: "A class expression." }, AST_Class); var AST_Symbol = DEFNODE("Symbol", "scope name thedef", { $propdoc: { name: "[string] name of this symbol", scope: "[AST_Scope/S] the current scope (not necessarily the definition scope)", thedef: "[SymbolDef/S] the definition of this symbol" }, $documentation: "Base class for all symbols" }); var AST_NewTarget = DEFNODE("NewTarget", null, { $documentation: "A reference to new.target" }); var AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init", { $documentation: "A declaration symbol (symbol in var/const, function name or argument, symbol in catch)", }, AST_Symbol); var AST_SymbolVar = DEFNODE("SymbolVar", null, { $documentation: "Symbol defining a variable", }, AST_SymbolDeclaration); var AST_SymbolBlockDeclaration = DEFNODE("SymbolBlockDeclaration", null, { $documentation: "Base class for block-scoped declaration symbols" }, AST_SymbolDeclaration); var AST_SymbolConst = DEFNODE("SymbolConst", null, { $documentation: "A constant declaration" }, AST_SymbolBlockDeclaration); var AST_SymbolLet = DEFNODE("SymbolLet", null, { $documentation: "A block-scoped `let` declaration" }, AST_SymbolBlockDeclaration); var AST_SymbolFunarg = DEFNODE("SymbolFunarg", null, { $documentation: "Symbol naming a function argument", }, AST_SymbolVar); var AST_SymbolDefun = DEFNODE("SymbolDefun", null, { $documentation: "Symbol defining a function", }, AST_SymbolDeclaration); var AST_SymbolMethod = DEFNODE("SymbolMethod", null, { $documentation: "Symbol in an object defining a method", }, AST_Symbol); var AST_SymbolLambda = DEFNODE("SymbolLambda", null, { $documentation: "Symbol naming a function expression", }, AST_SymbolDeclaration); var AST_SymbolDefClass = DEFNODE("SymbolDefClass", null, { $documentation: "Symbol naming a class's name in a class declaration. Lexically scoped to its containing scope, and accessible within the class." }, AST_SymbolBlockDeclaration); var AST_SymbolClass = DEFNODE("SymbolClass", null, { $documentation: "Symbol naming a class's name. Lexically scoped to the class." }, AST_SymbolDeclaration); var AST_SymbolCatch = DEFNODE("SymbolCatch", null, { $documentation: "Symbol naming the exception in catch", }, AST_SymbolBlockDeclaration); var AST_SymbolImport = DEFNODE("SymbolImport", null, { $documentation: "Symbol referring to an imported name", }, AST_SymbolBlockDeclaration); var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign", null, { $documentation: "A symbol imported from a module, but it is defined in the other module, and its real name is irrelevant for this module's purposes", }, AST_Symbol); var AST_Label = DEFNODE("Label", "references", { $documentation: "Symbol naming a label (declaration)", $propdoc: { references: "[AST_LoopControl*] a list of nodes referring to this label" }, initialize: function() { this.references = []; this.thedef = this; } }, AST_Symbol); var AST_SymbolRef = DEFNODE("SymbolRef", null, { $documentation: "Reference to some symbol (not definition/declaration)", }, AST_Symbol); var AST_SymbolExport = DEFNODE("SymbolExport", null, { $documentation: "Symbol referring to a name to export", }, AST_SymbolRef); var AST_SymbolExportForeign = DEFNODE("SymbolExportForeign", null, { $documentation: "A symbol exported from this module, but it is used in the other module, and its real name is irrelevant for this module's purposes", }, AST_Symbol); var AST_LabelRef = DEFNODE("LabelRef", null, { $documentation: "Reference to a label symbol", }, AST_Symbol); var AST_This = DEFNODE("This", null, { $documentation: "The `this` symbol", }, AST_Symbol); var AST_Super = DEFNODE("Super", null, { $documentation: "The `super` symbol", }, AST_This); var AST_Constant = DEFNODE("Constant", null, { $documentation: "Base class for all constants", getValue: function() { return this.value; } }); var AST_String = DEFNODE("String", "value quote", { $documentation: "A string literal", $propdoc: { value: "[string] the contents of this string", quote: "[string] the original quote character" } }, AST_Constant); var AST_Number = DEFNODE("Number", "value literal", { $documentation: "A number literal", $propdoc: { value: "[number] the numeric value", literal: "[string] numeric value as string (optional)" } }, AST_Constant); var AST_BigInt = DEFNODE("BigInt", "value", { $documentation: "A big int literal", $propdoc: { value: "[string] big int value" } }, AST_Constant); var AST_RegExp = DEFNODE("RegExp", "value", { $documentation: "A regexp literal", $propdoc: { value: "[RegExp] the actual regexp", } }, AST_Constant); var AST_Atom = DEFNODE("Atom", null, { $documentation: "Base class for atoms", }, AST_Constant); var AST_Null = DEFNODE("Null", null, { $documentation: "The `null` atom", value: null }, AST_Atom); var AST_NaN = DEFNODE("NaN", null, { $documentation: "The impossible value", value: 0/0 }, AST_Atom); var AST_Undefined = DEFNODE("Undefined", null, { $documentation: "The `undefined` value", value: (function() {}()) }, AST_Atom); var AST_Hole = DEFNODE("Hole", null, { $documentation: "A hole in an array", value: (function() {}()) }, AST_Atom); var AST_Infinity = DEFNODE("Infinity", null, { $documentation: "The `Infinity` value", value: 1/0 }, AST_Atom); var AST_Boolean = DEFNODE("Boolean", null, { $documentation: "Base class for booleans", }, AST_Atom); var AST_False = DEFNODE("False", null, { $documentation: "The `false` atom", value: false }, AST_Boolean); var AST_True = DEFNODE("True", null, { $documentation: "The `true` atom", value: true }, AST_Boolean); var AST_Await = DEFNODE("Await", "expression", { $documentation: "An `await` statement", $propdoc: { expression: "[AST_Node] the mandatory expression being awaited", }, _walk: function(visitor) { return visitor._visit(this, function() { this.expression._walk(visitor); }); } }); var AST_Yield = DEFNODE("Yield", "expression is_star", { $documentation: "A `yield` statement", $propdoc: { expression: "[AST_Node?] the value returned or thrown by this statement; could be null (representing undefined) but only when is_star is set to false", is_star: "[Boolean] Whether this is a yield or yield* statement" }, _walk: function(visitor) { return visitor._visit(this, this.expression && function() { this.expression._walk(visitor); }); } }); /* -----[ TreeWalker ]----- */ function TreeWalker(callback) { this.visit = callback; this.stack = []; this.directives = Object.create(null); } TreeWalker.prototype = { _visit: function(node, descend) { this.push(node); var ret = this.visit(node, descend ? function() { descend.call(node); } : noop); if (!ret && descend) { descend.call(node); } this.pop(); return ret; }, parent: function(n) { return this.stack[this.stack.length - 2 - (n || 0)]; }, push: function(node) { if (node instanceof AST_Lambda) { this.directives = Object.create(this.directives); } else if (node instanceof AST_Directive && !this.directives[node.value]) { this.directives[node.value] = node; } else if (node instanceof AST_Class) { this.directives = Object.create(this.directives); if (!this.directives["use strict"]) { this.directives["use strict"] = node; } } this.stack.push(node); }, pop: function() { var node = this.stack.pop(); if (node instanceof AST_Lambda || node instanceof AST_Class) { this.directives = Object.getPrototypeOf(this.directives); } }, self: function() { return this.stack[this.stack.length - 1]; }, find_parent: function(type) { var stack = this.stack; for (var i = stack.length; --i >= 0;) { var x = stack[i]; if (x instanceof type) return x; } }, has_directive: function(type) { var dir = this.directives[type]; if (dir) return dir; var node = this.stack[this.stack.length - 1]; if (node instanceof AST_Scope && node.body) { for (var i = 0; i < node.body.length; ++i) { var st = node.body[i]; if (!(st instanceof AST_Directive)) break; if (st.value == type) return st; } } }, loopcontrol_target: function(node) { var stack = this.stack; if (node.label) for (var i = stack.length; --i >= 0;) { var x = stack[i]; if (x instanceof AST_LabeledStatement && x.label.name == node.label.name) return x.body; } else for (var i = stack.length; --i >= 0;) { var x = stack[i]; if (x instanceof AST_IterationStatement || node instanceof AST_Break && x instanceof AST_Switch) return x; } } }; // Tree transformer helpers. class TreeTransformer extends TreeWalker { constructor(before, after) { super(); this.before = before; this.after = after; } } export { AST_Accessor, AST_Array, AST_Arrow, AST_Assign, AST_Atom, AST_Await, AST_BigInt, AST_Binary, AST_Block, AST_BlockStatement, AST_Boolean, AST_Break, AST_Call, AST_Case, AST_Catch, AST_Class, AST_ClassExpression, AST_ConciseMethod, AST_Conditional, AST_Const, AST_Constant, AST_Continue, AST_Debugger, AST_Default, AST_DefaultAssign, AST_DefClass, AST_Definitions, AST_Defun, AST_Destructuring, AST_Directive, AST_Do, AST_Dot, AST_DWLoop, AST_EmptyStatement, AST_Exit, AST_Expansion, AST_Export, AST_False, AST_Finally, AST_For, AST_ForIn, AST_ForOf, AST_Function, AST_Hole, AST_If, AST_Import, AST_Infinity, AST_IterationStatement, AST_Jump, AST_Label, AST_LabeledStatement, AST_LabelRef, AST_Lambda, AST_Let, AST_LoopControl, AST_NameMapping, AST_NaN, AST_New, AST_NewTarget, AST_Node, AST_Null, AST_Number, AST_Object, AST_ObjectGetter, AST_ObjectKeyVal, AST_ObjectProperty, AST_ObjectSetter, AST_PrefixedTemplateString, AST_PropAccess, AST_RegExp, AST_Return, AST_Scope, AST_Sequence, AST_SimpleStatement, AST_Statement, AST_StatementWithBody, AST_String, AST_Sub, AST_Super, AST_Switch, AST_SwitchBranch, AST_Symbol, AST_SymbolBlockDeclaration, AST_SymbolCatch, AST_SymbolClass, AST_SymbolConst, AST_SymbolDeclaration, AST_SymbolDefClass, AST_SymbolDefun, AST_SymbolExport, AST_SymbolExportForeign, AST_SymbolFunarg, AST_SymbolImport, AST_SymbolImportForeign, AST_SymbolLambda, AST_SymbolLet, AST_SymbolMethod, AST_SymbolRef, AST_SymbolVar, AST_TemplateSegment, AST_TemplateString, AST_This, AST_Throw, AST_Token, AST_Toplevel, AST_True, AST_Try, AST_Unary, AST_UnaryPostfix, AST_UnaryPrefix, AST_Undefined, AST_Var, AST_VarDef, AST_While, AST_With, AST_Yield, TreeTransformer, TreeWalker, walk_body, }; terser-4.1.2/lib/compress/000077500000000000000000000000001351061312300154165ustar00rootroot00000000000000terser-4.1.2/lib/compress/index.js000066400000000000000000011165271351061312300171000ustar00rootroot00000000000000/*********************************************************************** A JavaScript tokenizer / parser / beautifier / compressor. https://github.com/mishoo/UglifyJS2 -------------------------------- (C) --------------------------------- Author: Mihai Bazon http://mihai.bazon.net/blog Distributed under the BSD license: Copyright 2012 (c) Mihai Bazon Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ "use strict"; import { defaults, HOP, keep_name, makePredicate, map_add, MAP, member, noop, remove, return_false, return_null, return_this, return_true, string_template, } from "../utils/index.js"; import { first_in_statement, } from "../utils/first_in_statement.js"; import { AST_Accessor, AST_Array, AST_Arrow, AST_Assign, AST_Await, AST_BigInt, AST_Binary, AST_Block, AST_BlockStatement, AST_Boolean, AST_Break, AST_Call, AST_Case, AST_Catch, AST_Class, AST_ClassExpression, AST_ConciseMethod, AST_Conditional, AST_Const, AST_Constant, AST_Continue, AST_Debugger, AST_Default, AST_DefaultAssign, AST_DefClass, AST_Definitions, AST_Defun, AST_Destructuring, AST_Directive, AST_Do, AST_Dot, AST_DWLoop, AST_EmptyStatement, AST_Exit, AST_Expansion, AST_Export, AST_False, AST_Finally, AST_For, AST_ForIn, AST_Function, AST_Hole, AST_If, AST_Import, AST_Infinity, AST_IterationStatement, AST_Jump, AST_LabeledStatement, AST_Lambda, AST_Let, AST_LoopControl, AST_NaN, AST_New, AST_Node, AST_Null, AST_Number, AST_Object, AST_ObjectGetter, AST_ObjectKeyVal, AST_ObjectProperty, AST_PrefixedTemplateString, AST_PropAccess, AST_RegExp, AST_Return, AST_Scope, AST_Sequence, AST_SimpleStatement, AST_Statement, AST_String, AST_Sub, AST_Switch, AST_SwitchBranch, AST_Symbol, AST_SymbolBlockDeclaration, AST_SymbolCatch, AST_SymbolConst, AST_SymbolDeclaration, AST_SymbolDefun, AST_SymbolExport, AST_SymbolFunarg, AST_SymbolLambda, AST_SymbolMethod, AST_SymbolRef, AST_SymbolVar, AST_TemplateSegment, AST_TemplateString, AST_This, AST_Toplevel, AST_True, AST_Try, AST_Unary, AST_UnaryPostfix, AST_UnaryPrefix, AST_Undefined, AST_Var, AST_VarDef, AST_While, AST_With, AST_Yield, TreeTransformer, TreeWalker, walk_body, } from "../ast.js"; import { is_identifier_string, JS_Parse_Error, parse, PRECEDENCE, } from "../parse.js"; import { OutputStream } from "../output.js"; import { base54, SymbolDef, } from "../scope.js"; class Compressor extends TreeWalker { constructor(options, false_by_default) { super(); if (options.defaults !== undefined && !options.defaults) false_by_default = true; this.options = defaults(options, { arguments : false, arrows : !false_by_default, booleans : !false_by_default, booleans_as_integers : false, collapse_vars : !false_by_default, comparisons : !false_by_default, computed_props: !false_by_default, conditionals : !false_by_default, dead_code : !false_by_default, defaults : true, directives : !false_by_default, drop_console : false, drop_debugger : !false_by_default, ecma : 5, evaluate : !false_by_default, expression : false, global_defs : false, hoist_funs : false, hoist_props : !false_by_default, hoist_vars : false, ie8 : false, if_return : !false_by_default, inline : !false_by_default, join_vars : !false_by_default, keep_classnames: false, keep_fargs : true, keep_fnames : false, keep_infinity : false, loops : !false_by_default, module : false, negate_iife : !false_by_default, passes : 1, properties : !false_by_default, pure_getters : !false_by_default && "strict", pure_funcs : null, reduce_funcs : !false_by_default, reduce_vars : !false_by_default, sequences : !false_by_default, side_effects : !false_by_default, switches : !false_by_default, top_retain : null, toplevel : !!(options && options["top_retain"]), typeofs : !false_by_default, unsafe : false, unsafe_arrows : false, unsafe_comps : false, unsafe_Function: false, unsafe_math : false, unsafe_methods: false, unsafe_proto : false, unsafe_regexp : false, unsafe_undefined: false, unused : !false_by_default, warnings : false, }, true); var global_defs = this.options["global_defs"]; if (typeof global_defs == "object") for (var key in global_defs) { if (key[0] === "@" && HOP(global_defs, key)) { global_defs[key.slice(1)] = parse(global_defs[key], { expression: true }); } } if (this.options["inline"] === true) this.options["inline"] = 3; var pure_funcs = this.options["pure_funcs"]; if (typeof pure_funcs == "function") { this.pure_funcs = pure_funcs; } else { this.pure_funcs = pure_funcs ? function(node) { return !pure_funcs.includes(node.expression.print_to_string()); } : return_true; } var top_retain = this.options["top_retain"]; if (top_retain instanceof RegExp) { this.top_retain = function(def) { return top_retain.test(def.name); }; } else if (typeof top_retain == "function") { this.top_retain = top_retain; } else if (top_retain) { if (typeof top_retain == "string") { top_retain = top_retain.split(/,/); } this.top_retain = function(def) { return top_retain.includes(def.name); }; } if (this.options["module"]) { this.directives["use strict"] = true; this.options["toplevel"] = true; } var toplevel = this.options["toplevel"]; this.toplevel = typeof toplevel == "string" ? { funcs: /funcs/.test(toplevel), vars: /vars/.test(toplevel) } : { funcs: toplevel, vars: toplevel }; var sequences = this.options["sequences"]; this.sequences_limit = sequences == 1 ? 800 : sequences | 0; this.warnings_produced = {}; } option(key) { return this.options[key]; } exposed(def) { if (def.export) return true; if (def.global) for (var i = 0, len = def.orig.length; i < len; i++) if (!this.toplevel[def.orig[i] instanceof AST_SymbolDefun ? "funcs" : "vars"]) return true; return false; } in_boolean_context() { if (!this.option("booleans")) return false; var self = this.self(); for (var i = 0, p; p = this.parent(i); i++) { if (p instanceof AST_SimpleStatement || p instanceof AST_Conditional && p.condition === self || p instanceof AST_DWLoop && p.condition === self || p instanceof AST_For && p.condition === self || p instanceof AST_If && p.condition === self || p instanceof AST_UnaryPrefix && p.operator == "!" && p.expression === self) { return true; } if (p instanceof AST_Binary && (p.operator == "&&" || p.operator == "||") || p instanceof AST_Conditional || p.tail_node() === self) { self = p; } else { return false; } } } compress(node) { node = node.resolve_defines(this); if (this.option("expression")) { node.process_expression(true); } var passes = +this.options.passes || 1; var min_count = 1 / 0; var stopping = false; var mangle = { ie8: this.option("ie8") }; for (var pass = 0; pass < passes; pass++) { node.figure_out_scope(mangle); if (pass === 0 && this.option("drop_console")) { // must be run before reduce_vars and compress pass node = node.drop_console(); } if (pass > 0 || this.option("reduce_vars")) node.reset_opt_flags(this); node = node.transform(this); if (passes > 1) { var count = 0; node.walk(new TreeWalker(function() { count++; })); this.info("pass " + pass + ": last_count: " + min_count + ", count: " + count); if (count < min_count) { min_count = count; stopping = false; } else if (stopping) { break; } else { stopping = true; } } } if (this.option("expression")) { node.process_expression(false); } return node; } info() { if (this.options.warnings == "verbose") { AST_Node.warn.apply(AST_Node, arguments); } } warn(text, props) { if (this.options.warnings) { // only emit unique warnings var message = string_template(text, props); if (!(message in this.warnings_produced)) { this.warnings_produced[message] = true; AST_Node.warn.apply(AST_Node, arguments); } } } clear_warnings() { this.warnings_produced = {}; } before(node, descend, in_list) { if (node._squeezed) return node; var was_scope = false; if (node instanceof AST_Scope) { node = node.hoist_properties(this); node = node.hoist_declarations(this); was_scope = true; } // Before https://github.com/mishoo/UglifyJS2/pull/1602 AST_Node.optimize() // would call AST_Node.transform() if a different instance of AST_Node is // produced after def_optimize(). // This corrupts TreeWalker.stack, which cause AST look-ups to malfunction. // Migrate and defer all children's AST_Node.transform() to below, which // will now happen after this parent AST_Node has been properly substituted // thus gives a consistent AST snapshot. descend(node, this); // Existing code relies on how AST_Node.optimize() worked, and omitting the // following replacement call would result in degraded efficiency of both // output and performance. descend(node, this); var opt = node.optimize(this); if (was_scope && opt instanceof AST_Scope) { opt.drop_unused(this); descend(opt, this); } if (opt === node) opt._squeezed = true; return opt; } } (function() { function def_optimize(node, optimizer) { node.DEFMETHOD("optimize", function(compressor) { var self = this; if (self._optimized) return self; if (compressor.has_directive("use asm")) return self; var opt = optimizer(self, compressor); opt._optimized = true; return opt; }); } def_optimize(AST_Node, function(self, compressor) { return self; }); AST_Toplevel.DEFMETHOD("drop_console", function() { return this.transform(new TreeTransformer(function(self) { if (self.TYPE == "Call") { var exp = self.expression; if (exp instanceof AST_PropAccess) { var name = exp.expression; while (name.expression) { name = name.expression; } if (is_undeclared_ref(name) && name.name == "console") { return make_node(AST_Undefined, self); } } } })); }); AST_Node.DEFMETHOD("equivalent_to", function(node) { return this.TYPE == node.TYPE && this.print_to_string() == node.print_to_string(); }); AST_Scope.DEFMETHOD("process_expression", function(insert, compressor) { var self = this; var tt = new TreeTransformer(function(node) { if (insert && node instanceof AST_SimpleStatement) { return make_node(AST_Return, node, { value: node.body }); } if (!insert && node instanceof AST_Return) { if (compressor) { var value = node.value && node.value.drop_side_effect_free(compressor, true); return value ? make_node(AST_SimpleStatement, node, { body: value }) : make_node(AST_EmptyStatement, node); } return make_node(AST_SimpleStatement, node, { body: node.value || make_node(AST_UnaryPrefix, node, { operator: "void", expression: make_node(AST_Number, node, { value: 0 }) }) }); } if (node instanceof AST_Class || node instanceof AST_Lambda && node !== self) { return node; } if (node instanceof AST_Block) { var index = node.body.length - 1; if (index >= 0) { node.body[index] = node.body[index].transform(tt); } } else if (node instanceof AST_If) { node.body = node.body.transform(tt); if (node.alternative) { node.alternative = node.alternative.transform(tt); } } else if (node instanceof AST_With) { node.body = node.body.transform(tt); } return node; }); self.transform(tt); }); function read_property(obj, key) { key = get_value(key); if (key instanceof AST_Node) return; var value; if (obj instanceof AST_Array) { var elements = obj.elements; if (key == "length") return make_node_from_constant(elements.length, obj); if (typeof key == "number" && key in elements) value = elements[key]; } else if (obj instanceof AST_Object) { key = "" + key; var props = obj.properties; for (var i = props.length; --i >= 0;) { var prop = props[i]; if (!(prop instanceof AST_ObjectKeyVal)) return; if (!value && props[i].key === key) value = props[i].value; } } return value instanceof AST_SymbolRef && value.fixed_value() || value; } function is_modified(compressor, tw, node, value, level, immutable) { var parent = tw.parent(level); var lhs = is_lhs(node, parent); if (lhs) return lhs; if (!immutable && parent instanceof AST_Call && parent.expression === node && !(value instanceof AST_Arrow) && !(value instanceof AST_Class) && !parent.is_expr_pure(compressor) && (!(value instanceof AST_Function) || !(parent instanceof AST_New) && value.contains_this())) { return true; } if (parent instanceof AST_Array) { return is_modified(compressor, tw, parent, parent, level + 1); } if (parent instanceof AST_ObjectKeyVal && node === parent.value) { var obj = tw.parent(level + 1); return is_modified(compressor, tw, obj, obj, level + 2); } if (parent instanceof AST_PropAccess && parent.expression === node) { var prop = read_property(value, parent.property); return !immutable && is_modified(compressor, tw, parent, prop, level + 1); } } (function(def_reduce_vars) { def_reduce_vars(AST_Node, noop); function reset_def(compressor, def) { def.assignments = 0; def.chained = false; def.direct_access = false; def.escaped = false; if (def.scope.pinned()) { def.fixed = false; } else if (def.orig[0] instanceof AST_SymbolConst || !compressor.exposed(def)) { def.fixed = def.init; } else { def.fixed = false; } def.recursive_refs = 0; def.references = []; def.should_replace = undefined; def.single_use = undefined; } function reset_variables(tw, compressor, node) { node.variables.forEach(function(def) { reset_def(compressor, def); if (def.fixed === null) { def.safe_ids = tw.safe_ids; mark(tw, def, true); } else if (def.fixed) { tw.loop_ids[def.id] = tw.in_loop; mark(tw, def, true); } }); } function reset_block_variables(compressor, node) { if (node.block_scope) node.block_scope.variables.forEach(function(def) { reset_def(compressor, def); }); } function push(tw) { tw.safe_ids = Object.create(tw.safe_ids); } function pop(tw) { tw.safe_ids = Object.getPrototypeOf(tw.safe_ids); } function mark(tw, def, safe) { tw.safe_ids[def.id] = safe; } function safe_to_read(tw, def) { if (def.single_use == "m") return false; if (tw.safe_ids[def.id]) { if (def.fixed == null) { var orig = def.orig[0]; if (orig instanceof AST_SymbolFunarg || orig.name == "arguments") return false; def.fixed = make_node(AST_Undefined, orig); } return true; } return def.fixed instanceof AST_Defun; } function safe_to_assign(tw, def, value) { if (def.fixed === undefined) return true; if (def.fixed === null && def.safe_ids) { def.safe_ids[def.id] = false; delete def.safe_ids; return true; } if (!HOP(tw.safe_ids, def.id)) return false; if (!safe_to_read(tw, def)) return false; if (def.fixed === false) return false; if (def.fixed != null && (!value || def.references.length > def.assignments)) return false; return def.orig.every((sym) => { return !(sym instanceof AST_SymbolConst || sym instanceof AST_SymbolDefun || sym instanceof AST_SymbolLambda); }); } function ref_once(tw, compressor, def) { return compressor.option("unused") && !def.scope.pinned() && def.references.length - def.recursive_refs == 1 && tw.loop_ids[def.id] === tw.in_loop; } function is_immutable(value) { if (!value) return false; return value.is_constant() || value instanceof AST_Lambda || value instanceof AST_This; } function mark_escaped(tw, d, scope, node, value, level, depth) { var parent = tw.parent(level); if (value) { if (value.is_constant()) return; if (value instanceof AST_ClassExpression) return; } if (parent instanceof AST_Assign && parent.operator == "=" && node === parent.right || parent instanceof AST_Call && (node !== parent.expression || parent instanceof AST_New) || parent instanceof AST_Exit && node === parent.value && node.scope !== d.scope || parent instanceof AST_VarDef && node === parent.value || parent instanceof AST_Yield && node === parent.value && node.scope !== d.scope) { if (depth > 1 && !(value && value.is_constant_expression(scope))) depth = 1; if (!d.escaped || d.escaped > depth) d.escaped = depth; return; } else if (parent instanceof AST_Array || parent instanceof AST_Await || parent instanceof AST_Binary && lazy_op.has(parent.operator) || parent instanceof AST_Conditional && node !== parent.condition || parent instanceof AST_Expansion || parent instanceof AST_Sequence && node === parent.tail_node()) { mark_escaped(tw, d, scope, parent, parent, level + 1, depth); } else if (parent instanceof AST_ObjectKeyVal && node === parent.value) { var obj = tw.parent(level + 1); mark_escaped(tw, d, scope, obj, obj, level + 2, depth); } else if (parent instanceof AST_PropAccess && node === parent.expression) { value = read_property(value, parent.property); mark_escaped(tw, d, scope, parent, value, level + 1, depth + 1); if (value) return; } if (level > 0) return; if (parent instanceof AST_Sequence && node !== parent.tail_node()) return; if (parent instanceof AST_SimpleStatement) return; d.direct_access = true; } var suppressor = new TreeWalker(function(node) { if (!(node instanceof AST_Symbol)) return; var d = node.definition(); if (!d) return; if (node instanceof AST_SymbolRef) d.references.push(node); d.fixed = false; }); def_reduce_vars(AST_Accessor, function(tw, descend, compressor) { push(tw); reset_variables(tw, compressor, this); descend(); pop(tw); return true; }); def_reduce_vars(AST_Arrow, mark_func_expr); def_reduce_vars(AST_Assign, function(tw, descend, compressor) { var node = this; if (node.left instanceof AST_Destructuring) { node.left.walk(suppressor); return; } var sym = node.left; if (!(sym instanceof AST_SymbolRef)) return; var d = sym.definition(); var safe = safe_to_assign(tw, d, sym.scope, node.right); d.assignments++; if (!safe) return; var fixed = d.fixed; if (!fixed && node.operator != "=") return; var eq = node.operator == "="; var value = eq ? node.right : node; if (is_modified(compressor, tw, node, value, 0)) return; d.references.push(sym); if (!eq) d.chained = true; d.fixed = eq ? function() { return node.right; } : function() { return make_node(AST_Binary, node, { operator: node.operator.slice(0, -1), left: fixed instanceof AST_Node ? fixed : fixed(), right: node.right }); }; mark(tw, d, false); node.right.walk(tw); mark(tw, d, true); mark_escaped(tw, d, sym.scope, node, value, 0, 1); return true; }); def_reduce_vars(AST_Binary, function(tw) { if (!lazy_op.has(this.operator)) return; this.left.walk(tw); push(tw); this.right.walk(tw); pop(tw); return true; }); def_reduce_vars(AST_Block, function(tw, descend, compressor) { reset_block_variables(compressor, this); }); def_reduce_vars(AST_Case, function(tw) { push(tw); this.expression.walk(tw); pop(tw); push(tw); walk_body(this, tw); pop(tw); return true; }); def_reduce_vars(AST_ClassExpression, function(tw, descend) { this.inlined = false; push(tw); descend(); pop(tw); return true; }); def_reduce_vars(AST_Conditional, function(tw) { this.condition.walk(tw); push(tw); this.consequent.walk(tw); pop(tw); push(tw); this.alternative.walk(tw); pop(tw); return true; }); def_reduce_vars(AST_Default, function(tw, descend) { push(tw); descend(); pop(tw); return true; }); function mark_def_node(tw, descend, compressor) { this.inlined = false; var save_ids = tw.safe_ids; tw.safe_ids = Object.create(null); reset_variables(tw, compressor, this); descend(); tw.safe_ids = save_ids; return true; } def_reduce_vars(AST_DefClass, mark_def_node); def_reduce_vars(AST_Defun, mark_def_node); def_reduce_vars(AST_Do, function(tw, descend, compressor) { reset_block_variables(compressor, this); var saved_loop = tw.in_loop; tw.in_loop = this; push(tw); this.body.walk(tw); if (has_break_or_continue(this)) { pop(tw); push(tw); } this.condition.walk(tw); pop(tw); tw.in_loop = saved_loop; return true; }); def_reduce_vars(AST_For, function(tw, descend, compressor) { reset_block_variables(compressor, this); if (this.init) this.init.walk(tw); var saved_loop = tw.in_loop; tw.in_loop = this; push(tw); if (this.condition) this.condition.walk(tw); this.body.walk(tw); if (this.step) { if (has_break_or_continue(this)) { pop(tw); push(tw); } this.step.walk(tw); } pop(tw); tw.in_loop = saved_loop; return true; }); def_reduce_vars(AST_ForIn, function(tw, descend, compressor) { reset_block_variables(compressor, this); this.init.walk(suppressor); this.object.walk(tw); var saved_loop = tw.in_loop; tw.in_loop = this; push(tw); this.body.walk(tw); pop(tw); tw.in_loop = saved_loop; return true; }); function mark_func_expr(tw, descend, compressor) { var node = this; node.inlined = false; push(tw); reset_variables(tw, compressor, node); if (node.uses_arguments) { descend(); pop(tw); return; } var iife; if (!node.name && (iife = tw.parent()) instanceof AST_Call && iife.expression === node) { // Virtually turn IIFE parameters into variable definitions: // (function(a,b) {...})(c,d) => (function() {var a=c,b=d; ...})() // So existing transformation rules can work on them. node.argnames.forEach(function(arg, i) { if (!arg.definition) return; var d = arg.definition(); // Avoid setting fixed when there's more than one origin for a variable value if (d.orig.length > 1) return; if (d.fixed === undefined && (!node.uses_arguments || tw.has_directive("use strict"))) { d.fixed = function() { return iife.args[i] || make_node(AST_Undefined, iife); }; tw.loop_ids[d.id] = tw.in_loop; mark(tw, d, true); } else { d.fixed = false; } }); } descend(); pop(tw); return true; } def_reduce_vars(AST_Function, mark_func_expr); def_reduce_vars(AST_If, function(tw) { this.condition.walk(tw); push(tw); this.body.walk(tw); pop(tw); if (this.alternative) { push(tw); this.alternative.walk(tw); pop(tw); } return true; }); def_reduce_vars(AST_LabeledStatement, function(tw) { push(tw); this.body.walk(tw); pop(tw); return true; }); def_reduce_vars(AST_SymbolCatch, function() { this.definition().fixed = false; }); def_reduce_vars(AST_SymbolRef, function(tw, descend, compressor) { var d = this.definition(); d.references.push(this); if (d.references.length == 1 && !d.fixed && d.orig[0] instanceof AST_SymbolDefun) { tw.loop_ids[d.id] = tw.in_loop; } var value; if (d.fixed === undefined || !safe_to_read(tw, d)) { d.fixed = false; } else if (d.fixed) { value = this.fixed_value(); if (value instanceof AST_Lambda && recursive_ref(tw, d)) { d.recursive_refs++; } else if (value && !compressor.exposed(d) && ref_once(tw, compressor, d)) { d.single_use = value instanceof AST_Lambda && !value.pinned() || value instanceof AST_Class || d.scope === this.scope && value.is_constant_expression(); } else { d.single_use = false; } if (is_modified(compressor, tw, this, value, 0, is_immutable(value))) { if (d.single_use) { d.single_use = "m"; } else { d.fixed = false; } } } mark_escaped(tw, d, this.scope, this, value, 0, 1); }); def_reduce_vars(AST_Toplevel, function(tw, descend, compressor) { this.globals.forEach(function(def) { reset_def(compressor, def); }); reset_variables(tw, compressor, this); }); def_reduce_vars(AST_Try, function(tw, descend, compressor) { reset_block_variables(compressor, this); push(tw); walk_body(this, tw); pop(tw); if (this.bcatch) { push(tw); this.bcatch.walk(tw); pop(tw); } if (this.bfinally) this.bfinally.walk(tw); return true; }); def_reduce_vars(AST_Unary, function(tw, descend) { var node = this; if (node.operator != "++" && node.operator != "--") return; var exp = node.expression; if (!(exp instanceof AST_SymbolRef)) return; var d = exp.definition(); var safe = safe_to_assign(tw, d, true); d.assignments++; if (!safe) return; var fixed = d.fixed; if (!fixed) return; d.references.push(exp); d.chained = true; d.fixed = function() { return make_node(AST_Binary, node, { operator: node.operator.slice(0, -1), left: make_node(AST_UnaryPrefix, node, { operator: "+", expression: fixed instanceof AST_Node ? fixed : fixed() }), right: make_node(AST_Number, node, { value: 1 }) }); }; mark(tw, d, true); return true; }); def_reduce_vars(AST_VarDef, function(tw, descend) { var node = this; if (node.name instanceof AST_Destructuring) { node.name.walk(suppressor); return; } var d = node.name.definition(); if (node.value) { if (safe_to_assign(tw, d, node.value)) { d.fixed = function() { return node.value; }; tw.loop_ids[d.id] = tw.in_loop; mark(tw, d, false); descend(); mark(tw, d, true); return true; } else { d.fixed = false; } } }); def_reduce_vars(AST_While, function(tw, descend, compressor) { reset_block_variables(compressor, this); var saved_loop = tw.in_loop; tw.in_loop = this; push(tw); descend(); pop(tw); tw.in_loop = saved_loop; return true; }); })(function(node, func) { node.DEFMETHOD("reduce_vars", func); }); AST_Toplevel.DEFMETHOD("reset_opt_flags", function(compressor) { var self = this; var reduce_vars = compressor.option("reduce_vars"); var tw = new TreeWalker(function(node, descend) { node._squeezed = false; node._optimized = false; if (reduce_vars) { if (compressor.top_retain) { if (tw.parent() === self) node._top = true; else delete node._top; } return node.reduce_vars(tw, descend, compressor); } }); // Stack of look-up tables to keep track of whether a `SymbolDef` has been // properly assigned before use: // - `push()` & `pop()` when visiting conditional branches // - backup & restore via `save_ids` when visiting out-of-order sections tw.safe_ids = Object.create(null); tw.in_loop = null; tw.loop_ids = Object.create(null); self.walk(tw); }); AST_Symbol.DEFMETHOD("fixed_value", function() { var fixed = this.definition().fixed; if (!fixed || fixed instanceof AST_Node) return fixed; return fixed(); }); AST_SymbolRef.DEFMETHOD("is_immutable", function() { var orig = this.definition().orig; return orig.length == 1 && orig[0] instanceof AST_SymbolLambda; }); function is_func_expr(node) { return node instanceof AST_Arrow || node instanceof AST_Function; } function is_lhs_read_only(lhs) { if (lhs instanceof AST_This) return true; if (lhs instanceof AST_SymbolRef) return lhs.definition().orig[0] instanceof AST_SymbolLambda; if (lhs instanceof AST_PropAccess) { lhs = lhs.expression; if (lhs instanceof AST_SymbolRef) { if (lhs.is_immutable()) return false; lhs = lhs.fixed_value(); } if (!lhs) return true; if (lhs instanceof AST_RegExp) return false; if (lhs instanceof AST_Constant) return true; return is_lhs_read_only(lhs); } return false; } function is_ref_of(ref, type) { if (!(ref instanceof AST_SymbolRef)) return false; var orig = ref.definition().orig; for (var i = orig.length; --i >= 0;) { if (orig[i] instanceof type) return true; } } function find_variable(compressor, name) { var scope, i = 0; while (scope = compressor.parent(i++)) { if (scope instanceof AST_Scope) break; if (scope instanceof AST_Catch && scope.argname) { scope = scope.argname.definition().scope; break; } } return scope.find_variable(name); } function make_node(ctor, orig, props) { if (!props) props = {}; if (orig) { if (!props.start) props.start = orig.start; if (!props.end) props.end = orig.end; } return new ctor(props); } function make_sequence(orig, expressions) { if (expressions.length == 1) return expressions[0]; return make_node(AST_Sequence, orig, { expressions: expressions.reduce(merge_sequence, []) }); } function make_node_from_constant(val, orig) { switch (typeof val) { case "string": return make_node(AST_String, orig, { value: val }); case "number": if (isNaN(val)) return make_node(AST_NaN, orig); if (isFinite(val)) { return 1 / val < 0 ? make_node(AST_UnaryPrefix, orig, { operator: "-", expression: make_node(AST_Number, orig, { value: -val }) }) : make_node(AST_Number, orig, { value: val }); } return val < 0 ? make_node(AST_UnaryPrefix, orig, { operator: "-", expression: make_node(AST_Infinity, orig) }) : make_node(AST_Infinity, orig); case "boolean": return make_node(val ? AST_True : AST_False, orig); case "undefined": return make_node(AST_Undefined, orig); default: if (val === null) { return make_node(AST_Null, orig, { value: null }); } if (val instanceof RegExp) { return make_node(AST_RegExp, orig, { value: val }); } throw new Error(string_template("Can't handle constant of type: {type}", { type: typeof val })); } } // we shouldn't compress (1,func)(something) to // func(something) because that changes the meaning of // the func (becomes lexical instead of global). function maintain_this_binding(parent, orig, val) { if (parent instanceof AST_UnaryPrefix && parent.operator == "delete" || parent instanceof AST_Call && parent.expression === orig && (val instanceof AST_PropAccess || val instanceof AST_SymbolRef && val.name == "eval")) { return make_sequence(orig, [ make_node(AST_Number, orig, { value: 0 }), val ]); } return val; } function merge_sequence(array, node) { if (node instanceof AST_Sequence) { array.push.apply(array, node.expressions); } else { array.push(node); } return array; } function as_statement_array(thing) { if (thing === null) return []; if (thing instanceof AST_BlockStatement) return thing.body; if (thing instanceof AST_EmptyStatement) return []; if (thing instanceof AST_Statement) return [ thing ]; throw new Error("Can't convert thing to statement array"); } function is_empty(thing) { if (thing === null) return true; if (thing instanceof AST_EmptyStatement) return true; if (thing instanceof AST_BlockStatement) return thing.body.length == 0; return false; } function can_be_evicted_from_block(node) { return !( node instanceof AST_DefClass || node instanceof AST_Defun || node instanceof AST_Let || node instanceof AST_Const || node instanceof AST_Export || node instanceof AST_Import ); } function loop_body(x) { if (x instanceof AST_IterationStatement) { return x.body instanceof AST_BlockStatement ? x.body : x; } return x; } function is_iife_call(node) { if (node.TYPE != "Call") return false; return node.expression instanceof AST_Function || is_iife_call(node.expression); } function is_undeclared_ref(node) { return node instanceof AST_SymbolRef && node.definition().undeclared; } var global_names = makePredicate("Array Boolean clearInterval clearTimeout console Date decodeURI decodeURIComponent encodeURI encodeURIComponent Error escape eval EvalError Function isFinite isNaN JSON Math Number parseFloat parseInt RangeError ReferenceError RegExp Object setInterval setTimeout String SyntaxError TypeError unescape URIError"); AST_SymbolRef.DEFMETHOD("is_declared", function(compressor) { return !this.definition().undeclared || compressor.option("unsafe") && global_names.has(this.name); }); var identifier_atom = makePredicate("Infinity NaN undefined"); function is_identifier_atom(node) { return node instanceof AST_Infinity || node instanceof AST_NaN || node instanceof AST_Undefined; } function tighten_body(statements, compressor) { var in_loop, in_try; var scope = compressor.find_parent(AST_Scope).get_defun_scope(); find_loop_scope_try(); var CHANGED, max_iter = 10; do { CHANGED = false; eliminate_spurious_blocks(statements); if (compressor.option("dead_code")) { eliminate_dead_code(statements, compressor); } if (compressor.option("if_return")) { handle_if_return(statements, compressor); } if (compressor.sequences_limit > 0) { sequencesize(statements, compressor); sequencesize_2(statements, compressor); } if (compressor.option("join_vars")) { join_consecutive_vars(statements); } if (compressor.option("collapse_vars")) { collapse(statements, compressor); } } while (CHANGED && max_iter-- > 0); function find_loop_scope_try() { var node = compressor.self(), level = 0; do { if (node instanceof AST_Catch || node instanceof AST_Finally) { level++; } else if (node instanceof AST_IterationStatement) { in_loop = true; } else if (node instanceof AST_Scope) { scope = node; break; } else if (node instanceof AST_Try) { in_try = true; } } while (node = compressor.parent(level++)); } // Search from right to left for assignment-like expressions: // - `var a = x;` // - `a = x;` // - `++a` // For each candidate, scan from left to right for first usage, then try // to fold assignment into the site for compression. // Will not attempt to collapse assignments into or past code blocks // which are not sequentially executed, e.g. loops and conditionals. function collapse(statements, compressor) { if (scope.pinned()) return statements; var args; var candidates = []; var stat_index = statements.length; var scanner = new TreeTransformer(function(node, descend) { if (abort) return node; // Skip nodes before `candidate` as quickly as possible if (!hit) { if (node !== hit_stack[hit_index]) return node; hit_index++; if (hit_index < hit_stack.length) return handle_custom_scan_order(node); hit = true; stop_after = find_stop(node, 0); if (stop_after === node) abort = true; return node; } // Stop immediately if these node types are encountered var parent = scanner.parent(); if (node instanceof AST_Assign && node.operator != "=" && lhs.equivalent_to(node.left) || node instanceof AST_Await || node instanceof AST_Call && lhs instanceof AST_PropAccess && lhs.equivalent_to(node.expression) || node instanceof AST_Debugger || node instanceof AST_Destructuring || node instanceof AST_Expansion && node.expression instanceof AST_Symbol && node.expression.definition().references.length > 1 || node instanceof AST_IterationStatement && !(node instanceof AST_For) || node instanceof AST_LoopControl || node instanceof AST_Try || node instanceof AST_With || node instanceof AST_Yield || node instanceof AST_Export || parent instanceof AST_For && node !== parent.init || !replace_all && (node instanceof AST_SymbolRef && !node.is_declared(compressor))) { abort = true; return node; } // Stop only if candidate is found within conditional branches if (!stop_if_hit && (!lhs_local || !replace_all) && (parent instanceof AST_Binary && lazy_op.has(parent.operator) && parent.left !== node || parent instanceof AST_Conditional && parent.condition !== node || parent instanceof AST_If && parent.condition !== node)) { stop_if_hit = parent; } // Replace variable with assignment when found if (can_replace && !(node instanceof AST_SymbolDeclaration) && lhs.equivalent_to(node)) { if (stop_if_hit) { abort = true; return node; } if (is_lhs(node, parent)) { if (value_def) replaced++; return node; } CHANGED = abort = true; replaced++; compressor.info("Collapsing {name} [{file}:{line},{col}]", { name: node.print_to_string(), file: node.start.file, line: node.start.line, col: node.start.col }); if (candidate instanceof AST_UnaryPostfix) { return make_node(AST_UnaryPrefix, candidate, candidate); } if (candidate instanceof AST_VarDef) { if (value_def) { abort = false; return node; } var def = candidate.name.definition(); var value = candidate.value; if (def.references.length - def.replaced == 1 && !compressor.exposed(def)) { def.replaced++; if (funarg && is_identifier_atom(value)) { return value.transform(compressor); } else { return maintain_this_binding(parent, node, value); } } return make_node(AST_Assign, candidate, { operator: "=", left: make_node(AST_SymbolRef, candidate.name, candidate.name), right: value }); } candidate.write_only = false; return candidate; } // These node types have child nodes that execute sequentially, // but are otherwise not safe to scan into or beyond them. var sym; if (node instanceof AST_Call || node instanceof AST_Exit && (side_effects || lhs instanceof AST_PropAccess || may_modify(lhs)) || node instanceof AST_PropAccess && (side_effects || node.expression.may_throw_on_access(compressor)) || node instanceof AST_SymbolRef && (lvalues.get(node.name) || side_effects && may_modify(node)) || node instanceof AST_VarDef && node.value && (lvalues.has(node.name.name) || side_effects && may_modify(node.name)) || (sym = is_lhs(node.left, node)) && (sym instanceof AST_PropAccess || lvalues.has(sym.name)) || may_throw && (in_try ? node.has_side_effects(compressor) : side_effects_external(node))) { stop_after = node; if (node instanceof AST_Scope) abort = true; } return handle_custom_scan_order(node); }, function(node) { if (abort) return; if (stop_after === node) abort = true; if (stop_if_hit === node) stop_if_hit = null; }); var multi_replacer = new TreeTransformer(function(node) { if (abort) return node; // Skip nodes before `candidate` as quickly as possible if (!hit) { if (node !== hit_stack[hit_index]) return node; hit_index++; if (hit_index < hit_stack.length) return; hit = true; return node; } // Replace variable when found if (node instanceof AST_SymbolRef && node.name == def.name) { if (!--replaced) abort = true; if (is_lhs(node, multi_replacer.parent())) return node; def.replaced++; value_def.replaced--; return candidate.value; } // Skip (non-executed) functions and (leading) default case in switch statements if (node instanceof AST_Default || node instanceof AST_Scope) return node; }); while (--stat_index >= 0) { // Treat parameters as collapsible in IIFE, i.e. // function(a, b){ ... }(x()); // would be translated into equivalent assignments: // var a = x(), b = undefined; if (stat_index == 0 && compressor.option("unused")) extract_args(); // Find collapsible assignments var hit_stack = []; extract_candidates(statements[stat_index]); while (candidates.length > 0) { hit_stack = candidates.pop(); var hit_index = 0; var candidate = hit_stack[hit_stack.length - 1]; var value_def = null; var stop_after = null; var stop_if_hit = null; var lhs = get_lhs(candidate); if (!lhs || is_lhs_read_only(lhs) || lhs.has_side_effects(compressor)) continue; // Locate symbols which may execute code outside of scanning range var lvalues = get_lvalues(candidate); var lhs_local = is_lhs_local(lhs); if (lhs instanceof AST_SymbolRef) lvalues.set(lhs.name, false); var side_effects = value_has_side_effects(candidate); var replace_all = replace_all_symbols(); var may_throw = candidate.may_throw(compressor); var funarg = candidate.name instanceof AST_SymbolFunarg; var hit = funarg; var abort = false, replaced = 0, can_replace = !args || !hit; if (!can_replace) { for (var j = compressor.self().argnames.lastIndexOf(candidate.name) + 1; !abort && j < args.length; j++) { args[j].transform(scanner); } can_replace = true; } for (var i = stat_index; !abort && i < statements.length; i++) { statements[i].transform(scanner); } if (value_def) { var def = candidate.name.definition(); if (abort && def.references.length - def.replaced > replaced) replaced = false; else { abort = false; hit_index = 0; hit = funarg; for (var i = stat_index; !abort && i < statements.length; i++) { statements[i].transform(multi_replacer); } value_def.single_use = false; } } if (replaced && !remove_candidate(candidate)) statements.splice(stat_index, 1); } } function handle_custom_scan_order(node) { // Skip (non-executed) functions if (node instanceof AST_Scope) return node; // Scan case expressions first in a switch statement if (node instanceof AST_Switch) { node.expression = node.expression.transform(scanner); for (var i = 0, len = node.body.length; !abort && i < len; i++) { var branch = node.body[i]; if (branch instanceof AST_Case) { if (!hit) { if (branch !== hit_stack[hit_index]) continue; hit_index++; } branch.expression = branch.expression.transform(scanner); if (!replace_all) break; } } abort = true; return node; } } function has_overlapping_symbol(fn, arg, fn_strict) { var found = false, scan_this = !(fn instanceof AST_Arrow); arg.walk(new TreeWalker(function(node, descend) { if (found) return true; if (node instanceof AST_SymbolRef && fn.variables.has(node.name)) { var s = node.definition().scope; if (s !== scope) while (s = s.parent_scope) { if (s === scope) return true; } return found = true; } if ((fn_strict || scan_this) && node instanceof AST_This) { return found = true; } if (node instanceof AST_Scope && !(node instanceof AST_Arrow)) { var prev = scan_this; scan_this = false; descend(); scan_this = prev; return true; } })); return found; } function extract_args() { var iife, fn = compressor.self(); if (is_func_expr(fn) && !fn.name && !fn.uses_arguments && !fn.pinned() && (iife = compressor.parent()) instanceof AST_Call && iife.expression === fn && iife.args.every((arg) => !(arg instanceof AST_Expansion) )) { var fn_strict = compressor.has_directive("use strict"); if (fn_strict && !member(fn_strict, fn.body)) fn_strict = false; var len = fn.argnames.length; args = iife.args.slice(len); var names = new Set(); for (var i = len; --i >= 0;) { var sym = fn.argnames[i]; var arg = iife.args[i]; args.unshift(make_node(AST_VarDef, sym, { name: sym, value: arg })); if (names.has(sym.name)) continue; names.add(sym.name); if (sym instanceof AST_Expansion) { var elements = iife.args.slice(i); if (elements.every((arg) => !has_overlapping_symbol(fn, arg, fn_strict) )) { candidates.unshift([ make_node(AST_VarDef, sym, { name: sym.expression, value: make_node(AST_Array, iife, { elements: elements }) }) ]); } } else { if (!arg) { arg = make_node(AST_Undefined, sym).transform(compressor); } else if (arg instanceof AST_Lambda && arg.pinned() || has_overlapping_symbol(fn, arg, fn_strict)) { arg = null; } if (arg) candidates.unshift([ make_node(AST_VarDef, sym, { name: sym, value: arg }) ]); } } } } function extract_candidates(expr) { hit_stack.push(expr); if (expr instanceof AST_Assign) { if (!expr.left.has_side_effects(compressor)) { candidates.push(hit_stack.slice()); } extract_candidates(expr.right); } else if (expr instanceof AST_Binary) { extract_candidates(expr.left); extract_candidates(expr.right); } else if (expr instanceof AST_Call) { extract_candidates(expr.expression); expr.args.forEach(extract_candidates); } else if (expr instanceof AST_Case) { extract_candidates(expr.expression); } else if (expr instanceof AST_Conditional) { extract_candidates(expr.condition); extract_candidates(expr.consequent); extract_candidates(expr.alternative); } else if (expr instanceof AST_Definitions && (compressor.option("unused") || !(expr instanceof AST_Const))) { var len = expr.definitions.length; // limit number of trailing variable definitions for consideration var i = len - 200; if (i < 0) i = 0; for (; i < len; i++) { extract_candidates(expr.definitions[i]); } } else if (expr instanceof AST_DWLoop) { extract_candidates(expr.condition); if (!(expr.body instanceof AST_Block)) { extract_candidates(expr.body); } } else if (expr instanceof AST_Exit) { if (expr.value) extract_candidates(expr.value); } else if (expr instanceof AST_For) { if (expr.init) extract_candidates(expr.init); if (expr.condition) extract_candidates(expr.condition); if (expr.step) extract_candidates(expr.step); if (!(expr.body instanceof AST_Block)) { extract_candidates(expr.body); } } else if (expr instanceof AST_ForIn) { extract_candidates(expr.object); if (!(expr.body instanceof AST_Block)) { extract_candidates(expr.body); } } else if (expr instanceof AST_If) { extract_candidates(expr.condition); if (!(expr.body instanceof AST_Block)) { extract_candidates(expr.body); } if (expr.alternative && !(expr.alternative instanceof AST_Block)) { extract_candidates(expr.alternative); } } else if (expr instanceof AST_Sequence) { expr.expressions.forEach(extract_candidates); } else if (expr instanceof AST_SimpleStatement) { extract_candidates(expr.body); } else if (expr instanceof AST_Switch) { extract_candidates(expr.expression); expr.body.forEach(extract_candidates); } else if (expr instanceof AST_Unary) { if (expr.operator == "++" || expr.operator == "--") { candidates.push(hit_stack.slice()); } } else if (expr instanceof AST_VarDef) { if (expr.value) { candidates.push(hit_stack.slice()); extract_candidates(expr.value); } } hit_stack.pop(); } function find_stop(node, level, write_only) { var parent = scanner.parent(level); if (parent instanceof AST_Assign) { if (write_only && !(parent.left instanceof AST_PropAccess || lvalues.has(parent.left.name))) { return find_stop(parent, level + 1, write_only); } return node; } if (parent instanceof AST_Binary) { if (write_only && (!lazy_op.has(parent.operator) || parent.left === node)) { return find_stop(parent, level + 1, write_only); } return node; } if (parent instanceof AST_Call) return node; if (parent instanceof AST_Case) return node; if (parent instanceof AST_Conditional) { if (write_only && parent.condition === node) { return find_stop(parent, level + 1, write_only); } return node; } if (parent instanceof AST_Definitions) { return find_stop(parent, level + 1, true); } if (parent instanceof AST_Exit) { return write_only ? find_stop(parent, level + 1, write_only) : node; } if (parent instanceof AST_If) { if (write_only && parent.condition === node) { return find_stop(parent, level + 1, write_only); } return node; } if (parent instanceof AST_IterationStatement) return node; if (parent instanceof AST_Sequence) { return find_stop(parent, level + 1, parent.tail_node() !== node); } if (parent instanceof AST_SimpleStatement) { return find_stop(parent, level + 1, true); } if (parent instanceof AST_Switch) return node; if (parent instanceof AST_VarDef) return node; return null; } function mangleable_var(var_def) { var value = var_def.value; if (!(value instanceof AST_SymbolRef)) return; if (value.name == "arguments") return; var def = value.definition(); if (def.undeclared) return; return value_def = def; } function get_lhs(expr) { if (expr instanceof AST_VarDef && expr.name instanceof AST_SymbolDeclaration) { var def = expr.name.definition(); if (!member(expr.name, def.orig)) return; var referenced = def.references.length - def.replaced; if (!referenced) return; var declared = def.orig.length - def.eliminated; if (declared > 1 && !(expr.name instanceof AST_SymbolFunarg) || (referenced > 1 ? mangleable_var(expr) : !compressor.exposed(def))) { return make_node(AST_SymbolRef, expr.name, expr.name); } } else { var lhs = expr[expr instanceof AST_Assign ? "left" : "expression"]; return !is_ref_of(lhs, AST_SymbolConst) && lhs; } } function get_rvalue(expr) { return expr[expr instanceof AST_Assign ? "right" : "value"]; } function get_lvalues(expr) { var lvalues = new Map(); if (expr instanceof AST_Unary) return lvalues; var tw = new TreeWalker(function(node, descend) { var sym = node; while (sym instanceof AST_PropAccess) sym = sym.expression; if (sym instanceof AST_SymbolRef || sym instanceof AST_This) { lvalues.set(sym.name, lvalues.get(sym.name) || is_modified(compressor, tw, node, node, 0)); } }); get_rvalue(expr).walk(tw); return lvalues; } function remove_candidate(expr) { if (expr.name instanceof AST_SymbolFunarg) { var iife = compressor.parent(), argnames = compressor.self().argnames; var index = argnames.indexOf(expr.name); if (index < 0) { iife.args.length = Math.min(iife.args.length, argnames.length - 1); } else { var args = iife.args; if (args[index]) args[index] = make_node(AST_Number, args[index], { value: 0 }); } return true; } var found = false; return statements[stat_index].transform(new TreeTransformer(function(node, descend, in_list) { if (found) return node; if (node === expr || node.body === expr) { found = true; if (node instanceof AST_VarDef) { node.value = null; return node; } return in_list ? MAP.skip : null; } }, function(node) { if (node instanceof AST_Sequence) switch (node.expressions.length) { case 0: return null; case 1: return node.expressions[0]; } })); } function is_lhs_local(lhs) { while (lhs instanceof AST_PropAccess) lhs = lhs.expression; return lhs instanceof AST_SymbolRef && lhs.definition().scope === scope && !(in_loop && (lvalues.has(lhs.name) || candidate instanceof AST_Unary || candidate instanceof AST_Assign && candidate.operator != "=")); } function value_has_side_effects(expr) { if (expr instanceof AST_Unary) return false; return get_rvalue(expr).has_side_effects(compressor); } function replace_all_symbols() { if (side_effects) return false; if (value_def) return true; if (lhs instanceof AST_SymbolRef) { var def = lhs.definition(); if (def.references.length - def.replaced == (candidate instanceof AST_VarDef ? 1 : 2)) { return true; } } return false; } function may_modify(sym) { if (!sym.definition) return true; // AST_Destructuring var def = sym.definition(); if (def.orig.length == 1 && def.orig[0] instanceof AST_SymbolDefun) return false; if (def.scope.get_defun_scope() !== scope) return true; return !def.references.every((ref) => { var s = ref.scope.get_defun_scope(); // "block" scope within AST_Catch if (s.TYPE == "Scope") s = s.parent_scope; return s === scope; }); } function side_effects_external(node, lhs) { if (node instanceof AST_Assign) return side_effects_external(node.left, true); if (node instanceof AST_Unary) return side_effects_external(node.expression, true); if (node instanceof AST_VarDef) return node.value && side_effects_external(node.value); if (lhs) { if (node instanceof AST_Dot) return side_effects_external(node.expression, true); if (node instanceof AST_Sub) return side_effects_external(node.expression, true); if (node instanceof AST_SymbolRef) return node.definition().scope !== scope; } return false; } } function eliminate_spurious_blocks(statements) { var seen_dirs = []; for (var i = 0; i < statements.length;) { var stat = statements[i]; if (stat instanceof AST_BlockStatement && stat.body.every(can_be_evicted_from_block)) { CHANGED = true; eliminate_spurious_blocks(stat.body); [].splice.apply(statements, [i, 1].concat(stat.body)); i += stat.body.length; } else if (stat instanceof AST_EmptyStatement) { CHANGED = true; statements.splice(i, 1); } else if (stat instanceof AST_Directive) { if (seen_dirs.indexOf(stat.value) < 0) { i++; seen_dirs.push(stat.value); } else { CHANGED = true; statements.splice(i, 1); } } else i++; } } function handle_if_return(statements, compressor) { var self = compressor.self(); var multiple_if_returns = has_multiple_if_returns(statements); var in_lambda = self instanceof AST_Lambda; for (var i = statements.length; --i >= 0;) { var stat = statements[i]; var j = next_index(i); var next = statements[j]; if (in_lambda && !next && stat instanceof AST_Return) { if (!stat.value) { CHANGED = true; statements.splice(i, 1); continue; } if (stat.value instanceof AST_UnaryPrefix && stat.value.operator == "void") { CHANGED = true; statements[i] = make_node(AST_SimpleStatement, stat, { body: stat.value.expression }); continue; } } if (stat instanceof AST_If) { var ab = aborts(stat.body); if (can_merge_flow(ab)) { if (ab.label) { remove(ab.label.thedef.references, ab); } CHANGED = true; stat = stat.clone(); stat.condition = stat.condition.negate(compressor); var body = as_statement_array_with_return(stat.body, ab); stat.body = make_node(AST_BlockStatement, stat, { body: as_statement_array(stat.alternative).concat(extract_functions()) }); stat.alternative = make_node(AST_BlockStatement, stat, { body: body }); statements[i] = stat.transform(compressor); continue; } var ab = aborts(stat.alternative); if (can_merge_flow(ab)) { if (ab.label) { remove(ab.label.thedef.references, ab); } CHANGED = true; stat = stat.clone(); stat.body = make_node(AST_BlockStatement, stat.body, { body: as_statement_array(stat.body).concat(extract_functions()) }); var body = as_statement_array_with_return(stat.alternative, ab); stat.alternative = make_node(AST_BlockStatement, stat.alternative, { body: body }); statements[i] = stat.transform(compressor); continue; } } if (stat instanceof AST_If && stat.body instanceof AST_Return) { var value = stat.body.value; //--- // pretty silly case, but: // if (foo()) return; return; ==> foo(); return; if (!value && !stat.alternative && (in_lambda && !next || next instanceof AST_Return && !next.value)) { CHANGED = true; statements[i] = make_node(AST_SimpleStatement, stat.condition, { body: stat.condition }); continue; } //--- // if (foo()) return x; return y; ==> return foo() ? x : y; if (value && !stat.alternative && next instanceof AST_Return && next.value) { CHANGED = true; stat = stat.clone(); stat.alternative = next; statements[i] = stat.transform(compressor); statements.splice(j, 1); continue; } //--- // if (foo()) return x; [ return ; ] ==> return foo() ? x : undefined; if (value && !stat.alternative && (!next && in_lambda && multiple_if_returns || next instanceof AST_Return)) { CHANGED = true; stat = stat.clone(); stat.alternative = next || make_node(AST_Return, stat, { value: null }); statements[i] = stat.transform(compressor); if (next) statements.splice(j, 1); continue; } //--- // if (a) return b; if (c) return d; e; ==> return a ? b : c ? d : void e; // // if sequences is not enabled, this can lead to an endless loop (issue #866). // however, with sequences on this helps producing slightly better output for // the example code. var prev = statements[prev_index(i)]; if (compressor.option("sequences") && in_lambda && !stat.alternative && prev instanceof AST_If && prev.body instanceof AST_Return && next_index(j) == statements.length && next instanceof AST_SimpleStatement) { CHANGED = true; stat = stat.clone(); stat.alternative = make_node(AST_BlockStatement, next, { body: [ next, make_node(AST_Return, next, { value: null }) ] }); statements[i] = stat.transform(compressor); statements.splice(j, 1); continue; } } } function has_multiple_if_returns(statements) { var n = 0; for (var i = statements.length; --i >= 0;) { var stat = statements[i]; if (stat instanceof AST_If && stat.body instanceof AST_Return) { if (++n > 1) return true; } } return false; } function is_return_void(value) { return !value || value instanceof AST_UnaryPrefix && value.operator == "void"; } function can_merge_flow(ab) { if (!ab) return false; for (var j = i + 1, len = statements.length; j < len; j++) { var stat = statements[j]; if (stat instanceof AST_Const || stat instanceof AST_Let) return false; } var lct = ab instanceof AST_LoopControl ? compressor.loopcontrol_target(ab) : null; return ab instanceof AST_Return && in_lambda && is_return_void(ab.value) || ab instanceof AST_Continue && self === loop_body(lct) || ab instanceof AST_Break && lct instanceof AST_BlockStatement && self === lct; } function extract_functions() { var tail = statements.slice(i + 1); statements.length = i + 1; return tail.filter(function(stat) { if (stat instanceof AST_Defun) { statements.push(stat); return false; } return true; }); } function as_statement_array_with_return(node, ab) { var body = as_statement_array(node).slice(0, -1); if (ab.value) { body.push(make_node(AST_SimpleStatement, ab.value, { body: ab.value.expression })); } return body; } function next_index(i) { for (var j = i + 1, len = statements.length; j < len; j++) { var stat = statements[j]; if (!(stat instanceof AST_Var && declarations_only(stat))) { break; } } return j; } function prev_index(i) { for (var j = i; --j >= 0;) { var stat = statements[j]; if (!(stat instanceof AST_Var && declarations_only(stat))) { break; } } return j; } } function eliminate_dead_code(statements, compressor) { var has_quit; var self = compressor.self(); for (var i = 0, n = 0, len = statements.length; i < len; i++) { var stat = statements[i]; if (stat instanceof AST_LoopControl) { var lct = compressor.loopcontrol_target(stat); if (stat instanceof AST_Break && !(lct instanceof AST_IterationStatement) && loop_body(lct) === self || stat instanceof AST_Continue && loop_body(lct) === self) { if (stat.label) { remove(stat.label.thedef.references, stat); } } else { statements[n++] = stat; } } else { statements[n++] = stat; } if (aborts(stat)) { has_quit = statements.slice(i + 1); break; } } statements.length = n; CHANGED = n != len; if (has_quit) has_quit.forEach(function(stat) { extract_declarations_from_unreachable_code(compressor, stat, statements); }); } function declarations_only(node) { return node.definitions.every((var_def) => !var_def.value ); } function sequencesize(statements, compressor) { if (statements.length < 2) return; var seq = [], n = 0; function push_seq() { if (!seq.length) return; var body = make_sequence(seq[0], seq); statements[n++] = make_node(AST_SimpleStatement, body, { body: body }); seq = []; } for (var i = 0, len = statements.length; i < len; i++) { var stat = statements[i]; if (stat instanceof AST_SimpleStatement) { if (seq.length >= compressor.sequences_limit) push_seq(); var body = stat.body; if (seq.length > 0) body = body.drop_side_effect_free(compressor); if (body) merge_sequence(seq, body); } else if (stat instanceof AST_Definitions && declarations_only(stat) || stat instanceof AST_Defun) { statements[n++] = stat; } else { push_seq(); statements[n++] = stat; } } push_seq(); statements.length = n; if (n != len) CHANGED = true; } function to_simple_statement(block, decls) { if (!(block instanceof AST_BlockStatement)) return block; var stat = null; for (var i = 0, len = block.body.length; i < len; i++) { var line = block.body[i]; if (line instanceof AST_Var && declarations_only(line)) { decls.push(line); } else if (stat) { return false; } else { stat = line; } } return stat; } function sequencesize_2(statements, compressor) { function cons_seq(right) { n--; CHANGED = true; var left = prev.body; return make_sequence(left, [ left, right ]).transform(compressor); } var n = 0, prev; for (var i = 0; i < statements.length; i++) { var stat = statements[i]; if (prev) { if (stat instanceof AST_Exit) { stat.value = cons_seq(stat.value || make_node(AST_Undefined, stat).transform(compressor)); } else if (stat instanceof AST_For) { if (!(stat.init instanceof AST_Definitions)) { var abort = false; prev.body.walk(new TreeWalker(function(node) { if (abort || node instanceof AST_Scope) return true; if (node instanceof AST_Binary && node.operator == "in") { abort = true; return true; } })); if (!abort) { if (stat.init) stat.init = cons_seq(stat.init); else { stat.init = prev.body; n--; CHANGED = true; } } } } else if (stat instanceof AST_ForIn) { if (!(stat.init instanceof AST_Const) && !(stat.init instanceof AST_Let)) { stat.object = cons_seq(stat.object); } } else if (stat instanceof AST_If) { stat.condition = cons_seq(stat.condition); } else if (stat instanceof AST_Switch) { stat.expression = cons_seq(stat.expression); } else if (stat instanceof AST_With) { stat.expression = cons_seq(stat.expression); } } if (compressor.option("conditionals") && stat instanceof AST_If) { var decls = []; var body = to_simple_statement(stat.body, decls); var alt = to_simple_statement(stat.alternative, decls); if (body !== false && alt !== false && decls.length > 0) { var len = decls.length; decls.push(make_node(AST_If, stat, { condition: stat.condition, body: body || make_node(AST_EmptyStatement, stat.body), alternative: alt })); decls.unshift(n, 1); [].splice.apply(statements, decls); i += len; n += len + 1; prev = null; CHANGED = true; continue; } } statements[n++] = stat; prev = stat instanceof AST_SimpleStatement ? stat : null; } statements.length = n; } function join_object_assignments(defn, body) { if (!(defn instanceof AST_Definitions)) return; var def = defn.definitions[defn.definitions.length - 1]; if (!(def.value instanceof AST_Object)) return; var exprs; if (body instanceof AST_Assign) { exprs = [ body ]; } else if (body instanceof AST_Sequence) { exprs = body.expressions.slice(); } if (!exprs) return; var trimmed = false; do { var node = exprs[0]; if (!(node instanceof AST_Assign)) break; if (node.operator != "=") break; if (!(node.left instanceof AST_PropAccess)) break; var sym = node.left.expression; if (!(sym instanceof AST_SymbolRef)) break; if (def.name.name != sym.name) break; if (!node.right.is_constant_expression(scope)) break; var prop = node.left.property; if (prop instanceof AST_Node) { prop = prop.evaluate(compressor); } if (prop instanceof AST_Node) break; prop = "" + prop; var diff = compressor.option("ecma") < 6 && compressor.has_directive("use strict") ? function(node) { return node.key != prop && (node.key && node.key.name != prop); } : function(node) { return node.key && node.key.name != prop; }; if (!def.value.properties.every(diff)) break; var p = def.value.properties.filter(function (p) { return p.key === prop; })[0]; if (!p) { def.value.properties.push(make_node(AST_ObjectKeyVal, node, { key: prop, value: node.right })); } else { p.value = new AST_Sequence({ start: p.start, expressions: [p.value.clone(), node.right.clone()], end: p.end }); } exprs.shift(); trimmed = true; } while (exprs.length); return trimmed && exprs; } function join_consecutive_vars(statements) { var defs; for (var i = 0, j = -1, len = statements.length; i < len; i++) { var stat = statements[i]; var prev = statements[j]; if (stat instanceof AST_Definitions) { if (prev && prev.TYPE == stat.TYPE) { prev.definitions = prev.definitions.concat(stat.definitions); CHANGED = true; } else if (defs && defs.TYPE == stat.TYPE && declarations_only(stat)) { defs.definitions = defs.definitions.concat(stat.definitions); CHANGED = true; } else { statements[++j] = stat; defs = stat; } } else if (stat instanceof AST_Exit) { stat.value = extract_object_assignments(stat.value); } else if (stat instanceof AST_For) { var exprs = join_object_assignments(prev, stat.init); if (exprs) { CHANGED = true; stat.init = exprs.length ? make_sequence(stat.init, exprs) : null; statements[++j] = stat; } else if (prev instanceof AST_Var && (!stat.init || stat.init.TYPE == prev.TYPE)) { if (stat.init) { prev.definitions = prev.definitions.concat(stat.init.definitions); } stat.init = prev; statements[j] = stat; CHANGED = true; } else if (defs && stat.init && defs.TYPE == stat.init.TYPE && declarations_only(stat.init)) { defs.definitions = defs.definitions.concat(stat.init.definitions); stat.init = null; statements[++j] = stat; CHANGED = true; } else { statements[++j] = stat; } } else if (stat instanceof AST_ForIn) { stat.object = extract_object_assignments(stat.object); } else if (stat instanceof AST_If) { stat.condition = extract_object_assignments(stat.condition); } else if (stat instanceof AST_SimpleStatement) { var exprs = join_object_assignments(prev, stat.body); if (exprs) { CHANGED = true; if (!exprs.length) continue; stat.body = make_sequence(stat.body, exprs); } statements[++j] = stat; } else if (stat instanceof AST_Switch) { stat.expression = extract_object_assignments(stat.expression); } else if (stat instanceof AST_With) { stat.expression = extract_object_assignments(stat.expression); } else { statements[++j] = stat; } } statements.length = j + 1; function extract_object_assignments(value) { statements[++j] = stat; var exprs = join_object_assignments(prev, value); if (exprs) { CHANGED = true; if (exprs.length) { return make_sequence(value, exprs); } else if (value instanceof AST_Sequence) { return value.tail_node().left; } else { return value.left; } } return value; } } } function extract_declarations_from_unreachable_code(compressor, stat, target) { if (!(stat instanceof AST_Defun)) { compressor.warn("Dropping unreachable code [{file}:{line},{col}]", stat.start); } stat.walk(new TreeWalker(function(node) { if (node instanceof AST_Var) { compressor.warn("Declarations in unreachable code! [{file}:{line},{col}]", node.start); node.remove_initializers(); target.push(node); return true; } if (node instanceof AST_Defun && (node === stat || !compressor.has_directive("use strict"))) { target.push(node === stat ? node : make_node(AST_Var, node, { definitions: [ make_node(AST_VarDef, node, { name: make_node(AST_SymbolVar, node.name, node.name), value: null }) ] })); return true; } if (node instanceof AST_Scope) { return true; } })); } function get_value(key) { if (key instanceof AST_Constant) { return key.getValue(); } if (key instanceof AST_UnaryPrefix && key.operator == "void" && key.expression instanceof AST_Constant) { return; } return key; } function is_undefined(node, compressor) { return node.is_undefined || node instanceof AST_Undefined || node instanceof AST_UnaryPrefix && node.operator == "void" && !node.expression.has_side_effects(compressor); } // may_throw_on_access() // returns true if this node may be null, undefined or contain `AST_Accessor` (function(def_may_throw_on_access) { AST_Node.DEFMETHOD("may_throw_on_access", function(compressor) { return !compressor.option("pure_getters") || this._dot_throw(compressor); }); function is_strict(compressor) { return /strict/.test(compressor.option("pure_getters")); } def_may_throw_on_access(AST_Node, is_strict); def_may_throw_on_access(AST_Null, return_true); def_may_throw_on_access(AST_Undefined, return_true); def_may_throw_on_access(AST_Constant, return_false); def_may_throw_on_access(AST_Array, return_false); def_may_throw_on_access(AST_Object, function(compressor) { if (!is_strict(compressor)) return false; for (var i = this.properties.length; --i >=0;) if (this.properties[i]._dot_throw(compressor)) return true; return false; }); def_may_throw_on_access(AST_ObjectProperty, return_false); def_may_throw_on_access(AST_ObjectGetter, return_true); def_may_throw_on_access(AST_Expansion, function(compressor) { return this.expression._dot_throw(compressor); }); def_may_throw_on_access(AST_Function, return_false); def_may_throw_on_access(AST_Arrow, return_false); def_may_throw_on_access(AST_UnaryPostfix, return_false); def_may_throw_on_access(AST_UnaryPrefix, function() { return this.operator == "void"; }); def_may_throw_on_access(AST_Binary, function(compressor) { return (this.operator == "&&" || this.operator == "||") && (this.left._dot_throw(compressor) || this.right._dot_throw(compressor)); }); def_may_throw_on_access(AST_Assign, function(compressor) { return this.operator == "=" && this.right._dot_throw(compressor); }); def_may_throw_on_access(AST_Conditional, function(compressor) { return this.consequent._dot_throw(compressor) || this.alternative._dot_throw(compressor); }); def_may_throw_on_access(AST_Dot, function(compressor) { if (!is_strict(compressor)) return false; if (this.expression instanceof AST_Function && this.property == "prototype") return false; return true; }); def_may_throw_on_access(AST_Sequence, function(compressor) { return this.tail_node()._dot_throw(compressor); }); def_may_throw_on_access(AST_SymbolRef, function(compressor) { if (this.is_undefined) return true; if (!is_strict(compressor)) return false; if (is_undeclared_ref(this) && this.is_declared(compressor)) return false; if (this.is_immutable()) return false; var fixed = this.fixed_value(); return !fixed || fixed._dot_throw(compressor); }); })(function(node, func) { node.DEFMETHOD("_dot_throw", func); }); /* -----[ boolean/negation helpers ]----- */ // methods to determine whether an expression has a boolean result type (function(def_is_boolean) { const unary_bool = makePredicate("! delete"); const binary_bool = makePredicate("in instanceof == != === !== < <= >= >"); def_is_boolean(AST_Node, return_false); def_is_boolean(AST_UnaryPrefix, function() { return unary_bool.has(this.operator); }); def_is_boolean(AST_Binary, function() { return binary_bool.has(this.operator) || lazy_op.has(this.operator) && this.left.is_boolean() && this.right.is_boolean(); }); def_is_boolean(AST_Conditional, function() { return this.consequent.is_boolean() && this.alternative.is_boolean(); }); def_is_boolean(AST_Assign, function() { return this.operator == "=" && this.right.is_boolean(); }); def_is_boolean(AST_Sequence, function() { return this.tail_node().is_boolean(); }); def_is_boolean(AST_True, return_true); def_is_boolean(AST_False, return_true); })(function(node, func) { node.DEFMETHOD("is_boolean", func); }); // methods to determine if an expression has a numeric result type (function(def_is_number) { def_is_number(AST_Node, return_false); def_is_number(AST_Number, return_true); var unary = makePredicate("+ - ~ ++ --"); def_is_number(AST_Unary, function() { return unary.has(this.operator); }); var binary = makePredicate("- * / % & | ^ << >> >>>"); def_is_number(AST_Binary, function(compressor) { return binary.has(this.operator) || this.operator == "+" && this.left.is_number(compressor) && this.right.is_number(compressor); }); def_is_number(AST_Assign, function(compressor) { return binary.has(this.operator.slice(0, -1)) || this.operator == "=" && this.right.is_number(compressor); }); def_is_number(AST_Sequence, function(compressor) { return this.tail_node().is_number(compressor); }); def_is_number(AST_Conditional, function(compressor) { return this.consequent.is_number(compressor) && this.alternative.is_number(compressor); }); })(function(node, func) { node.DEFMETHOD("is_number", func); }); // methods to determine if an expression has a string result type (function(def_is_string) { def_is_string(AST_Node, return_false); def_is_string(AST_String, return_true); def_is_string(AST_TemplateString, function() { return this.segments.length === 1; }); def_is_string(AST_UnaryPrefix, function() { return this.operator == "typeof"; }); def_is_string(AST_Binary, function(compressor) { return this.operator == "+" && (this.left.is_string(compressor) || this.right.is_string(compressor)); }); def_is_string(AST_Assign, function(compressor) { return (this.operator == "=" || this.operator == "+=") && this.right.is_string(compressor); }); def_is_string(AST_Sequence, function(compressor) { return this.tail_node().is_string(compressor); }); def_is_string(AST_Conditional, function(compressor) { return this.consequent.is_string(compressor) && this.alternative.is_string(compressor); }); })(function(node, func) { node.DEFMETHOD("is_string", func); }); var lazy_op = makePredicate("&& ||"); var unary_side_effects = makePredicate("delete ++ --"); function is_lhs(node, parent) { if (parent instanceof AST_Unary && unary_side_effects.has(parent.operator)) return parent.expression; if (parent instanceof AST_Assign && parent.left === node) return node; } (function(def_find_defs) { function to_node(value, orig) { if (value instanceof AST_Node) return make_node(value.CTOR, orig, value); if (Array.isArray(value)) return make_node(AST_Array, orig, { elements: value.map(function(value) { return to_node(value, orig); }) }); if (value && typeof value == "object") { var props = []; for (var key in value) if (HOP(value, key)) { props.push(make_node(AST_ObjectKeyVal, orig, { key: key, value: to_node(value[key], orig) })); } return make_node(AST_Object, orig, { properties: props }); } return make_node_from_constant(value, orig); } function warn(compressor, node) { compressor.warn("global_defs " + node.print_to_string() + " redefined [{file}:{line},{col}]", node.start); } AST_Toplevel.DEFMETHOD("resolve_defines", function(compressor) { if (!compressor.option("global_defs")) return this; this.figure_out_scope({ ie8: compressor.option("ie8") }); return this.transform(new TreeTransformer(function(node) { var def = node._find_defs(compressor, ""); if (!def) return; var level = 0, child = node, parent; while (parent = this.parent(level++)) { if (!(parent instanceof AST_PropAccess)) break; if (parent.expression !== child) break; child = parent; } if (is_lhs(child, parent)) { warn(compressor, node); return; } return def; })); }); def_find_defs(AST_Node, noop); def_find_defs(AST_Dot, function(compressor, suffix) { return this.expression._find_defs(compressor, "." + this.property + suffix); }); def_find_defs(AST_SymbolDeclaration, function(compressor) { if (!this.global()) return; if (HOP(compressor.option("global_defs"), this.name)) warn(compressor, this); }); def_find_defs(AST_SymbolRef, function(compressor, suffix) { if (!this.global()) return; var defines = compressor.option("global_defs"); var name = this.name + suffix; if (HOP(defines, name)) return to_node(defines[name], this); }); })(function(node, func) { node.DEFMETHOD("_find_defs", func); }); function best_of_expression(ast1, ast2) { return ast1.print_to_string().length > ast2.print_to_string().length ? ast2 : ast1; } function best_of_statement(ast1, ast2) { return best_of_expression(make_node(AST_SimpleStatement, ast1, { body: ast1 }), make_node(AST_SimpleStatement, ast2, { body: ast2 })).body; } function best_of(compressor, ast1, ast2) { return (first_in_statement(compressor) ? best_of_statement : best_of_expression)(ast1, ast2); } function convert_to_predicate(obj) { for (var key of Object.keys(obj)) { obj[key] = makePredicate(obj[key]); } } var object_fns = [ "constructor", "toString", "valueOf", ]; var native_fns = { Array: [ "indexOf", "join", "lastIndexOf", "slice", ].concat(object_fns), Boolean: object_fns, Function: object_fns, Number: [ "toExponential", "toFixed", "toPrecision", ].concat(object_fns), Object: object_fns, RegExp: [ "test", ].concat(object_fns), String: [ "charAt", "charCodeAt", "concat", "indexOf", "italics", "lastIndexOf", "match", "replace", "search", "slice", "split", "substr", "substring", "toLowerCase", "toUpperCase", "trim", ].concat(object_fns), }; convert_to_predicate(native_fns); var static_fns = { Array: [ "isArray", ], Math: [ "abs", "acos", "asin", "atan", "ceil", "cos", "exp", "floor", "log", "round", "sin", "sqrt", "tan", "atan2", "pow", "max", "min", ], Number: [ "isFinite", "isNaN", ], Object: [ "create", "getOwnPropertyDescriptor", "getOwnPropertyNames", "getPrototypeOf", "isExtensible", "isFrozen", "isSealed", "keys", ], String: [ "fromCharCode", ], }; convert_to_predicate(static_fns); // methods to evaluate a constant expression (function(def_eval) { // If the node has been successfully reduced to a constant, // then its value is returned; otherwise the element itself // is returned. // They can be distinguished as constant value is never a // descendant of AST_Node. AST_Node.DEFMETHOD("evaluate", function(compressor) { if (!compressor.option("evaluate")) return this; var val = this._eval(compressor, 1); if (!val || val instanceof RegExp) return val; if (typeof val == "function" || typeof val == "object") return this; return val; }); var unaryPrefix = makePredicate("! ~ - + void"); AST_Node.DEFMETHOD("is_constant", function() { // Accomodate when compress option evaluate=false // as well as the common constant expressions !0 and -1 if (this instanceof AST_Constant) { return !(this instanceof AST_RegExp); } else { return this instanceof AST_UnaryPrefix && this.expression instanceof AST_Constant && unaryPrefix.has(this.operator); } }); def_eval(AST_Statement, function() { throw new Error(string_template("Cannot evaluate a statement [{file}:{line},{col}]", this.start)); }); def_eval(AST_Lambda, return_this); def_eval(AST_Class, return_this); def_eval(AST_Node, return_this); def_eval(AST_Constant, function() { return this.getValue(); }); def_eval(AST_TemplateString, function() { if (this.segments.length !== 1) return this; return this.segments[0].value; }); def_eval(AST_Function, function(compressor) { if (compressor.option("unsafe")) { var fn = function() {}; fn.node = this; fn.toString = function() { return this.node.print_to_string(); }; return fn; } return this; }); def_eval(AST_Array, function(compressor, depth) { if (compressor.option("unsafe")) { var elements = []; for (var i = 0, len = this.elements.length; i < len; i++) { var element = this.elements[i]; var value = element._eval(compressor, depth); if (element === value) return this; elements.push(value); } return elements; } return this; }); def_eval(AST_Object, function(compressor, depth) { if (compressor.option("unsafe")) { var val = {}; for (var i = 0, len = this.properties.length; i < len; i++) { var prop = this.properties[i]; if (prop instanceof AST_Expansion) return this; var key = prop.key; if (key instanceof AST_Symbol) { key = key.name; } else if (key instanceof AST_Node) { key = key._eval(compressor, depth); if (key === prop.key) return this; } if (typeof Object.prototype[key] === "function") { return this; } if (prop.value instanceof AST_Function) continue; val[key] = prop.value._eval(compressor, depth); if (val[key] === prop.value) return this; } return val; } return this; }); var non_converting_unary = makePredicate("! typeof void"); def_eval(AST_UnaryPrefix, function(compressor, depth) { var e = this.expression; // Function would be evaluated to an array and so typeof would // incorrectly return 'object'. Hence making is a special case. if (compressor.option("typeofs") && this.operator == "typeof" && (e instanceof AST_Lambda || e instanceof AST_SymbolRef && e.fixed_value() instanceof AST_Lambda)) { return typeof function() {}; } if (!non_converting_unary.has(this.operator)) depth++; e = e._eval(compressor, depth); if (e === this.expression) return this; switch (this.operator) { case "!": return !e; case "typeof": // typeof returns "object" or "function" on different platforms // so cannot evaluate reliably if (e instanceof RegExp) return this; return typeof e; case "void": return void e; case "~": return ~e; case "-": return -e; case "+": return +e; } return this; }); var non_converting_binary = makePredicate("&& || === !=="); def_eval(AST_Binary, function(compressor, depth) { if (!non_converting_binary.has(this.operator)) depth++; var left = this.left._eval(compressor, depth); if (left === this.left) return this; var right = this.right._eval(compressor, depth); if (right === this.right) return this; var result; switch (this.operator) { case "&&" : result = left && right; break; case "||" : result = left || right; break; case "|" : result = left | right; break; case "&" : result = left & right; break; case "^" : result = left ^ right; break; case "+" : result = left + right; break; case "*" : result = left * right; break; case "**" : result = Math.pow(left, right); break; case "/" : result = left / right; break; case "%" : result = left % right; break; case "-" : result = left - right; break; case "<<" : result = left << right; break; case ">>" : result = left >> right; break; case ">>>" : result = left >>> right; break; case "==" : result = left == right; break; case "===" : result = left === right; break; case "!=" : result = left != right; break; case "!==" : result = left !== right; break; case "<" : result = left < right; break; case "<=" : result = left <= right; break; case ">" : result = left > right; break; case ">=" : result = left >= right; break; default: return this; } if (isNaN(result) && compressor.find_parent(AST_With)) { // leave original expression as is return this; } return result; }); def_eval(AST_Conditional, function(compressor, depth) { var condition = this.condition._eval(compressor, depth); if (condition === this.condition) return this; var node = condition ? this.consequent : this.alternative; var value = node._eval(compressor, depth); return value === node ? this : value; }); def_eval(AST_SymbolRef, function(compressor, depth) { var fixed = this.fixed_value(); if (!fixed) return this; var value; if (HOP(fixed, "_eval")) { value = fixed._eval(); } else { this._eval = return_this; value = fixed._eval(compressor, depth); delete this._eval; if (value === fixed) return this; fixed._eval = function() { return value; }; } if (value && typeof value == "object") { var escaped = this.definition().escaped; if (escaped && depth > escaped) return this; } return value; }); var global_objs = { Array: Array, Math: Math, Number: Number, Object: Object, String: String, }; var static_values = { Math: [ "E", "LN10", "LN2", "LOG2E", "LOG10E", "PI", "SQRT1_2", "SQRT2", ], Number: [ "MAX_VALUE", "MIN_VALUE", "NaN", "NEGATIVE_INFINITY", "POSITIVE_INFINITY", ], }; convert_to_predicate(static_values); def_eval(AST_PropAccess, function(compressor, depth) { if (compressor.option("unsafe")) { var key = this.property; if (key instanceof AST_Node) { key = key._eval(compressor, depth); if (key === this.property) return this; } var exp = this.expression; var val; if (is_undeclared_ref(exp)) { var aa; var first_arg = exp.name === "hasOwnProperty" && key === "call" && (aa = compressor.parent() && compressor.parent().args) && (aa && aa[0] && aa[0].evaluate(compressor)); first_arg = first_arg instanceof AST_Dot ? first_arg.expression : first_arg; if (first_arg == null || first_arg.thedef && first_arg.thedef.undeclared) { return this.clone(); } var static_value = static_values[exp.name]; if (!static_value || !static_value.has(key)) return this; val = global_objs[exp.name]; } else { val = exp._eval(compressor, depth + 1); if (!val || val === exp || !HOP(val, key)) return this; if (typeof val == "function") switch (key) { case "name": return val.node.name ? val.node.name.name : ""; case "length": return val.node.argnames.length; default: return this; } } return val[key]; } return this; }); def_eval(AST_Call, function(compressor, depth) { var exp = this.expression; if (compressor.option("unsafe") && exp instanceof AST_PropAccess) { var key = exp.property; if (key instanceof AST_Node) { key = key._eval(compressor, depth); if (key === exp.property) return this; } var val; var e = exp.expression; if (is_undeclared_ref(e)) { var first_arg = e.name === "hasOwnProperty" && key === "call" && (this.args[0] && this.args[0].evaluate(compressor)); first_arg = first_arg instanceof AST_Dot ? first_arg.expression : first_arg; if ((first_arg == null || first_arg.thedef && first_arg.thedef.undeclared)) { return this.clone(); } var static_fn = static_fns[e.name]; if (!static_fn || !static_fn.has(key)) return this; val = global_objs[e.name]; } else { val = e._eval(compressor, depth + 1); if (val === e || !val) return this; var native_fn = native_fns[val.constructor.name]; if (!native_fn || !native_fn.has(key)) return this; } var args = []; for (var i = 0, len = this.args.length; i < len; i++) { var arg = this.args[i]; var value = arg._eval(compressor, depth); if (arg === value) return this; args.push(value); } try { return val[key].apply(val, args); } catch (ex) { compressor.warn("Error evaluating {code} [{file}:{line},{col}]", { code: this.print_to_string(), file: this.start.file, line: this.start.line, col: this.start.col }); } } return this; }); def_eval(AST_New, return_this); })(function(node, func) { node.DEFMETHOD("_eval", func); }); // method to negate an expression (function(def_negate) { function basic_negation(exp) { return make_node(AST_UnaryPrefix, exp, { operator: "!", expression: exp }); } function best(orig, alt, first_in_statement) { var negated = basic_negation(orig); if (first_in_statement) { var stat = make_node(AST_SimpleStatement, alt, { body: alt }); return best_of_expression(negated, stat) === stat ? alt : negated; } return best_of_expression(negated, alt); } def_negate(AST_Node, function() { return basic_negation(this); }); def_negate(AST_Statement, function() { throw new Error("Cannot negate a statement"); }); def_negate(AST_Function, function() { return basic_negation(this); }); def_negate(AST_Arrow, function() { return basic_negation(this); }); def_negate(AST_UnaryPrefix, function() { if (this.operator == "!") return this.expression; return basic_negation(this); }); def_negate(AST_Sequence, function(compressor) { var expressions = this.expressions.slice(); expressions.push(expressions.pop().negate(compressor)); return make_sequence(this, expressions); }); def_negate(AST_Conditional, function(compressor, first_in_statement) { var self = this.clone(); self.consequent = self.consequent.negate(compressor); self.alternative = self.alternative.negate(compressor); return best(this, self, first_in_statement); }); def_negate(AST_Binary, function(compressor, first_in_statement) { var self = this.clone(), op = this.operator; if (compressor.option("unsafe_comps")) { switch (op) { case "<=" : self.operator = ">" ; return self; case "<" : self.operator = ">=" ; return self; case ">=" : self.operator = "<" ; return self; case ">" : self.operator = "<=" ; return self; } } switch (op) { case "==" : self.operator = "!="; return self; case "!=" : self.operator = "=="; return self; case "===": self.operator = "!=="; return self; case "!==": self.operator = "==="; return self; case "&&": self.operator = "||"; self.left = self.left.negate(compressor, first_in_statement); self.right = self.right.negate(compressor); return best(this, self, first_in_statement); case "||": self.operator = "&&"; self.left = self.left.negate(compressor, first_in_statement); self.right = self.right.negate(compressor); return best(this, self, first_in_statement); } return basic_negation(this); }); })(function(node, func) { node.DEFMETHOD("negate", function(compressor, first_in_statement) { return func.call(this, compressor, first_in_statement); }); }); var global_pure_fns = makePredicate("Boolean decodeURI decodeURIComponent Date encodeURI encodeURIComponent Error escape EvalError isFinite isNaN Number Object parseFloat parseInt RangeError ReferenceError String SyntaxError TypeError unescape URIError"); AST_Call.DEFMETHOD("is_expr_pure", function(compressor) { if (compressor.option("unsafe")) { var expr = this.expression; var first_arg = (this.args && this.args[0] && this.args[0].evaluate(compressor)); if ( expr.expression && expr.expression.name === "hasOwnProperty" && (first_arg == null || first_arg.thedef && first_arg.thedef.undeclared) ) { return false; } if (is_undeclared_ref(expr) && global_pure_fns.has(expr.name)) return true; if (expr instanceof AST_Dot && is_undeclared_ref(expr.expression) && static_fns.hasOwnProperty(expr.expression.name) && static_fns[expr.expression.name].has(expr.property)) { return true; } } return this.pure || !compressor.pure_funcs(this); }); AST_Node.DEFMETHOD("is_call_pure", return_false); AST_Dot.DEFMETHOD("is_call_pure", function(compressor) { if (!compressor.option("unsafe")) return; const expr = this.expression; let map; if (expr instanceof AST_Array) { map = native_fns.Array; } else if (expr.is_boolean()) { map = native_fns.Boolean; } else if (expr.is_number(compressor)) { map = native_fns.Number; } else if (expr instanceof AST_RegExp) { map = native_fns.RegExp; } else if (expr.is_string(compressor)) { map = native_fns.String; } else if (!this.may_throw_on_access(compressor)) { map = native_fns.Object; } return map && map.has(this.property); }); // determine if expression has side effects (function(def_has_side_effects) { def_has_side_effects(AST_Node, return_true); def_has_side_effects(AST_EmptyStatement, return_false); def_has_side_effects(AST_Constant, return_false); def_has_side_effects(AST_This, return_false); function any(list, compressor) { for (var i = list.length; --i >= 0;) if (list[i].has_side_effects(compressor)) return true; return false; } def_has_side_effects(AST_Block, function(compressor) { return any(this.body, compressor); }); def_has_side_effects(AST_Call, function(compressor) { if (!this.is_expr_pure(compressor) && (!this.expression.is_call_pure(compressor) || this.expression.has_side_effects(compressor))) { return true; } return any(this.args, compressor); }); def_has_side_effects(AST_Switch, function(compressor) { return this.expression.has_side_effects(compressor) || any(this.body, compressor); }); def_has_side_effects(AST_Case, function(compressor) { return this.expression.has_side_effects(compressor) || any(this.body, compressor); }); def_has_side_effects(AST_Try, function(compressor) { return any(this.body, compressor) || this.bcatch && this.bcatch.has_side_effects(compressor) || this.bfinally && this.bfinally.has_side_effects(compressor); }); def_has_side_effects(AST_If, function(compressor) { return this.condition.has_side_effects(compressor) || this.body && this.body.has_side_effects(compressor) || this.alternative && this.alternative.has_side_effects(compressor); }); def_has_side_effects(AST_LabeledStatement, function(compressor) { return this.body.has_side_effects(compressor); }); def_has_side_effects(AST_SimpleStatement, function(compressor) { return this.body.has_side_effects(compressor); }); def_has_side_effects(AST_Lambda, return_false); def_has_side_effects(AST_Class, return_false); def_has_side_effects(AST_DefClass, return_true); def_has_side_effects(AST_Binary, function(compressor) { return this.left.has_side_effects(compressor) || this.right.has_side_effects(compressor); }); def_has_side_effects(AST_Assign, return_true); def_has_side_effects(AST_Conditional, function(compressor) { return this.condition.has_side_effects(compressor) || this.consequent.has_side_effects(compressor) || this.alternative.has_side_effects(compressor); }); def_has_side_effects(AST_Unary, function(compressor) { return unary_side_effects.has(this.operator) || this.expression.has_side_effects(compressor); }); def_has_side_effects(AST_SymbolRef, function(compressor) { return !this.is_declared(compressor); }); def_has_side_effects(AST_SymbolDeclaration, return_false); def_has_side_effects(AST_Object, function(compressor) { return any(this.properties, compressor); }); def_has_side_effects(AST_ObjectProperty, function(compressor) { if (this.key instanceof AST_ObjectKeyVal && this.key.has_side_effects(compressor)) return true; return this.value.has_side_effects(compressor); }); def_has_side_effects(AST_Array, function(compressor) { return any(this.elements, compressor); }); def_has_side_effects(AST_Dot, function(compressor) { return this.expression.may_throw_on_access(compressor) || this.expression.has_side_effects(compressor); }); def_has_side_effects(AST_Sub, function(compressor) { return this.expression.may_throw_on_access(compressor) || this.expression.has_side_effects(compressor) || this.property.has_side_effects(compressor); }); def_has_side_effects(AST_Sequence, function(compressor) { return any(this.expressions, compressor); }); def_has_side_effects(AST_Definitions, function(compressor) { return any(this.definitions, compressor); }); def_has_side_effects(AST_VarDef, function(compressor) { return this.value; }); def_has_side_effects(AST_TemplateSegment, return_false); def_has_side_effects(AST_TemplateString, function(compressor) { return any(this.segments, compressor); }); })(function(node, func) { node.DEFMETHOD("has_side_effects", func); }); // determine if expression may throw (function(def_may_throw) { def_may_throw(AST_Node, return_true); def_may_throw(AST_Class, return_false); def_may_throw(AST_Constant, return_false); def_may_throw(AST_EmptyStatement, return_false); def_may_throw(AST_Lambda, return_false); def_may_throw(AST_SymbolDeclaration, return_false); def_may_throw(AST_This, return_false); function any(list, compressor) { for (var i = list.length; --i >= 0;) if (list[i].may_throw(compressor)) return true; return false; } def_may_throw(AST_Array, function(compressor) { return any(this.elements, compressor); }); def_may_throw(AST_Assign, function(compressor) { if (this.right.may_throw(compressor)) return true; if (!compressor.has_directive("use strict") && this.operator == "=" && this.left instanceof AST_SymbolRef) { return false; } return this.left.may_throw(compressor); }); def_may_throw(AST_Binary, function(compressor) { return this.left.may_throw(compressor) || this.right.may_throw(compressor); }); def_may_throw(AST_Block, function(compressor) { return any(this.body, compressor); }); def_may_throw(AST_Call, function(compressor) { if (any(this.args, compressor)) return true; if (this.is_expr_pure(compressor)) return false; if (this.expression.may_throw(compressor)) return true; return !(this.expression instanceof AST_Lambda) || any(this.expression.body, compressor); }); def_may_throw(AST_Case, function(compressor) { return this.expression.may_throw(compressor) || any(this.body, compressor); }); def_may_throw(AST_Conditional, function(compressor) { return this.condition.may_throw(compressor) || this.consequent.may_throw(compressor) || this.alternative.may_throw(compressor); }); def_may_throw(AST_Definitions, function(compressor) { return any(this.definitions, compressor); }); def_may_throw(AST_Dot, function(compressor) { return this.expression.may_throw_on_access(compressor) || this.expression.may_throw(compressor); }); def_may_throw(AST_If, function(compressor) { return this.condition.may_throw(compressor) || this.body && this.body.may_throw(compressor) || this.alternative && this.alternative.may_throw(compressor); }); def_may_throw(AST_LabeledStatement, function(compressor) { return this.body.may_throw(compressor); }); def_may_throw(AST_Object, function(compressor) { return any(this.properties, compressor); }); def_may_throw(AST_ObjectProperty, function(compressor) { return this.value.may_throw(compressor); }); def_may_throw(AST_Return, function(compressor) { return this.value && this.value.may_throw(compressor); }); def_may_throw(AST_Sequence, function(compressor) { return any(this.expressions, compressor); }); def_may_throw(AST_SimpleStatement, function(compressor) { return this.body.may_throw(compressor); }); def_may_throw(AST_Sub, function(compressor) { return this.expression.may_throw_on_access(compressor) || this.expression.may_throw(compressor) || this.property.may_throw(compressor); }); def_may_throw(AST_Switch, function(compressor) { return this.expression.may_throw(compressor) || any(this.body, compressor); }); def_may_throw(AST_SymbolRef, function(compressor) { return !this.is_declared(compressor); }); def_may_throw(AST_Try, function(compressor) { return this.bcatch ? this.bcatch.may_throw(compressor) : any(this.body, compressor) || this.bfinally && this.bfinally.may_throw(compressor); }); def_may_throw(AST_Unary, function(compressor) { if (this.operator == "typeof" && this.expression instanceof AST_SymbolRef) return false; return this.expression.may_throw(compressor); }); def_may_throw(AST_VarDef, function(compressor) { if (!this.value) return false; return this.value.may_throw(compressor); }); })(function(node, func) { node.DEFMETHOD("may_throw", func); }); // determine if expression is constant (function(def_is_constant_expression) { function all_refs_local(scope) { var self = this; var result = true; self.walk(new TreeWalker(function(node) { if (!result) return true; if (node instanceof AST_SymbolRef) { if (self.inlined) { result = false; return true; } var def = node.definition(); if (member(def, self.enclosed) && !self.variables.has(def.name)) { if (scope) { var scope_def = scope.find_variable(node); if (def.undeclared ? !scope_def : scope_def === def) { result = "f"; return true; } } result = false; } return true; } if (node instanceof AST_This && self instanceof AST_Arrow) { result = false; return true; } })); return result; } def_is_constant_expression(AST_Node, return_false); def_is_constant_expression(AST_Constant, return_true); def_is_constant_expression(AST_Class, function(scope) { var self = this; if (self.extends && !self.extends.is_constant_expression(scope)) { return false; } return all_refs_local.call(self, scope); }); def_is_constant_expression(AST_Lambda, all_refs_local); def_is_constant_expression(AST_Unary, function() { return this.expression.is_constant_expression(); }); def_is_constant_expression(AST_Binary, function() { return this.left.is_constant_expression() && this.right.is_constant_expression(); }); def_is_constant_expression(AST_Array, function() { return this.elements.every((l) => l.is_constant_expression()); }); def_is_constant_expression(AST_Object, function() { return this.properties.every((l) => l.is_constant_expression()); }); def_is_constant_expression(AST_ObjectProperty, function() { return !(this.key instanceof AST_Node) && this.value.is_constant_expression(); }); })(function(node, func) { node.DEFMETHOD("is_constant_expression", func); }); // tell me if a statement aborts function aborts(thing) { return thing && thing.aborts(); } (function(def) { def(AST_Statement, return_null); def(AST_Jump, return_this); function block_aborts() { for (var i = 0; i < this.body.length; i++) { if (aborts(this.body[i])) { return this.body[i]; } } return null; } def(AST_Import, function() { return null; }); def(AST_BlockStatement, block_aborts); def(AST_SwitchBranch, block_aborts); def(AST_If, function() { return this.alternative && aborts(this.body) && aborts(this.alternative) && this; }); })(function(node, func) { node.DEFMETHOD("aborts", func); }); /* -----[ optimizers ]----- */ var directives = ["use asm", "use strict"]; def_optimize(AST_Directive, function(self, compressor) { if (compressor.option("directives") && (!member(self.value, directives) || compressor.has_directive(self.value) !== self)) { return make_node(AST_EmptyStatement, self); } return self; }); def_optimize(AST_Debugger, function(self, compressor) { if (compressor.option("drop_debugger")) return make_node(AST_EmptyStatement, self); return self; }); def_optimize(AST_LabeledStatement, function(self, compressor) { if (self.body instanceof AST_Break && compressor.loopcontrol_target(self.body) === self.body) { return make_node(AST_EmptyStatement, self); } return self.label.references.length == 0 ? self.body : self; }); def_optimize(AST_Block, function(self, compressor) { tighten_body(self.body, compressor); return self; }); function can_be_extracted_from_if_block(node) { return !( node instanceof AST_Const || node instanceof AST_Let || node instanceof AST_Class ); } def_optimize(AST_BlockStatement, function(self, compressor) { tighten_body(self.body, compressor); switch (self.body.length) { case 1: if (!compressor.has_directive("use strict") && compressor.parent() instanceof AST_If && can_be_extracted_from_if_block(self.body[0]) || can_be_evicted_from_block(self.body[0])) { return self.body[0]; } break; case 0: return make_node(AST_EmptyStatement, self); } return self; }); function opt_AST_Lambda(self, compressor) { tighten_body(self.body, compressor); if (compressor.option("side_effects") && self.body.length == 1 && self.body[0] === compressor.has_directive("use strict")) { self.body.length = 0; } return self; } def_optimize(AST_Lambda, opt_AST_Lambda); AST_Scope.DEFMETHOD("drop_unused", function(compressor) { if (!compressor.option("unused")) return; if (compressor.has_directive("use asm")) return; var self = this; if (self.pinned()) return; var drop_funcs = !(self instanceof AST_Toplevel) || compressor.toplevel.funcs; var drop_vars = !(self instanceof AST_Toplevel) || compressor.toplevel.vars; var assign_as_unused = /keep_assign/.test(compressor.option("unused")) ? return_false : function(node) { if (node instanceof AST_Assign && (node.write_only || node.operator == "=")) { return node.left; } if (node instanceof AST_Unary && node.write_only) return node.expression; }; var in_use_ids = new Map(); var fixed_ids = new Map(); if (self instanceof AST_Toplevel && compressor.top_retain) { self.variables.forEach(function(def) { if (compressor.top_retain(def) && !in_use_ids.has(def.id)) { in_use_ids.set(def.id, def); } }); } var var_defs_by_id = new Map(); var initializations = new Map(); var destructuring_value = null; // pass 1: find out which symbols are directly used in // this scope (not in nested scopes). var scope = this; var tw = new TreeWalker(function(node, descend) { if (node instanceof AST_Lambda && node.uses_arguments && !tw.has_directive("use strict")) { node.argnames.forEach(function(argname) { if (!(argname instanceof AST_SymbolDeclaration)) return; var def = argname.definition(); if (!in_use_ids.has(def.id)) { in_use_ids.set(def.id, def); } }); } if (node === self) return; if (node instanceof AST_Defun || node instanceof AST_DefClass) { var node_def = node.name.definition(); var in_export = tw.parent() instanceof AST_Export; if (in_export || !drop_funcs && scope === self) { if (node_def.global && !in_use_ids.has(node_def.id)) { in_use_ids.set(node_def.id, node_def); } } map_add(initializations, node_def.id, node); return true; // don't go in nested scopes } if (node instanceof AST_SymbolFunarg && scope === self) { map_add(var_defs_by_id, node.definition().id, node); } if (node instanceof AST_Definitions && scope === self) { var in_export = tw.parent() instanceof AST_Export; node.definitions.forEach(function(def) { if (def.name instanceof AST_SymbolVar) { map_add(var_defs_by_id, def.name.definition().id, def); } if (in_export || !drop_vars) { def.name.walk(new TreeWalker(function(node) { if (node instanceof AST_SymbolDeclaration) { var def = node.definition(); if ((in_export || def.global) && !in_use_ids.has(def.id)) { in_use_ids.set(def.id, def); } } })); } if (def.value) { if (def.name instanceof AST_Destructuring) { var destructuring_cache = destructuring_value; destructuring_value = def.value; def.walk(tw); destructuring_value = destructuring_cache; } else { var node_def = def.name.definition(); map_add(initializations, node_def.id, def.value); if (!node_def.chained && def.name.fixed_value() === def.value) { fixed_ids.set(node_def.id, def); } } if (def.value.has_side_effects(compressor)) { def.value.walk(tw); } } }); return true; } if (node.destructuring && destructuring_value) { map_add(initializations, node.name, destructuring_value); } return scan_ref_scoped(node, descend); }); self.walk(tw); // pass 2: for every used symbol we need to walk its // initialization code to figure out if it uses other // symbols (that may not be in_use). tw = new TreeWalker(scan_ref_scoped); in_use_ids.forEach(function (def) { var init = initializations.get(def.id); if (init) init.forEach(function(init) { init.walk(tw); }); }); // pass 3: we should drop declarations not in_use var tt = new TreeTransformer( function before(node, descend, in_list) { var parent = tt.parent(); if (drop_vars) { var sym = assign_as_unused(node); if (sym instanceof AST_SymbolRef) { var def = sym.definition(); var in_use = in_use_ids.has(def.id); if (node instanceof AST_Assign) { if (!in_use || fixed_ids.has(def.id) && fixed_ids.get(def.id) !== node) { return maintain_this_binding(parent, node, node.right.transform(tt)); } } else if (!in_use) return make_node(AST_Number, node, { value: 0 }); } } if (scope !== self) return; var def; if (node.name && (node instanceof AST_ClassExpression && !keep_name(compressor.option("keep_classnames"), (def = node.name.definition()).name) || node instanceof AST_Function && !keep_name(compressor.option("keep_fnames"), (def = node.name.definition()).name))) { // any declarations with same name will overshadow // name of this anonymous function and can therefore // never be used anywhere if (!in_use_ids.has(def.id) || def.orig.length > 1) node.name = null; } if (node instanceof AST_Lambda && !(node instanceof AST_Accessor)) { var trim = !compressor.option("keep_fargs"); for (var a = node.argnames, i = a.length; --i >= 0;) { var sym = a[i]; if (sym instanceof AST_Expansion) { sym = sym.expression; } if (sym instanceof AST_DefaultAssign) { sym = sym.left; } // Do not drop destructuring arguments. // They constitute a type assertion, so dropping // them would stop that TypeError which would happen // if someone called it with an incorrectly formatted // parameter. if (!(sym instanceof AST_Destructuring) && !in_use_ids.has(sym.definition().id)) { sym.__unused = true; if (trim) { a.pop(); compressor[sym.unreferenced() ? "warn" : "info"]("Dropping unused function argument {name} [{file}:{line},{col}]", template(sym)); } } else { trim = false; } } } if ((node instanceof AST_Defun || node instanceof AST_DefClass) && node !== self) { var def = node.name.definition(); var keep = in_use_ids.has(def.id) || !drop_funcs && def.global; if (!keep) { compressor[node.name.unreferenced() ? "warn" : "info"]("Dropping unused function {name} [{file}:{line},{col}]", template(node.name)); def.eliminated++; return make_node(AST_EmptyStatement, node); } } if (node instanceof AST_Definitions && !(parent instanceof AST_ForIn && parent.init === node)) { var drop_block = !(parent instanceof AST_Toplevel) && !(node instanceof AST_Var); // place uninitialized names at the start var body = [], head = [], tail = []; // for unused names whose initialization has // side effects, we can cascade the init. code // into the next one, or next statement. var side_effects = []; node.definitions.forEach(function(def) { if (def.value) def.value = def.value.transform(tt); var is_destructure = def.name instanceof AST_Destructuring; var sym = is_destructure ? new SymbolDef(null, { name: "" }) /* fake SymbolDef */ : def.name.definition(); if (drop_block && sym.global) return tail.push(def); if (!(drop_vars || drop_block) || is_destructure && (def.name.names.length || def.name.is_array || compressor.option("pure_getters") != true) || in_use_ids.has(sym.id)) { if (def.value && fixed_ids.has(sym.id) && fixed_ids.get(sym.id) !== def) { def.value = def.value.drop_side_effect_free(compressor); } if (def.name instanceof AST_SymbolVar) { var var_defs = var_defs_by_id.get(sym.id); if (var_defs.length > 1 && (!def.value || sym.orig.indexOf(def.name) > sym.eliminated)) { compressor.warn("Dropping duplicated definition of variable {name} [{file}:{line},{col}]", template(def.name)); if (def.value) { var ref = make_node(AST_SymbolRef, def.name, def.name); sym.references.push(ref); var assign = make_node(AST_Assign, def, { operator: "=", left: ref, right: def.value }); if (fixed_ids.get(sym.id) === def) { fixed_ids.set(sym.id, assign); } side_effects.push(assign.transform(tt)); } remove(var_defs, def); sym.eliminated++; return; } } if (def.value) { if (side_effects.length > 0) { if (tail.length > 0) { side_effects.push(def.value); def.value = make_sequence(def.value, side_effects); } else { body.push(make_node(AST_SimpleStatement, node, { body: make_sequence(node, side_effects) })); } side_effects = []; } tail.push(def); } else { head.push(def); } } else if (sym.orig[0] instanceof AST_SymbolCatch) { var value = def.value && def.value.drop_side_effect_free(compressor); if (value) side_effects.push(value); def.value = null; head.push(def); } else { var value = def.value && def.value.drop_side_effect_free(compressor); if (value) { if (!is_destructure) compressor.warn("Side effects in initialization of unused variable {name} [{file}:{line},{col}]", template(def.name)); side_effects.push(value); } else { if (!is_destructure) compressor[def.name.unreferenced() ? "warn" : "info"]("Dropping unused variable {name} [{file}:{line},{col}]", template(def.name)); } sym.eliminated++; } }); if (head.length > 0 || tail.length > 0) { node.definitions = head.concat(tail); body.push(node); } if (side_effects.length > 0) { body.push(make_node(AST_SimpleStatement, node, { body: make_sequence(node, side_effects) })); } switch (body.length) { case 0: return in_list ? MAP.skip : make_node(AST_EmptyStatement, node); case 1: return body[0]; default: return in_list ? MAP.splice(body) : make_node(AST_BlockStatement, node, { body: body }); } } // certain combination of unused name + side effect leads to: // https://github.com/mishoo/UglifyJS2/issues/44 // https://github.com/mishoo/UglifyJS2/issues/1830 // https://github.com/mishoo/UglifyJS2/issues/1838 // that's an invalid AST. // We fix it at this stage by moving the `var` outside the `for`. if (node instanceof AST_For) { descend(node, this); var block; if (node.init instanceof AST_BlockStatement) { block = node.init; node.init = block.body.pop(); block.body.push(node); } if (node.init instanceof AST_SimpleStatement) { node.init = node.init.body; } else if (is_empty(node.init)) { node.init = null; } return !block ? node : in_list ? MAP.splice(block.body) : block; } if (node instanceof AST_LabeledStatement && node.body instanceof AST_For) { descend(node, this); if (node.body instanceof AST_BlockStatement) { var block = node.body; node.body = block.body.pop(); block.body.push(node); return in_list ? MAP.splice(block.body) : block; } return node; } if (node instanceof AST_BlockStatement) { descend(node, this); if (in_list && node.body.every(can_be_evicted_from_block)) { return MAP.splice(node.body); } return node; } if (node instanceof AST_Scope) { var save_scope = scope; scope = node; descend(node, this); scope = save_scope; return node; } function template(sym) { return { name : sym.name, file : sym.start.file, line : sym.start.line, col : sym.start.col }; } } ); self.transform(tt); function scan_ref_scoped(node, descend) { var node_def, sym = assign_as_unused(node); if (sym instanceof AST_SymbolRef && !is_ref_of(node.left, AST_SymbolBlockDeclaration) && self.variables.get(sym.name) === (node_def = sym.definition())) { if (node instanceof AST_Assign) { node.right.walk(tw); if (!node_def.chained && node.left.fixed_value() === node.right) { fixed_ids.set(node_def.id, node); } } return true; } if (node instanceof AST_SymbolRef) { node_def = node.definition(); if (!in_use_ids.has(node_def.id)) { in_use_ids.set(node_def.id, node_def); if (node_def = node_def.redefined()) { in_use_ids.set(node_def.id, node_def); } } return true; } if (node instanceof AST_Scope) { var save_scope = scope; scope = node; descend(); scope = save_scope; return true; } } }); AST_Scope.DEFMETHOD("hoist_declarations", function(compressor) { var self = this; if (compressor.has_directive("use asm")) return self; // Hoisting makes no sense in an arrow func if (!Array.isArray(self.body)) return self; var hoist_funs = compressor.option("hoist_funs"); var hoist_vars = compressor.option("hoist_vars"); if (hoist_funs || hoist_vars) { var dirs = []; var hoisted = []; var vars = new Map(), vars_found = 0, var_decl = 0; // let's count var_decl first, we seem to waste a lot of // space if we hoist `var` when there's only one. self.walk(new TreeWalker(function(node) { if (node instanceof AST_Scope && node !== self) return true; if (node instanceof AST_Var) { ++var_decl; return true; } })); hoist_vars = hoist_vars && var_decl > 1; var tt = new TreeTransformer( function before(node) { if (node !== self) { if (node instanceof AST_Directive) { dirs.push(node); return make_node(AST_EmptyStatement, node); } if (hoist_funs && node instanceof AST_Defun && !(tt.parent() instanceof AST_Export) && tt.parent() === self) { hoisted.push(node); return make_node(AST_EmptyStatement, node); } if (hoist_vars && node instanceof AST_Var) { node.definitions.forEach(function(def) { if (def.name instanceof AST_Destructuring) return; vars.set(def.name.name, def); ++vars_found; }); var seq = node.to_assignments(compressor); var p = tt.parent(); if (p instanceof AST_ForIn && p.init === node) { if (seq == null) { var def = node.definitions[0].name; return make_node(AST_SymbolRef, def, def); } return seq; } if (p instanceof AST_For && p.init === node) { return seq; } if (!seq) return make_node(AST_EmptyStatement, node); return make_node(AST_SimpleStatement, node, { body: seq }); } if (node instanceof AST_Scope) return node; // to avoid descending in nested scopes } } ); self = self.transform(tt); if (vars_found > 0) { // collect only vars which don't show up in self's arguments list var defs = []; const is_lambda = self instanceof AST_Lambda; const args_as_names = is_lambda ? self.args_as_names() : null; vars.forEach((def, name) => { if (is_lambda && args_as_names.some((x) => x.name === def.name.name)) { vars.delete(name); } else { def = def.clone(); def.value = null; defs.push(def); vars.set(name, def); } }); if (defs.length > 0) { // try to merge in assignments for (var i = 0; i < self.body.length;) { if (self.body[i] instanceof AST_SimpleStatement) { var expr = self.body[i].body, sym, assign; if (expr instanceof AST_Assign && expr.operator == "=" && (sym = expr.left) instanceof AST_Symbol && vars.has(sym.name) ) { var def = vars.get(sym.name); if (def.value) break; def.value = expr.right; remove(defs, def); defs.push(def); self.body.splice(i, 1); continue; } if (expr instanceof AST_Sequence && (assign = expr.expressions[0]) instanceof AST_Assign && assign.operator == "=" && (sym = assign.left) instanceof AST_Symbol && vars.has(sym.name) ) { var def = vars.get(sym.name); if (def.value) break; def.value = assign.right; remove(defs, def); defs.push(def); self.body[i].body = make_sequence(expr, expr.expressions.slice(1)); continue; } } if (self.body[i] instanceof AST_EmptyStatement) { self.body.splice(i, 1); continue; } if (self.body[i] instanceof AST_BlockStatement) { var tmp = [ i, 1 ].concat(self.body[i].body); self.body.splice.apply(self.body, tmp); continue; } break; } defs = make_node(AST_Var, self, { definitions: defs }); hoisted.push(defs); } } self.body = dirs.concat(hoisted, self.body); } return self; }); AST_Scope.DEFMETHOD("var_names", function varNames() { var var_names = this._var_names; if (!var_names) { this._var_names = var_names = new Set(this.parent_scope ? varNames.call(this.parent_scope) : null); this.enclosed.forEach(function(def) { var_names.add(def.name); }); this.variables.forEach(function(def, name) { var_names.add(name); }); } return var_names; }); AST_Scope.DEFMETHOD("make_var_name", function(prefix) { var var_names = this.var_names(); prefix = prefix.replace(/(?:^[^a-z_$]|[^a-z0-9_$])/ig, "_"); var name = prefix; for (var i = 0; var_names.has(name); i++) name = prefix + "$" + i; var_names.add(name); return name; }); AST_Scope.DEFMETHOD("hoist_properties", function(compressor) { var self = this; if (!compressor.option("hoist_props") || compressor.has_directive("use asm")) return self; var top_retain = self instanceof AST_Toplevel && compressor.top_retain || return_false; var defs_by_id = new Map(); var tt = new TreeTransformer(function(node, descend) { if (node instanceof AST_Definitions && tt.parent() instanceof AST_Export) return node; if (node instanceof AST_VarDef) { var sym = node.name, def, value; if (sym.scope === self && (def = sym.definition()).escaped != 1 && !def.assignments && !def.direct_access && !def.single_use && !compressor.exposed(def) && !top_retain(def) && (value = sym.fixed_value()) === node.value && value instanceof AST_Object) { descend(node, this); var defs = new Map(); var assignments = []; value.properties.forEach(function(prop) { assignments.push(make_node(AST_VarDef, node, { name: make_sym(prop.key), value: prop.value })); }); defs_by_id.set(def.id, defs); return MAP.splice(assignments); } } if (node instanceof AST_PropAccess && node.expression instanceof AST_SymbolRef) { var defs = defs_by_id.get(node.expression.definition().id); if (defs) { var def = defs.get(String(get_value(node.property))); var sym = make_node(AST_SymbolRef, node, { name: def.name, scope: node.expression.scope, thedef: def }); sym.reference({}); return sym; } } function make_sym(key) { var new_var = make_node(sym.CTOR, sym, { name: self.make_var_name(sym.name + "_" + key), scope: self }); var def = self.def_variable(new_var); defs.set(String(key), def); self.enclosed.push(def); return new_var; } }); return self.transform(tt); }); // drop_side_effect_free() // remove side-effect-free parts which only affects return value (function(def_drop_side_effect_free) { // Drop side-effect-free elements from an array of expressions. // Returns an array of expressions with side-effects or null // if all elements were dropped. Note: original array may be // returned if nothing changed. function trim(nodes, compressor, first_in_statement) { var len = nodes.length; if (!len) return null; var ret = [], changed = false; for (var i = 0; i < len; i++) { var node = nodes[i].drop_side_effect_free(compressor, first_in_statement); changed |= node !== nodes[i]; if (node) { ret.push(node); first_in_statement = false; } } return changed ? ret.length ? ret : null : nodes; } def_drop_side_effect_free(AST_Node, return_this); def_drop_side_effect_free(AST_Constant, return_null); def_drop_side_effect_free(AST_This, return_null); def_drop_side_effect_free(AST_Call, function(compressor, first_in_statement) { if (!this.is_expr_pure(compressor)) { if (this.expression.is_call_pure(compressor)) { var exprs = this.args.slice(); exprs.unshift(this.expression.expression); exprs = trim(exprs, compressor, first_in_statement); return exprs && make_sequence(this, exprs); } if (is_func_expr(this.expression) && (!this.expression.name || !this.expression.name.definition().references.length)) { var node = this.clone(); node.expression.process_expression(false, compressor); return node; } return this; } if (this.pure) { compressor.warn("Dropping __PURE__ call [{file}:{line},{col}]", this.start); } var args = trim(this.args, compressor, first_in_statement); return args && make_sequence(this, args); }); def_drop_side_effect_free(AST_Accessor, return_null); def_drop_side_effect_free(AST_Function, return_null); def_drop_side_effect_free(AST_Arrow, return_null); def_drop_side_effect_free(AST_ClassExpression, return_null); def_drop_side_effect_free(AST_Binary, function(compressor, first_in_statement) { var right = this.right.drop_side_effect_free(compressor); if (!right) return this.left.drop_side_effect_free(compressor, first_in_statement); if (lazy_op.has(this.operator)) { if (right === this.right) return this; var node = this.clone(); node.right = right; return node; } else { var left = this.left.drop_side_effect_free(compressor, first_in_statement); if (!left) return this.right.drop_side_effect_free(compressor, first_in_statement); return make_sequence(this, [ left, right ]); } }); def_drop_side_effect_free(AST_Assign, function(compressor) { var left = this.left; if (left.has_side_effects(compressor) || compressor.has_directive("use strict") && left instanceof AST_PropAccess && left.expression.is_constant()) { return this; } this.write_only = true; while (left instanceof AST_PropAccess) { left = left.expression; } if (left.is_constant_expression(compressor.find_parent(AST_Scope))) { return this.right.drop_side_effect_free(compressor); } return this; }); def_drop_side_effect_free(AST_Conditional, function(compressor) { var consequent = this.consequent.drop_side_effect_free(compressor); var alternative = this.alternative.drop_side_effect_free(compressor); if (consequent === this.consequent && alternative === this.alternative) return this; if (!consequent) return alternative ? make_node(AST_Binary, this, { operator: "||", left: this.condition, right: alternative }) : this.condition.drop_side_effect_free(compressor); if (!alternative) return make_node(AST_Binary, this, { operator: "&&", left: this.condition, right: consequent }); var node = this.clone(); node.consequent = consequent; node.alternative = alternative; return node; }); def_drop_side_effect_free(AST_Unary, function(compressor, first_in_statement) { if (unary_side_effects.has(this.operator)) { this.write_only = !this.expression.has_side_effects(compressor); return this; } if (this.operator == "typeof" && this.expression instanceof AST_SymbolRef) return null; var expression = this.expression.drop_side_effect_free(compressor, first_in_statement); if (first_in_statement && expression && is_iife_call(expression)) { if (expression === this.expression && this.operator == "!") return this; return expression.negate(compressor, first_in_statement); } return expression; }); def_drop_side_effect_free(AST_SymbolRef, function(compressor) { return this.is_declared(compressor) ? null : this; }); def_drop_side_effect_free(AST_Object, function(compressor, first_in_statement) { var values = trim(this.properties, compressor, first_in_statement); return values && make_sequence(this, values); }); def_drop_side_effect_free(AST_ObjectProperty, function(compressor, first_in_statement) { return this.value.drop_side_effect_free(compressor, first_in_statement); }); def_drop_side_effect_free(AST_Array, function(compressor, first_in_statement) { var values = trim(this.elements, compressor, first_in_statement); return values && make_sequence(this, values); }); def_drop_side_effect_free(AST_Dot, function(compressor, first_in_statement) { if (this.expression.may_throw_on_access(compressor)) return this; return this.expression.drop_side_effect_free(compressor, first_in_statement); }); def_drop_side_effect_free(AST_Sub, function(compressor, first_in_statement) { if (this.expression.may_throw_on_access(compressor)) return this; var expression = this.expression.drop_side_effect_free(compressor, first_in_statement); if (!expression) return this.property.drop_side_effect_free(compressor, first_in_statement); var property = this.property.drop_side_effect_free(compressor); if (!property) return expression; return make_sequence(this, [ expression, property ]); }); def_drop_side_effect_free(AST_Sequence, function(compressor) { var last = this.tail_node(); var expr = last.drop_side_effect_free(compressor); if (expr === last) return this; var expressions = this.expressions.slice(0, -1); if (expr) expressions.push(expr); return make_sequence(this, expressions); }); def_drop_side_effect_free(AST_Expansion, function(compressor, first_in_statement) { return this.expression.drop_side_effect_free(compressor, first_in_statement); }); def_drop_side_effect_free(AST_TemplateSegment, return_null); def_drop_side_effect_free(AST_TemplateString, function(compressor) { var values = trim(this.segments, compressor, first_in_statement); return values && make_sequence(this, values); }); })(function(node, func) { node.DEFMETHOD("drop_side_effect_free", func); }); var pure_prop_access_globals = [ "Number", "String", "Array", "Object", "Function", "Promise", "global", "window", "document", "location" ]; def_optimize(AST_SimpleStatement, function(self, compressor) { if (self.body instanceof AST_SymbolRef && pure_prop_access_globals.indexOf(self.body.name) !== -1) { return make_node(AST_EmptyStatement, self); } if (compressor.option("side_effects")) { var body = self.body; var node = body.drop_side_effect_free(compressor, true); if (!node) { compressor.warn("Dropping side-effect-free statement [{file}:{line},{col}]", self.start); return make_node(AST_EmptyStatement, self); } if (node !== body) { return make_node(AST_SimpleStatement, self, { body: node }); } } return self; }); def_optimize(AST_While, function(self, compressor) { return compressor.option("loops") ? make_node(AST_For, self, self).optimize(compressor) : self; }); function has_break_or_continue(loop, parent) { var found = false; var tw = new TreeWalker(function(node) { if (found || node instanceof AST_Scope) return true; if (node instanceof AST_LoopControl && tw.loopcontrol_target(node) === loop) { return found = true; } }); if (parent instanceof AST_LabeledStatement) tw.push(parent); tw.push(loop); loop.body.walk(tw); return found; } def_optimize(AST_Do, function(self, compressor) { if (!compressor.option("loops")) return self; var cond = self.condition.tail_node().evaluate(compressor); if (!(cond instanceof AST_Node)) { if (cond) return make_node(AST_For, self, { body: make_node(AST_BlockStatement, self.body, { body: [ self.body, make_node(AST_SimpleStatement, self.condition, { body: self.condition }) ] }) }).optimize(compressor); if (!has_break_or_continue(self, compressor.parent())) { return make_node(AST_BlockStatement, self.body, { body: [ self.body, make_node(AST_SimpleStatement, self.condition, { body: self.condition }) ] }).optimize(compressor); } } return self; }); function if_break_in_loop(self, compressor) { var first = self.body instanceof AST_BlockStatement ? self.body.body[0] : self.body; if (compressor.option("dead_code") && is_break(first)) { var body = []; if (self.init instanceof AST_Statement) { body.push(self.init); } else if (self.init) { body.push(make_node(AST_SimpleStatement, self.init, { body: self.init })); } if (self.condition) { body.push(make_node(AST_SimpleStatement, self.condition, { body: self.condition })); } extract_declarations_from_unreachable_code(compressor, self.body, body); return make_node(AST_BlockStatement, self, { body: body }); } if (first instanceof AST_If) { if (is_break(first.body)) { if (self.condition) { self.condition = make_node(AST_Binary, self.condition, { left: self.condition, operator: "&&", right: first.condition.negate(compressor), }); } else { self.condition = first.condition.negate(compressor); } drop_it(first.alternative); } else if (is_break(first.alternative)) { if (self.condition) { self.condition = make_node(AST_Binary, self.condition, { left: self.condition, operator: "&&", right: first.condition, }); } else { self.condition = first.condition; } drop_it(first.body); } } return self; function is_break(node) { return node instanceof AST_Break && compressor.loopcontrol_target(node) === compressor.self(); } function drop_it(rest) { rest = as_statement_array(rest); if (self.body instanceof AST_BlockStatement) { self.body = self.body.clone(); self.body.body = rest.concat(self.body.body.slice(1)); self.body = self.body.transform(compressor); } else { self.body = make_node(AST_BlockStatement, self.body, { body: rest }).transform(compressor); } self = if_break_in_loop(self, compressor); } } def_optimize(AST_For, function(self, compressor) { if (!compressor.option("loops")) return self; if (compressor.option("side_effects") && self.init) { self.init = self.init.drop_side_effect_free(compressor); } if (self.condition) { var cond = self.condition.evaluate(compressor); if (!(cond instanceof AST_Node)) { if (cond) self.condition = null; else if (!compressor.option("dead_code")) { var orig = self.condition; self.condition = make_node_from_constant(cond, self.condition); self.condition = best_of_expression(self.condition.transform(compressor), orig); } } if (compressor.option("dead_code")) { if (cond instanceof AST_Node) cond = self.condition.tail_node().evaluate(compressor); if (!cond) { var body = []; extract_declarations_from_unreachable_code(compressor, self.body, body); if (self.init instanceof AST_Statement) { body.push(self.init); } else if (self.init) { body.push(make_node(AST_SimpleStatement, self.init, { body: self.init })); } body.push(make_node(AST_SimpleStatement, self.condition, { body: self.condition })); return make_node(AST_BlockStatement, self, { body: body }).optimize(compressor); } } } return if_break_in_loop(self, compressor); }); def_optimize(AST_If, function(self, compressor) { if (is_empty(self.alternative)) self.alternative = null; if (!compressor.option("conditionals")) return self; // if condition can be statically determined, warn and drop // one of the blocks. note, statically determined implies // “has no side effects”; also it doesn't work for cases like // `x && true`, though it probably should. var cond = self.condition.evaluate(compressor); if (!compressor.option("dead_code") && !(cond instanceof AST_Node)) { var orig = self.condition; self.condition = make_node_from_constant(cond, orig); self.condition = best_of_expression(self.condition.transform(compressor), orig); } if (compressor.option("dead_code")) { if (cond instanceof AST_Node) cond = self.condition.tail_node().evaluate(compressor); if (!cond) { compressor.warn("Condition always false [{file}:{line},{col}]", self.condition.start); var body = []; extract_declarations_from_unreachable_code(compressor, self.body, body); body.push(make_node(AST_SimpleStatement, self.condition, { body: self.condition })); if (self.alternative) body.push(self.alternative); return make_node(AST_BlockStatement, self, { body: body }).optimize(compressor); } else if (!(cond instanceof AST_Node)) { compressor.warn("Condition always true [{file}:{line},{col}]", self.condition.start); var body = []; if (self.alternative) { extract_declarations_from_unreachable_code(compressor, self.alternative, body); } body.push(make_node(AST_SimpleStatement, self.condition, { body: self.condition })); body.push(self.body); return make_node(AST_BlockStatement, self, { body: body }).optimize(compressor); } } var negated = self.condition.negate(compressor); var self_condition_length = self.condition.print_to_string().length; var negated_length = negated.print_to_string().length; var negated_is_best = negated_length < self_condition_length; if (self.alternative && negated_is_best) { negated_is_best = false; // because we already do the switch here. // no need to swap values of self_condition_length and negated_length // here because they are only used in an equality comparison later on. self.condition = negated; var tmp = self.body; self.body = self.alternative || make_node(AST_EmptyStatement, self); self.alternative = tmp; } if (is_empty(self.body) && is_empty(self.alternative)) { return make_node(AST_SimpleStatement, self.condition, { body: self.condition.clone() }).optimize(compressor); } if (self.body instanceof AST_SimpleStatement && self.alternative instanceof AST_SimpleStatement) { return make_node(AST_SimpleStatement, self, { body: make_node(AST_Conditional, self, { condition : self.condition, consequent : self.body.body, alternative : self.alternative.body }) }).optimize(compressor); } if (is_empty(self.alternative) && self.body instanceof AST_SimpleStatement) { if (self_condition_length === negated_length && !negated_is_best && self.condition instanceof AST_Binary && self.condition.operator == "||") { // although the code length of self.condition and negated are the same, // negated does not require additional surrounding parentheses. // see https://github.com/mishoo/UglifyJS2/issues/979 negated_is_best = true; } if (negated_is_best) return make_node(AST_SimpleStatement, self, { body: make_node(AST_Binary, self, { operator : "||", left : negated, right : self.body.body }) }).optimize(compressor); return make_node(AST_SimpleStatement, self, { body: make_node(AST_Binary, self, { operator : "&&", left : self.condition, right : self.body.body }) }).optimize(compressor); } if (self.body instanceof AST_EmptyStatement && self.alternative instanceof AST_SimpleStatement) { return make_node(AST_SimpleStatement, self, { body: make_node(AST_Binary, self, { operator : "||", left : self.condition, right : self.alternative.body }) }).optimize(compressor); } if (self.body instanceof AST_Exit && self.alternative instanceof AST_Exit && self.body.TYPE == self.alternative.TYPE) { return make_node(self.body.CTOR, self, { value: make_node(AST_Conditional, self, { condition : self.condition, consequent : self.body.value || make_node(AST_Undefined, self.body), alternative : self.alternative.value || make_node(AST_Undefined, self.alternative) }).transform(compressor) }).optimize(compressor); } if (self.body instanceof AST_If && !self.body.alternative && !self.alternative) { self = make_node(AST_If, self, { condition: make_node(AST_Binary, self.condition, { operator: "&&", left: self.condition, right: self.body.condition }), body: self.body.body, alternative: null }); } if (aborts(self.body)) { if (self.alternative) { var alt = self.alternative; self.alternative = null; return make_node(AST_BlockStatement, self, { body: [ self, alt ] }).optimize(compressor); } } if (aborts(self.alternative)) { var body = self.body; self.body = self.alternative; self.condition = negated_is_best ? negated : self.condition.negate(compressor); self.alternative = null; return make_node(AST_BlockStatement, self, { body: [ self, body ] }).optimize(compressor); } return self; }); def_optimize(AST_Switch, function(self, compressor) { if (!compressor.option("switches")) return self; var branch; var value = self.expression.evaluate(compressor); if (!(value instanceof AST_Node)) { var orig = self.expression; self.expression = make_node_from_constant(value, orig); self.expression = best_of_expression(self.expression.transform(compressor), orig); } if (!compressor.option("dead_code")) return self; if (value instanceof AST_Node) { value = self.expression.tail_node().evaluate(compressor); } var decl = []; var body = []; var default_branch; var exact_match; for (var i = 0, len = self.body.length; i < len && !exact_match; i++) { branch = self.body[i]; if (branch instanceof AST_Default) { if (!default_branch) { default_branch = branch; } else { eliminate_branch(branch, body[body.length - 1]); } } else if (!(value instanceof AST_Node)) { var exp = branch.expression.evaluate(compressor); if (!(exp instanceof AST_Node) && exp !== value) { eliminate_branch(branch, body[body.length - 1]); continue; } if (exp instanceof AST_Node) exp = branch.expression.tail_node().evaluate(compressor); if (exp === value) { exact_match = branch; if (default_branch) { var default_index = body.indexOf(default_branch); body.splice(default_index, 1); eliminate_branch(default_branch, body[default_index - 1]); default_branch = null; } } } if (aborts(branch)) { var prev = body[body.length - 1]; if (aborts(prev) && prev.body.length == branch.body.length && make_node(AST_BlockStatement, prev, prev).equivalent_to(make_node(AST_BlockStatement, branch, branch))) { prev.body = []; } } body.push(branch); } while (i < len) eliminate_branch(self.body[i++], body[body.length - 1]); if (body.length > 0) { body[0].body = decl.concat(body[0].body); } self.body = body; while (branch = body[body.length - 1]) { var stat = branch.body[branch.body.length - 1]; if (stat instanceof AST_Break && compressor.loopcontrol_target(stat) === self) branch.body.pop(); if (branch.body.length || branch instanceof AST_Case && (default_branch || branch.expression.has_side_effects(compressor))) break; if (body.pop() === default_branch) default_branch = null; } if (body.length == 0) { return make_node(AST_BlockStatement, self, { body: decl.concat(make_node(AST_SimpleStatement, self.expression, { body: self.expression })) }).optimize(compressor); } if (body.length == 1 && (body[0] === exact_match || body[0] === default_branch)) { var has_break = false; var tw = new TreeWalker(function(node) { if (has_break || node instanceof AST_Lambda || node instanceof AST_SimpleStatement) return true; if (node instanceof AST_Break && tw.loopcontrol_target(node) === self) has_break = true; }); self.walk(tw); if (!has_break) { var statements = body[0].body.slice(); var exp = body[0].expression; if (exp) statements.unshift(make_node(AST_SimpleStatement, exp, { body: exp })); statements.unshift(make_node(AST_SimpleStatement, self.expression, { body:self.expression })); return make_node(AST_BlockStatement, self, { body: statements }).optimize(compressor); } } return self; function eliminate_branch(branch, prev) { if (prev && !aborts(prev)) { prev.body = prev.body.concat(branch.body); } else { extract_declarations_from_unreachable_code(compressor, branch, decl); } } }); def_optimize(AST_Try, function(self, compressor) { tighten_body(self.body, compressor); if (self.bcatch && self.bfinally && self.bfinally.body.every(is_empty)) self.bfinally = null; if (compressor.option("dead_code") && self.body.every(is_empty)) { var body = []; if (self.bcatch) { extract_declarations_from_unreachable_code(compressor, self.bcatch, body); body.forEach(function(stat) { if (!(stat instanceof AST_Definitions)) return; stat.definitions.forEach(function(var_def) { var def = var_def.name.definition().redefined(); if (!def) return; var_def.name = var_def.name.clone(); var_def.name.thedef = def; }); }); } if (self.bfinally) body = body.concat(self.bfinally.body); return make_node(AST_BlockStatement, self, { body: body }).optimize(compressor); } return self; }); AST_Definitions.DEFMETHOD("remove_initializers", function() { var decls = []; this.definitions.forEach(function(def) { if (def.name instanceof AST_SymbolDeclaration) { def.value = null; decls.push(def); } else def.name.walk(new TreeWalker(function(node) { if (node instanceof AST_SymbolDeclaration) { decls.push(make_node(AST_VarDef, def, { name: node, value: null })); } })); }); this.definitions = decls; }); AST_Definitions.DEFMETHOD("to_assignments", function(compressor) { var reduce_vars = compressor.option("reduce_vars"); var assignments = this.definitions.reduce(function(a, def) { if (def.value && !(def.name instanceof AST_Destructuring)) { var name = make_node(AST_SymbolRef, def.name, def.name); a.push(make_node(AST_Assign, def, { operator : "=", left : name, right : def.value })); if (reduce_vars) name.definition().fixed = false; } else if (def.value) { // Because it's a destructuring, do not turn into an assignment. var varDef = make_node(AST_VarDef, def, { name: def.name, value: def.value }); var var_ = make_node(AST_Var, def, { definitions: [ varDef ] }); a.push(var_); } def = def.name.definition(); def.eliminated++; def.replaced--; return a; }, []); if (assignments.length == 0) return null; return make_sequence(this, assignments); }); def_optimize(AST_Definitions, function(self, compressor) { if (self.definitions.length == 0) return make_node(AST_EmptyStatement, self); return self; }); def_optimize(AST_Import, function(self, compressor) { return self; }); function retain_top_func(fn, compressor) { return compressor.top_retain && fn instanceof AST_Defun && fn._top && fn.name && compressor.top_retain(fn.name); } def_optimize(AST_Call, function(self, compressor) { var exp = self.expression; var fn = exp; inline_array_like_spread(self, compressor, self.args); var simple_args = self.args.every((arg) => !(arg instanceof AST_Expansion) ); if (compressor.option("reduce_vars") && fn instanceof AST_SymbolRef) { fn = fn.fixed_value(); if (retain_top_func(fn, compressor)) fn = exp; } var is_func = fn instanceof AST_Lambda; if (compressor.option("unused") && simple_args && is_func && !fn.uses_arguments && !fn.pinned()) { var pos = 0, last = 0; for (var i = 0, len = self.args.length; i < len; i++) { if (fn.argnames[i] instanceof AST_Expansion) { if (fn.argnames[i].expression.__unused) while (i < len) { var node = self.args[i++].drop_side_effect_free(compressor); if (node) { self.args[pos++] = node; } } else while (i < len) { self.args[pos++] = self.args[i++]; } last = pos; break; } var trim = i >= fn.argnames.length; if (trim || fn.argnames[i].__unused) { var node = self.args[i].drop_side_effect_free(compressor); if (node) { self.args[pos++] = node; } else if (!trim) { self.args[pos++] = make_node(AST_Number, self.args[i], { value: 0 }); continue; } } else { self.args[pos++] = self.args[i]; } last = pos; } self.args.length = last; } if (compressor.option("unsafe")) { if (is_undeclared_ref(exp)) switch (exp.name) { case "Array": if (self.args.length != 1) { return make_node(AST_Array, self, { elements: self.args }).optimize(compressor); } else if (self.args[0] instanceof AST_Number && self.args[0].value <= 11) { const elements = []; for (let i = 0; i < self.args[0].value; i++) elements.push(new AST_Hole); return new AST_Array({ elements }); } break; case "Object": if (self.args.length == 0) { return make_node(AST_Object, self, { properties: [] }); } break; case "String": if (self.args.length == 0) return make_node(AST_String, self, { value: "" }); if (self.args.length <= 1) return make_node(AST_Binary, self, { left: self.args[0], operator: "+", right: make_node(AST_String, self, { value: "" }) }).optimize(compressor); break; case "Number": if (self.args.length == 0) return make_node(AST_Number, self, { value: 0 }); if (self.args.length == 1) return make_node(AST_UnaryPrefix, self, { expression: self.args[0], operator: "+" }).optimize(compressor); case "Boolean": if (self.args.length == 0) return make_node(AST_False, self); if (self.args.length == 1) return make_node(AST_UnaryPrefix, self, { expression: make_node(AST_UnaryPrefix, self, { expression: self.args[0], operator: "!" }), operator: "!" }).optimize(compressor); break; case "RegExp": var params = []; if (self.args.every((arg) => { var value = arg.evaluate(compressor); params.push(value); return arg !== value; })) { try { return best_of(compressor, self, make_node(AST_RegExp, self, { value: RegExp.apply(RegExp, params), })); } catch (ex) { compressor.warn("Error converting {expr} [{file}:{line},{col}]", { expr: self.print_to_string(), file: self.start.file, line: self.start.line, col: self.start.col }); } } break; } else if (exp instanceof AST_Dot) switch(exp.property) { case "toString": if (self.args.length == 0 && !exp.expression.may_throw_on_access(compressor)) { return make_node(AST_Binary, self, { left: make_node(AST_String, self, { value: "" }), operator: "+", right: exp.expression }).optimize(compressor); } break; case "join": if (exp.expression instanceof AST_Array) EXIT: { var separator; if (self.args.length > 0) { separator = self.args[0].evaluate(compressor); if (separator === self.args[0]) break EXIT; // not a constant } var elements = []; var consts = []; for (var i = 0, len = exp.expression.elements.length; i < len; i++) { var el = exp.expression.elements[i]; if (el instanceof AST_Expansion) break EXIT; var value = el.evaluate(compressor); if (value !== el) { consts.push(value); } else { if (consts.length > 0) { elements.push(make_node(AST_String, self, { value: consts.join(separator) })); consts.length = 0; } elements.push(el); } } if (consts.length > 0) { elements.push(make_node(AST_String, self, { value: consts.join(separator) })); } if (elements.length == 0) return make_node(AST_String, self, { value: "" }); if (elements.length == 1) { if (elements[0].is_string(compressor)) { return elements[0]; } return make_node(AST_Binary, elements[0], { operator : "+", left : make_node(AST_String, self, { value: "" }), right : elements[0] }); } if (separator == "") { var first; if (elements[0].is_string(compressor) || elements[1].is_string(compressor)) { first = elements.shift(); } else { first = make_node(AST_String, self, { value: "" }); } return elements.reduce(function(prev, el) { return make_node(AST_Binary, el, { operator : "+", left : prev, right : el }); }, first).optimize(compressor); } // need this awkward cloning to not affect original element // best_of will decide which one to get through. var node = self.clone(); node.expression = node.expression.clone(); node.expression.expression = node.expression.expression.clone(); node.expression.expression.elements = elements; return best_of(compressor, self, node); } break; case "charAt": if (exp.expression.is_string(compressor)) { var arg = self.args[0]; var index = arg ? arg.evaluate(compressor) : 0; if (index !== arg) { return make_node(AST_Sub, exp, { expression: exp.expression, property: make_node_from_constant(index | 0, arg || exp) }).optimize(compressor); } } break; case "apply": if (self.args.length == 2 && self.args[1] instanceof AST_Array) { var args = self.args[1].elements.slice(); args.unshift(self.args[0]); return make_node(AST_Call, self, { expression: make_node(AST_Dot, exp, { expression: exp.expression, property: "call" }), args: args }).optimize(compressor); } break; case "call": var func = exp.expression; if (func instanceof AST_SymbolRef) { func = func.fixed_value(); } if (func instanceof AST_Lambda && !func.contains_this()) { return (self.args.length ? make_sequence(this, [ self.args[0], make_node(AST_Call, self, { expression: exp.expression, args: self.args.slice(1) }) ]) : make_node(AST_Call, self, { expression: exp.expression, args: [] })).optimize(compressor); } break; } } if (compressor.option("unsafe_Function") && is_undeclared_ref(exp) && exp.name == "Function") { // new Function() => function(){} if (self.args.length == 0) return make_node(AST_Function, self, { argnames: [], body: [] }).optimize(compressor); if (self.args.every((x) => x instanceof AST_String )) { // quite a corner-case, but we can handle it: // https://github.com/mishoo/UglifyJS2/issues/203 // if the code argument is a constant, then we can minify it. try { var code = "n(function(" + self.args.slice(0, -1).map(function(arg) { return arg.value; }).join(",") + "){" + self.args[self.args.length - 1].value + "})"; var ast = parse(code); var mangle = { ie8: compressor.option("ie8") }; ast.figure_out_scope(mangle); var comp = new Compressor(compressor.options); ast = ast.transform(comp); ast.figure_out_scope(mangle); base54.reset(); ast.compute_char_frequency(mangle); ast.mangle_names(mangle); var fun; ast.walk(new TreeWalker(function(node) { if (fun) return true; if (is_func_expr(node)) { fun = node; return true; } })); if (fun.body instanceof AST_Node) { fun.body = [ make_node(AST_Return, fun.body, { value: fun.body }) ]; } var code = OutputStream(); AST_BlockStatement.prototype._codegen.call(fun, fun, code); self.args = [ make_node(AST_String, self, { value: fun.argnames.map(function(arg) { return arg.print_to_string(); }).join(",") }), make_node(AST_String, self.args[self.args.length - 1], { value: code.get().replace(/^{|}$/g, "") }) ]; return self; } catch (ex) { if (ex instanceof JS_Parse_Error) { compressor.warn("Error parsing code passed to new Function [{file}:{line},{col}]", self.args[self.args.length - 1].start); compressor.warn(ex.toString()); } else { throw ex; } } } } var stat = is_func && fn.body; if (stat instanceof AST_Node) { stat = make_node(AST_Return, stat, { value: stat }); } else if (stat) { stat = stat[0]; } var is_regular_func = is_func && !fn.is_generator && !fn.async; var can_inline = compressor.option("inline") && !self.is_expr_pure(compressor); if (can_inline && stat instanceof AST_Return && is_regular_func) { var value = stat.value; if (!value || value.is_constant_expression()) { if (value) { value = value.clone(true); } else { value = make_node(AST_Undefined, self); } var args = self.args.concat(value); return make_sequence(self, args).optimize(compressor); } } if (is_regular_func) { var def, value, scope, in_loop, level = -1; if (can_inline && simple_args && !fn.uses_arguments && !fn.pinned() && !(compressor.parent() instanceof AST_Class) && !(fn.name && fn instanceof AST_Function) && (!(compressor.find_parent(AST_Lambda) instanceof AST_Arrow) || fn.argnames.length == 0 && (fn.body instanceof AST_Node || fn.body.length == 1)) && (value = can_flatten_body(stat)) && (exp === fn || compressor.option("unused") && (def = exp.definition()).references.length == 1 && !recursive_ref(compressor, def) && fn.is_constant_expression(exp.scope)) && !self.pure && !fn.contains_this() && can_inject_symbols() && !(scope instanceof AST_Class)) { fn._squeezed = true; return make_sequence(self, flatten_fn()).optimize(compressor); } if (compressor.option("side_effects") && !(fn.body instanceof AST_Node) && fn.body.every(is_empty)) { var args = self.args.concat(make_node(AST_Undefined, self)); return make_sequence(self, args).optimize(compressor); } } if (compressor.option("negate_iife") && compressor.parent() instanceof AST_SimpleStatement && is_iife_call(self)) { return self.negate(compressor, true); } var ev = self.evaluate(compressor); if (ev !== self) { ev = make_node_from_constant(ev, self).optimize(compressor); return best_of(compressor, ev, self); } return self; function return_value(stat) { if (!stat) return make_node(AST_Undefined, self); if (stat instanceof AST_Return) { if (!stat.value) return make_node(AST_Undefined, self); return stat.value.clone(true); } if (stat instanceof AST_SimpleStatement) { return make_node(AST_UnaryPrefix, stat, { operator: "void", expression: stat.body.clone(true) }); } } function can_flatten_body(stat) { var body = fn.body instanceof AST_Node ? [ fn.body ] : fn.body; var len = body.length; if (compressor.option("inline") < 3) { return len == 1 && return_value(stat); } stat = null; for (var i = 0; i < len; i++) { var line = body[i]; if (line instanceof AST_Var) { if (stat && !line.definitions.every((var_def) => !var_def.value )) { return false; } } else if (stat) { return false; } else if (!(line instanceof AST_EmptyStatement)) { stat = line; } } return return_value(stat); } function can_inject_args(block_scoped, safe_to_inject) { for (var i = 0, len = fn.argnames.length; i < len; i++) { var arg = fn.argnames[i]; if (arg instanceof AST_DefaultAssign) { if (arg.left.__unused) continue; return false; } if (arg instanceof AST_Destructuring) return false; if (arg instanceof AST_Expansion) { if (arg.expression.__unused) continue; return false; } if (arg.__unused) continue; if (!safe_to_inject || block_scoped.has(arg.name) || identifier_atom.has(arg.name) || scope.var_names().has(arg.name)) { return false; } if (in_loop) in_loop.push(arg.definition()); } return true; } function can_inject_args_values() { var arg_vals_outer_refs = new Set(); var value_walker = new TreeWalker(function(node) { if (node instanceof AST_Scope) { var scope_outer_refs = new Set(); node.enclosed.forEach(function(def) { scope_outer_refs.add(def.name); }); node.variables.forEach(function(name) { scope_outer_refs.delete(name); }); scope_outer_refs.forEach(function(name) { arg_vals_outer_refs.add(name); }); return true; } return false; }); self.args.forEach(function(value) { value.walk(value_walker); }); if (arg_vals_outer_refs.size == 0) return true; for (var i = 0, len = fn.argnames.length; i < len; i++) { var arg = fn.argnames[i]; if (arg instanceof AST_DefaultAssign && arg.left.__unused) continue; if (arg instanceof AST_Expansion && arg.expression.__unused) continue; if (arg.__unused) continue; if (arg_vals_outer_refs.has(arg.name)) return false; } for (var i = 0, len = fn.body.length; i < len; i++) { var stat = fn.body[i]; if (!(stat instanceof AST_Var)) continue; for (var j = stat.definitions.length; --j >= 0;) { var name = stat.definitions[j].name; if (name instanceof AST_Destructuring || arg_vals_outer_refs.has(name.name)) { return false; } } } return true; } function can_inject_vars(block_scoped, safe_to_inject) { var len = fn.body.length; for (var i = 0; i < len; i++) { var stat = fn.body[i]; if (!(stat instanceof AST_Var)) continue; if (!safe_to_inject) return false; for (var j = stat.definitions.length; --j >= 0;) { var name = stat.definitions[j].name; if (name instanceof AST_Destructuring || block_scoped.has(name.name) || identifier_atom.has(name.name) || scope.var_names().has(name.name)) { return false; } if (in_loop) in_loop.push(name.definition()); } } return true; } function can_inject_symbols() { var block_scoped = new Set(); do { scope = compressor.parent(++level); if (scope.is_block_scope() && !(compressor.parent(level - 1) instanceof AST_Scope)) { if (scope.block_scope) { // TODO this is sometimes undefined during compression. // But it should always have a value! scope.block_scope.variables.forEach(function (variable) { block_scoped.add(variable.name); }); } } if (scope instanceof AST_Catch) { if (scope.argname) { block_scoped.add(scope.argname.name); } } else if (scope instanceof AST_IterationStatement) { in_loop = []; } else if (scope instanceof AST_SymbolRef) { if (scope.fixed_value() instanceof AST_Scope) return false; } } while (!(scope instanceof AST_Scope) || scope instanceof AST_Arrow); var safe_to_inject = !(scope instanceof AST_Toplevel) || compressor.toplevel.vars; var inline = compressor.option("inline"); if (!can_inject_vars(block_scoped, inline >= 3 && safe_to_inject)) return false; if (!can_inject_args(block_scoped, inline >= 2 && safe_to_inject)) return false; if (!can_inject_args_values()) return false; return !in_loop || in_loop.length == 0 || !is_reachable(fn, in_loop); } function append_var(decls, expressions, name, value) { var def = name.definition(); scope.variables.set(name.name, def); scope.enclosed.push(def); if (!scope.var_names().has(name.name)) { scope.var_names().add(name.name); decls.push(make_node(AST_VarDef, name, { name: name, value: null })); } var sym = make_node(AST_SymbolRef, name, name); def.references.push(sym); if (value) expressions.push(make_node(AST_Assign, self, { operator: "=", left: sym, right: value.clone() })); } function flatten_args(decls, expressions) { var len = fn.argnames.length; for (var i = self.args.length; --i >= len;) { expressions.push(self.args[i]); } for (i = len; --i >= 0;) { var name = fn.argnames[i]; var value = self.args[i]; if (name.__unused || !name.name || scope.var_names().has(name.name)) { if (value) expressions.push(value); } else { var symbol = make_node(AST_SymbolVar, name, name); name.definition().orig.push(symbol); if (!value && in_loop) value = make_node(AST_Undefined, self); append_var(decls, expressions, symbol, value); } } decls.reverse(); expressions.reverse(); } function flatten_vars(decls, expressions) { var pos = expressions.length; for (var i = 0, lines = fn.body.length; i < lines; i++) { var stat = fn.body[i]; if (!(stat instanceof AST_Var)) continue; for (var j = 0, defs = stat.definitions.length; j < defs; j++) { var var_def = stat.definitions[j]; var name = var_def.name; append_var(decls, expressions, name, var_def.value); if (in_loop && fn.argnames.every((argname) => argname.name != name.name )) { var def = fn.variables.get(name.name); var sym = make_node(AST_SymbolRef, name, name); def.references.push(sym); expressions.splice(pos++, 0, make_node(AST_Assign, var_def, { operator: "=", left: sym, right: make_node(AST_Undefined, name) })); } } } } function flatten_fn() { var decls = []; var expressions = []; flatten_args(decls, expressions); flatten_vars(decls, expressions); expressions.push(value); if (decls.length) { i = scope.body.indexOf(compressor.parent(level - 1)) + 1; scope.body.splice(i, 0, make_node(AST_Var, fn, { definitions: decls })); } return expressions; } }); def_optimize(AST_New, function(self, compressor) { if ( compressor.option("unsafe") && is_undeclared_ref(self.expression) && ["Object", "RegExp", "Function", "Error", "Array"].includes(self.expression.name) ) return make_node(AST_Call, self, self).transform(compressor); return self; }); def_optimize(AST_Sequence, function(self, compressor) { if (!compressor.option("side_effects")) return self; var expressions = []; filter_for_side_effects(); var end = expressions.length - 1; trim_right_for_undefined(); if (end == 0) { self = maintain_this_binding(compressor.parent(), compressor.self(), expressions[0]); if (!(self instanceof AST_Sequence)) self = self.optimize(compressor); return self; } self.expressions = expressions; return self; function filter_for_side_effects() { var first = first_in_statement(compressor); var last = self.expressions.length - 1; self.expressions.forEach(function(expr, index) { if (index < last) expr = expr.drop_side_effect_free(compressor, first); if (expr) { merge_sequence(expressions, expr); first = false; } }); } function trim_right_for_undefined() { while (end > 0 && is_undefined(expressions[end], compressor)) end--; if (end < expressions.length - 1) { expressions[end] = make_node(AST_UnaryPrefix, self, { operator : "void", expression : expressions[end] }); expressions.length = end + 1; } } }); AST_Unary.DEFMETHOD("lift_sequences", function(compressor) { if (compressor.option("sequences")) { if (this.expression instanceof AST_Sequence) { var x = this.expression.expressions.slice(); var e = this.clone(); e.expression = x.pop(); x.push(e); return make_sequence(this, x).optimize(compressor); } } return this; }); def_optimize(AST_UnaryPostfix, function(self, compressor) { return self.lift_sequences(compressor); }); def_optimize(AST_UnaryPrefix, function(self, compressor) { var e = self.expression; if (self.operator == "delete" && !(e instanceof AST_SymbolRef || e instanceof AST_PropAccess || is_identifier_atom(e))) { if (e instanceof AST_Sequence) { e = e.expressions.slice(); e.push(make_node(AST_True, self)); return make_sequence(self, e).optimize(compressor); } return make_sequence(self, [ e, make_node(AST_True, self) ]).optimize(compressor); } var seq = self.lift_sequences(compressor); if (seq !== self) { return seq; } if (compressor.option("side_effects") && self.operator == "void") { e = e.drop_side_effect_free(compressor); if (e) { self.expression = e; return self; } else { return make_node(AST_Undefined, self).optimize(compressor); } } if (compressor.in_boolean_context()) { switch (self.operator) { case "!": if (e instanceof AST_UnaryPrefix && e.operator == "!") { // !!foo ==> foo, if we're in boolean context return e.expression; } if (e instanceof AST_Binary) { self = best_of(compressor, self, e.negate(compressor, first_in_statement(compressor))); } break; case "typeof": // typeof always returns a non-empty string, thus it's // always true in booleans compressor.warn("Boolean expression always true [{file}:{line},{col}]", self.start); return (e instanceof AST_SymbolRef ? make_node(AST_True, self) : make_sequence(self, [ e, make_node(AST_True, self) ])).optimize(compressor); } } if (self.operator == "-" && e instanceof AST_Infinity) { e = e.transform(compressor); } if (e instanceof AST_Binary && (self.operator == "+" || self.operator == "-") && (e.operator == "*" || e.operator == "/" || e.operator == "%")) { return make_node(AST_Binary, self, { operator: e.operator, left: make_node(AST_UnaryPrefix, e.left, { operator: self.operator, expression: e.left }), right: e.right }); } // avoids infinite recursion of numerals if (self.operator != "-" || !(e instanceof AST_Number || e instanceof AST_Infinity || e instanceof AST_BigInt)) { var ev = self.evaluate(compressor); if (ev !== self) { ev = make_node_from_constant(ev, self).optimize(compressor); return best_of(compressor, ev, self); } } return self; }); AST_Binary.DEFMETHOD("lift_sequences", function(compressor) { if (compressor.option("sequences")) { if (this.left instanceof AST_Sequence) { var x = this.left.expressions.slice(); var e = this.clone(); e.left = x.pop(); x.push(e); return make_sequence(this, x).optimize(compressor); } if (this.right instanceof AST_Sequence && !this.left.has_side_effects(compressor)) { var assign = this.operator == "=" && this.left instanceof AST_SymbolRef; var x = this.right.expressions; var last = x.length - 1; for (var i = 0; i < last; i++) { if (!assign && x[i].has_side_effects(compressor)) break; } if (i == last) { x = x.slice(); var e = this.clone(); e.right = x.pop(); x.push(e); return make_sequence(this, x).optimize(compressor); } else if (i > 0) { var e = this.clone(); e.right = make_sequence(this.right, x.slice(i)); x = x.slice(0, i); x.push(e); return make_sequence(this, x).optimize(compressor); } } } return this; }); var commutativeOperators = makePredicate("== === != !== * & | ^"); function is_object(node) { return node instanceof AST_Array || node instanceof AST_Lambda || node instanceof AST_Object || node instanceof AST_Class; } def_optimize(AST_Binary, function(self, compressor) { function reversible() { return self.left.is_constant() || self.right.is_constant() || !self.left.has_side_effects(compressor) && !self.right.has_side_effects(compressor); } function reverse(op) { if (reversible()) { if (op) self.operator = op; var tmp = self.left; self.left = self.right; self.right = tmp; } } if (commutativeOperators.has(self.operator)) { if (self.right.is_constant() && !self.left.is_constant()) { // if right is a constant, whatever side effects the // left side might have could not influence the // result. hence, force switch. if (!(self.left instanceof AST_Binary && PRECEDENCE[self.left.operator] >= PRECEDENCE[self.operator])) { reverse(); } } } self = self.lift_sequences(compressor); if (compressor.option("comparisons")) switch (self.operator) { case "===": case "!==": var is_strict_comparison = true; if ((self.left.is_string(compressor) && self.right.is_string(compressor)) || (self.left.is_number(compressor) && self.right.is_number(compressor)) || (self.left.is_boolean() && self.right.is_boolean()) || self.left.equivalent_to(self.right)) { self.operator = self.operator.substr(0, 2); } // XXX: intentionally falling down to the next case case "==": case "!=": // void 0 == x => null == x if (!is_strict_comparison && is_undefined(self.left, compressor)) { self.left = make_node(AST_Null, self.left); } else if (compressor.option("typeofs") // "undefined" == typeof x => undefined === x && self.left instanceof AST_String && self.left.value == "undefined" && self.right instanceof AST_UnaryPrefix && self.right.operator == "typeof") { var expr = self.right.expression; if (expr instanceof AST_SymbolRef ? expr.is_declared(compressor) : !(expr instanceof AST_PropAccess && compressor.option("ie8"))) { self.right = expr; self.left = make_node(AST_Undefined, self.left).optimize(compressor); if (self.operator.length == 2) self.operator += "="; } } else if (self.left instanceof AST_SymbolRef // obj !== obj => false && self.right instanceof AST_SymbolRef && self.left.definition() === self.right.definition() && is_object(self.left.fixed_value())) { return make_node(self.operator[0] == "=" ? AST_True : AST_False, self); } break; case "&&": case "||": var lhs = self.left; if (lhs.operator == self.operator) { lhs = lhs.right; } if (lhs instanceof AST_Binary && lhs.operator == (self.operator == "&&" ? "!==" : "===") && self.right instanceof AST_Binary && lhs.operator == self.right.operator && (is_undefined(lhs.left, compressor) && self.right.left instanceof AST_Null || lhs.left instanceof AST_Null && is_undefined(self.right.left, compressor)) && !lhs.right.has_side_effects(compressor) && lhs.right.equivalent_to(self.right.right)) { var combined = make_node(AST_Binary, self, { operator: lhs.operator.slice(0, -1), left: make_node(AST_Null, self), right: lhs.right }); if (lhs !== self.left) { combined = make_node(AST_Binary, self, { operator: self.operator, left: self.left.left, right: combined }); } return combined; } break; } if (self.operator == "+" && compressor.in_boolean_context()) { var ll = self.left.evaluate(compressor); var rr = self.right.evaluate(compressor); if (ll && typeof ll == "string") { compressor.warn("+ in boolean context always true [{file}:{line},{col}]", self.start); return make_sequence(self, [ self.right, make_node(AST_True, self) ]).optimize(compressor); } if (rr && typeof rr == "string") { compressor.warn("+ in boolean context always true [{file}:{line},{col}]", self.start); return make_sequence(self, [ self.left, make_node(AST_True, self) ]).optimize(compressor); } } if (compressor.option("comparisons") && self.is_boolean()) { if (!(compressor.parent() instanceof AST_Binary) || compressor.parent() instanceof AST_Assign) { var negated = make_node(AST_UnaryPrefix, self, { operator: "!", expression: self.negate(compressor, first_in_statement(compressor)) }); self = best_of(compressor, self, negated); } if (compressor.option("unsafe_comps")) { switch (self.operator) { case "<": reverse(">"); break; case "<=": reverse(">="); break; } } } if (self.operator == "+") { if (self.right instanceof AST_String && self.right.getValue() == "" && self.left.is_string(compressor)) { return self.left; } if (self.left instanceof AST_String && self.left.getValue() == "" && self.right.is_string(compressor)) { return self.right; } if (self.left instanceof AST_Binary && self.left.operator == "+" && self.left.left instanceof AST_String && self.left.left.getValue() == "" && self.right.is_string(compressor)) { self.left = self.left.right; return self.transform(compressor); } } if (compressor.option("evaluate")) { switch (self.operator) { case "&&": var ll = self.left.truthy ? true : self.left.falsy ? false : self.left.evaluate(compressor); if (!ll) { compressor.warn("Condition left of && always false [{file}:{line},{col}]", self.start); return maintain_this_binding(compressor.parent(), compressor.self(), self.left).optimize(compressor); } else if (!(ll instanceof AST_Node)) { compressor.warn("Condition left of && always true [{file}:{line},{col}]", self.start); return make_sequence(self, [ self.left, self.right ]).optimize(compressor); } var rr = self.right.evaluate(compressor); if (!rr) { if (compressor.in_boolean_context()) { compressor.warn("Boolean && always false [{file}:{line},{col}]", self.start); return make_sequence(self, [ self.left, make_node(AST_False, self) ]).optimize(compressor); } else self.falsy = true; } else if (!(rr instanceof AST_Node)) { var parent = compressor.parent(); if (parent.operator == "&&" && parent.left === compressor.self() || compressor.in_boolean_context()) { compressor.warn("Dropping side-effect-free && [{file}:{line},{col}]", self.start); return self.left.optimize(compressor); } } // x || false && y ---> x ? y : false if (self.left.operator == "||") { var lr = self.left.right.evaluate(compressor); if (!lr) return make_node(AST_Conditional, self, { condition: self.left.left, consequent: self.right, alternative: self.left.right }).optimize(compressor); } break; case "||": var ll = self.left.truthy ? true : self.left.falsy ? false : self.left.evaluate(compressor); if (!ll) { compressor.warn("Condition left of || always false [{file}:{line},{col}]", self.start); return make_sequence(self, [ self.left, self.right ]).optimize(compressor); } else if (!(ll instanceof AST_Node)) { compressor.warn("Condition left of || always true [{file}:{line},{col}]", self.start); return maintain_this_binding(compressor.parent(), compressor.self(), self.left).optimize(compressor); } var rr = self.right.evaluate(compressor); if (!rr) { var parent = compressor.parent(); if (parent.operator == "||" && parent.left === compressor.self() || compressor.in_boolean_context()) { compressor.warn("Dropping side-effect-free || [{file}:{line},{col}]", self.start); return self.left.optimize(compressor); } } else if (!(rr instanceof AST_Node)) { if (compressor.in_boolean_context()) { compressor.warn("Boolean || always true [{file}:{line},{col}]", self.start); return make_sequence(self, [ self.left, make_node(AST_True, self) ]).optimize(compressor); } else self.truthy = true; } if (self.left.operator == "&&") { var lr = self.left.right.evaluate(compressor); if (lr && !(lr instanceof AST_Node)) return make_node(AST_Conditional, self, { condition: self.left.left, consequent: self.left.right, alternative: self.right }).optimize(compressor); } break; } var associative = true; switch (self.operator) { case "+": // "foo" + ("bar" + x) => "foobar" + x if (self.left instanceof AST_Constant && self.right instanceof AST_Binary && self.right.operator == "+" && self.right.left instanceof AST_Constant && self.right.is_string(compressor)) { self = make_node(AST_Binary, self, { operator: "+", left: make_node(AST_String, self.left, { value: "" + self.left.getValue() + self.right.left.getValue(), start: self.left.start, end: self.right.left.end }), right: self.right.right }); } // (x + "foo") + "bar" => x + "foobar" if (self.right instanceof AST_Constant && self.left instanceof AST_Binary && self.left.operator == "+" && self.left.right instanceof AST_Constant && self.left.is_string(compressor)) { self = make_node(AST_Binary, self, { operator: "+", left: self.left.left, right: make_node(AST_String, self.right, { value: "" + self.left.right.getValue() + self.right.getValue(), start: self.left.right.start, end: self.right.end }) }); } // (x + "foo") + ("bar" + y) => (x + "foobar") + y if (self.left instanceof AST_Binary && self.left.operator == "+" && self.left.is_string(compressor) && self.left.right instanceof AST_Constant && self.right instanceof AST_Binary && self.right.operator == "+" && self.right.left instanceof AST_Constant && self.right.is_string(compressor)) { self = make_node(AST_Binary, self, { operator: "+", left: make_node(AST_Binary, self.left, { operator: "+", left: self.left.left, right: make_node(AST_String, self.left.right, { value: "" + self.left.right.getValue() + self.right.left.getValue(), start: self.left.right.start, end: self.right.left.end }) }), right: self.right.right }); } // a + -b => a - b if (self.right instanceof AST_UnaryPrefix && self.right.operator == "-" && self.left.is_number(compressor)) { self = make_node(AST_Binary, self, { operator: "-", left: self.left, right: self.right.expression }); break; } // -a + b => b - a if (self.left instanceof AST_UnaryPrefix && self.left.operator == "-" && reversible() && self.right.is_number(compressor)) { self = make_node(AST_Binary, self, { operator: "-", left: self.right, right: self.left.expression }); break; } case "*": associative = compressor.option("unsafe_math"); case "&": case "|": case "^": // a + +b => +b + a if (self.left.is_number(compressor) && self.right.is_number(compressor) && reversible() && !(self.left instanceof AST_Binary && self.left.operator != self.operator && PRECEDENCE[self.left.operator] >= PRECEDENCE[self.operator])) { var reversed = make_node(AST_Binary, self, { operator: self.operator, left: self.right, right: self.left }); if (self.right instanceof AST_Constant && !(self.left instanceof AST_Constant)) { self = best_of(compressor, reversed, self); } else { self = best_of(compressor, self, reversed); } } if (associative && self.is_number(compressor)) { // a + (b + c) => (a + b) + c if (self.right instanceof AST_Binary && self.right.operator == self.operator) { self = make_node(AST_Binary, self, { operator: self.operator, left: make_node(AST_Binary, self.left, { operator: self.operator, left: self.left, right: self.right.left, start: self.left.start, end: self.right.left.end }), right: self.right.right }); } // (n + 2) + 3 => 5 + n // (2 * n) * 3 => 6 + n if (self.right instanceof AST_Constant && self.left instanceof AST_Binary && self.left.operator == self.operator) { if (self.left.left instanceof AST_Constant) { self = make_node(AST_Binary, self, { operator: self.operator, left: make_node(AST_Binary, self.left, { operator: self.operator, left: self.left.left, right: self.right, start: self.left.left.start, end: self.right.end }), right: self.left.right }); } else if (self.left.right instanceof AST_Constant) { self = make_node(AST_Binary, self, { operator: self.operator, left: make_node(AST_Binary, self.left, { operator: self.operator, left: self.left.right, right: self.right, start: self.left.right.start, end: self.right.end }), right: self.left.left }); } } // (a | 1) | (2 | d) => (3 | a) | b if (self.left instanceof AST_Binary && self.left.operator == self.operator && self.left.right instanceof AST_Constant && self.right instanceof AST_Binary && self.right.operator == self.operator && self.right.left instanceof AST_Constant) { self = make_node(AST_Binary, self, { operator: self.operator, left: make_node(AST_Binary, self.left, { operator: self.operator, left: make_node(AST_Binary, self.left.left, { operator: self.operator, left: self.left.right, right: self.right.left, start: self.left.right.start, end: self.right.left.end }), right: self.left.left }), right: self.right.right }); } } } } // x && (y && z) ==> x && y && z // x || (y || z) ==> x || y || z // x + ("y" + z) ==> x + "y" + z // "x" + (y + "z")==> "x" + y + "z" if (self.right instanceof AST_Binary && self.right.operator == self.operator && (lazy_op.has(self.operator) || (self.operator == "+" && (self.right.left.is_string(compressor) || (self.left.is_string(compressor) && self.right.right.is_string(compressor))))) ) { self.left = make_node(AST_Binary, self.left, { operator : self.operator, left : self.left, right : self.right.left }); self.right = self.right.right; return self.transform(compressor); } var ev = self.evaluate(compressor); if (ev !== self) { ev = make_node_from_constant(ev, self).optimize(compressor); return best_of(compressor, ev, self); } return self; }); def_optimize(AST_SymbolExport, function(self, compressor) { return self; }); function recursive_ref(compressor, def) { var node; for (var i = 0; node = compressor.parent(i); i++) { if (node instanceof AST_Lambda) { var name = node.name; if (name && name.definition() === def) break; } } return node; } function within_array_or_object_literal(compressor) { var node, level = 0; while (node = compressor.parent(level++)) { if (node instanceof AST_Statement) return false; if (node instanceof AST_Array || node instanceof AST_ObjectKeyVal || node instanceof AST_Object) { return true; } } return false; } def_optimize(AST_SymbolRef, function(self, compressor) { if (!compressor.option("ie8") && is_undeclared_ref(self) && (!self.scope.uses_with || !compressor.find_parent(AST_With))) { switch (self.name) { case "undefined": return make_node(AST_Undefined, self).optimize(compressor); case "NaN": return make_node(AST_NaN, self).optimize(compressor); case "Infinity": return make_node(AST_Infinity, self).optimize(compressor); } } var parent = compressor.parent(); if (compressor.option("reduce_vars") && is_lhs(self, parent) !== self) { var d = self.definition(); if (compressor.top_retain && d.global && compressor.top_retain(d)) { d.fixed = false; d.should_replace = false; d.single_use = false; return self; } var fixed = self.fixed_value(); var single_use = d.single_use && !(parent instanceof AST_Call && parent.is_expr_pure(compressor)); if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) { if (retain_top_func(fixed, compressor)) { single_use = false; } else if (d.scope !== self.scope && (!compressor.option("reduce_funcs") && fixed instanceof AST_Lambda || d.escaped == 1 || fixed.inlined || within_array_or_object_literal(compressor))) { single_use = false; } else if (recursive_ref(compressor, d)) { single_use = false; } else if (d.scope !== self.scope || d.orig[0] instanceof AST_SymbolFunarg) { single_use = fixed.is_constant_expression(self.scope); if (single_use == "f") { var scope = self.scope; do { if (scope instanceof AST_Defun || is_func_expr(scope)) { scope.inlined = true; } } while (scope = scope.parent_scope); } } } if (single_use && fixed) { if (fixed instanceof AST_DefClass) { fixed = make_node(AST_ClassExpression, fixed, fixed); } if (fixed instanceof AST_Defun) { fixed._squeezed = true; fixed = make_node(AST_Function, fixed, fixed); } var value; if (d.recursive_refs > 0 && fixed.name instanceof AST_SymbolDefun) { value = fixed.clone(true); var defun_def = value.name.definition(); var lambda_def = value.variables.get(value.name.name); var name = lambda_def && lambda_def.orig[0]; if (!(name instanceof AST_SymbolLambda)) { name = make_node(AST_SymbolLambda, value.name, value.name); name.scope = value; value.name = name; lambda_def = value.def_function(name); } value.walk(new TreeWalker(function(node) { if (node instanceof AST_SymbolRef && node.definition() === defun_def) { node.thedef = lambda_def; lambda_def.references.push(node); } })); } else { value = fixed.optimize(compressor); if (value === fixed) value = fixed.clone(true); } return value; } if (fixed && d.should_replace === undefined) { var init; if (fixed instanceof AST_This) { if (!(d.orig[0] instanceof AST_SymbolFunarg) && d.references.every((ref) => d.scope === ref.scope )) { init = fixed; } } else { var ev = fixed.evaluate(compressor); if (ev !== fixed && (compressor.option("unsafe_regexp") || !(ev instanceof RegExp))) { init = make_node_from_constant(ev, fixed); } } if (init) { var value_length = init.optimize(compressor).print_to_string().length; var fn; if (has_symbol_ref(fixed)) { fn = function() { var result = init.optimize(compressor); return result === init ? result.clone(true) : result; }; } else { value_length = Math.min(value_length, fixed.print_to_string().length); fn = function() { var result = best_of_expression(init.optimize(compressor), fixed); return result === init || result === fixed ? result.clone(true) : result; }; } var name_length = d.name.length; var overhead = 0; if (compressor.option("unused") && !compressor.exposed(d)) { overhead = (name_length + 2 + value_length) / (d.references.length - d.assignments); } d.should_replace = value_length <= name_length + overhead ? fn : false; } else { d.should_replace = false; } } if (d.should_replace) { return d.should_replace(); } } return self; function has_symbol_ref(value) { var found; value.walk(new TreeWalker(function(node) { if (node instanceof AST_SymbolRef) found = true; if (found) return true; })); return found; } }); function is_atomic(lhs, self) { return lhs instanceof AST_SymbolRef || lhs.TYPE === self.TYPE; } def_optimize(AST_Undefined, function(self, compressor) { if (compressor.option("unsafe_undefined")) { var undef = find_variable(compressor, "undefined"); if (undef) { var ref = make_node(AST_SymbolRef, self, { name : "undefined", scope : undef.scope, thedef : undef }); ref.is_undefined = true; return ref; } } var lhs = is_lhs(compressor.self(), compressor.parent()); if (lhs && is_atomic(lhs, self)) return self; return make_node(AST_UnaryPrefix, self, { operator: "void", expression: make_node(AST_Number, self, { value: 0 }) }); }); def_optimize(AST_Infinity, function(self, compressor) { var lhs = is_lhs(compressor.self(), compressor.parent()); if (lhs && is_atomic(lhs, self)) return self; if (compressor.option("keep_infinity") && !(lhs && !is_atomic(lhs, self)) && !find_variable(compressor, "Infinity")) return self; return make_node(AST_Binary, self, { operator: "/", left: make_node(AST_Number, self, { value: 1 }), right: make_node(AST_Number, self, { value: 0 }) }); }); def_optimize(AST_NaN, function(self, compressor) { var lhs = is_lhs(compressor.self(), compressor.parent()); if (lhs && !is_atomic(lhs, self) || find_variable(compressor, "NaN")) { return make_node(AST_Binary, self, { operator: "/", left: make_node(AST_Number, self, { value: 0 }), right: make_node(AST_Number, self, { value: 0 }) }); } return self; }); function is_reachable(self, defs) { var reachable = false; var find_ref = new TreeWalker(function(node) { if (reachable) return true; if (node instanceof AST_SymbolRef && member(node.definition(), defs)) { return reachable = true; } }); var scan_scope = new TreeWalker(function(node) { if (reachable) return true; if (node instanceof AST_Scope && node !== self) { var parent = scan_scope.parent(); if (parent instanceof AST_Call && parent.expression === node) return; node.walk(find_ref); return true; } }); self.walk(scan_scope); return reachable; } const ASSIGN_OPS = makePredicate("+ - / * % >> << >>> | ^ &"); const ASSIGN_OPS_COMMUTATIVE = makePredicate("* | ^ &"); def_optimize(AST_Assign, function(self, compressor) { var def; if (compressor.option("dead_code") && self.left instanceof AST_SymbolRef && (def = self.left.definition()).scope === compressor.find_parent(AST_Lambda)) { var level = 0, node, parent = self; do { node = parent; parent = compressor.parent(level++); if (parent instanceof AST_Exit) { if (in_try(level, parent)) break; if (is_reachable(def.scope, [ def ])) break; if (self.operator == "=") return self.right; def.fixed = false; return make_node(AST_Binary, self, { operator: self.operator.slice(0, -1), left: self.left, right: self.right }).optimize(compressor); } } while (parent instanceof AST_Binary && parent.right === node || parent instanceof AST_Sequence && parent.tail_node() === node); } self = self.lift_sequences(compressor); if (self.operator == "=" && self.left instanceof AST_SymbolRef && self.right instanceof AST_Binary) { // x = expr1 OP expr2 if (self.right.left instanceof AST_SymbolRef && self.right.left.name == self.left.name && ASSIGN_OPS.has(self.right.operator)) { // x = x - 2 ---> x -= 2 self.operator = self.right.operator + "="; self.right = self.right.right; } else if (self.right.right instanceof AST_SymbolRef && self.right.right.name == self.left.name && ASSIGN_OPS_COMMUTATIVE.has(self.right.operator) && !self.right.left.has_side_effects(compressor)) { // x = 2 & x ---> x &= 2 self.operator = self.right.operator + "="; self.right = self.right.left; } } return self; function in_try(level, node) { var right = self.right; self.right = make_node(AST_Null, right); var may_throw = node.may_throw(compressor); self.right = right; var scope = self.left.definition().scope; var parent; while ((parent = compressor.parent(level++)) !== scope) { if (parent instanceof AST_Try) { if (parent.bfinally) return true; if (may_throw && parent.bcatch) return true; } } } }); def_optimize(AST_DefaultAssign, function(self, compressor) { if (!compressor.option("evaluate")) { return self; } var evaluateRight = self.right.evaluate(compressor); // `[x = undefined] = foo` ---> `[x] = foo` if (evaluateRight === undefined) { self = self.left; } else if (evaluateRight !== self.right) { evaluateRight = make_node_from_constant(evaluateRight, self.right); self.right = best_of_expression(evaluateRight, self.right); } return self; }); def_optimize(AST_Conditional, function(self, compressor) { if (!compressor.option("conditionals")) return self; // This looks like lift_sequences(), should probably be under "sequences" if (self.condition instanceof AST_Sequence) { var expressions = self.condition.expressions.slice(); self.condition = expressions.pop(); expressions.push(self); return make_sequence(self, expressions); } var cond = self.condition.evaluate(compressor); if (cond !== self.condition) { if (cond) { compressor.warn("Condition always true [{file}:{line},{col}]", self.start); return maintain_this_binding(compressor.parent(), compressor.self(), self.consequent); } else { compressor.warn("Condition always false [{file}:{line},{col}]", self.start); return maintain_this_binding(compressor.parent(), compressor.self(), self.alternative); } } var negated = cond.negate(compressor, first_in_statement(compressor)); if (best_of(compressor, cond, negated) === negated) { self = make_node(AST_Conditional, self, { condition: negated, consequent: self.alternative, alternative: self.consequent }); } var condition = self.condition; var consequent = self.consequent; var alternative = self.alternative; // x?x:y --> x||y if (condition instanceof AST_SymbolRef && consequent instanceof AST_SymbolRef && condition.definition() === consequent.definition()) { return make_node(AST_Binary, self, { operator: "||", left: condition, right: alternative }); } // if (foo) exp = something; else exp = something_else; // | // v // exp = foo ? something : something_else; if (consequent instanceof AST_Assign && alternative instanceof AST_Assign && consequent.operator == alternative.operator && consequent.left.equivalent_to(alternative.left) && (!self.condition.has_side_effects(compressor) || consequent.operator == "=" && !consequent.left.has_side_effects(compressor))) { return make_node(AST_Assign, self, { operator: consequent.operator, left: consequent.left, right: make_node(AST_Conditional, self, { condition: self.condition, consequent: consequent.right, alternative: alternative.right }) }); } // x ? y(a) : y(b) --> y(x ? a : b) var arg_index; if (consequent instanceof AST_Call && alternative.TYPE === consequent.TYPE && consequent.args.length > 0 && consequent.args.length == alternative.args.length && consequent.expression.equivalent_to(alternative.expression) && !self.condition.has_side_effects(compressor) && !consequent.expression.has_side_effects(compressor) && typeof (arg_index = single_arg_diff()) == "number") { var node = consequent.clone(); node.args[arg_index] = make_node(AST_Conditional, self, { condition: self.condition, consequent: consequent.args[arg_index], alternative: alternative.args[arg_index] }); return node; } // x?y?z:a:a --> x&&y?z:a if (consequent instanceof AST_Conditional && consequent.alternative.equivalent_to(alternative)) { return make_node(AST_Conditional, self, { condition: make_node(AST_Binary, self, { left: self.condition, operator: "&&", right: consequent.condition }), consequent: consequent.consequent, alternative: alternative }); } // x ? y : y --> x, y if (consequent.equivalent_to(alternative)) { return make_sequence(self, [ self.condition, consequent ]).optimize(compressor); } // x ? y || z : z --> x && y || z if (consequent instanceof AST_Binary && consequent.operator == "||" && consequent.right.equivalent_to(alternative)) { return make_node(AST_Binary, self, { operator: "||", left: make_node(AST_Binary, self, { operator: "&&", left: self.condition, right: consequent.left }), right: alternative }).optimize(compressor); } var in_bool = compressor.in_boolean_context(); if (is_true(self.consequent)) { if (is_false(self.alternative)) { // c ? true : false ---> !!c return booleanize(self.condition); } // c ? true : x ---> !!c || x return make_node(AST_Binary, self, { operator: "||", left: booleanize(self.condition), right: self.alternative }); } if (is_false(self.consequent)) { if (is_true(self.alternative)) { // c ? false : true ---> !c return booleanize(self.condition.negate(compressor)); } // c ? false : x ---> !c && x return make_node(AST_Binary, self, { operator: "&&", left: booleanize(self.condition.negate(compressor)), right: self.alternative }); } if (is_true(self.alternative)) { // c ? x : true ---> !c || x return make_node(AST_Binary, self, { operator: "||", left: booleanize(self.condition.negate(compressor)), right: self.consequent }); } if (is_false(self.alternative)) { // c ? x : false ---> !!c && x return make_node(AST_Binary, self, { operator: "&&", left: booleanize(self.condition), right: self.consequent }); } return self; function booleanize(node) { if (node.is_boolean()) return node; // !!expression return make_node(AST_UnaryPrefix, node, { operator: "!", expression: node.negate(compressor) }); } // AST_True or !0 function is_true(node) { return node instanceof AST_True || in_bool && node instanceof AST_Constant && node.getValue() || (node instanceof AST_UnaryPrefix && node.operator == "!" && node.expression instanceof AST_Constant && !node.expression.getValue()); } // AST_False or !1 function is_false(node) { return node instanceof AST_False || in_bool && node instanceof AST_Constant && !node.getValue() || (node instanceof AST_UnaryPrefix && node.operator == "!" && node.expression instanceof AST_Constant && node.expression.getValue()); } function single_arg_diff() { var a = consequent.args; var b = alternative.args; for (var i = 0, len = a.length; i < len; i++) { if (a[i] instanceof AST_Expansion) return; if (!a[i].equivalent_to(b[i])) { if (b[i] instanceof AST_Expansion) return; for (var j = i + 1; j < len; j++) { if (a[j] instanceof AST_Expansion) return; if (!a[j].equivalent_to(b[j])) return; } return i; } } } }); def_optimize(AST_Boolean, function(self, compressor) { if (compressor.in_boolean_context()) return make_node(AST_Number, self, { value: +self.value }); var p = compressor.parent(); if (compressor.option("booleans_as_integers")) { if (p instanceof AST_Binary && (p.operator == "===" || p.operator == "!==")) { p.operator = p.operator.replace(/=$/, ""); } return make_node(AST_Number, self, { value: +self.value }); } if (compressor.option("booleans")) { if (p instanceof AST_Binary && (p.operator == "==" || p.operator == "!=")) { compressor.warn("Non-strict equality against boolean: {operator} {value} [{file}:{line},{col}]", { operator : p.operator, value : self.value, file : p.start.file, line : p.start.line, col : p.start.col, }); return make_node(AST_Number, self, { value: +self.value }); } return make_node(AST_UnaryPrefix, self, { operator: "!", expression: make_node(AST_Number, self, { value: 1 - self.value }) }); } return self; }); function safe_to_flatten(value, compressor) { if (value instanceof AST_SymbolRef) { value = value.fixed_value(); } if (!value) return false; return !(value instanceof AST_Lambda || value instanceof AST_Class) || compressor.parent() instanceof AST_New || !value.contains_this(); } def_optimize(AST_Sub, function(self, compressor) { var expr = self.expression; var prop = self.property; if (compressor.option("properties")) { var key = prop.evaluate(compressor); if (key !== prop) { if (typeof key == "string") { if (key == "undefined") { key = undefined; } else { var value = parseFloat(key); if (value.toString() == key) { key = value; } } } prop = self.property = best_of_expression(prop, make_node_from_constant(key, prop).transform(compressor)); var property = "" + key; if (is_identifier_string(property) && property.length <= prop.print_to_string().length + 1) { return make_node(AST_Dot, self, { expression: expr, property: property, quote: prop.quote, }).optimize(compressor); } } } var fn; OPT_ARGUMENTS: if (compressor.option("arguments") && expr instanceof AST_SymbolRef && expr.name == "arguments" && expr.definition().orig.length == 1 && (fn = expr.scope) instanceof AST_Lambda && fn.uses_arguments && !(fn instanceof AST_Arrow) && prop instanceof AST_Number) { var index = prop.getValue(); var params = new Set(); var argnames = fn.argnames; for (var n = 0; n < argnames.length; n++) { if (!(argnames[n] instanceof AST_SymbolFunarg)) { break OPT_ARGUMENTS; // destructuring parameter - bail } var param = argnames[n].name; if (params.has(param)) { break OPT_ARGUMENTS; // duplicate parameter - bail } params.add(param); } var argname = fn.argnames[index]; if (argname && compressor.has_directive("use strict")) { var def = argname.definition(); if (!compressor.option("reduce_vars") || def.assignments || def.orig.length > 1) { argname = null; } } else if (!argname && !compressor.option("keep_fargs") && index < fn.argnames.length + 5) { while (index >= fn.argnames.length) { argname = make_node(AST_SymbolFunarg, fn, { name: fn.make_var_name("argument_" + fn.argnames.length), scope: fn }); fn.argnames.push(argname); fn.enclosed.push(fn.def_variable(argname)); } } if (argname) { var sym = make_node(AST_SymbolRef, self, argname); sym.reference({}); delete argname.__unused; return sym; } } if (is_lhs(self, compressor.parent())) return self; if (key !== prop) { var sub = self.flatten_object(property, compressor); if (sub) { expr = self.expression = sub.expression; prop = self.property = sub.property; } } if (compressor.option("properties") && compressor.option("side_effects") && prop instanceof AST_Number && expr instanceof AST_Array) { var index = prop.getValue(); var elements = expr.elements; var retValue = elements[index]; FLATTEN: if (safe_to_flatten(retValue, compressor)) { var flatten = true; var values = []; for (var i = elements.length; --i > index;) { var value = elements[i].drop_side_effect_free(compressor); if (value) { values.unshift(value); if (flatten && value.has_side_effects(compressor)) flatten = false; } } if (retValue instanceof AST_Expansion) break FLATTEN; retValue = retValue instanceof AST_Hole ? make_node(AST_Undefined, retValue) : retValue; if (!flatten) values.unshift(retValue); while (--i >= 0) { var value = elements[i]; if (value instanceof AST_Expansion) break FLATTEN; value = value.drop_side_effect_free(compressor); if (value) values.unshift(value); else index--; } if (flatten) { values.push(retValue); return make_sequence(self, values).optimize(compressor); } else return make_node(AST_Sub, self, { expression: make_node(AST_Array, expr, { elements: values }), property: make_node(AST_Number, prop, { value: index }) }); } } var ev = self.evaluate(compressor); if (ev !== self) { ev = make_node_from_constant(ev, self).optimize(compressor); return best_of(compressor, ev, self); } return self; }); AST_Lambda.DEFMETHOD("contains_this", function() { var result; var self = this; self.walk(new TreeWalker(function(node) { if (result) return true; if (node instanceof AST_This) return result = true; if (node !== self && node instanceof AST_Scope && !(node instanceof AST_Arrow)) return true; })); return result; }); AST_PropAccess.DEFMETHOD("flatten_object", function(key, compressor) { if (!compressor.option("properties")) return; var arrows = compressor.option("unsafe_arrows") && compressor.option("ecma") >= 6; var expr = this.expression; if (expr instanceof AST_Object) { var props = expr.properties; for (var i = props.length; --i >= 0;) { var prop = props[i]; if ("" + (prop instanceof AST_ConciseMethod ? prop.key.name : prop.key) == key) { if (!props.every((prop) => { return prop instanceof AST_ObjectKeyVal || arrows && prop instanceof AST_ConciseMethod && !prop.is_generator; })) break; if (!safe_to_flatten(prop.value, compressor)) break; return make_node(AST_Sub, this, { expression: make_node(AST_Array, expr, { elements: props.map(function(prop) { var v = prop.value; if (v instanceof AST_Accessor) v = make_node(AST_Function, v, v); var k = prop.key; if (k instanceof AST_Node && !(k instanceof AST_SymbolMethod)) { return make_sequence(prop, [ k, v ]); } return v; }) }), property: make_node(AST_Number, this, { value: i }) }); } } } }); def_optimize(AST_Dot, function(self, compressor) { if (self.property == "arguments" || self.property == "caller") { compressor.warn("Function.prototype.{prop} not supported [{file}:{line},{col}]", { prop: self.property, file: self.start.file, line: self.start.line, col: self.start.col }); } if (is_lhs(self, compressor.parent())) return self; if (compressor.option("unsafe_proto") && self.expression instanceof AST_Dot && self.expression.property == "prototype") { var exp = self.expression.expression; if (is_undeclared_ref(exp)) switch (exp.name) { case "Array": self.expression = make_node(AST_Array, self.expression, { elements: [] }); break; case "Function": self.expression = make_node(AST_Function, self.expression, { argnames: [], body: [] }); break; case "Number": self.expression = make_node(AST_Number, self.expression, { value: 0 }); break; case "Object": self.expression = make_node(AST_Object, self.expression, { properties: [] }); break; case "RegExp": self.expression = make_node(AST_RegExp, self.expression, { value: /t/ }); break; case "String": self.expression = make_node(AST_String, self.expression, { value: "" }); break; } } var sub = self.flatten_object(self.property, compressor); if (sub) return sub.optimize(compressor); var ev = self.evaluate(compressor); if (ev !== self) { ev = make_node_from_constant(ev, self).optimize(compressor); return best_of(compressor, ev, self); } return self; }); function literals_in_boolean_context(self, compressor) { if (compressor.in_boolean_context()) { return best_of(compressor, self, make_sequence(self, [ self, make_node(AST_True, self) ]).optimize(compressor)); } return self; } function inline_array_like_spread(self, compressor, elements) { for (var i = 0; i < elements.length; i++) { var el = elements[i]; if (el instanceof AST_Expansion) { var expr = el.expression; if ( expr instanceof AST_Array) { elements.splice.apply(elements, [i, 1].concat(expr.elements)); // Step back one, as the element at i is now new. i--; } // In array-like spread, spreading a non-iterable value is TypeError. // We therefore can’t optimize anything else, unlike with object spread. } } return self; } def_optimize(AST_Array, function(self, compressor) { var optimized = literals_in_boolean_context(self, compressor); if (optimized !== self) { return optimized; } return inline_array_like_spread(self, compressor, self.elements); }); def_optimize(AST_Object, function(self, compressor) { var optimized = literals_in_boolean_context(self, compressor); if (optimized !== self) { return optimized; } var props = self.properties; for (var i = 0; i < props.length; i++) { var prop = props[i]; if (prop instanceof AST_Expansion) { var expr = prop.expression; if (expr instanceof AST_Object) { props.splice.apply(props, [i, 1].concat(prop.expression.properties)); // Step back one, as the property at i is now new. i--; } else if (expr instanceof AST_Constant && !(expr instanceof AST_String)) { // Unlike array-like spread, in object spread, spreading a // non-iterable value silently does nothing; it is thus safe // to remove. AST_String is the only iterable AST_Constant. props.splice(i, 1); } } } return self; }); def_optimize(AST_RegExp, literals_in_boolean_context); def_optimize(AST_Return, function(self, compressor) { if (self.value && is_undefined(self.value, compressor)) { self.value = null; } return self; }); def_optimize(AST_Arrow, function(self, compressor) { if (!(self.body instanceof AST_Node)) { self = opt_AST_Lambda(self, compressor); } if (compressor.option("arrows") && self.body.length == 1 && self.body[0] instanceof AST_Return) { var value = self.body[0].value; self.body = value ? value : []; } return self; }); def_optimize(AST_Function, function(self, compressor) { self = opt_AST_Lambda(self, compressor); if (compressor.option("unsafe_arrows") && compressor.option("ecma") >= 6 && !self.name && !self.is_generator && !self.uses_arguments && !self.pinned()) { var has_special_symbol = false; self.walk(new TreeWalker(function(node) { if (has_special_symbol) return true; if (node instanceof AST_This) { has_special_symbol = true; return true; } })); if (!has_special_symbol) return make_node(AST_Arrow, self, self).optimize(compressor); } return self; }); def_optimize(AST_Class, function(self, compressor) { // HACK to avoid compress failure. // AST_Class is not really an AST_Scope/AST_Block as it lacks a body. return self; }); def_optimize(AST_Yield, function(self, compressor) { if (self.expression && !self.is_star && is_undefined(self.expression, compressor)) { self.expression = null; } return self; }); def_optimize(AST_TemplateString, function(self, compressor) { if (!compressor.option("evaluate") || compressor.parent() instanceof AST_PrefixedTemplateString) return self; var segments = []; for (var i = 0; i < self.segments.length; i++) { var segment = self.segments[i]; if (segment instanceof AST_Node) { var result = segment.evaluate(compressor); // Evaluate to constant value // Constant value shorter than ${segment} if (result !== segment && (result + "").length <= segment.print_to_string().length + "${}".length) { // There should always be a previous and next segment if segment is a node segments[segments.length - 1].value = segments[segments.length - 1].value + result + self.segments[++i].value; continue; } } segments.push(segment); } self.segments = segments; return segments.length == 1 ? make_node(AST_String, self, segments[0]) : self; }); def_optimize(AST_PrefixedTemplateString, function(self, compressor) { return self; }); // ["p"]:1 ---> p:1 // [42]:1 ---> 42:1 function lift_key(self, compressor) { if (!compressor.option("computed_props")) return self; // save a comparison in the typical case if (!(self.key instanceof AST_Constant)) return self; // whitelist acceptable props as not all AST_Constants are true constants if (self.key instanceof AST_String || self.key instanceof AST_Number) { if (self.key.value === "__proto__") return self; if (self.key.value == "constructor" && compressor.parent() instanceof AST_Class) return self; if (self instanceof AST_ObjectKeyVal) { self.key = self.key.value; } else { self.key = make_node(AST_SymbolMethod, self.key, { name: self.key.value }); } } return self; } def_optimize(AST_ObjectProperty, lift_key); def_optimize(AST_ConciseMethod, function(self, compressor) { lift_key(self, compressor); // p(){return x;} ---> p:()=>x if (compressor.option("arrows") && compressor.parent() instanceof AST_Object && !self.is_generator && !self.value.uses_arguments && !self.value.pinned() && self.value.body.length == 1 && self.value.body[0] instanceof AST_Return && self.value.body[0].value && !self.value.contains_this()) { var arrow = make_node(AST_Arrow, self.value, self.value); arrow.async = self.async; arrow.is_generator = self.is_generator; return make_node(AST_ObjectKeyVal, self, { key: self.key instanceof AST_SymbolMethod ? self.key.name : self.key, value: arrow, quote: self.quote, }); } return self; }); def_optimize(AST_ObjectKeyVal, function(self, compressor) { lift_key(self, compressor); // p:function(){} ---> p(){} // p:function*(){} ---> *p(){} // p:async function(){} ---> async p(){} // p:()=>{} ---> p(){} // p:async()=>{} ---> async p(){} var unsafe_methods = compressor.option("unsafe_methods"); if (unsafe_methods && compressor.option("ecma") >= 6 && (!(unsafe_methods instanceof RegExp) || unsafe_methods.test(self.key + ""))) { var key = self.key; var value = self.value; var is_arrow_with_block = value instanceof AST_Arrow && Array.isArray(value.body) && !value.contains_this(); if ((is_arrow_with_block || value instanceof AST_Function) && !value.name) { return make_node(AST_ConciseMethod, self, { async: value.async, is_generator: value.is_generator, key: key instanceof AST_Node ? key : make_node(AST_SymbolMethod, self, { name: key, }), value: make_node(AST_Accessor, value, value), quote: self.quote, }); } } return self; }); def_optimize(AST_Destructuring, function(self, compressor) { if (compressor.option("pure_getters") == true && compressor.option("unused") && !self.is_array && Array.isArray(self.names) && !is_destructuring_export_decl(compressor)) { var keep = []; for (var i = 0; i < self.names.length; i++) { var elem = self.names[i]; if (!(elem instanceof AST_ObjectKeyVal && typeof elem.key == "string" && elem.value instanceof AST_SymbolDeclaration && !should_retain(compressor, elem.value.definition()))) { keep.push(elem); } } if (keep.length != self.names.length) { self.names = keep; } } return self; function is_destructuring_export_decl(compressor) { var ancestors = [/^VarDef$/, /^(Const|Let|Var)$/, /^Export$/]; for (var a = 0, p = 0, len = ancestors.length; a < len; p++) { var parent = compressor.parent(p); if (!parent) return false; if (a === 0 && parent.TYPE == "Destructuring") continue; if (!ancestors[a].test(parent.TYPE)) { return false; } a++; } return true; } function should_retain(compressor, def) { if (def.references.length) return true; if (!def.global) return false; if (compressor.toplevel.vars) { if (compressor.top_retain) { return compressor.top_retain(def); } return false; } return true; } }); })(); export { Compressor, }; terser-4.1.2/lib/minify.js000066400000000000000000000241451351061312300154220ustar00rootroot00000000000000"use strict"; /* eslint-env browser, es6, node */ import { defaults, map_from_object, map_to_object, HOP, } from "./utils/index.js"; import { AST_Node, AST_Toplevel, } from "./ast.js"; import { parse } from "./parse.js"; import { OutputStream } from "./output.js"; import { Compressor } from "./compress/index.js"; import { base54 } from "./scope.js"; import { SourceMap } from "./sourcemap.js"; import { mangle_properties, reserve_quoted_keys, } from "./propmangle.js"; var to_ascii = typeof atob == "undefined" ? function(b64) { return Buffer.from(b64, "base64").toString(); } : atob; var to_base64 = typeof btoa == "undefined" ? function(str) { return Buffer.from(str).toString("base64"); } : btoa; function read_source_map(code) { var match = /(?:^|[^.])\/\/# sourceMappingURL=data:application\/json(;[\w=-]*)?;base64,([+/0-9A-Za-z]*=*)\s*$/.exec(code); if (!match) { AST_Node.warn("inline source map not found"); return null; } return to_ascii(match[2]); } function set_shorthand(name, options, keys) { if (options[name]) { keys.forEach(function(key) { if (options[key]) { if (typeof options[key] != "object") options[key] = {}; if (!(name in options[key])) options[key][name] = options[name]; } }); } } function init_cache(cache) { if (!cache) return; if (!("props" in cache)) { cache.props = new Map(); } else if (!(cache.props instanceof Map)) { cache.props = map_from_object(cache.props); } } function to_json(cache) { return { props: map_to_object(cache.props) }; } function minify(files, options) { var warn_function = AST_Node.warn_function; try { options = defaults(options, { compress: {}, ecma: undefined, enclose: false, ie8: false, keep_classnames: undefined, keep_fnames: false, mangle: {}, module: false, nameCache: null, output: {}, parse: {}, rename: undefined, safari10: false, sourceMap: false, timings: false, toplevel: false, warnings: false, wrap: false, }, true); var timings = options.timings && { start: Date.now() }; if (options.keep_classnames === undefined) { options.keep_classnames = options.keep_fnames; } if (options.rename === undefined) { options.rename = options.compress && options.mangle; } set_shorthand("ecma", options, [ "parse", "compress", "output" ]); set_shorthand("ie8", options, [ "compress", "mangle", "output" ]); set_shorthand("keep_classnames", options, [ "compress", "mangle" ]); set_shorthand("keep_fnames", options, [ "compress", "mangle" ]); set_shorthand("module", options, [ "parse", "compress", "mangle" ]); set_shorthand("safari10", options, [ "mangle", "output" ]); set_shorthand("toplevel", options, [ "compress", "mangle" ]); set_shorthand("warnings", options, [ "compress" ]); var quoted_props; if (options.mangle) { options.mangle = defaults(options.mangle, { cache: options.nameCache && (options.nameCache.vars || {}), eval: false, ie8: false, keep_classnames: false, keep_fnames: false, module: false, properties: false, reserved: [], safari10: false, toplevel: false, }, true); if (options.mangle.properties) { if (typeof options.mangle.properties != "object") { options.mangle.properties = {}; } if (options.mangle.properties.keep_quoted) { quoted_props = options.mangle.properties.reserved; if (!Array.isArray(quoted_props)) quoted_props = []; options.mangle.properties.reserved = quoted_props; } if (options.nameCache && !("cache" in options.mangle.properties)) { options.mangle.properties.cache = options.nameCache.props || {}; } } init_cache(options.mangle.cache); init_cache(options.mangle.properties.cache); } if (options.sourceMap) { options.sourceMap = defaults(options.sourceMap, { content: null, filename: null, includeSources: false, root: null, url: null, }, true); } var warnings = []; if (options.warnings && !AST_Node.warn_function) { AST_Node.warn_function = function(warning) { warnings.push(warning); }; } 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; for (var name in files) if (HOP(files, name)) { options.parse.filename = name; options.parse.toplevel = parse(files[name], options.parse); if (options.sourceMap && options.sourceMap.content == "inline") { if (Object.keys(files).length > 1) throw new Error("inline source map only works with singular input"); options.sourceMap.content = read_source_map(files[name]); } } toplevel = options.parse.toplevel; } if (quoted_props && options.mangle.properties.keep_quoted !== "strict") { reserve_quoted_keys(toplevel, quoted_props); } if (options.wrap) { toplevel = toplevel.wrap_commonjs(options.wrap); } if (options.enclose) { toplevel = toplevel.wrap_enclose(options.enclose); } if (timings) timings.rename = Date.now(); // disable rename on harmony due to expand_names bug in for-of loops // https://github.com/mishoo/UglifyJS2/issues/2794 if (0 && options.rename) { toplevel.figure_out_scope(options.mangle); toplevel.expand_names(options.mangle); } if (timings) timings.compress = Date.now(); if (options.compress) toplevel = new Compressor(options.compress).compress(toplevel); if (timings) timings.scope = Date.now(); if (options.mangle) toplevel.figure_out_scope(options.mangle); if (timings) timings.mangle = Date.now(); if (options.mangle) { base54.reset(); toplevel.compute_char_frequency(options.mangle); toplevel.mangle_names(options.mangle); } if (timings) timings.properties = Date.now(); if (options.mangle && options.mangle.properties) { toplevel = mangle_properties(toplevel, options.mangle.properties); } if (timings) timings.output = Date.now(); var result = {}; if (options.output.ast) { result.ast = toplevel; } if (!HOP(options.output, "code") || options.output.code) { if (options.sourceMap) { if (typeof options.sourceMap.content == "string") { options.sourceMap.content = JSON.parse(options.sourceMap.content); } options.output.source_map = SourceMap({ file: options.sourceMap.filename, orig: options.sourceMap.content, root: options.sourceMap.root }); if (options.sourceMap.includeSources) { if (files instanceof AST_Toplevel) { throw new Error("original source content unavailable"); } else for (var name in files) if (HOP(files, name)) { options.output.source_map.get().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(); if (options.sourceMap.url == "inline") { result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(result.map); } else if (options.sourceMap.url) { result.code += "\n//# sourceMappingURL=" + options.sourceMap.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.warn_function = warn_function; } } export { minify, to_ascii, }; terser-4.1.2/lib/mozilla-ast.js000066400000000000000000001233221351061312300163600ustar00rootroot00000000000000/*********************************************************************** A JavaScript tokenizer / parser / beautifier / compressor. https://github.com/mishoo/UglifyJS2 -------------------------------- (C) --------------------------------- Author: Mihai Bazon http://mihai.bazon.net/blog Distributed under the BSD license: Copyright 2012 (c) Mihai Bazon Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ "use strict"; import * as ast from "./ast.js"; import { AST_Accessor, AST_Array, AST_Arrow, AST_Assign, AST_Atom, AST_Await, AST_BigInt, AST_Binary, AST_Block, AST_BlockStatement, AST_Boolean, AST_Break, AST_Call, AST_Case, AST_Catch, AST_Class, AST_ClassExpression, AST_ConciseMethod, AST_Conditional, AST_Const, AST_Constant, AST_Continue, AST_Debugger, AST_Default, AST_DefaultAssign, AST_DefClass, AST_Definitions, AST_Defun, AST_Destructuring, AST_Directive, AST_Do, AST_Dot, AST_EmptyStatement, AST_Expansion, AST_Export, AST_False, AST_Finally, AST_For, AST_ForIn, AST_ForOf, AST_Function, AST_Hole, AST_If, AST_Import, AST_Label, AST_LabeledStatement, AST_LabelRef, AST_Lambda, AST_Let, AST_NameMapping, AST_New, AST_NewTarget, AST_Node, AST_Null, AST_Number, AST_Object, AST_ObjectGetter, AST_ObjectKeyVal, AST_ObjectProperty, AST_ObjectSetter, AST_PrefixedTemplateString, AST_PropAccess, AST_RegExp, AST_Return, AST_Sequence, AST_SimpleStatement, AST_Statement, AST_String, AST_Sub, AST_Super, AST_Switch, AST_SwitchBranch, AST_Symbol, AST_SymbolCatch, AST_SymbolClass, AST_SymbolConst, AST_SymbolDefClass, AST_SymbolDefun, AST_SymbolExport, AST_SymbolExportForeign, AST_SymbolFunarg, AST_SymbolImport, AST_SymbolImportForeign, AST_SymbolLambda, AST_SymbolLet, AST_SymbolMethod, AST_SymbolRef, AST_SymbolVar, AST_TemplateSegment, AST_TemplateString, AST_This, AST_Throw, AST_Token, AST_Toplevel, AST_True, AST_Try, AST_Unary, AST_UnaryPostfix, AST_UnaryPrefix, AST_Var, AST_VarDef, AST_While, AST_With, AST_Yield, } from "./ast.js"; (function() { var normalize_directives = function(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 = { 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)) }); }, ArrayPattern: function(M) { return new AST_Destructuring({ start: my_start_token(M), end: my_end_token(M), names: M.elements.map(function(elm) { if (elm === null) { return new AST_Hole(); } return from_moz(elm); }), is_array: true }); }, ObjectPattern: function(M) { return new AST_Destructuring({ start: my_start_token(M), end: my_end_token(M), names: M.properties.map(from_moz), is_array: false }); }, AssignmentPattern: function(M) { var Type = AST_Binary; if(FROM_MOZ_STACK.length > 2) { var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2]; if(p.type === "FunctionDeclaration" || p.type === "FunctionExpression" || p.type === "ArrowFunctionExpression") { Type = AST_DefaultAssign; } } return new Type({ start: my_start_token(M), end: my_end_token(M), left: from_moz(M.left), operator: "=", right: from_moz(M.right) }); }, SpreadElement: function(M) { return new AST_Expansion({ start: my_start_token(M), end: my_end_token(M), expression: from_moz(M.argument) }); }, RestElement: function(M) { return new AST_Expansion({ start: my_start_token(M), end: my_end_token(M), expression: from_moz(M.argument) }); }, TemplateElement: function(M) { return new AST_TemplateSegment({ start: my_start_token(M), end: my_end_token(M), value: M.value.cooked, raw: M.value.raw }); }, TemplateLiteral: function(M) { var segments = []; for (var i = 0; i < M.quasis.length; i++) { segments.push(from_moz(M.quasis[i])); if (M.expressions[i]) { segments.push(from_moz(M.expressions[i])); } } return new AST_TemplateString({ start: my_start_token(M), end: my_end_token(M), segments: segments }); }, TaggedTemplateExpression: function(M) { return new AST_PrefixedTemplateString({ start: my_start_token(M), end: my_end_token(M), template_string: from_moz(M.quasi), prefix: from_moz(M.tag) }); }, 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), is_generator: M.generator, async: M.async, 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), is_generator: M.generator, async: M.async, body: normalize_directives(from_moz(M.body).body) }); }, ArrowFunctionExpression: function(M) { return new AST_Arrow({ start: my_start_token(M), end: my_end_token(M), argnames: M.params.map(from_moz), body: from_moz(M.body), async: M.async, }); }, ExpressionStatement: function(M) { return new AST_SimpleStatement({ start: my_start_token(M), end: my_end_token(M), body: from_moz(M.expression) }); }, TryStatement: function(M) { var handlers = M.handlers || [M.handler]; if (handlers.length > 1 || M.guardedHandlers && M.guardedHandlers.length) { throw new Error("Multiple catch clauses are not supported."); } return new AST_Try({ start : my_start_token(M), end : my_end_token(M), body : from_moz(M.block).body, bcatch : from_moz(handlers[0]), bfinally : M.finalizer ? new AST_Finally(from_moz(M.finalizer)) : null }); }, Property: function(M) { var key = M.key; var args = { start : my_start_token(key || M.value), end : my_end_token(M.value), key : key.type == "Identifier" ? key.name : key.value, value : from_moz(M.value) }; if (M.computed) { args.key = from_moz(M.key); } if (M.method) { args.is_generator = M.value.generator; args.async = M.value.async; if (!M.computed) { args.key = new AST_SymbolMethod({ name: args.key }); } else { args.key = from_moz(M.key); } return new AST_ConciseMethod(args); } if (M.kind == "init") { if (key.type != "Identifier" && key.type != "Literal") { args.key = from_moz(key); } return new AST_ObjectKeyVal(args); } if (typeof args.key === "string" || typeof args.key === "number") { args.key = new AST_SymbolMethod({ name: args.key }); } args.value = new AST_Accessor(args.value); if (M.kind == "get") return new AST_ObjectGetter(args); if (M.kind == "set") return new AST_ObjectSetter(args); if (M.kind == "method") { args.async = M.value.async; args.is_generator = M.value.generator; args.quote = M.computed ? "\"" : null; return new AST_ConciseMethod(args); } }, MethodDefinition: function(M) { var args = { start : my_start_token(M), end : my_end_token(M), key : M.computed ? from_moz(M.key) : new AST_SymbolMethod({ name: M.key.name || M.key.value }), value : from_moz(M.value), static : M.static, }; if (M.kind == "get") { return new AST_ObjectGetter(args); } if (M.kind == "set") { return new AST_ObjectSetter(args); } args.is_generator = M.value.generator; args.async = M.value.async; return new AST_ConciseMethod(args); }, ArrayExpression: function(M) { 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) { return new AST_Object({ start : my_start_token(M), end : my_end_token(M), properties : M.properties.map(function(prop) { if (prop.type === "SpreadElement") { return from_moz(prop); } prop.type = "Property"; return from_moz(prop); }) }); }, SequenceExpression: function(M) { return new AST_Sequence({ start : my_start_token(M), end : my_end_token(M), expressions: M.expressions.map(from_moz) }); }, MemberExpression: function(M) { return new (M.computed ? AST_Sub : AST_Dot)({ start : my_start_token(M), end : my_end_token(M), property : M.computed ? from_moz(M.property) : M.property.name, expression : from_moz(M.object) }); }, SwitchCase: function(M) { return new (M.test ? AST_Case : AST_Default)({ start : my_start_token(M), end : my_end_token(M), expression : from_moz(M.test), body : M.consequent.map(from_moz) }); }, VariableDeclaration: function(M) { return new (M.kind === "const" ? AST_Const : M.kind === "let" ? AST_Let : AST_Var)({ start : my_start_token(M), end : my_end_token(M), definitions : M.declarations.map(from_moz) }); }, ImportDeclaration: function(M) { var imported_name = null; var imported_names = null; M.specifiers.forEach(function (specifier) { if (specifier.type === "ImportSpecifier") { if (!imported_names) { imported_names = []; } imported_names.push(new AST_NameMapping({ start: my_start_token(specifier), end: my_end_token(specifier), foreign_name: from_moz(specifier.imported), name: from_moz(specifier.local) })); } else if (specifier.type === "ImportDefaultSpecifier") { imported_name = from_moz(specifier.local); } else if (specifier.type === "ImportNamespaceSpecifier") { if (!imported_names) { imported_names = []; } imported_names.push(new AST_NameMapping({ start: my_start_token(specifier), end: my_end_token(specifier), foreign_name: new AST_SymbolImportForeign({ name: "*" }), name: from_moz(specifier.local) })); } }); return new AST_Import({ start : my_start_token(M), end : my_end_token(M), imported_name: imported_name, imported_names : imported_names, module_name : from_moz(M.source) }); }, ExportAllDeclaration: function(M) { return new AST_Export({ start: my_start_token(M), end: my_end_token(M), exported_names: [ new AST_NameMapping({ name: new AST_SymbolExportForeign({ name: "*" }), foreign_name: new AST_SymbolExportForeign({ name: "*" }) }) ], module_name: from_moz(M.source) }); }, ExportNamedDeclaration: function(M) { return new AST_Export({ start: my_start_token(M), end: my_end_token(M), exported_definition: from_moz(M.declaration), exported_names: M.specifiers && M.specifiers.length ? M.specifiers.map(function (specifier) { return new AST_NameMapping({ foreign_name: from_moz(specifier.exported), name: from_moz(specifier.local) }); }) : null, module_name: from_moz(M.source) }); }, ExportDefaultDeclaration: function(M) { return new AST_Export({ start: my_start_token(M), end: my_end_token(M), exported_value: from_moz(M.declaration), is_default: true }); }, Literal: function(M) { var val = M.value, args = { start : my_start_token(M), end : my_end_token(M) }; 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); var raw = args.value.toString(); args.value.raw_source = rx.flags ? raw.substring(0, raw.length - rx.flags.length) + rx.flags : raw; 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) { case "string": args.value = val; return new AST_String(args); case "number": args.value = val; return new AST_Number(args); case "boolean": return new (val ? AST_True : AST_False)(args); } }, MetaProperty: function(M) { if (M.meta.name === "new" && M.property.name === "target") { return new AST_NewTarget({ start: my_start_token(M), end: my_end_token(M) }); } }, Identifier: function(M) { var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2]; return new ( p.type == "LabeledStatement" ? AST_Label : p.type == "VariableDeclarator" && p.id === M ? (p.kind == "const" ? AST_SymbolConst : p.kind == "let" ? AST_SymbolLet : AST_SymbolVar) : /Import.*Specifier/.test(p.type) ? (p.local === M ? AST_SymbolImport : AST_SymbolImportForeign) : p.type == "ExportSpecifier" ? (p.local === M ? AST_SymbolExport : AST_SymbolExportForeign) : p.type == "FunctionExpression" ? (p.id === M ? AST_SymbolLambda : AST_SymbolFunarg) : p.type == "FunctionDeclaration" ? (p.id === M ? AST_SymbolDefun : AST_SymbolFunarg) : p.type == "ArrowFunctionExpression" ? (p.params.includes(M)) ? AST_SymbolFunarg : AST_SymbolRef : p.type == "ClassExpression" ? (p.id === M ? AST_SymbolClass : AST_SymbolRef) : p.type == "Property" ? (p.key === M && p.computed || p.value === M ? AST_SymbolRef : AST_SymbolMethod) : p.type == "ClassDeclaration" ? (p.id === M ? AST_SymbolDefClass : AST_SymbolRef) : p.type == "MethodDefinition" ? (p.computed ? AST_SymbolRef : AST_SymbolMethod) : p.type == "CatchClause" ? AST_SymbolCatch : p.type == "BreakStatement" || p.type == "ContinueStatement" ? AST_LabelRef : AST_SymbolRef)({ start : my_start_token(M), end : my_end_token(M), name : M.name }); }, BigIntLiteral(M) { return new AST_BigInt({ start : my_start_token(M), end : my_end_token(M), value : M.value }); } }; MOZ_TO_ME.UpdateExpression = MOZ_TO_ME.UnaryExpression = function To_Moz_Unary(M) { var prefix = "prefix" in M ? M.prefix : M.type == "UnaryExpression" ? true : false; return new (prefix ? AST_UnaryPrefix : AST_UnaryPostfix)({ start : my_start_token(M), end : my_end_token(M), operator : M.operator, expression : from_moz(M.argument) }); }; MOZ_TO_ME.ClassDeclaration = MOZ_TO_ME.ClassExpression = function From_Moz_Class(M) { return new (M.type === "ClassDeclaration" ? AST_DefClass : AST_ClassExpression)({ start : my_start_token(M), end : my_end_token(M), name : from_moz(M.id), extends : from_moz(M.superClass), properties: M.body.body.map(from_moz) }); }; map("EmptyStatement", AST_EmptyStatement); map("BlockStatement", AST_BlockStatement, "body@body"); map("IfStatement", AST_If, "test>condition, consequent>body, alternate>alternative"); map("LabeledStatement", AST_LabeledStatement, "label>label, body>body"); map("BreakStatement", AST_Break, "label>label"); map("ContinueStatement", AST_Continue, "label>label"); map("WithStatement", AST_With, "object>expression, body>body"); map("SwitchStatement", AST_Switch, "discriminant>expression, cases@body"); map("ReturnStatement", AST_Return, "argument>value"); map("ThrowStatement", AST_Throw, "argument>value"); map("WhileStatement", AST_While, "test>condition, body>body"); map("DoWhileStatement", AST_Do, "test>condition, 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("ForOfStatement", AST_ForOf, "left>init, right>object, body>body, await=await"); map("AwaitExpression", AST_Await, "argument>expression"); map("YieldExpression", AST_Yield, "argument>expression, delegate=is_star"); map("DebuggerStatement", AST_Debugger); map("VariableDeclarator", AST_VarDef, "id>name, init>value"); map("CatchClause", AST_Catch, "param>argname, body%body"); map("ThisExpression", AST_This); map("Super", AST_Super); map("BinaryExpression", 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("ConditionalExpression", AST_Conditional, "test>condition, consequent>consequent, alternate>alternative"); map("NewExpression", AST_New, "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_Expansion, function To_Moz_Spread(M, parent) { return { type: to_moz_in_destructuring() ? "RestElement" : "SpreadElement", argument: to_moz(M.expression) }; }); def_to_moz(AST_PrefixedTemplateString, function To_Moz_TaggedTemplateExpression(M) { return { type: "TaggedTemplateExpression", tag: to_moz(M.prefix), quasi: to_moz(M.template_string) }; }); def_to_moz(AST_TemplateString, function To_Moz_TemplateLiteral(M) { var quasis = []; var expressions = []; for (var i = 0; i < M.segments.length; i++) { if (i % 2 !== 0) { expressions.push(to_moz(M.segments[i])); } else { quasis.push({ type: "TemplateElement", value: { raw: M.segments[i].raw, cooked: M.segments[i].value }, tail: i === M.segments.length - 1 }); } } return { type: "TemplateLiteral", quasis: quasis, expressions: expressions }; }); def_to_moz(AST_Defun, function To_Moz_FunctionDeclaration(M) { return { type: "FunctionDeclaration", id: to_moz(M.name), params: M.argnames.map(to_moz), generator: M.is_generator, async: M.async, body: to_moz_scope("BlockStatement", M) }; }); def_to_moz(AST_Function, function To_Moz_FunctionExpression(M, parent) { var is_generator = parent.is_generator !== undefined ? parent.is_generator : M.is_generator; return { type: "FunctionExpression", id: to_moz(M.name), params: M.argnames.map(to_moz), generator: is_generator, async: M.async, body: to_moz_scope("BlockStatement", M) }; }); def_to_moz(AST_Arrow, function To_Moz_ArrowFunctionExpression(M) { var body = M.body instanceof Array ? { type: "BlockStatement", body: M.body.map(to_moz) } : to_moz(M.body); return { type: "ArrowFunctionExpression", params: M.argnames.map(to_moz), async: M.async, body: body }; }); def_to_moz(AST_Destructuring, function To_Moz_ObjectPattern(M) { if (M.is_array) { return { type: "ArrayPattern", elements: M.names.map(to_moz) }; } return { type: "ObjectPattern", properties: M.names.map(to_moz) }; }); def_to_moz(AST_Directive, function To_Moz_Directive(M) { return { type: "ExpressionStatement", expression: { type: "Literal", value: M.value } }; }); def_to_moz(AST_SimpleStatement, function To_Moz_ExpressionStatement(M) { return { type: "ExpressionStatement", expression: to_moz(M.body) }; }); def_to_moz(AST_SwitchBranch, function To_Moz_SwitchCase(M) { return { type: "SwitchCase", test: to_moz(M.expression), consequent: M.body.map(to_moz) }; }); def_to_moz(AST_Try, function To_Moz_TryStatement(M) { return { type: "TryStatement", block: to_moz_block(M), handler: to_moz(M.bcatch), guardedHandlers: [], finalizer: to_moz(M.bfinally) }; }); def_to_moz(AST_Catch, function To_Moz_CatchClause(M) { return { type: "CatchClause", param: to_moz(M.argname), guard: null, body: to_moz_block(M) }; }); def_to_moz(AST_Definitions, function To_Moz_VariableDeclaration(M) { return { type: "VariableDeclaration", kind: M instanceof AST_Const ? "const" : M instanceof AST_Let ? "let" : "var", declarations: M.definitions.map(to_moz) }; }); def_to_moz(AST_Export, function To_Moz_ExportDeclaration(M) { if (M.exported_names) { if (M.exported_names[0].name.name === "*") { return { type: "ExportAllDeclaration", source: to_moz(M.module_name) }; } return { type: "ExportNamedDeclaration", specifiers: M.exported_names.map(function (name_mapping) { return { type: "ExportSpecifier", exported: to_moz(name_mapping.foreign_name), local: to_moz(name_mapping.name) }; }), declaration: to_moz(M.exported_definition), source: to_moz(M.module_name) }; } return { type: M.is_default ? "ExportDefaultDeclaration" : "ExportNamedDeclaration", declaration: to_moz(M.exported_value || M.exported_definition) }; }); def_to_moz(AST_Import, function To_Moz_ImportDeclaration(M) { var specifiers = []; if (M.imported_name) { specifiers.push({ type: "ImportDefaultSpecifier", local: to_moz(M.imported_name) }); } if (M.imported_names && M.imported_names[0].foreign_name.name === "*") { specifiers.push({ type: "ImportNamespaceSpecifier", local: to_moz(M.imported_names[0].name) }); } else if (M.imported_names) { M.imported_names.forEach(function(name_mapping) { specifiers.push({ type: "ImportSpecifier", local: to_moz(name_mapping.name), imported: to_moz(name_mapping.foreign_name) }); }); } return { type: "ImportDeclaration", specifiers: specifiers, source: to_moz(M.module_name) }; }); def_to_moz(AST_Sequence, function To_Moz_SequenceExpression(M) { return { type: "SequenceExpression", expressions: M.expressions.map(to_moz) }; }); def_to_moz(AST_PropAccess, function To_Moz_MemberExpression(M) { var isComputed = M instanceof AST_Sub; return { type: "MemberExpression", object: to_moz(M.expression), computed: isComputed, property: isComputed ? to_moz(M.property) : {type: "Identifier", name: M.property} }; }); def_to_moz(AST_Unary, function To_Moz_Unary(M) { return { type: M.operator == "++" || M.operator == "--" ? "UpdateExpression" : "UnaryExpression", operator: M.operator, prefix: M instanceof AST_UnaryPrefix, argument: to_moz(M.expression) }; }); def_to_moz(AST_Binary, function To_Moz_BinaryExpression(M) { if (M.operator == "=" && to_moz_in_destructuring()) { return { type: "AssignmentPattern", left: to_moz(M.left), right: to_moz(M.right) }; } return { type: M.operator == "&&" || M.operator == "||" ? "LogicalExpression" : "BinaryExpression", left: to_moz(M.left), operator: M.operator, right: to_moz(M.right) }; }); 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) { return { type: "ObjectExpression", properties: M.properties.map(to_moz) }; }); def_to_moz(AST_ObjectProperty, function To_Moz_Property(M, parent) { var key = M.key instanceof AST_Node ? to_moz(M.key) : { type: "Identifier", value: M.key }; if (typeof M.key === "number") { key = { type: "Literal", value: Number(M.key) }; } if (typeof M.key === "string") { key = { type: "Identifier", name: M.key }; } var kind; var string_or_num = typeof M.key === "string" || typeof M.key === "number"; var computed = string_or_num ? false : !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef; if (M instanceof AST_ObjectKeyVal) { kind = "init"; computed = !string_or_num; } else if (M instanceof AST_ObjectGetter) { kind = "get"; } else if (M instanceof AST_ObjectSetter) { kind = "set"; } if (parent instanceof AST_Class) { return { type: "MethodDefinition", computed: computed, kind: kind, static: M.static, key: to_moz(M.key), value: to_moz(M.value) }; } return { type: "Property", computed: computed, kind: kind, key: key, value: to_moz(M.value) }; }); def_to_moz(AST_ConciseMethod, function To_Moz_MethodDefinition(M, parent) { if (parent instanceof AST_Object) { return { type: "Property", computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef, kind: "init", method: true, shorthand: false, key: to_moz(M.key), value: to_moz(M.value) }; } return { type: "MethodDefinition", computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef, kind: M.key === "constructor" ? "constructor" : "method", static: M.static, key: to_moz(M.key), value: to_moz(M.value) }; }); def_to_moz(AST_Class, function To_Moz_Class(M) { var type = M instanceof AST_ClassExpression ? "ClassExpression" : "ClassDeclaration"; return { type: type, superClass: to_moz(M.extends), id: M.name ? to_moz(M.name) : null, body: { type: "ClassBody", body: M.properties.map(to_moz) } }; }); def_to_moz(AST_NewTarget, function To_Moz_MetaProperty(M) { return { type: "MetaProperty", meta: { type: "Identifier", name: "new" }, property: { type: "Identifier", name: "target" } }; }); def_to_moz(AST_Symbol, function To_Moz_Identifier(M, parent) { if (M instanceof AST_SymbolMethod && parent.quote) { return { type: "Literal", value: M.name }; } var def = M.definition(); return { type: "Identifier", name: def ? def.mangled_name || def.name : M.name }; }); def_to_moz(AST_RegExp, function To_Moz_RegExpLiteral(M) { var pattern = M.value.source; var flags = M.value.toString().match(/[gimuys]*$/)[0]; return { type: "Literal", value: new RegExp(pattern, flags), raw: M.value.raw_source, regex: { pattern: pattern, flags: flags, } }; }); def_to_moz(AST_Constant, function To_Moz_Literal(M) { var value = M.value; if (typeof value === "number" && (value < 0 || (value === 0 && 1 / value < 0))) { return { type: "UnaryExpression", operator: "-", prefix: true, argument: { type: "Literal", value: -value, raw: M.start.raw } }; } return { type: "Literal", value: value, raw: M.start.raw }; }); def_to_moz(AST_Atom, function To_Moz_Atom(M) { return { type: "Identifier", name: String(M.value) }; }); def_to_moz(AST_BigInt, M => ({ type: "BigIntLiteral", value: M.value })); AST_Boolean.DEFMETHOD("to_mozilla_ast", AST_Constant.prototype.to_mozilla_ast); AST_Null.DEFMETHOD("to_mozilla_ast", AST_Constant.prototype.to_mozilla_ast); AST_Hole.DEFMETHOD("to_mozilla_ast", function To_Moz_ArrayHole() { return null; }); AST_Block.DEFMETHOD("to_mozilla_ast", AST_BlockStatement.prototype.to_mozilla_ast); AST_Lambda.DEFMETHOD("to_mozilla_ast", AST_Function.prototype.to_mozilla_ast); /* -----[ tools ]----- */ function raw_token(moznode) { if (moznode.type == "Literal") { return moznode.raw != null ? moznode.raw : moznode.value + ""; } } function my_start_token(moznode) { var loc = moznode.loc, start = loc && loc.start; var range = moznode.range; return new AST_Token({ file : loc && loc.source, line : start && start.line, col : start && start.column, pos : range ? range[0] : moznode.start, endline : start && start.line, endcol : start && start.column, endpos : range ? range[0] : moznode.start, raw : raw_token(moznode), }); } function my_end_token(moznode) { var loc = moznode.loc, end = loc && loc.end; var range = moznode.range; return new AST_Token({ file : loc && loc.source, line : end && end.line, col : end && end.column, pos : range ? range[1] : moznode.end, endline : end && end.line, endcol : end && end.column, endpos : range ? range[1] : moznode.end, raw : raw_token(moznode), }); } function map(moztype, mytype, propmap) { var moz_to_me = "function From_Moz_" + moztype + "(M){\n"; moz_to_me += "return new U2." + mytype.name + "({\n" + "start: my_start_token(M),\n" + "end: my_end_token(M)"; var me_to_moz = "function To_Moz_" + moztype + "(M){\n"; me_to_moz += "return {\n" + "type: " + JSON.stringify(moztype); if (propmap) propmap.split(/\s*,\s*/).forEach(function(prop) { var m = /([a-z0-9$_]+)([=@>%])([a-z0-9$_]+)/i.exec(prop); if (!m) throw new Error("Can't understand property map: " + prop); var moz = m[1], how = m[2], my = m[3]; moz_to_me += ",\n" + my + ": "; me_to_moz += ",\n" + moz + ": "; switch (how) { case "@": moz_to_me += "M." + moz + ".map(from_moz)"; me_to_moz += "M." + my + ".map(to_moz)"; break; case ">": moz_to_me += "from_moz(M." + moz + ")"; me_to_moz += "to_moz(M." + my + ")"; break; case "=": moz_to_me += "M." + moz; me_to_moz += "M." + my; break; case "%": moz_to_me += "from_moz(M." + moz + ").body"; me_to_moz += "to_moz_block(M)"; break; default: throw new Error("Can't understand operator in propmap: " + prop); } }); moz_to_me += "\n})\n}"; me_to_moz += "\n}\n}"; //moz_to_me = parse(moz_to_me).print_to_string({ beautify: true }); //me_to_moz = parse(me_to_moz).print_to_string({ beautify: true }); //console.log(moz_to_me); moz_to_me = new Function("U2", "my_start_token", "my_end_token", "from_moz", "return(" + moz_to_me + ")")( ast, 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 + ")")( to_moz, to_moz_block, to_moz_scope ); MOZ_TO_ME[moztype] = moz_to_me; def_to_moz(mytype, me_to_moz); } var FROM_MOZ_STACK = null; function from_moz(node) { FROM_MOZ_STACK.push(node); var ret = node != null ? MOZ_TO_ME[node.type](node) : null; FROM_MOZ_STACK.pop(); return ret; } AST_Node.from_mozilla_ast = function(node) { var save_stack = FROM_MOZ_STACK; FROM_MOZ_STACK = []; var ast = from_moz(node); FROM_MOZ_STACK = save_stack; return ast; }; function set_moz_loc(mynode, moznode, myparent) { var start = mynode.start; var end = mynode.end; if (start.pos != null && end.endpos != null) { moznode.range = [start.pos, end.endpos]; } if (start.line) { moznode.loc = { start: {line: start.line, column: start.col}, end: end.endline ? {line: end.endline, column: end.endcol} : null }; if (start.file) { moznode.loc.source = start.file; } } return moznode; } function def_to_moz(mytype, handler) { mytype.DEFMETHOD("to_mozilla_ast", function(parent) { return set_moz_loc(this, handler(this, parent)); }); } var TO_MOZ_STACK = null; function to_moz(node) { if (TO_MOZ_STACK === null) { TO_MOZ_STACK = []; } TO_MOZ_STACK.push(node); var ast = node != null ? node.to_mozilla_ast(TO_MOZ_STACK[TO_MOZ_STACK.length - 2]) : null; TO_MOZ_STACK.pop(); if (TO_MOZ_STACK.length === 0) { TO_MOZ_STACK = null; } return ast; } function to_moz_in_destructuring() { var i = TO_MOZ_STACK.length; while (i--) { if (TO_MOZ_STACK[i] instanceof AST_Destructuring) { return true; } } return false; } function to_moz_block(node) { return { type: "BlockStatement", 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 }; } })(); terser-4.1.2/lib/output.js000066400000000000000000002066561351061312300155000ustar00rootroot00000000000000/*********************************************************************** A JavaScript tokenizer / parser / beautifier / compressor. https://github.com/mishoo/UglifyJS2 -------------------------------- (C) --------------------------------- Author: Mihai Bazon http://mihai.bazon.net/blog Distributed under the BSD license: Copyright 2012 (c) Mihai Bazon Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ "use strict"; import { defaults, makePredicate, noop, return_false, return_true, } from "./utils/index.js"; import { first_in_statement } from "./utils/first_in_statement.js"; import { AST_Array, AST_Arrow, AST_Assign, AST_Await, AST_BigInt, AST_Binary, AST_BlockStatement, AST_Break, AST_Call, AST_Case, AST_Catch, AST_Class, AST_ClassExpression, AST_ConciseMethod, AST_Conditional, AST_Const, AST_Constant, AST_Continue, AST_Debugger, AST_Default, AST_DefaultAssign, AST_Definitions, AST_Defun, AST_Destructuring, AST_Directive, AST_Do, AST_Dot, AST_EmptyStatement, AST_Exit, AST_Expansion, AST_Export, AST_Finally, AST_For, AST_ForIn, AST_ForOf, AST_Function, AST_Hole, AST_If, AST_Import, AST_Jump, AST_LabeledStatement, AST_Lambda, AST_Let, AST_LoopControl, AST_NameMapping, AST_New, AST_NewTarget, AST_Node, AST_Number, AST_Object, AST_ObjectGetter, AST_ObjectKeyVal, AST_ObjectProperty, AST_ObjectSetter, AST_PrefixedTemplateString, AST_PropAccess, AST_RegExp, AST_Return, AST_Scope, AST_Sequence, AST_SimpleStatement, AST_Statement, AST_StatementWithBody, AST_String, AST_Sub, AST_Super, AST_Switch, AST_SwitchBranch, AST_Symbol, AST_SymbolMethod, AST_SymbolRef, AST_TemplateSegment, AST_TemplateString, AST_This, AST_Throw, AST_Toplevel, AST_Try, AST_Unary, AST_UnaryPostfix, AST_UnaryPrefix, AST_Var, AST_VarDef, AST_While, AST_With, AST_Yield, TreeWalker, } from "./ast.js"; import { get_full_char_code, get_full_char, is_identifier_char, is_identifier_string, is_surrogate_pair_head, is_surrogate_pair_tail, PRECEDENCE, RESERVED_WORDS, } from "./parse.js"; var EXPECT_DIRECTIVE = /^$|[;{][\s\n]*$/; const CODE_LINE_BREAK = 10; const CODE_SPACE = 32; function is_some_comments(comment) { // multiline comment return comment.type == "comment2" && /@preserve|@license|@cc_on/i.test(comment.value); } function OutputStream(options) { var readonly = !options; options = defaults(options, { ascii_only : false, beautify : false, braces : false, comments : false, ecma : 5, ie8 : false, indent_level : 4, indent_start : 0, inline_script : true, keep_quoted_props: false, max_line_len : false, preamble : null, quote_keys : false, quote_style : 0, safari10 : false, semicolons : true, shebang : true, shorthand : undefined, source_map : null, webkit : false, width : 80, wrap_iife : false, }, true); if (options.shorthand === undefined) options.shorthand = options.ecma > 5; // Convert comment option to RegExp if neccessary and set up comments filter var comment_filter = return_false; // Default case, throw all comments away if (options.comments) { var comments = options.comments; if (typeof options.comments === "string" && /^\/.*\/[a-zA-Z]*$/.test(options.comments)) { var regex_pos = options.comments.lastIndexOf("/"); comments = new RegExp( options.comments.substr(1, regex_pos - 1), options.comments.substr(regex_pos + 1) ); } if (comments instanceof RegExp) { comment_filter = function(comment) { return comment.type != "comment5" && comments.test(comment.value); }; } else if (typeof comments === "function") { comment_filter = function(comment) { return comment.type != "comment5" && comments(this, comment); }; } else if (comments === "some") { comment_filter = is_some_comments; } else { // NOTE includes "all" option comment_filter = return_true; } } var indentation = 0; var current_col = 0; var current_line = 1; var current_pos = 0; var OUTPUT = ""; var to_utf8 = options.ascii_only ? function(str, identifier) { if (options.ecma >= 6) { str = str.replace(/[\ud800-\udbff][\udc00-\udfff]/g, function(ch) { var code = get_full_char_code(ch, 0).toString(16); return "\\u{" + code + "}"; }); } return str.replace(/[\u0000-\u001f\u007f-\uffff]/g, function(ch) { var code = ch.charCodeAt(0).toString(16); if (code.length <= 2 && !identifier) { while (code.length < 2) code = "0" + code; return "\\x" + code; } else { while (code.length < 4) code = "0" + code; return "\\u" + code; } }); } : function(str) { var s = ""; for (var i = 0, len = str.length; i < len; i++) { if (is_surrogate_pair_head(str[i]) && !is_surrogate_pair_tail(str[i + 1]) || is_surrogate_pair_tail(str[i]) && !is_surrogate_pair_head(str[i - 1])) { s += "\\u" + str.charCodeAt(i).toString(16); } else { s += str[i]; } } return s; }; function make_string(str, quote) { var dq = 0, sq = 0; str = str.replace(/[\\\b\f\n\r\v\t\x22\x27\u2028\u2029\0\ufeff]/g, function(s, i) { switch (s) { case '"': ++dq; return '"'; case "'": ++sq; return "'"; case "\\": return "\\\\"; case "\n": return "\\n"; case "\r": return "\\r"; case "\t": return "\\t"; case "\b": return "\\b"; case "\f": return "\\f"; case "\x0B": return options.ie8 ? "\\x0B" : "\\v"; case "\u2028": return "\\u2028"; case "\u2029": return "\\u2029"; case "\ufeff": return "\\ufeff"; case "\0": return /[0-9]/.test(get_full_char(str, i+1)) ? "\\x00" : "\\0"; } return s; }); function quote_single() { return "'" + str.replace(/\x27/g, "\\'") + "'"; } function quote_double() { return '"' + str.replace(/\x22/g, '\\"') + '"'; } function quote_template() { return "`" + str.replace(/`/g, "\\`") + "`"; } str = to_utf8(str); if (quote === "`") return quote_template(); switch (options.quote_style) { case 1: return quote_single(); case 2: return quote_double(); case 3: return quote == "'" ? quote_single() : quote_double(); default: return dq > sq ? quote_single() : quote_double(); } } function encode_string(str, quote) { var ret = make_string(str, quote); if (options.inline_script) { ret = ret.replace(/<\x2f(script)([>\/\t\n\f\r ])/gi, "<\\/$1$2"); ret = ret.replace(/\x3c!--/g, "\\x3c!--"); ret = ret.replace(/--\x3e/g, "--\\x3e"); } return ret; } function make_name(name) { name = name.toString(); name = to_utf8(name, true); return name; } function make_indent(back) { return " ".repeat(options.indent_start + indentation - back * options.indent_level); } /* -----[ beautification/minification ]----- */ var has_parens = false; var might_need_space = false; var might_need_semicolon = false; var might_add_newline = 0; var need_newline_indented = false; var need_space = false; var newline_insert = -1; var last = ""; var mapping_token, mapping_name, mappings = options.source_map && []; var do_add_mapping = mappings ? function() { mappings.forEach(function(mapping) { try { options.source_map.add( mapping.token.file, mapping.line, mapping.col, mapping.token.line, mapping.token.col, !mapping.name && mapping.token.type == "name" ? mapping.token.value : mapping.name ); } catch(ex) { mapping.token.file != null && AST_Node.warn("Couldn't figure out mapping for {file}:{line},{col} → {cline},{ccol} [{name}]", { file: mapping.token.file, line: mapping.token.line, col: mapping.token.col, cline: mapping.line, ccol: mapping.col, name: mapping.name || "" }); } }); mappings = []; } : noop; var ensure_line_len = options.max_line_len ? function() { if (current_col > options.max_line_len) { if (might_add_newline) { var left = OUTPUT.slice(0, might_add_newline); var right = OUTPUT.slice(might_add_newline); if (mappings) { var delta = right.length - current_col; mappings.forEach(function(mapping) { mapping.line++; mapping.col += delta; }); } OUTPUT = left + "\n" + right; current_line++; current_pos++; current_col = right.length; } if (current_col > options.max_line_len) { AST_Node.warn("Output exceeds {max_line_len} characters", options); } } if (might_add_newline) { might_add_newline = 0; do_add_mapping(); } } : noop; var requireSemicolonChars = makePredicate("( [ + * / - , . `"); function print(str) { str = String(str); var ch = get_full_char(str, 0); if (need_newline_indented && ch) { need_newline_indented = false; if (ch !== "\n") { print("\n"); indent(); } } if (need_space && ch) { need_space = false; if (!/[\s;})]/.test(ch)) { space(); } } newline_insert = -1; var prev = last.charAt(last.length - 1); if (might_need_semicolon) { might_need_semicolon = false; if (prev === ":" && ch === "}" || (!ch || !";}".includes(ch)) && prev !== ";") { if (options.semicolons || requireSemicolonChars.has(ch)) { OUTPUT += ";"; current_col++; current_pos++; } else { ensure_line_len(); if (current_col > 0) { OUTPUT += "\n"; current_pos++; current_line++; current_col = 0; } if (/^\s+$/.test(str)) { // reset the semicolon flag, since we didn't print one // now and might still have to later might_need_semicolon = true; } } if (!options.beautify) might_need_space = false; } } if (might_need_space) { if ((is_identifier_char(prev) && (is_identifier_char(ch) || ch == "\\")) || (ch == "/" && ch == prev) || ((ch == "+" || ch == "-") && ch == last) ) { OUTPUT += " "; current_col++; current_pos++; } might_need_space = false; } if (mapping_token) { mappings.push({ token: mapping_token, name: mapping_name, line: current_line, col: current_col }); mapping_token = false; if (!might_add_newline) do_add_mapping(); } OUTPUT += str; has_parens = str[str.length - 1] == "("; current_pos += str.length; var a = str.split(/\r?\n/), n = a.length - 1; current_line += n; current_col += a[0].length; if (n > 0) { ensure_line_len(); current_col = a[n].length; } last = str; } var star = function() { print("*"); }; var space = options.beautify ? function() { print(" "); } : function() { might_need_space = true; }; var indent = options.beautify ? function(half) { if (options.beautify) { print(make_indent(half ? 0.5 : 0)); } } : noop; var with_indent = options.beautify ? function(col, cont) { if (col === true) col = next_indent(); var save_indentation = indentation; indentation = col; var ret = cont(); indentation = save_indentation; return ret; } : function(col, cont) { return cont(); }; var newline = options.beautify ? function() { if (newline_insert < 0) return print("\n"); if (OUTPUT[newline_insert] != "\n") { OUTPUT = OUTPUT.slice(0, newline_insert) + "\n" + OUTPUT.slice(newline_insert); current_pos++; current_line++; } newline_insert++; } : options.max_line_len ? function() { ensure_line_len(); might_add_newline = OUTPUT.length; } : noop; var semicolon = options.beautify ? function() { print(";"); } : function() { might_need_semicolon = true; }; function force_semicolon() { might_need_semicolon = false; print(";"); } function next_indent() { return indentation + options.indent_level; } function with_block(cont) { var ret; print("{"); newline(); with_indent(next_indent(), function() { ret = cont(); }); indent(); print("}"); return ret; } function with_parens(cont) { print("("); //XXX: still nice to have that for argument lists //var ret = with_indent(current_col, cont); var ret = cont(); print(")"); return ret; } function with_square(cont) { print("["); //var ret = with_indent(current_col, cont); var ret = cont(); print("]"); return ret; } function comma() { print(","); space(); } function colon() { print(":"); space(); } var add_mapping = mappings ? function(token, name) { mapping_token = token; mapping_name = name; } : noop; function get() { if (might_add_newline) { ensure_line_len(); } return OUTPUT; } function has_nlb() { let n = OUTPUT.length - 1; while (n >= 0) { const code = OUTPUT.charCodeAt(n); if (code === CODE_LINE_BREAK) { return true; } if (code !== CODE_SPACE) { return false; } n--; } return true; } function prepend_comments(node) { var self = this; var start = node.start; if (!start) return; if (start.comments_before && start.comments_before._dumped === self) return; var comments = start.comments_before; if (!comments) { comments = start.comments_before = []; } comments._dumped = self; if (node instanceof AST_Exit && node.value) { var tw = new TreeWalker(function(node) { var parent = tw.parent(); if (parent instanceof AST_Exit || parent instanceof AST_Binary && parent.left === node || parent.TYPE == "Call" && parent.expression === node || parent instanceof AST_Conditional && parent.condition === node || parent instanceof AST_Dot && parent.expression === node || parent instanceof AST_Sequence && parent.expressions[0] === node || parent instanceof AST_Sub && parent.expression === node || parent instanceof AST_UnaryPostfix) { if (!node.start) return; var text = node.start.comments_before; if (text && text._dumped !== self) { text._dumped = self; comments = comments.concat(text); } } else { return true; } }); tw.push(node); node.value.walk(tw); } if (current_pos == 0) { if (comments.length > 0 && options.shebang && comments[0].type == "comment5") { print("#!" + comments.shift().value + "\n"); indent(); } var preamble = options.preamble; if (preamble) { print(preamble.replace(/\r\n?|[\n\u2028\u2029]|\s*$/g, "\n")); } } comments = comments.filter(comment_filter, node); if (comments.length == 0) return; var last_nlb = has_nlb(); comments.forEach(function(c, i) { if (!last_nlb) { if (c.nlb) { print("\n"); indent(); last_nlb = true; } else if (i > 0) { space(); } } if (/comment[134]/.test(c.type)) { print("//" + c.value.replace(/[@#]__PURE__/g, " ") + "\n"); indent(); last_nlb = true; } else if (c.type == "comment2") { print("/*" + c.value.replace(/[@#]__PURE__/g, " ") + "*/"); last_nlb = false; } }); if (!last_nlb) { if (start.nlb) { print("\n"); indent(); } else { space(); } } } function append_comments(node, tail) { var self = this; var token = node.end; if (!token) return; var comments = token[tail ? "comments_before" : "comments_after"]; if (!comments || comments._dumped === self) return; if (!(node instanceof AST_Statement || comments.every((c) => !/comment[134]/.test(c.type) ))) return; comments._dumped = self; var insert = OUTPUT.length; comments.filter(comment_filter, node).forEach(function(c, i) { need_space = false; if (need_newline_indented) { print("\n"); indent(); need_newline_indented = false; } else if (c.nlb && (i > 0 || !has_nlb())) { print("\n"); indent(); } else if (i > 0 || !tail) { space(); } if (/comment[134]/.test(c.type)) { print("//" + c.value.replace(/[@#]__PURE__/g, " ")); need_newline_indented = true; } else if (c.type == "comment2") { print("/*" + c.value.replace(/[@#]__PURE__/g, " ") + "*/"); need_space = true; } }); if (OUTPUT.length > insert) newline_insert = insert; } var stack = []; return { get : get, toString : get, indent : indent, indentation : function() { return indentation; }, current_width : function() { return current_col - indentation; }, should_break : function() { return options.width && this.current_width() >= options.width; }, has_parens : function() { return has_parens; }, newline : newline, print : print, star : star, space : space, comma : comma, colon : colon, last : function() { return last; }, semicolon : semicolon, force_semicolon : force_semicolon, to_utf8 : to_utf8, print_name : function(name) { print(make_name(name)); }, print_string : function(str, quote, escape_directive) { var encoded = encode_string(str, quote); if (escape_directive === true && !encoded.includes("\\")) { // Insert semicolons to break directive prologue if (!EXPECT_DIRECTIVE.test(OUTPUT)) { force_semicolon(); } force_semicolon(); } print(encoded); }, print_template_string_chars: function(str) { var encoded = encode_string(str, "`").replace(/\${/g, "\\${"); return print(encoded.substr(1, encoded.length - 2)); }, encode_string : encode_string, next_indent : next_indent, with_indent : with_indent, with_block : with_block, with_parens : with_parens, with_square : with_square, add_mapping : add_mapping, option : function(opt) { return options[opt]; }, prepend_comments: readonly ? noop : prepend_comments, append_comments : readonly || comment_filter === return_false ? noop : append_comments, line : function() { return current_line; }, col : function() { return current_col; }, pos : function() { return current_pos; }, push_node : function(node) { stack.push(node); }, pop_node : function() { return stack.pop(); }, parent : function(n) { return stack[stack.length - 2 - (n || 0)]; } }; } /* -----[ code generators ]----- */ (function() { /* -----[ utils ]----- */ function DEFPRINT(nodetype, generator) { nodetype.DEFMETHOD("_codegen", generator); } var in_directive = false; var active_scope = null; var use_asm = null; AST_Node.DEFMETHOD("print", function(stream, force_parens) { var self = this, generator = self._codegen; if (self instanceof AST_Scope) { active_scope = self; } else if (!use_asm && self instanceof AST_Directive && self.value == "use asm") { use_asm = active_scope; } function doit() { stream.prepend_comments(self); self.add_source_map(stream); generator(self, stream); stream.append_comments(self); } stream.push_node(self); if (force_parens || self.needs_parens(stream)) { stream.with_parens(doit); } else { doit(); } stream.pop_node(); if (self === use_asm) { use_asm = null; } }); AST_Node.DEFMETHOD("_print", AST_Node.prototype.print); AST_Node.DEFMETHOD("print_to_string", function(options) { var s = OutputStream(options); this.print(s); return s.get(); }); /* -----[ PARENTHESES ]----- */ function PARENS(nodetype, func) { if (Array.isArray(nodetype)) { nodetype.forEach(function(nodetype) { PARENS(nodetype, func); }); } else { nodetype.DEFMETHOD("needs_parens", func); } } PARENS(AST_Node, return_false); // a function expression needs parens around it when it's provably // the first token to appear in a statement. PARENS(AST_Function, function(output) { if (!output.has_parens() && first_in_statement(output)) { return true; } if (output.option("webkit")) { var p = output.parent(); if (p instanceof AST_PropAccess && p.expression === this) { return true; } } if (output.option("wrap_iife")) { var p = output.parent(); return p instanceof AST_Call && p.expression === this; } return false; }); PARENS(AST_Arrow, function(output) { var p = output.parent(); return p instanceof AST_PropAccess && p.expression === this; }); // same goes for an object literal, because otherwise it would be // interpreted as a block of code. PARENS(AST_Object, function(output) { return !output.has_parens() && first_in_statement(output); }); PARENS(AST_ClassExpression, first_in_statement); PARENS(AST_Unary, function(output) { var p = output.parent(); return p instanceof AST_PropAccess && p.expression === this || p instanceof AST_Call && p.expression === this || p instanceof AST_Binary && p.operator === "**" && this instanceof AST_UnaryPrefix && p.left === this && this.operator !== "++" && this.operator !== "--"; }); PARENS(AST_Await, function(output) { var p = output.parent(); return p instanceof AST_PropAccess && p.expression === this || p instanceof AST_Call && p.expression === this || output.option("safari10") && p instanceof AST_UnaryPrefix; }); PARENS(AST_Sequence, function(output) { var p = output.parent(); return p instanceof AST_Call // (foo, bar)() or foo(1, (2, 3), 4) || p instanceof AST_Unary // !(foo, bar, baz) || p instanceof AST_Binary // 1 + (2, 3) + 4 ==> 8 || p instanceof AST_VarDef // var a = (1, 2), b = a + a; ==> b == 4 || p instanceof AST_PropAccess // (1, {foo:2}).foo or (1, {foo:2})["foo"] ==> 2 || p instanceof AST_Array // [ 1, (2, 3), 4 ] ==> [ 1, 3, 4 ] || p instanceof AST_ObjectProperty // { foo: (1, 2) }.foo ==> 2 || p instanceof AST_Conditional /* (false, true) ? (a = 10, b = 20) : (c = 30) * ==> 20 (side effect, set a := 10 and b := 20) */ || p instanceof AST_Arrow // x => (x, x) || p instanceof AST_DefaultAssign // x => (x = (0, function(){})) || p instanceof AST_Expansion // [...(a, b)] || p instanceof AST_ForOf && this === p.object // for (e of (foo, bar)) {} || p instanceof AST_Yield // yield (foo, bar) || p instanceof AST_Export // export default (foo, bar) ; }); PARENS(AST_Binary, function(output) { var p = output.parent(); // (foo && bar)() if (p instanceof AST_Call && p.expression === this) return true; // typeof (foo && bar) if (p instanceof AST_Unary) return true; // (foo && bar)["prop"], (foo && bar).prop if (p instanceof AST_PropAccess && p.expression === this) return true; // this deals with precedence: 3 * (2 + 1) if (p instanceof AST_Binary) { var po = p.operator, pp = PRECEDENCE[po]; var so = this.operator, sp = PRECEDENCE[so]; if (pp > sp || (pp == sp && (this === p.right || po == "**"))) { return true; } } }); PARENS(AST_Yield, function(output) { var p = output.parent(); // (yield 1) + (yield 2) // a = yield 3 if (p instanceof AST_Binary && p.operator !== "=") return true; // (yield 1)() // new (yield 1)() if (p instanceof AST_Call && p.expression === this) return true; // (yield 1) ? yield 2 : yield 3 if (p instanceof AST_Conditional && p.condition === this) return true; // -(yield 4) if (p instanceof AST_Unary) return true; // (yield x).foo // (yield x)['foo'] if (p instanceof AST_PropAccess && p.expression === this) return true; }); PARENS(AST_PropAccess, function(output) { var p = output.parent(); if (p instanceof AST_New && p.expression === this) { // i.e. new (foo.bar().baz) // // if there's one call into this subtree, then we need // parens around it too, otherwise the call will be // interpreted as passing the arguments to the upper New // expression. var parens = false; this.walk(new TreeWalker(function(node) { if (parens || node instanceof AST_Scope) return true; if (node instanceof AST_Call) { parens = true; return true; } })); return parens; } }); PARENS(AST_Call, function(output) { var p = output.parent(), p1; if (p instanceof AST_New && p.expression === this || p instanceof AST_Export && p.is_default && this.expression instanceof AST_Function) return true; // workaround for Safari bug. // https://bugs.webkit.org/show_bug.cgi?id=123506 return this.expression instanceof AST_Function && p instanceof AST_PropAccess && p.expression === this && (p1 = output.parent(1)) instanceof AST_Assign && p1.left === p; }); PARENS(AST_New, function(output) { var p = output.parent(); if (!need_constructor_parens(this, output) && (p instanceof AST_PropAccess // (new Date).getTime(), (new Date)["getTime"]() || p instanceof AST_Call && p.expression === this)) // (new foo)(bar) return true; }); PARENS(AST_Number, function(output) { var p = output.parent(); if (p instanceof AST_PropAccess && p.expression === this) { var value = this.getValue(); if (value < 0 || /^0/.test(make_num(value))) { return true; } } }); PARENS(AST_BigInt, function(output) { var p = output.parent(); if (p instanceof AST_PropAccess && p.expression === this) { var value = this.getValue(); if (value.startsWith("-")) { return true; } } }); PARENS([ AST_Assign, AST_Conditional ], function(output) { var p = output.parent(); // !(a = false) → true if (p instanceof AST_Unary) return true; // 1 + (a = 2) + 3 → 6, side effect setting a = 2 if (p instanceof AST_Binary && !(p instanceof AST_Assign)) return true; // (a = func)() —or— new (a = Object)() if (p instanceof AST_Call && p.expression === this) return true; // (a = foo) ? bar : baz if (p instanceof AST_Conditional && p.condition === this) return true; // (a = foo)["prop"] —or— (a = foo).prop if (p instanceof AST_PropAccess && p.expression === this) return true; // ({a, b} = {a: 1, b: 2}), a destructuring assignment if (this instanceof AST_Assign && this.left instanceof AST_Destructuring && this.left.is_array === false) return true; }); /* -----[ PRINTERS ]----- */ DEFPRINT(AST_Directive, function(self, output) { output.print_string(self.value, self.quote); output.semicolon(); }); DEFPRINT(AST_Expansion, function (self, output) { output.print("..."); self.expression.print(output); }); DEFPRINT(AST_Destructuring, function (self, output) { output.print(self.is_array ? "[" : "{"); var len = self.names.length; self.names.forEach(function (name, i) { if (i > 0) output.comma(); name.print(output); // If the final element is a hole, we need to make sure it // doesn't look like a trailing comma, by inserting an actual // trailing comma. if (i == len - 1 && name instanceof AST_Hole) output.comma(); }); output.print(self.is_array ? "]" : "}"); }); DEFPRINT(AST_Debugger, function(self, output) { output.print("debugger"); output.semicolon(); }); /* -----[ statements ]----- */ function display_body(body, is_toplevel, output, allow_directives) { var last = body.length - 1; in_directive = allow_directives; body.forEach(function(stmt, i) { if (in_directive === true && !(stmt instanceof AST_Directive || stmt instanceof AST_EmptyStatement || (stmt instanceof AST_SimpleStatement && stmt.body instanceof AST_String) )) { in_directive = false; } if (!(stmt instanceof AST_EmptyStatement)) { output.indent(); stmt.print(output); if (!(i == last && is_toplevel)) { output.newline(); if (is_toplevel) output.newline(); } } if (in_directive === true && stmt instanceof AST_SimpleStatement && stmt.body instanceof AST_String ) { in_directive = false; } }); in_directive = false; } AST_StatementWithBody.DEFMETHOD("_do_print_body", function(output) { force_statement(this.body, output); }); DEFPRINT(AST_Statement, function(self, output) { self.body.print(output); output.semicolon(); }); DEFPRINT(AST_Toplevel, function(self, output) { display_body(self.body, true, output, true); output.print(""); }); DEFPRINT(AST_LabeledStatement, function(self, output) { self.label.print(output); output.colon(); self.body.print(output); }); DEFPRINT(AST_SimpleStatement, function(self, output) { self.body.print(output); output.semicolon(); }); function print_braced_empty(self, output) { output.print("{"); output.with_indent(output.next_indent(), function() { output.append_comments(self, true); }); output.print("}"); } function print_braced(self, output, allow_directives) { if (self.body.length > 0) { output.with_block(function() { display_body(self.body, false, output, allow_directives); }); } else print_braced_empty(self, output); } DEFPRINT(AST_BlockStatement, function(self, output) { print_braced(self, output); }); DEFPRINT(AST_EmptyStatement, function(self, output) { output.semicolon(); }); DEFPRINT(AST_Do, function(self, output) { output.print("do"); output.space(); make_block(self.body, output); output.space(); output.print("while"); output.space(); output.with_parens(function() { self.condition.print(output); }); output.semicolon(); }); DEFPRINT(AST_While, function(self, output) { output.print("while"); output.space(); output.with_parens(function() { self.condition.print(output); }); output.space(); self._do_print_body(output); }); DEFPRINT(AST_For, function(self, output) { output.print("for"); output.space(); output.with_parens(function() { if (self.init) { if (self.init instanceof AST_Definitions) { self.init.print(output); } else { parenthesize_for_noin(self.init, output, true); } output.print(";"); output.space(); } else { output.print(";"); } if (self.condition) { self.condition.print(output); output.print(";"); output.space(); } else { output.print(";"); } if (self.step) { self.step.print(output); } }); output.space(); self._do_print_body(output); }); DEFPRINT(AST_ForIn, function(self, output) { output.print("for"); if (self.await) { output.space(); output.print("await"); } output.space(); output.with_parens(function() { self.init.print(output); output.space(); output.print(self instanceof AST_ForOf ? "of" : "in"); output.space(); self.object.print(output); }); output.space(); self._do_print_body(output); }); DEFPRINT(AST_With, function(self, output) { output.print("with"); output.space(); output.with_parens(function() { self.expression.print(output); }); output.space(); self._do_print_body(output); }); /* -----[ functions ]----- */ AST_Lambda.DEFMETHOD("_do_print", function(output, nokeyword) { var self = this; if (!nokeyword) { if (self.async) { output.print("async"); output.space(); } output.print("function"); if (self.is_generator) { output.star(); } if (self.name) { output.space(); } } if (self.name instanceof AST_Symbol) { self.name.print(output); } else if (nokeyword && self.name instanceof AST_Node) { output.with_square(function() { self.name.print(output); // Computed method name }); } output.with_parens(function() { self.argnames.forEach(function(arg, i) { if (i) output.comma(); arg.print(output); }); }); output.space(); print_braced(self, output, true); }); DEFPRINT(AST_Lambda, function(self, output) { self._do_print(output); }); DEFPRINT(AST_PrefixedTemplateString, function(self, output) { var tag = self.prefix; var parenthesize_tag = tag instanceof AST_Arrow || tag instanceof AST_Binary || tag instanceof AST_Conditional || tag instanceof AST_Sequence || tag instanceof AST_Unary; if (parenthesize_tag) output.print("("); self.prefix.print(output); if (parenthesize_tag) output.print(")"); self.template_string.print(output); }); DEFPRINT(AST_TemplateString, function(self, output) { var is_tagged = output.parent() instanceof AST_PrefixedTemplateString; output.print("`"); for (var i = 0; i < self.segments.length; i++) { if (!(self.segments[i] instanceof AST_TemplateSegment)) { output.print("${"); self.segments[i].print(output); output.print("}"); } else if (is_tagged) { output.print(self.segments[i].raw); } else { output.print_template_string_chars(self.segments[i].value); } } output.print("`"); }); AST_Arrow.DEFMETHOD("_do_print", function(output) { var self = this; var parent = output.parent(); var needs_parens = (parent instanceof AST_Binary && !(parent instanceof AST_Assign)) || parent instanceof AST_Unary || (parent instanceof AST_Call && self === parent.expression); if (needs_parens) { output.print("("); } if (self.async) { output.print("async"); output.space(); } if (self.argnames.length === 1 && self.argnames[0] instanceof AST_Symbol) { self.argnames[0].print(output); } else { output.with_parens(function() { self.argnames.forEach(function(arg, i) { if (i) output.comma(); arg.print(output); }); }); } output.space(); output.print("=>"); output.space(); if (self.body instanceof AST_Node) { self.body.print(output); } else { print_braced(self, output); } if (needs_parens) { output.print(")"); } }); /* -----[ exits ]----- */ AST_Exit.DEFMETHOD("_do_print", function(output, kind) { output.print(kind); if (this.value) { output.space(); this.value.print(output); } output.semicolon(); }); DEFPRINT(AST_Return, function(self, output) { self._do_print(output, "return"); }); DEFPRINT(AST_Throw, function(self, output) { self._do_print(output, "throw"); }); /* -----[ yield ]----- */ DEFPRINT(AST_Yield, function(self, output) { var star = self.is_star ? "*" : ""; output.print("yield" + star); if (self.expression) { output.space(); self.expression.print(output); } }); DEFPRINT(AST_Await, function(self, output) { output.print("await"); output.space(); var e = self.expression; var parens = !( e instanceof AST_Call || e instanceof AST_SymbolRef || e instanceof AST_PropAccess || e instanceof AST_Unary || e instanceof AST_Constant ); if (parens) output.print("("); self.expression.print(output); if (parens) output.print(")"); }); /* -----[ loop control ]----- */ AST_LoopControl.DEFMETHOD("_do_print", function(output, kind) { output.print(kind); if (this.label) { output.space(); this.label.print(output); } output.semicolon(); }); DEFPRINT(AST_Break, function(self, output) { self._do_print(output, "break"); }); DEFPRINT(AST_Continue, function(self, output) { self._do_print(output, "continue"); }); /* -----[ if ]----- */ function make_then(self, output) { var b = self.body; if (output.option("braces") || output.option("ie8") && b instanceof AST_Do) return make_block(b, output); // The squeezer replaces "block"-s that contain only a single // statement with the statement itself; technically, the AST // is correct, but this can create problems when we output an // IF having an ELSE clause where the THEN clause ends in an // IF *without* an ELSE block (then the outer ELSE would refer // to the inner IF). This function checks for this case and // adds the block braces if needed. if (!b) return output.force_semicolon(); while (true) { if (b instanceof AST_If) { if (!b.alternative) { make_block(self.body, output); return; } b = b.alternative; } else if (b instanceof AST_StatementWithBody) { b = b.body; } else break; } force_statement(self.body, output); } DEFPRINT(AST_If, function(self, output) { output.print("if"); output.space(); output.with_parens(function() { self.condition.print(output); }); output.space(); if (self.alternative) { make_then(self, output); output.space(); output.print("else"); output.space(); if (self.alternative instanceof AST_If) self.alternative.print(output); else force_statement(self.alternative, output); } else { self._do_print_body(output); } }); /* -----[ switch ]----- */ DEFPRINT(AST_Switch, function(self, output) { output.print("switch"); output.space(); output.with_parens(function() { self.expression.print(output); }); output.space(); var last = self.body.length - 1; if (last < 0) print_braced_empty(self, output); else output.with_block(function() { self.body.forEach(function(branch, i) { output.indent(true); branch.print(output); if (i < last && branch.body.length > 0) output.newline(); }); }); }); AST_SwitchBranch.DEFMETHOD("_do_print_body", function(output) { output.newline(); this.body.forEach(function(stmt) { output.indent(); stmt.print(output); output.newline(); }); }); DEFPRINT(AST_Default, function(self, output) { output.print("default:"); self._do_print_body(output); }); DEFPRINT(AST_Case, function(self, output) { output.print("case"); output.space(); self.expression.print(output); output.print(":"); self._do_print_body(output); }); /* -----[ exceptions ]----- */ DEFPRINT(AST_Try, function(self, output) { output.print("try"); output.space(); print_braced(self, output); if (self.bcatch) { output.space(); self.bcatch.print(output); } if (self.bfinally) { output.space(); self.bfinally.print(output); } }); DEFPRINT(AST_Catch, function(self, output) { output.print("catch"); if (self.argname) { output.space(); output.with_parens(function() { self.argname.print(output); }); } output.space(); print_braced(self, output); }); DEFPRINT(AST_Finally, function(self, output) { output.print("finally"); output.space(); print_braced(self, output); }); /* -----[ var/const ]----- */ AST_Definitions.DEFMETHOD("_do_print", function(output, kind) { output.print(kind); output.space(); this.definitions.forEach(function(def, i) { if (i) output.comma(); def.print(output); }); var p = output.parent(); var in_for = p instanceof AST_For || p instanceof AST_ForIn; var output_semicolon = !in_for || p && p.init !== this; if (output_semicolon) output.semicolon(); }); DEFPRINT(AST_Let, function(self, output) { self._do_print(output, "let"); }); DEFPRINT(AST_Var, function(self, output) { self._do_print(output, "var"); }); DEFPRINT(AST_Const, function(self, output) { self._do_print(output, "const"); }); DEFPRINT(AST_Import, function(self, output) { output.print("import"); output.space(); if (self.imported_name) { self.imported_name.print(output); } if (self.imported_name && self.imported_names) { output.print(","); output.space(); } if (self.imported_names) { if (self.imported_names.length === 1 && self.imported_names[0].foreign_name.name === "*") { self.imported_names[0].print(output); } else { output.print("{"); self.imported_names.forEach(function (name_import, i) { output.space(); name_import.print(output); if (i < self.imported_names.length - 1) { output.print(","); } }); output.space(); output.print("}"); } } if (self.imported_name || self.imported_names) { output.space(); output.print("from"); output.space(); } self.module_name.print(output); output.semicolon(); }); DEFPRINT(AST_NameMapping, function(self, output) { var is_import = output.parent() instanceof AST_Import; var definition = self.name.definition(); var names_are_different = (definition && definition.mangled_name || self.name.name) !== self.foreign_name.name; if (names_are_different) { if (is_import) { output.print(self.foreign_name.name); } else { self.name.print(output); } output.space(); output.print("as"); output.space(); if (is_import) { self.name.print(output); } else { output.print(self.foreign_name.name); } } else { self.name.print(output); } }); DEFPRINT(AST_Export, function(self, output) { output.print("export"); output.space(); if (self.is_default) { output.print("default"); output.space(); } if (self.exported_names) { if (self.exported_names.length === 1 && self.exported_names[0].name.name === "*") { self.exported_names[0].print(output); } else { output.print("{"); self.exported_names.forEach(function(name_export, i) { output.space(); name_export.print(output); if (i < self.exported_names.length - 1) { output.print(","); } }); output.space(); output.print("}"); } } else if (self.exported_value) { self.exported_value.print(output); } else if (self.exported_definition) { self.exported_definition.print(output); if (self.exported_definition instanceof AST_Definitions) return; } if (self.module_name) { output.space(); output.print("from"); output.space(); self.module_name.print(output); } if (self.exported_value && !(self.exported_value instanceof AST_Defun || self.exported_value instanceof AST_Function || self.exported_value instanceof AST_Class) || self.module_name || self.exported_names ) { output.semicolon(); } }); function parenthesize_for_noin(node, output, noin) { var parens = false; // need to take some precautions here: // https://github.com/mishoo/UglifyJS2/issues/60 if (noin) node.walk(new TreeWalker(function(node) { if (parens || node instanceof AST_Scope) return true; if (node instanceof AST_Binary && node.operator == "in") { parens = true; return true; } })); node.print(output, parens); } DEFPRINT(AST_VarDef, function(self, output) { self.name.print(output); if (self.value) { output.space(); output.print("="); output.space(); var p = output.parent(1); var noin = p instanceof AST_For || p instanceof AST_ForIn; parenthesize_for_noin(self.value, output, noin); } }); /* -----[ other expressions ]----- */ DEFPRINT(AST_Call, function(self, output) { self.expression.print(output); if (self instanceof AST_New && !need_constructor_parens(self, output)) return; if (self.expression instanceof AST_Call || self.expression instanceof AST_Lambda) { output.add_mapping(self.start); } output.with_parens(function() { self.args.forEach(function(expr, i) { if (i) output.comma(); expr.print(output); }); }); }); DEFPRINT(AST_New, function(self, output) { output.print("new"); output.space(); AST_Call.prototype._codegen(self, output); }); AST_Sequence.DEFMETHOD("_do_print", function(output) { this.expressions.forEach(function(node, index) { if (index > 0) { output.comma(); if (output.should_break()) { output.newline(); output.indent(); } } node.print(output); }); }); DEFPRINT(AST_Sequence, function(self, output) { self._do_print(output); // var p = output.parent(); // if (p instanceof AST_Statement) { // output.with_indent(output.next_indent(), function(){ // self._do_print(output); // }); // } else { // self._do_print(output); // } }); DEFPRINT(AST_Dot, function(self, output) { var expr = self.expression; expr.print(output); var prop = self.property; if (output.option("ie8") && RESERVED_WORDS.has(prop)) { output.print("["); output.add_mapping(self.end); output.print_string(prop); output.print("]"); } else { if (expr instanceof AST_Number && expr.getValue() >= 0) { if (!/[xa-f.)]/i.test(output.last())) { output.print("."); } } output.print("."); // the name after dot would be mapped about here. output.add_mapping(self.end); output.print_name(prop); } }); DEFPRINT(AST_Sub, function(self, output) { self.expression.print(output); output.print("["); self.property.print(output); output.print("]"); }); DEFPRINT(AST_UnaryPrefix, function(self, output) { var op = self.operator; output.print(op); if (/^[a-z]/i.test(op) || (/[+-]$/.test(op) && self.expression instanceof AST_UnaryPrefix && /^[+-]/.test(self.expression.operator))) { output.space(); } self.expression.print(output); }); DEFPRINT(AST_UnaryPostfix, function(self, output) { self.expression.print(output); output.print(self.operator); }); DEFPRINT(AST_Binary, function(self, output) { var op = self.operator; self.left.print(output); if (op[0] == ">" /* ">>" ">>>" ">" ">=" */ && self.left instanceof AST_UnaryPostfix && self.left.operator == "--") { // space is mandatory to avoid outputting --> output.print(" "); } else { // the space is optional depending on "beautify" output.space(); } output.print(op); if ((op == "<" || op == "<<") && self.right instanceof AST_UnaryPrefix && self.right.operator == "!" && self.right.expression instanceof AST_UnaryPrefix && self.right.expression.operator == "--") { // space is mandatory to avoid outputting ") && S.newline_before) { forward(3); skip_line_comment("comment4"); continue; } } var ch = peek(); if (!ch) return token("eof"); var code = ch.charCodeAt(0); switch (code) { case 34: case 39: return read_string(); case 46: return handle_dot(); case 47: { var tok = handle_slash(); if (tok === next_token) continue; return tok; } case 61: return handle_eq_sign(); case 96: return read_template_characters(true); case 123: S.brace_counter++; break; case 125: S.brace_counter--; if (S.template_braces.length > 0 && S.template_braces[S.template_braces.length - 1] === S.brace_counter) return read_template_characters(false); break; } if (is_digit(code)) return read_num(); if (PUNC_CHARS.has(ch)) return token("punc", next()); if (OPERATOR_CHARS.has(ch)) return read_operator(); if (code == 92 || is_identifier_start(ch)) return read_word(); break; } parse_error("Unexpected character '" + ch + "'"); } next_token.next = next; next_token.peek = peek; next_token.context = function(nc) { if (nc) S = nc; return S; }; next_token.add_directive = function(directive) { S.directive_stack[S.directive_stack.length - 1].push(directive); if (S.directives[directive] === undefined) { S.directives[directive] = 1; } else { S.directives[directive]++; } }; next_token.push_directives_stack = function() { S.directive_stack.push([]); }; next_token.pop_directives_stack = function() { var directives = S.directive_stack[S.directive_stack.length - 1]; for (var i = 0; i < directives.length; i++) { S.directives[directives[i]]--; } S.directive_stack.pop(); }; next_token.has_directive = function(directive) { return S.directives[directive] > 0; }; return next_token; } /* -----[ Parser (constants) ]----- */ var UNARY_PREFIX = makePredicate([ "typeof", "void", "delete", "--", "++", "!", "~", "-", "+" ]); var UNARY_POSTFIX = makePredicate([ "--", "++" ]); var ASSIGNMENT = makePredicate([ "=", "+=", "-=", "/=", "*=", "**=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=" ]); var PRECEDENCE = (function(a, ret) { for (var i = 0; i < a.length; ++i) { var b = a[i]; for (var j = 0; j < b.length; ++j) { ret[b[j]] = i + 1; } } return ret; })( [ ["||"], ["&&"], ["|"], ["^"], ["&"], ["==", "===", "!=", "!=="], ["<", ">", "<=", ">=", "in", "instanceof"], [">>", "<<", ">>>"], ["+", "-"], ["*", "/", "%"], ["**"] ], {} ); var ATOMIC_START_TOKEN = makePredicate([ "atom", "num", "big_int", "string", "regexp", "name" ]); /* -----[ Parser ]----- */ function parse($TEXT, options) { options = defaults(options, { bare_returns : false, ecma : 8, expression : false, filename : null, html5_comments : true, module : false, shebang : true, strict : false, toplevel : null, }, true); var S = { input : (typeof $TEXT == "string" ? tokenizer($TEXT, options.filename, options.html5_comments, options.shebang) : $TEXT), token : null, prev : null, peeked : null, in_function : 0, in_async : -1, in_generator : -1, in_directives : true, in_loop : 0, labels : [] }; S.token = next(); function is(type, value) { return is_token(S.token, type, value); } function peek() { return S.peeked || (S.peeked = S.input()); } function next() { S.prev = S.token; if (!S.peeked) peek(); S.token = S.peeked; S.peeked = null; S.in_directives = S.in_directives && ( S.token.type == "string" || is("punc", ";") ); return S.token; } function prev() { return S.prev; } function croak(msg, line, col, pos) { var ctx = S.input.context(); js_error(msg, ctx.filename, line != null ? line : ctx.tokline, col != null ? col : ctx.tokcol, pos != null ? pos : ctx.tokpos); } function token_error(token, msg) { croak(msg, token.line, token.col); } function unexpected(token) { if (token == null) token = S.token; token_error(token, "Unexpected token: " + token.type + " (" + token.value + ")"); } function expect_token(type, val) { if (is(type, val)) { return next(); } token_error(S.token, "Unexpected token " + S.token.type + " «" + S.token.value + "»" + ", expected " + type + " «" + val + "»"); } function expect(punc) { return expect_token("punc", punc); } function has_newline_before(token) { return token.nlb || !token.comments_before.every((comment) => !comment.nlb); } function can_insert_semicolon() { return !options.strict && (is("eof") || is("punc", "}") || has_newline_before(S.token)); } function is_in_generator() { return S.in_generator === S.in_function; } function is_in_async() { return S.in_async === S.in_function; } function semicolon(optional) { if (is("punc", ";")) next(); else if (!optional && !can_insert_semicolon()) unexpected(); } function parenthesised() { expect("("); var exp = expression(true); expect(")"); return exp; } function embed_tokens(parser) { return function() { var start = S.token; var expr = parser.apply(null, arguments); var end = prev(); expr.start = start; expr.end = end; return expr; }; } function handle_regexp() { if (is("operator", "/") || is("operator", "/=")) { S.peeked = null; S.token = S.input(S.token.value.substr(1)); // force regexp } } var statement = embed_tokens(function(is_export_default, is_for_body, is_if_body) { handle_regexp(); switch (S.token.type) { case "string": if (S.in_directives) { var token = peek(); if (!S.token.raw.includes("\\") && (is_token(token, "punc", ";") || is_token(token, "punc", "}") || has_newline_before(token) || is_token(token, "eof"))) { S.input.add_directive(S.token.value); } else { S.in_directives = false; } } var dir = S.in_directives, stat = simple_statement(); return dir && stat.body instanceof AST_String ? new AST_Directive(stat.body) : stat; case "template_head": case "num": case "big_int": case "regexp": case "operator": case "atom": return simple_statement(); case "name": if (S.token.value == "async" && is_token(peek(), "keyword", "function")) { next(); next(); if (is_for_body) { croak("functions are not allowed as the body of a loop"); } return function_(AST_Defun, false, true, is_export_default); } if (S.token.value == "import" && !is_token(peek(), "punc", "(")) { next(); var node = import_(); semicolon(); return node; } return is_token(peek(), "punc", ":") ? labeled_statement() : simple_statement(); case "punc": switch (S.token.value) { case "{": return new AST_BlockStatement({ start : S.token, body : block_(), end : prev() }); case "[": case "(": return simple_statement(); case ";": S.in_directives = false; next(); return new AST_EmptyStatement(); default: unexpected(); } case "keyword": switch (S.token.value) { case "break": next(); return break_cont(AST_Break); case "continue": next(); return break_cont(AST_Continue); case "debugger": next(); semicolon(); return new AST_Debugger(); case "do": next(); var body = in_loop(statement); expect_token("keyword", "while"); var condition = parenthesised(); semicolon(true); return new AST_Do({ body : body, condition : condition }); case "while": next(); return new AST_While({ condition : parenthesised(), body : in_loop(function() { return statement(false, true); }) }); case "for": next(); return for_(); case "class": next(); if (is_for_body) { croak("classes are not allowed as the body of a loop"); } if (is_if_body) { croak("classes are not allowed as the body of an if"); } return class_(AST_DefClass); case "function": next(); if (is_for_body) { croak("functions are not allowed as the body of a loop"); } return function_(AST_Defun, false, false, is_export_default); case "if": next(); return if_(); case "return": if (S.in_function == 0 && !options.bare_returns) croak("'return' outside of function"); next(); var value = null; if (is("punc", ";")) { next(); } else if (!can_insert_semicolon()) { value = expression(true); semicolon(); } return new AST_Return({ value: value }); case "switch": next(); return new AST_Switch({ expression : parenthesised(), body : in_loop(switch_body_) }); case "throw": next(); if (has_newline_before(S.token)) croak("Illegal newline after 'throw'"); var value = expression(true); semicolon(); return new AST_Throw({ value: value }); case "try": next(); return try_(); case "var": next(); var node = var_(); semicolon(); return node; case "let": next(); var node = let_(); semicolon(); return node; case "const": next(); var node = const_(); semicolon(); return node; case "with": if (S.input.has_directive("use strict")) { croak("Strict mode may not include a with statement"); } next(); return new AST_With({ expression : parenthesised(), body : statement() }); case "export": if (!is_token(peek(), "punc", "(")) { next(); var node = export_(); if (is("punc", ";")) semicolon(); return node; } } } unexpected(); }); function labeled_statement() { var label = as_symbol(AST_Label); if (label.name === "await" && is_in_async()) { token_error(S.prev, "await cannot be used as label inside async function"); } if (S.labels.some((l) => l.name === label.name)) { // ECMA-262, 12.12: An ECMAScript program is considered // syntactically incorrect if it contains a // LabelledStatement that is enclosed by a // LabelledStatement with the same Identifier as label. croak("Label " + label.name + " defined twice"); } expect(":"); S.labels.push(label); var stat = statement(); S.labels.pop(); if (!(stat instanceof AST_IterationStatement)) { // check for `continue` that refers to this label. // those should be reported as syntax errors. // https://github.com/mishoo/UglifyJS2/issues/287 label.references.forEach(function(ref) { if (ref instanceof AST_Continue) { ref = ref.label.start; croak("Continue label `" + label.name + "` refers to non-IterationStatement.", ref.line, ref.col, ref.pos); } }); } return new AST_LabeledStatement({ body: stat, label: label }); } function simple_statement(tmp) { return new AST_SimpleStatement({ body: (tmp = expression(true), semicolon(), tmp) }); } function break_cont(type) { var label = null, ldef; if (!can_insert_semicolon()) { label = as_symbol(AST_LabelRef, true); } if (label != null) { ldef = S.labels.find((l) => l.name === label.name); if (!ldef) croak("Undefined label " + label.name); label.thedef = ldef; } else if (S.in_loop == 0) croak(type.TYPE + " not inside a loop or switch"); semicolon(); var stat = new type({ label: label }); if (ldef) ldef.references.push(stat); return stat; } function for_() { var for_await_error = "`for await` invalid in this context"; var await_tok = S.token; if (await_tok.type == "name" && await_tok.value == "await") { if (!is_in_async()) { token_error(await_tok, for_await_error); } next(); } else { await_tok = false; } expect("("); var init = null; if (!is("punc", ";")) { init = is("keyword", "var") ? (next(), var_(true)) : is("keyword", "let") ? (next(), let_(true)) : is("keyword", "const") ? (next(), const_(true)) : expression(true, true); var is_in = is("operator", "in"); var is_of = is("name", "of"); if (await_tok && !is_of) { token_error(await_tok, for_await_error); } if (is_in || is_of) { if (init instanceof AST_Definitions) { if (init.definitions.length > 1) token_error(init.start, "Only one variable declaration allowed in for..in loop"); } else if (!(is_assignable(init) || (init = to_destructuring(init)) instanceof AST_Destructuring)) { token_error(init.start, "Invalid left-hand side in for..in loop"); } next(); if (is_in) { return for_in(init); } else { return for_of(init, !!await_tok); } } } else if (await_tok) { token_error(await_tok, for_await_error); } return regular_for(init); } function regular_for(init) { expect(";"); var test = is("punc", ";") ? null : expression(true); expect(";"); var step = is("punc", ")") ? null : expression(true); expect(")"); return new AST_For({ init : init, condition : test, step : step, body : in_loop(function() { return statement(false, true); }) }); } function for_of(init, is_await) { var lhs = init instanceof AST_Definitions ? init.definitions[0].name : null; var obj = expression(true); expect(")"); return new AST_ForOf({ await : is_await, init : init, name : lhs, object : obj, body : in_loop(function() { return statement(false, true); }) }); } function for_in(init) { var obj = expression(true); expect(")"); return new AST_ForIn({ init : init, object : obj, body : in_loop(function() { return statement(false, true); }) }); } var arrow_function = function(start, argnames, is_async) { if (has_newline_before(S.token)) { croak("Unexpected newline before arrow (=>)"); } expect_token("arrow", "=>"); var body = _function_body(is("punc", "{"), false, is_async); var end = body instanceof Array && body.length ? body[body.length - 1].end : body instanceof Array ? start : body.end; return new AST_Arrow({ start : start, end : end, async : is_async, argnames : argnames, body : body }); }; var function_ = function(ctor, is_generator_property, is_async, is_export_default) { var start = S.token; var in_statement = ctor === AST_Defun; var is_generator = is("operator", "*"); if (is_generator) { next(); } var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null; if (in_statement && !name) { if (is_export_default) { ctor = AST_Function; } else { unexpected(); } } if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration)) unexpected(prev()); var args = []; var body = _function_body(true, is_generator || is_generator_property, is_async, name, args); return new ctor({ start : args.start, end : body.end, is_generator: is_generator, async : is_async, name : name, argnames: args, body : body }); }; function track_used_binding_identifiers(is_parameter, strict) { var parameters = new Set(); var duplicate = false; var default_assignment = false; var spread = false; var strict_mode = !!strict; var tracker = { add_parameter: function(token) { if (parameters.has(token.value)) { if (duplicate === false) { duplicate = token; } tracker.check_strict(); } else { parameters.add(token.value); if (is_parameter) { switch (token.value) { case "arguments": case "eval": case "yield": if (strict_mode) { token_error(token, "Unexpected " + token.value + " identifier as parameter inside strict mode"); } break; default: if (RESERVED_WORDS.has(token.value)) { unexpected(); } } } } }, mark_default_assignment: function(token) { if (default_assignment === false) { default_assignment = token; } }, mark_spread: function(token) { if (spread === false) { spread = token; } }, mark_strict_mode: function() { strict_mode = true; }, is_strict: function() { return default_assignment !== false || spread !== false || strict_mode; }, check_strict: function() { if (tracker.is_strict() && duplicate !== false) { token_error(duplicate, "Parameter " + duplicate.value + " was used already"); } } }; return tracker; } function parameters(params) { var start = S.token; var used_parameters = track_used_binding_identifiers(true, S.input.has_directive("use strict")); expect("("); while (!is("punc", ")")) { var param = parameter(used_parameters); params.push(param); if (!is("punc", ")")) { expect(","); if (is("punc", ")") && options.ecma < 8) unexpected(); } if (param instanceof AST_Expansion) { break; } } next(); } function parameter(used_parameters, symbol_type) { var param; var expand = false; if (used_parameters === undefined) { used_parameters = track_used_binding_identifiers(true, S.input.has_directive("use strict")); } if (is("expand", "...")) { expand = S.token; used_parameters.mark_spread(S.token); next(); } param = binding_element(used_parameters, symbol_type); if (is("operator", "=") && expand === false) { used_parameters.mark_default_assignment(S.token); next(); param = new AST_DefaultAssign({ start: param.start, left: param, operator: "=", right: expression(false), end: S.token }); } if (expand !== false) { if (!is("punc", ")")) { unexpected(); } param = new AST_Expansion({ start: expand, expression: param, end: expand }); } used_parameters.check_strict(); return param; } function binding_element(used_parameters, symbol_type) { var elements = []; var first = true; var is_expand = false; var expand_token; var first_token = S.token; if (used_parameters === undefined) { used_parameters = track_used_binding_identifiers(false, S.input.has_directive("use strict")); } symbol_type = symbol_type === undefined ? AST_SymbolFunarg : symbol_type; if (is("punc", "[")) { next(); while (!is("punc", "]")) { if (first) { first = false; } else { expect(","); } if (is("expand", "...")) { is_expand = true; expand_token = S.token; used_parameters.mark_spread(S.token); next(); } if (is("punc")) { switch (S.token.value) { case ",": elements.push(new AST_Hole({ start: S.token, end: S.token })); continue; case "]": // Trailing comma after last element break; case "[": case "{": elements.push(binding_element(used_parameters, symbol_type)); break; default: unexpected(); } } else if (is("name")) { used_parameters.add_parameter(S.token); elements.push(as_symbol(symbol_type)); } else { croak("Invalid function parameter"); } if (is("operator", "=") && is_expand === false) { used_parameters.mark_default_assignment(S.token); next(); elements[elements.length - 1] = new AST_DefaultAssign({ start: elements[elements.length - 1].start, left: elements[elements.length - 1], operator: "=", right: expression(false), end: S.token }); } if (is_expand) { if (!is("punc", "]")) { croak("Rest element must be last element"); } elements[elements.length - 1] = new AST_Expansion({ start: expand_token, expression: elements[elements.length - 1], end: expand_token }); } } expect("]"); used_parameters.check_strict(); return new AST_Destructuring({ start: first_token, names: elements, is_array: true, end: prev() }); } else if (is("punc", "{")) { next(); while (!is("punc", "}")) { if (first) { first = false; } else { expect(","); } if (is("expand", "...")) { is_expand = true; expand_token = S.token; used_parameters.mark_spread(S.token); next(); } if (is("name") && (is_token(peek(), "punc") || is_token(peek(), "operator")) && [",", "}", "="].includes(peek().value)) { used_parameters.add_parameter(S.token); var start = prev(); var value = as_symbol(symbol_type); if (is_expand) { elements.push(new AST_Expansion({ start: expand_token, expression: value, end: value.end, })); } else { elements.push(new AST_ObjectKeyVal({ start: start, key: value.name, value: value, end: value.end, })); } } else if (is("punc", "}")) { continue; // Allow trailing hole } else { var property_token = S.token; var property = as_property_name(); if (property === null) { unexpected(prev()); } else if (prev().type === "name" && !is("punc", ":")) { elements.push(new AST_ObjectKeyVal({ start: prev(), key: property, value: new symbol_type({ start: prev(), name: property, end: prev() }), end: prev() })); } else { expect(":"); elements.push(new AST_ObjectKeyVal({ start: property_token, quote: property_token.quote, key: property, value: binding_element(used_parameters, symbol_type), end: prev() })); } } if (is_expand) { if (!is("punc", "}")) { croak("Rest element must be last element"); } } else if (is("operator", "=")) { used_parameters.mark_default_assignment(S.token); next(); elements[elements.length - 1].value = new AST_DefaultAssign({ start: elements[elements.length - 1].value.start, left: elements[elements.length - 1].value, operator: "=", right: expression(false), end: S.token }); } } expect("}"); used_parameters.check_strict(); return new AST_Destructuring({ start: first_token, names: elements, is_array: false, end: prev() }); } else if (is("name")) { used_parameters.add_parameter(S.token); return as_symbol(symbol_type); } else { croak("Invalid function parameter"); } } function params_or_seq_(allow_arrows, maybe_sequence) { var spread_token; var invalid_sequence; var trailing_comma; var a = []; expect("("); while (!is("punc", ")")) { if (spread_token) unexpected(spread_token); if (is("expand", "...")) { spread_token = S.token; if (maybe_sequence) invalid_sequence = S.token; next(); a.push(new AST_Expansion({ start: prev(), expression: expression(), end: S.token, })); } else { a.push(expression()); } if (!is("punc", ")")) { expect(","); if (is("punc", ")")) { if (options.ecma < 8) unexpected(); trailing_comma = prev(); if (maybe_sequence) invalid_sequence = trailing_comma; } } } expect(")"); if (allow_arrows && is("arrow", "=>")) { if (spread_token && trailing_comma) unexpected(trailing_comma); } else if (invalid_sequence) { unexpected(invalid_sequence); } return a; } function _function_body(block, generator, is_async, name, args) { var loop = S.in_loop; var labels = S.labels; var current_generator = S.in_generator; var current_async = S.in_async; ++S.in_function; if (generator) S.in_generator = S.in_function; if (is_async) S.in_async = S.in_function; if (args) parameters(args); if (block) S.in_directives = true; S.in_loop = 0; S.labels = []; if (block) { S.input.push_directives_stack(); var a = block_(); if (name) _verify_symbol(name); if (args) args.forEach(_verify_symbol); S.input.pop_directives_stack(); } else { var a = expression(false); } --S.in_function; S.in_loop = loop; S.labels = labels; S.in_generator = current_generator; S.in_async = current_async; return a; } function _await_expression() { // Previous token must be "await" and not be interpreted as an identifier if (!is_in_async()) { croak("Unexpected await expression outside async function", S.prev.line, S.prev.col, S.prev.pos); } // the await expression is parsed as a unary expression in Babel return new AST_Await({ start: prev(), end: S.token, expression : maybe_unary(true), }); } function _yield_expression() { // Previous token must be keyword yield and not be interpret as an identifier if (!is_in_generator()) { croak("Unexpected yield expression outside generator function", S.prev.line, S.prev.col, S.prev.pos); } var start = S.token; var star = false; var has_expression = true; // Attempt to get expression or star (and then the mandatory expression) // behind yield on the same line. // // If nothing follows on the same line of the yieldExpression, // it should default to the value `undefined` for yield to return. // In that case, the `undefined` stored as `null` in ast. // // Note 1: It isn't allowed for yield* to close without an expression // Note 2: If there is a nlb between yield and star, it is interpret as // yield * if (can_insert_semicolon() || (is("punc") && PUNC_AFTER_EXPRESSION.has(S.token.value))) { has_expression = false; } else if (is("operator", "*")) { star = true; next(); } return new AST_Yield({ start : start, is_star : star, expression : has_expression ? expression() : null, end : prev() }); } function if_() { var cond = parenthesised(), body = statement(false, false, true), belse = null; if (is("keyword", "else")) { next(); belse = statement(false, false, true); } return new AST_If({ condition : cond, body : body, alternative : belse }); } function block_() { expect("{"); var a = []; while (!is("punc", "}")) { if (is("eof")) unexpected(); a.push(statement()); } next(); return a; } function switch_body_() { expect("{"); var a = [], cur = null, branch = null, tmp; while (!is("punc", "}")) { if (is("eof")) unexpected(); if (is("keyword", "case")) { if (branch) branch.end = prev(); cur = []; branch = new AST_Case({ start : (tmp = S.token, next(), tmp), expression : expression(true), body : cur }); a.push(branch); expect(":"); } else if (is("keyword", "default")) { if (branch) branch.end = prev(); cur = []; branch = new AST_Default({ start : (tmp = S.token, next(), expect(":"), tmp), body : cur }); a.push(branch); } else { if (!cur) unexpected(); cur.push(statement()); } } if (branch) branch.end = prev(); next(); return a; } function try_() { var body = block_(), bcatch = null, bfinally = null; if (is("keyword", "catch")) { var start = S.token; next(); if (is("punc", "{")) { var name = null; } else { expect("("); var name = parameter(undefined, AST_SymbolCatch); expect(")"); } bcatch = new AST_Catch({ start : start, argname : name, body : block_(), end : prev() }); } if (is("keyword", "finally")) { var start = S.token; next(); bfinally = new AST_Finally({ start : start, body : block_(), end : prev() }); } if (!bcatch && !bfinally) croak("Missing catch/finally blocks"); return new AST_Try({ body : body, bcatch : bcatch, bfinally : bfinally }); } function vardefs(no_in, kind) { var a = []; var def; for (;;) { var sym_type = kind === "var" ? AST_SymbolVar : kind === "const" ? AST_SymbolConst : kind === "let" ? AST_SymbolLet : null; if (is("punc", "{") || is("punc", "[")) { def = new AST_VarDef({ start: S.token, name: binding_element(undefined ,sym_type), value: is("operator", "=") ? (expect_token("operator", "="), expression(false, no_in)) : null, end: prev() }); } else { def = new AST_VarDef({ start : S.token, name : as_symbol(sym_type), value : is("operator", "=") ? (next(), expression(false, no_in)) : !no_in && kind === "const" ? croak("Missing initializer in const declaration") : null, end : prev() }); if (def.name.name == "import") croak("Unexpected token: import"); } a.push(def); if (!is("punc", ",")) break; next(); } return a; } var var_ = function(no_in) { return new AST_Var({ start : prev(), definitions : vardefs(no_in, "var"), end : prev() }); }; var let_ = function(no_in) { return new AST_Let({ start : prev(), definitions : vardefs(no_in, "let"), end : prev() }); }; var const_ = function(no_in) { return new AST_Const({ start : prev(), definitions : vardefs(no_in, "const"), end : prev() }); }; var new_ = function(allow_calls) { var start = S.token; expect_token("operator", "new"); if (is("punc", ".")) { next(); expect_token("name", "target"); return subscripts(new AST_NewTarget({ start : start, end : prev() }), allow_calls); } var newexp = expr_atom(false), args; if (is("punc", "(")) { next(); args = expr_list(")", options.ecma >= 8); } else { args = []; } var call = new AST_New({ start : start, expression : newexp, args : args, end : prev() }); mark_pure(call); return subscripts(call, allow_calls); }; function as_atom_node() { var tok = S.token, ret; switch (tok.type) { case "name": ret = _make_symbol(AST_SymbolRef); break; case "num": ret = new AST_Number({ start: tok, end: tok, value: tok.value }); break; case "big_int": ret = new AST_BigInt({ start: tok, end: tok, value: tok.value }); break; case "string": ret = new AST_String({ start : tok, end : tok, value : tok.value, quote : tok.quote }); break; case "regexp": ret = new AST_RegExp({ start: tok, end: tok, value: tok.value }); break; case "atom": switch (tok.value) { case "false": ret = new AST_False({ start: tok, end: tok }); break; case "true": ret = new AST_True({ start: tok, end: tok }); break; case "null": ret = new AST_Null({ start: tok, end: tok }); break; } break; } next(); return ret; } function to_fun_args(ex, _, __, default_seen_above) { var insert_default = function(ex, default_value) { if (default_value) { return new AST_DefaultAssign({ start: ex.start, left: ex, operator: "=", right: default_value, end: default_value.end }); } return ex; }; if (ex instanceof AST_Object) { return insert_default(new AST_Destructuring({ start: ex.start, end: ex.end, is_array: false, names: ex.properties.map(to_fun_args) }), default_seen_above); } else if (ex instanceof AST_ObjectKeyVal) { ex.value = to_fun_args(ex.value, 0, [ex.key]); return insert_default(ex, default_seen_above); } else if (ex instanceof AST_Hole) { return ex; } else if (ex instanceof AST_Destructuring) { ex.names = ex.names.map(to_fun_args); return insert_default(ex, default_seen_above); } else if (ex instanceof AST_SymbolRef) { return insert_default(new AST_SymbolFunarg({ name: ex.name, start: ex.start, end: ex.end }), default_seen_above); } else if (ex instanceof AST_Expansion) { ex.expression = to_fun_args(ex.expression); return insert_default(ex, default_seen_above); } else if (ex instanceof AST_Array) { return insert_default(new AST_Destructuring({ start: ex.start, end: ex.end, is_array: true, names: ex.elements.map(to_fun_args) }), default_seen_above); } else if (ex instanceof AST_Assign) { return insert_default(to_fun_args(ex.left, undefined, undefined, ex.right), default_seen_above); } else if (ex instanceof AST_DefaultAssign) { ex.left = to_fun_args(ex.left, 0, [ex.left]); return ex; } else { croak("Invalid function parameter", ex.start.line, ex.start.col); } } var expr_atom = function(allow_calls, allow_arrows) { if (is("operator", "new")) { return new_(allow_calls); } var start = S.token; var peeked; var async = is("name", "async") && (peeked = peek()).value != "[" && peeked.type != "arrow" && as_atom_node(); if (is("punc")) { switch (S.token.value) { case "(": if (async && !allow_calls) break; var exprs = params_or_seq_(allow_arrows, !async); if (allow_arrows && is("arrow", "=>")) { return arrow_function(start, exprs.map(to_fun_args), !!async); } var ex = async ? new AST_Call({ expression: async, args: exprs }) : exprs.length == 1 ? exprs[0] : new AST_Sequence({ expressions: exprs }); if (ex.start) { var len = start.comments_before.length; [].unshift.apply(ex.start.comments_before, start.comments_before); start.comments_before = ex.start.comments_before; start.comments_before_length = len; if (len == 0 && start.comments_before.length > 0) { var comment = start.comments_before[0]; if (!comment.nlb) { comment.nlb = start.nlb; start.nlb = false; } } start.comments_after = ex.start.comments_after; } ex.start = start; var end = prev(); if (ex.end) { end.comments_before = ex.end.comments_before; [].push.apply(ex.end.comments_after, end.comments_after); end.comments_after = ex.end.comments_after; } ex.end = end; if (ex instanceof AST_Call) mark_pure(ex); return subscripts(ex, allow_calls); case "[": return subscripts(array_(), allow_calls); case "{": return subscripts(object_or_destructuring_(), allow_calls); } if (!async) unexpected(); } if (allow_arrows && is("name") && is_token(peek(), "arrow")) { var param = new AST_SymbolFunarg({ name: S.token.value, start: start, end: start, }); next(); return arrow_function(start, [param], !!async); } if (is("keyword", "function")) { next(); var func = function_(AST_Function, false, !!async); func.start = start; func.end = prev(); return subscripts(func, allow_calls); } if (async) return subscripts(async, allow_calls); if (is("keyword", "class")) { next(); var cls = class_(AST_ClassExpression); cls.start = start; cls.end = prev(); return subscripts(cls, allow_calls); } if (is("template_head")) { return subscripts(template_string(false), allow_calls); } if (ATOMIC_START_TOKEN.has(S.token.type)) { return subscripts(as_atom_node(), allow_calls); } unexpected(); }; function template_string(tagged) { var segments = [], start = S.token; segments.push(new AST_TemplateSegment({ start: S.token, raw: S.token.raw, value: S.token.value, end: S.token })); while (S.token.end === false) { next(); handle_regexp(); segments.push(expression(true)); if (!is_token("template_substitution")) { unexpected(); } segments.push(new AST_TemplateSegment({ start: S.token, raw: S.token.raw, value: S.token.value, end: S.token })); } next(); return new AST_TemplateString({ start: start, segments: segments, end: S.token }); } function expr_list(closing, allow_trailing_comma, allow_empty) { var first = true, a = []; while (!is("punc", closing)) { if (first) first = false; else expect(","); if (allow_trailing_comma && is("punc", closing)) break; if (is("punc", ",") && allow_empty) { a.push(new AST_Hole({ start: S.token, end: S.token })); } else if (is("expand", "...")) { next(); a.push(new AST_Expansion({start: prev(), expression: expression(),end: S.token})); } else { a.push(expression(false)); } } next(); return a; } var array_ = embed_tokens(function() { expect("["); return new AST_Array({ elements: expr_list("]", !options.strict, true) }); }); var create_accessor = embed_tokens(function(is_generator, is_async) { return function_(AST_Accessor, is_generator, is_async); }); var object_or_destructuring_ = embed_tokens(function object_or_destructuring_() { var start = S.token, first = true, a = []; expect("{"); while (!is("punc", "}")) { if (first) first = false; else expect(","); if (!options.strict && is("punc", "}")) // allow trailing comma break; start = S.token; if (start.type == "expand") { next(); a.push(new AST_Expansion({ start: start, expression: expression(false), end: prev(), })); continue; } var name = as_property_name(); var value; // Check property and fetch value if (!is("punc", ":")) { var concise = concise_method_or_getset(name, start); if (concise) { a.push(concise); continue; } value = new AST_SymbolRef({ start: prev(), name: name, end: prev() }); } else if (name === null) { unexpected(prev()); } else { next(); // `:` - see first condition value = expression(false); } // Check for default value and alter value accordingly if necessary if (is("operator", "=")) { next(); value = new AST_Assign({ start: start, left: value, operator: "=", right: expression(false), end: prev() }); } // Create property a.push(new AST_ObjectKeyVal({ start: start, quote: start.quote, key: name instanceof AST_Node ? name : "" + name, value: value, end: prev() })); } next(); return new AST_Object({ properties: a }); }); function class_(KindOfClass) { var start, method, class_name, extends_, a = []; S.input.push_directives_stack(); // Push directive stack, but not scope stack S.input.add_directive("use strict"); if (S.token.type == "name" && S.token.value != "extends") { class_name = as_symbol(KindOfClass === AST_DefClass ? AST_SymbolDefClass : AST_SymbolClass); } if (KindOfClass === AST_DefClass && !class_name) { unexpected(); } if (S.token.value == "extends") { next(); extends_ = expression(true); } expect("{"); if (is("punc", ";")) { next(); } // Leading semicolons are okay in class bodies. while (!is("punc", "}")) { start = S.token; method = concise_method_or_getset(as_property_name(), start, true); if (!method) { unexpected(); } a.push(method); if (is("punc", ";")) { next(); } } S.input.pop_directives_stack(); next(); return new KindOfClass({ start: start, name: class_name, extends: extends_, properties: a, end: prev(), }); } function concise_method_or_getset(name, start, is_class) { var get_ast = function(name, token) { if (typeof name === "string" || typeof name === "number") { return new AST_SymbolMethod({ start: token, name: "" + name, end: prev() }); } else if (name === null) { unexpected(); } return name; }; var is_async = false; var is_static = false; var is_generator = false; var property_token = start; if (is_class && name === "static" && !is("punc", "(")) { is_static = true; property_token = S.token; name = as_property_name(); } if (name === "async" && !is("punc", "(") && !is("punc", ",") && !is("punc", "}")) { is_async = true; property_token = S.token; name = as_property_name(); } if (name === null) { is_generator = true; property_token = S.token; name = as_property_name(); if (name === null) { unexpected(); } } if (is("punc", "(")) { name = get_ast(name, start); var node = new AST_ConciseMethod({ start : start, static : is_static, is_generator: is_generator, async : is_async, key : name, quote : name instanceof AST_SymbolMethod ? property_token.quote : undefined, value : create_accessor(is_generator, is_async), end : prev() }); return node; } property_token = S.token; if (name == "get") { if (!is("punc") || is("punc", "[")) { name = get_ast(as_property_name(), start); return new AST_ObjectGetter({ start : start, static: is_static, key : name, quote : name instanceof AST_SymbolMethod ? property_token.quote : undefined, value : create_accessor(), end : prev() }); } } else if (name == "set") { if (!is("punc") || is("punc", "[")) { name = get_ast(as_property_name(), start); return new AST_ObjectSetter({ start : start, static: is_static, key : name, quote : name instanceof AST_SymbolMethod ? property_token.quote : undefined, value : create_accessor(), end : prev() }); } } } function import_() { var start = prev(); var imported_name; var imported_names; if (is("name")) { imported_name = as_symbol(AST_SymbolImport); } if (is("punc", ",")) { next(); } imported_names = map_names(true); if (imported_names || imported_name) { expect_token("name", "from"); } var mod_str = S.token; if (mod_str.type !== "string") { unexpected(); } next(); return new AST_Import({ start: start, imported_name: imported_name, imported_names: imported_names, module_name: new AST_String({ start: mod_str, value: mod_str.value, quote: mod_str.quote, end: mod_str, }), end: S.token, }); } function map_name(is_import) { function make_symbol(type) { return new type({ name: as_property_name(), start: prev(), end: prev() }); } var foreign_type = is_import ? AST_SymbolImportForeign : AST_SymbolExportForeign; var type = is_import ? AST_SymbolImport : AST_SymbolExport; var start = S.token; var foreign_name; var name; if (is_import) { foreign_name = make_symbol(foreign_type); } else { name = make_symbol(type); } if (is("name", "as")) { next(); // The "as" word if (is_import) { name = make_symbol(type); } else { foreign_name = make_symbol(foreign_type); } } else if (is_import) { name = new type(foreign_name); } else { foreign_name = new foreign_type(name); } return new AST_NameMapping({ start: start, foreign_name: foreign_name, name: name, end: prev(), }); } function map_nameAsterisk(is_import, name) { var foreign_type = is_import ? AST_SymbolImportForeign : AST_SymbolExportForeign; var type = is_import ? AST_SymbolImport : AST_SymbolExport; var start = S.token; var foreign_name; var end = prev(); name = name || new type({ name: "*", start: start, end: end, }); foreign_name = new foreign_type({ name: "*", start: start, end: end, }); return new AST_NameMapping({ start: start, foreign_name: foreign_name, name: name, end: end, }); } function map_names(is_import) { var names; if (is("punc", "{")) { next(); names = []; while (!is("punc", "}")) { names.push(map_name(is_import)); if (is("punc", ",")) { next(); } } next(); } else if (is("operator", "*")) { var name; next(); if (is_import && is("name", "as")) { next(); // The "as" word name = as_symbol(is_import ? AST_SymbolImport : AST_SymbolExportForeign); } names = [map_nameAsterisk(is_import, name)]; } return names; } function export_() { var start = S.token; var is_default; var exported_names; if (is("keyword", "default")) { is_default = true; next(); } else if (exported_names = map_names(false)) { if (is("name", "from")) { next(); var mod_str = S.token; if (mod_str.type !== "string") { unexpected(); } next(); return new AST_Export({ start: start, is_default: is_default, exported_names: exported_names, module_name: new AST_String({ start: mod_str, value: mod_str.value, quote: mod_str.quote, end: mod_str, }), end: prev(), }); } else { return new AST_Export({ start: start, is_default: is_default, exported_names: exported_names, end: prev(), }); } } var node; var exported_value; var exported_definition; if (is("punc", "{") || is_default && (is("keyword", "class") || is("keyword", "function")) && is_token(peek(), "punc")) { exported_value = expression(false); semicolon(); } else if ((node = statement(is_default)) instanceof AST_Definitions && is_default) { unexpected(node.start); } else if (node instanceof AST_Definitions || node instanceof AST_Lambda || node instanceof AST_DefClass) { exported_definition = node; } else if (node instanceof AST_SimpleStatement) { exported_value = node.body; } else { unexpected(node.start); } return new AST_Export({ start: start, is_default: is_default, exported_value: exported_value, exported_definition: exported_definition, end: prev(), }); } function as_property_name() { var tmp = S.token; switch (tmp.type) { case "punc": if (tmp.value === "[") { next(); var ex = expression(false); expect("]"); return ex; } else unexpected(tmp); case "operator": if (tmp.value === "*") { next(); return null; } if (!["delete", "in", "instanceof", "new", "typeof", "void"].includes(tmp.value)) { unexpected(tmp); } case "name": if (tmp.value == "yield") { if (is_in_generator()) { token_error(tmp, "Yield cannot be used as identifier inside generators"); } else if (!is_token(peek(), "punc", ":") && !is_token(peek(), "punc", "(") && S.input.has_directive("use strict")) { token_error(tmp, "Unexpected yield identifier inside strict mode"); } } case "string": case "num": case "big_int": case "keyword": case "atom": next(); return tmp.value; default: unexpected(tmp); } } function as_name() { var tmp = S.token; if (tmp.type != "name") unexpected(); next(); return tmp.value; } function _make_symbol(type) { var name = S.token.value; return new (name == "this" ? AST_This : name == "super" ? AST_Super : type)({ name : String(name), start : S.token, end : S.token }); } function _verify_symbol(sym) { var name = sym.name; if (is_in_generator() && name == "yield") { token_error(sym.start, "Yield cannot be used as identifier inside generators"); } if (S.input.has_directive("use strict")) { if (name == "yield") { token_error(sym.start, "Unexpected yield identifier inside strict mode"); } if (sym instanceof AST_SymbolDeclaration && (name == "arguments" || name == "eval")) { token_error(sym.start, "Unexpected " + name + " in strict mode"); } } } function as_symbol(type, noerror) { if (!is("name")) { if (!noerror) croak("Name expected"); return null; } var sym = _make_symbol(type); _verify_symbol(sym); next(); return sym; } function mark_pure(call) { var start = call.start; var comments = start.comments_before; var i = HOP(start, "comments_before_length") ? start.comments_before_length : comments.length; while (--i >= 0) { var comment = comments[i]; if (/[@#]__PURE__/.test(comment.value)) { call.pure = comment; break; } } } var subscripts = function(expr, allow_calls) { var start = expr.start; if (is("punc", ".")) { next(); return subscripts(new AST_Dot({ start : start, expression : expr, property : as_name(), end : prev() }), allow_calls); } if (is("punc", "[")) { next(); var prop = expression(true); expect("]"); return subscripts(new AST_Sub({ start : start, expression : expr, property : prop, end : prev() }), allow_calls); } if (allow_calls && is("punc", "(")) { next(); var call = new AST_Call({ start : start, expression : expr, args : call_args(), end : prev() }); mark_pure(call); return subscripts(call, true); } if (is("template_head")) { return subscripts(new AST_PrefixedTemplateString({ start: start, prefix: expr, template_string: template_string(true), end: prev() }), allow_calls); } return expr; }; var call_args = embed_tokens(function _call_args() { var args = []; while (!is("punc", ")")) { if (is("expand", "...")) { next(); args.push(new AST_Expansion({ start: prev(), expression: expression(false), end: prev() })); } else { args.push(expression(false)); } if (!is("punc", ")")) { expect(","); if (is("punc", ")") && options.ecma < 8) unexpected(); } } next(); return args; }); var maybe_unary = function(allow_calls, allow_arrows) { var start = S.token; if (start.type == "name" && start.value == "await") { if (is_in_async()) { next(); return _await_expression(); } else if (S.input.has_directive("use strict")) { token_error(S.token, "Unexpected await identifier inside strict mode"); } } if (is("operator") && UNARY_PREFIX.has(start.value)) { next(); handle_regexp(); var ex = make_unary(AST_UnaryPrefix, start, maybe_unary(allow_calls)); ex.start = start; ex.end = prev(); return ex; } var val = expr_atom(allow_calls, allow_arrows); while (is("operator") && UNARY_POSTFIX.has(S.token.value) && !has_newline_before(S.token)) { if (val instanceof AST_Arrow) unexpected(); val = make_unary(AST_UnaryPostfix, S.token, val); val.start = start; val.end = S.token; next(); } return val; }; function make_unary(ctor, token, expr) { var op = token.value; switch (op) { case "++": case "--": if (!is_assignable(expr)) croak("Invalid use of " + op + " operator", token.line, token.col, token.pos); break; case "delete": if (expr instanceof AST_SymbolRef && S.input.has_directive("use strict")) croak("Calling delete on expression not allowed in strict mode", expr.start.line, expr.start.col, expr.start.pos); break; } return new ctor({ operator: op, expression: expr }); } var expr_op = function(left, min_prec, no_in) { var op = is("operator") ? S.token.value : null; if (op == "in" && no_in) op = null; if (op == "**" && left instanceof AST_UnaryPrefix /* unary token in front not allowed - parenthesis required */ && !is_token(left.start, "punc", "(") && left.operator !== "--" && left.operator !== "++") unexpected(left.start); var prec = op != null ? PRECEDENCE[op] : null; if (prec != null && (prec > min_prec || (op === "**" && min_prec === prec))) { next(); var right = expr_op(maybe_unary(true), prec, no_in); return expr_op(new AST_Binary({ start : left.start, left : left, operator : op, right : right, end : right.end }), min_prec, no_in); } return left; }; function expr_ops(no_in) { return expr_op(maybe_unary(true, true), 0, no_in); } var maybe_conditional = function(no_in) { var start = S.token; var expr = expr_ops(no_in); if (is("operator", "?")) { next(); var yes = expression(false); expect(":"); return new AST_Conditional({ start : start, condition : expr, consequent : yes, alternative : expression(false, no_in), end : prev() }); } return expr; }; function is_assignable(expr) { return expr instanceof AST_PropAccess || expr instanceof AST_SymbolRef; } function to_destructuring(node) { if (node instanceof AST_Object) { node = new AST_Destructuring({ start: node.start, names: node.properties.map(to_destructuring), is_array: false, end: node.end }); } else if (node instanceof AST_Array) { var names = []; for (var i = 0; i < node.elements.length; i++) { // Only allow expansion as last element if (node.elements[i] instanceof AST_Expansion) { if (i + 1 !== node.elements.length) { token_error(node.elements[i].start, "Spread must the be last element in destructuring array"); } node.elements[i].expression = to_destructuring(node.elements[i].expression); } names.push(to_destructuring(node.elements[i])); } node = new AST_Destructuring({ start: node.start, names: names, is_array: true, end: node.end }); } else if (node instanceof AST_ObjectProperty) { node.value = to_destructuring(node.value); } else if (node instanceof AST_Assign) { node = new AST_DefaultAssign({ start: node.start, left: node.left, operator: "=", right: node.right, end: node.end }); } return node; } // In ES6, AssignmentExpression can also be an ArrowFunction var maybe_assign = function(no_in) { handle_regexp(); var start = S.token; if (start.type == "name" && start.value == "yield") { if (is_in_generator()) { next(); return _yield_expression(); } else if (S.input.has_directive("use strict")) { token_error(S.token, "Unexpected yield identifier inside strict mode"); } } var left = maybe_conditional(no_in); var val = S.token.value; if (is("operator") && ASSIGNMENT.has(val)) { if (is_assignable(left) || (left = to_destructuring(left)) instanceof AST_Destructuring) { next(); return new AST_Assign({ start : start, left : left, operator : val, right : maybe_assign(no_in), end : prev() }); } croak("Invalid assignment"); } return left; }; var expression = function(commas, no_in) { var start = S.token; var exprs = []; while (true) { exprs.push(maybe_assign(no_in)); if (!commas || !is("punc", ",")) break; next(); commas = true; } return exprs.length == 1 ? exprs[0] : new AST_Sequence({ start : start, expressions : exprs, end : peek() }); }; function in_loop(cont) { ++S.in_loop; var ret = cont(); --S.in_loop; return ret; } if (options.expression) { return expression(true); } return (function() { var start = S.token; var body = []; S.input.push_directives_stack(); if (options.module) S.input.add_directive("use strict"); while (!is("eof")) body.push(statement()); S.input.pop_directives_stack(); var end = prev(); var toplevel = options.toplevel; if (toplevel) { toplevel.body = toplevel.body.concat(body); toplevel.end = end; } else { toplevel = new AST_Toplevel({ start: start, body: body, end: end }); } return toplevel; })(); } export { get_full_char_code, get_full_char, is_identifier_char, is_identifier_string, is_surrogate_pair_head, is_surrogate_pair_tail, js_error, JS_Parse_Error, parse, PRECEDENCE, RESERVED_WORDS, tokenizer, }; terser-4.1.2/lib/propmangle.js000066400000000000000000000244671351061312300163020ustar00rootroot00000000000000/*********************************************************************** A JavaScript tokenizer / parser / beautifier / compressor. https://github.com/mishoo/UglifyJS2 -------------------------------- (C) --------------------------------- Author: Mihai Bazon http://mihai.bazon.net/blog Distributed under the BSD license: Copyright 2012 (c) Mihai Bazon Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ "use strict"; /* global global, self */ import { defaults, push_uniq, } from "./utils/index.js"; import { base54 } from "./scope"; import { AST_Call, AST_Conditional, AST_Dot, AST_ObjectKeyVal, AST_ObjectProperty, AST_Sequence, AST_String, AST_Sub, TreeTransformer, TreeWalker, } from "./ast.js"; import { domprops } from "../tools/domprops.js"; function find_builtins(reserved) { domprops.forEach(add); // Compatibility fix for some standard defined globals not defined on every js environment var new_globals = ["Symbol", "Map", "Promise", "Proxy", "Reflect", "Set", "WeakMap", "WeakSet"]; var objects = {}; var global_ref = typeof global === "object" ? global : self; new_globals.forEach(function (new_global) { objects[new_global] = global_ref[new_global] || new Function(); }); // NaN will be included due to Number.NaN [ "null", "true", "false", "Infinity", "-Infinity", "undefined", ].forEach(add); [ Object, Array, Function, Number, String, Boolean, Error, Math, Date, RegExp, objects.Symbol, ArrayBuffer, DataView, decodeURI, decodeURIComponent, encodeURI, encodeURIComponent, eval, EvalError, Float32Array, Float64Array, Int8Array, Int16Array, Int32Array, isFinite, isNaN, JSON, objects.Map, parseFloat, parseInt, objects.Promise, objects.Proxy, RangeError, ReferenceError, objects.Reflect, objects.Set, SyntaxError, TypeError, Uint8Array, Uint8ClampedArray, Uint16Array, Uint32Array, URIError, objects.WeakMap, objects.WeakSet ].forEach(function(ctor) { Object.getOwnPropertyNames(ctor).map(add); if (ctor.prototype) { Object.getOwnPropertyNames(ctor.prototype).map(add); } }); function add(name) { reserved.add(name); } } function reserve_quoted_keys(ast, reserved) { function add(name) { push_uniq(reserved, name); } ast.walk(new TreeWalker(function(node) { if (node instanceof AST_ObjectKeyVal && node.quote) { add(node.key); } else if (node instanceof AST_ObjectProperty && node.quote) { add(node.key.name); } else if (node instanceof AST_Sub) { addStrings(node.property, add); } })); } function addStrings(node, add) { node.walk(new TreeWalker(function(node) { if (node instanceof AST_Sequence) { addStrings(node.tail_node(), add); } else if (node instanceof AST_String) { add(node.value); } else if (node instanceof AST_Conditional) { addStrings(node.consequent, add); addStrings(node.alternative, add); } return true; })); } function mangle_properties(ast, options) { options = defaults(options, { builtins: false, cache: null, debug: false, keep_quoted: false, only_cache: false, regex: null, reserved: null, }, true); var reserved_option = options.reserved; if (!Array.isArray(reserved_option)) reserved_option = [reserved_option]; var reserved = new Set(reserved_option); if (!options.builtins) find_builtins(reserved); var cname = -1; var cache; if (options.cache) { cache = options.cache.props; cache.forEach(function(mangled_name) { reserved.add(mangled_name); }); } else { cache = new Map(); } var regex = options.regex && new RegExp(options.regex); // note debug is either false (disabled), or a string of the debug suffix to use (enabled). // note debug may be enabled as an empty string, which is falsey. Also treat passing 'true' // the same as passing an empty string. var debug = options.debug !== false; var debug_name_suffix; if (debug) { debug_name_suffix = (options.debug === true ? "" : options.debug); } var names_to_mangle = new Set(); var unmangleable = new Set(); var keep_quoted_strict = options.keep_quoted === "strict"; // step 1: find candidates to mangle ast.walk(new TreeWalker(function(node) { if (node instanceof AST_ObjectKeyVal) { if (typeof node.key == "string" && (!keep_quoted_strict || !node.quote)) { add(node.key); } } else if (node instanceof AST_ObjectProperty) { // setter or getter, since KeyVal is handled above if (!keep_quoted_strict || !node.key.end.quote) { add(node.key.name); } } else if (node instanceof AST_Dot) { var root = node; while (root.expression) { root = root.expression; } if (!(root.thedef && root.thedef.undeclared) && (!keep_quoted_strict || !node.quote)) { add(node.property); } } else if (node instanceof AST_Sub) { if (!keep_quoted_strict) { addStrings(node.property, add); } } else if (node instanceof AST_Call && node.expression.print_to_string() == "Object.defineProperty") { addStrings(node.args[1], add); } })); // step 2: transform the tree, renaming properties return ast.transform(new TreeTransformer(function(node) { if (node instanceof AST_ObjectKeyVal) { if (typeof node.key == "string" && (!keep_quoted_strict || !node.quote)) { node.key = mangle(node.key); } } else if (node instanceof AST_ObjectProperty) { // setter or getter if (!keep_quoted_strict || !node.key.end.quote) { node.key.name = mangle(node.key.name); } } else if (node instanceof AST_Dot) { if (!keep_quoted_strict || !node.quote) { node.property = mangle(node.property); } } else if (!options.keep_quoted && node instanceof AST_Sub) { node.property = mangleStrings(node.property); } else if (node instanceof AST_Call && node.expression.print_to_string() == "Object.defineProperty") { node.args[1] = mangleStrings(node.args[1]); } })); // only function declarations after this line function can_mangle(name) { if (unmangleable.has(name)) return false; if (reserved.has(name)) return false; if (options.only_cache) { return cache.has(name); } if (/^-?[0-9]+(\.[0-9]+)?(e[+-][0-9]+)?$/.test(name)) return false; return true; } function should_mangle(name) { if (regex && !regex.test(name)) return false; if (reserved.has(name)) return false; return cache.has(name) || names_to_mangle.has(name); } function add(name) { if (can_mangle(name)) names_to_mangle.add(name); if (!should_mangle(name)) { unmangleable.add(name); } } function mangle(name) { if (!should_mangle(name)) { return name; } var mangled = cache.get(name); if (!mangled) { if (debug) { // debug mode: use a prefix and suffix to preserve readability, e.g. o.foo -> o._$foo$NNN_. var debug_mangled = "_$" + name + "$" + debug_name_suffix + "_"; if (can_mangle(debug_mangled)) { mangled = debug_mangled; } } // either debug mode is off, or it is on and we could not use the mangled name if (!mangled) { do { mangled = base54(++cname); } while (!can_mangle(mangled)); } cache.set(name, mangled); } return mangled; } function mangleStrings(node) { return node.transform(new TreeTransformer(function(node) { if (node instanceof AST_Sequence) { var last = node.expressions.length - 1; node.expressions[last] = mangleStrings(node.expressions[last]); } else if (node instanceof AST_String) { node.value = mangle(node.value); } else if (node instanceof AST_Conditional) { node.consequent = mangleStrings(node.consequent); node.alternative = mangleStrings(node.alternative); } return node; })); } } export { reserve_quoted_keys, mangle_properties, }; terser-4.1.2/lib/scope.js000066400000000000000000000650641351061312300152450ustar00rootroot00000000000000/*********************************************************************** A JavaScript tokenizer / parser / beautifier / compressor. https://github.com/mishoo/UglifyJS2 -------------------------------- (C) --------------------------------- Author: Mihai Bazon http://mihai.bazon.net/blog Distributed under the BSD license: Copyright 2012 (c) Mihai Bazon Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ "use strict"; import { defaults, keep_name, member, mergeSort, push_uniq, return_false, return_this, return_true, string_template, } from "./utils/index.js"; import { AST_Arrow, AST_Block, AST_Call, AST_Class, AST_Conditional, AST_DefClass, AST_Defun, AST_Destructuring, AST_Dot, AST_Export, AST_For, AST_ForIn, AST_Function, AST_Import, AST_IterationStatement, AST_Label, AST_LabeledStatement, AST_LabelRef, AST_Lambda, AST_LoopControl, AST_NameMapping, AST_Node, AST_Scope, AST_Sequence, AST_String, AST_Sub, AST_SwitchBranch, AST_Symbol, AST_SymbolBlockDeclaration, AST_SymbolCatch, AST_SymbolClass, AST_SymbolConst, AST_SymbolDefClass, AST_SymbolDefun, AST_SymbolExport, AST_SymbolFunarg, AST_SymbolImport, AST_SymbolLambda, AST_SymbolLet, AST_SymbolMethod, AST_SymbolRef, AST_SymbolVar, AST_Toplevel, AST_With, TreeWalker, } from "./ast.js"; import { RESERVED_WORDS, js_error, } from "./parse.js"; function SymbolDef(scope, orig, init) { this.name = orig.name; this.orig = [ orig ]; this.init = init; this.eliminated = 0; this.scope = scope; this.references = []; this.replaced = 0; this.global = false; this.export = false; this.mangled_name = null; this.undeclared = false; this.id = SymbolDef.next_id++; } SymbolDef.next_id = 1; var MASK_EXPORT_DONT_MANGLE = 1 << 0; var MASK_EXPORT_WANT_MANGLE = 1 << 1; SymbolDef.prototype = { unmangleable: function(options) { if (!options) options = {}; return this.global && !options.toplevel || (this.export & MASK_EXPORT_DONT_MANGLE) || this.undeclared || !options.eval && this.scope.pinned() || (this.orig[0] instanceof AST_SymbolLambda || this.orig[0] instanceof AST_SymbolDefun) && keep_name(options.keep_fnames, this.orig[0].name) || this.orig[0] instanceof AST_SymbolMethod || (this.orig[0] instanceof AST_SymbolClass || this.orig[0] instanceof AST_SymbolDefClass) && keep_name(options.keep_classnames, this.orig[0].name); }, mangle: function(options) { var cache = options.cache && options.cache.props; if (this.global && cache && cache.has(this.name)) { this.mangled_name = cache.get(this.name); } else if (!this.mangled_name && !this.unmangleable(options)) { var s = this.scope; var sym = this.orig[0]; if (options.ie8 && sym instanceof AST_SymbolLambda) s = s.parent_scope; var def; if (def = this.redefined()) { this.mangled_name = def.mangled_name || def.name; } else this.mangled_name = s.next_mangled(options, this); if (this.global && cache) { cache.set(this.name, this.mangled_name); } } }, redefined: function() { return this.defun && this.defun.variables.get(this.name); } }; AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) { options = defaults(options, { cache: null, ie8: false, safari10: false, }); // pass 1: setup scope chaining and handle definitions var self = this; var scope = self.parent_scope = null; var labels = new Map(); var defun = null; var in_destructuring = null; var for_scopes = []; var tw = new TreeWalker(function(node, descend) { if (node.is_block_scope()) { var save_scope = scope; node.block_scope = scope = new AST_Scope(node); scope.init_scope_vars(save_scope); if (!(node instanceof AST_Scope)) { scope.uses_with = save_scope.uses_with; scope.uses_eval = save_scope.uses_eval; scope.directives = save_scope.directives; } if (options.safari10) { if (node instanceof AST_For || node instanceof AST_ForIn) { for_scopes.push(scope); } } descend(); scope = save_scope; return true; } if (node instanceof AST_Destructuring) { in_destructuring = node; // These don't nest descend(); in_destructuring = null; return true; } if (node instanceof AST_Scope) { node.init_scope_vars(scope); var save_scope = scope; var save_defun = defun; var save_labels = labels; defun = scope = node; labels = new Map(); descend(); scope = save_scope; defun = save_defun; labels = save_labels; return true; // don't descend again in TreeWalker } if (node instanceof AST_LabeledStatement) { var l = node.label; if (labels.has(l.name)) { throw new Error(string_template("Label {name} defined twice", l)); } labels.set(l.name, l); descend(); labels.delete(l.name); return true; // no descend again } if (node instanceof AST_With) { for (var s = scope; s; s = s.parent_scope) s.uses_with = true; return; } if (node instanceof AST_Symbol) { node.scope = scope; } if (node instanceof AST_Label) { node.thedef = node; node.references = []; } if (node instanceof AST_SymbolLambda) { defun.def_function(node, node.name == "arguments" ? undefined : defun); } else if (node instanceof AST_SymbolDefun) { // Careful here, the scope where this should be defined is // the parent scope. The reason is that we enter a new // scope when we encounter the AST_Defun node (which is // instanceof AST_Scope) but we get to the symbol a bit // later. mark_export((node.scope = defun.parent_scope.get_defun_scope()).def_function(node, defun), 1); } else if (node instanceof AST_SymbolClass) { mark_export(defun.def_variable(node, defun), 1); } else if (node instanceof AST_SymbolImport) { scope.def_variable(node); } else if (node instanceof AST_SymbolDefClass) { // This deals with the name of the class being available // inside the class. mark_export((node.scope = defun.parent_scope).def_function(node, defun), 1); } else if (node instanceof AST_SymbolVar || node instanceof AST_SymbolLet || node instanceof AST_SymbolConst) { var def; if (node instanceof AST_SymbolBlockDeclaration) { def = scope.def_variable(node, null); } else { def = defun.def_variable(node, node.TYPE == "SymbolVar" ? null : undefined); } if (!def.orig.every((sym) => { if (sym === node) return true; if (node instanceof AST_SymbolBlockDeclaration) { return sym instanceof AST_SymbolLambda; } return !(sym instanceof AST_SymbolLet || sym instanceof AST_SymbolConst); })) { js_error( node.name + " redeclared", node.start.file, node.start.line, node.start.col, node.start.pos ); } if (!(node instanceof AST_SymbolFunarg)) mark_export(def, 2); def.destructuring = in_destructuring; if (defun !== scope) { node.mark_enclosed(options); var def = scope.find_variable(node); if (node.thedef !== def) { node.thedef = def; node.reference(options); } } } else if (node instanceof AST_SymbolCatch) { scope.def_variable(node).defun = defun; } else if (node instanceof AST_LabelRef) { var sym = labels.get(node.name); if (!sym) throw new Error(string_template("Undefined label {name} [{line},{col}]", { name: node.name, line: node.start.line, col: node.start.col })); node.thedef = sym; } if (!(scope instanceof AST_Toplevel) && (node instanceof AST_Export || node instanceof AST_Import)) { js_error( node.TYPE + " statement may only appear at top level", node.start.file, node.start.line, node.start.col, node.start.pos ); } function mark_export(def, level) { if (in_destructuring) { var i = 0; do { level++; } while (tw.parent(i++) !== in_destructuring); } var node = tw.parent(level); if (def.export = node instanceof AST_Export && MASK_EXPORT_DONT_MANGLE) { var exported = node.exported_definition; if ((exported instanceof AST_Defun || exported instanceof AST_DefClass) && node.is_default) { def.export = MASK_EXPORT_WANT_MANGLE; } } } }); self.walk(tw); // pass 2: find back references and eval self.globals = new Map(); var tw = new TreeWalker(function(node, descend) { if (node instanceof AST_LoopControl && node.label) { node.label.thedef.references.push(node); return true; } if (node instanceof AST_SymbolRef) { var name = node.name; if (name == "eval" && tw.parent() instanceof AST_Call) { for (var s = node.scope; s && !s.uses_eval; s = s.parent_scope) { s.uses_eval = true; } } var sym; if (tw.parent() instanceof AST_NameMapping && tw.parent(1).module_name || !(sym = node.scope.find_variable(name))) { sym = self.def_global(node); if (node instanceof AST_SymbolExport) sym.export = MASK_EXPORT_DONT_MANGLE; } else if (sym.scope instanceof AST_Lambda && name == "arguments") { sym.scope.uses_arguments = true; } node.thedef = sym; node.reference(options); if (node.scope.is_block_scope() && !(sym.orig[0] instanceof AST_SymbolBlockDeclaration)) { node.scope = node.scope.get_defun_scope(); } return true; } // ensure mangling works if catch reuses a scope variable var def; if (node instanceof AST_SymbolCatch && (def = node.definition().redefined())) { var s = node.scope; while (s) { push_uniq(s.enclosed, def); if (s === def.scope) break; s = s.parent_scope; } } }); self.walk(tw); // pass 3: work around IE8 and Safari catch scope bugs if (options.ie8 || options.safari10) { self.walk(new TreeWalker(function(node, descend) { if (node instanceof AST_SymbolCatch) { var name = node.name; var refs = node.thedef.references; var scope = node.thedef.defun; var def = scope.find_variable(name) || self.globals.get(name) || scope.def_variable(node); refs.forEach(function(ref) { ref.thedef = def; ref.reference(options); }); node.thedef = def; node.reference(options); return true; } })); } // pass 4: add symbol definitions to loop scopes // Safari/Webkit bug workaround - loop init let variable shadowing argument. // https://github.com/mishoo/UglifyJS2/issues/1753 // https://bugs.webkit.org/show_bug.cgi?id=171041 if (options.safari10) { for (var i = 0; i < for_scopes.length; i++) { var scope = for_scopes[i]; scope.parent_scope.variables.forEach(function(def) { push_uniq(scope.enclosed, def); }); } } }); AST_Toplevel.DEFMETHOD("def_global", function(node) { var globals = this.globals, name = node.name; if (globals.has(name)) { return globals.get(name); } else { var g = new SymbolDef(this, node); g.undeclared = true; g.global = true; globals.set(name, g); return g; } }); AST_Scope.DEFMETHOD("init_scope_vars", function(parent_scope) { this.variables = new Map(); // map name to AST_SymbolVar (variables defined in this scope; includes functions) this.functions = new Map(); // map name to AST_SymbolDefun (functions defined in this scope) this.uses_with = false; // will be set to true if this or some nested scope uses the `with` statement this.uses_eval = false; // will be set to true if this or nested scope uses the global `eval` this.parent_scope = parent_scope; // the parent scope this.enclosed = []; // a list of variables from this or outer scope(s) that are referenced from this or inner scopes this.cname = -1; // the current index for mangling functions/variables }); AST_Node.DEFMETHOD("is_block_scope", return_false); AST_Class.DEFMETHOD("is_block_scope", return_false); AST_Lambda.DEFMETHOD("is_block_scope", return_false); AST_Toplevel.DEFMETHOD("is_block_scope", return_false); AST_SwitchBranch.DEFMETHOD("is_block_scope", return_false); AST_Block.DEFMETHOD("is_block_scope", return_true); AST_IterationStatement.DEFMETHOD("is_block_scope", return_true); AST_Lambda.DEFMETHOD("init_scope_vars", function() { AST_Scope.prototype.init_scope_vars.apply(this, arguments); this.uses_arguments = false; this.def_variable(new AST_SymbolFunarg({ name: "arguments", start: this.start, end: this.end })); }); AST_Arrow.DEFMETHOD("init_scope_vars", function() { AST_Scope.prototype.init_scope_vars.apply(this, arguments); this.uses_arguments = false; }); AST_Symbol.DEFMETHOD("mark_enclosed", function(options) { var def = this.definition(); var s = this.scope; while (s) { push_uniq(s.enclosed, def); if (options.keep_fnames) { s.functions.forEach(function(d) { if (keep_name(options.keep_fnames, d.name)) { push_uniq(def.scope.enclosed, d); } }); } if (s === def.scope) break; s = s.parent_scope; } }); AST_Symbol.DEFMETHOD("reference", function(options) { this.definition().references.push(this); this.mark_enclosed(options); }); AST_Scope.DEFMETHOD("find_variable", function(name) { if (name instanceof AST_Symbol) name = name.name; return this.variables.get(name) || (this.parent_scope && this.parent_scope.find_variable(name)); }); AST_Scope.DEFMETHOD("def_function", function(symbol, init) { var def = this.def_variable(symbol, init); if (!def.init || def.init instanceof AST_Defun) def.init = init; this.functions.set(symbol.name, def); return def; }); AST_Scope.DEFMETHOD("def_variable", function(symbol, init) { var def = this.variables.get(symbol.name); if (def) { def.orig.push(symbol); if (def.init && (def.scope !== symbol.scope || def.init instanceof AST_Function)) { def.init = init; } } else { def = new SymbolDef(this, symbol, init); this.variables.set(symbol.name, def); def.global = !this.parent_scope; } return symbol.thedef = def; }); function next_mangled(scope, options) { var ext = scope.enclosed; out: while (true) { var m = base54(++scope.cname); if (RESERVED_WORDS.has(m)) continue; // skip over "do" // https://github.com/mishoo/UglifyJS2/issues/242 -- do not // shadow a name reserved from mangling. if (member(m, options.reserved)) continue; // we must ensure that the mangled name does not shadow a name // from some parent scope that is referenced in this or in // inner scopes. for (var i = ext.length; --i >= 0;) { var sym = ext[i]; var name = sym.mangled_name || (sym.unmangleable(options) && sym.name); if (m == name) continue out; } return m; } } AST_Scope.DEFMETHOD("next_mangled", function(options) { return next_mangled(this, options); }); AST_Toplevel.DEFMETHOD("next_mangled", function(options) { var name; do { name = next_mangled(this, options); } while (this.mangled_names.has(name)); return name; }); AST_Function.DEFMETHOD("next_mangled", function(options, def) { // #179, #326 // in Safari strict mode, something like (function x(x){...}) is a syntax error; // a function expression's argument cannot shadow the function expression's name var tricky_def = def.orig[0] instanceof AST_SymbolFunarg && this.name && this.name.definition(); // the function's mangled_name is null when keep_fnames is true var tricky_name = tricky_def ? tricky_def.mangled_name || tricky_def.name : null; while (true) { var name = next_mangled(this, options); if (!tricky_name || tricky_name != name) return name; } }); AST_Symbol.DEFMETHOD("unmangleable", function(options) { var def = this.definition(); return !def || def.unmangleable(options); }); // labels are always mangleable AST_Label.DEFMETHOD("unmangleable", return_false); AST_Symbol.DEFMETHOD("unreferenced", function() { return !this.definition().references.length && !this.scope.pinned(); }); AST_Symbol.DEFMETHOD("definition", function() { return this.thedef; }); AST_Symbol.DEFMETHOD("global", function() { return this.definition().global; }); AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options) { options = defaults(options, { eval : false, ie8 : false, keep_classnames: false, keep_fnames : false, module : false, reserved : [], toplevel : false, }); if (options["module"]) { options.toplevel = true; } if (!Array.isArray(options.reserved)) options.reserved = []; // Never mangle arguments push_uniq(options.reserved, "arguments"); return options; }); AST_Toplevel.DEFMETHOD("mangle_names", function(options) { options = this._default_mangler_options(options); // We only need to mangle declaration nodes. Special logic wired // into the code generator will display the mangled name if it's // present (and for AST_SymbolRef-s it'll use the mangled name of // the AST_SymbolDeclaration that it points to). var lname = -1; var to_mangle = []; var mangled_names = this.mangled_names = new Set(); if (options.cache) { this.globals.forEach(collect); if (options.cache.props) { options.cache.props.forEach(function(mangled_name) { mangled_names.add(mangled_name); }); } } var tw = new TreeWalker(function(node, descend) { if (node instanceof AST_LabeledStatement) { // lname is incremented when we get to the AST_Label var save_nesting = lname; descend(); lname = save_nesting; return true; // don't descend again in TreeWalker } if (node instanceof AST_Scope) { node.variables.forEach(collect); return; } if (node.is_block_scope()) { node.block_scope.variables.forEach(collect); return; } if (node instanceof AST_Label) { var name; do name = base54(++lname); while (RESERVED_WORDS.has(name)); node.mangled_name = name; return true; } if (!(options.ie8 || options.safari10) && node instanceof AST_SymbolCatch) { to_mangle.push(node.definition()); return; } }); this.walk(tw); to_mangle.forEach(function(def) { def.mangle(options); }); function collect(symbol) { if (!member(symbol.name, options.reserved)) { if (!(symbol.export & MASK_EXPORT_DONT_MANGLE)) { to_mangle.push(symbol); } } } }); AST_Toplevel.DEFMETHOD("find_colliding_names", function(options) { var cache = options.cache && options.cache.props; var avoid = new Set(); options.reserved.forEach(to_avoid); this.globals.forEach(add_def); this.walk(new TreeWalker(function(node) { if (node instanceof AST_Scope) node.variables.forEach(add_def); if (node instanceof AST_SymbolCatch) add_def(node.definition()); })); return avoid; function to_avoid(name) { avoid.add(name); } function add_def(def) { var name = def.name; if (def.global && cache && cache.has(name)) name = cache.get(name); else if (!def.unmangleable(options)) return; to_avoid(name); } }); AST_Toplevel.DEFMETHOD("expand_names", function(options) { base54.reset(); base54.sort(); options = this._default_mangler_options(options); var avoid = this.find_colliding_names(options); var cname = 0; this.globals.forEach(rename); this.walk(new TreeWalker(function(node) { if (node instanceof AST_Scope) node.variables.forEach(rename); if (node instanceof AST_SymbolCatch) rename(node.definition()); })); function next_name() { var name; do { name = base54(cname++); } while (avoid.has(name) || RESERVED_WORDS.has(name)); return name; } function rename(def) { if (def.global && options.cache) return; if (def.unmangleable(options)) return; if (member(def.name, options.reserved)) return; var d = def.redefined(); def.name = d ? d.name : next_name(); def.orig.forEach(function(sym) { sym.name = def.name; }); def.references.forEach(function(sym) { sym.name = def.name; }); } }); AST_Node.DEFMETHOD("tail_node", return_this); AST_Sequence.DEFMETHOD("tail_node", function() { return this.expressions[this.expressions.length - 1]; }); AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options) { options = this._default_mangler_options(options); try { AST_Node.prototype.print = function(stream, force_parens) { this._print(stream, force_parens); if (this instanceof AST_Symbol && !this.unmangleable(options)) { base54.consider(this.name, -1); } else if (options.properties) { if (this instanceof AST_Dot) { base54.consider(this.property, -1); } else if (this instanceof AST_Sub) { skip_string(this.property); } } }; base54.consider(this.print_to_string(), 1); } finally { AST_Node.prototype.print = AST_Node.prototype._print; } base54.sort(); function skip_string(node) { if (node instanceof AST_String) { base54.consider(node.value, -1); } else if (node instanceof AST_Conditional) { skip_string(node.consequent); skip_string(node.alternative); } else if (node instanceof AST_Sequence) { skip_string(node.tail_node()); } } }); var base54 = (function() { var leading = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_".split(""); var digits = "0123456789".split(""); var chars, frequency; function reset() { frequency = new Map(); leading.forEach(function(ch) { frequency.set(ch, 0); }); digits.forEach(function(ch) { frequency.set(ch, 0); }); } base54.consider = function(str, delta) { for (var i = str.length; --i >= 0;) { frequency.set(str[i], frequency.get(str[i]) + delta); } }; function compare(a, b) { return frequency.get(b) - frequency.get(a); } base54.sort = function() { chars = mergeSort(leading, compare).concat(mergeSort(digits, compare)); }; base54.reset = reset; reset(); function base54(num) { var ret = "", base = 54; num++; do { num--; ret += chars[num % base]; num = Math.floor(num / base); base = 64; } while (num > 0); return ret; } return base54; })(); export { base54, SymbolDef, }; terser-4.1.2/lib/sourcemap.js000066400000000000000000000072001351061312300161160ustar00rootroot00000000000000/*********************************************************************** A JavaScript tokenizer / parser / beautifier / compressor. https://github.com/mishoo/UglifyJS2 -------------------------------- (C) --------------------------------- Author: Mihai Bazon http://mihai.bazon.net/blog Distributed under the BSD license: Copyright 2012 (c) Mihai Bazon Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ "use strict"; import MOZ_SourceMap from "source-map"; import { defaults, } from "./utils/index.js"; // a small wrapper around fitzgen's source-map library function SourceMap(options) { options = defaults(options, { file : null, root : null, orig : null, orig_line_diff : 0, dest_line_diff : 0, }); var generator = new MOZ_SourceMap.SourceMapGenerator({ file : options.file, sourceRoot : options.root }); var orig_map = options.orig && new MOZ_SourceMap.SourceMapConsumer(options.orig); if (orig_map) { orig_map.sources.forEach(function(source) { var sourceContent = orig_map.sourceContentFor(source, true); if (sourceContent) { generator.setSourceContent(source, sourceContent); } }); } function add(source, gen_line, gen_col, orig_line, orig_col, name) { if (orig_map) { var info = orig_map.originalPositionFor({ line: orig_line, column: orig_col }); if (info.source === null) { return; } source = info.source; orig_line = info.line; orig_col = info.column; name = info.name || name; } generator.addMapping({ generated : { line: gen_line + options.dest_line_diff, column: gen_col }, original : { line: orig_line + options.orig_line_diff, column: orig_col }, source : source, name : name }); } return { add : add, get : function() { return generator; }, toString : function() { return JSON.stringify(generator.toJSON()); } }; } export { SourceMap, }; terser-4.1.2/lib/transform.js000066400000000000000000000224461351061312300161440ustar00rootroot00000000000000/*********************************************************************** A JavaScript tokenizer / parser / beautifier / compressor. https://github.com/mishoo/UglifyJS2 -------------------------------- (C) --------------------------------- Author: Mihai Bazon http://mihai.bazon.net/blog Distributed under the BSD license: Copyright 2012 (c) Mihai Bazon Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ "use strict"; import { AST_Array, AST_Await, AST_Binary, AST_Block, AST_Call, AST_Case, AST_Catch, AST_Class, AST_Conditional, AST_Definitions, AST_Destructuring, AST_Do, AST_Dot, AST_Exit, AST_Expansion, AST_Export, AST_For, AST_ForIn, AST_If, AST_Import, AST_LabeledStatement, AST_Lambda, AST_LoopControl, AST_NameMapping, AST_Node, AST_Object, AST_ObjectProperty, AST_PrefixedTemplateString, AST_Sequence, AST_SimpleStatement, AST_Sub, AST_Switch, AST_TemplateString, AST_Try, AST_Unary, AST_VarDef, AST_While, AST_With, AST_Yield, } from "./ast.js"; import { MAP, noop, } from "./utils/index.js"; (function() { function _(node, descend) { node.DEFMETHOD("transform", function(tw, in_list) { var x, y; tw.push(this); if (tw.before) x = tw.before(this, descend, in_list); if (x === undefined) { x = this; descend(x, tw); if (tw.after) { y = tw.after(x, in_list); if (y !== undefined) x = y; } } tw.pop(); 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_Do, function(self, tw) { self.body = self.body.transform(tw); self.condition = self.condition.transform(tw); }); _(AST_While, 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) { if (self.argname) 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_Destructuring, function(self, tw) { self.names = do_list(self.names, tw); }); _(AST_Lambda, function(self, tw) { if (self.name) self.name = self.name.transform(tw); self.argnames = do_list(self.argnames, tw); if (self.body instanceof AST_Node) { self.body = self.body.transform(tw); } else { self.body = do_list(self.body, tw); } }); _(AST_Call, function(self, tw) { self.expression = self.expression.transform(tw); self.args = do_list(self.args, tw); }); _(AST_Sequence, function(self, tw) { self.expressions = do_list(self.expressions, 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_Yield, function(self, tw) { if (self.expression) self.expression = self.expression.transform(tw); }); _(AST_Await, function(self, tw) { self.expression = self.expression.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) { if (self.key instanceof AST_Node) { self.key = self.key.transform(tw); } self.value = self.value.transform(tw); }); _(AST_Class, function(self, tw) { if (self.name) self.name = self.name.transform(tw); if (self.extends) self.extends = self.extends.transform(tw); self.properties = do_list(self.properties, tw); }); _(AST_Expansion, function(self, tw) { self.expression = self.expression.transform(tw); }); _(AST_NameMapping, function(self, tw) { self.foreign_name = self.foreign_name.transform(tw); self.name = self.name.transform(tw); }); _(AST_Import, function(self, tw) { if (self.imported_name) self.imported_name = self.imported_name.transform(tw); if (self.imported_names) do_list(self.imported_names, tw); self.module_name = self.module_name.transform(tw); }); _(AST_Export, function(self, tw) { if (self.exported_definition) self.exported_definition = self.exported_definition.transform(tw); if (self.exported_value) self.exported_value = self.exported_value.transform(tw); if (self.exported_names) do_list(self.exported_names, tw); if (self.module_name) self.module_name = self.module_name.transform(tw); }); _(AST_TemplateString, function(self, tw) { self.segments = do_list(self.segments, tw); }); _(AST_PrefixedTemplateString, function(self, tw) { self.prefix = self.prefix.transform(tw); self.template_string = self.template_string.transform(tw); }); })(); terser-4.1.2/lib/utils/000077500000000000000000000000001351061312300147235ustar00rootroot00000000000000terser-4.1.2/lib/utils/first_in_statement.js000066400000000000000000000020461351061312300211640ustar00rootroot00000000000000import { AST_Binary, AST_Conditional, AST_Dot, AST_Sequence, AST_Statement, AST_Sub, AST_UnaryPostfix } from "../ast.js"; // return true if the node at the top of the stack (that means the // innermost node in the current output) is lexically the first in // a statement. function first_in_statement(stack) { let node = stack.parent(-1); for (let i = 0, p; p = stack.parent(i); i++) { if (p instanceof AST_Statement && p.body === node) return true; if ((p instanceof AST_Sequence && p.expressions[0] === node) || (p.TYPE === "Call" && p.expression === node) || (p instanceof AST_Dot && p.expression === node) || (p instanceof AST_Sub && p.expression === node) || (p instanceof AST_Conditional && p.condition === node) || (p instanceof AST_Binary && p.left === node) || (p instanceof AST_UnaryPostfix && p.expression === node) ) { node = p; } else { return false; } } } export { first_in_statement }; terser-4.1.2/lib/utils/index.js000066400000000000000000000147751351061312300164060ustar00rootroot00000000000000/*********************************************************************** A JavaScript tokenizer / parser / beautifier / compressor. https://github.com/mishoo/UglifyJS2 -------------------------------- (C) --------------------------------- Author: Mihai Bazon http://mihai.bazon.net/blog Distributed under the BSD license: Copyright 2012 (c) Mihai Bazon Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ "use strict"; function characters(str) { return str.split(""); } function member(name, array) { return array.includes(name); } class DefaultsError extends Error { constructor(msg, defs) { super(); this.name = "DefaultsError"; this.message = msg; this.defs = defs; } } function defaults(args, defs, croak) { if (args === true) args = {}; var ret = args || {}; if (croak) for (var i in ret) if (HOP(ret, i) && !HOP(defs, i)) throw new DefaultsError("`" + i + "` is not a supported option", defs); for (var i in defs) if (HOP(defs, i)) { ret[i] = (args && HOP(args, i)) ? args[i] : defs[i]; } return ret; } function noop() {} function return_false() { return false; } function return_true() { return true; } function return_this() { return this; } function return_null() { return null; } var MAP = (function() { function MAP(a, f, backwards) { var ret = [], top = [], i; function doit() { var val = f(a[i], i); var is_last = val instanceof Last; if (is_last) val = val.v; if (val instanceof AtTop) { val = val.v; if (val instanceof Splice) { top.push.apply(top, backwards ? val.v.slice().reverse() : val.v); } else { top.push(val); } } else if (val !== skip) { if (val instanceof Splice) { ret.push.apply(ret, backwards ? val.v.slice().reverse() : val.v); } else { ret.push(val); } } return is_last; } if (Array.isArray(a)) { if (backwards) { for (i = a.length; --i >= 0;) if (doit()) break; ret.reverse(); top.reverse(); } else { for (i = 0; i < a.length; ++i) if (doit()) break; } } else { for (i in a) if (HOP(a, i)) if (doit()) break; } return top.concat(ret); } MAP.at_top = function(val) { return new AtTop(val); }; MAP.splice = function(val) { return new Splice(val); }; MAP.last = function(val) { return new Last(val); }; var skip = MAP.skip = {}; function AtTop(val) { this.v = val; } function Splice(val) { this.v = val; } function Last(val) { this.v = val; } return MAP; })(); function push_uniq(array, el) { if (!array.includes(el)) array.push(el); } function string_template(text, props) { return text.replace(/{(.+?)}/g, function(str, p) { return props && props[p]; }); } function remove(array, el) { for (var i = array.length; --i >= 0;) { if (array[i] === el) array.splice(i, 1); } } function mergeSort(array, cmp) { if (array.length < 2) return array.slice(); function merge(a, b) { var r = [], ai = 0, bi = 0, i = 0; while (ai < a.length && bi < b.length) { cmp(a[ai], b[bi]) <= 0 ? r[i++] = a[ai++] : r[i++] = b[bi++]; } if (ai < a.length) r.push.apply(r, a.slice(ai)); if (bi < b.length) r.push.apply(r, b.slice(bi)); return r; } function _ms(a) { if (a.length <= 1) return a; var m = Math.floor(a.length / 2), left = a.slice(0, m), right = a.slice(m); left = _ms(left); right = _ms(right); return merge(left, right); } return _ms(array); } function makePredicate(words) { if (!Array.isArray(words)) words = words.split(" "); return new Set(words); } function map_add(map, key, value) { if (map.has(key)) { map.get(key).push(value); } else { map.set(key, [ value ]); } } function map_from_object(obj) { var map = new Map(); for (var key in obj) { if (HOP(obj, key) && key.charAt(0) === "$") { map.set(key.substr(1), obj[key]); } } return map; } function map_to_object(map) { var obj = Object.create(null); map.forEach(function (value, key) { obj["$" + key] = value; }); return obj; } function HOP(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } function keep_name(keep_setting, name) { return keep_setting === true || (keep_setting instanceof RegExp && keep_setting.test(name)); } export { characters, defaults, HOP, keep_name, makePredicate, map_add, map_from_object, map_to_object, MAP, member, mergeSort, noop, push_uniq, remove, return_false, return_null, return_this, return_true, string_template, }; terser-4.1.2/logo.png000066400000000000000000005303701351061312300144730ustar00rootroot00000000000000PNG  IHDR ֽgAMA a cHRMz&u0`:pQ< iTXtXML:com.adobe.xmp 2 1 1 2 E*@IDATx%U0''&(HEsV5P1k\]Q15"kń ( y0pffzo>USV8;]S#& @ @ @ @ @ 0diC_ @ @ @ @ @ @f N @ @ @ @ @(B@{  @ @ @ @ @ @ @ @ @ @ @"$ @ @ @ @ @ @  @ @ @ @ @(B@{  @ @ @ @ @ @ @ @ @ @ @"$ @ @ @ @ @ @  @ @ @ @ @(B@{  @ @ @ @ @ @ @ @ @ @ @"$ @ @ @ @ @ @  @ @ @ @ @(B@{  @ @ @ @ @ @ @ @ @ @ @"$ @ @ @ @ @ @  @ @ @ @ @(B@{  @ @ @ @ @ @ @ @ @ @ @"$ @ @ @ @ @ @  @ @ @ @ @(B@{  @ @ @ @ @ @ @ @ @ @ @"$ @ @ @ @ @ @  @ @ @ @ @(B@{  @ @ @ @ @ @ @ @ @ @ @"$ @ @ @ @ @ @  @ @ @ @ @(B@{  @ @ @ @ @ @ @ @ @ @ @"$ @ @ @ @ @ @  @ @ @ @ @(B@{  @ @ @ @ @ @ @ @ @ @ @"$ @ @ @ @ @ @  @ @ @ @ @(B@{  @ @ @ @ @ @ @ @ @ @ @"$ @ @ @ @ @ @  @ @ @ @ @(B@{  @ @ @ @ @ @ @ @ @ @ @"$ @ @ @ @ @ @  @ @ @ @ @(B@{  @ @ @ @ @ @ @ @ @ @ @"$ @ @ @ @ @ @  @ @ @ @ @(B@{  @ @ @ @ @ @ @ @ @ @ @"$ @ @ @ @ @ @  @ @ @ @ @(B@{  @ @ @ @ @ @ @ @ @ @ @"$ @ @ @ @ @ @  @ @ @ @ @(B`FQ Ў7\q <:/~]M->q"F~sEIs^Ξ{VD̚Nt%@ @ @ @ @$wWrb5WE\u5״5}zĴ43gusO iǚ @xg^ݚߜ5_5_&ץ9/^AM##"vU.{u;$bAE @ @ @ @^`dSjʦ60'✈#4V"{SNKv b~;m^_/Xzߏ[u9D#_se[nzܜo:veJd uȑ= wOw8*bJ @ @ @ @v܄a|~ wȆA9}/o~9~ǭf$7 lq__qSק7Dץ_浭 u5)i=y[~=>/oH#+0gnăx"Cu!r @ @ @ @Y@{VyDڷ*L FFr?~:x=bZM99<%%%߼ܜ0>>i|l[|ry򼾝m7?LL}#^sbĮ @ @ @ @ @ܫحp?v\B{DsEݫ#B74 @ @ @ @ $OHS|uE%av&@ @ @ @ @@]$WgyϥM @@}Oli @ @ @ @ @#  HIo8W: @``O~A2TD @ @ @ @$+iSēݯb7 @@ }Fkޕ6Ri @ @ @ @&6.&}r 0@;Oظa @ @ @ @6ߜ#ݸ6k @ 7W}ۧe @ @ @ @@ }InzG As bU @ @ @ @ @`܇?qoyE/:v[ @z ".m: @ @ @ @l%0)M[vI1Fa  @p{4N @ @ @ @ }S#>e,; @ qZ'Oq5 @ @ @ @0-=n5w9⺵ÏE @/#.~," @ @ @ @ @@gඋIno @kD|7P @ @ @ @ E[,x"~2b P{G|#M,CDA @ @ @ @@dIKrpNC.#uZ[} @ @ @ @ %;hB$,) @ @ @ @ @/#ԗھWD\qY9HW~o @ @ @ @ X#] (Q ߓ/ @ @ @ @ 3 =철e'@j/վH @ @ @ @@$?=HA*pRF\ @ @ @ @F@{o/*]?F\zq[} @ @ @ @4X@{ icXB$b @JəG(> @ @ @ @t, cxyk@E @8{m @ @ @ @ @@{ y?.! 1 @U $F @ @ @ @:!\O0 @>7Ըs5 @ @ @ @ %^]Bb @ pUUR @ @ @ @H@{Gl=>HZAGj,p5n @ @ @ @ t %Fp/@!?7lXXEI @ @ @ @6$ ֗%U @6EPˮ( @ @ @ @"$p\sU Q5WV%Rq @ @ @ @ @- mqi5W` @0{-U @ @ @ @0{嗖( @jlX8EI @ @ @ @6&X_v})V @ @ @ @ @zq*! 1 @U#\UJ @ @ @ @' ;=zT @gԳ]ZE @ @ @ @@$p ܹ(@TE`̪D*N @ @ @ @% ->|U V, PKsj,"@ @ @ @ @΁%D! @*sV%Rq @ @ @ @ @- mqiQ#IV @sճ]ZE @ @ @ @@$p ,^1}z (]`d$bң @ @ @ @:[Iݰdy U PKySR @ @ @ @5^J.[QJ$ @JSщ @ @ @ @] Hp/[EV`ŵm @ @ @ @ @@{)R" PB %w @ @ @ @N@{w~;Z{,D, νm @ @ @ @/ S`يR" PNFp/{F @ @ @ @@wܻFp @@/s봍 @ @ @ @ Hp/^JO-H{$: @ @ @ @ލ^/]2ҔEU@{]{V @ @ @ @HK9 ^JO-xY @ @ @ @]XR`^*LK̞ӚgΊ\ExCkްap@Ug955sּ~}U%L @ @ @ @@^ ->EK"Ol\|Wm7˞+v<:[2bނV2I3fnpӖdu)".4?E\z9$} H`~YmZ?gs貴\)}s2{NjÜ6mܒ>~ڈ\Қ/Z?Ì[pS\\J @ @ @ @@#TD$sJ2 q4eٿ [z콈/'- /⥭Ͻy畻Ą^r^qyGlL?˦j |]f&@ @ @ @ @$'$霈h*K`eDG#b4nV '̈o9_eJ7誈;qxxtĭojoH"{7^q">##nuiDxS5~~ߩ @ @ @ @m Hpo?>%ddCpf͊=#sR>9IԶ_/"@`Ӧpww ᦈzč7&FơUb @ @ @ @[@{)&˟nR`C#9.b^"uZ/D[DŽ@)AFvOTqGG6k8THkVqƅSm @ @ @ @bOZ?>#'Mz(dY+=' K?Gf[,\gG<ꄈ]ouMY+#/~5tÊixfhx @ @ @ @}gඊ?Ds+wx#;,a] {oU!+] 8}Vj 5?D|#Nyo5 F~MO0 @ @ @ @ @jڮj6kj]x["z~qϑ>;'9ߊ8ÎF% -5'Dr{)}w[#LjKD4Xe+[ @ @ @ @ 0` auwƅ#^ƈ59] v׈}#_8.=.\q>=i/q3݄Rj-\ ]Ri0KGSZ @ @ @ @ 0$ Cnܷ{>$_D<su](p=hߎ",cE.R`C#N~S/2DAm%0svģNhݐWFJMXj+ @ @ @ @a Hpv_x_/J# C|S/qN5 O`ƌ>uv^j\`܈罶s{;/Ǒ |{ @ @ @ @ @K< {=4%Z<'L% V`n4{>Xֶpq{z´郭[m}n,\.{|%F,[I @ @ @ @^RJp7FF"^wJwYB :!?gC/u'ό{YJgD%DSKpWj  @ @ @ @[ HpZd1k0#vݳDOy!mv3ߍ8R"8]s[ME I.8/i>nL5>U) @ @ @ @ PQgueETxF|xt5e EKN#-p#sjĢn WDe+]v(RqD6 @ @ @ @ P} {d}"N93␔4k}O߿>"'z'~BՋ]ĝ ^Qm GF,I7߃& @ @ @ @X@{idyiϊJĮ{z+F -SiXKN3r{ˬaE'mwHU!e+  @ @ @ @ ЕpܧӢd]1S_է=uoջ׽ڷ#7_eD&b= @ @ @ @j# 4zd?q)7Eznz[#n}@Z=,ZJr?Nn1%7z @ @ @ @^Z?}N۷|4&5xGݿxGPF D|=־0 b $@ @ @ @ @ B{ig{Ggf̘S"اZ+.V-jB`tĢnܧe/ @ @ @ @, ɠ?44v[)0oAě+bfVe+KPlu7$nȔSb @ @ @ @QVZ}37R"YcKsSij_i %Ki1Ң*3n)cDE @ @ @ @@/$Re-XԋRYK~lVFY)nHċ^78DP ?3J#S_ @ @ @ @ H@\Nܷku"{v7YIgD"*/$c#ns*Wm o` }dm"@ @ @ @ @P$}.X ݔG~ٿ5ݶDs@fΌxk{X!xY M3 yݗSF^ @ @ @ @&>,X8K!E,Y^RDb筫uu :ǗO ^ @ @ @ @>䶫X`〭͌F"Wz/G>5b~ܦ <|Lk^ @ @ @ @ Poc%#C~;bÏ5jQW3G>qL=2cFTFp:  @ @ @ @!OZNFp{n-gTUc0n [ā7۶ytն!@ @ @ @ @@ $ةMOp"/gTU;m}5⾧jtT<  !/UE @ @ @ @ P;%vZTbT\]jjٜVDtAת##Mi9/5oYK @ @ @ @ Hp/C/,14kVđL]jilV{ڻ?(% s2HFյjШ&oXoCb @ @ @ @Xb6yj:t֡%I"#֢3M @ @ @ @ Hp/4xw%iܷm)YZD⩛@܍^3Z{ @ @ @ @؁ mSGp>Ӯ;zͫvXsU"{:bƯij @ @ @ @ h %vSGpω{Wb.w_H]ZSF;>8DQ#Q6NUm @ @ @ @^b65K 1I`銈}S DpmimM!@ @ @ @ @KڝUcס;zzHp)v s;81l"@ @ @ @ @nK K1wHPY΁#ށ*i{hwj4 #@ @ @ @ @ܷ)5F. л>s߈9zWP`$;pn]]ۦi @ @ @ @h`%OI|XbZ,bn+_>&r[w_#pٻޖG[ @ @ @ @S>2sPZF}*^4b4x }qU;lmuݲdyzN @ @ @ @ mH Y1cf! (PE!?C/ Ee#ۭٻG; @ @ @ @S>Eִ X }7M}(SX/] @ @ @ @ P R{F\uXᆊt{¨6.XS`W#נ5 @ @ @ @v$5}gdmï&E|뾷gωX[(@M!'@ @ @ @ @KjR{B\u}g*cr@]woj|U= @ @ @ @&voZそZ*JηO+/C :h;Qr  @ @ @ @*+ ԮkRs⪣ʝFkvu t,д'~@ @ @ @ @*) n9z2#AU;9;bb$~n'o" ^ȰE @ @ @ @~ Hpl6iww{8%:91cFpq}v @ @ @ @- }SI LU~z'0y܅@nFoڈ]%@ @ @ @ @K&%7m4RϹǗvw t*Ф:Ur @ @ @ @*+ Ԯ9z{owh#HǶ~ ̝*{tuY @ @ @ @>䎪htD ] ̞?xɲ@~vG>L @ @ @ @ Q@wXuH4`cޝh 4o;=KG @ @ @ @@$yMJph\YX︚$ۏ;*E= @ @ @ @@*w3gV,.6JC7Vt;:ظ#w,b @ @ @ @t) KޤcSL`B3&d>$E`Æ[dFp/[E @ @ @ @@$׷9# t,0ͯf͎䅎إ&ྺK, @ @ @ @ @z2! Xw*Q @ @ @ @ K@'wc܍>`{?޹H p}%8 @ @ @ @ ^jܴzޛ*qr&G`#Oc@_;jTB @ @ @ @9k]we 7ե%Q%i~u];s`( @ @ @ @JYjxC>. 7U##UxW@IDATc ̛  @ @ @ @ K@'I#dN 0_ǪFp΁=0{A @ @ @ @rfZ#3{Oﻀ;'޹#X{me( @ @uظ!+"K/XsuDd̈%#FWG,6.- @ @K+5uޗD L3dDn7M6@7mL_D]sJ @ @ !='ߏW#f%گ*bӦ`zJnI9=Ϸ7{X[  @ @C>)Uy}׭Tss;Gv/Ф iܻ?i@ @ @!kےԾ'\k59ȉq{nЍ,&@ @^j6iK= k;޹:?֑hR{~p @ @hexk#Nyo>> 9'Q|Z#?}|J~5rN:%@ @e MFpྥ߽YUFpYV9MJp)=rD @ @@s"/}W۷_GuOL߸#@ @]@{߉;I#xCH#Ѕ;Ǔ޹#hRݟ/J @ @ POq"ƈn^gD}#~vpcQ; @ Hϖ+ۯ[[jdkޣ*qR Mün@USt@ U ?(ޖ|͕[^_sMQ-w[iMޯ~czx~3g9-^--iqk0^^_ Fz  @o|kXF`? [ߴ)b9sc~ɀvn}o.[y &ߖ "ޖً.cqGE<%*׌]'uJ#@upN- ^jg_zװG}X*DYfFp/_UJIMr i_([Ӝ3U5'Q9bծi9:/ަMqj@&fo#曗iO&o^<}؜잓z!\g"@@6m%~Ec˱u9 /XTof^~_9}o~7Q:7s">vbg|Ks"^f\$O @@eWpũľ?SAv"`NZHpΑ 6bcٔ `Mi@:'܈" $ZեytSrDSNm{ݶ5_Z9_L @@'}~ȟAq['Mpm+nKsNޔ7"s|XkG6 @Xpw#~2nN`ߜ~yJn쉬`y>?s)>栈e>5< ό){o}.ym=%:p}-=#@pV`dSjۺ6,'>єiz)}Sv o~Y[ؿT_> Z)4_SO~/;5I9႔_dО9ַyױd"<HzY-'ZiD5iisE޾Fi+oy_W缪*ъ"\?\?P PAO'4O'VKο9.K1YsW l-7E%[~*g]hT /kF^Miv@2&'?93%9(kT  ud$%&%!;1svE L 4OϊnFidív֗6;z{NĊ O{ثR\?핤r @`PW*NA B}V&=zx 7@x["^ʅ=g/~ag>9ӈ5ZJK.Lg(68'G?"?"9}e)9_LZW9qm0be∻/%dxYV-7囎3)$=$WqvKtIV'@]OD@[\?b1WZ\}=Ğ3";]?4 >{jO= FGK%FjM~gcM %@`*ץmߎ8K:-%;S@~,mޒw?w~ъ"puNi-OMF=Ns7 0x]wJlUyyӦǡvK c-ao{CAoӓ&+iz @*S'"ڮ yi/^4/%5d"0(-_?Sϊ)MOO4%M1E>}-p[z5Qȏ#{?,b4}1 @^/eN?5b,4r\wO#?G5XEF@g6FV2wRR9\ ͦz LqD3%>:bjK"p>_?~SZ7}íytUăQydoXw{ˈQ_2PG/UE`0ƹJ~Z+p6Ot|C̞xJ4? &M_dokҘ6GF|;PU qq+j򡩽oJ_ҙhOggNd%w+wAǷF]\-'@[ }Wĩ[n^ G<ǦQ޿^muX._hlt9D`"}kkwhQ+#c Tj$С50O~h>&ptvZ&Ip/#_L}DjW l-Z'}"Nd{N?O{@K='}D<_tsR{J>ߕ#0==k%3gW'v @@oJ̉87e*Z߭~G,Pmn;Ԟo4jړ؟nS~x\~1-7S"R˿umvRZi)=! OٗR맥D#шVVkZkt Оioy$ O ?IS~*3{"~@;6D!xi?>)ž PE#KTW?VDyRcҨ{۫ҕCd??jN&ش)[{G<5=99?k֜|F'Jpsk[\?b  /O%[r]?^U8b#y% B`"ۈ=1bA L`5yGqeVE#?Q[L^ '}铭'h0%ɚK`ي'>5%e2Kkצ]L _A#p4EӦtts;GN* }R!G !Veunz9DUXF2]p5'"u{^a"֤䓦L ^Ҕj' \6 K>3pJyTyωXk?kR6rrYNɟ:כyYo9NcġEy^e[PNELkyn"0@~GtΫ"V>޶ 0~?#֥L%0?}}#`E]EO)~ CptHCWy\?#nMv;fIpk?ooWM!#^AT:~Өv&i}f 7sfJ]7N`M_~,%x_{Q?-3fDo">|-"Pu.8Ls^?UG,_n-Gr4U5acYG\[Ӻ`s~ym H$W>;{פ'5jtÆ@f>3♯XnL6 о?z)=8=i/;%hkg#*r}g]޺DA6JOkbSQ>6tOkQQѱGF6ɮqPD`~J~ jWsڤ5n[ۚXӝ9f %>f3T}M`g?㷼jj/z]k/ȣ<(}lߧ=jmdߚsT@N7>i@R֦O;%3|+bSSuse|,}lnlTe+sᦔD}YĥK.:>ė'(qN&M߈קLz-hIOf>uמʫ@g!ⷿ_~xTKޔnLjz#NRJ+|%.7>UA~맃)Ovu7ִF˫HF%=uOJy FjU֥򾈓qM N :suF9>qt ~[O _/cgcz+io=R;kJ1勅/~cP:YUdm'$kp[www;[uqwX] I{Wфg]ut}jGn3ϷݧwP\'mw@r1|]rb:[@84\UܶڃBhtOsMKJW?iCOZ4)(A .(k.Z2m۸tS⯢O`9v5m r9҇viЋ$C4Xq3S2<^ 0Ook 8`dwiȊ݅@'ώOi{Zݶkng;RԾS'%0[D0pÅ̮v-$0etŦg ۳^,`^A"yݲO-mtLi+s9攄qOl%'Kk-]dv' Ptvv^Uhь04{ O4>C,i1Tf/O˜dbC?M#V Иic"o#)Sr:IPH@VZ uG #qcP|C͗>6$ e!`{_@8ʒWhozW-}@~p"zZ&Tק?Kl-k' L5rYdKόȒUgIk+?G9<ٙ xui奓"!!otb ܳyB2Ki 6p*OSZJ觥L+A9@ԁ$*<]˓/;l,?x` #acP|-Pa-x Z`:{$!:Iw""Sгt>+r$)/9/TV&S3hC`(ȝIÌʿKl$4COT%` "oJUp#wA[Jn*}¹E~KIVh_KlxL@C yp/YO&֬ fMPQZ|Əةֵgdyi_䲃{$l JƝS9Tio3L L"soA fdx6Za9!f 镧3M=3HG͂K`<ھ#ō!ovZE4>}צmd?gN4:;F&~Z #~ iTrGkjUA y)Ѹ1*>_ {'2%0z޿+ө $0]x1B>Pps,A .q~୤( E#p׀מ);65 .;M7w IKN^wթ}i:)qB :'S?FiP&y'l f(pw-A>P/?T5$Oܣ198FA .aZ(!3qzmwpaK <@H`9m7~ü%S3&7kp<4?2|?lJ&@*~^꽡t!ҤLQ$Fo3U_bf1RxUiHVi|ޯcsO> nC pݐiC܋G4?FC (ӠJߏwRU=ըp-RZz^;ߝu-U|ݹ>UO_K{/s6qvWť;2O,xD`xXX jxi;Weuǁ5]mfA}/g%3'8CĜ6G= p!ݩj#G,΀[uޗHEo4G9::$AM"6 )J)}dlbM`xҶISI3$l$Fu5=Og3@ oGIl+]uVޞ0>@fY;|%@H)5}̢s벵\ l83 @?FVµ&E;N48ݵd4;,?x ܎fƀd>!~b>iE{Nu5@ |ʒL.}_Hw]#] _šQfQ~x1U +w;HƔ,8qWH;}崛88Nw{@?M1@&Ӛh}g8if 6*<]?\([(pϖϳjsb=7F'bq#OK:l{ioq,1C`)lti8RRiҤRB;Z:xk醾͌pJ;|rRV_il#ydwAC`zvp&~Zz*A?DD4%ݵ}sfO}:1Dԥl hxK4]KLCaa  M#V d+K. &HBY't>o>~ί6ݼvW M\Wzk܂@lS/v]Cq`lk 7 iSL'~Zt4&@&~!кbwW21FfwA mx ?$df~+ۃW)l I%p6˚ϒ'S"p9s-,fc wC,#`o^`icZ` 0}ځ=/QCݗ+^z"X&Э?O5iyr4Ӡi\@rOc% ]J=l vpwiYZ_Z:"'LLsF ߾3Q1@Evgs]?E))L;8Í}SL*@ /i̽;ϞT:{Y2\&0#/9nƖf _)t3bf?Tnﶦ@ P^!'2@?-sv%rO] >NT ]JgZ\1/ B>q /4CabhQbO% 4"`(4zT ҞI]^P[$0%~g*]' $0K/g|DwfNH -,@BLAz!~Z\)@?BcO2y~ZlK&Tx4Vu_P_~1hOA :vpf1">ä)fw]A )ÇVp^RH`$SHzt^b~4Q1.*#l8YxsE܃_Ҝt m0>zR>rGT(pw3/xi4n@-cE? Ɖ^@?M% 4Ӥb\טt5}9qgAnZ91 VH;ρ|QQ,A}$b)sC B>.Gk_# £+ A@H<SSHiHs5~+~&H4"8A BKA/,Rf(.cV(pd2>;~nf%ە]<2_?=> 8@;! i_

.:N\ t /iNWzt.?M:eidw}3@(p/w~KiSLB4%#y~SE.fOD. y&MYxfO`Bd%,|5BQ\ytboͤ(1+sB 8C2%zBx>sEG 'p>?xOk7M[1@O ,\@OsN@O#@cHO3dI&ݥ72zd3{ /|.,4dMO3ӪO7<%p;J&f;/E#Еh ޔVI&-Evn S!?P[ :NC%%cFX$~ZʴR%~*č& @?M&  o a$b7Qp#%F,3cD|o0=J7&>O,fƽ6sAMtH3HooR'``Dqb,A?ume޳M( X]UXf'J]SxO`yG@?-Hp@?u0)5\B?˹@?=8&O q.el!Кtb G l_ (AYNV\w.:9 Pn .QOC"+O]Dm?Ok|ÝY!iZ=sLH_qcns ih_hFƀ`)#(Q}swbxI-ccbx*^ @d}Of4@m/>.]z>]m^Y\@ȗBoYA@ 2~!l D4&:A w觹Tx"I.y7vX)h_hFƀpzġ,/? '3I,fN u+=ǨkL{m6< vpϑE1"&V!@;τi>Gw{ ^Fvr8ˬ*=}1@~(5Փdǖޭԣ4,Ҍ-2kAj׾SfIcMmokC_B~t9y@>O8tژ !,{>Oy@Y@?͊tyOwOg"izE?u.vm ^ ``WC7+ϔ.;ȃ=nݥZq\)h2?W .dF.B=l;i̦~y_3$*f7=fNw\67[ݗK_}Z)>Ip҆>hnlvl;ۿ7  ,oO}8B 砱觍p?KYҮ̅~=ψ~T)pw%5 yp/y]H@ؐ.;U,&b@ -`v>}iՠ9Z/-$-bus/Q<}/"\[Gu?}( 6;O%`uSnd.fLĎ*?:Jݞvg?Ǚݷf1]Ta>'[8C p,ӲexO;d3~,O#~Wͷ4'ZfXp++3cD<77tp]WKi~-ͽ@}o[nwtE Y6[ 14Qe.}&i9HpxѥV@ZbYi:S^f ϮHvު2F].:^Zgsi9{Y=S餽qM#`Ivleo_DS?o_yes܆%0|p@OAI@?mL$ufd2~~3)+piTb`xA:oVxw :_z%3F0{Li XM8!_ #vh82ڭrW l1tňCw[+/I ]fi݃g&N֞Ru,BG+;*}nun#жd)l,=vЭ ;~[`~K`ioGYsW!Ru]P;*xgVN+\<8支7OF idt~Zȴy4)G?u#>x~/M6e<97/nL:]NGvSS C@ZQNT md?=DG}nݤrx#7Ulrk%1jx];/:K&+FJkmc|9ROI~AmZ@IDAT3ҭ34'ƭurS޿7OMciwYTKˑ)>dهrcLvG׭y6뼁If39W~R|ޒrОHsIY@? Ϭh#O1Ft|ߗOg483~&mS": 8W{RF`SK- )ʬ)/Y KXz|/SB#Ҽ Vy |95cmicd,P;}kcFIV/'i#бtY)hCm^Hl҃7e\vg1[~i[Lbv5;oRzaG&=' <,n%{ל']|b32WR6Ŧd>w9)Ŷut/{6VrFT@?u?GQ G`oˇYҳ_F˧&v;A:̪uUNv^MbWъMMiu;Ikl,lvl5$`yI fCm)C9sC`nC;_٭M|(ӬߘBk/7vwltZ⎽֗L~nf O~[SVۀMA ~k6lxΜP`>zLA_.*X6(i˹D?m=Oi9 &~R*}(pOk.— }afA -~7g 練Kj!m9waLnUu,]XTV~En=~Y@oI F9N1ʟUvro1_|#=qC K;+}4Ѳ'0pۚod?73B7ӾxS4~>W*Pr4vL.:;)Φ4/t.)p1 L@ 1AnXzf@N<VlWKs׾!+M&/ƢGt$.)-3&̟ǬBnt,\tiץݥd/,9gd e5YXkJ ?nz+wAYLk>jlv9{luwI/;3/-Ԩw Ц4Cw'\ # 4iK}4]X9G?M7/bTӪ\Rv^Uz|iFa7̑4E`(iY/]eNx^"pҍ󬿕tŃ/x iͥ)SW{#{LY8i͎~~:Or'i@?Mg (poPfo3|n` +-e'p)q 2 Giu~Rw[%0|)n_Quqc(x 1G &?u9KtZ>E:|}` a}%+Qދv3TmA=VfcSe_?y7y^\gλQZ,lHGjNpx>H\WkSrIf30-ҳ;j 12ŴJ'D"~ [OSG觩#<i`TwD?OS~§P4YX8>]x/s fWS"0adǴYf+glD&3QwwӷuNS9(ٙ7)'IldvEx>)؉K)rwӥ9k.xiCr?}hZ)iŨG 7Κ7Y7} S>>jXkMf)6 ,i^Vl}՞2yrcN+w9oO3o?I,&4ih^]#7_nNfXw ah@ pc4=7ǢsS W癀~\.Ocق% [k!jDnZ+Iw G`i -81?=!fWVGsuULNVQ'3 s/O`x +EnƷN} =XFOুBw_~1 ~Yln%̦.?sz-*o]ff'^/=.Kg75%`ö.pkݦ\).ڡIC~+n .xqfW]>別(Qltt1%_q|1qR^\aoa~C@pYe4 ́~֧mSrG@?͖w&C4-X@= gMDkn,]n` LhvlWrp{>%;W|fv%:"\{tE>evj?仡)~I.=Ht5אn7\O5엛ӊG0 vfG_+ELJmV/6Eg*= &Nzs`9_?|+?N_*0O(m4u*@ 0yvYsB/}}HcF{}tYTN@O&itvE~oOev(S4EXxO3k<1ThN0 7qbnθ#%%`WB0E-4dIYV8μ8jKg*&`21=i(nϚ~>1oJ9ZyYldx3']ٿWVPZZҒ˛f1;Y^m`|#*æؔrg~N?n{%Q3D˨.;Dһxce>v>65&%mtcOnԍNf8ZSG6 *4|%Mig9V$/km&=_SlݎgIDq~ԏ\In|VZhɼ`^ ̽tQLc;=,OCMq/."*>J-~DPEIRhmP%+Jd YS0^^Բ՜py~[Gj`Zv7l<ܟҎe?ػ>3iB?͞93#~S{9{~%i4n!FNXv!Y4Mp:qc_窛qoej}?챪4"ۡ]h^zp=I<`v׼#I؂@|n\$`wwQnW`>Y8f7z/=%XF6O*?.QL#0•~$1E(p =Oc_Oi-` Koh\Oq 81YxB@k^CP ܫC4uG`p_;JYəyʮg]+:)NCf7M+-}g" 9yasS-{BǕJPo1++Lq(_"? 5Ά/Joiļ4 䤁6G]y5C$8[C@\q F~ϣO>i-` h_O3 1Rکs g|6 ":Lv+/z'@aju'TU4[*Gmgv9iֹ{Ri͂]K`0}a]w//Q=;SZcWf)>&gᙵ4jV9}ǖz8j9;݇GZ&`ahK4.O3cDivX3S8x ixA{@Pwb *hh١ %0}LcpU~ ^v&]ttR1E`{ߒ_8/ǥo#V,v=8imoߦvqK;`C29X_zI=#*$$3 R9X54%`78zo]Zst#~ OPOA(~!'~<Ӽ,EX󢟆i8^!zSV]٥̳Im"+/z' uCLQQSvOV]e"RI[Ռ~s3vv!Ep7A=;n;kE+5m?/={ls;$jcJw)* 1i,nfAٯ9O7i6%p\~jf 4xNO ٓRuh瘧6 &*#E$P^i.qc$Mﮏec'+f,Q+:vb(-yFH(rMM6!sIu4\ pB_i\@9E$'IJ¤+}dN%C`J#-\2jy--|GV@j=u4Oy>I>~$Ml5&~ژHOgO3i(~WTwz7 Z6 & ep@.`ZCSc$}cNНWP` JawBzn3Oe"\"ЛSX\JG(_=VӜA@=zJ ̞{H=2HOs'-ny'PĊfU%ؑjjzy׸ OP4>C,#~S^Q1.MiM6i|j4xfO ѓR.uxZ6 & Ӥm$@.& g.teθSZG8r|< 6DsJw.s.\t4bX*1 H5tV,kl$u^|[w,ttwqՓ洪74ZmcFISh ,tRmaA h=%|J~?>hŽB? Kq %xhOgČIPiܣ!ֽsL0ŌKYanK`ܱ .:'D`%2T3I:$a=4eJs(?zK%{ Ys~8> CelB :-w> R>gϾL3u6e(Xz1e).ӹMf1Ec0nvt᭜c[hH!4AA %ixfHi4IB? {`B3Tvo S7 nKp|!>!p ll Ei[tٜ&yyPyFϻ协ȊG`]6,*DL/]By'ϹN1n/:s.:`E{o$n|Z3 ^  ~ZLBOXOckv0ixx09@8%iDp J*OHL|!Gfx ;XS! 9v!Gc26'£GʐJl.F\hK` .:'Dی/79#.:^#Δ {qVvemסDJqvЁSKka'gKC`Mfl[M:g])v~c>2bmF?v+gas|XHNH'Kzq1yO~W&K4YiLitvYD?͂sx@ugZi]iZ/m ܋2xJv,7)4A`%9~`r)~%Kk7ǥG'kkHJ'g!F"x*]l XO1N>7K,ZoLIX|YiV>;oTFy?8⏸VҒ+?!u^1|K'gE󠟦?tb5rE?M'@?/iŶ%~y>!=$ԺCmpU, v HEP^rns+_{KSGf﵈t[-2)3}"r| ҧ%e ;G`Mgt:Xstlc>>F \ [~ߨl gujOQ 4>C,dO4YZ<54-حO>Oy.vWڶ%chA8C`q%WG݋, L^@S2zV]() @ s+-]v4gb 4@`u\vܿnC v3L-))S^mz+}Ž4NEљ82S2O;B?M>3bvOc~K,'~aO&ZOkOk6dQϋ(`LZZz{5*\˂c,fr{tR"_& ?"u|4t-(}9g K13tν>9{X@K8\jӦ^~>֋~]-vk-:,AHs.nڭH^+p-U3~Ҽ hBw .@<*vN|!/mvOWߏxRY!~q".Oߗ0_hț2[m m , =~"hOYOq(ݗӝַ?i1D`-)⦱Rޔ W*O}&&kn@?M&pJ|&a4 ؈B:5\"\=ԆK55Nސ۝OYcfH`եYf/cdbWXk9_{b36;į{moSpIb,M@\%@'J9~Nq$`sVS<'KoWxӽbа*#ϕx1qf"~,ydyb-4XG4$F&AQ V'~ZKTDސVz[gePrzJ;K-wl;$kHLq+|qxSl?95\\-8liCZtu1O`eҟ'ARŚãHvӴ^\}Y\ߓ'[}f%rhcمm<>gtr?#D~Z!5pTO4>C,'~a\ q 2>.Os yTќ"N3K -d&S1 `8ZC{2vNyqy/$ؔ<3Rp)I>~KgJcG'i[G`vÍwrh7=,A 77Ih H@;n !:v>u/Ar&3Xb}s~!@?/hӸOs yRҬs>SSʙּ7_E ,ig:op!EJ8f<0s҇j(IuC-y [Vt%E_FkѲEUx3\v/xZN3*-|9c)$ ;?g7EcCgavԭGaMQN:Lg፡O!i|X( IC?1 s8iL OiuթYŮ)O8Mvp!\oyn- +I !V%COCg }n{Whmbt;?_؜~NXw |#߿y鉼3Pq-S,A `mQvp1UcF?%EP\2~!@?/hӨӦT}OtHR)Oy{$tPFrx;n'N:]jwb7=ǧ'4"mkvwiX&A~>.'0ltϵ1I_в'pYbAP$ Nirٛ OuOOHF;V*iZ-+xE?Ǐ gijIiSMDB{$l)Z`qiqv3EДab0Gт=8+zK%+B`Z~4G]~aMQ]BfE OƾҤ1I$`# V7 [ 3HBf˜;GѬO/CѼNQå_KƖV?L>DJ>??_DܔiS&a%F@?Yxi<~QFFƘ4 6~ڔF+GFOIf@XˮvDzϙwʟ$"^G&a pH |jso~!E4z>Ocd|~ ~ڔiSP]펭e~0RRy@0&pL%^$ծtRNhv:؃@S q}(NK.fL`c.r~)s>ϏUn>f@Pv"ZC/>x×Hǹ< ƷdGNJdqi<~./E?Ύv4iXbϊiSҾMIDB{dt)lQ:ʓh3st!`{x;]JGyZ?Bie􀹇<P8^ΎBKd7WQfu>(JȒK\C+Iˬ P$]f6۹H/3,C?Ύ@?ki<~AG%E<6~ڔD+GFI3th Ms h3EK%B !9@/9j>tލeq؝2-Zxs/]8'' ,t>F/Oޕx. FC ?>NNf@T%YmVGǢƟJ c:c<22G46oć+ѳ~##~-Ѹ1*> X@? B>y@?mJG)XWZ )'y$bF (pw! xZ2PO[HS0QmN&Lo}F'%#ɎҞGK:_Tw[Ȋ@ٳyXL`'b݆yԆ~=dYZgdlaE#ݝٗƗda y~ PGE[ah7)Im6qi\6$f``}`PiSώfL)c`G9y!$0gE_pY͘`OqWOic"wi6% ՝e8'6p҄_pل[BD1 ÑW8^Ξ.O:JivvǛ.l>-)X~̓cHmU4n赘n7(M纗W&3Sj:7U<}S`5322fTi1 [D6FXsӖe&JR{ON1;i2g@?O#m ZOk}6Ii:\YE?F߮@?m!Ӧb]8(]OcMStF"C"`wLA"`Sr{UZ[S#I[4w 8_ɚK ^ķ㋅aC'%Zt_ФH>!v jJrze/?5Zv5یH`:-rM(4ЇH@? <@? όEOsjzOck-@?m'iPa(v҆fXw* ?AڟX}4|O3c#~ꏡVtZE?M-'~ڔOic_=6 Nn %WX.0{\`3x aʠ=(J? 22-{Z==ֹѦx[鴫9 BS%`'\pԣ'< $ ,9d$-f!D ,V).A(iz?h?WXw׸ ?Q4zO4\O7@? J4/z#~_sOc@?mӦǾBql9hFm5Gwm9&3i=\ <`4ϧ7&nyAz7ۤMvzcm VYW: V3盃c͢٧̏I{N:fOYe}'])HtcSc&i^-v r^g^\1ixf@PAIUExO6Liv|OF@+>FIJ5Ik1ff@S C(f]~$~nz,;R`iդy v:=[iV3oG$ҍI*dW&pEҤInwK-/qK E`zS@{ҥ)h]=" :$-Y[&MA M#=ZC>@s)jz+@'scZlƔw2?ᘢEo%~i8^G4jOQOf'imn赘tP[W]jl8xM9![J A P&mV^8+GUf LA-j\51Bj/wC!].K} H~{,"5Oz`Oa( `wˡ%K`퓵5M!iP<>}AO/d32&0(~yxOC? NjJ489i|-6&} 6͐Oic_=6B d4U]eSn>~[2%̮Z+#fR9"+/ztY;oMHƶԋǧ8?OcoM+_4nZ hR؁();= ˬMA m|AӔ7UOMJC7=4~|9Yjݦ!iEo!~ipVG4ƣO~6͒7iГB{av]rJ$]i{Dt*G&v^?3*-YLZdq*v_p O`A뎫C|WWlsK,]t|c;/Ϻ?H!<ݚGXkNE G.|e"O0v5%Mq>>4 iy}֯O4/zC .Og<5~ژ@i|OF X#f6ܮ"2$@v 0c4 dK`C.,Jvb6]R7@eѩ\"ONК'к,g(|#0G 2>Og48+zB IhDO3o> niL6<+FqA҅ ' >㥛+{ԩ+!`)GnԍNE DWpרp(8/3knjz|ŜCk\K:5߇G!_vpyo-r~!$Ogt5~ژ@z|OG*՝b(, å^޲@IDATxpJ,G$-Z'R[6}(}Y٢"iGMdw5$D0ݫUAo].S~=!`TOqW<~ZBz|OG*b(,VppW9#u4{#<%`w!.  MdtMn]K\>yysqp\|Rvpo3܇@D5iD/I48]i4nFV5 Vϐ/ic_36B @%К!!7XgIOD W QM0NN#v?[iŵ_6AWg^R-?P2$zxG}B;b!RYF? ΊHi08+:D?OE"~Z=[գ}1@I ey} ԕN@:u:*IJ`~7Go Bp@6κV(RˮB g Qå7E5o{7֥k܃v<ilD/dA4e`itvG֧@?)_b=B{,|  V>K@Y VQ蒍 5@ :}/#ۗH3m1kpDD'#҄ 3J|A3(tC_&`|y4ƌ ƅ^n@?  ,~@?ƭ(D_觵6PBG(p<#%p!PRll] k5wH .DŽE/ nil& cc0 @@ٿPlkKsI!v(H^<hڴ6QuZAЩ> Pvמ)Db?FNσw =Ӗy@?m[i(16JDg>>oM H $ R " * ""/VE,`_)J銈B@Pz/!BMr;f&wv)|{9s s>ǢČt4ant@&}&\زKNfw2ft[왫3evS3ün^;'&:*XVlmiQ?MD/!@4:tN.@4gP?]^m~%_ 5f:ND<`g '\WsHI'~/Ar8))Guf - Q}~ܠߐ/?k5m/7=Sharz /Gw*@49sO@&gi=j~Z[YO+5xoLV]dx*wOO8"?s$Øt4x/ P;=E^Oi:'z!LOQgQ?-KjlR?M߭\'! X%𗋥Er'grAA`I}p'7iC< 0&F.7(E G^. ;oHo-y?[P_T4zFMMst;-\ uv.wsY Q|[zn냧~BF@~CkOk Ϥ~Zg' P?M6*"ܖɝqpJܝJ' yr?u(gF$ҷ>ݤ XpkvYnA,";՗0^>?ΎX.?"~4sFtꋥݷ 땾!eݤM+2ƳSrMry΅TH@s?,dXEjnb|ty?yF@ə~lDOUARy P?Kq|֮x&  O<,=oܼJŕ@>^} G((Gp6v ͭ|;@}=|~};s?JnciwvN wwt@^YIhUR?M.腀 O@4وf7K_O>zǭ|7W w{bJQW6Z;{de{*':%3Ono&i=0Mi|FZ³nǙ P?]Ä|q@@o'&O‚O:тI2EXF`c9 4J׏^&г?/\(}?)t~Ή^$@49OMi6O+5x_Zs%Y^ .C#N S$|6i[D[[IQ۹Mmx} .НL)Z%ɣ6v _~Ũ |Zj{F@4Yi=0RibZ&!ӌ`ݩV`6L\ K@X S,pw*7|nr?{B'(@=<˟ߪ{~ia{f,D>>!5Y-2EgK,0Ϊט>ֽ1_gm#P@vpY^Q&R?M6 P? xZ P?nV>iY,Oh5/uY^ .C#N xʩt ^̛#:/B9nOtND& vM?Oz!'Ԭjݔpko`TE\)MEz &TG}gQZ̮wG==݋).ލk4~lDL~>f~,f~ͫܛiY$IBR?-P24 ܝJ' 7|u5'#k# Yр:G/2trL:v -ekoXyW~m{GAv_nmM^/?#U XC`ɉ~lDl~%>f~ͫܛiY8q:R?-0,p/@XT: ~u1Gu?UHE|Pz_9+DvY ۥvɣ 5\(ˣJ) z*\͟W6GK49{O聀OcD4ƌO3-N67΢~jo}%˰  M&^ܒKwK24HkvxZ {ozʞ|n4ި.0n3o~,pOg] ݧl+|Q?M6P?xZ P?MoUٓiFq̧iAa{A 'v;@ITԈQ҄Њp&>WSomi{ү,0|UixEeH\8G~ުܓiYjOɘܷiAa{A 8'wrJ@*p-…FO\;8fAyD L}$8G*DY$vn!}Oo{/?/Z~&F@&٢~Ckz=%x~b1e2, ܝK)!np6S @ `;2Ҭw SN[uSnٰS` ՃE J ?w`A#=7Яxmir樟&V6d~+M4/gP??ӾO  eX@@&,l[.l% 6ޢ 3UH%3=1%Vee?9H3ga6>~g<|7ޟR?MNd#z `Q?5tNVj,@,aoӂ`pNܝK)!'K~dhR @ `f'mT@iN@ ?,8[ӏao;{O[KOߟ.w3l_|OsF4و(@4>kO}hM'@4Se/꧕/ P?-K[l XE`s)% z'5(^7WNCI#3&2 Q YA>29v_~GֈQ._~O_N+> ݧl+nđ6_S?V 6~*I4/ie2,  @ۛ6]nҀM"@jǥ]W^>]@kk:>k: exQ+2  l*xJ,pg;*0tEw@q!@49O聀OgiuZ P?Mo~ˇOɲӂ`pO i |nrv4<@],pMJ#| =='=`GNOu<-vtQo4è!+o~@9S?MNd#z `Q?5YiQe꧕~giAd{A 8'wRJ@8%0:R!L`B\SAiǷӊ@@֤W Q= \XgC WIǘҳ$0w.|y} Q{RC4Ui|樟К,@4٨J S?u3k XE@hwH +v-MF !);{iMȹ :Ӄ =j!\p1Ք{2@W6,p5I8#0t`ͷ''nLڜ iR?MD/l~9>& P?M6*~Z5~iAYd{A 8'K޹tQU5%!+:l^glXO聀 OgiuZ P?M~ʇOʲӂ`pNΥpJ۝ `M,dXE yV ƌ $DIBKW_s{!p"У֮D=d7 hY"˿Xn'ir~&V"6~)#'Sw{LTD`i%(xg &[ gD KD c9޳}tmQx}v1O}h~SJROʿP@@>{< A ؁(>ܠ5^5֥@wS;wwwb%vpEtN{xÖ lmgcM4]js P? xZTR?=S{lRi(!@'ɴNۣ~.O9 giO}*[Vj;~ZH.Y^+". 1! =1 k؍ *9D!0yv Jbv Jozgs=B~O@⍊tK+pyM?Chkb-E'UiO3B4و"@4>O}h~SJRO?BrBXpPL*!!@[9H! *uv\ |-g!`;Aﰷ4Wi:腀 OH4އx>Ve ^C|Kʠ   u1|tJB {q#"xYpgJ#FuJ?Av{agZ:j=!]jGm\w;wGG4]s.P?"xZ\n|[f7s ndiayd{a 8&N%ppD 0AS00#`@ h #Zi<y  ?Sjgf'> /9z| \tk=W`އ;j3l[V @4]sP?ImhI~l~ɇ^O2rɝhpL%ppDࡻ 0AS00#`7hk"'.Dq:a#^ם< 쌙P뙜WXP:!Y#"qK5{ S?M腀+O3I4އx>a+d#_zP?u'O ˥cUœ@|@4W_fcڬ̜Of΋Y!@1}3++G36v]sU/-N7'0jvWb|2t+"ŋQE`q'e\y4<'.P?"xZO|AԍLS?-4,p/@@ x†vn`v r.@@~7ZYDDt`"7R}ׂ8Z܈%(=.}c$l7V{Xl'iP?MoEO\~E> P? [&҃~ZhY^(/# Rtw(%{ܠIMEG+v xZZie">K_wv &?ι5s(jtƽ/n"[`OHGb8\i S?MoEO\~E> P? [=ȗO4s‰ I$a =u6Y8! 4z|; QN|ѧ/=z_-uر39*skV#gKnol#GK_iOgiz+z",R?5^iOJ4ȗO4s‰ #_J:->BVD]؁8[FMrف(ȗL'}xc(jX((z]X~gE.yV_Ӯym K$;rD4]_ xZO|4ӆ a"   L{\+ғ艀 ,4";/WVNC?Acw4`15{/;t>?lFDT_~r7Jlg*~Zi=pIi|6/@4'l~lKvgiC0s@vpw ;|n\Ι?@n=ѳg[RwљAco*w&hդ㷷K_9H9՚][6i(#td_1?WR?-K{~Ή^"@4>O}h~C4ǷVfirQs!@r[@cܠɖ=7-,_g/͟[UU6W#'.^7GWFYy+އJ_lYSsE!8LQi=̝ҕI92O~C P?)xZP?~ڰܱa\\'#c:PF aoa؄ _k`R,;'j؈vZJ.>}gל1[!~,:IHI:Raޥ0I~FiiK-xOL4وO]G%x 9~м\ @@nwa `^L |^b: )`ڂI6 ;5K]Љ1ǝ. [j3 K6V:),ew͢8o/ԭɷp7۾4_ fJ~L4C8,@49O-@4ڥ|iYײӲ=O&WG+CG\SM-靷H- SWۿqlKmކ*pv JU1 `G<0@`q{ȝGoXz?^0I`/lVpR>ݺHC[4\-?-f7 l~.sO9ѫӮ&GVj>~jisA@R[8Sq0CZ0?1zMax0B?1 'DƧ Q|j؁(O Sy#=og͞y`_GD@Y`53)t6I[{m ~s-/ߚp%9OS?n*@4]樟sWW]M*P?}(@ԮӆmN@[H 0 fa.8Kui`Ό@ /HuͷZ9n5ʼn@E3ծӹ[wڧ-p?‰[8piGHNXSFF~)gg4}ȽңI?,zG -Z|p!+J;ovR.꧵imnMOgiz+z.+@tY~?S?3@)b{Sع(  @X^ݛJ:F:N$0\ \p$i·OԐ$i;\.m)hi53~[n;|[fk<ï^e5鵗̙3IwMϤ=q=ZC@K&>n9Jys>J EB˞O P?-Oks,l~-SOy{ӥQ﨟F}~ڴ< hiIщ. @a ;_aBC9NGJ\hD:?0;ŧx;yںnnQ؟4f-&lT?ݠ0wߖNO\#V%_/ؕ}{i=MXG)ыi}y~Zg#`왡~݌3JO? O}|m~j~機6-G,po=F,`e c8*syנ.t䮥n% (޻W ,y}@;Ujt} vw#lZK'~Ϥ5]k.K{}B"y L':;K|%sux>)pFҝ7;(!)@JمiJ(!`A4?KF~Z=OxB؏Ӧiz  `;[(@﮿ Nl,rYKZ}9N,_WٽG`Dϕ&?s_B›<+v7uVJiUSV!8/faJml~~M~Є,>t^[H_&̊9 ~7MZ*<8$@'iuZ~jDV+gD ` -HSDv *6ɋK=Tz{%FG+ @-@T]mm 0dUք1>_8J<7q!G>S}鈓[F\+1 @:jEV9Cږ1sKz.VE~j֧1{IA ` bzx hB1@X7t G;Eptϒz^3#hRA͹W=KR7n[e~,?Ӹ)2!@ W꧹r2 S_WOQ?nCKIfa,&  PU<4 do@6 *;UaUGu͞{_uc s7zy2+@^ r> @YiY׬OQ?nCKIfa,XnT:  `@ɓcn '|@! F(y v Wv nCRcN]3+p7Ckt=tҾJR"i @OSS@ AiUV6,~Ԣ﨟6C=,p@clhsO5\@=DD`Wo@?/k#tyE҄uֈ_:8i땥v,|`0o@$@O @^OosN -K.h;꧍Ou=b X·-͞GpE\d`|nuZ3Ҟ1~*V`]k0zI' aE=N?Jr%ؽ/|`[$)@Ki^CzΩVeYz4'꧍P,p@@. $DpT`BG#Z[ +vM]S&VєK{wѵ֗.ݻЛДKs#NY:piÃ]sRgG`@`3< SsOR?nCKW]M:B(\e{. x $0\4'! E2lmMȠAɰ`* s(qӳd-obKz>fϼW]zpӥ6&|տ^޸9-@ H꧍vZOiuZ P?jRE:& sd0@a;\BC_`L@ nX&#'bia6D lt/8ZH+\XM㥞Bwn zW*K;.>>xto#-^VD P?/g0Y1{nOiuZFui^öS28 J& `@;Z_na2 `7h̋ j,3Gv jWqKJH̚H dּ|ͰUϐ~?K=AAZm )_N=d~E Iyh&@Mğ6 P?J4}YnD `@ d 7h\,q!\/DsػO6ZHtMbw?Cw l$?w FS`(=+#74jl3X^_0 PMi5#"@5 VP?nCKdOlgiaR n`R pƣd* nn<E?S8mAǗIzK\<{&i=|03S$q4]3Ǭx|pr׹ YAY= û%@ԯ|- PӢitnFp4l^OVʴ1iE a@nؑ'f" [2e<[[͛ 3 $@ v;ixg 1cl{Е܍ O9W:(#a&̜!>u6}vz ˻?%ȤGpMk%@OoթFgi G P?fF4Yn`R4Hcq.eݑD p1m@P £7hpSvN:Dz:r=PW/f pt6{ns+={wiK ; Å[Xgl~jk7 `S3bìFgi GkOX]9T@ g,p$L\tF.P  ;y#|v '8GG`&uJg}AzFr5֖λB[q9Mp;JϷ8g kW]G; ;& P?51+ [k쩟FS?vh}OFXz&i#@ ټ Z~c1 7h*UrY Ѻ~tҷ(!` ӥ~ݖmL:E6Ξ9,)J䮑YAZ~+ ڟ# q O]nQ?~.5~¡w,pw(=#@& V.e@hlhV@Hav d`.mt!8C!}xoIX0aXU3,|.4 `o]֧oipjk,}T~(sw5E P?-Jq@7rтO]8S}rF @C=7;g7'0a2 G|M*Z؁(ZWE Op~ϗst3`䳥Uǘ9?fMgww. vr]v.0Q`Jףgiqs%!Ö Pz9@`yˋsZRO]8|=&M`-Ird@7<E؁(څ uvqtIҥ?.E)}M9]H+kEΘ#о@zsY,x_=\>v-i`ag P?MD/@O[sYz~ZhE 3~X`p. ݠd0@ FbphBI45qR A>9@QWNtҕ.9Oz뵢֘q*ttJ%K;c0unݤmv>}livn%k8g> =0F ,/M} K~Hc&H-ߡ<@$@O @Og<ѹ~o `{ F {KO@ ov [@zC@VJilzG  C:0#*p;g5l /oVJ;%<*ttH ϯ~a+iF( 0KKl$ii{}jV^O9'b@hE ;>R?vh63K@IDATΚ+*]\9 Xlt:Y7#7h.Dz3 ;E]8xp7](=o{Q-͝9o 0ڥ}$n6>&^o$|&^3ĜLpҳ<ϡJˋ7B?+n Kt @36CݍkR?#h6^i͹b],p@jvpO>'/Woʈ =@w *лOcA͚pwy)Ңc^=\>f-*Kc %ce~8} aK!Hwߖ&\z ^ɶHCE<pQY%&@OoթFgi G+@\= S1 `w'JP ;9TBB,DMNŗo=v damݥ *=VirY3}|gٟ~(_#ݷԧ߲} FV[C+ K%әK:;-4D#;{z+z"@s>wLFC@ \Z؁(Z-\›6+\z8H_aD$(R7ٍ-mL5sB ^i  P?͍oR0#?O#Y8hS Yv~Xl ܗ'h5Κ+!> SĚ;Ekr&څ @O^.],gx\5Xֻb#)v.@ 1?@Nv̈́YS?h" ,pOXpp9AR p&5@2ퟡ3]` +4x.p֯gI18j7ęroyҐ-w vwjWiᵍY-@haG~gi"h" l=D38,pp8"Apc y Qޢɣ.]M8">*ȓk9s@ O3$`Wҧ.y^_i UiWNK G@'ь {dKW@ G?q0B@`7h(*N;rQ@׃EgJx-@ңK"4Vg}ߑ?O@ 4J~"Q?v(  @a+Gyha{:(z!@sf>$" n!UrDpG/H(_(E<_+5QmӤ]ĕdF@.@4gFpv(  @avpO\'+Dz2 @I` $Mvpv( P[ZizG|(JoΑLe gI o= 0,"о@/Jی~u z*@6 PӂitrFpH`{ ;O. [`|= @@B Ei'ڍ4.E;t/~R7M3+0ss]֐Sfk2O1"~hqG4:O]8$=fpX±%4pFI% )&g*څ @QG$]u4aݢ P@G[E{I; # @꧵q @8ڒF Q?v(  @avpO\vpOoEOW4z2 H]s]>W.g@TJNNԳd^ $ҏO]U:S&A; P?]փ@~Z#P?>h" ,pO\X!-Q@>Xu4.h;v v( P@poH7>&m}Wc|(R}teҾJG.=tgWclMbA~jFlQ?v(  @QgK,;g7'DY2 @I`$]vܸv( (֔/nU%paKl%M)Ja P?&q@Z*yh" ,pO hf \`"2J< @؁9ymN< p㪫 G@ xQߞ8W P#I-}j=+\!~j} 0Nq)jBOE4څ @ hFG(gK,;g7'0n~c1 ;9Gz@Q@CW~zt #1y @c(={;zLM; @wPg[M更"+,}4BZ}\@D<@@ :IJ'zM+Ǡ'4NH?-'~q]imnYϢ~U <5QO%u@#| "XR`?<@F p&Wo4f4r4jsҢp!{>lFABH3A"![8ObKE\1@V7KtҪk~0|@Ӳ u N@NGK:;,8F<kOvh}IҎ6!ؙ=\@rhmeA@o`z_CUzq4D)ӧJm*ZimL~Z=l^F@ ,ZE`{ M ;gK.;g7#D9,j?gUg! ,Q @VHk ܧIwχ.:@ /3$}B#qMj~Zg! V @ hFG:;XAa XEX4FF4p@r`(@HIҜ{o[i[p wߖ9 1tf꧙D4g  UiV1#T`{#-,pEoG!,n&Fo@jZy v=Tå4uD7)g PO!ϗtV#p^OR?Eo@j~Z!,'@<`wOM `__>}}Ig"}z" @,"ݎ3@KEI.dK瞪ktNF|[?O9):ӥp鉩'  P?W@)><4ZGzO' ?=@@vv ݎ3@S i}Kpܷ__=\y^@,sK8?8½2KS^g~ފ +@^AGX"w>  ܳ彅"u60z#@.@`;@hHU@*0lgK?t4g?q^ -/}`{)@4.VD@^ r> Q@?:wQV9CzANoUc /D2 X}>BjTZȽSF̄k UڃE?ܛa䩟s y P?Kq@XG<ƅ'lN{wiB ouC/@^{@R`jRg'=z_}ɂϳ24&@T?H:M~~lD@~&c!^ < {䳃{6/z#@~}Io<GQ  Kaf dnG]z1鉇Kǃg]-2*}O JG_&DL49 O @Od,@k{~Gcŋ=Y^ @.}= r# @@&c! `@'6.=˳j/= ?-Q_. @IǧI+pidkF@@ Oyj2 ܽN?#;gK> ܳyox Z@Y[k2 +УgyHO>ZZ>uJgr^O ~piS?M֧~lD@~&c!^ < Î'tJ43=@@ ?6ia2  +muYN<.MB<*7܃Whot]܏ה&gi=@Six-9Ox,lgl^FAl`~rz  @~@%#! @Xhҳ2_/-x,v\>7. |=+VbD49'O @Od,@k{~Gc_K-9 @ܠI6?7=@@ ?v ϒ@p]`)|nkEҫ/ +ߟZ w恀o{|`~LL4و )@4OMB`'x<`lgl^FAl9H@@ Gv @Q Ld1{/7eyEgtY~ /Z/0])'Ig??9~lD@~&c!^ < tvx<# p&9Y@lD@hms4B@J"cKϭw[Veq=\^=\.˲^d忒6NfYP?M,d#z  <5 Z^X䳃{6/z#@~ܠI?/=@@ ?Via2 1jS\E W_(^^K/Kϙ,۟hGKko f#׵&i=@Six-9Ox,lg{6/z#@~7#%.@S؁0/@h.>Xb|=\^`|xW39@ΖN8HGcO," @Oet@#{lBE ?6QDt@؁(v>@@7#! E -_zF]Czͥ;,EoW6^O @Od,@k{~Gcvp8V gt2Yv j ;EXr't@h& Qzyt| v{_ؽ= KgΈ>'.5/ɒO @Od,@ky~Gcvpϖl%`^#;y  @؁q\ @?H>׋瞒*M>YzRgg9O_E0ؿ؋i.d#z  <5 Z^X3&y HW캛["C0S B@ ;HOܤG iOHoRًtפޗ'dgF@@ Oyj2 ܽN?#;gK>;g7'0|n"@Urd0@pXࣅ ߃g7> gsiwUO&m6>.O @Od,@k{~Gc't@"VhM*;5 "x+m "ဋ;;_&uvr91Lcz2lbNir⨟&@<X ,p:{| { h)/e8'Y0ɰ @cZ)&4Z \;qi[{ϔf9KObݧo _gå1^}=sY`&_z~?CKV+f͙.tߕN~cpRK-~ZM #@WFE<I'd:XsL\tF¯&fuTv nC  EQ!N<,bukI&J)mW "v`Fܓ V'?t=1dOA4އV@~(! 8 { ܳyM" @,8ד@t]> wvJTz.X9(XػҮH;}Jj5 Ʈ"HtbMKq. |INmlgi -@4oQC*m #UCWj ~I. mu xQKIn(rU۫i7S2 vuA`!<( %mtyҭӤk]-ogr)&j1'/F,ty#!I6^ Y 4уi|Њ @Oe<@[{zGsvp`{6/z#@ܠI|#@#Dq* @Q:h35>mQZtoo~90wtLH-ט:;{E49WO @^Od@{{O=c<@f p&Y@`|0Q? vnW;II'",3Ǭ0IMvK_N9G1ʤ2ߒؔQ+d7F@@ /yI2 ܽZaO Y`J5͉ݛ\( @Z[?f E_>)XdّEv[ZtT`Sofx^ qm<xg|l Q?M6 y P?Kq@XG@ @KKNtA `dXb7و %@-3>/Bb ڋv͙"lp'].KQiIR͞~X*@4Yi=@Ki^x/w? )X. PU ڙ]gRI  Ib @[C {ҙ2WOz05;PC~ N4و %@4/IA`@,pOD(L`j |Ů3$@ ?y !=j9& ^Q:\GK,i^V.y׶O3H4و %@4/IA`(8 I(I$C "ҥ(R(DDEA?R J^: p m:{'3g}?s;w  `rݥ旍؁ W@ZK{?@2EGIN.^rĎ='}tyWHC!e]O[R?mnD @~$  = @ vpDU`ur'r> @@ v rbh*p_o(͟g}3n,]xts{87{~؎ic" ,5 ZAO?#1Xf ֵ7TH@؁!8@ @ c5KOY&"IW_iU ـ[8O@,fH F @ -@ _~Aw@ QzCz@x,X7({닞@J.xt|…˧o{~|67 YP?B>@ y  //h;57 YtE/ P 9zc?q}#,K:Z fU\|Jiά|Wgis#Z  ,@ @ N1Q`urܓفȓ$ @:w>DDh ks5hॷLN3;8!#._2o_c;Iҝ;R?m> O@,fH F @ tb{s$Z @@Ԝ_47 YQ'…/g$нtUHV )bs_ŎhO"F@@ Y( `;/@,ponD W`߇yĮH .,م(@w_t;~G5nyNh "w#>FDILP?mnD @~"} 2@@_`R폳 )stF@ .]ɕL@Ǝƍ-J>_3/Bf5דn|Z6Gflѓ)ˊisy͍h @OP@#ox 4`F@\G8>q\ñҘҪkq#  Ho.fv:HZ P;=$yfN<7 ;H*`~97Ɵ~Mi挤q_{>#YY>o$@NF@n~ P?{~(Pb3 ܝ:G+ 7*\yռ`sN@ 0wSһowUGҷN(1,؁( E@yh=kc˨ PDG1 ͛v][q~\is#Z @<h0睬@#TD@A`rԳ.}^T 3;piu?Z?nBҦ_:s `@6FEL Ь>tr|Ȧ\i٢~܈ Xic" P?u 3@kvpzzIgg{ӹiִ @*ys+ΕDRS^YǢ]tҀˊq-Й"ֆ, `ai2XRF`]KY6B'Bh-wͽ67~Zۅ~ZKs  X[@:2#}֗^ƾlhTi""pA )}OI.͘nWO?"H D61  L=ۮEL+y%SJ;ퟶp~|67T P?6 6 @ ,po @ԓ8V D_w#B2ʁx./7 {G9nB:8nT93*+>x /p@`dLRv N{Kj/iu\RN0xtO9 *Oy% кj3&Ab=M@@,`3K8AY!UJfZV`>#SupB7q '0m{11olU/ү.G`fis/͍hꧼH&@4w!T  U^E (I`KءaCE(pү+-XPb ?F:z7鶫-d$DA  Pvp;`TCX~[:XMiTC7j\TM5Y:~ځ/@:0F H4A#8JAB`{Gv j>C^mގ H͓~y@n Qj }!>~qoϞ@@ͥ["Tǒ}O9F@ tꧡ?jA&Ab=M@XK4ͧbY%0|j]q)Iƻ7!D~#Y @xS=yp҇-#ݤ ͛{,B\b5"gis#Z Ӑgܳ~$  =  Cko(uP%% ̰ `iIIG#S4.!rpIsg-(Vv .a@ )ivq܉HM`s -l}6 xL4Mih3Ny P?!K @,poJD@;/Es)e GcA5USH +''];r"G8@XD<~L5?:O;OIQ?D+B~ڌo^O_@ 87$$&AS@l te[/%{la"@ce8vM >E+~|ԻYԐWϪਟ6͍h@hOCqSi%d@@ O}6nt١y҇^D2 Rӥ SvbQ^kipRL+URmiB2G2:_ўya#;[,p=yOQQ?D+B~,cOf,@k{=$d$ 2+іtu'O=(͝u$1/ Ѓ&^%͘A"`o"v 6 ' !6;IBz-~[R? ~ωV.@&2VS?6  C1h/_ `m>%3gHjގ ;M&g|؁ڕ_Tp込}1єyJ O~ϓ N7ohAִ~5@-AiLE P?~Zm@ c @@2~AoBxn<'Z!@B|ͮv^7_Q P?i665fi N!MXޔ  V laYwX!@?.MT@ "$؁z:فڄ3 `@vq1s;_D@Vݠ>7 VӢ~ωV&@Է%Vj 1X& @=(lʾ~]m""W _~Av`@ /NHuMGB{V`{o!@me:5.1b|F4iB4Կ@IDATMo3J>6 P? &Ab=M@XKnW+ò2(k Y37KK |6 ehwpN` '5XXH4Q?oEK|~LO; ӎ|`{L(!A ='yv[kó* VM P{ f0C^40F`ޤI" Yd# @ko60c Q*=[+Ӻ&+4R?G4-ADԇW9P?8?O;z S1h  `v0( Cz)i #$Es֩NLt*\uP3 ;;u X` ,.X!&]!P@g,p@G?K i{@p @`/7ȥƱWx\O9 _O}y9[ӎSC_!1Xf @,pzI>ĿQkG+p[`!M΢@;ua| !@c]i|;*~ߋi|+Z"Q?uUFO;ӎ|`{L(!A x4'yW`3C&bM89 <ɲQN/0D`Ο|'F_2@W*uJx܉@}א6TAX>ihYxOOVDe꧕٣~؍ةv'= )P4C@TƟ/ߖ ;u)\6X. F@AV=;;7D@ 9 o\}zW֓>Oڄ3&@2O}{eۗӎsB_!1Xf @N@nfw|6Ew)6ED, Ig٣}sJgi1qhFALf{&t ƶ,poS*Z*Q?Y|~x&.|vt~у@,p E3@ hN,pzI]w*,͜!~]B#͟^yDDy"ܹc$D@%6q)d3w!`q̙eg\6GE4P?oEK\~x֨.VR?6  C1h/_ `+I K `@ Cnϰ3ǻ1j,S@hKkC,0gFIG"اU꧵T꟣~Z߆+.@t R?]lg P?6~Zm@ c @@rw<@{g#D( 9ғdҕtE$a׭v 6 +q ζן@@R/Gmvivi3ש.3|~q6vlV{R?6  C1h/@z]>Dd"`D`CҌtE'K/E$aVbXm K@P{9 {I߸6P?mS}i gp]igUOũVp!H4A`{/^`]=ӚC7Қp2xX,̲?3`j qU کS'۪O\ W`M OH6O[s~ښpAiY~у~ZIڄ3 @ @   ܃ ]Jc}8tքC  R ѻRvƳ ,v [m[`-/mtƥ@l+;{gdsC57ꧭyVjd'@ڒi g@,pD@@vρ - +, P@ +J$yĮjMR@T=~Li27BH꧍6jzՆOM8`{ $ |ڤ՚@}aGE1e&iB{+;2v *{M8nq&%'>J`{)Xe׸Қּ~H+@P?mO Vp!H4AIū5/Z#k+}f;bq-.ƍr-jE NI2e$jӊ;Ukj FIt;2S'i5Ũ&5"6V~؇VR?6  C1h ̛aR94wn5 Wϱs=K,$51LzY( tv *9!؁M8n}ݡnQ"@GaC:~WJ]A#K4&s.~\is#Z~ZGڄ3 @ @ x(7M*&m͋ `&ubO<.Erқ1"= #ϤYv.[?܇@<v vgj +&uFI|;x2GwQ?M>sOq'y P?mKW~ZHڄ3 @ @ x(&o[5#kei/K̟/~|@;.nŽXlbm<_f}HqQl3c g@ k(g;6Y;w5g>AOR?Mnǝ%@,FH/@ڐi g@,pDPo[TZ5%pqvR4$]{"&Vfi{~6O>m܏@sv 6gj ;NI"})7= Pח{ir_<6W~܈VR?6  C1h LaR9Wt q- mz$SWT KqmPv 9qpE Œ]l'DoC=vp'};?~Rۅ @(vA/& B]Q7/P?ML4!= Ti<9hN:am?\jph"&@\F؍<٤Nadp܅|DkBq2Q?;Fo>r @WWx]]`ڳ5sFE\Dž(@_&{7_ziieڕQ?MK4w#Fi<=hNim?꧵]84`{ .#S'yT)ƀryiur(wާIX%0vt Vde0;+'àiΜ^y".˅(񚿚-BwWVvd[l[vO49~# Wi<)h^imC꧵]84`{ .#>0Rⱨ 3.pqR׮p4po9 ܛ esizG OJIO[2~Okph"&@\FF}aR4a@ gV:(A~+ҥ QRDLP?4EY0k< V3!ZG&?_45" t!ub{,7-zcX'} hRXH'kO~# PiC%/R?]R~Z[im"MX Blzi۝mʽxN2O^DfHn{ķB$ Q94m eYFϋ$֘(}!^`\i7kvE49~# PKi-稟ַJOR?o@ p<o @p~V^8`i-[um[kOOF=P?Ƒ^XR"~؇ P?I W@:,piX&dn܅v ei-͵^xB\xW I϶"m9ۢ"؁Q} +{4#w sC"pd,O'sKs4z~уH+@5Aꧭy:Op#:0FOfPL4Ӛ9C4>A(JtOqn\oI!pw9ɏ1v΁@Q@T__Է /sEc:¶6鏧e+!@!Org8lO6LͩfIg P?m@5/Z~Zߐi} uX^ a&VPZ+Ha@}XI>Fd@^_,=v_^W3/W o_[c#gp_G{{c.]Mj܆P?֕iifܑNi}?m`{N#C_4:(@q?)`@?_҈wI4X{K@Tpq]KW#/|_6$ DOMߍۄ~u- ]fN4[Oz OisNu3H/@!6\A @S7̣>9 r{QoI1M }it7'j7WYeEG|͸mv ?ߩ+ !/p9C:ٶ!.3[VYmmV=OIC Wh$@NkOp%?mַ  PGu`8 a{e{*>nF &y9Rehs8 BG`!F{,/5YQ} n ]v1bbe=!@<.6VrN49~)=/@9~ںwd#@#6\A @S!xXAii--,h0A 8$[ do.u ɒ&)yDx4"wev/ X-е\72 wS7FK_eF-V앩foJ P?M6OqWz꧍ 6* ܗKX`Hi'X@j#}(P`Q?(p@,i"P`$gf6xвon@ 2N65C>-Nz̘*Er4z{Wm|J~ P?M>Oqg:꧍6* ܗKX'W`jo\` $J+*h@F wo 3N ,\ fv!3;iݤ7r&/g\WFe"Wf8@`IK/y&̯MN9L?/".?i"Gtss3n~R?ޔ~|>&OR?mU@` /— +z\ | (H`ofLQ4"S?1:P(X`Ok( /sVO͠?k>C*YnʹR?g*J~P?M>Oqgz꧍ 6* ܗKX=NOjTpS?Ǖ^~|&OR?mnD @ a)x,0s49,0G8 C! ,_4X` W:,r;"I+G5.p*aߑ:wՔFd.0y=B@|k X+е*pIi30 }H! $r`AC[w'@e xNټ-@^FD HBvĸ~vAv+YjҗOt~ܝ^isC͍h`{; >E~JH%3$" *AELHӧ"cB}St8>e@%MJ`l,%g7wSf]A \)Z\`mwnގ P?לinC4!=~Ϗi<'Z!F @ ,pt~( J_6U!y{oI]pWi  f͐4zxf\l лti p ؁(/kG+@&ٳlƮXvn"\x~?uyԥky3rc꧍}^~V]~~֨7OR?D+@/0n=Ό#;f]Γ@2Nҏϱ,&6T:z7iX#jD9a_j\Tlϐݜ"/hⱾlvBl`{و~!OlU !()z*G<׎V% P?i `l&i6Ni@;vy#?wEf'([`4uʎ\G:{n@~3oh.0ؼmav@lMc{H/=մ) @ҏ'~$6Xzi)q-@4~1#/@49~#~ϐi<'Z!F @edXP=c"@A< KA:ۯWO(i{-0cjeq Ozf!lY@oVvn?csE X[4ly:q{I֨@?7o  7`iZq<S?Β PG4@#w^ {oJ_;Dz;RzY3. KG8c C%)ұf&[Iz@ YƦ!X"1kt!eĿ*ȝU燚}qb{XxS?-ƙQ~7,)O[`{O N]?#e |eGC_S<\*gO~/ut &7GzT]u<"&Y|mmshk|tڑR$T xW:)_`ͤmwߞ P?-f(P?֙i\ikvO[5+ozG o$ђ|ViάgX@=BC^4 0pW zFDW_p7"]dSD҂! ZkOk@lvpO6w/4al _[bњeCk)?R?֓ P?m͏ik^F`Xԓ8<$ZbӦH]Sb  ّn۝ !;fUzeb5ε52 Q6cG7 iZ#e CrHo' 5oZ@}tBUI]Aiq@8kF^iO7O[~ښ@ X;$@Wn!|yBv2,ĚA@<_MܹCyT;IWRO7g|Vz53'|CҘr `mĝ8fww&H@@E0zt؎C뇻p]`4xI9G?X5q{~Wv6 P?~6foJGu3@Xܔ0avp ɖa#9 l)<"pS+͛i>AJۮS9T3/t2tXZܧl@`{z3.;Ֆ?z@5I'7zε퉅HZ~ںY;ޢf/N4{SzL/@uCꧭq'জD U8+-n,FBJ}=qoF:z7px\mFo8N12_fit@jv jp}@ Yfq6Gz6gHGF?z@',=+J[?n P?-~oΈƷj%Vh_֕n  ܃rF QK@1Y 9DHٟr. 4@:x;i͸@cO_B b}94TI!IP:,n^K! @c4rK"͓nh Ha ۭTP?Mŗf꧉1GR?ϖ P?MfG4w!@P,pjI@4~ Zf-BA<8Z¾yLF} }c'D;Qb i}h!lxJ[ʍ @a3J91]ՉҷƎȶozCt-Df˛M% 7c'j&E~Z2c~WvO[7b&w~܎;@ 1$@@ϛ݁1-Juҿ.( BAr8r9uNuf_|t٦y=eZ"V`Lw*;M7%Emlg?mQO{u'^"E0XO"{H?# Aҡ^{){3 7O˳}do&s[tE|Dj & '@I_*Es'0<7>##E D}Fc%IgWY _#k/V^o77p#boK^H+liy GrLnǝ PŌ(w73?q H$jv})R튉h~c^&$Ovּh]Ox+woL`{_XҖ{ǿ48B2ˤQ;Cv*JW+}}{iЬ{g^(Y>G~._rf~KoD}]:~M6+Ykn4|E> ,}TB&qs]*NP?͍3~izCz@oXԒ ̛k~)5i䀒<ӎ7p > 9Xh _yVʋcvy1M6ED,txގ_U2v!J] P ܋q^r'xi%5v ,\PyNϷ+69ݽ{3̈́N4PG~ZS?-Κ P?M]Ok@#B@x4y))b)+rAE{P}3 kv=|g?*vlFOT4*Kg_@' ]$p>ȁ(0fQS+6.4{fy[ޗB nEnwσGdwDlB4 ~^#ϩK7\E|D:_ sUs/K?24B2kLˆbv :>x[:~oHћ8Xzi"J;#FsͽOk3|#{ó* oJj3?q `]W“6DW r~D6ַ) "iJXoFK&@4[R "@w^5Xw!1Jטņ  }H]ߚ7Y2$8h&0wYLki-'h֚Y iޤ~^ yG77Ϙ#ň%[ҁ[K'." O`TԾS9跾tS]B4O˙%3j|ⶤ~Wv  lRE+7^n1 V`C̢hkyQe7g+(}4wڙ׎;c#* ">N,]'@ ys>2H:v//KCf3}!\ z*[Iwм-- 7R.w5wO~ZP?-ǝQ[~ښWO(fr&]p]Ww&Mp=?,r?ˁ*0,MXt$]I˯hO\DR~$rqO}Vq2!fOήM D׾LFKo @RQKn+J`=~"OQ#2N癧{%]nސ6Rüq{lqOvKQQ?-ogƷj%Vh P=|I"c~v?{q1 W ZyMRq]yD}]J31*c*",\eq{R_[Y^<#*pYԪYsNwRִC3"1!de)y,yD:h}`6 `q{-0Q?s9/eEE,ʸOgO[ڒibGX^ m  J+d`vZ:Hi֌&YHo(aR_J{W'͙PZ ډ˥/n(g|/ڴt h5[+m;fh=tUeM `QFF\,~y:]NՊst7>Z&%~j\R?wniʍǠ~؇P?.o @6s8-"@*]waǽ; ~=KY`Ua<iull=qtyG+yMZyb7?OOퟣ,"~b6}P?Ƒ^~oީsXO>#oI0xI'%z,/a~x1N-HS@m/1Ё`q2v6;Lsx"`}MgI $'sNЃX0_:rWAkE7E15s `fmt=nxg\|ƉWK{?Ǯ9d)ik,0sަE&LOA)2 켷=K P?]R=?DGR?ߘ~cP?mU =PqP T?F .]%oOЕV,mt f{Q1n7тŸ^Z7)U%2{4!Z`L,͞%1;W]yDk>ϲݪ8&p)9to@|C 9jvu&m 0?bSTG`y 磏ZGcj׮]>9WϬ+d-g\gS6{G;%NZrdOK<#Nc9s^TYs3;VlCN{ |swG3fQҾ@nggnQacg>d?{H&?9bD;G?p+:tP!o\Z+i"͛m"m-2|ʛ:kS{3-Gf%IfFn 4OTޒguh{s/f' @s/ mގn DߗgeJuw;o.}wuI1Iռ=-89h$@ר;7#~^îϩ5ٹ4@IDAT~JkOc<l` @ ~ D?4^7+ ,(&ߨh-& lT|]yt~)scz˕]ۣ]9X$}sz؉>H7rpDO\G|$nj.7ʾI_N{;#@vna'dv #>8{hgv7o6v,(_G],=ry JA_;2ԝC4~{hW>x]ˣk[D-gjxb(o^YS=ǥg]HdvS|4l%b  6=J?=',n`#xPt}i^ц# |vW韏:/@9j!F:]~Z}Q* O[3At! =`+Q +供K KYkq{f!R.5nX?H&ǪcZ zapGg.Kvewтc3-?c}OG1y=$'3ݪvIB;B:,v,<(V )+ zر-@kEnZKWHZ>kqA˙҄q#s:O?>ԺcoyI,zeAMoJGl`.#@s{p"F;Sybng>[n w|e3w*e~ā@qoC9~Zѩƕ*O[ӎB_! =TR*Y _Hw5vehV^KWvkfQ!jC*Z8ǁ@f~TFV^UCn~1lGO,Md,H?FU^ؑn?H8@nߙC>ka1'*ftm]YåzǼf- ̞)t4Oi6/q_eP3XMY7^nvӿDzsp&֟oiOZ뙰"VKmט z7avT>X fhש͆DodI\YDEJˢ7@E {3-vGuF{H7.i͛훧ϗ}qO힟V~ڪXOuӲkK ӎE Q?Wx$w&T,~n-M-vtݳ6ȝZ,v7;0EEy*9ˎ*t9E便KW`fNKs썑ZʓF:8 5g?nI{ݕ7P둻~6_a>p/`y淥AϗKD篷fɢ7fG;\ĥ1#U4,|v`z??f=E-vgf7V4o,[u[QT~}3Mћ}4JS'q>D;!oW>+! DOo8z3'8&=Z.ɛESa=z oWd7~eQ?-`O6}8Ԁie:%T =-/Xĉ@,m5{PVqtQqZ5zIY(ަeP^̛>z;kwE^#p;1i\Yk@ћO>KޙFˁ2>zd>;>H$myF;5b\=zbedߕh F Hir;~j,Tb~j\ yP?C>(U3ÆH?P6ԋtHX,.iO\Ͽ0WyU,vE K_yf^0M3jv?I|C>̧j ?us Њ?(KѶ@Hi ?^?cxڭ]#>M$=ICӉ.L7,=Z3oۘp ViZA7~Zַq S;f@!@e@ Dy)iy<_'e tˍ@XJ$]q ~xt->eD. D@Z|m:f͐ϊV>n?>-8ι) as,֓KO-vQ PӢ\X +!pYf*I"+n~<.nv= 팏sbhݗ/>f#N6xQ¢o 88~x߯ѕ̆#4n+'d)ҿ78s @ lv@LIтhG kgyWiLto׎ysQy7Es%.W^dcS;(4ROi=S?-ޜIMA,$`{"6n ^ + R D #ozFis Iة㵝-ѮBE {\YޭO?/\ȣKcG63@.]8*mvdOK#߷1:bBξL E8%:?׌M"h{3`>_YduiiIsfKS&7X}l'2'xeloqwѮ}QZeM$4:?%@0jj @N pX*@҉!, =h'`_LzgHs|X,?s:i `(8+3BrQ`* /zG.ѣ >\c^fY邛,Fh.pU7oG [`09:3Cv y󬏔H,,p/Z6m ?ϊ~V~@@ڇmwiGi>J4W@S?4MOq/P?g.$H9$JwXБʐ@x qA2"xu Av9oFK(NҥwJBqc2R}ä/mjͭ߆+ %K{Nd@NۯEO+ #O72/^i挈Ʒ*%"w3WDfK?hIj9@+u4tX ^D$oݦ%ꧡ4y"S}sBD)@L}F Sqsp>/=xpi0x pz) I3;pF @lXuM'ͷ!b>-{ b=k>CcG6oC @;%}YkE oy ?*@US?ߘpMk3F|"O(WM@Kx@|"_#u)>AJXw#?OImR ZGֹiZ>#в [&@#v13ԭ؜WDOKgh @5_P?f*Z5@\Ǖ H݋ .mf7w[`ne'wg[`OK7Wwe7g#EM PK I _`̈mi PsewKvC?D@O|P?s^ 0 Ā@,po:H>-I<xct-$Cx.~ҥw_.y nqw_B >gKsfxiޜ85& '@"'u_n. P>~jKsCd-@`| =7);vFKo2-BK.GH ,7װh1!=qq/0,n~IÁXωV @$z7'DOav!P2,pOLǍ ȣsFW'0;5;B?&]i_nd,g1ɞfD@3ԓ<,p6  PKҵKVus!@Ԏy |~ S?uc%ϸ$`{b:n N䂛rF[Ӥg6=CK(];ey9$@k-ǼK_+;o$0b[Zp Bt@|1#ⷥ% *W^-TvIKE'@ԍ9~<%e P?-SH$DlM #wz!I="ilt&.exmA`-4))@*i'gJS''[@E7Ds SWf8pK;Eԝ"R~Z<"X1(qJd@ G IRDCh?K/9@8t5V'/fFAwLr7v"GHf3@ ѓmP WU3C\)$U6oH & AŌ(+W/׌ׄ(*QDTAɒsa I@iM%@%啩Ӧ$Yih&OK{tK'TV 1P$0@ : ~s++K70MMmhzz Si?E+ ܻ¨ C,AV-iXqJ^m#ґ}X}J|o+VoK D/9ѳ> K@{KO/(U8'y¦SOz%`W%|c;藀~I@wRCpWWrZ+0^{k^XqO޼W3xscKyC&~Z$@Y46-p SZ)Ov+ӗtC̟6t`EO{ۇ͟Yj.`(6 (poy Gn /pmՏQ,Z`:<}O hqɞW`f9n&osX_^Q3x{q,^m0:wӺ؂5`{ WROx!p߄j! tS.+wS[*%,Vs>m ~#l[3b{)N @VpoKy GL*P}K>hh"0ӹ0$@`pZ MiߨuDVp6/p(C'6ms7[`w$?CSv _5oNNHqŪ}d꜍Xzsn,SpIhvl GpsH R M` GLV ,l+Ӗ4 Xn'(=-x/I&/eXq|W*.zyإ/VZ~f?zz u6 JSFmO6%` v^uA菀8@w R3 Xe'(=Z)ڭL[/h&۽J< &ocUkKk=|'q㊻їtBӧ&U~|RK' Ps6L~E[<19@̟6`ӅMO@]e9XvN@OVWWcVLH^ ^ J\r_ 6uo弄P'z .p^&ھ vS߻L'$X#@$9}IXوa.L~^wH3 }g 9d%d=O<=Ykf&c0:VAzX4:VAh揱 'qC*ҳ'%@` <''g(^8?y}P7U`w''\7y~5 ^*"`"! 0: bA)=0#X蝀ji~I2mx[OyN {rF@Go#Õ.+b-){i;]#P[msc[ۛ{&OWNs.*&ޝ U6}F ? O[=$otoK\^H-: @{[m߽D@}ްGۋbmꛃ 4]K~yvrHqA4=[-N9.^ V).Vkӗ8a ̞vmAӧ /IߡL`x8 Jc/|?YvƢwM0ڴO̟6qTG9@̟6}P Xi@Y {I!s^:I@{\Ӓ,珠U"1T`5uV]? H D @^J,N֢}ƌgLYn/:eɻH)mTS,:5of|"ME94QiGu9?4UiSGV^ P^+VVE5E^d%ջ~ @q]A]k*9Bjſѻ/9d}qhjYRFf~ }|v5OBZ`X?'0Oӊ?n6J xqAvil&r +%[/XJ,|ԍie}>~mO P6'w* ?LwO{g͟6ytF`OGn P^JMvy_M&XsoXK\o,` 0lW:9c_NOs v:{~4Ym- G`UsTsV] g%O}^t[5oecKmG[O% ?û ? 4YiGWn-PނAb^^]nTs^ czo/K=/wMZ%F'=-9J{\L^O5^jO]3Z' ? A@{u@a"4W/L޸Gs(o$>?}@S6yjrh)Ņ"Ԕ1H{k2} 0hLVXiQ@}Vjy{Yx׫m\񧦷'9d'K.٫K> o|eHiO6駀~j/gYXE@-bY9rOo(0n\r7g!PihQ+g',V%$K(i`9Ջ46)'o߯˚hV^ug6㼕ʫsPJ jfɂ@97P*.Y_=^?텪6*`#;̟~ D@`Oo]P5J N-N^Qw PuNG)>&P];Qdꖁx VYſ;S7}Ь-m}ni&b'>7I/Wcn1,Y3 Fo6+7?+uI9/I~ÓF@3̟6ce;󧽳#O@̟ipqs9J@&ܕmrEC(o 2vxSR+W\x㆞[fJf3ţ|}^mx{?`#)}K=A A˳u7t$'P?[Oި~qw+W|n6vn:?L/-mtEɋ"B@̟a8QrL7̟vSS[/`c$B#P>,Xw'{2e1jk5;U׫X(B-ɶ ~Pw&ݔz?N-\(nﯷxw$G~=9& wɾ&xA3Sʻ9#X ʫ<=q,H`gn{|(}?-o}=J`7홼c*  P%U Jid;Qs?Xˡ)PXu?.0vI`v܏- "u<~uqKt3͌HAY^>n7;J>bO- @`$A~䈢Grc TW`׼Sؾ3Z(0'Ǔo2xm#@[n|ڏmF> 0HOAF0?8ygz<(:}AGGe.Kv@z ?_&?m(64 Xi]i` \ BeH8cVHIQްXd}囓k22Ix|Kofmt/E^ +c|Lv]˞Mw+ldbŽ6]?Z&0V N>W\~X[rHʻ-Q|gz^x_~]fم?*{Q\:%}ţKdx+[:ţ|~{ٳY7ydꔇw*.H+1Ǥ:)V՝[_ /pyqNϝo;uFbq*oo޹0?W9RXX&K/|BE ?]Ϫ(`" ?]У?7h=O$lz"0@u ~wt򃯴{ռՋ€Wa,GK_ ߾_/vl}=EOŊ'ֺޙqX}ߨ)BrϊոmTjJ\= t1ڏڷZIKmlsfw%cu|͝}y)~}^5g 3ܾ;SsHw(.R( ދ9n"6U(S]LݩU.Z W5ں!olO=Wj?OGktv$PS58aLg$G~#Ӊ\l&>q+Zm*@;R<ޑlquO L|LEg?=XRK%[nY}6w%oOMxBr쏓.뺕w*L_[Wn@7=R~[zm)䩝{vڽsj4G/I.{sN&Oyvr9z̘w#3;,VyOdvU%*q DMzd& ?'`kXxEe [6%nQ^L_sAK,a{Q>7.iІ4}Vڶ(ls28 @-~G* ݏigb i,,,Wyh*gcrq:qjk$ϷzY>x}'0GrUU^u[r[,((vTO$_Pg16Y}wѹ+qG&Ƞw.W+gEGyQqu'tVa,hpdeN T﫮lXaknQٶFw)p[ƬnyPv C I"<_dcYrɢ8}E#eC+֗,V"}|([K]<ʹDŽ}t3fW6IO{nx^ygPc =Y5k-}bw!xUd?ϑF#ɫT,>RhK1t0}S-+`t^Z,`Ńߜ͟6g,eBe [6ҭ@ UvVuG^AA7o(,W ,W䶛kyqO.V) O.^~w  p{S~Z<.8'Sd#0Z翼SڝWm+#|3b=s.ty烡b|Z5ɓ:?y="ŸG ykrڱ|tقϲ+־<*. @[ׇ' "qϷljG%;:<G7{^)j[:m @wO{gԖ͟6udE @Ti+&9/Vk~S)h+l @;5{{4/'xs[XfJC8ܭ;.?+P.F-llCFE_" ?L Pa @ 0L{.V%Xey3ŗnx#@IɎJnlQRn@YϿ&3Xqq'86_?9yjJblAc&`#jc$B @1 (p3 @ WE>R~ŅO 媒O/ ٟ^e1E @@ʻ=e2kV{_Y!yܞ"ؽ؃;͹[oQ|g,7vCWuE@̟n4͟^ @P>P~ @ PIEq{Y^/\syqe7W2R&O{dUEA& @4Pk&Rs;GlN>U~\K3mbZq΅eZr1*`7#k7Z%@Z  @IɵWEP{|ӵZq,%k=IvO~Vrciݹ @/0(J~KKH=߽( st{m7%wJ_|=Z`5u>"{c6ŏ9 @@!ݏ @*0cZr덝o/ "rz߄RLQaQNP!syx+WcDA 0|V|Ur5?jG>b%կmy#>}X~,O.VoʶJڏ?13ѕ+-|R/WL( @ @ @m(.꧒w}aꏔ  @ @`9 @ @hNv`rݕKxܸK{Pb @ @(}N'@ @ @*0{Vrϓ|!'oOO|<" @ @ @@U @ @ @@BVxM[fdwH6ظ @ @}PGl] @ @ @553ie$g&/L^U}u6M?Z%@ @ @@Wl@C @ @D`ҽɹg{w1}t:]ydՓUz ^iq= L @ @z(  @ @ @ @ @ x%  @ @ @ @ @ @ k1L$@ @ @ @ @ @@7eH @ @ @"L@IDAT @ @Z(p0  @ @ @ @ @P1! @ @ @ @ @j!$H @ @ @ @ @4_@{X @ @ @ @ @Z  @ @ @ @ @ |c @ @ @ @ @ @ k1L$@ @ @ @ @ @@7eH @ @ @ @ @Z(p0  @ @ @ @ @P1! @ @ @ @ @j!$H @ @ @ @ @4_@{X @ @ @ @ @Z  @ @ @ @ @ |c @ @ @ @ @ @ k1L$@ @ @ @ @ @@7eH @ @ @ @ @Z(p0  @ @ @ @ @P1! @ @ @ @ @j!$H @ @ @ @ @4_@{X @ @ @ @ @Z  @ @ @ @ @ |c @ @ @ @ @ @ k1L$@ @ @ @ @ @@7eH @ @ @ @ @Z(p0  @ @ @ @ @P1! @ @ @ @ @j!$H @ @ @ @ @4_@{X @ @ @ @ @Z  @ @ @ @ @ |c @ @ @ @ @ @ k1L$@ @ @ @ @ @@7eH @ @ @ @ @Z(p0  @ @ @ @ @P1! @ @ @ @ @j!$H @ @ @ @ @4_@{X @ @ @ @ @Z  @ @5gj  @ @ @臀~( @ v|!9mW? @: @ @ k1L$@ @4@_NH @_Tϵ0q) @ @[@{G @h_K>dΜ6+ȝ P//,!Y @ @P^ۡ8 @ @G|=k:|&@Z&_L~-KZ @ @P>H}} @ @*pO̞Vy @-Pq|q @ @q 7"@ @D#vMfͪI$@D{'G% K @ @J ܫ4b!@ @MG'y[2sF2/ @Ň#ՌOT @ @P!  @ @:[+ @ 5s~DG @ PeU @ @"p {wJMmK$@TK·;ՊK4 @ @P޺!0 @ @=9) PX @ wɩih"@ @:X  @ @MiޯKLnz#@TC`}oHtb5 @ @@G @ @b%I L8 @ ww7,1 @ @Y@{GO @ @ dW&mj"@ Vc>%tl @ @*$B! @ @dmk @c($ @ @n (pﶨ @ @'pn[%ս6Dh^6+ȝ @ @ +<8B#@ @(sQ{Q> @c8CζɅK+%@ @ S=8 @ @@W4u[ҜF @Kk]&@ @zh  @ @?.'^ @F#pnq.p4g; @ @@_[g @ @cN׍' @Z#0}ʋ[D  @ @-'z @ @@n>u䆫ۗ  @#k.Y%@ @ 0P9 @ @nS~:I @ zcl|$@ @hfl @ @d-.iO2%@ G늕7Onf8G; @ @@Wj8C @ 0"wE[%_8Lh Wwo)J @ @ ܛ=#@ @4_`dKk~2$@,J+]HnyQG @ @@WzxG @ 0,=M.w @qW]Zf[ @ @%]-[ @ @@s&ݗ_g57G @$pſ;XЧ @ @Z `  @ @)0yR$"! @1u2a|cR @ @@{eO @h>%gyɈ 0E&{lw{&@ @ Pk> @ @,P`d'? P{ N|e2ڧ" @ @s (p[k @ @LoNN2!@瞑< @ @4N@{TB @ @ ̘|-)zx @Z szu'@ @ 0  @ @f&y{rQG @@{<%yɔk s @ @ (poK @ @ f%=9 @z {wJMg&@ @ 0LÄr @ @@fN>W< @8oLOk]&@ @h  @ @3'Ͼ^ @8;'3g+n @ @Q9 @ @eO~՚& l @5'|ɬIY @ @ @ @h49v.k @||}Vc! @ @. (p" @ @j&ofA h/|jdƧ*A @ @ (p_{ @ @v |䫟jWβ%@+pagM̩n"#@ @ C=4 @ @@MwH$Xa @8k߯,1 @ @(pc @ @/M)C @?rrG @ @Q@{uE @ Pq~+VM0 4N̡h\Z"@ @ 0Qs @ @@s~w%g77G @AW?UxDB @ @` <'@ @o~||d֬ '$ @1|1H @ @@7wCQ @ @8(g6/7 @8#28D@ @ @b +6 !@ @$xK2cz  Pk9sϿ?9kNC @ @z%W%@ @hOdf#  @`peqgޓub3 @ @ (p  @ @]듩S* @Z ̞|j2|A @ @藀~I @ @g!gdz!z @f%=9G @ @5P^. @ @ݯM&O`&@j%0kfw$'UK @ @`P %_ @ @z wf׫I3~Q @9#O= @ @  @ @ pߓ=M&N@$@j!0}Z7&WpI @ @* ܫ2 @ @%%oL_EK^`d?} @ @@7l@C @ G/Lv*G; Pi)$>9J)8 @ @UP^Ց @ @@=(r2z+J @wܟ{ׇ  @ @4\@{Xz @ @}d͓oCg @*)pdW'QE @ @. 2R$@ @ Wwoq{=_\pv" @ @ (poـK @ @7_Er5=D @@'cs+` @ @U@{]GN @ @Nuf|"@'0a|ɥwM- @ @hH @ @wRo\}Y$ P w$m\J# @ @MPޔ @ @@)zEՊK4 @U-- @ @ 0y8!@ @ E{*߶J.=jm7wj"s @ @MPԑ @ @@5'cF< @F/p}$@ @ @` C @ @]xo+օ4A Dk:7_7uJ @ @- 2$@ @I^N`; 0rzu @ @#P>". @ @ޯKq* Wk.Ov"㖾v3 @ @mP֑7 @ @`NI!Ƀ_ @8md?Ǒ @ @I@L @ @`Ӧ&)Ӊ8) @@_.(n*ξt @ @: $ @ @oNN z' (KK޹Mr݋:g @ @@@{P5I @ @`X3g$~[ۣu @>\dmЙ. @ @_@" @ @Y&^E,H3^LoAG @ @@Y @ @)0{v=_p?I=D @ @,N@|N @ @s$;M @;-gdzM @ @] @ @(P}ɑ__v @=8ɾ;$SqM @ @ 0R#s< @ @^ |^O~B7$ӧ @ @ @"KU$a @ @ 0HfL;p^Y$L#xO\&Yqdu:ϫllmIt4W$y{(3 @ @5P^A2 @ @@KdڔC_lIҬ+O]rͩɔ #Kc$O>ld\G @`Ernɬb2 @ @7*` @ @'ٸό}@Q~/5-w3T~:dݢF^ S{]'l#?- @ @#P>- @ @N@>k&~}=^EG&lr ݏa\qAVw.XuE-ÓIfnXW>= @ @ C@0B @ 0Fc||,L.=/bS@@;~Qu&nn6?g @ @,V` @ @!p%۪Eqɏ^ڟRwɯޔqpfNF EbŅbGoL @ @}{uC @hܻ;;d%ۮ,Ls_>y`ŽgRm?Z'@|f6>u} @ @Z%`V d  @ @!pO̚وt$Qq{L~p%%y{bvűG@w  @ @,Z@}|J @ @e&3gT3>Q5C`ϷK3|sbrʇaO+R @ @P @ @@]plꚁ,0=WW's#+PՍOd @ @,T@Bi|@ @ @:)yNɴ5VגVOHrՋKDTG+$;: @ @ (p  @ @TPSlLy HR5C3;9CEls}09Ơw @ @$}L|N&@ @ PsNO~m HA]&U7[\'2/0|} @ @ (p* @ @ PMzur sUrOO&3&W?N {ŝ>wrw{ߗ @ @蹀 @ @@.8;cd>vF \vL2(6_U=J kYOB @ @"!)  @ @ \$./ [c}FK(0kfr?i`rR"@ @ ^{ @ @4Y ݶJYʭ]v~[]{ל̸wk ̜|m~QEF @ @I @ @j pEk+!p)cA̜\uw  1=[SӐA @ @  @ @@57oG ޮQ "d-k."@ @ @ ܛ9"@ @ 02O~mr#;xvgܸdF@n1ٵ(n" @ @$}L|N&@ @ )$>9%% AsFt@^EIz |]rɍ; @ @ ]a @ @LwO'5$!iX`F|Nxֵ  WwVn.5 @ @.#(~ @ @>-MvګޖK%OQ^)1XWtoi @ @  @ @ɇޚ}[VϜ 3C2bA׀% ^$&15&*v (vPQJC^v g`9m~k}|{f6]7:,av t7%.!@W\EG @ @TG`T' @ @)=9@r醾AX^)HaڜSyɬj!@~ yӓ%w/v'Ѣ @ @@{Tpo  @ @[`z/ ;y'vm':$wY%pS%V @ @z@@{L! @ @ @O~[Qot3 @ws] @ @ Pu U! @ @ @3&/9%nA7zo炅ɋOJLk~^ @ @ @k?@ @ @6 I(v20M9$/A2kq\T @ @ @n6c%@ @ @@'yr&S:}͚_7ိ{G @ @R"@ @ @@;6yKhe6qY @ @ @@$w] @ @L^d;!Gߔ>\z"@ @ @* :'@ @ @@$?E zƜ)7ywۗ  @ @ @J L\JE$ @ @X8O#-~1ޝ\1_2ӓ_ɜG= TN=a^P= @ @k0IB$@ @^@"[P"[_^ɵ'MK2&OxWAkUGUH}/hb @ @@ $SS @ @#Hd&%dUU?I.?%YtNd͝}":0#~dOOyN#K= ^9v{A;TI @ 0L@0  @ @m&5+C=ͦɪےշ'3gԃ5$%{*w @ @zM`Z x @ @ @"S's\+0 @ @ @j Lvx#@ @ @ @ @ @~/3m @ @ @ @ @O @ @ @ @ @ /e @ @ @ @ @^  @ @ @ @ @E@{̴q @ @ @ @ @ @+>A#@ @ @ @ @ @@Hp6N @ @ @ @ @T\@{'Hx @ @ @ @ @i2P$@ @ @4Xukriɍg'nKVߑ[LHv<0!.e}KS6c' @ @L^@ @ @ @Q3:#Go>6c!/M/ɬ> @ @LZ`L  @ @ؖBnScX9 V lXS*jW'˾vc6_x݂dykl(;2n[H\^P'z @ @@ $`H @DzODzϟ l(䶋7$+{^^dٓژ25KIt+W'=%ۗn-k'_=:Dpгw2}NkV|/,^P= @ @k0IB$@ @^@"[P"[O)~erEe6ޯ[^ FP^IZ2T~$==S?6{5 ={DO @L  @ @V)V}lX\wFre=$dͥb{])S^ݟP}L/8!_݁ɛ.Nv:mb{V}/ @ P 5$! @ @j/ S('ؔ,`2{#wXLzvr+N.7&7Y~d[j~G%/~cn-{u{{AfL @ @ Hpݔ  @ PCl5a!Kda@n/U/RrWڗ!ޯY;$zQIv`ejY^Lʱ_sɾG~=zϼ? @ @j 01  @ @[:~a;<ᯒW_9{9' @ @ > & @ @'9kenyy]_]P*\O-ͲHfl_9ɴكǻ:MɊEɲJFǰam$.|HYrh2gF۵ί>5$W8ٴkaTW&{c$}{7%3K,75&wΝWLzW @ @ @@$ @ @ @N~\ zArK~RgO۹ Jn&߳.. /I%W ^KkwY%y$h2cg_XIəL#H+/E}N$'ze-T1V_R> @ @eT .&@ @ 0’Pken!v}ܙs|rWJB{*D7q0xZƾFeƺiýUW\4Xp~omuoos1l%ݏn),הȧ?F<[gۯouמS ='@ @@@{ &I @ @ HdJd_.8ޓ.IA4yqr>}N9?P*_8/ZoשC @ @,=92"@ @)ՉE$-Mշ%;8Y|ɥӓ&W;%p3ri ='@ @@`Z b" @ @G>޸>'_/K8֑95rq @ @ @2+3!@ @ @@ XZ*WvٔH6mlk[ؘ @ @ Пsލ @ @* ,>*FVݘT4}խIH>v"kv;M- @ @ @$ل. @ @ WЖ^]n/g'o^l"j۾  @ @ I@IDAT `  @ @&V(̪UpK.P:&0[Y @ @޳Sk` @ @N`qY.Vr+ = v@  @ @ڽL @ @[ lX[o 0u` 'usON|PWT:< @ @ @*aH @ @@ߧ?Qlekk$?|ĮuUo Q&h @ @膀 P' @ @ tpmK`ƜmmK|MGnz)J @ @TX@{'Gh @ @Nـ[0ܙZc͛&؀zN`{nHD @ @N Hpﴸ @ @ 0@s7Gu8ٴ:bԁ/tR\_ @ @aM`dͪu=ukYQs|ݮnW7^MhK @ @`dN;qG9x[/J6{CMz @ @&( }p.ƍ-7$_p:}M%}evur4G6vH/;.cN#@ @ e>)U vrtWInaNڝ*@0kRx׆@IkEtغlp݉ |H @ @9Μ5y貀.O@tK?&?+T$7]_o0/_2xMߜ&'{`R϶ @ @@/$ʽ5Npۓ3z\u:c>ƺ磓{ޓި_Ǻl.O-/O3Z7֕.r @ @ ,/(9Íƺrn=kIdol.k#vM2Tbo7gppcs{Kρ]naTE\ څewoJByJ?mquT' 9eJrdF{C[Y @ @?m<ߓo(gΛl c/&ϯkG &uOR{&)UKJ>vW'znIx]rϒiKi, @ @j/O%DP"{㵑>edEy2cc2<ߛH~߻ Z;;VG`T)2YN ͝3~Fx/^[斊D{l#^ @ @,,hnen!vewZuzɣW.J>Q{{#^,iT %9'&g5Mo~D$ZF{껅 @DU lݙ7'?,牄b@2TԙQ}ɒkז)uXrUOn?afӇ,yoe˭mk-_Lv_Tuy'ڭ֛j @WQWޛ~[)+RhwHzo$?%w^18߭<T1;2uVܔo?+U]^7?" js(UxO[rZ|yrgD?lXZ{˟/XF`t*{AgGl @ PuI298zĭo]y3I?m- hUy)_)ՠE Բmy;/ؗ9y#} @ @@"ޟlݟMQ*<Z3KaFI$k.KR|naJQ^{Fy{Wv{A}? @ @@g6b?;%9ph$-u-#dFuk~}% Qa?H4XqsC _tRMxޖS2mf&O*v,|=Ay*-;*ETX|/ 9N @&(4|ϒ}29;IzeBïxkrL)< @ @@,_tBIl/OXwGM^Y І{$vjx>yzy|?"[SxIk~٭(K @ @uyY2}ֵ7ٖNl ͯ?󟪙>wUgor{cU*7ZKyfE~1cnϑ @ @'bY$Gn~QJ^GW@"w~+ +!lX|ɟ42z3I˵TrzE @ @-0< /@Z\q(KEW*!C{uJw'~r2Tp2mV#? @ @@֬N>[.<3-u7'g6Yz^ @ @+0uz2w7snc8B\[b2}֏[\_(N/nt#@ @h@_SxJreAX:?$O?09+E!u|I7Yrۢ5 |Kɳ-~ @ @(;; 8< ''c'ߔGۖH- @ @$0gG+*~% ,~Ir 5 @ @Xzgg'< pՊnDN vjnA_[ض&I/}bH՗W͛OCg%Kz#@ @' $ן63yG/Dw$svH^׹D @ 0q ;Xx̟L WO`_0Y~Yܫ87&^-?TթďHZ @ @TA [~ƻ/yɬG/D00+9՝ɒ;ח @ @&&O$/{rrM ɋ\wE w js c/CUL<h @ @@fV&qJjS:~ + @ @zP`ͪ- AZ ?$/|L*~ vZ? cOnPsխ67?ZwʽMg{q}v}[$}3m77o7C xssv}X'{v'ΰelb=ܯ}Cs>Ǜm7׸~zVM4xИo5|_fO-~ @ ̚߶|'V!}^Ɂ5T'C`=t8.ੋ.#P3όzԁ{38lپ[zoݸG,bͶsgiO|5Ж}e^&o?>Mf lپk~xb~v}cn[ڭoKL| , 7kl_>?45kkz'ohk|W!@},y1瀷}-|iwsw5E/*rIɻ^4~KB`4s  @7؆-L[nMC7 qmisv}~Y[Ï7nP[#?:<48^[UŷYL`7|{d$?[ڹ{Ѝ .C^{m74?lپ# ;d=s]75͖~K;ww2赱v}w0D|#_zE`dƜpkk-vlC'c$)ٰ&6Jb&͛ӶV  @&0totq~I ?:jkfm+p6ot|[*͛ZшB`kMޝ%{$wޞ佯*76޻ @@{?Xm @&'PUp/?ĸy5--f`5\ @ 03.K)_Mc=IнR0ݞ?8ݞ @ @ 0>^Jp_T^; [ݪ 9Wt/= @ @ :KK^KZצ&, }t-N  @ @$0< tFܪ kww=g#QD0w΍eKO @ @V[c\V'~vdkM{KKMGtkK @ @d͞l {> ۸96Nh! - @ @.,$?5]\C܇$:__Jn魯 @ @h@'ٴ&zU>[]kfkm{#䪑O @ @@]ޙ%➋S{L:ݫ @ @ z=R}یE+6f^: @ @$|I'JQM,;9_TuG} @ @ @}ݮު+Q}͓i: @ @/bYg$?}a+ [qY%6vi @ @tX`Z+*$w~?:S $ktH @ @@V./ITɽM#5+}$V_lVE @ @ L[Vv 혢:nG$@ @ @@uY}ʔUUgH-~نKO @ @tGoL9;}A[=kV'96ٸ-k @ @޽xZY 7Oa<{V~^F9N @ @JvLrMJ ճJխj @ @2нo׺emݘ@'ܫyZ; @ @Z-mu+[18'W?E @ @ LֽZ\Fg=2Ӭ8 @ @"%L2ުX4y߫[՚v @ @ P}]ʄ$-e罎ݳsQϘ׹D @ @@ɍt?@{&ߚzSZ @ @/0GV PXz)]ҹ{@ @ @X2y:7w?@{+&'&|-i @ @fsZumM rd[q}vP{o @ @ 眑|?z}R\ݛ&ۊ  @ @ P?^joޔՈc2ohɴߏ @ @ߗ\UÈ$Ov>'ۊ  @ @ P?nVp S%;XL.FuHv}hGS߇ @ @{K6B&I Hp m}2- @ @[fmֶ7N}wad[qp3]{U @ @!poXX+ePa$kVl @ @ @to<-Xו#o"{G2wω\9kdv @ @]mҨn]۟ծ#@ @ @@t1w9zqWzq5g}=7f O|mV  @ @L/_LJޛl8ѫ]G @ @b{+{d5㜏'?jVǨ=&YGJַE @ @)J/gZD&3}w"W @ @#K,x`5Hp5ccT.ٺغD @ @@/I>K#>}Dr  @ @zLܧlAj}j'LNi}Zv흼?$|2er5 @ @'%{$%=ޫO @ @f6$XƧ呶zmK'/^SYÎKZሿߵ&@ @ @֮I>ZdX-xɾ^| @ @@+7gzdd}CUE&yD%|SUI\{уʛJnudmy|ڥ㘽s݂dJ2>OJJ @ @ u.6v$uEi4' @ @ @?6woPߑ?޸ߜ\^?drs%ɡ :1 @ @G`+O㹪ϝgss  @ @ @ވoGi$ ӇV  @ @ @`r'1YS X, }To~vg; @ @/ەɎ5Tɧ|_  @ @ P'S9VNiIn[4ֳG @ @>~k=&_82'|>Y}{=!j @ @W?k#jx$#@ @ @@bdƜg'yuo'brֿ$w9 @ @.pɹi}_Xcrrs @ @ GXLÎ< %~^= @ @O༳˒oѰ~p @ @}* S;t{OHmrgt8M% 9m=J<0A'SJr @ @ qCr֩3_; *bϺ  @ @ @S;P}g[rɭ :^$_m}崙 zoN'㭣 @ @%+}[@yfնp @ @+*7fwK>$֏|C)4s녃/0QA{  @ @ PO3Jeܷlc @ @s>Ipo}J) G$Ww`ח `PK%  @ @P?Z|X HporN q @ @~ Cǣ|9 ͛zK566+ٯ!IdD? @ @@#GYSG</M @ @bۈ䨏'S^oؚް6ޚ|dӇ%?z06Dg @ @ 3~ؕnҩ #t~ @ @.~{&~YrתnKH֋JR4~!/$t2W @ @ _ u]̚=0%fal)}+o @ @ p?]!MEIt~,vT@`'$_^{'?}o & @ @b #RB @ @b kNv}6[_Kr!L.RTF @ @ @q_[wt_ @ @T_ܫޘy$>+y)S?gᵥI&.fU` @ @)p%}Kpiz.x# @ @ @] %ϘUg$ Q˒}2ġw"Yzu# @ @$)me @ @Tp|IOd`Ǽ'$/L @ @=GS hToob @ @#0fds)4_٫^$6$}$MɊ @ @-OV1h4 @F7ftW @ @}${cz.N;%Ƀ^Tݎއe=o\SJ~?+qS  @ @ 0SRLf*Kh> @ @.иޭ. =,y77]<ԁnw<%Hɇ&מ>+K @ @ \y3%7˚ @ @b{lI,84y19ɴYE`ɗ𭥚*$ @ @h WiM{L> @ @l- [GRw;|T2mfRk.'&KJUw  @ @&* f,ܛG @ @HpH=y듗~?ۓ~3y˓Y;-MN`% NW @ @ пܛ{}~? @ @cP},J?gA/\7OEr)ɵ?On(17h nKpd1V\G @ @@ Hpo:ܛ4S @ @-0uzF,k3 ^X7u;,y*쯱- @ @O{335 @ @l޲eKvJ>pmniIveY>~&>;KeKo<mN @ @)JfG#@ @ @!܇(*:s 6Mn8Rݽ$[Q{&ƟKWzX @ @ @h]x}l } @ @ E@n Jx%2oK'ٽ$%/a6&(pW)%;'` @ @h,[' ~$eK3 @ @ [{ݔdC75w[K &//6{m ,6 WLs%@ @ @0z `$7S @ @P> ~;{dGyC^ޗFw ?vC_$?|[rx @ @ @`d Mm$7cL> @ @G)G ;0ik=C %}k ߏ˹N|drqL @ @X$7UތE{3 @ @ fܷw3&6ޗ`~mIvbp.)eוޟdvq  @ @~~kV$7P T#@ @ @}z4}d5Sw/ ˶e|S'; @ @l-+ܙ\W]Jݒ{$;gL*0uFO|oyCry&_fHrG)u  @ @hܛ}@ @ @ @V5~&=>kV#ߛ77S⿞;y'RwGp WIxXK \RQx[7%?z{r\To!@ @ @p 5l+-bA& @ @k,ѓG69rFIbV``>cQrWZ~`JkDkם\N @ @$:E۱X%7>AAl, @ @ @]kZ}E&_|iK+f%~iʟ&o*N=U{jJqmU @ @8,[' ~$eǜ4;b @ @lc{~r-hyMn>%MidOۯMrOQ.e'8" @ @J,|h%¨ZG<  @ @ @!P 矐\sz{/]62<5[/Odjy_W=B @ @ );%ѩjՏt~ @ @[U?j_ZY`ɳ>~G|^\duUD  @ @t[#MdTpI~ @ @S$߾,Y}kyG䘯%sv:x_V%@ @ @J{ܛ*$c? @ @ɺuZ-ճ۽|^{h~Ig&;7ڙ9~w{tGJ @ @z[@WH4 t~ @ @H͒tom?=.!ɫV HKN;c18 @ @P}>ͬ?Q  @ @ @n;Q]+|."ɫJ">OJDqݶE @ @@ F-}[HG @ @8m@IDAT @jV}ퟯ״=]`+~,|دę @ @ wp2ܿ4ޔ垝mu @ @}.PM?_+=O`Zyb닾vkًKuKك  @ @mΎmd=uc @ @ Pu:力:ӏ^'0uF㻮]go.wj] @ @T]aW>ߐMq @ @U[eD ~xv]qoղv  @ @9cr]MhSpQ8 @ @TF gwf6mH:U-3#^d^e9UB  @ @tZOKftOhGN,  @ @ u>C O;PO< G{@ @ @!G#;?yF;q @ @@*7gǾvbYc>4yK&zu[(YYV  @ @% }>*Q9nj, @ @ @@ߣ3ݵ3eyįmKmek"@ @ @{](LMfuc9 @ @UpoXP: hOO:im?aҶw @ @*$p Hp!9c99 @ @#%ۧ3s{g'˔>Zs%iG+ @ @C#.G)}7L @ @ @?V}:3/WwLN/ZV(j @ @@=#.G)}Gj.#@ @ @@Ԭ{7탹!d;5*wwN @ @/{s;wW3G˹ @ @Nw& qnE/>L'J @ @5uϫQ Ux~i2wxp. @ @zW`s*dʔχ{vĮs @ @x뒁iJp7+K @ @Y>-kzh8j @ @;r? #e\~b`&@ @ @@ԭ{cJv}h'fmC[ eӆno @ @:!{]ىq a|U| @g>$<'G&1!GE I` `V(f%HI*(%!̾g:Tx{_mU9~zO"@ @@7 Tl,a[ZCtz3Q @ @(@msmǐ4p2apFC @ @n[oܬ KiV}xpF @ @['[TbS+%4 @ @ @@'fw^S)_ytq;_v @ @Z+O6~F>܅=ɴm @ @@M3lw%]<2\Gc$}$| @ @(/H6߮%8 ]i3Z @ @* SOڱkj7{Z+Z @ @!0fLr1BH90H"K @ @ T=k[܄  @ @O`'k}jӌ4z䠏$ @ @@wpiZ1yd@ܧDgd h4 @ @ L\U$ #]lHO @ @f3䚋ZG t}*#h @ @'ڷ')_]HHktAɯ$ @ @)՜64d.;>T="tnNM @ @IWZ@ X5MfD @ @XPim5szZw]zd嗙 @ @ |dܛy[M @ @T@ 㧶_ٞ\ ]O'# f# @ @(Jv۫U2 ZQOLn/FU8 @ @@'[sm\mvtr-&P./;yE'M @ @@3[1͌ӱ47sWZ=ygQ, @ @h66?|_6{T$mQF6^&@ @ P&LQ*]f/ߘI!@ @ @@ bQx{?j Jzoנ @ @F&%n=F+Ёw;OdCsnfE @ @TtubZgWNvѿNd^4Ӟ׾"@ @ @Z/zMwW UՋu'lu  @ @ @`( əMnmb48~;ʻ^;YzVf @ @V l'2CogL٨ՙ'@ @ @@{Txyת1C$gOgnw${S+3 >l3x,w @ @(*k&_<'7duW9۱&ǝ^ @ @ @@*6 fnp}*pށ}775䰃װH @ @@Hn2c5kWXo%fw @ @A;8Y0+pɩ;&:tsZZc )C%j @ @ @`(c&_zƺCa hp&ܰmUrӆ5  @ @K;wzE|}8[QNJTśSJ @ @JusDG7;dl @ @XG~vxr%=7G$羡ad @ @TKOyE;M{;6~frʅɴ3  @ @ P=qi}ɱ&>U},9mEs{G7|e^mV @ @yg  0݆[$_Q2c酧 @ @ @@J<<{nwٯNW-.*~tѡͨ1[  @ @!0jTrF]VN.&^ZUM @ @ iwrwg%|8yP %OO?Z~R @ @O5dz͙hpo bQ~q% @ @Q-]J~ՊF$t~eɉ[&b1f\ÇW @ @x袵c'%{kδM@{ۨh o&` @ @4EmAkt`_OGkn+y @ @ п1';6m$欜s\]_4~su1ݳϵn</V^wnZ7^F:ZsﯦZs^?_n"GSc[b 4A @*ϖΖ;ߟH<(__ثǵ'-︺$ZTF`8~Mu)>{'kxou^?_~S zc_/i|b5^uj^?_ny|jVeZs4{ύcj^?_~G0NCM\}N_s\cjjz;Wk9/z?:Y+\/@k @T3ۛY~4ұS'%9#YwŎ37juV:g&@joz=ߋ9P\??xk5smL~4#/V^wqxWK^wV=@ύsnqKS7i:kd9>OXݧ5kןs6^@Oο|?.8s;X{߹Zz-]?7ּXߒz=@ύ9y>5 hJ"XjZ;_~ht?8tdrO[|XhR|}ǵ c6\㽍xůz|?{,C`@HVx ^e:HzL>zBR+!ݍj @ )hnq->ro @:g:+Wo!VwZ\%Ibsӏ>P27Xov_f`TRIWhj?.OW,n5mw~.hxs @ @@{.MrKM/>!O`Qg;h1Rʪk'_Ug== 0go&m5E @ @ Tq{o h=.@`]\ս+G;_vR^|]v/ @ @ s.M~e .xٓ'%Y|?8J)`R.K?E{fS])s>c鮜I @ @@ ة nj_+? $9ev)&ovu_2'v~֏-v}r/صd#k8}%Ѐ|~.\PeR$ @ 0 XR <CXas 6 [n_lS7%?pW)K%x7'GWb5 @ @Ws*TGU>c}}N;P|G~mhoԙRohno4 @ P&ZO[?lU}{,Suji@G%g:#>B|r̷s(vs?nmoSL>xLRK @ @ Tq{o,j{뫭='rSh´bccBQ~_<@◃s]Eo}"W[AN&;; @ @-&CѯWl:|IiXfN㒝ipbb7^ŵ/dt @ @J(P܇4^_P-~A3z]  @ @XKtoOMNLٺ"7]G%껹d2 t+5 @ @@%wp^o T!Z* @ @)Mk=|FhG,BrܹɧN^U^E[?\dE.zqrؗ<ɾ%'<' @ @TSb ܚ{Ԫ.{'/>mZ @ @(Qg%g.n&iK/|+OZ,޳e3v8/@KoM՟%_~kRT$]=ɤO  @ @\_inŗD`wg&Ǖ e @ @T`͓ONIv-M% j~xɫޒ^ *sT lGR{䴣s̽\$xS&f,^W  @ @hYwcQŞA{lQA @ {>9%%_843'MI^Kf-jo[[k|OoHd5JWbe Sn{%\Qy.  @ @/`{*FޜF`\ /?Gs{ktE%@ @TKYKnݓQU]e;Zk8Ě5+n_jzڷ'?{r췓wiud˭1?.9}cՑ @ @ *~ڋk7>Y~敭ˬion\ @ @+P|s/xd՝O+o[]k}WGOhpe`ߩxCE$LVh'NJv~Ar&d^ @ @@hp_Z?|o2{d_'9bJyqPƵKY @ @J ɻ>\r}S,AQ.aRɫ'9{^>jAq oQ]+psJ~P<.y2~NueՎKvyasI: @ @ 9U;-J9J:rk;S!$ZN/vnױVį,vp^|k=XG&;A=dΪV炪\_~. @#p3)vw/6ҽr1c-Ox?nW%&wGO hpohv/=.IĠ.eUw-7VRA @ O@#2J#[YV|uZ~]gzmFC ھzWٶܟ-;\NxJbEmJ'djesA^? @ @@{}$UŅo'e6n|s^׫9svU[4;/]ѷ՝{HˮlRbz,r @ @4C5`JZB']4O1xGKo?==9k7GP<;!0VoOF-GMZ ~. @:'PwyAٽx\ҩ'%WR;U%^*uyMc5_Zx /{A @4Y@#[AN#[+SWg ~=!y#fO͹ojA,&VZ_I~[sK-.QJiy* ?T^? @ @@y~Ew56!cLĺ'mn#js/$?X3ۈ?);~%ٙ @ @@FQAU]kx[m=̾b+Z\edX75vpvzEN>hh^/ @ @@W kj_+J=ء5Z|bqC|zmŮG:V*y}PK~W'%:'0eCM^-6UqtFqoVV?4KR @ 0<;o{ٽ^{ޢ)bGGIfZfmkM59$c flT RS0R* @ @6 g7moa~b=N';6y6vi7N}wˊTKWٴ @ @!0svR{l} dn~}}ϵCsEof}דv hpHO @ @ ,Xҋ]zX_?kᏭ\'S4,f^}dw%kk37_ @ @^7>=es /  @ @ Q:~0kyUsM(v߶hr=E~J'ݜe:_]<^Xfg> @ @z ]&H @ @ {Ev0ڮ5,f tY 嬴MR{~Dr9dƻzb _>gޛ @ @ @[.0 @ @7nMfbH.,vBo3h]{wS󓫋G}[==Y}d=G)Suj!@ @ @a hp&a @ @y}oÒ~՜{I6~]c5 gȾFԾNɔbv @ @t[R"@ @ @@:{mI82vުc%U[=vP`{K/{Ϣ}tR+$ڗ-mmkw|'@ @ @RxA @ @ީ&^`m}7AOw7=7N{ߣ衻F?˓K]0-Y}>s'kM퓖n}~ @ @ @K,"@ @ @@:{{e />#9g/߬}՜c̸d7iNVE0=YuǓs̽ht }7'ߟԹ @ @@-@ @ @]/ Ւ=OLKk/Nn]m>I3͋'+mCcqS~M @ @K@{!@ @ @@7 ԛ;1'LOgI|I @ @G`t{B @ @]%-3 @ @ R - @ @]*'RT"@ @ @4 @ @ @ zLK(;0?-tdWt  @ @ @ hpo; @ @4M`̦jJ-ޜ,aSBu,?K0/Kʶ  @ @hVɊK @ @@f0udǏ ro$ok3.ოC @ @ @@4\B @ @&0h*l ;؉˿L1x/o&Ydkv @ @ @mvr  @ @hrOoj!5*yɊ[ yhi]Gvq:T@ @ @tD@{G%%@ @ P1c_uƝ>0?.FycyP2uND @ @TJ@{K @ @(0fl򹯶10S06i NIb5'1bRMl @ @ ܻ}͏ @ @pƍOF{v&_}d̲9cVrze'6'^;g'>cw%f ~w PMi8 @ @ 0`&@ @ г'$Gj)]kɹoHN)ֲsoO?(9e/_[jN̢6/pEɌfH @ @4  @ @]*0qRrwg?Z\$\Qr{n*$39b7G% z%ɏ\3,&^.l7 @ @1̱ @ @:w:+0iJr.;vdtnUn֌3>'oM%E\vRKs7}}gQǕɾ'_vsoͻ_-V} O @( @ @ yYp-IDAT8e%[<TO>]Qx]숿ۓUwHFim-1w}Z%6#TMڿ5rC*z5ڛ9 @ @M-  @ @4{x~VsI=pkrĪ#ne=&֫;d]EsHGHn(viO\\]MGK: Cr+ @ @p4G @ @ hpW9hn Yovel}%G̽d;6_\=8F =7_[4_wu̩gW՜ @ @R-b @ @I`eӊnjnM*wdɋN+{z؆FWJNIƺ8;s"@ @ @`~{0H( @ @e5aLil_6ENH^d*%*J)F`?q)I! @ @W@{{e#@ @ Yg\JR2nrge1ɋLVל!@@]`r}Mn\? @ @Cm @ @=.j}ORϳj3|ɺ/Z%@3g'^ly'I @ @@4w_j @ @mXe$+޶Ow <.맒MA LraіN @ @*/Kh @ @ :}+.LVߩ 'V)m YK@)H|A6(G @ @^@{e @ @ 9/,bjdQc+YyNV۹d{ i?Hadq&@ @ @+L$@ @ 0 u6JNq2{a !J^u~3hRʨݏHvBU"<59ŧA\RH @ @4h @ @`d2嬯U/v}Uhw7hDn͚LY& @ @B@{)A @ @(і)?Jjb.5azυ{tdJm){*ќM,IOMd h g'͉#@ @ @ۡ, @ @vlCrԢ۱m]?آI1rQg9ymsFO,I`䈯'{lIwN @ @@F-(լ\ @ @ S4:Z+.1N&Mnmn~1nY3s''>}9e"@@]`޼ݯI=~sW& @ {;  @ @ZH>;0y59G'?yneU۵}b]>" @`'/9pH4DX @ @Ahp[ @ @F(}#Q4_M. J-7u{Od^~'PJMP( ]&C @(2 @ @&5+^羚ךޒyM %%hp4  @ @@y4wmTF @ #[ߕ#atk_?MnMur_ Zs8MNV:Yud퓕)vS?;>O{{e!@ @^|S'@ @M@}x#;#]Eok ZFI,~Ծ]_S [إ e8G, iIhp_ @ @#>B@  @ @!}H֏&o> NURk:{g``׏+^?tϒ/+'3VOf*=U4(&@_RlKxp _@ @ @/kB @ @@4} dw }] 0hz⹶{^{.) @Cgod~c܇nf @ @n7 @ @ z}!#CI3%PY_[иݯIͫTO @ @4w㪚 @ @@5FJ>]UM"竒EGR:  @ @ϱe6I @ @ .ު KP $@e_ktI @ @ hp @ @@ƌIr> @j 賓Uj  @ @t.^\S#@ @ɧOO^oU"Bd.) @ @ꭙ  @ @E`_Kw< @@5-9ɤլ_ @ @H@{- @ @TH`o&UJX`띓Lœ45 @ @^5R! @ @@ LdẇT[`LVy @ @@4WxN @ PAIMߣ+$_ 6&k @ @'|k" @ @n<596t ͋tF[&(>;c @ @*$BT @ @ Lt~  @@ lYrE=4iS%@ @ y _ @ @tɗ/H6۶gj~ @89k^fC @ @K8J#@ @鳒S~leL @@ A_+M @ @@4\F @ @^Lwqf2c$@)ƺ?Iܝ3+ @ @%^P  @ @@ ^ou6I aUkr_qF0u @ @zc @ @zM`3]^Zfn @VZ}5{fG @ @;/5 @ @@ J_jOə M@ @ @[+8 @ @@O vu=Į=&K=(P5ɛ2 @ @ hpo @ @"}++36O ONq @ @h& G @ ЃkdzpLzX`e&7aS'@ @ \  @ @ް}96s%@j3Nd-x @ @  M@ @ @Gۤo @wLN0d50s @ @M$Ha @ @zLK%3gMW`?LxV$@ @ @`p. @ @OvgZۭA LY*9;x&@ @ @`܇v @ @Z۝K dISl듯 @ @Ahp[ @ @<&N}vgu @8)9d  @ @@@0N @ @XD`$7 @,I`$;`IwN @ @@ /  @ @+&~' @ V`o$5#@ @ {[ @ @bvyarImV @`c%Zܽ: @ @zR@{O.I @ @ J`Z}AɧOO^p#G @ @g4R( @ @|U3ZC 0R1cÿdF2 @ @@W hp59 @ @a SE# ,ůR75+8 @ @N@{-  @ @H` @f |d߃Y< @ @]!t]&A @ }k859 @x~2 @ @*)˦h @ @ #M@]N\t @ @@o hpu7k @ @Fޛ3g&@GK䒅 @ @@4W`H @ B`򎏷0 @%a?,e @ @;S5S @ @O5vow @:-PdSt% @ @言;/9 @ @@×W`C%'  @ @^Yi$@ @5*9!@O`߃~fq @ @A =L @YZ؇}Y'@* þ   @ @,]& G @ PRZNJ>* OpK @ @/  @ @ja:5u, @x>ɧO/Vf @ @N @ PrZCgL|U U @|kq\t @ @@ hp55# @ @ɑHxYg @@v+9Ig @ @. lz @ @?!9d, @]$/LE2 @ @OTg @ @.0qRrwg?3Q? @ g: @ @]*Kִ @ @=+0iJrӳ&NtSA @ @ 4wᢚ @ @g,x^{  @sIg @ @.e j: @ @Xjzr-ճ&NSA @ @4wb  @ @gLN0do^_83Z"etKj򖥄Qэ.t })"!iEHDPD/k,NΈsΜZq={a3[c'@*H>( 9 @ @" ^ A @V``ĉo@ @@3 Tu @ @K^ @ @ ,Yq\Ėj\ @Q;DA @ @ s| @ @@KGq{'@lr?18 @FFcD @ @ po@C @VG~z^'@tM m(L okKZ @ @Tܧ @ @/~{̮ @icᗿFv9 @ @X@< @ @zLj9S @t] m0L |K[ @ @@'N* @ @tG#?НB 0V`܈?Ek @ @貀{-G @ #F|t*bv? @^ d+> @ @@> @ @'Oxx+>'[ @@xp) @ @pU @ @. F( @ @r˝ @ @8F+4 @L.Bo @ @4 :YC @ @ @@Uk~XxD @h@Q  @ @ @ x$ @ @& @ @ @ @ @d*0+ӺM @ @ @ @ @ 6P @ @ @ @ @ @ W\'n @ @ @ @ @& ^@C @ @ @ @ @\s  @ @ @ @ @ P{a @ @ @ @ @rpur&@ @ @ @ @ @@a T; @ @ @ @ @U@=ɩ @ @ @ @ @ 6P @ @ @ @ @ @ W\'n @ @ @ @ @& ^@C @ @ @ @ @\s  @ @ @ @ @ P{a @ @ @ @ @rpur&@ @ @ @ @ @@a T; @ @ @ @ @U@=ɩ @ @ @ @ @ 6P @ @ @ @ @ @ W\'n @ @ @ @ @& ^@C @ @ @ @ @\s  @ @ @ @ @ P{a @ @ @ @ @rpur&@ @ @ @ @ @@a T; @ @ @ @ @U@=ɩ @ @ @ @ @ 6P @ @ @ @ @ @ W\'n @ @ @ @ @& ^@C @ @ @ @ @\s  @ @ @ @ @ P{a @ @ @ @ @rpur&@ @ @ @ @ @@a T; @ @ @ @ @U@=ɩ @ @ @ @ @ THIENDB`terser-4.1.2/main.js000066400000000000000000000052771351061312300143120ustar00rootroot00000000000000// API import "./lib/transform.js"; export { minify } from "./lib/minify.js"; // CLI export { AST_Accessor, AST_Array, AST_Arrow, AST_Assign, AST_Atom, AST_Await, AST_Binary, AST_Block, AST_BlockStatement, AST_Boolean, AST_Break, AST_Call, AST_Case, AST_Catch, AST_Class, AST_ClassExpression, AST_ConciseMethod, AST_Conditional, AST_Const, AST_Constant, AST_Continue, AST_Debugger, AST_Default, AST_DefaultAssign, AST_DefClass, AST_Definitions, AST_Defun, AST_Destructuring, AST_Directive, AST_Do, AST_Dot, AST_DWLoop, AST_EmptyStatement, AST_Exit, AST_Expansion, AST_Export, AST_False, AST_Finally, AST_For, AST_ForIn, AST_ForOf, AST_Function, AST_Hole, AST_If, AST_Import, AST_Infinity, AST_IterationStatement, AST_Jump, AST_Label, AST_LabeledStatement, AST_LabelRef, AST_Lambda, AST_Let, AST_LoopControl, AST_NameMapping, AST_NaN, AST_New, AST_NewTarget, AST_Node, AST_Null, AST_Number, AST_Object, AST_ObjectGetter, AST_ObjectKeyVal, AST_ObjectProperty, AST_ObjectSetter, AST_PrefixedTemplateString, AST_PropAccess, AST_RegExp, AST_Return, AST_Scope, AST_Sequence, AST_SimpleStatement, AST_Statement, AST_StatementWithBody, AST_String, AST_Sub, AST_Super, AST_Switch, AST_SwitchBranch, AST_Symbol, AST_SymbolBlockDeclaration, AST_SymbolCatch, AST_SymbolClass, AST_SymbolConst, AST_SymbolDeclaration, AST_SymbolDefClass, AST_SymbolDefun, AST_SymbolExport, AST_SymbolExportForeign, AST_SymbolFunarg, AST_SymbolImport, AST_SymbolImportForeign, AST_SymbolLambda, AST_SymbolLet, AST_SymbolMethod, AST_SymbolRef, AST_SymbolVar, AST_TemplateSegment, AST_TemplateString, AST_This, AST_Throw, AST_Token, AST_Toplevel, AST_True, AST_Try, AST_Unary, AST_UnaryPostfix, AST_UnaryPrefix, AST_Undefined, AST_Var, AST_VarDef, AST_While, AST_With, AST_Yield, TreeTransformer, TreeWalker, } from "./lib/ast.js"; export { defaults, push_uniq, string_template, } from "./lib/utils/index.js"; export { base54 } from "./lib/scope.js"; export { Compressor } from "./lib/compress/index.js"; export { to_ascii } from "./lib/minify.js"; export { OutputStream } from "./lib/output.js"; export { parse } from "./lib/parse.js"; export { mangle_properties, reserve_quoted_keys, } from "./lib/propmangle.js"; export { default_options } from "./tools/node"; import "./lib/mozilla-ast.js"; terser-4.1.2/main.tests.js000066400000000000000000000003121351061312300154340ustar00rootroot00000000000000// Core export * from "./main"; // TESTS export * from "./lib/ast.js"; export { map_from_object, } from "./lib/utils/index.js"; export { JS_Parse_Error, tokenizer, } from "./lib/parse.js"; terser-4.1.2/package-lock.json000066400000000000000000002350761351061312300162460ustar00rootroot00000000000000{ "name": "terser", "version": "4.1.2", "lockfileVersion": 1, "requires": true, "dependencies": { "@babel/code-frame": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz", "integrity": "sha512-OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA==", "dev": true, "requires": { "@babel/highlight": "^7.0.0" } }, "@babel/generator": { "version": "7.0.0-beta.44", "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.0.0-beta.44.tgz", "integrity": "sha512-5xVb7hlhjGcdkKpMXgicAVgx8syK5VJz193k0i/0sLP6DzE6lRrU1K3B/rFefgdo9LPGMAOOOAWW4jycj07ShQ==", "dev": true, "requires": { "@babel/types": "7.0.0-beta.44", "jsesc": "^2.5.1", "lodash": "^4.2.0", "source-map": "^0.5.0", "trim-right": "^1.0.1" }, "dependencies": { "source-map": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", "dev": true } } }, "@babel/helper-function-name": { "version": "7.0.0-beta.44", "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.0.0-beta.44.tgz", "integrity": "sha512-MHRG2qZMKMFaBavX0LWpfZ2e+hLloT++N7rfM3DYOMUOGCD8cVjqZpwiL8a0bOX3IYcQev1ruciT0gdFFRTxzg==", "dev": true, "requires": { "@babel/helper-get-function-arity": "7.0.0-beta.44", "@babel/template": "7.0.0-beta.44", "@babel/types": "7.0.0-beta.44" } }, "@babel/helper-get-function-arity": { "version": "7.0.0-beta.44", "resolved": "https://registry.npmjs.org/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0-beta.44.tgz", "integrity": "sha512-w0YjWVwrM2HwP6/H3sEgrSQdkCaxppqFeJtAnB23pRiJB5E/O9Yp7JAAeWBl+gGEgmBFinnTyOv2RN7rcSmMiw==", "dev": true, "requires": { "@babel/types": "7.0.0-beta.44" } }, "@babel/helper-split-export-declaration": { "version": "7.0.0-beta.44", "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0-beta.44.tgz", "integrity": "sha512-aQ7QowtkgKKzPGf0j6u77kBMdUFVBKNHw2p/3HX/POt5/oz8ec5cs0GwlgM8Hz7ui5EwJnzyfRmkNF1Nx1N7aA==", "dev": true, "requires": { "@babel/types": "7.0.0-beta.44" } }, "@babel/highlight": { "version": "7.5.0", "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.5.0.tgz", "integrity": "sha512-7dV4eu9gBxoM0dAnj/BCFDW9LFU0zvTrkq0ugM7pnHEgguOEeOz1so2ZghEdzviYzQEED0r4EAgpsBChKy1TRQ==", "dev": true, "requires": { "chalk": "^2.0.0", "esutils": "^2.0.2", "js-tokens": "^4.0.0" }, "dependencies": { "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", "dev": true } } }, "@babel/template": { "version": "7.0.0-beta.44", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.0.0-beta.44.tgz", "integrity": "sha512-w750Sloq0UNifLx1rUqwfbnC6uSUk0mfwwgGRfdLiaUzfAOiH0tHJE6ILQIUi3KYkjiCDTskoIsnfqZvWLBDng==", "dev": true, "requires": { "@babel/code-frame": "7.0.0-beta.44", "@babel/types": "7.0.0-beta.44", "babylon": "7.0.0-beta.44", "lodash": "^4.2.0" }, "dependencies": { "@babel/code-frame": { "version": "7.0.0-beta.44", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0-beta.44.tgz", "integrity": "sha512-cuAuTTIQ9RqcFRJ/Y8PvTh+paepNcaGxwQwjIDRWPXmzzyAeCO4KqS9ikMvq0MCbRk6GlYKwfzStrcP3/jSL8g==", "dev": true, "requires": { "@babel/highlight": "7.0.0-beta.44" } }, "@babel/highlight": { "version": "7.0.0-beta.44", "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.0.0-beta.44.tgz", "integrity": "sha512-Il19yJvy7vMFm8AVAh6OZzaFoAd0hbkeMZiX3P5HGD+z7dyI7RzndHB0dg6Urh/VAFfHtpOIzDUSxmY6coyZWQ==", "dev": true, "requires": { "chalk": "^2.0.0", "esutils": "^2.0.2", "js-tokens": "^3.0.0" } } } }, "@babel/traverse": { "version": "7.0.0-beta.44", "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.0.0-beta.44.tgz", "integrity": "sha512-UHuDz8ukQkJCDASKHf+oDt3FVUzFd+QYfuBIsiNu/4+/ix6pP/C+uQZJ6K1oEfbCMv/IKWbgDEh7fcsnIE5AtA==", "dev": true, "requires": { "@babel/code-frame": "7.0.0-beta.44", "@babel/generator": "7.0.0-beta.44", "@babel/helper-function-name": "7.0.0-beta.44", "@babel/helper-split-export-declaration": "7.0.0-beta.44", "@babel/types": "7.0.0-beta.44", "babylon": "7.0.0-beta.44", "debug": "^3.1.0", "globals": "^11.1.0", "invariant": "^2.2.0", "lodash": "^4.2.0" }, "dependencies": { "@babel/code-frame": { "version": "7.0.0-beta.44", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0-beta.44.tgz", "integrity": "sha512-cuAuTTIQ9RqcFRJ/Y8PvTh+paepNcaGxwQwjIDRWPXmzzyAeCO4KqS9ikMvq0MCbRk6GlYKwfzStrcP3/jSL8g==", "dev": true, "requires": { "@babel/highlight": "7.0.0-beta.44" } }, "@babel/highlight": { "version": "7.0.0-beta.44", "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.0.0-beta.44.tgz", "integrity": "sha512-Il19yJvy7vMFm8AVAh6OZzaFoAd0hbkeMZiX3P5HGD+z7dyI7RzndHB0dg6Urh/VAFfHtpOIzDUSxmY6coyZWQ==", "dev": true, "requires": { "chalk": "^2.0.0", "esutils": "^2.0.2", "js-tokens": "^3.0.0" } } } }, "@babel/types": { "version": "7.0.0-beta.44", "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.0.0-beta.44.tgz", "integrity": "sha512-5eTV4WRmqbaFM3v9gHAIljEQJU4Ssc6fxL61JN+Oe2ga/BwyjzjamwkCVVAQjHGuAX8i0BWo42dshL8eO5KfLQ==", "dev": true, "requires": { "esutils": "^2.0.2", "lodash": "^4.2.0", "to-fast-properties": "^2.0.0" } }, "@types/estree": { "version": "0.0.39", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", "dev": true }, "@types/murmurhash": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/@types/murmurhash/-/murmurhash-0.0.1.tgz", "integrity": "sha512-jiYuTCJ60WxEDOkJFs2192G/nH0PY8mtyHeZkv5fOQQ5DkSkmEgY7YLzCxyM8Y8jibd8Dprb9bGth4EO34mAjw==", "dev": true }, "@types/node": { "version": "10.14.12", "resolved": "https://registry.npmjs.org/@types/node/-/node-10.14.12.tgz", "integrity": "sha512-QcAKpaO6nhHLlxWBvpc4WeLrTvPqlHOvaj0s5GriKkA1zq+bsFBPpfYCvQhLqLgYlIko8A9YrPdaMHCo5mBcpg==", "dev": true }, "acorn": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.2.0.tgz", "integrity": "sha512-8oe72N3WPMjA+2zVG71Ia0nXZ8DpQH+QyyHO+p06jT8eg8FGG3FbcUIi8KziHlAfheJQZeoqbvq1mQSQHXKYLw==", "dev": true }, "acorn-jsx": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-3.0.1.tgz", "integrity": "sha1-r9+UiPsezvyDSPb7IvRk4ypYs2s=", "dev": true, "requires": { "acorn": "^3.0.4" }, "dependencies": { "acorn": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-3.3.0.tgz", "integrity": "sha1-ReN/s56No/JbruP/U2niu18iAXo=", "dev": true } } }, "ajv": { "version": "5.5.2", "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", "integrity": "sha1-c7Xuyj+rZT49P5Qis0GtQiBdyWU=", "dev": true, "requires": { "co": "^4.6.0", "fast-deep-equal": "^1.0.0", "fast-json-stable-stringify": "^2.0.0", "json-schema-traverse": "^0.3.0" } }, "ajv-keywords": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-2.1.1.tgz", "integrity": "sha1-YXmX/F9gV2iUxDX5QNgZ4TW4B2I=", "dev": true }, "ansi-escapes": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.2.0.tgz", "integrity": "sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ==", "dev": true }, "ansi-regex": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", "dev": true }, "ansi-styles": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", "dev": true }, "argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", "dev": true, "requires": { "sprintf-js": "~1.0.2" } }, "babel-code-frame": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", "integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=", "dev": true, "requires": { "chalk": "^1.1.3", "esutils": "^2.0.2", "js-tokens": "^3.0.2" }, "dependencies": { "chalk": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", "dev": true, "requires": { "ansi-styles": "^2.2.1", "escape-string-regexp": "^1.0.2", "has-ansi": "^2.0.0", "strip-ansi": "^3.0.0", "supports-color": "^2.0.0" } }, "strip-ansi": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "dev": true, "requires": { "ansi-regex": "^2.0.0" } } } }, "babel-eslint": { "version": "8.2.6", "resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-8.2.6.tgz", "integrity": "sha512-aCdHjhzcILdP8c9lej7hvXKvQieyRt20SF102SIGyY4cUIiw6UaAtK4j2o3dXX74jEmy0TJ0CEhv4fTIM3SzcA==", "dev": true, "requires": { "@babel/code-frame": "7.0.0-beta.44", "@babel/traverse": "7.0.0-beta.44", "@babel/types": "7.0.0-beta.44", "babylon": "7.0.0-beta.44", "eslint-scope": "3.7.1", "eslint-visitor-keys": "^1.0.0" }, "dependencies": { "@babel/code-frame": { "version": "7.0.0-beta.44", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0-beta.44.tgz", "integrity": "sha512-cuAuTTIQ9RqcFRJ/Y8PvTh+paepNcaGxwQwjIDRWPXmzzyAeCO4KqS9ikMvq0MCbRk6GlYKwfzStrcP3/jSL8g==", "dev": true, "requires": { "@babel/highlight": "7.0.0-beta.44" } }, "@babel/highlight": { "version": "7.0.0-beta.44", "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.0.0-beta.44.tgz", "integrity": "sha512-Il19yJvy7vMFm8AVAh6OZzaFoAd0hbkeMZiX3P5HGD+z7dyI7RzndHB0dg6Urh/VAFfHtpOIzDUSxmY6coyZWQ==", "dev": true, "requires": { "chalk": "^2.0.0", "esutils": "^2.0.2", "js-tokens": "^3.0.0" } }, "eslint-scope": { "version": "3.7.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.1.tgz", "integrity": "sha1-PWPD7f2gLgbgGkUq2IyqzHzctug=", "dev": true, "requires": { "esrecurse": "^4.1.0", "estraverse": "^4.1.1" } } } }, "babel-polyfill": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.26.0.tgz", "integrity": "sha1-N5k3q8Z9eJWXCtxiHyhM2WbPIVM=", "dev": true, "requires": { "babel-runtime": "^6.26.0", "core-js": "^2.5.0", "regenerator-runtime": "^0.10.5" } }, "babel-runtime": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=", "dev": true, "requires": { "core-js": "^2.4.0", "regenerator-runtime": "^0.11.0" }, "dependencies": { "regenerator-runtime": { "version": "0.11.1", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz", "integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==", "dev": true } } }, "babylon": { "version": "7.0.0-beta.44", "resolved": "https://registry.npmjs.org/babylon/-/babylon-7.0.0-beta.44.tgz", "integrity": "sha512-5Hlm13BJVAioCHpImtFqNOF2H3ieTOHd0fmFGMxOJ9jgeFqeAwsv3u5P5cR7CSeFrkgHsT19DgFJkHV0/Mcd8g==", "dev": true }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "dev": true }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" } }, "browser-stdout": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", "dev": true }, "buffer-from": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==" }, "caller-path": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/caller-path/-/caller-path-0.1.0.tgz", "integrity": "sha1-lAhe9jWB7NPaqSREqP6U6CV3dR8=", "dev": true, "requires": { "callsites": "^0.2.0" } }, "callsites": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-0.2.0.tgz", "integrity": "sha1-r6uWJikQp/M8GaV3WCXGnzTjUMo=", "dev": true }, "camelcase": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", "dev": true }, "chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", "dev": true, "requires": { "ansi-styles": "^3.2.1", "escape-string-regexp": "^1.0.5", "supports-color": "^5.3.0" }, "dependencies": { "ansi-styles": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", "dev": true, "requires": { "color-convert": "^1.9.0" } }, "supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", "dev": true, "requires": { "has-flag": "^3.0.0" } } } }, "chardet": { "version": "0.4.2", "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.4.2.tgz", "integrity": "sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I=", "dev": true }, "circular-json": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.3.3.tgz", "integrity": "sha512-UZK3NBx2Mca+b5LsG7bY183pHWt5Y1xts4P3Pz7ENTwGVnJOUWbRb3ocjvX7hx9tq/yTAdclXm9sZ38gNuem4A==", "dev": true }, "cli-cursor": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", "integrity": "sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=", "dev": true, "requires": { "restore-cursor": "^2.0.0" } }, "cli-width": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz", "integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=", "dev": true }, "cliui": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/cliui/-/cliui-5.0.0.tgz", "integrity": "sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA==", "dev": true, "requires": { "string-width": "^3.1.0", "strip-ansi": "^5.2.0", "wrap-ansi": "^5.1.0" }, "dependencies": { "ansi-regex": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", "dev": true }, "string-width": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", "dev": true, "requires": { "emoji-regex": "^7.0.1", "is-fullwidth-code-point": "^2.0.0", "strip-ansi": "^5.1.0" } }, "strip-ansi": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", "dev": true, "requires": { "ansi-regex": "^4.1.0" } } } }, "co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=", "dev": true }, "color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", "dev": true, "requires": { "color-name": "1.1.3" } }, "color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", "dev": true }, "commander": { "version": "2.20.0", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz", "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==" }, "compatible-pool": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/compatible-pool/-/compatible-pool-1.0.1.tgz", "integrity": "sha512-ipwflSyC/ddUiwoniQ7upjsznEwzl/4lyA5RlPtX6Ub2eld9AOW8INgeaU7Bjlywj2EFv3JBzukgbt8LjGFaOw==", "dev": true, "requires": { "@types/node": "^10.12.2", "crc32": "^0.2.2" } }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, "concat-stream": { "version": "1.6.2", "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", "dev": true, "requires": { "buffer-from": "^1.0.0", "inherits": "^2.0.3", "readable-stream": "^2.2.2", "typedarray": "^0.0.6" } }, "core-js": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.9.tgz", "integrity": "sha512-HOpZf6eXmnl7la+cUdMnLvUxKNqLUzJvgIziQ0DiF3JwSImNphIqdGqzj6hIKyX04MmV0poclQ7+wjWvxQyR2A==", "dev": true }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", "dev": true }, "crc32": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/crc32/-/crc32-0.2.2.tgz", "integrity": "sha1-etIg1v/c0Rn5/BJ6d3LKzqOQpLo=", "dev": true }, "cross-spawn": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", "integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=", "dev": true, "requires": { "lru-cache": "^4.0.1", "shebang-command": "^1.2.0", "which": "^1.2.9" } }, "csv": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/csv/-/csv-5.1.1.tgz", "integrity": "sha512-gezB9D+enrh2tLj+vsAD8JyYRMIJdSMpec/Pgbb+7YRj6Q6/D12HLSwjhx+CrirRT4dESjZYXWX1JfqlV4RlTA==", "dev": true, "requires": { "csv-generate": "^3.2.0", "csv-parse": "^4.3.0", "csv-stringify": "^5.1.2", "stream-transform": "^1.0.8" } }, "csv-generate": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/csv-generate/-/csv-generate-3.2.3.tgz", "integrity": "sha512-IcR3K0Nx+nJAkcU2eAglVR7DuHnxcuhUM2w2cR+aHOW7bZp2S5LyN2HF3zTkp6BV/DjR6ykoKznUm+AjnWcOKg==", "dev": true }, "csv-parse": { "version": "4.4.3", "resolved": "https://registry.npmjs.org/csv-parse/-/csv-parse-4.4.3.tgz", "integrity": "sha512-TiLGAy14FPJ7/yB+Gn6RgSxoZLpf6pJTRkGqmCt9t/SGVwubrXjbUWtEw39RlKB6hDHzbdjLyBZaysQ0Ji6p/w==", "dev": true }, "csv-stringify": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/csv-stringify/-/csv-stringify-5.3.0.tgz", "integrity": "sha512-VMYPbE8zWz475smwqb9VbX9cj0y4J0PBl59UdcqzLkzXHZZ8dh4Rmbb0ZywsWEtUml4A96Hn7Q5MW9ppVghYzg==", "dev": true, "requires": { "lodash.get": "~4.4.2" } }, "debug": { "version": "3.2.6", "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", "dev": true, "requires": { "ms": "^2.1.1" } }, "decamelize": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", "dev": true }, "deep-is": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", "dev": true }, "diff": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", "dev": true }, "doctrine": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==", "dev": true, "requires": { "esutils": "^2.0.2" } }, "emoji-regex": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", "dev": true }, "end-of-stream": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz", "integrity": "sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==", "dev": true, "requires": { "once": "^1.4.0" } }, "es6-promise": { "version": "4.2.8", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==", "dev": true }, "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "dev": true }, "escodegen": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-1.11.1.tgz", "integrity": "sha512-JwiqFD9KdGVVpeuRa68yU3zZnBEOcPs0nKW7wZzXky8Z7tffdYUHbe11bPCV5jYlK6DVdKLWLm0f5I/QlL0Kmw==", "dev": true, "requires": { "esprima": "^3.1.3", "estraverse": "^4.2.0", "esutils": "^2.0.2", "optionator": "^0.8.1", "source-map": "~0.6.1" } }, "eslint": { "version": "4.19.1", "resolved": "https://registry.npmjs.org/eslint/-/eslint-4.19.1.tgz", "integrity": "sha512-bT3/1x1EbZB7phzYu7vCr1v3ONuzDtX8WjuM9c0iYxe+cq+pwcKEoQjl7zd3RpC6YOLgnSy3cTN58M2jcoPDIQ==", "dev": true, "requires": { "ajv": "^5.3.0", "babel-code-frame": "^6.22.0", "chalk": "^2.1.0", "concat-stream": "^1.6.0", "cross-spawn": "^5.1.0", "debug": "^3.1.0", "doctrine": "^2.1.0", "eslint-scope": "^3.7.1", "eslint-visitor-keys": "^1.0.0", "espree": "^3.5.4", "esquery": "^1.0.0", "esutils": "^2.0.2", "file-entry-cache": "^2.0.0", "functional-red-black-tree": "^1.0.1", "glob": "^7.1.2", "globals": "^11.0.1", "ignore": "^3.3.3", "imurmurhash": "^0.1.4", "inquirer": "^3.0.6", "is-resolvable": "^1.0.0", "js-yaml": "^3.9.1", "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.3.0", "lodash": "^4.17.4", "minimatch": "^3.0.2", "mkdirp": "^0.5.1", "natural-compare": "^1.4.0", "optionator": "^0.8.2", "path-is-inside": "^1.0.2", "pluralize": "^7.0.0", "progress": "^2.0.0", "regexpp": "^1.0.1", "require-uncached": "^1.0.3", "semver": "^5.3.0", "strip-ansi": "^4.0.0", "strip-json-comments": "~2.0.1", "table": "4.0.2", "text-table": "~0.2.0" } }, "eslint-scope": { "version": "3.7.3", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.3.tgz", "integrity": "sha512-W+B0SvF4gamyCTmUc+uITPY0989iXVfKvhwtmJocTaYoc/3khEHmEmvfY/Gn9HA9VV75jrQECsHizkNw1b68FA==", "dev": true, "requires": { "esrecurse": "^4.1.0", "estraverse": "^4.1.1" } }, "eslint-visitor-keys": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", "integrity": "sha512-qzm/XxIbxm/FHyH341ZrbnMUpe+5Bocte9xkmFMzPMjRaZMcXww+MpBptFvtU+79L362nqiLhekCxCxDPaUMBQ==", "dev": true }, "eslump": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/eslump/-/eslump-2.0.0.tgz", "integrity": "sha512-80p4ogK1rh8LWyTIRAeL4BEC1sSP0O/8JYNygSvLQXN0+zhKlTtRsESOsBUU+POHNISTifbefaEJNqpqZQxdKQ==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", "mkdirp": "^0.5.1", "optionator": "^0.8.2", "random-int": "^1.0.0", "random-item": "^1.0.0", "shift-codegen": "5.1.0", "shift-fuzzer": "^1.0.2", "shift-reducer": "^5.0.0" } }, "espree": { "version": "3.5.4", "resolved": "https://registry.npmjs.org/espree/-/espree-3.5.4.tgz", "integrity": "sha512-yAcIQxtmMiB/jL32dzEp2enBeidsB7xWPLNiw3IIkpVds1P+h7qF9YwJq1yUNzp2OKXgAprs4F61ih66UsoD1A==", "dev": true, "requires": { "acorn": "^5.5.0", "acorn-jsx": "^3.0.0" }, "dependencies": { "acorn": { "version": "5.7.3", "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", "integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==", "dev": true } } }, "esprima": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/esprima/-/esprima-3.1.3.tgz", "integrity": "sha1-/cpRzuYTOJXjyI1TXOSdv/YqRjM=", "dev": true }, "esquery": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.0.1.tgz", "integrity": "sha512-SmiyZ5zIWH9VM+SRUReLS5Q8a7GxtRdxEBVZpm98rJM7Sb+A9DVCndXfkeFUd3byderg+EbDkfnevfCwynWaNA==", "dev": true, "requires": { "estraverse": "^4.0.0" } }, "esrecurse": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz", "integrity": "sha512-64RBB++fIOAXPw3P9cy89qfMlvZEXZkqqJkjqqXIvzP5ezRZjW+lPWjw35UX/3EhUPFYbg5ER4JYgDw4007/DQ==", "dev": true, "requires": { "estraverse": "^4.1.0" } }, "estraverse": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.2.0.tgz", "integrity": "sha1-De4/7TH81GlhjOc0IJn8GvoL2xM=", "dev": true }, "esutils": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", "dev": true }, "execa": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz", "integrity": "sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==", "dev": true, "requires": { "cross-spawn": "^6.0.0", "get-stream": "^4.0.0", "is-stream": "^1.1.0", "npm-run-path": "^2.0.0", "p-finally": "^1.0.0", "signal-exit": "^3.0.0", "strip-eof": "^1.0.0" }, "dependencies": { "cross-spawn": { "version": "6.0.5", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", "dev": true, "requires": { "nice-try": "^1.0.4", "path-key": "^2.0.1", "semver": "^5.5.0", "shebang-command": "^1.2.0", "which": "^1.2.9" } } } }, "external-editor": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-2.2.0.tgz", "integrity": "sha512-bSn6gvGxKt+b7+6TKEv1ZycHleA7aHhRHyAqJyp5pbUFuYYNIzpZnQDk7AsYckyWdEnTeAnay0aCy2aV6iTk9A==", "dev": true, "requires": { "chardet": "^0.4.0", "iconv-lite": "^0.4.17", "tmp": "^0.0.33" } }, "fast-deep-equal": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz", "integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=", "dev": true }, "fast-json-stable-stringify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=", "dev": true }, "fast-levenshtein": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", "dev": true }, "figures": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", "integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=", "dev": true, "requires": { "escape-string-regexp": "^1.0.5" } }, "file-entry-cache": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-2.0.0.tgz", "integrity": "sha1-w5KZDD5oR4PYOLjISkXYoEhFg2E=", "dev": true, "requires": { "flat-cache": "^1.2.1", "object-assign": "^4.0.1" } }, "find-up": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", "dev": true, "requires": { "locate-path": "^3.0.0" } }, "flat-cache": { "version": "1.3.4", "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-1.3.4.tgz", "integrity": "sha512-VwyB3Lkgacfik2vhqR4uv2rvebqmDvFu4jlN/C1RzWoJEo8I7z4Q404oiqYCkq41mni8EzQnm95emU9seckwtg==", "dev": true, "requires": { "circular-json": "^0.3.1", "graceful-fs": "^4.1.2", "rimraf": "~2.6.2", "write": "^0.2.1" } }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, "functional-red-black-tree": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", "dev": true }, "get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", "dev": true }, "get-stream": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", "dev": true, "requires": { "pump": "^3.0.0" } }, "glob": { "version": "7.1.4", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", "dev": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", "inherits": "2", "minimatch": "^3.0.4", "once": "^1.3.0", "path-is-absolute": "^1.0.0" } }, "globals": { "version": "11.12.0", "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", "dev": true }, "graceful-fs": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.0.tgz", "integrity": "sha512-jpSvDPV4Cq/bgtpndIWbI5hmYxhQGHPC4d4cqBPb4DLniCfhJokdXhwhaDuLBGLQdvvRum/UiX6ECVIPvDXqdg==", "dev": true }, "growl": { "version": "1.10.5", "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", "dev": true }, "has-ansi": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", "dev": true, "requires": { "ansi-regex": "^2.0.0" } }, "has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", "dev": true }, "he": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", "dev": true }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", "dev": true, "requires": { "safer-buffer": ">= 2.1.2 < 3" } }, "ignore": { "version": "3.3.10", "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.10.tgz", "integrity": "sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==", "dev": true }, "imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", "dev": true }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", "dev": true, "requires": { "once": "^1.3.0", "wrappy": "1" } }, "inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true }, "inquirer": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-3.3.0.tgz", "integrity": "sha512-h+xtnyk4EwKvFWHrUYsWErEVR+igKtLdchu+o0Z1RL7VU/jVMFbYir2bp6bAj8efFNxWqHX0dIss6fJQ+/+qeQ==", "dev": true, "requires": { "ansi-escapes": "^3.0.0", "chalk": "^2.0.0", "cli-cursor": "^2.1.0", "cli-width": "^2.0.0", "external-editor": "^2.0.4", "figures": "^2.0.0", "lodash": "^4.3.0", "mute-stream": "0.0.7", "run-async": "^2.2.0", "rx-lite": "^4.0.8", "rx-lite-aggregates": "^4.0.8", "string-width": "^2.1.0", "strip-ansi": "^4.0.0", "through": "^2.3.6" } }, "invariant": { "version": "2.2.4", "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz", "integrity": "sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==", "dev": true, "requires": { "loose-envify": "^1.0.0" } }, "invert-kv": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz", "integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==", "dev": true }, "is-fullwidth-code-point": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", "dev": true }, "is-promise": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=", "dev": true }, "is-resolvable": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-resolvable/-/is-resolvable-1.1.0.tgz", "integrity": "sha512-qgDYXFSR5WvEfuS5dMj6oTMEbrrSaM0CrFk2Yiq/gXnBvD9pMa2jGXxyhGLfvhZpuMZe18CJpFxAt3CRs42NMg==", "dev": true }, "is-stream": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=", "dev": true }, "isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", "dev": true }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", "dev": true }, "js-tokens": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=", "dev": true }, "js-yaml": { "version": "3.13.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", "dev": true, "requires": { "argparse": "^1.0.7", "esprima": "^4.0.0" }, "dependencies": { "esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", "dev": true } } }, "jsesc": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", "integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==", "dev": true }, "json-schema-traverse": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz", "integrity": "sha1-NJptRMU6Ud6JtAgFxdXlm0F9M0A=", "dev": true }, "json-stable-stringify-without-jsonify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", "dev": true }, "lcid": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz", "integrity": "sha512-avPEb8P8EGnwXKClwsNUgryVjllcRqtMYa49NTsbQagYuT1DcXnl1915oxWjoyGrXR6zH/Y0Zc96xWsPcoDKeA==", "dev": true, "requires": { "invert-kv": "^2.0.0" } }, "levn": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", "integrity": "sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=", "dev": true, "requires": { "prelude-ls": "~1.1.2", "type-check": "~0.3.2" } }, "locate-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", "dev": true, "requires": { "p-locate": "^3.0.0", "path-exists": "^3.0.0" } }, "lodash": { "version": "4.17.11", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", "dev": true }, "lodash.get": { "version": "4.4.2", "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=", "dev": true }, "loose-envify": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", "dev": true, "requires": { "js-tokens": "^3.0.0 || ^4.0.0" } }, "lru-cache": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", "dev": true, "requires": { "pseudomap": "^1.0.2", "yallist": "^2.1.2" } }, "map-age-cleaner": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz", "integrity": "sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w==", "dev": true, "requires": { "p-defer": "^1.0.0" } }, "mem": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/mem/-/mem-4.3.0.tgz", "integrity": "sha512-qX2bG48pTqYRVmDB37rn/6PT7LcR8T7oAX3bf99u1Tt1nzxYfxkgqDwUwolPlXweM0XzBOBFzSx4kfp7KP1s/w==", "dev": true, "requires": { "map-age-cleaner": "^0.1.1", "mimic-fn": "^2.0.0", "p-is-promise": "^2.0.0" }, "dependencies": { "mimic-fn": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", "dev": true } } }, "mimic-fn": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==", "dev": true }, "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "dev": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", "dev": true }, "mkdirp": { "version": "0.5.1", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "dev": true, "requires": { "minimist": "0.0.8" } }, "mocha": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.2.0.tgz", "integrity": "sha512-2IUgKDhc3J7Uug+FxMXuqIyYzH7gJjXECKe/w43IGgQHTSj3InJi+yAA7T24L9bQMRKiUEHxEX37G5JpVUGLcQ==", "dev": true, "requires": { "browser-stdout": "1.3.1", "commander": "2.15.1", "debug": "3.1.0", "diff": "3.5.0", "escape-string-regexp": "1.0.5", "glob": "7.1.2", "growl": "1.10.5", "he": "1.1.1", "minimatch": "3.0.4", "mkdirp": "0.5.1", "supports-color": "5.4.0" }, "dependencies": { "commander": { "version": "2.15.1", "resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz", "integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==", "dev": true }, "debug": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", "dev": true, "requires": { "ms": "2.0.0" } }, "glob": { "version": "7.1.2", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", "dev": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", "inherits": "2", "minimatch": "^3.0.4", "once": "^1.3.0", "path-is-absolute": "^1.0.0" } }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", "dev": true }, "supports-color": { "version": "5.4.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", "dev": true, "requires": { "has-flag": "^3.0.0" } } } }, "mochallel": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/mochallel/-/mochallel-2.0.0.tgz", "integrity": "sha512-ZP1kQ+7odO6GIjf1u4CsQLS0A2qgo6F48XLzI+TJa3sREwMORyQUuZhhU34KL7y4E/pdsCvheFycYyr24Q4bgA==", "dev": true, "requires": { "multiprocess-map": "^1.5.3", "yargs": "^13.2.4" } }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, "multiprocess-map": { "version": "1.5.3", "resolved": "https://registry.npmjs.org/multiprocess-map/-/multiprocess-map-1.5.3.tgz", "integrity": "sha512-zF/zJl+ogCMd/W+LQg5ZWeeIA+arZxz1BjDnvMm/1W6braW89f/Q28QhCCJyyyYMVRpNbDqbfl2qZtLGq7Lozw==", "dev": true, "requires": { "compatible-pool": "^1.0.0", "parallel-worker": "^1.2.1" } }, "murmurhash": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/murmurhash/-/murmurhash-0.0.2.tgz", "integrity": "sha1-bwe9ihEF5wnCb8iUIMtZMMJFhf4=", "dev": true }, "mute-stream": { "version": "0.0.7", "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=", "dev": true }, "natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", "dev": true }, "nice-try": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", "dev": true }, "npm-run-path": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", "integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=", "dev": true, "requires": { "path-key": "^2.0.0" } }, "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", "dev": true }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "dev": true, "requires": { "wrappy": "1" } }, "onetime": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz", "integrity": "sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ=", "dev": true, "requires": { "mimic-fn": "^1.0.0" } }, "optionator": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.2.tgz", "integrity": "sha1-NkxeQJ0/TWMB1sC0wFu6UBgK62Q=", "dev": true, "requires": { "deep-is": "~0.1.3", "fast-levenshtein": "~2.0.4", "levn": "~0.3.0", "prelude-ls": "~1.1.2", "type-check": "~0.3.2", "wordwrap": "~1.0.0" } }, "os-locale": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-3.1.0.tgz", "integrity": "sha512-Z8l3R4wYWM40/52Z+S265okfFj8Kt2cC2MKY+xNi3kFs+XGI7WXu/I309QQQYbRW4ijiZ+yxs9pqEhJh0DqW3Q==", "dev": true, "requires": { "execa": "^1.0.0", "lcid": "^2.0.0", "mem": "^4.0.0" } }, "os-shim": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/os-shim/-/os-shim-0.1.3.tgz", "integrity": "sha1-a2LDeRz3kJ6jXtRuF2WLtBfLORc=", "dev": true }, "os-tmpdir": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", "dev": true }, "p-defer": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz", "integrity": "sha1-n26xgvbJqozXQwBKfU+WsZaw+ww=", "dev": true }, "p-finally": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=", "dev": true }, "p-is-promise": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-2.1.0.tgz", "integrity": "sha512-Y3W0wlRPK8ZMRbNq97l4M5otioeA5lm1z7bkNkxCka8HSPjR0xRWmpCmc9utiaLP9Jb1eD8BgeIxTW4AIF45Pg==", "dev": true }, "p-limit": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.0.tgz", "integrity": "sha512-pZbTJpoUsCzV48Mc9Nh51VbwO0X9cuPFE8gYwx9BTCt9SF8/b7Zljd2fVgOxhIF/HDTKgpVzs+GPhyKfjLLFRQ==", "dev": true, "requires": { "p-try": "^2.0.0" } }, "p-locate": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", "dev": true, "requires": { "p-limit": "^2.0.0" } }, "p-try": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", "dev": true }, "parallel-worker": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/parallel-worker/-/parallel-worker-1.2.1.tgz", "integrity": "sha512-psh7l6kUCp6QrnmjMRKIUKwBqzWkI7/kJCKkglvNWehG1MSyCIBn3hKGusd+lCmEmV19ayfwt/IaUamqZb0rqw==", "dev": true, "requires": { "@types/murmurhash": "0.0.1", "babel-polyfill": "^6.26.0", "circular-json": "^0.5.9", "murmurhash": "0.0.2", "semver": "^5.6.0", "user-async-function": "^1.1.3" }, "dependencies": { "circular-json": { "version": "0.5.9", "resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.5.9.tgz", "integrity": "sha512-4ivwqHpIFJZBuhN3g/pEcdbnGUywkBblloGbkglyloVjjR3uT6tieI89MVOfbP2tHX5sgb01FuLgAOzebNlJNQ==", "dev": true } } }, "path-exists": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", "dev": true }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, "path-is-inside": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/path-is-inside/-/path-is-inside-1.0.2.tgz", "integrity": "sha1-NlQX3t5EQw0cEa9hAn+s8HS9/FM=", "dev": true }, "path-key": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=", "dev": true }, "pluralize": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/pluralize/-/pluralize-7.0.0.tgz", "integrity": "sha512-ARhBOdzS3e41FbkW/XWrTEtukqqLoK5+Z/4UeDaLuSW+39JPeFgs4gCGqsrJHVZX0fUrx//4OF0K1CUGwlIFow==", "dev": true }, "pre-commit": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/pre-commit/-/pre-commit-1.2.2.tgz", "integrity": "sha1-287g7p3nI15X95xW186UZBpp7sY=", "dev": true, "requires": { "cross-spawn": "^5.0.1", "spawn-sync": "^1.0.15", "which": "1.2.x" }, "dependencies": { "which": { "version": "1.2.14", "resolved": "https://registry.npmjs.org/which/-/which-1.2.14.tgz", "integrity": "sha1-mofEN48D6CfOyvGs31bHNsAcFOU=", "dev": true, "requires": { "isexe": "^2.0.0" } } } }, "prelude-ls": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", "dev": true }, "process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", "dev": true }, "progress": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", "dev": true }, "pseudomap": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=", "dev": true }, "pump": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", "dev": true, "requires": { "end-of-stream": "^1.1.0", "once": "^1.3.1" } }, "random-int": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/random-int/-/random-int-1.0.0.tgz", "integrity": "sha1-5qLtNEisnGZGoGV0Q7HBUhWS7Qg=", "dev": true }, "random-item": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/random-item/-/random-item-1.0.0.tgz", "integrity": "sha1-Fu4xYmywUMihaGpfD0KmuZoqrxE=", "dev": true }, "readable-stream": { "version": "2.3.6", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "dev": true, "requires": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", "isarray": "~1.0.0", "process-nextick-args": "~2.0.0", "safe-buffer": "~5.1.1", "string_decoder": "~1.1.1", "util-deprecate": "~1.0.1" } }, "regenerator-runtime": { "version": "0.10.5", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz", "integrity": "sha1-M2w+/BIgrc7dosn6tntaeVWjNlg=", "dev": true }, "regexpp": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-1.1.0.tgz", "integrity": "sha512-LOPw8FpgdQF9etWMaAfG/WRthIdXJGYp4mJ2Jgn/2lpkbod9jPn0t9UqN7AxBOKNfzRbYyVfgc7Vk4t/MpnXgw==", "dev": true }, "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", "dev": true }, "require-main-filename": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", "dev": true }, "require-uncached": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz", "integrity": "sha1-Tg1W1slmL9MeQwEcS5WqSZVUIdM=", "dev": true, "requires": { "caller-path": "^0.1.0", "resolve-from": "^1.0.0" } }, "resolve-from": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-1.0.1.tgz", "integrity": "sha1-Jsv+k10a7uq7Kbw/5a6wHpPUQiY=", "dev": true }, "restore-cursor": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz", "integrity": "sha1-n37ih/gv0ybU/RYpI9YhKe7g368=", "dev": true, "requires": { "onetime": "^2.0.0", "signal-exit": "^3.0.2" } }, "rimraf": { "version": "2.6.3", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", "dev": true, "requires": { "glob": "^7.1.3" } }, "rollup": { "version": "1.16.6", "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.16.6.tgz", "integrity": "sha512-oM3iKkzPCq9Da95wCnNfS8YlNZjgCD5c/TceKnJIthI9FOeJqnO3PUr/C5Suv9Kjzh0iphKL02PLeja3A5AMIA==", "dev": true, "requires": { "@types/estree": "0.0.39", "@types/node": "^12.0.10", "acorn": "^6.1.1" }, "dependencies": { "@types/node": { "version": "12.0.12", "resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.12.tgz", "integrity": "sha512-Uy0PN4R5vgBUXFoJrKryf5aTk3kJ8Rv3PdlHjl6UaX+Cqp1QE0yPQ68MPXGrZOfG7gZVNDIJZYyot0B9ubXUrQ==", "dev": true } } }, "run-async": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz", "integrity": "sha1-A3GrSuC91yDUFm19/aZP96RFpsA=", "dev": true, "requires": { "is-promise": "^2.1.0" } }, "rx-lite": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/rx-lite/-/rx-lite-4.0.8.tgz", "integrity": "sha1-Cx4Rr4vESDbwSmQH6S2kJGe3lEQ=", "dev": true }, "rx-lite-aggregates": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/rx-lite-aggregates/-/rx-lite-aggregates-4.0.8.tgz", "integrity": "sha1-dTuHqJoRyVRnxKwWJsTvxOBcZ74=", "dev": true, "requires": { "rx-lite": "*" } }, "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", "dev": true }, "safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true }, "semver": { "version": "5.7.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", "dev": true }, "set-blocking": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", "dev": true }, "shebang-command": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", "dev": true, "requires": { "shebang-regex": "^1.0.0" } }, "shebang-regex": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", "dev": true }, "shift-ast": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/shift-ast/-/shift-ast-4.0.0.tgz", "integrity": "sha1-HUFSoq3ShkSlKusuDIfYkl09l/8=", "dev": true }, "shift-codegen": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/shift-codegen/-/shift-codegen-5.1.0.tgz", "integrity": "sha512-OpRpMYukx4uNyZl+4j192qlghA+orUuXQwCxGB4C7XWVCeFOoz9MVCAQ9XNMQqeZKHE9YNoMpBA/kzrVUFpqcQ==", "dev": true, "requires": { "babel-eslint": "^8.2.2", "esutils": "^2.0.2", "object-assign": "^4.1.0", "shift-reducer": "^4.3.0" }, "dependencies": { "shift-reducer": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/shift-reducer/-/shift-reducer-4.4.1.tgz", "integrity": "sha512-IJmk9grLnuO8vLSG5e52wFXaDLXJmVMGPXKQljhh/Pwb1mQL8OgCr6c4OYyIa3OInTH9rBtms3SwDFWsJzVEnA==", "dev": true, "requires": { "shift-ast": "^4.0.0" } } } }, "shift-fuzzer": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/shift-fuzzer/-/shift-fuzzer-1.0.2.tgz", "integrity": "sha1-g7uuFHv2Aiqupyc+LiviJamZVys=", "dev": true, "requires": { "shift-ast": "^4.0.0" } }, "shift-reducer": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/shift-reducer/-/shift-reducer-5.0.0.tgz", "integrity": "sha512-Jgr6kPMZuzsQ63NdeLJT6BZvtJ6IDbYFBVqiid1bZlwxeJYq81Cj2Wc4UUERjO4Q9tz5U4KpWaZhitjcBvfiYA==", "dev": true, "requires": { "shift-ast": "5.0.0" }, "dependencies": { "shift-ast": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/shift-ast/-/shift-ast-5.0.0.tgz", "integrity": "sha512-kMhr/GwgrQ1U2kaa50sD5YxNDQEZHAZigVwrf/NNeezb6oiYnpPMV8v1WVRhCW8sjI7xUdzuPujSQ3gA2IuUAQ==", "dev": true } } }, "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", "dev": true }, "slice-ansi": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-1.0.0.tgz", "integrity": "sha512-POqxBK6Lb3q6s047D/XsDVNPnF9Dl8JSaqe9h9lURl0OdNqy/ujDrOiIHtsqXMGbWWTIomRzAMaTyawAU//Reg==", "dev": true, "requires": { "is-fullwidth-code-point": "^2.0.0" } }, "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" }, "source-map-support": { "version": "0.5.12", "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.12.tgz", "integrity": "sha512-4h2Pbvyy15EE02G+JOZpUCmqWJuqrs+sEkzewTm++BPi7Hvn/HwcqLAcNxYAyI0x13CpPPn+kMjl+hplXMHITQ==", "requires": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" } }, "spawn-sync": { "version": "1.0.15", "resolved": "https://registry.npmjs.org/spawn-sync/-/spawn-sync-1.0.15.tgz", "integrity": "sha1-sAeZVX63+wyDdsKdROih6mfldHY=", "dev": true, "requires": { "concat-stream": "^1.4.7", "os-shim": "^0.1.2" } }, "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, "stream-transform": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/stream-transform/-/stream-transform-1.0.8.tgz", "integrity": "sha512-1q+dL790Ps0NV33rISMq9OLtfDA9KMJZdo1PHZXE85orrWsM4FAh8CVyAOTHO0rhyeM138KNPngBPrx33bFsxw==", "dev": true }, "string-width": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", "dev": true, "requires": { "is-fullwidth-code-point": "^2.0.0", "strip-ansi": "^4.0.0" } }, "string_decoder": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", "dev": true, "requires": { "safe-buffer": "~5.1.0" } }, "strip-ansi": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", "dev": true, "requires": { "ansi-regex": "^3.0.0" }, "dependencies": { "ansi-regex": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", "dev": true } } }, "strip-eof": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=", "dev": true }, "strip-json-comments": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", "dev": true }, "supports-color": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", "dev": true }, "table": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/table/-/table-4.0.2.tgz", "integrity": "sha512-UUkEAPdSGxtRpiV9ozJ5cMTtYiqz7Ni1OGqLXRCynrvzdtR1p+cfOWe2RJLwvUG8hNanaSRjecIqwOjqeatDsA==", "dev": true, "requires": { "ajv": "^5.2.3", "ajv-keywords": "^2.1.0", "chalk": "^2.1.0", "lodash": "^4.17.4", "slice-ansi": "1.0.0", "string-width": "^2.1.1" } }, "text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", "dev": true }, "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true }, "tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", "dev": true, "requires": { "os-tmpdir": "~1.0.2" } }, "to-fast-properties": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=", "dev": true }, "trim-right": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz", "integrity": "sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=", "dev": true }, "type-check": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", "integrity": "sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=", "dev": true, "requires": { "prelude-ls": "~1.1.2" } }, "typedarray": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", "dev": true }, "user-async-function": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/user-async-function/-/user-async-function-1.1.3.tgz", "integrity": "sha512-IdoqXRu5z0+AmFBXuZOdv+URJ3jyXRUXdhE8GGT3tcXzRCjm+EL4eW0r49Z+P5Szdv4U9mIBmID0JyIxUnSc4w==", "dev": true, "requires": { "es6-promise": "^4.2.5" } }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", "dev": true }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", "dev": true, "requires": { "isexe": "^2.0.0" } }, "which-module": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", "dev": true }, "wordwrap": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=", "dev": true }, "wrap-ansi": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-5.1.0.tgz", "integrity": "sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q==", "dev": true, "requires": { "ansi-styles": "^3.2.0", "string-width": "^3.0.0", "strip-ansi": "^5.0.0" }, "dependencies": { "ansi-regex": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", "dev": true }, "ansi-styles": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", "dev": true, "requires": { "color-convert": "^1.9.0" } }, "string-width": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", "dev": true, "requires": { "emoji-regex": "^7.0.1", "is-fullwidth-code-point": "^2.0.0", "strip-ansi": "^5.1.0" } }, "strip-ansi": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", "dev": true, "requires": { "ansi-regex": "^4.1.0" } } } }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true }, "write": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/write/-/write-0.2.1.tgz", "integrity": "sha1-X8A4KOJkzqP+kUVUdvejxWbLB1c=", "dev": true, "requires": { "mkdirp": "^0.5.1" } }, "y18n": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", "dev": true }, "yallist": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=", "dev": true }, "yargs": { "version": "13.2.4", "resolved": "https://registry.npmjs.org/yargs/-/yargs-13.2.4.tgz", "integrity": "sha512-HG/DWAJa1PAnHT9JAhNa8AbAv3FPaiLzioSjCcmuXXhP8MlpHO5vwls4g4j6n30Z74GVQj8Xa62dWVx1QCGklg==", "dev": true, "requires": { "cliui": "^5.0.0", "find-up": "^3.0.0", "get-caller-file": "^2.0.1", "os-locale": "^3.1.0", "require-directory": "^2.1.1", "require-main-filename": "^2.0.0", "set-blocking": "^2.0.0", "string-width": "^3.0.0", "which-module": "^2.0.0", "y18n": "^4.0.0", "yargs-parser": "^13.1.0" }, "dependencies": { "ansi-regex": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", "dev": true }, "string-width": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", "dev": true, "requires": { "emoji-regex": "^7.0.1", "is-fullwidth-code-point": "^2.0.0", "strip-ansi": "^5.1.0" } }, "strip-ansi": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", "dev": true, "requires": { "ansi-regex": "^4.1.0" } } } }, "yargs-parser": { "version": "13.1.1", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.1.tgz", "integrity": "sha512-oVAVsHz6uFrg3XQheFII8ESO2ssAf9luWuAd6Wexsu4F3OtIW0o8IribPXYrD4WC24LWtPrJlGy87y5udK+dxQ==", "dev": true, "requires": { "camelcase": "^5.0.0", "decamelize": "^1.2.0" } } } } terser-4.1.2/package.json000066400000000000000000000051601351061312300153050ustar00rootroot00000000000000{ "name": "terser", "description": "JavaScript parser, mangler/compressor and beautifier toolkit for ES6+", "homepage": "https://github.com/fabiosantoscode/terser", "author": "Mihai Bazon (http://lisperator.net/)", "license": "BSD-2-Clause", "version": "4.1.2", "engines": { "node": ">=6.0.0" }, "maintainers": [ "Fábio Santos " ], "repository": "https://github.com/fabiosantoscode/terser.git", "main": "dist/bundle.min.js", "types": "tools/terser.d.ts", "bin": { "terser": "bin/uglifyjs" }, "files": [ "bin", "dist", "tools", "LICENSE", "README.md", "CHANGELOG.md", "PATRONS.md" ], "dependencies": { "commander": "^2.20.0", "source-map": "~0.6.1", "source-map-support": "~0.5.12" }, "devDependencies": { "acorn": "^6.1.1", "csv": "^5.1.1", "escodegen": "^1.11.1", "eslint": "^4.19.1", "eslump": "^2.0.0", "mocha": "^5.2.0", "mochallel": "^2.0.0", "pre-commit": "^1.2.2", "rimraf": "^2.6.3", "rollup": "^1.13.1", "semver": "^5.7.0" }, "scripts": { "test": "npm run build -- --silent --input=main.tests.js && npm run minify && node test/run-tests.js", "lint": "eslint lib", "lint-fix": "eslint --fix lib", "build": "rimraf dist/* && rollup -c", "minify": "cd dist && node ../bin/uglifyjsnobundle bundle.js -mc --source-map content=bundle.js.map,includeSources=true -o bundle.min.js", "prepare": "npm run build && npm run minify", "postversion": "echo 'Remember to update the changelog!'" }, "keywords": [ "uglify", "terser", "uglify-es", "uglify-js", "minify", "minifier", "javascript", "ecmascript", "es5", "es6", "es7", "es8", "es2015", "es2016", "es2017", "async", "await" ], "eslintConfig": { "parserOptions": { "sourceType": "module" }, "env": { "es6": true }, "globals": { "describe": false, "it": false, "require": false, "global": false }, "rules": { "brace-style": [ "error", "1tbs", { "allowSingleLine": true } ], "quotes": [ "error", "double", "avoid-escape" ], "no-debugger": "error", "no-undef": "error", "no-tabs": "error", "semi": [ "error", "always" ], "no-extra-semi": "error", "no-irregular-whitespace": "error", "space-before-blocks": [ "error", "always" ] } }, "pre-commit": [ "lint-fix", "test" ] } terser-4.1.2/rollup.config.js000066400000000000000000000004411351061312300161330ustar00rootroot00000000000000export default { input: "main.js", output: { file: "dist/bundle.js", format: "umd", globals: { "source-map": "sourceMap", }, name: "Terser", sourcemap: true, esModule: false, }, external: "source-map", }; terser-4.1.2/test/000077500000000000000000000000001351061312300137745ustar00rootroot00000000000000terser-4.1.2/test/benchmark.js000066400000000000000000000053451351061312300162730ustar00rootroot00000000000000#! /usr/bin/env node // -*- js -*- "use strict"; var createHash = require("crypto").createHash; var fetch = require("./fetch"); var fork = require("child_process").fork; var zlib = require("zlib"); var args = process.argv.slice(2); if (!args.length) { args.push("-mc"); } args.push("--timings"); var urls = [ "https://code.jquery.com/jquery-3.2.1.js", "https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.4/angular.js", "https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.9.0/math.js", "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js", "https://unpkg.com/react@15.3.2/dist/react.js", "http://builds.emberjs.com/tags/v2.11.0/ember.prod.js", "https://cdn.jsdelivr.net/lodash/4.17.4/lodash.js", "https://cdnjs.cloudflare.com/ajax/libs/d3/4.5.0/d3.js", "https://raw.githubusercontent.com/kangax/html-minifier/v3.5.7/dist/htmlminifier.js", ]; var results = {}; var remaining = 2 * urls.length; function done() { if (!--remaining) { var failures = []; 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); } }); if (failures.length) { console.error("Benchmark failed:"); failures.forEach(function(url) { console.error(url); }); process.exit(1); } } } urls.forEach(function(url) { results[url] = { input: 0, output: 0, gzip: 0, log: "" }; fetch(url, function(err, res) { if (err) throw err; var uglifyjs = fork("bin/uglifyjs", args, { silent: true }); res.on("data", function(data) { results[url].input += data.length; }).pipe(uglifyjs.stdin); 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; }).pipe(createHash("sha1")).on("data", function(data) { results[url].sha1 = data.toString("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(); }); }); }); terser-4.1.2/test/compress/000077500000000000000000000000001351061312300156275ustar00rootroot00000000000000terser-4.1.2/test/compress/arguments.js000066400000000000000000000223621351061312300201770ustar00rootroot00000000000000replace_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" } arguments_in_arrow_func_1: { options = { arguments: true, evaluate: true, keep_fargs: false, properties: true, } input: { (function(a, b) { console.log(arguments[0], a, arguments[1], arguments[3], b, arguments[2]); })("bar", 42, false); (function(a, b) { (() => { console.log(arguments[0], a, arguments[1], arguments[3], b, arguments[2]); })(10, 20, 30, 40); })("bar", 42, false); } expect: { (function(a, b, argument_2, argument_3) { console.log(a, a, b, argument_3, b, argument_2); })("bar", 42, false); (function(a, b) { (() => { console.log(arguments[0], a, arguments[1], arguments[3], b, arguments[2]); })(10, 20, 30, 40); })("bar", 42, false); } expect_stdout: [ "bar bar 42 undefined 42 false", "bar bar 42 undefined 42 false", ] } arguments_in_arrow_func_2: { options = { arguments: true, evaluate: true, keep_fargs: true, properties: true, } input: { (function(a, b) { console.log(arguments[0], a, arguments[1], arguments[3], b, arguments[2]); })("bar", 42, false); (function(a, b) { (() => { console.log(arguments[0], a, arguments[1], arguments[3], b, arguments[2]); })(10, 20, 30, 40); })("bar", 42, false); } expect: { (function(a, b) { console.log(a, a, b, arguments[3], b, arguments[2]); })("bar", 42, false); (function(a, b) { (() => { console.log(arguments[0], a, arguments[1], arguments[3], b, arguments[2]); })(10, 20, 30, 40); })("bar", 42, false); } expect_stdout: [ "bar bar 42 undefined 42 false", "bar bar 42 undefined 42 false", ] } arguments_and_destructuring_1: { options = { arguments: true, defaults: true, } input: { (function({d}) { console.log(a = "foo", arguments[0].d); })({ d: "Bar" }); } expect: { !function({d: d}) { console.log(a = "foo", arguments[0].d); }({ d: "Bar" }); } expect_stdout: "foo Bar" } arguments_and_destructuring_2: { options = { arguments: true, defaults: true, } input: { (function(a, {d}) { console.log(a = "foo", arguments[0]); })("baz", { d: "Bar" }); } expect: { !function(a, {d: d}) { console.log(a = "foo", arguments[0]); }("baz", { d: "Bar" }); } expect_stdout: "foo baz" } arguments_and_destructuring_3: { options = { arguments: true, defaults: true, } input: { (function({d}, a) { console.log(a = "foo", arguments[0].d); })({ d: "Bar" }, "baz"); } expect: { !function({d: d}, a) { console.log(a = "foo", arguments[0].d); }({ d: "Bar" }, "baz"); } expect_stdout: "foo Bar" } duplicate_parameter_with_arguments: { options = { arguments: true, defaults: true, } input: { (function(a, a) { console.log(a = "foo", arguments[0]); })("baz", "Bar"); } expect: { !function(a, a) { console.log(a = "foo", arguments[0]); }("baz", "Bar"); } expect_stdout: "foo baz" } terser-4.1.2/test/compress/array-constructor.js000066400000000000000000000023531351061312300216710ustar00rootroot00000000000000array_constructor: { input: { console.log(new Array()); console.log(new Array(0)); console.log(new Array(1)); console.log(new Array(11)); console.log(new Array(12)); } expect: { console.log(new Array()); console.log(new Array(0)); console.log(new Array(1)); console.log(new Array(11)); console.log(new Array(12)); } } array_constructor_unsafe: { options = { unsafe: true } input: { console.log(new Array()); console.log(new Array(0)); console.log(new Array(1)); console.log(new Array(11)); console.log(Array(11)); console.log(new Array(12)); console.log(Array(12)); console.log(new Array(foo)); console.log(Array(foo)); console.log(new Array("foo")); console.log(Array("foo")); } expect: { console.log([]); console.log([]); console.log([,]); console.log([,,,,,,,,,,,]); console.log([,,,,,,,,,,,]); console.log(Array(12)); console.log(Array(12)); console.log(Array(foo)); console.log(Array(foo)); console.log(Array("foo")); console.log(Array("foo")); } } terser-4.1.2/test/compress/arrays.js000066400000000000000000000203161351061312300174700ustar00rootroot00000000000000// NOTE trailing comma doesn't contribute to length of an array // That also means the array changes length if previous element is a hole too and got cut off holes_and_undefined: { input: { w = [1,,]; x = [1, 2, undefined]; y = [1, , 2, ]; z = [1, undefined, 3]; } expect: { w=[1,,]; x=[1,2,void 0]; y=[1,,2]; z=[1,void 0,3]; } } constant_join: { options = { evaluate: true, unsafe: true, } input: { var a = [ "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 c = [ boo(), "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 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 e = [].join(foo + bar); var f = [].join(""); var g = [].join("foo"); } expect: { var a = "foobarbaz"; 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 c = boo() + "foo123bar" + bar(); var c1 = "" + boo() + bar() + "foo123bar" + bar(); 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 e = [].join(foo + bar); var f = ""; var g = ""; } } constant_join_2: { options = { evaluate: true, unsafe: true, } input: { var a = [ "foo", "bar", boo(), "baz", "x", "y" ].join(""); var b = [ "foo", "bar", boo(), "baz", "x", "y" ].join("-"); var c = [ "foo", "bar", boo(), "baz", "x", "y" ].join("really-long-separator"); var d = [ "foo", "bar", boo(), [ "foo", 1, 2, 3, "bar" ].join("+"), "baz", "x", "y" ].join("-"); var e = [ "foo", "bar", boo(), [ "foo", 1, 2, 3, "bar" ].join("+"), "baz", "x", "y" ].join("really-long-separator"); var f = [ "str", "str" + variable, "foo", "bar", "moo" + foo ].join(""); } expect: { var a = "foobar" + boo() + "bazxy"; var b = [ "foo-bar", boo(), "baz-x-y" ].join("-"); var c = [ "foo", "bar", boo(), "baz", "x", "y" ].join("really-long-separator"); var d = [ "foo-bar", boo(), "foo+1+2+3+bar-baz-x-y" ].join("-"); var e = [ "foo", "bar", boo(), "foo+1+2+3+bar", "baz", "x", "y" ].join("really-long-separator"); var f = "strstr" + variable + "foobarmoo" + foo; } } spread_with_variable_as_last_element: { input: { var values = [4, 5, 6]; var a = [1, 2, 3, ...values]; } expect: { var values = [4, 5, 6]; var a = [1, 2, 3, ...values]; } } spread_with_variable_in_middle: { input: { var values = [4, 5, 6]; var a = [1, 2, 3, ...values, 7,,,]; } expect: { var values = [4, 5, 6]; var a = [1, 2, 3, ...values, 7,,,]; } } spread_with_variable_at_front: { input: { var values = [1, 2, 3]; var a = [...values, 4, 5, 6]; } expect: { var values = [1, 2, 3]; var a = [...values, 4, 5, 6]; } } spread_with_variable_at_front_after_elisions: { input: { var values = [1, 2, 3]; var a = [,,,...values, 4, 5, 6]; } expect: { var values = [1, 2, 3]; var a = [,,,...values, 4, 5, 6]; } } spread_with_array_at_end: { input: { var a = [1, 2, ...[4, 5, 6]]; } expect: { var a = [1, 2, 4, 5, 6]; } } spread_with_logical_expression_at_end: { options = { evaluate: true } input: { var a = [1, 2, 3, ...[2+2]] } expect: { var a = [1, 2, 3, 4] } } spread_with_logical_expression_at_middle: { options = { evaluate: true } input: { var a = [1, 1, ...[1+1, 1+2, 2+3], 8] } expect: { var a = [1, 1, 2, 3, 5, 8] } } constant_join_3: { options = { evaluate: true, unsafe: true, } input: { 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 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" } terser-4.1.2/test/compress/arrow.js000066400000000000000000000363221351061312300173250ustar00rootroot00000000000000arrow_functions_without_body: { input: { var a1 = () => 42; var a2 = (p) => p; var a3 = p => p; var a4 = (...p) => p; var a5 = (b, c) => b + c; var a6 = (b, ...c) => b + c[0]; var a7 = (...b) => b.join(); } expect: { var a1 = () => 42; var a2 = (p) => p; var a3 = p => p; var a4 = (...p) => p; var a5 = (b, c) => b + c; var a6 = (b, ...c) => b + c[0]; var a7 = (...b) => b.join(); } } arrow_functions_with_body: { input: { var a1 = () => { var a = 42 * Math.random(); return a; }; var a2 = (p) => { var a = Math.random() * p; return a; }; var a3 = p => { var a = Math.random() * p; return a; }; var a4 = (...p) => { var a = Math.random() * p; return a; }; var a5 = (b, c) => { var result = b * c + b / c; return result }; var a6 = (b, ...c) => { var result = b; for (var i = 0; i < c.length; i++) result += c[i]; return result }; var a7 = (...b) => { b.join(); } } expect: { var a1 = () => { var a = 42 * Math.random(); return a; }; var a2 = (p) => { var a = Math.random() * p; return a; }; var a3 = p => { var a = Math.random() * p; return a; }; var a4 = (...p) => { var a = Math.random() * p; return a; }; var a5 = (b, c) => { var result = b * c + b / c; return result }; var a6 = (b, ...c) => { var result = b; for (var i = 0; i < c.length; i++) result += c[i]; return result }; var a7 = (...b) => { b.join(); }; } } arrow_function_with_single_parameter_with_default: { input: { var foo = (a = 0) => doSomething(a); } expect_exact: "var foo=(a=0)=>doSomething(a);" } arrow_binding_pattern: { input: { var foo = ([]) => "foo"; var bar = ({}) => "bar"; var with_default = (foo = "default") => foo; var object_with_default = ({foo = "default", bar: baz = "default"}) => foo; var array_after_spread = (...[foo]) => foo; var array_after_spread = (...{foo}) => foo; var computed = ({ [compute()]: x }) => {}; var array_hole = ([, , ...x] = [1, 2]) => {}; var object_trailing_elision = ({foo,}) => {}; var spread_empty_array = (...[]) => "foo"; var spread_empty_object = (...{}) => "foo"; } expect: { var foo = ([]) => "foo"; var bar = ({}) => "bar"; var with_default = (foo = "default") => foo; var object_with_default = ({foo = "default", bar: baz = "default"}) => foo; var array_after_spread = (...[foo]) => foo; var array_after_spread = (...{foo}) => foo; var computed = ({ [compute()]: x }) => {}; var array_hole = ([, , ...x] = [1, 2]) => {}; var object_trailing_elision = ({foo,}) => {}; var spread_empty_array = (...[]) => "foo"; var spread_empty_object = (...{}) => "foo"; } } arrow_binding_pattern_strict: { input: { var foo = ([,]) => "foo"; } expect_exact: 'var foo=([,])=>"foo";' } arrow_with_regexp: { input: { num => /\d{11,14}/.test( num ) } expect: { num => /\d{11,14}/.test( num ) } } arrow_unused: { options = { toplevel: false, side_effects: true, unused: true, } input: { top => dog; let fn = a => { console.log(a * a); }; let u = (x, y) => x - y + g; (() => { console.log("0"); })(); !function(x) { (() => { console.log("1"); })(); let unused = x => { console.log(x); }; let baz = e => e + e; console.log(baz(x)); }(1); fn(3); } expect: { let fn = a => { console.log(a * a); }; let u = (x, y) => x - y + g; (() => { console.log("0"); })(); !function(x) { (() => { console.log("1"); })(); let baz = e => e + e; console.log(baz(x)); }(1); fn(3); } expect_stdout: [ "0", "1", "2", "9" ] } arrow_unused_toplevel: { options = { toplevel: true, side_effects: true, unused: true, } input: { top => dog; let fn = a => { console.log(a * a); }; let u = (x, y) => x - y + g; (() => { console.log("0"); })(); !function(x) { (() => { console.log("1"); })(); let unused = x => { console.log(x); }; let baz = e => e + e; console.log(baz(x)); }(1); fn(3); } expect: { let fn = a => { console.log(a * a); }; (() => { console.log("0"); })(); !function(x) { (() => { console.log("1"); })(); let baz = e => e + e; console.log(baz(x)); }(1); fn(3); } expect_stdout: [ "0", "1", "2", "9" ] } no_leading_parentheses: { input: { (x,y) => x(y); async (x,y) => await x(y); } expect_exact: "(x,y)=>x(y);async(x,y)=>await x(y);" } async_identifiers: { options = { unsafe_arrows: true, ecma: 6, } input: { var async = function(x){ console.log("async", x); }; var await = function(x){ console.log("await", x); }; async(1); await(2); } expect: { var async = x => { console.log("async", x); }; var await = x => { console.log("await", x); }; async(1); await(2); } expect_stdout: [ "async 1", "await 2", ] } async_function_expression: { options = { unsafe_arrows: true, ecma: 6, evaluate: true, side_effects: true, } input: { var named = async function foo() { await bar(1 + 0) + (2 + 0); } var anon = async function() { await (1 + 0) + bar(2 + 0); } } expect: { var named = async function foo() { await bar(1); }; var anon = async () => { await 1, bar(2); }; } } issue_27: { options = { unsafe_arrows: true, collapse_vars: true, ecma: 6, unused: true, } input: { (function(jQuery) { var $; $ = jQuery; $("body").addClass("foo"); })(jQuery); } expect: { (jQuery => { jQuery("body").addClass("foo"); })(jQuery); } } issue_2105_1: { options = { unsafe_arrows: true, collapse_vars: true, ecma: 6, inline: true, passes: 3, reduce_funcs: true, reduce_vars: true, side_effects: true, unsafe_methods: true, unused: true, } input: { !function(factory) { factory(); }( function() { return function(fn) { fn()().prop(); }( function() { function bar() { var quux = function() { console.log("PASS"); }, foo = function() { console.log; quux(); }; return { prop: foo }; } return bar; } ); }); } expect: { ({ prop() { console.log; console.log("PASS"); } }).prop(); } expect_stdout: "PASS" } issue_2105_2: { options = { collapse_vars: true, inline: true, passes: 2, reduce_funcs: true, reduce_vars: true, side_effects: true, unused: true, } input: { ((factory) => { factory(); })( () => { return ((fn) => { fn()().prop(); })( () => { let bar = () => { var quux = () => { console.log("PASS"); }, foo = () => { console.log; quux(); }; return { prop: foo }; }; return bar; } ); }); } expect: { ({ prop: () => { console.log; console.log("PASS"); } }).prop(); } expect_stdout: "PASS" } issue_2136_2: { options = { arrows: true, collapse_vars: true, ecma: 6, inline: true, side_effects: true, unused: true, } input: { function f(x) { console.log(x); } !function(a, ...b) { f(b[0]); }(1, 2, 3); } expect: { function f(x) { console.log(x); } f([2,3][0]); } expect_stdout: "2" } issue_2136_3: { options = { arrows: true, collapse_vars: true, ecma: 6, evaluate: true, inline: true, passes: 3, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unsafe: true, unused: true, } input: { function f(x) { console.log(x); } !function(a, ...b) { f(b[0]); }(1, 2, 3); } expect: { console.log(2); } expect_stdout: "2" } call_args: { options = { arrows: true, ecma: 6, evaluate: true, inline: true, reduce_funcs: true, reduce_vars: true, } input: { const a = 1; console.log(a); +function(a) { return a; }(a); } expect: { const a = 1; console.log(1); +(1, 1); } expect_stdout: true } call_args_drop_param: { options = { arrows: true, ecma: 6, evaluate: true, inline: true, keep_fargs: false, reduce_funcs: true, reduce_vars: true, unused: true, } input: { const a = 1; console.log(a); +function(a) { return a; }(a, b); } expect: { const a = 1; console.log(1); +(b, 1); } expect_stdout: true } issue_485_crashing_1530: { options = { arrows: true, conditionals: true, dead_code: true, ecma: 6, evaluate: true, inline: true, side_effects: true, } input: { (function(a) { if (true) return; var b = 42; })(this); } expect: {} } issue_2084: { options = { unsafe_arrows: true, collapse_vars: true, conditionals: true, ecma: 6, evaluate: true, inline: true, passes: 2, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { var c = 0; !function() { !function(c) { c = 1 + c; var c = 0; function f14(a_1) { if (c = 1 + c, 0 !== 23..toString()) c = 1 + c, a_1 && (a_1[0] = 0); } f14(); }(-1); }(); console.log(c); } expect: { var c = 0; (c => { c = 1 + c, c = 1 + (c = 0), 0 !== 23..toString() && (c = 1 + c); })(-1), console.log(c); } expect_stdout: "0" } export_default_object_expression: { options = { arrows: true, evaluate: true, } input: { export default { foo: 1 + 2, bar() { return 4; }, get baz() { return this.foo; }, }; } expect_exact: "export default{foo:3,bar:()=>4,get baz(){return this.foo}};" } concise_methods_with_computed_property2: { options = { arrows: true, evaluate: true, } input: { var foo = { [[1]](v) { return v; } }; console.log(foo[[1]]("PASS")); } expect_exact: 'var foo={[[1]]:v=>v};console.log(foo[[1]]("PASS"));' expect_stdout: "PASS" } async_object_literal: { options = { arrows: true, unsafe_arrows: true, ecma: 6, evaluate: true, } input: { var obj = { async a() { return await foo(1 + 0); }, anon: async function() { return await foo(2 + 0); } }; } expect: { var obj = { a: async () => await foo(1), anon: async () => await foo(2) }; } } issue_2271: { options = { arrows: true, ecma: 6, evaluate: true, unsafe_arrows: false, } input: { var Foo = function() {}; Foo.prototype.set = function(value) { this.value = value; return this; } Foo.prototype.print = function() { console.log(this.value); } new Foo().set("PASS").print(); } expect: { var Foo = function() {}; Foo.prototype.set = function(value) { this.value = value; return this; } Foo.prototype.print = function() { console.log(this.value); } new Foo().set("PASS").print(); } expect_stdout: "PASS" } concise_method_with_super: { options = { arrows: true, } input: { var o = { f: "FAIL", g() { return super.f; } } Object.setPrototypeOf(o, { f: "PASS" }); console.log(o.g()); } expect: { var o = { f: "FAIL", g() { return super.f; } } Object.setPrototypeOf(o, { f: "PASS" }); console.log(o.g()); } expect_stdout: "PASS" } issue_3092a: { options = { arrows: true, } input: { console.log({ *gen(x) { return (yield x.toUpperCase()), 2; } }.gen("pass").next().value); } expect: { console.log({ *gen(x) { return yield x.toUpperCase(), 2; } }.gen("pass").next().value); } expect_stdout: "PASS" } issue_3092b: { options = { arrows: true, } input: { var obj = { async bar(x) { return (await x), 2; }, *gen(x) { return (yield x.toUpperCase()), 2; }, }; console.log(obj.gen("pass").next().value); } expect: { var obj = { bar: async x => (await x, 2), * gen(x) { return yield x.toUpperCase(), 2; } }; console.log(obj.gen("pass").next().value); } expect_stdout: "PASS" node_version: ">=8" } terser-4.1.2/test/compress/ascii.js000066400000000000000000000030211351061312300172510ustar00rootroot00000000000000ascii_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\'}' } terser-4.1.2/test/compress/asm.js000066400000000000000000000116421351061312300167510ustar00rootroot00000000000000asm_mixed: { 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: 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; var sum = 0, p = 0, q = 0; for (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;' } terser-4.1.2/test/compress/assignment.js000066400000000000000000000103601351061312300203350ustar00rootroot00000000000000op_equals_left_local_var: { options = { 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 = { 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 = { 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 = { 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; } } terser-4.1.2/test/compress/async.js000066400000000000000000000253201351061312300173040ustar00rootroot00000000000000await_precedence: { input: { async function f1() { await x + y; } async function f2() { await (x + y); } } expect_exact: "async function f1(){await x+y}async function f2(){await(x+y)}" } await_precedence_prop: { input: { async function f1(){ return (await foo()).bar; } async function f2(){ return (await foo().bar); } } expect_exact: "async function f1(){return(await foo()).bar}async function f2(){return await foo().bar}" } await_precedence_call: { input: { async function f3(){ return (await foo())(); } async function f4(){ return await (foo()()); } } expect_exact: "async function f3(){return(await foo())()}async function f4(){return await foo()()}" } async_function_declaration: { options = { side_effects: true, unused: true, } input: { async function f0() {} async function f1() { await x + y; } async function f2() { await (x + y); } async function f3() { await x + await y; } async function f4() { await (x + await y); } async function f5() { await x; await y; } async function f6() { await x, await y; } } expect: { async function f0() {} async function f1() { await x, y; } async function f2() { await (x + y); } async function f3() { await x, await y; } async function f4() { await (x + await y); } async function f5() { await x; await y; } async function f6() { await x, await y; } } } async_function_expression: { options = { evaluate: true, side_effects: true, unused: true, } input: { var named = async function foo() { await bar(1 + 0) + (2 + 0); } var anon = async function() { await (1 + 0) + bar(2 + 0); } } expect: { var named = async function() { await bar(1); }; var anon = async function() { await 1, bar(2); }; } } async_class: { options = { evaluate: true, } input: { class Foo { async m1() { return await foo(1 + 2); } static async m2() { return await foo(3 + 4); } } } expect: { class Foo { async m1() { return await foo(3); } static async m2() { return await foo(7); } } } } async_object_literal: { options = { evaluate: true, } input: { var obj = { async a() { await foo(1 + 0); }, anon: async function(){ await foo(2 + 0); } }; } expect: { var obj = { async a() { await foo(1); }, anon: async function() { await foo(2); } }; } } async_export: { input: { export async function run() {}; export default async function def() {}; } expect: { export async function run() {}; export default async function def() {}; } } async_inline: { options = { collapse_vars: true, conditionals: true, evaluate: true, inline: true, negate_iife: true, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { (async function(){ return await 3; })(); (async function(x){ await console.log(x); })(4); function echo(x) { return x; } echo( async function(){ return await 1; }() ); echo( async function(x){ await console.log(x); }(2) ); function top() { console.log("top"); } top(); async function async_top() { console.log("async_top"); } async_top(); } expect: { !async function(){await 3}(); !async function(x){await console.log(4)}(); function echo(x){return x} echo(async function(){return await 1}()); echo(async function(x){await console.log(2)}()); console.log("top"); !async function(){console.log("async_top")}(); } expect_stdout: [ "4", "2", "top", "async_top", ] node_version: ">=8" } async_identifiers: { input: { var async = function(x){ console.log("async", x); }; var await = function(x){ console.log("await", x); }; async(1); await(2); } expect: { var async = function(x){ console.log("async", x); }; var await = function(x){ console.log("await", x); }; async(1); await(2); } expect_stdout: [ "async 1", "await 2", ] } async_shorthand_property: { mangle = { toplevel: true, } input: { function print(o) { console.log(o.async + " " + o.await); } var async = "Async", await = "Await"; print({ async }); print({ await }); print({ async, await }); print({ await, async }); print({ async: async }); print({ await: await }); print({ async: async, await: await }); print({ await: await, async: async }); } expect: { function a(a) { console.log(a.async + " " + a.await); } var n = "Async", c = "Await"; a({ async: n }); a({ await: c }); a({ async: n, await: c }); a({ await: c, async: n }); a({ async: n }); a({ await: c }); a({ async: n, await: c }); a({ await: c, async: n }); } expect_stdout: [ "Async undefined", "undefined Await", "Async Await", "Async Await", "Async undefined", "undefined Await", "Async Await", "Async Await", ] } async_arrow: { input: { let a1 = async x => await foo(x); let a2 = async () => await bar(); let a3 = async (x) => await baz(x); let a4 = async (x, y) => { await far(x, y); } let a5 = async ({x = [1], y: z = 2}) => { await wow(x, z); } } expect: { let a1 = async x => await foo(x); let a2 = async () => await bar(); let a3 = async (x) => await baz(x); let a4 = async (x, y) => { await far(x, y); } let a5 = async ({x = [1], y: z = 2}) => { await wow(x, z); } } } async_arrow_wait: { input: { var a = async (x, y) => await x(y); } expect_exact: "var a=async(x,y)=>await x(y);" } async_arrow_iife: { input: { (async () => { await fetch({}); })(); } expect_exact: "(async()=>{await fetch({})})();" } async_arrow_iife_negate_iife: { options = { negate_iife: true, } input: { (async () => { await fetch(); })(); (() => { plain(); })(); } expect_exact: "(async()=>{await fetch()})();(()=>{plain()})();" } issue_2344_1: { beautify = { safari10: false, } input: { async () => { +await x; await y; return await z; }; } expect_exact: "async()=>{+await x;await y;return await z};" } issue_2344_2: { beautify = { safari10: true, } input: { async () => { +await x; await y; return await z; }; } expect_exact: "async()=>{+(await x);await y;return await z};" } issue_3079: { input: { async => 1; var async = async => async; console.log(async(1)); async = (async) => async; console.log(async(2)); console.log({ m: async => async ? "3" : "4" }.m(true)); } expect: { async => 1; var async = async => async; console.log(async(1)); async = (async) => async; console.log(async(2)); console.log({ m: async => async ? "3" : "4" }.m(true)); } expect_stdout: [ "1", "2", "3", ] } issue_3079_2: { input: { async async => async; async (async) => async; } expect_exact: "async async=>async;async async=>async;" } for_await_of: { input: { async function f(x) { for await (a of x) {} for await (var b of x) {} for await (let c of x) {} for await (const d of x) {} } } expect_exact: "async function f(x){for await(a of x);for await(var b of x);for await(let c of x);for await(const d of x);}" } for_await_of_2: { options = {} input: { async function foo(x) { for await (a of x) {} for await (var b of x) {} for await (let c of x) {} for await (const d of x) {} } const bar = async x => { for await (a of x) {} for await (var b of x) {} for await (let c of x) {} for await (const d of x) {} } } expect: { async function foo(x) { for await (a of x) ; for await (var b of x) ; for await (let c of x) ; for await (const d of x) ; } const bar = async x => { for await (a of x) ; for await (var b of x) ; for await (let c of x) ; for await (const d of x) ; } } } issue_87: { input: { function async(async) { console.log(async[0], async.prop) } async({0: 1, prop: 2}) } expect_stdout: [ "1 2" ] } async_generator_function: { options = { defaults: true, } input: { async function* baz() { yield await Promise.resolve(1); } } expect_exact: "async function*baz(){yield await Promise.resolve(1)}" } async_generator_class_method: { options = { defaults: true, } input: { class Foo { async* bar() { yield await Promise.resolve(2); } } } expect_exact: "class Foo{async*bar(){yield await Promise.resolve(2)}}" } async_generator_static_class_method: { options = { defaults: true, } input: { class Foo { static async* bar() { yield await Promise.resolve(4); } } } expect_exact: "class Foo{static async*bar(){yield await Promise.resolve(4)}}" } async_generator_object_literal_method: { options = { defaults: true, } input: { foo({ baz: 4, async* bar() { yield await Promise.resolve(3); }, qux, }); } expect_exact: "foo({baz:4,async*bar(){yield await Promise.resolve(3)},qux:qux});" } terser-4.1.2/test/compress/big_int.js000066400000000000000000000006221351061312300176000ustar00rootroot00000000000000big_int_positive: { input: { 1000n } expect_exact: "1000n;" } big_int_negative: { input: { -15n } expect_exact: "-15n;" } big_int_hex: { input: { 0x20n } expect_exact: "0x20n;" } big_int_binary: { input: { 0b101n } expect_exact: "0b101n;" } big_int_octal: { input: { 0o7n } expect_exact: "0o7n;" } terser-4.1.2/test/compress/block-scope.js000066400000000000000000000125411351061312300203710ustar00rootroot00000000000000 let_statement: { input: { let x = 6; } expect_exact: "let x=6;" } do_not_hoist_let: { options = { hoist_vars: true, }; input: { function x() { if (FOO) { let let1; let let2; var var1; var var2; } } } expect: { function x() { var var1, var2; if (FOO) { let let1; let let2; } } } } do_not_remove_anon_blocks_if_they_have_decls: { input: { function x() { { let x; } { var x; } { const y = 1; class Zee {}; } } { let y; } { var y; } } expect: { function x(){ { let x } var x; { const y = 1; class Zee {} } } { let y } var y; } } remove_unused_in_global_block: { options = { unused: true, } input: { { let x; const y = 1; class Zee {}; var w; } let ex; const why = 2; class Zed {}; var wut; console.log(x, y, Zee); } expect: { var w; let ex; const why = 2; class Zed {}; var wut; console.log(x, y, Zee); } } regression_block_scope_resolves: { mangle = { }; options = { dead_code: false }; input: { (function () { if (1) { let x; const y = 1; class Zee {}; } if (1) { let ex; const why = 2; class Zi {}; } console.log(typeof x, typeof y, typeof Zee, typeof ex, typeof why, typeof Zi); }()); } expect: { (function () { if (1) { let e; const o = 1; class t {}; } if (1) { let e; const o = 2; class t {}; } console.log(typeof x, typeof y, typeof Zee, typeof ex, typeof why, typeof Zi); }()); } expect_stdout: "undefined undefined undefined undefined undefined undefined" } switch_block_scope_mangler: { mangle = {} input: { var fn = function(code) { switch (code) { case 1: let apple = code + 1; let dog = code + 4; console.log(apple, dog); break; case 2: let banana = code + 2; console.log(banana); break; default: let cat = code + 3; console.log(cat); } }; fn(1); fn(2); fn(3); } expect: { var fn = function(e) { switch (e) { case 1: let l = e + 1 let o = e + 4; console.log(l, o); break; case 2: let n = e + 2; console.log(n); break; default: let c = e + 3; console.log(c); } }; fn(1); fn(2); fn(3); } expect_stdout: [ "2 5", "4", "6", ] } issue_241: { options = { defaults: true, } input: { var a = {}; (function(global) { function fail(o) { var result = {}; function inner() { return outer({ one: o.one, two: o.two }); } result.inner = function() { return inner(); }; return result; } function outer(o) { var ret; if (o) { ret = o.one; } else { ret = o.two; } return ret; } global.fail = fail; })(a); var b = a.fail({}); b.inner(); } expect: { var a = {}; a.fail = function (o) { var result = {}; return result.inner = function () { return function (o) { return o ? o.one : o.two; }({one: o.one, two: o.two}); }, result; }; var b = a.fail({}); b.inner(); } } issue_334: { options = { defaults: true, toplevel: true }; input: { (function (A) { (function () { doPrint(); })(); function doPrint() { print(A); } }("Hello World!")); function print(A) { if (!A.x) { console.log(A); } } } expect: { var A; (A="Hello World!").x || console.log(A); } expect_stdout: "Hello World!"; } terser-4.1.2/test/compress/blocks.js000066400000000000000000000076371351061312300174570ustar00rootroot00000000000000remove_blocks: { input: { {;} foo(); {}; { {}; }; bar(); {} } expect: { foo(); bar(); } } keep_some_blocks: { input: { // 1. if (foo) { {{{}}} if (bar) { baz(); } {{}} } else { stuff(); } // 2. if (foo) { for (var i = 0; i < 5; ++i) if (bar) baz(); } else { stuff(); } } expect: { // 1. if (foo) { if (bar) baz(); } else stuff(); // 2. if (foo) { for (var i = 0; i < 5; ++i) if (bar) baz(); } else stuff(); } } issue_1664: { input: { var a = 1; function f() { if (undefined) a = 2; { function undefined() {} undefined(); } } f(); console.log(a); } expect: { var a = 1; function f() { if (undefined) a = 2; { function undefined() {} undefined(); } } f(); console.log(a); } expect_stdout: "1" reminify: false // FIXME - block scoped function } issue_1672_for: { input: { switch (function() { return xxx; }) { case xxx: for (; console.log("FAIL");) { function xxx() {} } break; } } expect: { switch (function() { return xxx; }) { case xxx: for (; console.log("FAIL");) { function xxx() {} } break; } } expect_stdout: true } issue_1672_for_strict: { input: { "use strict"; switch (function() { return xxx; }) { case xxx: for (; console.log("FAIL");) { function xxx() {} } break; } } expect: { "use strict"; switch (function() { return xxx; }) { case xxx: for (; console.log("FAIL");) { function xxx() {} } break; } } expect_stdout: true } issue_1672_if: { input: { switch (function() { return xxx; }) { case xxx: if (console.log("FAIL")) { function xxx() {} } break; } } expect: { switch (function() { return xxx; }) { case xxx: if (console.log("FAIL")) function xxx() {} break; } } expect_stdout: true } issue_1672_if_strict: { input: { "use strict"; switch (function() { return xxx; }) { case xxx: if (console.log("FAIL")) { function xxx() {} } break; } } expect: { "use strict"; switch (function() { return xxx; }) { case xxx: if (console.log("FAIL")) { function xxx() {} } break; } } expect_stdout: true } issue_2946_else_const: { input: { if (1) { const x = 6; } else { const y = 12; } if (2) { let z = 24; } else { let w = 48; } if (3) { class X {} } else { class Y {} } } expect: { if (1) { const x = 6; } else { const y = 12; } if (2) { let z = 24; } else { let w = 48; } if (3) { class X {} } else { class Y {} } } } terser-4.1.2/test/compress/collapse_vars.js000066400000000000000000004030171351061312300210270ustar00rootroot00000000000000collapse_vars_side_effects_1: { 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, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { function f1() { var e = 7; var s = "abcdef"; var i = 2; var log = console.log.bind(console); var x = s.charAt(i++); var y = s.charAt(i++); var z = s.charAt(i++); log(x, y, z, e); } function f2() { var e = 7; var log = console.log.bind(console); var s = "abcdef"; var i = 2; var x = s.charAt(i++); var y = s.charAt(i++); var z = s.charAt(i++); log(x, i, y, z, e); } function f3() { var e = 7; var s = "abcdef"; var i = 2; var log = console.log.bind(console); var x = s.charAt(i++); var y = s.charAt(i++); var z = s.charAt(i++); log(x, z, y, e); } function f4() { var log = console.log.bind(console), i = 10, x = i += 2, y = i += 3, z = i += 4; log(x, z, y, i); } f1(), f2(), f3(), f4(); } expect: { function f1() { var s = "abcdef", i = 2; console.log.bind(console)(s.charAt(i++), s.charAt(i++), s.charAt(i++), 7); } function f2() { var s = "abcdef", i = 2; console.log.bind(console)(s.charAt(i++), 5, s.charAt(i++), s.charAt(i++), 7); } function f3() { var s = "abcdef", i = 2, log = console.log.bind(console), x = s.charAt(i++), y = s.charAt(i++); log(x, s.charAt(i++), y, 7); } function f4() { var i = 10, x = i += 2, y = i += 3; console.log.bind(console)(x, i += 4, y, 19); } f1(), f2(), f3(), f4(); } expect_stdout: true } collapse_vars_side_effects_2: { 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: true, side_effects: true, unused: true, } input: { function fn(x) { return console.log(x), x; } function p1() { var a = foo(), b = bar(), c = baz(); return a + b + c; } function p2() { var a = foo(), c = bar(), b = baz(); return a + b + c; } function p3() { var b = foo(), a = bar(), c = baz(); return a + b + c; } function p4() { var b = foo(), c = bar(), a = baz(); return a + b + c; } function p5() { var c = foo(), a = bar(), b = baz(); return a + b + c; } function p6() { var c = foo(), b = bar(), a = baz(); return a + b + c; } function q1() { var a = foo(), b = bar(), c = baz(); return fn(a + b + c); } function q2() { var a = foo(), c = bar(), b = baz(); return fn(a + b + c); } function q3() { var b = foo(), a = bar(), c = baz(); return fn(a + b + c); } function q4() { var b = foo(), c = bar(), a = baz(); return fn(a + b + c); } function q5() { var c = foo(), a = bar(), b = baz(); return fn(a + b + c); } function q6() { var c = foo(), b = bar(), a = baz(); return fn(a + b + c); } function r1() { var a = foo(), b = bar(), c = baz(); return fn(a) + fn(b) + fn(c); } function r2() { var a = foo(), c = bar(), b = baz(); return fn(a) + fn(b) + fn(c); } function r3() { var b = foo(), a = bar(), c = baz(); return fn(a) + fn(b) + fn(c); } function r4() { var b = foo(), c = bar(), a = baz(); return fn(a) + fn(b) + fn(c); } function r5() { var c = foo(), a = bar(), b = baz(); return fn(a) + fn(b) + fn(c); } function r6() { var c = foo(), b = bar(), a = baz(); return fn(a) + fn(b) + fn(c); } function s1() { var a = foo(), b = bar(), c = baz(); return g(a + b + c); } function s6() { var c = foo(), b = bar(), a = baz(); return g(a + b + c); } function t1() { var a = foo(), b = bar(), c = baz(); return g(a) + g(b) + g(c); } function t6() { var c = foo(), b = bar(), a = baz(); return g(a) + g(b) + g(c); } } expect: { function fn(x) { return console.log(x), x; } function p1() { return foo() + bar() + baz(); } function p2() { var a = foo(), c = bar(); return a + baz() + c; } function p3() { var b = foo(); return bar() + b + baz(); } function p4() { var b = foo(), c = bar(); return baz() + b + c; } function p5() { var c = foo(); return bar() + baz() + c; } function p6() { var c = foo(), b = bar(); return baz() + b + c; } function q1() { return fn(foo() + bar() + baz()); } function q2() { var a = foo(), c = bar(); return fn(a + baz() + c); } function q3() { var b = foo(); return fn(bar() + b + baz()); } function q4() { var b = foo(), c = bar(); return fn(baz() + b + c); } function q5() { var c = foo(); return fn(bar() + baz() + c); } function q6() { var c = foo(), b = bar(); return fn(baz() + b + c); } function r1() { var a = foo(), b = bar(), c = baz(); return fn(a) + fn(b) + fn(c); } function r2() { var a = foo(), c = bar(), b = baz(); return fn(a) + fn(b) + fn(c); } function r3() { var b = foo(), a = bar(), c = baz(); return fn(a) + fn(b) + fn(c); } function r4() { var b = foo(), c = bar(); return fn(baz()) + fn(b) + fn(c); } function r5() { var c = foo(), a = bar(), b = baz(); return fn(a) + fn(b) + fn(c); } function r6() { var c = foo(), b = bar(); return fn(baz()) + fn(b) + fn(c); } function s1() { var a = foo(), b = bar(), c = baz(); return g(a + b + c); } function s6() { var c = foo(), b = bar(), a = baz(); return g(a + b + c); } function t1() { var a = foo(), b = bar(), c = baz(); return g(a) + g(b) + g(c); } function t6() { var c = foo(), b = bar(), a = baz(); return g(a) + g(b) + g(c); } } } collapse_vars_issue_721: { 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, passes: 2, properties: true, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { define(["require", "exports", 'handlebars'], function (require, exports, hb) { var win = window; var _hb = win.Handlebars = hb; return _hb; }); def(function (hb) { var win = window; var prop = 'Handlebars'; var _hb = win[prop] = hb; return _hb; }); def(function (hb) { var prop = 'Handlebars'; var win = window; var _hb = win[prop] = hb; return _hb; }); def(function (hb) { var prop = 'Handlebars'; var win = g(); var _hb = win[prop] = hb; return _hb; }); def(function (hb) { var prop = g1(); var win = g2(); var _hb = win[prop] = hb; return _hb; }); def(function (hb) { var win = g2(); var prop = g1(); var _hb = win[prop] = hb; return _hb; }); } expect: { define([ "require", "exports", "handlebars" ], function(require, exports, hb) { return window.Handlebars = hb; }), def(function(hb) { return window.Handlebars = hb; }), def(function(hb) { return window.Handlebars = hb; }), def(function (hb) { return g().Handlebars = hb; }), def(function (hb) { var prop = g1(); return g2()[prop] = hb; }), def(function (hb) { return g2()[g1()] = hb; }); } } collapse_vars_properties: { 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, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { function f1(obj) { var prop = 'LiteralProperty'; return !!-+obj[prop]; } function f2(obj) { var prop1 = 'One'; var prop2 = 'Two'; return ~!!-+obj[prop1 + prop2]; } } expect: { function f1(obj) { return !!-+obj.LiteralProperty; } function f2(obj) { return ~!!-+obj.OneTwo; } } } collapse_vars_if: { 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, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { function f1() { var not_used = sideeffect(), x = g1 + g2; var y = x / 4, z = 'Bar' + y; if ('x' != z) { return g9; } else return g5; } function f2() { var x = g1 + g2, not_used = sideeffect(); var y = x / 4 var z = 'Bar' + y; if ('x' != z) { return g9; } else return g5; } function f3(x) { if (x) { var a = 1; return a; } else { var b = 2; return b; } } } expect: { function f1() { sideeffect(); return "x" != "Bar" + (g1 + g2) / 4 ? g9 : g5; } function f2() { var x = g1 + g2; sideeffect(); return "x" != "Bar" + x / 4 ? g9 : g5; } function f3(x) { if (x) { return 1; } return 2; } } } collapse_vars_while: { 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: false, properties: true, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { function f1(y) { // Neither the non-constant while condition `c` will be // replaced, nor the non-constant `x` in the body. var x = y, c = 3 - y; while (c) { return x; } var z = y * y; return z; } function f2(y) { // The constant `x` will be replaced in the while body. var x = 7; while (y) { return x; } var z = y * y; return z; } function f3(y) { // The non-constant `n` will not be replaced in the while body. var n = 5 - y; while (y) { return n; } var z = y * y; return z; } } expect: { function f1(y) { var x = y, c = 3 - y; while (c) return x; return y * y; } function f2(y) { while (y) return 7; return y * y } function f3(y) { var n = 5 - y; while (y) return n; return y * y; } } } collapse_vars_do_while: { options = { booleans: false, 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: false, properties: true, sequences: true, side_effects: true, unused: "keep_assign", } input: { function f1(y) { // The constant do-while condition `c` will not be replaced. var c = 9; do {} while (c === 77); } function f2(y) { // The non-constant do-while condition `c` will not be replaced. var c = 5 - y; do { } while (c); } function f3(y) { // The constant `x` will be replaced in the do loop body. function fn(n) { console.log(n); } var a = 2, x = 7; do { fn(a = x); break; } while (y); } function f4(y) { // The non-constant `a` will not be replaced in the do loop body. var a = y / 4; do { return a; } while (y); } function f5(y) { function p(x) { console.log(x); } do { // The non-constant `a` will be replaced in p(a) // because it is declared in same block. var a = y - 3; p(a); } while (--y); } } expect: { function f1(y) { var c = 9; do ; while (77 === c); } function f2(y) { var c = 5 - y; do ; while (c); } function f3(y) { function fn(n) { console.log(n); } var a = 2, x = 7; do { fn(a = x); break; } while (y); } function f4(y) { var a = y / 4; do return a; while (y); } function f5(y) { function p(x) { console.log(x); } do { p(y - 3); } while (--y); } } } collapse_vars_do_while_drop_assign: { options = { booleans: false, 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: false, properties: true, sequences: true, side_effects: true, unused: true, } input: { function f1(y) { // The constant do-while condition `c` will be not replaced. var c = 9; do {} while (c === 77); } function f2(y) { // The non-constant do-while condition `c` will not be replaced. var c = 5 - y; do { } while (c); } function f3(y) { // The constant `x` will be replaced in the do loop body. function fn(n) { console.log(n); } var a = 2, x = 7; do { fn(a = x); break; } while (y); } function f4(y) { // The non-constant `a` will not be replaced in the do loop body. var a = y / 4; do { return a; } while (y); } function f5(y) { function p(x) { console.log(x); } do { // The non-constant `a` will be replaced in p(a) // because it is declared in same block. var a = y - 3; p(a); } while (--y); } } expect: { function f1(y) { var c = 9; do ; while (77 === c); } function f2(y) { var c = 5 - y; do ; while (c); } function f3(y) { function fn(n) { console.log(n); } var x = 7; do { fn(x); break; } while (y); } function f4(y) { var a = y / 4; do return a; while (y); } function f5(y) { function p(x) { console.log(x); } do { p(y - 3); } while (--y); } } } collapse_vars_seq: { 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: true, side_effects: true, unused: true, } input: { var f1 = function(x, y) { var a, b, r = x + y, q = r * r, z = q - r; a = z, b = 7; return a + b; }; console.log(f1(1, 2)); } expect: { var f1 = function(x, y) { var r = x + y; return r * r - r + 7; }; console.log(f1(1, 2)); } expect_stdout: "13" } collapse_vars_throw: { 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: true, side_effects: true, unused: true, } input: { var f1 = function(x, y) { var a, b, r = x + y, q = r * r, z = q - r; a = z, b = 7; throw a + b; }; try { f1(1, 2); } catch (e) { console.log(e); } } expect: { var f1 = function(x, y) { var r = x + y; throw r * r - r + 7; }; try { f1(1, 2); } catch (e) { console.log(e); } } expect_stdout: "13" } collapse_vars_switch: { 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: true, side_effects: true, unused: true, } input: { function f1() { var not_used = sideeffect(), x = g1 + g2; var y = x / 4, z = 'Bar' + y; switch (z) { case 0: return g9; } } function f2() { var x = g1 + g2, not_used = sideeffect(); var y = x / 4 var z = 'Bar' + y; switch (z) { case 0: return g9; } } function f3(x) { switch(x) { case 1: var a = 3 - x; return a; } } } expect: { function f1() { sideeffect(); switch ("Bar" + (g1 + g2) / 4) { case 0: return g9 } } function f2() { var x = g1 + g2; sideeffect(); switch ("Bar" + x / 4) { case 0: return g9 } } function f3(x) { // verify no extraneous semicolon in case block before return // when the var definition was eliminated switch(x) { case 1: return 3 - x; } } } } collapse_vars_assignment: { options = { booleans: true, collapse_vars: true, comparisons: true, conditionals: true, evaluate: true, hoist_funs: true, if_return: true, join_vars: true, keep_fargs: true, loops: true, properties: true, sequences: true, side_effects: true, unused: true, } input: { function log(x) { return console.log(x), x; } function f0(c) { var a = 3 / c; return a = a; } function f1(c) { const a = 3 / c; const b = 1 - a; return b; } function f2(c) { var a = 3 / c; var b = a - 7; return log(c = b); } function f3(c) { var a = 3 / c; var b = a - 7; return log(c |= b); } function f4(c) { var a = 3 / c; var b = 2; return log(b += a); } function f5(c) { var b = 2; var a = 3 / c; return log(b += a); } function f6(c) { var b = g(); var a = 3 / c; return log(b += a); } } expect: { function log(x) { return console.log(x), x; } function f0(c) { var a = 3 / c; return a = a; } function f1(c) { return 1 - 3 / c; } function f2(c) { return log(c = 3 / c - 7); } function f3(c) { return log(c |= 3 / c - 7); } function f4(c) { var b = 2; return log(b += 3 / c); } function f5(c) { var b = 2; return log(b += 3 / c); } function f6(c) { var b = g(); return log(b += 3 / c); } } } collapse_vars_lvalues: { options = { booleans: true, collapse_vars: true, comparisons: true, conditionals: true, evaluate: true, hoist_funs: true, if_return: true, join_vars: true, keep_fargs: true, loops: true, properties: true, sequences: true, side_effects: true, unused: "keep_assign", } input: { function f0(x) { var i = ++x; return x += i; } function f1(x) { var a = (x -= 3); return x += a; } function f2(x) { var z = x, a = ++z; return z += a; } function f3(x) { var a = (x -= 3), b = x + a; return b; } function f4(x) { var a = (x -= 3); return x + a; } function f5(x) { var w = e1(), v = e2(), c = v = --x, b = w = x; return b - c; } function f6(x) { var w = e1(), v = e2(), c = v = --x, b = w = x; return c - b; } function f7(x) { var w = e1(), v = e2(), c = v - x, b = w = x; return b - c; } function f8(x) { var w = e1(), v = e2(), b = w = x, c = v - x; return b - c; } function f9(x) { var w = e1(), v = e2(), b = w = x, c = v - x; return c - b; } } expect: { function f0(x) { var i = ++x; return x += i; } function f1(x) { var a = (x -= 3); return x += a; } function f2(x) { var z = x, a = ++z; return z += a; } function f3(x) { var a = (x -= 3); return x + a; } function f4(x) { var a = (x -= 3); return x + a; } function f5(x) { var w = e1(), v = e2(), c = v = --x; return (w = x) - c; } function f6(x) { var w = e1(), v = e2(); return (v = --x) - (w = x); } function f7(x) { var w = e1(); return (w = x) - (e2() - x); } function f8(x) { var w = e1(); return (w = x) - (e2() - x); } function f9(x) { var w = e1(); return e2() - x - (w = x); } } } collapse_vars_lvalues_drop_assign: { options = { booleans: true, collapse_vars: true, comparisons: true, conditionals: true, evaluate: true, hoist_funs: true, if_return: true, join_vars: true, keep_fargs: true, loops: true, passes: 3, properties: true, sequences: true, side_effects: true, unused: true, } input: { function f0(x) { var i = ++x; return x += i; } function f1(x) { var a = (x -= 3); return x += a; } function f2(x) { var z = x, a = ++z; return z += a; } function f3(x) { var a = (x -= 3), b = x + a; return b; } function f4(x) { var a = (x -= 3); return x + a; } function f5(x) { var w = e1(), v = e2(), c = v = --x, b = w = x; return b - c; } function f6(x) { var w = e1(), v = e2(), c = v = --x, b = w = x; return c - b; } function f7(x) { var w = e1(), v = e2(), c = v - x, b = w = x; return b - c; } function f8(x) { var w = e1(), v = e2(), b = w = x, c = v - x; return b - c; } function f9(x) { var w = e1(), v = e2(), b = w = x, c = v - x; return c - b; } } expect: { function f0(x) { var i = ++x; return x += i; } function f1(x) { var a = (x -= 3); return x += a; } function f2(x) { var z = x, a = ++z; return z += a; } function f3(x) { var a = (x -= 3); return x + a; } function f4(x) { var a = (x -= 3); return x + a; } function f5(x) { e1(), e2(); var c = --x; return x - c; } function f6(x) { return e1(), e2(), --x - x; } function f7(x) { return e1(), x - (e2() - x); } function f8(x) { return e1(), x - (e2() - x); } function f9(x) { return e1(), e2() - x - x; } } } collapse_vars_misc1: { options = { booleans: true, collapse_vars: true, comparisons: true, conditionals: true, evaluate: true, hoist_funs: true, if_return: true, join_vars: true, keep_fargs: true, loops: true, properties: true, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { function f0(o, a, h) { var b = 3 - a; var obj = o; var seven = 7; var prop = 'run'; var t = obj[prop](b)[seven] = h; return t; } function f1(x) { var y = 5 - x; return y; } function f2(x) { const z = foo(), y = z / (5 - x); return y; } function f3(x) { var z = foo(), y = (5 - x) / z; return y; } function f4(x) { var z = foo(), y = (5 - u) / z; return y; } function f5(x) { const z = foo(), y = (5 - window.x) / z; return y; } function f6() { var b = window.a * window.z; return b && zap(); } function f7() { var b = window.a * window.z; return b + b; } function f8() { var b = window.a * window.z; var c = b + 5; return b + c; } function f9() { var b = window.a * window.z; return bar() || b; } function f10(x) { var a = 5, b = 3; return a += b; } function f11(x) { var a = 5, b = 3; return a += --b; } } expect: { function f0(o, a, h) { var b = 3 - a; return o.run(b)[7] = h; } function f1(x) { return 5 - x } function f2(x) { return foo() / (5 - x) } function f3(x) { return (5 - x) / foo() } function f4(x) { var z = foo(); return (5 - u) / z } function f5(x) { const z = foo(); return (5 - window.x) / z } function f6() { return window.a * window.z && zap() } function f7() { var b = window.a * window.z; return b + b } function f8() { var b = window.a * window.z; return b + (b + 5) } function f9() { var b = window.a * window.z; return bar() || b } function f10(x) { var a = 5; return a += 3; } function f11(x) { var a = 5, b = 3; return a += --b; } } } collapse_vars_self_reference: { 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: true, side_effects: true, unused: false, } input: { // avoid bug in self-referential declaration. function f1() { var self = { inner: function() { return self; } }; } function f2() { var self = { inner: self }; } } expect: { // note: `unused` option is false function f1() { var self = { inner: function() { return self } }; } function f2() { var self = { inner: self }; } } } collapse_vars_repeated: { 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, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { function f1() { var dummy = 3, a = 5, unused = 2, a = 1, a = 3; return -a; } function f2(x) { var a = 3, a = x; return a; } (function(x){ var a = "GOOD" + x, e = "BAD", k = "!", e = a; console.log(e + k); })("!"), (function(x){ var a = "GOOD" + x, e = "BAD" + x, k = "!", e = a; console.log(e + k); })("!"); } expect: { function f1() { return -3; } function f2(x) { return x; } (function(x){ console.log("GOOD!!"); })(), (function(x){ console.log("GOOD!!"); })(); } expect_stdout: true } collapse_vars_closures: { 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, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { function constant_vars_can_be_replaced_in_any_scope() { var outer = 3; return function() { return outer; } } function non_constant_vars_can_only_be_replace_in_same_scope(x) { var outer = x; return function() { return outer; } } } expect: { function constant_vars_can_be_replaced_in_any_scope() { return function() { return 3 } } function non_constant_vars_can_only_be_replace_in_same_scope(x) { var outer = x return function() { return outer } } } } collapse_vars_unary: { 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: true, side_effects: true, unused: true, } input: { function f0(o, p) { var x = o[p]; return delete x; } function f1(n) { var k = !!n; return n > +k; } function f2(n) { // test unary with constant var k = 7; return k--; } function f3(n) { // test unary with constant var k = 7; return ++k; } function f4(n) { // test unary with non-constant var k = 8 - n; return k--; } function f5(n) { // test unary with non-constant var k = 9 - n; return ++k; } } expect: { function f0(o, p) { var x = o[p]; return delete x; } function f1(n) { return n > +!!n } function f2(n) { var k = 7; return k-- } function f3(n) { var k = 7; return ++k } function f4(n) { var k = 8 - n; return k--; } function f5(n) { var k = 9 - n; return ++k; } } } collapse_vars_try: { 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, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { function f1() { try { var a = 1; return a; } catch (ex) { var b = 2; return b; } finally { var c = 3; return c; } } function f2() { var t = could_throw(); // shouldn't be replaced in try block try { return t + might_throw(); } catch (ex) { return 3; } } } expect: { function f1() { try { return 1; } catch (ex) { return 2; } finally { return 3; } } function f2() { var t = could_throw(); try { return t + might_throw(); } catch (ex) { return 3; } } } } collapse_vars_array: { 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: true, side_effects: true, unused: true, } input: { function f1(x, y) { var z = x + y; return [z]; } function f2(x, y) { var z = x + y; return [x, side_effect(), z]; } function f3(x, y) { var z = f(x + y); return [ [3], [z, x, y], [g()] ]; } } expect: { function f1(x, y) { return [x + y] } function f2(x, y) { var z = x + y return [x, side_effect(), z] } function f3(x, y) { return [ [3], [f(x + y), x, y], [g()] ] } } } collapse_vars_object: { 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: true, side_effects: true, unused: true, } input: { function f0(x, y) { var z = x + y; return { get b() { return 7; }, r: z }; } function f1(x, y) { var z = x + y; return { r: z, get b() { return 7; } }; } function f2(x, y) { var z = x + y; var k = x - y; return { q: k, r: g(x), s: z }; } function f3(x, y) { var z = f(x + y); return [{ a: {q: x, r: y, s: z}, b: g() }]; } } expect: { function f0(x, y) { return { get b() { return 7; }, r: x + y }; } function f1(x, y) { return { r: x + y, get b() { return 7; } }; } function f2(x, y) { var z = x + y; return { q: x - y, r: g(x), s: z }; } function f3(x, y) { return [{ a: {q: x, r: y, s: f(x + y)}, b: g() }]; } } } collapse_vars_eval_and_with: { 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: { // Don't attempt to collapse vars in presence of eval() or with statement. (function f0() { var a = 2; console.log(a - 5); eval("console.log(a);"); })(); (function f1() { var o = {a: 1}, a = 2; with (o) console.log(a); })(); (function f2() { var o = {a: 1}, a = 2; return function() { with (o) console.log(a) }; })()(); } expect: { (function f0() { var a = 2; console.log(a - 5); eval("console.log(a);"); })(); (function f1() { var o = {a: 1}, a = 2; with(o) console.log(a); })(); (function f2() { var o = {a: 1}, a = 2; return function() { with (o) console.log(a) }; })()(); } expect_stdout: true } collapse_vars_constants: { 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, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: 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; })(); } function f3(x) { var a = 4, b = x.prop, c = 5, not_used = sideeffect1(); return b + (function() { return -a - c; })(); } } expect: { function f1(x) { var b = x.prop, d = sideeffect1(), e = sideeffect2(); return b + (function() { return d - 4 * e - 5; })(); } function f2(x) { var b = x.prop, e = (sideeffect1(), sideeffect2()); return b + (function() { return -4 * e - 5; })(); } function f3(x) { var b = x.prop; sideeffect1(); return b + (function() { return -9; })(); } } } collapse_vars_arguments: { 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, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, toplevel: true, unused: true, } input: { var outer = function() { // Do not replace `arguments` but do replace the constant `k` before it. var k = 7, arguments = 5, inner = function() { console.log(arguments); } inner(k, 1); } outer(); } expect: { (function() { (function(){console.log(arguments);})(7, 1); })(); } expect_stdout: true } collapse_vars_short_circuit: { 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: true, side_effects: true, unused: true, } input: { function f0(x) { var a = foo(), b = bar(); return b || x; } function f1(x) { var a = foo(), b = bar(); return b && x; } function f2(x) { var a = foo(), b = bar(); return x && a && b; } function f3(x) { var a = foo(), b = bar(); return a && x; } function f4(x) { var a = foo(), b = bar(); return a && x && b; } function f5(x) { var a = foo(), b = bar(); return x || a || b; } function f6(x) { var a = foo(), b = bar(); return a || x || b; } function f7(x) { var a = foo(), b = bar(); return a && b && x; } function f8(x,y) { var a = foo(), b = bar(); return (x || a) && (y || b); } function f9(x,y) { var a = foo(), b = bar(); return (x && a) || (y && b); } function f10(x,y) { var a = foo(), b = bar(); return (x - a) || (y - b); } function f11(x,y) { var a = foo(), b = bar(); return (x - b) || (y - a); } function f12(x,y) { var a = foo(), b = bar(); return (x - y) || (b - a); } function f13(x,y) { var a = foo(), b = bar(); return (a - b) || (x - y); } function f14(x,y) { var a = foo(), b = bar(); return (b - a) || (x - y); } } expect: { function f0(x) { foo(); return bar() || x; } function f1(x) { foo(); return bar() && x; } function f2(x) { var a = foo(), b = bar(); return x && a && b; } function f3(x) { var a = foo(); bar(); return a && x; } function f4(x) { var a = foo(), b = bar(); return a && x && b; } function f5(x) { var a = foo(), b = bar(); return x || a || b; } function f6(x) { var a = foo(), b = bar(); return a || x || b; } function f7(x) { var a = foo(), b = bar(); return a && b && x; } function f8(x,y) { var a = foo(), b = bar(); return (x || a) && (y || b); } function f9(x,y) { var a = foo(), b = bar(); return (x && a) || (y && b); } function f10(x,y) { var a = foo(), b = bar(); return (x - a) || (y - b); } function f11(x,y) { var a = foo(); return (x - bar()) || (y - a); } function f12(x,y) { var a = foo(), b = bar(); return (x - y) || (b - a); } function f13(x,y) { return (foo() - bar()) || (x - y); } function f14(x,y) { var a = foo(); return (bar() - a) || (x - y); } } } collapse_vars_short_circuited_conditions: { options = { booleans: true, collapse_vars: true, comparisons: false, conditionals: false, dead_code: true, evaluate: true, hoist_funs: true, if_return: false, join_vars: true, keep_fargs: true, loops: true, sequences: false, side_effects: true, unused: true, } input: { function c1(x) { var a = foo(), b = bar(), c = baz(); return a ? b : c; } function c2(x) { var a = foo(), b = bar(), c = baz(); return a ? c : b; } function c3(x) { var a = foo(), b = bar(), c = baz(); return b ? a : c; } function c4(x) { var a = foo(), b = bar(), c = baz(); return b ? c : a; } function c5(x) { var a = foo(), b = bar(), c = baz(); return c ? a : b; } function c6(x) { var a = foo(), b = bar(), c = baz(); return c ? b : a; } function i1(x) { var a = foo(), b = bar(), c = baz(); if (a) return b; else return c; } function i2(x) { var a = foo(), b = bar(), c = baz(); if (a) return c; else return b; } function i3(x) { var a = foo(), b = bar(), c = baz(); if (b) return a; else return c; } function i4(x) { var a = foo(), b = bar(), c = baz(); if (b) return c; else return a; } function i5(x) { var a = foo(), b = bar(), c = baz(); if (c) return a; else return b; } function i6(x) { var a = foo(), b = bar(), c = baz(); if (c) return b; else return a; } } expect: { function c1(x) { var a = foo(), b = bar(), c = baz(); return a ? b : c; } function c2(x) { var a = foo(), b = bar(), c = baz(); return a ? c : b; } function c3(x) { var a = foo(), b = bar(), c = baz(); return b ? a : c; } function c4(x) { var a = foo(), b = bar(), c = baz(); return b ? c : a; } function c5(x) { var a = foo(), b = bar(); return baz() ? a : b; } function c6(x) { var a = foo(), b = bar(); return baz() ? b : a; } function i1(x) { var a = foo(), b = bar(), c = baz(); if (a) return b; else return c; } function i2(x) { var a = foo(), b = bar(), c = baz(); if (a) return c; else return b; } function i3(x) { var a = foo(), b = bar(), c = baz(); if (b) return a; else return c; } function i4(x) { var a = foo(), b = bar(), c = baz(); if (b) return c; else return a; } function i5(x) { var a = foo(), b = bar(); if (baz()) return a; else return b; } function i6(x) { var a = foo(), b = bar(); if (baz()) return b; else return a; } } } collapse_vars_regexp: { 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: false, reduce_funcs: true, reduce_vars: true, side_effects: true, unused: true, } input: { function f1() { var k = 9; var rx = /[A-Z]+/; return [rx, k]; } function f2() { var rx = /ab*/g; return function(s) { return rx.exec(s); }; } (function() { var result; var s = 'acdabcdeabbb'; var rx = /ab*/g; while (result = rx.exec(s)) { console.log(result[0]); } })(); (function() { var result; var s = 'acdabcdeabbb'; var rx = f2(); while (result = rx(s)) { console.log(result[0]); } })(); } expect: { function f1() { return [/[A-Z]+/, 9]; } function f2() { var rx = /ab*/g; return function(s) { return rx.exec(s); }; } (function() { var result, rx = /ab*/g; while (result = rx.exec("acdabcdeabbb")) console.log(result[0]); })(); (function() { var result, rx = f2(); while (result = rx("acdabcdeabbb")) console.log(result[0]); })(); } expect_stdout: true } issue_1537: { options = { collapse_vars: true, toplevel: true, } input: { var k = ''; for (k in {prop: 'val'}){} } expect: { var k = ''; for (k in {prop: 'val'}); } } issue_1537_for_of: { options = { collapse_vars: true, toplevel: true, } input: { var k = ''; for (k of {prop: 'val'}){} } expect: { var k = ''; for (k of {prop: 'val'}); } } issue_1537_destructuring_1: { options = { collapse_vars: true, toplevel: true, } input: { var x = 1, y = 2; [x] = [y]; } expect: { var x = 1, y = 2; [x] = [y]; } } issue_1537_destructuring_2: { options = { collapse_vars: true, toplevel: true, } input: { var x = foo(); [x] = [1]; } expect: { var x = foo(); [x] = [1]; } } issue_1537_destructuring_3: { options = { collapse_vars: true, toplevel: true, } input: { var x = Math.random(); ({p: x = 9} = {v: 1}); } expect: { var x = Math.random(); ({p: x = 9} = {v: 1}); } } issue_1537_destructuring_for_in: { options = { collapse_vars: true, toplevel: true, } input: { var x = 1, y = 2; (function() { for ([[x], y] in a); })(); } expect: { var x = 1, y = 2; (function() { for ([[x], y] in a); })(); } } issue_1537_destructuring_for_of: { options = { collapse_vars: true, toplevel: true, } input: { var x = 1, y = 2; (function() { for ([[x], y] of a); })(); } expect: { var x = 1, y = 2; (function() { for ([[x], y] of a); })(); } } issue_1562: { options = { collapse_vars: true, evaluate: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var v = 1, B = 2; for (v in objs) f(B); var x = 3, C = 10; while(x + 2) bar(C); var y = 4, D = 20; do bar(D); while(y + 2); var z = 5, E = 30; for (; f(z + 2) ;) bar(E); } expect: { var v = 1; for (v in objs) f(2); while(5) bar(10); do bar(20); while(6); for (; f(7) ;) bar(30); } } issue_1605_1: { options = { collapse_vars: true, toplevel: false, unused: true, } input: { function foo(x) { var y = x; return y; } var o = new Object; o.p = 1; } expect: { function foo(x) { return x; } var o = new Object; o.p = 1; } } issue_1605_2: { options = { collapse_vars: true, toplevel: "vars", unused: true, } input: { function foo(x) { var y = x; return y; } var o = new Object; o.p = 1; } expect: { function foo(x) { return x; } (new Object).p = 1; } } issue_1631_1: { options = { collapse_vars: true, hoist_funs: true, join_vars: true, sequences: true, side_effects: true, } input: { var pc = 0; function f(x) { pc = 200; return 100; } function x() { var t = f(); pc += t; return pc; } console.log(x()); } expect: { function f(x) { return pc = 200, 100; } function x() { var t = f(); return pc += t; } var pc = 0; console.log(x()); } expect_stdout: "300" } issue_1631_2: { options = { collapse_vars: true, hoist_funs: true, join_vars: true, sequences: true, side_effects: true, } input: { var a = 0, b = 1; function f() { a = 2; return 4; } function g() { var t = f(); b = a + t; return b; } console.log(g()); } expect: { function f() { return a = 2, 4; } function g() { var t = f(); return b = a + t; } var a = 0, b = 1; console.log(g()); } expect_stdout: "6" } issue_1631_3: { options = { collapse_vars: true, hoist_funs: true, join_vars: true, sequences: true, side_effects: true, } input: { function g() { var a = 0, b = 1; function f() { a = 2; return 4; } var t = f(); b = a + t; return b; } console.log(g()); } expect: { function g() { function f() { return a = 2, 4; } var a = 0, b = 1, t = f(); return b = a + t; } console.log(g()); } expect_stdout: "6" } var_side_effects_1: { options = { collapse_vars: true, unused: true, } input: { var print = console.log.bind(console); function foo(x) { var twice = x * 2; print('Foo:', twice); } foo(10); } expect: { var print = console.log.bind(console); function foo(x) { print('Foo:', 2 * x); } foo(10); } expect_stdout: true } var_side_effects_2: { options = { collapse_vars: true, unused: true, } input: { var print = console.log.bind(console); function foo(x) { var twice = x.y * 2; print('Foo:', twice); } foo({ y: 10 }); } expect: { var print = console.log.bind(console); function foo(x) { var twice = 2 * x.y; print('Foo:', twice); } foo({ y: 10 }); } expect_stdout: true } var_side_effects_3: { options = { collapse_vars: true, pure_getters: true, unsafe: true, unused: true, } input: { var print = console.log.bind(console); function foo(x) { var twice = x.y * 2; print('Foo:', twice); } foo({ y: 10 }); } expect: { var print = console.log.bind(console); function foo(x) { print('Foo:', 2 * x.y); } foo({ y: 10 }); } expect_stdout: true } reduce_vars_assign: { options = { collapse_vars: true, reduce_funcs: true, reduce_vars: true, } input: { !function() { var a = 1; a = [].length, console.log(a); }(); } expect: { !function() { var a = 1; a = [].length, console.log(a); }(); } expect_stdout: "0" } iife_1: { options = { collapse_vars: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var log = function(x) { console.log(x); }, foo = bar(); log(foo); } expect: { (function(x) { console.log(x); })(bar()); } } iife_2: { options = { collapse_vars: true, reduce_funcs: false, reduce_vars: false, toplevel: true, unused: false, } input: { var foo = bar(); !function(x) { console.log(x); }(foo); } expect: { var foo; !function(x) { console.log(x); }(bar()); } } var_defs: { 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: true, side_effects: true, unused: true, } input: { var f1 = function(x, y) { var a, b, r = x + y, q = r * r, z = q - r, a = z, b = 7; console.log(a + b); }; f1("1", 0); } expect: { var f1 = function(x, y) { var r = x + y, a = r * r - r, b = 7; console.log(a + b); }; f1("1", 0); } expect_stdout: "97" } assignment: { options = { collapse_vars: true, unused: true, } input: { function f() { var a; a = x; return a; } } expect: { function f() { return x; } } } for_init: { options = { collapse_vars: true, unused: true, } input: { function f(x, y) { var a = x; var b = y; for (a; b;); } } expect: { function f(x, y) { var b = y; for (x; b;); } } } switch_case_1: { options = { collapse_vars: true, unused: true, } input: { function f(x, y, z) { var a = x(); var b = y(); var c = z; switch (a) { default: d(); case b: e(); case c: f(); } } } expect: { function f(x, y, z) { switch (x()) { default: d(); case y(): e(); case z: f(); } } } } switch_case_2: { options = { collapse_vars: true, } input: { var a = 1, b = 2; switch (b++) { case b: var c = a; var a; break; } console.log(a); } expect: { var a = 1, b = 2; switch (b++) { case b: var c = a; var a; break; } console.log(a); } expect_stdout: "1" } switch_case_3: { options = { collapse_vars: true, } input: { var a = 1, b = 2; switch (a) { case a: var b; break; case b: break; } console.log(b); } expect: { var a = 1, b = 2; switch (a) { case a: var b; break; case b: break; } console.log(b); } expect_stdout: "2" } issue_27: { options = { collapse_vars: true, unused: true, } input: { (function(jQuery) { var $; $ = jQuery; $("body").addClass("foo"); })(jQuery); } expect: { (function(jQuery) { jQuery("body").addClass("foo"); })(jQuery); } } modified: { options = { collapse_vars: true, unused: true, } input: { function f1(b) { var a = b; return b + a; } function f2(b) { var a = b; return b++ + a; } function f3(b) { var a = b++; return b + a; } function f4(b) { var a = b++; return b++ + a; } function f5(b) { var a = function() { return b; }(); return b++ + a; } console.log(f1(1), f2(1), f3(1), f4(1), f5(1)); } expect: { function f1(b) { return b + b; } function f2(b) { var a = b; return b++ + a; } function f3(b) { var a = b++; return b + a; } function f4(b) { var a = b++; return b++ + a; } function f5(b) { var a = function() { return b; }(); return b++ + a; } console.log(f1(1), f2(1), f3(1), f4(1), f5(1)); } expect_stdout: "2 2 3 3 2" } issue_1858: { options = { collapse_vars: true, pure_getters: true, unused: true, } input: { console.log(function(x) { var a = {}, b = a.b = x; return a.b + b; }(1)); } expect: { console.log(function(x) { var a = {}, b = a.b = 1; return a.b + b; }()); } expect_stdout: "2" } anonymous_function: { options = { collapse_vars: true, } input: { console.log(function f(a) { f ^= 0; return f * a; }(1)); } expect: { console.log(function f(a) { f ^= 0; return f * a; }(1)); } expect_stdout: true } side_effects_property: { options = { collapse_vars: true, } input: { var a = []; var b = 0; a[b++] = function() { return 42;}; var c = a[b++](); console.log(c); } expect: { var a = []; var b = 0; a[b++] = function() { return 42;}; var c = a[b++](); console.log(c); } expect_stdout: true } undeclared: { options = { collapse_vars: true, unused: true, } input: { function f(x, y) { var a; a = x; b = y; return b + a; } } expect: { function f(x, y) { b = y; return b + x; } } } ref_scope: { options = { collapse_vars: 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 function() { return a; }() + b; }()); } expect_stdout: true } chained_1: { options = { collapse_vars: true, unused: true, } input: { var a = 2; var a = 3 / a; console.log(a); } expect: { var a = 3 / (a = 2); console.log(a); } expect_stdout: true } chained_2: { options = { collapse_vars: true, unused: true, } input: { var a; var a = 2; a = 3 / a; console.log(a); } expect: { var a; a = 3 / (a = 2); console.log(a); } expect_stdout: true } chained_3: { options = { collapse_vars: true, unused: true, } input: { console.log(function(a, b) { var c = a, c = b; b++; return c; }(1, 2)); } expect: { console.log(function(a, b) { var c = 1; c = b; b++; return c; }(0, 2)); } expect_stdout: "2" } boolean_binary_1: { options = { collapse_vars: true, } input: { var a = 1; a++; (function() {} || a || 3).toString(); console.log(a); } expect: { var a = 1; a++; (function() {} || a || 3).toString(); console.log(a); } expect_stdout: true } boolean_binary_2: { options = { collapse_vars: true, } input: { var c = 0; c += 1; (function() { c = 1 + c; } || 9).toString(); console.log(c); } expect: { var c = 0; c += 1; (function() { c = 1 + c; } || 9).toString(); console.log(c); } expect_stdout: true } inner_lvalues: { options = { collapse_vars: true, unused: true, } input: { var a, b = 10; var a = (--b || a || 3).toString(), c = --b + -a; console.log(null, a, b); } expect: { var b = 10; var a = (--b || a || 3).toString(), c = --b + -a; console.log(null, a, b); } expect_stdout: true } double_def_1: { options = { collapse_vars: true, unused: true, } input: { var a = x, a = a && y; a(); } expect: { var a; (a = (a = x) && y)(); } } double_def_2: { options = { collapse_vars: true, toplevel: true, unused: true, } input: { var a = x, a = a && y; a(); } expect: { (x && y)(); } } toplevel_single_reference: { options = { collapse_vars: true, unused: true, } input: { var a; for (var b in x) { var a = b; b(a); } } expect: { for (var b in x) { var a; b(a = b); } } } unused_orig: { options = { collapse_vars: true, dead_code: true, passes: 2, reduce_funcs: true, reduce_vars: true, unused: true, } input: { var a = 1; console.log(function(b) { var a; var c = b; for (var d in c) { var a; return --b + c[0]; } try { } catch (e) { --b + a; } a && a.NaN; }([2]), a); } expect: { var a = 1; console.log(function(b) { var c = b; for (var d in c) { var a; return --b + c[0]; } a && a.NaN; }([2]), a); } expect_stdout: "3 1" } issue_315: { options = { collapse_vars: true, evaluate: true, keep_fargs: false, reduce_funcs: true, reduce_vars: true, sequences: true, unused: true, } input: { console.log(function(s) { var w, _i, _len, _ref, _results; _ref = s.trim().split(" "); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { w = _ref[_i]; _results.push(w.toLowerCase()); } return _results; }("test")); } expect: { console.log(function() { var w, _i, _len, _ref, _results; for (_results = [], _i = 0, _len = (_ref = "test".trim().split(" ")).length; _i < _len ; _i++) w = _ref[_i], _results.push(w.toLowerCase()); return _results; }()); } expect_stdout: true } lvalues_def: { options = { collapse_vars: true, side_effects: true, unused: true, } input: { var a = 0, b = 1; var a = b++, b = +function() {}(); a && a[a++]; console.log(a, b); } expect: { var a = 0, b = 1; a = b++, b = +void 0; a && a[a++]; console.log(a, b); } expect_stdout: true } compound_assignment: { options = { collapse_vars: true, } input: { var a; a = 1; a += a + 2; console.log(a); } expect: { var a; a = 1; a += a + 2; console.log(a); } expect_stdout: "4" } reassign_const_1: { options = { collapse_vars: true, } input: { function f() { const a = 1; a = 2; return a; } console.log(f()); } expect: { function f() { const a = 1; a = 2; return a; } console.log(f()); } expect_stdout: true } reassign_const_2: { options = { collapse_vars: true, } input: { function f() { const a = 1; ++a; return a; } console.log(f()); } expect: { function f() { const a = 1; ++a; return a; } console.log(f()); } expect_stdout: true } issue_2187_1: { options = { collapse_vars: true, unused: true, } input: { var a = 1; !function(foo) { foo(); var a = 2; console.log(a); }(function() { console.log(a); }); } expect: { var a = 1; !function(foo) { foo(); var a = 2; console.log(a); }(function() { console.log(a); }); } expect_stdout: [ "1", "2", ] } issue_2187_2: { options = { collapse_vars: true, unused: true, } input: { var b = 1; console.log(function(a) { return a && ++b; }(b--)); } expect: { var b = 1; console.log(function(a) { return b-- && ++b; }()); } expect_stdout: "1" } issue_2187_3: { options = { collapse_vars: true, inline: true, unused: true, } input: { var b = 1; console.log(function(a) { return a && ++b; }(b--)); } expect: { var b = 1; console.log(b-- && ++b); } expect_stdout: "1" } issue_2203_1: { options = { collapse_vars: true, unused: true, } input: { a = "FAIL"; console.log({ a: "PASS", b: function() { return function(c) { return c.a; }((String, (Object, this))); } }.b()); } expect: { a = "FAIL"; console.log({ a: "PASS", b: function() { return function(c) { return c.a; }((String, (Object, this))); } }.b()); } expect_stdout: "PASS" } issue_2203_2: { options = { collapse_vars: true, unused: true, } input: { a = "PASS"; console.log({ a: "FAIL", b: function() { return function(c) { return c.a; }((String, (Object, function() { return this; }()))); } }.b()); } expect: { a = "PASS"; console.log({ a: "FAIL", b: function() { return function(c) { return (String, (Object, function() { return this; }())).a; }(); } }.b()); } expect_stdout: "PASS" } issue_2203_3: { options = { collapse_vars: true, unused: true, } input: { a = "FAIL"; console.log({ a: "PASS", b: function() { return function(c) { return c.a; }((String, (Object, (() => this)()))); } }.b()); } expect: { a = "FAIL"; console.log({ a: "PASS", b: function() { return function(c) { return c.a; }((String, (Object, (() => this)()))); } }.b()); } expect_stdout: "PASS" } issue_2203_4: { options = { collapse_vars: true, unused: true, } input: { a = "FAIL"; console.log({ a: "PASS", b: function() { return (c => { return c.a; })((String, (Object, (() => this)()))); } }.b()); } expect: { a = "FAIL"; console.log({ a: "PASS", b: function() { return (c => { return (String, (Object, (() => this)())).a; })(); } }.b()); } expect_stdout: "PASS" } duplicate_argname: { options = { collapse_vars: true, unused: true, } input: { function f() { return "PASS"; } console.log(function(a, a) { f++; return a; }("FAIL", f())); } expect: { function f() { return "PASS"; } console.log(function(a, a) { f++; return a; }("FAIL", f())); } expect_stdout: "PASS" } issue_2250_1: { options = { collapse_vars: true, conditionals: true, passes: 2, reduce_funcs: true, reduce_vars: true, unused: true, } input: { function f(x) { if (x) { const a = foo(); x(a); } } function g(x) { if (x) { let a = foo(); x(a); } } function h(x) { if (x) { var a = foo(); x(a); } } } expect: { function f(x) { x && x(foo()); } function g(x) { x && x(foo()); } function h(x) { x && x(foo()); } } } issue_2250_2: { options = { collapse_vars: true, passes: 2, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { { const foo = function(){}; foo(bar()); } { let foo = function(){}; foo(bar()); } { var foo = function(){}; foo(bar()); } } expect: { bar(); bar(); bar(); } } issue_2298: { options = { collapse_vars: true, passes: 2, reduce_funcs: true, reduce_vars: true, unused: true, } input: { !function() { function f() { var a = undefined; var undefined = a++; try { !function g(b) { b[1] = "foo"; }(); console.log("FAIL"); } catch (e) { console.log("PASS"); } } f(); }(); } expect: { !function() { (function() { var a = undefined; var undefined = a++; try { !function(b) { (void 0)[1] = "foo"; }(); console.log("FAIL"); } catch (e) { console.log("PASS"); } })(); }(); } expect_stdout: "PASS" } issue_2313_1: { options = { collapse_vars: true, conditionals: true, } input: { var a = 0, b = 0; var foo = { get c() { a++; return 42; }, set c(c) { b++; }, d: function() { this.c++; if (this.c) console.log(a, b); } } foo.d(); } expect: { var a = 0, b = 0; var foo = { get c() { a++; return 42; }, set c(c) { b++; }, d: function() { this.c++; this.c && console.log(a, b); } } foo.d(); } expect_stdout: "2 1" } issue_2313_2: { options = { collapse_vars: true, } input: { var c = 0; !function a() { a && c++; var a = 0; a && c++; }(); console.log(c); } expect: { var c = 0; !function a() { a && c++; var a = 0; a && c++; }(); console.log(c); } expect_stdout: "0" } issue_2319_1: { options = { collapse_vars: true, unused: true, } input: { console.log(function(a) { return a; }(!function() { return this; }())); } expect: { console.log(function(a) { return !function() { return this; }(); }()); } expect_stdout: "false" } issue_2319_2: { options = { collapse_vars: true, unused: true, } input: { console.log(function(a) { "use strict"; return a; }(!function() { return this; }())); } expect: { console.log(function(a) { "use strict"; return a; }(!function() { return this; }())); } expect_stdout: "false" } issue_2319_3: { options = { collapse_vars: true, unused: true, } input: { "use strict"; console.log(function(a) { return a; }(!function() { return this; }())); } expect: { "use strict"; console.log(function(a) { return !function() { return this; }(); }()); } expect_stdout: "true" } issue_2365: { options = { collapse_vars: true, pure_getters: true, } input: { console.log(function(a) { var b = a.f; a.f++; return b; }({ f: 1 })); console.log(function() { var a = { f: 1 }, b = a.f; a.f++; return b; }()); console.log({ f: 1, g: function() { var b = this.f; this.f++; return b; } }.g()); } expect: { console.log(function(a) { var b = a.f; a.f++; return b; }({ f: 1 })); console.log(function() { var a = { f: 1 }, b = a.f; a.f++; return b; }()); console.log({ f: 1, g: function() { var b = this.f; this.f++; return b; } }.g()); } expect_stdout: [ "1", "1", "1", ] } issue_2364_1: { options = { collapse_vars: true, pure_getters: true, } input: { function inc(obj) { return obj.count++; } function foo() { var first = arguments[0]; var result = inc(first); return foo.amount = first.count, result; } var data = { count: 0, }; var answer = foo(data); console.log(foo.amount, answer); } expect: { function inc(obj) { return obj.count++; } function foo() { var first = arguments[0]; var result = inc(first); return foo.amount = first.count, result; } var data = { count: 0 }; var answer = foo(data); console.log(foo.amount, answer); } expect_stdout: "1 0" } issue_2364_2: { options = { collapse_vars: true, pure_getters: true, } input: { function callValidate() { var validate = compilation.validate; var result = validate.apply(null, arguments); return callValidate.errors = validate.errors, result; } } expect: { function callValidate() { var validate = compilation.validate; var result = validate.apply(null, arguments); return callValidate.errors = validate.errors, result; } } } issue_2364_3: { options = { collapse_vars: true, pure_getters: true, } input: { function inc(obj) { return obj.count++; } function foo(bar) { var result = inc(bar); return foo.amount = bar.count, result; } var data = { count: 0, }; var answer = foo(data); console.log(foo.amount, answer); } expect: { function inc(obj) { return obj.count++; } function foo(bar) { var result = inc(bar); return foo.amount = bar.count, result; } var data = { count: 0, }; var answer = foo(data); console.log(foo.amount, answer); } expect_stdout: "1 0" } issue_2364_4: { options = { collapse_vars: true, pure_getters: true, } input: { function inc(obj) { return obj.count++; } function foo(bar, baz) { var result = inc(bar); return foo.amount = baz.count, result; } var data = { count: 0, }; var answer = foo(data, data); console.log(foo.amount, answer); } expect: { function inc(obj) { return obj.count++; } function foo(bar, baz) { var result = inc(bar); return foo.amount = baz.count, result; } var data = { count: 0, }; var answer = foo(data, data); console.log(foo.amount, answer); } expect_stdout: "1 0" } issue_2364_5: { options = { collapse_vars: true, evaluate: true, properties: true, pure_getters: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { function f0(o, a, h) { var b = 3 - a; var obj = o; var seven = 7; var prop = 'run'; var t = obj[prop](b)[seven] = h; return t; } } expect: { function f0(o, a, h) { return o.run(3 - a)[7] = h; } } } issue_2364_6: { options = { collapse_vars: true, pure_getters: true, } input: { function f(a, b) { var c = a.p; b.p = "FAIL"; return c; } var o = { p: "PASS" } console.log(f(o, o)); } expect: { function f(a, b) { var c = a.p; b.p = "FAIL"; return c; } var o = { p: "PASS" } console.log(f(o, o)); } expect_stdout: "PASS" } issue_2364_7: { options = { collapse_vars: true, pure_getters: true, } input: { function f(a, b) { var c = a.p; b.f(); return c; } var o = { p: "PASS", f: function() { this.p = "FAIL"; } } console.log(f(o, o)); } expect: { function f(a, b) { var c = a.p; b.f(); return c; } var o = { p: "PASS", f: function() { this.p = "FAIL"; } } console.log(f(o, o)); } expect_stdout: "PASS" } issue_2364_8: { options = { collapse_vars: true, pure_getters: true, } input: { function f(a, b, c) { var d = a[b.f = function() { return "PASS"; }]; return c.f(d); } var o = { f: function() { return "FAIL"; } }; console.log(f({}, o, o)); } expect: { function f(a, b, c) { var d = a[b.f = function() { return "PASS"; }]; return c.f(d); } var o = { f: function() { return "FAIL"; } }; console.log(f({}, o, o)); } expect_stdout: "PASS" } issue_2364_9: { options = { collapse_vars: true, pure_getters: true, } input: { function f(a, b) { var d = a(); return b.f(d); } var o = { f: function() { return "FAIL"; } }; console.log(f(function() { o.f = function() { return "PASS"; }; }, o)); } expect: { function f(a, b) { var d = a(); return b.f(d); } var o = { f: function() { return "FAIL"; } }; console.log(f(function() { o.f = function() { return "PASS"; }; }, o)); } expect_stdout: "PASS" } pure_getters_chain: { options = { collapse_vars: true, pure_getters: true, unused: true, } input: { function o(t, r) { var a = t[1], s = t[2], o = t[3], i = t[5]; return a <= 23 && s <= 59 && o <= 59 && (!r || i); } console.log(o([ , 23, 59, 59, , 42], 1)); } expect: { function o(t, r) { return t[1] <= 23 && t[2] <= 59 && t[3] <= 59 && (!r || t[5]); } console.log(o([ , 23, 59, 59, , 42], 1)); } expect_stdout: "42" } conditional_1: { options = { collapse_vars: true, unused: true, } input: { function f(a, b) { var c = ""; var d = b ? ">" : "<"; if (a) c += "="; return c += d; } console.log(f(0, 0), f(0, 1), f(1, 0), f(1, 1)); } expect: { function f(a, b) { var c = ""; if (a) c += "="; return c += b ? ">" : "<"; } console.log(f(0, 0), f(0, 1), f(1, 0), f(1, 1)); } expect_stdout: "< > =< =>" } conditional_2: { options = { collapse_vars: true, unused: true, } input: { function f(a, b) { var c = a + 1, d = a + 2; return b ? c : d; } console.log(f(3, 0), f(4, 1)); } expect: { function f(a, b) { return b ? a + 1 : a + 2; } console.log(f(3, 0), f(4, 1)); } expect_stdout: "5 5" } issue_2425_1: { options = { collapse_vars: true, unused: true, } input: { var a = 8; (function(b) { b.toString(); })(--a, a |= 10); console.log(a); } expect: { var a = 8; (function(b) { b.toString(); })(--a, a |= 10); console.log(a); } expect_stdout: "15" } issue_2425_2: { options = { collapse_vars: true, unused: true, } input: { var a = 8; (function(b, c) { b.toString(); })(--a, a |= 10); console.log(a); } expect: { var a = 8; (function(b, c) { b.toString(); })(--a, a |= 10); console.log(a); } expect_stdout: "15" } issue_2425_3: { options = { collapse_vars: true, unused: true, } input: { var a = 8; (function(b, b) { b.toString(); })(--a, a |= 10); console.log(a); } expect: { var a = 8; (function(b, b) { (a |= 10).toString(); })(--a); console.log(a); } expect_stdout: "15" } issue_2437: { options = { collapse_vars: true, conditionals: true, inline: true, join_vars: true, passes: 2, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, toplevel: true, unused: true, } input: { function foo() { bar(); } function bar() { if (xhrDesc) { var req = new XMLHttpRequest(); var result = !!req.onreadystatechange; Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', xhrDesc || {}); return result; } else { var req = new XMLHttpRequest(); var detectFunc = function () {}; req.onreadystatechange = detectFunc; var result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc; req.onreadystatechange = null; return result; } } foo(); } expect: { !function() { if (xhrDesc) { var result = !!(req = new XMLHttpRequest()).onreadystatechange; return Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {}), result; } var req, detectFunc = function() {}; (req = new XMLHttpRequest()).onreadystatechange = detectFunc; result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc; req.onreadystatechange = null; }(); } } issue_2453: { options = { collapse_vars: true, conditionals: true, inline: true, join_vars: true, passes: 2, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, toplevel: true, } input: { function log(n) { console.log(n); } const a = 42; log(a); } expect: { function log(n) { console.log(n); } const a = 42; log(a); } expect_stdout: "42" } issue_2436_1: { options = { collapse_vars: true, inline: true, pure_getters: "strict", reduce_vars: true, toplevel: true, unused: true, } input: { var o = { a: 1, b: 2, }; console.log(function(c) { return { x: c.a, y: c.b, }; }(o)); } expect: { var o = { a: 1, b: 2, }; console.log({ x: o.a, y: o.b, }); } expect_stdout: true } issue_2436_2: { options = { collapse_vars: true, inline: true, pure_getters: "strict", reduce_vars: true, toplevel: true, unused: true, } input: { var o = { a: 1, b: 2, }; console.log(function(c) { o.a = 3; return { x: c.a, y: c.b, }; }(o)); } expect: { var o = { a: 1, b: 2, }; console.log(function(c) { o.a = 3; return { x: c.a, y: c.b, }; }(o)); } expect_stdout: true } issue_2436_3: { options = { collapse_vars: true, inline: true, pure_getters: "strict", reduce_vars: true, toplevel: true, unused: true, } input: { var o = { a: 1, b: 2, }; console.log(function(c) { o = { a: 3, b: 4, }; return { x: c.a, y: c.b, }; }(o)); } expect: { var o = { a: 1, b: 2, }; console.log(function(c) { o = { a: 3, b: 4, }; return { x: c.a, y: c.b, }; }(o)); } expect_stdout: true } issue_2436_4: { options = { collapse_vars: true, inline: true, pure_getters: "strict", reduce_vars: true, toplevel: true, unused: true, } input: { var o = { a: 1, b: 2, }; console.log(function(c) { return { x: c.a, y: c.b, }; var o; }(o)); } expect: { console.log({ x: (c = { a: 1, b: 2, }).a, y: c.b, }); var c; } expect_stdout: true } issue_2436_5: { options = { collapse_vars: true, inline: true, pure_getters: "strict", reduce_vars: true, toplevel: true, unused: true, } input: { var o = { a: 1, b: 2, }; console.log(function(o) { return { x: o.a, y: o.b, }; }(o)); } expect: { console.log(function(o) { return { x: o.a, y: o.b, }; }({ a: 1, b: 2, })); } expect_stdout: true } issue_2436_6: { options = { collapse_vars: true, evaluate: true, inline: true, passes: 2, pure_getters: "strict", reduce_vars: true, toplevel: true, unsafe: true, unused: true, } input: { var o = { a: 1, b: 2, }; console.log(function(c) { return { x: c.a, y: c.b, }; }(o)); } expect: { console.log({ x: 1, y: 2, }); } expect_stdout: true } issue_2436_7: { options = { collapse_vars: true, hoist_props: true, inline: true, passes: 3, pure_getters: "strict", reduce_vars: true, toplevel: true, unused: true, } input: { var o = { a: 1, b: 2, }; console.log(function(c) { return { x: c.a, y: c.b, }; }(o)); } expect: { console.log({ x: 1, y: 2, }); } expect_stdout: true } issue_2436_8: { options = { collapse_vars: true, inline: true, pure_getters: "strict", reduce_vars: true, toplevel: true, unused: true, } input: { console.log(function(c) { return { x: c.a, y: c.b, }; }(o)); } expect: { console.log({ x: (c = o).a, y: c.b, }); var c; } expect_stdout: true } issue_2436_9: { options = { collapse_vars: true, inline: true, pure_getters: "strict", reduce_vars: true, toplevel: true, unused: true, } input: { var o = console; console.log(function(c) { return { x: c.a, y: c.b, }; }(o)); } expect: { var o = console; console.log({ x: (c = o).a, y: c.b, }); var c; } expect_stdout: true } issue_2436_10: { options = { collapse_vars: true, inline: true, pure_getters: true, reduce_vars: true, toplevel: true, unused: true, } input: { var o = { a: 1, b: 2, }; function f(n) { o = { b: 3 }; return n; } console.log(function(c) { return [ c.a, f(c.b), c.b, ]; }(o).join(" ")); } expect: { var o = { a: 1, b: 2, }; function f(n) { o = { b: 3 }; return n; } console.log((c = o, [ c.a, f(c.b), c.b, ]).join(" ")); var c; } expect_stdout: "1 2 2" } issue_2436_11: { options = { collapse_vars: true, join_vars: true, reduce_vars: true, unused: true, } input: { function matrix() {} function isCollection() {} function _randomDataForMatrix() {} function _randomInt() {} function f(arg1, arg2) { if (isCollection(arg1)) { var size = arg1; var max = arg2; var min = 0; var res = _randomDataForMatrix(size.valueOf(), min, max, _randomInt); return size && true === size.isMatrix ? matrix(res) : res; } else { var min = arg1; var max = arg2; return _randomInt(min, max); } } } expect: { function matrix() {} function isCollection() {} function _randomDataForMatrix() {} function _randomInt() {} function f(arg1, arg2) { if (isCollection(arg1)) { var size = arg1, max = arg2, min = 0, res = _randomDataForMatrix(size.valueOf(), min, max, _randomInt); return size && true === size.isMatrix ? matrix(res) : res; } else { return _randomInt(min = arg1, max = arg2); } } } } issue_2436_12: { options = { collapse_vars: true, unused: true, } input: { function isUndefined() {} function f() { var viewValue = this.$$lastCommittedViewValue; var modelValue = viewValue; return isUndefined(modelValue) ? modelValue : null; } } expect: { function isUndefined() {} function f() { var modelValue = this.$$lastCommittedViewValue; return isUndefined(modelValue) ? modelValue : null; } } } issue_2436_13: { options = { collapse_vars: true, passes: 2, reduce_vars: true, unused: true, } input: { var a = "PASS"; (function() { function f(b) { (function g(b) { var b = b && (b.null = "FAIL"); })(a); } f(); })(); console.log(a); } expect: { var a = "PASS"; (function() { (function(b) { (function(b) { a && (a.null = "FAIL"); })(); })(); })(); console.log(a); } expect_stdout: "PASS" } issue_2436_14: { options = { collapse_vars: true, reduce_vars: true, unused: true, } input: { var a = "PASS"; var b = {}; (function() { var c = a; c && function(c, d) { console.log(c, d); }(b, c); })(); } expect: { var a = "PASS"; var b = {}; (function() { a && function(c, d) { console.log(c, d); }(b, a); })(); } expect_stdout: true } issue_2497: { options = { collapse_vars: true, unused: true, } input: { function sample() { if (true) { for (var i = 0; i < 1; ++i) { for (var k = 0; k < 1; ++k) { var value = 1; var x = value; value = x ? x + 1 : 0; } } } else { for (var i = 0; i < 1; ++i) { for (var k = 0; k < 1; ++k) { var value = 1; } } } } } expect: { function sample() { if (true) for (var i = 0; i < 1; ++i) for (var k = 0; k < 1; ++k) { value = 1; value = value ? value + 1 : 0; } else for (i = 0; i < 1; ++i) for (k = 0; k < 1; ++k) var value = 1; } } } issue_2506: { options = { collapse_vars: true, passes: 2, reduce_vars: true, unused: true, } input: { var c = 0; function f0(bar) { function f1(Infinity_2) { function f13(NaN) { if (false <= NaN & this >> 1 >= 0) { c++; } } var b_2 = f13(NaN, c++); } var bar = f1(-3, -1); } f0(false); console.log(c); } expect: { var c = 0; function f0(bar) { (function(Infinity_2) { (function(NaN) { if (false <= 0/0 & this >> 1 >= 0) c++; })(0, c++); })(); } f0(false); console.log(c); } expect_stdout: "1" } issue_2571_1: { options = { collapse_vars: true, toplevel: true, } input: { var b = 1; try { var a = function f0(c) { throw c; }(2); var d = --b + a; } catch (e) { } console.log(b); } expect: { var b = 1; try { var a = function f0(c) { throw c; }(2); var d = --b + a; } catch (e) { } console.log(b); } expect_stdout: "1" } issue_2571_2: { options = { collapse_vars: true, toplevel: true, } input: { try { var a = A, b = 1; throw a; } catch (e) { console.log(b); } } expect: { try { var a = A, b = 1; throw a; } catch (e) { console.log(b); } } expect_stdout: "undefined" } may_throw_1: { options = { collapse_vars: true, } input: { function f() { var a_2 = function() { var a; }(); } } expect: { function f() { var a_2 = function() { var a; }(); } } } may_throw_2: { options = { collapse_vars: true, unused: true, } input: { function f(b) { try { var a = x(); ++b; return b(a); } catch(e) {} console.log(b); } f(0); } expect: { function f(b) { try { var a = x(); return (++b)(a); } catch(e) {} console.log(b); } f(0); } expect_stdout: "0" } side_effect_free_replacement: { options = { collapse_vars: true, inline: true, side_effects: true, unused: true, } input: { var b; (function(a) { x(a); })(b); } expect: { var b; x(b); } } recursive_function_replacement: { rename = true options = { collapse_vars: true, inline: true, passes: 2, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } mangle = {} input: { function f(a) { return x(g(a)); } function g(a) { return y(f(a)); } console.log(f(c)); } expect: { console.log(function n(o) { return x(y(n(o))); }(c)); } } cascade_conditional: { options = { collapse_vars: true, } input: { function f(a, b) { (a = x(), a) ? a++ : (b = y(a), b(a)); } } expect: { function f(a, b) { (a = x()) ? a++ : (b = y(a))(a); } } } cascade_if_1: { options = { collapse_vars: true, } input: { var a; if (a = x(), a) if (a == y()) z(); } expect: { var a; if (a = x()) if (a == y()) z(); } } cascade_if_2: { options = { collapse_vars: true, } input: { function f(a, b) { if (a(), b = x()) return b; } } expect: { function f(a, b) { if (a(), b = x()) return b; } } } cascade_return: { options = { collapse_vars: true, } input: { function f(a) { return a = x(); return a; } } expect: { function f(a) { return a = x(); return a; } } } cascade_switch: { options = { collapse_vars: true, } input: { function f(a, b) { switch(a = x(), a) { case a = x(), b(a): break; } } } expect: { function f(a, b) { switch(a = x()) { case b(a = x()): break; } } } } cascade_call: { options = { collapse_vars: true, unused: true, } input: { function f(a) { var b; return x((b = a, y(b))); } } expect: { function f(a) { return x(y(a)); } } } replace_all_var: { options = { collapse_vars: true, unused: true, } input: { var a = "PASS"; (function() { var b = b || c && c[a = "FAIL"], c = a; })(); console.log(a); } expect: { var a = "PASS"; (function() { var b = b || c && c[a = "FAIL"], c = a; })(); console.log(a); } expect_stdout: "PASS" } cascade_statement: { options = { collapse_vars: true, } input: { function f1(a, b) { var c; if (a) return c = b, c || a; else c = a, c(b); } function f2(a, b) { var c; while (a) c = b, a = c + b; do throw c = a + b, c; while (c); } function f3(a, b) { for (; a < b; a++) if (c = a, c && b) var c = (c = b(a), c); } } expect: { function f1(a, b) { var c; if (a) return (c = b) || a; else (c = a)(b); } function f2(a, b) { var c; while (a) a = (c = b) + b; do throw c = a + b; while (c); } function f3(a, b) { for (; a < b; a++) if ((c = a) && b) var c = c = b(a); } } } cascade_forin: { options = { collapse_vars: true, } input: { var a; function f(b) { return [ b, b, b ]; } for (var c in a = console, f(a)) console.log(c); } expect: { var a; function f(b) { return [ b, b, b ]; } for (var c in f(a = console)) console.log(c); } expect_stdout: [ "0", "1", "2", ] } unsafe_builtin: { options = { collapse_vars: true, pure_getters: "strict", unsafe: true, unused: true, } input: { function f(a) { var b = Math.abs(a); return Math.pow(b, 2); } console.log(f(-1), f(2)); } expect: { function f(a) { return Math.pow(Math.abs(a), 2); } console.log(f(-1), f(2)); } expect_stdout: "1 4" } return_1: { options = { collapse_vars: true, unused: true, } input: { var log = console.log; function f(b, c) { var a = c; if (b) return b; log(a); } f(false, 1); f(true, 2); } expect: { var log = console.log; function f(b, c) { if (b) return b; log(c); } f(false, 1); f(true, 2); } expect_stdout: "1" } return_2: { options = { collapse_vars: true, unused: true, } input: { var log = console.log; function f(b, c) { var a = c(); if (b) return b; log(a); } f(false, function() { return 1 }); f(true, function() { return 2 }); } expect: { var log = console.log; function f(b, c) { var a = c(); if (b) return b; log(a); } f(false, function() { return 1 }); f(true, function() { return 2 }); } expect_stdout: "1" } return_3: { options = { collapse_vars: true, unused: true, } input: { var log = console.log; function f(b, c) { var a = b <<= c; if (b) return b; log(a); } f(false, 1); f(true, 2); } expect: { var log = console.log; function f(b, c) { var a = b <<= c; if (b) return b; log(a); } f(false, 1); f(true, 2); } expect_stdout: "0" } return_4: { options = { collapse_vars: true, } input: { var a = "FAIL"; (function(b) { a = "PASS"; return; b(a); })(); console.log(a); } expect: { var a = "FAIL"; (function(b) { a = "PASS"; return; b(a); })(); console.log(a); } expect_stdout: "PASS" } issue_2858: { options = { collapse_vars: true, unused: true, } input: { var b; (function() { function f() { a++; } f(); var c = f(); var a = void 0; c || (b = a); })(); console.log(b); } expect: { var b; (function() { function f() { a++; } f(); var c = f(); var a = void 0; c || (b = a); })(); console.log(b); } expect_stdout: "undefined" } cond_branch_1: { options = { collapse_vars: true, sequences: true, unused: true, } input: { function f1(b, c) { var log = console.log; var a = ++c; if (b) b++; log(a, b); } function f2(b, c) { var log = console.log; var a = ++c; b && b++; log(a, b); } function f3(b, c) { var log = console.log; var a = ++c; b ? b++ : b--; log(a, b); } f1(1, 2); f2(3, 4); f3(5, 6); } expect: { function f1(b, c) { if (b) b++; (0, console.log)(++c, b); } function f2(b, c) { b && b++, (0, console.log)(++c, b); } function f3(b, c) { b ? b++ : b--, (0, console.log)(++c, b); } f1(1, 2), f2(3, 4), f3(5, 6); } expect_stdout: [ "3 2", "5 4", "7 6", ] } cond_branch_2: { options = { collapse_vars: true, sequences: true, unused: true, } input: { function f1(b, c) { var log = console.log; var a = ++c; if (b) b += a; log(a, b); } function f2(b, c) { var log = console.log; var a = ++c; b && (b += a); log(a, b); } function f3(b, c) { var log = console.log; var a = ++c; b ? b += a : b--; log(a, b); } f1(1, 2); f2(3, 4); f3(5, 6); } expect: { function f1(b, c) { var a = ++c; if (b) b += a; (0, console.log)(a, b); } function f2(b, c) { var a = ++c; b && (b += a), (0, console.log)(a, b); } function f3(b, c) { var a = ++c; b ? b += a : b--, (0, console.log)(a, b); } f1(1, 2), f2(3, 4), f3(5, 6); } expect_stdout: [ "3 4", "5 8", "7 12", ] } cond_branch_switch: { options = { collapse_vars: true, } input: { var c = 0; if (c = 1 + c, 0) switch (c = 1 + c) { } console.log(c); } expect: { var c = 0; if (c = 1 + c, 0) switch (c = 1 + c) { } console.log(c); } expect_stdout: "1" } issue_2873_1: { options = { collapse_vars: true, } input: { var b = 1, c = 0; do { c++; if (!--b) break; c = 1 + c; } while (0); console.log(b, c); } expect: { var b = 1, c = 0; do { c++; if (!--b) break; c = 1 + c; } while (0); console.log(b, c); } expect_stdout: "0 1" } issue_2873_2: { options = { collapse_vars: true, } input: { var b = 1, c = 0; do { c++; if (!--b) continue; c = 1 + c; } while (0); console.log(b, c); } expect: { var b = 1, c = 0; do { c++; if (!--b) continue; c = 1 + c; } while (0); console.log(b, c); } expect_stdout: "0 1" } issue_2878: { options = { collapse_vars: true, sequences: true, } input: { var c = 0; (function (a, b) { function f2() { if (a) c++; } b = f2(); a = 1; b && b.b; f2(); })(); console.log(c); } expect: { var c = 0; (function (a, b) { function f2() { if (a) c++; } b = f2(), a = 1, b && b.b, f2(); })(), console.log(c); } expect_stdout: "1" } issue_2891_1: { options = { collapse_vars: true, } input: { var a = "PASS", b; try { b = c.p = 0; a = "FAIL"; b(); } catch (e) { } console.log(a); } expect: { var a = "PASS", b; try { b = c.p = 0; a = "FAIL"; b(); } catch (e) { } console.log(a); } expect_stdout: "PASS" } issue_2891_2: { options = { collapse_vars: true, } input: { "use strict"; var a = "PASS", b; try { b = c = 0; a = "FAIL"; b(); } catch (e) { } console.log(a); } expect: { "use strict"; var a = "PASS", b; try { b = c = 0; a = "FAIL"; b(); } catch (e) { } console.log(a); } expect_stdout: true } issue_2908: { options = { collapse_vars: true, } input: { var a = 0, b = 0; function f(c) { if (1 == c) return; a++; if (2 == c) b = a; } f(0); f(2); console.log(b); } expect: { var a = 0, b = 0; function f(c) { if (1 == c) return; a++; if (2 == c) b = a; } f(0); f(2); console.log(b); } expect_stdout: "2" } issue_3096: { options = { collapse_vars: true, } input: { console.log(function() { var ar = ["a", "b"]; var first = ar.pop(); return ar + "" + first; }()); } expect: { console.log(function() { var ar = ["a", "b"]; var first = ar.pop(); return ar + "" + first; }()); } expect_stdout: "ab" } issue_2914_1: { options = { collapse_vars: true, } input: { function read(input) { var i = 0; var e = 0; var t = 0; while (e < 32) { var n = input[i++]; t |= (127 & n) << e; if (0 === (128 & n)) return t; e += 7; } } console.log(read([129])); } expect: { function read(input) { var i = 0; var e = 0; var t = 0; while (e < 32) { var n = input[i++]; t |= (127 & n) << e; if (0 === (128 & n)) return t; e += 7; } } console.log(read([129])); } expect_stdout: "1" } issue_2914_2: { options = { collapse_vars: true, } input: { function read(input) { var i = 0; var e = 0; var t = 0; while (e < 32) { var n = input[i++]; t = (127 & n) << e; if (0 === (128 & n)) return t; e += 7; } } console.log(read([129])); } expect: { function read(input) { var i = 0; var e = 0; var t = 0; while (e < 32) { var n = input[i++]; if (0 === (128 & n)) return t = (127 & n) << e; e += 7; } } console.log(read([129])); } expect_stdout: "0" } issue_2931: { options = { collapse_vars: true, unused: true, } input: { console.log(function() { var a = function() { return; }(); return a; }()); } expect: { console.log(function() { return function() { return; }(); }()); } expect_stdout: "undefined" } issue_2954_1: { options = { collapse_vars: true, } input: { var a = "PASS", b; try { do { b = function() { throw 0; }(); a = "FAIL"; b && b.c; } while (0); } catch (e) { } console.log(a); } expect: { var a = "PASS", b; try { do { b = function() { throw 0; }(); a = "FAIL"; b && b.c; } while (0); } catch (e) { } console.log(a); } expect_stdout: "PASS" } issue_2954_2: { options = { collapse_vars: true, } input: { var a = "FAIL_1", b; try { throw 0; } catch (e) { do { b = function() { throw new Error("PASS"); }(); a = "FAIL_2"; b && b.c; } while (0); } console.log(a); } expect: { var a = "FAIL_1", b; try { throw 0; } catch (e) { do { a = "FAIL_2"; (b = function() { throw new Error("PASS"); }()) && b.c; } while (0); } console.log(a); } expect_stdout: Error("PASS") } issue_2954_3: { options = { collapse_vars: true, } input: { var a = "FAIL_1", b; try { } finally { do { b = function() { throw new Error("PASS"); }(); a = "FAIL_2"; b && b.c; } while (0); } console.log(a); } expect: { var a = "FAIL_1", b; try { } finally { do { a = "FAIL_2"; (b = function() { throw new Error("PASS"); }()) && b.c; } while (0); } console.log(a); } expect_stdout: Error("PASS") } collapse_rhs_conditional_1: { options = { collapse_vars: true, } input: { var a = "PASS", b = "FAIL"; b = a; "function" == typeof f && f(a); console.log(a, b); } expect: { var a = "PASS", b = "FAIL"; b = a; "function" == typeof f && f(a); console.log(a, b); } expect_stdout: "PASS PASS" } collapse_rhs_conditional_2: { options = { collapse_vars: true, } input: { var a = "FAIL", b; while ((a = "PASS", --b) && "PASS" == b); console.log(a, b); } expect: { var a = "FAIL", b; while ((a = "PASS", --b) && "PASS" == b); console.log(a, b); } expect_stdout: "PASS NaN" } collapse_rhs_lhs_1: { options = { collapse_vars: true, } input: { var c = 0; new function() { this[c++] = 1; c += 1; }(); console.log(c); } expect: { var c = 0; new function() { this[c++] = 1; c += 1; }(); console.log(c); } expect_stdout: "2" } collapse_rhs_lhs_2: { options = { collapse_vars: true, } input: { var b = 1; (function f(f) { f = b; f[b] = 0; })(); console.log("PASS"); } expect: { var b = 1; (function f(f) { f = b; f[b] = 0; })(); console.log("PASS"); } expect_stdout: "PASS" } collapse_rhs_loop: { options = { collapse_vars: true, } input: { var s; s = "PASS"; for (var m, r = /(.*)<\/tpl>/; m = s.match(r);) s = s.replace(m[0], m[1]); console.log(s); } expect: { var s; s = "PASS"; for (var m, r = /(.*)<\/tpl>/; m = s.match(r);) s = s.replace(m[0], m[1]); console.log(s); } expect_stdout: "PASS" } collapse_rhs_side_effects: { options = { collapse_vars: true, } input: { var a = 1, c = 0; new function f() { this[a-- && f()] = 1; c += 1; }(); console.log(c); } expect: { var a = 1, c = 0; new function f() { this[a-- && f()] = 1; c += 1; }(); console.log(c); } expect_stdout: "2" } collapse_rhs_vardef: { options = { collapse_vars: true, } input: { var a, b = 1; a = --b + function c() { var b; c[--b] = 1; }(); b |= a; console.log(a, b); } expect_stdout: "NaN 0" } collapse_rhs_array: { options = { collapse_vars: true, } input: { var a, b; function f() { a = []; b = []; return []; } var c = f(); console.log(a === b, b === c, c === a); } expect: { var a, b; function f() { a = []; b = []; return []; } var c = f(); console.log(a === b, b === c, c === a); } expect_stdout: "false false false" } collapse_rhs_boolean_1: { options = { collapse_vars: true, } input: { var a, b; function f() { a = !0; b = !0; return !0; } var c = f(); console.log(a === b, b === c, c === a); } expect_stdout: "true true true" } collapse_rhs_boolean_2: { options = { collapse_vars: true, } input: { var a; (function f1() { a = function() {}; if (/foo/) console.log(typeof a); })(); console.log(function f2() { a = []; return !1; }()); } expect_stdout: [ "function", "false", ] } collapse_rhs_function: { options = { collapse_vars: true, } input: { var a, b; function f() { a = function() {}; b = function() {}; return function() {}; } var c = f(); console.log(a === b, b === c, c === a); } expect: { var a, b; function f() { a = function() {}; b = function() {}; return function() {}; } var c = f(); console.log(a === b, b === c, c === a); } expect_stdout: "false false false" } collapse_rhs_number: { options = { collapse_vars: true, } input: { var a, b; function f() { a = 42; b = 42; return 42; } var c = f(); console.log(a === b, b === c, c === a); } expect_stdout: "true true true" } collapse_rhs_object: { options = { collapse_vars: true, } input: { var a, b; function f() { a = {}; b = {}; return {}; } var c = f(); console.log(a === b, b === c, c === a); } expect: { var a, b; function f() { a = {}; b = {}; return {}; } var c = f(); console.log(a === b, b === c, c === a); } expect_stdout: "false false false" } collapse_rhs_regexp: { options = { collapse_vars: true, } input: { var a, b; function f() { a = /bar/; b = /bar/; return /bar/; } var c = f(); console.log(a === b, b === c, c === a); } expect: { var a, b; function f() { a = /bar/; b = /bar/; return /bar/; } var c = f(); console.log(a === b, b === c, c === a); } expect_stdout: "false false false" } collapse_rhs_string: { options = { collapse_vars: true, } input: { var a, b; function f() { a = "foo"; b = "foo"; return "foo"; } var c = f(); console.log(a === b, b === c, c === a); } expect_stdout: "true true true" } collapse_rhs_var: { options = { collapse_vars: true, } input: { var a, b; function f() { a = f; b = f; return f; } var c = f(); console.log(a === b, b === c, c === a); } expect_stdout: "true true true" } collapse_rhs_this: { options = { collapse_vars: true, } input: { var a, b; function f() { a = this; b = this; return this; } var c = f(); console.log(a === b, b === c, c === a); } expect_stdout: "true true true" } collapse_rhs_undefined: { options = { collapse_vars: true, } input: { var a, b; function f() { a = void 0; b = void 0; return void 0; } var c = f(); console.log(a === b, b === c, c === a); } expect_stdout: "true true true" } issue_2437_1: { options = { collapse_vars: true, conditionals: true, inline: true, join_vars: true, passes: 2, reduce_funcs: true, reduce_vars: true, side_effects: true, sequences: true, toplevel: true, unused: true, } input: { function foo() { return bar(); } function bar() { if (xhrDesc) { var req = new XMLHttpRequest(); var result = !!req.onreadystatechange; Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', xhrDesc || {}); return result; } else { var req = new XMLHttpRequest(); var detectFunc = function () {}; req.onreadystatechange = detectFunc; var result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc; req.onreadystatechange = null; return result; } } console.log(foo()); } expect: { console.log(function() { if (xhrDesc) { var result = !!(req = new XMLHttpRequest()).onreadystatechange; return Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {}), result; } var req, detectFunc = function() {}; (req = new XMLHttpRequest()).onreadystatechange = detectFunc; result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc; return req.onreadystatechange = null, result; }()); } } issue_2974: { options = { booleans: true, collapse_vars: true, evaluate: true, loops: true, passes: 2, pure_getters: "strict", reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { var c = 0; (function f(b) { var a = 2; do { b && b[b]; b && (b.null = -4); c++; } while (b.null && --a > 0); })(true); console.log(c); } expect_stdout: "1" } issue_3032: { options = { collapse_vars: true, pure_getters: true, } input: { console.log({ f: function() { this.a = 42; return [ this.a, !1 ]; } }.f()[0]); } expect: { console.log({ f: function() { this.a = 42; return [ this.a, !1 ]; } }.f()[0]); } expect_stdout: "42" } issue_805: { options = { collapse_vars: true, pure_getters: "strict", reduce_vars: true, } input: { function f() { function Foo(){} Foo.prototype = {}; Foo.prototype.bar = 42; return Foo; } console.log((new (f())).bar); } expect_stdout: "42" } replace_all_var_scope: { rename = true; options = { collapse_vars: true, unused: true, } mangle = {} input: { var a = 100, b = 10; (function(r, a) { switch (~a) { case (b += a): case a++: } })(--b, a); console.log(a, b); } expect: { var a = 100, b = 10; (function(c, o) { switch (~a) { case (b += a): case o++: } })(--b, a); console.log(a, b); } expect_stdout: "100 109" } terser-4.1.2/test/compress/comparing.js000066400000000000000000000201421351061312300201430ustar00rootroot00000000000000keep_comparisons: { options = { comparisons: true, unsafe_comps: false } input: { var obj1 = { valueOf: function() {triggeredFirst();} } var obj2 = { valueOf: function() {triggeredSecond();} } var result1 = obj1 <= obj2; var result2 = obj1 < obj2; var result3 = obj1 >= obj2; var result4 = obj1 > obj2; } expect: { var obj1 = { valueOf: function() {triggeredFirst();} } var obj2 = { valueOf: function() {triggeredSecond();} } var result1 = obj1 <= obj2; var result2 = obj1 < obj2; var result3 = obj1 >= obj2; var result4 = obj1 > obj2; } } keep_comparisons_with_unsafe_comps: { options = { comparisons: true, unsafe_comps: true } input: { var obj1 = { valueOf: function() {triggeredFirst();} } var obj2 = { valueOf: function() {triggeredSecond();} } var result1 = obj1 <= obj2; var result2 = obj1 < obj2; var result3 = obj1 >= obj2; var result4 = obj1 > obj2; } expect: { var obj1 = { valueOf: function() {triggeredFirst();} } var obj2 = { valueOf: function() {triggeredSecond();} } var result1 = obj2 >= obj1; var result2 = obj2 > obj1; var result3 = obj1 >= obj2; var result4 = obj1 > obj2; } } 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" } 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" } terser-4.1.2/test/compress/concat-strings.js000066400000000000000000000123351351061312300211270ustar00rootroot00000000000000concat_1: { options = { evaluate: true, } input: { var a = "foo" + "bar" + x() + "moo" + "foo" + y() + "x" + "y" + "z" + q(); var b = "foo" + 1 + x() + 2 + "boo"; var c = 1 + x() + 2 + "boo"; // this CAN'T safely be shortened to 1 + x() + "5boo" var d = 1 + x() + 2 + 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: { var a = "foobar" + x() + "moofoo" + y() + "xyz" + q(); var b = "foo1" + x() + "2boo"; var c = 1 + x() + 2 + "boo"; var d = 1 + x() + 2 + 3 + "boo"; var e = 1 + x() + 2 + "X3boo"; var f = "\x00360\x008\0"; } } concat_2: { options = {} 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 = {} 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 = {} 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 = {} 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 = {} 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: { 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: { 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 } terser-4.1.2/test/compress/conditionals.js000066400000000000000000000717331351061312300206660ustar00rootroot00000000000000ifs_1: { options = { conditionals: true, } input: { if (foo) bar(); if (!foo); else bar(); if (foo); else bar(); if (foo); else; } expect: { foo&&bar(); foo&&bar(); foo||bar(); foo; } } ifs_2: { options = { conditionals: true, } input: { if (foo) { x(); } else if (bar) { y(); } else if (baz) { z(); } if (foo) { x(); } else if (bar) { y(); } else if (baz) { z(); } else { t(); } } expect: { foo ? x() : bar ? y() : baz && z(); foo ? x() : bar ? y() : baz ? z() : t(); } } ifs_3_should_warn: { options = { booleans: true, conditionals: true, dead_code: true, evaluate: true, side_effects: true, } input: { var x, y; if (x && !(x + "1") && y) { // 1 var qq; foo(); } else { bar(); } if (x || !!(x + "1") || y) { // 2 foo(); } else { var jj; bar(); } } expect: { var x, y; var qq; bar(); // 1 var jj; foo(); // 2 } } ifs_4: { options = { conditionals: true, } input: { if (foo && bar) { x(foo)[10].bar.baz = something(); } else x(foo)[10].bar.baz = something_else(); } expect: { foo && bar ? x(foo)[10].bar.baz = something() : x(foo)[10].bar.baz = something_else(); } } ifs_5: { options = { comparisons: true, conditionals: true, if_return: true, } input: { function f() { if (foo) return; bar(); baz(); } function g() { if (foo) return; if (bar) return; if (baz) return; if (baa) return; a(); b(); } } expect: { function f() { if (!foo) { bar(); baz(); } } function g() { if (!(foo || bar || baz || baa)) { a(); b(); } } } } ifs_6: { options = { comparisons: true, conditionals: true, } input: { var x, y; if (!foo && !bar && !baz && !boo) { x = 10; } else { x = 20; } if (y) { x[foo] = 10; } else { x[foo] = 20; } if (foo) { x[bar] = 10; } else { x[bar] = 20; } } expect: { var x, y; x = foo || bar || baz || boo ? 20 : 10; x[foo] = y ? 10 : 20; foo ? x[bar] = 10 : x[bar] = 20; } } cond_1: { options = { conditionals: true, } input: { function foo(do_something, some_condition) { if (some_condition) { do_something(x); } else { do_something(y); } if (some_condition) { side_effects(x); } else { side_effects(y); } } } expect: { function foo(do_something, some_condition) { do_something(some_condition ? x : y); some_condition ? side_effects(x) : side_effects(y); } } } cond_2: { options = { conditionals: true, } input: { function foo(x, FooBar, some_condition) { if (some_condition) { x = new FooBar(1); } else { x = new FooBar(2); } } } expect: { function foo(x, FooBar, some_condition) { x = new FooBar(some_condition ? 1 : 2); } } } cond_3: { options = { conditionals: true, } input: { var FooBar; if (some_condition()) { new FooBar(1); } else { FooBar(2); } } expect: { var FooBar; some_condition() ? new FooBar(1) : FooBar(2); } } cond_4: { options = { conditionals: true, } input: { var do_something; if (some_condition()) { do_something(); } else { do_something(); } if (some_condition()) { side_effects(); } else { side_effects(); } } expect: { var do_something; some_condition(), do_something(); some_condition(), side_effects(); } } cond_5: { options = { conditionals: 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(); some_condition() && some_other_condition() && do_something(); } } cond_7: { options = { conditionals: true, evaluate: true, side_effects: true, } input: { var x, y, z, a, b; // compress these if (y) { x = 1+1; } else { x = 2; } if (y) { x = 1+1; } else if (z) { x = 2; } else { x = 3-1; } x = y ? 'foo' : 'fo'+'o'; x = y ? 'foo' : y ? 'foo' : 'fo'+'o'; // Compress conditions that have side effects if (condition()) { x = 10+10; } else { x = 20; } if (z) { x = 'fuji'; } else if (condition()) { x = 'fu'+'ji'; } else { x = 'fuji'; } x = condition() ? 'foobar' : 'foo'+'bar'; // don't compress these x = y ? a : b; x = y ? 'foo' : 'fo'; } expect: { var x, y, z, a, b; x = 2; x = 2; x = 'foo'; x = 'foo'; x = (condition(), 20); x = z ? 'fuji' : (condition(), 'fuji'); x = (condition(), 'foobar'); x = y ? a : b; x = y ? 'foo' : 'fo'; } } cond_7_1: { options = { conditionals: true, evaluate: true, } input: { var x; // access to global should be assumed to have side effects if (y) { x = 1+1; } else { x = 2; } } expect: { var x; x = (y, 2); } } cond_8: { options = { booleans: false, conditionals: true, evaluate: true, } input: { var a; // compress these a = condition ? true : false; a = !condition ? true : false; a = condition() ? true : false; a = condition ? !0 : !1; a = !condition ? !null : !2; a = condition() ? !0 : !-3.5; if (condition) { a = true; } else { a = false; } if (condition) { a = !0; } else { a = !1; } a = condition ? false : true; a = !condition ? false : true; a = condition() ? false : true; a = condition ? !3 : !0; a = !condition ? !2 : !0; a = condition() ? !1 : !0; if (condition) { a = false; } else { a = true; } if (condition) { a = !1; } else { a = !0; } // don't compress these a = condition ? 1 : false; a = !condition ? true : 0; a = condition ? 1 : 0; } expect: { var a; a = !!condition; a = !condition; a = !!condition(); a = !!condition; a = !condition; a = !!condition(); a = !!condition; a = !!condition; a = !condition; a = !!condition; a = !condition(); a = !condition; a = !!condition; a = !condition(); a = !condition; a = !condition; a = !!condition && 1; a = !condition || 0; a = condition ? 1 : 0; } } cond_8b: { options = { booleans: true, conditionals: true, evaluate: true, } input: { var a; // compress these a = condition ? true : false; a = !condition ? true : false; a = condition() ? true : false; a = condition ? !0 : !1; a = !condition ? !null : !2; a = condition() ? !0 : !-3.5; if (condition) { a = true; } else { a = false; } if (condition) { a = !0; } else { a = !1; } a = condition ? false : true; a = !condition ? false : true; a = condition() ? false : true; a = condition ? !3 : !0; a = !condition ? !2 : !0; a = condition() ? !1 : !0; if (condition) { a = false; } else { a = true; } if (condition) { a = !1; } else { a = !0; } a = condition ? 1 : false; a = !condition ? true : 0; a = condition ? 1 : 0; } expect: { var a; a = !!condition; a = !condition; a = !!condition(); a = !!condition; a = !condition; a = !!condition(); a = !!condition; a = !!condition; a = !condition; a = !!condition; a = !condition(); a = !condition; a = !!condition; a = !condition(); a = !condition; a = !condition; a = !!condition && 1; a = !condition || 0; a = condition ? 1 : 0; } } cond_8c: { options = { booleans: false, conditionals: true, evaluate: false, } input: { var a; // compress these a = condition ? true : false; a = !condition ? true : false; a = condition() ? true : false; a = condition ? !0 : !1; a = !condition ? !null : !2; a = condition() ? !0 : !-3.5; if (condition) { a = true; } else { a = false; } if (condition) { a = !0; } else { a = !1; } a = condition ? false : true; a = !condition ? false : true; a = condition() ? false : true; a = condition ? !3 : !0; a = !condition ? !2 : !0; a = condition() ? !1 : !0; if (condition) { a = false; } else { a = true; } if (condition) { a = !1; } else { a = !0; } a = condition ? 1 : false; a = !condition ? true : 0; a = condition ? 1 : 0; } expect: { var a; a = !!condition; a = !condition; a = !!condition(); a = !!condition; a = !condition; a = !!condition() || !-3.5; a = !!condition; a = !!condition; a = !condition; a = !!condition; a = !condition(); a = !condition; a = !!condition; a = !condition(); a = !condition; a = !condition; a = !!condition && 1; a = !condition || 0; a = condition ? 1 : 0; } } cond_9: { options = { conditionals: true, } input: { function f(x, y) { g() ? x(1) : x(2); x ? (y || x)() : (y || x)(); x ? y(a, b) : y(d, b, c); x ? y(a, b, c) : y(a, b, c); x ? y(a, b, c) : y(a, b, f); x ? y(a, b, c) : y(a, e, c); x ? y(a, b, c) : y(a, e, f); x ? y(a, b, c) : y(d, b, c); x ? y(a, b, c) : y(d, b, f); x ? y(a, b, c) : y(d, e, c); x ? y(a, b, c) : y(d, e, f); } } expect: { function f(x, y) { g() ? x(1) : x(2); x, (y || x)(); x ? y(a, b) : y(d, b, c); x, y(a, b, c); y(a, b, x ? c : f); y(a, x ? b : e, c); x ? y(a, b, c) : y(a, e, f); y(x ? a : d, b, c); x ? y(a, b, c) : y(d, b, f); x ? y(a, b, c) : y(d, e, c); x ? y(a, b, c) : y(d, e, f); } } } ternary_boolean_consequent: { 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: true, side_effects: true, unused: true, } input: { function f1() { return a == b ? true : x; } function f2() { return a == b ? false : x; } function f3() { return a < b ? !0 : x; } function f4() { return a < b ? !1 : x; } function f5() { return c ? !0 : x; } function f6() { return c ? false : x; } function f7() { return !c ? true : x; } function f8() { return !c ? !1 : x; } } expect: { function f1() { return a == b || x; } function f2() { return a != b && x; } function f3() { return a < b || x; } function f4() { return !(a < b) && x; } function f5() { return !!c || x; } function f6() { return !c && x; } function f7() { return !c || x; } function f8() { return !!c && x; } } } ternary_boolean_alternative: { 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: true, side_effects: true, unused: true, } input: { function f1() { return a == b ? x : true; } function f2() { return a == b ? x : false; } function f3() { return a < b ? x : !0; } function f4() { return a < b ? x : !1; } function f5() { return c ? x : true; } function f6() { return c ? x : !1; } function f7() { return !c ? x : !0; } function f8() { return !c ? x : false; } } expect: { function f1() { return a != b || x; } function f2() { return a == b && x; } function f3() { return !(a < b) || x; } function f4() { return a < b && x; } function f5() { return !c || x; } function f6() { return !!c && x; } function f7() { return !!c || x; } function f8() { return !c && x; } } } trivial_boolean_ternary_expressions : { options = { conditionals: true, evaluate : true, booleans : true }; input: { f('foo' in m ? true : false); f('foo' in m ? false : true); f(g ? true : false); f(foo() ? true : false); f("bar" ? true : false); f(5 ? true : false); f(5.7 ? true : false); f(x - y ? true : false); f(x == y ? true : false); f(x === y ? !0 : !1); f(x < y ? !0 : false); f(x <= y ? true : false); f(x > y ? true : !1); f(x >= y ? !0 : !1); f(g ? false : true); f(foo() ? false : true); f("bar" ? false : true); f(5 ? false : true); f(5.7 ? false : true); f(x - y ? false : true); f(x == y ? !1 : !0); f(x === y ? false : true); f(x < y ? false : true); f(x <= y ? false : !0); f(x > y ? !1 : true); f(x >= y ? !1 : !0); } expect: { f('foo' in m); f(!('foo' in m)); f(!!g); f(!!foo()); f(!0); f(!0); f(!0); f(!!(x - y)); f(x == y); f(x === y); f(x < y); f(x <= y); f(x > y); f(x >= y); f(!g); f(!foo()); f(!1); f(!1); f(!1); f(!(x - y)); f(x != y); f(x !== y); f(!(x < y)); f(!(x <= y)); f(!(x > y)); f(!(x >= y)); } } issue_1154: { options = { booleans: true, conditionals: true, evaluate: true, side_effects: true, } input: { function f1(x) { return x ? -1 : -1; } function f2(x) { return x ? +2 : +2; } function f3(x) { return x ? ~3 : ~3; } function f4(x) { return x ? !4 : !4; } function f5(x) { return x ? void 5 : void 5; } function f6(x) { return x ? typeof 6 : typeof 6; } function g1() { return g() ? -1 : -1; } function g2() { return g() ? +2 : +2; } function g3() { return g() ? ~3 : ~3; } function g4() { return g() ? !4 : !4; } function g5() { return g() ? void 5 : void 5; } function g6() { return g() ? typeof 6 : typeof 6; } } expect: { function f1(x) { return -1; } function f2(x) { return 2; } function f3(x) { return -4; } function f4(x) { return !1; } function f5(x) { return; } function f6(x) { return "number"; } function g1() { return g(), -1; } function g2() { return g(), 2; } function g3() { return g(), -4; } function g4() { return g(), !1; } function g5() { return void g(); } function g6() { return g(), "number"; } } } no_evaluate: { options = { conditionals: true, evaluate: false, side_effects: true, } input: { function f(b) { a = b ? !0 : !0; a = b ? ~1 : ~1; a = b ? -2 : -2; a = b ? +3 : +3; } } expect: { function f(b) { a = !0; a = ~1; a = -2; a = +3; } } } equality_conditionals_false: { options = { conditionals: false, sequences: true, } input: { function f(a, b, c) { console.log( a == (b ? a : a), a == (b ? a : c), a != (b ? a : a), a != (b ? a : c), a === (b ? a : a), a === (b ? a : c), a !== (b ? a : a), a !== (b ? a : c) ); } f(0, 0, 0); f(0, true, 0); f(1, 2, 3); f(1, null, 3); f(NaN); f(NaN, "foo"); } expect: { function f(a, b, c) { console.log( a == (b ? a : a), a == (b ? a : c), a != (b ? a : a), a != (b ? a : c), a === (b ? a : a), a === (b ? a : c), a !== (b ? a : a), a !== (b ? a : c) ); } f(0, 0, 0), f(0, true, 0), f(1, 2, 3), f(1, null, 3), f(NaN), f(NaN, "foo"); } expect_stdout: true } equality_conditionals_true: { options = { conditionals: true, sequences: true, } input: { function f(a, b, c) { console.log( a == (b ? a : a), a == (b ? a : c), a != (b ? a : a), a != (b ? a : c), a === (b ? a : a), a === (b ? a : c), a !== (b ? a : a), a !== (b ? a : c) ); } f(0, 0, 0); f(0, true, 0); f(1, 2, 3); f(1, null, 3); f(NaN); f(NaN, "foo"); } expect: { function f(a, b, c) { console.log( (b, a == a), a == (b ? a : c), (b, a != a), a != (b ? a : c), (b, a === a), a === (b ? a : c), (b, a !== a), a !== (b ? a : c) ); } f(0, 0, 0), f(0, true, 0), f(1, 2, 3), f(1, null, 3), f(NaN), f(NaN, "foo"); } expect_stdout: true } issue_1645_1: { options = { conditionals: true, } input: { var a = 100, b = 10; (b = a) ? a++ + (b += a) ? b += a : b += a : b ^= a; console.log(a, b); } expect: { var a = 100, b = 10; (b = a) ? (a++ + (b += a), b += a) : b ^= a; console.log(a,b); } expect_stdout: true } issue_1645_2: { options = { conditionals: true, } input: { var a = 0; function f() { return a++; } f() ? a += 2 : a += 4; console.log(a); } expect: { var a = 0; function f(){ return a++; } f() ? a += 2 : a += 4; console.log(a); } expect_stdout: true } condition_symbol_matches_consequent: { options = { conditionals: true, } input: { function foo(x, y) { return x ? x : y; } function bar() { return g ? g : h; } var g = 4; var h = 5; console.log(foo(3, null), foo(0, 7), foo(true, false), bar()); } expect: { function foo(x, y) { return x || y; } function bar() { return g || h; } var g = 4; var h = 5; console.log(foo(3, null), foo(0, 7), foo(true, false), bar()); } expect_stdout: "3 7 true 4" } delete_conditional_1: { options = { booleans: true, conditionals: true, evaluate: true, side_effects: true, } input: { console.log(delete (1 ? undefined : x)); console.log(delete (1 ? void 0 : x)); console.log(delete (1 ? Infinity : x)); console.log(delete (1 ? 1 / 0 : x)); console.log(delete (1 ? NaN : x)); console.log(delete (1 ? 0 / 0 : x)); } expect: { console.log(!0); console.log(!0); console.log(!0); console.log(!0); console.log(!0); console.log(!0); } expect_stdout: true } delete_conditional_2: { options = { booleans: true, conditionals: true, evaluate: true, keep_infinity: true, side_effects: true, } input: { console.log(delete (0 ? x : undefined)); console.log(delete (0 ? x : void 0)); console.log(delete (0 ? x : Infinity)); console.log(delete (0 ? x : 1 / 0)); console.log(delete (0 ? x : NaN)); console.log(delete (0 ? x : 0 / 0)); } expect: { console.log(!0); console.log(!0); console.log(!0); console.log(!0); console.log(!0); console.log(!0); } expect_stdout: true } issue_2535_1: { options = { booleans: true, conditionals: true, evaluate: true, passes: 2, side_effects: true, } input: { if (true || x()) y(); if (true && x()) y(); if (x() || true) y(); if (x() && true) y(); if (false || x()) y(); if (false && x()) y(); if (x() || false) y(); if (x() && false) y(); } expect: { y(); x() && y(); (x(), 1) && y(); x() && y(); x() && y(); x() && y(); (x(), 0) && y(); } } issue_2535_2: { options = { booleans: true, conditionals: true, evaluate: true, side_effects: true, } input: { function x() {} function y() { return "foo"; } console.log((x() || true) || y()); console.log((y() || true) || x()); console.log((x() || true) && y()); console.log((y() || true) && x()); console.log((x() && true) || y()); console.log((y() && true) || x()); console.log((x() && true) && y()); console.log((y() && true) && x()); console.log((x() || false) || y()); console.log((y() || false) || x()); console.log((x() || false) && y()); console.log((y() || false) && x()); console.log((x() && false) || y()); console.log((y() && false) || x()); console.log((x() && false) && y()); console.log((y() && false) && x()); } expect: { function x() {} function y() { return "foo"; } console.log(x() || !0); console.log(y() || !0); console.log((x(), y())); console.log((y(), x())); console.log(!!x() || y()); console.log(!!y() || x()); console.log(x() && y()); console.log(y() && x()); console.log(x() || y()); console.log(y() || x()); console.log(!!x() && y()); console.log(!!y() && x()); console.log((x(), y())); console.log((y(), x())); console.log(x() && !1); console.log(y() && !1); } expect_stdout: [ "true", "foo", "foo", "undefined", "foo", "true", "undefined", "undefined", "foo", "foo", "false", "undefined", "foo", "undefined", "undefined", "false", ] } issue_2560: { options = { conditionals: true, inline: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function log(x) { console.log(x); } function foo() { return log; } function bar() { if (x !== (x = foo())) { x(1); } else { x(2); } } var x = function() { console.log("init"); }; bar(); bar(); } expect: { function log(x) { console.log(x); } function bar() { x !== (x = log) ? x(1) : x(2); } var x = function() { console.log("init"); }; bar(); bar(); } expect_stdout: [ "1", "2", ] } issue_2994: { options = { conditionals: true, if_return: true } input: { function f(condition1, condition2, condition3) { if (condition1) { if (condition2) { return aValue; } else { const variable1 = 'something'; if (condition3) { const variable2 = 'else'; return anotherValue; } else { return undefined; } } } } let aValue = 2, anotherValue = 3; for (let i = 0; i < 8; ++i) { console.log(f(i & 4, i & 2, i & 1)); } } expect: { function f(condition1, condition2, condition3) { if (condition1) { if (condition2) return aValue; { const variable1 = "something"; if (condition3) { const variable2 = "else"; return anotherValue; } return; } } } let aValue = 2, anotherValue = 3; for (let i = 0; i < 8; ++i) console.log(f(4 & i, 2 & i, 1 & i)); } expect_stdout: [ "undefined", "undefined", "undefined", "undefined", "undefined", "3", "2", "2", ] } hoist_decl: { options = { conditionals: true, join_vars: true, sequences: true, } input: { if (x()) { var a; y(); } else { z(); var b; } } expect: { var a, b; x() ? y() : z(); } } to_and_or: { options = { conditionals: true, } input: { var values = [ 0, null, true, "foo", false, -1 / 0, void 0, ]; values.forEach(function(x) { values.forEach(function(y) { values.forEach(function(z) { console.log(x ? y || z : z); }); }); }); } expect: { var values = [ 0, null, true, "foo", false, -1 / 0, void 0, ]; values.forEach(function(x) { values.forEach(function(y) { values.forEach(function(z) { console.log(x && y || z); }); }); }); } expect_stdout: true } terser-4.1.2/test/compress/const.js000066400000000000000000000102741351061312300173170ustar00rootroot00000000000000issue_1191: { options = { evaluate : true, booleans : true, comparisons : true, dead_code : true, conditionals : true, side_effects : true, unused : true, hoist_funs : true, if_return : true, join_vars : true, sequences : false, collapse_vars : false, reduce_funcs : true, reduce_vars : true, } input: { function foo(rot) { const rotTol = 5; if (rot < -rotTol || rot > rotTol) bar(); baz(); } } expect: { function foo(rot) { (rot < -5 || rot > 5) && bar(); baz(); } } } issue_1194: { options = { evaluate : true, booleans : true, comparisons : true, dead_code : true, conditionals : true, side_effects : true, unused : true, hoist_funs : true, if_return : true, join_vars : true, sequences : false, collapse_vars : false, reduce_funcs : true, reduce_vars : true, } input: { function f1() {const a = "X"; return a + a;} function f2() {const aa = "X"; return aa + aa;} function f3() {const aaa = "X"; return aaa + aaa;} } expect: { function f1(){return"XX"} function f2(){return"XX"} function f3(){return"XX"} } } issue_1396: { options = { evaluate : true, booleans : true, comparisons : true, dead_code : true, conditionals : true, side_effects : true, unused : true, hoist_funs : true, if_return : true, join_vars : true, sequences : false, collapse_vars : false, reduce_funcs : true, reduce_vars : true, } input: { function foo(a) { const VALUE = 1; console.log(2 | VALUE); console.log(VALUE + 1); console.log(VALUE); console.log(a & VALUE); } function bar() { const s = "01234567890123456789"; console.log(s + s + s + s + s); const CONSTANT = "abc"; console.log(CONSTANT + CONSTANT + CONSTANT + CONSTANT + CONSTANT); } } expect: { function foo(a) { console.log(3); console.log(2); console.log(1); console.log(1 & a); } function bar() { const s = "01234567890123456789"; console.log(s + s + s + s + s); console.log("abcabcabcabcabc"); } } } unused_regexp_literal: { options = { evaluate : true, booleans : true, comparisons : true, dead_code : true, conditionals : true, side_effects : true, unused : true, hoist_funs : true, if_return : true, join_vars : true, sequences : false, collapse_vars : false, } input: { function f(){ var a = /b/; } } expect: { function f(){} } } regexp_literal_not_const: { options = { evaluate : true, booleans : true, comparisons : true, dead_code : true, conditionals : true, side_effects : true, unused : true, hoist_funs : true, if_return : true, join_vars : true, sequences : false, collapse_vars : false, reduce_funcs : true, reduce_vars : true, } input: { (function(){ var result; const s = 'acdabcdeabbb'; const REGEXP_LITERAL = /ab*/g; while (result = REGEXP_LITERAL.exec(s)) { console.log(result[0]); } })(); } expect: { (function() { var result; const REGEXP_LITERAL = /ab*/g; while (result = REGEXP_LITERAL.exec("acdabcdeabbb")) console.log(result[0]); })(); } expect_stdout: true } terser-4.1.2/test/compress/dead-code.js000066400000000000000000000632041351061312300177770ustar00rootroot00000000000000dead_code_1: { options = { dead_code: true, } input: { function f() { a(); b(); x = 10; return; if (x) { y(); } } } expect: { function f() { a(); b(); x = 10; return; } } } dead_code_2_should_warn: { options = { dead_code: true, } input: { function f() { g(); x = 10; throw new Error("foo"); // completely discarding the `if` would introduce some // bugs. UglifyJS v1 doesn't deal with this issue; in v2 // we copy any declarations to the upper scope. if (x) { y(); var x; function g(){}; // but nested declarations should not be kept. (function(){ var q; function y(){}; })(); } } f(); } expect: { function f() { g(); x = 10; throw new Error("foo"); var x; var g; } f(); } expect_stdout: true reminify: false // FIXME - block scoped function } dead_code_2_should_warn_strict: { options = { dead_code: true }; input: { "use strict"; function f() { g(); x = 10; throw new Error("foo"); // completely discarding the `if` would introduce some // bugs. UglifyJS v1 doesn't deal with this issue; in v2 // we copy any declarations to the upper scope. if (x) { y(); var x; function g(){}; // but nested declarations should not be kept. (function(){ var q; function y(){}; })(); } } f(); } expect: { "use strict"; function f() { g(); x = 10; throw new Error("foo"); var x; } f(); } expect_stdout: true reminify: false // FIXME - block scoped function } dead_code_constant_boolean_should_warn_more: { options = { booleans: true, conditionals: true, dead_code: true, evaluate: true, loops: true, side_effects: true, } input: { while (!((foo && bar) || (x + "0"))) { console.log("unreachable"); var foo; function bar() {} } for (var x = 10, y; x && (y || x) && (!typeof x); ++x) { asdf(); foo(); var moo; } bar(); } expect: { var foo; var bar; // nothing for the while // as for the for, it should keep: var moo; var x = 10, y; bar(); } expect_stdout: true reminify: false // FIXME - block scoped function } dead_code_constant_boolean_should_warn_more_strict: { options = { dead_code : true, loops : true, booleans : true, conditionals : true, evaluate : true, side_effects : true, }; input: { "use strict"; while (!((foo && bar) || (x + "0"))) { console.log("unreachable"); var foo; function bar() {} } for (var x = 10, y; x && (y || x) && (!typeof x); ++x) { asdf(); foo(); var moo; } bar(); } expect: { "use strict"; var foo; // nothing for the while // as for the for, it should keep: var moo; var x = 10, y; bar(); } expect_stdout: true reminify: false // FIXME - block scoped function } dead_code_block_decls_die: { options = { booleans: true, conditionals: true, dead_code: true, evaluate: true, side_effects: true, }; input: { if (0) { let foo = 6; const bar = 12; class Baz {}; var qux; } console.log(foo, bar, Baz); } expect: { var qux; console.log(foo, bar, Baz); } } dead_code_const_declaration: { options = { booleans: true, conditionals: true, dead_code: true, evaluate: true, loops: true, reduce_funcs: true, reduce_vars: true, side_effects: true, }; input: { var unused; const CONST_FOO = false; if (CONST_FOO) { console.log("unreachable"); var moo; function bar() {} } } expect: { var unused; const CONST_FOO = !1; var moo; var bar; } expect_stdout: true } dead_code_const_annotation: { options = { booleans: true, conditionals: true, dead_code: true, evaluate: true, loops: true, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, }; input: { var unused; /** @const */ var CONST_FOO_ANN = false; if (CONST_FOO_ANN) { console.log("unreachable"); var moo; function bar() {} } } expect: { var unused; var CONST_FOO_ANN = !1; var moo; var bar; } expect_stdout: true } dead_code_const_annotation_regex: { options = { dead_code : true, loops : true, booleans : true, conditionals : true, evaluate : 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; CONST_FOO_ANN && console.log('reachable'); } expect_stdout: true } dead_code_const_annotation_complex_scope: { options = { booleans: true, conditionals: true, dead_code: true, evaluate: true, loops: true, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, toplevel: true, }; input: { var unused_var; /** @const */ var test = 'test'; // @const var CONST_FOO_ANN = false; var unused_var_2; if (CONST_FOO_ANN) { console.log("unreachable"); var moo; function bar() {} } if (test === 'test') { var beef = 'good'; /** @const */ var meat = 'beef'; var pork = 'bad'; if (meat === 'pork') { console.log('also unreachable'); } else if (pork === 'good') { console.log('reached, not const'); } } } expect: { var unused_var; var test = 'test'; var CONST_FOO_ANN = !1; var unused_var_2; var moo; var bar; var beef = 'good'; var meat = 'beef'; var pork = 'bad'; } expect_stdout: true } try_catch_finally: { options = { conditionals: true, dead_code: true, evaluate: true, passes: 2, side_effects: true, } input: { var a = 1; !function() { try { if (false) throw x; } catch (a) { var a = 2; console.log("FAIL"); } finally { a = 3; console.log("PASS"); } }(); try { console.log(a); } finally { } } expect: { var a = 1; !function() { var a; a = 3; console.log("PASS"); }(); try { console.log(a); } finally { } } expect_stdout: [ "PASS", "1", ] } accessor: { options = { side_effects: true, } input: { ({ get a() {}, set a(v){ this.b = 2; }, b: 1 }); } expect: {} } issue_2233_1: { options = { pure_getters: "strict", side_effects: true, unsafe: true, } input: { Array.isArray; Boolean; console.log; Date; decodeURI; decodeURIComponent; encodeURI; encodeURIComponent; Error.name; escape; eval; EvalError; Function.length; isFinite; isNaN; JSON; Math.random; Number.isNaN; parseFloat; parseInt; RegExp; Object.defineProperty; String.fromCharCode; RangeError; ReferenceError; SyntaxError; TypeError; unescape; URIError; } expect: {} expect_stdout: true } global_timeout_and_interval_symbols: { options = { pure_getters: "strict", side_effects: true, unsafe: true, } input: { // These global symbols do not exist in the test sandbox // and must be tested separately. clearInterval; clearTimeout; setInterval; setTimeout; } expect: {} } issue_2233_2: { options = { pure_getters: "strict", reduce_funcs: true, reduce_vars: true, side_effects: true, unsafe: true, unused: true, } input: { var RegExp; Array.isArray; RegExp; UndeclaredGlobal; function foo() { var Number; AnotherUndeclaredGlobal; Math.sin; Number.isNaN; } } expect: { var RegExp; UndeclaredGlobal; function foo() { var Number; AnotherUndeclaredGlobal; Number.isNaN; } } } issue_2233_3: { options = { pure_getters: "strict", reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unsafe: true, unused: true, } input: { var RegExp; Array.isArray; RegExp; UndeclaredGlobal; function foo() { var Number; AnotherUndeclaredGlobal; Math.sin; Number.isNaN; } } expect: { UndeclaredGlobal; } } global_fns: { options = { side_effects: true, unsafe: true, } input: { Boolean(1, 2); decodeURI(1, 2); decodeURIComponent(1, 2); Date(1, 2); encodeURI(1, 2); encodeURIComponent(1, 2); Error(1, 2); escape(1, 2); EvalError(1, 2); isFinite(1, 2); isNaN(1, 2); Number(1, 2); Object(1, 2); parseFloat(1, 2); parseInt(1, 2); RangeError(1, 2); ReferenceError(1, 2); String(1, 2); SyntaxError(1, 2); TypeError(1, 2); unescape(1, 2); URIError(1, 2); try { Function(1, 2); } catch (e) { console.log(e.name); } try { RegExp(1, 2); } catch (e) { console.log(e.name); } try { Array(NaN); } catch (e) { console.log(e.name); } } expect: { try { Function(1, 2); } catch (e) { console.log(e.name); } try { RegExp(1, 2); } catch (e) { console.log(e.name); } try { Array(NaN); } catch (e) { console.log(e.name); } } expect_stdout: [ "SyntaxError", "SyntaxError", "RangeError", ] } issue_2383_1: { options = { conditionals: true, dead_code: true, evaluate: true, side_effects: true, } input: { if (0) { var {x, y} = foo(); } } expect: { var x, y; } } issue_2383_2: { options = { conditionals: true, dead_code: true, evaluate: true, side_effects: true, } input: { if (0) { var { x = 0, y: [ w, , { z, p: q = 7 } ] = [ 1, 2, { z: 3 } ] } = {}; } console.log(x, q, w, z); } expect: { var x, w, z, q; console.log(x, q, w, z); } expect_stdout: "undefined undefined undefined undefined" } issue_2383_3: { options = { conditionals: true, dead_code: true, evaluate: true, side_effects: true, } input: { var b = 7, y = 8; if (0) { var a = 1, [ x, y, z ] = [ 2, 3, 4 ], b = 5; } console.log(a, x, y, z, b); } expect: { var b = 7, y = 8; var a, x, y, z, b; console.log(a, x, y, z, b); } expect_stdout: "undefined undefined 8 undefined 7" } collapse_vars_assignment: { options = { collapse_vars: true, dead_code: true, passes: 2, unused: true, } input: { function f0(c) { var a = 3 / c; return a = a; } } expect: { function f0(c) { return 3 / c; } } } collapse_vars_lvalues_drop_assign: { options = { collapse_vars: true, dead_code: true, unused: true, } input: { function f0(x) { var i = ++x; return x += i; } function f1(x) { var a = (x -= 3); return x += a; } function f2(x) { var z = x, a = ++z; return z += a; } } expect: { function f0(x) { var i = ++x; return x + i; } function f1(x) { var a = (x -= 3); return x + a; } function f2(x) { var z = x, a = ++z; return z + a; } } } collapse_vars_misc1: { options = { collapse_vars: true, dead_code: true, unused: true, } input: { function f10(x) { var a = 5, b = 3; return a += b; } function f11(x) { var a = 5, b = 3; return a += --b; } } expect: { function f10(x) { return 5 + 3; } function f11(x) { var b = 3; return 5 + --b; } } } return_assignment: { options = { dead_code: true, unused: true, } input: { function f1(a, b, c) { return a = x(), b = y(), b = a && (c >>= 5); } function f2() { return e = x(); } function f3(e) { return e = x(); } function f4() { var e; return e = x(); } function f5(a) { try { return a = x(); } catch (b) { console.log(a); } } function f6(a) { try { return a = x(); } finally { console.log(a); } } function y() { console.log("y"); } function test(inc) { var counter = 0; x = function() { counter += inc; if (inc < 0) throw counter; return counter; }; [ f1, f2, f3, f4, f5, f6 ].forEach(function(f, i) { e = null; try { i += 1; console.log("result " + f(10 * i, 100 * i, 1000 * i)); } catch (x) { console.log("caught " + x); } if (null !== e) console.log("e: " + e); }); } var x, e; test(1); test(-1); } expect: { function f1(a, b, c) { return a = x(), y(), a && (c >> 5); } function f2() { return e = x(); } function f3(e) { return x(); } function f4() { return x(); } function f5(a) { try { return x(); } catch (b) { console.log(a); } } function f6(a) { try { return a = x(); } finally { console.log(a); } } function y() { console.log("y"); } function test(inc) { var counter = 0; x = function() { counter += inc; if (inc < 0) throw counter; return counter; }; [ f1, f2, f3, f4, f5, f6 ].forEach(function(f, i) { e = null; try { i += 1; console.log("result " + f(10 * i, 100 * i, 1000 * i)); } catch (x) { console.log("caught " + x); } if (null !== e) console.log("e: " + e); }); } var x, e; test(1); test(-1); } expect_stdout: [ "y", "result 31", "result 2", "e: 2", "result 3", "result 4", "result 5", "6", "result 6", "caught -1", "caught -2", "caught -3", "caught -4", "50", "result undefined", "60", "caught -6", ] } throw_assignment: { options = { dead_code: true, unused: true, } input: { function f1() { throw a = x(); } function f2(a) { throw a = x(); } function f3() { var a; throw a = x(); } function f4() { try { throw a = x(); } catch (b) { console.log(a); } } function f5(a) { try { throw a = x(); } catch (b) { console.log(a); } } function f6() { var a; try { throw a = x(); } catch (b) { console.log(a); } } function f7() { try { throw a = x(); } finally { console.log(a); } } function f8(a) { try { throw a = x(); } finally { console.log(a); } } function f9() { var a; try { throw a = x(); } finally { console.log(a); } } function test(inc) { var counter = 0; x = function() { counter += inc; if (inc < 0) throw counter; return counter; }; [ f1, f2, f3, f4, f5, f6, f7, f8, f9 ].forEach(function(f, i) { a = null; try { f(10 * (1 + i)); } catch (x) { console.log("caught " + x); } if (null !== a) console.log("a: " + a); }); } var x, a; test(1); test(-1); } expect: { function f1() { throw a = x(); } function f2(a) { throw x(); } function f3() { throw x(); } function f4() { try { throw a = x(); } catch (b) { console.log(a); } } function f5(a) { try { throw a = x(); } catch (b) { console.log(a); } } function f6() { var a; try { throw a = x(); } catch (b) { console.log(a); } } function f7() { try { throw a = x(); } finally { console.log(a); } } function f8(a) { try { throw a = x(); } finally { console.log(a); } } function f9() { var a; try { throw a = x(); } finally { console.log(a); } } function test(inc) { var counter = 0; x = function() { counter += inc; if (inc < 0) throw counter; return counter; }; [ f1, f2, f3, f4, f5, f6, f7, f8, f9 ].forEach(function(f, i) { a = null; try { f(10 * (1 + i)); } catch (x) { console.log("caught " + x); } if (null !== a) console.log("a: " + a); }); } var x, a; test(1); test(-1); } expect_stdout: [ "caught 1", "a: 1", "caught 2", "caught 3", "4", "a: 4", "5", "6", "7", "caught 7", "a: 7", "8", "caught 8", "9", "caught 9", "caught -1", "caught -2", "caught -3", "null", "50", "undefined", "null", "caught -7", "80", "caught -8", "undefined", "caught -9", ] } issue_2597: { options = { dead_code: true, } input: { function f(b) { try { try { throw "foo"; } catch (e) { return b = true; } } finally { b && (a = "PASS"); } } var a = "FAIL"; f(); console.log(a); } expect: { function f(b) { try { try { throw "foo"; } catch (e) { return b = true; } } finally { b && (a = "PASS"); } } var a = "FAIL"; f(); console.log(a); } expect_stdout: "PASS" } issue_2666: { options = { dead_code: true, } input: { function f(a) { return a = { p: function() { return a; } }; } console.log(typeof f().p()); } expect: { function f(a) { return a = { p: function() { return a; } }; } console.log(typeof f().p()); } expect_stdout: "object" } issue_2692: { options = { dead_code: true, reduce_vars: false, } input: { function f(a) { return a = g; function g() { return a; } } console.log(typeof f()()); } expect: { function f(a) { return a = g; function g() { return a; } } console.log(typeof f()()); } expect_stdout: "function" } issue_2701: { options = { dead_code: true, inline: false, } input: { function f(a) { return a = function() { return function() { return a; }; }(); } console.log(typeof f()()); } expect: { function f(a) { return a = function() { return function() { return a; }; }(); } console.log(typeof f()()); } expect_stdout: "function" } issue_2749: { options = { dead_code: true, inline: true, toplevel: true, unused: true, } input: { var a = 2, c = "PASS"; while (a--) (function() { return b ? c = "FAIL" : b = 1; try { } catch (b) { var b; } })(); console.log(c); } expect: { var a = 2, c = "PASS"; while (a--) b = void 0, b ? c = "FAIL" : b = 1; var b; console.log(c); } expect_stdout: "PASS" } unsafe_builtin: { options = { side_effects: true, unsafe: true, } input: { (!w).constructor(x); Math.abs(y); [ 1, 2, z ].valueOf(); } expect: { w, x; y; z; } } issue_2860_1: { options = { dead_code: true, evaluate: true, reduce_vars: true, } input: { console.log(function(a) { return a ^= 1; }()); } expect: { console.log(function(a) { return 1 ^ a; }()); } expect_stdout: "1" } issue_2860_2: { options = { dead_code: true, evaluate: true, inline: true, passes: 2, reduce_vars: true, } input: { console.log(function(a) { return a ^= 1; }()); } expect: { console.log(1); } expect_stdout: "1" } issue_2929: { options = { dead_code: true, } input: { console.log(function(a) { try { return null.p = a = 1; } catch (e) { return a ? "PASS" : "FAIL"; } }()); } expect: { console.log(function(a) { try { return null.p = a = 1; } catch (e) { return a ? "PASS" : "FAIL"; } }()); } expect_stdout: "PASS" } terser-4.1.2/test/compress/debugger.js000066400000000000000000000004771351061312300177610ustar00rootroot00000000000000keep_debugger: { options = { drop_debugger: false, } input: { debugger; } expect: { debugger; } } drop_debugger: { options = { drop_debugger: true, } input: { debugger; if (foo) debugger; } expect: { if (foo); } } terser-4.1.2/test/compress/defaults.js000066400000000000000000000027651351061312300200060ustar00rootroot00000000000000defaults_undefined: { options = { defaults: undefined, } input: { if (true) { console.log(1 + 2); } } expect: { if (true) console.log(1 + 2); } expect_stdout: "3" } defaults_false: { options = { defaults: false, } input: { if (true) { console.log(1 + 2); } } expect: { if (true) console.log(1 + 2); } expect_stdout: "3" } defaults_false_evaluate_true: { options = { defaults: false, evaluate: true, } input: { if (true) { console.log(1 + 2); } } expect: { if (true) console.log(3); } expect_stdout: "3" } defaults_true: { options = { defaults: true, } input: { if (true) { console.log(1 + 2); } } expect: { console.log(3); } expect_stdout: "3" } defaults_true_conditionals_false: { options = { defaults: true, conditionals: false, } input: { if (true) { console.log(1 + 2); } } expect: { if (1) console.log(3); } expect_stdout: "3" } defaults_true_evaluate_false: { options = { defaults: true, evaluate: false, } input: { if (true) { console.log(1 + 2); } } expect: { 1 && console.log(1 + 2); } expect_stdout: "3" } terser-4.1.2/test/compress/destructuring.js000066400000000000000000001040071351061312300210710ustar00rootroot00000000000000destructuring_arrays: { input: { {const [aa, bb] = cc;} {const [aa, [bb, cc]] = dd;} {let [aa, bb] = cc;} {let [aa, [bb, cc]] = dd;} var [aa, bb] = cc; var [aa, [bb, cc]] = dd; var [,[,,,,,],,,zz,] = xx; // Trailing comma var [,,zzz,,] = xxx; // Trailing comma after hole } expect: { {const [aa, bb] = cc;} {const [aa, [bb, cc]] = dd;} {let [aa, bb] = cc;} {let [aa, [bb, cc]] = dd;} var [aa, bb] = cc; var [aa, [bb, cc]] = dd; var [,[,,,,,],,,zz] = xx; var [,,zzz,,] = xxx; } } destructuring_arrays_holes: { input: { var [,,,,] = a; var [,,b,] = c; var [d,,] = e; } expect_exact: "var[,,,,]=a;var[,,b]=c;var[d,,]=e;" } destructuring_objects: { input: { {const {aa, bb} = {aa:1, bb:2};} {const {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};} {let {aa, bb} = {aa:1, bb:2};} {let {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};} var {aa, bb} = {aa:1, bb:2}; var {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}}; } expect: { {const {aa, bb} = {aa:1, bb:2};} {const {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};} {let {aa, bb} = {aa:1, bb:2};} {let {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};} var {aa, bb} = {aa:1, bb:2}; var {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}}; } } destructuring_objects_trailing_elision: { beautify = { ecma: 6 } input: { var {cc,} = foo; } expect_exact: "var{cc}=foo;" } nested_destructuring_objects: { beautify = { ecma: 6 } input: { const [{a},b] = c; let [{d},e] = f; var [{g},h] = i; } expect_exact: 'const[{a},b]=c;let[{d},e]=f;var[{g},h]=i;'; } destructuring_constdef_in_loops: { beautify = { ecma: 6 } input: { for (const [x,y] in pairs); for (const [a] = 0;;); for (const {c} of cees); } expect_exact: "for(const[x,y]in pairs);for(const[a]=0;;);for(const{c}of cees);" } destructuring_letdef_in_loops: { beautify = { ecma: 6 } input: { for (let [x,y] in pairs); for (let [a] = 0;;); for (let {c} of cees); } expect_exact: "for(let[x,y]in pairs);for(let[a]=0;;);for(let{c}of cees);" } destructuring_vardef_in_loops: { beautify = { ecma: 6 } input: { for (var [x,y] in pairs); for (var [a] = 0;;); for (var {c} of cees); } expect_exact: "for(var[x,y]in pairs);for(var[a]=0;;);for(var{c}of cees);" } destructuring_expressions: { beautify = { ecma: 6 } input: { ({a, b}); [{a}]; f({x}); } expect_exact: "({a,b});[{a}];f({x});" } destructuring_remove_unused_1: { options = { unused: true } input: { function a() { var unused = "foo"; var a = [1]; var [b] = a; f(b); } function b() { var unused = "foo"; var a = {b: 1}; var {b} = a; f(b); } function c() { var unused = "foo"; var a = [[1]]; var [[b]] = a; f(b); } function d() { var unused = "foo"; var a = {b: {b:1}}; var {b:{b}} = a; f(b); } function e() { var unused = "foo"; var a = [1, 2, 3, 4, 5]; var x = [[1, 2, 3]]; var y = {h: 1}; var [b, ...c] = a; var [...[e, f]] = x; var [...{g: h}] = y; f(b, c, e, f, g); } } expect: { function a() { var a = [1]; var [b] = a; f(b); } function b() { var a = {b: 1}; var {b} = a; f(b); } function c() { var a = [[1]]; var [[b]] = a; f(b); } function d() { var a = {b: {b:1}}; var {b:{b}} = a; f(b); } function e() { var a = [1, 2, 3, 4, 5]; var x = [[1, 2, 3]]; var y = {h: 1}; var [b, ...c] = a; var [...[e, f]] = x; var [...{g: h}] = y; f(b, c, e, f, g); } } } destructuring_remove_unused_2: { options = { unused: true } input: { function a() { var unused = "foo"; var a = [,,1]; var [b] = a; f(b); } function b() { var unused = "foo"; var a = [{a: [1]}]; var [{b: a}] = a; f(b); } } expect: { function a() { var a = [,,1]; var [b] = a; f(b); } function b() { var a = [{a: [1]}]; var [{b: a}] = a; f(b); } } } object_destructuring_may_need_parentheses: { beautify = { ecma: 6 } input: { ({a, b} = {a: 1, b: 2}); } expect_exact: "({a,b}={a:1,b:2});" } destructuring_with_undefined_as_default_assignment: { options = { evaluate: true } input: { [foo = undefined] = bar; [foo = void 0] = bar; } expect: { [foo] = bar; [foo] = bar; } } destructuring_dont_evaluate_with_undefined_as_default_assignment: { options = { evaluate: false } input: { [foo = undefined] = bar; } expect: { [foo = void 0] = bar; } } reduce_vars: { options = { reduce_funcs: true, reduce_vars: true, } input: { {const [aa, [bb, cc]] = dd;} {let [aa, [bb, cc]] = dd;} var [aa, [bb, cc]] = dd; [aa, [bb, cc]] = dd; {const {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};} {let {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};} var {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}}; ({aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}}); const [{a},b] = c; let [{d},e] = f; var [{g},h] = i; [{a},b] = c; for (const [x,y] in pairs); for (let [x,y] in pairs); for (var [x,y] in pairs); for ([x,y] in pairs); } expect: { {const [aa, [bb, cc]] = dd;} {let [aa, [bb, cc]] = dd;} var [aa, [bb, cc]] = dd; [aa, [bb, cc]] = dd; {const {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};} {let {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}};} var {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}}; ({aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}}); const [{a},b] = c; let [{d},e] = f; var [{g},h] = i; [{a},b] = c; for (const [x,y] in pairs); for (let [x,y] in pairs); for (var [x,y] in pairs); for ([x,y] in pairs); } } unused: { options = { unused: true, } input: { let { foo: [, , ...a] } = { foo: [1, 2, 3, 4], bar: 5 }; console.log(a); } expect: { let { foo: [, , ...a] } = { foo: [1, 2, 3, 4], bar: 5 }; console.log(a); } } issue_1886: { options = { collapse_vars: true, } input: { let [a] = [1]; console.log(a); } expect: { let [a] = [1]; console.log(a); } } destructuring_decl_of_numeric_key: { options = { evaluate: true, unused: true, } input: { let { 3: x } = { [1 + 2]: 42 }; console.log(x); } expect: { let { 3: x } = { [3]: 42 }; console.log(x); } expect_stdout: "42" } destructuring_decl_of_computed_key: { options = { evaluate: true, unused: true, } input: { let four = 4; let { [7 - four]: x } = { [1 + 2]: 42 }; console.log(x); } expect: { let four = 4; let { [7 - four]: x } = { [3]: 42 }; console.log(x); } expect_stdout: "42" } destructuring_assign_of_numeric_key: { options = { evaluate: true, unused: true, } input: { let x; ({ 3: x } = { [1 + 2]: 42 }); console.log(x); } expect: { let x; ({ 3: x } = { [3]: 42 }); console.log(x); } expect_stdout: "42" } destructuring_assign_of_computed_key: { options = { evaluate: true, unused: true, } input: { let x; let four = 4; ({ [(5 + 2) - four]: x } = { [1 + 2]: 42 }); console.log(x); } expect: { let x; let four = 4; ({ [7 - four]: x } = { [3]: 42 }); console.log(x); } expect_stdout: "42" } mangle_destructuring_decl: { options = { evaluate: true, unused: true, } mangle = { } input: { function test(opts) { let a = opts.a || { e: 7, n: 8 }; let { t, e, n, s = 5 + 4, o, r } = a; console.log(t, e, n, s, o, r); } test({a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 }}); test({}); } expect: { function test(t) { let e = t.a || { e: 7, n: 8 }; let {t: n, e: o, n: s, s: l = 9, o: a, r: c} = e; console.log(n, o, s, l, a, c); } test({ a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 } }); test({}); } expect_stdout: [ "1 2 3 4 5 6", "undefined 7 8 9 undefined undefined", ] } mangle_destructuring_decl_collapse_vars: { options = { collapse_vars: true, evaluate: true, unused: true, } mangle = { } input: { function test(opts) { let a = opts.a || { e: 7, n: 8 }; let { t, e, n, s = 5 + 4, o, r } = a; console.log(t, e, n, s, o, r); } test({a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 }}); test({}); } expect: { function test(t) { let e = t.a || { e: 7, n: 8 }; let {t: n, e: o, n: s, s: l = 9, o: a, r: c} = e; console.log(n, o, s, l, a, c); } test({ a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 } }); test({}); } expect_stdout: [ "1 2 3 4 5 6", "undefined 7 8 9 undefined undefined", ] } mangle_destructuring_assign_toplevel_true: { options = { toplevel: true, evaluate: true, unused: true, } mangle = { toplevel: true, } beautify = { ecma: 6 } input: { function test(opts) { let s, o, r; let a = opts.a || { e: 7, n: 8 }; ({ t, e, n, s = 5 + 4, o, r } = a); console.log(t, e, n, s, o, r); } let t, e, n; test({a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 }}); test({}); } expect: { function e(e) { let l, s, a; let c = e.a || { e: 7, n: 8 }; ({t: n, e: o, n: t, s: l = 9, o: s, r: a} = c); console.log(n, o, t, l, s, a); } let n, o, t; e({ a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 } }); e({}); } expect_stdout: [ "1 2 3 4 5 6", "undefined 7 8 9 undefined undefined", ] } mangle_destructuring_assign_toplevel_false: { options = { toplevel: false, evaluate: true, unused: true, } mangle = { toplevel: false, } beautify = { ecma: 6 } input: { function test(opts) { let s, o, r; let a = opts.a || { e: 7, n: 8 }; ({ t, e, n, s = 9, o, r } = a); console.log(t, e, n, s, o, r); } let t, e, n; test({a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 }}); test({}); } expect: { function test(o) { let s, l, a; let c = o.a || { e: 7, n: 8 }; ({t, e, n, s = 9, o: l, r: a} = c); console.log(t, e, n, s, l, a); } let t, e, n; test({ a: { t: 1, e: 2, n: 3, s: 4, o: 5, r: 6 } }); test({}); } expect_stdout: [ "1 2 3 4 5 6", "undefined 7 8 9 undefined undefined", ] } mangle_destructuring_decl_array: { options = { evaluate: true, unused: true, toplevel: true, } mangle = { toplevel: true, } beautify = { ecma: 6 } input: { var [, t, e, n, s, o = 2, r = [ 1 + 2 ]] = [ 9, 8, 7, 6 ]; console.log(t, e, n, s, o, r); } expect: { var [, o, l, a, c, e = 2, g = [ 3 ]] = [ 9, 8, 7, 6 ]; console.log(o, l, a, c, e, g); } expect_stdout: "8 7 6 undefined 2 [ 3 ]" } anon_func_with_destructuring_args: { options = { evaluate: true, unused: true, toplevel: true, } mangle = { toplevel: true, } beautify = { ecma: 5, } input: { (function({foo = 1 + 0, bar = 2}, [car = 3, far = 4]) { console.log(foo, bar, car, far); })({bar: 5 - 0}, [, 6]); } expect: { (function({foo: o = 1, bar: n = 2}, [a = 3, b = 4]) { console.log(o, n, a, b); })({bar: 5}, [, 6]); } expect_stdout: "1 5 3 6" } arrow_func_with_destructuring_args: { options = { evaluate: true, unused: true, toplevel: true, } mangle = { toplevel: true, } beautify = { ecma: 5, } input: { (({foo = 1 + 0, bar = 2}, [car = 3, far = 4]) => { console.log(foo, bar, car, far); })({bar: 5 - 0}, [, 6]); } expect: { (({foo: o = 1, bar: a = 2}, [b = 3, l = 4]) => { console.log(o, a, b, l); })({bar: 5}, [, 6]); } expect_stdout: "1 5 3 6" } issue_2044_ecma_5: { beautify = { beautify: false, ecma: 5, } input: { ({x : a = 1, y = 2 + b, z = 3 - c} = obj); } expect_exact: "({x:a=1,y:y=2+b,z:z=3-c}=obj);" } issue_2044_ecma_6: { beautify = { beautify: false, ecma: 6, } input: { ({x : a = 1, y = 2 + b, z = 3 - c} = obj); } expect_exact: "({x:a=1,y=2+b,z=3-c}=obj);" } issue_2044_ecma_5_beautify: { beautify = { beautify: true, ecma: 5, } input: { ({x : a = 1, y = 2 + b, z = 3 - c} = obj); } expect_exact: "({x: a = 1, y: y = 2 + b, z: z = 3 - c} = obj);" } issue_2044_ecma_6_beautify: { beautify = { beautify: true, ecma: 6, } input: { ({x : a = 1, y = 2 + b, z = 3 - c} = obj); } expect_exact: "({x: a = 1, y = 2 + b, z = 3 - c} = obj);" } issue_2140: { options = { unused: true, } input: { !function() { var t = {}; console.log(([t.a] = [42])[0]); }(); } expect: { !function() { var t = {}; console.log(([t.a] = [42])[0]); }(); } expect_stdout: "42" } issue_3205_1: { options = { inline: 3, reduce_vars: true, side_effects: true, unused: true, } input: { function f(a) { function g() { var {b, c} = a; console.log(b, c); } g(); } f({ b: 2, c: 3 }); } expect: { function f(a) { (function() { var {b: b, c: c} = a; console.log(b, c); })(); } f({ b: 2, c: 3 }); } expect_stdout: "2 3" } issue_3205_2: { options = { inline: 3, side_effects: true, unused: true, } input: { (function() { function f() { var o = { a: "PASS" }, {a: x} = o; console.log(x); } f(); })(); } expect: { (function() { function f() { var o = { a: "PASS" }, {a: x} = o; console.log(x); } f(); })(); } expect_stdout: "PASS" } issue_3205_3: { options = { inline: 3, side_effects: true, unused: true, } input: { (function() { function f(o, {a: x} = o) { console.log(x); } f({ a: "PASS" }); })(); } expect: { (function() { function f(o, {a: x} = o) { console.log(x); } f({ a: "PASS" }); })(); } expect_stdout: "PASS" } issue_3205_4: { options = { inline: 3, side_effects: true, unused: true, } input: { (function() { function f(o) { var {a: x} = o; console.log(x); } f({ a: "PASS" }); })(); } expect: { (function() { function f(o) { var {a: x} = o; console.log(x); } f({ a: "PASS" }); })(); } expect_stdout: "PASS" } issue_3205_5: { options = { inline: 3, passes: 4, reduce_vars: true, side_effects: true, unused: true, } input: { (function() { function f(g) { var o = g, {a: x} = o; console.log(x); } f({ a: "PASS" }); })(); } expect: { !function(g) { var {a: x} = { a: "PASS" }; console.log(x); }(); } expect_stdout: "PASS" } unused_destructuring_decl_1: { options = { pure_getters: true, toplevel: true, unused: true, } input: { let { x: L, y } = { x: 2 }; var { U: u, V } = { V: 3 }; const { C, D } = { C: 1, D: 4 }; console.log(L, V); } expect: { let { x: L } = { x: 2 }; var { V } = { V: 3 }; console.log(L, V); } expect_stdout: "2 3" } unused_destructuring_decl_2: { options = { pure_getters: true, toplevel: false, unused: true, } input: { const { a, b: c, d = new Object(1) } = { b: 7 }; let { e, f: g, h = new Object(2) } = { e: 8 }; var { w, x: y, z = new Object(3) } = { w: 4, x: 5, y: 6 }; console.log(c, e, z + 0); } expect: { const { a, b: c, d = new Object(1) } = { b: 7 }; let { e, f: g, h = new Object(2) } = { e: 8 }; var { w, x: y, z = new Object(3) } = { w: 4, x: 5, y: 6 }; console.log(c, e, z + 0); } expect_stdout: "7 8 3" } unused_destructuring_decl_3: { options = { pure_getters: false, toplevel: true, unused: true, } input: { const { a, b: c, d = new Object(1) } = { b: 7 }; let { e, f: g, h = new Object(2) } = { e: 8 }; var { w, x: y, z = new Object(3) } = { w: 4, x: 5, y: 6 }; console.log(c, e, z + 0); } expect: { const { a, b: c, d = new Object(1) } = { b: 7 }; let { e, f: g, h = new Object(2) } = { e: 8 }; var { w, x: y, z = new Object(3) } = { w: 4, x: 5, y: 6 }; console.log(c, e, z + 0); } expect_stdout: "7 8 3" } unused_destructuring_decl_4: { options = { pure_getters: true, toplevel: true, unused: false, } input: { const { a, b: c, d = new Object(1) } = { b: 7 }; let { e, f: g, h = new Object(2) } = { e: 8 }; var { w, x: y, z = new Object(3) } = { w: 4, x: 5, y: 6 }; console.log(c, e, z + 0); } expect: { const { a, b: c, d = new Object(1) } = { b: 7 }; let { e, f: g, h = new Object(2) } = { e: 8 }; var { w, x: y, z = new Object(3) } = { w: 4, x: 5, y: 6 }; console.log(c, e, z + 0); } expect_stdout: "7 8 3" } unused_destructuring_decl_5: { options = { pure_getters: true, toplevel: true, top_retain: [ "a", "e", "w" ], unused: true, } input: { const { a, b: c, d = new Object(1) } = { b: 7 }; let { e, f: g, h = new Object(2) } = { e: 8 }; var { w, x: y, z = new Object(3) } = { w: 4, x: 5, y: 6 }; console.log(c, e, z + 0); } expect: { const { a, b: c, d = new Object(1) } = { b: 7 }; let { e, h = new Object(2) } = { e: 8 }; var { w, z = new Object(3) } = { w: 4, x: 5, y: 6 }; console.log(c, e, z + 0); } expect_stdout: "7 8 3" } unused_destructuring_function_param: { options = { pure_getters: true, unused: true, } input: { function foo({w = console.log("side effect"), x, y: z}) { console.log(x); } foo({x: 1, y: 2, z: 3}); } expect: { function foo({w = console.log("side effect"), x}) { console.log(x); } foo({x: 1, y: 2, z: 3}); } expect_stdout: [ "side effect", "1", ] } unused_destructuring_arrow_param: { options = { pure_getters: true, unused: true, } input: { let bar = ({w = console.log("side effect"), x, y: z}) => { console.log(x); }; bar({x: 4, y: 5, z: 6}); } expect: { let bar = ({w = console.log("side effect"), x}) => { console.log(x); }; bar({x: 4, y: 5, z: 6}); } expect_stdout: [ "side effect", "4", ] } unused_destructuring_object_method_param: { options = { pure_getters: true, unused: true, } input: { ({ baz({w = console.log("side effect"), x, y: z}) { console.log(x); } }).baz({x: 7, y: 8, z: 9}); } expect: { ({ baz({w = console.log("side effect"), x}) { console.log(x); } }).baz({x: 7, y: 8, z: 9}); } expect_stdout: [ "side effect", "7", ] } unused_destructuring_class_method_param: { options = { pure_getters: true, unused: true, } input: { (new class { baz({w = console.log("side effect"), x, y: z}) { console.log(x); } }).baz({x: 7, y: 8, z: 9}); } expect: { (new class { baz({w = console.log("side effect"), x}) { console.log(x); } }).baz({x: 7, y: 8, z: 9}); } expect_stdout: [ "side effect", "7", ] } unused_destructuring_getter_side_effect_1: { options = { pure_getters: false, unused: true, } input: { function extract(obj) { const { a, b } = obj; console.log(b); } extract({a: 1, b: 2}); extract({ get a() { var s = "side effect"; console.log(s); return s; }, b: 4, }); } expect: { function extract(obj) { const { a, b } = obj; console.log(b); } extract({a: 1, b: 2}); extract({ get a() { var s = "side effect"; console.log(s); return s; }, b: 4, }); } expect_stdout: [ "2", "side effect", "4", ] } unused_destructuring_getter_side_effect_2: { options = { pure_getters: true, unused: true, } input: { function extract(obj) { const { a, b } = obj; console.log(b); } extract({a: 1, b: 2}); extract({ get a() { var s = "side effect"; console.log(s); return s; }, b: 4, }); } expect: { function extract(obj) { const { b } = obj; console.log(b); } extract({a: 1, b: 2}); extract({ get a() { var s = "side effect"; console.log(s); return s; }, b: 4, }); } // No `expect_stdout` clause here because `pure_getters` // drops the getter side effect as expected and produces // different output than the original `input` code. } unused_destructuring_assign_1: { options = { pure_getters: true, unused: true, } input: { function extract(obj) { var a; let b; ({ a, b } = obj); console.log(b); } extract({a: 1, b: 2}); extract({b: 4}); } expect: { function extract(obj) { var a; let b; ({ a, b } = obj); // TODO: future optimization opportunity console.log(b); } extract({a: 1, b: 2}); extract({b: 4}); } expect_stdout: [ "2", "4", ] } unused_destructuring_assign_2: { options = { pure_getters: false, unused: true, } input: { function extract(obj) { var a; let b; ({ a, b } = obj); console.log(b); } extract({a: 1, b: 2}); extract({ get a() { var s = "side effect"; console.log(s); return s; }, b: 4, }); } expect: { function extract(obj) { var a; let b; ({ a, b } = obj); console.log(b); } extract({a: 1, b: 2}); extract({ get a() { var s = "side effect"; console.log(s); return s; }, b: 4, }); } expect_stdout: [ "2", "side effect", "4", ] } export_unreferenced_declarations_1: { options = { module: true, pure_getters: true, unused: true, } beautify = { beautify: false, ecma: 6, } input: { export const { keys } = Object; export let { L, M } = Object; export var { V, W } = Object; } expect_exact: "export const{keys}=Object;export let{L,M}=Object;export var{V,W}=Object;" } export_unreferenced_declarations_2: { options = { module: true, pure_getters: true, unused: true, } input: { var {unused} = obj; export const [{a, b = 1}] = obj; export let [[{c, d = 2}]] = obj; export var [, [{e, f = 3}]] = obj; } expect: { obj; export const [{a, b = 1}] = obj; export let [[{c, d = 2}]] = obj; export var [, [{e, f = 3}]] = obj; } } export_function_containing_destructuring_decl: { options = { module: true, pure_getters: true, unused: true, } input: { export function f() { let [{x, y, z}] = [{x: 1, y: 2}]; return x; } } expect: { export function f() { let [{x}] = [{x: 1, y: 2}]; return x; } } } unused_destructuring_declaration_complex_1: { options = { toplevel: true, pure_getters: true, unused: true, } input: { const [, w, , x, {y, z}] = [1, 2, 3, 4, {z: 5}]; console.log(x, z); } expect: { // TODO: unused destructuring array declarations not optimized const [, w, , x, {z}] = [1, 2, 3, 4, {z: 5}]; console.log(x, z); } expect_stdout: "4 5" } unused_destructuring_declaration_complex_2: { options = { toplevel: true, pure_getters: false, unused: true, } input: { const [, w, , x, {y, z}] = [1, 2, 3, 4, {z: 5}]; console.log(x, z); } expect: { const [, w, , x, {y, z}] = [1, 2, 3, 4, {z: 5}]; console.log(x, z); } expect_stdout: "4 5" } unused_destructuring_multipass: { options = { conditionals: true, evaluate: true, toplevel: true, passes: 2, pure_getters: true, side_effects: true, unused: true, } input: { let { w, x: y, z } = { x: 1, y: 2, z: 3 }; console.log(y); if (0) { console.log(z); } } expect: { let { x: y } = { x: 1, y: 2, z: 3 }; console.log(y); } expect_stdout: "1" } issue_t111_1: { options = { toplevel: true, unused: true, } input: { var p = x => (console.log(x), x), unused = p(1), {} = p(2); } expect: { var p = x => (console.log(x), x), {} = (p(1), p(2)); } expect_stdout: [ "1", "2", ] } issue_t111_2a: { options = { toplevel: true, unused: true, } input: { var p = x => (console.log(x), x), a = p(1), {} = p(2), c = p(3), d = p(4); } expect: { var p = x => (console.log(x), x), {} = (p(1), p(2)); p(3), p(4); } expect_stdout: [ "1", "2", "3", "4", ] } issue_t111_2b: { options = { toplevel: true, unused: true, } input: { let p = x => (console.log(x), x), a = p(1), {} = p(2), c = p(3), d = p(4); } expect: { let p = x => (console.log(x), x), {} = (p(1), p(2)); p(3), p(4); } expect_stdout: [ "1", "2", "3", "4", ] } issue_t111_2c: { options = { toplevel: true, unused: true, } input: { const p = x => (console.log(x), x), a = p(1), {} = p(2), c = p(3), d = p(4); } expect: { const p = x => (console.log(x), x), {} = (p(1), p(2)); p(3), p(4); } expect_stdout: [ "1", "2", "3", "4", ] } issue_t111_3: { options = { toplevel: true, unused: true, } input: { let p = x => (console.log(x), x), a = p(1), {} = p(2), c = p(3), {} = p(4); } expect: { let p = x => (console.log(x), x), {} = (p(1), p(2)), {} = (p(3), p(4)); } expect_stdout: [ "1", "2", "3", "4", ] } issue_t111_4: { options = { toplevel: true, unused: true, } input: { let p = x => (console.log(x), x), a = 1, {length} = [0], c = 3, {x} = {x: 2}; p(`${length} ${x}`); } expect: { let p = x => (console.log(x), x), {length} = [0], {x} = {x: 2}; p(`${length} ${x}`); } expect_stdout: "1 2" } empty_object_destructuring_1: { options = { pure_getters: false, toplevel: true, unused: true, } input: { var {} = Object; let {L} = Object, L2 = "foo"; const bar = "bar", {prop: C1, C2 = console.log("side effect"), C3} = Object; } expect: { var {} = Object; let {L: L} = Object; const {prop: C1, C2: C2 = console.log("side effect"), C3: C3} = Object; } expect_stdout: "side effect" } empty_object_destructuring_2: { options = { pure_getters: "strict", toplevel: true, unused: true, } input: { var {} = Object; let {L} = Object, L2 = "foo"; const bar = "bar", {prop: C1, C2 = console.log("side effect"), C3} = Object; } expect: { var {} = Object; let {L: L} = Object; const {prop: C1, C2: C2 = console.log("side effect"), C3: C3} = Object; } expect_stdout: "side effect" } empty_object_destructuring_3: { options = { pure_getters: true, toplevel: true, unused: true, } input: { var {} = Object; let {L} = Object, L2 = "foo"; const bar = "bar", {prop: C1, C2 = console.log("side effect"), C3} = Object; } expect: { const {C2: C2 = console.log("side effect")} = Object; } expect_stdout: "side effect" } empty_object_destructuring_4: { options = { pure_getters: true, toplevel: true, unsafe: true, unused: true, } input: { var {} = Object; let {L} = Object, L2 = "foo"; const bar = "bar", {prop: C1, C2 = console.log("side effect"), C3} = Object; } expect: { const {C2: C2 = console.log("side effect")} = Object; } expect_stdout: "side effect" } empty_object_destructuring_misc: { options = { pure_getters: true, toplevel: true, unsafe: true, unused: true, } input: { let out = [], foo = (out.push(0), 1), {} = {k: 9}, bar = out.push(2), {unused} = (out.push(3), {unused: 7}), {a: b, prop, w, x: y, z} = {prop: 8}, baz = (out.push(4), 5); console.log(`${foo} ${prop} ${baz} ${JSON.stringify(out)}`); } expect: { let out = [], foo = (out.push(0), 1), {prop: prop} = (out.push(2), out.push(3), {prop: 8}), baz = (out.push(4), 5); console.log(`${foo} ${prop} ${baz} ${JSON.stringify(out)}`); } expect_stdout: "1 8 5 [0,2,3,4]" } destructure_empty_array_1: { options = { pure_getters: false, toplevel: true, unsafe: true, unused: true, } input: { let {} = Object, [] = {}, unused = console.log("not reached"); } expect: { let {} = Object, [] = {}; console.log("not reached"); } expect_stdout: true // TypeError: {} is not iterable } destructure_empty_array_2: { options = { pure_getters: "strict", toplevel: true, unsafe: true, unused: true, } input: { let {} = Object, [] = {}, unused = console.log("not reached"); } expect: { let {} = Object, [] = {}; console.log("not reached"); } expect_stdout: true // TypeError: {} is not iterable } destructure_empty_array_3: { options = { pure_getters: true, toplevel: true, unsafe: true, unused: true, } input: { let {} = Object, [] = {}, unused = console.log("not reached"); } expect: { let [] = {}; console.log("not reached"); } expect_stdout: true // TypeError: {} is not iterable } terser-4.1.2/test/compress/directives.js000066400000000000000000000024011351061312300203230ustar00rootroot00000000000000class_directives_compression: { options = { directives: true, } input: { class foo { foo() { "use strict"; } } } expect_exact: "class foo{foo(){}}" } 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", ] } terser-4.1.2/test/compress/drop-console.js000066400000000000000000000016241351061312300205740ustar00rootroot00000000000000drop_console_1: { options = {} input: { console.log('foo'); console.log.apply(console, arguments); } expect: { console.log('foo'); console.log.apply(console, arguments); } } drop_console_2: { options = { drop_console: 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; } } unexpected_side_effects_dropping_console: { options = { drop_console: true, evaluate: true, reduce_vars: true, side_effects: true, unused: true, } input: { function f() { var a = 33; console.log(a++); alert(a); } } expect: { function f() { alert(33); } } } terser-4.1.2/test/compress/drop-unused.js000066400000000000000000001454131351061312300204420ustar00rootroot00000000000000unused_funarg_1: { options = { keep_fargs: false, unused: true, } input: { function f(a, b, c, d, e) { return a + b; } } expect: { function f(a, b) { return a + b; } } } unused_funarg_2: { options = { keep_fargs: false, unused: true, } input: { function f(a, b, c, d, e) { return a + c; } } expect: { function f(a, b, c) { return a + c; } } } unused_nested_function: { options = { unused: true, } input: { function f(x, y) { function g() { something(); } return x + y; } }; expect: { function f(x, y) { return x + y; } } } unused_circular_references_1: { options = { unused: true, } input: { function f(x, y) { // circular reference function g() { return h(); } function h() { return g(); } return x + y; } }; expect: { function f(x, y) { return x + y; } } } unused_circular_references_2: { options = { unused: true, } input: { function f(x, y) { var foo = 1, bar = baz, baz = foo + bar, qwe = moo(); return x + y; } }; expect: { function f(x, y) { moo(); // keeps side effect return x + y; } } } unused_circular_references_3: { options = { unused: true, } input: { function f(x, y) { var g = function() { return h() }; var h = function() { return g() }; return x + y; } }; expect: { function f(x, y) { return x + y; } } } unused_keep_setter_arg: { options = { unused: true, } input: { var x = { _foo: null, set foo(val) { }, get foo() { return this._foo; } } } expect: { var x = { _foo: null, set foo(val) { }, get foo() { return this._foo; } } } } unused_var_in_catch: { options = { unused: true, } input: { function foo() { try { foo(); } catch(ex) { var x = 10; } } } expect: { function foo() { try { foo(); } catch(ex) {} } } } used_var_in_catch: { options = { unused: true, } input: { function foo() { try { foo(); } catch(ex) { var x = 10; } return x; } } expect: { function foo() { try { foo(); } catch(ex) { var x = 10; } return x; } } } unused_block_decls_in_catch: { options = { unused: true }; input: { function foo() { try { foo(); } catch(ex) { let x = 10; const y = 10; class Zee {}; } } } expect: { function foo() { try { foo(); } catch(ex) {} } } } used_block_decls_in_catch: { options = { unused: true }; input: { function foo() { try { foo(); } catch(ex) { let x = 10; const y = 10; class Zee {}; } console.log(x, y, Zee); } } expect: { function foo() { try { foo(); } catch(ex) {} console.log(x, y, Zee); } } } unused_block_decls: { options = { unused: true }; input: { function foo() { { const x = 1; } { let y; } console.log(x, y); } } expect: { function foo() { console.log(x, y); } } } unused_keep_harmony_destructuring: { options = { unused: true }; input: { function foo() { var {x, y} = foo; var a = foo; } } expect: { function foo() { var {x, y} = foo; } } } keep_fnames: { options = { keep_fnames: true, unsafe: true, unused: true, } input: { function foo() { return function bar(baz) {}; } } expect: { function foo() { return function bar(baz) {}; } } } drop_assign: { options = { unused: true, } input: { function f1() { var a; a = 1; } function f2() { var a = 1; a = 2; } function f3(a) { a = 1; } function f4() { var a; return a = 1; } function f5() { var a; return function() { a = 1; }; } } expect: { function f1() { 1; } function f2() { 2; } function f3(a) { 1; } function f4() { return 1; } function f5() { return function() { 1; }; } } } keep_assign: { options = { unused: "keep_assign", } input: { function f1() { var a; a = 1; } function f2() { var a = 1; a = 2; } function f3(a) { a = 1; } function f4() { var a; return a = 1; } function f5() { var a; return function() { a = 1; }; } } expect: { function f1() { var a; a = 1; } function f2() { var a = 1; a = 2; } function f3(a) { a = 1; } function f4() { var a; return a = 1; } function f5() { var a; return function() { a = 1; }; } } } drop_toplevel_funcs: { options = { toplevel: "funcs", unused: true, } input: { var a, b = 1, c = g; function f(d) { return function() { c = 2; }; } a = 2; function g() {} function h() {} console.log(b = 3); } expect: { var a, b = 1, c = g; a = 2; function g() {} console.log(b = 3); } } drop_toplevel_vars: { options = { toplevel: "vars", unused: true, } input: { var a, b = 1, c = g; function f(d) { return function() { c = 2; }; } a = 2; function g() {} function h() {} console.log(b = 3); } expect: { function f(d) { return function() { 2; }; } 2; function g() {} function h() {} console.log(3); } } drop_toplevel_vars_fargs: { options = { keep_fargs: false, toplevel: "vars", unused: true, } input: { var a, b = 1, c = g; function f(d) { return function() { c = 2; }; } a = 2; function g() {} function h() {} console.log(b = 3); } expect: { function f() { return function() { 2; }; } 2; function g() {} function h() {} console.log(3); } } drop_toplevel_all: { options = { toplevel: true, unused: true, } input: { var a, b = 1, c = g; function f(d) { return function() { c = 2; }; } a = 2; function g() {} function h() {} console.log(b = 3); } expect: { 2; console.log(3); } } drop_toplevel_retain: { options = { top_retain: "f,a,o", unused: true, } input: { var a, b = 1, c = g; function f(d) { return function() { c = 2; }; } a = 2; function g() {} function h() {} console.log(b = 3); } expect: { var a; function f(d) { return function() { 2; }; } a = 2; console.log(3); } } drop_toplevel_retain_array: { options = { top_retain: [ "f", "a", "o" ], unused: true, } input: { var a, b = 1, c = g; function f(d) { return function() { c = 2; }; } a = 2; function g() {} function h() {} console.log(b = 3); } expect: { var a; function f(d) { return function() { 2; }; } a = 2; console.log(3); } } drop_toplevel_retain_regex: { options = { top_retain: /^[fao]$/, unused: true, } input: { var a, b = 1, c = g; function f(d) { return function() { c = 2; }; } a = 2; function g() {} function h() {} console.log(b = 3); } expect: { var a; function f(d) { return function() { 2; }; } a = 2; console.log(3); } } drop_toplevel_all_retain: { options = { top_retain: "f,a,o", toplevel: true, unused: true, } input: { var a, b = 1, c = g; function f(d) { return function() { c = 2; }; } a = 2; function g() {} function h() {} console.log(b = 3); } expect: { var a; function f(d) { return function() { 2; }; } a = 2; console.log(3); } } drop_toplevel_funcs_retain: { options = { top_retain: "f,a,o", toplevel: "funcs", unused: true, } input: { var a, b = 1, c = g; function f(d) { return function() { c = 2; }; } a = 2; function g() {} function h() {} console.log(b = 3); } expect: { var a, b = 1, c = g; function f(d) { return function() { c = 2; }; } a = 2; function g() {} console.log(b = 3); } } drop_toplevel_vars_retain: { options = { top_retain: "f,a,o", toplevel: "vars", unused: true, } input: { var a, b = 1, c = g; function f(d) { return function() { c = 2; }; } a = 2; function g() {} function h() {} console.log(b = 3); } expect: { var a; function f(d) { return function() { 2; }; } a = 2; function g() {} function h() {} console.log(3); } } drop_toplevel_keep_assign: { options = { toplevel: true, unused: "keep_assign", } input: { var a, b = 1, c = g; function f(d) { return function() { c = 2; }; } a = 2; function g() {} function h() {} console.log(b = 3); } expect: { var a, b = 1; a = 2; console.log(b = 3); } } drop_fargs: { options = { keep_fargs: false, unused: true, } input: { function f(a) { var b = a; } } expect: { function f() {} } } drop_fnames: { options = { keep_fnames: false, unused: true, } input: { function f() { return function g() { var a = g; }; } } expect: { function f() { return function() {}; } } } global_var: { options = { side_effects: true, unused: true, } input: { var a; function foo(b) { a; b; c; typeof c === "undefined"; c + b + a; b && b.ar(); return b; } } expect: { var a; function foo(b) { c; c; b && b.ar(); return b; } } } iife: { options = { side_effects: true, unused: true, } input: { function f() { var a; ~function() {}(b); } } expect: { function f() { b; } } } drop_value: { options = { side_effects: true, } input: { (1, [2, foo()], 3, {a:1, b:bar()}); } expect: { foo(), bar(); } } const_assign: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { function f() { const b = 2; return 1 + b; } function g() { const b = 2; b = 3; return 1 + b; } } expect: { function f() { return 3; } function g() { const b = 2; b = 3; return 1 + b; } } } issue_1539: { options = { collapse_vars: true, sequences: true, side_effects: true, unused: true, } input: { function f() { var a, b; a = b = 42; return a; } } expect: { function f() { return 42; } } } vardef_value: { options = { keep_fnames: false, reduce_funcs: true, reduce_vars: true, unused: true, } input: { function f() { function g(){ return x(); } var a = g(); return a(42); } } expect: { function f() { var a = function(){ return x(); }(); return a(42); } } } assign_binding: { options = { collapse_vars: true, side_effects: true, unused: true, } input: { function f() { var a; a = f.g, a(); } } expect: { function f() { (0, f.g)(); } } } assign_chain: { options = { unused: true, } input: { function f() { var a, b; x = a = y = b = 42; } } expect: { function f() { x = y = 42; } } } issue_1583: { options = { keep_fargs: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { function m(t) { (function(e) { t = e(); })(function() { return (function(a) { return a; })(function(a) {}); }); } } expect: { function m(t) { (function(e) { (function() { return (function(a) { return function(a) {}; })(); })(); })(); } } } issue_1656: { options = { toplevel: true, unused: true, } beautify = { beautify: true, } input: { for(var a=0;;); } expect_exact: "for (;;) ;" } issue_1709: { options = { unused: true, } input: { console.log( function x() { var x = 1; return x; }(), function y() { const y = 2; return y; }(), function z() { function z() {} return z; }() ); } expect: { console.log( function() { var x = 1; return x; }(), function() { const y = 2; return y; }(), function() { function z() {} return z; }() ); } expect_stdout: true } issue_1715_1: { options = { unused: true, } input: { var a = 1; function f() { a++; try { x(); } catch (a) { var a; } } f(); console.log(a); } expect: { var a = 1; function f() { a++; try { x(); } catch (a) { var a; } } f(); console.log(a); } expect_stdout: "1" } issue_1715_2: { options = { unused: true, } input: { var a = 1; function f() { a++; try { x(); } catch (a) { var a = 2; } } f(); console.log(a); } expect: { var a = 1; function f() { a++; try { x(); } catch (a) { var a; } } f(); console.log(a); } expect_stdout: "1" } issue_1715_3: { options = { unused: true, } input: { var a = 1; function f() { a++; try { console; } catch (a) { var a = 2 + x(); } } f(); console.log(a); } expect: { var a = 1; function f() { a++; try { console; } catch (a) { var a; x(); } } f(); console.log(a); } expect_stdout: "1" } issue_1715_4: { options = { unused: true, } input: { var a = 1; !function a() { a++; try { x(); } catch (a) { var a; } }(); console.log(a); } expect: { var a = 1; !function() { a++; try { x(); } catch (a) { var a; } }(); console.log(a); } expect_stdout: "1" } delete_assign_1: { options = { booleans: true, side_effects: true, toplevel: true, unused: true, } input: { var a; console.log(delete (a = undefined)); console.log(delete (a = void 0)); console.log(delete (a = Infinity)); console.log(delete (a = 1 / 0)); console.log(delete (a = NaN)); console.log(delete (a = 0 / 0)); } expect: { console.log((void 0, !0)); console.log((void 0, !0)); console.log((1 / 0, !0)); console.log((1 / 0, !0)); console.log((NaN, !0)); console.log((0 / 0, !0)); } expect_stdout: true } delete_assign_2: { options = { booleans: true, keep_infinity: true, side_effects: true, toplevel: true, unused: true, } input: { var a; console.log(delete (a = undefined)); console.log(delete (a = void 0)); console.log(delete (a = Infinity)); console.log(delete (a = 1 / 0)); console.log(delete (a = NaN)); console.log(delete (a = 0 / 0)); } expect: { console.log((void 0, !0)); console.log((void 0, !0)); console.log((Infinity, !0)); console.log((1 / 0, !0)); console.log((NaN, !0)); console.log((0 / 0, !0)); } expect_stdout: true } drop_var: { options = { toplevel: true, unused: true, } input: { var a; console.log(a, b); var a = 1, b = 2; console.log(a, b); var a = 3; console.log(a, b); } expect: { console.log(a, b); var a = 1, b = 2; console.log(a, b); a = 3; console.log(a, b); } expect_stdout: [ "undefined undefined", "1 2", "3 2", ] } issue_1830_1: { options = { unused: true, } input: { !function() { L: for (var b = console.log(1); !1;) continue L; }(); } expect: { !function() { L: for (console.log(1); !1;) continue L; }(); } expect_stdout: "1" } issue_1830_2: { options = { unused: true, } input: { !function() { L: for (var a = 1, b = console.log(a); --a;) continue L; }(); } expect: { !function() { var a = 1; L: for (console.log(a); --a;) continue L; }(); } expect_stdout: "1" } issue_1838: { options = { join_vars: true, loops: true, unused: true, } beautify = { beautify: true, } input: { function f() { var b = a; while (c); } } expect_exact: [ "function f() {", " for (a; c; ) ;", "}", ] } var_catch_toplevel: { options = { conditionals: true, negate_iife: true, passes: 2, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { function f() { a--; try { a++; x(); } catch(a) { if (a) var a; var a = 10; } } f(); } expect: { !function() { try { x(); } catch(a) { var a; } }(); } } reassign_const: { options = { collapse_vars: true, sequences: true, side_effects: true, unused: true, } input: { function f() { const a = 1; a = 2; return a; } console.log(f()); } expect: { function f() { const a = 1; return a = 2, a; } console.log(f()); } expect_stdout: true } issue_1968: { options = { unused: true, } input: { function f(c) { var a; if (c) { let b; return (a = 2) + (b = 3); } } console.log(f(1)); } expect: { function f(c) { if (c) { let b; return 2 + (b = 3); } } console.log(f(1)); } expect_stdout: "5" } issue_2063: { options = { unused: true, } input: { var a; var a; } expect: { var a; } } issue_2105_1: { options = { collapse_vars: true, inline: true, passes: 3, reduce_funcs: true, reduce_vars: true, side_effects: true, unused: true, } input: { !function(factory) { factory(); }( function() { return function(fn) { fn()().prop(); }( function() { function bar() { var quux = function() { console.log("PASS"); }, foo = function() { console.log; quux(); }; return { prop: foo }; } return bar; } ); }); } expect: { ({ prop: function() { console.log; console.log("PASS"); } }).prop(); } expect_stdout: "PASS" } issue_2105_2: { options = { collapse_vars: true, inline: true, passes: 3, properties: true, pure_getters: "strict", reduce_funcs: true, reduce_vars: true, side_effects: true, unsafe: true, unused: true, } input: { !function(factory) { factory(); }( function() { return function(fn) { fn()().prop(); }( function() { function bar() { var quux = function() { console.log("PASS"); }, foo = function() { console.log; quux(); }; return { prop: foo }; } return bar; } ); }); } expect: { console.log("PASS"); } expect_stdout: "PASS" } issue_2136_1: { options = { inline: true, unused: true, } input: { !function(a, ...b) { console.log(b); }(); } expect: { !function(a, ...b) { console.log(b); }(); } expect_stdout: "[]" } issue_2136_2: { options = { collapse_vars: true, inline: true, side_effects: true, unused: true, } input: { function f(x) { console.log(x); } !function(a, ...b) { f(b[0]); }(1, 2, 3); } expect: { function f(x) { console.log(x); } f([2,3][0]); } expect_stdout: "2" } issue_2136_3: { options = { collapse_vars: true, evaluate: true, inline: true, passes: 3, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unsafe: true, unused: true, } input: { function f(x) { console.log(x); } !function(a, ...b) { f(b[0]); }(1, 2, 3); } expect: { console.log(2); } expect_stdout: "2" } issue_2163: { options = { pure_funcs: [ "pure" ], side_effects: true, } input: { var c; /*@__PURE__*/f(...a); pure(b, ...c); } expect: { var c; a; b; } } issue_2226_1: { options = { side_effects: true, unused: true, } input: { function f1() { var a = b; a += c; } function f2(a) { a <<= b; } function f3(a) { --a; } function f4() { var a = b; return a *= c; } function f5(a) { x(a /= b); } } expect: { function f1() { b; c; } function f2(a) { b; } function f3(a) { 0; } function f4() { var a = b; return a *= c; } function f5(a) { x(a /= b); } } } issue_2226_2: { options = { collapse_vars: true, sequences: true, side_effects: true, unused: true, } input: { console.log(function(a, b) { a += b; return a; }(1, 2)); } expect: { console.log(function(a, b) { return a += 2; }(1)); } expect_stdout: "3" } issue_2226_3: { options = { collapse_vars: true, side_effects: true, unused: true, } input: { console.log(function(a, b) { a += b; return a; }(1, 2)); } expect: { console.log(function(a, b) { return a += 2; }(1)); } expect_stdout: "3" } issue_2288: { options = { unused: true, } beautify = { beautify: true, } input: { function foo(o) { for (var j = o.a, i = 0; i < 0; i++); for (var i = 0; i < 0; i++); } } expect: { function foo(o) { o.a; for (var i = 0; i < 0; i++); for (i = 0; i < 0; i++); } } } issue_2516_1: { options = { collapse_vars: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { function foo() { function qux(x) { bar.call(null, x); } function bar(x) { var FOUR = 4; var trouble = x || never_called(); var value = (FOUR - 1) * trouble; console.log(value == 6 ? "PASS" : value); } Baz = qux; } var Baz; foo(); Baz(2); } expect: { function foo() { Baz = function(x) { (function(x) { var trouble = x || never_called(); var value = (4 - 1) * trouble; console.log(6 == value ? "PASS" : value); }).call(null, x); }; } var Baz; foo(); Baz(2); } } issue_2516_2: { options = { collapse_vars: true, passes: 2, reduce_funcs: true, reduce_vars: true, unused: true, } input: { function foo() { function qux(x) { bar.call(null, x); } function bar(x) { var FOUR = 4; var trouble = x || never_called(); var value = (FOUR - 1) * trouble; console.log(value == 6 ? "PASS" : value); } Baz = qux; } var Baz; foo(); Baz(2); } expect: { function foo() { Baz = function(x) { (function(x) { var value = (4 - 1) * (x || never_called()); console.log(6 == value ? "PASS" : value); }).call(null, x); }; } var Baz; foo(); Baz(2); } } issue_2418_1: { options = { unused: true, } input: { class C {} function F() {} (class c {}); (function f() {}); } expect: { class C {} function F() {} (class {}); (function() {}); } } issue_2418_2: { options = { keep_classnames: false, keep_fnames: false, unused: true, } input: { class C {} function F() {} (class c {}); (function f() {}); } expect: { class C {} function F() {} (class {}); (function() {}); } } issue_2418_3: { options = { keep_classnames: false, keep_fnames: true, unused: true, } input: { class C {} function F() {} (class c {}); (function f() {}); } expect: { class C {} function F() {} (class {}); (function f() {}); } } issue_2418_4: { options = { keep_classnames: true, keep_fnames: false, unused: true, } input: { class C {} function F() {} (class c {}); (function f() {}); } expect: { class C {} function F() {} (class c {}); (function() {}); } } issue_2418_5: { options = { keep_classnames: true, keep_fnames: true, unused: true, } input: { class C {} function F() {} (class c {}); (function f() {}); } expect: { class C {} function F() {} (class c {}); (function f() {}); } } defun_lambda_same_name: { options = { toplevel: true, unused: true, } input: { function f(n) { return n ? n * f(n - 1) : 1; } console.log(function f(n) { return n ? n * f(n - 1) : 1; }(5)); } expect: { console.log(function f(n) { return n ? n * f(n - 1) : 1; }(5)); } expect_stdout: "120" } issue_2660_1: { options = { reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { var a = 2; function f(b) { return b && f() || a--; } f(1); console.log(a); } expect: { var a = 2; (function f(b) { return b && f() || a--; })(1); console.log(a); } expect_stdout: "1" } issue_2660_2: { options = { collapse_vars: true, reduce_vars: true, sequences: true, side_effects: true, toplevel: true, unused: true, } input: { var a = 1; function f(b) { b && f(); --a, a.toString(); } f(); console.log(a); } expect: { var a = 1; (function f(b) { b && f(), (--a).toString(); })(), console.log(a); } expect_stdout: "0" } issue_2665: { options = { evaluate: true, inline: true, keep_fargs: false, passes: 2, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, typeofs: true, unused: true, } input: { var a = 1; function g() { a-- && g(); } typeof h == "function" && h(); function h() { typeof g == "function" && g(); } console.log(a); } expect: { var a = 1; !function g() { a-- && g(); }(); console.log(a); } expect_stdout: "-1" } double_assign_1: { options = { passes: 2, reduce_vars: true, side_effects: true, unused: true, } input: { function f1() { var a = {}; var a = []; return a; } function f2() { var a = {}; a = []; return a; } function f3() { a = {}; var a = []; return a; } function f4(a) { a = {}; a = []; return a; } function f5(a) { var a = {}; a = []; return a; } function f6(a) { a = {}; var a = []; return a; } console.log(f1(), f2(), f3(), f4(), f5(), f6()); } expect: { function f1() { return []; } function f2() { var a; a = []; return a; } function f3() { return []; } function f4(a) { a = []; return a; } function f5(a) { a = []; return a; } function f6(a) { a = []; return a; } console.log(f1(), f2(), f3(), f4(), f5(), f6()); } expect_stdout: true } double_assign_2: { options = { reduce_vars: true, toplevel: true, unused: true, } input: { for (var i = 0; i < 2; i++) a = void 0, a = {}, console.log(a); var a; } expect: { for (var i = 0; i < 2; i++) void 0, a = {}, console.log(a); var a; } } double_assign_3: { options = { reduce_vars: true, toplevel: true, unused: true, } input: { for (var i = 0; i < 2; i++) a = void 0, a = { a: a }, console.log(a); var a; } expect: { for (var i = 0; i < 2; i++) a = void 0, a = { a: a }, console.log(a); var a; } } cascade_drop_assign: { options = { reduce_vars: true, toplevel: true, unused: true, } input: { var a, b = a = "PASS"; console.log(b); } expect: { var b = "PASS"; console.log(b); } expect_stdout: "PASS" } chained_3: { options = { reduce_vars: true, unused: true, } input: { console.log(function(a, b) { var c = a, c = b; b++; return c; }(1, 2)); } expect: { console.log(function(a, b) { var c = b; b++; return c; }(0, 2)); } expect_stdout: "2" } issue_2768: { options = { inline: true, reduce_vars: true, sequences: true, side_effects: true, toplevel: true, unused: true, } input: { var a = "FAIL", c = 1; var c = function(b) { var d = b = a; var e = --b + (d && (a = "PASS")); }(); console.log(a, typeof c); } expect: { var a = "FAIL"; var c = (d = a, 0, void (d && (a = "PASS"))); var d; console.log(a, typeof c); } expect_stdout: "PASS undefined" } issue_2846: { options = { collapse_vars: true, reduce_vars: true, toplevel: true, unused: true, } input: { function f(a, b) { var a = 0; b && b(a); return a++; } var c = f(); console.log(c); } expect: { var c = function(a, b) { a = 0; b && b(a); return a++; }(); console.log(c); } expect_stdout: "0" } issue_805_1: { options = { inline: true, passes: 2, pure_getters: "strict", reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { (function(a) { var unused = function() {}; unused.prototype[a()] = 42; (unused.prototype.bar = function() { console.log("bar"); })(); return unused; })(function() { console.log("foo"); return "foo"; }); } expect_stdout: [ "foo", "bar", ] } issue_805_2: { options = { inline: true, passes: 2, pure_getters: "strict", reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { (function(a) { function unused() {} unused.prototype[a()] = 42; (unused.prototype.bar = function() { console.log("bar"); })(); return unused; })(function() { console.log("foo"); return "foo"; }); } expect_stdout: [ "foo", "bar", ] } issue_2995: { options = { pure_getters: "strict", reduce_vars: true, unused: true, } input: { function f(a) { var b; a.b = b = function() {}; b.c = "PASS"; } var o = {}; f(o); console.log(o.b.c); } expect: { function f(a) { var b; a.b = b = function() {}; b.c = "PASS"; } var o = {}; f(o); console.log(o.b.c); } expect_stdout: "PASS" } issue_3146_1: { options = { collapse_vars: true, unused: true, } input: { (function(f) { f("g()"); })(function(a) { eval(a); function g(b) { if (!b) b = "PASS"; console.log(b); } }); } expect: { (function(f) { f("g()"); })(function(a) { eval(a); function g(b) { if (!b) b = "PASS"; console.log(b); } }); } expect_stdout: "PASS" } issue_3146_2: { options = { reduce_vars: true, unused: true, } input: { (function(f) { f("g()"); })(function(a) { eval(a); function g(b) { if (!b) b = "PASS"; console.log(b); } }); } expect: { (function(f) { f("g()"); })(function(a) { eval(a); function g(b) { if (!b) b = "PASS"; console.log(b); } }); } expect_stdout: "PASS" } issue_3146_3: { options = { collapse_vars: true, unused: true, } input: { var g = "PASS"; (function(f) { var g = "FAIL"; f("console.log(g)", g[g]); })(function(a) { eval(a); }); } expect: { var g = "PASS"; (function(f) { var g = "FAIL"; f("console.log(g)", g[g]); })(function(a) { eval(a); }); } expect_stdout: "PASS" } issue_3146_4: { options = { reduce_vars: true, unused: true, } input: { var g = "PASS"; (function(f) { var g = "FAIL"; f("console.log(g)", g[g]); })(function(a) { eval(a); }); } expect: { var g = "PASS"; (function(f) { var g = "FAIL"; f("console.log(g)", g[g]); })(function(a) { eval(a); }); } expect_stdout: "PASS" } issue_3192: { options = { unused: true, } input: { (function(a) { console.log(a = "foo", arguments[0]); })("bar"); (function(a) { "use strict"; console.log(a = "foo", arguments[0]); })("bar"); } expect: { (function(a) { console.log(a = "foo", arguments[0]); })("bar"); (function(a) { "use strict"; console.log("foo", arguments[0]); })("bar"); } expect_stdout: [ "foo foo", "foo bar", ] } issue_t161_top_retain_1: { options = { reduce_vars: true, top_retain: "f", unused: true, } input: { function f() { return 2; } function g() { return 3; } console.log(f(), g()); } expect: { function f() { return 2; } console.log(f(), function() { return 3; }()); } expect_stdout: "2 3" } issue_t161_top_retain_2: { options = { reduce_vars: true, top_retain: "f", unused: true, } input: { function f() { return 2; } function g() { return 3; } console.log(f(), f(), g(), g()); } expect: { function f() { return 2; } function g() { return 3; } console.log(f(), f(), g(), g()); } expect_stdout: "2 2 3 3" } issue_t161_top_retain_3: { options = { defaults: true, inline: 3, passes: 3, top_retain: "f", } input: { function f() { return 2; } function g() { return 3; } console.log(f(), g()); } expect: { function f() { return 2; } console.log(f(), 3); } expect_stdout: "2 3" } issue_t161_top_retain_4: { options = { defaults: true, inline: 3, passes: 3, top_retain: "f", } input: { function f() { return 2; } function g() { return 3; } console.log(f(), f(), g(), g()); } expect: { function f() { return 2; } console.log(f(), f(), 3, 3); } expect_stdout: "2 2 3 3" } issue_t161_top_retain_5: { options = { defaults: true, inline: 3, passes: 3, top_retain: "f", } input: { (function() { function f() { return 2; } function g() { return 3; } console.log(f(), g()); })(); } expect: { console.log(2, 3); } expect_stdout: "2 3" } issue_t161_top_retain_6: { options = { defaults: true, inline: 3, passes: 3, top_retain: "f", } input: { (function() { function f() { return 2; } function g() { return 3; } console.log(f(), f(), g(), g()); })(); } expect: { console.log(2, 2, 3, 3); } expect_stdout: "2 2 3 3" } issue_t161_top_retain_7: { options = { evaluate: true, reduce_vars: true, side_effects: true, top_retain: "y", unused: true, } input: { var x = 2, y = 3, z = 4; console.log(x, y, z, x * y, x * z, y * z); } expect: { var y = 3; console.log(2, y, 4, 2 * y, 8, 4 * y); } expect_stdout: "2 3 4 6 8 12" } issue_t161_top_retain_8: { options = { defaults: true, inline: 3, passes: 2, top_retain: "y", } input: { function f() { return x; } function g() { return y; } function h() { return z; } var x = 2, y = 3, z = 4; console.log(x, y, z, x * y, x * z, y * z, f(), g(), h()); } expect: { var y = 3; console.log(2, y, 4, 2 * y, 8, 4 * y, 2, y, 4); } expect_stdout: "2 3 4 6 8 12 2 3 4" } issue_t161_top_retain_9: { options = { defaults: true, inline: 3, passes: 2, top_retain: "y", } input: { function f() { return x; } function g() { return y; } function h() { return z; } var x = 2, y = 3, z = 4; console.log(x, y, z, x * y, x * z, y * z, f(), g(), h()); } expect: { var y = 3; console.log(2, y, 4, 2 * y, 8, 4 * y, 2, y, 4); } expect_stdout: "2 3 4 6 8 12 2 3 4" } issue_t161_top_retain_10: { options = { defaults: true, inline: 3, passes: 2, top_retain: "y,f", } input: { function f() { return x; } function g() { return y; } function h() { return z; } var x = 2, y = 3, z = 4; console.log(x, y, z, x * y, x * z, y * z, f(), g(), h()); } expect: { function f() { return x; } var x = 2, y = 3; console.log(x, y, 4, x * y, 4 * x, 4 * y, f(), y, 4); } expect_stdout: "2 3 4 6 8 12 2 3 4" } issue_t161_top_retain_11: { options = { defaults: true, inline: 3, passes: 2, top_retain: "g,x,y", } input: { function f() { return x; } function g() { return y; } function h() { return z; } var x = 2, y = 3, z = 4; console.log(x, y, z, x * y, x * z, y * z, f(), g(), h()); } expect: { function g() { return y; } var x = 2, y = 3; console.log(x, y, 4, x * y, 4 * x, 4 * y, x, g(), 4); } expect_stdout: "2 3 4 6 8 12 2 3 4" } issue_t161_top_retain_12: { options = { defaults: true, inline: 3, passes: 2, top_retain: "g,h", } input: { function f() { return x; } function g() { return y; } function h() { return z; } var x = 2, y = 3, z = 4; console.log(x, y, z, x * y, x * z, y * z, f(), g(), h()); } expect: { function g() { return y; } function h() { return z; } var y = 3, z = 4; console.log(2, y, z, 2 * y, 2 * z, y * z, 2, g(), h()); } expect_stdout: "2 3 4 6 8 12 2 3 4" } issue_t161_top_retain_13: { options = { defaults: true, inline: 3, passes: 2, top_retain: "g", } input: { const f = () => x; const g = () => y; const h = () => z; const x = 2, y = 3, z = 4; console.log(x, y, z, x * y, x * z, y * z, f(), g(), h()); } expect: { const g = () => y, y = 3; console.log(2, y, 4, 2 * y, 8, 4 * y, 2, g(), 4); } expect_stdout: "2 3 4 6 8 12 2 3 4" } issue_t161_top_retain_14: { options = { defaults: true, inline: 3, passes: 2, top_retain: "Alpha,z", } input: { class Alpha { num() { return x; } } class Beta { num() { return y; } } class Carrot { num() { return z; } } function f() { return x; } const g = () => y; const h = () => z; let x = 2, y = 3, z = 4; console.log(x, y, z, x * y, x * z, y * z, f(), g(), h(), (new Alpha).num(), (new Beta).num(), (new Carrot).num()); } expect: { class Alpha { num() { return x; } } let x = 2, z = 4; console.log(x, 3, z, 3 * x, x * z, 3 * z, x, 3, (() => z)(), new Alpha().num(), new class { num() { return 3; } }().num(), new class { num() { return z; } }().num()); } expect_stdout: "2 3 4 6 8 12 2 3 4 2 3 4" } issue_t161_top_retain_15: { options = { defaults: true, inline: 3, passes: 2, top_retain: "Alpha,z", } mangle = { keep_classnames: /^Alpha$/, toplevel: true, } input: { class Alpha { num() { return x; } } class Beta { num() { return y; } } class Carrot { num() { return z; } } function f() { return x; } const g = () => y; const h = () => z; let x = 2, y = 3, z = 4; console.log(x, y, z, x * y, x * z, y * z, f(), g(), h(), (new Alpha).num(), (new Beta).num(), (new Carrot).num()); } expect: { class Alpha { num() { return n; } } let n = 2, u = 4; console.log(n, 3, u, 3 * n, n * u, 3 * u, n, 3, (() => u)(), new Alpha().num(), new class { num() { return 3; } }().num(), new class { num() { return u; } }().num()); } expect_stdout: "2 3 4 6 8 12 2 3 4 2 3 4" } issue_t183: { options = { defaults: true, top_retain: [], } input: { function foo(val) { function bar(x) { if (x) return x; bar(x-1); } return bar(val); } console.log(foo("PASS")); } expect: { console.log(function bar(x) { if (x) return x; bar(x - 1); }("PASS")); } expect_stdout: "PASS" } terser-4.1.2/test/compress/evaluate.js000066400000000000000000001110051351061312300177710ustar00rootroot00000000000000and: { options = { evaluate: true, side_effects: true, } input: { var a; // compress these a = true && condition; a = 1 && console.log("a"); a = 2 * 3 && 2 * condition; a = 5 == 5 && condition + 3; a = "string" && 4 - condition; a = 5 + "" && condition / 5; a = -4.5 && 6 << condition; a = 6 && 7; a = false && condition; a = NaN && console.log("b"); a = 0 && console.log("c"); a = undefined && 2 * condition; a = null && condition + 3; a = 2 * 3 - 6 && 4 - condition; a = 10 == 7 && condition / 5; a = !"string" && 6 % condition; a = 0 && 7; // don't compress these a = condition && true; a = console.log("a") && 2; a = 4 - condition && "string"; a = 6 << condition && -4.5; a = condition && false; a = console.log("b") && NaN; a = console.log("c") && 0; a = 2 * condition && undefined; a = condition + 3 && null; } expect: { var a; a = condition; a = console.log("a"); a = 2 * condition; a = condition + 3; a = 4 - condition; a = condition / 5; a = 6 << condition; a = 7; a = false; a = NaN; a = 0; a = void 0; a = null; a = 0; a = false; a = false; a = 0; a = condition && true; a = console.log("a") && 2; a = 4 - condition && "string"; a = 6 << condition && -4.5; a = condition && false; a = console.log("b") && NaN; a = console.log("c") && 0; a = 2 * condition && void 0; a = condition + 3 && null; } } or: { options = { evaluate: true, side_effects: true, } input: { var a; // compress these a = true || condition; a = 1 || console.log("a"); a = 2 * 3 || 2 * condition; a = 5 == 5 || condition + 3; a = "string" || 4 - condition; a = 5 + "" || condition / 5; a = -4.5 || 6 << condition; a = 6 || 7; a = false || condition; a = 0 || console.log("b"); a = NaN || console.log("c"); a = undefined || 2 * condition; a = null || condition + 3; a = 2 * 3 - 6 || 4 - condition; a = 10 == 7 || condition / 5; a = !"string" || 6 % condition; a = null || 7; a = console.log(undefined && condition || null); a = console.log(undefined || condition && null); // don't compress these a = condition || true; a = console.log("a") || 2; a = 4 - condition || "string"; a = 6 << condition || -4.5; a = condition || false; a = console.log("b") || NaN; a = console.log("c") || 0; a = 2 * condition || undefined; a = condition + 3 || null; } expect: { var a; a = true; a = 1; a = 6; a = true; a = "string"; a = "5"; a = -4.5; a = 6; a = condition; a = console.log("b"); a = console.log("c"); a = 2 * condition; a = condition + 3; a = 4 - condition; a = condition / 5; a = 6 % condition; a = 7; a = console.log(null); a = console.log(condition && null); a = condition || true; a = console.log("a") || 2; a = 4 - condition || "string"; a = 6 << condition || -4.5; a = condition || false; a = console.log("b") || NaN; a = console.log("c") || 0; a = 2 * condition || void 0; a = condition + 3 || null; } } unary_prefix: { options = { evaluate: true, side_effects: true, } input: { a = !0 && b; a = !0 || b; a = ~1 && b; a = ~1 || b; a = -2 && b; a = -2 || b; a = +3 && b; a = +3 || b; } expect: { a = b; a = !0; a = b; a = -2; a = b; a = -2; a = b; a = 3; } } negative_zero: { options = { evaluate: true, } input: { console.log( -"", - -"", 1 / (-0), 1 / (-"") ); } expect: { console.log( -0, 0, -1/0, -1/0 ); } expect_stdout: true } positive_zero: { options = { evaluate: true, } input: { console.log( +"", + -"", 1 / (+0), 1 / (+"") ); } expect: { console.log( 0, -0, 1/0, 1/0 ); } expect_stdout: true } pow: { options = { evaluate: true } input: { var a = 5 ** 3; } expect: { var a = 125; } } pow_sequence: { options = { evaluate: true } input: { var a = 2 ** 3 ** 2; } expect: { var a = 512; } } pow_mixed: { options = { evaluate: true } input: { var a = 5 + 2 ** 3 + 5; var b = 5 * 3 ** 2; var c = 5 ** 3 * 2; var d = 5 ** +3; } expect: { var a = 18; var b = 45; var c = 250; var d = 125; } } pow_with_right_side_evaluating_to_unary: { options = { evaluate: true } input: { var a = (4 - 7) ** foo; var b = ++bar ** 3; var c = --baz ** 2; } expect_exact: "var a=(-3)**foo;var b=++bar**3;var c=--baz**2;" } pow_with_number_constants: { options = { evaluate: true } input: { var a = 5 ** NaN; /* NaN exponent results to NaN */ var b = 42 ** +0; /* +0 exponent results to NaN */ var c = 42 ** -0; /* -0 exponent results to NaN */ var d = NaN ** 1; /* NaN with non-zero exponent is NaN */ var e = 2 ** Infinity; /* abs(base) > 1 with Infinity as exponent is Infinity */ var f = 2 ** -Infinity; /* abs(base) > 1 with -Infinity as exponent is +0 */ var g = (-7) ** (0.5); var h = 2324334 ** 34343443; var i = (-2324334) ** 34343443; var j = 2 ** (-3); var k = 2.0 ** -3; var l = 2.0 ** (5 - 7); var m = 3 ** -10; // Result will be 0.000016935087808430286, which is too long } expect: { var a = NaN; var b = 1; var c = 1; var d = NaN; var e = 1/0; var f = 0; var g = NaN; var h = 1/0; var i = -1/0; var j = .125; var k = .125; var l = .25; var m = 3 ** -10; } } pow_sequence_with_parens: { input: { var one = 1; var two = 2; var four = 4; console.log((four ** one) ** two, (four ** one) ** (one / two)); } expect: { var one=1; var two=2; var four=4; console.log((four**one)**two,(four**one)**(one/two)); } expect_stdout: "16 2" node_version: ">=8" } pow_sequence_with_parens_evaluated: { options = { evaluate: true, reduce_vars: true, toplevel: true, unused: true, } input: { var one = 1; var two = 2; var four = 4; console.log((four ** one) ** two, (four ** one) ** (one / two)); } expect: { console.log(16,2); } expect_stdout: "16 2" node_version: ">=8" } pow_sequence_with_constants_and_parens: { options = { evaluate: true, toplevel: true, } input: { console.log((4 ** 1) ** 2, (4 ** 1) ** (1 / 2)); } expect: { console.log(16,2); } expect_stdout: "16 2" node_version: ">=8" } pow_sequence_with_parens_exact: { input: { console.log((4 ** 1) ** 2, (4 ** 1) ** (1 / 2)); var one = 1; var two = 2; var four = 4; console.log((four ** one) ** two, (four ** one) ** (one / two)); } expect_exact: "console.log((4**1)**2,(4**1)**(1/2));var one=1;var two=2;var four=4;console.log((four**one)**two,(four**one)**(one/two));" expect_stdout: [ "16 2", "16 2", ] node_version: ">=8" } unsafe_constant: { options = { evaluate: true, unsafe: true, } input: { console.log( true.a, false.a, null.a, undefined.a ); } expect: { console.log( true.a, false.a, null.a, (void 0).a ); } expect_stdout: true } unsafe_object: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unsafe: true, } input: { var o = { a: 1 }; console.log( o + 1, o.a + 1, o.b + 1, o.a.b + 1 ); } expect: { var o = { a: 1 }; console.log( o + 1, 2, o.b + 1, 1..b + 1 ); } expect_stdout: true } unsafe_object_nested: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unsafe: true, } input: { var o = { a: { b: 1 } }; console.log( o + 1, o.a + 1, o.b + 1, o.a.b + 1 ); } expect: { var o = { a: { b: 1 } }; console.log( o + 1, o.a + 1, o.b + 1, 2 ); } expect_stdout: true } unsafe_object_complex: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unsafe: true, } input: { var o = { a: { b: 1 }, b: 1 }; console.log( o + 1, o.a + 1, o.b + 1, o.a.b + 1 ); } expect: { var o = { a: { b: 1 }, b: 1 }; console.log( o + 1, o.a + 1, 2, 2 ); } expect_stdout: true } unsafe_object_repeated: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unsafe: true, } input: { var o = { a: { b: 1 }, a: 1 }; console.log( o + 1, o.a + 1, o.b + 1, o.a.b + 1 ); } expect: { var o = { a: { b: 1 }, a: 1 }; console.log( o + 1, 2, o.b + 1, 1..b + 1 ); } expect_stdout: true } unsafe_object_accessor: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unsafe: true, } input: { function f() { var a = { get b() {}, set b() {} }; return {a:a}; } } expect: { function f() { var a = { get b() {}, set b() {} }; return {a:a}; } } } prop_function: { options = { evaluate: true, properties: true, side_effects: true, } input: { console.log( ({a:{b:1},b:function(){}}) + 1, ({a:{b:1},b:function(){}}).a + 1, ({a:{b:1},b:function(){}}).b + 1, ({a:{b:1},b:function(){}}).a.b + 1 ); } expect: { console.log( ({a:{b:1},b:function(){}}) + 1, ({b:1}) + 1, function(){} + 1, 2 ); } expect_stdout: true } unsafe_integer_key: { options = { evaluate: true, unsafe: true, } input: { console.log( ({0:1}) + 1, ({0:1})[0] + 1, ({0:1})["0"] + 1, ({0:1})[1] + 1, ({0:1})[0][1] + 1, ({0:1})[0]["1"] + 1 ); } expect: { console.log( ({0:1}) + 1, 2, 2, ({0:1})[1] + 1, 1[1] + 1, 1["1"] + 1 ); } expect_stdout: true } unsafe_integer_key_complex: { options = { evaluate: true, unsafe: true, } input: { console.log( ({0:{1:1},1:1}) + 1, ({0:{1:1},1:1})[0] + 1, ({0:{1:1},1:1})["0"] + 1, ({0:{1:1},1:1})[1] + 1, ({0:{1:1},1:1})[0][1] + 1, ({0:{1:1},1:1})[0]["1"] + 1 ); } expect: { console.log( ({0:{1:1},1:1}) + 1, "[object Object]1", "[object Object]1", 2, 2, 2 ); } expect_stdout: true } unsafe_float_key: { options = { evaluate: true, unsafe: true, } input: { console.log( ({2.72:1}) + 1, ({2.72:1})[2.72] + 1, ({2.72:1})["2.72"] + 1, ({2.72:1})[3.14] + 1, ({2.72:1})[2.72][3.14] + 1, ({2.72:1})[2.72]["3.14"] + 1 ); } expect: { console.log( ({2.72:1}) + 1, 2, 2, ({2.72:1})[3.14] + 1, 1[3.14] + 1, 1["3.14"] + 1 ); } expect_stdout: true } unsafe_float_key_complex: { options = { evaluate: true, unsafe: true, } input: { console.log( ({2.72:{3.14:1},3.14:1}) + 1, ({2.72:{3.14:1},3.14:1})[2.72] + 1, ({2.72:{3.14:1},3.14:1})["2.72"] + 1, ({2.72:{3.14:1},3.14:1})[3.14] + 1, ({2.72:{3.14:1},3.14:1})[2.72][3.14] + 1, ({2.72:{3.14:1},3.14:1})[2.72]["3.14"] + 1 ); } expect: { console.log( "[object Object]1", "[object Object]1", "[object Object]1", 2, 2, 2 ); } expect_stdout: true } unsafe_array: { options = { evaluate: true, unsafe: true, } input: { console.log( [1, , 3][1], [1, 2, 3, a] + 1, [1, 2, 3, 4] + 1, [1, 2, 3, a][0] + 1, [1, 2, 3, 4][0] + 1, [1, 2, 3, 4][6 - 5] + 1, [1, , 3, 4][6 - 5] + 1, [[1, 2], [3, 4]][0] + 1, [[1, 2], [3, 4]][6 - 5][1] + 1, [[1, 2], , [3, 4]][6 - 5][1] + 1 ); } expect: { console.log( void 0, [1, 2, 3, a] + 1, "1,2,3,41", [1, 2, 3, a][0] + 1, 2, 3, NaN, "1,21", 5, (void 0)[1] + 1 ); } expect_stdout: true } unsafe_string: { options = { evaluate: true, unsafe: true, } input: { console.log( "1234" + 1, "1234"[0] + 1, "1234"[6 - 5] + 1, ("12" + "34")[0] + 1, ("12" + "34")[6 - 5] + 1, [1, 2, 3, 4].join("")[0] + 1 ); } expect: { console.log( "12341", "11", "21", "11", "21", "11" ); } expect_stdout: true } unsafe_array_bad_index: { options = { evaluate: true, unsafe: true, } input: { console.log( [1, 2, 3, 4].a + 1, [1, 2, 3, 4]["a"] + 1, [1, 2, 3, 4][3.14] + 1 ); } expect: { console.log( [1, 2, 3, 4].a + 1, [1, 2, 3, 4]["a"] + 1, [1, 2, 3, 4][3.14] + 1 ); } expect_stdout: true } unsafe_string_bad_index: { options = { evaluate: true, unsafe: true, } input: { console.log( "1234".a + 1, "1234"["a"] + 1, "1234"[3.14] + 1 ); } expect: { console.log( "1234".a + 1, "1234"["a"] + 1, "1234"[3.14] + 1 ); } expect_stdout: true } prototype_function: { options = { evaluate: true, properties: true, side_effects: true, } input: { var a = ({valueOf: 0}) < 1; var b = ({toString: 0}) < 1; var c = ({valueOf: 0}) + ""; var d = ({toString: 0}) + ""; var e = (({valueOf: 0}) + "")[2]; var f = (({toString: 0}) + "")[2]; var g = ({valueOf: 0}).valueOf(); var h = ({toString: 0}).toString(); } expect: { var a = ({valueOf: 0}) < 1; var b = ({toString: 0}) < 1; var c = ({valueOf: 0}) + ""; var d = ({toString: 0}) + ""; var e = (({valueOf: 0}) + "")[2]; var f = (({toString: 0}) + "")[2]; var g = 0(); var h = 0(); } } call_args: { options = { evaluate: true, inline: true, reduce_funcs: true, reduce_vars: true, } input: { const a = 1; console.log(a); +function(a) { return a; }(a); } expect: { const a = 1; console.log(1); +(1, 1); } expect_stdout: true } call_args_drop_param: { options = { evaluate: true, inline: true, keep_fargs: false, reduce_funcs: true, reduce_vars: true, unused: true, } input: { const a = 1; console.log(a); +function(a) { return a; }(a, b); } expect: { const a = 1; console.log(1); +(b, 1); } expect_stdout: true } in_boolean_context: { options = { booleans: true, evaluate: true, sequences: true, side_effects: true, } input: { console.log( !42, !"foo", ![1, 2], !/foo/, !b(42), !b("foo"), !b([1, 2]), !b(/foo/), ![1, foo()], ![1, foo(), 2] ); } expect: { console.log( !1, !1, !1, !1, !b(42), !b("foo"), !b([1, 2]), !b(/foo/), ![1, foo()], (foo(), !1) ); } expect_stdout: true } unsafe_charAt: { options = { evaluate: true, unsafe: true, } input: { console.log( "1234" + 1, "1234".charAt(0) + 1, "1234".charAt(6 - 5) + 1, ("12" + "34").charAt(0) + 1, ("12" + "34").charAt(6 - 5) + 1, [1, 2, 3, 4].join("").charAt(0) + 1 ); } expect: { console.log( "12341", "11", "21", "11", "21", "11" ); } expect_stdout: true } unsafe_charAt_bad_index: { options = { evaluate: true, unsafe: true, } input: { console.log( "1234".charAt() + 1, "1234".charAt("a") + 1, "1234".charAt(3.14) + 1 ); } expect: { console.log( "11", "11", "41" ); } expect_stdout: true } unsafe_charAt_noop: { options = { evaluate: true, unsafe: true, } input: { console.log( s.charAt(0), "string".charAt(x), (typeof x).charAt() ); } expect: { console.log( s.charAt(0), "string".charAt(x), (typeof x)[0] ); } } issue_1649: { options = { evaluate: true, } input: { console.log(-1 + -1); } expect: { console.log(-2); } expect_stdout: "-2"; } issue_1760_1: { options = { evaluate: true, } input: { !function(a) { try { throw 0; } catch (NaN) { a = +"foo"; } console.log(a); }(); } expect: { !function(a) { try { throw 0; } catch (NaN) { a = 0 / 0; } console.log(a); }(); } expect_stdout: "NaN" } issue_1760_2: { options = { evaluate: true, keep_infinity: true, } input: { !function(a) { try { throw 0; } catch (Infinity) { a = 123456789 / 0; } console.log(a); }(); } expect: { !function(a) { try { throw 0; } catch (Infinity) { a = 1 / 0; } console.log(a); }(); } expect_stdout: "Infinity" } delete_expr_1: { options = { booleans: true, evaluate: true, } input: { console.log(delete undefined); console.log(delete void 0); console.log(delete Infinity); console.log(delete (1 / 0)); console.log(delete NaN); console.log(delete (0 / 0)); } expect: { console.log(delete undefined); console.log((void 0, !0)); console.log(delete Infinity); console.log((1 / 0, !0)); console.log(delete NaN); console.log((0 / 0, !0)); } expect_stdout: true } delete_expr_2: { options = { booleans: true, evaluate: true, keep_infinity: true, } input: { console.log(delete undefined); console.log(delete void 0); console.log(delete Infinity); console.log(delete (1 / 0)); console.log(delete NaN); console.log(delete (0 / 0)); } expect: { console.log(delete undefined); console.log((void 0, !0)); console.log(delete Infinity); console.log((1 / 0, !0)); console.log(delete NaN); console.log((0 / 0, !0)); } expect_stdout: true } delete_binary_1: { options = { booleans: true, evaluate: true, side_effects: true, } input: { console.log(delete (true && undefined)); console.log(delete (true && void 0)); console.log(delete (true && Infinity)); console.log(delete (true && (1 / 0))); console.log(delete (true && NaN)); console.log(delete (true && (0 / 0))); } expect: { console.log(!0); console.log(!0); console.log(!0); console.log(!0); console.log(!0); console.log(!0); } expect_stdout: true } delete_binary_2: { options = { booleans: true, evaluate: true, keep_infinity: true, side_effects: true, } input: { console.log(delete (false || undefined)); console.log(delete (false || void 0)); console.log(delete (false || Infinity)); console.log(delete (false || (1 / 0))); console.log(delete (false || NaN)); console.log(delete (false || (0 / 0))); } expect: { console.log(!0); console.log(!0); console.log(!0); console.log(!0); console.log(!0); console.log(!0); } expect_stdout: true } Infinity_NaN_undefined_LHS: { beautify = { beautify: true, } input: { function f() { Infinity = Infinity; ++Infinity; Infinity--; NaN *= NaN; ++NaN; NaN--; undefined |= undefined; ++undefined; undefined--; } } expect_exact: [ "function f() {", " Infinity = 1 / 0;", " ++Infinity;", " Infinity--;", " NaN *= NaN;", " ++NaN;", " NaN--;", " undefined |= void 0;", " ++undefined;", " undefined--;", "}", ] } issue_1964_1: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unsafe_regexp: false, unused: true, } input: { function f() { var long_variable_name = /\s/; console.log(long_variable_name.source); return "a b c".split(long_variable_name)[1]; } console.log(f()); } expect: { function f() { var long_variable_name = /\s/; console.log(long_variable_name.source); return "a b c".split(long_variable_name)[1]; } console.log(f()); } expect_stdout: [ "\\s", "b", ] } issue_1964_2: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unsafe_regexp: true, unused: true, } input: { function f() { var long_variable_name = /\s/; console.log(long_variable_name.source); return "a b c".split(long_variable_name)[1]; } console.log(f()); } expect: { function f() { console.log(/\s/.source); return "a b c".split(/\s/)[1]; } console.log(f()); } expect_stdout: [ "\\s", "b", ] } array_slice_index: { options = { evaluate: true, unsafe: true, } input: { console.log([1,2,3].slice(1)[1]); } expect: { console.log(3); } expect_stdout: "3" } string_charCodeAt: { options = { evaluate: true, unsafe: true, } input: { console.log("foo".charCodeAt("bar".length)); } expect: { console.log(NaN); } expect_stdout: "NaN" } issue_2207_1: { options = { evaluate: true, unsafe: true, } input: { console.log(String.fromCharCode(65)); console.log(Math.max(3, 6, 2, 7, 3, 4)); console.log(Math.cos(1.2345)); console.log(Math.cos(1.2345) - Math.sin(4.321)); console.log(Math.pow(Math.PI, Math.E - Math.LN10).toFixed(15)); } expect: { console.log("A"); console.log(7); console.log(Math.cos(1.2345)); console.log(1.2543732512566947); console.log("1.609398451447204"); } expect_stdout: true } issue_2207_2: { options = { evaluate: true, unsafe: true, } input: { console.log(Math.E); console.log(Math.LN10); console.log(Math.LN2); console.log(Math.LOG2E); console.log(Math.LOG10E); console.log(Math.PI); console.log(Math.SQRT1_2); console.log(Math.SQRT2); } expect: { console.log(Math.E); console.log(Math.LN10); console.log(Math.LN2); console.log(Math.LOG2E); console.log(Math.LOG10E); console.log(Math.PI); console.log(Math.SQRT1_2); console.log(Math.SQRT2); } expect_stdout: true } issue_2207_3: { options = { evaluate: true, unsafe: true, } input: { console.log(Number.MAX_VALUE); console.log(Number.MIN_VALUE); console.log(Number.NaN); console.log(Number.NEGATIVE_INFINITY); console.log(Number.POSITIVE_INFINITY); } expect: { console.log(Number.MAX_VALUE); console.log(5e-324); console.log(NaN); console.log(-1/0); console.log(1/0); } expect_stdout: true } issue_2231_1: { options = { evaluate: true, unsafe: true, } input: { console.log(Object.keys(void 0)); } expect: { console.log(Object.keys(void 0)); } expect_stdout: true expect_warnings: [ "WARN: Error evaluating Object.keys(void 0) [test/compress/evaluate.js:1,20]", ] } issue_2231_2: { options = { evaluate: true, unsafe: true, } input: { console.log(Object.getOwnPropertyNames(null)); } expect: { console.log(Object.getOwnPropertyNames(null)); } expect_stdout: true expect_warnings: [ "WARN: Error evaluating Object.getOwnPropertyNames(null) [test/compress/evaluate.js:1,20]", ] } issue_2231_3: { options = { evaluate: true, unsafe: true, } input: { console.log(Object.keys({ foo: "bar" })[0]); } expect: { console.log("foo"); } expect_stdout: "foo" } self_comparison_1: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unsafe: true, unused: true, } input: { var o = { n: NaN }; console.log(typeof o.n, o.n == o.n, o.n === o.n, o.n != o.n, o.n !== o.n); } expect: { console.log("number", false, false, true, true); } expect_stdout: "number false false true true" } self_comparison_2: { options = { evaluate: true, hoist_props: true, passes: 2, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var o = { n: NaN }; console.log(typeof o.n, o.n == o.n, o.n === o.n, o.n != o.n, o.n !== o.n); } expect: { console.log("number", false, false, true, true); } expect_stdout: "number false false true true" } issue_2535_1: { options = { booleans: true, evaluate: true, sequences: true, side_effects: true, } input: { if ((x() || true) || y()) z(); if ((x() || true) && y()) z(); if ((x() && true) || y()) z(); if ((x() && true) && y()) z(); if ((x() || false) || y()) z(); if ((x() || false) && y()) z(); if ((x() && false) || y()) z(); if ((x() && false) && y()) z(); } expect: { if (x(), 1) z(); if (x(), y()) z(); if (x() || y()) z(); if (x() && y()) z(); if (x() || y()) z(); if (x() && y()) z(); if (x(), y()) z(); if (x(), 0) z(); } } issue_2535_2: { options = { booleans: true, evaluate: true, sequences: true, side_effects: true, } input: { (x() || true) || y(); (x() || true) && y(); (x() && true) || y(); (x() && true) && y(); (x() || false) || y(); (x() || false) && y(); (x() && false) || y(); (x() && false) && y(); } expect: { x(), x(), y(), x() || y(), x() && y(), x() || y(), x() && y(), x(), y(), x(); } } issue_2535_3: { options = { booleans: true, evaluate: true, } input: { console.log(Object(1) && 1 && 2); console.log(Object(1) && true && 1 && 2 && Object(2)); console.log(Object(1) && true && 1 && null && 2 && Object(2)); console.log(2 == Object(1) || 0 || void 0 || null); console.log(2 == Object(1) || 0 || void 0 || null || Object(2)); console.log(2 == Object(1) || 0 || void 0 || "ok" || null || Object(2)); } expect: { console.log(Object(1) && 2); console.log(Object(1) && Object(2)); console.log(Object(1) && null); console.log(2 == Object(1) || null); console.log(2 == Object(1) || Object(2)); console.log(2 == Object(1) || "ok"); } expect_stdout: true expect_warnings: [ "WARN: Dropping side-effect-free && [test/compress/evaluate.js:1,20]", "WARN: Dropping side-effect-free && [test/compress/evaluate.js:2,20]", "WARN: Dropping side-effect-free && [test/compress/evaluate.js:3,20]", "WARN: Condition left of && always false [test/compress/evaluate.js:3,20]", "WARN: Dropping side-effect-free || [test/compress/evaluate.js:4,20]", "WARN: Dropping side-effect-free || [test/compress/evaluate.js:5,20]", "WARN: Dropping side-effect-free || [test/compress/evaluate.js:6,20]", "WARN: Condition left of || always true [test/compress/evaluate.js:6,20]", ] } issue_2822: { options = { evaluate: true, unsafe: true, } input: { console.log([ function() {}, "PASS", "FAIL" ][1]); } expect: { console.log("PASS"); } expect_stdout: "PASS" } string_case: { options = { evaluate: true, unsafe: true, } input: { console.log("İ".toLowerCase().charCodeAt(0)); console.log("I".toLowerCase().charCodeAt(0)); console.log("Ş".toLowerCase().charCodeAt(0)); console.log("Ğ".toLowerCase().charCodeAt(0)); console.log("Ü".toLowerCase().charCodeAt(0)); console.log("Ö".toLowerCase().charCodeAt(0)); console.log("Ç".toLowerCase().charCodeAt(0)); console.log("i".toUpperCase().charCodeAt(0)); console.log("ı".toUpperCase().charCodeAt(0)); console.log("ş".toUpperCase().charCodeAt(0)); console.log("ğ".toUpperCase().charCodeAt(0)); console.log("ü".toUpperCase().charCodeAt(0)); console.log("ö".toUpperCase().charCodeAt(0)); console.log("ç".toUpperCase().charCodeAt(0)); } expect: { console.log(105); console.log(105); console.log(351); console.log(287); console.log(252); console.log(246); console.log(231); console.log(73); console.log(73); console.log(350); console.log(286); console.log(220); console.log(214); console.log(199); } expect_stdout: [ "105", "105", "351", "287", "252", "246", "231", "73", "73", "350", "286", "220", "214", "199", ] } issue_2916_1: { options = { evaluate: true, reduce_vars: true, unsafe: true, } input: { var c = "PASS"; (function(a, b) { (function(d) { d[0] = 1; })(b); a == b && (c = "FAIL"); })("", []); console.log(c); } expect: { var c = "PASS"; (function(a, b) { (function(d) { d[0] = 1; })(b); a == b && (c = "FAIL"); })("", []); console.log(c); } expect_stdout: "PASS" } issue_2916_2: { options = { collapse_vars: true, evaluate: true, inline: true, reduce_vars: true, side_effects: true, unsafe: true, unused: true, } input: { var c = "FAIL"; (function(b) { (function(d) { d[0] = 1; })(b); +b && (c = "PASS"); })([]); console.log(c); } expect: { var c = "FAIL"; (function(b) { b[0] = 1; +b && (c = "PASS"); })([]); console.log(c); } expect_stdout: "PASS" } issue_2919: { options = { evaluate: true, unsafe: true, } input: { console.log([ function() {} ].toString()); } expect: { console.log("function(){}"); } } issue_2926_1: { options = { evaluate: true, reduce_vars: true, unsafe: true, } input: { (function f(a) { console.log(f.name.length, f.length); })(); } expect: { (function f(a) { console.log(1, 1); })(); } expect_stdout: "1 1" } issue_2926_2: { options = { evaluate: true, unsafe: true, } input: { console.log(typeof function() {}.valueOf()); } expect: { console.log("function"); } expect_stdout: "function" } optional_expect_when_expect_stdout_present: { options = { evaluate: true, } input: { console.log(5 % 3); } expect_stdout: "2" } issue_2968: { options = { collapse_vars: true, evaluate: true, inline: true, passes: 2, reduce_vars: true, unused: true, } input: { var c = "FAIL"; (function() { (function(a, b) { a <<= 0; a && (a[(c = "PASS", 0 >>> (b += 1))] = 0); })(42, -42); })(); console.log(c); } expect_stdout: "PASS" } global_hasOwnProperty: { options = { unsafe: true } input: { hasOwnProperty.call(a, b) hasOwnProperty.call(a.b, b) hasOwnProperty.call(a['b'], b) } expect: { hasOwnProperty.call(a, b) hasOwnProperty.call(a.b, b) hasOwnProperty.call(a['b'], b) } } terser-4.1.2/test/compress/expansions.js000066400000000000000000000025441351061312300203610ustar00rootroot00000000000000 expand_arguments: { input: { func(a, ...rest); func(...all); } expect_exact: "func(a,...rest);func(...all);" } expand_expression_arguments: { input: { f(...a.b); f(...a.b()); f(...(a)); f(...(a.b)); f(...a[i]); } expect_exact: "f(...a.b);f(...a.b());f(...a);f(...a.b);f(...a[i]);" } expand_parameters: { input: { (function (a, ...b){}); (function (...args){}); } expect_exact: "(function(a,...b){});(function(...args){});" } avoid_spread_in_ternary: { options = { comparisons: true, conditionals: true, evaluate: true, } input: { function print(...x) { console.log(...x); } var a = [1, 2], b = [3, 4], m = Math; if (m) print(a); else print(b); if (m) print(...a); else print(b); if (m.no_such_property) print(a); else print(...b); } expect: { function print(...x) { console.log(...x); } var a = [ 1, 2 ], b = [ 3, 4 ], m = Math; print(m ? a : b); m ? print(...a) : print(b); m.no_such_property ? print(a) : print(...b); } expect_stdout: [ "[ 1, 2 ]", "1 2", "3 4", ] } terser-4.1.2/test/compress/export.js000066400000000000000000000451321351061312300175130ustar00rootroot00000000000000issue_2038_1: { options = { toplevel: true, unused: true, } mangle = { toplevel: true, } input: { export var V = 1; export let L = 2; export const C = 3; } expect: { export var V = 1; export let L = 2; export const C = 3; } } issue_2038_2: { options = { toplevel: true, unused: true, } mangle = { toplevel: true, } input: { let LET = 1; const CONST = 2; var VAR = 3; export { LET, CONST, VAR }; } expect: { let t = 1; const e = 2; var o = 3; export { t as LET, e as CONST, o as VAR }; } } issue_2126: { mangle = { toplevel: true, } input: { import { foo as bar, cat as dog } from "stuff"; console.log(bar, dog); export { bar as qux }; export { dog }; } expect: { import { foo as o, cat as s } from "stuff"; console.log(o, s); export { o as qux }; export { s as dog }; } } beautify: { beautify = { beautify: true, } input: { export { A as B, C as D }; } expect_exact: "export { A as B, C as D };" } issue_2131: { options = { toplevel: true, unused: true, } input: { function no() { console.log(42); } function go() { console.log(42); } var X = 1, Y = 2; export function main() { go(X); }; } expect: { function go() { console.log(42); } var X = 1; export function main() { go(X); }; } } issue_2129: { mangle = { toplevel: true, } input: { export const { keys } = Object; } expect: { export const { keys } = Object; } } async_func: { options = { keep_fargs: false, unused: true, } input: { export async function Foo(x){}; } expect: { export async function Foo(){}; } } issue_2134_1: { options = { keep_fargs: false, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { export function Foo(x){}; Foo.prototype = {}; } expect: { export function Foo(){}; Foo.prototype = {}; } } issue_2134_2: { options = { keep_fargs: false, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { export async function Foo(x){}; Foo.prototype = {}; } expect: { export async function Foo(){}; Foo.prototype = {}; } } redirection: { mangle = { toplevel: true, } input: { let foo = 1, bar = 2; export { foo as delete }; export { bar as default }; export { foo as var } from "module.js"; } expect: { let e = 1, o = 2; export { e as delete }; export { o as default }; export { foo as var } from "module.js"; } } keyword_invalid_1: { input: { export { default }; } expect: { export { default }; } } keyword_invalid_2: { input: { export { default as Alias }; } expect: { export { default as Alias }; } } keyword_invalid_3: { input: { export { default as default }; } expect: { export { default as default }; } } keyword_valid_1: { input: { export { default } from "module.js"; } expect: { export { default } from "module.js"; } } keyword_valid_2: { input: { export { default as Alias } from "module.js"; } expect: { export { default as Alias } from "module.js"; } } keyword_valid_3: { input: { export { default as default } from "module.js"; } expect: { export { default as default } from "module.js"; } } dynamic_import: { mangle = { toplevel: true, } input: { import traditional from './traditional.js'; function imp(x) { return import(x); } import("module_for_side_effects.js"); let dynamic = import("some/module.js"); dynamic.foo(); } expect: { import o from "./traditional.js"; function t(o) { return import(o); } import("module_for_side_effects.js"); let r = import("some/module.js"); r.foo(); } } trailing_comma: { beautify = { beautify: true, } input: { export const a = 1; } expect_exact: "export const a = 1;" } export_default_anonymous_function: { options = { reduce_vars: true, toplevel: true, unused: true, } mangle = { toplevel: true, } input: { export default function () { foo(); } } expect_exact: "export default function(){foo()}" } export_default_seq: { input: { export default (1, 2) } expect_exact: "export default(1,2);" } export_default_arrow: { options = { reduce_vars: true, toplevel: true, unused: true, } mangle = { toplevel: true, } input: { export default () => foo(); } expect_exact: "export default()=>foo();" } export_default_anonymous_generator: { options = { reduce_vars: true, toplevel: true, unused: true, } mangle = { toplevel: true, } input: { export default function * () { yield foo(); } } expect_exact: "export default function*(){yield foo()}" } export_default_anonymous_async_function: { options = { reduce_vars: true, toplevel: true, unused: true, } mangle = { toplevel: true, } input: { export default async function() { return await foo(); } } expect_exact: "export default async function(){return await foo()}" } export_default_async_arrow_function: { options = { reduce_vars: true, toplevel: true, unused: true, } mangle = { toplevel: true, } input: { export default async () => await foo(); } expect_exact: "export default async()=>await foo();" } export_default_named_generator: { options = { reduce_vars: true, toplevel: true, unused: true, } mangle = { cache: { props: { $gen: "_$GEN$_", } }, toplevel: true, } input: { export default function * gen() { yield foo(); } } expect_exact: "export default function*_$GEN$_(){yield foo()}" } export_default_named_async_function: { options = { reduce_vars: true, toplevel: true, unused: true, } mangle = { cache: { props: { $bar: "_$BAR$_", } }, toplevel: true, } input: { export default async function bar() { return await foo(); } } expect_exact: "export default async function _$BAR$_(){return await foo()}" } export_default_anonymous_class: { options = { reduce_vars: true, toplevel: true, unused: true, } mangle = { toplevel: true, } input: { export default class { constructor() { foo(); } }; } expect_exact: "export default class{constructor(){foo()}}" } export_default_anonymous_function_not_call: { options = { reduce_vars: true, toplevel: true, unused: true, } mangle = { toplevel: true, } input: { export default function(){}(foo); } // FIXME: should be `export default function(){};foo;` expect_exact: "export default(function(){}(foo));" } export_default_anonymous_generator_not_call: { options = { reduce_vars: true, toplevel: true, unused: true, } mangle = { toplevel: true, } input: { export default function*(){}(foo); } // agrees with `acorn` and `babylon 7` expect_exact: "export default function*(){}foo;" } export_default_anonymous_async_function_not_call: { options = { reduce_vars: true, toplevel: true, unused: true, } mangle = { toplevel: true, } input: { export default async function(){}(foo); } // agrees with `acorn` and `babylon 7` expect_exact: "export default async function(){}foo;" } issue_2977: { input: { export default (function () {})(); } expect_exact: "export default(function(){}());" } name_cache_do_not_mangle_export_function_name: { options = { defaults: true, module: true, } mangle = { cache: { props: { $add: "_$ADD$_", $sub: "_$SUB$_", } }, module: true, } input: { export function add(x, y) { return x + y; } function sub(x, y) { return x - y; } console.log(add(1, 2), add(3, 4), sub(5, 6), sub(7, 8)); } expect: { export function add(n, d) { return n + d; } function _$SUB$_(n, d) { return n - d; } console.log(add(1, 2), add(3, 4), _$SUB$_(5, 6), _$SUB$_(7, 8)); } } name_cache_do_not_mangle_export_class_name: { options = { defaults: true, module: true, } mangle = { cache: { props: { $add: "_$ADD$_", $sub: "_$SUB$_", } }, module: true, } input: { export class add {} class sub {} console.log(add, add, sub, sub); } expect: { export class add {} class _$SUB$_ {} console.log(add, add, _$SUB$_, _$SUB$_); } } name_cache_do_not_mangle_export_var_name: { options = { defaults: true, reduce_vars: false, toplevel: true, } mangle = { cache: { props: { $add: "_$ADD$_", $sub: "_$SUB$_", } }, toplevel: true, } input: { export var add = 1; var sub = 2, mul = 3; console.log(add, add, sub, sub, mul, mul); } expect: { export var add = 1; var _$SUB$_ = 2, d = 3; console.log(add, add, _$SUB$_, _$SUB$_, d, d); } } name_cache_do_not_mangle_export_let_name: { options = { defaults: true, reduce_vars: false, toplevel: true, } mangle = { cache: { props: { $add: "_$ADD$_", $sub: "_$SUB$_", } }, toplevel: true, } input: { export let add = 1; let sub = 2, mul = 3; console.log(add, add, sub, sub, mul, mul); } expect: { export let add = 1; let _$SUB$_ = 2, d = 3; console.log(add, add, _$SUB$_, _$SUB$_, d, d); } } name_cache_do_not_mangle_export_const_name: { options = { defaults: true, reduce_vars: false, toplevel: true, } mangle = { cache: { props: { $add: "_$ADD$_", $sub: "_$SUB$_", } }, toplevel: true, } input: { export const add = 1; const sub = 2, mul = 3; console.log(add, add, sub, sub, mul, mul); } expect: { export const add = 1; const _$SUB$_ = 2, d = 3; console.log(add, add, _$SUB$_, _$SUB$_, d, d); } } name_cache_do_not_mangle_export_destructuring_name: { options = { defaults: true, module: true, } mangle = { cache: { props: { $add: "_$ADD$_", $sub: "_$SUB$_", } }, module: true, } input: { export const [add] = [1, 2, 3]; const [mul, sub] = [1, 2, 3]; console.log(add, add, sub, sub, mul, mul); } expect: { export const [add] = [ 1, 2, 3 ]; const [d, _$SUB$_] = [ 1, 2, 3 ]; console.log(add, add, _$SUB$_, _$SUB$_, d, d); } } name_cache_do_not_mangle_export_from_names: { options = { defaults: true, module: true, } mangle = { cache: { props: { $add: "_$ADD$_", $div: "_$DIV$_", $mul: "_$MUL$_", $divide: "_$DIVIDE$_", $minus: "_$MINUS$_", $keep: "_$KEEP$_", } }, module: true, } input: { // these symbols are unrelated to the `export {} from` statement function add() { console.log("should be dropped"); } function div() { console.log("should be dropped"); } function mul() { console.log("should be dropped"); } function divide() { console.log("should be dropped"); } function minus() { console.log("should be dropped"); } function keep() { console.log("should be kept"); } export { add, div as divide, sub as minus, mul } from "path"; export { keep }; } expect: { function _$KEEP$_() { console.log("should be kept"); } export { add, div as divide, sub as minus, mul } from "path"; export { _$KEEP$_ as keep }; } } name_cache_mangle_export_default_class: { options = { defaults: true, module: true, } mangle = { cache: { props: { $foo: "_$FOO$_", $bar: "_$BAR$_", $baz: "_$BAZ$_", $qux: "_$QUX$_", } }, module: true, } input: { export default class foo {} export class bar {} class baz { meth() {} } class qux {} console.log(foo, bar, baz, qux, qux); } expect: { export default class _$FOO$_ {} export class bar {} class _$QUX$_ {} console.log(_$FOO$_, bar, class { meth() {} }, _$QUX$_, _$QUX$_); } } module_mangle_export_default_class: { options = { defaults: true, module: true, passes: 3, } mangle = { module: true, } input: { export default class foo {} export class bar {} class baz { meth(){} } class qux {} console.log(foo, bar, baz, qux); } expect: { export default class s {} export class bar {} console.log(s, bar, class { meth(){} }, class {}); } } name_cache_mangle_export_default_function: { options = { defaults: true, module: true, passes: 3, } mangle = { cache: { props: { $foo: "_$FOO$_", $bar: "_$BAR$_", $qux: "_$QUX$_", } }, module: true, } input: { export default function foo() { return 1; } export function bar() { return 2; } function qux() { return 3; } console.log(foo(), bar(), qux()); } expect: { export default function _$FOO$_() { return 1; } export function bar() { return 2; } console.log(_$FOO$_(), bar(), 3); } } module_mangle_export_default_function: { options = { defaults: true, module: true, passes: 3, } mangle = { module: true, } input: { export default function foo() { return 1; } export function bar() { return 2; } function qux() { return 3; } console.log(foo(), bar(), qux()); } expect: { export default function r() { return 1; } export function bar() { return 2; } console.log(r(), bar(), 3); } } name_cache_mangle_local_import_and_export_aliases: { options = { defaults: true, module: true, } mangle = { cache: { props: { $foo: "_$FOO$_", $bar: "_$BAR$_", $qux: "_$QUX$_", $cat: "_$CAT$_", $dog: "_$DOG$_", $bird: "_$BIRD$_", } }, module: true, } input: { import { foo as bar, cat as dog, bird } from "stuff"; console.log(bar, dog, bird); export { bar as qux, dog, bird }; } expect: { import { foo as _$BAR$_, cat as _$DOG$_, bird as _$BIRD$_ } from "stuff"; console.log(_$BAR$_, _$DOG$_, _$BIRD$_); export { _$BAR$_ as qux, _$DOG$_ as dog, _$BIRD$_ as bird }; } } name_cache_import_star_as_name_from_module: { options = { defaults: true, module: true, } mangle = { cache: { props: { $fs: "_$FS$_", } }, module: true, } input: { import * as fs from "filesystem"; import * as stuff from "whatever"; fs.resolve(); stuff.search(); export { fs, stuff }; } expect: { import * as _$FS$_ from "filesystem"; import * as e from "whatever"; _$FS$_.resolve(), e.search(); export { _$FS$_ as fs, e as stuff }; } } issue_333: { options = { collapse_vars: true, } input: { function shortOut() { return function() {}; } var setToString = shortOut(); var _setToString = setToString; export function baseRest() { return _setToString(); } export { _setToString }; } expect: { function shortOut() { return function () {}; } var setToString = shortOut(); var _setToString = setToString; export function baseRest() { return _setToString(); } export { _setToString }; } } issue_333_toplevel: { options = { defaults: true, toplevel: true, } input: { function shortOut() { return function() {}; } var setToString = shortOut(); var _setToString = setToString; export function baseRest() { return _setToString(); } export { _setToString }; } expect: { var _setToString = function () {}; export function baseRest() { return _setToString(); } export { _setToString }; } } terser-4.1.2/test/compress/expression.js000066400000000000000000000020521351061312300203630ustar00rootroot00000000000000pow: { input: { var a = 2 ** 7; var b = 3; b **= 2; } expect: { var a = 2 ** 7; var b = 3; b **= 2; } } pow_with_number_constants: { input: { var a = 5 ** NaN; var b = 42 ** +0; var c = 42 ** -0; var d = NaN ** 1; var e = 2 ** Infinity; var f = 2 ** -Infinity; } expect: { var a = 5 ** NaN; var b = 42 ** +0; var c = 42 ** -0; var d = NaN ** 1; var e = 2 ** (1/0); var f = 2 ** (-1/0); } } pow_with_parentheses: { input: { var g = (-7) ** (0.5); var h = 2324334 ** 34343443; var i = (-2324334) ** 34343443; var j = 2 ** (-3); var k = 2.0 ** -3; var l = 2.0 ** (5 - 7); } expect_exact: "var g=(-7)**.5;var h=2324334**34343443;var i=(-2324334)**34343443;var j=2**-3;var k=2**-3;var l=2**(5-7);" } pow_with_unary_between_brackets: { input: { var a = (-(+5)) ** 3; } expect: { var a = (-+5)**3; } } terser-4.1.2/test/compress/functions.js000066400000000000000000001570431351061312300202070ustar00rootroot00000000000000non_ascii_function_identifier_name: { input: { function fooλ(δλ) {} function λ(δλ) {} (function λ(δλ) {})() } expect_exact: "function fooλ(δλ){}function λ(δλ){}(function λ(δλ){})();" } iifes_returning_constants_keep_fargs_true: { options = { booleans: true, collapse_vars: true, comparisons: true, conditionals: true, dead_code: true, evaluate: true, if_return: true, inline: true, join_vars: true, keep_fargs: true, reduce_funcs: true, reduce_vars: true, side_effects: true, unused: true, } input: { (function(){ return -1.23; }()); console.log( function foo(){ return "okay"; }() ); console.log( function foo(x, y, z){ return 123; }() ); console.log( function(x, y, z){ return z; }() ); console.log( function(x, y, z){ if (x) return y; return z; }(1, 2, 3) ); console.log( function(x, y){ return x * y; }(2, 3) ); console.log( function(x, y){ return x * y; }(2, 3, a(), b()) ); } expect: { console.log("okay"); console.log(123); console.log(void 0); console.log(2); console.log(6); console.log((a(), b(), 6)); } expect_stdout: true } iifes_returning_constants_keep_fargs_false: { options = { booleans: true, collapse_vars: true, comparisons: true, conditionals: true, dead_code: true, evaluate: true, if_return: true, inline: true, join_vars: true, keep_fargs: false, reduce_funcs: true, reduce_vars: true, side_effects: true, unused: true, } input: { (function(){ return -1.23; }()); console.log( function foo(){ return "okay"; }() ); console.log( function foo(x, y, z){ return 123; }() ); console.log( function(x, y, z){ return z; }() ); console.log( function(x, y, z){ if (x) return y; return z; }(1, 2, 3) ); console.log( function(x, y){ return x * y; }(2, 3) ); console.log( function(x, y){ return x * y; }(2, 3, a(), b()) ); } expect: { console.log("okay"); console.log(123); console.log(void 0); console.log(2); console.log(6); console.log((a(), b(), 6)); } expect_stdout: true } issue_485_crashing_1530: { options = { conditionals: true, dead_code: true, evaluate: true, inline: true, side_effects: true, } input: { (function(a) { if (true) return; var b = 42; })(this); } expect: {} } issue_1841_1: { options = { keep_fargs: false, pure_getters: "strict", reduce_funcs: true, reduce_vars: true, unused: true, } input: { var b = 10; !function(arg) { for (var key in "hi") var n = arg.baz, n = [ b = 42 ]; }(--b); console.log(b); } expect: { var b = 10; !function() { for (var key in "hi") b = 42; }(--b); console.log(b); } expect_exact: "42" } issue_1841_2: { options = { keep_fargs: false, pure_getters: false, reduce_funcs: true, reduce_vars: true, unused: true, } input: { var b = 10; !function(arg) { for (var key in "hi") var n = arg.baz, n = [ b = 42 ]; }(--b); console.log(b); } expect: { var b = 10; !function(arg) { for (var key in "hi") arg.baz, b = 42; }(--b); console.log(b); } expect_exact: "42" } function_returning_constant_literal: { options = { inline: true, passes: 2, properties: true, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { function greeter() { return { message: 'Hello there' }; } var greeting = greeter(); console.log(greeting.message); } expect: { console.log("Hello there"); } expect_stdout: "Hello there" } hoist_funs: { options = { hoist_funs: true, } input: { console.log(typeof f, typeof g, 1); if (console.log(typeof f, typeof g, 2)) console.log(typeof f, typeof g, 3); else { console.log(typeof f, typeof g, 4); function f() {} console.log(typeof f, typeof g, 5); } function g() {} console.log(typeof f, typeof g, 6); } expect: { function g() {} console.log(typeof f, typeof g, 1); if (console.log(typeof f, typeof g, 2)) console.log(typeof f, typeof g, 3); else { console.log(typeof f, typeof g, 4); function f() {} console.log(typeof f, typeof g, 5); } console.log(typeof f, typeof g, 6); } expect_stdout: [ "undefined function 1", "undefined function 2", "function function 4", "function function 5", "function function 6", ] } hoist_funs_strict: { options = { hoist_funs: true, } input: { "use strict"; console.log(typeof f, typeof g, 1); if (console.log(typeof f, typeof g, 2)) console.log(typeof f, typeof g, 3); else { console.log(typeof f, typeof g, 4); function f() {} console.log(typeof f, typeof g, 5); } function g() {} console.log(typeof f, typeof g, 6); } expect: { "use strict"; function g() {} console.log(typeof f, typeof g, 1); if (console.log(typeof f, typeof g, 2)) console.log(typeof f, typeof g, 3); else { console.log(typeof f, typeof g, 4); function f() {} console.log(typeof f, typeof g, 5); } console.log(typeof f, typeof g, 6); } expect_stdout: [ "undefined function 1", "undefined function 2", "function function 4", "function function 5", "undefined function 6", ] } issue_203: { options = { keep_fargs: false, side_effects: true, unsafe_Function: true, unused: true, } input: { var m = {}; var fn = Function("require", "module", "exports", "module.exports = 42;"); fn(null, m, m.exports); console.log(m.exports); } expect: { var m = {}; var fn = Function("n,o", "o.exports=42"); fn(null, m, m.exports); console.log(m.exports); } expect_stdout: "42" } no_webkit: { beautify = { webkit: false, } input: { console.log(function() { 1 + 1; }.a = 1); } expect_exact: "console.log(function(){1+1}.a=1);" expect_stdout: "1" } webkit: { beautify = { webkit: true, } input: { console.log(function() { 1 + 1; }.a = 1); } expect_exact: "console.log((function(){1+1}).a=1);" expect_stdout: "1" } issue_2084: { options = { collapse_vars: true, conditionals: true, evaluate: true, inline: true, passes: 2, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { var c = 0; !function() { !function(c) { c = 1 + c; var c = 0; function f14(a_1) { if (c = 1 + c, 0 !== 23..toString()) c = 1 + c, a_1 && (a_1[0] = 0); } f14(); }(-1); }(); console.log(c); } expect: { var c = 0; !function (c) { c = 1 + c, c = 1 + (c = 0), 0 !== 23..toString() && (c = 1 + c); }(-1), console.log(c); } expect_stdout: "0" } issue_2097: { options = { negate_iife: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function f() { try { throw 0; } catch (e) { console.log(arguments[0]); } } f(1); } expect: { !function() { try { throw 0; } catch (e) { console.log(arguments[0]); } }(1); } expect_stdout: "1" } issue_2101: { options = { inline: true, } input: { a = {}; console.log(function() { return function() { return this.a; }(); }() === function() { return a; }()); } expect: { a = {}; console.log(function() { return this.a; }() === a); } expect_stdout: "true" } inner_ref: { options = { inline: true, unused: true, } input: { console.log(function(a) { return function() { return a; }(); }(1), function(a) { return function(a) { return a; }(); }(2)); } expect: { console.log(function(a) { return a; }(1), function(a) { return a; }()); } expect_stdout: "1 undefined" } issue_2107: { options = { collapse_vars: true, inline: true, passes: 3, sequences: true, side_effects: true, unused: true, } input: { var c = 0; !function() { c++; }(c++ + new function() { this.a = 0; var a = (c = c + 1) + (c = 1 + c); return c++ + a; }()); console.log(c); } expect: { var c = 0; c++, new function() { this.a = 0, c = 1 + (c += 1), c++; }(), c++, console.log(c); } expect_stdout: "5" } issue_2114_1: { options = { collapse_vars: true, if_return: true, inline: true, keep_fargs: false, side_effects: true, unused: true, } input: { var c = 0; !function(a) { a = 0; }([ { 0: c = c + 1, length: c = 1 + c }, typeof void function a() { var b = function f1(a) { }(b && (b.b += (c = c + 1, 0))); }() ]); console.log(c); } expect: { var c = 0; c = 1 + (c += 1), function() { var b = void (b && (b.b += (c += 1, 0))); }(); console.log(c); } expect_stdout: "2" } issue_2114_2: { options = { collapse_vars: true, if_return: true, inline: true, keep_fargs: false, passes: 2, side_effects: true, unused: true, } input: { var c = 0; !function(a) { a = 0; }([ { 0: c = c + 1, length: c = 1 + c }, typeof void function a() { var b = function f1(a) { }(b && (b.b += (c = c + 1, 0))); }() ]); console.log(c); } expect: { var c = 0; c = 1 + (c += 1), function() { var b = void (b && (b.b += (c += 1, 0))); }(); console.log(c); } expect_stdout: "2" } issue_2428: { options = { collapse_vars: true, inline: true, passes: 3, pure_getters: "strict", reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unsafe: true, unused: true, } input: { function bar(k) { console.log(k); } function foo(x) { return bar(x); } function baz(a) { foo(a); } baz(42); baz("PASS"); } expect: { function baz(a) { console.log(a); } baz(42); baz("PASS"); } expect_stdout: [ "42", "PASS", ] } issue_2531_1: { options = { evaluate: true, inline: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { function outer() { function inner(value) { function closure() { return value; } return function() { return closure(); }; } return inner("Hello"); } console.log("Greeting:", outer()()); } expect: { function outer() { return value = "Hello", function() { return value; }; var value; } console.log("Greeting:", outer()()); } expect_stdout: "Greeting: Hello" } issue_2531_2: { options = { evaluate: true, inline: true, passes: 3, reduce_funcs: true, reduce_vars: true, side_effects: true, unused: true, } input: { function outer() { function inner(value) { function closure() { return value; } return function() { return closure(); }; } return inner("Hello"); } console.log("Greeting:", outer()()); } expect: { function outer() { return function() { return "Hello"; }; } console.log("Greeting:", outer()()); } expect_stdout: "Greeting: Hello" } issue_2531_3: { options = { evaluate: true, inline: true, passes: 3, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { function outer() { function inner(value) { function closure() { return value; } return function() { return closure(); }; } return inner("Hello"); } console.log("Greeting:", outer()()); } expect: { console.log("Greeting:", "Hello"); } expect_stdout: "Greeting: Hello" } empty_body: { options = { reduce_vars: true, side_effects: true, } input: { function f() { function noop() {} noop(); return noop; } } expect: { function f() { function noop() {} return noop; } } } inline_loop_1: { options = { inline: true, reduce_vars: true, toplevel: true, unused: true, } input: { function f() { return x(); } for (;;) f(); } expect: { for (;;) x(); } } inline_loop_2: { options = { inline: true, reduce_vars: true, toplevel: true, unused: true, } input: { for (;;) f(); function f() { return x(); } } expect: { for (;;) x(); } } inline_loop_3: { options = { inline: true, reduce_vars: true, toplevel: true, unused: true, } input: { var f = function() { return x(); }; for (;;) f(); } expect: { for (;;) x(); } } inline_loop_4: { options = { inline: true, reduce_vars: true, toplevel: true, unused: true, } input: { for (;;) f(); var f = function() { return x(); }; } expect: { for (;;) f(); var f = function() { return x(); }; } } issue_2476: { options = { inline: true, reduce_vars: true, toplevel: true, unused: true, } input: { function foo(x, y, z) { return x < y ? x * y + z : x * z - y; } for (var sum = 0, i = 0; i < 10; i++) sum += foo(i, i + 1, 3 * i); console.log(sum); } expect: { for (var sum = 0, i = 0; i < 10; i++) sum += (x = i, y = i + 1, z = 3 * i, x < y ? x * y + z : x * z - y); var x, y, z; console.log(sum); } expect_stdout: "465" } issue_2601_1: { options = { inline: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { var a = "FAIL"; (function() { function f(b) { function g(b) { b && b(); } g(); (function() { b && (a = "PASS"); })(); } f("foo"); })(); console.log(a); } expect: { var a = "FAIL"; (function() { var b; b = "foo", function(b) { b && b(); }(), b && (a = "PASS"); })(), console.log(a); } expect_stdout: "PASS" } issue_2601_2: { rename = true options = { evaluate: true, inline: true, passes: 3, reduce_vars: true, sequences: true, side_effects: true, unused: true, } mangle = {} input: { var a = "FAIL"; (function() { function f(b) { function g(b) { b && b(); } g(); (function() { b && (a = "PASS"); })(); } f("foo"); })(); console.log(a); } expect: { var a = "FAIL"; a = "PASS", console.log(a); } expect_stdout: "PASS" } issue_2604_1: { options = { inline: true, side_effects: true, unused: true, } input: { var a = "FAIL"; (function() { try { throw 1; } catch (b) { (function f(b) { b && b(); })(); b && (a = "PASS"); } })(); console.log(a); } expect: { var a = "FAIL"; (function() { try { throw 1; } catch (b) { (function(b) { b && b(); })(); b && (a = "PASS"); } })(); console.log(a); } expect_stdout: "PASS" } issue_2604_2: { rename = true options = { evaluate: true, inline: true, passes: 3, reduce_vars: true, side_effects: true, unused: true, } mangle = {} input: { var a = "FAIL"; (function() { try { throw 1; } catch (b) { (function f(b) { b && b(); })(); b && (a = "PASS"); } })(); console.log(a); } expect: { var a = "FAIL"; (function() { try { throw 1; } catch (o) { o && (a = "PASS"); } })(); console.log(a); } expect_stdout: "PASS" } unsafe_apply_1: { options = { inline: true, passes: 2, reduce_vars: true, side_effects: true, unsafe: true, unused: true, } input: { (function(a, b) { console.log(a, b); }).apply("foo", [ "bar" ]); (function(a, b) { console.log(this, a, b); }).apply("foo", [ "bar" ]); (function(a, b) { console.log(a, b); }).apply("foo", [ "bar" ], "baz"); } expect: { console.log("bar", void 0); (function(a, b) { console.log(this, a, b); }).call("foo", "bar"); (function(a, b) { console.log(a, b); }).apply("foo", [ "bar" ], "baz"); } expect_stdout: true } unsafe_apply_2: { options = { reduce_vars: true, side_effects: true, toplevel: true, unsafe: true, } input: { function foo() { console.log(a, b); } var bar = function(a, b) { console.log(this, a, b); } (function() { foo.apply("foo", [ "bar" ]); bar.apply("foo", [ "bar" ]); })(); } expect: { function foo() { console.log(a, b); } var bar = function(a, b) { console.log(this, a, b); } (function() { foo("bar"); bar.call("foo", "bar"); })(); } expect_stdout: true } unsafe_apply_expansion_1: { options = { unsafe: true, } input: { console.log.apply(console, [1, ...[2, 3], 4]); } expect: { console.log.call(console, 1, 2, 3, 4); } expect_stdout: "1 2 3 4" } unsafe_apply_expansion_2: { options = { unsafe: true, } input: { var values = [2, 3]; console.log.apply(console, [1, ...values, 4]); } expect: { var values = [2, 3]; console.log.call(console, 1, ...values, 4); } expect_stdout: "1 2 3 4" } unsafe_call_1: { options = { inline: true, passes: 2, reduce_vars: true, side_effects: true, unsafe: true, unused: true, } input: { (function(a, b) { console.log(a, b); }).call("foo", "bar"); (function(a, b) { console.log(this, a, b); }).call("foo", "bar"); } expect: { console.log("bar", void 0); (function(a, b) { console.log(this, a, b); }).call("foo", "bar"); } expect_stdout: true } unsafe_call_2: { options = { reduce_vars: true, side_effects: true, toplevel: true, unsafe: true, } input: { function foo() { console.log(a, b); } var bar = function(a, b) { console.log(this, a, b); } (function() { foo.call("foo", "bar"); bar.call("foo", "bar"); })(); } expect: { function foo() { console.log(a, b); } var bar = function(a, b) { console.log(this, a, b); } (function() { foo("bar"); bar.call("foo", "bar"); })(); } expect_stdout: true } unsafe_call_3: { options = { side_effects: true, unsafe: true, } input: { console.log(function() { return arguments[0] + eval("arguments")[1]; }.call(0, 1, 2)); } expect: { console.log(function() { return arguments[0] + eval("arguments")[1]; }(1, 2)); } expect_stdout: "3" } unsafe_call_expansion_1: { options = { unsafe: true, } input: { (function(...a) { console.log(...a); }).call(console, 1, ...[2, 3], 4); } expect: { console, (function(...a) { console.log(...a); })(1, 2, 3, 4); } expect_stdout: "1 2 3 4" } unsafe_call_expansion_2: { options = { unsafe: true, } input: { var values = [2, 3]; (function(...a) { console.log(...a); }).call(console, 1, ...values, 4); } expect: { var values = [2, 3]; console, (function(...a) { console.log(...a); })(1, ...values, 4); } expect_stdout: "1 2 3 4" } issue_2616: { options = { evaluate: true, inline: true, reduce_vars: true, side_effects: true, unused: true, } input: { var c = "FAIL"; (function() { function f() { function g(NaN) { (true << NaN) - 0/0 || (c = "PASS"); } g([]); } f(); })(); console.log(c); } expect: { var c = "FAIL"; !function (NaN) { (true << NaN) - 0 / 0 || (c = "PASS"); }([]); console.log(c); } expect_stdout: "PASS" } issue_2620_1: { options = { inline: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { var c = "FAIL"; (function() { function f(a) { var b = function g(a) { a && a(); }(); if (a) { var d = c = "PASS"; } } f(1); })(); console.log(c); } expect: { var c = "FAIL"; !function (a) { if (function (a) { a && a(); }(), a) c = "PASS"; }(1), console.log(c); } expect_stdout: "PASS" } issue_2620_2: { options = { conditionals: true, evaluate: true, inline: true, passes: 2, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { var c = "FAIL"; (function() { function f(a) { var b = function g(a) { a && a(); }(); if (a) { var d = c = "PASS"; } } f(1); })(); console.log(c); } expect: { var c = "FAIL"; c = "PASS", console.log(c); } expect_stdout: "PASS" } issue_2620_3: { options = { evaluate: true, inline: true, reduce_vars: true, side_effects: true, unused: true, } input: { var c = "FAIL"; (function() { function f(a, NaN) { function g() { switch (a) { case a: break; case c = "PASS", NaN: break; } } g(); } f(0/0); })(); console.log(c); } expect: { var c = "FAIL"; !function (a, NaN) { (function () { switch (a) { case a: break; case c = "PASS", NaN: break; } })(); }(NaN); console.log(c); } expect_stdout: "PASS" } issue_2620_4: { rename = true, options = { dead_code: true, evaluate: true, inline: true, passes: 2, reduce_vars: true, side_effects: true, switches: true, unused: true, } input: { var c = "FAIL"; (function() { function f(a, NaN) { function g() { switch (a) { case a: break; case c = "PASS", NaN: break; } } g(); } f(0/0); })(); console.log(c); } expect: { var c = "FAIL"; !function() { switch (NaN) { case void (c = "PASS"): } }(); console.log(c); } expect_stdout: "PASS" } issue_2630_1: { options = { collapse_vars: true, inline: true, passes: 2, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { var c = 0; (function() { while (f()); function f() { var a = function() { var b = c++, d = c = 1 + c; }(); } })(); console.log(c); } expect: { var c = 0; (function() { while (void (c = 1 + ++c)); })(), console.log(c); } expect_stdout: "2" } issue_2630_2: { options = { collapse_vars: true, inline: true, passes: 2, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { var c = 0; !function() { while (f()) {} function f() { var not_used = function() { c = 1 + c; }(c = c + 1); } }(); console.log(c); } expect: { var c = 0; !function() { while (void (c = 1 + (c += 1))); }(), console.log(c); } expect_stdout: "2" } issue_2630_3: { options = { inline: true, reduce_vars: true, unused: true, } input: { var x = 2, a = 1; (function() { function f1(a) { f2(); --x >= 0 && f1({}); } f1(a++); function f2() { a++; } })(); console.log(a); } expect: { var x = 2, a = 1; (function() { (function f1(a) { f2(); --x >= 0 && f1({}); })(a++); function f2() { a++; } })(); console.log(a); } expect_stdout: "5" } issue_2630_4: { options = { collapse_vars: true, inline: true, reduce_vars: true, side_effects: true, unused: true, } input: { var x = 3, a = 1, b = 2; (function() { (function f1() { while (--x >= 0 && f2()); }()); function f2() { a++ + (b += a); } })(); console.log(a); } expect: { var x = 3, a = 1, b = 2; (function() { (function() { while (--x >= 0 && void (a++, b += a)); })(); })(); console.log(a); } expect_stdout: "2" } issue_2630_5: { options = { collapse_vars: true, inline: true, reduce_vars: true, unused: true, } input: { var c = 1; !function() { do { c *= 10; } while (f()); function f() { return function() { return (c = 2 + c) < 100; }(c = c + 3); } }(); console.log(c); } expect: { var c = 1; !function() { do { c *= 10; } while ((c = 2 + (c += 3)) < 100); }(); console.log(c); } expect_stdout: "155" } issue_2647_1: { options = { inline: true, reduce_vars: true, side_effects: true, unused: true, } input: { (function(n, o = "FAIL") { console.log(n); })("PASS"); (function(n, o = "PASS") { console.log(o); })("FAIL"); (function(o = "PASS") { console.log(o); })(); (function(n, {o = "FAIL"}) { console.log(n); })("PASS", {}); } expect: { console.log("PASS"); (function(n, o = "PASS") { console.log(o); })(); (function(o = "PASS") { console.log(o); })(); (function(n, {o = "FAIL"}) { console.log("PASS"); })(0, {}); } expect_stdout: [ "PASS", "PASS", "PASS", "PASS", ] } issue_2647_2: { options = { collapse_vars: true, inline: true, reduce_vars: true, unused: true, } input: { (function() { function foo(x) { return x.toUpperCase(); } console.log((() => foo("pass"))()); }()); } expect: { (function() { function foo(x) { return x.toUpperCase(); } console.log((() => foo("pass"))()); }()); } expect_stdout: "PASS" } issue_2647_3: { options = { collapse_vars: true, inline: true, reduce_vars: true, unused: true, } input: { (function() { function foo(x) { return x.toUpperCase(); } console.log((() => { return foo("pass"); })()); }()); } expect: { void console.log("pass".toUpperCase()); } expect_stdout: "PASS" } recursive_inline_1: { options = { inline: true, reduce_funcs: true, reduce_vars: true, sequences: true, toplevel: true, unused: true, } input: { function f() { h(); } function g(a) { a(); } function h(b) { g(); if (b) x(); } } expect: {} } recursive_inline_2: { options = { reduce_vars: true, toplevel: true, unused: true, } input: { function f(n) { return n ? n * f(n - 1) : 1; } console.log(f(5)); } expect: { console.log(function f(n) { return n ? n * f(n - 1) : 1; }(5)); } expect_stdout: "120" } issue_2657: { options = { inline: true, reduce_vars: true, sequences: true, unused: true, } input: { "use strict"; console.log(function f() { return h; function g(b) { return b || b(); } function h(a) { g(a); return a; } }()(42)); } expect: { "use strict"; console.log(function(a) { return b = a, b || b(), a; var b; }(42)); } expect_stdout: "42" } issue_2663_1: { options = { inline: true, reduce_vars: true, unused: true, } input: { (function() { var i, o = {}; function createFn(j) { return function() { console.log(j); }; } for (i in { a: 1, b: 2, c: 3 }) o[i] = createFn(i); for (i in o) o[i](); })(); } expect: { (function() { var i, o = {}; function createFn(j) { return function() { console.log(j); }; } for (i in { a: 1, b: 2, c: 3 }) o[i] = createFn(i); for (i in o) o[i](); })(); } expect_stdout: [ "a", "b", "c", ] } issue_2663_2: { options = { inline: true, reduce_vars: true, side_effects: true, unused: true, } input: { (function() { var i; function fn(j) { return function() { console.log(j); }(); } for (i in { a: 1, b: 2, c: 3 }) fn(i); })(); } expect: { (function() { var i; for (i in { a: 1, b: 2, c: 3 }) j = i, console.log(j); var j; })(); } expect_stdout: [ "a", "b", "c", ] } issue_2663_3: { options = { inline: true, reduce_vars: true, unused: true, } input: { (function () { var outputs = [ { type: 0, target: null, eventName: "ngSubmit", propName: null }, { type: 0, target: null, eventName: "submit", propName: null }, { type: 0, target: null, eventName: "reset", propName: null }, ]; function listenToElementOutputs(outputs) { var handlers = []; for (var i = 0; i < outputs.length; i++) { var output = outputs[i]; var handleEventClosure = renderEventHandlerClosure(output.eventName); handlers.push(handleEventClosure) } var target, name; return handlers; } function renderEventHandlerClosure(eventName) { return function () { return console.log(eventName); }; } listenToElementOutputs(outputs).forEach(function (handler) { return handler() }); })(); } expect: { (function() { function renderEventHandlerClosure(eventName) { return function() { return console.log(eventName); }; } (function(outputs) { var handlers = []; for (var i = 0; i < outputs.length; i++) { var output = outputs[i]; var handleEventClosure = renderEventHandlerClosure(output.eventName); handlers.push(handleEventClosure); } return handlers; })([ { type: 0, target: null, eventName: "ngSubmit", propName: null }, { type: 0, target: null, eventName: "submit", propName: null }, { type: 0, target: null, eventName: "reset", propName: null } ]).forEach(function(handler) { return handler(); }); })(); } expect_stdout: [ "ngSubmit", "submit", "reset", ] } duplicate_argnames: { options = { inline: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { var a = "PASS"; function f(b, b, b) { b && (a = "FAIL"); } f(0, console); console.log(a); } expect: { var a = "PASS"; console, b && (a = "FAIL"); var b; console.log(a); } expect_stdout: "PASS" } loop_init_arg: { options = { inline: true, side_effects: true, toplevel: true, } input: { var a = "PASS"; for (var k in "12") (function (b) { (b >>= 1) && (a = "FAIL"), b = 2; })(); console.log(a); } expect: { var a = "PASS"; for (var k in "12") b = void 0, (b >>= 1) && (a = "FAIL"), b = 2; var b; console.log(a); } expect_stdout: "PASS" } inline_false: { options = { inline: false, side_effects: true, toplevel: true, } input: { (function() { console.log(1); })(); (function(a) { console.log(a); })(2); (function(b) { var c = b; console.log(c); })(3); } expect: { (function() { console.log(1); })(); (function(a) { console.log(a); })(2); (function(b) { var c = b; console.log(c); })(3); } expect_stdout: [ "1", "2", "3", ] } inline_0: { options = { inline: 0, side_effects: true, toplevel: true, } input: { (function() { console.log(1); })(); (function(a) { console.log(a); })(2); (function(b) { var c = b; console.log(c); })(3); } expect: { (function() { console.log(1); })(); (function(a) { console.log(a); })(2); (function(b) { var c = b; console.log(c); })(3); } expect_stdout: [ "1", "2", "3", ] } inline_1: { options = { inline: 1, side_effects: true, toplevel: true, } input: { (function() { console.log(1); })(); (function(a) { console.log(a); })(2); (function(b) { var c = b; console.log(c); })(3); } expect: { console.log(1); (function(a) { console.log(a); })(2); (function(b) { var c = b; console.log(c); })(3); } expect_stdout: [ "1", "2", "3", ] } inline_2: { options = { inline: 2, side_effects: true, toplevel: true, } input: { (function() { console.log(1); })(); (function(a) { console.log(a); })(2); (function(b) { var c = b; console.log(c); })(3); } expect: { console.log(1); a = 2, console.log(a); var a; (function(b) { var c = b; console.log(c); })(3); } expect_stdout: [ "1", "2", "3", ] } inline_3: { options = { inline: 3, side_effects: true, toplevel: true, } input: { (function() { console.log(1); })(); (function(a) { console.log(a); })(2); (function(b) { var c = b; console.log(c); })(3); } expect: { console.log(1); a = 2, console.log(a); var a; b = 3, c = b, console.log(c); var b, c; } expect_stdout: [ "1", "2", "3", ] } inline_true: { options = { inline: true, side_effects: true, toplevel: true, } input: { (function() { console.log(1); })(); (function(a) { console.log(a); })(2); (function(b) { var c = b; console.log(c); })(3); } expect: { console.log(1); a = 2, console.log(a); var a; b = 3, c = b, console.log(c); var b, c; } expect_stdout: [ "1", "2", "3", ] } issue_2842: { options = { side_effects: true, reduce_vars: true, reduce_funcs: true, unused: true, } input: { (function() { function inlinedFunction(data) { return data[data[0]]; } function testMinify() { if (true) { const data = inlinedFunction([1, 2, 3]); console.log(data); } } return testMinify(); })(); } expect: { (function () { (function () { if (true) { const data = function (data) { return data[data[0]]; }([1, 2, 3]); console.log(data); } })(); })(); } expect_stdout: [ "2" ] } use_before_init_in_loop: { options = { inline: true, side_effects: true, toplevel: true, } input: { var a = "PASS"; for (var b = 2; --b >= 0;) (function() { var c = function() { return 1; }(c && (a = "FAIL")); })(); console.log(a); } expect: { var a = "PASS"; for (var b = 2; --b >= 0;) c = void 0, c = (c && (a = "FAIL"), 1); var c; console.log(a); } expect_stdout: "PASS" } duplicate_arg_var: { options = { inline: true, toplevel: true, } input: { console.log(function(b) { return b; var b; }("PASS")); } expect: { console.log((b = "PASS", b)); var b; } expect_stdout: "PASS" } issue_2737_1: { options = { inline: true, reduce_vars: true, unused: true, } input: { (function(a) { while (a()); })(function f() { console.log(typeof f); }); } expect: { (function(a) { while (a()); })(function f() { console.log(typeof f); }); } expect_stdout: "function" } issue_2737_2: { options = { 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 qux() { return console.log("PASS"), qux; }); } expect_stdout: "PASS" } issue_2783: { options = { collapse_vars: true, conditionals: true, if_return: true, inline: true, reduce_vars: true, unused: true, } input: { (function() { return g; function f(a) { var b = a.b; if (b) return b; return a; } function g(o, i) { while (i--) { console.log(f(o)); } } })()({ b: "PASS" }, 1); } expect: { (function() { return function(o,i) { while (i--) console.log(f(o)); }; function f(a) { var b = a.b; return b || a; } })()({ b: "PASS" },1); } expect_stdout: "PASS" } inline_function_expressions: { options = { inline: 2 } input: { (async()=>2)().catch(x=>null); (async function(){ return 3; })().catch(x => null); (() => 4)(); (function(){ return 5; })(); (function*(){ return 6; })(); } expect: { (async()=>2)().catch(x=>null); (async function(){return 3})().catch(x=>null); 4; 5; (function*(){return 6})(); } } issue_2898: { options = { collapse_vars: true, inline: true, reduce_vars: true, sequences: true, unused: true, } input: { var c = 0; (function() { while (f()); function f() { var b = (c = 1 + c, void (c = 1 + c)); b && b[0]; } })(); console.log(c); } expect: { var c = 0; (function() { while (b = void 0, void ((b = void (c = 1 + (c = 1 + c))) && b[0])); var b; })(), console.log(c); } expect_stdout: "2" } deduplicate_parenthesis: { input: { ({}).a = b; (({}).a = b)(); (function() {}).a = b; ((function() {}).a = b)(); } expect_exact: "({}).a=b;({}.a=b)();(function(){}).a=b;(function(){}.a=b)();" } issue_3166: { options = { directives: true, } input: { "foo"; "use strict"; function f() { "use strict"; "bar"; "use asm"; } } expect: { "use strict"; function f() { "use asm"; } } } issue_3016_1: { options = { inline: true, toplevel: true, } input: { var b = 1; do { (function(a) { return a[b]; var a; })(3); } while (0); console.log(b); } expect: { var b = 1; do { a = 3, a[b]; } while(0); var a; console.log(b); } expect_stdout: "1" } issue_3016_2: { options = { dead_code: true, inline: true, toplevel: true, } input: { var b = 1; do { (function(a) { return a[b]; try { a = 2; } catch (a) { var a; } })(3); } while (0); console.log(b); } expect: { var b = 1; do { a = 3, a[b]; } while(0); var a; console.log(b); } expect_stdout: "1" } issue_3016_2_ie8: { options = { dead_code: true, ie8: true, inline: true, toplevel: true, } input: { var b = 1; do { (function(a) { return a[b]; try { a = 2; } catch (a) { var a; } })(3); } while (0); console.log(b); } expect: { var b = 1; do { a = 3, a[b]; } while(0); var a; console.log(b); } expect_stdout: "1" } issue_3016_3: { options = { dead_code: true, inline: true, toplevel: true, } input: { var b = 1; do { console.log(function() { return a ? "FAIL" : a = "PASS"; try { a = 2; } catch (a) { var a; } }()); } while (b--); } expect: { var b = 1; do { console.log((a = void 0, a ? "FAIL" : a = "PASS")); } while(b--); var a; } expect_stdout: [ "PASS", "PASS", ] } issue_3016_3_ie8: { options = { dead_code: true, ie8: true, inline: true, toplevel: true, } input: { var b = 1; do { console.log(function() { return a ? "FAIL" : a = "PASS"; try { a = 2; } catch (a) { var a; } }()); } while (b--); } expect: { var b = 1; do { console.log((a = void 0, a ? "FAIL" : a = "PASS")); } while(b--); var a; } expect_stdout: [ "PASS", "PASS", ] } issue_3018: { options = { inline: true, side_effects: true, toplevel: true, } input: { var b = 1, c = "PASS"; do { (function() { (function(a) { a = 0 != (a && (c = "FAIL")); })(); })(); } while (b--); console.log(c); } expect: { var b = 1, c = "PASS"; do { a = void 0, a = 0 != (a && (c = "FAIL")); } while (b--); var a; console.log(c); } expect_stdout: "PASS" } issue_3054: { options = { booleans: true, collapse_vars: true, inline: 1, reduce_vars: true, toplevel: true, } input: { "use strict"; function f() { return { a: true }; } console.log(function(b) { b = false; return f(); }().a, f.call().a); } expect_stdout: "true true" } issue_3076: { options = { dead_code: true, inline: true, sequences: true, unused: true, } input: { var c = "PASS"; (function(b) { var n = 2; while (--b + function() { e && (c = "FAIL"); e = 5; return 1; try { var a = 5; } catch (e) { var e; } }().toString() && --n > 0); })(2); console.log(c); } expect: { var c = "PASS"; (function(b) { var n = 2; while (--b + (e = void 0, e && (c = "FAIL"), e = 5, 1).toString() && --n > 0); var e; })(2), console.log(c); } expect_stdout: "PASS" } issue_3125: { options = { inline: true, unsafe: true, } input: { console.log(function() { return "PASS"; }.call()); } expect: { console.log("PASS"); } expect_stdout: "PASS" } drop_lone_use_strict: { options = { directives: true, side_effects: true, } input: { function f1() { "use strict"; } function f2() { "use strict"; function f3() { "use strict"; } } (function f4() { "use strict"; })(); } expect: { function f1() { } function f2() { "use strict"; function f3() { } } } } drop_lone_use_strict_arrows_1: { options = { side_effects: true, directives: true, } input: { var f0 = () => 0; var f1 = () => { "use strict"; } var f2 = () => { "use strict"; var f3 = () => { "use strict"; } } (() => { "use strict"; })(); } expect: { var f0 = () => 0; var f1 = () => {}; var f2 = () => { "use strict"; var f3 = () => {}; }; } } drop_lone_use_strict_arrows_2: { options = { dead_code: true, passes: 2, side_effects: true, unused: true, } input: { let f0 = () => 0; let f1 = () => { "use strict"; } let f2 = () => { "use strict"; let f3 = () => { "use strict"; } } (() => { "use strict"; return undefined; })(); } expect: { let f0 = () => 0; let f1 = () => {}; let f2 = () => {}; } } issue_t131a: { options = { inline: 1, join_vars: true, reduce_vars: true, side_effects: true, unused: true, } input: { (function() { function thing() { return { a: 1, }; } function one() { return thing(); } function two() { var x = thing(); x.a = 2; x.b = 3; return x; } console.log(JSON.stringify(one()), JSON.stringify(two())); })(); } expect: { (function() { console.log(JSON.stringify({ a: 1 }), JSON.stringify(function() { var x = { a: 2, b: 3 }; return x; }())); })(); } expect_stdout: '{"a":1} {"a":2,"b":3}' } issue_t131b: { options = { defaults: true, passes: 2, } input: { (function() { function thing() { return { a: 1, }; } function one() { return thing(); } function two() { var x = thing(); x.a = 2; x.b = 3; return x; } console.log(JSON.stringify(one()), JSON.stringify(two())); })(); } expect: { console.log(JSON.stringify({ a: 1 }), JSON.stringify({ a: 2, b: 3 })); } expect_stdout: '{"a":1} {"a":2,"b":3}' } terser-4.1.2/test/compress/global_defs.js000066400000000000000000000105311351061312300204260ustar00rootroot00000000000000must_replace: { options = { global_defs: { D: "foo bar", }, } input: { console.log(D); } expect: { console.log("foo bar"); } } 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: { const 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: { const 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); } } terser-4.1.2/test/compress/harmony.js000066400000000000000000001217661351061312300176570ustar00rootroot00000000000000arrow_function_parens: { input: { something && (() => {}); } expect_exact: "something&&(()=>{});" } arrow_function_parens_2: { input: { (() => null)(); } expect_exact: "(()=>null)();" } typeof_arrow_functions: { options = { evaluate: true, typeofs: true, } input: { var foo = typeof (x => null); console.log(foo); } expect_exact: "var foo=\"function\";console.log(foo);" expect_stdout: "function" } classes: { input: { class SomeClass { constructor() { }; foo() {}; }; class NoSemi { constructor(...args) { } foo() {} }; class ChildClass extends SomeClass {}; var asExpression = class AsExpression {}; var nameless = class {}; } expect_exact: "class SomeClass{constructor(){}foo(){}}class NoSemi{constructor(...args){}foo(){}}class ChildClass extends SomeClass{}var asExpression=class AsExpression{};var nameless=class{};" } class_statics: { input: { x = class { static staticMethod() {} static get foo() {} static set bar() {} static() { /* "static" can be a method name! */ } get() { /* "get" can be a method name! */ } set() { /* "set" can be a method name! */ } } } expect_exact: "x=class{static staticMethod(){}static get foo(){}static set bar(){}static(){}get(){}set(){}};" } class_name_can_be_mangled: { mangle = { }; input: { function x() { class Foo { } var class1 = Foo; var class2 = class Bar {}; } } expect: { function x() { class a { } var s = a; var c = class a {}; } } } class_name_can_be_preserved: { mangle = { keep_classnames: true } input: { function x() { (class Baz { }); class Foo {}; } } expect: { function x() { (class Baz { }); class Foo {}; } } } classes_can_have_generators: { input: { class Foo { *bar() {} static *baz() {} } } expect: { class Foo { *bar() {} static *baz() {} } } } classes_can_have_computed_generators: { input: { class C4 { *['constructor']() {} } } expect: { class C4 { *['constructor']() {} } } } classes_can_have_computed_static: { input: { class C4 { static ['constructor']() {} } } expect: { class C4 { static ['constructor']() {} } } } class_methods_and_getters_with_keep_quoted_props_enabled: { beautify = { quote_style: 3, keep_quoted_props: true, } input: { class clss { a() {} "b"() {} get c() { return "c"} get "d"() { return "d"} set e(a) { doSomething(a); } set 'f'(a) { doSomething(b); } static g() {} static "h"() {} } } expect_exact: 'class clss{a(){}"b"(){}get c(){return"c"}get"d"(){return"d"}set e(a){doSomething(a)}set\'f\'(a){doSomething(b)}static g(){}static"h"(){}}' } classes_with_expression_as_expand: { input: { class D extends (calls++, C) {} } expect_exact: "class D extends(calls++,C){}" } new_target: { input: { new.target; new.target.name; } expect_exact: "new.target;new.target.name;" } number_literals: { input: { 0b1001; 0B1001; 0o11; 0O11; } expect: { 9; 9; 9; 9; } } import_statement: { input: { import "mod-name"; import Foo from "bar"; import { Bar, Baz } from 'lel'; import Bar, { Foo } from 'lel'; import { Bar as kex, Baz as food } from 'lel'; } expect_exact: 'import"mod-name";import Foo from"bar";import{Bar,Baz}from"lel";import Bar,{Foo}from"lel";import{Bar as kex,Baz as food}from"lel";' } import_all_statement: { input: { import * from 'lel'; import * as Lel from 'lel'; } expect_exact: 'import*from"lel";import*as Lel from"lel";' } export_statement: { options = { evaluate: true, } input: { export default 1 + 2; export var a = 4; export let b = 6; export const c = 6; export function d() {}; export class e {}; } expect_exact: "export default 3;export var a=4;export let b=6;export const c=6;export function d(){}export class e{}" } export_default_object_expression: { options = { evaluate: true, } input: { export default { foo: 1 + 2, bar() { return 4; }, get baz() { return this.foo; }, }; } expect_exact: "export default{foo:3,bar(){return 4},get baz(){return this.foo}};" } export_default_array: { options = { evaluate: true, } input: { export default [ 1 + 2, foo ]; } expect_exact: "export default[3,foo];" } export_default_anon_function: { options = { evaluate: true, } input: { export default function(){ console.log(1 + 2); } } expect_exact: "export default function(){console.log(3)}" } export_default_anon_class: { options = { evaluate: true, } input: { export default class { foo() { console.log(1 + 2); } } } expect_exact: "export default class{foo(){console.log(3)}}" } export_module_statement: { input: { export * from "a.js"; export {A} from "a.js"; export {A, B} from "a.js"; export {C}; } expect_exact: 'export*from"a.js";export{A}from"a.js";export{A,B}from"a.js";export{C};' } import_statement_mangling: { mangle = { toplevel: true }; input: { import Foo from "foo"; import Bar, {Food} from "lel"; import {What as Whatever} from "lel"; Foo(); Bar(); Food(); Whatever(); } expect: { import o from "foo"; import m, {Food as r} from "lel"; import {What as f} from "lel"; o(); m(); r(); f(); } } export_statement_mangling: { mangle = { }; input: { export var foo = 6; export function bar() { } export class Baz { } bar(foo, Baz) } expect: { export var foo = 6; export function bar() { } export class Baz { } bar(foo, Baz) } } // https://github.com/mishoo/UglifyJS2/issues/1021 regression_for_of_const: { input: { for (const x of y) {} for (const x in y) {} } expect: { for (const x of y);for (const x in y); } } // Fabio: My patches accidentally caused a crash whenever // there's an extraneous set of parens around an object. regression_cannot_destructure: { input: { var x = ({ x : 3 }); x(({ x: 3 })); } expect_exact: "var x={x:3};x({x:3});"; } regression_cannot_use_of: { input: { function of() { } var of = "is a valid variable name"; of = { of: "is ok" }; x.of; of: foo() } expect: { function of(){} var of="is a valid variable name"; of={of:"is ok"}; x.of; foo(); /* Label statement missing? No prob. */ } } fat_arrow_as_param: { input: { foo(x => x); foo(x => x, y => y); foo(x => (x, x)); foo(x => (x, x), y => (y, y)); } expect_exact: "foo(x=>x);foo(x=>x,y=>y);foo(x=>(x,x));foo(x=>(x,x),y=>(y,y));" } default_assign: { options = { keep_fargs: false, unused: true, } input: { function f(a, b = 3) { console.log(a); } g = ([[] = 123]) => {}; h = ([[x, y, z] = [4, 5, 6]] = []) => {}; function i([[x, y, z] = [4, 5, 6]] = []) { console.log(b); }; } expect: { function f(a) { console.log(a); } g = ([[] = 123]) => {}; h = ([[x, y, z] = [4, 5, 6]] = []) => {}; function i([[x, y, z] = [4, 5, 6]] = []) { console.log(b); }; } } expansion: { options = { keep_fargs: false, unused: true, } input: { function f(a, ...b) { console.log(a); } } expect: { function f(a) { console.log(a); } } } issue_1613: { mangle = { toplevel: true }; input: { const name = 1; const foo = { name }; } expect_exact: "const n=1;const c={name:n};" } format_methods: { beautify = { beautify: true, } input: { class A extends B {constructor(a){x()} static s(b,c){y()} run(d,e,f){z()}} } expect_exact: [ "class A extends B {", " constructor(a) {", " x();", " }", " static s(b, c) {", " y();", " }", " run(d, e, f) {", " z();", " }", "}", ] } issue_1898: { options = { } mangle = { } input: { class Foo { bar() { for (const x of [ 6, 5 ]) { for (let y of [ 4, 3 ]) { for (var z of [ 2, 1 ]) { console.log(x, y, z); } } } } } new Foo().bar(); } expect: { class Foo { bar() { for (const f of [ 6, 5 ]) for (let r of [ 4, 3 ]) for (var o of [ 2, 1 ]) console.log(f, r, o); } } new Foo().bar(); } } issue_1753: { mangle = { safari10: true }; input: { class SomeClass { constructor(props) { let pickedSets = []; for (let i = 0; i < 6; i++) { pickedSets.push({ mainDrawNumbers: [], extraDrawNumbers: [] }); } } } } expect: { class SomeClass { constructor(r) { let s = []; for (let a = 0; a < 6; a++) s.push({ mainDrawNumbers: [], extraDrawNumbers: [] }); } } } } issue_1753_disable: { mangle = { safari10: false } input: { class SomeClass { constructor(props) { let pickedSets = []; for (let i = 0; i < 6; i++) { pickedSets.push({ mainDrawNumbers: [], extraDrawNumbers: [] }); } } } } expect: { class SomeClass { constructor(r) { let s = []; for (let r = 0; r < 6; r++) s.push({ mainDrawNumbers: [], extraDrawNumbers: [] }); } } } } class_extends: { options = { evaluate: true, } input: { function f() { class foo extends bar {} class pro extends some.prop {} class arr extends stuff[1 - 1] {} class bin extends (a || b) {} class seq extends (a, b) {} class ter extends (a ? b : c) {} class uni extends (!0) {} } } expect_exact: "function f(){class foo extends bar{}class pro extends some.prop{}class arr extends stuff[0]{}class bin extends(a||b){}class seq extends(a,b){}class ter extends(a?b:c){}class uni extends(!0){}}" } class_extends_class: { options = { } input: { class anon extends class {} {} class named extends class base {} {} } expect_exact: "class anon extends class{}{}class named extends class base{}{}" } class_extends_function: { options = { } input: { class anon extends function(){} {} class named extends function base(){} {} } expect_exact: "class anon extends function(){}{}class named extends function base(){}{}" } class_extends_regex: { options = { } input: { function f() { class rx1 extends (/rx/) {} // class rx2 extends /rx/ {} // FIXME - parse error } } expect_exact: "function f(){class rx1 extends(/rx/){}}" } issue_2028: { options = { side_effects: true, } input: { var a = {}; (function(x) { x.X = function() { return X; }; class X { static hello() { console.log("hello"); } } }(a)); a.X().hello(); } expect: { var a = {}; (function(x) { x.X = function() { return X; }; class X { static hello() { console.log("hello"); } } }(a)); a.X().hello(); } expect_stdout: "hello" } class_expression_statement: { options = { toplevel: false, side_effects: false, unused: false, } input: { (class {}); (class NamedClassExpr {}); let expr = (class AnotherClassExpr {}); class C {} } expect_exact: "(class{});(class NamedClassExpr{});let expr=class AnotherClassExpr{};class C{}" } class_expression_statement_unused: { options = { toplevel: false, side_effects: true, unused: true, } input: { (class {}); (class NamedClassExpr {}); let expr = (class AnotherClassExpr {}); class C {} } expect_exact: "let expr=class{};class C{}" } class_expression_statement_unused_toplevel: { options = { toplevel: true, side_effects: true, unused: true, } input: { (class {}); (class NamedClassExpr {}); let expr = (class AnotherClassExpr {}); class C {} } expect_exact: "" } export_default_function_decl: { options = { toplevel: true, passes: 3, unused: true, } input: { // do not drop "unused" exports export default function Foo() {}; export function Far() {}; } expect_exact: "export default function Foo(){}export function Far(){}" } export_default_class_decl: { options = { toplevel: true, passes: 3, unused: true, } input: { // do not drop "unused" exports export default class Car {}; export class Cab {}; } expect_exact: "export default class Car{}export class Cab{}" } object_rest_spread: { mangle = { toplevel: true, } input: { var { w: w1, ...V } = { w: 7, x: 1, y: 2 }; console.log(w1, V); let { w: w2, ...L } = { w: 8, x: 3, y: 4 }; console.log(w2, L); const { w: w3, ...C } = { w: 9, x: 5, y: 6 }; console.log(w3, C); let b; ({ b, ...V } = { a: 1, b: 2, c: 3 }); console.log(V); ({ b, ...L } = { a: 4, b: 5, c: 6 }); console.log(L); (function({ y, ...p }){ console.log(p); })({ x: 1, y: 2, z: 3 }); (({ y, ...p }) => { console.log(p); })({ x: 4, y: 5, z: 6 }); const T = { a: 1, b: 2 }; console.log({ ...T, w: 0, ...{}, ...L, ...{K: 9} }); } expect: { var { w: o, ...l } = { w: 7, x: 1, y: 2 }; console.log(o, l); let { w: c, ...n } = { w: 8, x: 3, y: 4 }; console.log(c, n); const { w: e, ...s } = { w: 9, x: 5, y: 6 }; console.log(e, s); let g; ({ b: g, ...l } = { a: 1, b: 2, c: 3 }); console.log(l); ({ b: g, ...n } = { a: 4, b: 5, c: 6 }); console.log(n); (function({ y: o, ...l }) { console.log(l); })({ x: 1, y: 2, z: 3 }); (({ y: o, ...l }) => { console.log(l); })({ x: 4, y: 5, z: 6 }); const w = { a: 1, b: 2 }; console.log({ ...w, w: 0, ...n, K: 9 }); } } object_spread_unsafe: { options = { collapse_vars: true, evaluate: true, join_vars: true, passes: 3, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unsafe: true, unused: true, } mangle = { toplevel: true, } input: { var o1 = { x: 1, y: 2 }; var o2 = { x: 3, z: 4 }; var cloned = { ...o1 }; var merged = { ...o1, ...o2 }; console.log(cloned, merged); } expect: { var o = { x: 1, y: 2 }, l = { ...o }, x = { ...o, x: 3, z: 4 }; console.log(l, x); } } array_spread_of_sequence: { mangle = { toplevel: true, } input: { var a = [1]; console.log([...(a, a)]); console.log([...a, a]); console.log([...(a || a)]); console.log([...a || a]); } expect: { var o = [1]; console.log([...(o, o)]); console.log([...o, o]); console.log([...o || o]); console.log([...o || o]); } expect_stdout: [ "[ 1 ]", "[ 1, [ 1 ] ]", "[ 1 ]", "[ 1 ]", ] } object_spread_of_sequence: { mangle = { toplevel: true, } input: { var a = {x: 1}; console.log({ ...(a, a) }); console.log({ ...a, a }); console.log({ ...(a || a) }); console.log({ ...a || a }); } expect: { var o = { x: 1 }; console.log({ ...(o, o) }); console.log({ ...o, a: o }); console.log({ ...o || o }); console.log({ ...o || o }); } } // issue 2316 class_name_can_be_preserved_with_reserved: { mangle = { reserved: [ "Foo" ], } input: { function x() { class Foo {} Foo.bar; class Bar {} Bar.foo; } function y() { var Foo = class Foo {}; Foo.bar; var Bar = class Bar {}; Bar.bar; } } expect: { function x() { class Foo {} Foo.bar; class a {} a.foo; } function y() { var Foo = class Foo {}; Foo.bar; var a = class a {}; a.bar; } } } issue_2345: { options = { evaluate: true, side_effects: true, unsafe: true, unused: true, } input: { console.log([...[3, 2, 1]].join("-")); var a = [3, 2, 1]; console.log([...a].join("-")); } expect: { console.log("3-2-1"); var a = [3, 2, 1]; console.log([...a].join("-")); } expect_stdout: [ "3-2-1", "3-2-1", ] } issue_2349: { mangle = {} input: { function foo(boo, key) { const value = boo.get(); return value.map(({[key]: bar}) => bar); } console.log(foo({ get: () => [ { blah: 42 } ] }, "blah")); } expect: { function foo(o, n) { const t = o.get(); return t.map(({[n]: o}) => o); } console.log(foo({ get: () => [ { blah: 42 } ] }, "blah")); } expect_stdout: [ "[ 42 ]", ] node_version: ">=7" } issue_2349b: { options = { arrows: true, collapse_vars: true, ecma: 6, evaluate: true, inline: true, passes: 3, properties: true, reduce_funcs: true, reduce_vars: true, toplevel: true, side_effects: true, unsafe_arrows: true, unused: true, } mangle = { toplevel: true, } input: { function foo(boo, key) { const value = boo.get(); return value.map(function({[key]: bar}){ return bar; }); } console.log(foo({ get: function() { return [ { blah: 42 } ]; } }, "blah")); } expect: { console.log([ { blah: 42 } ].map(({["blah"]: l}) => l)); } expect_stdout: [ "[ 42 ]", ] node_version: ">=7" } shorthand_keywords: { beautify = { ecma: 6, } input: { var foo = 0, async = 1, await = 2, implements = 3, package = 4, private = 5, protected = 6, static = 7, yield = 8; console.log({ foo: foo, 0: 0, NaN: NaN, async: async, await: await, false: false, implements: implements, null: null, package: package, private: private, protected: protected, static: static, this: this, true: true, undefined: undefined, yield: yield, }); } expect_exact: "var foo=0,async=1,await=2,implements=3,package=4,private=5,protected=6,static=7,yield=8;console.log({foo,0:0,NaN:NaN,async,await,false:false,implements:implements,null:null,package:package,private:private,protected:protected,static:static,this:this,true:true,undefined:void 0,yield});" expect_stdout: true } array_literal_with_spread_1: { options = { properties: true, side_effects: true, } input: { var f = (x) => [...x][0]; console.log(f(["PASS"])); } expect: { var f = x => [ ...x ][0]; console.log(f([ "PASS" ])); } expect_stdout: "PASS" } array_literal_with_spread_2a: { options = { properties: true, side_effects: true, } input: { console.log([10, ...[], 20, ...[30, 40], 50]["length"]); console.log([10, ...[], 20, ...[30, 40], 50][0]); console.log([10, ...[], 20, ...[30, 40], 50][1]); console.log([10, ...[], 20, ...[30, 40], 50][2]); console.log([10, ...[], 20, ...[30, 40], 50][3]); console.log([10, ...[], 20, ...[30, 40], 50][4]); console.log([10, ...[], 20, ...[30, 40], 50][5]); } expect: { console.log([ 10, 20, 30, 40, 50 ]["length"]); console.log(10); console.log(20); console.log(30); console.log(40); console.log(50); console.log([ 10, 20, 30, 40, 50 ][5]); } expect_stdout: [ "5", "10", "20", "30", "40", "50", "undefined", ] } array_literal_with_spread_2b: { options = { properties: true, side_effects: true, } input: { var x = [30, 40]; console.log([10, ...[], 20, ...x, 50]["length"]); console.log([10, ...[], 20, ...x, 50][0]); console.log([10, ...[], 20, ...x, 50][1]); console.log([10, ...[], 20, ...x, 50][2]); console.log([10, ...[], 20, ...x, 50][3]); console.log([10, ...[], 20, ...x, 50][4]); console.log([10, ...[], 20, ...x, 50][5]); } expect: { var x = [30, 40]; console.log([ 10, 20, ...x, 50 ]["length"]); console.log(10); console.log(20); console.log([ 10, 20, ...x, 50 ][2]); console.log([ 10, 20, ...x, 50 ][3]); console.log([ 10, 20, ...x, 50 ][4]); console.log([ 10, 20, ...x, 50 ][5]); } expect_stdout: [ "5", "10", "20", "30", "40", "50", "undefined", ] } array_literal_with_spread_3a: { options = { properties: true, side_effects: true, } input: { console.log([10, 20][0]); console.log([10, 20][1]); console.log([10, 20][2]); console.log([...[], 10, 20][0]); console.log([...[], 10, 20][1]); console.log([...[], 10, 20][2]); console.log([10, ...[], 20][0]); console.log([10, ...[], 20][1]); console.log([10, ...[], 20][2]); console.log([10, 20, ...[]][0]); console.log([10, 20, ...[]][1]); console.log([10, 20, ...[]][2]); } expect: { console.log(10); console.log(20); console.log([ 10, 20 ][2]); console.log(10); console.log(20); console.log([10, 20][2]); console.log(10); console.log(20); console.log([10, 20][2]); console.log(10); console.log(20); console.log([10, 20][2]); } expect_stdout: [ "10", "20", "undefined", "10", "20", "undefined", "10", "20", "undefined", "10", "20", "undefined", ] } array_literal_with_spread_3b: { options = { properties: true, side_effects: true, } input: { var nothing = []; console.log([10, 20][0]); console.log([10, 20][1]); console.log([10, 20][2]); console.log([...nothing, 10, 20][0]); console.log([...nothing, 10, 20][1]); console.log([...nothing, 10, 20][2]); console.log([10, ...nothing, 20][0]); console.log([10, ...nothing, 20][1]); console.log([10, ...nothing, 20][2]); console.log([10, 20, ...nothing][0]); console.log([10, 20, ...nothing][1]); console.log([10, 20, ...nothing][2]); } expect: { var nothing = []; console.log(10); console.log(20); console.log([ 10, 20 ][2]); console.log([...nothing, 10, 20][0]); console.log([...nothing, 10, 20][1]); console.log([...nothing, 10, 20][2]); console.log(10); console.log([10, ...nothing, 20][1]); console.log([10, ...nothing, 20][2]); console.log(10); console.log(20); console.log([10, 20, ...nothing][2]); } expect_stdout: [ "10", "20", "undefined", "10", "20", "undefined", "10", "20", "undefined", "10", "20", "undefined", ] } array_literal_with_spread_4a: { options = { properties: true, side_effects: true, } input: { function t(x) { console.log("(" + x + ")"); return 10 * x; } console.log([t(1), t(2)][0]); console.log([t(1), t(2)][1]); console.log([t(1), t(2)][2]); console.log([...[], t(1), t(2)][0]); console.log([...[], t(1), t(2)][1]); console.log([...[], t(1), t(2)][2]); console.log([t(1), ...[], t(2)][0]); console.log([t(1), ...[], t(2)][1]); console.log([t(1), ...[], t(2)][2]); console.log([t(1), t(2), ...[]][0]); console.log([t(1), t(2), ...[]][1]); console.log([t(1), t(2), ...[]][2]); } expect: { function t(x) { console.log("(" + x + ")"); return 10 * x; } console.log([ t(1), t(2) ][0]); console.log((t(1), t(2))); console.log([ t(1), t(2) ][2]); console.log([ t(1), t(2) ][0]); console.log((t(1), t(2))); console.log([ t(1), t(2) ][2]); console.log([ t(1), t(2) ][0]); console.log((t(1), t(2))); console.log([ t(1), t(2) ][2]); console.log([ t(1), t(2) ][0]); console.log((t(1), t(2))); console.log([ t(1), t(2) ][2]); } expect_stdout: [ "(1)", "(2)", "10", "(1)", "(2)", "20", "(1)", "(2)", "undefined", "(1)", "(2)", "10", "(1)", "(2)", "20", "(1)", "(2)", "undefined", "(1)", "(2)", "10", "(1)", "(2)", "20", "(1)", "(2)", "undefined", "(1)", "(2)", "10", "(1)", "(2)", "20", "(1)", "(2)", "undefined", ] } array_literal_with_spread_4b: { options = { properties: true, side_effects: true, } input: { var nothing = []; function t(x) { console.log("(" + x + ")"); return 10 * x; } console.log([t(1), t(2)][0]); console.log([t(1), t(2)][1]); console.log([t(1), t(2)][2]); console.log([...nothing, t(1), t(2)][0]); console.log([...nothing, t(1), t(2)][1]); console.log([...nothing, t(1), t(2)][2]); console.log([t(1), ...nothing, t(2)][0]); console.log([t(1), ...nothing, t(2)][1]); console.log([t(1), ...nothing, t(2)][2]); console.log([t(1), t(2), ...nothing][0]); console.log([t(1), t(2), ...nothing][1]); console.log([t(1), t(2), ...nothing][2]); } expect: { var nothing = []; function t(x) { console.log("(" + x + ")"); return 10 * x; } console.log([ t(1), t(2) ][0]); console.log((t(1), t(2))); console.log([ t(1), t(2) ][2]); console.log([ ...nothing, t(1), t(2) ][0]); console.log([ ...nothing, t(1), t(2) ][1]); console.log([ ...nothing, t(1), t(2) ][2]); console.log([ t(1), t(2) ][0]); console.log([ t(1), ...nothing, t(2) ][1]); console.log([ t(1), ...nothing, t(2) ][2]); console.log([ t(1), t(2) ][0]); console.log((t(1), t(2))); console.log([ t(1), t(2), ...nothing ][2]); } expect_stdout: [ "(1)", "(2)", "10", "(1)", "(2)", "20", "(1)", "(2)", "undefined", "(1)", "(2)", "10", "(1)", "(2)", "20", "(1)", "(2)", "undefined", "(1)", "(2)", "10", "(1)", "(2)", "20", "(1)", "(2)", "undefined", "(1)", "(2)", "10", "(1)", "(2)", "20", "(1)", "(2)", "undefined", ] } object_literal_method_using_arguments: { options = { arrows: true, } input: { console.log(({ m() { return arguments[0]; } }).m("PASS")); } expect: { console.log(({ m() { return arguments[0]; } }).m("PASS")); } expect_stdout: "PASS" } class_method_using_arguments: { options = { arrows: true, } input: { console.log(new class { m() { return arguments[0]; } }().m("PASS")); } expect: { console.log(new class { m() { return arguments[0]; } }().m("PASS")); } expect_stdout: "PASS" } issue_2676: { options = { reduce_vars: true, toplevel: true, unused: true, } input: { class A {} A.a = 42; } expect: { (class {}).a = 42; } } issue_2762: { mangle = {} input: { var bar = 1, T = true; (function() { if (T) { const a = function() { var foo = bar; console.log(foo, a.prop, b.prop); }; a.prop = 2; const b = { prop: 3 }; a(); } })(); } expect: { var bar = 1, T = true; (function() { if (T) { const o = function() { var p = bar; console.log(p, o.prop, r.prop); }; o.prop = 2; const r = { prop: 3 }; o(); } })(); } expect_stdout: "1 2 3" } issue_2794_1: { options = { collapse_vars: true, evaluate: true, inline: true, passes: 1, properties: true, reduce_funcs: true, reduce_vars: true, toplevel: false, side_effects: true, unused: true, } input: { function foo() { for (const a of func(value)) { console.log(a); } function func(va) { return doSomething(va); } } function doSomething(x) { return [ x, 2 * x, 3 * x ]; } const value = 10; foo(); } expect: { function foo() { for (const a of doSomething(value)) console.log(a); } function doSomething(x) { return [ x, 2 * x, 3 * x ]; } const value = 10; foo(); } expect_stdout: [ "10", "20", "30", ] } issue_2794_2: { mangle = { toplevel: false, } options = { collapse_vars: true, evaluate: true, inline: true, passes: 1, properties: true, reduce_funcs: true, reduce_vars: true, toplevel: false, side_effects: true, unused: true, } input: { function foo() { for (const a of func(value)) { console.log(a); } function func(va) { return doSomething(va); } } function doSomething(x) { return [ x, 2 * x, 3 * x ]; } const value = 10; foo(); } expect: { function foo() { for (const o of doSomething(value)) console.log(o); } function doSomething(o) { return [ o, 2 * o, 3 * o ]; } const value = 10; foo(); } expect_stdout: [ "10", "20", "30", ] } issue_2794_3: { mangle = { toplevel: true, } options = { collapse_vars: true, evaluate: true, inline: 3, passes: 3, properties: true, reduce_funcs: true, reduce_vars: true, toplevel: true, side_effects: true, unused: true, } input: { function foo() { for (const a of func(value)) { console.log(a); } function func(va) { return doSomething(va); } } function doSomething(x) { return [ x, 2 * x, 3 * x ]; } const value = 10; foo(); } expect: { (function() { for (const o of [ 10, 20, 30 ]) console.log(o); })(); } expect_stdout: [ "10", "20", "30", ] } issue_2794_4: { options = {} input: { for (var x of ([1, 2], [3, 4])) { console.log(x); } } expect_exact: "for(var x of([1,2],[3,4]))console.log(x);" expect_stdout: [ "3", "4", ] } issue_2794_5: { mangle = {} options = { evaluate: true, passes: 1, side_effects: true, unused: true, } input: { for (var x of ([1, 2], [3, 4])) { console.log(x); } } expect_exact: "for(var x of[3,4])console.log(x);" expect_stdout: [ "3", "4", ] } issue_2794_6: { options = { } input: { // TODO (or not): have parser flag invalid for-of expression. // Consider it an uglify extension in the meantime. for (let e of [1,2], [3,4,5]) { console.log(e); } } expect_exact: "for(let e of([1,2],[3,4,5]))console.log(e);" expect_stdout: [ "3", "4", "5", ] } inline_arrow_using_arguments: { options = { evaluate: true, inline: 1, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { (function(){ ((x) => { console.log.apply(console, arguments), console.log(x); })(4); })(3, 2, 1); } expect: { (function(){ console.log.apply(console, arguments), console.log(4); })(3, 2, 1); } expect_stdout: [ "3 2 1", "4", ] } issue_2874_1: { options = { collapse_vars: true, evaluate: true, inline: 3, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { (function() { function foo() { let letters = ["A", "B", "C"]; let result = [2, 1, 0].map(key => bar(letters[key] + key)); return result; } function bar(value) { return () => console.log(value); } foo().map(fn => fn()); })(); } expect: { (function () { let letters = ["A", "B", "C"]; return [2, 1, 0].map(key => (function (value) { return () => console.log(value); })(letters[key] + key)); })().map(fn => fn()); } expect_stdout: [ "C2", "B1", "A0", ] } issue_2874_2: { options = { collapse_vars: true, evaluate: true, inline: 3, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { (function() { let keys = []; function foo() { var result = [2, 1, 0].map(value => { keys.push(value); return bar(); }); return result; } function bar() { var letters = ["A", "B", "C"], key = keys.shift(); return () => console.log(letters[key] + key); } foo().map(fn => fn()); })(); } expect: { (function() { let keys = []; [ 2, 1, 0 ].map(value => { return keys.push(value), function() { var letters = [ "A", "B", "C" ], key = keys.shift(); return () => console.log(letters[key] + key); }(); }).map(fn => fn()); })(); } expect_stdout: [ "C2", "B1", "A0", ] } issue_2874_3: { options = { collapse_vars: true, evaluate: true, inline: 3, reduce_funcs: false, reduce_vars: true, sequences: true, side_effects: true, toplevel: true, unused: true, } input: { function f() { return x + y; } let x, y; let a = (z) => { x = "A"; y = z; console.log(f()); } a(1); a(2); } expect: { let x, y; let a = z => { x = "A", y = z, console.log(x + y); }; a(1), a(2); } expect_stdout: [ "A1", "A2", ] } issue_3061: { options = { collapse_vars: true, evaluate: true, inline: 3, reduce_funcs: false, reduce_vars: true, side_effects: true, unused: true, } input: { console.log(new class extends(function(base) { return class extends base {}; }(Error)){}() instanceof Error); } expect: { console.log(new class extends(function(base) { return class extends base {}; }(Error)){}() instanceof Error); } expect_stdout: "true" } module_enables_strict_mode: { options = { module: true, } input: { if (1) { function xyz() {} } } expect: { if (1) { function xyz() {} } } } module_mangle_scope: { mangle = { module: true } input: { let a = 10; } expect: { let e = 10; } } module_enabled: { options = { module: true, reduce_vars: true, unused: true, } mangle = { module: true, } input: { let apple = 10, b = 20; console.log(apple++, b, apple++); export { apple }; } expect: { let o = 10; console.log(o++, 20, o++); export { o as apple }; } } issue_3028: { options = { collapse_vars: true, evaluate: true, side_effects: true, unused: true, } input: { function a(array) { var shifted = array.splice(0, 2); return [ ...array, ...shifted ]; } console.log(a([ 1, 2, 3 ]).join(" ")); } expect: { function a(array) { var shifted = array.splice(0, 2); return [ ...array, ...shifted ]; } console.log(a([ 1, 2, 3 ]).join(" ")); } expect_stdout: "3 1 2" } issue_t80: { options = { unused: true, } input: { function foo(data = []) { var u, v = "unused"; if (arguments.length == 1) { data = [data]; } return data; } console.log(JSON.stringify([foo(), foo(null), foo(5, 6)])); } expect: { function foo(data = []) { if (1 == arguments.length) data = [data]; return data; } console.log(JSON.stringify([foo(), foo(null), foo(5, 6)])); } expect_stdout: "[[],[null],5]" } terser-4.1.2/test/compress/hoist.js000066400000000000000000000030201351061312300173060ustar00rootroot00000000000000 hoist_vars: { options = { hoist_vars: true } input: { function a() { bar(); var var1; var var2; } function b(anArg) { bar(); var var1; var anArg; } } expect: { function a() { var var1, var2; // Vars go up and are joined bar(); } function b(anArg) { var var1; bar(); // But vars named like arguments go away! } } } hoist_funs: { options = { hoist_funs: true } input: { function a() { bar(); function foo() {} } } expect: { function a() { function foo() {} // Funs go up bar(); } } } hoist_no_destructurings: { options = { hoist_vars: true, hoist_funs: true } input: { function a([anArg]) { bar(); var var1; var anArg; // Because anArg is already declared, this goes away! } } expect: { function a([anArg]) { var var1; bar(); } } } dont_hoist_var_destructurings: { options = { hoist_vars: true, hoist_funs: true } input: { function x() { // If foo is null or undefined, this should be an exception var {x,y} = foo; } } expect: { function x() { var {x,y} = foo; } } } terser-4.1.2/test/compress/hoist_props.js000066400000000000000000000516141351061312300205450ustar00rootroot00000000000000issue_2377_1: { options = { evaluate: true, hoist_props: true, inline: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var obj = { foo: 1, bar: 2, square: function(x) { return x * x; }, cube: function(x) { return x * x * x; }, }; console.log(obj.foo, obj.cube(3)); } expect: { var obj_foo = 1, obj_cube = function(x) { return x * x * x; }; console.log(obj_foo, obj_cube(3)); } expect_stdout: "1 27" } issue_2377_2: { options = { evaluate: true, hoist_props: true, inline: true, passes: 2, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var obj = { foo: 1, bar: 2, square: function(x) { return x * x; }, cube: function(x) { return x * x * x; }, }; console.log(obj.foo, obj.cube(3)); } expect: { console.log(1, (x = 3, x * x * x)); var x; } expect_stdout: "1 27" } issue_2377_3: { options = { evaluate: true, hoist_props: true, inline: true, passes: 4, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { var obj = { foo: 1, bar: 2, square: function(x) { return x * x; }, cube: function(x) { return x * x * x; }, }; console.log(obj.foo, obj.cube(3)); } expect: { console.log(1, 27); } expect_stdout: "1 27" } direct_access_1: { options = { hoist_props: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var a = 0; var obj = { a: 1, b: 2, }; for (var k in obj) a++; console.log(a, obj.a); } expect: { var a = 0; var obj = { a: 1, b: 2, }; for (var k in obj) a++; console.log(a, obj.a); } expect_stdout: "2 1" } direct_access_2: { options = { hoist_props: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var o = { a: 1 }; var f = function(k) { if (o[k]) return "PASS"; }; console.log(f("a")); } expect: { var o = { a: 1 }; console.log(function(k) { if (o[k]) return "PASS"; }("a")); } expect_stdout: "PASS" } direct_access_3: { options = { hoist_props: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var o = { a: 1 }; o.b; console.log(o.a); } expect: { var o = { a: 1 }; o.b; console.log(o.a); } expect_stdout: "1" } single_use: { options = { hoist_props: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var obj = { bar: function() { return 42; }, }; console.log(obj.bar()); } expect: { console.log({ bar: function() { return 42; }, }.bar()); } } name_collision_1: { options = { hoist_props: true, reduce_funcs: true, reduce_vars: true, toplevel: true, } input: { var obj_foo = 1; var obj_bar = 2; function f() { var obj = { foo: 3, bar: 4, "b-r": 5, "b+r": 6, "b!r": 7, }; console.log(obj_foo, obj.foo, obj.bar, obj["b-r"], obj["b+r"], obj["b!r"]); } f(); } expect: { var obj_foo = 1; var obj_bar = 2; function f() { var obj_foo$0 = 3, obj_bar$0 = 4, obj_b_r = 5, obj_b_r$0 = 6, obj_b_r$1 = 7; console.log(obj_foo, obj_foo$0, obj_bar$0, obj_b_r, obj_b_r$0, obj_b_r$1); } f(); } expect_stdout: "1 3 4 5 6 7" } name_collision_2: { options = { hoist_props: true, reduce_funcs: true, reduce_vars: true, toplevel: true, } input: { var o = { p: 1, "+": function(x) { return x; }, "-": function(x) { return x + 1; } }, o__$0 = 2, o__$1 = 3; console.log(o.p === o.p, o["+"](4), o["-"](5), o__$0, o__$1); } expect: { var o_p = 1, o__ = function(x) { return x; }, o__$2 = function(x) { return x + 1; }, o__$0 = 2, o__$1 = 3; console.log(o_p === o_p, o__(4), o__$2(5), o__$0, o__$1); } expect_stdout: "true 4 6 2 3" } name_collision_3: { options = { hoist_props: true, reduce_funcs: true, reduce_vars: true, toplevel: true, } input: { var o = { p: 1, "+": function(x) { return x; }, "-": function(x) { return x + 1; } }, o__$0 = 2, o__$1 = 3; console.log(o.p === o.p, o["+"](4), o["-"](5)); } expect: { var o_p = 1, o__ = function(x) { return x; }, o__$2 = function(x) { return x + 1; }, o__$0 = 2, o__$1 = 3; console.log(o_p === o_p, o__(4), o__$2(5)); } expect_stdout: "true 4 6" } contains_this_1: { options = { evaluate: true, hoist_props: true, inline: true, passes: 2, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var o = { u: function() { return this === this; }, p: 1 }; console.log(o.p, o.p); } expect: { console.log(1, 1); } expect_stdout: "1 1" } contains_this_2: { options = { evaluate: true, hoist_props: true, inline: true, passes: 2, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var o = { u: function() { return this === this; }, p: 1 }; console.log(o.p, o.p, o.u); } expect: { console.log(1, 1, function() { return this === this; }); } expect_stdout: true } contains_this_3: { options = { evaluate: true, hoist_props: true, inline: true, passes: 2, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var o = { u: function() { return this === this; }, p: 1 }; console.log(o.p, o.p, o.u()); } expect: { var o = { u: function() { return this === this; }, p: 1 }; console.log(o.p, o.p, o.u()); } expect_stdout: "1 1 true" } hoist_class: { options = { comparisons: true, evaluate: true, hoist_props: true, inline: true, keep_classnames: true, keep_fnames: true, passes: 2, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function run(c, v) { return new c(v).value; } var o = { p: class Foo { constructor(value) { this.value = value * 10; } }, x: 1, y: 2, }; console.log(o.p.name, o.p === o.p, run(o.p, o.x), run(o.p, o.y)); } expect: { function run(c, v) { return new c(v).value; } var o_p = class Foo { constructor(value) { this.value = 10 * value; } }; console.log(o_p.name, true, run(o_p, 1), run(o_p, 2)); } expect_stdout: "Foo true 10 20" } hoist_class_with_new: { options = { comparisons: true, evaluate: true, hoist_props: true, inline: true, keep_classnames: true, keep_fnames: true, passes: 2, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var o = { p: class Foo { constructor(value) { this.value = value * 10; } }, x: 1, y: 2, }; console.log(o.p.name, o.p === o.p, new o.p(o.x).value, new o.p(o.y).value); } expect: { var o_p = class Foo { constructor(value) { this.value = 10 * value; } }; console.log(o_p.name, true, new o_p(1).value, new o_p(2).value); } expect_stdout: "Foo true 10 20" } hoist_function_with_call: { options = { comparisons: true, evaluate: true, hoist_props: true, inline: true, keep_fnames: true, passes: 2, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var o = { p: function Foo(value) { return 10 * value; }, x: 1, y: 2 }; console.log(o.p.name, o.p === o.p, o.p(o.x), o.p(o.y)); } expect: { var o = { p: function Foo(value) { return 10 * value; }, x: 1, y: 2 }; console.log(o.p.name, o.p == o.p, o.p(o.x), o.p(o.y)); } expect_stdout: "Foo true 10 20" } new_this: { options = { evaluate: true, hoist_props: true, inline: true, passes: 2, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var o = { a: 1, b: 2, f: function(a) { this.b = a; } }; console.log(new o.f(o.a).b, o.b); } expect: { console.log(new function(a) { this.b = a; }(1).b, 2); } expect_stdout: "1 2" } issue_2462: { options = { hoist_props: true, reduce_funcs: true, reduce_vars: true, } input: { export const Foo = { a: 1, b: () => 2 }; } expect: { export const Foo = { a: 1, b: () => 2 }; } } issue_2473_1: { options = { hoist_props: false, reduce_vars: true, top_retain: [ "x", "y" ], toplevel: true, unused: true, } input: { var x = {}; var y = []; var z = {}; } expect: { var x = {}; var y = []; } } issue_2473_2: { options = { hoist_props: true, reduce_vars: true, top_retain: [ "x", "y" ], toplevel: true, unused: true, } input: { var x = {}; var y = []; var z = {}; } expect: { var x = {}; var y = []; } } issue_2473_3: { options = { hoist_props: true, reduce_vars: true, top_retain: "o", toplevel: true, unused: true, } input: { var o = { a: 1, b: 2, }; console.log(o.a, o.b); } expect: { var o = { a: 1, b: 2, }; console.log(o.a, o.b); } expect_stdout: "1 2" } issue_2473_4: { options = { hoist_props: true, reduce_vars: true, top_retain: "o", toplevel: true, unused: true, } input: { (function() { var o = { a: 1, b: 2, }; console.log(o.a, o.b); })(); } expect: { (function() { var o_a = 1, o_b = 2; console.log(o_a, o_b); })(); } expect_stdout: "1 2" } issue_2508_1: { options = { collapse_vars: true, hoist_props: true, reduce_vars: true, toplevel: true, unused: true, } input: { var o = { a: [ 1 ], f: function(x) { console.log(x); } }; o.f(o.a); } expect: { (function(x) { console.log(x); })([ 1 ]); } expect_stdout: true } issue_2508_2: { options = { collapse_vars: true, hoist_props: true, reduce_vars: true, toplevel: true, unused: true, } input: { var o = { a: { b: 2 }, f: function(x) { console.log(x); } }; o.f(o.a); } expect: { (function(x) { console.log(x); })({ b: 2 }); } expect_stdout: true } issue_2508_3: { options = { collapse_vars: true, hoist_props: true, reduce_vars: true, toplevel: true, unused: true, } input: { var o = { a: [ o ], f: function(x) { console.log(x); } }; o.f(o.a); } expect: { var o = { a: [ o ], f: function(x) { console.log(x); } }; o.f(o.a); } expect_stdout: true } issue_2508_4: { options = { collapse_vars: true, hoist_props: true, reduce_vars: true, toplevel: true, unused: true, } input: { var o = { a: { b: o }, f: function(x) { console.log(x); } }; o.f(o.a); } expect: { var o = { a: { b: o }, f: function(x) { console.log(x); } }; o.f(o.a); } expect_stdout: true } issue_2508_5: { options = { collapse_vars: true, hoist_props: true, reduce_vars: true, toplevel: true, unused: true, } input: { var o = { f: function(x) { console.log(x); } }; o.f(o.f); } expect: { var o_f = function(x) { console.log(x); }; o_f(o_f); } expect_stdout: true } issue_2508_6: { options = { collapse_vars: true, hoist_props: true, reduce_vars: true, toplevel: true, unused: true, } input: { var o = { f: x => { console.log(x); } }; o.f(o.f); } expect: { var o_f = x => { console.log(x); }; o_f(o_f); } expect_stdout: true } issue_2519: { options = { collapse_vars: true, evaluate: true, hoist_props: true, reduce_vars: true, unused: true, } input: { function testFunc() { var dimensions = { minX: 5, maxX: 6, }; var scale = 1; var d = { x: (dimensions.maxX + dimensions.minX) / 2, }; return d.x * scale; } console.log(testFunc()); } expect: { function testFunc() { return 1 * ((6 + 5) / 2); } console.log(testFunc()); } expect_stdout: "5.5" } toplevel_const: { options = { hoist_props: true, reduce_vars: true, toplevel: false, } input: { const a = { b: 1, c: 2 }; console.log(a.b + a.c); } expect: { const a = { b: 1, c: 2 }; console.log(a.b + a.c); } expect_stdout: "3" } toplevel_let: { options = { hoist_props: true, reduce_vars: true, toplevel: false, } input: { let a = { b: 1, c: 2 }; console.log(a.b + a.c); } expect: { let a = { b: 1, c: 2 }; console.log(a.b + a.c); } expect_stdout: "3" } toplevel_var: { options = { hoist_props: true, reduce_vars: true, toplevel: false, } input: { var a = { b: 1, c: 2 }; console.log(a.b + a.c); } expect: { var a = { b: 1, c: 2 }; console.log(a.b + a.c); } expect_stdout: "3" } undefined_key: { options = { evaluate: true, hoist_props: true, join_vars: true, passes: 4, reduce_vars: true, toplevel: true, unused: true, } input: { var a, o = {}; o[a] = 1; o.b = 2; console.log(o[a] + o.b); } expect: { console.log(3); } expect_stdout: "3" } issue_3021: { options = { hoist_props: true, reduce_vars: true, } input: { var a = 1, b = 2; (function() { b = a; if (a++ + b--) return 1; return; var b = {}; })(); console.log(a, b); } expect: { var a = 1, b = 2; (function() { b = a; if (a++ + b--) return 1; return; var b = {}; })(); console.log(a, b); } expect_stdout: "2 2" } issue_3046: { options = { hoist_props: true, reduce_vars: true, } input: { console.log(function(a) { do { var b = { c: a++ }; } while (b.c && a); return a; }(0)); } expect: { // NOTE: differs from uglify-js, but produces correct result console.log(function(a) { do { var b = { c: a++ }; } while (b.c && a); return a; }(0)); } expect_stdout: "1" } issue_3071_1: { options = { evaluate: true, hoist_props: true, inline: true, join_vars: true, passes: 3, reduce_vars: true, sequences: true, side_effects: true, toplevel: true, unused: true, } input: { (function() { var obj = {}; obj.one = 1; obj.two = 2; console.log(obj.one); })(); } expect_stdout: "1" } issue_3071_2: { options = { evaluate: true, hoist_props: true, inline: true, join_vars: true, passes: 3, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { (function() { obj = {}; obj.one = 1; obj.two = 2; console.log(obj.one); var obj; })(); } expect_stdout: "1" } issue_3071_2_toplevel: { options = { evaluate: true, hoist_props: true, inline: true, join_vars: true, passes: 3, reduce_vars: true, sequences: true, side_effects: true, toplevel: true, unused: true, } input: { (function() { obj = {}; obj.one = 1; obj.two = 2; console.log(obj.one); var obj; })(); } expect_stdout: "1" } issue_3071_3: { options = { hoist_props: true, reduce_vars: true, } input: { var c = 0; (function(a, b) { (function f(o) { var n = 2; while (--b + (o = { p: c++, }) && --n > 0); })(); })(); console.log(c); } expect: { var c = 0; (function(a, b) { (function f(o) { var n = 2; while (--b + (o = { p: c++, }) && --n > 0); })(); })(); console.log(c); } expect_stdout: "2" } terser-4.1.2/test/compress/hoist_vars.js000066400000000000000000000042301351061312300203450ustar00rootroot00000000000000statements: { 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; } } } regression_toplevel_args: { options = { hoist_vars: true } input: { var Foo; var Bar; } expect: { var Foo, Bar; } } terser-4.1.2/test/compress/html_comments.js000066400000000000000000000027421351061312300210430ustar00rootroot00000000000000html_comment_in_expression: { input: { function f(a, b, x, y) { return a < !--b && x-- > y; } } expect_exact: "function f(a,b,x,y){return a< !--b&&x-- >y}"; } html_comment_in_less_than: { input: { function f(a, b) { return a < !--b; } } expect_exact: "function f(a,b){return a< !--b}"; } html_comment_in_left_shift: { input: { function f(a, b) { return a << !--b; } } expect_exact: "function f(a,b){return a<< !--b}"; } html_comment_in_right_shift: { input: { function f(a, b) { return a-- >> b; } } expect_exact: "function f(a,b){return a-- >>b}"; } html_comment_in_zero_fill_right_shift: { input: { function f(a, b) { return a-- >>> b; } } expect_exact: "function f(a,b){return a-- >>>b}"; } html_comment_in_greater_than: { input: { function f(a, b) { return a-- > b; } } expect_exact: "function f(a,b){return a-- >b}"; } html_comment_in_greater_than_or_equal: { input: { function f(a, b) { return a-- >= b; } } expect_exact: "function f(a,b){return a-- >=b}"; } html_comment_in_string_literal: { input: { function f() { return "comment in"; } } expect_exact: 'function f(){return"\\x3c!--HTML--\\x3ecomment in\\x3c!--string literal--\\x3e"}'; } html_comment_after_multiline_comment: { input: { var foo; /* */--> var bar; var foobar; } expect_exact: "var foo;var foobar;" } terser-4.1.2/test/compress/ie8.js000066400000000000000000000160271351061312300166600ustar00rootroot00000000000000do_screw: { options = { ie8: false, } beautify = { ie8: false, ascii_only: true, } input: { f("\v"); } expect_exact: 'f("\\v");' } dont_screw: { options = { ie8: true, } beautify = { ie8: true, ascii_only: true, } input: { f("\v"); } expect_exact: 'f("\\x0B");' } do_screw_constants: { options = { ie8: false, } input: { f(undefined, Infinity); } expect_exact: "f(void 0,1/0);" } dont_screw_constants: { options = { ie8: true, } input: { f(undefined, Infinity); } expect_exact: "f(undefined,Infinity);" } do_screw_try_catch: { options = { ie8: false, } mangle = { ie8: false, } beautify = { ie8: false, } input: { good = function(e){ return function(error){ try{ e() } catch(e) { error(e) } } }; } expect: { good = function(n){ return function(t){ try{ n() } catch(n) { t(n) } } }; } } dont_screw_try_catch: { options = { ie8: true, } mangle = { ie8: true, } beautify = { ie8: true, } input: { bad = function(e){ return function(error){ try{ e() } catch(e) { error(e) } } }; } expect: { bad = function(n){ return function(t){ try{ n() } catch(n) { t(n) } } }; } } do_screw_try_catch_undefined: { options = { ie8: false, } mangle = { ie8: false, } beautify = { ie8: false, } input: { function a(b){ try { throw 'Stuff'; } catch (undefined) { console.log('caught: ' + undefined); } console.log('undefined is ' + undefined); return b === undefined; }; } expect: { function a(o){ try{ throw "Stuff" } catch (o) { console.log("caught: "+o) } console.log("undefined is " + void 0); return void 0===o } } expect_stdout: true } dont_screw_try_catch_undefined: { options = { ie8: true, } mangle = { ie8: true, } beautify = { ie8: true, } input: { function a(b){ try { throw 'Stuff'; } catch (undefined) { console.log('caught: ' + undefined); } console.log('undefined is ' + undefined); return b === undefined; }; } expect: { function a(n){ try{ throw "Stuff" } catch (undefined) { console.log("caught: " + undefined) } console.log("undefined is " + undefined); return n === undefined } } expect_stdout: true } reduce_vars: { options = { evaluate: true, ie8: true, reduce_funcs: true, reduce_vars: true, unused: true, } mangle = { ie8: true, } input: { function f() { var a; try { x(); } catch (a) { y(); } alert(a); } } expect: { function f() { var t; try { x(); } catch (t) { y(); } alert(t); } } } issue_1586_1: { options = { ie8: true, } mangle = { ie8: true, } input: { function f() { try { x(); } catch (err) { console.log(err.message); } } } expect_exact: "function f(){try{x()}catch(c){console.log(c.message)}}" } issue_1586_2: { options = { ie8: false, } mangle = { ie8: false, } input: { function f() { try { x(); } catch (err) { console.log(err.message); } } } expect_exact: "function f(){try{x()}catch(c){console.log(c.message)}}" } issue_2120_1: { mangle = { ie8: false, } input: { "aaaaaaaa"; var a = 1, b = "FAIL"; try { throw 1; } catch (c) { try { throw 0; } catch (a) { if (c) b = "PASS"; } } console.log(b); } expect: { "aaaaaaaa"; var a = 1, b = "FAIL"; try { throw 1; } catch (t) { try { throw 0; } catch (a) { if (t) b = "PASS"; } } console.log(b); } expect_stdout: "PASS" } issue_2120_2: { mangle = { ie8: true, } input: { "aaaaaaaa"; var a = 1, b = "FAIL"; try { throw 1; } catch (c) { try { throw 0; } catch (a) { if (c) b = "PASS"; } } console.log(b); } expect: { "aaaaaaaa"; var a = 1, b = "FAIL"; try { throw 1; } catch (c) { try { throw 0; } catch (a) { if (c) b = "PASS"; } } console.log(b); } expect_stdout: "PASS" } issue_2254_1: { mangle = { ie8: false, } input: { "eeeeee"; try { console.log(f("PASS")); } catch (e) {} function f(s) { try { throw "FAIL"; } catch (e) { return s; } } } expect: { "eeeeee"; try { console.log(f("PASS")); } catch (e) {} function f(e) { try { throw "FAIL"; } catch (t) { return e; } } } expect_stdout: "PASS" } issue_2254_2: { mangle = { ie8: true, } input: { "eeeeee"; try { console.log(f("PASS")); } catch (e) {} function f(s) { try { throw "FAIL"; } catch (e) { return s; } } } expect: { "eeeeee"; try { console.log(f("PASS")); } catch (e) {} function f(t) { try { throw "FAIL"; } catch (e) { return t; } } } expect_stdout: "PASS" } terser-4.1.2/test/compress/if_return.js000066400000000000000000000227561351061312300201760ustar00rootroot00000000000000if_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 (f.files[0].size > 12345) 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(); } } } issue_1317: { options = { if_return: true, } input: { !function(a) { if (a) return; let b = 1; function g() { return b; } console.log(g()); }(); } expect: { !function(a) { if (a) return; let b = 1; function g() { return b; } console.log(g()); }(); } expect_stdout: "1" } issue_1317_strict: { options = { if_return: true, } input: { "use strict"; !function(a) { if (a) return; let b = 1; function g() { return b; } console.log(g()); }(); } expect: { "use strict"; !function(a) { if (a) return; let b = 1; function g() { return b; } console.log(g()); }(); } expect_stdout: "1" } 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(); } } } issue_2747: { options = { conditionals: true, if_return: true, sequences: true, unused: true, } input: { "use strict"; function f(baz) { if (baz === 0) { return null; } let r; if (baz > 2) { r = 4; } else { r = 5; } return r; } console.log(f(0), f(1), f(3)); } expect: { "use strict"; function f(baz) { if (0 === baz) return null; let r; return r = baz > 2 ? 4 : 5, r; } console.log(f(0), f(1), f(3)); } expect_stdout: "null 5 4" } terser-4.1.2/test/compress/inline.js000066400000000000000000000066411351061312300174520ustar00rootroot00000000000000inline_within_extends_1: { options = { evaluate: true, inline: 3, passes: 1, reduce_funcs: true, reduce_vars: true, side_effects: true, unused: true, } input: { (function() { function foo(foo_base) { return class extends foo_base {}; } function bar(bar_base) { return class extends bar_base {}; } console.log((new class extends (foo(bar(Array))){}).concat(["PASS"])[0]); })(); } expect: { console.log((new class extends(function(foo_base) { return class extends foo_base {}; }(function(bar_base) { return class extends bar_base {}; }(Array))){}).concat([ "PASS" ])[0]); } expect_stdout: "PASS" } inline_within_extends_2: { options = { defaults: true, evaluate: true, inline: 3, passes: 3, reduce_funcs: true, reduce_vars: true, side_effects: true, unused: true, } input: { (function() { class Baz extends(foo(bar(Array))) { constructor() { super(...arguments); } } function foo(foo_base) { return class extends foo_base { constructor() { super(...arguments); } second() { return this[1]; } }; } function bar(bar_base) { return class extends bar_base { constructor(...args) { super(...args); } }; } console.log(new Baz(1, "PASS", 3).second()); })(); } expect: { console.log(new class extends(function(foo_base) { return class extends foo_base { constructor() { super(...arguments); } second() { return this[1]; } }; }(function(bar_base) { return class extends bar_base { constructor(...args) { super(...args); } }; }(Array))) { constructor() { super(...arguments); } }(1, "PASS", 3).second()); } expect_stdout: "PASS" } issue_308: { options = { defaults: true, passes: 4, toplevel: true } input: { exports.withStyles = withStyles; function _inherits(superClass) { if (typeof superClass !== "function") { throw new TypeError("Super expression must be a function, not " + typeof superClass); } Object.create(superClass); } function withStyles() { var a = EXTERNAL(); return function(_a) { _inherits(_a); function d() {} }(a); } } expect: { exports.withStyles = function () { !function (superClass) { if ("function" != typeof superClass) throw new TypeError("Super expression must be a function, not " + typeof superClass); Object.create(superClass); }(EXTERNAL()); }; } } terser-4.1.2/test/compress/issue-1001.js000066400000000000000000000002151351061312300176720ustar00rootroot00000000000000parenthesis_strings_in_parenthesis: { input: { var foo = ('('); a(')'); } expect_exact: 'var foo="(";a(")");' } terser-4.1.2/test/compress/issue-1034.js000066400000000000000000000226611351061312300177110ustar00rootroot00000000000000non_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, warnings: "verbose", } 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 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]", "WARN: Dropping unused variable a [test/compress/issue-1034.js:4,20]", "WARN: Dropping unused variable b [test/compress/issue-1034.js:7,20]", "WARN: Dropping unused variable c [test/compress/issue-1034.js:9,16]", "WARN: Dropping unused function nope [test/compress/issue-1034.js:11,21]", "WARN: pass 0: last_count: Infinity, count: 23", "WARN: pass 1: last_count: 23, 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, warnings: "verbose", } 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 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]", "WARN: Dropping unused variable a [test/compress/issue-1034.js:5,20]", "WARN: Dropping unused variable b [test/compress/issue-1034.js:8,20]", "WARN: Dropping unused variable c [test/compress/issue-1034.js:10,16]", "WARN: Dropping unused function nope [test/compress/issue-1034.js:12,21]", "WARN: pass 0: last_count: Infinity, count: 34", "WARN: pass 1: last_count: 34, 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]", ] } terser-4.1.2/test/compress/issue-1041.js000066400000000000000000000012201351061312300176730ustar00rootroot00000000000000const_declaration: { options = { evaluate: true }; input: { const goog = goog || {}; } expect: { const goog = goog || {}; } } 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 || {}; } } terser-4.1.2/test/compress/issue-1043.js000066400000000000000000000011531351061312300177020ustar00rootroot00000000000000issue_1043: { options = { side_effects: true }; input: { function* range(start = 0, end = null, step = 1) { if (end == null) { end = start; start = 0; } for (let i = start; i < end; i += step) { yield i; } } } expect: { function* range(start = 0, end = null, step = 1) { if (null == end) { end = start; start = 0; } for (let i = start; i < end; i += step) yield i; } } } terser-4.1.2/test/compress/issue-1044.js000066400000000000000000000003511351061312300177020ustar00rootroot00000000000000issue_1044: { options = { evaluate: true, conditionals: true }; input: { const mixed = Base ? class extends Base {} : class {} } expect: { const mixed = Base ? class extends Base {} : class {} } } terser-4.1.2/test/compress/issue-1052.js000066400000000000000000000062151351061312300177060ustar00rootroot00000000000000multiple_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 h() {} if (window) function g() {} } } } 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() {} } } } terser-4.1.2/test/compress/issue-1105.js000066400000000000000000000155541351061312300177130ustar00rootroot00000000000000with_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: 'oInfinity' }; var vInfinity = "Infinity"; vInfinity = Infinity; } expect: { var o = { Infinity: 'oInfinity' } var vInfinity = "Infinity" vInfinity = 1/0 } } Infinity_in_with_scope: { options = { unused: true, } input: { var o = { Infinity: 'oInfinity' }; var vInfinity = "Infinity"; with (o) { vInfinity = Infinity; } } expect: { var o = { Infinity: 'oInfinity' } var vInfinity = "Infinity" with (o) vInfinity = Infinity } } 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 } terser-4.1.2/test/compress/issue-12.js000066400000000000000000000024631351061312300175420ustar00rootroot00000000000000keep_name_of_getter: { options = { unused: true, } input: { a = { get foo () {} } } expect: { a = { get foo () {} } } } keep_name_of_setter: { options = { unused: true, } input: { 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; } }; } }terser-4.1.2/test/compress/issue-1202.js000066400000000000000000000017271351061312300177060ustar00rootroot00000000000000mangle_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; }; } } } terser-4.1.2/test/compress/issue-1212.js000066400000000000000000000033751351061312300177100ustar00rootroot00000000000000issue_1212_debug_false: { options = { global_defs : { DEBUG: false }, sequences : true, properties : true, dead_code : true, conditionals : true, comparisons : true, evaluate : true, booleans : true, loops : true, unused : true, hoist_funs : true, keep_fargs : true, if_return : true, join_vars : true, collapse_vars : true, side_effects : true, } input: { class foo { bar() { if (DEBUG) console.log("DEV"); else console.log("PROD"); } } new foo().bar(); } expect: { class foo{ bar() { console.log("PROD") } } (new foo).bar(); } } issue_1212_debug_true: { options = { global_defs : { DEBUG: true }, sequences : true, properties : true, dead_code : true, conditionals : true, comparisons : true, evaluate : true, booleans : true, loops : true, unused : true, hoist_funs : true, keep_fargs : true, if_return : true, join_vars : true, collapse_vars : true, side_effects : true, } input: { class foo { bar() { if (DEBUG) console.log("DEV"); else console.log("PROD"); } } new foo().bar(); } expect: { class foo{ bar() { console.log("DEV") } } (new foo).bar(); } } terser-4.1.2/test/compress/issue-126.js000066400000000000000000000015071351061312300176260ustar00rootroot00000000000000concatenate_rhs_strings: { options = { evaluate: true, unsafe: true, } input: { foo(bar() + 123 + "Hello" + "World"); foo(bar() + (123 + "Hello") + "World"); foo((bar() + 123) + "Hello" + "World"); foo(bar() + 123 + "Hello" + "World" + ("Foo" + "Bar")); foo("Foo" + "Bar" + bar() + 123 + "Hello" + "World" + ("Foo" + "Bar")); foo("Hello" + bar() + 123 + "World"); foo(bar() + 'Foo' + (10 + parseInt('10'))); } expect: { foo(bar() + 123 + "HelloWorld"); foo(bar() + "123HelloWorld"); foo((bar() + 123) + "HelloWorld"); foo(bar() + 123 + "HelloWorldFooBar"); foo("FooBar" + bar() + "123HelloWorldFooBar"); foo("Hello" + bar() + "123World"); foo(bar() + 'Foo' + (10 + parseInt('10'))); } } terser-4.1.2/test/compress/issue-1261.js000066400000000000000000000157111351061312300177110ustar00rootroot00000000000000pure_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: Dropping __PURE__ call [test/compress/issue-1261.js:9,24]", "WARN: Condition always true [test/compress/issue-1261.js:9,8]", "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:10,31]", "WARN: Condition always false [test/compress/issue-1261.js:10,8]", ] } terser-4.1.2/test/compress/issue-1275.js000066400000000000000000000024351351061312300177150ustar00rootroot00000000000000string_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 } terser-4.1.2/test/compress/issue-1321.js000066400000000000000000000021111351061312300176740ustar00rootroot00000000000000issue_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.o=1;x["a"]=2*x.o;console.log(x.o,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.o=1;x["_$foo$_"]=2*x.o;console.log(x.o,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.o = 1; x["a"] = 2 * x.o; console.log(x.o, x["a"]); } expect_stdout: true } terser-4.1.2/test/compress/issue-143.js000066400000000000000000000021041351061312300176170ustar00rootroot00000000000000/** * There was an incorrect sort behaviour documented in issue #143: * (x = f(…)) <= x → x >= (x = f(…)) * * For example, let the equation be: * (a = parseInt('100')) <= a * * If a was an integer and has the value of 99, * (a = parseInt('100')) <= a → 100 <= 100 → true * * When transformed incorrectly: * a >= (a = parseInt('100')) → 99 >= 100 → false */ tranformation_sort_order_equal: { options = { comparisons: true, } input: { (a = parseInt('100')) == a } expect: { (a = parseInt('100')) == a } } tranformation_sort_order_unequal: { options = { comparisons: true, } input: { (a = parseInt('100')) != a } expect: { (a = parseInt('100')) != a } } tranformation_sort_order_lesser_or_equal: { options = { comparisons: true, } input: { (a = parseInt('100')) <= a } expect: { (a = parseInt('100')) <= a } } tranformation_sort_order_greater_or_equal: { options = { comparisons: true, } input: { (a = parseInt('100')) >= a } expect: { (a = parseInt('100')) >= a } }terser-4.1.2/test/compress/issue-1431.js000066400000000000000000000063001351061312300177020ustar00rootroot00000000000000level_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); } ]; }; } } } terser-4.1.2/test/compress/issue-1443.js000066400000000000000000000024021351061312300177040ustar00rootroot00000000000000// 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; }; } } } terser-4.1.2/test/compress/issue-1446.js000066400000000000000000000034211351061312300177110ustar00rootroot00000000000000typeof_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}" } terser-4.1.2/test/compress/issue-1447.js000066400000000000000000000015561351061312300177210ustar00rootroot00000000000000else_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 } terser-4.1.2/test/compress/issue-1466.js000066400000000000000000000244721351061312300177240ustar00rootroot00000000000000same_variable_in_multiple_for_loop: { options = { hoist_funs: true, dead_code: true, conditionals: true, comparisons: true, evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true, if_return: true, join_vars: true, side_effects: true, collapse_vars: true, } mangle = {} input: { for (let i = 0; i < 3; i++) { let a = 100; console.log(i, a); for (let i = 0; i < 2; i++) { console.log(i, a); let c = 2; console.log(c); } } } expect: { for (let o = 0; o < 3; o++) { let l = 100; console.log(o, l); for (let o = 0; o < 2; o++) { console.log(o, l); let e = 2; console.log(e); } } } expect_stdout: true } same_variable_in_multiple_forOf: { options = { hoist_funs: true, dead_code: true, conditionals: true, comparisons: true, evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true, if_return: true, join_vars: true, side_effects: true, collapse_vars: true, } mangle = {} input: { var test = [ "a", "b", "c" ]; for (let tmp of test) { console.log(tmp); let dd; dd = [ "e", "f", "g" ]; for (let tmp of dd) { console.log(tmp); } } } expect: { var test = [ "a", "b", "c" ]; for (let o of test) { console.log(o); let e; e = [ "e", "f", "g" ]; for (let o of e) console.log(o); } } expect_stdout: true } same_variable_in_multiple_forIn: { options = { hoist_funs: true, dead_code: true, conditionals: true, comparisons: true, evaluate: true, booleans: true, loops: true, unused: false, keep_fargs: true, if_return: true, join_vars: true, side_effects: true, collapse_vars: true, } mangle = {} input: { var test = [ "a", "b", "c" ]; for (let tmp in test) { console.log(tmp); let dd; dd = [ "e", "f", "g" ]; for (let tmp in test) { console.log(tmp); } } } expect: { var test = [ "a", "b", "c" ]; for (let e in test) { console.log(e); let t; t = [ "e", "f", "g" ]; for (let e in test) console.log(e); } } expect_stdout: true } different_variable_in_multiple_for_loop: { options = { hoist_funs: true, dead_code: true, conditionals: true, comparisons: true, evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true, if_return: true, join_vars: true, side_effects: true, collapse_vars: true, } mangle = {} input: { for (let i = 0; i < 3; i++) { let a = 100; console.log(i, a); for (let j = 0; j < 2; j++) { console.log(j, a); let c = 2; console.log(c); } } } expect: { for (let o = 0; o < 3; o++) { let l = 100; console.log(o, l); for (let o = 0; o < 2; o++) { console.log(o, l); let e = 2; console.log(e); } } } expect_stdout: true } different_variable_in_multiple_forOf: { options = { hoist_funs: true, dead_code: true, conditionals: true, comparisons: true, evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true, if_return: true, join_vars: true, side_effects: true, collapse_vars: true, } mangle = {} input: { var test = [ "a", "b", "c" ]; for (let tmp of test) { console.log(tmp); let dd; dd = [ "e", "f", "g" ]; for (let t of dd) { console.log(t); } } } expect: { var test = [ "a", "b", "c" ]; for (let o of test) { console.log(o); let e; e = [ "e", "f", "g" ]; for (let o of e) console.log(o); } } expect_stdout: true } different_variable_in_multiple_forIn: { options = { hoist_funs: true, dead_code: true, conditionals: true, comparisons: true, evaluate: true, booleans: true, loops: true, unused: false, keep_fargs: true, if_return: true, join_vars: true, side_effects: true, collapse_vars: true, } mangle = {} input: { var test = [ "a", "b", "c" ]; for (let tmp in test) { console.log(tmp); let dd; dd = [ "e", "f", "g" ]; for (let t in test) { console.log(t); } } } expect: { var test = [ "a", "b", "c" ]; for (let e in test) { console.log(e); let t; t = [ "e", "f", "g" ]; for (let e in test) console.log(e); } } expect_stdout: true } same_variable_in_multiple_forOf_sequences_let: { options = { hoist_funs: true, dead_code: true, conditionals: true, comparisons: true, evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true, if_return: true, join_vars: true, sequences: true, side_effects: true, collapse_vars: true, } mangle = {} input: { var test = [ "a", "b", "c" ]; for (let tmp of test) { console.log(tmp); let dd; dd = [ "e", "f", "g" ]; for (let tmp of dd) { console.log(tmp); } } } expect: { var test = [ "a", "b", "c" ]; for (let o of test) { let e; console.log(o), e = [ "e", "f", "g" ]; for (let o of e) console.log(o); } } expect_stdout: true } same_variable_in_multiple_forOf_sequences_const: { options = { hoist_funs: true, dead_code: true, conditionals: true, comparisons: true, evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true, if_return: true, join_vars: true, sequences: true, side_effects: true, collapse_vars: true, } mangle = {} input: { var test = [ "a", "b", "c" ]; for (const tmp of test) { console.log(tmp); let dd; dd = [ "e", "f", "g" ]; for (const tmp of dd) { console.log(tmp); } } } expect: { var test = [ "a", "b", "c" ]; for (const o of test) { let t; console.log(o), t = [ "e", "f", "g" ]; for (const o of t) console.log(o); } } expect_stdout: true } same_variable_in_multiple_forIn_sequences_let: { options = { hoist_funs: true, dead_code: true, conditionals: true, comparisons: true, evaluate: true, booleans: true, loops: true, unused: false, keep_fargs: true, if_return: true, join_vars: true, sequences: true, side_effects: true, collapse_vars: true, } mangle = {} input: { var test = [ "a", "b", "c" ]; for (let tmp in test) { console.log(tmp); let dd; dd = [ "e", "f", "g" ]; for (let tmp in test) { console.log(tmp); } } } expect: { var test = [ "a", "b", "c" ]; for (let e in test) { let t; console.log(e), t = [ "e", "f", "g" ]; for (let e in test) console.log(e); } } expect_stdout: true } same_variable_in_multiple_forIn_sequences_const: { options = { hoist_funs: true, dead_code: true, conditionals: true, comparisons: true, evaluate: true, booleans: true, loops: true, unused: false, keep_fargs: true, if_return: true, join_vars: true, sequences: true, side_effects: true, collapse_vars: true, } mangle = {} input: { var test = [ "a", "b", "c" ]; for (const tmp in test) { console.log(tmp); let dd; dd = [ "e", "f", "g" ]; for (const tmp in test) { console.log(tmp); } } } expect: { var test = [ "a", "b", "c" ]; for (const o in test) { let t; console.log(o), t = [ "e", "f", "g" ]; for (const o in test) console.log(o); } } expect_stdout: true } more_variable_in_multiple_for: { options = { hoist_funs: true, dead_code: true, conditionals: true, comparisons: true, evaluate: true, booleans: true, loops: true, unused: false, keep_fargs: true, if_return: true, join_vars: true, side_effects: true, collapse_vars: true, } mangle = {} input: { for (let a = 9, i = 0; i < 20; i += a) { let b = a++ + i; console.log(a, b, i); for (let k = b, m = b*b, i = 0; i < 10; i++) { console.log(a, b, m, k, i); } } } expect: { for (let o = 9, l = 0; l < 20; l += o) { let e = o++ + l; console.log(o, e, l); for (let l = e, t = e * e, c = 0; c < 10; c++) console.log(o, e, t, l, c); } } expect_stdout: true } terser-4.1.2/test/compress/issue-1569.js000066400000000000000000000005311351061312300177160ustar00rootroot00000000000000inner_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; } } terser-4.1.2/test/compress/issue-1588.js000066400000000000000000000035561351061312300177310ustar00rootroot00000000000000screw_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 } runtime_error: { input: { const a = 1; console.log(a++); } expect: { const a = 1; console.log(a++); } expect_stdout: true } terser-4.1.2/test/compress/issue-1609.js000066400000000000000000000021101351061312300177040ustar00rootroot00000000000000chained_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; })(); })(); } } terser-4.1.2/test/compress/issue-1639.js000066400000000000000000000032341351061312300177170ustar00rootroot00000000000000 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; --L1 > 0;) if (--b, 0) var ignore = 0; console.log(a, b); } expect_stdout: true } 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, 0; } f19(), console.log(a, b); } expect_stdout: true } 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: true } terser-4.1.2/test/compress/issue-1656.js000066400000000000000000000017661351061312300177260ustar00rootroot00000000000000f7: { 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: [ "var b = 10;", "", "!function() {", " b = 100;", "}(), console.log(100, b);", ] expect_stdout: true } terser-4.1.2/test/compress/issue-1673.js000066400000000000000000000062721351061312300177220ustar00rootroot00000000000000side_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" } terser-4.1.2/test/compress/issue-1704.js000066400000000000000000000210731351061312300177110ustar00rootroot00000000000000mangle_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 o="FAIL";try{throw 1}catch(c){o="PASS"}console.log(o);' 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 o="FAIL";try{throw 1}catch(r){var o="PASS"}console.log(o);' 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: "PASS" } 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_stdout: "PASS" } mangle_catch_redef_ie8_3: { 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: "PASS" } 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_stdout: "PASS" } terser-4.1.2/test/compress/issue-1733.js000066400000000000000000000042051351061312300177110ustar00rootroot00000000000000function_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(c){var o=1;console.log(c,o)}}()}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(o){!function(){try{throw 0}catch(o){var c=1;console.log(o,c)}}()}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(c){try{throw 2}catch(o){var o=3;console.log(o)}}console.log(o)}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", ] } terser-4.1.2/test/compress/issue-1750.js000066400000000000000000000016611351061312300177130ustar00rootroot00000000000000case_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" } terser-4.1.2/test/compress/issue-1770.js000066400000000000000000000035121351061312300177120ustar00rootroot00000000000000mangle_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, 37: 4, o: 5, 1e42: 6, j: 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["j"], obj["1e+42"]); } expect_stdout: [ "0 0 1", "3 3", "4 5 4 4", "8 7 8", ] } terser-4.1.2/test/compress/issue-1787.js000066400000000000000000000005301351061312300177170ustar00rootroot00000000000000unary_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 } terser-4.1.2/test/compress/issue-1833.js000066400000000000000000000045771351061312300177260ustar00rootroot00000000000000iife_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}" } terser-4.1.2/test/compress/issue-1943.js000066400000000000000000000005721351061312300177170ustar00rootroot00000000000000operator: { 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;" } terser-4.1.2/test/compress/issue-2001.js000066400000000000000000000122711351061312300177000ustar00rootroot00000000000000export_func_1: { options = { hoist_funs: true, toplevel: true, unused: true, } input: { export function f(){} } expect_exact: "export function f(){}" } export_func_2: { options = { hoist_funs: true, side_effects: false, toplevel: true, unused: true, } input: { export function f(){}(1); } expect_exact: "export function f(){}1;" } export_func_3: { options = { hoist_funs: true, side_effects: true, toplevel: true, unused: true, } input: { export function f(){}(1); } expect_exact: "export function f(){}" } export_default_func_1: { options = { hoist_funs: true, toplevel: true, unused: true, } input: { export default function f(){} } expect_exact: "export default function f(){}" } export_default_func_2: { options = { hoist_funs: true, side_effects: false, toplevel: true, unused: true, } input: { export default function f(){}(1); } expect_exact: "export default function f(){}1;" } export_default_func_3: { options = { hoist_funs: true, side_effects: true, toplevel: true, unused: true, } input: { export default function f(){}(1); } expect_exact: "export default function f(){}" } export_class_1: { options = { hoist_funs: true, toplevel: true, unused: true, } input: { export class C {}; } expect_exact: "export class C{}" } export_class_2: { options = { hoist_funs: true, side_effects: false, toplevel: true, unused: true, } input: { export class C {}(1); } expect_exact: "export class C{}1;" } export_class_3: { options = { hoist_funs: true, side_effects: true, toplevel: true, unused: true, } input: { export class C {}(1); } expect_exact: "export class C{}" } export_default_class_1: { options = { hoist_funs: true, toplevel: true, unused: true, } input: { export default class C {} } expect_exact: "export default class C{}" } export_default_class_2: { options = { hoist_funs: true, side_effects: false, toplevel: true, unused: true, } input: { export default class C {}(1); } expect_exact: "export default class C{}1;" } export_default_class_3: { options = { hoist_funs: true, side_effects: true, toplevel: true, unused: true, } input: { export default class C {}(1); } expect_exact: "export default class C{}" } export_mangle_1: { mangle = { toplevel: true, } input: { export function foo(one, two) { return one - two; }; } expect_exact: "export function foo(o,n){return o-n}" } export_mangle_2: { mangle = { toplevel: true, } input: { export default function foo(one, two) { return one - two; } } expect_exact: "export default function t(t,e){return t-e}" } export_mangle_3: { options = { collapse_vars: true, unused: true, } mangle = { toplevel: true, } input: { export class C { go(one, two) { var z = one; return one - two + z; } }; } expect_exact: "export class C{go(r,e){return r-e+r}}" } export_mangle_4: { options = { collapse_vars: true, unused: true, } mangle = { toplevel: true, } input: { export default class C { go(one, two) { var z = one; return one - two + z; } } } expect_exact: "export default class e{go(e,r){return e-r+e}}" } export_mangle_5: { mangle = { toplevel: true, } input: { export default { prop: function(one, two) { return one - two; } }; } expect_exact: "export default{prop:function(r,t){return r-t}};" } export_mangle_6: { mangle = { toplevel: true, } input: { var baz = 2; export let foo = 1, bar = baz; } expect_exact: "var o=2;export let foo=1,bar=o;" } export_toplevel_1: { options = { toplevel: true, unused: true, } input: { function f(){} export function g(){} export default function h(){} } expect: { export function g(){} export default function h(){} } } export_toplevel_2: { options = { toplevel: true, unused: true, } input: { class A {} export class B {} export default class C {} } expect: { export class B {} export default class C {} } } export_default_func_ref: { options = { hoist_funs: true, toplevel: true, unused: true, } input: { export default function f(){} f(); } expect_exact: "export default function f(){}f();" } terser-4.1.2/test/compress/issue-203.js000066400000000000000000000023601351061312300176200ustar00rootroot00000000000000 compress_new_function: { options = { unsafe: true, unsafe_Function: true, } input: { new Function("aa, bb", 'return aa;'); } expect: { Function("n,r", "return n"); } } compress_new_function_with_destruct: { options = { unsafe: true, unsafe_Function: true, ecma: 6 } beautify = { ecma: 6 } input: { new Function("aa, [bb]", 'return aa;'); new Function("aa, {bb}", 'return aa;'); new Function("[[aa]], [{bb}]", 'return aa;'); } expect: { Function("n,[r]", "return n"); Function("n,{bb:b}", "return n"); Function("[[n]],[{bb:b}]", "return n"); } } compress_new_function_with_destruct_arrows: { options = { arrows: true, unsafe_arrows: true, unsafe: true, unsafe_Function: true, ecma: 6, } beautify = { ecma: 6 } input: { new Function("aa, [bb]", 'return aa;'); new Function("aa, {bb}", 'return aa;'); new Function("[[aa]], [{bb}]", 'return aa;'); } expect: { Function("n,[a]", "return n"); Function("b,{bb:n}", "return b"); Function("[[b]],[{bb:n}]", "return b"); } } terser-4.1.2/test/compress/issue-208.js000066400000000000000000000027421351061312300176310ustar00rootroot00000000000000do_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: { const ENV = 3; var FOO = 4; f(ENV * 10); --FOO; DEBUG = 1; DEBUG++; DEBUG += 1; f(DEBUG); x = DEBUG; } expect: { const 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,14]", "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]", ] } terser-4.1.2/test/compress/issue-22.js000066400000000000000000000005341351061312300175400ustar00rootroot00000000000000return_with_no_value_in_if_body: { options = { conditionals: true, } input: { function foo(bar) { if (bar) { return; } else { return 1; } } } expect: { function foo (bar) { return bar ? void 0 : 1; } } } terser-4.1.2/test/compress/issue-229.js000066400000000000000000000002541351061312300176300ustar00rootroot00000000000000template_strings: { input: { var x = {}; var y = {...x}; y.hello = 'world'; } expect_exact: "var x={};var y={...x};y.hello=\"world\";" }terser-4.1.2/test/compress/issue-2652.js000066400000000000000000000007351351061312300177160ustar00rootroot00000000000000insert_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;", ] } terser-4.1.2/test/compress/issue-267.js000066400000000000000000000003221351061312300176260ustar00rootroot00000000000000issue_267: { options = { comparisons: true, } input: { x = a % b / b * c * 2; x = a % b * 2 } expect: { x = a % b / b * c * 2; x = a % b * 2; } } terser-4.1.2/test/compress/issue-269.js000066400000000000000000000023511351061312300176340ustar00rootroot00000000000000issue_269_1: { options = { unsafe: true, } input: { f( String(x), Number(x), Boolean(x), String(), Number(), Boolean() ); } expect: { f( x + '', +x, !!x, '', 0, false ); } } issue_269_dangers: { options = { unsafe: true, } input: { f( String(x, x), Number(x, x), Boolean(x, x) ); } expect: { f(String(x, x), Number(x, x), Boolean(x, x)); } } issue_269_in_scope: { options = { unsafe: true, } input: { var String, Number, Boolean; f( String(x), Number(x, x), Boolean(x) ); } expect: { var String, Number, Boolean; f(String(x), Number(x, x), Boolean(x)); } } strings_concat: { options = { unsafe: true, } input: { f( String(x + 'str'), String('str' + x) ); } expect: { f( x + 'str', 'str' + x ); } } 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,2]', ] } terser-4.1.2/test/compress/issue-2719.js000066400000000000000000000014731351061312300177220ustar00rootroot00000000000000warn: { 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.caller not supported [test/compress/issue-2719.js:5,19]", "WARN: Function.prototype.arguments not supported [test/compress/issue-2719.js:5,19]", ] } terser-4.1.2/test/compress/issue-281.js000066400000000000000000000234151351061312300176320ustar00rootroot00000000000000collapse_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" } terser-4.1.2/test/compress/issue-2871.js000066400000000000000000000012131351061312300177110ustar00rootroot00000000000000comparison_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; } } terser-4.1.2/test/compress/issue-2989.js000066400000000000000000000006351351061312300177320ustar00rootroot00000000000000inline_script_off: { beautify = { inline_script: false, } input: { console.log(""); } expect_exact: 'console.log("");' expect_stdout: "" } inline_script_on: { beautify = { inline_script: true, } input: { console.log(""); } expect_exact: 'console.log("<\\/sCrIpT>");' expect_stdout: "" } terser-4.1.2/test/compress/issue-368.js000066400000000000000000000024711351061312300176370ustar00rootroot00000000000000collapse: { 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; } } } terser-4.1.2/test/compress/issue-44.js000066400000000000000000000011611351061312300175410ustar00rootroot00000000000000issue_44_valid_ast_1: { options = { unused: true, } input: { function a(b) { for (var i = 0, e = b.qoo(); ; i++) {} } } expect: { function a(b) { var i = 0; for (b.qoo(); ; i++); } } } issue_44_valid_ast_2: { options = { unused: true, } input: { function a(b) { if (foo) for (var i = 0, e = b.qoo(); ; i++) {} } } expect: { function a(b) { if (foo) { var i = 0; for (b.qoo(); ; i++); } } } } terser-4.1.2/test/compress/issue-59.js000066400000000000000000000010471351061312300175520ustar00rootroot00000000000000keep_continue: { options = { dead_code: true, evaluate: true, } input: { while (a) { if (b) { switch (true) { case c(): d(); } continue; } f(); } } expect: { while (a) { if (b) { switch (true) { case c(): d(); } continue; } f(); } } } terser-4.1.2/test/compress/issue-597.js000066400000000000000000000062511351061312300176430ustar00rootroot00000000000000NaN_and_Infinity_must_have_parens: { options = {} input: { Infinity.toString(); NaN.toString(); } 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(); (0/0).toString(); } } beautify_off_1: { options = { evaluate: true, } beautify = { beautify: false, } 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_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" } terser-4.1.2/test/compress/issue-611.js000066400000000000000000000005051351061312300176220ustar00rootroot00000000000000issue_611: { options = { sequences: true, side_effects: true, } input: { define(function() { function fn() {} if (fn()) { fn(); return void 0; } }); } expect: { define(function() { function fn(){} if (fn()) return void fn(); }); } } terser-4.1.2/test/compress/issue-637.js000066400000000000000000000006241351061312300176340ustar00rootroot00000000000000wrongly_optimized: { options = { booleans: true, conditionals: true, evaluate: true, } input: { function func() { foo(); } if (func() || true) { bar(); } } expect: { function func() { foo(); } // TODO: optimize to `func(), bar()` (func(), 1) && bar(); } } terser-4.1.2/test/compress/issue-640.js000066400000000000000000000150541351061312300176310ustar00rootroot00000000000000cond_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, evaluate: true, expression: true, } input: { function func() { foo(); } if (func() || true) { bar(); } } expect: { function func() { foo(); } // TODO: optimize to `func(), bar()` if (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() {}(); } } terser-4.1.2/test/compress/issue-747.js000066400000000000000000000013641351061312300176400ustar00rootroot00000000000000dont_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.o=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.o=256;obj.a=123;console.log(obj.a); } expect_stdout: "123" } terser-4.1.2/test/compress/issue-751.js000066400000000000000000000010551351061312300176300ustar00rootroot00000000000000negate_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(); } } terser-4.1.2/test/compress/issue-782.js000066400000000000000000000010521351061312300176310ustar00rootroot00000000000000remove_redundant_sequence_items: { options = { side_effects: true }; input: { (0, 1, eval)(); (0, 1, logThis)(); (0, 1, _decorators.logThis)(); } expect: { (0, eval)(); logThis(); (0, _decorators.logThis)(); } } dont_remove_this_binding_sequence: { options = { side_effects: true }; input: { (0, eval)(); (0, logThis)(); (0, _decorators.logThis)(); } expect: { (0, eval)(); logThis(); (0, _decorators.logThis)(); } } terser-4.1.2/test/compress/issue-892.js000066400000000000000000000014651351061312300176430ustar00rootroot00000000000000dont_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 } terser-4.1.2/test/compress/issue-913.js000066400000000000000000000005651351061312300176350ustar00rootroot00000000000000keep_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; })(); } } terser-4.1.2/test/compress/issue-926.js000066400000000000000000000003521351061312300176330ustar00rootroot00000000000000template_strings: { input: { foo( `${contents}`, `${text}` ); } expect_exact: "foo(`${contents}`,`${text}`);" } terser-4.1.2/test/compress/issue-973.js000066400000000000000000000047261351061312300176460ustar00rootroot00000000000000this_binding_conditionals: { options = { conditionals: true, evaluate: true, side_effects: true, }; input: { (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: { 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, toplevel: true, unused: true, }; input: { var c = a; c(); var d = a.b; d(); var e = eval; e(); } expect: { 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) { 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) { var eval = console; foo(); (0, foo.bar)(); (0, 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_stdout: [ "object", "undefined", "object", "object", ] } terser-4.1.2/test/compress/issue-976.js000066400000000000000000000052741351061312300176500ustar00rootroot00000000000000eval_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")}' } terser-4.1.2/test/compress/issue-979.js000066400000000000000000000043371351061312300176520ustar00rootroot00000000000000issue979_reported: { options = { booleans: 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: true, side_effects: true, unused: true, } input: { function f1() { if (a == 1 || b == 2) { foo(); } } function f2() { if (!(a == 1 || b == 2)) { } else { foo(); } } } expect: { function f1() { 1!=a&&2!=b||foo(); } function f2() { 1!=a&&2!=b||foo(); } } } issue979_test_negated_is_best: { options = { booleans: 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: true, side_effects: true, unused: true, } input: { function f3() { if (a == 1 | b == 2) { foo(); } } function f4() { if (!(a == 1 | b == 2)) { } else { foo(); } } function f5() { if (a == 1 && b == 2) { foo(); } } function f6() { if (!(a == 1 && b == 2)) { } else { foo(); } } function f7() { if (a == 1 || b == 2) { foo(); } else { return bar(); } } } expect: { function f3() { 1==a|2==b&&foo(); } function f4() { 1==a|2==b&&foo(); } function f5() { 1==a&&2==b&&foo(); } function f6() { 1!=a||2!=b||foo(); } function f7() { if(1!=a&&2!=b)return bar();foo() } } } terser-4.1.2/test/compress/issue-t120.js000066400000000000000000000111321351061312300177770ustar00rootroot00000000000000issue_t120_1: { options = { collapse_vars: true, evaluate: true, inline: 3, join_vars: true, loops: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { function foo(node) { var traverse = function(obj) { var i = obj.data; return i && i.a != i.b; }; while (traverse(node)) { node = node.data; } return node; } var x = { a: 1, b: 2, data: { a: "hello", } }; console.log(foo(x).a, foo({a : "world"}).a); } expect: { function foo(node) { for (var i; i = void 0, (i = node.data) && i.a != i.b; ) node = node.data; return node; } var x = { a: 1, b: 2, data: { a: "hello" } }; console.log(foo(x).a, foo({a: "world"}).a); } expect_stdout: "hello world" } issue_t120_2: { options = { collapse_vars: true, evaluate: true, inline: 3, join_vars: true, loops: true, passes: 3, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { function foo(node) { var traverse = function(obj) { var i = obj.data; return i && i.a != i.b; }; while (traverse(node)) { node = node.data; } return node; } var x = { a: 1, b: 2, data: { a: "hello", } }; console.log(foo(x).a, foo({a : "world"}).a); } expect: { function foo(node) { for (var i; (i = node.data) && i.a != i.b; ) node = node.data; return node; } var x = { a: 1, b: 2, data: { a: "hello" } }; console.log(foo(x).a, foo({a: "world"}).a); } expect_stdout: "hello world" } issue_t120_3: { options = { defaults: true, inline: 3, toplevel: true, } input: { for (var t = o => { var i = +o; return console.log(i + i) && 0; }; t(1); ) ; } expect: { for (;i = void 0, i = +1, console.log(i + i), 0; ) ; var i; } expect_stdout: "2" } issue_t120_4: { options = { defaults: true, inline: 3, toplevel: true, } input: { for (var x = 1, t = o => { var i = +o; return console.log(i + i) && 0; }; x--; t(2)) ; } expect: { for (var x = 1; x--; i = void 0, i = +2, console.log(i + i) && 0) ; var i; } expect_stdout: "4" } issue_t120_5: { options = { defaults: true, inline: 3, toplevel: true, } input: { for (var x = 1, t = o => { var i = +o; return console.log(i + i) && 0; }; x--; ) t(3); } expect: { for (var x = 1; x--; ) i = void 0, i = +3, console.log(i + i); var i; } expect_stdout: "6" } pr_152_regression: { reminify: false // TODO: remove when https://github.com/terser-js/terser/issues/156 fixed options = { collapse_vars: true, evaluate: true, inline: 3, join_vars: true, loops: true, passes: 1, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { (function(root, factory) { root.CryptoJS = factory(); })(this, function() { var CryptoJS = CryptoJS || function(Math) { var C = {}; C.demo = function(n) { return Math.ceil(n); }; return C; }(Math); return CryptoJS; }); var result = this.CryptoJS.demo(1.3); console.log(result); } expect: { (function(root, factory) { var CryptoJS; root.CryptoJS = CryptoJS = CryptoJS || function(Math) { var C = { demo: function(n) { return Math.ceil(n); } }; return C; }(Math); })(this); var result = this.CryptoJS.demo(1.3); console.log(result); } expect_stdout: "2" } terser-4.1.2/test/compress/issue-t292.js000066400000000000000000000036331351061312300200200ustar00rootroot00000000000000no_flatten_with_arg_colliding_with_arg_value_inner_scope: { options = { collapse_vars: true, inline: true, reduce_funcs: true, reduce_vars: true, sequences: true, toplevel: true, unused: true, } input: { var g = ["a"]; function problem(arg) { return g.indexOf(arg); } function unused(arg) { return problem(arg); } function a(arg) { return problem(arg); } function b(problem) { return g[problem]; } function c(arg) { return b(a(arg)); } console.log(c("a")); } expect: { var g=["a"]; function problem(arg){return g.indexOf(arg)} console.log(function(problem){return g[problem]}(function(arg){return problem(arg)}("a"))); } expect_stdout: "a" } no_flatten_with_var_colliding_with_arg_value_inner_scope: { options = { collapse_vars: true, inline: true, reduce_funcs: true, reduce_vars: true, sequences: true, toplevel: true, unused: true, } input: { var g = ["a"]; function problem(arg) { return g.indexOf(arg); } function unused(arg) { return problem(arg); } function a(arg) { return problem(arg); } function b(test) { var problem = test * 2; console.log(problem); return g[problem]; } function c(arg) { return b(a(arg)); } console.log(c("a")); } expect: { var g=["a"]; function problem(arg){return g.indexOf(arg)} console.log(function(test){var problem=2*test;return console.log(problem),g[problem]}(function(arg){return problem(arg)}("a"))); } expect_stdout: [ "0", "a", ] } terser-4.1.2/test/compress/issue-t50.js000066400000000000000000001063251351061312300177320ustar00rootroot00000000000000issue_t50: { options = { defaults: true, passes: 2, } input: { (function() { var v1 = [ 4, [ {a: -1, b: 5} ] ]; var v2 = [ 4, [ {a: -2, b: 5} ] ]; var v3 = [ 4, [ {a: -3, b: 5} ] ]; var v4 = [ 4, [ {a: -4, b: 5} ] ]; var v5 = [ 4, [ {a: -5, b: 5} ] ]; var v6 = [ 4, [ {a: -6, b: 5} ] ]; var v7 = [ 4, [ {a: -7, b: 5} ] ]; var v8 = [ 4, [ {a: -8, b: 5} ] ]; var v9 = [ 4, [ {a: -9, b: 5} ] ]; var v10 = [ 4, [ {a: -10, b: 5} ] ]; var v11 = [ 4, [ {a: -11, b: 5} ] ]; var v12 = [ 4, [ {a: -12, b: 5} ] ]; var v13 = [ 4, [ {a: -13, b: 5} ] ]; var v14 = [ 4, [ {a: -14, b: 5} ] ]; var v15 = [ 4, [ {a: -15, b: 5} ] ]; var v16 = [ 4, [ {a: -16, b: 5} ] ]; var v17 = [ 4, [ {a: -17, b: 5} ] ]; var v18 = [ 4, [ {a: -18, b: 5} ] ]; var v19 = [ 4, [ {a: -19, b: 5} ] ]; var v20 = [ 4, [ {a: -20, b: 5} ] ]; var v21 = [ 4, [ {a: -21, b: 5} ] ]; var v22 = [ 4, [ {a: -22, b: 5} ] ]; var v23 = [ 4, [ {a: -23, b: 5} ] ]; var v24 = [ 4, [ {a: -24, b: 5} ] ]; var v25 = [ 4, [ {a: -25, b: 5} ] ]; var v26 = [ 4, [ {a: -26, b: 5} ] ]; var v27 = [ 4, [ {a: -27, b: 5} ] ]; var v28 = [ 4, [ {a: -28, b: 5} ] ]; var v29 = [ 4, [ {a: -29, b: 5} ] ]; var v30 = [ 4, [ {a: -30, b: 5} ] ]; var v31 = [ 4, [ {a: -31, b: 5} ] ]; var v32 = [ 4, [ {a: -32, b: 5} ] ]; var v33 = [ 4, [ {a: -33, b: 5} ] ]; var v34 = [ 4, [ {a: -34, b: 5} ] ]; var v35 = [ 4, [ {a: -35, b: 5} ] ]; var v36 = [ 4, [ {a: -36, b: 5} ] ]; var v37 = [ 4, [ {a: -37, b: 5} ] ]; var v38 = [ 4, [ {a: -38, b: 5} ] ]; var v39 = [ 4, [ {a: -39, b: 5} ] ]; var v40 = [ 4, [ {a: -40, b: 5} ] ]; var v41 = [ 4, [ {a: -41, b: 5} ] ]; var v42 = [ 4, [ {a: -42, b: 5} ] ]; var v43 = [ 4, [ {a: -43, b: 5} ] ]; var v44 = [ 4, [ {a: -44, b: 5} ] ]; var v45 = [ 4, [ {a: -45, b: 5} ] ]; var v46 = [ 4, [ {a: -46, b: 5} ] ]; var v47 = [ 4, [ {a: -47, b: 5} ] ]; var v48 = [ 4, [ {a: -48, b: 5} ] ]; var v49 = [ 4, [ {a: -49, b: 5} ] ]; var v50 = [ 4, [ {a: -50, b: 5} ] ]; var v51 = [ 4, [ {a: -51, b: 5} ] ]; var v52 = [ 4, [ {a: -52, b: 5} ] ]; var v53 = [ 4, [ {a: -53, b: 5} ] ]; var v54 = [ 4, [ {a: -54, b: 5} ] ]; var v55 = [ 4, [ {a: -55, b: 5} ] ]; var v56 = [ 4, [ {a: -56, b: 5} ] ]; var v57 = [ 4, [ {a: -57, b: 5} ] ]; var v58 = [ 4, [ {a: -58, b: 5} ] ]; var v59 = [ 4, [ {a: -59, b: 5} ] ]; var v60 = [ 4, [ {a: -60, b: 5} ] ]; var v61 = [ 4, [ {a: -61, b: 5} ] ]; var v62 = [ 4, [ {a: -62, b: 5} ] ]; var v63 = [ 4, [ {a: -63, b: 5} ] ]; var v64 = [ 4, [ {a: -64, b: 5} ] ]; var v65 = [ 4, [ {a: -65, b: 5} ] ]; var v66 = [ 4, [ {a: -66, b: 5} ] ]; var v67 = [ 4, [ {a: -67, b: 5} ] ]; var v68 = [ 4, [ {a: -68, b: 5} ] ]; var v69 = [ 4, [ {a: -69, b: 5} ] ]; var v70 = [ 4, [ {a: -70, b: 5} ] ]; var v71 = [ 4, [ {a: -71, b: 5} ] ]; var v72 = [ 4, [ {a: -72, b: 5} ] ]; var v73 = [ 4, [ {a: -73, b: 5} ] ]; var v74 = [ 4, [ {a: -74, b: 5} ] ]; var v75 = [ 4, [ {a: -75, b: 5} ] ]; var v76 = [ 4, [ {a: -76, b: 5} ] ]; var v77 = [ 4, [ {a: -77, b: 5} ] ]; var v78 = [ 4, [ {a: -78, b: 5} ] ]; var v79 = [ 4, [ {a: -79, b: 5} ] ]; var v80 = [ 4, [ {a: -80, b: 5} ] ]; var v81 = [ 4, [ {a: -81, b: 5} ] ]; var v82 = [ 4, [ {a: -82, b: 5} ] ]; var v83 = [ 4, [ {a: -83, b: 5} ] ]; var v84 = [ 4, [ {a: -84, b: 5} ] ]; var v85 = [ 4, [ {a: -85, b: 5} ] ]; var v86 = [ 4, [ {a: -86, b: 5} ] ]; var v87 = [ 4, [ {a: -87, b: 5} ] ]; var v88 = [ 4, [ {a: -88, b: 5} ] ]; var v89 = [ 4, [ {a: -89, b: 5} ] ]; var v90 = [ 4, [ {a: -90, b: 5} ] ]; var v91 = [ 4, [ {a: -91, b: 5} ] ]; var v92 = [ 4, [ {a: -92, b: 5} ] ]; var v93 = [ 4, [ {a: -93, b: 5} ] ]; var v94 = [ 4, [ {a: -94, b: 5} ] ]; var v95 = [ 4, [ {a: -95, b: 5} ] ]; var v96 = [ 4, [ {a: -96, b: 5} ] ]; var v97 = [ 4, [ {a: -97, b: 5} ] ]; var v98 = [ 4, [ {a: -98, b: 5} ] ]; var v99 = [ 4, [ {a: -99, b: 5} ] ]; var v100 = [ 4, [ {a: -100, b: 5} ] ]; var v101 = [ 4, [ {a: -101, b: 5} ] ]; var v102 = [ 4, [ {a: -102, b: 5} ] ]; var v103 = [ 4, [ {a: -103, b: 5} ] ]; var v104 = [ 4, [ {a: -104, b: 5} ] ]; var v105 = [ 4, [ {a: -105, b: 5} ] ]; var v106 = [ 4, [ {a: -106, b: 5} ] ]; var v107 = [ 4, [ {a: -107, b: 5} ] ]; var v108 = [ 4, [ {a: -108, b: 5} ] ]; var v109 = [ 4, [ {a: -109, b: 5} ] ]; var v110 = [ 4, [ {a: -110, b: 5} ] ]; var v111 = [ 4, [ {a: -111, b: 5} ] ]; var v112 = [ 4, [ {a: -112, b: 5} ] ]; var v113 = [ 4, [ {a: -113, b: 5} ] ]; var v114 = [ 4, [ {a: -114, b: 5} ] ]; var v115 = [ 4, [ {a: -115, b: 5} ] ]; var v116 = [ 4, [ {a: -116, b: 5} ] ]; var v117 = [ 4, [ {a: -117, b: 5} ] ]; var v118 = [ 4, [ {a: -118, b: 5} ] ]; var v119 = [ 4, [ {a: -119, b: 5} ] ]; var v120 = [ 4, [ {a: -120, b: 5} ] ]; var v121 = [ 4, [ {a: -121, b: 5} ] ]; var v122 = [ 4, [ {a: -122, b: 5} ] ]; var v123 = [ 4, [ {a: -123, b: 5} ] ]; var v124 = [ 4, [ {a: -124, b: 5} ] ]; var v125 = [ 4, [ {a: -125, b: 5} ] ]; var v126 = [ 4, [ {a: -126, b: 5} ] ]; var v127 = [ 4, [ {a: -127, b: 5} ] ]; var v128 = [ 4, [ {a: -128, b: 5} ] ]; var v129 = [ 4, [ {a: -129, b: 5} ] ]; var v130 = [ 4, [ {a: -130, b: 5} ] ]; var v131 = [ 4, [ {a: -131, b: 5} ] ]; var v132 = [ 4, [ {a: -132, b: 5} ] ]; var v133 = [ 4, [ {a: -133, b: 5} ] ]; var v134 = [ 4, [ {a: -134, b: 5} ] ]; var v135 = [ 4, [ {a: -135, b: 5} ] ]; var v136 = [ 4, [ {a: -136, b: 5} ] ]; var v137 = [ 4, [ {a: -137, b: 5} ] ]; var v138 = [ 4, [ {a: -138, b: 5} ] ]; var v139 = [ 4, [ {a: -139, b: 5} ] ]; var v140 = [ 4, [ {a: -140, b: 5} ] ]; var v141 = [ 4, [ {a: -141, b: 5} ] ]; var v142 = [ 4, [ {a: -142, b: 5} ] ]; var v143 = [ 4, [ {a: -143, b: 5} ] ]; var v144 = [ 4, [ {a: -144, b: 5} ] ]; var v145 = [ 4, [ {a: -145, b: 5} ] ]; var v146 = [ 4, [ {a: -146, b: 5} ] ]; var v147 = [ 4, [ {a: -147, b: 5} ] ]; var v148 = [ 4, [ {a: -148, b: 5} ] ]; var v149 = [ 4, [ {a: -149, b: 5} ] ]; var v150 = [ 4, [ {a: -150, b: 5} ] ]; var v151 = [ 4, [ {a: -151, b: 5} ] ]; var v152 = [ 4, [ {a: -152, b: 5} ] ]; var v153 = [ 4, [ {a: -153, b: 5} ] ]; var v154 = [ 4, [ {a: -154, b: 5} ] ]; var v155 = [ 4, [ {a: -155, b: 5} ] ]; var v156 = [ 4, [ {a: -156, b: 5} ] ]; var v157 = [ 4, [ {a: -157, b: 5} ] ]; var v158 = [ 4, [ {a: -158, b: 5} ] ]; var v159 = [ 4, [ {a: -159, b: 5} ] ]; var v160 = [ 4, [ {a: -160, b: 5} ] ]; var v161 = [ 4, [ {a: -161, b: 5} ] ]; var v162 = [ 4, [ {a: -162, b: 5} ] ]; var v163 = [ 4, [ {a: -163, b: 5} ] ]; var v164 = [ 4, [ {a: -164, b: 5} ] ]; var v165 = [ 4, [ {a: -165, b: 5} ] ]; var v166 = [ 4, [ {a: -166, b: 5} ] ]; var v167 = [ 4, [ {a: -167, b: 5} ] ]; var v168 = [ 4, [ {a: -168, b: 5} ] ]; var v169 = [ 4, [ {a: -169, b: 5} ] ]; var v170 = [ 4, [ {a: -170, b: 5} ] ]; var v171 = [ 4, [ {a: -171, b: 5} ] ]; var v172 = [ 4, [ {a: -172, b: 5} ] ]; var v173 = [ 4, [ {a: -173, b: 5} ] ]; var v174 = [ 4, [ {a: -174, b: 5} ] ]; var v175 = [ 4, [ {a: -175, b: 5} ] ]; var v176 = [ 4, [ {a: -176, b: 5} ] ]; var v177 = [ 4, [ {a: -177, b: 5} ] ]; var v178 = [ 4, [ {a: -178, b: 5} ] ]; var v179 = [ 4, [ {a: -179, b: 5} ] ]; var v180 = [ 4, [ {a: -180, b: 5} ] ]; var v181 = [ 4, [ {a: -181, b: 5} ] ]; var v182 = [ 4, [ {a: -182, b: 5} ] ]; var v183 = [ 4, [ {a: -183, b: 5} ] ]; var v184 = [ 4, [ {a: -184, b: 5} ] ]; var v185 = [ 4, [ {a: -185, b: 5} ] ]; var v186 = [ 4, [ {a: -186, b: 5} ] ]; var v187 = [ 4, [ {a: -187, b: 5} ] ]; var v188 = [ 4, [ {a: -188, b: 5} ] ]; var v189 = [ 4, [ {a: -189, b: 5} ] ]; var v190 = [ 4, [ {a: -190, b: 5} ] ]; var v191 = [ 4, [ {a: -191, b: 5} ] ]; var v192 = [ 4, [ {a: -192, b: 5} ] ]; var v193 = [ 4, [ {a: -193, b: 5} ] ]; var v194 = [ 4, [ {a: -194, b: 5} ] ]; var v195 = [ 4, [ {a: -195, b: 5} ] ]; var v196 = [ 4, [ {a: -196, b: 5} ] ]; var v197 = [ 4, [ {a: -197, b: 5} ] ]; var v198 = [ 4, [ {a: -198, b: 5} ] ]; var v199 = [ 4, [ {a: -199, b: 5} ] ]; var v200 = [ 4, [ {a: -200, b: 5} ] ]; var v201 = [ 4, [ {a: -201, b: 5} ] ]; var v202 = [ 4, [ {a: -202, b: 5} ] ]; var v203 = [ 4, [ {a: -203, b: 5} ] ]; var v204 = [ 4, [ {a: -204, b: 5} ] ]; var v205 = [ 4, [ {a: -205, b: 5} ] ]; var v206 = [ 4, [ {a: -206, b: 5} ] ]; var v207 = [ 4, [ {a: -207, b: 5} ] ]; var v208 = [ 4, [ {a: -208, b: 5} ] ]; var v209 = [ 4, [ {a: -209, b: 5} ] ]; var v210 = [ 4, [ {a: -210, b: 5} ] ]; var v211 = [ 4, [ {a: -211, b: 5} ] ]; var v212 = [ 4, [ {a: -212, b: 5} ] ]; var v213 = [ 4, [ {a: -213, b: 5} ] ]; var v214 = [ 4, [ {a: -214, b: 5} ] ]; var v215 = [ 4, [ {a: -215, b: 5} ] ]; var v216 = [ 4, [ {a: -216, b: 5} ] ]; var v217 = [ 4, [ {a: -217, b: 5} ] ]; var v218 = [ 4, [ {a: -218, b: 5} ] ]; var v219 = [ 4, [ {a: -219, b: 5} ] ]; var v220 = [ 4, [ {a: -220, b: 5} ] ]; var v221 = [ 4, [ {a: -221, b: 5} ] ]; var v222 = [ 4, [ {a: -222, b: 5} ] ]; var v223 = [ 4, [ {a: -223, b: 5} ] ]; var v224 = [ 4, [ {a: -224, b: 5} ] ]; var v225 = [ 4, [ {a: -225, b: 5} ] ]; var v226 = [ 4, [ {a: -226, b: 5} ] ]; var v227 = [ 4, [ {a: -227, b: 5} ] ]; var v228 = [ 4, [ {a: -228, b: 5} ] ]; var v229 = [ 4, [ {a: -229, b: 5} ] ]; var v230 = [ 4, [ {a: -230, b: 5} ] ]; var v231 = [ 4, [ {a: -231, b: 5} ] ]; var v232 = [ 4, [ {a: -232, b: 5} ] ]; var v233 = [ 4, [ {a: -233, b: 5} ] ]; var v234 = [ 4, [ {a: -234, b: 5} ] ]; var v235 = [ 4, [ {a: -235, b: 5} ] ]; var v236 = [ 4, [ {a: -236, b: 5} ] ]; var v237 = [ 4, [ {a: -237, b: 5} ] ]; var v238 = [ 4, [ {a: -238, b: 5} ] ]; var v239 = [ 4, [ {a: -239, b: 5} ] ]; var v240 = [ 4, [ {a: -240, b: 5} ] ]; var v241 = [ 4, [ {a: -241, b: 5} ] ]; var v242 = [ 4, [ {a: -242, b: 5} ] ]; var v243 = [ 4, [ {a: -243, b: 5} ] ]; var v244 = [ 4, [ {a: -244, b: 5} ] ]; var v245 = [ 4, [ {a: -245, b: 5} ] ]; var v246 = [ 4, [ {a: -246, b: 5} ] ]; var v247 = [ 4, [ {a: -247, b: 5} ] ]; var v248 = [ 4, [ {a: -248, b: 5} ] ]; var v249 = [ 4, [ {a: -249, b: 5} ] ]; var v250 = [ 4, [ {a: -250, b: 5} ] ]; var v251 = [ 4, [ {a: -251, b: 5} ] ]; var v252 = [ 4, [ {a: -252, b: 5} ] ]; var v253 = [ 4, [ {a: -253, b: 5} ] ]; var v254 = [ 4, [ {a: -254, b: 5} ] ]; var v255 = [ 4, [ {a: -255, b: 5} ] ]; var v256 = [ 4, [ {a: -256, b: 5} ] ]; var v257 = [ 4, [ {a: -257, b: 5} ] ]; var v258 = [ 4, [ {a: -258, b: 5} ] ]; var v259 = [ 4, [ {a: -259, b: 5} ] ]; var v260 = [ 4, [ {a: -260, b: 5} ] ]; var v261 = [ 4, [ {a: -261, b: 5} ] ]; var v262 = [ 4, [ {a: -262, b: 5} ] ]; var v263 = [ 4, [ {a: -263, b: 5} ] ]; var v264 = [ 4, [ {a: -264, b: 5} ] ]; var v265 = [ 4, [ {a: -265, b: 5} ] ]; var v266 = [ 4, [ {a: -266, b: 5} ] ]; var v267 = [ 4, [ {a: -267, b: 5} ] ]; var v268 = [ 4, [ {a: -268, b: 5} ] ]; var v269 = [ 4, [ {a: -269, b: 5} ] ]; var v270 = [ 4, [ {a: -270, b: 5} ] ]; var v271 = [ 4, [ {a: -271, b: 5} ] ]; var v272 = [ 4, [ {a: -272, b: 5} ] ]; var v273 = [ 4, [ {a: -273, b: 5} ] ]; var v274 = [ 4, [ {a: -274, b: 5} ] ]; var v275 = [ 4, [ {a: -275, b: 5} ] ]; var v276 = [ 4, [ {a: -276, b: 5} ] ]; var v277 = [ 4, [ {a: -277, b: 5} ] ]; var v278 = [ 4, [ {a: -278, b: 5} ] ]; var v279 = [ 4, [ {a: -279, b: 5} ] ]; var v280 = [ 4, [ {a: -280, b: 5} ] ]; var v281 = [ 4, [ {a: -281, b: 5} ] ]; var v282 = [ 4, [ {a: -282, b: 5} ] ]; var v283 = [ 4, [ {a: -283, b: 5} ] ]; var v284 = [ 4, [ {a: -284, b: 5} ] ]; var v285 = [ 4, [ {a: -285, b: 5} ] ]; var v286 = [ 4, [ {a: -286, b: 5} ] ]; var v287 = [ 4, [ {a: -287, b: 5} ] ]; var v288 = [ 4, [ {a: -288, b: 5} ] ]; var v289 = [ 4, [ {a: -289, b: 5} ] ]; var v290 = [ 4, [ {a: -290, b: 5} ] ]; var v291 = [ 4, [ {a: -291, b: 5} ] ]; var v292 = [ 4, [ {a: -292, b: 5} ] ]; var v293 = [ 4, [ {a: -293, b: 5} ] ]; var v294 = [ 4, [ {a: -294, b: 5} ] ]; var v295 = [ 4, [ {a: -295, b: 5} ] ]; var v296 = [ 4, [ {a: -296, b: 5} ] ]; var v297 = [ 4, [ {a: -297, b: 5} ] ]; var v298 = [ 4, [ {a: -298, b: 5} ] ]; var v299 = [ 4, [ {a: -299, b: 5} ] ]; var v300 = [ 4, [ {a: -300, b: 5} ] ]; var v301 = [ 4, [ {a: -301, b: 5} ] ]; var v302 = [ 4, [ {a: -302, b: 5} ] ]; var v303 = [ 4, [ {a: -303, b: 5} ] ]; var v304 = [ 4, [ {a: -304, b: 5} ] ]; var v305 = [ 4, [ {a: -305, b: 5} ] ]; var v306 = [ 4, [ {a: -306, b: 5} ] ]; var v307 = [ 4, [ {a: -307, b: 5} ] ]; var v308 = [ 4, [ {a: -308, b: 5} ] ]; var v309 = [ 4, [ {a: -309, b: 5} ] ]; var v310 = [ 4, [ {a: -310, b: 5} ] ]; var v311 = [ 4, [ {a: -311, b: 5} ] ]; var v312 = [ 4, [ {a: -312, b: 5} ] ]; var v313 = [ 4, [ {a: -313, b: 5} ] ]; var v314 = [ 4, [ {a: -314, b: 5} ] ]; var v315 = [ 4, [ {a: -315, b: 5} ] ]; var v316 = [ 4, [ {a: -316, b: 5} ] ]; var v317 = [ 4, [ {a: -317, b: 5} ] ]; var v318 = [ 4, [ {a: -318, b: 5} ] ]; var v319 = [ 4, [ {a: -319, b: 5} ] ]; var v320 = [ 4, [ {a: -320, b: 5} ] ]; var v321 = [ 4, [ {a: -321, b: 5} ] ]; var v322 = [ 4, [ {a: -322, b: 5} ] ]; var v323 = [ 4, [ {a: -323, b: 5} ] ]; var v324 = [ 4, [ {a: -324, b: 5} ] ]; var v325 = [ 4, [ {a: -325, b: 5} ] ]; var v326 = [ 4, [ {a: -326, b: 5} ] ]; var v327 = [ 4, [ {a: -327, b: 5} ] ]; var v328 = [ 4, [ {a: -328, b: 5} ] ]; var v329 = [ 4, [ {a: -329, b: 5} ] ]; var v330 = [ 4, [ {a: -330, b: 5} ] ]; var v331 = [ 4, [ {a: -331, b: 5} ] ]; var v332 = [ 4, [ {a: -332, b: 5} ] ]; var v333 = [ 4, [ {a: -333, b: 5} ] ]; var v334 = [ 4, [ {a: -334, b: 5} ] ]; var v335 = [ 4, [ {a: -335, b: 5} ] ]; var v336 = [ 4, [ {a: -336, b: 5} ] ]; var v337 = [ 4, [ {a: -337, b: 5} ] ]; var v338 = [ 4, [ {a: -338, b: 5} ] ]; var v339 = [ 4, [ {a: -339, b: 5} ] ]; var v340 = [ 4, [ {a: -340, b: 5} ] ]; var v341 = [ 4, [ {a: -341, b: 5} ] ]; var v342 = [ 4, [ {a: -342, b: 5} ] ]; var v343 = [ 4, [ {a: -343, b: 5} ] ]; var v344 = [ 4, [ {a: -344, b: 5} ] ]; var v345 = [ 4, [ {a: -345, b: 5} ] ]; var v346 = [ 4, [ {a: -346, b: 5} ] ]; var v347 = [ 4, [ {a: -347, b: 5} ] ]; var v348 = [ 4, [ {a: -348, b: 5} ] ]; var v349 = [ 4, [ {a: -349, b: 5} ] ]; var v350 = [ 4, [ {a: -350, b: 5} ] ]; var v351 = [ 4, [ {a: -351, b: 5} ] ]; var v352 = [ 4, [ {a: -352, b: 5} ] ]; var v353 = [ 4, [ {a: -353, b: 5} ] ]; var v354 = [ 4, [ {a: -354, b: 5} ] ]; var v355 = [ 4, [ {a: -355, b: 5} ] ]; var v356 = [ 4, [ {a: -356, b: 5} ] ]; var v357 = [ 4, [ {a: -357, b: 5} ] ]; var v358 = [ 4, [ {a: -358, b: 5} ] ]; var v359 = [ 4, [ {a: -359, b: 5} ] ]; var v360 = [ 4, [ {a: -360, b: 5} ] ]; var v361 = [ 4, [ {a: -361, b: 5} ] ]; var v362 = [ 4, [ {a: -362, b: 5} ] ]; var v363 = [ 4, [ {a: -363, b: 5} ] ]; var v364 = [ 4, [ {a: -364, b: 5} ] ]; var v365 = [ 4, [ {a: -365, b: 5} ] ]; var v366 = [ 4, [ {a: -366, b: 5} ] ]; var v367 = [ 4, [ {a: -367, b: 5} ] ]; var v368 = [ 4, [ {a: -368, b: 5} ] ]; var v369 = [ 4, [ {a: -369, b: 5} ] ]; var v370 = [ 4, [ {a: -370, b: 5} ] ]; var v371 = [ 4, [ {a: -371, b: 5} ] ]; var v372 = [ 4, [ {a: -372, b: 5} ] ]; var v373 = [ 4, [ {a: -373, b: 5} ] ]; var v374 = [ 4, [ {a: -374, b: 5} ] ]; var v375 = [ 4, [ {a: -375, b: 5} ] ]; var v376 = [ 4, [ {a: -376, b: 5} ] ]; var v377 = [ 4, [ {a: -377, b: 5} ] ]; var v378 = [ 4, [ {a: -378, b: 5} ] ]; var v379 = [ 4, [ {a: -379, b: 5} ] ]; var v380 = [ 4, [ {a: -380, b: 5} ] ]; var v381 = [ 4, [ {a: -381, b: 5} ] ]; var v382 = [ 4, [ {a: -382, b: 5} ] ]; var v383 = [ 4, [ {a: -383, b: 5} ] ]; var v384 = [ 4, [ {a: -384, b: 5} ] ]; var v385 = [ 4, [ {a: -385, b: 5} ] ]; var v386 = [ 4, [ {a: -386, b: 5} ] ]; var v387 = [ 4, [ {a: -387, b: 5} ] ]; var v388 = [ 4, [ {a: -388, b: 5} ] ]; var v389 = [ 4, [ {a: -389, b: 5} ] ]; var v390 = [ 4, [ {a: -390, b: 5} ] ]; var v391 = [ 4, [ {a: -391, b: 5} ] ]; var v392 = [ 4, [ {a: -392, b: 5} ] ]; var v393 = [ 4, [ {a: -393, b: 5} ] ]; var v394 = [ 4, [ {a: -394, b: 5} ] ]; var v395 = [ 4, [ {a: -395, b: 5} ] ]; var v396 = [ 4, [ {a: -396, b: 5} ] ]; var v397 = [ 4, [ {a: -397, b: 5} ] ]; var v398 = [ 4, [ {a: -398, b: 5} ] ]; var v399 = [ 4, [ {a: -399, b: 5} ] ]; var v400 = [ 4, [ {a: -400, b: 5} ] ]; var v401 = [ 4, [ {a: -401, b: 5} ] ]; var v402 = [ 4, [ {a: -402, b: 5} ] ]; var v403 = [ 4, [ {a: -403, b: 5} ] ]; var v404 = [ 4, [ {a: -404, b: 5} ] ]; var v405 = [ 4, [ {a: -405, b: 5} ] ]; var v406 = [ 4, [ {a: -406, b: 5} ] ]; var v407 = [ 4, [ {a: -407, b: 5} ] ]; var v408 = [ 4, [ {a: -408, b: 5} ] ]; var v409 = [ 4, [ {a: -409, b: 5} ] ]; var v410 = [ 4, [ {a: -410, b: 5} ] ]; var v411 = [ 4, [ {a: -411, b: 5} ] ]; var v412 = [ 4, [ {a: -412, b: 5} ] ]; var v413 = [ 4, [ {a: -413, b: 5} ] ]; var v414 = [ 4, [ {a: -414, b: 5} ] ]; var v415 = [ 4, [ {a: -415, b: 5} ] ]; var v416 = [ 4, [ {a: -416, b: 5} ] ]; var v417 = [ 4, [ {a: -417, b: 5} ] ]; var v418 = [ 4, [ {a: -418, b: 5} ] ]; var v419 = [ 4, [ {a: -419, b: 5} ] ]; var v420 = [ 4, [ {a: -420, b: 5} ] ]; var v421 = [ 4, [ {a: -421, b: 5} ] ]; var v422 = [ 4, [ {a: -422, b: 5} ] ]; var v423 = [ 4, [ {a: -423, b: 5} ] ]; var v424 = [ 4, [ {a: -424, b: 5} ] ]; var v425 = [ 4, [ {a: -425, b: 5} ] ]; var v426 = [ 4, [ {a: -426, b: 5} ] ]; var v427 = [ 4, [ {a: -427, b: 5} ] ]; var v428 = [ 4, [ {a: -428, b: 5} ] ]; var v429 = [ 4, [ {a: -429, b: 5} ] ]; var v430 = [ 4, [ {a: -430, b: 5} ] ]; var v431 = [ 4, [ {a: -431, b: 5} ] ]; var v432 = [ 4, [ {a: -432, b: 5} ] ]; var v433 = [ 4, [ {a: -433, b: 5} ] ]; var v434 = [ 4, [ {a: -434, b: 5} ] ]; var v435 = [ 4, [ {a: -435, b: 5} ] ]; var v436 = [ 4, [ {a: -436, b: 5} ] ]; var v437 = [ 4, [ {a: -437, b: 5} ] ]; var v438 = [ 4, [ {a: -438, b: 5} ] ]; var v439 = [ 4, [ {a: -439, b: 5} ] ]; var v440 = [ 4, [ {a: -440, b: 5} ] ]; var v441 = [ 4, [ {a: -441, b: 5} ] ]; var v442 = [ 4, [ {a: -442, b: 5} ] ]; var v443 = [ 4, [ {a: -443, b: 5} ] ]; var v444 = [ 4, [ {a: -444, b: 5} ] ]; var v445 = [ 4, [ {a: -445, b: 5} ] ]; var v446 = [ 4, [ {a: -446, b: 5} ] ]; var v447 = [ 4, [ {a: -447, b: 5} ] ]; var v448 = [ 4, [ {a: -448, b: 5} ] ]; var v449 = [ 4, [ {a: -449, b: 5} ] ]; var v450 = [ 4, [ {a: -450, b: 5} ] ]; var v451 = [ 4, [ {a: -451, b: 5} ] ]; var v452 = [ 4, [ {a: -452, b: 5} ] ]; var v453 = [ 4, [ {a: -453, b: 5} ] ]; var v454 = [ 4, [ {a: -454, b: 5} ] ]; var v455 = [ 4, [ {a: -455, b: 5} ] ]; var v456 = [ 4, [ {a: -456, b: 5} ] ]; var v457 = [ 4, [ {a: -457, b: 5} ] ]; var v458 = [ 4, [ {a: -458, b: 5} ] ]; var v459 = [ 4, [ {a: -459, b: 5} ] ]; var v460 = [ 4, [ {a: -460, b: 5} ] ]; var v461 = [ 4, [ {a: -461, b: 5} ] ]; var v462 = [ 4, [ {a: -462, b: 5} ] ]; var v463 = [ 4, [ {a: -463, b: 5} ] ]; var v464 = [ 4, [ {a: -464, b: 5} ] ]; var v465 = [ 4, [ {a: -465, b: 5} ] ]; var v466 = [ 4, [ {a: -466, b: 5} ] ]; var v467 = [ 4, [ {a: -467, b: 5} ] ]; var v468 = [ 4, [ {a: -468, b: 5} ] ]; var v469 = [ 4, [ {a: -469, b: 5} ] ]; var v470 = [ 4, [ {a: -470, b: 5} ] ]; var v471 = [ 4, [ {a: -471, b: 5} ] ]; var v472 = [ 4, [ {a: -472, b: 5} ] ]; var v473 = [ 4, [ {a: -473, b: 5} ] ]; var v474 = [ 4, [ {a: -474, b: 5} ] ]; var v475 = [ 4, [ {a: -475, b: 5} ] ]; var v476 = [ 4, [ {a: -476, b: 5} ] ]; var v477 = [ 4, [ {a: -477, b: 5} ] ]; var v478 = [ 4, [ {a: -478, b: 5} ] ]; var v479 = [ 4, [ {a: -479, b: 5} ] ]; var v480 = [ 4, [ {a: -480, b: 5} ] ]; var v481 = [ 4, [ {a: -481, b: 5} ] ]; var v482 = [ 4, [ {a: -482, b: 5} ] ]; var v483 = [ 4, [ {a: -483, b: 5} ] ]; var v484 = [ 4, [ {a: -484, b: 5} ] ]; var v485 = [ 4, [ {a: -485, b: 5} ] ]; var v486 = [ 4, [ {a: -486, b: 5} ] ]; var v487 = [ 4, [ {a: -487, b: 5} ] ]; var v488 = [ 4, [ {a: -488, b: 5} ] ]; var v489 = [ 4, [ {a: -489, b: 5} ] ]; var v490 = [ 4, [ {a: -490, b: 5} ] ]; var v491 = [ 4, [ {a: -491, b: 5} ] ]; var v492 = [ 4, [ {a: -492, b: 5} ] ]; var v493 = [ 4, [ {a: -493, b: 5} ] ]; var v494 = [ 4, [ {a: -494, b: 5} ] ]; var v495 = [ 4, [ {a: -495, b: 5} ] ]; var v496 = [ 4, [ {a: -496, b: 5} ] ]; var v497 = [ 4, [ {a: -497, b: 5} ] ]; var v498 = [ 4, [ {a: -498, b: 5} ] ]; var v499 = [ 4, [ {a: -499, b: 5} ] ]; var v500 = [ 4, [ {a: -500, b: 5} ] ]; var unused = { p1: v1, p2: v2, p3: v3, p4: v4, p5: v5, p6: v6, p7: v7, p8: v8, p9: v9, p10: v10, p11: v11, p12: v12, p13: v13, p14: v14, p15: v15, p16: v16, p17: v17, p18: v18, p19: v19, p20: v20, p21: v21, p22: v22, p23: v23, p24: v24, p25: v25, p26: v26, p27: v27, p28: v28, p29: v29, p30: v30, p31: v31, p32: v32, p33: v33, p34: v34, p35: v35, p36: v36, p37: v37, p38: v38, p39: v39, p40: v40, p41: v41, p42: v42, p43: v43, p44: v44, p45: v45, p46: v46, p47: v47, p48: v48, p49: v49, p50: v50, p51: v51, p52: v52, p53: v53, p54: v54, p55: v55, p56: v56, p57: v57, p58: v58, p59: v59, p60: v60, p61: v61, p62: v62, p63: v63, p64: v64, p65: v65, p66: v66, p67: v67, p68: v68, p69: v69, p70: v70, p71: v71, p72: v72, p73: v73, p74: v74, p75: v75, p76: v76, p77: v77, p78: v78, p79: v79, p80: v80, p81: v81, p82: v82, p83: v83, p84: v84, p85: v85, p86: v86, p87: v87, p88: v88, p89: v89, p90: v90, p91: v91, p92: v92, p93: v93, p94: v94, p95: v95, p96: v96, p97: v97, p98: v98, p99: v99, p100: v100, p101: v101, p102: v102, p103: v103, p104: v104, p105: v105, p106: v106, p107: v107, p108: v108, p109: v109, p110: v110, p111: v111, p112: v112, p113: v113, p114: v114, p115: v115, p116: v116, p117: v117, p118: v118, p119: v119, p120: v120, p121: v121, p122: v122, p123: v123, p124: v124, p125: v125, p126: v126, p127: v127, p128: v128, p129: v129, p130: v130, p131: v131, p132: v132, p133: v133, p134: v134, p135: v135, p136: v136, p137: v137, p138: v138, p139: v139, p140: v140, p141: v141, p142: v142, p143: v143, p144: v144, p145: v145, p146: v146, p147: v147, p148: v148, p149: v149, p150: v150, p151: v151, p152: v152, p153: v153, p154: v154, p155: v155, p156: v156, p157: v157, p158: v158, p159: v159, p160: v160, p161: v161, p162: v162, p163: v163, p164: v164, p165: v165, p166: v166, p167: v167, p168: v168, p169: v169, p170: v170, p171: v171, p172: v172, p173: v173, p174: v174, p175: v175, p176: v176, p177: v177, p178: v178, p179: v179, p180: v180, p181: v181, p182: v182, p183: v183, p184: v184, p185: v185, p186: v186, p187: v187, p188: v188, p189: v189, p190: v190, p191: v191, p192: v192, p193: v193, p194: v194, p195: v195, p196: v196, p197: v197, p198: v198, p199: v199, p200: v200, p201: v201, p202: v202, p203: v203, p204: v204, p205: v205, p206: v206, p207: v207, p208: v208, p209: v209, p210: v210, p211: v211, p212: v212, p213: v213, p214: v214, p215: v215, p216: v216, p217: v217, p218: v218, p219: v219, p220: v220, p221: v221, p222: v222, p223: v223, p224: v224, p225: v225, p226: v226, p227: v227, p228: v228, p229: v229, p230: v230, p231: v231, p232: v232, p233: v233, p234: v234, p235: v235, p236: v236, p237: v237, p238: v238, p239: v239, p240: v240, p241: v241, p242: v242, p243: v243, p244: v244, p245: v245, p246: v246, p247: v247, p248: v248, p249: v249, p250: v250, p251: v251, p252: v252, p253: v253, p254: v254, p255: v255, p256: v256, p257: v257, p258: v258, p259: v259, p260: v260, p261: v261, p262: v262, p263: v263, p264: v264, p265: v265, p266: v266, p267: v267, p268: v268, p269: v269, p270: v270, p271: v271, p272: v272, p273: v273, p274: v274, p275: v275, p276: v276, p277: v277, p278: v278, p279: v279, p280: v280, p281: v281, p282: v282, p283: v283, p284: v284, p285: v285, p286: v286, p287: v287, p288: v288, p289: v289, p290: v290, p291: v291, p292: v292, p293: v293, p294: v294, p295: v295, p296: v296, p297: v297, p298: v298, p299: v299, p300: v300, p301: v301, p302: v302, p303: v303, p304: v304, p305: v305, p306: v306, p307: v307, p308: v308, p309: v309, p310: v310, p311: v311, p312: v312, p313: v313, p314: v314, p315: v315, p316: v316, p317: v317, p318: v318, p319: v319, p320: v320, p321: v321, p322: v322, p323: v323, p324: v324, p325: v325, p326: v326, p327: v327, p328: v328, p329: v329, p330: v330, p331: v331, p332: v332, p333: v333, p334: v334, p335: v335, p336: v336, p337: v337, p338: v338, p339: v339, p340: v340, p341: v341, p342: v342, p343: v343, p344: v344, p345: v345, p346: v346, p347: v347, p348: v348, p349: v349, p350: v350, p351: v351, p352: v352, p353: v353, p354: v354, p355: v355, p356: v356, p357: v357, p358: v358, p359: v359, p360: v360, p361: v361, p362: v362, p363: v363, p364: v364, p365: v365, p366: v366, p367: v367, p368: v368, p369: v369, p370: v370, p371: v371, p372: v372, p373: v373, p374: v374, p375: v375, p376: v376, p377: v377, p378: v378, p379: v379, p380: v380, p381: v381, p382: v382, p383: v383, p384: v384, p385: v385, p386: v386, p387: v387, p388: v388, p389: v389, p390: v390, p391: v391, p392: v392, p393: v393, p394: v394, p395: v395, p396: v396, p397: v397, p398: v398, p399: v399, p400: v400, p401: v401, p402: v402, p403: v403, p404: v404, p405: v405, p406: v406, p407: v407, p408: v408, p409: v409, p410: v410, p411: v411, p412: v412, p413: v413, p414: v414, p415: v415, p416: v416, p417: v417, p418: v418, p419: v419, p420: v420, p421: v421, p422: v422, p423: v423, p424: v424, p425: v425, p426: v426, p427: v427, p428: v428, p429: v429, p430: v430, p431: v431, p432: v432, p433: v433, p434: v434, p435: v435, p436: v436, p437: v437, p438: v438, p439: v439, p440: v440, p441: v441, p442: v442, p443: v443, p444: v444, p445: v445, p446: v446, p447: v447, p448: v448, p449: v449, p450: v450, p451: v451, p452: v452, p453: v453, p454: v454, p455: v455, p456: v456, p457: v457, p458: v458, p459: v459, p460: v460, p461: v461, p462: v462, p463: v463, p464: v464, p465: v465, p466: v466, p467: v467, p468: v468, p469: v469, p470: v470, p471: v471, p472: v472, p473: v473, p474: v474, p475: v475, p476: v476, p477: v477, p478: v478, p479: v479, p480: v480, p481: v481, p482: v482, p483: v483, p484: v484, p485: v485, p486: v486, p487: v487, p488: v488, p489: v489, p490: v490, p491: v491, p492: v492, p493: v493, p494: v494, p495: v495, p496: v496, p497: v497, p498: v498, p499: v499, p500: v500, }; console.log(v1[1][0].a, v10[1][0].a); })(); } expect: { console.log(-1, -10); } expect_stdout: "-1 -10" } issue_t50_let: { options = { defaults: true, passes: 2, } input: { (function() { let v1 = [ 4, [ {a: -1, b: 5} ] ]; let v2 = [ 4, [ {a: -2, b: 5} ] ]; let v3 = [ 4, [ {a: -3, b: 5} ] ]; let v4 = [ 4, [ {a: -4, b: 5} ] ]; let v5 = [ 4, [ {a: -5, b: 5} ] ]; let v6 = [ 4, [ {a: -6, b: 5} ] ]; let v7 = [ 4, [ {a: -7, b: 5} ] ]; let v8 = [ 4, [ {a: -8, b: 5} ] ]; let v9 = [ 4, [ {a: -9, b: 5} ] ]; let v10 = [ 4, [ {a: -10, b: 5} ] ]; let v11 = [ 4, [ {a: -11, b: 5} ] ]; let v12 = [ 4, [ {a: -12, b: 5} ] ]; let v13 = [ 4, [ {a: -13, b: 5} ] ]; let v14 = [ 4, [ {a: -14, b: 5} ] ]; let v15 = [ 4, [ {a: -15, b: 5} ] ]; let v16 = [ 4, [ {a: -16, b: 5} ] ]; let v17 = [ 4, [ {a: -17, b: 5} ] ]; let v18 = [ 4, [ {a: -18, b: 5} ] ]; let v19 = [ 4, [ {a: -19, b: 5} ] ]; let v20 = [ 4, [ {a: -20, b: 5} ] ]; let unused = { p1: v1, p2: v2, p3: v3, p4: v4, p5: v5, p6: v6, p7: v7, p8: v8, p9: v9, p10: v10, p11: v11, p12: v12, p13: v13, p14: v14, p15: v15, p16: v16, p17: v17, p18: v18, p19: v19, p20: v20, }; console.log(v1[1][0].a, v10[1][0].a); })(); } expect: { console.log(-1, -10); } expect_stdout: "-1 -10" } issue_t50_const: { options = { defaults: true, passes: 2, } input: { (function() { const v1 = [ 4, [ {a: -1, b: 5} ] ]; const v2 = [ 4, [ {a: -2, b: 5} ] ]; const v3 = [ 4, [ {a: -3, b: 5} ] ]; const v4 = [ 4, [ {a: -4, b: 5} ] ]; const v5 = [ 4, [ {a: -5, b: 5} ] ]; const v6 = [ 4, [ {a: -6, b: 5} ] ]; const v7 = [ 4, [ {a: -7, b: 5} ] ]; const v8 = [ 4, [ {a: -8, b: 5} ] ]; const v9 = [ 4, [ {a: -9, b: 5} ] ]; const v10 = [ 4, [ {a: -10, b: 5} ] ]; const v11 = [ 4, [ {a: -11, b: 5} ] ]; const v12 = [ 4, [ {a: -12, b: 5} ] ]; const v13 = [ 4, [ {a: -13, b: 5} ] ]; const v14 = [ 4, [ {a: -14, b: 5} ] ]; const v15 = [ 4, [ {a: -15, b: 5} ] ]; const v16 = [ 4, [ {a: -16, b: 5} ] ]; const v17 = [ 4, [ {a: -17, b: 5} ] ]; const v18 = [ 4, [ {a: -18, b: 5} ] ]; const v19 = [ 4, [ {a: -19, b: 5} ] ]; const v20 = [ 4, [ {a: -20, b: 5} ] ]; const unused = { p1: v1, p2: v2, p3: v3, p4: v4, p5: v5, p6: v6, p7: v7, p8: v8, p9: v9, p10: v10, p11: v11, p12: v12, p13: v13, p14: v14, p15: v15, p16: v16, p17: v17, p18: v18, p19: v19, p20: v20, }; console.log(v1[1][0].a, v10[1][0].a); })(); } expect: { console.log(-1, -10); } expect_stdout: "-1 -10" } terser-4.1.2/test/compress/join-vars.js000066400000000000000000000016661351061312300201060ustar00rootroot00000000000000only_vars: { options = { join_vars: true }; input: { let netmaskBinary = ''; for (let i = 0; i < netmaskBits; ++i) { netmaskBinary += '1'; } } expect: { let netmaskBinary = ''; for (let i = 0; i < netmaskBits; ++i) netmaskBinary += '1'; } } issue_1079_with_vars: { options = { join_vars: true }; input: { var netmaskBinary = ''; for (var i = 0; i < netmaskBits; ++i) { netmaskBinary += '1'; } } expect: { for (var netmaskBinary = '', i = 0; i < netmaskBits; ++i) netmaskBinary += '1'; } } issue_1079_with_mixed: { options = { join_vars: true }; input: { var netmaskBinary = ''; for (let i = 0; i < netmaskBits; ++i) { netmaskBinary += '1'; } } expect: { var netmaskBinary = '' for (let i = 0; i < netmaskBits; ++i) netmaskBinary += '1'; } }terser-4.1.2/test/compress/keep_names.js000066400000000000000000000043761351061312300203060ustar00rootroot00000000000000drop_fnames: { mangle = { keep_fnames : false, } input: { function foo() { function bar() { return "foobar"; } } } expect: { function foo() { function o() { return "foobar"; } } } } keep_fnames: { mangle = { keep_fnames: true, } input: { function foo() { function bar() { return "foobar"; } } } expect: { function foo() { function bar() { return "foobar"; } } } } drop_classnames: { mangle = { keep_classnames : false, } input: { function foo() { class Bar {} } } expect: { function foo() { class o {} } } } keep_classnames: { mangle = { keep_classnames: true, } input: { function foo() { class Bar {} } } expect: { function foo() { class Bar {} } } } keep_some_fnames: { mangle = { keep_fnames: /Element$/, } input: { function foo() { function bar() {} function barElement() {} } } expect: { function foo() { function n() {} function barElement() {} } } } keep_some_fnames_reduce: { options = { reduce_vars: true, unused: true, keep_fnames: /Element$/, } mangle = { keep_fnames: /Element$/, } input: { function foo() { var array = []; function bar() {} array.map(bar); function barElement() {} array.map(barElement); } } expect: { function foo() { var n = []; n.map(function() {}); n.map(function barElement() {}); } } } keep_some_classnames: { mangle = { keep_classnames: /Element$/, } input: { function foo() { class Bar {} class BarElement {} } } expect: { function foo() { class s {} class BarElement {} } } } terser-4.1.2/test/compress/keep_quoted_strict.js000066400000000000000000000033431351061312300220650ustar00rootroot00000000000000keep_quoted_strict: { options = { evaluate: true, properties: true, }, mangle = { properties: { keep_quoted: "strict", reserved: ["propc", "propd"], }, } input: { var a = { propa: 1, get propb() { return 2; }, propc: 3, get propd() { return 4; }, }; var b = { "propa": 5, get "propb"() { return 6; }, "propc": 7, get "propd"() { return 8; }, }; var c = {}; Object.defineProperty(c, "propa", {"value": 9}); Object.defineProperty(c, "propc", {"value": 10}); console.log(a.propa, a.propb, a.propc, a["propc"], a.propd, a["propd"]); console.log(b["propa"], b["propb"], b.propc, b["propc"], b.propd, b["propd"]); console.log(c.propa, c["propc"]); } expect: { var a = { p: 1, get o() { return 2; }, propc: 3, get propd() { return 4; } }; var b = { propa: 5, get propb() { return 6; }, propc: 7, get propd() { return 8; } }; var c = {}; Object.defineProperty(c, "p", { value: 9 }); Object.defineProperty(c, "propc", { value: 10 }); console.log(a.p, a.o, a.propc, a.propc, a.propd, a.propd); console.log(b.propa, b.propb, b.propc, b.propc, b.propd, b.propd); console.log(c.p, c.propc); } expect_stdout: [ "1 2 3 3 4 4", "5 6 7 7 8 8", "9 10", ] } terser-4.1.2/test/compress/labels.js000066400000000000000000000065441351061312300174400ustar00rootroot00000000000000labels_1: { options = { conditionals: true, dead_code: true, if_return: true, } input: { out: { if (foo) break out; console.log("bar"); } }; expect: { foo || console.log("bar"); } expect_stdout: true } labels_2: { options = { conditionals: true, dead_code: true, if_return: true, } input: { out: { if (foo) print("stuff"); else break out; console.log("here"); } }; expect: { if (foo) { print("stuff"); console.log("here"); } } } labels_3: { options = { conditionals: true, dead_code: true, if_return: true, } input: { for (var i = 0; i < 5; ++i) { if (i < 3) continue; console.log(i); } }; expect: { for (var i = 0; i < 5; ++i) i < 3 || console.log(i); } expect_stdout: true } labels_4: { options = { conditionals: true, dead_code: true, if_return: true, } input: { out: for (var i = 0; i < 5; ++i) { if (i < 3) continue out; console.log(i); } }; expect: { for (var i = 0; i < 5; ++i) i < 3 || console.log(i); } expect_stdout: true } labels_5: { options = { conditionals: true, dead_code: true, if_return: true, } // should keep the break-s in the following input: { while (foo) { if (bar) break; console.log("foo"); } out: while (foo) { if (bar) break out; console.log("foo"); } }; expect: { while (foo) { if (bar) break; console.log("foo"); } out: while (foo) { if (bar) break out; console.log("foo"); } } } labels_6: { input: { out: break out; }; expect: {} } labels_7: { options = { conditionals: true, dead_code: true, if_return: true, } input: { while (foo) { x(); y(); continue; } }; expect: { while (foo) { x(); y(); } } } labels_8: { options = { conditionals: true, dead_code: true, if_return: true, } input: { while (foo) { x(); y(); break; } }; expect: { while (foo) { x(); y(); break; } } } labels_9: { options = { conditionals: true, dead_code: true, if_return: true, } input: { out: while (foo) { x(); y(); continue out; z(); k(); } }; expect: { while (foo) { x(); y(); } } } labels_10: { options = { conditionals: true, dead_code: true, if_return: true, } input: { out: while (foo) { x(); y(); break out; z(); k(); } }; expect: { out: while (foo) { x(); y(); break out; } } } terser-4.1.2/test/compress/loops.js000066400000000000000000000320231351061312300173210ustar00rootroot00000000000000while_becomes_for: { options = { loops: true, } input: { while (foo()) bar(); } expect: { for (; foo(); ) bar(); } } drop_if_break_1: { options = { loops: true, } input: { for (;;) if (foo()) break; } expect: { for (; !foo();); } } drop_if_break_2: { options = { loops: true, } input: { for (;bar();) if (foo()) break; } expect: { for (; bar() && !foo();); } } drop_if_break_3: { options = { loops: true, } input: { for (;bar();) { if (foo()) break; stuff1(); stuff2(); } } expect: { for (; bar() && !foo();) { stuff1(); stuff2(); } } } drop_if_break_4: { options = { loops: true, sequences: true, } input: { for (;bar();) { x(); y(); if (foo()) break; z(); k(); } } expect: { for (; bar() && (x(), y(), !foo());) z(), k(); } } drop_if_else_break_1: { options = { loops: true, } input: { for (;;) if (foo()) bar(); else break; } expect: { for (; foo(); ) bar(); } } drop_if_else_break_2: { options = { loops: true, } input: { for (;bar();) { if (foo()) baz(); else break; } } expect: { for (; bar() && foo();) baz(); } } drop_if_else_break_3: { options = { loops: true, } input: { for (;bar();) { if (foo()) baz(); else break; stuff1(); stuff2(); } } expect: { for (; bar() && foo();) { baz(); stuff1(); stuff2(); } } } drop_if_else_break_4: { options = { loops: true, sequences: true, } input: { for (;bar();) { x(); y(); if (foo()) baz(); else break; z(); k(); } } expect: { for (; bar() && (x(), y(), foo());) baz(), z(), k(); } } parse_do_while_with_semicolon: { options = { loops: false, } input: { do { x(); } while (false);y() } expect: { do x(); while (false);y(); } } parse_do_while_without_semicolon: { options = { loops: false, } input: { do { x(); } while (false)y() } expect: { do x(); while (false);y(); } } keep_collapse_const_in_own_block_scope: { options = { join_vars: true, loops: true } input: { var i=2; const c=5; while(i--) console.log(i); console.log(c); } expect: { var i=2; const c=5; for(;i--;) console.log(i); console.log(c); } expect_stdout: true } keep_collapse_const_in_own_block_scope_2: { options = { join_vars: true, loops: true } input: { const c=5; var i=2; // Moves to loop, while it did not in previous test while(i--) console.log(i); console.log(c); } expect: { const c=5; for(var i=2;i--;) console.log(i); console.log(c); } expect_stdout: true } evaluate: { options = { dead_code: true, evaluate: true, loops: true, passes: 2, side_effects: true, } input: { while (true) { a(); } while (false) { b(); } do { c(); } while (true); do { d(); } while (false); } expect: { for(;;) a(); for(;;) c(); d(); } } issue_1532: { options = { evaluate: true, loops: true, } input: { function f(x, y) { do { if (x) break; foo(); } while (false); } } expect: { function f(x, y) { do { if (x) break; foo(); } while (false); } } } issue_186: { beautify = { beautify: false, ie8: false, } input: { var x = 3; if (foo()) do do alert(x); while (--x); while (x); else bar(); } expect_exact: 'var x=3;if(foo())do{do{alert(x)}while(--x)}while(x);else bar();' } issue_186_ie8: { beautify = { beautify: false, ie8: true, } input: { var x = 3; if (foo()) do do alert(x); while (--x); while (x); else bar(); } expect_exact: 'var x=3;if(foo()){do{do{alert(x)}while(--x)}while(x)}else bar();' } issue_186_beautify: { beautify = { beautify: true, ie8: false, } input: { var x = 3; if (foo()) do do alert(x); while (--x); while (x); else bar(); } expect_exact: [ 'var x = 3;', '', 'if (foo()) do {', ' do {', ' alert(x);', ' } while (--x);', '} while (x); else bar();', ] } issue_186_beautify_ie8: { beautify = { beautify: true, ie8: true, } input: { var x = 3; if (foo()) do do alert(x); while (--x); while (x); else bar(); } expect_exact: [ 'var x = 3;', '', 'if (foo()) {', ' do {', ' do {', ' alert(x);', ' } while (--x);', ' } while (x);', '} else bar();', ] } issue_186_braces: { beautify = { beautify: false, braces: true, ie8: false, } input: { var x = 3; if (foo()) do do alert(x); while (--x); while (x); else bar(); } expect_exact: 'var x=3;if(foo()){do{do{alert(x)}while(--x)}while(x)}else{bar()}' } issue_186_braces_ie8: { beautify = { beautify: false, braces: true, ie8: true, } input: { var x = 3; if (foo()) do do alert(x); while (--x); while (x); else bar(); } expect_exact: 'var x=3;if(foo()){do{do{alert(x)}while(--x)}while(x)}else{bar()}' } issue_186_beautify_braces: { beautify = { beautify: true, braces: true, ie8: false, } input: { var x = 3; if (foo()) do do alert(x); while (--x); while (x); else bar(); } expect_exact: [ 'var x = 3;', '', 'if (foo()) {', ' do {', ' do {', ' alert(x);', ' } while (--x);', ' } while (x);', '} else {', ' bar();', '}', ] } issue_186_beautify_braces_ie8: { beautify = { beautify: true, braces: true, ie8: true, } input: { var x = 3; if (foo()) do do alert(x); while (--x); while (x); else bar(); } expect_exact: [ 'var x = 3;', '', 'if (foo()) {', ' do {', ' do {', ' alert(x);', ' } while (--x);', ' } while (x);', '} else {', ' bar();', '}', ] } issue_1648: { options = { join_vars: true, loops: true, passes: 2, sequences: true, unused: true, } input: { function f() { x(); var b = 1; while (1); } } expect_exact: "function f(){for(x();1;);}" } do_switch: { options = { evaluate: true, loops: true, } input: { do { switch (a) { case b: continue; } } while (false); } expect: { do { switch (a) { case b: continue; } } while (false); } } in_parenthesis_1: { input: { for (("foo" in {});0;); } expect_exact: 'for(("foo"in{});0;);' } in_parenthesis_2: { input: { for ((function(){ "foo" in {}; });0;); } expect_exact: 'for(function(){"foo"in{}};0;);' } init_side_effects: { options = { loops: true, side_effects: true, } input: { for (function() {}(), i = 0; i < 5; i++) console.log(i); for (function() {}(); i < 10; i++) console.log(i); } expect: { for (i = 0; i < 5; i++) console.log(i); for (; i < 10; i++) console.log(i); } expect_stdout: true } dead_code_condition: { options = { dead_code: true, evaluate: true, loops: true, sequences: true, } input: { for (var a = 0, b = 5; (a += 1, 3) - 3 && b > 0; b--) { var c = function() { b--; }(a++); } console.log(a); } expect: { var c; var a = 0, b = 5; a += 1, 0, console.log(a); } expect_stdout: "1" } issue_2740_1: { options = { dead_code: true, loops: true, } input: { for (; ; ) break; for (a(); ; ) break; for (; b(); ) break; for (c(); d(); ) break; for (; ; e()) break; for (f(); ; g()) break; for (; h(); i()) break; for (j(); k(); l()) break; } expect: { a(); b(); c(); d(); f(); h(); j(); k(); } } issue_2740_2: { options = { dead_code: true, loops: true, passes: 2, } input: { L1: while (x()) { break L1; } } expect: { x(); } } issue_2740_3: { options = { dead_code: true, loops: true, } input: { L1: for (var x = 0; x < 3; x++) { L2: for (var y = 0; y < 2; y++) { break L1; } } console.log(x, y); } expect: { L1: for (var x = 0; x < 3; x++) for (var y = 0; y < 2; y++) break L1; console.log(x, y); } expect_stdout: "0 0" } issue_2740_4: { options = { dead_code: true, loops: true, passes: 2, } input: { L1: for (var x = 0; x < 3; x++) { L2: for (var y = 0; y < 2; y++) { break L2; } } console.log(x, y); } expect: { for (var x = 0; x < 3; x++) { var y = 0; y < 2; } console.log(x, y); } expect_stdout: "3 0" } issue_2740_5: { options = { dead_code: true, loops: true, passes: 2, } input: { L1: for (var x = 0; x < 3; x++) { break L1; L2: for (var y = 0; y < 2; y++) { break L2; } } console.log(x, y); } expect: { var x = 0; x < 3; var y; console.log(x,y); } expect_stdout: "0 undefined" } issue_2740_6: { options = { dead_code: true, loops: true, } input: { const a = 9, b = 0; for (const a = 1; a < 3; ++b) break; console.log(a, b); } expect: { const a = 9, b = 0; { const a = 1; a < 3; } console.log(a, b); } expect_stdout: "9 0" } issue_2740_7: { options = { dead_code: true, loops: true, } input: { let a = 9, b = 0; for (const a = 1; a < 3; ++b) break; console.log(a, b); } expect: { let a = 9, b = 0; { const a = 1; a < 3; } console.log(a, b); } expect_stdout: "9 0" } issue_2740_8: { options = { dead_code: true, loops: true, } input: { var a = 9, b = 0; for (const a = 1; a < 3; ++b) break; console.log(a, b); } expect: { var a = 9, b = 0; { const a = 1; a < 3; } console.log(a, b); } expect_stdout: "9 0" } issue_2904: { options = { join_vars: true, loops: true, } input: { var a = 1; do { console.log(a); } while (--a); } expect_stdout: "1" } terser-4.1.2/test/compress/max_line_len.js000066400000000000000000000012441351061312300206200ustar00rootroot00000000000000too_short: { beautify = { max_line_len: 10, } input: { function f(a) { return { c: 42, d: a(), e: "foo"}; } } expect_exact: [ 'function f(a){', 'return{', 'c:42,', 'd:a(),', 'e:"foo"}}', ] expect_warnings: [ "WARN: Output exceeds 10 characters" ] } just_enough: { beautify = { max_line_len: 14, } input: { function f(a) { return { c: 42, d: a(), e: "foo"}; } } expect_exact: [ 'function f(a){', 'return{c:42,', 'd:a(),e:"foo"}', '}', ] expect_warnings: [ ] } terser-4.1.2/test/compress/negate-iife.js000066400000000000000000000210101351061312300203340ustar00rootroot00000000000000negate_iife_1: { options = { negate_iife: true, } input: { (function(){ stuff() })(); } expect: { !function(){ stuff() }(); } } negate_iife_1_off: { options = { negate_iife: false, } input: { (function(){ stuff() })(); } expect_exact: '(function(){stuff()})();' } negate_iife_2: { options = { inline: true, negate_iife: true, } input: { (function(){ return {} })().x = 10; } expect_exact: "({}).x=10;" } negate_iife_2_side_effects: { options = { inline: true, negate_iife: true, side_effects: true, } input: { (function(){ return {} })().x = 10; } expect_exact: "({}).x=10;" } negate_iife_3: { options = { conditionals: true, negate_iife: true, } input: { (function(){ return t })() ? console.log(true) : console.log(false); } expect: { !function(){ return t }() ? console.log(false) : console.log(true); } } negate_iife_3_evaluate: { options = { conditionals: true, evaluate: true, inline: true, negate_iife: true, } input: { (function(){ return true })() ? console.log(true) : console.log(false); } expect: { console.log(true); } expect_stdout: true } negate_iife_3_side_effects: { options = { conditionals: true, negate_iife: true, side_effects: true, } input: { (function(){ return t })() ? console.log(true) : console.log(false); } expect: { !function(){ return t }() ? console.log(false) : console.log(true); } } negate_iife_3_off: { options = { conditionals: true, negate_iife: false, } input: { (function(){ return t })() ? console.log(true) : console.log(false); } expect: { !function(){ return t }() ? console.log(false) : console.log(true); } } negate_iife_3_off_evaluate: { options = { conditionals: true, evaluate: true, inline: true, negate_iife: false, } input: { (function(){ return true })() ? console.log(true) : console.log(false); } expect: { console.log(true); } expect_stdout: true } negate_iife_4: { options = { conditionals: 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"); }(); } } sequence_off: { options = { conditionals: true, negate_iife: false, passes: 2, sequences: true, } input: { function f() { (function(){ return t })() ? console.log(true) : console.log(false); (function(){ console.log("something"); })(); } function g() { (function(){ console.log("something"); })(); (function(){ return t })() ? console.log(true) : console.log(false); } } expect: { function f() { !function(){ return t }() ? console.log(false) : console.log(true), function(){ console.log("something"); }(); } function g() { (function(){ console.log("something"); })(), function(){ return t }() ? console.log(true) : console.log(false); } } } negate_iife_5: { options = { conditionals: 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, 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"); }(); } } negate_iife_nested: { options = { conditionals: true, negate_iife: true, sequences: true, } input: { function Foo(f) { this.f = f; } new Foo(function() { (function(x) { (function(y) { console.log(y); })(x); })(7); }).f(); } expect: { function Foo(f) { this.f = f; } new Foo(function() { !function(x) { !function(y) { console.log(y); }(x); }(7); }).f(); } expect_stdout: true } negate_iife_nested_off: { options = { conditionals: true, negate_iife: false, sequences: true, } input: { function Foo(f) { this.f = f; } new Foo(function() { (function(x) { (function(y) { console.log(y); })(x); })(7); }).f(); } expect: { function Foo(f) { this.f = f; } new Foo(function() { (function(x) { (function(y) { console.log(y); })(x); })(7); }).f(); } expect_stdout: true } negate_iife_issue_1073: { options = { conditionals: true, negate_iife: true, sequences: true, } input: { new (function(a) { return function Foo() { this.x = a; console.log(this); }; }(7))(); } expect: { new (function(a) { return function Foo() { this.x = a, console.log(this); }; }(7))(); } expect_stdout: true } issue_1254_negate_iife_false: { options = { negate_iife: false, } input: { (function() { return function() { console.log('test') }; })()(); } expect_exact: '(function(){return function(){console.log("test")}})()();' expect_stdout: true } issue_1254_negate_iife_true: { options = { 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 = { negate_iife: true, } input: { (function() { return function() { console.log('test') }; })()()()()(); } expect_exact: '!function(){return function(){console.log("test")}}()()()()();' expect_stdout: true } issue_1288: { options = { conditionals: true, negate_iife: true, side_effects: false, } input: { if (w) ; else { (function f() {})(); } if (!x) { (function() { x = {}; })(); } if (y) (function() {})(); else (function(z) { return z; })(0); } expect: { w || !function f() {}(); x || !function() { x = {}; }(); y ? !function() {}() : !function(z) { return z; }(0); } } issue_1288_side_effects: { options = { conditionals: true, negate_iife: true, side_effects: true, } input: { if (w) ; else { (function f() {})(); } if (!x) { (function() { x = {}; })(); } if (y) (function() {})(); else (function(z) { return z; })(0); } expect: { w; x || function() { x = {}; }(); y; } } terser-4.1.2/test/compress/new.js000066400000000000000000000064751351061312300167720ustar00rootroot00000000000000new_statement: { input: { new x(1); new x(1)(2); new x(1)(2)(3); new new x(1); new new x(1)(2); new (new x(1))(2); (new new x(1))(2); } expect_exact: "new x(1);new x(1)(2);new x(1)(2)(3);new new x(1);new new x(1)(2);new new x(1)(2);(new new x(1))(2);" } new_statements_2: { input: { new x; new new x; new new new x; new true; new (0); new (!0); new (bar = function(foo) {this.foo=foo;})(123); new (bar = function(foo) {this.foo=foo;})(); } expect_exact: "new x;new(new x);new(new(new x));new true;new 0;new(!0);new(bar=function(foo){this.foo=foo})(123);new(bar=function(foo){this.foo=foo});" } new_statements_3: { input: { new (function(foo){this.foo=foo;})(1); new (function(foo){this.foo=foo;})(); new (function test(foo){this.foo=foo;})(1); new (function test(foo){this.foo=foo;})(); } expect_exact: "new function(foo){this.foo=foo}(1);new function(foo){this.foo=foo};new function test(foo){this.foo=foo}(1);new function test(foo){this.foo=foo};" } new_with_rewritten_true_value: { options = { booleans: true, } input: { new true; } expect_exact: "new(!0);" } new_with_many_parameters: { input: { new foo.bar("baz"); new x(/123/, 456); } expect_exact: 'new foo.bar("baz");new x(/123/,456);' } new_constructor_with_unary_arguments: { input: { new x(); new x(-1); new x(-1, -2); new x(void 1, +2, -3, ~4, !5, --a, ++b, c--, d++, typeof e, delete f); new (-1); // should parse despite being invalid at runtime. new (-1)(); // should parse despite being invalid at runtime. new (-1)(-2); // should parse despite being invalid at runtime. } expect_exact: "new x;new x(-1);new x(-1,-2);new x(void 1,+2,-3,~4,!5,--a,++b,c--,d++,typeof e,delete f);new(-1);new(-1);new(-1)(-2);" } call_with_unary_arguments: { input: { x(); x(-1); x(-1, -2); x(void 1, +2, -3, ~4, !5, --a, ++b, c--, d++, typeof e, delete f); (-1)(); // should parse despite being invalid at runtime. (-1)(-2); // should parse despite being invalid at runtime. } expect_exact: "x();x(-1);x(-1,-2);x(void 1,+2,-3,~4,!5,--a,++b,c--,d++,typeof e,delete f);(-1)();(-1)(-2);" } new_with_unary_prefix: { input: { var bar = (+new Date()).toString(32); } expect_exact: 'var bar=(+new Date).toString(32);'; } new_with_assignement_expression: { options = { evaluate: true } input: { var a; new x(a = 5 * 2, b = [1, 2, 3], c = {a: "a", b: "b", cd: "c" + "d"}); new y([a, b] = [3, 4]); } expect: { var a; new x(a = 10, b = [1, 2, 3], c = {a: "a", b: "b", cd: "cd"}); new y([a, b] = [3, 4]); } } dot_parenthesis_1: { input: { console.log(new (Math.random().constructor) instanceof Number); } expect_exact: "console.log(new(Math.random().constructor)instanceof Number);" expect_stdout: "true" } dot_parenthesis_2: { input: { console.log(typeof new function(){Math.random()}.constructor); } expect_exact: "console.log(typeof new function(){Math.random()}.constructor);" expect_stdout: "function" } terser-4.1.2/test/compress/node_version.js000066400000000000000000000002531351061312300206570ustar00rootroot00000000000000eval_let_6: { input: { eval("let a;"); console.log(); } expect: { eval("let a;"); console.log(); } expect_stdout: "" } terser-4.1.2/test/compress/numbers.js000066400000000000000000000106601351061312300176430ustar00rootroot00000000000000hex_numbers_in_parentheses_for_prototype_functions: { input: { (-2); (-2).toFixed(0); (2); (2).toFixed(0); (0.2); (0.2).toFixed(0); (0.00000002); (0.00000002).toFixed(0); (1000000000000000128); (1000000000000000128).toFixed(0); } expect_exact: "-2;(-2).toFixed(0);2;2..toFixed(0);.2;.2.toFixed(0);2e-8;2e-8.toFixed(0);0xde0b6b3a7640080;(0xde0b6b3a7640080).toFixed(0);" } comparisons: { options = { comparisons: true, } input: { console.log( ~x === 42, x % n === 42 ); } expect: { console.log( 42 == ~x, x % n == 42 ); } } evaluate_1: { options = { evaluate: true, unsafe_math: false, } input: { console.log( x + 1 + 2, x * 1 * 2, +x + 1 + 2, 1 + x + 2 + 3, 1 | x | 2 | 3, 1 + x-- + 2 + 3, 1 + (x*y + 2) + 3, 1 + (2 + x + 3), 1 + (2 + ~x + 3), -y + (2 + ~x + 3), 1 & (2 & x & 3), 1 + (2 + (x |= 0) + 3) ); } expect: { console.log( x + 1 + 2, 1 * x * 2, +x + 1 + 2, 1 + x + 2 + 3, 3 | x, 1 + x-- + 2 + 3, x*y + 2 + 1 + 3, 1 + (2 + x + 3), 2 + ~x + 3 + 1, -y + (2 + ~x + 3), 0 & x, 2 + (x |= 0) + 3 + 1 ); } } evaluate_2: { options = { evaluate: true, unsafe_math: true, } input: { console.log( x + 1 + 2, x * 1 * 2, +x + 1 + 2, 1 + x + 2 + 3, 1 | x | 2 | 3, 1 + x-- + 2 + 3, 1 + (x*y + 2) + 3, 1 + (2 + x + 3), 1 & (2 & x & 3), 1 + (2 + (x |= 0) + 3) ); } expect: { console.log( x + 1 + 2, 2 * x, 3 + +x, 1 + x + 2 + 3, 3 | x, 6 + x--, 6 + x*y, 1 + (2 + x + 3), 0 & x, 6 + (x |= 0) ); } } evaluate_3: { options = { evaluate: true, unsafe: true, unsafe_math: true, } input: { console.log(1 + Number(x) + 2); } expect: { console.log(3 + +x); } } evaluate_4: { options = { evaluate: true, } input: { console.log( 1+ +a, +a+1, 1+-a, -a+1, +a+ +b, +a+-b, -a+ +b, -a+-b ); } expect: { console.log( +a+1, +a+1, 1-a, 1-a, +a+ +b, +a-b, -a+ +b, -a-b ); } } issue_1710: { options = { evaluate: true, } input: { var x = {}; console.log((x += 1) + -x); } expect: { var x = {}; console.log((x += 1) + -x); } expect_stdout: true } unary_binary_parenthesis: { input: { var v = [ 0, 1, NaN, Infinity, null, undefined, true, false, "", "foo", /foo/ ]; v.forEach(function(x) { v.forEach(function(y) { console.log( +(x*y), +(x/y), +(x%y), -(x*y), -(x/y), -(x%y) ); }); }); } expect: { var v = [ 0, 1, NaN, 1/0, null, void 0, true, false, "", "foo", /foo/ ]; v.forEach(function(x) { v.forEach(function(y) { console.log( +x*y, +x/y, +x%y, -x*y, -x/y, -x%y ); }); }); } expect_stdout: true } compress_numbers: { input: { const exp = 1000; const Exp = 1000000000000; const negativeExp = 0.00000001; const huge = 1000000000001; const big = 100000000001; const fractional = 100.2300200; } expect: { const exp = 1e3; const Exp = 1e12; const negativeExp = 1e-8; const huge = 0xe8d4a51001; const big = 100000000001; const fractional = 100.23002; } } terser-4.1.2/test/compress/object.js000066400000000000000000000543641351061312300174470ustar00rootroot00000000000000getter_setter: { input: { var get = "bar"; var a = { get, set: "foo", get bar() { return this.get; }, get 5() { return "five"; }, get 0xf55() { return "f five five"; }, get "five"() { return 5; }, set one(value) { this._one = value; }, set 9(value) { this._nine = value; }, set 0b1010(value) { this._ten = value; }, set "eleven"(value) { this._eleven = value; } }; var b = { get() { return "gift"; }, set: function(code) { return "Storing code " + code; } }; var c = { ["get"]: "foo", ["set"]: "bar" }; var d = { get: "foo", set: "bar" }; } expect: { var get = "bar"; var a = { get, set: "foo", get bar() { return this.get; }, get 5() { return "five"; }, get 0xf55() { return "f five five"; }, get "five"() { return 5; }, set one(value) { this._one = value; }, set 9(value) { this._nine = value; }, set 0b1010(value) { this._ten = value; }, set "eleven"(value) { this._eleven = value; } }; var b = { get() { return "gift"; }, set: function(code) { return "Storing code " + code; } }; var c = { ["get"]: "foo", ["set"]: "bar" }; var d = { get: "foo", set: "bar" }; } } getter_setter_mangler: { mangle = {} beautify = { ecma: 6 } input: { function f(get,set) { return { get, set, get g(){}, set s(n){}, c, a:1, m(){} }; } } expect_exact: "function f(t,e){return{get:t,set:e,get g(){},set s(t){},c,a:1,m(){}}}" } use_shorthand_opportunity: { beautify = { ecma: 6 } input: { var foo = 123; var obj = {foo: foo}; } expect_exact: "var foo=123;var obj={foo};" } computed_property_names: { input: { obj({ ["x" + "x"]: 6 }); } expect_exact: 'obj({["x"+"x"]:6});' } convert_computed_props_to_regular_ones: { options = { booleans: true, computed_props: true, evaluate: true, } input: { var o = { ["hi"]: 0, ["A" + 1]: 1, [/B/]: 2, [100 + 23]: 3, [1 + .5]: 4, [Math.PI]: 5, [undefined]: 6, [true]: 7, [false]: 8, [null]: 9, [Infinity]: 10, [NaN]: 11, }; for (var k in o) { console.log(k, o[k]); } } expect: { var o = { hi: 0, A1: 1, [/B/]: 2, 123: 3, 1.5: 4, [Math.PI]: 5, // leave these problematic cases as is [void 0]: 6, [!0]: 7, [!1]: 8, [null]: 9, [1 / 0]: 10, [NaN]: 11 }; for (var k in o) console.log(k, o[k]); } expect_stdout: [ "123 3", "hi 0", "A1 1", "/B/ 2", "1.5 4", "3.141592653589793 5", "undefined 6", "true 7", "false 8", "null 9", "Infinity 10", "NaN 11", ] } computed_property_names_evaluated_1: { options = { evaluate: true } input: { obj({ [1 + 1]: 2, ["x" + "x"]: 6 }); } expect_exact: 'obj({[2]:2,["xx"]:6});' } computed_property_names_evaluated_2: { options = { evaluate: true } input: { var foo = something(); var obj = { [foo]() { return "blah"; } } } expect_exact: 'var foo=something();var obj={[foo](){return"blah"}};' } shorthand_properties: { mangle = true; input: { (function() { var prop = 1; const value = {prop}; return value; })(); } expect: { (function() { var n = 1; const r = {prop:n}; return r; })(); } } concise_methods: { beautify = { ecma: 6 } input: { x = { foo(a, b) { return x; } } y = { foo([{a}]) { return a; }, bar(){} } } expect_exact: "x={foo(a,b){return x}};y={foo([{a}]){return a},bar(){}};" } concise_methods_with_computed_property: { options = { evaluate: true } input: { var foo = { [Symbol.iterator]() { return { /* stuff */ } }, [1 + 2]() { return 3; }, ["1" + "4"]() { return 14; } } } expect: { var foo = { [Symbol.iterator]() { return { /* stuff */ } }, [3]() { return 3; }, ["14"]() { return 14; } } } } concise_methods_with_computed_property2: { options = { evaluate: true } input: { var foo = { [[1]](){ return "success"; } }; doSomething(foo[[1]]()); } expect_exact: 'var foo={[[1]](){return"success"}};doSomething(foo[[1]]());' } concise_methods_with_various_property_names: { input: { var get = "bar"; var a = { bar() { return this.get; }, 5() { return "five"; }, 0xf55() { return "f five five"; }, "five"() { return 5; }, 0b1010(value) { this._ten = value; } }; } expect: { var get = "bar"; var a = { bar() { return this.get; }, 5() { return "five"; }, 0xf55() { return "f five five"; }, "five"() { return 5; }, 0b1010(value) { this._ten = value; } }; } } concise_methods_and_mangle_props: { mangle = { properties: { regex: /_/, }, } input: { function x() { obj = { _foo() { return 1; } } } } expect: { function x() { obj = { o() { return 1; } } } } } concise_generators: { beautify = { ecma: 6 } input: { x = { *foo(a, b) { return x; } } y = { *foo([{a}]) { yield a; }, bar(){} } } expect_exact: "x={*foo(a,b){return x}};y={*foo([{a}]){yield a},bar(){}};" } concise_methods_and_keyword_names: { input: { x = { catch() {}, throw() {} } } expect: { x={catch(){},throw(){}}; } } getter_setter_with_computed_value: { input: { class C { get ['a']() { return 'A'; } set ['a'](value) { do_something(a); } } var x = { get [a.b]() { return 42; } }; class MyArray extends Array { get [Symbol.species]() { return Array; } } } expect_exact: 'class C{get["a"](){return"A"}set["a"](value){do_something(a)}}var x={get[a.b](){return 42}};class MyArray extends Array{get[Symbol.species](){return Array}}' } property_with_operator_value: { input: { var foo = { "*": 1, get "*"() { return 2; }, *"*"() { return 3; }, "%": 1, get "%"() { return 2; }, *"%"() { return 3; } } class bar { get "*"() { return 1 } *"*"() { return 2; } get "%"() { return 1 } *"%"() { return 2; } } } expect_exact: 'var foo={"*":1,get"*"(){return 2},*"*"(){return 3},"%":1,get"%"(){return 2},*"%"(){return 3}};class bar{get"*"(){return 1}*"*"(){return 2}get"%"(){return 1}*"%"(){return 2}}' } property_with_unprintable: { input: { var foo = { "\x00\x01": "foo", get "\x00\x01"() { return "bar"; }, set "\x00\x01"(foo) { save(foo); }, *"\x00\x01"() { return "foobar"; } } class bar { get "\x00\x01"() { return "bar" } set "\x00\x01"(foo) { save(foo); } *"\x00\x01"() { return "foobar"; } } } expect_exact: 'var foo={"\\0\x01":"foo",get"\\0\x01"(){return"bar"},set"\\0\x01"(foo){save(foo)},*"\\0\x01"(){return"foobar"}};class bar{get"\\0\x01"(){return"bar"}set"\\0\x01"(foo){save(foo)}*"\\0\x01"(){return"foobar"}}' } property_with_unprintable_ascii_only: { beautify = { ascii_only: true, } input: { var foo = { "\x00\x01": "foo", get "\x00\x01"() { return "bar"; }, set "\x00\x01"(foo) { save(foo); }, *"\x00\x01"() { return "foobar"; } } class bar { get "\x00\x01"() { return "bar" } set "\x00\x01"(foo) { save(foo); } *"\x00\x01"() { return "foobar"; } } } expect_exact: 'var foo={"\\0\\x01":"foo",get"\\0\\x01"(){return"bar"},set"\\0\\x01"(foo){save(foo)},*"\\0\\x01"(){return"foobar"}};class bar{get"\\0\\x01"(){return"bar"}set"\\0\\x01"(foo){save(foo)}*"\\0\\x01"(){return"foobar"}}' } property_with_unprintable_ascii_only_static: { beautify = { ascii_only: true } input: { class foo { static get "\x02\x03"() { return "bar"; } static set "\x04\x05"(foo) { save(foo); } } } expect_exact: 'class foo{static get"\\x02\\x03"(){return"bar"}static set"\\x04\\x05"(foo){save(foo)}}' } methods_and_getters_with_keep_quoted_props_enabled: { beautify = { quote_style: 3, keep_quoted_props: true, } input: { var obj = { a() {}, "b"() {}, get c() { return "c"}, get "d"() { return "d"}, set e(a) { doSomething(a); }, set f(a) { doSomething(b); } } } expect_exact: 'var obj={a(){},"b"(){},get c(){return"c"},get"d"(){return"d"},set e(a){doSomething(a)},set f(a){doSomething(b)}};' } allow_assignments_to_property_values: { input: { var foo = {123: foo = 123} = {foo: "456"}; } expect: { var foo = {123: foo = 123} = {foo: "456"}; } } variable_as_computed_property: { input: { function getLine(header) { return { [header]: {} }; } } expect_exact: "function getLine(header){return{[header]:{}}}" } prop_func_to_concise_method: { options = { ecma: 6, unsafe_methods: true, } input: { ({ emit: function NamedFunctionExpression() { console.log("PASS"); }, run: function() { this.emit(); } }).run(); } expect: { ({ emit: function NamedFunctionExpression() { console.log("PASS"); }, run() { this.emit(); } }).run(); } expect_stdout: "PASS" } prop_arrow_to_concise_method: { options = { ecma: 6, unsafe_methods: true, } input: { ({ run: () => { console.log("PASS"); } }).run(); } expect: { ({ run() { console.log("PASS"); } }).run(); } expect_stdout: "PASS" } concise_method_to_prop_arrow: { options = { arrows: true, ecma: 6, } input: { console.log(({ a: () => 1 }).a()); console.log(({ a: () => { return 2; } }).a()); console.log(({ a() { return 3; } }).a()); console.log(({ a() { return this.b; }, b: 4 }).a()); } expect: { console.log({ a: () => 1 }.a()); console.log({ a: () => 2 }.a()); console.log({ a: () => 3 }.a()); console.log({ a() { return this.b; }, b: 4 }.a()); } expect_stdout: [ "1", "2", "3", "4", ] } prop_func_to_async_concise_method: { options = { ecma: 8, unsafe_methods: true, } input: { ({ run: async function() { console.log("PASS"); } }).run(); } expect: { ({ async run() { console.log("PASS"); } }).run(); } expect_stdout: "PASS" node_version: ">=8" } prop_func_to_concise_method_various: { options = { ecma: 6, unsafe_methods: true, } input: { ({ null: function(x, y){ x(y); }, 123: function(x, y){ x(y); }, "A B": function(x, y){ x(y); }, p1: function(x, y){ x(y); }, p2: function*(x, y){ yield x(y); }, p3: async function(x, y){ await x(y); }, [c1]: function(x, y){ x(y); }, [c2]: function*(x, y){ yield x(y); }, [c3]: async function(x, y){ await x(y); }, }); } expect: { ({ null(x, y) { x(y); }, 123(x, y) { x(y); }, "A B"(x, y) { x(y); }, p1(x, y) { x(y); }, *p2(x, y) { yield x(y); }, async p3(x, y) { await x(y); }, [c1](x, y) { x(y); }, *[c2](x, y) { yield x(y); }, async [c3](x, y) { await x(y); }, }); } } prop_arrows_to_concise_method_various: { options = { ecma: 6, unsafe_methods: true, } input: { ({ null: (x, y) => { x(y); }, 123: (x, y) => { x(y); }, "A B": (x, y) => { x(y); }, p1: (x, y) => { x(y); }, p3: async (x, y) => { await x(y); }, [c1]: (x, y) => { x(y); }, [c3]: async (x, y) => { await x(y); }, }); } expect: { ({ null(x, y) { x(y); }, 123(x, y) { x(y); }, "A B"(x, y) { x(y); }, p1(x, y) { x(y); }, async p3(x, y) { await x(y); }, [c1](x, y) { x(y); }, async [c3](x, y) { await x(y); }, }); } } prop_arrow_with_this: { options = { ecma: 6, unsafe_methods: true, } input: { function run(arg) { console.log(arg === this ? "global" : arg === foo ? "foo" : arg); } var foo = { func_no_this: function() { run(); }, func_with_this: function() { run(this); }, arrow_no_this: () => { run(); }, arrow_with_this: () => { run(this); }, }; for (var key in foo) foo[key](); } expect: { function run(arg) { console.log(arg === this ? "global" : arg === foo ? "foo" : arg); } var foo = { func_no_this() { run(); }, func_with_this() { run(this); }, arrow_no_this() { run(); }, arrow_with_this: () => { run(this); }, }; for (var key in foo) foo[key](); } expect_stdout: [ "undefined", "foo", "undefined", "global", ] } prop_arrow_with_nested_this: { options = { ecma: 6, unsafe_methods: true, } input: { function run(arg) { console.log(arg === this ? "global" : arg === foo ? "foo" : arg); } var foo = { func_func_this: function() { (function() { run(this); })(); }, func_arrow_this: function() { (() => { run(this); })(); }, arrow_func_this: () => { (function() { run(this); })(); }, arrow_arrow_this: () => { (() => { run(this); })(); }, }; for (var key in foo) foo[key](); } expect: { function run(arg) { console.log(arg === this ? "global" : arg === foo ? "foo" : arg); } var foo = { func_func_this() { (function() { run(this); })(); }, func_arrow_this() { (() => { run(this); })(); }, arrow_func_this() { (function() { run(this); })(); }, arrow_arrow_this: () => { (() => { run(this); })(); }, }; for (var key in foo) foo[key](); } expect_stdout: [ "global", "foo", "global", "global", ] } issue_2554_1: { options = { computed_props: true, evaluate: true, } input: { var obj = { ["x" + ""]: 1, ["method" + ""]() { this.s = "PASS"; }, get ["g" + ""]() { return this.x; }, set ["s" + ""](value) { this.x = value; } }; obj.method(); console.log(obj.g); } expect: { var obj = { x: 1, method() { this.s = "PASS"; }, get g() { return this.x; }, set s(value) { this.x = value; } }; obj.method(); console.log(obj.g); } expect_stdout: "PASS" } issue_2554_2: { options = { computed_props: true, evaluate: true, } input: { var instance = new class { constructor() { this.x = 2; } ["method" + ""]() { this.s = "PASS"; } get ["g" + ""]() { return this.x; } set ["s" + ""](value) { this.x = value; } }(); instance.method(); console.log(instance.g); } expect: { var instance = new class { constructor() { this.x = 2; } method() { this.s = "PASS"; } get g() { return this.x; } set s(value) { this.x = value; } }(); instance.method(); console.log(instance.g); } expect_stdout: "PASS" } issue_2554_3: { options = { computed_props: true, evaluate: true, } input: { var foo = { [1 + 0]: 1, [2 + 0]() { this[4] = "PASS"; }, get [3 + 0]() { return this[1]; }, set [4 + 0](value) { this[1] = value; } }; foo[2](); console.log(foo[3]); } expect: { var foo = { 1: 1, 2() { this[4] = "PASS"; }, get 3() { return this[1]; }, set 4(value) { this[1] = value; } }; foo[2](); console.log(foo[3]); } expect_stdout: "PASS" } issue_2554_4: { options = { computed_props: true, evaluate: true, } input: { var bar = new class { constructor() { this[1] = 2; } [2 + 0]() { this[4] = "PASS"; } get [3 + 0]() { return this[1]; } set [4 + 0](value) { this[1] = value; } }(); bar[2](); console.log(bar[3]); } expect: { var bar = new class { constructor() { this[1] = 2; } 2() { this[4] = "PASS"; } get 3() { return this[1]; } set 4(value) { this[1] = value; } }(); bar[2](); console.log(bar[3]); } expect_stdout: "PASS" } issue_2554_5: { options = { computed_props: true, evaluate: true, } input: { new class { ["constructor"]() { console.log("FAIL"); } "constructor"() { console.log("PASS"); } }(); } expect: { new class { ["constructor"]() { console.log("FAIL"); } constructor() { console.log("PASS"); } }(); } expect_stdout: "PASS" } dont_join_repeat_object_keys: { options = { join_vars: true } input: { const obj = { foo: 1 } obj.foo = 2 } expect: { const obj = { foo: (1, 2) } } } issue_206: { options = { computed_props: true } input: { throw {["__proto__"]: 1} } expect: { throw {["__proto__"]: 1} } } terser-4.1.2/test/compress/parameters.js000066400000000000000000000110761351061312300203350ustar00rootroot00000000000000arrow_functions: { options = { arrows: true, } input: { (a) => b; // 1 args (a, b) => c; // n args () => b; // 0 args (a) => (b) => c; // func returns func returns func (a) => ((b) => c); // So these parens are dropped () => (b,c) => d; // func returns func returns func a=>{return b;} a => 'lel'; // Dropping the parens } expect_exact: "a=>b;(a,b)=>c;()=>b;a=>b=>c;a=>b=>c;()=>(b,c)=>d;a=>b;a=>\"lel\";" } arrow_return: { options = { arrows: true, } input: { () => {}; () => { return; }; a => { return 1; } a => { return -b } a => { return b; var b; } (x, y) => { return x - y; } } expect_exact: "()=>{};()=>{};a=>1;a=>-b;a=>{return b;var b};(x,y)=>x-y;" } regression_arrow_functions_and_hoist: { options = { hoist_vars: true, hoist_funs: true } input: { (a) => b; } expect_exact: "a=>b;" } regression_assign_arrow_functions: { input: { oninstall = e => false; oninstall = () => false; } expect: { oninstall=e=>false; oninstall=()=>false; } } destructuring_arguments_1: { input: { (function ( a ) { }); (function ( [ a ] ) { }); (function ( [ a, b ] ) { }); (function ( [ [ a ] ] ) { }); (function ( [ [ a, b ] ] ) { }); (function ( [ a, [ b ] ] ) { }); (function ( [ [ b ], a ] ) { }); (function ( { a } ) { }); (function ( { a, b } ) { }); (function ( [ { a } ] ) { }); (function ( [ { a, b } ] ) { }); (function ( [ a, { b } ] ) { }); (function ( [ { b }, a ] ) { }); ( [ a ] ) => { }; ( [ a, b ] ) => { }; ( { a } ) => { }; ( { a, b, c, d, e } ) => { }; ( [ a ] ) => b; ( [ a, b ] ) => c; ( { a } ) => b; ( { a, b } ) => c; } expect: { (function(a){}); (function([a]){}); (function([a,b]){}); (function([[a]]){}); (function([[a,b]]){}); (function([a,[b]]){}); (function([[b],a]){}); (function({a}){}); (function({a,b}){}); (function([{a}]){}); (function([{a,b}]){}); (function([a,{b}]){}); (function([{b},a]){}); ([a])=>{}; ([a,b])=>{}; ({a})=>{}; ({a,b,c,d,e})=>{}; ([a])=>b; ([a,b])=>c; ({a})=>b; ({a,b})=>c; } } destructuring_arguments_2: { input: { (function([]) {}); (function({}) {}); (function([,,,,,]) {}); (function ([a, {b: c}]) {}); (function ([...args]) {}); (function ({x,}) {}); class a { *method({ [thrower()]: x } = {}) {}}; (function(a, b, c, d, [{e: [...f]}]){})(1, 2, 3, 4, [{e: [1, 2, 3]}]); } expect: { (function([]) {}); (function({}) {}); (function([,,,,,]) {}); (function ([a, {b: c}]) {}); (function ([...args]) {}); (function ({x,}) {}); class a { *method({ [thrower()]: x } = {}) {}}; (function(a, b, c, d, [{e: [...f]}]){})(1, 2, 3, 4, [{e: [1, 2, 3]}]); } } destructuring_arguments_3: { beautify = { ecma: 6 } input: { function fn3({x: {y: {z: {} = 42}}}) {} const { a = (function () {}), b = (0, function() {}) } = {}; let { c = (function () {}), d = (0, function() {}) } = {}; var { e = (function () {}), f = (0, function() {}) } = {}; } expect_exact: "function fn3({x:{y:{z:{}=42}}}){}const{a=function(){},b=(0,function(){})}={};let{c=function(){},d=(0,function(){})}={};var{e=function(){},f=(0,function(){})}={};" } default_arguments: { beautify = { ecma: 6 } input: { function x(a = 6) { } function x(a = (6 + 5)) { } function x({ foo } = {}, [ bar ] = [ 1 ]) { } } expect_exact: "function x(a=6){}function x(a=6+5){}function x({foo}={},[bar]=[1]){}" } default_values_in_destructurings: { beautify = { ecma: 6 } input: { function x({a=(4), b}) {} function x([b, c=(12)]) {} var { x = (6), y } = x; var [ x, y = (6) ] = x; } expect_exact: "function x({a=4,b}){}function x([b,c=12]){}var{x=6,y}=x;var[x,y=6]=x;" } accept_duplicated_parameters_in_non_strict_without_spread_or_default_assignment: { input: { function a(b, b){} function b({c: test, c: test}){} } expect: { function a(b, b){} function b({c: test, c: test}){} } } terser-4.1.2/test/compress/parse_errors.js000066400000000000000000000016221351061312300206740ustar00rootroot00000000000000basic_syntax_error: { input: ` // notice the code is within a template string // as opposed to a block so that the test can // survive a parse error var x = 5--; ` expect_error: ({ name: "SyntaxError", message: "Invalid use of -- operator", line: 5, col: 17, }) } valid_template_string_example: { options = { evaluate: true, } input: ` // notice that template quote characters and // template expressions need to be escaped console.log(\`foo \${100 + 23} bar\`); ` expect: { console.log("foo 123 bar"); } expect_stdout: "foo 123 bar" } invalid_template_string_example: { input: ` console.log(\`foo \${100 + 23} ` expect_error: ({ name: "SyntaxError", message: "Unterminated template", line: 2, col: 35, }) } terser-4.1.2/test/compress/properties.js000066400000000000000000001733011351061312300203660ustar00rootroot00000000000000keep_properties: { options = { evaluate: true, properties: false, } input: { a["foo"] = "bar"; } expect: { a["foo"] = "bar"; } } dot_properties: { options = { evaluate: true, properties: true, } beautify = { ie8: true, } input: { a["foo"] = "bar"; a["if"] = "if"; a["*"] = "asterisk"; a["\u0EB3"] = "unicode"; a[""] = "whitespace"; a["1_1"] = "foo"; } expect: { a.foo = "bar"; a["if"] = "if"; a["*"] = "asterisk"; a["\u0EB3"] = "unicode"; a[""] = "whitespace"; a["1_1"] = "foo"; } } dot_properties_es5: { options = { evaluate: true, properties: true, } beautify = { ie8: false, } input: { a["foo"] = "bar"; a["if"] = "if"; a["*"] = "asterisk"; a["\u0EB3"] = "unicode"; a[""] = "whitespace"; } expect: { a.foo = "bar"; a.if = "if"; a["*"] = "asterisk"; a["\u0EB3"] = "unicode"; a[""] = "whitespace"; } } sub_properties: { options = { evaluate: true, properties: true, } input: { a[0] = 0; a["0"] = 1; a[3.14] = 2; a["3" + ".14"] = 3; a["i" + "f"] = 4; a["foo" + " bar"] = 5; a[0 / 0] = 6; a[null] = 7; a[undefined] = 8; } expect: { a[0] = 0; a[0] = 1; a[3.14] = 2; a[3.14] = 3; a.if = 4; a["foo bar"] = 5; a.NaN = 6; a.null = 7; a[void 0] = 8; } } evaluate_array_length: { options = { evaluate: true, properties: true, unsafe: true, } input: { a = [1, 2, 3].length; a = [1, 2, 3].join()["len" + "gth"]; a = [1, 2, b].length; a = [1, 2, 3].join(b).length; } expect: { a = 3; a = 5; a = [1, 2, b].length; a = [1, 2, 3].join(b).length; } } evaluate_string_length: { options = { evaluate: true, properties: true, unsafe: true, } input: { a = "foo".length; a = ("foo" + "bar")["len" + "gth"]; a = b.length; a = ("foo" + b).length; } expect: { a = 3; a = 6; a = b.length; a = ("foo" + b).length; } } mangle_properties: { mangle = { properties: { keep_quoted: false, }, } input: { a["foo"] = "bar"; a.color = "red"; x = {"bar": 10}; a.run(x.bar, a.foo); a['run']({color: "blue", foo: "baz"}); } expect: { a["o"]="bar";a.color="red";x={l:10};a.u(x.l,a.o);a["u"]({color:"blue",o:"baz"}); } } mangle_unquoted_properties: { options = { evaluate: true, properties: false, } mangle = { properties: { builtins: true, keep_quoted: true, }, } beautify = { beautify: false, quote_style: 3, keep_quoted_props: true, } input: { var a = {}; a.top = 1; function f1() { a["foo"] = "bar"; a.color = "red"; a.stuff = 2; x = {"bar": 10, size: 7}; a.size = 9; } function f2() { a.foo = "bar"; a['color'] = "red"; x = {bar: 10, size: 7}; a.size = 9; a.stuff = 3; } } expect: { var a = {}; a.a = 1; function f1() { a["foo"] = "bar"; a.color = "red"; a.r = 2; x = {"bar": 10, b: 7}; a.b = 9; } function f2() { a.foo = "bar"; a['color'] = "red"; x = {bar: 10, b: 7}; a.b = 9; a.r = 3; } } } mangle_debug: { mangle = { properties: { debug: "", }, } input: { var a = {}; a.foo = "bar"; x = { baz: "ban" }; } expect: { var a = {}; a._$foo$_ = "bar"; x = { _$baz$_: "ban" }; } } mangle_debug_true: { mangle = { properties: { debug: true, }, } input: { var a = {}; a.foo = "bar"; x = { baz: "ban" }; } expect: { var a = {}; a._$foo$_ = "bar"; x = { _$baz$_: "ban" }; } } mangle_debug_suffix: { mangle = { properties: { debug: "XYZ", }, } input: { var a = {}; a.foo = "bar"; x = { baz: "ban" }; } expect: { var a = {}; a._$foo$XYZ_ = "bar"; x = { _$baz$XYZ_: "ban" }; } } mangle_debug_suffix_keep_quoted: { options = { evaluate: true, properties: false, } mangle = { properties: { builtins: true, debug: "XYZ", keep_quoted: true, reserved: [], }, } beautify = { beautify: false, quote_style: 3, keep_quoted_props: true, } input: { var a = {}; a.top = 1; function f1() { a["foo"] = "bar"; a.color = "red"; a.stuff = 2; x = {"bar": 10, size: 7}; a.size = 9; } function f2() { a.foo = "bar"; a['color'] = "red"; x = {bar: 10, size: 7}; a.size = 9; a.stuff = 3; } } expect: { var a = {}; a._$top$XYZ_ = 1; function f1() { a["foo"] = "bar"; a.color = "red"; a._$stuff$XYZ_ = 2; x = {"bar": 10, _$size$XYZ_: 7}; a._$size$XYZ_ = 9; } function f2() { a.foo = "bar"; a['color'] = "red"; x = {bar: 10, _$size$XYZ_: 7}; a._$size$XYZ_ = 9; a._$stuff$XYZ_ = 3; } } } first_256_chars_as_properties: { beautify = { ascii_only: true, } input: { // Note: some of these unicode character keys are not visible on github.com var o = { "\0":0,"":1,"":2,"":3,"":4,"":5,"":6,"":7,"\b":8, "\t":9,"\n":10,"\v":11,"\f":12,"\r":13,"":14,"":15,"":16,"":17, "":18,"":19,"":20,"":21,"":22,"":23,"":24,"":25,"":26, "":27,"":28,"":29,"":30,"":31," ":32,"!":33,'"':34,"#":35, $:36,"%":37,"&":38,"'":39,"(":40,")":41,"*":42,"+":43,",":44, "-":45,".":46,"/":47,"0":48,"1":49,"2":50,"3":51,"4":52,"5":53,"6":54,"7":55, "8":56,"9":57,":":58,";":59,"<":60,"=":61,">":62,"?":63,"@":64,A:65, B:66,C:67,D:68,E:69,F:70,G:71,H:72,I:73,J:74,K:75,L:76,M:77,N:78, O:79,P:80,Q:81,R:82,S:83,T:84,U:85,V:86,W:87,X:88,Y:89,Z:90,"[":91, "\\":92,"]":93,"^":94,_:95,"`":96,a:97,b:98,c:99,d:100,e:101, f:102,g:103,h:104,i:105,j:106,k:107,l:108,m:109,n:110,o:111,p:112, q:113,r:114,s:115,t:116,u:117,v:118,w:119,x:120,y:121,z:122,"{":123, "|":124,"}":125,"~":126,"":127,"€":128,"":129,"‚":130,"ƒ":131, "„":132,"…":133,"†":134,"‡":135,"ˆ":136,"‰":137,"Š":138,"‹":139, "Œ":140,"":141,"Ž":142,"":143,"":144,"‘":145,"’":146,"“":147, "”":148,"•":149,"–":150,"—":151,"˜":152,"™":153,"š":154,"›":155, "œ":156,"":157,"ž":158,"Ÿ":159," ":160,"¡":161,"¢":162,"£":163, "¤":164,"¥":165,"¦":166,"§":167,"¨":168,"©":169,"ª":170,"«":171, "¬":172,"­":173,"®":174,"¯":175,"°":176,"±":177,"²":178,"³":179, "´":180,"µ":181,"¶":182,"·":183,"¸":184,"¹":185,"º":186,"»":187, "¼":188,"½":189,"¾":190,"¿":191,"À":192,"Á":193,"Â":194,"Ã":195, "Ä":196,"Å":197,"Æ":198,"Ç":199,"È":200,"É":201,"Ê":202,"Ë":203, "Ì":204,"Í":205,"Î":206,"Ï":207,"Ð":208,"Ñ":209,"Ò":210,"Ó":211, "Ô":212,"Õ":213,"Ö":214,"×":215,"Ø":216,"Ù":217,"Ú":218,"Û":219, "Ü":220,"Ý":221,"Þ":222,"ß":223,"à":224,"á":225,"â":226,"ã":227, "ä":228,"å":229,"æ":230,"ç":231,"è":232,"é":233,"ê":234,"ë":235, "ì":236,"í":237,"î":238,"ï":239,"ð":240,"ñ":241,"ò":242,"ó":243, "ô":244,"õ":245,"ö":246,"÷":247,"ø":248,"ù":249,"ú":250,"û":251, "ü":252,"ý":253,"þ":254,"ÿ":255 }; } expect: { var o = { "\0":0,"\x01":1,"\x02":2,"\x03":3,"\x04":4,"\x05":5,"\x06":6, "\x07":7,"\b":8,"\t":9,"\n":10,"\v":11,"\f":12,"\r":13,"\x0e":14, "\x0f":15,"\x10":16,"\x11":17,"\x12":18,"\x13":19,"\x14":20,"\x15":21, "\x16":22,"\x17":23,"\x18":24,"\x19":25,"\x1a":26,"\x1b":27,"\x1c":28, "\x1d":29,"\x1e":30,"\x1f":31," ":32,"!":33,'"':34,"#":35,$:36, "%":37,"&":38,"'":39,"(":40,")":41,"*":42,"+":43,",":44,"-":45, ".":46,"/":47,0:48,1:49,2:50,3:51,4:52,5:53,6:54,7:55,8:56,9:57, ":":58,";":59,"<":60,"=":61,">":62,"?":63,"@":64,A:65,B:66,C:67, D:68,E:69,F:70,G:71,H:72,I:73,J:74,K:75,L:76,M:77,N:78,O:79,P:80, Q:81,R:82,S:83,T:84,U:85,V:86,W:87,X:88,Y:89,Z:90,"[":91,"\\":92, "]":93,"^":94,_:95,"`":96,a:97,b:98,c:99,d:100,e:101,f:102,g:103, h:104,i:105,j:106,k:107,l:108,m:109,n:110,o:111,p:112,q:113,r:114, s:115,t:116,u:117,v:118,w:119,x:120,y:121,z:122,"{":123,"|":124, "}":125,"~":126,"\x7f":127,"\x80":128,"\x81":129,"\x82":130,"\x83":131, "\x84":132,"\x85":133,"\x86":134,"\x87":135,"\x88":136,"\x89":137, "\x8a":138,"\x8b":139,"\x8c":140,"\x8d":141,"\x8e":142,"\x8f":143, "\x90":144,"\x91":145,"\x92":146,"\x93":147,"\x94":148,"\x95":149, "\x96":150,"\x97":151,"\x98":152,"\x99":153,"\x9a":154,"\x9b":155, "\x9c":156,"\x9d":157,"\x9e":158,"\x9f":159,"\xa0":160,"\xa1":161, "\xa2":162,"\xa3":163,"\xa4":164,"\xa5":165,"\xa6":166,"\xa7":167, "\xa8":168,"\xa9":169,"\xaa":170,"\xab":171,"\xac":172,"\xad":173, "\xae":174,"\xaf":175,"\xb0":176,"\xb1":177,"\xb2":178,"\xb3":179, "\xb4":180,"\xb5":181,"\xb6":182,"\xb7":183,"\xb8":184,"\xb9":185, "\xba":186,"\xbb":187,"\xbc":188,"\xbd":189,"\xbe":190,"\xbf":191, "\xc0":192,"\xc1":193,"\xc2":194,"\xc3":195,"\xc4":196,"\xc5":197, "\xc6":198,"\xc7":199,"\xc8":200,"\xc9":201,"\xca":202,"\xcb":203, "\xcc":204,"\xcd":205,"\xce":206,"\xcf":207,"\xd0":208,"\xd1":209, "\xd2":210,"\xd3":211,"\xd4":212,"\xd5":213,"\xd6":214,"\xd7":215, "\xd8":216,"\xd9":217,"\xda":218,"\xdb":219,"\xdc":220,"\xdd":221, "\xde":222,"\xdf":223,"\xe0":224,"\xe1":225,"\xe2":226,"\xe3":227, "\xe4":228,"\xe5":229,"\xe6":230,"\xe7":231,"\xe8":232,"\xe9":233, "\xea":234,"\xeb":235,"\xec":236,"\xed":237,"\xee":238,"\xef":239, "\xf0":240,"\xf1":241,"\xf2":242,"\xf3":243,"\xf4":244,"\xf5":245, "\xf6":246,"\xf7":247,"\xf8":248,"\xf9":249,"\xfa":250,"\xfb":251, "\xfc":252,"\xfd":253,"\xfe":254,"\xff":255 }; } } first_256_unicode_chars_as_properties: { input: { var o = { "\u0000": 0, "\u0001": 1, "\u0002": 2, "\u0003": 3, "\u0004": 4, "\u0005": 5, "\u0006": 6, "\u0007": 7, "\u0008": 8, "\u0009": 9, "\u000A": 10, "\u000B": 11, "\u000C": 12, "\u000D": 13, "\u000E": 14, "\u000F": 15, "\u0010": 16, "\u0011": 17, "\u0012": 18, "\u0013": 19, "\u0014": 20, "\u0015": 21, "\u0016": 22, "\u0017": 23, "\u0018": 24, "\u0019": 25, "\u001A": 26, "\u001B": 27, "\u001C": 28, "\u001D": 29, "\u001E": 30, "\u001F": 31, "\u0020": 32, "\u0021": 33, "\u0022": 34, "\u0023": 35, "\u0024": 36, "\u0025": 37, "\u0026": 38, "\u0027": 39, "\u0028": 40, "\u0029": 41, "\u002A": 42, "\u002B": 43, "\u002C": 44, "\u002D": 45, "\u002E": 46, "\u002F": 47, "\u0030": 48, "\u0031": 49, "\u0032": 50, "\u0033": 51, "\u0034": 52, "\u0035": 53, "\u0036": 54, "\u0037": 55, "\u0038": 56, "\u0039": 57, "\u003A": 58, "\u003B": 59, "\u003C": 60, "\u003D": 61, "\u003E": 62, "\u003F": 63, "\u0040": 64, "\u0041": 65, "\u0042": 66, "\u0043": 67, "\u0044": 68, "\u0045": 69, "\u0046": 70, "\u0047": 71, "\u0048": 72, "\u0049": 73, "\u004A": 74, "\u004B": 75, "\u004C": 76, "\u004D": 77, "\u004E": 78, "\u004F": 79, "\u0050": 80, "\u0051": 81, "\u0052": 82, "\u0053": 83, "\u0054": 84, "\u0055": 85, "\u0056": 86, "\u0057": 87, "\u0058": 88, "\u0059": 89, "\u005A": 90, "\u005B": 91, "\u005C": 92, "\u005D": 93, "\u005E": 94, "\u005F": 95, "\u0060": 96, "\u0061": 97, "\u0062": 98, "\u0063": 99, "\u0064": 100, "\u0065": 101, "\u0066": 102, "\u0067": 103, "\u0068": 104, "\u0069": 105, "\u006A": 106, "\u006B": 107, "\u006C": 108, "\u006D": 109, "\u006E": 110, "\u006F": 111, "\u0070": 112, "\u0071": 113, "\u0072": 114, "\u0073": 115, "\u0074": 116, "\u0075": 117, "\u0076": 118, "\u0077": 119, "\u0078": 120, "\u0079": 121, "\u007A": 122, "\u007B": 123, "\u007C": 124, "\u007D": 125, "\u007E": 126, "\u007F": 127, "\u0080": 128, "\u0081": 129, "\u0082": 130, "\u0083": 131, "\u0084": 132, "\u0085": 133, "\u0086": 134, "\u0087": 135, "\u0088": 136, "\u0089": 137, "\u008A": 138, "\u008B": 139, "\u008C": 140, "\u008D": 141, "\u008E": 142, "\u008F": 143, "\u0090": 144, "\u0091": 145, "\u0092": 146, "\u0093": 147, "\u0094": 148, "\u0095": 149, "\u0096": 150, "\u0097": 151, "\u0098": 152, "\u0099": 153, "\u009A": 154, "\u009B": 155, "\u009C": 156, "\u009D": 157, "\u009E": 158, "\u009F": 159, "\u00A0": 160, "\u00A1": 161, "\u00A2": 162, "\u00A3": 163, "\u00A4": 164, "\u00A5": 165, "\u00A6": 166, "\u00A7": 167, "\u00A8": 168, "\u00A9": 169, "\u00AA": 170, "\u00AB": 171, "\u00AC": 172, "\u00AD": 173, "\u00AE": 174, "\u00AF": 175, "\u00B0": 176, "\u00B1": 177, "\u00B2": 178, "\u00B3": 179, "\u00B4": 180, "\u00B5": 181, "\u00B6": 182, "\u00B7": 183, "\u00B8": 184, "\u00B9": 185, "\u00BA": 186, "\u00BB": 187, "\u00BC": 188, "\u00BD": 189, "\u00BE": 190, "\u00BF": 191, "\u00C0": 192, "\u00C1": 193, "\u00C2": 194, "\u00C3": 195, "\u00C4": 196, "\u00C5": 197, "\u00C6": 198, "\u00C7": 199, "\u00C8": 200, "\u00C9": 201, "\u00CA": 202, "\u00CB": 203, "\u00CC": 204, "\u00CD": 205, "\u00CE": 206, "\u00CF": 207, "\u00D0": 208, "\u00D1": 209, "\u00D2": 210, "\u00D3": 211, "\u00D4": 212, "\u00D5": 213, "\u00D6": 214, "\u00D7": 215, "\u00D8": 216, "\u00D9": 217, "\u00DA": 218, "\u00DB": 219, "\u00DC": 220, "\u00DD": 221, "\u00DE": 222, "\u00DF": 223, "\u00E0": 224, "\u00E1": 225, "\u00E2": 226, "\u00E3": 227, "\u00E4": 228, "\u00E5": 229, "\u00E6": 230, "\u00E7": 231, "\u00E8": 232, "\u00E9": 233, "\u00EA": 234, "\u00EB": 235, "\u00EC": 236, "\u00ED": 237, "\u00EE": 238, "\u00EF": 239, "\u00F0": 240, "\u00F1": 241, "\u00F2": 242, "\u00F3": 243, "\u00F4": 244, "\u00F5": 245, "\u00F6": 246, "\u00F7": 247, "\u00F8": 248, "\u00F9": 249, "\u00FA": 250, "\u00FB": 251, "\u00FC": 252, "\u00FD": 253, "\u00FE": 254, "\u00FF": 255 }; } expect: { var o = { "\0":0,"\x01":1,"\x02":2,"\x03":3,"\x04":4,"\x05":5,"\x06":6, "\x07":7,"\b":8,"\t":9,"\n":10,"\v":11,"\f":12,"\r":13,"\x0e":14, "\x0f":15,"\x10":16,"\x11":17,"\x12":18,"\x13":19,"\x14":20,"\x15":21, "\x16":22,"\x17":23,"\x18":24,"\x19":25,"\x1a":26,"\x1b":27,"\x1c":28, "\x1d":29,"\x1e":30,"\x1f":31," ":32,"!":33,'"':34,"#":35,$:36, "%":37,"&":38,"'":39,"(":40,")":41,"*":42,"+":43,",":44,"-":45, ".":46,"/":47,0:48,1:49,2:50,3:51,4:52,5:53,6:54,7:55,8:56,9:57, ":":58,";":59,"<":60,"=":61,">":62,"?":63,"@":64,A:65,B:66,C:67, D:68,E:69,F:70,G:71,H:72,I:73,J:74,K:75,L:76,M:77,N:78,O:79,P:80, Q:81,R:82,S:83,T:84,U:85,V:86,W:87,X:88,Y:89,Z:90,"[":91,"\\":92, "]":93,"^":94,_:95,"`":96,a:97,b:98,c:99,d:100,e:101,f:102,g:103, h:104,i:105,j:106,k:107,l:108,m:109,n:110,o:111,p:112,q:113,r:114, s:115,t:116,u:117,v:118,w:119,x:120,y:121,z:122,"{":123,"|":124, "}":125,"~":126,"\x7f":127,"\x80":128,"\x81":129,"\x82":130,"\x83":131, "\x84":132,"\x85":133,"\x86":134,"\x87":135,"\x88":136,"\x89":137, "\x8a":138,"\x8b":139,"\x8c":140,"\x8d":141,"\x8e":142,"\x8f":143, "\x90":144,"\x91":145,"\x92":146,"\x93":147,"\x94":148,"\x95":149, "\x96":150,"\x97":151,"\x98":152,"\x99":153,"\x9a":154,"\x9b":155, "\x9c":156,"\x9d":157,"\x9e":158,"\x9f":159,"\xa0":160,"\xa1":161, "\xa2":162,"\xa3":163,"\xa4":164,"\xa5":165,"\xa6":166,"\xa7":167, "\xa8":168,"\xa9":169,"\xaa":170,"\xab":171,"\xac":172,"\xad":173, "\xae":174,"\xaf":175,"\xb0":176,"\xb1":177,"\xb2":178,"\xb3":179, "\xb4":180,"\xb5":181,"\xb6":182,"\xb7":183,"\xb8":184,"\xb9":185, "\xba":186,"\xbb":187,"\xbc":188,"\xbd":189,"\xbe":190,"\xbf":191, "\xc0":192,"\xc1":193,"\xc2":194,"\xc3":195,"\xc4":196,"\xc5":197, "\xc6":198,"\xc7":199,"\xc8":200,"\xc9":201,"\xca":202,"\xcb":203, "\xcc":204,"\xcd":205,"\xce":206,"\xcf":207,"\xd0":208,"\xd1":209, "\xd2":210,"\xd3":211,"\xd4":212,"\xd5":213,"\xd6":214,"\xd7":215, "\xd8":216,"\xd9":217,"\xda":218,"\xdb":219,"\xdc":220,"\xdd":221, "\xde":222,"\xdf":223,"\xe0":224,"\xe1":225,"\xe2":226,"\xe3":227, "\xe4":228,"\xe5":229,"\xe6":230,"\xe7":231,"\xe8":232,"\xe9":233, "\xea":234,"\xeb":235,"\xec":236,"\xed":237,"\xee":238,"\xef":239, "\xf0":240,"\xf1":241,"\xf2":242,"\xf3":243,"\xf4":244,"\xf5":245, "\xf6":246,"\xf7":247,"\xf8":248,"\xf9":249,"\xfa":250,"\xfb":251, "\xfc":252,"\xfd":253,"\xfe":254,"\xff":255 }; } } first_256_hex_chars_as_properties: { input: { var o = { "\x00": 0, "\x01": 1, "\x02": 2, "\x03": 3, "\x04": 4, "\x05": 5, "\x06": 6, "\x07": 7, "\x08": 8, "\x09": 9, "\x0A": 10, "\x0B": 11, "\x0C": 12, "\x0D": 13, "\x0E": 14, "\x0F": 15, "\x10": 16, "\x11": 17, "\x12": 18, "\x13": 19, "\x14": 20, "\x15": 21, "\x16": 22, "\x17": 23, "\x18": 24, "\x19": 25, "\x1A": 26, "\x1B": 27, "\x1C": 28, "\x1D": 29, "\x1E": 30, "\x1F": 31, "\x20": 32, "\x21": 33, "\x22": 34, "\x23": 35, "\x24": 36, "\x25": 37, "\x26": 38, "\x27": 39, "\x28": 40, "\x29": 41, "\x2A": 42, "\x2B": 43, "\x2C": 44, "\x2D": 45, "\x2E": 46, "\x2F": 47, "\x30": 48, "\x31": 49, "\x32": 50, "\x33": 51, "\x34": 52, "\x35": 53, "\x36": 54, "\x37": 55, "\x38": 56, "\x39": 57, "\x3A": 58, "\x3B": 59, "\x3C": 60, "\x3D": 61, "\x3E": 62, "\x3F": 63, "\x40": 64, "\x41": 65, "\x42": 66, "\x43": 67, "\x44": 68, "\x45": 69, "\x46": 70, "\x47": 71, "\x48": 72, "\x49": 73, "\x4A": 74, "\x4B": 75, "\x4C": 76, "\x4D": 77, "\x4E": 78, "\x4F": 79, "\x50": 80, "\x51": 81, "\x52": 82, "\x53": 83, "\x54": 84, "\x55": 85, "\x56": 86, "\x57": 87, "\x58": 88, "\x59": 89, "\x5A": 90, "\x5B": 91, "\x5C": 92, "\x5D": 93, "\x5E": 94, "\x5F": 95, "\x60": 96, "\x61": 97, "\x62": 98, "\x63": 99, "\x64": 100, "\x65": 101, "\x66": 102, "\x67": 103, "\x68": 104, "\x69": 105, "\x6A": 106, "\x6B": 107, "\x6C": 108, "\x6D": 109, "\x6E": 110, "\x6F": 111, "\x70": 112, "\x71": 113, "\x72": 114, "\x73": 115, "\x74": 116, "\x75": 117, "\x76": 118, "\x77": 119, "\x78": 120, "\x79": 121, "\x7A": 122, "\x7B": 123, "\x7C": 124, "\x7D": 125, "\x7E": 126, "\x7F": 127, "\x80": 128, "\x81": 129, "\x82": 130, "\x83": 131, "\x84": 132, "\x85": 133, "\x86": 134, "\x87": 135, "\x88": 136, "\x89": 137, "\x8A": 138, "\x8B": 139, "\x8C": 140, "\x8D": 141, "\x8E": 142, "\x8F": 143, "\x90": 144, "\x91": 145, "\x92": 146, "\x93": 147, "\x94": 148, "\x95": 149, "\x96": 150, "\x97": 151, "\x98": 152, "\x99": 153, "\x9A": 154, "\x9B": 155, "\x9C": 156, "\x9D": 157, "\x9E": 158, "\x9F": 159, "\xA0": 160, "\xA1": 161, "\xA2": 162, "\xA3": 163, "\xA4": 164, "\xA5": 165, "\xA6": 166, "\xA7": 167, "\xA8": 168, "\xA9": 169, "\xAA": 170, "\xAB": 171, "\xAC": 172, "\xAD": 173, "\xAE": 174, "\xAF": 175, "\xB0": 176, "\xB1": 177, "\xB2": 178, "\xB3": 179, "\xB4": 180, "\xB5": 181, "\xB6": 182, "\xB7": 183, "\xB8": 184, "\xB9": 185, "\xBA": 186, "\xBB": 187, "\xBC": 188, "\xBD": 189, "\xBE": 190, "\xBF": 191, "\xC0": 192, "\xC1": 193, "\xC2": 194, "\xC3": 195, "\xC4": 196, "\xC5": 197, "\xC6": 198, "\xC7": 199, "\xC8": 200, "\xC9": 201, "\xCA": 202, "\xCB": 203, "\xCC": 204, "\xCD": 205, "\xCE": 206, "\xCF": 207, "\xD0": 208, "\xD1": 209, "\xD2": 210, "\xD3": 211, "\xD4": 212, "\xD5": 213, "\xD6": 214, "\xD7": 215, "\xD8": 216, "\xD9": 217, "\xDA": 218, "\xDB": 219, "\xDC": 220, "\xDD": 221, "\xDE": 222, "\xDF": 223, "\xE0": 224, "\xE1": 225, "\xE2": 226, "\xE3": 227, "\xE4": 228, "\xE5": 229, "\xE6": 230, "\xE7": 231, "\xE8": 232, "\xE9": 233, "\xEA": 234, "\xEB": 235, "\xEC": 236, "\xED": 237, "\xEE": 238, "\xEF": 239, "\xF0": 240, "\xF1": 241, "\xF2": 242, "\xF3": 243, "\xF4": 244, "\xF5": 245, "\xF6": 246, "\xF7": 247, "\xF8": 248, "\xF9": 249, "\xFA": 250, "\xFB": 251, "\xFC": 252, "\xFD": 253, "\xFE": 254, "\xFF": 255 }; } expect: { var o = { "\0":0,"\x01":1,"\x02":2,"\x03":3,"\x04":4,"\x05":5,"\x06":6, "\x07":7,"\b":8,"\t":9,"\n":10,"\v":11,"\f":12,"\r":13,"\x0e":14, "\x0f":15,"\x10":16,"\x11":17,"\x12":18,"\x13":19,"\x14":20,"\x15":21, "\x16":22,"\x17":23,"\x18":24,"\x19":25,"\x1a":26,"\x1b":27,"\x1c":28, "\x1d":29,"\x1e":30,"\x1f":31," ":32,"!":33,'"':34,"#":35,$:36, "%":37,"&":38,"'":39,"(":40,")":41,"*":42,"+":43,",":44,"-":45, ".":46,"/":47,0:48,1:49,2:50,3:51,4:52,5:53,6:54,7:55,8:56,9:57, ":":58,";":59,"<":60,"=":61,">":62,"?":63,"@":64,A:65,B:66,C:67, D:68,E:69,F:70,G:71,H:72,I:73,J:74,K:75,L:76,M:77,N:78,O:79,P:80, Q:81,R:82,S:83,T:84,U:85,V:86,W:87,X:88,Y:89,Z:90,"[":91,"\\":92, "]":93,"^":94,_:95,"`":96,a:97,b:98,c:99,d:100,e:101,f:102,g:103, h:104,i:105,j:106,k:107,l:108,m:109,n:110,o:111,p:112,q:113,r:114, s:115,t:116,u:117,v:118,w:119,x:120,y:121,z:122,"{":123,"|":124, "}":125,"~":126,"\x7f":127,"\x80":128,"\x81":129,"\x82":130,"\x83":131, "\x84":132,"\x85":133,"\x86":134,"\x87":135,"\x88":136,"\x89":137, "\x8a":138,"\x8b":139,"\x8c":140,"\x8d":141,"\x8e":142,"\x8f":143, "\x90":144,"\x91":145,"\x92":146,"\x93":147,"\x94":148,"\x95":149, "\x96":150,"\x97":151,"\x98":152,"\x99":153,"\x9a":154,"\x9b":155, "\x9c":156,"\x9d":157,"\x9e":158,"\x9f":159,"\xa0":160,"\xa1":161, "\xa2":162,"\xa3":163,"\xa4":164,"\xa5":165,"\xa6":166,"\xa7":167, "\xa8":168,"\xa9":169,"\xaa":170,"\xab":171,"\xac":172,"\xad":173, "\xae":174,"\xaf":175,"\xb0":176,"\xb1":177,"\xb2":178,"\xb3":179, "\xb4":180,"\xb5":181,"\xb6":182,"\xb7":183,"\xb8":184,"\xb9":185, "\xba":186,"\xbb":187,"\xbc":188,"\xbd":189,"\xbe":190,"\xbf":191, "\xc0":192,"\xc1":193,"\xc2":194,"\xc3":195,"\xc4":196,"\xc5":197, "\xc6":198,"\xc7":199,"\xc8":200,"\xc9":201,"\xca":202,"\xcb":203, "\xcc":204,"\xcd":205,"\xce":206,"\xcf":207,"\xd0":208,"\xd1":209, "\xd2":210,"\xd3":211,"\xd4":212,"\xd5":213,"\xd6":214,"\xd7":215, "\xd8":216,"\xd9":217,"\xda":218,"\xdb":219,"\xdc":220,"\xdd":221, "\xde":222,"\xdf":223,"\xe0":224,"\xe1":225,"\xe2":226,"\xe3":227, "\xe4":228,"\xe5":229,"\xe6":230,"\xe7":231,"\xe8":232,"\xe9":233, "\xea":234,"\xeb":235,"\xec":236,"\xed":237,"\xee":238,"\xef":239, "\xf0":240,"\xf1":241,"\xf2":242,"\xf3":243,"\xf4":244,"\xf5":245, "\xf6":246,"\xf7":247,"\xf8":248,"\xf9":249,"\xfa":250,"\xfb":251, "\xfc":252,"\xfd":253,"\xfe":254,"\xff":255 }; } } native_prototype: { options = { unsafe_proto: true, } input: { Array.prototype.splice.apply(a, [1, 2, b, c]); Function.prototype.call.apply(console.log, console, [ "foo" ]); Number.prototype.toFixed.call(Math.PI, 2); Object.prototype.hasOwnProperty.call(d, "foo"); RegExp.prototype.test.call(/foo/, "bar"); String.prototype.indexOf.call(e, "bar"); } expect: { [].splice.apply(a, [1, 2, b, c]); (function() {}).call.apply(console.log, console, [ "foo" ]); 0..toFixed.call(Math.PI, 2); ({}).hasOwnProperty.call(d, "foo"); /t/.test.call(/foo/, "bar"); "".indexOf.call(e, "bar"); } } native_prototype_lhs: { options = { unsafe_proto: true, } input: { console.log(function() { Function.prototype.bar = "PASS"; return function() {}; }().bar); } expect: { console.log(function() { Function.prototype.bar = "PASS"; return function() {}; }().bar); } expect_stdout: "PASS" } accessor_boolean: { input: { var a = 1; var b = { get true() { return a; }, set false(c) { a = c; } }; console.log(b.true, b.false = 2, b.true); } expect_exact: 'var a=1;var b={get true(){return a},set false(c){a=c}};console.log(b.true,b.false=2,b.true);' expect_stdout: "1 2 2" } accessor_get_set: { input: { var a = 1; var b = { get set() { return a; }, set get(c) { a = c; } }; console.log(b.set, b.get = 2, b.set); } expect_exact: 'var a=1;var b={get set(){return a},set get(c){a=c}};console.log(b.set,b.get=2,b.set);' expect_stdout: "1 2 2" } accessor_null_undefined: { input: { var a = 1; var b = { get null() { return a; }, set undefined(c) { a = c; } }; console.log(b.null, b.undefined = 2, b.null); } expect_exact: 'var a=1;var b={get null(){return a},set undefined(c){a=c}};console.log(b.null,b.undefined=2,b.null);' expect_stdout: "1 2 2" } accessor_number: { input: { var a = 1; var b = { get 42() { return a; }, set 42(c) { a = c; } }; console.log(b[42], b[42] = 2, b[42]); } expect_exact: 'var a=1;var b={get 42(){return a},set 42(c){a=c}};console.log(b[42],b[42]=2,b[42]);' expect_stdout: "1 2 2" } accessor_string: { input: { var a = 1; var b = { get "a-b"() { return a; }, set "a-b"(c) { a = c; } }; console.log(b["a-b"], b["a-b"] = 2, b["a-b"]); } expect_exact: 'var a=1;var b={get"a-b"(){return a},set"a-b"(c){a=c}};console.log(b["a-b"],b["a-b"]=2,b["a-b"]);' expect_stdout: "1 2 2" } accessor_this: { input: { var a = 1; var b = { get this() { return a; }, set this(c) { a = c; } }; console.log(b.this, b.this = 2, b.this); } expect_exact: 'var a=1;var b={get this(){return a},set this(c){a=c}};console.log(b.this,b.this=2,b.this);' expect_stdout: "1 2 2" } issue_2208_1: { options = { inline: true, properties: true, side_effects: true, } input: { console.log({ p: function() { return 42; } }.p()); } expect: { console.log(42); } expect_stdout: "42" } issue_2208_2: { options = { inline: true, properties: true, side_effects: true, } input: { console.log({ a: 42, p: function() { return this.a; } }.p()); } expect: { console.log({ a: 42, p: function() { return this.a; } }.p()); } expect_stdout: "42" } issue_2208_3: { options = { inline: true, properties: true, side_effects: true, } input: { a = 42; console.log({ p: function() { return function() { return this.a; }(); } }.p()); } expect: { a = 42; console.log(function() { return this.a; }()); } expect_stdout: "42" } issue_2208_4: { options = { inline: true, properties: true, side_effects: true, } input: { function foo() {} console.log({ a: foo(), p: function() { return 42; } }.p()); } expect: { function foo() {} console.log((foo(), function() { return 42; })()); } expect_stdout: "42" } issue_2208_5: { options = { inline: true, properties: true, side_effects: true, } input: { console.log({ p: "FAIL", p: function() { return 42; } }.p()); } expect: { console.log(42); } expect_stdout: "42" } issue_2208_6: { options = { inline: true, properties: true, side_effects: true, } input: { console.log({ p: () => 42 }.p()); } expect: { console.log(42); } expect_stdout: "42" } issue_2208_7: { options = { ecma: 6, inline: true, properties: true, side_effects: true, unsafe_arrows: true, } input: { console.log({ p() { return 42; } }.p()); } expect: { console.log(42); } expect_stdout: "42" } issue_2208_8: { options = { ecma: 6, inline: true, properties: true, side_effects: true, unsafe_arrows: true, } input: { console.log({ *p() { return x(); } }.p()); console.log({ async p() { return await x(); } }.p()); } expect: { console.log({ *p() { return x(); } }.p()); console.log((async () => { return await x(); })()); } } issue_2208_9: { options = { inline: true, properties: true, side_effects: true, } input: { a = 42; console.log({ p: () => { return function() { return this.a; }(); } }.p()); } expect: { a = 42; console.log(function() { return this.a; }()); } expect_stdout: "42" } methods_keep_quoted_true: { options = { arrows: true, ecma: 6, unsafe_methods: true, } mangle = { properties: { keep_quoted: true, }, } input: { class C { "Quoted"(){} Unquoted(){} } f1({ "Quoted"(){}, Unquoted(){}, "Prop": 3 }); f2({ "Quoted": function(){} }); f3({ "Quoted": ()=>{} }); } expect_exact: "class C{Quoted(){}o(){}}f1({Quoted(){},o(){},Prop:3});f2({Quoted(){}});f3({Quoted(){}});" } methods_keep_quoted_false: { options = { arrows: true, ecma: 6, unsafe_methods: true, } mangle = { properties: { keep_quoted: false, }, } input: { class C { "Quoted"(){} Unquoted(){} } f1({ "Quoted"(){}, Unquoted(){}, "Prop": 3 }); f2({ "Quoted": function(){} }); f3({ "Quoted": ()=>{} }); } expect_exact: "class C{o(){}t(){}}f1({o(){},t(){},u:3});f2({o(){}});f3({o(){}});" } methods_keep_quoted_from_dead_code: { options = { arrows: true, booleans: true, conditionals: true, dead_code: true, ecma: 6, evaluate: true, reduce_funcs: true, reduce_vars: true, side_effects: true, unsafe_methods: true, } mangle = { properties: { keep_quoted: true, }, } input: { class C { Quoted(){} Unquoted(){} } f1({ Quoted(){}, Unquoted(){}, "Prop": 3 }); f2({ Quoted: function(){} }); f3({ Quoted: ()=>{} }); 0 && obj["Quoted"]; } expect_exact: "class C{Quoted(){}o(){}}f1({Quoted(){},o(){},Prop:3});f2({Quoted(){}});f3({Quoted(){}});" } issue_2256: { options = { side_effects: true, } mangle = { properties: { keep_quoted: true, }, } input: { var g = {}; ({ "keep": 1 }); g.keep = g.change; } expect: { var g = {}; g.keep = g.g; } } issue_2321: { options = { ecma: 6, unsafe_methods: false, } input: { var f = { foo: function(){ console.log("foo") }, bar() { console.log("bar") } }; var foo = new f.foo(); var bar = f.bar(); } expect: { var f = { foo: function() { console.log("foo"); }, bar() { console.log("bar"); } }; var foo = new f.foo(); var bar = f.bar(); } expect_stdout: [ "foo", "bar", ] } unsafe_methods_regex: { options = { ecma: 6, unsafe_methods: /^[A-Z1]/, } input: { var f = { 123: function(){ console.log("123") }, foo: function(){ console.log("foo") }, bar() { console.log("bar") }, Baz: function(){ console.log("baz") }, BOO: function(){ console.log("boo") }, null: function(){ console.log("null") }, undefined: function(){ console.log("undefined") }, }; f[123](); new f.foo(); f.bar(); f.Baz(); f.BOO(); new f.null(); new f.undefined(); } expect: { var f = { 123() { console.log("123") }, foo: function(){ console.log("foo") }, bar() { console.log("bar"); }, Baz() { console.log("baz") }, BOO() { console.log("boo") }, null: function(){ console.log("null") }, undefined: function(){ console.log("undefined") }, }; f[123](); new f.foo(); f.bar(); f.Baz(); f.BOO(); new f.null(); new f.undefined(); } expect_stdout: [ "123", "foo", "bar", "baz", "boo", "null", "undefined", ] } lhs_prop_1: { options = { evaluate: true, properties: true, } input: { console.log(++{ a: 1 }.a); } expect: { console.log(++{ a: 1 }.a); } expect_stdout: "2" } lhs_prop_2: { options = { evaluate: true, inline: true, properties: true, reduce_funcs: true, reduce_vars: true, side_effects: true, unused: true, } input: { [1][0] = 42; (function(a) { a.b = "g"; })("abc"); (function(a) { a[2] = "g"; })("def"); (function(a) { a[""] = "g"; })("ghi"); } expect: { [1][0] = 42; "abc".b = "g"; "def"[2] = "g"; "ghi"[""] = "g"; } } literal_duplicate_key_side_effects: { options = { properties: true, side_effects: true, } input: { console.log({ a: "FAIL", a: console.log ? "PASS" : "FAIL" }.a); } expect: { console.log(console.log ? "PASS" : "FAIL"); } expect_stdout: "PASS" } prop_side_effects_1: { options = { evaluate: true, inline: true, properties: true, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { var C = 1; console.log(C); var obj = { bar: function() { return C + C; } }; console.log(obj.bar()); } expect: { console.log(1); var obj = { bar: function() { return 2; } }; console.log(obj.bar()); } expect_stdout: [ "1", "2", ] } prop_side_effects_2: { options = { evaluate: true, inline: true, passes: 2, properties: true, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { var C = 1; console.log(C); var obj = { "": function() { return C + C; } }; console.log(obj[""]()); } expect: { console.log(1); console.log(2); } expect_stdout: [ "1", "2", ] } accessor_1: { options = { properties: true, } input: { console.log({ a: "FAIL", get a() { return "PASS"; } }.a); } expect: { console.log({ a: "FAIL", get a() { return "PASS"; } }.a); } expect_stdout: "PASS" } accessor_2: { options = { properties: true, } input: { console.log({ get a() { return "PASS"; }, set a(v) {}, a: "FAIL" }.a); } expect: { console.log({ get a() { return "PASS"; }, set a(v) {}, a: "FAIL" }.a); } expect_stdout: true } array_hole: { options = { properties: true, side_effects: true, } input: { console.log( [ 1, 2, , 3][1], [ 1, 2, , 3][2], [ 1, 2, , 3][3] ); } expect: { console.log(2, void 0, 3); } expect_stdout: "2 undefined 3" } computed_property: { options = { properties: true, side_effects: true, } input: { console.log({ a: "bar", [console.log("foo")]: 42, }.a); } expect: { console.log([ "bar", console.log("foo") ][0]); } expect_stdout: [ "foo", "bar" ] } new_this: { options = { properties: true, side_effects: true, } input: { new { f: function(a) { this.a = a; } }.f(42); } expect: { new function(a) { this.a = a; }(42); } } issue_2513: { options = { evaluate: true, properties: true, } input: { !function(Infinity, NaN, undefined) { console.log("a"[1/0], "b"["Infinity"]); console.log("c"[0/0], "d"["NaN"]); console.log("e"[void 0], "f"["undefined"]); }(0, 0, 0); } expect: { !function(Infinity, NaN, undefined) { console.log("a"[1/0], "b"[1/0]); console.log("c".NaN, "d".NaN); console.log("e"[void 0], "f"[void 0]); }(0, 0, 0); } expect_stdout: [ "undefined undefined", "undefined undefined", "undefined undefined", ] } const_prop_assign_strict: { options = { pure_getters: "strict", side_effects: true, } input: { function Simulator() { /abc/.index = 1; this._aircraft = []; } (function() {}).prototype.destroy = x(); } expect: { function Simulator() { this._aircraft = []; } x(); } } const_prop_assign_pure: { options = { pure_getters: true, side_effects: true, } input: { function Simulator() { /abc/.index = 1; this._aircraft = []; } (function() {}).prototype.destroy = x(); } expect: { function Simulator() { this._aircraft = []; } x(); } } join_object_assignments_1: { options = { evaluate: true, join_vars: true, } input: { console.log(function() { var x = { a: 1, c: (console.log("c"), "C"), }; x.b = 2; x[3] = function() { console.log(x); }, x["a"] = /foo/, x.bar = x; return x; }()); } expect: { console.log(function() { var x = { a: (1, /foo/), c: (console.log("c"), "C"), b: 2, 3: function() { console.log(x); }, }; x.bar = x; return x; }()); } expect_stdout: true } join_object_assignments_2: { options = { evaluate: true, hoist_props: true, join_vars: true, passes: 3, reduce_vars: true, toplevel: true, unused: true, } input: { var o = { foo: 1, }; o.bar = 2; o.baz = 3; console.log(o.foo, o.bar + o.bar, o.foo * o.bar * o.baz); } expect: { console.log(1, 4, 6); } expect_stdout: "1 4 6" } join_object_assignments_3: { options = { evaluate: true, join_vars: true, } input: { console.log(function() { var o = { a: "PASS", }, a = o.a; o.a = "FAIL"; return a; }()); } expect: { console.log(function() { var o = { a: "PASS", }, a = o.a; o.a = "FAIL"; return a; }()); } expect_stdout: "PASS" } join_object_assignments_4: { options = { join_vars: true, sequences: true, } input: { var o; console.log(o); o = {}; o.a = "foo"; console.log(o.b); o.b = "bar"; console.log(o.a); } expect_stdout: [ "undefined", "undefined", "foo", ] } join_object_assignments_return_1: { options = { join_vars: true, } input: { console.log(function() { var o = { p: 3 }; return o.q = "foo"; }()); } expect: { console.log(function() { var o = { p: 3, q: "foo" }; return o.q; }()); } expect_stdout: "foo" } join_object_assignments_return_2: { options = { join_vars: true, } input: { console.log(function() { var o = { p: 3 }; return o.q = /foo/, o.r = "bar"; }()); } expect: { console.log(function() { var o = { p: 3, q: /foo/, r: "bar" }; return o.r; }()); } expect_stdout: "bar" } join_object_assignments_return_3: { options = { join_vars: true, } input: { console.log(function() { var o = { p: 3 }; return o.q = "foo", o.p += "", console.log(o.q), o.p; }()); } expect: { console.log(function() { var o = { p: 3, q: "foo" }; return o.p += "", console.log(o.q), o.p; }()); } expect_stdout: [ "foo", "3", ] } join_object_assignments_for: { options = { join_vars: true, } input: { console.log(function() { var o = { p: 3 }; for (o.q = "foo"; console.log(o.q);); return o.p; }()); } expect: { console.log(function() { for (var o = { p: 3, q: "foo" }; console.log(o.q);); return o.p; }()); } expect_stdout: [ "foo", "3", ] } join_object_assignments_if: { options = { join_vars: true, } input: { console.log(function() { var o = {}; if (o.a = "PASS") return o.a; }()) } expect: { console.log(function() { var o = { a: "PASS" }; if (o.a) return o.a; }()); } expect_stdout: "PASS" } join_object_assignments_forin: { options = { join_vars: true, } input: { console.log(function() { var o = {}; for (var a in o.a = "PASS", o) return o[a]; }()) } expect: { console.log(function() { var o = { a: "PASS" }; for (var a in o) return o[a]; }()); } expect_stdout: "PASS" } join_object_assignments_negative: { options = { evaluate: true, join_vars: true, properties: true, } input: { var o = {}; o[0] = 0; o[-0] = 1; o[-1] = 2; console.log(o[0], o[-0], o[-1]); } expect: { var o = { 0: (0, 1), "-1": 2 }; console.log(o[0], o[-0], o[-1]); } expect_stdout: "1 1 2" } join_object_assignments_NaN_1: { options = { join_vars: true, } input: { var o = {}; o[NaN] = 1; o[0/0] = 2; console.log(o[NaN], o[NaN]); } expect: { var o = {}; o[NaN] = 1; o[0/0] = 2; console.log(o[NaN], o[NaN]); } expect_stdout: "2 2" } join_object_assignments_NaN_2: { options = { evaluate: true, join_vars: true, properties: true, } input: { var o = {}; o[NaN] = 1; o[0/0] = 2; console.log(o[NaN], o[NaN]); } expect: { var o = { NaN: (1, 2), }; console.log(o.NaN, o.NaN); } expect_stdout: "2 2" } join_object_assignments_null_0: { options = { join_vars: true, } input: { var o = {}; o[null] = 1; console.log(o[null]); } expect: { var o = {}; o[null] = 1; console.log(o[null]); } expect_stdout: "1" } join_object_assignments_null_1: { options = { evaluate: true, join_vars: true, properties: true, } input: { var o = {}; o[null] = 1; console.log(o[null]); } expect: { var o = { null: 1 }; console.log(o.null); } expect_stdout: "1" } join_object_assignments_void_0: { options = { evaluate: true, join_vars: true, } input: { var o = {}; o[void 0] = 1; console.log(o[void 0]); } expect: { var o = { undefined: 1 }; console.log(o[void 0]); } expect_stdout: "1" } join_object_assignments_undefined_1: { options = { join_vars: true, } input: { var o = {}; o[undefined] = 1; console.log(o[undefined]); } expect: { var o = {}; o[void 0] = 1; console.log(o[void 0]); } expect_stdout: "1" } join_object_assignments_undefined_2: { options = { evaluate: true, join_vars: true, properties: true, } input: { var o = {}; o[undefined] = 1; console.log(o[undefined]); } expect: { var o = { undefined : 1 }; console.log(o[void 0]); } expect_stdout: "1" } join_object_assignments_Infinity: { options = { evaluate: true, join_vars: true, properties: true, } input: { var o = {}; o[Infinity] = 1; o[1/0] = 2; o[-Infinity] = 3; o[-1/0] = 4; console.log(o[Infinity], o[1/0], o[-Infinity], o[-1/0]); } expect: { var o = { Infinity: (1, 2), "-Infinity": (3, 4) }; console.log(o[1/0], o[1/0], o[-1/0], o[-1/0]); } expect_stdout: "2 2 4 4" } join_object_assignments_regex: { options = { evaluate: true, join_vars: true, properties: true, } input: { var o = {}; o[/rx/] = 1; console.log(o[/rx/]); } expect: { var o = { "/rx/": 1 }; console.log(o[/rx/]); } expect_stdout: "1" } issue_2816: { options = { join_vars: true, } input: { "use strict"; var o = { a: 1 }; o.b = 2; o.a = 3; o.c = 4; console.log(o.a, o.b, o.c); } expect: { "use strict"; var o = { a: 1, b: 2 }; o.a = 3; o.c = 4; console.log(o.a, o.b, o.c); } expect_stdout: "3 2 4" } issue_2816_ecma6: { options = { ecma: "6", join_vars: true, } input: { "use strict"; var o = { a: 1 }; o.b = 2; o.a = 3; o.c = 4; console.log(o.a, o.b, o.c); } expect: { "use strict"; var o = { a: (1, 3), b: 2, c: 4 }; console.log(o.a, o.b, o.c); } expect_stdout: "3 2 4" } issue_2893_1: { options = { ecma: 5, join_vars: true, } input: { var o = { get a() { return "PASS"; }, }; o.a = "FAIL"; console.log(o.a); } expect: { var o = { get a() { return "PASS"; }, }; o.a = "FAIL"; console.log(o.a); } expect_stdout: "PASS" } issue_2893_2: { options = { ecma: 5, join_vars: true, } input: { var o = { set a(v) { this.b = v; }, b: "FAIL", }; o.a = "PASS"; console.log(o.b); } expect: { var o = { set a(v) { this.b = v; }, b: "FAIL", }; o.a = "PASS"; console.log(o.b); } expect_stdout: "PASS" } issue_2893_3: { options = { ecma: 6, join_vars: true, } input: { var o = { get a() { return "PASS"; }, }; o.a = "FAIL"; console.log(o.a); } expect: { var o = { get a() { return "PASS"; } }; o.a = "FAIL"; console.log(o.a); } expect_stdout: "PASS" } issue_2893_4: { options = { ecma: 6, join_vars: true, } input: { var o = { set a(v) { this.b = v; }, b: "FAIL", }; o.a = "PASS"; console.log(o.b); } expect: { var o = { set a(v) { this.b = v; }, b: "FAIL" }; o.a = "PASS"; console.log(o.b); } expect_stdout: "PASS" } issue_2893_5: { options = { ecma: 5, join_vars: true, } input: { "use strict"; var o = { get a() { return "PASS"; }, }; o.a = "FAIL"; console.log(o.a); } expect: { "use strict"; var o = { get a() { return "PASS"; }, }; o.a = "FAIL"; console.log(o.a); } expect_stdout: true // TypeError: Cannot set property a of # which has only a getter } issue_2893_6: { options = { ecma: 5, join_vars: true, } input: { "use strict"; var o = { set a(v) { this.b = v; }, b: "FAIL", }; o.a = "PASS"; console.log(o.b); } expect: { "use strict"; var o = { set a(v) { this.b = v; }, b: "FAIL", }; o.a = "PASS"; console.log(o.b); } expect_stdout: "PASS" } issue_2893_7: { options = { ecma: 6, join_vars: true, } input: { "use strict"; var o = { get a() { return "PASS"; }, }; o.a = "FAIL"; console.log(o.a); } expect: { "use strict"; var o = { get a() { return "PASS"; } }; o.a = "FAIL"; console.log(o.a); } expect_stdout: true // TypeError: Cannot set property a of # which has only a getter } issue_2893_8: { options = { ecma: 6, join_vars: true, } input: { "use strict"; var o = { set a(v) { this.b = v; }, b: "FAIL", }; o.a = "PASS"; console.log(o.b); } expect: { "use strict"; var o = { set a(v) { this.b = v; }, b: "FAIL" }; o.a = "PASS"; console.log(o.b); } expect_stdout: "PASS" } issue_869_1: { mangle = { properties: { reserved: [ "get" ] }, } input: { var o = { p: "FAIL" }; Object.defineProperty(o, "p", { get: function() { return "PASS"; } }); console.log(o.p); } expect: { var o = { o: "FAIL" }; Object.defineProperty(o, "o", { get: function() { return "PASS"; } }); console.log(o.o); } expect_stdout: "PASS" } issue_869_2: { mangle = { properties: { reserved: [ "get" ] }, } input: { var o = { p: "FAIL" }; Object.defineProperties(o, { p: { get: function() { return "PASS"; } } }); console.log(o.p); } expect: { var o = { o: "FAIL" }; Object.defineProperties(o, { o: { get: function() { return "PASS"; } } }); console.log(o.o); } expect_stdout: "PASS" } issue_3188_1: { options = { collapse_vars: true, inline: true, properties: true, reduce_vars: true, side_effects: true, } input: { (function() { function f() { console.log(this.p); } (function() { var o = { p: "PASS", f: f }; o.f(); })(); })(); } expect: { (function() { function f() { console.log(this.p); } ({ p: "PASS", f: f }).f(); var o; })(); } expect_stdout: "PASS" } issue_3188_2: { options = { collapse_vars: true, inline: true, properties: true, reduce_vars: true, side_effects: true, unused: true, } input: { (function() { var f = function() { console.log(this.p); }; function g() { var o = { p: "PASS", f: f }; o.f(); } g(); })(); } expect_stdout: "PASS" } issue_3188_3: { options = { collapse_vars: true, inline: true, properties: true, reduce_vars: true, side_effects: true, } input: { (function() { function f() { console.log(this[0]); } (function() { var o = ["PASS", f]; o[1](); })(); })(); } expect: { (function() { function f() { console.log(this[0]); } ["PASS", f][1](); var o; })(); } expect_stdout: "PASS" } issue_t64: { options = { collapse_vars: true, join_vars: true, properties: true, reduce_vars: true, side_effects: true, unused: true, } input: { var obj = {}; obj.Base = class { constructor() { this.id = "PASS"; } }; obj.Derived = class extends obj.Base { constructor() { super(); console.log(this.id); } }; new obj.Derived; } expect: { var obj = { Base: class { constructor() { this.id = "PASS"; } } }; obj.Derived = class extends obj.Base { constructor() { super(); console.log(this.id); } }; new obj.Derived(); } expect_stdout: "PASS" } dont_mangle_computed_property_1: { mangle = { properties: {} } input: { "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"; "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"; const prop = Symbol("foo"); const obj = { [prop]: "bar", "baz": 1, qux: 2, [3 + 4]: "seven", 0: "zero", 1: "one", null: "Null", undefined: "Undefined", Infinity: "infinity", NaN: "nan", void: "Void", } console.log(obj[prop], obj["baz"], obj.qux, obj[7], obj[0], obj[1+0], obj[null], obj[undefined], obj[1/0], obj[NaN], obj.void); console.log(obj.null, obj.undefined, obj.Infinity, obj.NaN); } expect: { "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"; "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"; const prop = Symbol("foo"); const obj = { [prop]: "bar", A: 1, B: 2, [3 + 4]: "seven", 0: "zero", 1: "one", null: "Null", undefined: "Undefined", Infinity: "infinity", NaN: "nan", C: "Void", }; console.log(obj[prop], obj["A"], obj.B, obj[7], obj[0], obj[1+0], obj[null], obj[void 0], obj[1/0], obj[NaN], obj.C); console.log(obj.null, obj.undefined, obj.Infinity, obj.NaN); } expect_stdout: [ "bar 1 2 seven zero one Null Undefined infinity nan Void", "Null Undefined infinity nan", ] } dont_mangle_computed_property_2: { options = { defaults: true, toplevel: true, } mangle = { properties: {}, toplevel: true, } input: { const prop = Symbol("foo"); const obj = { [prop]: "bar", "baz": 1, qux: 2, [3 + 4]: "seven", 0: "zero", 1: "one", null: "Null", undefined: "Undefined", Infinity: "infinity", NaN: "nan", void: "Void", } console.log(obj[prop], obj["baz"], obj.qux, obj[7], obj[0], obj[1+0], obj[null], obj[undefined], obj[1/0], obj[NaN], obj.void); console.log(obj.null, obj.undefined, obj.Infinity, obj.NaN); } expect: { const n=Symbol("foo"),o={[n]:"bar",o:1,i:2,7:"seven",0:"zero",1:"one",null:"Null",undefined:"Undefined",Infinity:"infinity",NaN:"nan",l:"Void"}; console.log(o[n],o.o,o.i,o[7],o[0],o[1],o.null,o[void 0],o[1/0],o.NaN,o.l),console.log(o.null,o.undefined,o.Infinity,o.NaN); } expect_stdout: [ "bar 1 2 seven zero one Null Undefined infinity nan Void", "Null Undefined infinity nan", ] } mangle_properties_which_matches_pattern: { options = { defaults: true } mangle = { properties: { regex: '^_' } } input: { var acd = { get asd() { return this._asd; }, _asd: true }; console.log(acd) } expect: { var acd = { get asd() { return this.s }, s: !0 }; console.log(acd); } } terser-4.1.2/test/compress/pure_funcs.js000066400000000000000000000333121351061312300203400ustar00rootroot00000000000000array: { options = { pure_funcs: [ "Math.floor" ], side_effects: true, } input: { var a; function f(b) { Math.floor(a / b); Math.floor(c / b); } } expect: { var a; function f(b) { c; } } } func: { options = { pure_funcs: function(node) { return !~node.args[0].print_to_string().indexOf("a"); }, side_effects: true, } input: { function f(a, b) { Math.floor(a / b); Math.floor(c / b); } } expect: { function f(a, b) { Math.floor(c / b); } } } side_effects: { options = { pure_funcs: [ "console.log" ], side_effects: true, } input: { function f(a, b) { console.log(a()); console.log(b); } } expect: { function f(a, b) { a(); } } } unused: { options = { pure_funcs: [ "pure" ], side_effects: true, unused: true, } input: { function foo() { var u = pure(1); var x = pure(2); var y = pure(x); var z = pure(pure(side_effects())); return pure(3); } } expect: { function foo() { side_effects(); return pure(3); } } } babel: { options = { pure_funcs: [ "_classCallCheck" ], side_effects: true, unused: true, } input: { function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } var Foo = function Foo() { _classCallCheck(this, Foo); }; } expect: { function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } var Foo = function() { }; } } conditional: { options = { 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(); } } relational: { options = { pure_funcs: [ "foo" ], side_effects :true, } input: { foo() in foo(); foo() instanceof bar(); foo() < "bar"; bar() > foo(); bar() != bar(); bar() !== "bar"; "bar" == foo(); "bar" === bar(); "bar" >= "bar"; } expect: { bar(); bar(); bar(), bar(); bar(); bar(); } } arithmetic: { options = { pure_funcs: [ "foo" ], side_effects :true, } input: { foo() + foo(); foo() - bar(); foo() * "bar"; bar() / foo(); bar() & bar(); bar() | "bar"; "bar" >> foo(); "bar" << bar(); "bar" >>> "bar"; } expect: { bar(); bar(); bar(), bar(); bar(); bar(); } } boolean_and: { options = { pure_funcs: [ "foo" ], side_effects :true, } input: { foo() && foo(); foo() && bar(); foo() && "bar"; bar() && foo(); bar() && bar(); bar() && "bar"; "bar" && foo(); "bar" && bar(); "bar" && "bar"; } expect: { foo() && bar(); bar(); bar() && bar(); bar(); "bar" && bar(); } } boolean_or: { options = { pure_funcs: [ "foo" ], side_effects :true, } input: { foo() || foo(); foo() || bar(); foo() || "bar"; bar() || foo(); bar() || bar(); bar() || "bar"; "bar" || foo(); "bar" || bar(); "bar" || "bar"; } expect: { foo() || bar(); bar(); bar() || bar(); bar(); "bar" || bar(); } } assign: { options = { pure_funcs: [ "foo" ], side_effects :true, } input: { var a; function f(b) { a = foo(); b *= 4 + foo(); c >>= 0 | foo(); } } expect: { var a; function f(b) { a = foo(); b *= 4 + foo(); c >>= 0 | foo(); } } } unary: { options = { pure_funcs: [ "foo" ], side_effects :true, } input: { typeof foo(); typeof bar(); typeof "bar"; void foo(); void bar(); void "bar"; delete a[foo()]; delete a[bar()]; delete a["bar"]; a[foo()]++; a[bar()]++; a["bar"]++; --a[foo()]; --a[bar()]; --a["bar"]; ~foo(); ~bar(); ~"bar"; } expect: { bar(); bar(); delete a[foo()]; delete a[bar()]; delete a["bar"]; a[foo()]++; a[bar()]++; a["bar"]++; --a[foo()]; --a[bar()]; --a["bar"]; bar(); } } issue_2629_1: { options = { side_effects: true, } beautify = { comments: "all", } input: { /*@__PURE__*/ a(); /*@__PURE__*/ (b()); (/*@__PURE__*/ c)(); (/*@__PURE__*/ d()); } expect_exact: [ "/* */c();", ] } issue_2629_2: { options = { side_effects: true, } beautify = { comments: "all", } input: { /*@__PURE__*/ a(1)(2)(3); /*@__PURE__*/ (b(1))(2)(3); /*@__PURE__*/ (c(1)(2))(3); /*@__PURE__*/ (d(1)(2)(3)); (/*@__PURE__*/ e)(1)(2)(3); (/*@__PURE__*/ f(1))(2)(3); (/*@__PURE__*/ g(1)(2))(3); (/*@__PURE__*/ h(1)(2)(3)); } expect_exact: [ "/* */e(1)(2)(3);", "/* */f(1)(2)(3);", "/* */g(1)(2)(3);", ] } issue_2629_3: { options = { side_effects: true, } beautify = { comments: "all", } input: { /*@__PURE__*/ a.x(1).y(2).z(3); /*@__PURE__*/ (b.x)(1).y(2).z(3); /*@__PURE__*/ (c.x(1)).y(2).z(3); /*@__PURE__*/ (d.x(1).y)(2).z(3); /*@__PURE__*/ (e.x(1).y(2)).z(3); /*@__PURE__*/ (f.x(1).y(2).z)(3); /*@__PURE__*/ (g.x(1).y(2).z(3)); (/*@__PURE__*/ h).x(1).y(2).z(3); (/*@__PURE__*/ i.x)(1).y(2).z(3); (/*@__PURE__*/ j.x(1)).y(2).z(3); (/*@__PURE__*/ k.x(1).y)(2).z(3); (/*@__PURE__*/ l.x(1).y(2)).z(3); (/*@__PURE__*/ m.x(1).y(2).z)(3); (/*@__PURE__*/ n.x(1).y(2).z(3)); } expect_exact: [ "/* */h.x(1).y(2).z(3);", "/* */i.x(1).y(2).z(3);", "/* */j.x(1).y(2).z(3);", "/* */k.x(1).y(2).z(3);", "/* */l.x(1).y(2).z(3);", "/* */m.x(1).y(2).z(3);", ] } issue_2629_4: { options = { side_effects: true, } input: { (/*@__PURE__*/ x(), y()); (w(), /*@__PURE__*/ x(), y()); } expect: { y(); w(), y(); } } issue_2629_5: { options = { side_effects: true, } input: { [ /*@__PURE__*/ x() ]; [ /*@__PURE__*/ x(), y() ]; [ w(), /*@__PURE__*/ x(), y() ]; } expect: { y(); w(), y(); } } issue_2638: { options = { side_effects: true, } beautify = { comments: "all", } input: { /*@__PURE__*/(g() || h())(x(), y()); (/*@__PURE__*/ (a() || b()))(c(), d()); } expect_exact: [ "/* */x(),y();", "/* */(a()||b())(c(),d());", ] } issue_2705_1: { options = { side_effects: true, } beautify = { comments: "all", } input: { /*@__PURE__*/ new a(); /*@__PURE__*/ (new b()); new (/*@__PURE__*/ c)(); (/*@__PURE__*/ new d()); } expect_exact: [ "new/* */c;", ] } issue_2705_2: { options = { side_effects: true, } beautify = { comments: "all", } input: { /*@__PURE__*/ new a(1)(2)(3); /*@__PURE__*/ new (b(1))(2)(3); /*@__PURE__*/ new (c(1)(2))(3); /*@__PURE__*/ new (d(1)(2)(3)); new (/*@__PURE__*/ e)(1)(2)(3); (/*@__PURE__*/ new f(1))(2)(3); (/*@__PURE__*/ new g(1)(2))(3); (/*@__PURE__*/ new h(1)(2)(3)); } expect_exact: [ "new/* */e(1)(2)(3);", "/* */new f(1)(2)(3);", "/* */new g(1)(2)(3);", ] } issue_2705_3: { options = { side_effects: true, } beautify = { comments: "all", } input: { /*@__PURE__*/ new a.x(1).y(2).z(3); /*@__PURE__*/ new (b.x)(1).y(2).z(3); /*@__PURE__*/ new (c.x(1)).y(2).z(3); /*@__PURE__*/ new (d.x(1).y)(2).z(3); /*@__PURE__*/ new (e.x(1).y(2)).z(3); /*@__PURE__*/ new (f.x(1).y(2).z)(3); /*@__PURE__*/ new (g.x(1).y(2).z(3)); new (/*@__PURE__*/ h).x(1).y(2).z(3); /* */ new (/*@__PURE__*/ i.x)(1).y(2).z(3); (/*@__PURE__*/ new j.x(1)).y(2).z(3); (/*@__PURE__*/ new k.x(1).y)(2).z(3); (/*@__PURE__*/ new l.x(1).y(2)).z(3); (/*@__PURE__*/ new m.x(1).y(2).z)(3); (/*@__PURE__*/ new n.x(1).y(2).z(3)); } expect_exact: [ "new/* */h.x(1).y(2).z(3);", "/* */new/* */i.x(1).y(2).z(3);", "/* */new j.x(1).y(2).z(3);", "/* */new k.x(1).y(2).z(3);", "/* */new l.x(1).y(2).z(3);", "/* */new m.x(1).y(2).z(3);", ] } issue_2705_4: { options = { side_effects: true, } input: { (/*@__PURE__*/ new x(), y()); (w(), /*@__PURE__*/ new x(), y()); } expect: { y(); w(), y(); } } issue_2705_5: { options = { side_effects: true, } input: { [ /*@__PURE__*/ new x() ]; [ /*@__PURE__*/ new x(), y() ]; [ w(), /*@__PURE__*/ new x(), y() ]; } expect: { y(); w(), y(); } } issue_2705_6: { options = { side_effects: true, } beautify = { comments: "all", } input: { /*@__PURE__*/new (g() || h())(x(), y()); /* */ new (/*@__PURE__*/ (a() || b()))(c(), d()); } expect_exact: [ "/* */x(),y();", "/* */new(/* */a()||b())(c(),d());", ] } issue_3065_1: { options = { inline: true, pure_funcs: [ "pureFunc" ], reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { function modifyWrapper(a, f, wrapper) { wrapper.a = a; wrapper.f = f; return wrapper; } function pureFunc(fun) { return modifyWrapper(1, fun, function(a) { return fun(a); }); } var unused = pureFunc(function(x) { return x; }); } expect: {} } issue_3065_2: { rename = true options = { inline: true, pure_funcs: [ "pureFunc" ], reduce_vars: true, side_effects: true, toplevel: true, unused: true, } mangle = { reserved: [ "pureFunc" ], toplevel: true, } input: { function modifyWrapper(a, f, wrapper) { wrapper.a = a; wrapper.f = f; return wrapper; } function pureFunc(fun) { return modifyWrapper(1, fun, function(a) { return fun(a); }); } var unused = pureFunc(function(x) { return x; }); } expect: {} } issue_3065_2b: { rename = false options = { inline: true, pure_funcs: [ "pureFunc" ], reduce_vars: true, side_effects: true, toplevel: true, unused: true, } mangle = { toplevel: true, } input: { function modifyWrapper(a, f, wrapper) { wrapper.a = a; wrapper.f = f; return wrapper; } function pureFunc(fun) { return modifyWrapper(1, fun, function(a) { return fun(a); }); } var unused = pureFunc(function(x) { return x; }); function print(message) { console.log(message); } print(2); print(3); } expect: { function o(o) { console.log(o); } o(2); o(3); } expect_stdout: [ "2", "3", ] } issue_3065_3: { options = { pure_funcs: [ "debug" ], reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { function debug(msg) { console.log(msg); } debug(function() { console.log("PASS"); return "FAIL"; }()); } expect: { (function() { console.log("PASS"); })(); } } issue_3065_4: { options = { pure_funcs: [ "debug" ], reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { var debug = function(msg) { console.log(msg); }; debug(function() { console.log("PASS"); return "FAIL"; }()); } expect: { (function() { console.log("PASS"); })(); } } terser-4.1.2/test/compress/pure_getters.js000066400000000000000000000575571351061312300207200ustar00rootroot00000000000000strict: { options = { pure_getters: "strict", reduce_funcs: false, reduce_vars: false, side_effects: true, toplevel: true, } input: { var a, b = null, c = {}; a.prop; b.prop; c.prop; d.prop; null.prop; (void 0).prop; undefined.prop; } expect: { var a, b = null, c = {}; a.prop; b.prop; c.prop; d.prop; null.prop; (void 0).prop; (void 0).prop; } } strict_reduce_vars: { options = { pure_getters: "strict", reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, } input: { var a, b = null, c = {}; a.prop; b.prop; c.prop; d.prop; null.prop; (void 0).prop; undefined.prop; } expect: { var a, b = null, c = {}; a.prop; b.prop; d.prop; null.prop; (void 0).prop; (void 0).prop; } } unsafe: { options = { pure_getters: true, reduce_funcs: false, reduce_vars: false, side_effects: true, toplevel: true, } input: { var a, b = null, c = {}; a.prop; b.prop; c.prop; d.prop; null.prop; (void 0).prop; undefined.prop; } expect: { var a, b = null, c = {}; d; null.prop; (void 0).prop; (void 0).prop; } } unsafe_reduce_vars: { options = { pure_getters: true, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, } input: { var a, b = null, c = {}; a.prop; b.prop; c.prop; d.prop; null.prop; (void 0).prop; undefined.prop; } expect: { var a, b = null, c = {}; d; null.prop; (void 0).prop; (void 0).prop; } } chained: { options = { pure_getters: "strict", side_effects: true, } input: { a.b.c; } expect: { a.b.c; } } impure_getter_1: { options = { pure_getters: "strict", side_effects: true, } input: { ({ get a() { console.log(1); }, b: 1 }).a; ({ get a() { console.log(1); }, b: 1 }).b; } expect: { ({ get a() { console.log(1); }, b: 1 }).a; ({ get a() { console.log(1); }, b: 1 }).b; } expect_stdout: "1" } impure_getter_2: { options = { pure_getters: true, side_effects: true, } input: { // will produce incorrect output because getter is not pure ({ get a() { console.log(1); }, b: 1 }).a; ({ get a() { console.log(1); }, b: 1 }).b; } expect: {} } issue_2110_1: { options = { collapse_vars: true, pure_getters: "strict", reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { function f() { function f() {} function g() { return this; } f.g = g; return f.g(); } console.log(typeof f()); } expect: { function f() { function f() {} return f.g = function() { return this; }, f.g(); } console.log(typeof f()); } expect_stdout: "function" } issue_2110_2: { options = { collapse_vars: true, pure_getters: "strict", reduce_funcs: true, reduce_vars: true, unused: true, } input: { function f() { function f() {} function g() { return this; } f.g = g; return f.g(); } console.log(typeof f()); } expect: { function f() { function f() {} f.g = function() { return this; }; return f.g(); } console.log(typeof f()); } expect_stdout: "function" } set_immutable_1: { options = { collapse_vars: true, evaluate: true, pure_getters: "strict", reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var a = 1; a.foo += ""; if (a.foo) console.log("FAIL"); else console.log("PASS"); } expect: { 1..foo += ""; if (1..foo) console.log("FAIL"); else console.log("PASS"); } expect_stdout: "PASS" } set_immutable_2: { options = { collapse_vars: true, conditionals: true, pure_getters: "strict", reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, toplevel: true, } input: { var a = 1; a.foo += ""; if (a.foo) console.log("FAIL"); else console.log("PASS"); } expect: { var a = 1; a.foo += "", a.foo ? console.log("FAIL") : console.log("PASS"); } expect_stdout: "PASS" } set_immutable_3: { options = { collapse_vars: true, evaluate: true, pure_getters: "strict", reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { "use strict"; var a = 1; a.foo += ""; if (a.foo) console.log("FAIL"); else console.log("PASS"); } expect: { "use strict"; 1..foo += ""; if (1..foo) console.log("FAIL"); else console.log("PASS"); } expect_stdout: true } set_immutable_4: { options = { collapse_vars: true, conditionals: true, pure_getters: "strict", reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, toplevel: true, } input: { "use strict"; var a = 1; a.foo += ""; if (a.foo) console.log("FAIL"); else console.log("PASS"); } expect: { "use strict"; var a = 1; a.foo += "", a.foo ? console.log("FAIL") : console.log("PASS"); } expect_stdout: true } set_immutable_5: { options = { collapse_vars: true, conditionals: true, evaluate: true, pure_getters: "strict", reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { "use strict"; var a = 1; a.foo += ""; if (a.foo) console.log("FAIL"); else console.log("PASS"); } expect: { "use strict"; 1..foo += ""; 1..foo ? console.log("FAIL") : console.log("PASS"); } expect_stdout: true } set_immutable_6: { options = { collapse_vars: true, conditionals: true, evaluate: true, pure_getters: "strict", reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { var a = 1; a.foo += ""; if (a.foo) console.log("FAIL"); else console.log("PASS"); } expect: { 1..foo ? console.log("FAIL") : console.log("PASS"); } expect_stdout: true } set_mutable_1: { options = { collapse_vars: true, evaluate: true, pure_getters: "strict", reduce_funcs: true, reduce_vars: true, unused: true, } input: { !function a() { a.foo += ""; if (a.foo) console.log("PASS"); else console.log("FAIL"); }(); } expect: { !function a() { if (a.foo += "") console.log("PASS"); else console.log("FAIL"); }(); } expect_stdout: "PASS" } set_mutable_2: { options = { collapse_vars: true, conditionals: true, pure_getters: "strict", reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, } input: { !function a() { a.foo += ""; if (a.foo) console.log("PASS"); else console.log("FAIL"); }(); } expect: { !function a() { (a.foo += "") ? console.log("PASS") : console.log("FAIL"); }(); } expect_stdout: "PASS" } issue_2265_1: { options = { pure_getters: "strict", side_effects: true, } input: { ({ ...{} }).p; ({ ...g }).p; } expect: { ({ ...g }).p; } } issue_2265_2: { options = { pure_getters: "strict", reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, } input: { var a = { get b() { throw 0; } }; ({...a}).b; } expect: { var a = { get b() { throw 0; } }; ({...a}).b; } } issue_2265_3: { options = { pure_getters: "strict", reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { var a = { set b() { throw 0; } }; ({...a}).b; } expect: {} } issue_2265_4: { options = { pure_getters: "strict", reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { var a = { b: 1 }; ({...a}).b; } expect: {} } issue_2313_1: { options = { collapse_vars: true, conditionals: true, pure_getters: "strict", sequences: true, side_effects: true, } input: { function x() { console.log(1); return { y: function() { console.log(2); return { z: 0 }; } }; } x().y().z++; if (x().y().z) { console.log(3); } } expect: { function x() { return console.log(1), { y: function() { return console.log(2), { z: 0 }; } }; } x().y().z++, x().y().z && console.log(3); } expect_stdout: [ "1", "2", "1", "2", ] } issue_2313_2: { options = { collapse_vars: true, conditionals: true, pure_getters: true, sequences: true, side_effects: true, } input: { function x() { console.log(1); return { y: function() { console.log(2); return { z: 0 }; } }; } x().y().z++; if (x().y().z) { console.log(3); } } expect: { function x() { return console.log(1), { y: function() { return console.log(2), { z: 0 }; } }; } x().y().z++, x().y().z && console.log(3); } expect_stdout: [ "1", "2", "1", "2", ] } issue_2313_3: { options = { collapse_vars: true, conditionals: true, pure_getters: "strict", } input: { function x() { console.log(1); return { y: function() { console.log(2); return { z: 0 }; } }; } x().y().z++; if (x().y().z) { console.log(3); } } expect: { function x() { console.log(1); return { y: function() { console.log(2); return { z: 0 }; } }; } x().y().z++; x().y().z && console.log(3); } expect_stdout: [ "1", "2", "1", "2", ] } issue_2313_4: { options = { collapse_vars: true, conditionals: true, pure_getters: true, } input: { function x() { console.log(1); return { y: function() { console.log(2); return { z: 0 }; } }; } x().y().z++; if (x().y().z) { console.log(3); } } expect: { function x() { console.log(1); return { y: function() { console.log(2); return { z: 0 }; } }; } x().y().z++; x().y().z && console.log(3); } expect_stdout: [ "1", "2", "1", "2", ] } issue_2313_5: { options = { pure_getters: "strict", side_effects: true, } input: { x().y++; x().y; } expect: { x().y++; x().y; } } issue_2313_6: { options = { pure_getters: true, side_effects: true, } input: { x().y++; x().y; } expect: { x().y++; x(); } } issue_2313_7: { options = { collapse_vars: true, conditionals: true, pure_getters: true, } input: { var a = 0, b = 0; class foo { get c() { a++; return 42; } set c(c) { b++; } } class bar extends foo { d() { super.c++; if (super.c) console.log(a, b); } } new bar().d(); } expect: { var a = 0, b = 0; class foo { get c() { a++; return 42; } set c(c) { b++; } } class bar extends foo { d() { super.c++; super.c && console.log(a, b); } } new bar().d(); } expect_stdout: "2 1" } issue_2678: { options = { pure_getters: "strict", side_effects: true, } input: { var a = 1, c = "FAIL"; (function f() { (a-- && f()).p; return { get p() { c = "PASS"; } }; })(); console.log(c); } expect: { var a = 1, c = "FAIL"; (function f() { (a-- && f()).p; return { get p() { c = "PASS"; } }; })(); console.log(c); } expect_stdout: "PASS" } issue_2838: { options = { pure_getters: true, side_effects: true, } input: { function f(a, b) { (a || b).c = "PASS"; (function() { return f(a, b); }).prototype.foo = "bar"; } var o = {}; f(null, o); console.log(o.c); } expect: { function f(a, b) { (a || b).c = "PASS"; } var o = {}; f(null, o); console.log(o.c); } expect_stdout: "PASS" } issue_2938_1: { options = { pure_getters: true, unused: true, } input: { function f(a) { a.b = "PASS"; } var o = {}; f(o); console.log(o.b); } expect: { function f(a) { a.b = "PASS"; } var o = {}; f(o); console.log(o.b); } expect_stdout: "PASS" } issue_2938_2: { options = { pure_getters: true, toplevel: true, unused: true, } input: { var Parser = function Parser() {}; var p = Parser.prototype; p.initialContext = function initialContext() { console.log("PASS"); }; p.braceIsBlock = function() {}; (new Parser).initialContext(); } expect: { var Parser = function() {}; var p = Parser.prototype; p.initialContext = function() { console.log("PASS"); }; p.braceIsBlock = function() {}; (new Parser).initialContext(); } expect_stdout: "PASS" } issue_2938_3: { options = { pure_getters: true, side_effects: true, unused: true, } input: { function f(a) { var unused = a.a; a.b = "PASS"; a.c; } var o = {}; o.d; f(o); console.log(o.b); } expect: { function f(a) { a.b = "PASS"; } var o = {}; f(o); console.log(o.b); } expect_stdout: "PASS" } issue_2938_4: { options = { pure_getters: true, side_effects: true, toplevel: true, unused: true, } input: { var Parser = function Parser() {}; var p = Parser.prototype; var unused = p.x; p.initialContext = function initialContext() { p.y; console.log("PASS"); }; p.braceIsBlock = function() {}; (new Parser).initialContext(); } expect: { var Parser = function() {}; var p = Parser.prototype; p.initialContext = function() { console.log("PASS"); }; p.braceIsBlock = function() {}; (new Parser).initialContext(); } expect_stdout: "PASS" } collapse_vars_1_true: { options = { collapse_vars: true, pure_getters: true, unused: true, } input: { function f(a, b) { for (;;) { var c = a.g(); var d = b.p; if (c || d) break; } } } expect: { function f(a, b) { for (;;) { if (a.g() || b.p) break; } } } } collapse_vars_1_false: { options = { collapse_vars: true, pure_getters: false, unused: true, } input: { function f(a, b) { for (;;) { var c = a.g(); var d = b.p; if (c || d) break; } } } expect: { function f(a, b) { for (;;) { var c = a.g(); var d = b.p; if (c || d) break; } } } } collapse_vars_1_strict: { options = { collapse_vars: true, pure_getters: "strict", unused: true, } input: { function f(a, b) { for (;;) { var c = a.g(); var d = b.p; if (c || d) break; } } } expect: { function f(a, b) { for (;;) { var c = a.g(); var d = b.p; if (c || d) break; } } } } collapse_vars_2_true: { options = { collapse_vars: true, pure_getters: true, reduce_vars: true, } input: { function f() { function g() {} g.a = function() {}; g.b = g.a; return g; } } expect: { function f() { function g() {} g.b = g.a = function() {}; return g; } } } collapse_vars_2_false: { options = { collapse_vars: true, pure_getters: false, reduce_vars: true, } input: { function f() { function g() {} g.a = function() {}; g.b = g.a; return g; } } expect: { function f() { function g() {} g.a = function() {}; g.b = g.a; return g; } } } collapse_vars_2_strict: { options = { collapse_vars: true, pure_getters: "strict", reduce_vars: true, } input: { function f() { function g() {} g.a = function() {}; g.b = g.a; return g; } } expect: { function f() { function g() {} g.a = function() {}; g.b = g.a; return g; } } } collapse_rhs_true: { options = { collapse_vars: true, pure_getters: true, } input: { console.log((42..length = "PASS", "PASS")); console.log(("foo".length = "PASS", "PASS")); console.log((false.length = "PASS", "PASS")); console.log((function() {}.length = "PASS", "PASS")); console.log(({ get length() { return "FAIL"; } }.length = "PASS", "PASS")); } expect_stdout: [ "PASS", "PASS", "PASS", "PASS", "PASS", ] } collapse_rhs_false: { options = { collapse_vars: true, pure_getters: false, } input: { console.log((42..length = "PASS", "PASS")); console.log(("foo".length = "PASS", "PASS")); console.log((false.length = "PASS", "PASS")); console.log((function() {}.length = "PASS", "PASS")); console.log(({ get length() { return "FAIL"; } }.length = "PASS", "PASS")); } expect_stdout: [ "PASS", "PASS", "PASS", "PASS", "PASS", ] } collapse_rhs_strict: { options = { collapse_vars: true, pure_getters: "strict", } input: { console.log((42..length = "PASS", "PASS")); console.log(("foo".length = "PASS", "PASS")); console.log((false.length = "PASS", "PASS")); console.log((function() {}.length = "PASS", "PASS")); console.log(({ get length() { return "FAIL"; } }.length = "PASS", "PASS")); } expect_stdout: [ "PASS", "PASS", "PASS", "PASS", "PASS", ] } collapse_rhs_setter: { options = { collapse_vars: true, pure_getters: "strict", } input: { try { console.log(({ set length(v) { throw "PASS"; } }.length = "FAIL", "FAIL")); } catch (e) { console.log(e); } } expect_stdout: "PASS" } collapse_rhs_call: { options = { collapse_vars: true, passes: 2, pure_getters: "strict", reduce_vars: true, toplevel: true, unused: true, } input: { var o = {}; function f() { console.log("PASS"); } o.f = f; f(); } expect_stdout: "PASS" } collapse_rhs_lhs: { options = { collapse_vars: true, pure_getters: true, } input: { function f(a, b) { a.b = b, b += 2; console.log(a.b, b); } f({}, 1); } expect: { function f(a, b) { a.b = b, b += 2; console.log(a.b, b); } f({}, 1); } expect_stdout: "1 3" } terser-4.1.2/test/compress/reduce_vars.js000066400000000000000000004317521351061312300205030ustar00rootroot00000000000000reduce_vars: { options = { conditionals: true, evaluate: true, global_defs: { C: 0, }, inline: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var A = 1; (function f0() { var a = 2; console.log(a - 5); console.log(A - 5); })(); (function f1() { var a = 2; console.log(a - 5); eval("console.log(a);"); })(); (function f2(eval) { var a = 2; console.log(a - 5); eval("console.log(a);"); })(eval); (function f3() { var b = typeof C !== "undefined"; var c = 4; if (b) { return 'yes'; } else { return 'no'; } })(); console.log(A + 1); } expect: { var A = 1; (function() { console.log(-3); console.log(A - 5); })(); (function f1() { var a = 2; console.log(a - 5); eval("console.log(a);"); })(); (function f2(eval) { var a = 2; console.log(a - 5); eval("console.log(a);"); })(eval); "yes"; console.log(A + 1); } expect_stdout: true } modified: { options = { conditionals: true, evaluate: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { function f0() { var a = 1, b = 2; b++; console.log(a + 1); console.log(b + 1); } function f1() { var a = 1, b = 2; --b; console.log(a + 1); console.log(b + 1); } function f2() { var a = 1, b = 2, c = 3; b = c; console.log(a + b); console.log(b + c); console.log(a + c); console.log(a + b + c); } function f3() { var a = 1, b = 2, c = 3; b *= c; console.log(a + b); console.log(b + c); console.log(a + c); console.log(a + b + c); } function f4() { var a = 1, b = 2, c = 3; if (a) { b = c; } else { c = b; } console.log(a + b); console.log(b + c); console.log(a + c); console.log(a + b + c); } function f5(a) { B = a; console.log(typeof A ? "yes" : "no"); console.log(typeof B ? "yes" : "no"); } f0(), f1(), f2(), f3(), f4(), f5(); } expect: { function f0() { var b = 2; b++; console.log(2); console.log(4); } function f1() { var b = 2; --b; console.log(2); console.log(2); } function f2() { 3; console.log(4); console.log(6); console.log(4); console.log(7); } function f3() { var b = 2; b *= 3; console.log(7); console.log(9); console.log(4); console.log(10); } function f4() { var b = 2, c = 3; b = c; console.log(1 + b); console.log(b + c); console.log(1 + c); console.log(1 + b + c); } function f5(a) { B = a; console.log(typeof A ? "yes" : "no"); console.log(typeof B ? "yes" : "no"); } f0(), f1(), f2(), f3(), f4(), f5(); } expect_stdout: [ "2", "4", "2", "2", "4", "6", "4", "7", "7", "9", "4", "10", "4", "6", "4", "7", "yes", "yes", ] } unsafe_evaluate: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, side_effects: true, unsafe: true, unused: true, } input: { function f0(){ var a = { b:1 }; console.log(a.b + 3); } function f1(){ var a = { b:{ c:1 }, d:2 }; console.log(a.b + 3, a.d + 4, a.b.c + 5, a.d.c + 6); } } expect: { function f0(){ console.log(4); } function f1(){ var a = { b:{ c:1 }, d:2 }; console.log(a.b + 3, 6, 6, 2..c + 6); } } } unsafe_evaluate_side_effect_free_1: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unsafe: true, unused: true, } input: { console.log(function(){ var o={p:1}; console.log(o.p); return o.p; }()); console.log(function(){ var o={p:2}; console.log(o.p); return o; }()); console.log(function(){ var o={p:3}; console.log([o][0].p); return o.p; }()); } expect: { console.log(function(){ console.log(1); return 1; }()); console.log(function(){ var o={p:2}; console.log(2); return o; }()); console.log(function(){ console.log(3); return 3; }()); } expect_stdout: true } unsafe_evaluate_side_effect_free_2: { options = { collapse_vars: true, evaluate: true, passes: 2, pure_getters: "strict", reduce_funcs: true, reduce_vars: true, unsafe: true, unused: true, } input: { console.log(function(){ var o={p:1},a=[o]; console.log(a[0].p); return o.p; }()); } expect: { console.log(function(){ console.log(1); return 1; }()); } expect_stdout: true } unsafe_evaluate_escaped: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unsafe: true, unused: true, } input: { console.log(function(){ var o={p:1}; console.log(o, o.p); return o.p; }()); console.log(function(){ var o={p:2}; console.log(o.p, o); return o.p; }()); console.log(function(){ var o={p:3},a=[o]; console.log(a[0].p++); return o.p; }()); } expect: { console.log(function(){ var o={p:1}; console.log(o, o.p); return o.p; }()); console.log(function(){ var o={p:2}; console.log(o.p, o); return o.p; }()); console.log(function(){ var o={p:3},a=[o]; console.log(a[0].p++); return o.p; }()); } expect_stdout: true } unsafe_evaluate_modified: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unsafe: true, unused: true, } input: { console.log(function(){ var o={p:1}; o.p++; console.log(o.p); return o.p; }()); console.log(function(){ var o={p:2}; --o.p; console.log(o.p); return o.p; }()); console.log(function(){ var o={p:3}; o.p += ""; console.log(o.p); return o.p; }()); console.log(function(){ var o={p:4}; o = {}; console.log(o.p); return o.p; }()); console.log(function(){ var o={p:5}; o.p = -9; console.log(o.p); return o.p; }()); function inc() { this.p++; } console.log(function(){ var o={p:6}; inc.call(o); console.log(o.p); return o.p; }()); console.log(function(){ var o={p:7}; console.log([o][0].p++); return o.p; }()); console.log(function(){ var o={p:8}; console.log({q:o}.q.p++); return o.p; }()); } expect: { console.log(function(){ var o={p:1}; o.p++; console.log(o.p); return o.p; }()); console.log(function(){ var o={p:2}; --o.p; console.log(o.p); return o.p; }()); console.log(function(){ var o={p:3}; o.p += ""; console.log(o.p); return o.p; }()); console.log(function(){ var o; o = {}; console.log(o.p); return o.p; }()); console.log(function(){ var o={p:5}; o.p = -9; console.log(o.p); return o.p; }()); function inc() { this.p++; } console.log(function(){ var o={p:6}; inc.call(o); console.log(o.p); return o.p; }()); console.log(function(){ var o={p:7}; console.log([o][0].p++); return o.p; }()); console.log(function(){ var o={p:8}; console.log({q:o}.q.p++); return o.p; }()); } expect_stdout: true } unsafe_evaluate_unknown: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unsafe: true, unused: true, } input: { console.log(function(){ var o={p:1}; console.log(o.not_present); return o.p; }()); console.log(function(){ var o={p:2}; console.log(o.prototype); return o.p; }()); console.log(function(){ var o={p:3}; console.log(o.hasOwnProperty); return o.p; }()); } expect: { console.log(function(){ var o={p:1}; console.log(o.not_present); return o.p; }()); console.log(function(){ var o={p:2}; console.log(o.prototype); return o.p; }()); console.log(function(){ var o={p:3}; console.log(o.hasOwnProperty); return o.p; }()); } expect_stdout: true } unsafe_evaluate_object_1: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unsafe: true, } input: { function f0(){ var a = 1; var b = {}; b[a] = 2; console.log(a + 3); } function f1(){ var a = { b:1 }; a.b = 2; console.log(a.b + 3); } } expect: { function f0(){ var a = 1; var b = {}; b[1] = 2; console.log(4); } function f1(){ var a = { b:1 }; a.b = 2; console.log(a.b + 3); } } } unsafe_evaluate_object_2: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unsafe: true, } input: { var obj = { foo: 1, bar: 2, square: function(x) { return x * x; }, cube: function(x) { return x * x * x; }, }; console.log(obj.foo, obj.bar, obj.square(2), obj.cube); } expect: { var obj = { foo: 1, bar: 2, square: function(x) { return x * x; }, cube: function(x) { return x * x * x; }, }; console.log(1, 2, obj.square(2), obj.cube); } expect_stdout: true } unsafe_evaluate_object_3: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unsafe: true, } input: { var obj = { get foo() { return 1; }, bar: 2, square: function(x) { return x * x; }, cube: function(x) { return x * x * x; }, }; console.log(obj.foo, obj.bar, obj.square(2), obj.cube); } expect: { var obj = { get foo() { return 1; }, bar: 2, square: function(x) { return x * x; }, cube: function(x) { return x * x * x; }, }; console.log(obj.foo, obj.bar, obj.square(2), obj.cube); } expect_stdout: true } unsafe_evaluate_array_1: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unsafe: true, } input: { function f0(){ var a = 1; var b = []; b[a] = 2; console.log(a + 3); } function f1(){ var a = [1]; a[2] = 3; console.log(a.length); } function f2(){ var a = [1]; a.push(2); console.log(a.length); } } expect: { function f0(){ var a = 1; var b = []; b[1] = 2; console.log(4); } function f1(){ var a = [1]; a[2] = 3; console.log(a.length); } function f2(){ var a = [1]; a.push(2); console.log(a.length); } } } unsafe_evaluate_array_2: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unsafe: true, } input: { var arr = [ 1, 2, function(x) { return x * x; }, function(x) { return x * x * x; }, ]; console.log(arr[0], arr[1], arr[2](2), arr[3]); } expect: { var arr = [ 1, 2, function(x) { return x * x; }, function(x) { return x * x * x; }, ]; console.log(1, 2, arr[2](2), arr[3]); } expect_stdout: true } unsafe_evaluate_array_3: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unsafe: true, } input: { var arr = [ 1, 2, function() { return ++arr[0]; }, ]; console.log(arr[0], arr[1], arr[2](), arr[0]); } expect: { var arr = [ 1, 2, function() { return ++arr[0]; }, ]; console.log(arr[0], arr[1], arr[2](), arr[0]); } expect_stdout: "1 2 2 2" } unsafe_evaluate_array_4: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unsafe: true, } input: { var arr = [ 1, 2, function() { return ++this[0]; }, ]; console.log(arr[0], arr[1], arr[2], arr[0]); } expect: { var arr = [ 1, 2, function() { return ++this[0]; }, ]; console.log(1, 2, arr[2], 1); } expect_stdout: true } unsafe_evaluate_array_5: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unsafe: true, } input: { var arr = [ 1, 2, function() { return ++this[0]; }, ]; console.log(arr[0], arr[1], arr[2](), arr[0]); } expect: { var arr = [ 1, 2, function() { return ++this[0]; }, ]; console.log(arr[0], arr[1], arr[2](), arr[0]); } expect_stdout: "1 2 2 2" } unsafe_evaluate_equality_1: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unsafe: true, unused: true, } input: { function f0() { var a = {}; return a === a; } function f1() { var a = []; return a === a; } console.log(f0(), f1()); } expect: { function f0() { return true; } function f1() { return true; } console.log(f0(), f1()); } expect_stdout: true } unsafe_evaluate_equality_2: { options = { collapse_vars: true, evaluate: true, passes: 2, reduce_funcs: true, reduce_vars: true, unsafe: true, unused: true, } input: { function f2() { var a = {a:1, b:2}; var b = a; var c = a; return b === c; } function f3() { var a = [1, 2, 3]; var b = a; var c = a; return b === c; } console.log(f2(), f3()); } expect: { function f2() { return true; } function f3() { return true; } console.log(f2(), f3()); } expect_stdout: true } passes: { options = { conditionals: true, evaluate: true, passes: 2, reduce_funcs: true, reduce_vars: true, unused: true, } input: { function f() { var a = 1, b = 2, c = 3; if (a) { b = c; } else { c = b; } console.log(a + b); console.log(b + c); console.log(a + c); console.log(a + b + c); } } expect: { function f() { 3; console.log(4); console.log(6); console.log(4); console.log(7); } } } iife: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, } input: { !function(a, b, c) { b++; console.log(a - 1, b * 1, c + 2); }(1, 2, 3); } expect: { !function(a, b, c) { b++; console.log(0, 3, 5); }(1, 2, 3); } expect_stdout: true } iife_new: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, } input: { var A = new function(a, b, c) { b++; console.log(a - 1, b * 1, c + 2); }(1, 2, 3); } expect: { var A = new function(a, b, c) { b++; console.log(0, 3, 5); }(1, 2, 3); } expect_stdout: true } multi_def_1: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, } input: { function f(a) { if (a) var b = 1; else var b = 2; console.log(b + 1); } } expect: { function f(a) { if (a) var b = 1; else var b = 2; console.log(b + 1); } } } multi_def_2: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, } input: { function f(){ if (code == 16) var bitsLength = 2, bitsOffset = 3, what = len; else if (code == 17) var bitsLength = 3, bitsOffset = 3, what = (len = 0); else if (code == 18) var bitsLength = 7, bitsOffset = 11, what = (len = 0); var repeatLength = this.getBits(bitsLength) + bitsOffset; } } expect: { function f(){ if (16 == code) var bitsLength = 2, bitsOffset = 3, what = len; else if (17 == code) var bitsLength = 3, bitsOffset = 3, what = (len = 0); else if (18 == code) var bitsLength = 7, bitsOffset = 11, what = (len = 0); var repeatLength = this.getBits(bitsLength) + bitsOffset; } } } multi_def_3: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, } input: { function f(a) { var b = 2; if (a) var b; else var b; console.log(b + 1); } } expect: { function f(a) { var b = 2; if (a) var b; else var b; console.log(3); } } } use_before_var: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, } input: { function f(){ console.log(t); var t = 1; } } expect: { function f(){ console.log(t); var t = 1; } } } inner_var_if: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, } input: { function f(a){ if (a) var t = 1; if (!t) console.log(t); } } expect: { function f(a){ if (a) var t = 1; if (!t) console.log(t); } } } inner_var_label: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, } input: { function f(a){ l: { if (a) break l; var t = 1; } console.log(t); } } expect: { function f(a){ l: { if (a) break l; var t = 1; } console.log(t); } } } inner_var_for_1: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, } input: { function f() { var a = 1; x(a, b, d); for (var b = 2, c = 3; x(a, b, c, d); x(a, b, c, d)) { var d = 4, e = 5; x(a, b, c, d, e); } x(a, b, c, d, e); } } expect: { function f() { var a = 1; x(1, b, d); for (var b = 2, c = 3; x(1, b, 3, d); x(1, b, 3, d)) { var d = 4, e = 5; x(1, b, 3, d, e); } x(1, b, 3, d, e); } } } inner_var_for_2: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { !function() { var a = 1; for (var b = 1; --b;) var a = 2; console.log(a); }(); } expect: { !function() { var a = 1; for (var b = 1; --b;) a = 2; console.log(a); }(); } expect_stdout: "1" } inner_var_for_in_1: { options = { evaluate: 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 (function() { return x(1, b, c); })()) { var c = 3, d = 4; x(1, b, c, d); } x(1, b, c, d); } } } inner_var_for_in_2: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, } input: { function f() { for (var long_name in {}) console.log(long_name); } } expect: { function f() { for (var long_name in {}) console.log(long_name); } } } inner_var_catch: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, } input: { function f() { try { a(); } catch (e) { var b = 1; } console.log(b); } } expect: { function f() { try { a(); } catch (e) { var b = 1; } console.log(b); } } } issue_1533_1: { options = { collapse_vars: true, reduce_funcs: true, reduce_vars: true, } input: { function f() { var id = ""; for (id in {break: "me"}) console.log(id); } } expect: { function f() { var id = ""; for (id in {break: "me"}) console.log(id); } } } issue_1533_2: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, } input: { function f() { var id = ""; for (var id in {break: "me"}) console.log(id); console.log(id); } } expect: { function f() { var id = ""; for (var id in {break: "me"}) console.log(id); console.log(id); } } } toplevel_on: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var x = 3; console.log(x); } expect: { console.log(3); } expect_stdout: true } toplevel_off: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, toplevel: false, unused: true, } input: { var x = 3; console.log(x); } expect: { var x = 3; console.log(x); } expect_stdout: true } toplevel_on_loops_1: { options = { evaluate: true, loops: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function bar() { console.log("bar:", --x); } var x = 3; do bar(); while (x); } expect: { function bar() { console.log("bar:", --x); } var x = 3; do bar(); while (x); } expect_stdout: true } toplevel_off_loops_1: { options = { evaluate: true, loops: true, reduce_funcs: true, reduce_vars: true, toplevel: false, unused: true, } input: { function bar() { console.log("bar:", --x); } var x = 3; do bar(); while (x); } expect: { function bar() { console.log("bar:", --x); } var x = 3; do bar(); while (x); } expect_stdout: true } toplevel_on_loops_2: { options = { evaluate: true, loops: true, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { function bar() { console.log("bar:"); } var x = 3; do bar(); while (x); } expect: { function bar() { console.log("bar:"); } for (;;) bar(); } } toplevel_off_loops_2: { options = { evaluate: true, loops: true, reduce_funcs: true, reduce_vars: true, toplevel: false, unused: true, } input: { function bar() { console.log("bar:"); } var x = 3; do bar(); while (x); } expect: { function bar() { console.log("bar:"); } var x = 3; do bar(); while (x); } } toplevel_on_loops_3: { options = { evaluate: true, loops: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var x = 3; while (x) bar(); } expect: { for (;;) bar(); } } toplevel_off_loops_3: { options = { evaluate: true, loops: true, reduce_funcs: true, reduce_vars: true, toplevel: false, unused: true, } input: { var x = 3; while (x) bar(); } expect: { var x = 3; for (;x;) bar(); } } defun_reference: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, } input: { function f() { function g() { x(); return a; } var a = h(); var b = 2; return a + b; function h() { y(); return b; } } } expect: { function f() { function g() { x(); return a; } var a = h(); var b = 2; return a + b; function h() { y(); return b; } } } } defun_inline_1: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { function f() { return g(2) + h(); function g(b) { return b; } function h() { return h(); } } } expect: { function f() { return function(b) { return b; }(2) + function h() { return h(); }(); } } } defun_inline_2: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { function f() { function g(b) { return b; } function h() { return h(); } return g(2) + h(); } } expect: { function f() { return function(b) { return b; }(2) + function h() { return h(); }(); } } } defun_inline_3: { options = { evaluate: true, inline: true, passes: 3, reduce_funcs: true, reduce_vars: true, side_effects: true, unused: true, } input: { function f() { return g(2); function g(b) { return b; } } } expect: { function f() { return 2; } } } defun_call: { options = { inline: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { function f() { return g() + h(1) - h(g(), 2, 3); function g() { return 4; } function h(a) { return a; } } } expect: { function f() { return 4 + h(1) - h(4); function h(a) { return a; } } } } defun_redefine: { options = { inline: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { function f() { function g() { return 1; } function h() { return 2; } g = function() { return 3; }; return g() + h(); } } expect: { function f() { function g() { return 1; } g = function() { return 3; }; return g() + 2; } } } func_inline: { options = { inline: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { function f() { var g = function() { return 1; }; console.log(g() + h()); var h = function() { return 2; }; } } expect: { function f() { console.log(1 + h()); var h = function() { return 2; }; } } } func_modified: { options = { inline: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { function f(a) { function a() { return 1; } function b() { return 2; } function c() { return 3; } b.inject = []; c = function() { return 4; }; return a() + b() + c(); } } expect: { function f(a) { function b() { return 2; } function c() { return 3; } b.inject = []; c = function() { return 4; }; return 1 + 2 + c(); } } } unused_modified: { options = { reduce_vars: true, unused: true, } input: { console.log(function() { var b = 1, c = "FAIL"; if (0 || b--) c = "PASS"; b = 1; return c; }()); } expect: { console.log(function() { var b = 1, c = "FAIL"; if (0 || b--) c = "PASS"; b = 1; return c; }()); } expect_stdout: "PASS" } defun_label: { options = { passes: 2, reduce_funcs: true, reduce_vars: true, unused: true, } input: { !function() { function f(a) { L: { if (a) break L; return 1; } } console.log(f(2)); }(); } expect: { !function() { console.log(function(a) { L: { if (2) break L; return 1; } }()); }(); } expect_stdout: true } double_reference: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { function f() { var g = function g() { g(); }; g(); } } expect: { function f() { (function g() { g(); })(); } } } iife_eval_1: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { (function(x) { console.log(x() === eval("x")); })(function f() { return f; }); } expect: { (function(x) { console.log(x() === eval("x")); })(function f() { return f; }); } expect_stdout: true } iife_eval_2: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { (function() { var x = function f() { return f; }; console.log(x() === eval("x")); })(); } expect: { (function() { var x = function f() { return f; }; console.log(x() === eval("x")); })(); } expect_stdout: true } iife_func_side_effects: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { function x() { console.log("x"); } function y() { console.log("y"); } function z() { console.log("z"); } (function(a, b, c) { function y() { console.log("FAIL"); } return y + b(); })(x(), function() { return y(); }, z()); } expect: { function x() { console.log("x"); } function y() { console.log("y"); } function z() { console.log("z"); } (function(a, b, c) { return function() { console.log("FAIL"); } + b(); })(x(), function() { return y(); }, z()); } expect_stdout: [ "x", "z", "y", ] } issue_1595_1: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { (function f(a) { return f(a + 1); })(2); } expect: { (function f(a) { return f(a + 1); })(2); } } issue_1595_2: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { (function f(a) { return g(a + 1); })(2); } expect: { (function(a) { return g(a + 1); })(2); } } issue_1595_3: { options = { evaluate: true, passes: 2, reduce_funcs: true, reduce_vars: true, unused: true, } input: { (function f(a) { return g(a + 1); })(2); } expect: { (function(a) { return g(3); })(); } } issue_1595_4: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { (function iife(a, b, c) { console.log(a, b, c); if (a) iife(a - 1, b, c); })(3, 4, 5); } expect: { (function iife(a, b, c) { console.log(a, b, c); if (a) iife(a - 1, b, c); })(3, 4, 5); } expect_stdout: true } issue_1606: { options = { evaluate: true, hoist_vars: true, reduce_funcs: true, reduce_vars: true, } input: { function f() { var a; function g(){}; var b = 2; x(b); } } expect: { function f() { var a, b; function g(){}; b = 2; x(b); } } } issue_1670_1: { options = { comparisons: true, conditionals: true, dead_code: true, evaluate: true, reduce_funcs: true, reduce_vars: true, side_effects: true, switches: true, typeofs: true, unused: true, } input: { (function f() { switch (1) { case 0: var a = true; break; default: if (typeof a === "undefined") console.log("PASS"); else console.log("FAIL"); } })(); } expect: { (function() { var a; void 0 === a ? console.log("PASS") : console.log("FAIL"); })(); } expect_stdout: "PASS" } issue_1670_2: { options = { conditionals: true, dead_code: true, evaluate: true, passes: 2, reduce_funcs: true, reduce_vars: true, side_effects: true, switches: true, unused: true, } input: { (function f() { switch (1) { case 0: var a = true; break; default: if (typeof a === "undefined") console.log("PASS"); else console.log("FAIL"); } })(); } expect: { (function() { console.log("PASS"); })(); } expect_stdout: "PASS" } issue_1670_3: { options = { comparisons: true, conditionals: true, dead_code: true, evaluate: true, reduce_funcs: true, reduce_vars: true, side_effects: true, switches: true, typeofs: true, unused: true, } input: { (function f() { switch (1) { case 0: var a = true; break; case 1: if (typeof a === "undefined") console.log("PASS"); else console.log("FAIL"); } })(); } expect: { (function() { var a; void 0 === a ? console.log("PASS") : console.log("FAIL"); })(); } expect_stdout: "PASS" } issue_1670_4: { options = { conditionals: true, dead_code: true, evaluate: true, passes: 2, reduce_funcs: true, reduce_vars: true, side_effects: true, switches: true, unused: true, } input: { (function f() { switch (1) { case 0: var a = true; break; case 1: if (typeof a === "undefined") console.log("PASS"); else console.log("FAIL"); } })(); } expect: { (function() { console.log("PASS"); })(); } expect_stdout: "PASS" } issue_1670_5: { options = { dead_code: true, evaluate: true, keep_fargs: false, reduce_funcs: true, reduce_vars: true, side_effects: true, switches: true, unused: true, } input: { (function(a) { switch (1) { case a: console.log(a); break; default: console.log(2); break; } })(1); } expect: { (function() { console.log(1); })(); } expect_stdout: "1" } issue_1670_6: { options = { dead_code: true, evaluate: true, keep_fargs: false, reduce_funcs: true, reduce_vars: true, side_effects: true, switches: true, unused: true, } input: { (function(a) { switch (1) { case a = 1: console.log(a); break; default: console.log(2); break; } })(1); } expect: { (function(a) { switch (1) { case a = 1: console.log(a); break; default: console.log(2); } })(1); } expect_stdout: "1" } unary_delete: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { var b = 10; function f() { var a; if (delete a) b--; } f(); console.log(b); } expect: { var b = 10; function f() { var a; if (delete a) b--; } f(); console.log(b); } expect_stdout: true } redefine_arguments_1: { options = { evaluate: true, keep_fargs: false, reduce_funcs: true, reduce_vars: true, unused: true, } input: { function f() { var arguments; return typeof arguments; } function g() { var arguments = 42; return typeof arguments; } function h(x) { var arguments = x; return typeof arguments; } console.log(f(), g(), h()); } expect: { function f() { var arguments; return typeof arguments; } function g() { return "number"; } function h(x) { var arguments = x; return typeof arguments; } console.log(f(), g(), h()); } expect_stdout: "object number undefined" } redefine_arguments_2: { options = { evaluate: true, inline: true, keep_fargs: false, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { function f() { var arguments; return typeof arguments; } function g() { var arguments = 42; return typeof arguments; } function h(x) { var arguments = x; return typeof arguments; } console.log(f(), g(), h()); } expect: { console.log(function() { var arguments; return typeof arguments; }(), "number", function(x) { var arguments = x; return typeof arguments; }()); } expect_stdout: "object number undefined" } redefine_arguments_3: { options = { evaluate: true, inline: true, keep_fargs: false, passes: 3, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { function f() { var arguments; return typeof arguments; } function g() { var arguments = 42; return typeof arguments; } function h(x) { var arguments = x; return typeof arguments; } console.log(f(), g(), h()); } expect: { console.log(function() { var arguments; return typeof arguments; }(), "number", function(x) { var arguments = x; return typeof arguments; }()); } expect_stdout: "object number undefined" } redefine_farg_1: { options = { evaluate: true, keep_fargs: false, reduce_funcs: true, reduce_vars: true, unused: true, } input: { function f(a) { var a; return typeof a; } function g(a) { var a = 42; return typeof a; } function h(a, b) { var a = b; return typeof a; } console.log(f([]), g([]), h([])); } expect: { function f(a) { return typeof a; } function g() { return "number"; } function h(a, b) { a = b; return typeof a; } console.log(f([]), g([]), h([])); } expect_stdout: "object number undefined" } redefine_farg_2: { options = { evaluate: true, inline: true, keep_fargs: false, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { function f(a) { var a; return typeof a; } function g(a) { var a = 42; return typeof a; } function h(a, b) { var a = b; return typeof a; } console.log(f([]), g([]), h([])); } expect: { console.log((a = [], typeof a), "number",function(a, b) { a = b; return typeof a; }([])); var a; } expect_stdout: "object number undefined" } redefine_farg_3: { options = { collapse_vars: true, evaluate: true, inline: true, keep_fargs: false, passes: 3, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, toplevel: true, unused: true, } input: { function f(a) { var a; return typeof a; } function g(a) { var a = 42; return typeof a; } function h(a, b) { var a = b; return typeof a; } console.log(f([]), g([]), h([])); } expect: { console.log(typeof [], "number", "undefined"); } expect_stdout: "object number undefined" } delay_def: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { function f() { return a; var a; } function g() { return a; var a = 1; } console.log(f(), g()); } expect: { function f() { return; } function g() { return a; var a = 1; } console.log(f(), g()); } expect_stdout: true } delay_def_lhs: { options = { evaluate: true, reduce_vars: true, } input: { console.log(function() { long_name++; return long_name; var long_name; }()); } expect: { console.log(function() { long_name++; return long_name; var long_name; }()); } expect_stdout: "NaN" } booleans: { options = { booleans: true, evaluate: true, reduce_funcs: true, reduce_vars: true, } input: { console.log(function(a) { if (a != 0); switch (a) { case 0: return "FAIL"; case false: return "PASS"; } }(false)); } expect: { console.log(function(a) { if (0); switch (!1) { case 0: return "FAIL"; case !1: return "PASS"; } }(!1)); } expect_stdout: "PASS" } side_effects_assign: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, toplevel: true, } input: { var a = typeof void (a && a.in == 1, 0); console.log(a); } expect: { var a = typeof void (a && a.in); console.log(a); } expect_stdout: "undefined" } pure_getters_1: { options = { pure_getters: "strict", reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, } input: { try { var a = (a.b, 2); } catch (e) {} console.log(a); } expect: { try { var a = (a.b, 2); } catch (e) {} console.log(a); } expect_stdout: "undefined" } pure_getters_2: { options = { pure_getters: "strict", reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var a; var a = a && a.b; } expect: { var a = a && a.b; } } pure_getters_3: { options = { pure_getters: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var a; var a = a && a.b; } expect: { } } catch_var: { options = { booleans: true, evaluate: true, reduce_funcs: true, reduce_vars: true, } input: { try { throw {}; } catch (e) { var e; console.log(!!e); } } expect: { try { throw {}; } catch (e) { var e; console.log(!!e); } } expect_stdout: "true" } var_assign_1: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { !function() { var a; a = 2; console.log(a); }(); } expect: { !function() { console.log(2); }(); } expect_stdout: "2" } var_assign_2: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { !function() { var a; if (a = 2) console.log(a); }(); } expect: { !function() { if (2) console.log(2); }(); } expect_stdout: "2" } var_assign_3: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { !function() { var a; while (a = 2); console.log(a); }(); } expect: { !function() { var a; while (a = 2); console.log(a); }(); } } var_assign_4: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { !function a() { a = 2; console.log(a); }(); } expect: { !function a() { a = 2, console.log(a); }(); } } var_assign_5: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { !function() { var a; !function(b) { a = 2; console.log(a, b); }(a); }(); } expect: { !function() { var a; !function(b) { a = 2, console.log(a, b); }(a); }(); } expect_stdout: "2 undefined" } var_assign_6: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { !function() { var a = function(){}(a = 1); console.log(a); }(); } expect: { !function() { var a = function(){}(a = 1); console.log(a); }(); } expect_stdout: "undefined" } immutable: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { !function() { var a = "test"; console.log(a.indexOf("e")); }(); } expect: { !function() { console.log("test".indexOf("e")); }(); } expect_stdout: "1" } issue_1814_1: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { const a = 42; !function() { var b = a; !function(a) { console.log(a++, b); }(0); }(); } expect: { const a = 42; !function() { !function(a) { console.log(a++, 42); }(0); }(); } expect_stdout: "0 42" } issue_1814_2: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { const a = "32"; !function() { var b = a + 1; !function(a) { console.log(b, a++); }(0); }(); } expect: { const a = "32"; !function() { !function(a) { console.log("321", a++); }(0); }(); } expect_stdout: "321 0" } try_abort: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { !function() { try { var a = 1; throw ""; var b = 2; } catch (e) { } console.log(a, b); }(); } expect: { !function() { try { var a = 1; throw ""; var b = 2; } catch (e) { } console.log(a, b); }(); } expect_stdout: "1 undefined" } boolean_binary_assign: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { !function() { var a; void 0 && (a = 1); console.log(a); }(); } expect: { !function() { var a; void 0; console.log(a); }(); } expect_stdout: "undefined" } cond_assign: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { !function() { var a; void 0 ? (a = 1) : 0; console.log(a); }(); } expect: { !function() { var a; void 0 ? (a = 1) : 0; console.log(a); }(); } expect_stdout: "undefined" } iife_assign: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { !function() { var a = 1, b = 0; !function() { b++; return; a = 2; }(); console.log(a); }(); } expect: { !function() { var a = 1, b = 0; !function() { b++; return; a = 2; }(); console.log(a); }(); } expect_stdout: "1" } issue_1850_1: { options = { reduce_funcs: true, reduce_vars: true, toplevel: false, unused: true, } input: { function f() { console.log(a, a, a); } var a = 1; f(); } expect: { function f() { console.log(a, a, a); } var a = 1; f(); } expect_stdout: true } issue_1850_2: { options = { reduce_funcs: true, reduce_vars: true, toplevel: "funcs", unused: true, } input: { function f() { console.log(a, a, a); } var a = 1; f(); } expect: { var a = 1; (function() { console.log(a, a, a); })(); } expect_stdout: true } issue_1850_3: { options = { reduce_funcs: true, reduce_vars: true, toplevel: "vars", unused: true, } input: { function f() { console.log(a, a, a); } var a = 1; f(); } expect: { function f() { console.log(a, a, a); } var a = 1; f(); } expect_stdout: true } issue_1850_4: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function f() { console.log(a, a, a); } var a = 1; f(); } expect: { var a = 1; (function() { console.log(a, a, a); })(); } expect_stdout: true } issue_1865: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unsafe: true, } input: { function f(some) { some.thing = false; } console.log(function() { var some = { thing: true }; f(some); return some.thing; }()); } expect: { function f(some) { some.thing = false; } console.log(function() { var some = { thing: true }; f(some); return some.thing; }()); } expect_stdout: true } issue_1922_1: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { console.log(function(a) { arguments[0] = 2; return a; }(1)); } expect: { console.log(function(a) { arguments[0] = 2; return a; }(1)); } expect_stdout: "2" } issue_1922_2: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, unused: true, } input: { console.log(function() { var a; eval("a = 1"); return a; }(1)); } expect: { console.log(function() { var a; eval("a = 1"); return a; }(1)); } expect_stdout: "1" } accessor_1: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, toplevel: true, } input: { var a = 1; console.log({ get a() { a = 2; return a; }, b: 1 }.b, a); } expect: { var a = 1; console.log({ get a() { a = 2; return a; }, b: 1 }.b, a); } expect_stdout: "1 1" } accessor_2: { options = { collapse_vars: true, evaluate: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var A = 1; var B = { get c() { console.log(A); } }; B.c; } expect: { ({ get c() { console.log(1); } }).c; } expect_stdout: "1" } method_1: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, toplevel: true, } input: { var a = 1; console.log(new class { a() { a = 2; return a; } }().a(), a); } expect: { var a = 1; console.log(new class { a() { a = 2; return a; } }().a(), a); } expect_stdout: "2 2" } method_2: { options = { collapse_vars: true, evaluate: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var A = 1; var B = class { c() { console.log(A); } }; new B().c(); } expect: { new class { c() { console.log(1); } }().c(); } expect_stdout: "1" } issue_2090_1: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, } input: { console.log(function() { var x = 1; [].forEach(() => x = 2); return x; }()); } expect: { console.log(function() { var x = 1; [].forEach(() => x = 2); return x; }()); } expect_stdout: "1" } issue_2090_2: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, } input: { console.log(function() { var x = 1; [].forEach(() => { x = 2; }); return x; }()); } expect: { console.log(function() { var x = 1; [].forEach(() => { x = 2; }); return x; }()); } expect_stdout: "1" } for_in_prop: { options = { reduce_funcs: true, reduce_vars: true, } input: { var a = { foo: function() { for (this.b in [1, 2]); } }; a.foo(); console.log(a.b); } expect: { var a = { foo: function() { for (this.b in [1, 2]); } }; a.foo(); console.log(a.b); } expect_stdout: "1" } obj_var_1: { options = { evaluate: true, passes: 2, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var C = 1; var obj = { bar: function() { return C + C; } }; console.log(obj.bar()); } expect: { console.log({ bar: function() { return 2; } }.bar()); } expect_stdout: "2" } obj_var_2: { options = { evaluate: true, inline: true, passes: 2, properties: true, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unsafe: true, unused: true, } input: { var C = 1; var obj = { bar: function() { return C + C; } }; console.log(obj.bar()); } expect: { console.log(2); } expect_stdout: "2" } obj_arg_1: { options = { collapse_vars: true, evaluate: true, inline: true, passes: 2, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var C = 1; function f(obj) { return obj.bar(); } console.log(f({ bar: function() { return C + C; } })); } expect: { console.log({ bar: function() { return 2; } }.bar()); } expect_stdout: "2" } obj_arg_2: { options = { collapse_vars: true, evaluate: true, inline: true, passes: 3, properties: true, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { var C = 1; function f(obj) { return obj.bar(); } console.log(f({ bar: function() { return C + C; } })); } expect: { console.log(2); } expect_stdout: "2" } func_arg_1: { options = { evaluate: true, inline: true, passes: 2, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { var a = 42; !function(a) { console.log(a()); }(function() { return a; }); } expect: { console.log(42); } expect_stdout: "42" } func_arg_2: { options = { evaluate: true, inline: true, passes: 2, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { var a = 42; !function(a) { console.log(a()); }(function(a) { return a; }); } expect: { console.log(void 0); } expect_stdout: "undefined" } regex_loop: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function f(x) { for (var r, s = "acdabcdeabbb"; r = x().exec(s);) console.log(r[0]); } var a = /ab*/g; f(function() { return a; }); } expect: { var a = /ab*/g; (function(x) { for (var r, s = "acdabcdeabbb"; r = x().exec(s);) console.log(r[0]); })(function() { return a; }); } expect_stdout: true } obj_for_1: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var o = { a: 1 }; for (var i = o.a--; i; i--) console.log(i); } expect: { for (var i = { a: 1 }.a--; i; i--) console.log(i); } expect_stdout: "1" } obj_for_2: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var o = { a: 1 }; for (var i; i = o.a--;) console.log(i); } expect: { var o = { a: 1 }; for (var i; i = o.a--;) console.log(i); } expect_stdout: "1" } array_forin_1: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var a = [ 1, 2, 3 ]; for (var b in a) console.log(b); } expect: { for (var b in [ 1, 2, 3 ]) console.log(b); } expect_stdout: [ "0", "1", "2", ] } array_forin_2: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var a = []; for (var b in [ 1, 2, 3 ]) a.push(b); console.log(a.length); } expect: { var a = []; for (var b in [ 1, 2, 3 ]) a.push(b); console.log(a.length); } expect_stdout: "3" } array_forof_1: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var a = [ 1, 2, 3 ]; for (var b of a) console.log(b); } expect: { for (var b of [ 1, 2, 3 ]) console.log(b); } expect_stdout: [ "1", "2", "3", ] } array_forof_2: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var a = []; for (var b of [ 1, 2, 3 ]) a.push(b); console.log(a.length); } expect: { var a = []; for (var b of [ 1, 2, 3 ]) a.push(b); console.log(a.length); } expect_stdout: "3" } const_expr_1: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unsafe: true, unused: true, } input: { var o = { a: 1, b: 2 }; o.a++; console.log(o.a, o.b); } expect: { var o = { a: 1, b: 2 }; o.a++; console.log(o.a, o.b); } expect_stdout: "2 2" } const_expr_2: { options = { evaluate: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unsafe: true, unused: true, } input: { Object.prototype.c = function() { this.a++; }; var o = { a: 1, b: 2 }; o.c(); console.log(o.a, o.b); } expect: { Object.prototype.c = function() { this.a++; }; var o = { a: 1, b: 2 }; o.c(); console.log(o.a, o.b); } expect_stdout: "2 2" } issue_2406_1: { options = { reduce_funcs: true, reduce_vars: true, toplevel: false, unused: true, } input: { const c = { fn: function() { return this; } }; let l = { fn: function() { return this; } }; var v = { fn: function() { return this; } }; console.log(c.fn(), l.fn(), v.fn()); } expect: { const c = { fn: function() { return this; } }; let l = { fn: function() { return this; } }; var v = { fn: function() { return this; } }; console.log(c.fn(), l.fn(), v.fn()); } } issue_2406_2: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { const c = { fn: function() { return this; } }; let l = { fn: function() { return this; } }; var v = { fn: function() { return this; } }; console.log(c.fn(), l.fn(), v.fn()); } expect: { console.log({ fn: function() { return this; } }.fn(), { fn: function() { return this; } }.fn(), { fn: function() { return this; } }.fn()); } } escaped_prop_1: { options = { collapse_vars: true, evaluate: true, inline: true, pure_getters: "strict", reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unsafe: true, unused: true, } input: { var obj = { o: { a: 1 } }; (function(o) { o.a++; })(obj.o); (function(o) { console.log(o.a); })(obj.o); } expect: { var obj = { o: { a: 1 } }; obj.o.a++; console.log(obj.o.a); } expect_stdout: "2" } escaped_prop_2: { options = { collapse_vars: true, evaluate: true, inline: true, passes: 2, pure_getters: "strict", reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unsafe: true, unused: true, } input: { var obj = { o: { a: 1 } }; (function(o) { o.a++; })(obj.o); (function(o) { console.log(o.a); })(obj.o); } expect: { var obj = { o: { a: 1 } }; obj.o.a++; console.log(obj.o.a); } expect_stdout: "2" } escaped_prop_3: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var a; function f(b) { if (a) console.log(a === b.c); a = b.c; } function g() {} function h() { f({ c: g }); } h(); h(); } expect: { var a; function g() {} function h() { (function(b) { if (a) console.log(a === b.c); a = b.c; })({ c: g }); } h(); h(); } expect_stdout: "true" } issue_2420_1: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { function run() { var self = this; if (self.count++) self.foo(); else self.bar(); } var o = { count: 0, foo: function() { console.log("foo"); }, bar: function() { console.log("bar"); }, }; run.call(o); run.call(o); } expect: { function run() { if (this.count++) this.foo(); else this.bar(); } var o = { count: 0, foo: function() { console.log("foo"); }, bar: function() { console.log("bar"); }, }; run.call(o); run.call(o); } expect_stdout: [ "bar", "foo", ] } issue_2420_2: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { function f() { var that = this; if (that.bar) that.foo(); else !function(that, self) { console.log(this === that, self === this, that === self); }(that, this); } f.call({ bar: 1, foo: function() { console.log("foo", this.bar); }, }); f.call({}); } expect: { function f() { if (this.bar) this.foo(); else !function(that, self) { console.log(this === that, self === this, that === self); }(this, this); } f.call({ bar: 1, foo: function() { console.log("foo", this.bar); }, }); f.call({}); } expect_stdout: [ "foo 1", "false false true", ] } issue_2420_3: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { function f() { var that = this; if (that.bar) that.foo(); else ((that, self) => { console.log(this === that, self === this, that === self); })(that, this); } f.call({ bar: 1, foo: function() { console.log("foo", this.bar); }, }); f.call({}); } expect: { function f() { if (this.bar) this.foo(); else ((that, self) => { console.log(this === that, self === this, that === self); })(this, this); } f.call({ bar: 1, foo: function() { console.log("foo", this.bar); }, }); f.call({}); } expect_stdout: [ "foo 1", "true true true", ] } issue_2423_1: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function c() { return 1; } function p() { console.log(c()); } p(); p(); } expect: { function p() { console.log(function() { return 1; }()); } p(); p(); } expect_stdout: [ "1", "1", ] } issue_2423_2: { options = { inline: true, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function c() { return 1; } function p() { console.log(c()); } p(); p(); } expect: { function p() { console.log(1); } p(); p(); } expect_stdout: [ "1", "1", ] } issue_2423_3: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function c() { return 1; } function p() { console.log(c()); } p(); } expect: { (function() { console.log(function() { return 1; }()); })(); } expect_stdout: "1" } issue_2423_4: { options = { inline: true, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { function c() { return 1; } function p() { console.log(c()); } p(); } expect: { console.log(1); } expect_stdout: "1" } issue_2423_5: { options = { inline: true, passes: 2, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { function x() { y(); } function y() { console.log(1); } function z() { function y() { console.log(2); } x(); } z(); z(); } expect: { function z() { console.log(1); } z(); z(); } expect_stdout: [ "1", "1", ] } issue_2423_6: { options = { inline: true, passes: 2, reduce_funcs: true, reduce_vars: true, side_effects: true, toplevel: true, unused: true, } input: { function x() { y(); } function y() { console.log(1); } function z() { function y() { console.log(2); } x(); y(); } z(); z(); } expect: { function z(){ console.log(1); console.log(2); } z(); z(); } expect_stdout: [ "1", "2", "1", "2", ] } issue_2440_eval_1: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function foo() { return bar(); } baz = { quux: foo }; exec = function() { return eval("foo()"); }; } expect: { function foo() { return bar(); } baz = { quux: foo }; exec = function() { return eval("foo()"); }; } } issue_2440_eval_2: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { baz = { quux: foo }; exec = function() { return eval("foo()"); }; function foo() { return bar(); } } expect: { baz = { quux: foo }; exec = function() { return eval("foo()"); }; function foo() { return bar(); } } } issue_2440_with_1: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function foo() { return bar(); } baz = { quux: foo }; with (o) whatever(); } expect: { function foo() { return bar(); } baz = { quux: foo }; with (o) whatever(); } } issue_2440_with_2: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { baz = { quux: foo }; with (o) whatever(); function foo() { return bar(); } } expect: { baz = { quux: foo }; with (o) whatever(); function foo() { return bar(); } } } issue_2442: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function foo() { foo(); } } expect: {} } recursive_inlining_1: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { !function() { function foo() { bar(); } function bar() { foo(); } console.log("PASS"); }(); } expect: { !function() { console.log("PASS"); }(); } expect_stdout: "PASS" } recursive_inlining_2: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { !function() { function foo() { qux(); } function bar() { foo(); } function qux() { bar(); } console.log("PASS"); }(); } expect: { !function() { console.log("PASS"); }(); } expect_stdout: "PASS" } recursive_inlining_3: { options = { passes: 2, reduce_funcs: true, reduce_vars: true, unused: true, } input: { !function() { function foo(x) { console.log("foo", x); if (x) bar(x-1); } function bar(x) { console.log("bar", x); if (x) qux(x-1); } function qux(x) { console.log("qux", x); if (x) foo(x-1); } qux(4); }(); } expect: { !function() { function qux(x) { console.log("qux", x); if (x) (function(x) { console.log("foo", x); if (x) (function(x) { console.log("bar", x); if (x) qux(x - 1); })(x - 1); })(x - 1); } qux(4); }(); } expect_stdout: [ "qux 4", "foo 3", "bar 2", "qux 1", "foo 0", ] } recursive_inlining_4: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { !function() { function foo(x) { console.log("foo", x); if (x) bar(x-1); } function bar(x) { console.log("bar", x); if (x) qux(x-1); } function qux(x) { console.log("qux", x); if (x) foo(x-1); } qux(4); bar(5); }(); } expect: { !function() { function bar(x) { console.log("bar", x); if (x) qux(x - 1); } function qux(x) { console.log("qux", x); if (x) (function(x) { console.log("foo", x); if (x) bar(x - 1); })(x - 1); } qux(4); bar(5); }(); } expect_stdout: [ "qux 4", "foo 3", "bar 2", "qux 1", "foo 0", "bar 5", "qux 4", "foo 3", "bar 2", "qux 1", "foo 0", ] } recursive_inlining_5: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { !function() { function foo(x) { console.log("foo", x); if (x) bar(x-1); } function bar(x) { console.log("bar", x); if (x) qux(x-1); } function qux(x) { console.log("qux", x); if (x) foo(x-1); } qux(4); bar(5); foo(3); }(); } expect: { !function() { function foo(x) { console.log("foo", x); if (x) bar(x - 1); } function bar(x) { console.log("bar", x); if (x) qux(x - 1); } function qux(x) { console.log("qux", x); if (x) foo(x - 1); } qux(4); bar(5); foo(3); }(); } expect_stdout: [ "qux 4", "foo 3", "bar 2", "qux 1", "foo 0", "bar 5", "qux 4", "foo 3", "bar 2", "qux 1", "foo 0", "foo 3", "bar 2", "qux 1", "foo 0", ] } issue_2450_1: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function f() {} function g() { return f; } console.log(g() === g()); } expect: { function f() {} function g() { return f; } console.log(g() === g()); } expect_stdout: "true" } issue_2450_2: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function g() { function f() {} return f; } console.log(g() === g()); } expect: { function g() { return function() {}; } console.log(g() === g()); } expect_stdout: "false" } issue_2450_3: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { var x = (function() { function test() { return "foo"; } return function b() { return [1, test]; } })(); console.log(x()[1] === x()[1]); } expect: { var x = (function() { function test() { return "foo"; } return function() { return [1, test]; } })(); console.log(x()[1] === x()[1]); } expect_stdout: "true" } issue_2450_4: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var a; function f(b) { console.log(a === b); a = b; } function g() {} for (var i = 3; --i >= 0;) f(g); } expect: { var a; function f(b) { console.log(a === b); a = b; } function g() {} for (var i = 3; --i >= 0;) f(g); } expect_stdout: [ "false", "true", "true", ] } issue_2450_5: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var a; function f(b) { console.log(a === b); a = b; } function g() {} [1, 2, 3].forEach(function() { f(g); }); } expect: { var a; function g() {} [1, 2, 3].forEach(function() { (function(b) { console.log(a === b); a = b; })(g); }); } expect_stdout: [ "false", "true", "true", ] } issue_2449: { options = { passes: 10, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var a = "PASS"; function f() { return a; } function g() { return f(); } (function() { var a = "FAIL"; if (a == a) console.log(g()); })(); } expect: { var a = "PASS"; function g() { return function() { return a; }(); } (function() { var a = "FAIL"; if (a == a) console.log(g()); })(); } expect_stdout: "PASS" } perf_1: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function foo(x, y, z) { return x < y ? x * y + z : x * z - y; } function indirect_foo(x, y, z) { return foo(x, y, z); } var sum = 0; for (var i = 0; i < 100; ++i) { sum += indirect_foo(i, i + 1, 3 * i); } console.log(sum); } expect: { function indirect_foo(x, y, z) { return function(x, y, z) { return x < y ? x * y + z : x * z - y; }(x, y, z); } var sum = 0; for (var i = 0; i < 100; ++i) sum += indirect_foo(i, i + 1, 3 * i); console.log(sum); } expect_stdout: "348150" } perf_2: { options = { reduce_funcs: false, reduce_vars: true, toplevel: true, unused: true, } input: { function foo(x, y, z) { return x < y ? x * y + z : x * z - y; } function indirect_foo(x, y, z) { return foo(x, y, z); } var sum = 0; for (var i = 0; i < 100; ++i) { sum += indirect_foo(i, i + 1, 3 * i); } console.log(sum); } expect: { function foo(x, y, z) { return x < y ? x * y + z : x * z - y; } function indirect_foo(x, y, z) { return foo(x, y, z); } var sum = 0; for (var i = 0; i < 100; ++i) sum += indirect_foo(i, i + 1, 3 * i); console.log(sum); } expect_stdout: "348150" } perf_3: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var foo = function(x, y, z) { return x < y ? x * y + z : x * z - y; } var indirect_foo = function(x, y, z) { return foo(x, y, z); } var sum = 0; for (var i = 0; i < 100; ++i) sum += indirect_foo(i, i + 1, 3 * i); console.log(sum); } expect: { var indirect_foo = function(x, y, z) { return function(x, y, z) { return x < y ? x * y + z : x * z - y; }(x, y, z); } var sum = 0; for (var i = 0; i < 100; ++i) sum += indirect_foo(i, i + 1, 3 * i); console.log(sum); } expect_stdout: "348150" } perf_4: { options = { reduce_funcs: false, reduce_vars: true, toplevel: true, unused: true, } input: { var foo = function(x, y, z) { return x < y ? x * y + z : x * z - y; } var indirect_foo = function(x, y, z) { return foo(x, y, z); } var sum = 0; for (var i = 0; i < 100; ++i) sum += indirect_foo(i, i + 1, 3 * i); console.log(sum); } expect: { var foo = function(x, y, z) { return x < y ? x * y + z : x * z - y; } var indirect_foo = function(x, y, z) { return foo(x, y, z); } var sum = 0; for (var i = 0; i < 100; ++i) sum += indirect_foo(i, i + 1, 3 * i); console.log(sum); } expect_stdout: "348150" } perf_5: { options = { passes: 10, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function indirect_foo(x, y, z) { function foo(x, y, z) { return x < y ? x * y + z : x * z - y; } return foo(x, y, z); } var sum = 0; for (var i = 0; i < 100; ++i) { sum += indirect_foo(i, i + 1, 3 * i); } console.log(sum); } expect: { function indirect_foo(x, y, z) { return function(x, y, z) { return x < y ? x * y + z : x * z - y; }(x, y, z); } var sum = 0; for (var i = 0; i < 100; ++i) sum += indirect_foo(i, i + 1, 3 * i); console.log(sum); } expect_stdout: "348150" } perf_6: { options = { passes: 10, reduce_funcs: false, reduce_vars: true, toplevel: true, unused: true, } input: { function indirect_foo(x, y, z) { function foo(x, y, z) { return x < y ? x * y + z : x * z - y; } return foo(x, y, z); } var sum = 0; for (var i = 0; i < 100; ++i) { sum += indirect_foo(i, i + 1, 3 * i); } console.log(sum); } expect: { function indirect_foo(x, y, z) { return function(x, y, z) { return x < y ? x * y + z : x * z - y; }(x, y, z); } var sum = 0; for (var i = 0; i < 100; ++i) sum += indirect_foo(i, i + 1, 3 * i); console.log(sum); } expect_stdout: "348150" } perf_7: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { var indirect_foo = function(x, y, z) { var foo = function(x, y, z) { return x < y ? x * y + z : x * z - y; } return foo(x, y, z); } var sum = 0; for (var i = 0; i < 100; ++i) sum += indirect_foo(i, i + 1, 3 * i); console.log(sum); } expect: { var indirect_foo = function(x, y, z) { return function(x, y, z) { return x < y ? x * y + z : x * z - y; }(x, y, z); } var sum = 0; for (var i = 0; i < 100; ++i) sum += indirect_foo(i, i + 1, 3 * i); console.log(sum); } expect_stdout: "348150" } perf_8: { options = { reduce_funcs: false, reduce_vars: true, toplevel: true, unused: true, } input: { var indirect_foo = function(x, y, z) { var foo = function(x, y, z) { return x < y ? x * y + z : x * z - y; } return foo(x, y, z); } var sum = 0; for (var i = 0; i < 100; ++i) sum += indirect_foo(i, i + 1, 3 * i); console.log(sum); } expect: { var indirect_foo = function(x, y, z) { return function(x, y, z) { return x < y ? x * y + z : x * z - y; }(x, y, z); } var sum = 0; for (var i = 0; i < 100; ++i) sum += indirect_foo(i, i + 1, 3 * i); console.log(sum); } expect_stdout: "348150" } issue_2485: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { var foo = function(bar) { var n = function(a, b) { return a + b; }; var sumAll = function(arg) { return arg.reduce(n, 0); }; var runSumAll = function(arg) { return sumAll(arg); }; bar.baz = function(arg) { var n = runSumAll(arg); return (n.get = 1), n; }; return bar; }; var bar = foo({}); console.log(bar.baz([1, 2, 3])); } expect: { var foo = function(bar) { var n = function(a, b) { return a + b; }; var runSumAll = function(arg) { return function(arg) { return arg.reduce(n, 0); }(arg); }; bar.baz = function(arg) { var n = runSumAll(arg); return (n.get = 1), n; }; return bar; }; var bar = foo({}); console.log(bar.baz([1, 2, 3])); } expect_stdout: "6" } issue_2496: { options = { passes: 2, reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function execute(callback) { callback(); } class Foo { constructor(message) { this.message = message; } go() { this.message = "PASS"; console.log(this.message); } run() { execute(() => { this.go(); }); } } new Foo("FAIL").run(); } expect: { new class { constructor(message) { this.message = message; } go() { this.message = "PASS"; console.log(this.message); } run() { (function(callback) { callback(); })(() => { this.go(); }); } }("FAIL").run(); } expect_stdout: "PASS" } issue_2416: { options = { keep_classnames: true, reduce_vars: true, toplevel: true, unused: true, } input: { class Foo {} console.log(Foo.name); } expect: { console.log((class Foo {}).name); } expect_stdout: "Foo" } issue_2455: { options = { reduce_vars: true, unused: true, } input: { function foo() { var that = this; for (;;) that.bar(); } } expect: { function foo() { for (;;) this.bar(); } } } escape_conditional: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function main() { var thing = baz(); if (thing !== (thing = baz())) console.log("FAIL"); else console.log("PASS"); } function baz(s) { return s ? foo : bar; } function foo() {} function bar() {} main(); } expect: { function baz(s) { return s ? foo : bar; } function foo() {} function bar() {} (function() { var thing = baz(); if (thing !== (thing = baz())) console.log("FAIL"); else console.log("PASS"); })(); } expect_stdout: "PASS" } escape_sequence: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function main() { var thing = baz(); if (thing !== (thing = baz())) console.log("FAIL"); else console.log("PASS"); } function baz() { return foo, bar; } function foo() {} function bar() {} main(); } expect: { function baz() { return function() {}, bar; } function bar() {} (function() { var thing = baz(); if (thing !== (thing = baz())) console.log("FAIL"); else console.log("PASS"); })(); } expect_stdout: "PASS" } escape_throw: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function main() { var thing = baz(); if (thing !== (thing = baz())) console.log("FAIL"); else console.log("PASS"); } function baz() { try { throw foo; } catch (bar) { return bar; } } function foo() {} main(); } expect: { function baz() { try { throw foo; } catch (bar) { return bar; } } function foo() {} (function() { var thing = baz(); if (thing !== (thing = baz())) console.log("FAIL"); else console.log("PASS"); })(); } expect_stdout: "PASS" } escape_local_conditional: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function main() { var thing = baz(); if (thing !== (thing = baz())) console.log("PASS"); else console.log("FAIL"); } function baz(s) { function foo() {} function bar() {} return s ? foo : bar; } main(); } expect: { function baz(s) { return s ? function() {} : function() {}; } (function() { var thing = baz(); if (thing !== (thing = baz())) console.log("PASS"); else console.log("FAIL"); })(); } expect_stdout: "PASS" } escape_local_sequence: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function main() { var thing = baz(); if (thing !== (thing = baz())) console.log("PASS"); else console.log("FAIL"); } function baz() { function foo() {} function bar() {} return foo, bar; } main(); } expect: { function baz() { return function() {}, function() {}; } (function() { var thing = baz(); if (thing !== (thing = baz())) console.log("PASS"); else console.log("FAIL"); })(); } expect_stdout: "PASS" } escape_local_throw: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function main() { var thing = baz(); if (thing !== (thing = baz())) console.log("PASS"); else console.log("FAIL"); } function baz() { function foo() {} try { throw foo; } catch (bar) { return bar; } } main(); } expect: { function baz() { try { throw function() {}; } catch (bar) { return bar; } } (function() { var thing = baz(); if (thing !== (thing = baz())) console.log("PASS"); else console.log("FAIL"); })(); } expect_stdout: "PASS" } escape_yield: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function main() { var thing = gen.next().value; if (thing !== (thing = gen.next().value)) console.log("FAIL"); else console.log("PASS"); } function foo() {} function* baz(s) { for (;;) yield foo; } var gen = baz(); main(); } expect: { function foo() {} var gen = function*(s) { for (;;) yield foo; }(); (function() { var thing = gen.next().value; if (thing !== (thing = gen.next().value)) console.log("FAIL"); else console.log("PASS"); })(); } expect_stdout: "PASS" } escape_await: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function main() { var thing; baz().then(x => { thing = x; }); baz().then(x => { if (thing !== (thing = x)) console.log("FAIL"); else console.log("PASS"); }); } function foo() {} async function baz() { return await foo; } main(); } expect: { function foo() {} async function baz() { return await foo; } (function() { var thing; baz().then(x => { thing = x; }); baz().then(x => { if (thing !== (thing = x)) console.log("FAIL"); else console.log("PASS"); }); })(); } } escape_expansion: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function main() { var thing = baz(); if (thing !== (thing = baz())) console.log("FAIL"); else console.log("PASS"); } function foo() {} function bar(...x) { return x[0]; } function baz() { return bar(...[ foo ]); } main(); } expect: { function foo() {} function baz() { return function(...x) { return x[0]; }(foo); } (function() { var thing = baz(); if (thing !== (thing = baz())) console.log("FAIL"); else console.log("PASS"); })(); } expect_stdout: "PASS" } inverted_var: { options = { evaluate: true, inline: true, passes: 3, reduce_vars: true, side_effects: true, unused: true, } input: { console.log(function() { var a = 1; return a; }(), function() { var b; b = 2; return b; }(), function() { c = 3; return c; var c; }(), function(c) { c = 4; return c; }(), function (c) { c = 5; return c; var c; }(), function c() { c = 6; return c; }(), function c() { c = 7; return c; var c; }(), function() { c = 8; return c; var c = "foo"; }()); } expect: { console.log(1, 2, 3, 4, 5, function c() { c = 6; return c; }(), 7, function() { c = 8; return c; var c = "foo"; }()); } expect_stdout: true } defun_single_use_loop: { options = { reduce_vars: true, toplevel: true, unused: true, } input: { for (var x, i = 2; --i >= 0; ) { var y = x; x = f; console.log(x === y); } function f() {}; } expect: { for (var x, i = 2; --i >= 0; ) { var y = x; x = f; console.log(x === y); } function f() {}; } expect_stdout: [ "false", "true", ] } do_while: { options = { evaluate: true, reduce_vars: true, } input: { function f(a) { do { (function() { a && (c = "PASS"); })(); } while (a = 0); } var c = "FAIL"; f(1); console.log(c); } expect: { function f(a) { do { (function() { a && (c = "PASS"); })(); } while (a = 0); } var c = "FAIL"; f(1); console.log(c); } expect_stdout: "PASS" } issue_2598: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function f() {} function g(a) { return a || f; } console.log(g(false) === g(null)); } expect: { function f() {} function g(a) { return a || f; } console.log(g(false) === g(null)); } expect_stdout: "true" } issue_2669: { options = { evaluate: true, reduce_vars: true, toplevel: true, unused: true, } input: { let foo; console.log(([ foo ] = [ "PASS" ]) && foo); } expect: { let foo; console.log(([ foo ] = [ "PASS" ]) && foo); } expect_stdout: "PASS" } issue_2670: { options = { reduce_vars: true, toplevel: true, unused: true, } input: { const obj = {}; obj.prop = "PASS"; const {prop: value} = obj; console.log(value); } expect: { const obj = {}; obj.prop = "PASS"; const {prop: value} = obj; console.log(value); } expect_stdout: "PASS" } var_if: { options = { evaluate: true, reduce_vars: true, unused: true, } input: { function f() { if (x()) { var a; if (!g) a = true; if (a) g(); } } } expect: { function f() { if (x()) { var a; if (!g) a = true; if (a) g(); } } } } defun_assign: { options = { reduce_vars: true, toplevel: true, } input: { console.log(typeof a); a = 42; console.log(typeof a); function a() {} console.log(typeof a); } expect: { console.log(typeof a); a = 42; console.log(typeof a); function a() {} console.log(typeof a); } expect_stdout: [ "function", "number", "number", ] } defun_var_1: { options = { evaluate: true, reduce_vars: true, toplevel: true, typeofs: true, unused: true, } input: { var a = 42, b; function a() {} function b() {} console.log(typeof a, typeof b); } expect: { var a = 42; function a() {} console.log(typeof a, "function"); } expect_stdout: "number function" } defun_var_2: { options = { evaluate: true, reduce_vars: true, toplevel: true, typeofs: true, unused: true, } input: { function a() {} function b() {} var a = 42, b; console.log(typeof a, typeof b); } expect: { function a() {} var a = 42; console.log(typeof a, "function"); } expect_stdout: "number function" } defun_var_3: { options = { evaluate: true, reduce_vars: true, toplevel: true, typeofs: true, unused: true, } input: { function a() {} function b() {} console.log(typeof a, typeof b); var a = 42, b; } expect: { function a() {} console.log(typeof a, "function"); var a = 42; } expect_stdout: "function function" } defun_catch_1: { options = { reduce_vars: true, toplevel: true, unused: true, } input: { function a() {} try { throw 42; } catch (a) { console.log(a); } } expect: { // TODO: drop unused AST_Defun function a() {} try { throw 42; } catch (a) { console.log(a); } } expect_stdout: "42" } defun_catch_2: { options = { reduce_vars: true, toplevel: true, unused: true, } input: { try { function a() {} throw 42; } catch (a) { console.log(a); } } expect: { try { // TODO: drop unused AST_Defun function a() {} throw 42; } catch (a) { console.log(a); } } expect_stdout: "42" } defun_catch_3: { options = { reduce_vars: true, toplevel: true, unused: true, } input: { try { throw 42; function a() {} } catch (a) { console.log(a); } } expect: { try { throw 42; // TODO: drop unused AST_Defun function a() {} } catch (a) { console.log(a); } } expect_stdout: "42" } defun_catch_4: { options = { reduce_vars: true, toplevel: true, unused: true, } input: { try { throw 42; } catch (a) { function a() {} console.log(a); } } expect: { try { throw 42; } catch (a) { function a() {} console.log(a); } } expect_stdout: true } defun_catch_5: { options = { reduce_vars: true, toplevel: true, unused: true, } input: { try { throw 42; } catch (a) { console.log(a); function a() {} } } expect: { try { throw 42; } catch (a) { console.log(a); function a() {} } } expect_stdout: true } defun_catch_6: { options = { reduce_vars: true, toplevel: true, unused: true, } input: { try { throw 42; } catch (a) { console.log(a); } function a() {} } expect: { try { throw 42; } catch (a) { console.log(a); } // TODO: drop unused AST_Defun function a() {} } expect_stdout: "42" } duplicate_lambda_defun_name_1: { options = { reduce_vars: true, } input: { console.log(function f(a) { function f() {} return f.length; }()); } expect: { console.log(function f(a) { function f() {} return f.length; }()); } expect_stdout: "0" } duplicate_lambda_defun_name_2: { options = { passes: 2, reduce_vars: true, unused: true, } input: { console.log(function f(a) { function f() {} return f.length; }()); } expect: { console.log(function(a) { return function() {}.length; }()); } expect_stdout: "0" } issue_2757_1: { options = { evaluate: true, inline: true, reduce_vars: true, side_effects: true, unused: true, } input: { let u; (function() { let v; console.log(u, v); })(); } expect: { let u; console.log(u, void 0); } expect_stdout: "undefined undefined" } issue_2757_2: { options = { conditionals: true, evaluate: true, inline: true, passes: 2, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { (function() { let bar; const unused = function() { bar = true; }; if (!bar) { console.log(1); } console.log(2); }()); } expect: { console.log(1), console.log(2); } expect_stdout: [ "1", "2", ] } issue_2774: { options = { reduce_vars: true, unused: true, } input: { console.log({ get a() { var b; (b = true) && b.c; b = void 0; } }.a); } expect: { console.log({ get a() { var b; (b = true) && b.c; b = void 0; } }.a); } expect_stdout: "undefined" } issue_2799_1: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { console.log(function() { return f; function f(n) { function g(i) { return i && i + g(i - 1); } function h(j) { return g(j); } return h(n); } }()(5)); } expect: { console.log(function() { return function(n) { return function(j) { return function g(i) { return i && i + g(i - 1); }(j); }(n); } }()(5)); } expect_stdout: "15" } issue_2799_2: { options = { reduce_vars: true, unsafe_proto: true, unused: true, } input: { (function() { function foo() { Function.prototype.call.apply(console.log, [ null, "PASS" ]); } foo(); })(); } expect: { (function() { (function() { (function() {}).call.apply(console.log, [ null, "PASS" ]); })(); })(); } expect_stdout: "PASS" } issue_2836: { options = { reduce_vars: true, toplevel: true, unused: true, } input: { function f() { return "FAIL"; } console.log(f()); function f() { return "PASS"; } } expect: { console.log(function() { return "PASS"; }()); } expect_stdout: "PASS" } lvalues_def_1: { options = { reduce_vars: true, toplevel: true, unused: true, } input: { var b = 1; var a = b++, b = NaN; console.log(a, b); } expect: { var b = 1; var a = b++; b = NaN; console.log(a, b); } expect_stdout: "1 NaN" } lvalues_def_2: { options = { reduce_vars: true, toplevel: true, unused: true, } input: { var b = 1; var a = b += 1, b = NaN; console.log(a, b); } expect: { var b = 1; var a = b += 1; b = NaN; console.log(a, b); } expect_stdout: "2 NaN" } chained_assignments: { options = { evaluate: true, inline: true, reduce_vars: true, sequences: true, side_effects: true, toplevel: true, unsafe: true, unused: true, } input: { function f() { var a = [0x5e, 0xad, 0xbe, 0xef]; var b = 0; b |= a[0]; b <<= 8; b |= a[1]; b <<= 8; b |= a[2]; b <<= 8; b |= a[3]; return b; } console.log(f().toString(16)); } expect: { console.log("5eadbeef"); } expect_stdout: "5eadbeef" } issue_2860_1: { options = { dead_code: true, evaluate: true, reduce_vars: true, } input: { console.log(function(a) { return a ^= 1; a ^= 2; }()); } expect: { console.log(function(a) { return 1 ^ a; }()); } expect_stdout: "1" } issue_2860_2: { options = { dead_code: true, evaluate: true, inline: true, passes: 2, reduce_vars: true, } input: { console.log(function(a) { return a ^= 1; a ^= 2; }()); } expect: { console.log(1); } expect_stdout: "1" } issue_2869: { options = { evaluate: true, reduce_vars: true, } input: { var c = "FAIL"; (function f(a) { var a; if (!f) a = 0; if (a) c = "PASS"; })(1); console.log(c); } expect: { var c = "FAIL"; (function f(a) { var a; if (!f) a = 0; if (a) c = "PASS"; })(1); console.log(c); } expect_stdout: "PASS" } issue_3042_1: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function f() {} var a = [ 1, 2 ].map(function() { return new f(); }); console.log(a[0].constructor === a[1].constructor); } expect: { function f() {} var a = [ 1, 2 ].map(function() { return new f(); }); console.log(a[0].constructor === a[1].constructor); } expect_stdout: "true" } issue_3042_2: { options = { reduce_funcs: true, reduce_vars: true, toplevel: true, unused: true, } input: { function Foo() { this.isFoo = function(o) { return o instanceof Foo; }; } function FooCollection() { this.foos = [1, 1].map(function() { return new Foo(); }); } var fooCollection = new FooCollection(); console.log(fooCollection.foos[0].isFoo(fooCollection.foos[0])); console.log(fooCollection.foos[0].isFoo(fooCollection.foos[1])); console.log(fooCollection.foos[1].isFoo(fooCollection.foos[0])); console.log(fooCollection.foos[1].isFoo(fooCollection.foos[1])); } expect: { function Foo() { this.isFoo = function(o) { return o instanceof Foo; }; } var fooCollection = new function() { this.foos = [1, 1].map(function() { return new Foo(); }); }(); console.log(fooCollection.foos[0].isFoo(fooCollection.foos[0])); console.log(fooCollection.foos[0].isFoo(fooCollection.foos[1])); console.log(fooCollection.foos[1].isFoo(fooCollection.foos[0])); console.log(fooCollection.foos[1].isFoo(fooCollection.foos[1])); } expect_stdout: [ "true", "true", "true", "true", ] } issue_2919: { options = { evaluate: true, reduce_vars: true, toplevel: true, unsafe: true, unused: true, } input: { var arr = [ function() {} ]; console.log(typeof arr[0]); } expect: { console.log("function"); } expect_stdout: "function" } issue_2436: { options = { evaluate: true, reduce_vars: true, toplevel: true, unsafe: true, } input: { var c; console.log(((c = { a: 1, b: 2 }).a = 3, { x: c.a, y: c.b })); } expect: { var c; console.log(((c = { a: 1, b: 2 }).a = 3, { x: c.a, y: c.b })); } expect_stdout: true } issue_2916: { options = { collapse_vars: true, evaluate: true, inline: true, passes: 2, reduce_vars: true, side_effects: true, unsafe: true, unused: true, } input: { var c = "FAIL"; (function(b) { (function(d) { d[0] = 1; })(b); +b && (c = "PASS"); })([]); console.log(c); } expect: { var c = "FAIL"; (function(b) { b[0] = 1; +b && (c = "PASS"); })([]); console.log(c); } expect_stdout: "PASS" } issue_3125: { options = { evaluate: true, reduce_vars: true, toplevel: true, unsafe: true, } input: { var o; console.log((function() { this.p++; }.call(o = { p: 6 }), o.p)); } expect: { var o; console.log((function() { this.p++; }.call(o = { p: 6 }), o.p)); } expect_stdout: "7" } issue_2992: { options = { evaluate: true, reduce_vars: true, } input: { var c = "PASS"; (function f(b) { switch (0) { case 0: case b = 1: b && (c = "FAIL"); } })(); console.log(c); } expect: { var c = "PASS"; (function f(b) { switch (0) { case 0: case b = 1: b && (c = "FAIL"); } })(); console.log(c); } expect_stdout: "PASS" } issue_3068_1: { options = { evaluate: true, reduce_vars: true, } input: { (function() { do { continue; var b = "defined"; } while (b && b.c); })(); } expect: { (function() { do { continue; var b = "defined"; } while (b && b.c); })(); } expect_stdout: true } issue_3068_2: { options = { evaluate: true, reduce_vars: true, } input: { (function() { do { try { while ("" == typeof a); } finally { continue; } var b = "defined"; } while (b && b.c); })(); } expect: { (function() { do { try { while ("" == typeof a); } finally { continue; } var b = "defined"; } while (b && b.c); })(); } expect_stdout: true } issue_3110_1: { options = { conditionals: true, evaluate: true, inline: true, passes: 3, properties: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { (function() { function foo() { return isDev ? "foo" : "bar"; } var isDev = true; var obj = { foo: foo }; console.log(foo()); console.log(obj.foo()); })(); } expect_stdout: [ "foo", "foo", ] } issue_3110_2: { options = { conditionals: true, evaluate: true, inline: true, passes: 4, properties: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { (function() { function foo() { return isDev ? "foo" : "bar"; } var isDev = true; console.log(foo()); var obj = { foo: foo }; console.log(obj.foo()); })(); } expect_stdout: [ "foo", "foo", ] } issue_3110_3: { options = { conditionals: true, evaluate: true, inline: true, properties: true, reduce_vars: true, sequences: true, side_effects: true, unused: true, } input: { (function() { function foo() { return isDev ? "foo" : "bar"; } console.log(foo()); var isDev = true; var obj = { foo: foo }; console.log(obj.foo()); })(); } expect: { (function() { function foo() { return isDev ? "foo" : "bar"; } console.log(foo()); var isDev = true; var obj = { foo: foo }; console.log(obj.foo()); })(); } expect_stdout: [ "bar", "foo", ] } issue_3113_1: { options = { evaluate: true, reduce_vars: true, } input: { var c = 0; (function() { function f() { while (g()); } var a = f(); function g() { a && a[c++]; } g(a = 1); })(); console.log(c); } expect: { var c = 0; (function() { function f() { while (g()); } var a = f(); function g() { a && a[c++]; } g(a = 1); })(); console.log(c); } expect_stdout: "1" } issue_3113_2: { options = { evaluate: true, reduce_vars: true, } input: { var c = 0; (function() { function f() { while (g()); } var a = f(); function g() { a && a[c++]; } a = 1; g(); })(); console.log(c); } expect: { var c = 0; (function() { function f() { while (g()); } var a = f(); function g() { a && a[c++]; } a = 1; g(); })(); console.log(c); } expect_stdout: "1" } issue_3113_3: { options = { evaluate: true, inline: true, passes: 2, pure_getters: "strict", reduce_vars: true, side_effects: true, unused: true, } input: { var c = 0; (function() { function f() { while (g()); } var a; function g() { a && a[c++]; } g(a = 1); })(); console.log(c); } expect_stdout: "1" } issue_3113_4: { options = { evaluate: true, reduce_vars: true, toplevel: true, } input: { var a = 0, b = 0; function f() { b += a; } f(f(), ++a); console.log(a, b); } expect: { var a = 0, b = 0; function f() { b += a; } f(f(), ++a); console.log(a, b); } expect_stdout: "1 1" } issue_3113_5: { options = { evaluate: true, reduce_vars: true, toplevel: true, } input: { function f() { console.log(a); } function g() { f(); } while (g()); var a = 1; f(); } expect: { function f() { console.log(a); } function g() { f(); } while (g()); var a = 1; f(); } expect_stdout: [ "undefined", "1", ] } conditional_nested_1: { options = { evaluate: true, reduce_vars: true, } input: { var a = 1, b = 0; (function f(c) { function g() { c && (c.a = 0); c && (c.a = 0); c && (c[b++] *= 0); } g(a-- && f(g(c = 42))); })(); console.log(b); } expect: { var a = 1, b = 0; (function f(c) { function g() { c && (c.a = 0); c && (c.a = 0); c && (c[b++] *= 0); } g(a-- && f(g(c = 42))); })(); console.log(b); } expect_stdout: "2" } conditional_nested_2: { options = { evaluate: true, reduce_vars: true, } input: { var c = 0; (function(a) { function f() { a && c++; } f(!c && f(), a = 1); })(); console.log(c); } expect: { var c = 0; (function(a) { function f() { a && c++; } f(!c && f(), a = 1); })(); console.log(c); } expect_stdout: "1" } conditional_nested_3: { options = { evaluate: true, reduce_vars: true, } input: { var n = 2, c = 0; (function f(a) { 0 < n-- && g(a = 1); function g() { a && c++; } g(); 0 < n-- && f(); })(); console.log(c); } expect: { var n = 2, c = 0; (function f(a) { 0 < n-- && g(a = 1); function g() { a && c++; } g(); 0 < n-- && f(); })(); console.log(c); } expect_stdout: "2" } issue_3140_1: { options = { reduce_vars: true, unused: true, } input: { (function() { var a; function f() { } f.g = function g() { function h() { console.log(a ? "PASS" : "FAIL"); } a = true; this(); a = false; h.g = g; return h; }; return f; })().g().g(); } expect: { (function() { var a; function f() { } f.g = function g() { function h() { console.log(a ? "PASS" : "FAIL"); } a = true; this(); a = false; h.g = g; return h; }; return f; })().g().g(); } expect_stdout: "PASS" } issue_3140_2: { options = { reduce_vars: true, unused: true, } input: { (function() { var a; function f() { } f.g = function g() { var self = this; function h() { console.log(a ? "PASS" : "FAIL"); } a = true; self(); a = false; h.g = g; return h; }; return f; })().g().g(); } expect: { (function() { var a; function f() { } f.g = function g() { function h() { console.log(a ? "PASS" : "FAIL"); } a = true; this(); a = false; h.g = g; return h; }; return f; })().g().g(); } expect_stdout: "PASS" } issue_3140_3: { options = { reduce_vars: true, unused: true, } input: { (function() { var a; function f() { } f.g = function g() { var self = this; function h() { console.log(a ? "PASS" : "FAIL"); } a = true; (function() { return self; })()(); a = false; h.g = g; return h; }; return f; })().g().g(); } expect: { (function() { var a; function f() { } f.g = function g() { var self = this; function h() { console.log(a ? "PASS" : "FAIL"); } a = true; (function() { return self; })()(); a = false; h.g = g; return h; }; return f; })().g().g(); } expect_stdout: "PASS" } issue_3140_4: { options = { reduce_vars: true, unused: true, } input: { (function() { var a; function f() { } f.g = function g() { var o = { p: this }; function h() { console.log(a ? "PASS" : "FAIL"); } a = true; o.p(); a = false; h.g = g; return h; }; return f; })().g().g(); } expect: { (function() { var a; function f() { } f.g = function g() { var o = { p: this }; function h() { console.log(a ? "PASS" : "FAIL"); } a = true; o.p(); a = false; h.g = g; return h; }; return f; })().g().g(); } expect_stdout: "PASS" } issue_3140_5: { options = { evaluate: true, reduce_vars: true, } input: { var n = 1, c = 0; (function(a) { var b = function() { this; n-- && h(); }(); function h() { b && c++; } h(b = 1); })(); console.log(c); } expect: { var n = 1, c = 0; (function(a) { var b = function() { this; n-- && h(); }(); function h() { b && c++; } h(b = 1); })(); console.log(c); } expect_stdout: "1" } reduce_funcs_in_array_1: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { (function() { function Foo() { return 123; } function bar() { return [Foo].concat([2]); } var a = [bar(), bar()]; console.log(a[0][0] === a[1][0], a[0][0]()); })(); } expect_stdout: "true 123" } reduce_funcs_in_array_2: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { (function() { function Foo() { return 123; } function bar(val) { return [val || Foo].concat([2]); } var a = [bar(), bar()]; console.log(a[0][0] === a[1][0], a[0][0]()); })(); } expect_stdout: "true 123" } reduce_funcs_in_object_literal_1: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { (function() { function Foo() { return 123; } function bar() { return [({prop: Foo}).prop].concat([2]); } var a = [bar(), bar()]; console.log(a[0][0] === a[1][0], a[0][0]()); })(); } expect_stdout: "true 123" } reduce_funcs_in_object_literal_2: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { (function() { function Foo() { return 123; } function bar(val) { return [val || Foo].concat([2]); } var a = [bar(), bar()]; console.log(a[0][0] === a[1][0], a[0][0]()); })(); } expect_stdout: "true 123" } single_use_class_referenced_in_array: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { (function() { class Foo { data() { return 123; } } function bar(val) { return [val || Foo].concat([2]); } var a = [bar(), bar()]; console.log(a[0][0] === a[1][0], (new a[0][0]).data()); })(); } expect_stdout: "true 123" } single_use_class_referenced_in_object_literal: { options = { reduce_funcs: true, reduce_vars: true, unused: true, } input: { (function() { class Foo { data() { return 123; } } function bar(val) { return [({prop: val || Foo}).prop].concat([2]); } var a = [bar(), bar()]; console.log(a[0][0] === a[1][0], (new a[0][0]).data()); })(); } expect_stdout: "true 123" } issue_369: { options = { reduce_vars: true } input: { var printTest = function (ret) { function ret() { console.log("Value after override"); } return ret; }("Value before override"); printTest(); } expect_stdout: "Value after override" } terser-4.1.2/test/compress/regexp.js000066400000000000000000000014261351061312300174620ustar00rootroot00000000000000regexp_simple: { input: { /rx/ig } expect_exact: "/rx/gi;" } regexp_slashes: { input: { /\\\/rx\/\\/ig } expect_exact: "/\\\\\\/rx\\/\\\\/gi;" } regexp_1: { options = { } input: { console.log(JSON.stringify("COMPASS? Overpass.".match(/([Sap]+)/ig))); } expect: { console.log(JSON.stringify("COMPASS? Overpass.".match(/([Sap]+)/gi))); } expect_stdout: '["PASS","pass"]' } regexp_2: { options = { evaluate: true, unsafe: true, } input: { console.log(JSON.stringify("COMPASS? Overpass.".match(new RegExp("([Sap]+)", "ig")))); } expect: { console.log(JSON.stringify("COMPASS? Overpass.".match(/([Sap]+)/gi))); } expect_stdout: '["PASS","pass"]' } terser-4.1.2/test/compress/rename.js000066400000000000000000000250071351061312300174400ustar00rootroot00000000000000mangle_catch: { rename = true 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: { rename = true 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: { rename = true 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: { rename = true 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: { rename = true 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 o="FAIL";try{throw 1}catch(c){o="PASS"}console.log(o);' expect_stdout: "PASS" } mangle_catch_ie8_toplevel: { rename = true 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: { rename = true 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 o="FAIL";try{throw 1}catch(r){var o="PASS"}console.log(o);' expect_stdout: "PASS" } mangle_catch_var_ie8_toplevel: { rename = true 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: { rename = true 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: { rename = true 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: { rename = true 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: { rename = true 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: { rename = true 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: { rename = true 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: { rename = true 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: { rename = true 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" } issue_2120_1: { rename = true mangle = { ie8: false, } input: { "aaaaaaaa"; var a = 1, b = "FAIL"; try { throw 1; } catch (c) { try { throw 0; } catch (a) { if (c) b = "PASS"; } } console.log(b); } expect: { "aaaaaaaa"; var a = 1, b = "FAIL"; try { throw 1; } catch (t) { try { throw 0; } catch (a) { if (t) b = "PASS"; } } console.log(b); } expect_stdout: "PASS" } issue_2120_2: { rename = true mangle = { ie8: true, } input: { "aaaaaaaa"; var a = 1, b = "FAIL"; try { throw 1; } catch (c) { try { throw 0; } catch (a) { if (c) b = "PASS"; } } console.log(b); } expect: { "aaaaaaaa"; var a = 1, b = "FAIL"; try { throw 1; } catch (c) { try { throw 0; } catch (a) { if (c) b = "PASS"; } } console.log(b); } expect_stdout: "PASS" } function_iife_catch: { rename = true 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(c){var o=1;console.log(c,o)}}()}f();" expect_stdout: "0 1" } function_iife_catch_ie8: { rename = true 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(o){!function(){try{throw 0}catch(o){var c=1;console.log(o,c)}}()}f();" expect_stdout: "0 1" } function_catch_catch: { rename = true 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(c){try{throw 2}catch(o){var o=3;console.log(o)}}console.log(o)}f();" expect_stdout: [ "3", "undefined", ] } function_catch_catch_ie8: { rename = true 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", ] } terser-4.1.2/test/compress/return_undefined.js000066400000000000000000000056351351061312300215360ustar00rootroot00000000000000return_undefined: { 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: true, properties: true, sequences: false, side_effects: true, unused: true, } input: { function f0() { } function f1() { return undefined; } function f2() { return void 0; } function f3() { return void 123; } function f4() { return; } function f5(a, b) { console.log(a, b); baz(a); return; } function f6(a, b) { console.log(a, b); if (a) { foo(b); baz(a); return a + b; } return undefined; } function f7(a, b) { console.log(a, b); if (a) { foo(b); baz(a); return void 0; } return a + b; } function f8(a, b) { foo(a); bar(b); return void 0; } function f9(a, b) { foo(a); bar(b); return undefined; } function f10() { return false; } function f11() { return null; } function f12() { return 0; } } expect: { function f0() {} function f1() {} function f2() {} function f3() {} function f4() {} function f5(a, b) { console.log(a, b); baz(a); } function f6(a, b) { console.log(a, b); if (a) { foo(b); baz(a); return a + b; } } function f7(a, b) { console.log(a, b); if (!a) return a + b; foo(b); baz(a); } function f8(a, b) { foo(a); bar(b); } function f9(a, b) { foo(a); bar(b); } function f10() { return !1; } function f11() { return null; } function f12() { return 0; } } } return_void: { options = { if_return: true, inline: true, reduce_vars: true, unused: true, } input: { function f() { function g() { h(); } return g(); } } expect: { function f() { h(); } } } terser-4.1.2/test/compress/sandbox.js000066400000000000000000000003701351061312300176230ustar00rootroot00000000000000console_log: { input: { console.log("%% %s"); console.log("%% %s", "%s"); } expect: { console.log("%% %s"); console.log("%% %s", "%s"); } expect_stdout: [ "%% %s", "% %s", ] } terser-4.1.2/test/compress/sequences.js000066400000000000000000000430521351061312300201640ustar00rootroot00000000000000make_sequences_1: { options = { sequences: true, } input: { foo(); bar(); baz(); } expect: { foo(),bar(),baz(); } } make_sequences_2: { options = { sequences: true, } input: { if (boo) { foo(); bar(); baz(); } else { x(); y(); z(); } } expect: { if (boo) foo(),bar(),baz(); else x(),y(),z(); } } make_sequences_3: { options = { sequences: true, } input: { function f() { foo(); bar(); return baz(); } function g() { foo(); bar(); throw new Error(); } } expect: { function f() { return foo(), bar(), baz(); } function g() { throw foo(), bar(), new Error(); } } } make_sequences_4: { options = { sequences: true, } input: { x = 5; if (y) z(); x = 5; for (i = 0; i < 5; i++) console.log(i); x = 5; for (; i < 5; i++) console.log(i); x = 5; switch (y) {} x = 5; with (obj) {} } expect: { if (x = 5, y) z(); for (x = 5, i = 0; i < 5; i++) console.log(i); for (x = 5; i < 5; i++) console.log(i); switch (x = 5, y) {} with (x = 5, obj); } expect_stdout: true } lift_sequences_1: { options = { sequences: true, } input: { var foo, x, y, bar; foo = !(x(), y(), bar()); } expect: { var foo, x, y, bar; x(), y(), foo = !bar(); } } lift_sequences_2: { options = { evaluate: true, sequences: true, } input: { var foo = 1, bar; foo.x = (foo = {}, 10); bar = (bar = {}, 10); console.log(foo, bar); } expect: { var foo = 1, bar; foo.x = (foo = {}, 10), bar = {}, bar = 10, console.log(foo, bar); } expect_stdout: true } lift_sequences_3: { options = { conditionals: true, sequences: true, } input: { var x, foo, bar, baz; x = (foo(), bar(), baz()) ? 10 : 20; } expect: { var x, foo, bar, baz; foo(), bar(), x = baz() ? 10 : 20; } } lift_sequences_4: { options = { side_effects: true, } input: { var x, foo, bar, baz; x = (foo, bar, baz); } expect: { var x, foo, bar, baz; x = baz; } } lift_sequences_5: { options = { sequences: true, } input: { var a = 2, b; a *= (b, a = 4, 3); console.log(a); } expect: { var a = 2, b; b, a *= (a = 4, 3), console.log(a); } expect_stdout: "6" } for_sequences: { options = { sequences: true, } input: { // 1 foo(); bar(); for (; false;); // 2 foo(); bar(); for (x = 5; false;); // 3 x = (foo in bar); for (; false;); // 4 x = (foo in bar); for (y = 5; false;); // 5 x = function() { foo in bar; }; for (y = 5; false;); } expect: { // 1 for (foo(), bar(); false;); // 2 for (foo(), bar(), x = 5; false;); // 3 x = (foo in bar); for (; false;); // 4 x = (foo in bar); for (y = 5; false;); // 5 for (x = function() { foo in bar; }, y = 5; false;); } } limit_1: { options = { sequences: 3, } input: { a; b; c; d; e; f; g; h; i; j; k; } expect: { a, b, c; d, e, f; g, h, i; j, k; } } limit_2: { options = { sequences: 3, } input: { a, b; c, d; e, f; g, h; i, j; k; } expect: { a, b, c, d; e, f, g, h; i, j, k; } } negate_iife_for: { options = { negate_iife: true, sequences: true, } input: { (function() {})(); for (i = 0; i < 5; i++) console.log(i); (function() {})(); for (; i < 10; i++) console.log(i); } expect: { for (!function() {}(), i = 0; i < 5; i++) console.log(i); for (!function() {}(); i < 10; i++) console.log(i); } expect_stdout: true } iife: { options = { 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() {}(), function g() {}(); } } unsafe_undefined: { options = { conditionals: true, if_return: true, sequences: true, side_effects: true, unsafe_undefined: true, } input: { function f(undefined) { if (a) return b; if (c) return d; } function g(undefined) { if (a) return b; if (c) return d; e(); } } expect: { function f(undefined) { return a ? b : c ? d : undefined; } function g(undefined) { return a ? b : c ? d : void e(); } } } issue_1685: { options = { collapse_vars: true, side_effects: true, } input: { var a = 100, b = 10; function f() { var a = (a--, delete a && --b); } f(); console.log(a, b); } expect: { var a = 100, b = 10; function f() { var a = (a--, delete a && --b); } f(); console.log(a, b); } expect_stdout: true } func_def_1: { options = { collapse_vars: true, side_effects: true, } input: { function f() { return f = 0, !!f; } console.log(f()); } expect: { function f() { return !!(f = 0); } console.log(f()); } expect_stdout: "false" } func_def_2: { options = { collapse_vars: true, side_effects: true, } input: { console.log(function f() { return f = 0, !!f; }()); } expect: { console.log(function f() { return f = 0, !!f; }()); } expect_stdout: "true" } func_def_3: { options = { collapse_vars: true, side_effects: true, } input: { function f() { function g() {} return g = 0, !!g; } console.log(f()); } expect: { function f() { function g() {} return !!(g = 0); } console.log(f()); } expect_stdout: "false" } func_def_4: { options = { collapse_vars: true, side_effects: true, } input: { function f() { function g() { return g = 0, !!g; } return g(); } console.log(f()); } expect: { function f() { function g() { return !!(g = 0); } return g(); } console.log(f()); } expect_stdout: "false" } func_def_5: { options = { collapse_vars: true, side_effects: true, } input: { function f() { return function g(){ return g = 0, !!g; }(); } console.log(f()); } expect: { function f() { return function g(){ return g = 0, !!g; }(); } console.log(f()); } expect_stdout: "true" } issue_1758: { options = { 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 function() { return c--, c--, void c.toString(); }(); }()); } expect_stdout: "undefined" } delete_seq_1: { options = { booleans: true, side_effects: true, } input: { console.log(delete (1, undefined)); console.log(delete (1, void 0)); console.log(delete (1, Infinity)); console.log(delete (1, 1 / 0)); console.log(delete (1, NaN)); console.log(delete (1, 0 / 0)); } expect: { console.log(!0); console.log(!0); console.log(!0); console.log(!0); console.log(!0); console.log(!0); } expect_stdout: true } delete_seq_2: { options = { booleans: true, side_effects: true, } input: { console.log(delete (1, 2, undefined)); console.log(delete (1, 2, void 0)); console.log(delete (1, 2, Infinity)); console.log(delete (1, 2, 1 / 0)); console.log(delete (1, 2, NaN)); console.log(delete (1, 2, 0 / 0)); } expect: { console.log(!0); console.log(!0); console.log(!0); console.log(!0); console.log(!0); console.log(!0); } expect_stdout: true } delete_seq_3: { options = { booleans: true, keep_infinity: true, side_effects: true, } input: { console.log(delete (1, 2, undefined)); console.log(delete (1, 2, void 0)); console.log(delete (1, 2, Infinity)); console.log(delete (1, 2, 1 / 0)); console.log(delete (1, 2, NaN)); console.log(delete (1, 2, 0 / 0)); } expect: { console.log(!0); console.log(!0); console.log(!0); console.log(!0); console.log(!0); console.log(!0); } expect_stdout: true } delete_seq_4: { options = { booleans: true, sequences: true, side_effects: true, } input: { function f() {} console.log(delete (f(), undefined)); console.log(delete (f(), void 0)); console.log(delete (f(), Infinity)); console.log(delete (f(), 1 / 0)); console.log(delete (f(), NaN)); console.log(delete (f(), 0 / 0)); } expect: { function f() {} console.log((f(), !0)), console.log((f(), !0)), console.log((f(), !0)), console.log((f(), !0)), console.log((f(), !0)), console.log((f(), !0)); } expect_stdout: true } delete_seq_5: { options = { booleans: true, keep_infinity: true, sequences: true, side_effects: true, } input: { function f() {} console.log(delete (f(), undefined)); console.log(delete (f(), void 0)); console.log(delete (f(), Infinity)); console.log(delete (f(), 1 / 0)); console.log(delete (f(), NaN)); console.log(delete (f(), 0 / 0)); } expect: { function f() {} console.log((f(), !0)), console.log((f(), !0)), console.log((f(), !0)), console.log((f(), !0)), console.log((f(), !0)), console.log((f(), !0)); } expect_stdout: true } delete_seq_6: { options = { booleans: true, side_effects: true, } input: { var a; console.log(delete (1, a)); } expect: { var a; console.log(!0); } expect_stdout: true } side_effects: { options = { sequences: true, side_effects: true, } input: { 0, a(), 1, b(), 2, c(), 3; } expect: { a(), b(), c(); } } side_effects_cascade_1: { options = { collapse_vars: true, conditionals: true, sequences: true, side_effects: true, } input: { function f(a, b) { a -= 42; if (a < 0) a = 0; b.a = a; } } expect: { function f(a, b) { (a -= 42) < 0 && (a = 0), b.a = a; } } } side_effects_cascade_2: { options = { collapse_vars: true, side_effects: true, } input: { function f(a, b) { b = a, !a + (b += a) || (b += a), b = a, b; } } expect: { function f(a, b) { b = a, !a + (b += a) || (b += a), b = a; } } } side_effects_cascade_3: { options = { collapse_vars: true, conditionals: true, side_effects: true, } input: { function f(a, b) { "foo" ^ (b += a), b ? false : (b = a) ? -1 : (b -= a) - (b ^= a), a-- || !a, a; } } expect: { function f(a, b) { !(b += a) && ((b = a) || (b -= a, b ^= a)), a--; } } } issue_27: { options = { collapse_vars: true, passes: 2, sequences: true, side_effects: true, unused: true, } input: { (function(jQuery) { var $; $ = jQuery; $("body").addClass("foo"); })(jQuery); } expect: { (function(jQuery) { jQuery("body").addClass("foo"); })(jQuery); } } reassign_const: { options = { collapse_vars: true, sequences: true, side_effects: true, } input: { function f() { const a = 1; a++; return a; } console.log(f()); } expect: { function f() { const a = 1; return a++, a; } console.log(f()); } expect_stdout: true } issue_2062: { options = { booleans: true, collapse_vars: true, conditionals: true, side_effects: true, } input: { var a = 1; if ([ a || a++ + a--, a++ + a--, a && a.var ]); console.log(a); } expect: { var a = 1; a || (a++, a--), a++, --a && a.var; console.log(a); } expect_stdout: "1" } issue_2313: { options = { collapse_vars: true, sequences: true, side_effects: true, } input: { var a = 0, b = 0; var foo = { get c() { a++; return 42; }, set c(c) { b++; }, d: function() { this.c++; if (this.c) console.log(a, b); } } foo.d(); } expect: { var a = 0, b = 0; var foo = { get c() { return a++, 42; }, set c(c) { b++; }, d: function() { if (this.c++, this.c) console.log(a, b); } } foo.d(); } expect_stdout: "2 1" } cascade_assignment_in_return: { options = { collapse_vars: true, unused: true, } input: { function f(a, b) { return a = x(), b(a); } } expect: { function f(a, b) { return b(x()); } } } hoist_defun: { options = { join_vars: true, sequences: true, } input: { x(); function f() {} y(); } expect: { function f() {} x(), y(); } } hoist_decl: { options = { join_vars: true, sequences: true, } input: { var a; w(); var b = x(); y(); for (var c; 0;) z(); var d; } expect: { var a; w(); var b = x(), c, d; for (y(); 0;) z(); } } for_init_var: { options = { join_vars: true, unused: false, } input: { var a = "PASS"; (function() { var b = 42; for (var c = 5; c > 0;) c--; a = "FAIL"; var a; })(); console.log(a); } expect: { var a = "PASS"; (function() { for (var b = 42, c = 5, a; c > 0;) c--; a = "FAIL"; })(); console.log(a); } expect_stdout: "PASS" } forin: { options = { sequences: true, } input: { var o = []; o.push("PASS"); for (var a in o) console.log(o[a]); } expect: { var o = []; for (var a in o.push("PASS"), o) console.log(o[a]); } expect_stdout: "PASS" } call: { options = { sequences: true, } input: { var a = function() { return this; }(); function b() { console.log("foo"); } b.c = function() { console.log(this === b ? "bar" : "baz"); }; (a, b)(); (a, b.c)(); (a, function() { console.log(this === a); })(); new (a, b)(); new (a, b.c)(); new (a, function() { console.log(this === a); })(); } expect_stdout: [ "foo", "baz", "true", "foo", "baz", "false", ] } terser-4.1.2/test/compress/string-literal.js000066400000000000000000000013551351061312300211310ustar00rootroot00000000000000octal_escape_sequence: { input: { var boundaries = "\0\7\00\07\70\77\000\077\300\377"; var border_check = "\400\700\0000\3000"; } expect: { var boundaries = "\x00\x07\x00\x07\x38\x3f\x00\x3f\xc0\xff"; var border_check = "\x20\x30\x38\x30\x00\x30\xc0\x30"; } } issue_1929: { input: { function f(s) { return s.split(/[\\/]/); } var r = f("A/B\\C\\D/E\\F"); console.log(r[5], r[4], r[3], r[2], r[1], r[0], r.length); } expect: { function f(s) { return s.split(/[\\/]/); } var r = f("A/B\\C\\D/E\\F"); console.log(r[5], r[4], r[3], r[2], r[1], r[0], r.length); } expect_stdout: "F E D C B A 6" } terser-4.1.2/test/compress/super.js000066400000000000000000000002051351061312300173200ustar00rootroot00000000000000 super_can_be_parsed: { input: { super(1,2); super.meth(); } expect_exact: "super(1,2);super.meth();" } terser-4.1.2/test/compress/switch.js000066400000000000000000000355371351061312300175030ustar00rootroot00000000000000constant_switch_1: { options = { dead_code: true, evaluate: true, side_effects: true, switches: true, } input: { switch (1+1) { case 1: foo(); break; case 1+1: bar(); break; case 1+1+1: baz(); break; } } expect: { bar(); } } constant_switch_2: { options = { dead_code: true, evaluate: true, side_effects: true, switches: true, } input: { switch (1) { case 1: foo(); case 1+1: bar(); break; case 1+1+1: baz(); } } expect: { foo(); bar(); } } constant_switch_3: { options = { dead_code: true, evaluate: true, side_effects: true, switches: true, } input: { switch (10) { case 1: foo(); case 1+1: bar(); break; case 1+1+1: baz(); default: def(); } } expect: { def(); } } constant_switch_4: { options = { dead_code: true, evaluate: true, side_effects: true, switches: true, } input: { switch (2) { case 1: x(); if (foo) break; y(); break; case 1+1: bar(); default: def(); } } expect: { bar(); def(); } } constant_switch_5: { options = { dead_code: true, evaluate: true, side_effects: true, switches: true, } input: { switch (1) { case 1: x(); if (foo) break; y(); break; case 1+1: bar(); default: def(); } } expect: { // the break inside the if ruins our job // we can still get rid of irrelevant cases. switch (1) { case 1: x(); if (foo) break; y(); } // XXX: we could optimize this better by inventing an outer // labeled block, but that's kinda tricky. } } constant_switch_6: { options = { dead_code: true, evaluate: true, side_effects: true, switches: true, } input: { OUT: { foo(); switch (1) { case 1: x(); if (foo) break OUT; y(); case 1+1: bar(); break; default: def(); } } } expect: { OUT: { foo(); x(); if (foo) break OUT; y(); bar(); } } } constant_switch_7: { options = { dead_code: true, evaluate: true, side_effects: true, switches: true, } input: { OUT: { foo(); switch (1) { case 1: x(); if (foo) break OUT; for (var x = 0; x < 10; x++) { if (x > 5) break; // this break refers to the for, not to the switch; thus it // shouldn't ruin our optimization console.log(x); } y(); case 1+1: bar(); break; default: def(); } } } expect: { OUT: { foo(); x(); if (foo) break OUT; for (var x = 0; x < 10; x++) { if (x > 5) break; console.log(x); } y(); bar(); } } } constant_switch_8: { options = { dead_code: true, evaluate: true, side_effects: true, switches: true, } input: { OUT: switch (1) { case 1: x(); for (;;) break OUT; y(); break; case 1+1: bar(); default: def(); } } expect: { OUT: { x(); for (;;) break OUT; y(); } } } constant_switch_9: { options = { dead_code: true, evaluate: true, side_effects: true, switches: true, } input: { OUT: switch (1) { case 1: x(); for (;;) if (foo) break OUT; y(); case 1+1: bar(); default: def(); } } expect: { OUT: { x(); for (;;) if (foo) break OUT; y(); bar(); def(); } } } drop_default_1: { options = { dead_code: true, switches: true, } input: { switch (foo) { case 'bar': baz(); default: } } expect: { switch (foo) { case 'bar': baz(); } } } drop_default_2: { options = { dead_code: true, switches: true, } input: { switch (foo) { case 'bar': baz(); break; default: break; } } expect: { switch (foo) { case 'bar': baz(); } } } keep_default: { options = { dead_code: true, switches: true, } input: { switch (foo) { case 'bar': baz(); default: something(); break; } } expect: { switch (foo) { case 'bar': baz(); default: something(); } } } issue_1663: { options = { dead_code: true, evaluate: true, side_effects: true, switches: true, } input: { var a = 100, b = 10; function f() { switch (1) { case 1: b = a++; return ++b; default: var b; } } f(); console.log(a, b); } expect: { var a = 100, b = 10; function f() { var b; b = a++; return ++b; } f(); console.log(a, b); } expect_stdout: true } drop_case: { options = { dead_code: true, switches: true, } input: { switch (foo) { case 'bar': baz(); break; case 'moo': break; } } expect: { switch (foo) { case 'bar': baz(); } } } keep_case: { options = { dead_code: true, switches: true, } input: { switch (foo) { case 'bar': baz(); break; case moo: break; } } expect: { switch (foo) { case 'bar': baz(); break; case moo: } } } issue_376: { options = { dead_code: true, evaluate: true, switches: true, } input: { switch (true) { case boolCondition: console.log(1); break; case false: console.log(2); break; } } expect: { switch (true) { case boolCondition: console.log(1); } } } issue_441_1: { options = { dead_code: true, switches: true, } input: { switch (foo) { case bar: qux(); break; case baz: qux(); break; default: qux(); break; } } expect: { switch (foo) { case bar: case baz: default: qux(); } } } issue_441_2: { options = { dead_code: true, switches: true, } input: { switch (foo) { case bar: // TODO: Fold into the case below qux(); break; case fall: case baz: qux(); break; default: qux(); break; } } expect: { switch (foo) { case bar: qux(); break; case fall: case baz: default: qux(); } } } issue_1674: { options = { dead_code: true, evaluate: true, side_effects: true, switches: true, } input: { switch (0) { default: console.log("FAIL"); break; case 0: console.log("PASS"); break; } } expect: { console.log("PASS"); } expect_stdout: "PASS" } issue_1679: { options = { dead_code: true, evaluate: true, switches: true, } input: { var a = 100, b = 10; function f() { switch (--b) { default: case !function x() {}: break; case b--: switch (0) { default: case a--: } break; case (a++): break; } } f(); console.log(a, b); } expect: { var a = 100, b = 10; function f() { switch (--b) { default: case !function x() {}: break; case b--: switch (0) { default: case a--: } break; case (a++): } } f(); console.log(a, b); } expect_stdout: true } issue_1680_1: { options = { dead_code: true, evaluate: true, switches: true, } input: { function f(x) { console.log(x); return x + 1; } switch (2) { case f(0): case f(1): f(2); case 2: case f(3): case f(4): f(5); } } expect: { function f(x) { console.log(x); return x + 1; } switch (2) { case f(0): case f(1): f(2); case 2: f(5); } } expect_stdout: [ "0", "1", "2", "5", ] } issue_1680_2: { options = { dead_code: true, switches: true, } input: { var a = 100, b = 10; switch (b) { case a--: break; case b: var c; break; case a: break; case a--: break; } console.log(a, b); } expect: { var a = 100, b = 10; switch (b) { case a--: break; case b: var c; break; case a: case a--: } console.log(a, b); } expect_stdout: true } issue_1690_1: { options = { dead_code: true, switches: true, } input: { switch (console.log("PASS")) {} } expect: { console.log("PASS"); } expect_stdout: "PASS" } issue_1690_2: { options = { dead_code: false, switches: true, } input: { switch (console.log("PASS")) {} } expect: { switch (console.log("PASS")) {} } expect_stdout: "PASS" } if_switch_typeof: { options = { conditionals: true, dead_code: true, side_effects: true, switches: true, } input: { if (a) switch(typeof b) {} } expect: { a; } } issue_1698: { options = { side_effects: true, switches: true, } input: { var a = 1; !function() { switch (a++) {} }(); console.log(a); } expect: { var a = 1; !function() { switch (a++) {} }(); console.log(a); } expect_stdout: "2" } issue_1705_1: { options = { dead_code: true, switches: true, } input: { var a = 0; switch (a) { default: console.log("FAIL"); case 0: break; } } expect: { var a = 0; switch (a) { default: console.log("FAIL"); case 0: } } expect_stdout: true } issue_1705_2: { options = { dead_code: true, evaluate: true, reduce_funcs: true, reduce_vars: true, sequences: true, side_effects: true, switches: true, toplevel: true, unused: true, } input: { var a = 0; switch (a) { default: console.log("FAIL"); case 0: break; } } expect: { } expect_stdout: true } issue_1705_3: { options = { dead_code: true, switches: true, } input: { switch (a) { case 0: break; default: break; } } expect: { a; } expect_stdout: true } beautify: { beautify = { beautify: true, } input: { switch (a) { case 0: case 1: break; case 2: default: } switch (b) { case 3: foo(); bar(); default: break; } } expect_exact: [ "switch (a) {", " case 0:", " case 1:", " break;", "", " case 2:", " default:", "}", "", "switch (b) {", " case 3:", " foo();", " bar();", "", " default:", " break;", "}", ] } issue_1758: { options = { dead_code: true, switches: true, } input: { var a = 1, b = 2; switch (a--) { default: b++; } console.log(a, b); } expect: { var a = 1, b = 2; a--; b++; console.log(a, b); } expect_stdout: "0 3" } issue_2535: { options = { dead_code: true, evaluate: true, switches: true, } input: { switch(w(), 42) { case 13: x(); case 42: y(); default: z(); } } expect: { w(), 42; 42; y(); z(); } } issue_1750: { 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; true; a, true; b = 2; console.log(a, b); } expect_stdout: "0 2" } terser-4.1.2/test/compress/syntax-errors.js000066400000000000000000000133311351061312300210260ustar00rootroot00000000000000 missing_loop_body: { input: ` for (;;) ` expect_error: ({ name: "SyntaxError", message: "Unexpected token: eof (undefined)", line: 3, col: 4 }) } decrement_constant_number: { input: ` 5-- ` expect_error: ({ name: "SyntaxError", message: "Invalid use of -- operator", line: 2, col: 9 }) } assign_to_call: { input: ` Math.random() /= 2 ` expect_error: ({ name: "SyntaxError", message: "Invalid assignment", line: 2, col: 22 }) } increment_this: { input: ` ++this ` expect_error: ({ name: "SyntaxError", message: "Invalid use of ++ operator", line: 2, col: 8 }) } increment_null: { input: ` ++null ` expect_error: ({ name: "SyntaxError", message: "Invalid use of ++ operator", line: 2, col: 8 }) } invalid_dot: { input: ` a.= ` expect_error: ({ name: "SyntaxError", message: "Unexpected token: operator (=)", line: 2, col: 10 }) } invalid_percent: { input: ` %.a; ` expect_error: ({ name: "SyntaxError", message: "Unexpected token: operator (%)", line: 2, col: 8 }) } invalid_divide: { input: ` a./() ` expect_error: ({ name: "SyntaxError", message: "Unexpected token: operator (/)", line: 2, col: 10 }) } invalid_object_key: { input: ` x({%: 1}) ` expect_error: ({ name: "SyntaxError", message: "Unexpected token: operator (%)", line: 2, col: 11 }) } invalid_const: { input: ` const a ` expect_error: ({ name: "SyntaxError", message: "Missing initializer in const declaration", line: 3, col: 4 }) } invalid_delete: { input: ` function f(x) { delete 42; delete (0, x); delete null; delete x; } function g(x) { "use strict"; delete 42; delete (0, x); delete null; delete x; } ` expect_error: ({ name: "SyntaxError", message: "Calling delete on expression not allowed in strict mode", line: 14, col: 19 }) } invalid_arguments: { input: ` function x() { "use strict" function a(arguments) { } } ` expect_error: ({ name: "SyntaxError", message: "Unexpected arguments identifier as parameter inside strict mode", line: 4, col: 23 }) } invalid_eval: { input: ` function x() { "use strict" function eval() { } } ` expect_error: ({ name: "SyntaxError", message: "Unexpected eval in strict mode", line: 4, col: 21 }) } invalid_iife: { input: ` function x() { "use strict" !function arguments() { }() } ` expect_error: ({ name: "SyntaxError", message: "Unexpected arguments in strict mode", line: 4, col: 22 }) } invalid_catch_eval: { input: ` function x() { "use strict" try { } catch (eval) { } } ` expect_error: ({ name: "SyntaxError", message: "Unexpected eval identifier as parameter inside strict mode", line: 6, col: 21 }) } invalid_var_eval: { input: ` function x() { "use strict" var eval } ` expect_error: ({ name: "SyntaxError", message: "Unexpected eval in strict mode", line: 4, col: 16 }) } invalid_else: { input: ` if (0) else 1 ` expect_error: ({ name: "SyntaxError", message: "Unexpected token: keyword (else)", line: 2, col: 15 }) } invalid_return: { input: ` return 42 ` expect_error: ({ name: "SyntaxError", message: "'return' outside of function", line: 2, col: 8 }) } export_anonymous_class: { input: ` export class {} ` expect_error: ({ name: "SyntaxError", message: "Unexpected token: punc ({)", line: 2, col: 21 }) } export_anonymous_function: { input: ` export function () {} ` expect_error: ({ name: "SyntaxError", message: "Unexpected token: punc (()", line: 2, col: 24 }) } spread_in_sequence: { input: ` (a, ...b) ` expect_error: ({ name: "SyntaxError", message: "Unexpected token: expand (...)", line: 2, col: 12 }) } invalid_for_in: { input: ` for (1, 2, a in b) { } ` expect_error: ({ name: "SyntaxError", message: "Invalid left-hand side in for..in loop", line: 2, col: 13 }) } invalid_for_in_var: { input: ` for (var a, b in c) { } ` expect_error: ({ name: "SyntaxError", message: "Only one variable declaration allowed in for..in loop", line: 2, col: 13 }) } big_int_decimal: { input: ` .23n ` expect_error: ({ name: "SyntaxError", message: "Invalid or unexpected token", line: 2, col: 8 }) } big_int_scientific_format: { input: ` 1e3n ` expect_error: ({ name: "SyntaxError", message: "Invalid or unexpected token", line: 2, col: 8 }) } terser-4.1.2/test/compress/template-string.js000066400000000000000000000430361351061312300213120ustar00rootroot00000000000000tagged_template_parens: { input: { (a) `0`; (a => b) `1`; (a = b) `2`; (a + b) `3`; (a ? b : c) `4`; (a, b, c) `5`; (~a) `6`; (a.b) `7`; (a["b"]) `8`; (a()) `9`; } expect_exact: 'a`0`;(a=>b)`1`;(a=b)`2`;(a+b)`3`;(a?b:c)`4`;(a,b,c)`5`;(~a)`6`;a.b`7`;a["b"]`8`;a()`9`;' } template_strings: { beautify = { quote_style: 3 } input: { ``; `xx\`x`; `${ foo + 2 }`; ` foo ${ bar + `baz ${ qux }` }`; } expect_exact: "``;`xx\\`x`;`${foo+2}`;` foo ${bar+`baz ${qux}`}`;"; } template_string_prefixes: { beautify = { quote_style: 3 } input: { String.raw`foo`; foo `bar`; } expect_exact: "String.raw`foo`;foo`bar`;"; } template_strings_ascii_only: { beautify = { ascii_only: true, quote_style: 3 } input: { var foo = `foo bar ↂωↂ`; var bar = `\``; } expect_exact: "var foo=`foo\\n bar\\n \\u2182\\u03c9\\u2182`;var bar=`\\``;" } template_strings_without_ascii_only: { beautify = { quote_style: 3 } input: { var foo = `foo bar ↂωↂ` } expect_exact: "var foo=`foo\\n bar\\n ↂωↂ`;" } template_string_with_constant_expression: { options = { evaluate: true } beautify = { quote_style: 3 } input: { var foo = `${4 + 4} equals 4 + 4`; } expect: { var foo = "8 equals 4 + 4"; } } template_string_with_predefined_constants: { options = { evaluate: true } beautify = { quote_style: 3 } input: { var foo = `This is ${undefined}`; var bar = `This is ${NaN}`; var baz = `This is ${null}`; var foofoo = `This is ${Infinity}`; var foobar = "This is ${1/0}"; var foobaz = 'This is ${1/0}'; var barfoo = "This is ${NaN}"; var bazfoo = "This is ${null}"; var bazbaz = `This is ${1/0}`; var barbar = `This is ${0/0}`; var barbar = "This is ${0/0}"; var barber = 'This is ${0/0}'; var a = `${4**11}`; // 8 in template vs 7 chars - 4194304 var b = `${4**12}`; // 8 in template vs 8 chars - 16777216 var c = `${4**14}`; // 8 in template vs 9 chars - 268435456 } expect: { var foo = "This is undefined"; var bar = "This is NaN"; var baz = "This is null"; var foofoo = `This is ${1/0}`; var foobar = "This is ${1/0}"; var foobaz = 'This is ${1/0}'; var barfoo = "This is ${NaN}"; var bazfoo = "This is ${null}"; var bazbaz = `This is ${1/0}`; var barbar = "This is NaN"; var barbar = "This is ${0/0}"; var barber = 'This is ${0/0}'; var a = "4194304"; var b = "16777216"; // Potential for further concatentation var c = `${4**14}`; // Not worth converting } } template_string_evaluate_with_many_segments: { options = { evaluate: true } beautify = { quote_style: 3 } input: { var foo = `Hello ${guest()}, welcome to ${location()}${"."}`; var bar = `${1}${2}${3}${4}${5}${6}${7}${8}${9}${0}`; var baz = `${foobar()}${foobar()}${foobar()}${foobar()}`; var buzz = `${1}${foobar()}${2}${foobar()}${3}${foobar()}`; } expect: { var foo = `Hello ${guest()}, welcome to ${location()}.`; var bar = "1234567890"; var baz = `${foobar()}${foobar()}${foobar()}${foobar()}`; var buzz = `1${foobar()}2${foobar()}3${foobar()}`; } } template_string_with_many_segments: { beautify = { quote_style: 3 } input: { var foo = `Hello ${guest()}, welcome to ${location()}${"."}`; var bar = `${1}${2}${3}${4}${5}${6}${7}${8}${9}${0}`; var baz = `${foobar()}${foobar()}${foobar()}${foobar()}`; var buzz = `${1}${foobar()}${2}${foobar()}${3}${foobar()}`; } expect: { var foo = `Hello ${guest()}, welcome to ${location()}${"."}`; var bar = `${1}${2}${3}${4}${5}${6}${7}${8}${9}${0}`; var baz = `${foobar()}${foobar()}${foobar()}${foobar()}`; var buzz = `${1}${foobar()}${2}${foobar()}${3}${foobar()}`; } } template_string_to_normal_string: { options = { evaluate: true } beautify = { quote_style: 0 } input: { var foo = `This is ${undefined}`; var bar = "Decimals " + `${1}${2}${3}${4}${5}${6}${7}${8}${9}${0}`; } expect: { var foo = "This is undefined"; var bar = "Decimals 1234567890"; } } template_concattenating_string: { options = { evaluate: true } beautify = { quote_style: 3 // Yes, keep quotes } input: { var foo = "Have a nice " + `day. ${`day. ` + `day.`}`; var bar = "Have a nice " + `${day()}`; } expect: { var foo = "Have a nice day. day. day."; var bar = "Have a nice " + `${day()}`; } } evaluate_nested_templates: { options = { evaluate: true } beautify = { quote_style: 0 } input: { var baz = `${`${`${`foo`}`}`}`; } expect: { var baz = "foo"; } } enforce_double_quotes: { beautify = { quote_style: 1 } input: { var foo = `Hello world`; var bar = `Hello ${'world'}`; var baz = `Hello ${world()}`; } expect: { var foo = `Hello world`; var bar = `Hello ${"world"}`; var baz = `Hello ${world()}`; } } enforce_single_quotes: { beautify = { quote_style: 2 } input: { var foo = `Hello world`; var bar = `Hello ${"world"}`; var baz = `Hello ${world()}`; } expect: { var foo = `Hello world`; var bar = `Hello ${'world'}`; var baz = `Hello ${world()}`; } } enforce_double_quotes_and_evaluate: { beautify = { quote_style: 1 } options = { evaluate: true } input: { var foo = `Hello world`; var bar = `Hello ${'world'}`; var baz = `Hello ${world()}`; } expect: { var foo = "Hello world"; var bar = "Hello world"; var baz = `Hello ${world()}`; } } enforce_single_quotes_and_evaluate: { beautify = { quote_style: 2 } options = { evaluate: true } input: { var foo = `Hello world`; var bar = `Hello ${"world"}`; var baz = `Hello ${world()}`; } expect: { var foo = "Hello world"; var bar = "Hello world"; var baz = `Hello ${world()}`; } } respect_inline_script: { beautify = { inline_script: true, quote_style: 3 } input: { var foo = `${content}`; var bar = ``; } expect_exact: "var foo=`<\\/script>${content}`;var bar=`\\x3c!--`;var baz=`--\\x3e`;"; } do_not_optimize_tagged_template_1: { beautify = { quote_style: 0 } options = { evaluate: true } input: { var foo = tag`Shall not be optimized. ${"But " + "this " + "is " + "fine."}`; var bar = tag`Don't even mind changing my quotes!`; } expect_exact: 'var foo=tag`Shall not be optimized. ${"But this is fine."}`;var bar=tag`Don\'t even mind changing my quotes!`;'; } do_not_optimize_tagged_template_2: { options = { evaluate: true } input: { var foo = tag`test` + " something out"; } expect_exact: 'var foo=tag`test`+" something out";'; } keep_raw_content_in_tagged_template: { options = { evaluate: true } input: { var foo = tag`\u0020\u{20}\u{00020}\x20\40\040 `; } expect_exact: "var foo=tag`\\u0020\\u{20}\\u{00020}\\x20\\40\\040 `;"; } allow_chained_templates: { input: { var foo = tag`a``b``c``d`; } expect: { var foo = tag`a``b``c``d`; } } check_escaped_chars: { input: { var foo = `\u0020\u{20}\u{00020}\x20 `; } expect_exact: "var foo=` `;"; } escape_dollar_curly: { options = { evaluate: true } input: { console.log(`\$\{ beep \}`) console.log(`${1-0}\${2-0}$\{3-0}${4-0}`) console.log(`$${""}{not an expression}`) } expect_exact: 'console.log("${ beep }");console.log("1${2-0}${3-0}4");console.log("${not an expression}");' } template_starting_with_newline: { options = { dead_code: true } input: { function foo(e) { return ` this is a template string!`; }; } expect_exact: "function foo(e){return`\\nthis is a template string!`}" } template_with_newline: { options = { dead_code: true } input: { function foo(e) { return `yep, this is a template string!`; }; } expect_exact: "function foo(e){return`yep,\\nthis is a template string!`}" } template_ending_with_newline: { options = { dead_code: true } input: { function foo(e) { return `this is a template string! `; }; } expect_exact: "function foo(e){return`this is a template string!\\n`}" } issue_1856: { beautify = { ascii_only: false, } input: { console.log(`\\n\\r\\u2028\\u2029\n\r\u2028\u2029`); } expect_exact: "console.log(`\\\\n\\\\r\\\\u2028\\\\u2029\\n\\r\\u2028\\u2029`);" } issue_1856_ascii_only: { beautify = { ascii_only: true, } input: { console.log(`\\n\\r\\u2028\\u2029\n\r\u2028\u2029`); } expect_exact: "console.log(`\\\\n\\\\r\\\\u2028\\\\u2029\\n\\r\\u2028\\u2029`);" } side_effects: { options = { evaluate: true, side_effects: true, } input: { `t1`; tag`t2`; `t${3}`; tag`t${4}`; console.log(` t${5}`); function f(a) { `t6${a}`; a = `t7${a}` & a; a = `t8${b}` | a; a = f`t9${a}` ^ a; } } expect: { tag`t2`; tag`t${4}`; console.log("\nt5"); function f(a) { a &= `t7${a}`; a = `t8${b}` | a; a = f`t9${a}` ^ a; } } } simple_string: { options = { computed_props: true, evaluate: true, properties: true, } input: { console.log( `world`, {[`foo`]: 1}[`foo`], `hi` == "hi"); } expect: { console.log("world", [ 1 ][0], true); } expect_stdout: "world 1 true" } semicolons: { beautify = { semicolons: false, } input: { foo; `bar`; } expect_exact: "foo;`bar`\n" } regex_1: { input: { console.log(`${/a/} ${6/2} ${/b/.test("b")} ${1?/c/:/d/}`); } expect_exact: 'console.log(`${/a/} ${6/2} ${/b/.test("b")} ${1?/c/:/d/}`);' expect_stdout: "/a/ 3 true /c/" } regex_2: { options = { evaluate: true, unsafe: true, } input: { console.log(`${/a/} ${6/2} ${/b/.test("b")} ${1?/c/:/d/}`); } expect: { console.log("/a/ 3 true /c/"); } expect_stdout: "/a/ 3 true /c/" } sequence_1: { input: { console.log(`${1,2} ${/a/,/b/}`); } expect_exact: 'console.log(`${1,2} ${/a/,/b/}`);' expect_stdout: "2 /b/" } sequence_2: { options = { evaluate: true, side_effects: true, } input: { console.log(`${1,2} ${/a/,/b/}`); } expect: { console.log("2 /b/"); } expect_stdout: "2 /b/" } return_template_string_with_trailing_backslash: { input: { function a() { return `\ foo`; } function b() { return ` bar`; } function c() { return `\ baz`; } function d() { return `qux`; } function e() { return `\nfin`; } console.log(a(), b(), c(), d(), e()); } expect: { function a() { return `foo`; } function b() { return `\nbar`; } function c() { return; `baz`; } function d() { return; `qux`; } function e() { return `\nfin`; } console.log(a(), b(), c(), d(), e()); } expect_stdout: [ "foo ", "bar undefined undefined ", "fin", ] } tagged_template_with_invalid_escape: { input: { function x(s) { return s.raw[0]; } console.log(String.raw`\u`); console.log(x`\u`); } expect_exact: "function x(s){return s.raw[0]}console.log(String.raw`\\u`);console.log(x`\\u`);" expect_stdout: [ "\\u", "\\u", ] node_version: ">=10" } tagged_call_with_invalid_escape_2: { options = { defaults: true, toplevel: true, } input: { var x = { y: () => String.raw }; console.log(x.y()`\4321\u\x`); let z = () => String.raw; console.log(z()`\4321\u\x`); } expect: { var x_y = () => String.raw; console.log(x_y()`\4321\u\x`); console.log((() => String.raw)()`\4321\u\x`); } expect_stdout: [ "\\4321\\u\\x", "\\4321\\u\\x", ] node_version: ">=10" } es2018_revision_of_template_escapes_1: { options = { defaults: true, } input: { console.log(String.raw`\unicode \xerces \1234567890`); } expect_exact: "console.log(String.raw\`\\unicode \\xerces \\1234567890\`);" expect_stdout: "\\unicode \\xerces \\1234567890" node_version: ">=10" } tagged_call_with_invalid_escape: { input: { let z = () => String.raw; console.log(z()`\4321\u\x`); } expect: { let z = () => String.raw; console.log(z()`\4321\u\x`); } expect_stdout: [ "\\4321\\u\\x", ] node_version: ">=10" } invalid_unicode_escape_in_regular_string: { options = { defaults: true, } input: ` console.log("FAIL\\u") ` expect_error: ({ "name": "SyntaxError", "message": "Invalid hex-character pattern in string", "line": 2, "col": 20, }) } invalid_escape_in_template_string_1: { options = { defaults: true, } input: ` console.log(\`\\unicode \\xerces\ \\1234567890\`); ` expect_error: ({ "name": "SyntaxError", "message": "Invalid hex-character pattern in string", "line": 2, "col": 20 }) } invalid_escape_in_template_string_2: { options = { defaults: true, } input: ` console.log(\`\\u\`.charCodeAt(0)); ` expect_error: ({ "name": "SyntaxError", "message": "Invalid hex-character pattern in string", "line": 2, "col": 20 }) } invalid_escape_in_template_string_3: { options = { defaults: true, } input: ` console.log("FAIL\\041" + \`\\041\`); ` expect_error: ({ "name": "SyntaxError", "message": "Octal escape sequences are not allowed in template strings", "line": 2, "col": 33, }) } invalid_escape_in_template_string_4: { options = { defaults: true, } input: ` console.log("FAIL\\x21" + \`\\x\`); ` expect_error: ({ "name": "SyntaxError", "message": "Invalid hex-character pattern in string", "line": 2, "col": 33 }) } invalid_escape_in_template_string_5: { options = { defaults: true, } input: ` console.log("FAIL\\x21" + \`\\xERROR\`); ` expect_error: ({ "name": "SyntaxError", "message": "Invalid hex-character pattern in string", "line": 2, "col": 33, }) } invalid_hex_character_pattern: { input: ` console.log('\\u{-1}') ` expect_error: ({ "name": "SyntaxError", "message": "Invalid hex-character pattern in string", "line": 2, "col": 20 }) } invalid_unicode_patterns: { input: ` "\\u{110000}" ` expect_error: ({ "name": "SyntaxError", "message": "Unicode reference out of bounds" }) } invalid_unicode_patterns_2: { input: ` "\\u{100000061}" ` expect_error: ({ "name": "SyntaxError", "message": "Unicode reference out of bounds" }) } invalid_unicode_patterns_3: { input: ` "\\u{fffffffffff}" ` expect_error: ({ "name": "SyntaxError", "message": "Unicode reference out of bounds" }) } untagged_template_with_ill_formed_unicode_escape: { input: ` console.log(\`\\u{-1}\`) ` expect_error: ({ "name": "SyntaxError", "message": "Invalid hex-character pattern in string", "line": 2, "col": 20 }) } tagged_template_with_ill_formed_unicode_escape: { input: { console.log(String.raw`\u{-1}`); } expect_exact: "console.log(String.raw`\\u{-1}`);"; expect_stdout: "\\u{-1}" node_version: ">=10" } tagged_template_with_comment: { input: { console.log(String.raw/*foo*/`\u`); console.log((() => String.raw)()/*bar*/`\x`); } expect_exact: "console.log(String.raw`\\u`);console.log((()=>String.raw)()`\\x`);" expect_stdout: [ "\\u", "\\x" ] node_version: ">=10" } tagged_template_valid_strict_legacy_octal: { input: { "use strict"; console.log(String.raw`\u\x\567`); } expect_exact: '"use strict";console.log(String.raw`\\u\\x\\567`);' expect_stdout: "\\u\\x\\567" node_version: ">=10" } terser-4.1.2/test/compress/transform.js000066400000000000000000000044201351061312300202000ustar00rootroot00000000000000booleans_evaluate: { options = { booleans: true, evaluate: true, } input: { console.log(typeof void 0 != "undefined"); console.log(1 == 1, 1 === 1) console.log(1 != 1, 1 !== 1) } expect: { console.log(!1); console.log(!0, !0); console.log(!1, !1); } expect_stdout: true } booleans_global_defs: { options = { booleans: true, evaluate: true, global_defs: { A: true, }, } input: { console.log(A == 1); } expect: { console.log(!0); } } condition_evaluate: { options = { booleans: true, dead_code: false, evaluate: true, loops: false, } input: { while (1 === 2); for (; 1 == true;); if (void 0 == null); } expect: { while (0); for (; 1;); if (1); } } if_else_empty: { options = { conditionals: true, } input: { if ({} ? a : b); else {} } expect: { !{} ? b : a; } } label_if_break: { options = { conditionals: true, dead_code: true, evaluate: true, side_effects: true, } input: { L: if (true) { a; break L; } } expect: { a; } } while_if_break: { options = { conditionals: true, loops: true, sequences: true, } input: { while (a) { if (b) if(c) d; if (e) break; } } expect: { for(; a && (b && c && d, !e);); } } if_return: { options = { booleans: true, conditionals: true, if_return: true, sequences: true, } input: { function f(w, x, y, z) { if (x) return; if (w) { if (y) return; } else if (z) return; if (x == y) return true; if (x) w(); if (y) z(); return true; } } expect: { function f(w, x, y, z) { if (!x) { if (w) { if (y) return; } else if (z) return; return x == y || (x && w(), y && z(), !0); } } } } terser-4.1.2/test/compress/try-catch.js000066400000000000000000000045221351061312300200660ustar00rootroot00000000000000catch_destructuring_with_sequence: { beautify = { ecma: 6 } input: { try { throw {}; } catch ({xCover = (0, function() {})} ) { } } expect_exact: "try{throw{}}catch({xCover=(0,function(){})}){}" } broken_safari_catch_scope: { mangle = { safari10: true, } input: { "AAAAAAAA"; "BBBBBBB"; new class { f(x) { try { throw { m: "PASS" }; } catch ({m: s}) { console.log(s); } } }().f(); } expect: { "AAAAAAAA"; "BBBBBBB"; new class { f(A) { try { throw { m: "PASS" }; } catch ({m: B}) { console.log(B); } } }().f(); } expect_stdout: "PASS" } broken_safari_catch_scope_caveat: { // The `input` of this test reportedly fails on Safari 10+ despite // being valid ECMAScript. // The `expect`ed output of this test will also fail on Safari 10+ // despite of the `safari10` `mangle` option being enabled. // This test just exists to prove that both forms will run correctly // on ES spec compliant engines such as V8. mangle = { safari10: true, } input: { "AAAAAAAA"; "BBBBBBB"; new class { f(x) { try { throw { m: "PASS" }; } catch ({m: x}) { console.log(x); } } }().f(); } expect: { "AAAAAAAA"; "BBBBBBB"; new class { f(A) { try { throw { m: "PASS" }; } catch ({m: A}) { console.log(A); } } }().f(); } expect_stdout: "PASS" } parameterless_catch: { input: { try { unknown(); } catch { console.log("PASS"); } } expect_exact: 'try{unknown()}catch{console.log("PASS")}' expect_stdout: "PASS" node_version: ">=10" } terser-4.1.2/test/compress/typeof.js000066400000000000000000000141001351061312300174670ustar00rootroot00000000000000typeof_evaluation: { options = { evaluate: true, typeofs: true, } input: { a = typeof 1; b = typeof 'test'; c = typeof []; d = typeof {}; e = typeof /./; f = typeof false; g = typeof function(){}; h = typeof undefined; } expect: { a='number'; b='string'; c=typeof[]; d=typeof{}; e=typeof/./; f='boolean'; g='function'; h='undefined'; } } typeof_in_boolean_context: { options = { booleans: true, conditionals: true, evaluate: true, side_effects: true, } input: { function f1(x) { return typeof x ? "yes" : "no"; } function f2() { return typeof g()? "Yes" : "No"; } typeof 0 ? foo() : bar(); !typeof console.log(1); var a = !typeof console.log(2); if (typeof (1 + foo())); } expect: { function f1(x) { return "yes"; } function f2() { return g(), "Yes"; } foo(); console.log(1); var a = !(console.log(2), 1); foo(); } } issue_1668: { options = { booleans: true, } input: { if (typeof bar); } expect: { if (1); } } typeof_defun_1: { options = { evaluate: true, inline: true, passes: 2, reduce_vars: true, side_effects: true, toplevel: true, typeofs: true, unused: true, } input: { function f() { console.log("YES"); } function g() { h = 42; console.log("NOPE"); } function h() { console.log("YUP"); } g = 42; "function" == typeof f && f(); "function" == typeof g && g(); "function" == typeof h && h(); } expect: { function g() { h = 42; console.log("NOPE"); } function h() { console.log("YUP"); } g = 42; console.log("YES"); "function" == typeof g && g(); "function" == typeof h && h(); } expect_stdout: [ "YES", "YUP", ] } typeof_defun_2: { options = { evaluate: true, reduce_vars: true, toplevel: true, typeofs: true, } input: { var f = function() { console.log(x); }; var x = 0; x++ < 2 && typeof f == "function" && f(); x++ < 2 && typeof f == "function" && f(); x++ < 2 && typeof f == "function" && f(); } expect: { var f = function() { console.log(x); }; var x = 0; x++ < 2 && f(); x++ < 2 && f(); x++ < 2 && f(); } expect_stdout: [ "1", "2", ] } duplicate_defun_arg_name: { options = { evaluate: true, reduce_vars: true, typeofs: true, } input: { function long_name(long_name) { return typeof long_name; } console.log(typeof long_name, long_name()); } expect: { function long_name(long_name) { return typeof long_name; } console.log(typeof long_name, long_name()); } expect_stdout: "function undefined" } duplicate_lambda_arg_name: { options = { evaluate: true, reduce_vars: true, typeofs: true, } input: { console.log(function long_name(long_name) { return typeof long_name; }()); } expect: { console.log(function long_name(long_name) { return typeof long_name; }()); } expect_stdout: "undefined" } issue_2728_1: { options = { evaluate: true, reduce_vars: true, typeofs: true, } input: { (function arguments() { console.log(typeof arguments); })(); } expect: { (function arguments() { console.log(typeof arguments); })(); } expect_stdout: "object" } issue_2728_2: { options = { evaluate: true, reduce_vars: true, typeofs: true, } input: { function arguments() { return typeof arguments; } console.log(typeof arguments, arguments()); } expect: { function arguments() { return typeof arguments; } console.log(typeof arguments, arguments()); } expect_stdout: "function object" } issue_2728_3: { options = { evaluate: true, reduce_vars: true, typeofs: true, } input: { (function() { function arguments() { } console.log(typeof arguments); })(); } expect: { (function() { function arguments() { } console.log("function"); })(); } expect_stdout: "function" } issue_2728_4: { options = { evaluate: true, reduce_vars: true, toplevel: true, typeofs: true, } input: { function arguments() { } console.log(typeof arguments); } expect: { function arguments() { } console.log("function"); } expect_stdout: "function" } issue_2728_5: { options = { evaluate: true, reduce_vars: true, typeofs: true, } input: { (function arguments(arguments) { console.log(typeof arguments); })(); } expect: { (function arguments(arguments) { console.log(typeof arguments); })(); } expect_stdout: "undefined" } issue_2728_6: { options = { evaluate: true, reduce_vars: true, typeofs: true, } input: { function arguments(arguments) { return typeof arguments; } console.log(typeof arguments, arguments()); } expect: { function arguments(arguments) { return typeof arguments; } console.log(typeof arguments, arguments()); } expect_stdout: "function undefined" } terser-4.1.2/test/compress/unicode.js000066400000000000000000000075531351061312300176250ustar00rootroot00000000000000unicode_parse_variables: { options = {} input: { var a = {}; a.你好 = 456; var ↂωↂ = 123; var l০ = 3; // 2nd char is a unicode digit } expect: { var a = {}; a.你好 = 456; var ↂωↂ = 123; var l০ = 3; } } unicode_escaped_identifier: { beautify = {ecma: 6} input: { var \u{61} = "foo"; var \u{10000} = "bar"; } expect_exact: 'var a="foo";var \u{10000}="bar";'; } unicode_identifier_ascii_only: { beautify = {ascii_only: true, ecma: 6} input: { var \u{0061} = "hi"; var bar = "h\u{0065}llo"; var \u{10000} = "testing \u{101111}"; } expect_exact: 'var a="hi";var bar="hello";var \\u{10000}="testing \\u{101111}";' } unicode_string_literals: { beautify = {ascii_only: true, ecma: 6} input: { var a = "6 length unicode character: \u{101111}"; } expect_exact: 'var a="6 length unicode character: \\u{101111}";' } check_escape_style: { beautify = {ascii_only: true, ecma: 6} input: { var a = "\x01"; var \ua0081 = "\x10"; // \u0081 only in ID_Continue var \u0100 = "\u0100"; var \u1000 = "\u1000"; var \u{10000} = "\u{10000}"; var \u{2f800} = "\u{100000}"; } expect_exact: 'var a="\\x01";var \\ua0081="\\x10";var \\u0100="\\u0100";var \\u1000="\\u1000";var \\u{10000}="\\u{10000}";var \\u{2f800}="\\u{100000}";' } ID_continue_with_surrogate_pair: { beautify = {ascii_only: true, ecma: 6} input: { var \u{2f800}\u{2f800}\u{2f800}\u{2f800} = "\u{100000}\u{100000}\u{100000}\u{100000}\u{100000}"; } expect_exact: 'var \\u{2f800}\\u{2f800}\\u{2f800}\\u{2f800}="\\u{100000}\\u{100000}\\u{100000}\\u{100000}\\u{100000}";' } escape_non_escaped_identifier: { beautify = {ascii_only: true, ecma: 6} input: { var µþ = "µþ"; } expect_exact: 'var \\u00b5\\u00fe="\\xb5\\xfe";' } non_escape_2_non_escape: { beautify = {ascii_only: false, ecma: 6} input: { var µþ = "µþ"; } expect_exact: 'var µþ="µþ";' } issue_2242_1: { beautify = { ascii_only: false, } input: { console.log("\ud83d", "\ude00", "\ud83d\ude00", "\ud83d@\ude00"); } expect_exact: 'console.log("\\ud83d","\\ude00","\ud83d\ude00","\\ud83d@\\ude00");' } issue_2242_2: { beautify = { ascii_only: true, } input: { console.log("\ud83d", "\ude00", "\ud83d\ude00", "\ud83d@\ude00"); } expect_exact: 'console.log("\\ud83d","\\ude00","\\ud83d\\ude00","\\ud83d@\\ude00");' } issue_2242_3: { options = { evaluate: false, } input: { console.log("\ud83d" + "\ude00", "\ud83d" + "@" + "\ude00"); } expect_exact: 'console.log("\\ud83d"+"\\ude00","\\ud83d"+"@"+"\\ude00");' } issue_2242_4: { options = { evaluate: true, } input: { console.log("\ud83d" + "\ude00", "\ud83d" + "@" + "\ude00"); } expect_exact: 'console.log("\ud83d\ude00","\\ud83d@\\ude00");' } issue_2569: { input: { new RegExp("[\udc42-\udcaa\udd74-\udd96\ude45-\ude4f\udea3-\udecc]"); } expect_exact: 'new RegExp("[\\udc42-\\udcaa\\udd74-\\udd96\\ude45-\\ude4f\\udea3-\\udecc]");' } issue_3271: { input: { function string2buf(str) { var i=0, buf = new Array(2), c = str.charCodeAt(0); if (c < 0x800) { /* two byte char */ buf[i++] = 0xC0 | (c >>> 6); buf[i++] = 0x80 | (c & 0x3f); } else { /* three byte char */ buf[i++] = 0xE0 | (c >>> 12); buf[i++] = 0x80 | (c >>> 6 & 0x3f); buf[i++] = 0x80 | (c & 0x3f); } return buf; }; console.log(string2buf("é")); } expect_stdout: "[ 195, 169 ]" } terser-4.1.2/test/compress/wrap_iife.js000066400000000000000000000016731351061312300201410ustar00rootroot00000000000000wrap_iife: { options = { negate_iife: false, } beautify = { wrap_iife: true, } input: { (function() { return function() { console.log('test') }; })()(); } expect_exact: '(function(){return function(){console.log("test")}})()();' } wrap_iife_in_expression: { options = { negate_iife: false, } beautify = { wrap_iife: true, } input: { foo = (function () { return bar(); })(); } expect_exact: 'foo=(function(){return bar()})();' } wrap_iife_in_return_call: { options = { negate_iife: false, } beautify = { wrap_iife: true, } input: { (function() { return (function() { console.log('test') })(); })()(); } expect_exact: '(function(){return(function(){console.log("test")})()})()();' } terser-4.1.2/test/compress/yield.js000066400000000000000000000144501351061312300172770ustar00rootroot00000000000000generators: { input: { function* fn() {}; } expect_exact: "function*fn(){}" } generators_yield: { input: { function* fn() { yield remote(); } } expect_exact: "function*fn(){yield remote()}" } generators_yield_assign: { input: { function* fn() { var x = {}; x.prop = yield 5; } } expect_exact: "function*fn(){var x={};x.prop=yield 5}" } generator_yield_undefined: { input: { function* fn() { yield; } } expect_exact: "function*fn(){yield}" } yield_optimize_expression: { options = { } input: { function* f1() { yield; } function* f2() { yield undefined; } function* f3() { yield null; } function* f4() { yield* undefined; } } expect: { function* f1() { yield } function* f2() { yield; } function* f3() { yield null; } function* f4() { yield* void 0; } } } yield_statements: { input: { function* fn() { var a = (yield 1) + (yield 2); var b = (yield 3) === (yield 4); var c = (yield 5) << (yield 6); var d = yield 7; var e = (yield 8) ? yield 9 : yield 10; var f = -(yield 11); } } expect_exact: "function*fn(){var a=(yield 1)+(yield 2);var b=(yield 3)===(yield 4);var c=(yield 5)<<(yield 6);var d=yield 7;var e=(yield 8)?yield 9:yield 10;var f=-(yield 11)}" } yield_as_identifier_in_function_in_generator: { input: { var g = function*() { function h() { yield = 1; } }; } expect: { var g = function*() { function h() { yield = 1; } }; } } yield_before_punctuators: { input: { iter = (function*() { assignmentResult = [ x = yield ] = value; })(); function* g1() { (yield) } function* g2() { [yield] } function* g3() { yield, yield; } function* g4() { (yield) ? yield : yield; } } expect: { iter = (function*() { assignmentResult = [ x = yield ] = value; })(); function* g1() { (yield) } function* g2() { [yield] } function* g3() { yield, yield; } function* g4() { (yield) ? yield : yield; } } } yield_as_identifier_outside_strict_mode: { input: { import yield from "bar"; yield = 123; while (true) { yield: for(;;) break yield; foo(); } while (true) yield: for(;;) continue yield; function yield(){} function foo(...yield){} try { new Error("") } catch (yield) {} var yield = "foo"; } expect: { import yield from "bar"; yield = 123; while (true) { yield: for(;;) break yield; foo(); } while (true) yield: for(;;) continue yield; function yield(){} function foo(...yield){} try { new Error("") } catch (yield) {} var yield = "foo"; } } empty_generator_as_parameter_with_side_effects: { options = { side_effects: true } input: { var GeneratorPrototype = Object.getPrototypeOf( Object.getPrototypeOf(function*() {}()) ); evaluate(GeneratorPrototype); } expect_exact: "var GeneratorPrototype=Object.getPrototypeOf(Object.getPrototypeOf(function*(){}()));evaluate(GeneratorPrototype);" } empty_generator_as_parameter_without_side_effects: { options = { side_effects: false } input: { var GeneratorPrototype = Object.getPrototypeOf( Object.getPrototypeOf(function*() {}()) ); evaluate(GeneratorPrototype); } expect_exact: "var GeneratorPrototype=Object.getPrototypeOf(Object.getPrototypeOf(function*(){}()));evaluate(GeneratorPrototype);" } yield_dot: { options = { } input: { function* foo(){ yield x.foo; (yield x).foo; yield (yield obj.foo()).bar(); } } expect_exact: "function*foo(){yield x.foo;(yield x).foo;yield(yield obj.foo()).bar()}" } yield_sub: { options = { } input: { function* foo(){ yield x['foo']; (yield x)['foo']; yield (yield obj.foo())['bar'](); } } expect_exact: 'function*foo(){yield x["foo"];(yield x)["foo"];yield(yield obj.foo())["bar"]()}' } yield_as_ES5_property: { input: { "use strict"; console.log({yield: 42}.yield); } expect_exact: '"use strict";console.log({yield:42}.yield);' expect_stdout: "42" } issue_2689: { options = { collapse_vars: true, unused: true, } input: { function* y() { var t = yield x(); return new t(); } } expect_exact: "function*y(){return new(yield x())}" } issue_2832: { beautify = { beautify: true, } input: { function* gen(i) { const result = yield (x = i, -x); var x; console.log(x); console.log(result); yield 2; } var x = gen(1); console.log(x.next("first").value); console.log(x.next("second").value); } expect_exact: [ "function* gen(i) {", " const result = yield (x = i, -x);", " var x;", " console.log(x);", " console.log(result);", " yield 2;", "}", "", "var x = gen(1);", "", 'console.log(x.next("first").value);', "", 'console.log(x.next("second").value);', ] expect_stdout: [ "-1", "1", "second", "2", ] } issue_t60: { options = { collapse_vars: true, side_effects: true, unused: true, } input: { function* t() { const v = yield 1; yield 2; return v; } var g = t(); console.log(g.next().value, g.next().value); } expect: { function* t() { const v = yield 1; yield 2; return v; } var g = t(); console.log(g.next().value, g.next().value); } expect_stdout: "1 2" } terser-4.1.2/test/fetch.js000066400000000000000000000015651351061312300154320ustar00rootroot00000000000000var fs = require("fs"); var parse = require("url").parse; var path = require("path"); try { fs.mkdirSync("./tmp"); } catch (e) { if (e.code != "EEXIST") throw e; } function local(url) { return path.join("./tmp", encodeURIComponent(url)); } function read(url) { return fs.createReadStream(local(url)); } module.exports = function(url, callback) { var result = read(url); result.on("error", function(e) { if (e.code != "ENOENT") return callback(e); var options = parse(url); options.rejectUnauthorized = false; require(options.protocol.slice(0, -1)).get(options, function(res) { if (res.statusCode !== 200) return callback(res.statusCode); res.pipe(fs.createWriteStream(local(url))); callback(null, res); }); }).on("open", function() { callback(null, result); }); }; terser-4.1.2/test/fuzz.js000077500000000000000000000030351351061312300153340ustar00rootroot00000000000000#! /usr/bin/env node /* eslint-env node */ var acorn = require("acorn"); var generateRandomJS = require("eslump").generateRandomJS; var minify = require("../dist/bundle.js").minify; var known_terser_errors = new RegExp([ "Cannot negate a statement", "Cannot read property 'references' of undefined", "Cannot read property 'value' of undefined", "Octal escape sequences are not allowed in template strings", "Parameter .* was used already", "redeclared", "argname.definition is not a function", "Unexpected token: template_substitution", "Unexpected yield identifier inside strict mode", ].join("|")); var known_acorn_errors = new RegExp([ "Argument name clash", "Comma is not permitted after the rest element", "Duplicate export", "Expecting Unicode escape sequence", "Export '.*' is not defined", "Identifier '.*' has already been declared", "Invalid regular expression: .* Unmatched", "Invalid regular expression: .* Unterminated group", "Octal literal in strict mode", "Unexpected token", "Unterminated regular expression", ].join("|")); while (true) { var input = generateRandomJS(); try { acorn.parse(input, { sourceType: "module", }); } catch (e) { if (!known_acorn_errors.test(e.message)) { var result = minify(input); if (!result.error) { console.log(input); throw e; } } continue; } var result = minify(input); if (result.error && !known_terser_errors.test(result.error.message)) { console.log(input); throw result.error; } } terser-4.1.2/test/input/000077500000000000000000000000001351061312300151335ustar00rootroot00000000000000terser-4.1.2/test/input/comments/000077500000000000000000000000001351061312300167605ustar00rootroot00000000000000terser-4.1.2/test/input/comments/filter.js000066400000000000000000000000341351061312300206000ustar00rootroot00000000000000// foo /*@preserve*/ // bar terser-4.1.2/test/input/config-file/000077500000000000000000000000001351061312300173155ustar00rootroot00000000000000terser-4.1.2/test/input/config-file/1.js000066400000000000000000000000261351061312300200110ustar00rootroot00000000000000console.log("First"); terser-4.1.2/test/input/config-file/2.js000066400000000000000000000000271351061312300200130ustar00rootroot00000000000000console.log("Second"); terser-4.1.2/test/input/config-file/cf.json000066400000000000000000000001201351061312300205710ustar00rootroot00000000000000{ "files": ["test/input/config-file/1.js", "test/input/config-file/2.js"] } terser-4.1.2/test/input/defaults/000077500000000000000000000000001351061312300167425ustar00rootroot00000000000000terser-4.1.2/test/input/defaults/input.js000066400000000000000000000000461351061312300204370ustar00rootroot00000000000000if (true) { console.log(1 + 2); } terser-4.1.2/test/input/enclose/000077500000000000000000000000001351061312300165635ustar00rootroot00000000000000terser-4.1.2/test/input/enclose/input.js000066400000000000000000000001031351061312300202520ustar00rootroot00000000000000function enclose() { console.log("test enclose"); } enclose(); terser-4.1.2/test/input/global_defs/000077500000000000000000000000001351061312300173745ustar00rootroot00000000000000terser-4.1.2/test/input/global_defs/nested.js000066400000000000000000000000271351061312300212130ustar00rootroot00000000000000console.log(C.V, C.D); terser-4.1.2/test/input/global_defs/simple.js000066400000000000000000000000201351061312300212130ustar00rootroot00000000000000console.log(D); terser-4.1.2/test/input/invalid/000077500000000000000000000000001351061312300165615ustar00rootroot00000000000000terser-4.1.2/test/input/invalid/assign_1.js000066400000000000000000000000271351061312300206220ustar00rootroot00000000000000console.log(1 || 5--); terser-4.1.2/test/input/invalid/assign_2.js000066400000000000000000000000501351061312300206170ustar00rootroot00000000000000console.log(2 || (Math.random() /= 2)); terser-4.1.2/test/input/invalid/assign_3.js000066400000000000000000000000321351061312300206200ustar00rootroot00000000000000console.log(3 || ++this); terser-4.1.2/test/input/invalid/assign_4.js000066400000000000000000000000071351061312300206230ustar00rootroot00000000000000++null terser-4.1.2/test/input/invalid/eof.js000066400000000000000000000000121351061312300176610ustar00rootroot00000000000000foo, bar( terser-4.1.2/test/input/invalid/loop-no-body.js000066400000000000000000000000351351061312300214330ustar00rootroot00000000000000for (var i = 0; i < 1; i++) terser-4.1.2/test/input/invalid/simple.js000066400000000000000000000000171351061312300204060ustar00rootroot00000000000000function f(a{} terser-4.1.2/test/input/invalid/tab.js000066400000000000000000000000231351061312300176600ustar00rootroot00000000000000 foo( xyz, 0abc); terser-4.1.2/test/input/issue-1236/000077500000000000000000000000001351061312300166545ustar00rootroot00000000000000terser-4.1.2/test/input/issue-1236/simple.js000066400000000000000000000002001351061312300204730ustar00rootroot00000000000000"use strict"; var foo = function foo(x) { return "foo " + x; }; console.log(foo("bar")); //# sourceMappingURL=simple.js.map terser-4.1.2/test/input/issue-1236/simple.js.map000066400000000000000000000004371351061312300212630ustar00rootroot00000000000000{ "version": 3, "sources": ["index.js"], "names": [], "mappings": ";;AAAA,IAAI,MAAM,SAAN,GAAM;AAAA,SAAK,SAAS,CAAd;AAAA,CAAV;AACA,QAAQ,GAAR,CAAY,IAAI,KAAJ,CAAZ", "file": "simple.js", "sourcesContent": ["let foo = x => \"foo \" + x;\nconsole.log(foo(\"bar\"));"] } terser-4.1.2/test/input/issue-1242/000077500000000000000000000000001351061312300166515ustar00rootroot00000000000000terser-4.1.2/test/input/issue-1242/bar.es5000066400000000000000000000001051351061312300200270ustar00rootroot00000000000000function bar(x) { var triple = x * (2 + 1); return triple; } terser-4.1.2/test/input/issue-1242/baz.es5000066400000000000000000000000731351061312300200430ustar00rootroot00000000000000function baz(x) { var half = x / 2; return half; } terser-4.1.2/test/input/issue-1242/foo.es5000066400000000000000000000001541351061312300200520ustar00rootroot00000000000000var print = console.log.bind(console); function foo(x) { var twice = x * 2; print('Foo:', twice); } terser-4.1.2/test/input/issue-1242/qux.js000066400000000000000000000001141351061312300200200ustar00rootroot00000000000000var x = bar(1+2); var y = baz(3+9); print('q' + 'u' + 'x', x, y); foo(5+6); terser-4.1.2/test/input/issue-1323/000077500000000000000000000000001351061312300166515ustar00rootroot00000000000000terser-4.1.2/test/input/issue-1323/sample.js000066400000000000000000000001421351061312300204650ustar00rootroot00000000000000var bar = (function () { function foo (bar) { return bar; } return foo; })();terser-4.1.2/test/input/issue-1431/000077500000000000000000000000001351061312300166515ustar00rootroot00000000000000terser-4.1.2/test/input/issue-1431/sample.js000066400000000000000000000003121351061312300204640ustar00rootroot00000000000000function f(x) { return function() { function n(a) { return a * a; } return x(n); }; } function g(op) { return op(1) + op(2); } console.log(f(g)() == 5);terser-4.1.2/test/input/issue-1482/000077500000000000000000000000001351061312300166575ustar00rootroot00000000000000terser-4.1.2/test/input/issue-1482/braces.js000066400000000000000000000014361351061312300204600ustar00rootroot00000000000000if (x) { foo(); } if (x) { foo(); } else { baz(); } if (x) { foo(); } else if (y) { bar(); } else { baz(); } if (x) { if (y) { foo(); } else { bar(); } } else { baz(); } if (x) { foo(); } else if (y) { bar(); } else if (z) { baz(); } else { moo(); } function f() { if (x) { foo(); } if (x) { foo(); } else { baz(); } if (x) { foo(); } else if (y) { bar(); } else { baz(); } if (x) { if (y) { foo(); } else { bar(); } } else { baz(); } if (x) { foo(); } else if (y) { bar(); } else if (z) { baz(); } else { moo(); } } terser-4.1.2/test/input/issue-1482/default.js000066400000000000000000000006561351061312300206500ustar00rootroot00000000000000if (x) foo(); if (x) foo(); else baz(); if (x) foo(); else if (y) bar(); else baz(); if (x) if (y) foo(); else bar(); else baz(); if (x) foo(); else if (y) bar(); else if (z) baz(); else moo(); function f() { if (x) foo(); if (x) foo(); else baz(); if (x) foo(); else if (y) bar(); else baz(); if (x) if (y) foo(); else bar(); else baz(); if (x) foo(); else if (y) bar(); else if (z) baz(); else moo(); } terser-4.1.2/test/input/issue-1482/input.js000066400000000000000000000006251351061312300203570ustar00rootroot00000000000000if (x) foo(); if (x) foo(); else baz(); if (x) foo(); else if (y) bar(); else baz(); if (x) if (y) foo(); else bar(); else baz(); if (x) foo(); else if (y) bar(); else if (z) baz(); else moo(); function f() { if (x) foo(); if (x) foo(); else baz(); if (x) foo(); else if (y) bar(); else baz(); if (x) if (y) foo(); else bar(); else baz(); if (x) foo(); else if (y) bar(); else if (z) baz(); else moo(); } terser-4.1.2/test/input/issue-1632/000077500000000000000000000000001351061312300166545ustar00rootroot00000000000000terser-4.1.2/test/input/issue-1632/^{foo}[bar](baz)+$.js000066400000000000000000000000171351061312300224330ustar00rootroot00000000000000console.log(x);terser-4.1.2/test/input/issue-2082/000077500000000000000000000000001351061312300166545ustar00rootroot00000000000000terser-4.1.2/test/input/issue-2082/sample.js000066400000000000000000000000171351061312300204710ustar00rootroot00000000000000console.log(x);terser-4.1.2/test/input/issue-2082/sample.js.map000066400000000000000000000000671351061312300212520ustar00rootroot00000000000000{"version": 3,"sources": ["index.js"],"mappings": ";"} terser-4.1.2/test/input/issue-2310/000077500000000000000000000000001351061312300166465ustar00rootroot00000000000000terser-4.1.2/test/input/issue-2310/input.js000066400000000000000000000002001351061312300203330ustar00rootroot00000000000000function foo() { return function() { console.log("PASS"); }; } (function() { var f = foo(); f(); })(); terser-4.1.2/test/input/issue-505/000077500000000000000000000000001351061312300165725ustar00rootroot00000000000000terser-4.1.2/test/input/issue-505/input.js000066400000000000000000000001461351061312300202700ustar00rootroot00000000000000function test(callback) { 'aaaaaaaaaaaaaaaa'; callback(err, data); callback(err, data); } terser-4.1.2/test/input/issue-505/output.js000066400000000000000000000004741351061312300204750ustar00rootroot00000000000000function test(a){ "aaaaaaaaaaaaaaaa" ;a(err,data),a(err,data) } //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIjAiXSwibmFtZXMiOlsidGVzdCIsImNhbGxiYWNrIiwiZXJyIiwiZGF0YSJdLCJtYXBwaW5ncyI6IkFBQUEsU0FBU0EsS0FBS0M7QUFDVjtDQUNBQSxFQUFTQyxJQUFLQyxNQUNkRixFQUFTQyxJQUFLQyJ9terser-4.1.2/test/input/issue-520/000077500000000000000000000000001351061312300165675ustar00rootroot00000000000000terser-4.1.2/test/input/issue-520/input.js000066400000000000000000000011241351061312300202620ustar00rootroot00000000000000var Foo = function Foo(){console.log(1+2);}; new Foo(); //# sourceMappingURL=data:application/json;charset=utf-8;base64,I/am/not/a/sourceMappingURL/but/a/comment //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjpudWxsLCJzb3VyY2VzIjpbInN0ZGluIl0sInNvdXJjZXNDb250ZW50IjpbImNsYXNzIEZvbyB7IGNvbnN0cnVjdG9yKCl7Y29uc29sZS5sb2coMSsyKTt9IH0gbmV3IEZvbygpO1xuIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLElBQU0sR0FBRyxHQUFDLEFBQUUsWUFBVyxFQUFFLENBQUMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFBLEFBQUUsQ0FBQyxJQUFJLEdBQUcsRUFBRSxDQUFDOyJ9 terser-4.1.2/test/input/issue-520/output.js000066400000000000000000000005251351061312300204670ustar00rootroot00000000000000new function(){console.log(3)}; //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIl0sIm5hbWVzIjpbImNvbnNvbGUiLCJsb2ciXSwibWFwcGluZ3MiOiJBQUErQyxJQUFyQyxXQUFnQkEsUUFBUUMsSUFBSSIsInNvdXJjZXNDb250ZW50IjpbImNsYXNzIEZvbyB7IGNvbnN0cnVjdG9yKCl7Y29uc29sZS5sb2coMSsyKTt9IH0gbmV3IEZvbygpO1xuIl19 terser-4.1.2/test/input/module/000077500000000000000000000000001351061312300164205ustar00rootroot00000000000000terser-4.1.2/test/input/module/input.js000066400000000000000000000000461351061312300201150ustar00rootroot00000000000000let foo = 1, bar = 2; export { foo }; terser-4.1.2/test/input/rename/000077500000000000000000000000001351061312300164025ustar00rootroot00000000000000terser-4.1.2/test/input/rename/input.js000066400000000000000000000001171351061312300200760ustar00rootroot00000000000000function f(x) { return g(x); function g(x) { return x; } } terser-4.1.2/test/input/source-maps/000077500000000000000000000000001351061312300173715ustar00rootroot00000000000000terser-4.1.2/test/input/source-maps/expect.js000066400000000000000000000012251351061312300212170ustar00rootroot00000000000000function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i null; () => {}; async function f() { } function*gen() { yield 1; yield* 2; } class Class extends Object { constructor(...args) { super.init(args); } foo() {} } x = class { static staticMethod() {} static get foo() {} static set bar(value) {} get x() {} set x(value) {} static() { // "static" can be a method name! } get() { // "get" can be a method name! } async set() { // "set" can be a method name! } *bar() {} static *baz() {} *['constructor']() {} static ['constructor']() {} [a]() {} "%"(){} } y = { get x() {}, set x(value) {}, bar() {}, *bar() {}, *['constructor']() {} } function f2 () { console.log(new.target); } console.log([10, ...[], 20, ...[30, 40], 50]["length"]); var { w: w1, ...V } = { w: 7, x: 1, y: 2 }; for (const x of y) {} async function f1() { await x; } ``; `x`; `x${1}`; String.raw`\n`; // arrow.js var foo = ([]) => "foo"; var bar = ({}) => "bar"; var with_default = (foo = "default") => foo; var object_with_default = ({foo = "default", bar: baz = "default"}) => foo; var array_after_spread = (...[foo]) => foo; var array_after_spread = (...{foo}) => foo; var computed = ({ [compute()]: x }) => {}; var array_hole = ([, , ...x] = [1, 2]) => {}; var object_trailing_elision = ({foo,}) => {}; var spread_empty_array = (...[]) => "foo"; var spread_empty_object = (...{}) => "foo"; // async.js async (x) => await x // destructuring.js var [aa, bb] = cc; var [aa, [bb, cc]] = dd; var [,[,,,,,],,,zz,] = xx; // Trailing comma var [,,zzz,,] = xxx; // Trailing comma after hole var {aa, bb} = {aa:1, bb:2}; var {aa, bb: {cc, dd}} = {aa:1, bb: {cc:2, dd: 3}}; for (const [x,y] in pairs); for (const [a] = 0;;); for (const {c} of cees); // object.js var a = { get, set: "foo", get bar() { return this.get; }, get 5() { return "five"; }, get 0xf55() { return "f five five"; }, get "five"() { return 5; }, set one(value) { this._one = value; }, set 9(value) { this._nine = value; }, set 0b1010(value) { this._ten = value; }, set "eleven"(value) { this._eleven = value; }, *"%"() { return 2; }, *["%"]() { return 2; }, [a]() {} }; // RegExp literals console.log(/rx/ig.test("RX")); /rx1/; /\/rx2\//ig; /\\rx3\\/ig; /[\\/]/ig; /[\\/]/; terser-4.1.2/test/jetstream.js000066400000000000000000000076541351061312300163440ustar00rootroot00000000000000#! /usr/bin/env node // -*- js -*- "use strict"; if (Number((/([0-9]+)\./.exec(process.version) || [])[1]) >= 8) { return; // TODO investigate what's making this fail } var site = "https://browserbench.org/JetStream"; if (typeof phantom == "undefined") { require("../tools/exit"); var args = process.argv.slice(2); var debug = args.indexOf("--debug"); if (debug >= 0) { args.splice(debug, 1); debug = true; } else { debug = false; } if (!args.length) { args.push("-mcb", "beautify=false,webkit"); } args.push("--timings"); var child_process = require("child_process"); var fetch = require("./fetch"); var http = require("http"); var server = http.createServer(function(request, response) { request.resume(); var url = site + request.url; fetch(url, function(err, res) { if (err) { if (typeof err != "number") throw err; response.writeHead(err); response.end(); } else { response.writeHead(200, { "Content-Type": { css: "text/css", js: "application/javascript", png: "image/png" }[url.slice(url.lastIndexOf(".") + 1)] || "text/html; charset=utf-8" }); if (/\.js$/.test(url)) { var stderr = ""; var uglifyjs = child_process.fork("bin/uglifyjs", args, { silent: true }).on("exit", function(code) { console.log("uglifyjs", url.slice(site.length + 1), args.join(" ")); console.log(stderr); if (code) throw new Error("uglifyjs failed with code " + code); }); uglifyjs.stderr.on("data", function(data) { stderr += data; }).setEncoding("utf8"); uglifyjs.stdout.pipe(response); res.pipe(uglifyjs.stdin); } else { res.pipe(response); } } }); }).listen(); server.on("listening", function() { var port = server.address().port; if (debug) { console.log("http://localhost:" + port + "/"); } else { child_process.exec("npm install phantomjs-prebuilt@2.1.14 --no-save", function(error) { if (error) throw error; var program = require("phantomjs-prebuilt").exec(process.argv[1], port); program.stdout.pipe(process.stdout); program.stderr.pipe(process.stderr); program.on("exit", function(code) { server.close(); if (code) throw new Error("JetStream failed!"); console.log("JetStream completed successfully."); process.exit(0); }); }); } }); server.timeout = 0; } else { var page = require("webpage").create(); page.onError = function(msg, trace) { var body = [ msg ]; if (trace) trace.forEach(function(t) { body.push(" " + (t.function || "Anonymous function") + " (" + t.file + ":" + t.line + ")"); }); console.error(body.join("\n")); phantom.exit(1); }; var url = "http://localhost:" + require("system").args[1] + "/"; page.onConsoleMessage = function(msg) { if (/Error:/i.test(msg)) { console.error(msg); phantom.exit(1); } console.log(msg); if (~msg.indexOf("Raw results:")) { phantom.exit(); } }; page.open(url, function(status) { if (status != "success") phantom.exit(1); page.evaluate(function() { JetStream.switchToQuick(); JetStream.start(); }); }); } terser-4.1.2/test/mocha.js000066400000000000000000000012541351061312300154230ustar00rootroot00000000000000var fs = require("fs"); var path = require("path"); // Instantiate a Mocha instance var Mocha = process.env.TRAVIS ? require("mocha") : require("mochallel"); var mocha = new Mocha({ timeout: 5000 }); var testDir = path.join(__dirname, "mocha"); // Add each .js file to the Mocha instance fs.readdirSync(testDir).filter(function(file) { return /\.js$/.test(file); }).forEach(function(file) { mocha.addFile(path.join(testDir, file)); }); module.exports = function() { mocha.run(function(failures) { if (failures) process.on("exit", function() { process.exit(failures); }); }); }; if (module.parent === null) { module.exports(); } terser-4.1.2/test/mocha/000077500000000000000000000000001351061312300150635ustar00rootroot00000000000000terser-4.1.2/test/mocha/arguments.js000066400000000000000000000356141351061312300174370ustar00rootroot00000000000000var assert = require("assert"); var UglifyJS = require("../.."); describe("arguments", function() { it("Should known that arguments in functions are local scoped", function() { var ast = UglifyJS.parse("var arguments; var f = function() {arguments.length}"); ast.figure_out_scope(); // Test scope of `var arguments` assert.strictEqual(ast.find_variable("arguments").global, true); // Select arguments symbol in function var symbol = ast.body[1].definitions[0].value.find_variable("arguments"); assert.strictEqual(symbol.global, false); assert.strictEqual(symbol.scope, ast. // From ast body[1]. // Select 2nd statement (equals to `var f ...`) definitions[0]. // First definition of selected statement value // Select function as scope ); }); it("Should recognize when a function uses arguments", function() { var ast = UglifyJS.parse("function a(){function b(){function c(){}; return arguments[0];}}"); ast.figure_out_scope(); assert.strictEqual(ast.body[0].uses_arguments, false); assert.strictEqual(ast.body[0].body[0].uses_arguments, true); assert.strictEqual(ast.body[0].body[0].body[0].uses_arguments, false); }); it("Should parse a function containing default assignment correctly", function() { var ast = UglifyJS.parse("function foo(a = 123) {}"); assert(ast.body[0] instanceof UglifyJS.AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // First argument assert(ast.body[0].argnames[0] instanceof UglifyJS.AST_DefaultAssign); assert(ast.body[0].argnames[0].left instanceof UglifyJS.AST_SymbolFunarg); assert.strictEqual(ast.body[0].argnames[0].operator, "="); assert(ast.body[0].argnames[0].right instanceof UglifyJS.AST_Number); ast = UglifyJS.parse("function foo(a = a) {}"); assert(ast.body[0] instanceof UglifyJS.AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // First argument assert(ast.body[0].argnames[0] instanceof UglifyJS.AST_DefaultAssign); assert(ast.body[0].argnames[0].left instanceof UglifyJS.AST_SymbolFunarg); assert.strictEqual(ast.body[0].argnames[0].operator, "="); assert(ast.body[0].argnames[0].right instanceof UglifyJS.AST_SymbolRef); }); it("Should parse a function containing default assignments in destructuring correctly", function() { var ast = UglifyJS.parse("function foo([a = 123]) {}"); assert(ast.body[0] instanceof UglifyJS.AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // First argument assert(ast.body[0].argnames[0] instanceof UglifyJS.AST_Destructuring); assert.strictEqual(ast.body[0].argnames[0].is_array, true); assert.strictEqual(ast.body[0].argnames[0].names.length, 1); assert(ast.body[0].argnames[0].names[0] instanceof UglifyJS.AST_DefaultAssign); assert(ast.body[0].argnames[0].names[0].left instanceof UglifyJS.AST_SymbolFunarg); assert.strictEqual(ast.body[0].argnames[0].names[0].operator, "="); assert(ast.body[0].argnames[0].names[0].right instanceof UglifyJS.AST_Number); ast = UglifyJS.parse("function foo({a = 123}) {}"); assert(ast.body[0] instanceof UglifyJS.AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // First argument assert(ast.body[0].argnames[0] instanceof UglifyJS.AST_Destructuring); assert.strictEqual(ast.body[0].argnames[0].is_array, false); assert.strictEqual(ast.body[0].argnames[0].names.length, 1); assert(ast.body[0].argnames[0].names[0] instanceof UglifyJS.AST_ObjectKeyVal); assert.strictEqual(ast.body[0].argnames[0].names[0].key, "a"); // Property a of first argument assert(ast.body[0].argnames[0].names[0].value instanceof UglifyJS.AST_DefaultAssign); assert(ast.body[0].argnames[0].names[0].value.left instanceof UglifyJS.AST_SymbolFunarg); assert.strictEqual(ast.body[0].argnames[0].names[0].value.operator, "="); assert(ast.body[0].argnames[0].names[0].value.right instanceof UglifyJS.AST_Number); ast = UglifyJS.parse("function foo({a: a = 123}) {}"); assert(ast.body[0] instanceof UglifyJS.AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // First argument assert(ast.body[0].argnames[0] instanceof UglifyJS.AST_Destructuring); assert.strictEqual(ast.body[0].argnames[0].is_array, false); assert.strictEqual(ast.body[0].argnames[0].names.length, 1); // Content destructuring of first argument assert(ast.body[0].argnames[0].names[0] instanceof UglifyJS.AST_ObjectKeyVal); assert.strictEqual(ast.body[0].argnames[0].names[0].key, "a"); assert(ast.body[0].argnames[0].names[0].value instanceof UglifyJS.AST_DefaultAssign); // Property a of first argument assert(ast.body[0].argnames[0].names[0].value instanceof UglifyJS.AST_DefaultAssign); assert(ast.body[0].argnames[0].names[0].value.left instanceof UglifyJS.AST_SymbolFunarg); assert.strictEqual(ast.body[0].argnames[0].names[0].value.operator, "="); assert(ast.body[0].argnames[0].names[0].value.right instanceof UglifyJS.AST_Number); }); it("Should parse a function containing default assignments in complex destructuring correctly", function() { var ast = UglifyJS.parse("function foo([a, [b = 123]]){}"); assert(ast.body[0] instanceof UglifyJS.AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // Check first argument assert(ast.body[0].argnames[0] instanceof UglifyJS.AST_Destructuring); assert.strictEqual(ast.body[0].argnames[0].is_array, true); assert.strictEqual(ast.body[0].argnames[0].names.length, 2); // Check whole destructuring structure of first argument assert(ast.body[0].argnames[0].names[0] instanceof UglifyJS.AST_SymbolFunarg); assert(ast.body[0].argnames[0].names[1] instanceof UglifyJS.AST_Destructuring); assert.strictEqual(ast.body[0].argnames[0].names[1].is_array, true); // Check content of second destructuring element (which is the nested destructuring pattern) assert(ast.body[0].argnames[0].names[1].names[0] instanceof UglifyJS.AST_DefaultAssign); assert(ast.body[0].argnames[0].names[1].names[0].left instanceof UglifyJS.AST_SymbolFunarg); assert.strictEqual(ast.body[0].argnames[0].names[1].names[0].operator, "="); assert(ast.body[0].argnames[0].names[1].names[0].right instanceof UglifyJS.AST_Number); ast = UglifyJS.parse("function foo([a, {b: c = 123}]){}"); assert(ast.body[0] instanceof UglifyJS.AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // Check first argument assert(ast.body[0].argnames[0] instanceof UglifyJS.AST_Destructuring); assert.strictEqual(ast.body[0].argnames[0].is_array, true); assert.strictEqual(ast.body[0].argnames[0].names.length, 2); // Check whole destructuring structure of first argument assert(ast.body[0].argnames[0].names[0] instanceof UglifyJS.AST_SymbolFunarg); assert(ast.body[0].argnames[0].names[1] instanceof UglifyJS.AST_Destructuring); assert.strictEqual(ast.body[0].argnames[0].names[1].is_array, false); // Check content of second destructuring element (which is the nested destructuring pattern) assert(ast.body[0].argnames[0].names[1].names[0] instanceof UglifyJS.AST_ObjectKeyVal); assert.strictEqual(ast.body[0].argnames[0].names[1].names[0].key, "b"); assert(ast.body[0].argnames[0].names[1].names[0].value instanceof UglifyJS.AST_DefaultAssign); // Property b of second argument assert(ast.body[0].argnames[0].names[1].names[0].value instanceof UglifyJS.AST_DefaultAssign); assert(ast.body[0].argnames[0].names[1].names[0].value.left instanceof UglifyJS.AST_SymbolFunarg); assert.strictEqual(ast.body[0].argnames[0].names[1].names[0].value.operator, "="); assert(ast.body[0].argnames[0].names[1].names[0].value.right instanceof UglifyJS.AST_Number); ast = UglifyJS.parse("function foo({a, b: {b = 123}}){}"); assert(ast.body[0] instanceof UglifyJS.AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // Check first argument assert(ast.body[0].argnames[0] instanceof UglifyJS.AST_Destructuring); assert.strictEqual(ast.body[0].argnames[0].is_array, false); assert.strictEqual(ast.body[0].argnames[0].names.length, 2); // Check whole destructuring structure of first argument assert(ast.body[0].argnames[0].names[0] instanceof UglifyJS.AST_ObjectKeyVal); assert.strictEqual(ast.body[0].argnames[0].names[0].key, "a"); assert(ast.body[0].argnames[0].names[0].value instanceof UglifyJS.AST_SymbolFunarg); assert(ast.body[0].argnames[0].names[1] instanceof UglifyJS.AST_ObjectKeyVal); assert.strictEqual(ast.body[0].argnames[0].names[1].key, "b"); assert(ast.body[0].argnames[0].names[1].value instanceof UglifyJS.AST_Destructuring); // Check content of nested destructuring in first parameter var content = ast.body[0].argnames[0].names[1].value assert.strictEqual(content.is_array, false); assert.strictEqual(content.names.length, 1); assert(content.names[0] instanceof UglifyJS.AST_ObjectKeyVal); assert.strictEqual(content.names[0].key, "b"); assert(content.names[0].value instanceof UglifyJS.AST_DefaultAssign); assert(content.names[0].value.left instanceof UglifyJS.AST_SymbolFunarg); assert.strictEqual(content.names[0].value.operator, "="); assert(content.names[0].value.right instanceof UglifyJS.AST_Number); ast = UglifyJS.parse("function foo({a: {b = 123}}){}"); assert(ast.body[0] instanceof UglifyJS.AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // Check first argument assert(ast.body[0].argnames[0] instanceof UglifyJS.AST_Destructuring); assert.strictEqual(ast.body[0].argnames[0].is_array, false); assert.strictEqual(ast.body[0].argnames[0].names.length, 1); // Check whole destructuring structure of first argument assert(ast.body[0].argnames[0].names[0] instanceof UglifyJS.AST_ObjectKeyVal); assert.strictEqual(ast.body[0].argnames[0].names[0].key, "a"); assert(ast.body[0].argnames[0].names[0].value instanceof UglifyJS.AST_Destructuring); // Check content of nested destructuring content = ast.body[0].argnames[0].names[0].value assert.strictEqual(content.is_array, false); assert.strictEqual(content.names.length, 1); assert(content.names[0] instanceof UglifyJS.AST_ObjectKeyVal); assert.strictEqual(content.names[0].key, "b"); assert(content.names[0].value instanceof UglifyJS.AST_DefaultAssign); assert(content.names[0].value.left instanceof UglifyJS.AST_SymbolFunarg); assert.strictEqual(content.names[0].value.operator, "="); assert(content.names[0].value.right instanceof UglifyJS.AST_Number); }); it("Should parse spread correctly", function() { var ast = UglifyJS.parse("function foo(a, b, ...c){}"); assert(ast.body[0] instanceof UglifyJS.AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 3); // Check parameters assert(ast.body[0].argnames[0] instanceof UglifyJS.AST_SymbolFunarg); assert(ast.body[0].argnames[1] instanceof UglifyJS.AST_SymbolFunarg); assert(ast.body[0].argnames[2] instanceof UglifyJS.AST_Expansion); assert(ast.body[0].argnames[2].expression instanceof UglifyJS.AST_SymbolFunarg); ast = UglifyJS.parse("function foo([a, b, ...c]){}"); assert(ast.body[0] instanceof UglifyJS.AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // Check first parameter assert(ast.body[0].argnames[0] instanceof UglifyJS.AST_Destructuring); assert.strictEqual(ast.body[0].argnames[0].is_array, true); // Check content first parameter assert(ast.body[0].argnames[0].names[0] instanceof UglifyJS.AST_SymbolFunarg); assert(ast.body[0].argnames[0].names[1] instanceof UglifyJS.AST_SymbolFunarg); assert(ast.body[0].argnames[0].names[2] instanceof UglifyJS.AST_Expansion); assert(ast.body[0].argnames[0].names[2].expression instanceof UglifyJS.AST_SymbolFunarg); ast = UglifyJS.parse("function foo([a, b, [c, ...d]]){}"); assert(ast.body[0] instanceof UglifyJS.AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // Check first parameter assert(ast.body[0].argnames[0] instanceof UglifyJS.AST_Destructuring); assert.strictEqual(ast.body[0].argnames[0].is_array, true); // Check content outer destructuring array assert(ast.body[0].argnames[0].names[0] instanceof UglifyJS.AST_SymbolFunarg); assert(ast.body[0].argnames[0].names[1] instanceof UglifyJS.AST_SymbolFunarg); assert(ast.body[0].argnames[0].names[2] instanceof UglifyJS.AST_Destructuring); assert.strictEqual(ast.body[0].argnames[0].names[2].is_array, true); // Check content nested destructuring array assert.strictEqual(ast.body[0].argnames[0].names[2].names.length, 2); assert(ast.body[0].argnames[0].names[2].names[0] instanceof UglifyJS.AST_SymbolFunarg); assert(ast.body[0].argnames[0].names[2].names[1] instanceof UglifyJS.AST_Expansion); assert(ast.body[0].argnames[0].names[2].names[1].expression instanceof UglifyJS.AST_SymbolFunarg); ast = UglifyJS.parse("function foo({a: [b, ...c]}){}"); assert(ast.body[0] instanceof UglifyJS.AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // Check first parameter assert(ast.body[0].argnames[0] instanceof UglifyJS.AST_Destructuring); assert.strictEqual(ast.body[0].argnames[0].is_array, false); // Check outer destructuring object assert.strictEqual(ast.body[0].argnames[0].names.length, 1); assert(ast.body[0].argnames[0].names[0] instanceof UglifyJS.AST_ObjectKeyVal); assert.strictEqual(ast.body[0].argnames[0].names[0].key, "a"); assert(ast.body[0].argnames[0].names[0].value instanceof UglifyJS.AST_Destructuring); assert.strictEqual(ast.body[0].argnames[0].names[0].value.is_array, true); // Check content nested destructuring array assert.strictEqual(ast.body[0].argnames[0].names[0].value.names.length, 2); assert(ast.body[0].argnames[0].names[0].value.names[0] instanceof UglifyJS.AST_SymbolFunarg); assert(ast.body[0].argnames[0].names[0].value.names[1] instanceof UglifyJS.AST_Expansion); assert(ast.body[0].argnames[0].names[0].value.names[1].expression instanceof UglifyJS.AST_SymbolFunarg); }); }); terser-4.1.2/test/mocha/arrow.js000066400000000000000000000557441351061312300165720ustar00rootroot00000000000000var assert = require("assert"); var uglify = require("../node"); describe("Arrow functions", function() { it.skip("Should not accept spread tokens on non-last parameters or without arguments parentheses", function() { var tests = [ "var a = ...a => {return a.join()}", "var b = (a, ...b, c) => { return a + b.join() + c}", "var c = (...a, b) => a.join()" ]; var test = function(code) { return function() { uglify.parse(code); }; }; var error = function(e) { return e instanceof uglify.JS_Parse_Error && e.message === "Unexpected token: expand (...)"; }; for (var i = 0; i < tests.length; i++) { assert.throws(test(tests[i]), error); } }); it("Should not accept holes in object binding patterns, while still allowing a trailing elision", function() { var tests = [ "f = ({, , ...x} = [1, 2]) => {};" ]; var test = function(code) { return function() { uglify.parse(code); }; }; var error = function(e) { return e instanceof uglify.JS_Parse_Error && e.message === "Unexpected token: punc (,)"; }; for (var i = 0; i < tests.length; i++) { assert.throws(test(tests[i]), error); } }); it("Should not accept newlines before arrow token", function() { var tests = [ "f = foo\n=> 'foo';", "f = (foo, bar)\n=> 'foo';", "f = ()\n=> 'foo';", "foo((bar)\n=>'baz';);" ]; var test = function(code) { return function() { uglify.parse(code); }; }; var error = function(e) { return e instanceof uglify.JS_Parse_Error && e.message === "Unexpected newline before arrow (=>)"; }; for (var i = 0; i < tests.length; i++) { assert.throws(test(tests[i]), error); } }); it("Should not accept arrow functions in the middle or end of an expression", function() { [ "0 + x => 0", "0 + async x => 0", "typeof x => 0", "typeof async x => 0", "typeof (x) => null", "typeof async (x) => null", ].forEach(function(code) { assert.throws(function() { uglify.parse(code); }, function(e) { return e instanceof uglify.JS_Parse_Error && /^Unexpected /.test(e.message); }, code); }); }); it("Should parse a function containing default assignment correctly", function() { var ast = uglify.parse("var a = (a = 123) => {}"); assert(ast.body[0] instanceof uglify.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof uglify.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof uglify.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof uglify.AST_Arrow); assert.strictEqual(ast.body[0].definitions[0].value.argnames.length, 1); // First argument assert(ast.body[0].definitions[0].value.argnames[0] instanceof uglify.AST_DefaultAssign); assert(ast.body[0].definitions[0].value.argnames[0].left instanceof uglify.AST_SymbolFunarg); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].operator, "="); assert(ast.body[0].definitions[0].value.argnames[0].right instanceof uglify.AST_Number); ast = uglify.parse("var a = (a = a) => {}"); assert(ast.body[0] instanceof uglify.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof uglify.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof uglify.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof uglify.AST_Arrow); assert.strictEqual(ast.body[0].definitions[0].value.argnames.length, 1); // First argument assert(ast.body[0].definitions[0].value.argnames[0] instanceof uglify.AST_DefaultAssign); assert(ast.body[0].definitions[0].value.argnames[0].left instanceof uglify.AST_SymbolFunarg); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].operator, "="); assert(ast.body[0].definitions[0].value.argnames[0].right instanceof uglify.AST_SymbolRef); }); it("Should parse a function containing default assignments in destructuring correctly", function() { var ast = uglify.parse("var a = ([a = 123]) => {}"); assert(ast.body[0] instanceof uglify.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof uglify.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof uglify.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof uglify.AST_Arrow); assert.strictEqual(ast.body[0].definitions[0].value.argnames.length, 1); // First argument assert(ast.body[0].definitions[0].value.argnames[0] instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].is_array, true); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names.length, 1); assert(ast.body[0].definitions[0].value.argnames[0].names[0] instanceof uglify.AST_DefaultAssign); assert(ast.body[0].definitions[0].value.argnames[0].names[0].left instanceof uglify.AST_SymbolFunarg); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names[0].operator, "="); assert(ast.body[0].definitions[0].value.argnames[0].names[0].right instanceof uglify.AST_Number); ast = uglify.parse("var a = ({a = 123}) => {}"); assert(ast.body[0] instanceof uglify.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof uglify.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof uglify.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof uglify.AST_Arrow); assert.strictEqual(ast.body[0].definitions[0].value.argnames.length, 1); // First argument assert(ast.body[0].definitions[0].value.argnames[0] instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].is_array, false); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names.length, 1); assert(ast.body[0].definitions[0].value.argnames[0].names[0] instanceof uglify.AST_ObjectKeyVal); // First object element in first argument assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names[0].key, "a"); assert(ast.body[0].definitions[0].value.argnames[0].names[0].value instanceof uglify.AST_DefaultAssign); assert(ast.body[0].definitions[0].value.argnames[0].names[0].value.left instanceof uglify.AST_SymbolFunarg); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names[0].value.operator, "="); assert(ast.body[0].definitions[0].value.argnames[0].names[0].value.right instanceof uglify.AST_Number); ast = uglify.parse("var a = ({a: a = 123}) => {}"); assert(ast.body[0] instanceof uglify.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof uglify.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof uglify.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof uglify.AST_Arrow); assert.strictEqual(ast.body[0].definitions[0].value.argnames.length, 1); // First argument assert(ast.body[0].definitions[0].value.argnames[0] instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].is_array, false); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names.length, 1); // Content destructuring of first argument assert(ast.body[0].definitions[0].value.argnames[0].names[0] instanceof uglify.AST_ObjectProperty); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names[0].key, "a"); assert(ast.body[0].definitions[0].value.argnames[0].names[0].value instanceof uglify.AST_DefaultAssign); assert(ast.body[0].definitions[0].value.argnames[0].names[0].value.left instanceof uglify.AST_SymbolFunarg); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names[0].value.operator, "="); assert(ast.body[0].definitions[0].value.argnames[0].names[0].value.right instanceof uglify.AST_Number); }); it("Should parse a function containing default assignments in complex destructuring correctly", function() { var ast = uglify.parse("var a = ([a, [b = 123]]) => {}"); assert(ast.body[0] instanceof uglify.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof uglify.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof uglify.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof uglify.AST_Arrow); assert.strictEqual(ast.body[0].definitions[0].value.argnames.length, 1); // Check first argument assert(ast.body[0].definitions[0].value.argnames[0] instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].is_array, true); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names.length, 2); // Check whole destructuring structure of first argument assert(ast.body[0].definitions[0].value.argnames[0].names[0] instanceof uglify.AST_SymbolFunarg); assert(ast.body[0].definitions[0].value.argnames[0].names[1] instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names[1].is_array, true); // Check content of second destructuring element (which is the nested destructuring pattern) assert(ast.body[0].definitions[0].value.argnames[0].names[1].names[0] instanceof uglify.AST_DefaultAssign); assert(ast.body[0].definitions[0].value.argnames[0].names[1].names[0].left instanceof uglify.AST_SymbolFunarg); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names[1].names[0].operator, "="); assert(ast.body[0].definitions[0].value.argnames[0].names[1].names[0].right instanceof uglify.AST_Number); ast = uglify.parse("var a = ([a, {b: c = 123}]) => {}"); assert(ast.body[0] instanceof uglify.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof uglify.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof uglify.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof uglify.AST_Arrow); assert.strictEqual(ast.body[0].definitions[0].value.argnames.length, 1); // Check first argument assert(ast.body[0].definitions[0].value.argnames[0] instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].is_array, true); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names.length, 2); // Check whole destructuring structure of first argument assert(ast.body[0].definitions[0].value.argnames[0].names[0] instanceof uglify.AST_SymbolFunarg); assert(ast.body[0].definitions[0].value.argnames[0].names[1] instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names[1].is_array, false); // Check content of second destructuring element (which is the nested destructuring pattern) assert(ast.body[0].definitions[0].value.argnames[0].names[1].names[0] instanceof uglify.AST_ObjectKeyVal); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names[1].names[0].key, "b"); assert(ast.body[0].definitions[0].value.argnames[0].names[1].names[0].value instanceof uglify.AST_DefaultAssign); assert(ast.body[0].definitions[0].value.argnames[0].names[1].names[0].value.left instanceof uglify.AST_SymbolFunarg); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names[1].names[0].value.operator, "="); assert(ast.body[0].definitions[0].value.argnames[0].names[1].names[0].value.right instanceof uglify.AST_Number); ast = uglify.parse("var a = ({a, b: {b = 123}}) => {}"); assert(ast.body[0] instanceof uglify.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof uglify.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof uglify.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof uglify.AST_Arrow); assert.strictEqual(ast.body[0].definitions[0].value.argnames.length, 1); // Check first argument assert(ast.body[0].definitions[0].value.argnames[0] instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].is_array, false); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names.length, 2); // First argument, property 1 assert(ast.body[0].definitions[0].value.argnames[0].names[0] instanceof uglify.AST_ObjectKeyVal); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names[0].key, "a"); assert(ast.body[0].definitions[0].value.argnames[0].names[0].value instanceof uglify.AST_SymbolFunarg); // First argument, property 2 assert(ast.body[0].definitions[0].value.argnames[0].names[1] instanceof uglify.AST_ObjectKeyVal); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names[1].key, "b"); assert(ast.body[0].definitions[0].value.argnames[0].names[1].value instanceof uglify.AST_Destructuring); // Check content of nested destructuring var content = ast.body[0].definitions[0].value.argnames[0].names[1].value; assert.strictEqual(content.is_array, false); assert.strictEqual(content.names.length, 1); assert(content.names[0] instanceof uglify.AST_ObjectKeyVal); // Content of first property in nested destructuring assert.strictEqual(content.names[0].key, "b"); assert(content.names[0].value instanceof uglify.AST_DefaultAssign); assert(content.names[0].value.left instanceof uglify.AST_SymbolFunarg); assert.strictEqual(content.names[0].value.operator, "="); assert(content.names[0].value.right instanceof uglify.AST_Number); ast = uglify.parse("var a = ({a: {b = 123}}) => {}"); assert(ast.body[0] instanceof uglify.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof uglify.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof uglify.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof uglify.AST_Arrow); assert.strictEqual(ast.body[0].definitions[0].value.argnames.length, 1); // Check first argument assert(ast.body[0].definitions[0].value.argnames[0] instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].is_array, false); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names.length, 1); // Check whole destructuring structure of first argument assert(ast.body[0].definitions[0].value.argnames[0].names[0] instanceof uglify.AST_ObjectKeyVal); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names[0].key, "a"); assert(ast.body[0].definitions[0].value.argnames[0].names[0].value instanceof uglify.AST_Destructuring); // Check content of nested destructuring content = ast.body[0].definitions[0].value.argnames[0].names[0].value; assert.strictEqual(content.is_array, false); assert.strictEqual(content.names.length, 1); assert(content.names[0] instanceof uglify.AST_ObjectKeyVal); // Check first property of nested destructuring assert.strictEqual(content.names[0].key, "b"); assert(content.names[0].value instanceof uglify.AST_DefaultAssign); assert(content.names[0].value.left instanceof uglify.AST_SymbolFunarg); assert.strictEqual(content.names[0].value.operator, "="); assert(content.names[0].value.right instanceof uglify.AST_Number); }); it("Should parse spread correctly", function() { var ast = uglify.parse("var a = (a, b, ...c) => {}"); assert(ast.body[0] instanceof uglify.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof uglify.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof uglify.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof uglify.AST_Arrow); assert.strictEqual(ast.body[0].definitions[0].value.argnames.length, 3); // Check parameters assert(ast.body[0].definitions[0].value.argnames[0] instanceof uglify.AST_SymbolFunarg); assert(ast.body[0].definitions[0].value.argnames[1] instanceof uglify.AST_SymbolFunarg); assert(ast.body[0].definitions[0].value.argnames[2] instanceof uglify.AST_Expansion); assert(ast.body[0].definitions[0].value.argnames[2].expression instanceof uglify.AST_SymbolFunarg); ast = uglify.parse("var a = ([a, b, ...c]) => {}"); assert(ast.body[0] instanceof uglify.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof uglify.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof uglify.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof uglify.AST_Arrow); assert.strictEqual(ast.body[0].definitions[0].value.argnames.length, 1); // Check first parameter assert(ast.body[0].definitions[0].value.argnames[0] instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].is_array, true); // Check content first parameter assert(ast.body[0].definitions[0].value.argnames[0].names[0] instanceof uglify.AST_SymbolFunarg); assert(ast.body[0].definitions[0].value.argnames[0].names[1] instanceof uglify.AST_SymbolFunarg); assert(ast.body[0].definitions[0].value.argnames[0].names[2] instanceof uglify.AST_Expansion); assert(ast.body[0].definitions[0].value.argnames[0].names[2].expression instanceof uglify.AST_SymbolFunarg); ast = uglify.parse("var a = ([a, b, [c, ...d]]) => {}"); assert(ast.body[0] instanceof uglify.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof uglify.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof uglify.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof uglify.AST_Arrow); assert.strictEqual(ast.body[0].definitions[0].value.argnames.length, 1); // Check first parameter assert(ast.body[0].definitions[0].value.argnames[0] instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].is_array, true); // Check content outer destructuring array assert(ast.body[0].definitions[0].value.argnames[0].names[0] instanceof uglify.AST_SymbolFunarg); assert(ast.body[0].definitions[0].value.argnames[0].names[1] instanceof uglify.AST_SymbolFunarg); assert(ast.body[0].definitions[0].value.argnames[0].names[2] instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names[2].is_array, true); // Check content nested destructuring array assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names[2].names.length, 2); assert(ast.body[0].definitions[0].value.argnames[0].names[2].names[0] instanceof uglify.AST_SymbolFunarg); assert(ast.body[0].definitions[0].value.argnames[0].names[2].names[1] instanceof uglify.AST_Expansion); assert(ast.body[0].definitions[0].value.argnames[0].names[2].names[1].expression instanceof uglify.AST_SymbolFunarg); ast = uglify.parse("var a = ({a: [b, ...c]}) => {}"); assert(ast.body[0] instanceof uglify.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof uglify.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof uglify.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof uglify.AST_Arrow); assert.strictEqual(ast.body[0].definitions[0].value.argnames.length, 1); // Check first parameter assert(ast.body[0].definitions[0].value.argnames[0] instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].is_array, false); // Check outer destructuring object assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names.length, 1); assert(ast.body[0].definitions[0].value.argnames[0].names[0] instanceof uglify.AST_ObjectKeyVal); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names[0].key, "a"); assert(ast.body[0].definitions[0].value.argnames[0].names[0].value instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names[0].value.is_array, true); // Check content nested destructuring array assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].names[0].value.names.length, 2); assert(ast.body[0].definitions[0].value.argnames[0].names[0].value.names[0] instanceof uglify.AST_SymbolFunarg); assert(ast.body[0].definitions[0].value.argnames[0].names[0].value.names[1] instanceof uglify.AST_Expansion); assert(ast.body[0].definitions[0].value.argnames[0].names[0].value.names[1].expression instanceof uglify.AST_SymbolFunarg); }); it("Should handle arrow function with bind", function() { function minify(code) { return uglify.minify(code, { mangle: false }).code; } assert.strictEqual( minify(minify("test(((index) => { console.log(this, index); }).bind(this, 1));")), "test((index=>{console.log(this,index)}).bind(this,1));" ); assert.strictEqual( minify(minify('test(((index) => { console.log(this, index); })["bind"](this, 1));')), "test((index=>{console.log(this,index)}).bind(this,1));" ); }); it("Should handle return of arrow function assignment", function() { function minify(code) { return uglify.minify(code, { mangle:false }).code; } assert.strictEqual( minify("export function foo(x) { bar = () => x; return 2};"), "export function foo(x){return bar=()=>x,2}" ); }); }); terser-4.1.2/test/mocha/builtins.js000066400000000000000000000030741351061312300172560ustar00rootroot00000000000000var UglifyJS = require("../../"); var assert = require("assert"); describe("builtins", function() { it ("Should not mangle builtins", function() { var test = "function foo(something){\n" + " return [Object,Array,Function,Number,String,Boolean,Error,Math,Date,RegExp,Symbol,Map,Promise,Proxy,Reflect,Set,WeakMap,WeakSet,Float32Array,something];\n" + "};"; var result = UglifyJS.minify(test, {parse: {bare_returns: true}}).code; assert.strictEqual(result.indexOf("something"), -1); assert.notEqual(result.indexOf("Object"), -1); assert.notEqual(result.indexOf("Array"), -1); assert.notEqual(result.indexOf("Function"), -1); assert.notEqual(result.indexOf("Number"), -1); assert.notEqual(result.indexOf("String"), -1); assert.notEqual(result.indexOf("Boolean"), -1); assert.notEqual(result.indexOf("Error"), -1); assert.notEqual(result.indexOf("Math"), -1); assert.notEqual(result.indexOf("Date"), -1); assert.notEqual(result.indexOf("RegExp"), -1); assert.notEqual(result.indexOf("Symbol"), -1); assert.notEqual(result.indexOf("Promise"), -1); assert.notEqual(result.indexOf("Proxy"), -1); assert.notEqual(result.indexOf("Reflect"), -1); assert.notEqual(result.indexOf("Set"), -1); assert.notEqual(result.indexOf("WeakMap"), -1); assert.notEqual(result.indexOf("WeakSet"), -1); assert.notEqual(result.indexOf("Map"), -1); assert.notEqual(result.indexOf("Float32Array"), -1); }); }); terser-4.1.2/test/mocha/class.js000066400000000000000000000036571351061312300165410ustar00rootroot00000000000000var assert = require("assert"); var uglify = require("../node"); describe("Class", function() { it("Should not accept spread on non-last parameters in methods", function() { var tests = [ "class foo { bar(...a, b) { return a.join(b) } }", "class foo { bar(a, b, ...c, d) { return c.join(a + b) + d } }", "class foo { *bar(...a, b) { return a.join(b) } }", "class foo { *bar(a, b, ...c, d) { return c.join(a + b) + d } }" ]; var test = function(code) { return function() { uglify.parse(code); } } var error = function(e) { return e instanceof uglify.JS_Parse_Error && /^Unexpected token: /.test(e.message); } for (var i = 0; i < tests.length; i++) { assert.throws(test(tests[i]), error); } }); it("Should return the correct token for class methods", function() { var tests = [ { code: "class foo{static test(){}}", token_value_start: "static", token_value_end: "}" }, { code: "class bar{*procedural(){}}", token_value_start: "*", token_value_end: "}" }, { code: "class foobar{aMethod(){}}", token_value_start: "aMethod", token_value_end: "}" }, { code: "class foobaz{get something(){}}", token_value_start: "get", token_value_end: "}" } ]; for (var i = 0; i < tests.length; i++) { var ast = uglify.parse(tests[i].code); assert.strictEqual(ast.body[0].properties[0].start.value, tests[i].token_value_start); assert.strictEqual(ast.body[0].properties[0].end.value, tests[i].token_value_end); } }); }); terser-4.1.2/test/mocha/cli-2.js000066400000000000000000000166021351061312300163340ustar00rootroot00000000000000var assert = require("assert"); var exec = require("child_process").exec; var readFileSync = require("fs").readFileSync; function read(path) { return readFileSync(path, "utf8"); } describe("bin/uglifyjs (2)", function() { var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs'; it("Should handle literal string as source map input", function(done) { var command = [ uglifyjscmd, "test/input/issue-1236/simple.js", "--source-map", 'content="' + read_map() + '",url=inline' ].join(" "); exec(command, function (err, stdout) { if (err) throw err; assert.strictEqual(stdout, [ '"use strict";var foo=function foo(x){return"foo "+x};console.log(foo("bar"));', "//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LmpzIl0sIm5hbWVzIjpbImZvbyIsIngiLCJjb25zb2xlIiwibG9nIl0sIm1hcHBpbmdzIjoiYUFBQSxJQUFJQSxJQUFNLFNBQU5BLElBQU1DLEdBQUEsTUFBSyxPQUFTQSxHQUN4QkMsUUFBUUMsSUFBSUgsSUFBSSJ9", "" ].join("\n")); done(); }); function read_map() { var map = JSON.parse(read("./test/input/issue-1236/simple.js.map")); delete map.sourcesContent; return JSON.stringify(map).replace(/"/g, '\\"'); } }); it("Should include function calls in source map", function(done) { var command = [ uglifyjscmd, "test/input/issue-2310/input.js", "-c", "--source-map", "url=inline", ].join(" "); exec(command, function(err, stdout, stderr) { if (err) throw err; assert.strictEqual(stdout, [ 'function foo(){return function(){console.log("PASS")}}foo()();', "//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvaW5wdXQvaXNzdWUtMjMxMC9pbnB1dC5qcyJdLCJuYW1lcyI6WyJmb28iLCJjb25zb2xlIiwibG9nIiwiZiJdLCJtYXBwaW5ncyI6IkFBQUEsU0FBU0EsTUFDTCxPQUFPLFdBQ0hDLFFBQVFDLElBQUksU0FLUkYsS0FDUkcifQ==", "" ].join("\n")); done(); }); }); it("Should dump AST as JSON", function(done) { var command = uglifyjscmd + " test/input/global_defs/simple.js -mco ast"; exec(command, function (err, stdout) { if (err) throw err; var ast = JSON.parse(stdout); assert.strictEqual(ast._class, "AST_Toplevel"); assert.ok(Array.isArray(ast.body)); done(); }); }); it("Should print supported options on invalid option syntax", function(done) { var command = uglifyjscmd + " test/input/comments/filter.js -b ascii-only"; exec(command, function (err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.ok(/^Supported options:\n[\s\S]*?\nERROR: `ascii-only` is not a supported option/.test(stderr), stderr); done(); }); }); it("Should work with --mangle reserved=[]", function(done) { var command = uglifyjscmd + " test/input/issue-505/input.js -m reserved=[callback]"; exec(command, function (err, stdout) { if (err) throw err; assert.strictEqual(stdout, 'function test(callback){"aaaaaaaaaaaaaaaa";callback(err,data);callback(err,data)}\n'); done(); }); }); it("Should work with --mangle reserved=false", function(done) { var command = uglifyjscmd + " test/input/issue-505/input.js -m reserved=false"; exec(command, function (err, stdout) { if (err) throw err; assert.strictEqual(stdout, 'function test(a){"aaaaaaaaaaaaaaaa";a(err,data);a(err,data)}\n'); done(); }); }); it("Should fail with --mangle-props reserved=[in]", function(done) { var command = uglifyjscmd + " test/input/issue-505/input.js --mangle-props reserved=[in]"; exec(command, function (err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.ok(/^Supported options:\n[\s\S]*?\nERROR: `reserved=\[in]` is not a supported option/.test(stderr), stderr); done(); }); }); it("Should mangle toplevel names with the --module option", function(done) { var command = uglifyjscmd + " test/input/module/input.js --module -mc"; exec(command, function (err, stdout, stderr) { if (err) throw err; assert.strictEqual(stdout, "let e=1;export{e as foo};\n") done(); }); }); it("Should fail with --define a-b", function(done) { var command = uglifyjscmd + " test/input/issue-505/input.js --define a-b"; exec(command, function (err, stdout, stderr) { assert.ok(err); assert.strictEqual(stdout, ""); assert.strictEqual(stderr, "Error parsing arguments for 'define': a-b\n"); done(); }); }); it("Should work with -c defaults=false,conditionals", function(done) { var command = uglifyjscmd + " test/input/defaults/input.js -c defaults=false,conditionals"; exec(command, function(err, stdout, stderr) { if (err) throw err; assert.strictEqual(stdout, 'true&&console.log(1+2);\n'); done(); }); }); it("Should work with --enclose", function(done) { var command = uglifyjscmd + " test/input/enclose/input.js --enclose"; exec(command, function(err, stdout, stderr) { if (err) throw err; assert.strictEqual(stdout, '(function(){function enclose(){console.log("test enclose")}enclose()})();\n'); done(); }); }); it("Should work with --enclose arg", function(done) { var command = uglifyjscmd + " test/input/enclose/input.js --enclose undefined"; exec(command, function(err, stdout, stderr) { if (err) throw err; assert.strictEqual(stdout, '(function(undefined){function enclose(){console.log("test enclose")}enclose()})();\n'); done(); }); }); it("Should work with --enclose arg:value", function(done) { var command = uglifyjscmd + " test/input/enclose/input.js --enclose window,undefined:window"; exec(command, function(err, stdout, stderr) { if (err) throw err; assert.strictEqual(stdout, '(function(window,undefined){function enclose(){console.log("test enclose")}enclose()})(window);\n'); done(); }); }); it("Should work with --enclose & --wrap", function(done) { var command = uglifyjscmd + " test/input/enclose/input.js --enclose window,undefined:window --wrap exports"; exec(command, function(err, stdout, stderr) { if (err) throw err; assert.strictEqual(stdout, '(function(window,undefined){(function(exports){function enclose(){console.log("test enclose")}enclose()})(typeof exports=="undefined"?exports={}:exports)})(window);\n'); done(); }); }); it("should read files list from config file", (done) => { var command = uglifyjscmd + " --config-file test/input/config-file/cf.json"; exec(command, function(err, stdout, stderr) { if (err) throw err; assert.strictEqual(stdout, 'console.log("First"),console.log("Second");\n'); done(); }); }); }); terser-4.1.2/test/mocha/cli.js000066400000000000000000000255621351061312300162020ustar00rootroot00000000000000var assert = require("assert"); var exec = require("child_process").exec; var execSync = require("child_process").execSync; var fs = require("fs"); var {assertCodeWithInlineMapEquals} = require("./utils"); function read(path) { return fs.readFileSync(path, "utf8"); } describe("bin/uglifyjs", function() { var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs'; it("Should be able to filter comments correctly with `--comments all`", function (done) { var command = uglifyjscmd + ' test/input/comments/filter.js --comments all'; exec(command, function (err, stdout) { if (err) throw err; assert.strictEqual(stdout, "// foo\n/*@preserve*/\n// bar\n\n"); done(); }); }); it("Should be able to filter comments correctly with `--comment `", function (done) { this.timeout(10 * 1000); var command = uglifyjscmd + ' test/input/comments/filter.js --comments /r/'; exec(command, function (err, stdout) { if (err) throw err; assert.strictEqual(stdout, "/*@preserve*/\n// bar\n\n"); done(); }); }); it("Should be able to filter comments correctly with just `--comment`", function (done) { var command = uglifyjscmd + ' test/input/comments/filter.js --comments'; exec(command, function (err, stdout) { if (err) throw err; assert.strictEqual(stdout, "/*@preserve*/\n\n"); done(); }); }); it("Should append source map to output when using --source-map url=inline", function (done) { var command = uglifyjscmd + " test/input/issue-1323/sample.js --source-map url=inline"; exec(command, function (err, stdout) { if (err) throw err; assertCodeWithInlineMapEquals(stdout, "var bar=function(){function foo(bar){return bar}return foo}();\n" + "//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvaW5wdXQvaXNzdWUtMTMyMy9zYW1wbGUuanMiXSwibmFtZXMiOlsiYmFyIiwiZm9vIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFJQSxJQUFNLFdBQ04sU0FBU0MsSUFBS0QsS0FDVixPQUFPQSxJQUdYLE9BQU9DLElBTEQifQ==\n"); done(); }); }); it("Should not append source map to output when not using --source-map url=inline", function (done) { var command = uglifyjscmd + ' test/input/issue-1323/sample.js'; exec(command, function (err, stdout) { if (err) throw err; assert.strictEqual(stdout, "var bar=function(){function foo(bar){return bar}return foo}();\n"); done(); }); }); it("Should not load source map before finish reading from STDIN", function(done) { var mapFile = "tmp/input.js.map"; try { fs.mkdirSync("./tmp"); } catch (e) { if (e.code != "EEXIST") throw e; } try { fs.unlinkSync(mapFile); } catch (e) { if (e.code != "ENOENT") throw e; } var command = [ uglifyjscmd, "--source-map", "content=" + mapFile, "--source-map", "url=inline" ].join(" "); var child = exec(command, function(err, stdout) { if (err) throw err; assert.strictEqual(stdout, read("test/input/source-maps/expect.js")); done(); }); setTimeout(function() { fs.writeFileSync(mapFile, read("test/input/source-maps/input.js.map")); child.stdin.end(read("test/input/source-maps/input.js")); }, 1000); }); it("Should work with --keep-fnames (mangle only)", function (done) { var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fnames -m'; exec(command, function (err, stdout) { if (err) throw err; assert.strictEqual(stdout, "function f(r){return function(){function n(n){return n*n}return r(n)}}function g(n){return n(1)+n(2)}console.log(f(g)()==5);\n"); done(); }); }); it("Should work with --keep-fnames (mangle & compress)", function (done) { var command = uglifyjscmd + ' test/input/issue-1431/sample.js --keep-fnames -m -c unused=false'; exec(command, function (err, stdout) { if (err) throw err; assert.strictEqual(stdout, "function f(r){return function(){function n(n){return n*n}return r(n)}}function g(n){return n(1)+n(2)}console.log(5==f(g)());\n"); done(); }); }); it("Should work with keep_fnames under mangler options", function (done) { var command = uglifyjscmd + ' test/input/issue-1431/sample.js -m keep_fnames=true'; exec(command, function (err, stdout) { if (err) throw err; assert.strictEqual(stdout, "function f(r){return function(){function n(n){return n*n}return r(n)}}function g(n){return n(1)+n(2)}console.log(f(g)()==5);\n"); done(); }); }); it("Should work with --define (simple)", function (done) { var command = uglifyjscmd + ' test/input/global_defs/simple.js --define D=5 -c'; exec(command, function (err, stdout) { if (err) throw err; assert.strictEqual(stdout, "console.log(5);\n"); done(); }); }); it("Should work with --define (nested)", function (done) { var command = uglifyjscmd + ' test/input/global_defs/nested.js --define C.D=5,C.V=3 -c'; exec(command, function (err, stdout) { if (err) throw err; assert.strictEqual(stdout, "console.log(3,5);\n"); done(); }); }); it("Should work with --define (AST_Node)", function (done) { var command = uglifyjscmd + ' test/input/global_defs/simple.js --define console.log=stdout.println -c'; exec(command, function (err, stdout) { if (err) throw err; assert.strictEqual(stdout, "stdout.println(D);\n"); done(); }); }); it("Should work with `--beautify`", function (done) { var command = uglifyjscmd + ' test/input/issue-1482/input.js -b'; exec(command, function (err, stdout) { if (err) throw err; assert.strictEqual(stdout, read("test/input/issue-1482/default.js")); done(); }); }); it("Should work with `--beautify braces`", function (done) { var command = uglifyjscmd + ' test/input/issue-1482/input.js -b braces'; exec(command, function (err, stdout) { if (err) throw err; assert.strictEqual(stdout, read("test/input/issue-1482/braces.js")); done(); }); }); it("Should process inline source map", function(done) { var command = uglifyjscmd + " test/input/issue-520/input.js -mc toplevel --source-map content=inline,url=inline"; exec(command, function (err, stdout) { if (err) throw err; assertCodeWithInlineMapEquals(stdout, read("test/input/issue-520/output.js")); done(); }); }); it("Should warn for missing inline source map", function(done) { var command = uglifyjscmd + " test/input/issue-1323/sample.js --source-map content=inline,url=inline"; exec(command, function (err, stdout, stderr) { if (err) throw err; assertCodeWithInlineMapEquals(stdout, [ "var bar=function(){function foo(bar){return bar}return foo}();", "//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvaW5wdXQvaXNzdWUtMTMyMy9zYW1wbGUuanMiXSwibmFtZXMiOlsiYmFyIiwiZm9vIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFJQSxJQUFNLFdBQ04sU0FBU0MsSUFBS0QsS0FDVixPQUFPQSxJQUdYLE9BQU9DLElBTEQifQ==", "", ].join("\n")); assert.strictEqual(stderr, "WARN: inline source map not found\n"); done(); }); }); it("Should fail with multiple input and inline source map", function(done) { this.timeout(60000); var command = uglifyjscmd + " test/input/issue-520/input.js test/input/issue-520/output.js --source-map content=inline,url=inline"; exec(command, function (err, stdout, stderr) { assert.ok(err); assert.strictEqual(stderr.split(/\n/)[0], "ERROR: inline source map only works with singular input"); done(); }); }); it("Should fail with acorn and inline source map", function(done) { var command = uglifyjscmd + " test/input/issue-520/input.js --source-map content=inline,url=inline -p acorn"; exec(command, function (err, stdout, stderr) { assert.ok(err); assert.strictEqual(stderr, "ERROR: inline source map only works with built-in parser\n"); done(); }); }); it("Should fail with SpiderMonkey and inline source map", function(done) { var command = uglifyjscmd + " test/input/issue-520/input.js --source-map content=inline,url=inline -p spidermonkey"; exec(command, function (err, stdout, stderr) { assert.ok(err); assert.strictEqual(stderr, "ERROR: inline source map only works with built-in parser\n"); done(); }); }); it("Should fail with invalid syntax", function(done) { var command = uglifyjscmd + ' test/input/invalid/simple.js'; exec(command, function (err, stdout, stderr) { assert.ok(err); var lines = stderr.split(/\n/); assert.strictEqual(lines[0], "Parse error at test/input/invalid/simple.js:1,12"); assert.strictEqual(lines[1], "function f(a{}"); assert.strictEqual(lines[2], " ^"); assert.strictEqual(lines[3], "ERROR: Unexpected token punc «{», expected punc «,»"); done(); }); }); it("Should fail with correct marking of tabs", function(done) { var command = uglifyjscmd + ' test/input/invalid/tab.js'; exec(command, function (err, stdout, stderr) { assert.ok(err); var lines = stderr.split(/\n/); assert.strictEqual(lines[0], "Parse error at test/input/invalid/tab.js:1,12"); assert.strictEqual(lines[1], "\t\tfoo(\txyz, 0abc);"); assert.strictEqual(lines[2], "\t\t \t ^"); assert.strictEqual(lines[3], "ERROR: Invalid syntax: 0abc"); done(); }); }); it("Should fail with correct marking at start of line", function(done) { var command = uglifyjscmd + ' test/input/invalid/eof.js'; exec(command, function (err, stdout, stderr) { assert.ok(err); var lines = stderr.split(/\n/); assert.strictEqual(lines[0], "Parse error at test/input/invalid/eof.js:2,0"); assert.strictEqual(lines[1], "foo, bar("); assert.strictEqual(lines[2], " ^"); assert.strictEqual(lines[3], "ERROR: Unexpected token: eof (undefined)"); done(); }); }); }); terser-4.1.2/test/mocha/comments.js000066400000000000000000000332441351061312300172540ustar00rootroot00000000000000var assert = require("assert"); var UglifyJS = require("../node"); describe("comments", function() { it("Should recognize eol of single line comments", function() { var tests = [ "//Some comment 1\n>", "//Some comment 2\r>", "//Some comment 3\r\n>", "//Some comment 4\u2028>", "//Some comment 5\u2029>" ]; var fail = function(e) { return e instanceof UglifyJS.JS_Parse_Error && e.message === "Unexpected token: operator (>)" && e.line === 2 && e.col === 0; } for (var i = 0; i < tests.length; i++) { assert.throws(function() { UglifyJS.parse(tests[i]); }, fail, tests[i]); } }); it("Should update the position of a multiline comment correctly", function() { var tests = [ "/*Some comment 1\n\n\n*/\n>\n\n\n\n\n\n", "/*Some comment 2\r\n\r\n\r\n*/\r\n>\n\n\n\n\n\n", "/*Some comment 3\r\r\r*/\r>\n\n\n\n\n\n", "/*Some comment 4\u2028\u2028\u2028*/\u2028>\n\n\n\n\n\n", "/*Some comment 5\u2029\u2029\u2029*/\u2029>\n\n\n\n\n\n" ]; var fail = function(e) { return e instanceof UglifyJS.JS_Parse_Error && e.message === "Unexpected token: operator (>)" && e.line === 5 && e.col === 0; } for (var i = 0; i < tests.length; i++) { assert.throws(function() { UglifyJS.parse(tests[i]); }, fail, tests[i]); } }); it("Should handle comment within return correctly", function() { var result = UglifyJS.minify([ "function unequal(x, y) {", " return (", " // Either one", " x < y", " ||", " y < x", " );", "}", ].join("\n"), { compress: false, mangle: false, output: { beautify: true, comments: "all", }, }); if (result.error) throw result.error; assert.strictEqual(result.code, [ "function unequal(x, y) {", " // Either one", " return x < y || y < x;", "}", ].join("\n")); }); it("Should handle comment folded into return correctly", function() { var result = UglifyJS.minify([ "function f() {", " /* boo */ x();", " return y();", "}", ].join("\n"), { mangle: false, output: { beautify: true, comments: "all", }, }); if (result.error) throw result.error; assert.strictEqual(result.code, [ "function f() {", " /* boo */", " return x(), y();", "}", ].join("\n")); }); it("Should not drop comments after first OutputStream", function() { var code = "/* boo */\nx();"; var ast = UglifyJS.parse(code); var out1 = UglifyJS.OutputStream({ beautify: true, comments: "all", }); ast.print(out1); var out2 = UglifyJS.OutputStream({ beautify: true, comments: "all", }); ast.print(out2); assert.strictEqual(out1.get(), code); assert.strictEqual(out2.get(), out1.get()); }); it("Should retain trailing comments", function() { var code = [ "if (foo /* lost comment */ && bar /* lost comment */) {", " // this one is kept", " {/* lost comment */}", " !function() {", " // lost comment", " }();", " function baz() {/* lost comment */}", " // lost comment", "}", "// comments right before EOF are lost as well", ].join("\n"); var result = UglifyJS.minify(code, { compress: false, mangle: false, output: { beautify: true, comments: "all", }, }); if (result.error) throw result.error; assert.strictEqual(result.code, code); }); it("Should retain comments within braces", function() { var code = [ "{/* foo */}", "a({/* foo */});", "while (a) {/* foo */}", "switch (a) {/* foo */}", "if (a) {/* foo */} else {/* bar */}", ].join("\n\n"); var result = UglifyJS.minify(code, { compress: false, mangle: false, output: { beautify: true, comments: "all", }, }); if (result.error) throw result.error; assert.strictEqual(result.code, code); }); it("Should correctly preserve new lines around comments", function() { var tests = [ [ "// foo", "// bar", "x();", ].join("\n"), [ "// foo", "/* bar */", "x();", ].join("\n"), [ "// foo", "/* bar */ x();", ].join("\n"), [ "/* foo */", "// bar", "x();", ].join("\n"), [ "/* foo */ // bar", "x();", ].join("\n"), [ "/* foo */", "/* bar */", "x();", ].join("\n"), [ "/* foo */", "/* bar */ x();", ].join("\n"), [ "/* foo */ /* bar */", "x();", ].join("\n"), "/* foo */ /* bar */ x();", ].forEach(function(code) { var result = UglifyJS.minify(code, { compress: false, mangle: false, output: { beautify: true, comments: "all", }, }); if (result.error) throw result.error; assert.strictEqual(result.code, code); }); }); it("Should preserve new line before comment without beautify", function() { var code = [ "function f(){", "/* foo */bar()}", ].join("\n"); var result = UglifyJS.minify(code, { compress: false, mangle: false, output: { comments: "all", }, }); if (result.error) throw result.error; assert.strictEqual(result.code, code); }); it("Should preserve comments around IIFE", function() { var result = UglifyJS.minify("/*a*/(/*b*/function(){/*c*/}/*d*/)/*e*/();", { compress: false, mangle: false, output: { comments: "all", }, }); if (result.error) throw result.error; assert.strictEqual(result.code, "/*a*/ /*b*/(function(){/*c*/}/*d*/ /*e*/)();"); }); it("Should output line comments after statements", function() { var result = UglifyJS.minify([ "x()//foo", "{y()//bar", "}", ].join("\n"), { compress: false, mangle: false, output: { comments: "all", }, }); if (result.error) throw result.error; assert.strictEqual(result.code, [ "x();//foo", "{y();//bar", "}", ].join("\n")); }); describe("comment before constant", function() { var js = 'function f() { /*c1*/ var /*c2*/ foo = /*c3*/ false; return foo; }'; it("Should test comment before constant is retained and output after mangle.", function() { var result = UglifyJS.minify(js, { compress: { collapse_vars: false, reduce_vars: false }, output: { comments: true }, }); assert.strictEqual(result.code, 'function f(){/*c1*/var/*c2*/n=/*c3*/!1;return n}'); }); it("Should test code works when comments disabled.", function() { var result = UglifyJS.minify(js, { compress: { collapse_vars: false, reduce_vars: false }, output: { comments: false }, }); assert.strictEqual(result.code, 'function f(){var n=!1;return n}'); }); }); describe("comment filters", function() { it("Should be able to filter comments by passing regexp", function() { var ast = UglifyJS.parse("/*!test1*/\n/*test2*/\n//!test3\n//test4\ntest7\n-->!test8"); assert.strictEqual(ast.print_to_string({comments: /^!/}), "/*!test1*/\n//!test3\n//!test6\n//!test8\n"); }); it("Should be able to filter comments with the 'all' option", function() { var ast = UglifyJS.parse("/*!test1*/\n/*test2*/\n//!test3\n//test4\ntest7\n-->!test8"); assert.strictEqual(ast.print_to_string({comments: "all"}), "/*!test1*/\n/*test2*/\n//!test3\n//test4\n//test5\n//!test6\n//test7\n//!test8\n"); }); it("Should be able to filter commments with the 'some' option", function() { var ast = UglifyJS.parse("// foo\n/*@preserve*/\n// bar\n/*@license*/\n//@license with the wrong comment type\n/*@cc_on something*/"); assert.strictEqual(ast.print_to_string({comments: "some"}), "/*@preserve*/\n/*@license*/\n/*@cc_on something*/"); }); it("Should be able to filter comments by passing a function", function() { var ast = UglifyJS.parse("/*TEST 123*/\n//An other comment\n//8 chars."); var f = function(node, comment) { return comment.value.length === 8; }; assert.strictEqual(ast.print_to_string({comments: f}), "/*TEST 123*/\n//8 chars.\n"); }); it("Should be able to filter comments by passing regex in string format", function() { var ast = UglifyJS.parse("/*!test1*/\n/*test2*/\n//!test3\n//test4\ntest7\n-->!test8"); assert.strictEqual(ast.print_to_string({comments: "/^!/"}), "/*!test1*/\n//!test3\n//!test6\n//!test8\n"); }); it("Should be able to get the comment and comment type when using a function", function() { var ast = UglifyJS.parse("/*!test1*/\n/*test2*/\n//!test3\n//test4\ntest7\n-->!test8"); var f = function(node, comment) { return comment.type == "comment1" || comment.type == "comment3"; }; assert.strictEqual(ast.print_to_string({comments: f}), "//!test3\n//test4\n//test5\n//!test6\n"); }); it("Should be able to filter comments by passing a boolean", function() { var ast = UglifyJS.parse("/*!test1*/\n/*test2*/\n//!test3\n//test4\ntest7\n-->!test8"); assert.strictEqual(ast.print_to_string({comments: true}), "/*!test1*/\n/*test2*/\n//!test3\n//test4\n//test5\n//!test6\n//test7\n//!test8\n"); assert.strictEqual(ast.print_to_string({comments: false}), ""); }); it("Should never be able to filter comment5 (shebangs)", function() { var ast = UglifyJS.parse("#!Random comment\n//test1\n/*test2*/"); var f = function(node, comment) { assert.strictEqual(comment.type === "comment5", false); return true; }; assert.strictEqual(ast.print_to_string({comments: f}), "#!Random comment\n//test1\n/*test2*/"); }); it("Should never be able to filter comment5 when using 'some' as filter", function() { var ast = UglifyJS.parse("#!foo\n//foo\n/*@preserve*/\n/* please hide me */"); assert.strictEqual(ast.print_to_string({comments: "some"}), "#!foo\n/*@preserve*/"); }); it("Should have no problem on multiple calls", function() { const options = { comments: /ok/ }; assert.strictEqual(UglifyJS.parse("/* ok */ function a(){}").print_to_string(options), "/* ok */function a(){}"); assert.strictEqual(UglifyJS.parse("/* ok */ function a(){}").print_to_string(options), "/* ok */function a(){}"); assert.strictEqual(UglifyJS.parse("/* ok */ function a(){}").print_to_string(options), "/* ok */function a(){}"); }); it("Should handle shebang and preamble correctly", function() { var code = UglifyJS.minify("#!/usr/bin/node\nvar x = 10;", { output: { preamble: "/* Build */" } }).code; assert.strictEqual(code, "#!/usr/bin/node\n/* Build */\nvar x=10;"); }); it("Should handle preamble without shebang correctly", function() { var code = UglifyJS.minify("var x = 10;", { output: { preamble: "/* Build */" } }).code; assert.strictEqual(code, "/* Build */\nvar x=10;"); }); }); describe("Huge number of comments.", function() { it("Should parse and compress code with thousands of consecutive comments", function() { var js = "function lots_of_comments(x) { return 7 -"; for (var i = 1; i <= 5000; ++i) js += "// " + i + "\n"; for (; i <= 10000; ++i) js += "/* " + i + " */ /**/"; js += "x; }"; var result = UglifyJS.minify(js, { mangle: false }); assert.strictEqual(result.code, "function lots_of_comments(x){return 7-x}"); }); }); }); terser-4.1.2/test/mocha/destructuring.js000066400000000000000000000105311351061312300203230ustar00rootroot00000000000000var assert = require("assert"); var uglify = require("../node"); describe("Destructuring", function() { it("Should generate similar trees for destructuring in left hand side expressions, definitions, functions and arrow functions", function() { var patterns = [ "[]", "{}", "[a, b, c]", "{a: b, c: d}", "{a}", "{a, b}", "{a: {}}", "{a: []}", "[{}]", "[[]]", "{a: {b}}", // Can't do `a = 123` with lhs expression, so only test in destructuring "[foo = bar]", "{a = 123}", "[{foo: abc = 123}]", "{foo: [abc = 123]}", "[...foo]", "[...{}]", "[...[]]" // Can't do `...` because that is an invalid lhs expression, spread in array destructuring should be fine though ]; var types = [ { name: "lhs", symbolType: uglify.AST_SymbolRef, tree: function (ast) { return ast.body[0].body.left; }, generate: function (code) { return "(" + code + " = a)"; } }, { name: "var", symbolType: uglify.AST_SymbolVar, tree: function (ast) { return ast.body[0].definitions[0].name; }, generate: function (code) { return "var " + code + " = a"; } }, { name: "function", symbolType: uglify.AST_SymbolFunarg, tree: function (ast) { return ast.body[0].argnames[0]; }, generate: function (code) { return "function a(" + code + ") {}"; } }, { name: "arrow", symbolType: uglify.AST_SymbolFunarg, tree: function (ast) { return ast.body[0].definitions[0].value.argnames[0]; }, generate: function (code) { return "var a = (" + code + ") => {}"; } } ]; var walker = function(type, ref, code, result) { var w = new uglify.TreeWalker(function(node) { if (w.parent() instanceof uglify.AST_DefaultAssign && w.parent().right === node ) { return true; // Don't check the content of the default assignment } else if (node instanceof uglify.AST_Symbol) { assert(node instanceof type.symbolType, node.TYPE + " while " + type.symbolType.TYPE + " expected at pos " + node.start.pos + " in `" + code + "` (" + ref + ")" ); result.push([ new uglify.AST_Symbol({ start: node.start, name: node.name, end: node.end }), w.parent() ]); return; } result.push([node, w.parent()]); }); return w; }; var getNodeType = function(node) { return node[0].TYPE + (node[1] ? " " + node[1].TYPE : ""); } for (var i = 0; i < patterns.length; i++) { var results = []; for (var j = 0; j < types.length; j++) { var code = types[j].generate(patterns[i]) var ast = types[j].tree( uglify.parse(code) ); results.push([]); ast.walk(walker( types[j], "`" + patterns[i] + "` on " + types[j].name, code, results[j] )); if (j > 0) { assert.deepEqual( results[0].map(getNodeType), results[j].map(getNodeType), "AST disagree on " + patterns[i] + " with " + types[j].name ); } } } }); }); terser-4.1.2/test/mocha/directives.js000066400000000000000000000453241351061312300175720ustar00rootroot00000000000000var assert = require("assert"); var UglifyJS = require("../node"); describe("Directives", function() { it("Should allow tokenizer to store directives state", function() { var tokenizer = UglifyJS.tokenizer("", "foo.js"); // Stack level 0 assert.strictEqual(tokenizer.has_directive("use strict"), false); assert.strictEqual(tokenizer.has_directive("use asm"), false); assert.strictEqual(tokenizer.has_directive("use thing"), false); // Stack level 2 tokenizer.push_directives_stack(); tokenizer.push_directives_stack(); tokenizer.add_directive("use strict"); assert.strictEqual(tokenizer.has_directive("use strict"), true); assert.strictEqual(tokenizer.has_directive("use asm"), false); assert.strictEqual(tokenizer.has_directive("use thing"), false); // Stack level 3 tokenizer.push_directives_stack(); tokenizer.add_directive("use strict"); tokenizer.add_directive("use asm"); assert.strictEqual(tokenizer.has_directive("use strict"), true); assert.strictEqual(tokenizer.has_directive("use asm"), true); assert.strictEqual(tokenizer.has_directive("use thing"), false); // Stack level 2 tokenizer.pop_directives_stack(); assert.strictEqual(tokenizer.has_directive("use strict"), true); assert.strictEqual(tokenizer.has_directive("use asm"), false); assert.strictEqual(tokenizer.has_directive("use thing"), false); // Stack level 3 tokenizer.push_directives_stack(); tokenizer.add_directive("use thing"); tokenizer.add_directive("use\\\nasm"); assert.strictEqual(tokenizer.has_directive("use strict"), true); assert.strictEqual(tokenizer.has_directive("use asm"), false); // Directives are strict! assert.strictEqual(tokenizer.has_directive("use thing"), true); // Stack level 2 tokenizer.pop_directives_stack(); assert.strictEqual(tokenizer.has_directive("use strict"), true); assert.strictEqual(tokenizer.has_directive("use asm"), false); assert.strictEqual(tokenizer.has_directive("use thing"), false); // Stack level 1 tokenizer.pop_directives_stack(); assert.strictEqual(tokenizer.has_directive("use strict"), false); assert.strictEqual(tokenizer.has_directive("use asm"), false); assert.strictEqual(tokenizer.has_directive("use thing"), false); // Stack level 0 tokenizer.pop_directives_stack(); assert.strictEqual(tokenizer.has_directive("use strict"), false); assert.strictEqual(tokenizer.has_directive("use asm"), false); assert.strictEqual(tokenizer.has_directive("use thing"), false); }); it("Should know which strings are directive and which ones are not", function() { var test_directive = function(tokenizer, test) { test.directives.map(function(directive) { assert.strictEqual(tokenizer.has_directive(directive), true, "Didn't found directive `" + directive + "` at the end of `" + test.input + '`'); }); test.non_directives.map(function(fake_directive) { assert.strictEqual(tokenizer.has_directive(fake_directive), false, "Unexpectedly found directive `" + fake_directive + "` at the end of `" + test.input + '`'); }); } var tests = [ { input: '"use strict"\n', directives: ["use strict"], non_directives: ["use asm"] }, { input: '"use\\\nstrict";', directives: [], non_directives: ["use strict", "use\nstrict", "use \nstrict", "use asm"] }, { input: '"use strict"\n"use asm"\n"use bar"\n', directives: ["use strict", "use asm", "use bar"], non_directives: ["use foo", "use\\x20strict"] }, { input: '"use \\\nstrict";"use strict";', directives: [], non_directives: ["use strict", "use\nstrict", "use \nstrict", "use asm"] }, { input: '"\\76";', directives: [], non_directives: [">", "\\76"] }, { input: '"use strict"', // no ; or newline directives: [], non_directives: ["use strict", "use\nstrict", "use \nstrict", "use asm"] }, { input: ';"use strict"', directives: [], non_directives: ["use strict", "use\nstrict", "use \nstrict", "use asm"] }, { input: '"1";"2";"3";"4";;"5"', directives: ["1", "2", "3", "4"], non_directives: ["5", "6", "use strict", "use asm"] }, { input: 'if(1){"use strict";', directives: [], non_directives: ["use strict", "use\nstrict", "use \nstrict", "use asm"] }, { input: '"use strict";try{"use asm";', directives: ["use strict"], non_directives: ["use\nstrict", "use \nstrict", "use asm"] }, { input: 'class foo {', directives: ["use strict"], non_directives: ["use\nstrict", "use asm"] }, { input: 'class foo {}', directives: [], non_directives: ["use strict", "use asm", "use\nstrict"] } ]; for (var i = 0; i < tests.length; i++) { // Fail parser deliberately to get state at failure var tokenizer = UglifyJS.tokenizer(tests[i].input + "]", "foo.js"); try { var parser = UglifyJS.parse(tokenizer); throw new Error("Expected parser to fail"); } catch (e) { assert.strictEqual(e instanceof UglifyJS.JS_Parse_Error, true); assert.strictEqual(e.message, "Unexpected token: punc (])"); } test_directive(tokenizer, tests[i]); } [ [ '"use strict"\n', [ "use strict"], [ "use asm"] ], [ '"use\\\nstrict";', [], [ "use strict", "use\nstrict", "use \nstrict", "use asm" ] ], [ '"use strict"\n"use asm"\n"use bar"\n', [ "use strict", "use asm", "use bar" ], [ "use foo", "use\\x20strict" ] ], [ '"use \\\nstrict";"use strict";', [], [ "use strict", "use\nstrict", "use \nstrict", "use asm" ] ], [ '"\\76";', [], [ ">", "\\76" ] ], [ // no ; or newline '"use strict"', [], [ "use strict", "use\nstrict", "use \nstrict", "use asm" ] ], [ ';"use strict"', [], [ "use strict", "use\nstrict", "use \nstrict", "use asm" ] ], // Duplicate above code but put it in a function [ 'function foo() {"use strict"\n', [ "use strict" ], [ "use asm" ] ], [ 'function foo() {"use\\\nstrict";', [], [ "use strict", "use\nstrict", "use \nstrict", "use asm" ] ], [ 'function foo() {"use strict"\n"use asm"\n"use bar"\n', [ "use strict", "use asm", "use bar" ], [ "use foo", "use\\x20strict" ] ], [ 'function foo() {"use \\\nstrict";"use strict";', [], [ "use strict", "use\nstrict", "use \nstrict", "use asm" ] ], [ 'var foo = function() {"\\76";', [], [ ">", "\\76" ] ], [ 'var foo = function() {"use strict"', // no ; or newline [], [ "use strict", "use\nstrict", "use \nstrict", "use asm" ] ], [ 'var foo = function() {;"use strict"', [], [ "use strict", "use\nstrict", "use \nstrict", "use asm" ] ], // Special cases [ '"1";"2";"3";"4";;"5"', [ "1", "2", "3", "4" ], [ "5", "6", "use strict", "use asm" ] ], [ 'if(1){"use strict";', [], [ "use strict", "use\nstrict", "use \nstrict", "use asm" ] ], [ '"use strict";try{"use asm";', [ "use strict" ], [ "use\nstrict", "use \nstrict", "use asm" ] ], ].forEach(function(test) { var tokenizer = UglifyJS.tokenizer(test[0] + "]", "foo.js"); assert.throws(function() { UglifyJS.parse(tokenizer); }, function(e) { return e instanceof UglifyJS.JS_Parse_Error && e.message === "Unexpected token: punc (])" }, test[0]); test[1].forEach(function(directive) { assert.strictEqual(tokenizer.has_directive(directive), true, directive + " in " + test[0]); }); test[2].forEach(function(fake_directive) { assert.strictEqual(tokenizer.has_directive(fake_directive), false, fake_directive + " in " + test[0]); }); }); }); it("Should test EXPECT_DIRECTIVE RegExp", function() { [ [ "", true ], [ "'test';", true ], [ "'test';;", true ], [ "'tests';\n", true ], [ "'tests'", false ], [ "'tests'; \n\t", true ], [ "'tests';\n\n", true ], [ "\n\n\"use strict\";\n\n", true ], ].forEach(function(test) { var out = UglifyJS.OutputStream(); out.print(test[0]); out.print_string("", null, true); assert.strictEqual(out.get() === test[0] + ';""', test[1], test[0]); }); }); it("Should only print 2 semicolons spread over 2 lines in beautify mode", function() { var result = UglifyJS.minify([ '"use strict";', "'use strict';", '"use strict";', '"use strict";;', "'use strict';", "console.log('use strict');" ].join(""), { compress: false, output: { beautify: true, quote_style: 3 } }); if (result.error) throw result.error; assert.strictEqual(result.code, [ '"use strict";', "'use strict';", '"use strict";', '"use strict";', ";'use strict';", "console.log('use strict');" ].join("\n\n")); }); it("Should not add double semicolons in non-scoped block statements to avoid strings becoming directives", function() { [ [ '{"use\x20strict"}', '{"use strict"}' ], [ 'function foo(){"use\x20strict";}', // Valid place for directives 'function foo(){"use strict"}' ], [ 'try{"use\x20strict"}catch(e){}finally{"use\x20strict"}', 'try{"use strict"}catch(e){}finally{"use strict"}' ], [ 'if(1){"use\x20strict"} else {"use strict"}', 'if(1){"use strict"}else{"use strict"}' ] ].forEach(function(test) { var result = UglifyJS.minify(test[0], { compress: false, mangle: false }); if (result.error) throw result.error; assert.strictEqual(result.code, test[1], test[0]); }); }); it("Should add double semicolon when relying on automatic semicolon insertion", function() { var result = UglifyJS.minify('"use strict";"use\\x20strict";', { compress: false, output: { semicolons: false } }); if (result.error) throw result.error; assert.strictEqual(result.code, '"use strict";;"use strict"\n'); }); it("Should check quote style of directives", function() { [ // 0. Prefer double quotes, unless string contains more double quotes than single quotes [ '"testing something";', 0, '"testing something";' ], [ "'use strict';", 0, '"use strict";' ], [ '"\\\'use strict\\\'";', // Not a directive as it contains quotes 0, ';"\'use strict\'";', ], [ "'\"use strict\"';", 0, "'\"use strict\"';", ], // 1. Always use single quote [ '"testing something";', 1, "'testing something';" ], [ "'use strict';", 1, "'use strict';" ], [ '"\'use strict\'";', 1, // Intentionally causes directive breakage at cost of less logic, usage should be rare anyway "'\\'use strict\\'';", ], [ "'\\'use strict\\'';", // Not a valid directive 1, "'\\'use strict\\'';" // But no ; necessary as directive stays invalid ], [ "'\"use strict\"';", 1, "'\"use strict\"';", ], // 2. Always use double quote [ '"testing something";', 2, '"testing something";' ], [ "'use strict';", 2, '"use strict";' ], [ '"\'use strict\'";', 2, "\"'use strict'\";", ], [ "'\"use strict\"';", 2, // Intentionally causes directive breakage at cost of less logic, usage should be rare anyway '"\\\"use strict\\\"";', ], [ '"\\"use strict\\"";', // Not a valid directive 2, '"\\"use strict\\"";' // But no ; necessary as directive stays invalid ], // 3. Always use original [ '"testing something";', 3, '"testing something";' ], [ "'use strict';", 3, "'use strict';", ], [ '"\'use strict\'";', 3, '"\'use strict\'";', ], [ "'\"use strict\"';", 3, "'\"use strict\"';", ], ].forEach(function(test) { var result = UglifyJS.minify(test[0], { compress: false, output: { quote_style: test[1] } }); if (result.error) throw result.error; assert.strictEqual(result.code, test[2], test[0] + " using mode " + test[1]); }); }); it("Should be able to compress without side effects", function() { [ [ '"use strict";"use strict";"use strict";"use foo";"use strict";;"use sloppy";doSomething("foo");', '"use strict";doSomething("foo");' ], [ // Nothing gets optimised in the compressor because "use asm" is the first statement '"use asm";"use\\x20strict";1+1;', // Yet, the parser noticed that "use strict" wasn't a directive '"use asm";;"use strict";1+1;', ], [ 'function f(){ "use strict" }', 'function f(){}' ], [ 'function f(){ "use asm" }', 'function f(){"use asm"}' ], [ 'function f(){ "use nondirective" }', 'function f(){}' ], [ 'function f(){ ;"use strict" }', 'function f(){}' ], [ 'function f(){ "use \\n"; }', 'function f(){}' ], ].forEach(function(test) { var result = UglifyJS.minify(test[0]); if (result.error) throw result.error; assert.strictEqual(result.code, test[1], test[0]); }); }); it("Should be detect implicit usages of strict mode from tree walker", function() { var tests = [ { input: 'class foo {bar(){_check_}}', directives: ["use strict"], non_directives: ["use bar"] }, { input: 'class foo {bar(){}}_check_', directives: [], non_directives: ["use strict", "use bar"] } ]; var i = 0; var checked; var checkWalker = new UglifyJS.TreeWalker(function(node, descend) { if (node instanceof UglifyJS.AST_Symbol && node.name === "_check_") { checked = true; for (var j = 0; j < tests[i].directives.length; j++) { assert.ok(checkWalker.has_directive(tests[i].directives[j]), "Did not found directive '" + tests[i].directives[j] + "' in test " + tests[i].input) } for (var k = 0; k < tests[i].non_directives.length; k++) { assert.equal(checkWalker.has_directive(tests[i].non_directives[k]), undefined, "Found directive '" + tests[i].non_directives[k] + "' in test " + tests[i].input) } } }); for (; i < tests.length; i++) { // Do tests - iterate the ast in each test - check only when _check_ occurs - fail when no _check_ has been found checked = false; var ast = UglifyJS.parse(tests[i].input); ast.walk(checkWalker); if (!checked) { throw "No _check_ symbol found in " + tests[i].input; } } }); }); terser-4.1.2/test/mocha/eof.js000066400000000000000000000023671351061312300162020ustar00rootroot00000000000000var assert = require("assert"); var uglify = require("../node"); describe("EOF", function() { it("Should test code for at least throwing syntax error when incomplete", function() { var error = function(e) { return e instanceof uglify.JS_Parse_Error; } var parse = function(test) { return function() { uglify.parse(test); } } // Chops off 1 char at a time until limit or start of string is reached // The passed code must still be valid when unchopped var test_eol = function(input, chopLimit) { if (chopLimit === undefined) { chopLimit = input.length - 1; } assert.doesNotThrow(parse(input), "Expected valid code for \n" + input); for (var i = input.length - 1; chopLimit > 0; chopLimit--, i--) { var code = input.substr(0, i); assert.throws(parse(code), error, code); } } test_eol("var \\u1234", 7); // Incomplete identifier test_eol("'Incomplete string'"); test_eol("/Unterminated regex/"); test_eol("` Unterminated template string`"); test_eol("/* Unfinishing multiline comment */"); }); }); terser-4.1.2/test/mocha/export.js000066400000000000000000000051471351061312300167510ustar00rootroot00000000000000var assert = require("assert"); var uglify = require("../node"); describe("Export/Import", function() { it("Should parse export directives", function() { var inputs = [ ['export * from "a.js"', ['*'], "a.js"], ['export {A} from "a.js"', ['A'], "a.js"], ['export {A as X} from "a.js"', ['X'], "a.js"], ['export {A as Foo, B} from "a.js"', ['Foo', 'B'], "a.js"], ['export {A, B} from "a.js"', ['A', 'B'], "a.js"], ]; function test(code) { return uglify.parse(code); } function extractNames(symbols) { var ret = []; for (var i = 0; i < symbols.length; i++) { ret.push(symbols[i].foreign_name.name); } return ret; } for (var i = 0; i < inputs.length; i++) { var ast = test(inputs[i][0]); var names = inputs[i][1]; var filename = inputs[i][2]; assert(ast instanceof uglify.AST_Toplevel); assert.equal(ast.body.length, 1); var st = ast.body[0]; assert(st instanceof uglify.AST_Export); var actualNames = extractNames(st.exported_names); assert.deepEqual(actualNames, names); assert.equal(st.module_name.value, filename); } }); it("Should not parse invalid uses of export", function() { assert.equal(uglify.minify("export").error.message, "Unexpected token: eof (undefined)"); assert.equal(uglify.minify("export;").error.message, "Unexpected token: punc (;)"); assert.equal(uglify.minify("export();").error.message, "Unexpected token: keyword (export)"); assert.equal(uglify.minify("export(1);").error.message, "Unexpected token: keyword (export)"); assert.equal(uglify.minify("var export;").error.message, "Name expected"); assert.equal(uglify.minify("var export = 1;").error.message, "Name expected"); assert.equal(uglify.minify("function f(export){}").error.message, "Invalid function parameter"); }); it("Should not parse invalid uses of import", function() { assert.equal(uglify.minify("import").error.message, "Unexpected token: eof (undefined)"); assert.equal(uglify.minify("import;").error.message, "Unexpected token: punc (;)"); assert.equal(uglify.minify("var import;").error.message, "Unexpected token: import"); assert.equal(uglify.minify("var import = 1;").error.message, "Unexpected token: import"); assert.equal(uglify.minify("function f(import){}").error.message, "Unexpected token: name (import)"); }); }); terser-4.1.2/test/mocha/expression.js000066400000000000000000000016231351061312300176220ustar00rootroot00000000000000var assert = require("assert"); var uglify = require("../node"); describe("Expression", function() { it("Should not allow the first exponentiation operator to be prefixed with an unary operator", function() { var tests = [ "+5 ** 3", "-5 ** 3", "~5 ** 3", "!5 ** 3", "void 5 ** 3", "typeof 5 ** 3", "delete 5 ** 3", "var a = -(5) ** 3;" ]; var fail = function(e) { return e instanceof uglify.JS_Parse_Error && /^Unexpected token: operator \((?:[!+~-]|void|typeof|delete)\)/.test(e.message); } var exec = function(test) { return function() { uglify.parse(test); } } for (var i = 0; i < tests.length; i++) { assert.throws(exec(tests[i]), fail, tests[i]); } }); }); terser-4.1.2/test/mocha/function.js000066400000000000000000000242471351061312300172570ustar00rootroot00000000000000var assert = require("assert"); var uglify = require("../node"); describe("Function", function() { it ("Should parse binding patterns correctly", function() { // Function argument nodes are correct function get_args(args) { return args.map(function (arg) { return [arg.TYPE, arg.name]; }); } // Destructurings as arguments var destr_fun1 = uglify.parse('(function ({a, b}) {})').body[0].body; var destr_fun2 = uglify.parse('(function ([a, [b]]) {})').body[0].body; var destr_fun3 = uglify.parse('({a, b}) => null').body[0].body; var destr_fun4 = uglify.parse('([a, [b]]) => null').body[0].body; assert.equal(destr_fun1.argnames.length, 1); assert.equal(destr_fun2.argnames.length, 1); assert.equal(destr_fun3.argnames.length, 1); assert.equal(destr_fun4.argnames.length, 1); var destruct1 = destr_fun1.argnames[0]; var destruct2 = destr_fun2.argnames[0]; var destruct3 = destr_fun3.argnames[0]; var destruct4 = destr_fun4.argnames[0]; assert(destruct1 instanceof uglify.AST_Destructuring); assert(destruct2 instanceof uglify.AST_Destructuring); assert(destruct3 instanceof uglify.AST_Destructuring); assert(destruct4 instanceof uglify.AST_Destructuring); assert(destruct2.names[1] instanceof uglify.AST_Destructuring); assert(destruct4.names[1] instanceof uglify.AST_Destructuring); assert.equal(destruct1.start.value, '{'); assert.equal(destruct1.end.value, '}'); assert.equal(destruct2.start.value, '['); assert.equal(destruct2.end.value, ']'); assert.equal(destruct3.start.value, '{'); assert.equal(destruct3.end.value, '}'); assert.equal(destruct4.start.value, '['); assert.equal(destruct4.end.value, ']'); assert.equal(destruct1.is_array, false); assert.equal(destruct2.is_array, true); assert.equal(destruct3.is_array, false); assert.equal(destruct4.is_array, true); // destruct 1 assert.deepEqual( [ destruct1.names[0].TYPE, destruct1.names[0].key, destruct1.names[0].value.name ], ['ObjectKeyVal', 'a', 'a'] ); assert.deepEqual( [ destruct1.names[1].TYPE, destruct1.names[1].key, destruct1.names[1].value.name ], ['ObjectKeyVal', 'b', 'b'] ); // destruct 2 assert.deepEqual( [ destruct2.names[0].TYPE, destruct2.names[0].name ], ['SymbolFunarg', 'a'] ); assert.deepEqual( [ destruct2.names[1].names[0].TYPE, destruct2.names[1].names[0].name ], ['SymbolFunarg', 'b'] ); // destruct 3 assert.strictEqual(typeof destruct3.names[0].key, "string"); assert.strictEqual(destruct3.names[0].key, "a"); assert.strictEqual(destruct3.names[0].value.TYPE, "SymbolFunarg"); assert.strictEqual(destruct3.names[0].value.name, "a"); assert.strictEqual(typeof destruct3.names[1].key, "string"); assert.strictEqual(destruct3.names[1].key, "b"); assert.strictEqual(destruct3.names[1].value.TYPE, "SymbolFunarg"); assert.strictEqual(destruct3.names[1].value.name, "b"); // destruct 4 assert.deepEqual( [ destruct4.names[0].TYPE, destruct4.names[0].name ], ['SymbolFunarg', 'a'] ); assert.strictEqual(destruct4.names[1].TYPE, "Destructuring"); assert.deepEqual( [ destruct4.names[1].names[0].TYPE, destruct4.names[1].names[0].name ], ['SymbolFunarg', 'b'] ); assert.deepEqual( get_args(destr_fun1.args_as_names()), [['SymbolFunarg', 'a'], ['SymbolFunarg', 'b']] ); assert.deepEqual( get_args(destr_fun2.args_as_names()), [['SymbolFunarg', 'a'], ['SymbolFunarg', 'b']] ); assert.deepEqual( get_args(destr_fun3.args_as_names()), [['SymbolFunarg', 'a'], ['SymbolFunarg', 'b']] ); assert.deepEqual( get_args(destr_fun4.args_as_names()), [['SymbolFunarg', 'a'], ['SymbolFunarg', 'b']] ); // Making sure we don't accidentally accept things which // Aren't argument destructurings assert.throws(function () { uglify.parse('(function ( { a, [ b ] } ) { })') }); assert.throws(function () { uglify.parse('(function (1) { })'); }, /Invalid function parameter/); assert.throws(function () { uglify.parse('(function (this) { })'); }); assert.throws(function () { uglify.parse('(function ([1]) { })'); }, /Invalid function parameter/); assert.throws(function () { uglify.parse('(function [a] { })'); }); // generators var generators_def = uglify.parse('function* fn() {}').body[0]; assert.equal(generators_def.is_generator, true); assert.throws(function () { uglify.parse('function* (){ }'); }); var generators_yield_def = uglify.parse('function* fn() {\nyield remote();\}').body[0].body[0]; assert.strictEqual(generators_yield_def.body.is_star, false); }); it("Should not accept spread on non-last parameters", function() { var tests = [ "var a = function(...a, b) { return a.join(b) }", "var b = function(a, b, ...c, d) { return c.join(a + b) + d }", "function foo(...a, b) { return a.join(b) }", "function bar(a, b, ...c, d) { return c.join(a + b) + d }", "var a = function*(...a, b) { return a.join(b) }", "var b = function*(a, b, ...c, d) { return c.join(a + b) + d }", "function* foo(...a, b) { return a.join(b) }", "function* bar(a, b, ...c, d) { return c.join(a + b) + d }" ]; var test = function(code) { return function() { uglify.parse(code); } } var error = function(e) { return e instanceof uglify.JS_Parse_Error && /^Unexpected token: /.test(e.message); } for (var i = 0; i < tests.length; i++) { assert.throws(test(tests[i]), error); } }); it("Should not accept empty parameters after elision", function() { var tests = [ "(function(,){})()", "(function(a,){})()", ]; var test = function(code) { return function() { uglify.parse(code, { ecma: 5 }); } } var error = function(e) { return e instanceof uglify.JS_Parse_Error; } for (var i = 0; i < tests.length; i++) { assert.throws(test(tests[i]), error, tests[i]); } }); it("Should accept trailing commas only for ES8", function() { [ "new Foo(a, );", "async(...[1, 2], );", "console.log(...[1, 2], );", "!function(a, b, ){ console.log(a + b); }(3, 4, );", ].forEach(function(code) { uglify.parse(code, { ecma: 8 }); assert.throws(function() { uglify.parse(code, { ecma: 6 }); }, function(e) { return e instanceof uglify.JS_Parse_Error; }, code); }); }); it("Should not accept invalid trailing commas", function() { var tests = [ "f(, );", "(, ) => {};", "(...p, ) => {};", "function f(, ) {}", "function f(...p, ) {}", "function foo(a, b, , ) {}", 'console.log("hello", , );', ]; var test = function(code) { return function() { uglify.parse(code, { ecma: 8 }); } } var error = function(e) { return e instanceof uglify.JS_Parse_Error; } for (var i = 0; i < tests.length; i++) { assert.throws(test(tests[i]), error, tests[i]); } }); it("Should not accept an initializer when parameter is a rest parameter", function() { var tests = [ "(function(...a = b){})()", "(function(a, ...b = [c, d]))" ]; var test = function(code) { return function () { uglify.parse(code); } } var error = function (e) { return e instanceof uglify.JS_Parse_Error; } for (var i = 0; i < tests.length; i++) { assert.throws(test(tests[i]), error, tests[i]); } }); it("Shoult not accept duplicated identifiers inside parameters in strict mode or when using default assigment or spread", function() { // From: ES2016 9.2.12 FunctionDeclarationInstantiation (func, argumentsList) // NOTE Early errors ensure that duplicate parameter names can only occur // in non-strict functions that do not have parameter default values or // rest parameters. var tests = [ "(function(a = 1, a){})()", "(function(a, [a = 3]){})()", "(function(a, b, c, d, [{e: [...a]}]){})()", "'use strict'; (function(a, a){})", "(function({a, a = b}))", "(function(a, [...a]){})", "(function(a, ...a){})", "(function(a, [a, ...b]){})", "(function(a, {b: a, c: [...d]}){})", "(function(a, a, {b: [...c]}){})" ]; var test = function(code) { return function () { uglify.parse(code); } } var error = function (e) { return e instanceof uglify.JS_Parse_Error && /^Parameter [a-zA-Z]+ was used already$/.test(e.message); } for (var i = 0; i < tests.length; i++) { assert.throws(test(tests[i]), error, tests[i]); } }); }); terser-4.1.2/test/mocha/functional.js000066400000000000000000000003411351061312300175610ustar00rootroot00000000000000'use strict' const assert = require('assert') const Terser = require('../..') describe('Terser (functional tests)', () => { it('does not have a __esModule property', () => { assert(!Terser.__esModule) }) }) terser-4.1.2/test/mocha/getter-setter.js000066400000000000000000000043511351061312300202220ustar00rootroot00000000000000var assert = require("assert"); var UglifyJS = require("../node"); describe("Getters and setters", function() { it("Should not accept operator symbols as getter/setter name", function() { var illegalOperators = [ "++", "--", "+", "-", "!", "~", "&", "|", "^", "*", "/", "%", ">>", "<<", ">>>", "<", ">", "<=", ">=", "==", "===", "!=", "!==", "?", "=", "+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=", "&&", "||" ]; var generator = function() { var results = []; for (var i in illegalOperators) { results.push({ code: "var obj = { get " + illegalOperators[i] + "() { return test; }};", operator: illegalOperators[i], method: "get" }); results.push({ code: "var obj = { set " + illegalOperators[i] + "(value) { test = value}};", operator: illegalOperators[i], method: "set" }); } return results; }; var testCase = function(data) { return function() { UglifyJS.parse(data.code); }; }; var fail = function(data) { return function (e) { return e instanceof UglifyJS.JS_Parse_Error && /^Unexpected token: /.test(e.message); }; }; var errorMessage = function(data) { return "Expected but didn't get a syntax error while parsing following line:\n" + data.code; }; var tests = generator(); for (var i = 0; i < tests.length; i++) { var test = tests[i]; assert.throws(testCase(test), fail(test), errorMessage(test)); } }); }); terser-4.1.2/test/mocha/glob.js000066400000000000000000000055141351061312300163510ustar00rootroot00000000000000var assert = require("assert"); var exec = require("child_process").exec; var path = require("path"); describe("bin/uglifyjs with input file globs", function() { var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs'; it("bin/uglifyjs with one input file extension glob.", function(done) { var command = uglifyjscmd + ' "test/input/issue-1242/foo.*" -cm'; exec(command, function(err, stdout) { if (err) throw err; assert.strictEqual(stdout, 'var print=console.log.bind(console);function foo(o){print("Foo:",2*o)}\n'); done(); }); }); it("bin/uglifyjs with one input file name glob.", function(done) { var command = uglifyjscmd + ' "test/input/issue-1242/b*.es5" -cm'; exec(command, function(err, stdout) { if (err) throw err; assert.strictEqual(stdout, 'function bar(n){return 3*n}function baz(n){return n/2}\n'); done(); }); }); it("bin/uglifyjs with multiple input file globs.", function(done) { var command = uglifyjscmd + ' "test/input/issue-1242/???.es5" "test/input/issue-1242/*.js" -mc toplevel,passes=3'; exec(command, function(err, stdout) { if (err) throw err; assert.strictEqual(stdout, 'var print=console.log.bind(console);print("qux",9,6),print("Foo:",22);\n'); done(); }); }); it("Should throw with non-matching glob string", function(done) { var command = uglifyjscmd + ' "test/input/issue-1242/blah.*"'; exec(command, function(err, stdout, stderr) { assert.ok(err); assert.ok(/^ERROR: ENOENT/.test(stderr)); done(); }); }); it('"?" in glob string should not match "/"', function(done) { var command = uglifyjscmd + ' "test/input?issue-1242/foo.*"'; exec(command, function(err, stdout, stderr) { assert.ok(err); assert.ok(/^ERROR: ENOENT/.test(stderr)); done(); }); }); it("Should handle special characters in glob string", function(done) { var command = uglifyjscmd + ' "test/input/issue-1632/^{*}[???](*)+$.??" -cm'; exec(command, function(err, stdout) { if (err) throw err; assert.strictEqual(stdout, "console.log(x);\n"); done(); }); }); it("Should handle array of glob strings - matching and otherwise", function(done) { var dir = "test/input/issue-1242"; var command = uglifyjscmd + ' "' + [ path.join(dir, "b*.es5"), path.join(dir, "z*.es5"), path.join(dir, "*.js") ].join('" "') + '"'; exec(command, function(err, stdout, stderr) { assert.ok(err); assert.ok(/^ERROR: ENOENT.*?z\*\.es5/.test(stderr)); done(); }); }); }); terser-4.1.2/test/mocha/ie8.js000066400000000000000000000015031351061312300161050ustar00rootroot00000000000000var assert = require("assert"); var UglifyJS = require("../.."); describe("screw-ie8", function () { it("Should be able to minify() with undefined as catch parameter in a try...catch statement", function () { assert.strictEqual( UglifyJS.minify([ "function a(b){", " try {", " throw 'Stuff';", " } catch (undefined) {", " console.log('caught: ' + undefined);", " }", " console.log('undefined is ' + undefined);", " return b === undefined;", "};", ].join("\n")).code, 'function a(o){try{throw"Stuff"}catch(o){console.log("caught: "+o)}return console.log("undefined is "+void 0),void 0===o}' ); }); }); terser-4.1.2/test/mocha/input-sourcemaps.js000066400000000000000000000043061351061312300207420ustar00rootroot00000000000000var Uglify = require('../../'); var assert = require("assert"); var SourceMapConsumer = require("source-map").SourceMapConsumer; describe("input sourcemaps", function() { var transpilemap, map; function getMap() { return { "version": 3, "sources": ["index.js"], "names": [], "mappings": ";;AAAA,IAAI,MAAM,SAAN,GAAM;AAAA,SAAK,SAAS,CAAd;AAAA,CAAV;AACA,QAAQ,GAAR,CAAY,IAAI,KAAJ,CAAZ", "file": "bundle.js", "sourcesContent": ["let foo = x => \"foo \" + x;\nconsole.log(foo(\"bar\"));"] }; } function prepareMap(sourceMap) { var transpiled = '"use strict";\n\n' + 'var foo = function foo(x) {\n return "foo " + x;\n};\n' + 'console.log(foo("bar"));\n\n' + '//# sourceMappingURL=bundle.js.map'; transpilemap = sourceMap || getMap(); var result = Uglify.minify(transpiled, { sourceMap: { content: transpilemap } }); map = new SourceMapConsumer(result.map); } beforeEach(function () { prepareMap(); }); it("Should copy over original sourcesContent", function() { assert.equal(map.sourceContentFor("index.js"), transpilemap.sourcesContent[0]); }); it("Should copy sourcesContent if sources are relative", function () { var relativeMap = getMap(); relativeMap.sources = ['./index.js']; prepareMap(relativeMap); assert.notEqual(map.sourcesContent, null); assert.equal(map.sourcesContent.length, 1); assert.equal(map.sourceContentFor("index.js"), transpilemap.sourcesContent[0]); }); it("Final sourcemap should not have invalid mappings from inputSourceMap (issue #882)", function() { // The original source has only 2 lines, check that mappings don't have more lines var msg = "Mapping should not have higher line number than the original file had"; map.eachMapping(function(mapping) { assert.ok(mapping.originalLine <= 2, msg) }); map.allGeneratedPositionsFor({source: "index.js", line: 1, column: 1}).forEach(function(pos) { assert.ok(pos.line <= 2, msg); }) }); }); terser-4.1.2/test/mocha/let.js000066400000000000000000000023171351061312300162100ustar00rootroot00000000000000var assert = require("assert"); var UglifyJS = require("../.."); describe("let", function() { this.timeout(60000); it("Should not produce reserved keywords as variable name in mangle", function() { // Produce a lot of variables in a function and run it through mangle. var s = '"dddddeeeeelllllooooottttt"; function foo() {'; for (var i = 0; i < 18000; i++) { s += "var v" + i + "=0;"; } s += '}'; var result = UglifyJS.minify(s, { compress: false }).code; // Verify that select keywords and reserved keywords not produced [ "do", "let", "var", ].forEach(function(name) { assert.strictEqual(result.indexOf("var " + name + "="), -1); }); // Verify that the variable names that appeared immediately before // and after the erroneously generated variable name still exist // to show the test generated enough symbols. [ "to", "eo", "eet", "fet", "rar", "oar", ].forEach(function(name) { assert.notStrictEqual(result.indexOf("var " + name + "="), -1); }); }); }); terser-4.1.2/test/mocha/lhs-expressions.js000066400000000000000000000325221351061312300205730ustar00rootroot00000000000000var assert = require("assert"); var uglify = require("../node"); describe("Left-hand side expressions", function () { it("Should parse destructuring with const/let/var correctly", function () { var decls = uglify.parse('var {a,b} = foo, { c, d } = bar'); assert.equal(decls.body[0].TYPE, 'Var'); assert.equal(decls.body[0].definitions.length, 2); // Item 1 assert.equal(decls.body[0].definitions[0].name.TYPE, 'Destructuring'); assert.equal(decls.body[0].definitions[0].value.TYPE, 'SymbolRef'); // Item 2 assert.equal(decls.body[0].definitions[1].name.TYPE, 'Destructuring'); assert.equal(decls.body[0].definitions[1].value.TYPE, 'SymbolRef'); var nested_def = uglify.parse('var [{x}] = foo').body[0].definitions[0]; assert.equal(nested_def.name.names[0].names[0].TYPE, 'ObjectKeyVal'); assert.equal(nested_def.name.names[0].names[0].value.TYPE, 'SymbolVar'); assert.equal(nested_def.name.names[0].names[0].key, 'x'); assert.equal(nested_def.name.names[0].names[0].value.name, 'x'); var holey_def = uglify.parse('const [,,third] = [1,2,3]').body[0].definitions[0]; assert.equal(holey_def.name.names[0].TYPE, 'Hole'); assert.equal(holey_def.name.names[1].TYPE, 'Hole'); assert.equal(holey_def.name.names[2].TYPE, 'SymbolConst'); var expanding_def = uglify.parse('var [first, ...rest] = [1,2,3]').body[0].definitions[0]; assert.equal(expanding_def.name.names[0].TYPE, 'SymbolVar'); assert.equal(expanding_def.name.names[1].TYPE, 'Expansion'); assert.equal(expanding_def.name.names[1].expression.TYPE, 'SymbolVar'); }); it("Parser should use AST_Array for array literals", function() { var ast = uglify.parse('["foo", "bar"]'); assert(ast.body[0] instanceof uglify.AST_SimpleStatement); assert(ast.body[0].body instanceof uglify.AST_Array); ast = uglify.parse('a = ["foo"]'); assert(ast.body[0] instanceof uglify.AST_SimpleStatement); assert(ast.body[0].body instanceof uglify.AST_Assign); assert(ast.body[0].body.left instanceof uglify.AST_SymbolRef); assert.equal(ast.body[0].body.operator, "="); assert(ast.body[0].body.right instanceof uglify.AST_Array); }); it("Parser should use AST_Object for object literals", function() { var ast = uglify.parse('({foo: "bar"})'); assert(ast.body[0] instanceof uglify.AST_SimpleStatement); assert(ast.body[0].body instanceof uglify.AST_Object); // This example should be fine though ast = uglify.parse('a = {foo: "bar"}'); assert(ast.body[0] instanceof uglify.AST_SimpleStatement); assert(ast.body[0].body instanceof uglify.AST_Assign); assert(ast.body[0].body.left instanceof uglify.AST_SymbolRef); assert.equal(ast.body[0].body.operator, "="); assert(ast.body[0].body.right instanceof uglify.AST_Object); }); it("Parser should use AST_Destructuring for array assignment patterns", function() { var ast = uglify.parse('[foo, bar] = [1, 2]'); assert(ast.body[0] instanceof uglify.AST_SimpleStatement); assert(ast.body[0].body instanceof uglify.AST_Assign); assert(ast.body[0].body.left instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].body.left.is_array, true); assert.equal(ast.body[0].body.operator, "="); assert(ast.body[0].body.right instanceof uglify.AST_Array); }); it("Parser should use AST_Destructuring for object assignment patterns", function() { var ast = uglify.parse('({a: b, b: c} = {b: "c", c: "d"})'); assert(ast.body[0] instanceof uglify.AST_SimpleStatement); assert(ast.body[0].body instanceof uglify.AST_Assign); assert(ast.body[0].body.left instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].body.left.is_array, false); assert.equal(ast.body[0].body.operator, "="); assert(ast.body[0].body.right instanceof uglify.AST_Object); }); it("Parser should be able to handle nested destructuring", function() { var ast = uglify.parse('[{a,b},[d, e, f, {g, h}]] = [{a: 1, b: 2}, [3, 4, 5, {g: 6, h: 7}]]'); assert(ast.body[0] instanceof uglify.AST_SimpleStatement); assert(ast.body[0].body instanceof uglify.AST_Assign); assert(ast.body[0].body.left instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].body.left.is_array, true); assert.equal(ast.body[0].body.operator, "="); assert(ast.body[0].body.right instanceof uglify.AST_Array); assert(ast.body[0].body.left.names[0] instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].body.left.names[0].is_array, false); assert(ast.body[0].body.left.names[1] instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].body.left.names[1].is_array, true); assert(ast.body[0].body.left.names[1].names[3] instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].body.left.names[1].names[3].is_array, false); }); it("Should handle spread operator in destructuring", function() { var ast = uglify.parse("[a, b, ...c] = [1, 2, 3, 4, 5]"); assert(ast.body[0] instanceof uglify.AST_SimpleStatement); assert(ast.body[0].body instanceof uglify.AST_Assign); assert(ast.body[0].body.left instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].body.left.is_array, true); assert.equal(ast.body[0].body.operator, "="); assert(ast.body[0].body.right instanceof uglify.AST_Array); assert(ast.body[0].body.left.names[0] instanceof uglify.AST_SymbolRef); assert(ast.body[0].body.left.names[1] instanceof uglify.AST_SymbolRef); assert(ast.body[0].body.left.names[2] instanceof uglify.AST_Expansion); }); it("Should handle default assignments in destructuring", function() { var ast = uglify.parse("({x: v, z = z + 5} = obj);"); assert(ast.body[0] instanceof uglify.AST_SimpleStatement); assert(ast.body[0].body instanceof uglify.AST_Assign); assert(ast.body[0].body.left instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].body.left.is_array, false); assert.equal(ast.body[0].body.operator, "="); assert(ast.body[0].body.right instanceof uglify.AST_SymbolRef); assert(ast.body[0].body.left.names[0].value instanceof uglify.AST_SymbolRef); assert.strictEqual(ast.body[0].body.left.names[0].start.value, "x"); assert(ast.body[0].body.left.names[1].value instanceof uglify.AST_DefaultAssign); assert.strictEqual(ast.body[0].body.left.names[1].start.value, "z"); assert(ast.body[0].body.left.names[1].value.left instanceof uglify.AST_SymbolRef); assert.strictEqual(ast.body[0].body.left.names[1].value.operator, "="); assert(ast.body[0].body.left.names[1].value.right instanceof uglify.AST_Binary); ast = uglify.parse("({x = 123} = obj);"); assert(ast.body[0] instanceof uglify.AST_SimpleStatement); assert(ast.body[0].body instanceof uglify.AST_Assign); assert(ast.body[0].body.left instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].body.left.is_array, false); assert.equal(ast.body[0].body.operator, "="); assert(ast.body[0].body.right instanceof uglify.AST_SymbolRef); assert(ast.body[0].body.left.names[0].value instanceof uglify.AST_DefaultAssign); assert.strictEqual(ast.body[0].body.left.names[0].value.operator, "="); assert(ast.body[0].body.left.names[0].value.left instanceof uglify.AST_SymbolRef); ast = uglify.parse("[x, y = 5] = foo"); assert(ast.body[0] instanceof uglify.AST_SimpleStatement); assert(ast.body[0].body instanceof uglify.AST_Assign); assert(ast.body[0].body.left instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].body.left.is_array, true); assert.equal(ast.body[0].body.operator, "="); assert(ast.body[0].body.right instanceof uglify.AST_SymbolRef); assert(ast.body[0].body.left.names[0] instanceof uglify.AST_SymbolRef); assert.strictEqual(ast.body[0].body.left.names[0].start.value, "x"); assert(ast.body[0].body.left.names[1] instanceof uglify.AST_DefaultAssign); assert(ast.body[0].body.left.names[1].left instanceof uglify.AST_SymbolRef); assert.strictEqual(ast.body[0].body.left.names[1].start.value, "y"); }); it("Should handle default assignments containing assignments in a destructuring", function() { var ast = uglify.parse("[x, y = z = 2] = a;"); assert(ast.body[0] instanceof uglify.AST_SimpleStatement); assert(ast.body[0].body instanceof uglify.AST_Assign); assert(ast.body[0].body.left instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].body.left.is_array, true); assert.equal(ast.body[0].body.operator, "="); assert(ast.body[0].body.right instanceof uglify.AST_SymbolRef); assert(ast.body[0].body.left.names[0] instanceof uglify.AST_SymbolRef); assert(ast.body[0].body.left.names[1] instanceof uglify.AST_DefaultAssign); assert(ast.body[0].body.left.names[1].left instanceof uglify.AST_SymbolRef); assert.equal(ast.body[0].body.left.names[1].operator, "="); assert(ast.body[0].body.left.names[1].right instanceof uglify.AST_Assign); assert(ast.body[0].body.left.names[1].right.left instanceof uglify.AST_SymbolRef); assert.equal(ast.body[0].body.left.names[1].right.operator, "="); assert(ast.body[0].body.left.names[1].right.right instanceof uglify.AST_Number); ast = uglify.parse("({a: a = 123} = obj)"); assert(ast.body[0] instanceof uglify.AST_SimpleStatement); assert(ast.body[0].body instanceof uglify.AST_Assign); assert(ast.body[0].body.left instanceof uglify.AST_Destructuring); assert.strictEqual(ast.body[0].body.left.is_array, false); assert.equal(ast.body[0].body.operator, "="); assert(ast.body[0].body.right instanceof uglify.AST_SymbolRef); assert(ast.body[0].body.left.names[0] instanceof uglify.AST_ObjectProperty); assert.strictEqual(ast.body[0].body.left.names[0].key, "a"); assert(ast.body[0].body.left.names[0].value instanceof uglify.AST_DefaultAssign); assert(ast.body[0].body.left.names[0].value.left instanceof uglify.AST_SymbolRef); assert.strictEqual(ast.body[0].body.left.names[0].value.operator, "="); assert(ast.body[0].body.left.names[0].value.right instanceof uglify.AST_Number); }); it("Should allow multiple spread in array literals", function() { var ast = uglify.parse("var a = [1, 2, 3], b = [4, 5, 6], joined; joined = [...a, ...b]"); assert(ast.body[0] instanceof uglify.AST_Var); assert(ast.body[1] instanceof uglify.AST_SimpleStatement); // Check statement containing array with spreads assert(ast.body[1].body instanceof uglify.AST_Assign); assert(ast.body[1].body.left instanceof uglify.AST_SymbolRef); assert.equal(ast.body[1].body.operator, "="); assert(ast.body[1].body.right instanceof uglify.AST_Array); // Check array content assert.strictEqual(ast.body[1].body.right.elements.length, 2); assert(ast.body[1].body.right.elements[0] instanceof uglify.AST_Expansion); assert(ast.body[1].body.right.elements[0].expression instanceof uglify.AST_SymbolRef); assert(ast.body[1].body.right.elements[0].expression.name, "a"); assert(ast.body[1].body.right.elements[1] instanceof uglify.AST_Expansion); assert(ast.body[1].body.right.elements[1].expression instanceof uglify.AST_SymbolRef); assert(ast.body[1].body.right.elements[1].expression.name, "b"); }); it("Should not allow spread on invalid locations", function() { var expect = function(input, expected) { var execute = function(input) { return function() { uglify.parse(input); } } var check = function(e) { return e instanceof uglify.JS_Parse_Error && e.message === expected; } assert.throws(execute(input), check); } // Spreads are not allowed in destructuring array if it's not the last element expect("[...a, ...b] = [1, 2, 3, 4]", "Spread must the be last element in destructuring array"); // Multiple spreads are not allowed in destructuring array expect("[...a, ...b] = [1, 2, 3, 4]", "Spread must the be last element in destructuring array"); // Array spread must be last in destructuring declaration expect("let [ ...x, a ] = o;", "Rest element must be last element"); // Only one spread per destructuring array declaration expect("let [ a, ...x, ...y ] = o;", "Rest element must be last element"); // Spread in block should not be allowed expect("{...a} = foo", "Unexpected token: expand (...)"); // Object spread must be last in destructuring declaration expect("let { ...x, a } = o;", "Rest element must be last element"); // Only one spread per destructuring declaration expect("let { a, ...x, ...y } = o;", "Rest element must be last element"); }); }); terser-4.1.2/test/mocha/line-endings.js000066400000000000000000000035641351061312300200050ustar00rootroot00000000000000var assert = require("assert"); var UglifyJS = require("../node"); describe("line-endings", function() { var options = { compress: false, mangle: false, output: { beautify: false, comments: /^!/, } }; var expected_code = '/*!one\n2\n3*/\nfunction f(x){if(x)return 3}'; it("Should parse LF line endings", function() { var js = '/*!one\n2\n3*///comment\nfunction f(x) {\n if (x)\n//comment\n return 3;\n}\n'; var result = UglifyJS.minify(js, options); assert.strictEqual(result.code, expected_code); }); it("Should parse CR/LF line endings", function() { var js = '/*!one\r\n2\r\n3*///comment\r\nfunction f(x) {\r\n if (x)\r\n//comment\r\n return 3;\r\n}\r\n'; var result = UglifyJS.minify(js, options); assert.strictEqual(result.code, expected_code); }); it("Should parse CR line endings", function() { var js = '/*!one\r2\r3*///comment\rfunction f(x) {\r if (x)\r//comment\r return 3;\r}\r'; var result = UglifyJS.minify(js, options); assert.strictEqual(result.code, expected_code); }); it("Should not allow line terminators in regexp", function() { var inputs = [ "/\n/", "/\r/", "/\u2028/", "/\u2029/", "/\\\n/", "/\\\r/", "/\\\u2028/", "/\\\u2029/", "/someRandomTextLike[]()*AndThen\n/" ] var test = function(input) { return function() { UglifyJS.parse(input); } } var fail = function(e) { return e instanceof UglifyJS.JS_Parse_Error && e.message === "Unexpected line terminator"; } for (var i = 0; i < inputs.length; i++) { assert.throws(test(inputs[i]), fail); } }); }); terser-4.1.2/test/mocha/minify-file-map.js000066400000000000000000000031721351061312300204070ustar00rootroot00000000000000var assert = require("assert"); var UglifyJS = require("../.."); describe("Input file as map", function() { it("Should accept object", function() { var jsMap = { '/scripts/foo.js': 'var foo = {"x": 1, y: 2, \'z\': 3};' }; var result = UglifyJS.minify(jsMap, {sourceMap: true}); var map = JSON.parse(result.map); assert.strictEqual(result.code, 'var foo={x:1,y:2,z:3};'); assert.deepEqual(map.sources, ['/scripts/foo.js']); assert.strictEqual(map.file, undefined); result = UglifyJS.minify(jsMap); assert.strictEqual(result.map, undefined); result = UglifyJS.minify(jsMap, {sourceMap: {filename: 'out.js'}}); map = JSON.parse(result.map); assert.strictEqual(map.file, 'out.js'); }); it("Should accept array of strings", function() { var jsSeq = [ 'var foo = {"x": 1, y: 2, \'z\': 3};', 'var bar = 15;' ]; var result = UglifyJS.minify(jsSeq, {sourceMap: true}); var map = JSON.parse(result.map); assert.strictEqual(result.code, 'var foo={x:1,y:2,z:3},bar=15;'); assert.deepEqual(map.sources, ['0', '1']); }); it("Should correctly include source", function() { var jsMap = { '/scripts/foo.js': 'var foo = {"x": 1, y: 2, \'z\': 3};' }; var result = UglifyJS.minify(jsMap, {sourceMap: {includeSources: true}}); var map = JSON.parse(result.map); assert.strictEqual(result.code, 'var foo={x:1,y:2,z:3};'); assert.deepEqual(map.sourcesContent, ['var foo = {"x": 1, y: 2, \'z\': 3};']); }); }); terser-4.1.2/test/mocha/minify.js000066400000000000000000000522331351061312300167210ustar00rootroot00000000000000var assert = require("assert"); var readFileSync = require("fs").readFileSync; var run_code = require("../sandbox").run_code; var UglifyJS = require("../../"); function read(path) { return readFileSync(path, "utf8"); } describe("minify", function() { it("Should test basic sanity of minify with default options", function() { var js = 'function foo(bar) { if (bar) return 3; else return 7; var u = not_called(); }'; var result = UglifyJS.minify(js); assert.strictEqual(result.code, 'function foo(n){return n?3:7}'); }); it("Should skip inherited keys from `files`", function() { var files = Object.create({ skip: this }); files[0] = "alert(1 + 1)"; var result = UglifyJS.minify(files); assert.strictEqual(result.code, "alert(2);"); }); it("Should work with mangle.cache", function() { var cache = {}; var original = ""; var compressed = ""; [ "bar.es5", "baz.es5", "foo.es5", "qux.js", ].forEach(function(file) { var code = read("test/input/issue-1242/" + file); var result = UglifyJS.minify(code, { mangle: { cache: cache, toplevel: true } }); if (result.error) throw result.error; original += code; compressed += result.code; }); assert.strictEqual(JSON.stringify(cache).slice(0, 10), '{"props":{'); assert.strictEqual(compressed, [ "function n(n){return 3*n}", "function r(n){return n/2}", "var o=console.log.bind(console);", 'function c(n){o("Foo:",2*n)}', "var a=n(3),b=r(12);", 'o("qux",a,b),c(11);', ].join("")); assert.strictEqual(run_code(compressed), run_code(original)); }); it("Should work with nameCache", function() { var cache = {}; var original = ""; var compressed = ""; [ "bar.es5", "baz.es5", "foo.es5", "qux.js", ].forEach(function(file) { var code = read("test/input/issue-1242/" + file); var result = UglifyJS.minify(code, { mangle: { toplevel: true }, nameCache: cache }); if (result.error) throw result.error; original += code; compressed += result.code; }); assert.strictEqual(JSON.stringify(cache).slice(0, 18), '{"vars":{"props":{'); assert.strictEqual(compressed, [ "function n(n){return 3*n}", "function r(n){return n/2}", "var o=console.log.bind(console);", 'function c(n){o("Foo:",2*n)}', "var a=n(3),b=r(12);", 'o("qux",a,b),c(11);', ].join("")); assert.strictEqual(run_code(compressed), run_code(original)); }); it.skip("Should avoid mangled names in cache", function() { var cache = {}; var original = ""; var compressed = ""; [ '"xxxyy";var i={s:1};', '"xxyyy";var j={t:2,u:3},k=4;', 'console.log(i.s,j.t,j.u,k);', ].forEach(function(code) { var result = UglifyJS.minify(code, { compress: false, mangle: { properties: true, toplevel: true }, nameCache: cache }); if (result.error) throw result.error; original += code; compressed += result.code; }); assert.strictEqual(compressed, [ '"xxxyy";var x={x:1};', '"xxyyy";var y={y:2,a:3},a=4;', 'console.log(x.x,y.y,y.a,a);', ].join("")); assert.strictEqual(run_code(compressed), run_code(original)); }); it("Should not parse invalid use of reserved words", function() { assert.strictEqual(UglifyJS.minify("function enum(){}").error, undefined); assert.strictEqual(UglifyJS.minify("function static(){}").error, undefined); assert.strictEqual(UglifyJS.minify("function super(){}").error.message, "Unexpected token: name (super)"); assert.strictEqual(UglifyJS.minify("function this(){}").error.message, "Unexpected token: name (this)"); }); describe("keep_quoted_props", function() { it("Should preserve quotes in object literals", function() { var js = 'var foo = {"x": 1, y: 2, \'z\': 3};'; var result = UglifyJS.minify(js, { output: { keep_quoted_props: true }}); assert.strictEqual(result.code, 'var foo={"x":1,y:2,"z":3};'); }); it("Should preserve quote styles when quote_style is 3", function() { var js = 'var foo = {"x": 1, y: 2, \'z\': 3};'; var result = UglifyJS.minify(js, { output: { keep_quoted_props: true, quote_style: 3 }}); assert.strictEqual(result.code, 'var foo={"x":1,y:2,\'z\':3};'); }); it("Should not preserve quotes in object literals when disabled", function() { var js = 'var foo = {"x": 1, y: 2, \'z\': 3};'; var result = UglifyJS.minify(js, { output: { keep_quoted_props: false, quote_style: 3 }}); assert.strictEqual(result.code, 'var foo={x:1,y:2,z:3};'); }); }); describe("mangleProperties", function() { it.skip("Shouldn't mangle quoted properties", function() { var js = 'a["foo"] = "bar"; a.color = "red"; x = {"bar": 10};'; var result = UglifyJS.minify(js, { compress: { properties: false }, mangle: { properties: { keep_quoted: true } }, output: { keep_quoted_props: true, quote_style: 3 } }); assert.strictEqual(result.code, 'a["foo"]="bar",a.a="red",x={"bar":10};'); }); it.skip("Should not mangle quoted property within dead code", function() { var result = UglifyJS.minify('var g = {}; ({ "keep": 1 }); g.keep = g.change;', { mangle: { properties: { keep_quoted: true } } }); if (result.error) throw result.error; assert.strictEqual(result.code, "var g={};g.keep=g.g;"); }); }); describe("inSourceMap", function() { it("Should read the given string filename correctly when sourceMapIncludeSources is enabled (#1236)", function() { var result = UglifyJS.minify(read("./test/input/issue-1236/simple.js"), { sourceMap: { content: read("./test/input/issue-1236/simple.js.map"), filename: "simple.min.js", includeSources: true } }); var map = JSON.parse(result.map); assert.equal(map.file, 'simple.min.js'); assert.equal(map.sourcesContent.length, 1); assert.equal(map.sourcesContent[0], 'let foo = x => "foo " + x;\nconsole.log(foo("bar"));'); }); it("Should process inline source map", function() { var code = UglifyJS.minify(read("./test/input/issue-520/input.js"), { compress: { toplevel: true }, sourceMap: { content: "inline", url: "inline" } }).code + "\n"; assert.strictEqual(code, readFileSync("test/input/issue-520/output.js", "utf8")); }); it("Should warn for missing inline source map", function() { var warn_function = UglifyJS.AST_Node.warn_function; var warnings = []; UglifyJS.AST_Node.warn_function = function(txt) { warnings.push(txt); }; try { var result = UglifyJS.minify(read("./test/input/issue-1323/sample.js"), { mangle: false, sourceMap: { content: "inline" } }); assert.strictEqual(result.code, "var bar=function(bar){return bar};"); assert.strictEqual(warnings.length, 1); assert.strictEqual(warnings[0], "inline source map not found"); } finally { UglifyJS.AST_Node.warn_function = warn_function; } }); it("Should fail with multiple input and inline source map", function() { var result = UglifyJS.minify([ read("./test/input/issue-520/input.js"), read("./test/input/issue-520/output.js") ], { sourceMap: { content: "inline", url: "inline" } }); var err = result.error; assert.ok(err instanceof Error); assert.strictEqual(err.stack.split(/\n/)[0], "Error: inline source map only works with singular input"); }); }); describe("sourceMapInline", function() { it("should append source map to output js when sourceMapInline is enabled", function() { var result = UglifyJS.minify('var a = function(foo) { return foo; };', { sourceMap: { url: "inline" } }); var code = result.code; assert.strictEqual(code, "var a=function(n){return n};\n" + "//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIjAiXSwibmFtZXMiOlsiYSIsImZvbyJdLCJtYXBwaW5ncyI6IkFBQUEsSUFBSUEsRUFBSSxTQUFTQyxHQUFPLE9BQU9BIn0="); }); it("should not append source map to output js when sourceMapInline is not enabled", function() { var result = UglifyJS.minify('var a = function(foo) { return foo; };'); var code = result.code; assert.strictEqual(code, "var a=function(n){return n};"); }); it("should work with max_line_len", function() { var result = UglifyJS.minify(read("./test/input/issue-505/input.js"), { compress: { directives: false }, output: { max_line_len: 20 }, sourceMap: { url: "inline" } }); assert.strictEqual(result.error, undefined); assert.strictEqual(result.code, read("./test/input/issue-505/output.js")); }); }); describe("#__PURE__", function() { it("Should drop #__PURE__ hint after use", function() { var result = UglifyJS.minify('//@__PURE__ comment1 #__PURE__ comment2\n foo(), bar();', { output: { comments: "all", beautify: false, } }); var code = result.code; assert.strictEqual(code, "// comment1 comment2\nbar();"); }); it("Should drop #__PURE__ hint if function is retained", function() { var result = UglifyJS.minify("var a = /*#__PURE__*/(function(){ foo(); })();", { output: { comments: "all", beautify: false, } }); var code = result.code; assert.strictEqual(code, "var a=/* */function(){foo()}();"); }) }); describe("JS_Parse_Error", function() { it("Should return syntax error", function() { var result = UglifyJS.minify("function f(a{}"); var err = result.error; assert.ok(err instanceof Error); assert.strictEqual(err.stack.split(/\n/)[0], "SyntaxError: Unexpected token punc «{», expected punc «,»"); assert.strictEqual(err.filename, "0"); assert.strictEqual(err.line, 1); assert.strictEqual(err.col, 12); }); it("Should reject duplicated label name", function() { var result = UglifyJS.minify("L:{L:{}}"); var err = result.error; assert.ok(err instanceof Error); assert.strictEqual(err.stack.split(/\n/)[0], "SyntaxError: Label L defined twice"); assert.strictEqual(err.filename, "0"); assert.strictEqual(err.line, 1); assert.strictEqual(err.col, 4); }); }); describe("global_defs", function() { it("Should throw for non-trivial expressions", function() { var result = UglifyJS.minify("alert(42);", { compress: { global_defs: { "@alert": "debugger" } } }); var err = result.error; assert.ok(err instanceof Error); assert.strictEqual(err.stack.split(/\n/)[0], "SyntaxError: Unexpected token: keyword (debugger)"); }); it("Should skip inherited properties", function() { var foo = Object.create({ skip: this }); foo.bar = 42; var result = UglifyJS.minify("alert(FOO);", { compress: { global_defs: { FOO: foo } } }); assert.strictEqual(result.code, "alert({bar:42});"); }); }); describe("duplicated block-scoped declarations", function() { [ "let a=1;let a=2;", "let a=1;var a=2;", "var a=1;let a=2;", "let[a]=[1];var a=2;", "let a=1;var[a]=[2];", "let[a]=[1];var[a]=[2];", "const a=1;const a=2;", "const a=1;var a=2;", "var a=1;const a=2;", "const[a]=[1];var a=2;", "const a=1;var[a]=[2];", "const[a]=[1];var[a]=[2];", ].forEach(function(code) { it(code, function() { var result = UglifyJS.minify(code, { compress: false, mangle: false }); assert.strictEqual(result.error, undefined); assert.strictEqual(result.code, code); result = UglifyJS.minify(code); var err = result.error; assert.ok(err instanceof Error); assert.strictEqual(err.stack.split(/\n/)[0], "SyntaxError: a redeclared"); }); }); }); describe("collapse_vars", function() { it("Should not produce invalid AST", function() { var code = [ "function f(a) {", " a = x();", " return a;", "}", "f();", ].join("\n"); var ast = UglifyJS.minify(code, { compress: false, mangle: false, output: { ast: true }, }).ast; assert.strictEqual(ast.TYPE, "Toplevel"); assert.strictEqual(ast.body.length, 2); assert.strictEqual(ast.body[0].TYPE, "Defun"); assert.strictEqual(ast.body[0].body.length, 2); assert.strictEqual(ast.body[0].body[0].TYPE, "SimpleStatement"); var stat = ast.body[0].body[0]; UglifyJS.minify(ast, { compress: { sequences: false }, mangle: false }); assert.ok(stat.body); assert.strictEqual(stat.print_to_string(), "a=x()"); }); }); // rename is disabled on harmony due to expand_names bug in for-of loops if (0) describe("rename", function() { it("Should be repeatable", function() { var code = "!function(x){return x(x)}(y);"; for (var i = 0; i < 2; i++) { assert.strictEqual(UglifyJS.minify(code, { compress: { toplevel: true, }, rename: true, }).code, "var a;(a=y)(a);"); } }); }); it("should work with compress defaults disabled", function() { var code = 'if (true) { console.log(1 + 2); }'; var options = { compress: { defaults: false, } }; assert.strictEqual(UglifyJS.minify(code, options).code, 'if(true)console.log(1+2);'); }); it("should work with compress defaults disabled and evaluate enabled", function() { var code = 'if (true) { console.log(1 + 2); }'; var options = { compress: { defaults: false, evaluate: true, } }; assert.strictEqual(UglifyJS.minify(code, options).code, 'if(true)console.log(3);'); }); describe("AST_RegExp", function() { it("should preserve raw_source", function() { var result = UglifyJS.minify("console.log(/\\/rx\\//ig);", { output: { ast: true, code: true, } }); assert.strictEqual(result.code, "console.log(/\\/rx\\//gi);"); assert.strictEqual(result.ast.body[0].body.args[0].TYPE, "RegExp"); assert.strictEqual(result.ast.body[0].body.args[0].value.toString(), "/\\/rx\\//gi"); assert.strictEqual(result.ast.body[0].body.args[0].value.raw_source, "/\\/rx\\//ig"); }); }); describe("enclose", function() { var code = read("test/input/enclose/input.js"); it("Should work with true", function() { var result = UglifyJS.minify(code, { compress: false, enclose: true, mangle: false, }); if (result.error) throw result.error; assert.strictEqual(result.code, '(function(){function enclose(){console.log("test enclose")}enclose()})();'); }); it("Should work with arg", function() { var result = UglifyJS.minify(code, { compress: false, enclose: 'undefined', mangle: false, }); if (result.error) throw result.error; assert.strictEqual(result.code, '(function(undefined){function enclose(){console.log("test enclose")}enclose()})();'); }); it("Should work with arg:value", function() { var result = UglifyJS.minify(code, { compress: false, enclose: 'window,undefined:window', mangle: false, }); if (result.error) throw result.error; assert.strictEqual(result.code, '(function(window,undefined){function enclose(){console.log("test enclose")}enclose()})(window);'); }); it("Should work alongside wrap", function() { var result = UglifyJS.minify(code, { compress: false, enclose: 'window,undefined:window', mangle: false, wrap: 'exports', }); if (result.error) throw result.error; assert.strictEqual(result.code, '(function(window,undefined){(function(exports){function enclose(){console.log("test enclose")}enclose()})(typeof exports=="undefined"?exports={}:exports)})(window);'); }); }); describe("for-await-of", function() { it("should fail in invalid contexts", function() { [ [ "async function f(x){ for await (e of x) {} }" ], [ "async function f(x){ for await (const e of x) {} }" ], [ "async function f(x){ for await (var e of x) {} }" ], [ "async function f(x){ for await (let e of x) {} }" ], [ "for await(e of x){}", "`for await` invalid in this context" ], [ "for await(const e of x){}", "`for await` invalid in this context" ], [ "for await(const e in x){}", "`for await` invalid in this context" ], [ "for await(;;){}", "`for await` invalid in this context" ], [ "function f(x){ for await (e of x) {} }", "`for await` invalid in this context" ], [ "function f(x){ for await (var e of x) {} }", "`for await` invalid in this context" ], [ "function f(x){ for await (const e of x) {} }", "`for await` invalid in this context" ], [ "function f(x){ for await (let e of x) {} }", "`for await` invalid in this context" ], [ "async function f(x){ for await (const e in x) {} }", "`for await` invalid in this context" ], [ "async function f(x){ for await (;;) {} }", "`for await` invalid in this context" ], ].forEach(function(entry) { var code = entry[0]; var expected_error = entry[1]; var result = UglifyJS.minify(code); assert.strictEqual(result.error && result.error.message, expected_error, JSON.stringify(entry)); }); }); }); }); terser-4.1.2/test/mocha/new.js000066400000000000000000000006241351061312300162140ustar00rootroot00000000000000var assert = require("assert"); var UglifyJS = require("../node"); describe("New", function() { it("Should check target in new.target", function() { assert.throws(function() {UglifyJS.parse("new.blah")}, function(e) { return e instanceof UglifyJS.JS_Parse_Error && e.message === "Unexpected token name «blah», expected name «target»"; }); }); }); terser-4.1.2/test/mocha/number-literal.js000066400000000000000000000013601351061312300203430ustar00rootroot00000000000000var assert = require("assert"); var UglifyJS = require("../node"); describe("Number literals", function () { it("Should not allow legacy octal literals in strict mode", function() { var inputs = [ '"use strict";00;', '"use strict"; var foo = 00;' ]; var test = function(input) { return function() { UglifyJS.parse(input); } } var error = function(e) { return e instanceof UglifyJS.JS_Parse_Error && e.message === "Legacy octal literals are not allowed in strict mode"; }; for (var i = 0; i < inputs.length; i++) { assert.throws(test(inputs[i]), error, inputs[i]); } }); }); terser-4.1.2/test/mocha/object.js000066400000000000000000000102221351061312300166640ustar00rootroot00000000000000var Uglify = require("../node"); var assert = require("assert"); describe("Object", function() { it("Should allow objects to have a methodDefinition as property", function() { var code = "var a = {test() {return true;}}"; assert.equal(Uglify.minify(code, { compress: { arrows: false } }).code, "var a={test(){return!0}};"); }); it("Should not allow objects to use static keywords like in classes", function() { var code = "{static test() {}}"; var parse = function() { Uglify.parse(code); } var expect = function(e) { return e instanceof Uglify.JS_Parse_Error; } assert.throws(parse, expect); }); it("Should not allow objects to have static computed properties like in classes", function() { var code = "var foo = {static [123](){}}"; var parse = function() { console.log(Uglify.parse(code).body[0].body[0]); } var expect = function(e) { return e instanceof Uglify.JS_Parse_Error; } assert.throws(parse, expect); }); it("Should not accept operator tokens as property/getter/setter name", function() { var illegalOperators = [ "++", "--", "+", "-", "!", "~", "&", "|", "^", "*", "/", "%", ">>", "<<", ">>>", "<", ">", "<=", ">=", "==", "===", "!=", "!==", "?", "=", "+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=", "&&", "||" ]; var generator = function() { var results = []; for (var i in illegalOperators) { results.push({ code: "var obj = { get " + illegalOperators[i] + "() { return test; }};", operator: illegalOperators[i], method: "get" }); results.push({ code: "var obj = { set " + illegalOperators[i] + "(value) { test = value}};", operator: illegalOperators[i], method: "set" }); results.push({ code: "var obj = { " + illegalOperators[i] + ': "123"};', operator: illegalOperators[i], method: "key" }); results.push({ code: "var obj = { " + illegalOperators[i] + "(){ return test; }};", operator: illegalOperators[i], method: "method" }); } return results; }; var testCase = function(data) { return function() { Uglify.parse(data.code); }; }; var fail = function(data) { return function (e) { return e instanceof Uglify.JS_Parse_Error && ( e.message === "Unexpected token: operator (" + data.operator + ")" || (e.message === "Unterminated regular expression" && data.operator[0] === "/") || (e.message === "Unexpected token: punc (()" && data.operator === "*") ); }; }; var errorMessage = function(data) { return "Expected but didn't get a syntax error while parsing following line:\n" + data.code; }; var tests = generator(); for (var i = 0; i < tests.length; i++) { var test = tests[i]; assert.throws(testCase(test), fail(test), errorMessage(test)); } }); it("Should be able to use shorthand properties", function() { var ast = Uglify.parse("var foo = 123\nvar obj = {foo: foo}"); assert.strictEqual(ast.print_to_string({ecma: 6}), "var foo=123;var obj={foo};"); }) }); terser-4.1.2/test/mocha/operator.js000066400000000000000000000511721351061312300172620ustar00rootroot00000000000000var assert = require("assert"); var UglifyJS = require("../.."); describe("operator", function() { it("Should handle mixing of ++/+/--/- correctly", function() { this.timeout(10000); function evaluate(exp) { return new Function("var a=1,b=2,c=" + exp + ";return{a:a,b:b,c:c}")(); } [ "", "+", "-" ].forEach(function(p) { [ "++a", "--a", "a", "a--", "a++" ].forEach(function(a) { [ "+", "-" ].forEach(function(o) { [ "", "+", "-" ].forEach(function(q) { [ "++b", "--b", "b", "b--", "b++" ].forEach(function(b) { var exp = [p, a, o, q, b].join(" "); var orig = evaluate(exp); var uglify = evaluate(UglifyJS.parse(exp).print_to_string()); assert.strictEqual(orig.a, uglify.a); assert.strictEqual(orig.b, uglify.b); assert.strictEqual(orig.c, uglify.c); var beautify = evaluate(UglifyJS.parse(exp).print_to_string({ beautify: true })); assert.strictEqual(orig.a, beautify.a); assert.strictEqual(orig.b, beautify.b); assert.strictEqual(orig.c, beautify.c); }); }); }); }); }); }); it("Should remove extraneous spaces", function() { [ [ "++a + ++b", "++a+ ++b" ], [ "++a + --b", "++a+--b" ], [ "++a + b", "++a+b" ], [ "++a + b--", "++a+b--" ], [ "++a + b++", "++a+b++" ], [ "++a + + ++b", "++a+ + ++b" ], [ "++a + + --b", "++a+ +--b" ], [ "++a + + b", "++a+ +b" ], [ "++a + + b--", "++a+ +b--" ], [ "++a + + b++", "++a+ +b++" ], [ "++a + - ++b", "++a+-++b" ], [ "++a + - --b", "++a+- --b" ], [ "++a + - b", "++a+-b" ], [ "++a + - b--", "++a+-b--" ], [ "++a + - b++", "++a+-b++" ], [ "++a - ++b", "++a-++b" ], [ "++a - --b", "++a- --b" ], [ "++a - b", "++a-b" ], [ "++a - b--", "++a-b--" ], [ "++a - b++", "++a-b++" ], [ "++a - + ++b", "++a-+ ++b" ], [ "++a - + --b", "++a-+--b" ], [ "++a - + b", "++a-+b" ], [ "++a - + b--", "++a-+b--" ], [ "++a - + b++", "++a-+b++" ], [ "++a - - ++b", "++a- -++b" ], [ "++a - - --b", "++a- - --b" ], [ "++a - - b", "++a- -b" ], [ "++a - - b--", "++a- -b--" ], [ "++a - - b++", "++a- -b++" ], [ "--a + ++b", "--a+ ++b" ], [ "--a + --b", "--a+--b" ], [ "--a + b", "--a+b" ], [ "--a + b--", "--a+b--" ], [ "--a + b++", "--a+b++" ], [ "--a + + ++b", "--a+ + ++b" ], [ "--a + + --b", "--a+ +--b" ], [ "--a + + b", "--a+ +b" ], [ "--a + + b--", "--a+ +b--" ], [ "--a + + b++", "--a+ +b++" ], [ "--a + - ++b", "--a+-++b" ], [ "--a + - --b", "--a+- --b" ], [ "--a + - b", "--a+-b" ], [ "--a + - b--", "--a+-b--" ], [ "--a + - b++", "--a+-b++" ], [ "--a - ++b", "--a-++b" ], [ "--a - --b", "--a- --b" ], [ "--a - b", "--a-b" ], [ "--a - b--", "--a-b--" ], [ "--a - b++", "--a-b++" ], [ "--a - + ++b", "--a-+ ++b" ], [ "--a - + --b", "--a-+--b" ], [ "--a - + b", "--a-+b" ], [ "--a - + b--", "--a-+b--" ], [ "--a - + b++", "--a-+b++" ], [ "--a - - ++b", "--a- -++b" ], [ "--a - - --b", "--a- - --b" ], [ "--a - - b", "--a- -b" ], [ "--a - - b--", "--a- -b--" ], [ "--a - - b++", "--a- -b++" ], [ "a + ++b", "a+ ++b" ], [ "a + --b", "a+--b" ], [ "a + b", "a+b" ], [ "a + b--", "a+b--" ], [ "a + b++", "a+b++" ], [ "a + + ++b", "a+ + ++b" ], [ "a + + --b", "a+ +--b" ], [ "a + + b", "a+ +b" ], [ "a + + b--", "a+ +b--" ], [ "a + + b++", "a+ +b++" ], [ "a + - ++b", "a+-++b" ], [ "a + - --b", "a+- --b" ], [ "a + - b", "a+-b" ], [ "a + - b--", "a+-b--" ], [ "a + - b++", "a+-b++" ], [ "a - ++b", "a-++b" ], [ "a - --b", "a- --b" ], [ "a - b", "a-b" ], [ "a - b--", "a-b--" ], [ "a - b++", "a-b++" ], [ "a - + ++b", "a-+ ++b" ], [ "a - + --b", "a-+--b" ], [ "a - + b", "a-+b" ], [ "a - + b--", "a-+b--" ], [ "a - + b++", "a-+b++" ], [ "a - - ++b", "a- -++b" ], [ "a - - --b", "a- - --b" ], [ "a - - b", "a- -b" ], [ "a - - b--", "a- -b--" ], [ "a - - b++", "a- -b++" ], [ "a-- + ++b", "a--+ ++b" ], [ "a-- + --b", "a--+--b" ], [ "a-- + b", "a--+b" ], [ "a-- + b--", "a--+b--" ], [ "a-- + b++", "a--+b++" ], [ "a-- + + ++b", "a--+ + ++b" ], [ "a-- + + --b", "a--+ +--b" ], [ "a-- + + b", "a--+ +b" ], [ "a-- + + b--", "a--+ +b--" ], [ "a-- + + b++", "a--+ +b++" ], [ "a-- + - ++b", "a--+-++b" ], [ "a-- + - --b", "a--+- --b" ], [ "a-- + - b", "a--+-b" ], [ "a-- + - b--", "a--+-b--" ], [ "a-- + - b++", "a--+-b++" ], [ "a-- - ++b", "a---++b" ], [ "a-- - --b", "a--- --b" ], [ "a-- - b", "a---b" ], [ "a-- - b--", "a---b--" ], [ "a-- - b++", "a---b++" ], [ "a-- - + ++b", "a---+ ++b" ], [ "a-- - + --b", "a---+--b" ], [ "a-- - + b", "a---+b" ], [ "a-- - + b--", "a---+b--" ], [ "a-- - + b++", "a---+b++" ], [ "a-- - - ++b", "a--- -++b" ], [ "a-- - - --b", "a--- - --b" ], [ "a-- - - b", "a--- -b" ], [ "a-- - - b--", "a--- -b--" ], [ "a-- - - b++", "a--- -b++" ], [ "a++ + ++b", "a+++ ++b" ], [ "a++ + --b", "a+++--b" ], [ "a++ + b", "a+++b" ], [ "a++ + b--", "a+++b--" ], [ "a++ + b++", "a+++b++" ], [ "a++ + + ++b", "a+++ + ++b" ], [ "a++ + + --b", "a+++ +--b" ], [ "a++ + + b", "a+++ +b" ], [ "a++ + + b--", "a+++ +b--" ], [ "a++ + + b++", "a+++ +b++" ], [ "a++ + - ++b", "a+++-++b" ], [ "a++ + - --b", "a+++- --b" ], [ "a++ + - b", "a+++-b" ], [ "a++ + - b--", "a+++-b--" ], [ "a++ + - b++", "a+++-b++" ], [ "a++ - ++b", "a++-++b" ], [ "a++ - --b", "a++- --b" ], [ "a++ - b", "a++-b" ], [ "a++ - b--", "a++-b--" ], [ "a++ - b++", "a++-b++" ], [ "a++ - + ++b", "a++-+ ++b" ], [ "a++ - + --b", "a++-+--b" ], [ "a++ - + b", "a++-+b" ], [ "a++ - + b--", "a++-+b--" ], [ "a++ - + b++", "a++-+b++" ], [ "a++ - - ++b", "a++- -++b" ], [ "a++ - - --b", "a++- - --b" ], [ "a++ - - b", "a++- -b" ], [ "a++ - - b--", "a++- -b--" ], [ "a++ - - b++", "a++- -b++" ], [ "+ ++a + ++b", "+ ++a+ ++b" ], [ "+ ++a + --b", "+ ++a+--b" ], [ "+ ++a + b", "+ ++a+b" ], [ "+ ++a + b--", "+ ++a+b--" ], [ "+ ++a + b++", "+ ++a+b++" ], [ "+ ++a + + ++b", "+ ++a+ + ++b" ], [ "+ ++a + + --b", "+ ++a+ +--b" ], [ "+ ++a + + b", "+ ++a+ +b" ], [ "+ ++a + + b--", "+ ++a+ +b--" ], [ "+ ++a + + b++", "+ ++a+ +b++" ], [ "+ ++a + - ++b", "+ ++a+-++b" ], [ "+ ++a + - --b", "+ ++a+- --b" ], [ "+ ++a + - b", "+ ++a+-b" ], [ "+ ++a + - b--", "+ ++a+-b--" ], [ "+ ++a + - b++", "+ ++a+-b++" ], [ "+ ++a - ++b", "+ ++a-++b" ], [ "+ ++a - --b", "+ ++a- --b" ], [ "+ ++a - b", "+ ++a-b" ], [ "+ ++a - b--", "+ ++a-b--" ], [ "+ ++a - b++", "+ ++a-b++" ], [ "+ ++a - + ++b", "+ ++a-+ ++b" ], [ "+ ++a - + --b", "+ ++a-+--b" ], [ "+ ++a - + b", "+ ++a-+b" ], [ "+ ++a - + b--", "+ ++a-+b--" ], [ "+ ++a - + b++", "+ ++a-+b++" ], [ "+ ++a - - ++b", "+ ++a- -++b" ], [ "+ ++a - - --b", "+ ++a- - --b" ], [ "+ ++a - - b", "+ ++a- -b" ], [ "+ ++a - - b--", "+ ++a- -b--" ], [ "+ ++a - - b++", "+ ++a- -b++" ], [ "+ --a + ++b", "+--a+ ++b" ], [ "+ --a + --b", "+--a+--b" ], [ "+ --a + b", "+--a+b" ], [ "+ --a + b--", "+--a+b--" ], [ "+ --a + b++", "+--a+b++" ], [ "+ --a + + ++b", "+--a+ + ++b" ], [ "+ --a + + --b", "+--a+ +--b" ], [ "+ --a + + b", "+--a+ +b" ], [ "+ --a + + b--", "+--a+ +b--" ], [ "+ --a + + b++", "+--a+ +b++" ], [ "+ --a + - ++b", "+--a+-++b" ], [ "+ --a + - --b", "+--a+- --b" ], [ "+ --a + - b", "+--a+-b" ], [ "+ --a + - b--", "+--a+-b--" ], [ "+ --a + - b++", "+--a+-b++" ], [ "+ --a - ++b", "+--a-++b" ], [ "+ --a - --b", "+--a- --b" ], [ "+ --a - b", "+--a-b" ], [ "+ --a - b--", "+--a-b--" ], [ "+ --a - b++", "+--a-b++" ], [ "+ --a - + ++b", "+--a-+ ++b" ], [ "+ --a - + --b", "+--a-+--b" ], [ "+ --a - + b", "+--a-+b" ], [ "+ --a - + b--", "+--a-+b--" ], [ "+ --a - + b++", "+--a-+b++" ], [ "+ --a - - ++b", "+--a- -++b" ], [ "+ --a - - --b", "+--a- - --b" ], [ "+ --a - - b", "+--a- -b" ], [ "+ --a - - b--", "+--a- -b--" ], [ "+ --a - - b++", "+--a- -b++" ], [ "+ a + ++b", "+a+ ++b" ], [ "+ a + --b", "+a+--b" ], [ "+ a + b", "+a+b" ], [ "+ a + b--", "+a+b--" ], [ "+ a + b++", "+a+b++" ], [ "+ a + + ++b", "+a+ + ++b" ], [ "+ a + + --b", "+a+ +--b" ], [ "+ a + + b", "+a+ +b" ], [ "+ a + + b--", "+a+ +b--" ], [ "+ a + + b++", "+a+ +b++" ], [ "+ a + - ++b", "+a+-++b" ], [ "+ a + - --b", "+a+- --b" ], [ "+ a + - b", "+a+-b" ], [ "+ a + - b--", "+a+-b--" ], [ "+ a + - b++", "+a+-b++" ], [ "+ a - ++b", "+a-++b" ], [ "+ a - --b", "+a- --b" ], [ "+ a - b", "+a-b" ], [ "+ a - b--", "+a-b--" ], [ "+ a - b++", "+a-b++" ], [ "+ a - + ++b", "+a-+ ++b" ], [ "+ a - + --b", "+a-+--b" ], [ "+ a - + b", "+a-+b" ], [ "+ a - + b--", "+a-+b--" ], [ "+ a - + b++", "+a-+b++" ], [ "+ a - - ++b", "+a- -++b" ], [ "+ a - - --b", "+a- - --b" ], [ "+ a - - b", "+a- -b" ], [ "+ a - - b--", "+a- -b--" ], [ "+ a - - b++", "+a- -b++" ], [ "+ a-- + ++b", "+a--+ ++b" ], [ "+ a-- + --b", "+a--+--b" ], [ "+ a-- + b", "+a--+b" ], [ "+ a-- + b--", "+a--+b--" ], [ "+ a-- + b++", "+a--+b++" ], [ "+ a-- + + ++b", "+a--+ + ++b" ], [ "+ a-- + + --b", "+a--+ +--b" ], [ "+ a-- + + b", "+a--+ +b" ], [ "+ a-- + + b--", "+a--+ +b--" ], [ "+ a-- + + b++", "+a--+ +b++" ], [ "+ a-- + - ++b", "+a--+-++b" ], [ "+ a-- + - --b", "+a--+- --b" ], [ "+ a-- + - b", "+a--+-b" ], [ "+ a-- + - b--", "+a--+-b--" ], [ "+ a-- + - b++", "+a--+-b++" ], [ "+ a-- - ++b", "+a---++b" ], [ "+ a-- - --b", "+a--- --b" ], [ "+ a-- - b", "+a---b" ], [ "+ a-- - b--", "+a---b--" ], [ "+ a-- - b++", "+a---b++" ], [ "+ a-- - + ++b", "+a---+ ++b" ], [ "+ a-- - + --b", "+a---+--b" ], [ "+ a-- - + b", "+a---+b" ], [ "+ a-- - + b--", "+a---+b--" ], [ "+ a-- - + b++", "+a---+b++" ], [ "+ a-- - - ++b", "+a--- -++b" ], [ "+ a-- - - --b", "+a--- - --b" ], [ "+ a-- - - b", "+a--- -b" ], [ "+ a-- - - b--", "+a--- -b--" ], [ "+ a-- - - b++", "+a--- -b++" ], [ "+ a++ + ++b", "+a+++ ++b" ], [ "+ a++ + --b", "+a+++--b" ], [ "+ a++ + b", "+a+++b" ], [ "+ a++ + b--", "+a+++b--" ], [ "+ a++ + b++", "+a+++b++" ], [ "+ a++ + + ++b", "+a+++ + ++b" ], [ "+ a++ + + --b", "+a+++ +--b" ], [ "+ a++ + + b", "+a+++ +b" ], [ "+ a++ + + b--", "+a+++ +b--" ], [ "+ a++ + + b++", "+a+++ +b++" ], [ "+ a++ + - ++b", "+a+++-++b" ], [ "+ a++ + - --b", "+a+++- --b" ], [ "+ a++ + - b", "+a+++-b" ], [ "+ a++ + - b--", "+a+++-b--" ], [ "+ a++ + - b++", "+a+++-b++" ], [ "+ a++ - ++b", "+a++-++b" ], [ "+ a++ - --b", "+a++- --b" ], [ "+ a++ - b", "+a++-b" ], [ "+ a++ - b--", "+a++-b--" ], [ "+ a++ - b++", "+a++-b++" ], [ "+ a++ - + ++b", "+a++-+ ++b" ], [ "+ a++ - + --b", "+a++-+--b" ], [ "+ a++ - + b", "+a++-+b" ], [ "+ a++ - + b--", "+a++-+b--" ], [ "+ a++ - + b++", "+a++-+b++" ], [ "+ a++ - - ++b", "+a++- -++b" ], [ "+ a++ - - --b", "+a++- - --b" ], [ "+ a++ - - b", "+a++- -b" ], [ "+ a++ - - b--", "+a++- -b--" ], [ "+ a++ - - b++", "+a++- -b++" ], [ "- ++a + ++b", "-++a+ ++b" ], [ "- ++a + --b", "-++a+--b" ], [ "- ++a + b", "-++a+b" ], [ "- ++a + b--", "-++a+b--" ], [ "- ++a + b++", "-++a+b++" ], [ "- ++a + + ++b", "-++a+ + ++b" ], [ "- ++a + + --b", "-++a+ +--b" ], [ "- ++a + + b", "-++a+ +b" ], [ "- ++a + + b--", "-++a+ +b--" ], [ "- ++a + + b++", "-++a+ +b++" ], [ "- ++a + - ++b", "-++a+-++b" ], [ "- ++a + - --b", "-++a+- --b" ], [ "- ++a + - b", "-++a+-b" ], [ "- ++a + - b--", "-++a+-b--" ], [ "- ++a + - b++", "-++a+-b++" ], [ "- ++a - ++b", "-++a-++b" ], [ "- ++a - --b", "-++a- --b" ], [ "- ++a - b", "-++a-b" ], [ "- ++a - b--", "-++a-b--" ], [ "- ++a - b++", "-++a-b++" ], [ "- ++a - + ++b", "-++a-+ ++b" ], [ "- ++a - + --b", "-++a-+--b" ], [ "- ++a - + b", "-++a-+b" ], [ "- ++a - + b--", "-++a-+b--" ], [ "- ++a - + b++", "-++a-+b++" ], [ "- ++a - - ++b", "-++a- -++b" ], [ "- ++a - - --b", "-++a- - --b" ], [ "- ++a - - b", "-++a- -b" ], [ "- ++a - - b--", "-++a- -b--" ], [ "- ++a - - b++", "-++a- -b++" ], [ "- --a + ++b", "- --a+ ++b" ], [ "- --a + --b", "- --a+--b" ], [ "- --a + b", "- --a+b" ], [ "- --a + b--", "- --a+b--" ], [ "- --a + b++", "- --a+b++" ], [ "- --a + + ++b", "- --a+ + ++b" ], [ "- --a + + --b", "- --a+ +--b" ], [ "- --a + + b", "- --a+ +b" ], [ "- --a + + b--", "- --a+ +b--" ], [ "- --a + + b++", "- --a+ +b++" ], [ "- --a + - ++b", "- --a+-++b" ], [ "- --a + - --b", "- --a+- --b" ], [ "- --a + - b", "- --a+-b" ], [ "- --a + - b--", "- --a+-b--" ], [ "- --a + - b++", "- --a+-b++" ], [ "- --a - ++b", "- --a-++b" ], [ "- --a - --b", "- --a- --b" ], [ "- --a - b", "- --a-b" ], [ "- --a - b--", "- --a-b--" ], [ "- --a - b++", "- --a-b++" ], [ "- --a - + ++b", "- --a-+ ++b" ], [ "- --a - + --b", "- --a-+--b" ], [ "- --a - + b", "- --a-+b" ], [ "- --a - + b--", "- --a-+b--" ], [ "- --a - + b++", "- --a-+b++" ], [ "- --a - - ++b", "- --a- -++b" ], [ "- --a - - --b", "- --a- - --b" ], [ "- --a - - b", "- --a- -b" ], [ "- --a - - b--", "- --a- -b--" ], [ "- --a - - b++", "- --a- -b++" ], [ "- a + ++b", "-a+ ++b" ], [ "- a + --b", "-a+--b" ], [ "- a + b", "-a+b" ], [ "- a + b--", "-a+b--" ], [ "- a + b++", "-a+b++" ], [ "- a + + ++b", "-a+ + ++b" ], [ "- a + + --b", "-a+ +--b" ], [ "- a + + b", "-a+ +b" ], [ "- a + + b--", "-a+ +b--" ], [ "- a + + b++", "-a+ +b++" ], [ "- a + - ++b", "-a+-++b" ], [ "- a + - --b", "-a+- --b" ], [ "- a + - b", "-a+-b" ], [ "- a + - b--", "-a+-b--" ], [ "- a + - b++", "-a+-b++" ], [ "- a - ++b", "-a-++b" ], [ "- a - --b", "-a- --b" ], [ "- a - b", "-a-b" ], [ "- a - b--", "-a-b--" ], [ "- a - b++", "-a-b++" ], [ "- a - + ++b", "-a-+ ++b" ], [ "- a - + --b", "-a-+--b" ], [ "- a - + b", "-a-+b" ], [ "- a - + b--", "-a-+b--" ], [ "- a - + b++", "-a-+b++" ], [ "- a - - ++b", "-a- -++b" ], [ "- a - - --b", "-a- - --b" ], [ "- a - - b", "-a- -b" ], [ "- a - - b--", "-a- -b--" ], [ "- a - - b++", "-a- -b++" ], [ "- a-- + ++b", "-a--+ ++b" ], [ "- a-- + --b", "-a--+--b" ], [ "- a-- + b", "-a--+b" ], [ "- a-- + b--", "-a--+b--" ], [ "- a-- + b++", "-a--+b++" ], [ "- a-- + + ++b", "-a--+ + ++b" ], [ "- a-- + + --b", "-a--+ +--b" ], [ "- a-- + + b", "-a--+ +b" ], [ "- a-- + + b--", "-a--+ +b--" ], [ "- a-- + + b++", "-a--+ +b++" ], [ "- a-- + - ++b", "-a--+-++b" ], [ "- a-- + - --b", "-a--+- --b" ], [ "- a-- + - b", "-a--+-b" ], [ "- a-- + - b--", "-a--+-b--" ], [ "- a-- + - b++", "-a--+-b++" ], [ "- a-- - ++b", "-a---++b" ], [ "- a-- - --b", "-a--- --b" ], [ "- a-- - b", "-a---b" ], [ "- a-- - b--", "-a---b--" ], [ "- a-- - b++", "-a---b++" ], [ "- a-- - + ++b", "-a---+ ++b" ], [ "- a-- - + --b", "-a---+--b" ], [ "- a-- - + b", "-a---+b" ], [ "- a-- - + b--", "-a---+b--" ], [ "- a-- - + b++", "-a---+b++" ], [ "- a-- - - ++b", "-a--- -++b" ], [ "- a-- - - --b", "-a--- - --b" ], [ "- a-- - - b", "-a--- -b" ], [ "- a-- - - b--", "-a--- -b--" ], [ "- a-- - - b++", "-a--- -b++" ], [ "- a++ + ++b", "-a+++ ++b" ], [ "- a++ + --b", "-a+++--b" ], [ "- a++ + b", "-a+++b" ], [ "- a++ + b--", "-a+++b--" ], [ "- a++ + b++", "-a+++b++" ], [ "- a++ + + ++b", "-a+++ + ++b" ], [ "- a++ + + --b", "-a+++ +--b" ], [ "- a++ + + b", "-a+++ +b" ], [ "- a++ + + b--", "-a+++ +b--" ], [ "- a++ + + b++", "-a+++ +b++" ], [ "- a++ + - ++b", "-a+++-++b" ], [ "- a++ + - --b", "-a+++- --b" ], [ "- a++ + - b", "-a+++-b" ], [ "- a++ + - b--", "-a+++-b--" ], [ "- a++ + - b++", "-a+++-b++" ], [ "- a++ - ++b", "-a++-++b" ], [ "- a++ - --b", "-a++- --b" ], [ "- a++ - b", "-a++-b" ], [ "- a++ - b--", "-a++-b--" ], [ "- a++ - b++", "-a++-b++" ], [ "- a++ - + ++b", "-a++-+ ++b" ], [ "- a++ - + --b", "-a++-+--b" ], [ "- a++ - + b", "-a++-+b" ], [ "- a++ - + b--", "-a++-+b--" ], [ "- a++ - + b++", "-a++-+b++" ], [ "- a++ - - ++b", "-a++- -++b" ], [ "- a++ - - --b", "-a++- - --b" ], [ "- a++ - - b", "-a++- -b" ], [ "- a++ - - b--", "-a++- -b--" ], [ "- a++ - - b++", "-a++- -b++" ], ].forEach(function(exp) { assert.strictEqual(UglifyJS.parse(exp[0]).print_to_string(), exp[1] + ";"); }); }); }); terser-4.1.2/test/mocha/parentheses.js000066400000000000000000000067541351061312300177560ustar00rootroot00000000000000var assert = require("assert"); var UglifyJS = require("../.."); describe("parentheses", function() { it("Should add trailing parentheses for new expressions with zero arguments in beautify mode", function() { var tests = [ "new x(1);", "new x;", "new new x;", "new (function(foo){this.foo=foo;})(1);", "new (function(foo){this.foo=foo;})();", "new (function test(foo){this.foo=foo;})(1);", "new (function test(foo){this.foo=foo;})();", "new true;", "new (0);", "new (!0);", "new (bar = function(foo) {this.foo=foo;})(123);", "new (bar = function(foo) {this.foo=foo;})();" ]; var expected = [ "new x(1);", "new x();", "new new x()();", "new function(foo) {\n this.foo = foo;\n}(1);", "new function(foo) {\n this.foo = foo;\n}();", "new function test(foo) {\n this.foo = foo;\n}(1);", "new function test(foo) {\n this.foo = foo;\n}();", "new true();", "new 0();", "new (!0)();", "new (bar = function(foo) {\n this.foo = foo;\n})(123);", "new (bar = function(foo) {\n this.foo = foo;\n})();" ]; for (var i = 0; i < tests.length; i++) { assert.strictEqual( UglifyJS.minify(tests[i], { output: {beautify: true}, compress: false, mangle: false }).code, expected[i] ); } }); it("Should not add trailing parentheses for new expressions with zero arguments in non-beautify mode", function() { var tests = [ "new x(1);", "new x;", "new new x;", "new (function(foo){this.foo=foo;})(1);", "new (function(foo){this.foo=foo;})();", "new (function test(foo){this.foo=foo;})(1);", "new (function test(foo){this.foo=foo;})();", "new true;", "new (0);", "new (!0);", "new (bar = function(foo) {this.foo=foo;})(123);", "new (bar = function(foo) {this.foo=foo;})();" ]; var expected = [ "new x(1);", "new x;", "new(new x);", "new function(foo){this.foo=foo}(1);", "new function(foo){this.foo=foo};", "new function test(foo){this.foo=foo}(1);", "new function test(foo){this.foo=foo};", "new true;", "new 0;", "new(!0);", "new(bar=function(foo){this.foo=foo})(123);", "new(bar=function(foo){this.foo=foo});" ]; for (var i = 0; i < tests.length; i++) { assert.strictEqual( UglifyJS.minify(tests[i], { output: {beautify: false}, compress: false, mangle: false }).code, expected[i] ); } }); it("Should compress leading parenthesis with reasonable performance", function() { var code = [ "({}?0:1)&&x();", "(function(){}).name;", ]; for (var i = 9; --i >= 0;) { code = code.concat(code); } code = code.join(""); var result = UglifyJS.minify(code, { compress: false, mangle: false, }); }); }) terser-4.1.2/test/mocha/release.js000066400000000000000000000030011351061312300170330ustar00rootroot00000000000000var assert = require("assert"); var semver = require("semver"); var spawn = require("child_process").spawn; if (!process.env.UGLIFYJS_TEST_ALL) return; function run(command, args, done) { spawn(command, args, { stdio: [ "ignore", 1, 2 ] }).on("exit", function(code) { assert.strictEqual(code, 0); done(); }); } if (semver.satisfies(process.version, "6")) return; describe("test/benchmark.js", function() { this.timeout(10 * 60 * 1000); [ "-b", "-b braces", "-m", "-mc passes=3", "-mc passes=3,toplevel", "-mc passes=3,unsafe", "-mc keep_fargs=false,passes=3", "-mc keep_fargs=false,passes=3,pure_getters,unsafe,unsafe_comps,unsafe_math,unsafe_proto", ].forEach(function(options) { it("Should pass with options " + options, function(done) { var args = options.split(/ /); args.unshift("test/benchmark.js"); run(process.argv[0], args, done); }); }); }); describe("test/jetstream.js", function() { this.timeout(20 * 60 * 1000); [ "-mc", "-mc keep_fargs=false,passes=3,pure_getters,unsafe,unsafe_comps,unsafe_math,unsafe_proto", ].forEach(function(options) { it("Should pass with options " + options, function(done) { var args = options.split(/ /); args.unshift("test/jetstream.js"); args.push("-b", "beautify=false,webkit"); run(process.argv[0], args, done); }); }); }); terser-4.1.2/test/mocha/sourcemaps.js000066400000000000000000000246371351061312300176160ustar00rootroot00000000000000var assert = require("assert"); var readFileSync = require("fs").readFileSync; var SourceMapConsumer = require("source-map").SourceMapConsumer; var {assertCodeWithInlineMapEquals} = require('./utils'); var UglifyJS = require("../.."); function read(path) { return readFileSync(path, "utf8"); } function source_map(code) { return JSON.parse(UglifyJS.minify(code, { compress: false, mangle: false, sourceMap: true, }).map); } function get_map() { return { "version": 3, "sources": ["index.js"], "names": [], "mappings": ";;AAAA,IAAI,MAAM,SAAN,GAAM;AAAA,SAAK,SAAS,CAAd;AAAA,CAAV;AACA,QAAQ,GAAR,CAAY,IAAI,KAAJ,CAAZ", "file": "bundle.js", "sourcesContent": ["let foo = x => \"foo \" + x;\nconsole.log(foo(\"bar\"));"] }; } function get_sections_map() { return { "version": 3, "file": "bundle-outer.js", "sections": [ { "offset": { "line": 0, "column": 0 }, "map": get_map() } ] }; } function prepare_map(sourceMap) { var code = [ '"use strict";', "", "var foo = function foo(x) {", ' return "foo " + x;', "};", 'console.log(foo("bar"));', "", "//# sourceMappingURL=bundle.js.map", ].join("\n"); var result = UglifyJS.minify(code, { sourceMap: { content: sourceMap, includeSources: true, } }); if (result.error) throw result.error; return new SourceMapConsumer(result.map); } describe("sourcemaps", function() { it("Should give correct version", function() { var map = source_map("var x = 1 + 1;"); assert.strictEqual(map.version, 3); assert.deepEqual(map.names, [ "x" ]); }); it("Should give correct names", function() { var map = source_map([ "({", " get enabled() {", " return 3;", " },", " set enabled(x) {", " ;", " }", "});", ].join("\n")); assert.deepEqual(map.names, [ "enabled", "x" ]); }); it("Should mark array/object literals", function() { var result = UglifyJS.minify([ "var obj = {};", "obj.wat([]);", ].join("\n"), { sourceMap: true, toplevel: true, }); if (result.error) throw result.error; assert.strictEqual(result.code, "({}).wat([]);"); assert.strictEqual(result.map, '{"version":3,"sources":["0"],"names":["wat"],"mappings":"CAAU,IACNA,IAAI"}'); }); it("Should mark class literals", function() { var result = UglifyJS.minify([ "class bar {};", "var obj = class {};", "obj.wat(bar);", ].join("\n"), { sourceMap: true, toplevel: true, }); if (result.error) throw result.error; assert.strictEqual(result.code, "(class{}).wat(class{});"); assert.strictEqual(result.map, '{"version":3,"sources":["0"],"names":["wat"],"mappings":"CACU,SACNA,IAFJ"}'); }); it("Should give correct sourceRoot", function() { var code = "console.log(42);"; var result = UglifyJS.minify(code, { sourceMap: { root: "//foo.bar/", }, }); if (result.error) throw result.error; assert.strictEqual(result.code, code); assert.strictEqual(result.map, '{"version":3,"sources":["0"],"names":["console","log"],"mappings":"AAAAA,QAAQC,IAAI","sourceRoot":"//foo.bar/"}'); }); describe("inSourceMap", function() { it("Should read the given string filename correctly when sourceMapIncludeSources is enabled", function() { var result = UglifyJS.minify(read("./test/input/issue-1236/simple.js"), { sourceMap: { content: read("./test/input/issue-1236/simple.js.map"), filename: "simple.min.js", includeSources: true } }); if (result.error) throw result.error; var map = JSON.parse(result.map); assert.equal(map.file, "simple.min.js"); assert.equal(map.sourcesContent.length, 1); assert.equal(map.sourcesContent[0], 'let foo = x => "foo " + x;\nconsole.log(foo("bar"));'); }); it("Should process inline source map", function() { var result = UglifyJS.minify(read("./test/input/issue-520/input.js"), { compress: { toplevel: true }, sourceMap: { content: "inline", includeSources: true, url: "inline" } }); if (result.error) throw result.error; assertCodeWithInlineMapEquals(result.code + "\n", readFileSync("test/input/issue-520/output.js", "utf8")); }); it("Should warn for missing inline source map", function() { var warn_function = UglifyJS.AST_Node.warn_function; var warnings = []; UglifyJS.AST_Node.warn_function = function(txt) { warnings.push(txt); }; try { var result = UglifyJS.minify(read("./test/input/issue-1323/sample.js"), { mangle: false, sourceMap: { content: "inline" } }); assert.strictEqual(result.code, "var bar=function(bar){return bar};"); assert.strictEqual(warnings.length, 1); assert.strictEqual(warnings[0], "inline source map not found"); } finally { UglifyJS.AST_Node.warn_function = warn_function; } }); }); describe("sourceMapInline", function() { it("Should append source map to output js when sourceMapInline is enabled", function() { var result = UglifyJS.minify('var a = function(foo) { return foo; };', { sourceMap: { url: "inline" } }); if (result.error) throw result.error; var code = result.code; assertCodeWithInlineMapEquals(code, "var a=function(n){return n};\n" + "//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIjAiXSwibmFtZXMiOlsiYSIsImZvbyJdLCJtYXBwaW5ncyI6IkFBQUEsSUFBSUEsRUFBSSxTQUFTQyxHQUFPLE9BQU9BIn0="); }); it("Should not append source map to output js when sourceMapInline is not enabled", function() { var result = UglifyJS.minify('var a = function(foo) { return foo; };'); if (result.error) throw result.error; var code = result.code; assertCodeWithInlineMapEquals(code, "var a=function(n){return n};"); }); it("Should work with max_line_len", function() { var result = UglifyJS.minify(read("./test/input/issue-505/input.js"), { compress: { directives: false, }, output: { max_line_len: 20 }, sourceMap: { url: "inline" } }); if (result.error) throw result.error; assertCodeWithInlineMapEquals(result.code, read("./test/input/issue-505/output.js")); }); it("Should work with unicode characters", function() { var code = [ "var tëst = '→unicøde←';", "alert(tëst);", ].join("\n"); var result = UglifyJS.minify(code, { sourceMap: { includeSources: true, url: "inline", } }); if (result.error) throw result.error; var map = JSON.parse(result.map); assert.strictEqual(map.sourcesContent.length, 1); assert.strictEqual(map.sourcesContent[0], code); var encoded = result.code.slice(result.code.lastIndexOf(",") + 1); map = JSON.parse(UglifyJS.to_ascii(encoded).toString()); assert.strictEqual(map.sourcesContent.length, 1); assert.strictEqual(map.sourcesContent[0], code); result = UglifyJS.minify(result.code, { sourceMap: { content: "inline", includeSources: true, } }); if (result.error) throw result.error; map = JSON.parse(result.map); assert.strictEqual(map.names.length, 2); assert.strictEqual(map.names[0], "tëst"); assert.strictEqual(map.names[1], "alert"); }); }); describe("input sourcemaps", function() { it("Should copy over original sourcesContent", function() { var orig = get_map(); var map = prepare_map(orig); assert.equal(map.sourceContentFor("index.js"), orig.sourcesContent[0]); }); it("Should copy over original sourcesContent for section sourcemaps", function() { var orig = get_sections_map(); var map = prepare_map(orig); assert.equal(map.sourceContentFor("index.js"), orig.sections[0].map.sourcesContent[0]); }); it("Should copy sourcesContent if sources are relative", function() { var relativeMap = get_map(); relativeMap.sources = ['./index.js']; var map = prepare_map(relativeMap); assert.notEqual(map.sourcesContent, null); assert.equal(map.sourcesContent.length, 1); assert.equal(map.sourceContentFor("index.js"), relativeMap.sourcesContent[0]); }); it("Should not have invalid mappings from inputSourceMap", function() { var map = prepare_map(get_map()); // The original source has only 2 lines, check that mappings don't have more lines var msg = "Mapping should not have higher line number than the original file had"; map.eachMapping(function(mapping) { assert.ok(mapping.originalLine <= 2, msg); }); map.allGeneratedPositionsFor({ source: "index.js", line: 1, column: 1 }).forEach(function(pos) { assert.ok(pos.line <= 2, msg); }); }); }); }); terser-4.1.2/test/mocha/spidermonkey.js000066400000000000000000000120461351061312300201350ustar00rootroot00000000000000var assert = require("assert"); var fs = require("fs"); var acorn = require("acorn"); var escodegen = require("escodegen"); var UglifyJS = require("../.."); describe("spidermonkey export/import sanity test", function() { it("Should judge between directives and strings correctly on import", function() { var tests = [ { input: '"use strict";;"use sloppy"', directives: 1, strings: 1 }, { input: ';"use strict"', directives: 0, strings: 1 }, { input: '"use strict"; "use something else";', directives: 2, strings: 0 }, { input: 'function foo() {"use strict";;"use sloppy" }', directives: 1, strings: 1 }, { input: 'function foo() {;"use strict" }', directives: 0, strings: 1 }, { input: 'function foo() {"use strict"; "use something else"; }', directives: 2, strings: 0 }, { input: 'var foo = function() {"use strict";;"use sloppy" }', directives: 1, strings: 1 }, { input: 'var foo = function() {;"use strict" }', directives: 0, strings: 1 }, { input: 'var foo = function() {"use strict"; "use something else"; }', directives: 2, strings: 0 }, { input: '{"use strict";;"use sloppy" }', directives: 0, strings: 2 }, { input: '{;"use strict" }', directives: 0, strings: 1 }, { input: '{"use strict"; "use something else"; }', directives: 0, strings: 2 } ]; var counter_directives; var counter_strings; var checkWalker = new UglifyJS.TreeWalker(function(node, descend) { if (node instanceof UglifyJS.AST_String) { counter_strings++; } else if (node instanceof UglifyJS.AST_Directive) { counter_directives++; } }); for (var i = 0; i < tests.length; i++) { counter_directives = 0; counter_strings = 0; var ast = UglifyJS.parse(tests[i].input); var moz_ast = ast.to_mozilla_ast(); var from_moz_ast = UglifyJS.AST_Node.from_mozilla_ast(moz_ast); from_moz_ast.walk(checkWalker); assert.strictEqual(counter_directives, tests[i].directives, "Directives count mismatch for test " + tests[i].input); assert.strictEqual(counter_strings, tests[i].strings, "String count mismatch for test " + tests[i].input); } }); it("should output and parse ES6 code correctly", function() { var code = fs.readFileSync("test/input/spidermonkey/input.js", "utf-8"); var uglify_ast = UglifyJS.parse(code); var moz_ast = uglify_ast.to_mozilla_ast(); var from_moz_ast = UglifyJS.AST_Node.from_mozilla_ast(moz_ast); assert.strictEqual( from_moz_ast.print_to_string(), uglify_ast.print_to_string() ); }); it("should be capable of importing from acorn", function() { var code = fs.readFileSync("test/input/spidermonkey/input.js", "utf-8"); var uglify_ast = UglifyJS.parse(code); var moz_ast = acorn.parse(code, {sourceType: 'module', ecmaVersion: 9}); var from_moz_ast = UglifyJS.AST_Node.from_mozilla_ast(moz_ast); assert.strictEqual( from_moz_ast.print_to_string(), uglify_ast.print_to_string() ); }); it("should correctly minify AST from from_moz_ast with default function parameter", () => { const code = "function run(x = 2){}"; const acornAst = acorn.parse(code, { locations: true }); const terserAst = UglifyJS.AST_Node.from_mozilla_ast(acornAst); const result = UglifyJS.minify(terserAst); assert.strictEqual( result.code, "function run(x=2){}" ); }); it("should produce an AST compatible with escodegen", function() { var code = fs.readFileSync("test/input/spidermonkey/input.js", "utf-8"); var uglify_ast = UglifyJS.parse(code); var moz_ast = uglify_ast.to_mozilla_ast(); var generated = escodegen.generate(moz_ast) .replace(/\[object Object\].\[object Object\]/g, "new.target"); // escodegen issue var parsed = acorn.parse(generated, { sourceType: "module", ecmaVersion: 9 }); assert.strictEqual( UglifyJS.AST_Node.from_mozilla_ast(parsed).print_to_string(), uglify_ast.print_to_string() ); }); }); terser-4.1.2/test/mocha/string-literal.js000066400000000000000000000074341351061312300203710ustar00rootroot00000000000000var assert = require("assert"); var UglifyJS = require("../node"); describe("String literals", function() { it("Should throw syntax error if a string literal contains a newline", function() { var inputs = [ "'\n'", "'\r'", '"\r\n"' ]; var test = function(input) { return function() { var ast = UglifyJS.parse(input); }; }; var error = function(e) { return e instanceof UglifyJS.JS_Parse_Error && e.message === "Unterminated string constant"; }; for (var input in inputs) { assert.throws(test(inputs[input]), error); } }); it("Should not throw syntax error if a string has a line continuation", function() { var output = UglifyJS.parse('var a = "a\\\nb";').print_to_string(); assert.equal(output, 'var a="ab";'); }); it("Should throw error in strict mode if string contains escaped octalIntegerLiteral", function() { var inputs = [ '"use strict";\n"\\76";', '"use strict";\nvar foo = "\\76";', '"use strict";\n"\\1";', '"use strict";\n"\\07";', '"use strict";\n"\\011"' ]; var test = function(input) { return function() { var output = UglifyJS.parse(input); } }; var error = function(e) { return e instanceof UglifyJS.JS_Parse_Error && e.message === "Legacy octal escape sequences are not allowed in strict mode"; } for (var input in inputs) { assert.throws(test(inputs[input]), error); } }); it("Should not throw error outside strict mode if string contains escaped octalIntegerLiteral", function() { var tests = [ ['"\\76";', ';">";'], ['"\\0"', '"\\0";'], ['"\\08"', '"\\x008";'], ['"\\008"', '"\\x008";'], ['"\\0008"', '"\\x008";'], ['"use strict" === "use strict";\n"\\76";', '"use strict"==="use strict";">";'], ['"use\\\n strict";\n"\\07";', ';"use strict";"\07";'] ]; for (var test in tests) { var output = UglifyJS.parse(tests[test][0]).print_to_string(); assert.equal(output, tests[test][1]); } }); it("Should not throw error when digit is 8 or 9", function() { assert.equal(UglifyJS.parse('"use strict";"\\08"').print_to_string(), '"use strict";"\\x008";'); assert.equal(UglifyJS.parse('"use strict";"\\09"').print_to_string(), '"use strict";"\\x009";'); }); it("Should not unescape unpaired surrogates", function() { var code = []; for (var i = 0; i <= 0xF; i++) { code.push("\\u000" + i.toString(16)); } for (;i <= 0xFF; i++) { code.push("\\u00" + i.toString(16)); } for (;i <= 0xFFF; i++) { code.push("\\u0" + i.toString(16)); } for (; i <= 0xFFFF; i++) { code.push("\\u" + i.toString(16)); } code = '"' + code.join() + '"'; var normal = UglifyJS.minify(code, { compress: false, mangle: false, output: { ascii_only: false } }); if (normal.error) throw normal.error; assert.ok(code.length > normal.code.length); assert.strictEqual(eval(code), eval(normal.code)); var ascii = UglifyJS.minify(code, { compress: false, mangle: false, output: { ascii_only: false } }); if (ascii.error) throw ascii.error; assert.ok(code.length > ascii.code.length); assert.strictEqual(eval(code), eval(ascii.code)); }); }); terser-4.1.2/test/mocha/template-string.js000066400000000000000000000026061351061312300205440ustar00rootroot00000000000000var assert = require("assert"); var uglify = require("../node"); describe("Template string", function() { it("Should not accept invalid sequences", function() { var tests = [ // Stress invalid expression "var foo = `Hello ${]}`", "var foo = `Test 123 ${>}`", "var foo = `Blah ${;}`", // Stress invalid template_substitution after expression "var foo = `Blablabla ${123 456}`", "var foo = `Blub ${123;}`", "var foo = `Bleh ${a b}`" ]; var exec = function(test) { return function() { uglify.parse(test); } }; var fail = function(e) { return e instanceof uglify.JS_Parse_Error && /^Unexpected token: /.test(e.message); }; for (var i = 0; i < tests.length; i++) { assert.throws(exec(tests[i]), fail, tests[i]); } }); it("Should process all line terminators as LF", function() { [ "`a\rb`", "`a\nb`", "`a\r\nb`", ].forEach(function(code) { assert.strictEqual(uglify.parse(code).print_to_string(), "`a\\nb`;"); }); }); it("Should not throw on extraneous escape (#231)", function() { assert.doesNotThrow(function() { uglify.parse("`\\a`"); }); }); }); terser-4.1.2/test/mocha/tokens.js000066400000000000000000000022761351061312300167330ustar00rootroot00000000000000var assert = require("assert"); var UglifyJS = require("../.."); describe("tokens", function() { it("Should give correct positions for accessors", function() { // location 0 1 2 3 4 // 01234567890123456789012345678901234567890123456789 var ast = UglifyJS.parse("var obj = { get latest() { return undefined; } }"); // test all AST_ObjectProperty tokens are set as expected var found = false; ast.walk(new UglifyJS.TreeWalker(function(node) { if (node instanceof UglifyJS.AST_ObjectProperty) { found = true; assert.equal(node.start.pos, 12); assert.equal(node.end.endpos, 46); assert(node.key instanceof UglifyJS.AST_SymbolMethod); assert.equal(node.key.start.pos, 12); assert.equal(node.key.end.endpos, 22); assert(node.value instanceof UglifyJS.AST_Accessor); assert.equal(node.value.start.pos, 22); assert.equal(node.value.end.endpos, 46); } })); assert(found, "AST_ObjectProperty not found"); }); }); terser-4.1.2/test/mocha/try.js000066400000000000000000000011171351061312300162370ustar00rootroot00000000000000var assert = require("assert"); var uglify = require("../node"); describe("Try", function() { it("Should not allow catch with an empty parameter", function() { var tests = [ "try {} catch() {}" ]; var test = function(code) { return function () { uglify.parse(code); } } var error = function (e) { return e instanceof uglify.JS_Parse_Error; } for (var i = 0; i < tests.length; i++) { assert.throws(test(tests[i]), error, tests[i]); } }); }); terser-4.1.2/test/mocha/unicode.js000066400000000000000000000102561351061312300170530ustar00rootroot00000000000000var assert = require("assert"); var uglify = require("../node"); describe("Unicode", function() { it("Should throw error if escaped first identifier char is not part of ID_start", function() { var tests = [ 'var \\u{0} = "foo";', 'var \\u{10ffff} = "bar";', 'var \\u000a = "what\'s up";', // Valid ID_Start, but using up 2 escaped characters and not fitting in IdentifierStart 'var \\ud800\\udc00 = "Hello";', 'var \\udbff\\udfff = "Unicode";', // Same as previous test 'var \\ud800\udc01 = "Weird unicode";', // Same as above, but mixed escaped with unicode chars ]; var exec = function(test) { return function() { uglify.parse(test); } } var fail = function(e) { return e instanceof uglify.JS_Parse_Error && e.message === "First identifier char is an invalid identifier char"; } for (var i = 0; i < tests.length; i++) { assert.throws(exec(tests[i]), fail); } }); it("Should throw error if escaped non-first identifier char is not part of ID_start", function() { var tests = [ 'var a\\u{0} = "foo";', 'var a\\u{10ffff} = "bar";', 'var z\\u000a = "what\'s up";' ]; var exec = function(test) { return function() { uglify.parse(test); } } var fail = function(e) { return e instanceof uglify.JS_Parse_Error && e.message === "Invalid escaped identifier char"; } for (var i = 0; i < tests.length; i++) { assert.throws(exec(tests[i]), fail); } }); it("Should throw error if identifier is a keyword with a escape sequences", function() { var tests = [ 'var \\u0069\\u006e = "foo"', // in 'var \\u0076\\u0061\\u0072 = "bar"', // var 'var \\u{66}\\u{6f}\\u{72} = "baz"', // for 'var \\u0069\\u{66} = "foobar"', // if 'var \\u{73}uper' // super ]; var exec = function(test) { return function() { uglify.parse(test); } } var fail = function(e) { return e instanceof uglify.JS_Parse_Error && e.message === "Escaped characters are not allowed in keywords"; } for (var i = 0; i < tests.length; i++) { assert.throws(exec(tests[i]), fail); } }); it("Should read strings containing surigates correctly", function() { var tests = [ ['var a = "\ud800\udc00";', 'var a="\\u{10000}";'], ['var b = "\udbff\udfff";', 'var b="\\u{10ffff}";'] ]; for (var i = 0; i < tests.length; i++) { assert.strictEqual(uglify.minify(tests[i][0], { output: { ascii_only: true, ecma: 6 } }).code, tests[i][1]); } }); it("Should parse raw characters correctly", function() { var ast = uglify.parse('console.log("\\udbff");'); assert.strictEqual(ast.print_to_string(), 'console.log("\\udbff");'); ast = uglify.parse(ast.print_to_string()); assert.strictEqual(ast.print_to_string(), 'console.log("\\udbff");'); }); it("Should not unescape unpaired surrogates", function() { this.timeout(20000); var code = []; for (var i = 0; i <= 0x20001; i++) { code.push("\\u{" + i.toString(16) + "}"); } code = '"' + code.join() + '"'; [true, false].forEach(function(ascii_only) { [5, 6].forEach(function(ecma) { var result = uglify.minify(code, { compress: false, mangle: false, output: { ascii_only: ascii_only }, ecma: ecma }); if (result.error) throw result.error; if (ecma > 5) assert.ok(code.length > result.code.length); assert.strictEqual(eval(code), eval(result.code)); }); }); }); }); terser-4.1.2/test/mocha/utils.js000066400000000000000000000014171351061312300165640ustar00rootroot00000000000000function decodeMap(mapData) { const buffer = new Buffer(mapData.replace('data:application/json;charset=utf-8;base64,', ''), 'base64'); return JSON.parse(buffer.toString()); } function assertCodeWithInlineMapEquals(actual, expected) { if (actual === expected) return; const [actualCode, actualSourceMapData] = actual.split('//# sourceMappingURL=', 2); const [expectedCode, expectedSourceMapData] = expected.split('//# sourceMappingURL=', 2); const actualSourceMap = decodeMap(actualSourceMapData); const expectedSourceMap = decodeMap(expectedSourceMapData); assert.deepStrictEqual({code: actualCode, map: actualSourceMap}, {code: expectedCode, map: expectedSourceMap}); } module.exports.assertCodeWithInlineMapEquals = assertCodeWithInlineMapEquals; terser-4.1.2/test/mocha/with.js000066400000000000000000000016521351061312300164000ustar00rootroot00000000000000var assert = require("assert"); var UglifyJS = require("../node"); describe("With", function() { it("Should throw syntaxError when using with statement in strict mode", function() { var code = '"use strict";\nthrow NotEarlyError;\nwith ({}) { }'; var test = function() { UglifyJS.parse(code); } var error = function(e) { return e instanceof UglifyJS.JS_Parse_Error && e.message === "Strict mode may not include a with statement"; } assert.throws(test, error); }); it("Should set uses_with for scopes involving With statements", function() { var ast = UglifyJS.parse("with(e) {f(1, 2)}"); ast.figure_out_scope(); assert.equal(ast.uses_with, true); assert.equal(ast.body[0].expression.scope.uses_with, true); assert.equal(ast.body[0].body.body[0].body.expression.scope.uses_with, true); }); }); terser-4.1.2/test/mocha/yield.js000066400000000000000000000107221351061312300165310ustar00rootroot00000000000000var UglifyJS = require("../node"); var assert = require("assert"); describe("Yield", function() { it("Should not delete statements after yield", function() { var js = 'function *foo(bar) { yield 1; yield 2; return 3; }'; var result = UglifyJS.minify(js); assert.strictEqual(result.code, 'function*foo(e){return yield 1,yield 2,3}'); }); it("Should not allow yield* followed by a semicolon in generators", function() { var js = "function* test() {yield*\n;}"; var test = function() { UglifyJS.parse(js); } var expect = function(e) { return e instanceof UglifyJS.JS_Parse_Error && e.message === "Unexpected token: punc (;)"; } assert.throws(test, expect); }); it("Should not allow yield with next token star on next line", function() { var js = "function* test() {yield\n*123;}"; var test = function() { UglifyJS.parse(js); } var expect = function(e) { return e instanceof UglifyJS.JS_Parse_Error && e.message === "Unexpected token: operator (*)"; } assert.throws(test, expect); }); it("Should be able to compress its expression", function() { assert.strictEqual( UglifyJS.minify("function *f() { yield 3-4; }", {compress: true}).code, "function*f(){yield-1}" ); }); it("Should keep undefined after yield without compression if found in ast", function() { assert.strictEqual( UglifyJS.minify("function *f() { yield undefined; yield; yield* undefined; yield void 0}", {compress: false}).code, "function*f(){yield undefined;yield;yield*undefined;yield void 0}" ); }); it("Should be able to drop undefined after yield if necessary with compression", function() { assert.strictEqual( UglifyJS.minify("function *f() { yield undefined; yield; yield* undefined; yield void 0}", {compress: true}).code, "function*f(){yield,yield,yield*void 0,yield}" ); }); var identifiers = [ // Fail in as_symbol 'import yield from "bar";', 'yield = 123;', 'yield: "123";', 'for(;;){break yield;}', 'for(;;){continue yield;}', 'function yield(){}', 'try { new Error("")} catch (yield) {}', 'var yield = "foo";', 'class yield {}', // Fail in as_property_name 'var foo = {yield};', ]; it("Should not allow yield to be used as symbol, identifier or shorthand property outside generators in strict mode", function() { function fail(e) { return e instanceof UglifyJS.JS_Parse_Error && /^Unexpected yield identifier (?:as parameter )?inside strict mode/.test(e.message); } function test(input) { return function() { UglifyJS.parse(input); } } identifiers.concat([ // Fail in as_symbol "function foo(...yield){}", // Fail in maybe_assign 'var foo = yield;', 'var foo = bar = yield', ]).map(function(code) { return '"use strict"; ' + code; }).forEach(function(code) { assert.throws(test(code), fail, code); }); }); it("Should not allow yield to be used as symbol, identifier or shorthand property inside generators", function() { function fail(e) { return e instanceof UglifyJS.JS_Parse_Error && [ "Unexpected token: operator (=)", "Yield cannot be used as identifier inside generators", ].includes(e.message); } function test(input) { return function() { UglifyJS.parse(input); } } identifiers.map(function(code) { return "function* f() { " + code + " }"; }).concat([ // Fail in as_symbol "function* f(yield) {}", ]).forEach(function(code) { assert.throws(test(code), fail, code); }); }); it("Should allow yield to be used as class/object property name", function() { var input = [ '"use strict";', "({yield:42});", "({yield(){}});", "(class{yield(){}});", "class C{yield(){}}", ].join(""); assert.strictEqual(UglifyJS.minify(input, { compress: false }).code, input); }); }); terser-4.1.2/test/mozilla-ast.js000066400000000000000000000044021351061312300165660ustar00rootroot00000000000000// Testing UglifyJS <-> SpiderMonkey AST conversion "use strict"; var acorn = require("acorn"); var ufuzz = require("./ufuzz"); var UglifyJS = require(".."); function try_beautify(code) { var beautified = UglifyJS.minify(code, { compress: false, mangle: false, output: { beautify: true, braces: true } }); if (beautified.error) { console.log("// !!! beautify failed !!!"); console.log(beautified.error.stack); console.log(code); } else { console.log("// (beautified)"); console.log(beautified.code); } } function test(original, estree, description) { var transformed = UglifyJS.minify(UglifyJS.AST_Node.from_mozilla_ast(estree), { compress: false, mangle: false }); if (transformed.error || original !== transformed.code) { console.log("//============================================================="); console.log("// !!!!!! Failed... round", round); console.log("// original code"); try_beautify(original); console.log(); console.log(); console.log("//-------------------------------------------------------------"); console.log("//", description); if (transformed.error) { console.log(transformed.error.stack); } else { try_beautify(transformed.code); } console.log("!!!!!! Failed... round", round); process.exit(1); } } var num_iterations = ufuzz.num_iterations; for (var round = 1; round <= num_iterations; round++) { process.stdout.write(round + " of " + num_iterations + "\r"); var code = ufuzz.createTopLevelCode(); var uglified = UglifyJS.minify(code, { compress: false, mangle: false, output: { ast: true } }); test(uglified.code, uglified.ast.to_mozilla_ast(), "AST_Node.to_mozilla_ast()"); try { test(uglified.code, acorn.parse(code), "acorn.parse()"); } catch (e) { console.log("//============================================================="); console.log("// acorn parser failed... round", round); console.log(e); console.log("// original code"); console.log(code); } } console.log(); terser-4.1.2/test/node.js000066400000000000000000000000541351061312300152560ustar00rootroot00000000000000module.exports = require("../dist/bundle"); terser-4.1.2/test/run-tests.js000077500000000000000000000520751351061312300163120ustar00rootroot00000000000000#! /usr/bin/env node try { require("source-map-support").install(); } catch (err) {} var U = require("../dist/bundle.js"); var path = require("path"); var fs = require("fs"); var assert = require("assert"); var Console = require("console").Console; var sandbox = require("./sandbox"); var semver = require("semver"); require("../tools/colorless-console"); var tests_dir = path.dirname(module.filename); var failures = 0; var failed_files = {}; var minify_options = require("./ufuzz.json").map(JSON.stringify); run_compress_tests(); if (failures) { console.error("\n!!! Failed " + failures + " test cases."); console.error("!!! " + Object.keys(failed_files).join(", ")); process.exit(1); } if (process.argv.length > 2) { // User specified a specific compress/ test, don't run entire test suite return; } var mocha_tests = require("./mocha.js"); mocha_tests(); /* -----[ utils ]----- */ function HOP(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } function tmpl() { return U.string_template.apply(this, arguments); } function log() { var txt = tmpl.apply(this, arguments); console.log("%s", txt); } function log_directory(dir) { log("*** Entering [{dir}]", { dir: dir }); } function log_start_file(file) { log("--- {file}", { file: file }); } function log_test(name) { log(" Running test [{name}]", { name: name }); } function find_test_files(dir) { var files = fs.readdirSync(dir).filter(function(name){ return /\.js$/i.test(name); }); if (process.argv.length > 2) { var x = process.argv.slice(2); files = files.filter(function(f){ return x.includes(f); }); } return files; } function test_directory(dir) { return path.resolve(tests_dir, dir); } function as_toplevel(input, mangle_options) { if (!(input instanceof U.AST_BlockStatement)) throw new Error("Unsupported input syntax"); for (var i = 0; i < input.body.length; i++) { var stat = input.body[i]; if (stat instanceof U.AST_SimpleStatement && stat.body instanceof U.AST_String) input.body[i] = new U.AST_Directive(stat.body); else break; } var toplevel = new U.AST_Toplevel(input); toplevel.figure_out_scope(mangle_options); return toplevel; } function run_compress_tests() { var dir = test_directory("compress"); log_directory("compress"); var files = find_test_files(dir); function test_file(file) { log_start_file(file); function test_case(test) { log_test(test.name); var output_options = test.beautify || {}; var expect; if (test.expect) { expect = make_code(as_toplevel(test.expect, test.mangle), output_options); } else { expect = test.expect_exact; } if (test.expect_error && (test.expect || test.expect_exact || test.expect_stdout)) { log("!!! Test cannot have an `expect_error` with other expect clauses\n", {}); return false; } if (test.input instanceof U.AST_SimpleStatement && test.input.body instanceof U.AST_TemplateString) { if (test.input.body.segments.length == 1) { try { var input = U.parse(test.input.body.segments[0].value); } catch (ex) { if (!test.expect_error) { log("!!! Test is missing an `expect_error` clause\n", {}); return false; } if (test.expect_error instanceof U.AST_SimpleStatement && test.expect_error.body instanceof U.AST_Object) { var expect_error = eval("(" + test.expect_error.body.print_to_string() + ")"); var ex_normalized = JSON.parse(JSON.stringify(ex)); ex_normalized.name = ex.name; for (var prop in expect_error) { if (prop == "name" || HOP(expect_error, prop)) { if (expect_error[prop] != ex_normalized[prop]) { log("!!! Failed `expect_error` property `{prop}`:\n\n---expect_error---\n{expect_error}\n\n---ACTUAL exception--\n{actual_ex}\n\n", { prop: prop, expect_error: JSON.stringify(expect_error, null, 2), actual_ex: JSON.stringify(ex_normalized, null, 2), }); return false; } } } return true; } log("!!! Test `expect_error` clause must be an object literal\n---expect_error---\n{expect_error}\n\n", { expect_error: test.expect_error.print_to_string(), }); return false; } var input_code = make_code(input, output_options); var input_formatted = test.input.body.segments[0].value; } else { log("!!! Test input template string cannot use unescaped ${} expressions\n---INPUT---\n{input}\n\n", { input: test.input.body.print_to_string(), }); return false; } } else if (test.expect_error) { log("!!! Test cannot have an `expect_error` clause without a template string `input`\n", {}); return false; } else { var input = as_toplevel(test.input, test.mangle); var input_code = make_code(input, output_options); var input_formatted = make_code(test.input, { beautify: true, quote_style: 3, keep_quoted_props: true }); } try { U.parse(input_code); } catch (ex) { log("!!! Cannot parse input\n---INPUT---\n{input}\n--PARSE ERROR--\n{error}\n\n", { input: input_formatted, error: ex, }); return false; } var ast = input.to_mozilla_ast(); var ast_as_string = U.AST_Node.from_mozilla_ast(ast).print_to_string(); var input_string = input.print_to_string(); if (input_string !== ast_as_string) { log("!!! Mozilla AST I/O corrupted input\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n\n", { input: input_string, output: ast_as_string, }); return false; } var options = U.defaults(test.options, { warnings: false }); var warnings_emitted = []; var original_warn_function = U.AST_Node.warn_function; if (test.expect_warnings) { U.AST_Node.warn_function = function(text) { text = text.replace(/:(\d+),/, function(_, $1) { var relative_line = Number($1) - input.start.line; return ':' + relative_line + ','; }); warnings_emitted.push("WARN: " + text); }; if (!options.warnings) options.warnings = true; } 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; if (test.mangle.properties.keep_quoted !== "strict") { 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(options, options.defaults === undefined ? true : !options.defaults); var output = cmp.compress(input); output.figure_out_scope(test.mangle); if (test.mangle) { U.base54.reset(); output.compute_char_frequency(test.mangle); (function(cache) { if (!cache) return; if (!("props" in cache)) { cache.props = new Map(); } else if (!(cache.props instanceof Map)) { const props = new Map(); for (const key in cache.props) { if (HOP(cache.props, key) && key.charAt(0) === '$') { props.set(key.substr(1), cache.props[key]); } } cache.props = props; } })(test.mangle.cache); output.mangle_names(test.mangle); if (test.mangle.properties) { output = U.mangle_properties(output, test.mangle.properties); } } output = make_code(output, output_options); if (test.expect_stdout && typeof expect == "undefined") { // Do not verify generated `output` against `expect` or `expect_exact`. // Rely on the pending `expect_stdout` check below. } else if (expect != output) { log("!!! failed\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n---EXPECTED---\n{expected}\n\n", { input: input_formatted, output: output, expected: expect }); return false; } try { U.parse(output); } catch (ex) { log("!!! Test matched expected result but cannot parse output\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n--REPARSE ERROR--\n{error}\n\n", { input: input_formatted, output: output, error: ex.stack, }); return false; } if (test.expect_warnings) { U.AST_Node.warn_function = original_warn_function; var expected_warnings = make_code(test.expect_warnings, { beautify: false, quote_style: 2, // force double quote to match JSON }); 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\n---INPUT---\n{input}\n---EXPECTED WARNINGS---\n{expected_warnings}\n---ACTUAL WARNINGS---\n{actual_warnings}\n\n", { input: input_formatted, expected_warnings: JSON.parse(expected_warnings).join('\n'), actual_warnings: JSON.parse(actual_warnings).join('\n'), }); return false; } } if (test.expect_stdout && (!test.node_version || semver.satisfies(process.version, test.node_version))) { var stdout = sandbox.run_code(input_code); if (test.expect_stdout === true) { test.expect_stdout = stdout; } if (!sandbox.same_stdout(test.expect_stdout, stdout)) { log("!!! Invalid input or expected stdout\n---INPUT---\n{input}\n---EXPECTED {expected_type}---\n{expected}\n---ACTUAL {actual_type}---\n{actual}\n\n", { input: input_formatted, expected_type: typeof test.expect_stdout == "string" ? "STDOUT" : "ERROR", expected: test.expect_stdout, actual_type: typeof stdout == "string" ? "STDOUT" : "ERROR", actual: stdout, }); return false; } stdout = sandbox.run_code(output); if (!sandbox.same_stdout(test.expect_stdout, stdout)) { log("!!! failed\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n---EXPECTED {expected_type}---\n{expected}\n---ACTUAL {actual_type}---\n{actual}\n\n", { input: input_formatted, output: output, expected_type: typeof test.expect_stdout == "string" ? "STDOUT" : "ERROR", expected: test.expect_stdout, actual_type: typeof stdout == "string" ? "STDOUT" : "ERROR", actual: stdout, }); return false; } if (test.reminify && !reminify(test.options, input_code, input_formatted, test.expect_stdout)) { return false; } } return true; } var tests = parse_test(path.resolve(dir, file)); for (var i in tests) if (tests.hasOwnProperty(i)) { if (!test_case(tests[i])) { failures++; failed_files[file] = 1; } } } files.forEach(function(file){ test_file(file); }); } function parse_test(file) { var script = fs.readFileSync(file, "utf8"); // TODO try/catch can be removed after fixing https://github.com/mishoo/UglifyJS2/issues/348 try { var ast = U.parse(script, { filename: file }); } catch (e) { console.log("Caught error while parsing tests in " + file + "\n"); console.log(e); throw e; } var tests = {}; 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_boolean(stat) { if (stat.TYPE == "SimpleStatement") { var body = stat.body; if (body instanceof U.AST_Boolean) { return body.value; } } throw new Error("Should be boolean"); } 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: {}, reminify: true, }; 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_error", "expect_exact", "expect_warnings", "expect_stdout", "node_version", "reminify", ].includes(label.name), 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 == "reminify") { var value = read_boolean(stat); test.reminify = value == null || value; } 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; }; } function make_code(ast, options) { var stream = U.OutputStream(options); ast.print(stream); return stream.get(); } function evaluate(code) { if (code instanceof U.AST_Node) code = make_code(code, { beautify: true }); return new Function("return(" + code + ")")(); } // Try to reminify original input with standard options // to see if it matches expect_stdout. function reminify(orig_options, input_code, input_formatted, expect_stdout) { for (var i = 0; i < minify_options.length; i++) { var options = JSON.parse(minify_options[i]); options.keep_fnames = orig_options.keep_fnames; options.keep_classnames = orig_options.keep_classnames; if (orig_options.compress) { options.compress.keep_classnames = orig_options.compress.keep_classnames; options.compress.keep_fargs = orig_options.compress.keep_fargs; options.compress.keep_fnames = orig_options.compress.keep_fnames; } if (orig_options.mangle) { options.mangle.keep_classnames = orig_options.mangle.keep_classnames; options.mangle.keep_fnames = orig_options.mangle.keep_fnames; } var options_formatted = JSON.stringify(options, null, 4); var result = U.minify(input_code, options); if (result.error) { log("!!! failed input reminify\n---INPUT---\n{input}\n--ERROR---\n{error}\n\n", { input: input_formatted, error: result.error.stack, }); return false; } else { var stdout = sandbox.run_code(result.code); if (typeof expect_stdout != "string" && typeof stdout != "string" && expect_stdout.name == stdout.name) { stdout = expect_stdout; } if (!sandbox.same_stdout(expect_stdout, stdout)) { log("!!! failed running reminified input\n---INPUT---\n{input}\n---OPTIONS---\n{options}\n---OUTPUT---\n{output}\n---EXPECTED {expected_type}---\n{expected}\n---ACTUAL {actual_type}---\n{actual}\n\n", { input: input_formatted, options: options_formatted, output: result.code, expected_type: typeof expect_stdout == "string" ? "STDOUT" : "ERROR", expected: expect_stdout, actual_type: typeof stdout == "string" ? "STDOUT" : "ERROR", actual: stdout, }); return false; } } } return true; } terser-4.1.2/test/sandbox.js000066400000000000000000000046061351061312300157760ustar00rootroot00000000000000var vm = require("vm"); function safe_log(arg, level) { if (arg) switch (typeof arg) { case "function": return arg.toString(); case "object": if (/Error$/.test(arg.name)) return arg.toString(); arg.constructor.toString(); if (level--) for (var key in arg) { if (!Object.getOwnPropertyDescriptor(arg, key).get) { arg[key] = safe_log(arg[key], level); } } } return arg; } function strip_func_ids(text) { return text.toString().replace(/F[0-9]{6}N/g, "N>"); } var FUNC_TOSTRING = [ "[ Array, Boolean, Error, Function, Number, Object, RegExp, String].forEach(function(f) {", " f.toString = Function.prototype.toString;", "});", "Function.prototype.toString = function() {", " var id = 100000;", " return function() {", " var n = this.name;", ' if (!/^F[0-9]{6}N$/.test(n)) {', ' n = "F" + ++id + "N";', ].concat(Object.getOwnPropertyDescriptor(Function.prototype, "name").configurable ? [ ' Object.defineProperty(this, "name", {', " get: function() {", " return n;", " }", " });", ] : [], [ " }", ' return "function " + n + "() {...}";', " }", "}();", ]).join("\n"); exports.run_code = function(code) { var stdout = ""; var original_write = process.stdout.write; process.stdout.write = function(chunk) { stdout += chunk; }; try { vm.runInNewContext([ FUNC_TOSTRING, "!function() {", code, "}();", ].join("\n"), { console: { log: function(msg) { if (arguments.length == 1 && typeof msg == "string") { return console.log("%s", msg); } return console.log.apply(console, [].map.call(arguments, function(arg) { return safe_log(arg, 3); })); } } }, { timeout: 5000 }); return stdout; } catch (ex) { return ex; } finally { process.stdout.write = original_write; } }; exports.same_stdout = function(expected, actual) { return typeof expected == typeof actual && strip_func_ids(expected) == strip_func_ids(actual); }; terser-4.1.2/test/travis-ufuzz.js000066400000000000000000000052621351061312300170300ustar00rootroot00000000000000"use strict"; var child_process = require("child_process"); var https = require("https"); var url = require("url"); var period = 45 * 60 * 1000; var wait = 2 * 60 * 1000; var ping = 5 * 60 * 1000; if (process.argv[2] == "run") { var endTime = Date.now() + period; for (var i = 0; i < 2; i++) spawn(endTime); } else if (process.argv.length > 2) { var token = process.argv[2]; var branch = process.argv[3] || "v" + require("../package.json").version; var repository = encodeURIComponent(process.argv[4] || "mishoo/UglifyJS2"); var concurrency = process.argv[5] || 1; (function request() { setTimeout(request, (period + wait) / concurrency); var options = url.parse("https://api.travis-ci.org/repo/" + repository + "/requests"); options.method = "POST"; options.headers = { "Content-Type": "application/json", "Travis-API-Version": 3, "Authorization": "token " + token }; https.request(options, function(res) { console.log("HTTP", res.statusCode); console.log(JSON.stringify(res.headers, null, 2)); console.log(); res.setEncoding("utf8"); res.on("data", console.log); }).on("error", console.error).end(JSON.stringify({ request: { message: "ufuzz testing (when idle)", branch: branch, config: { merge_mode: "replace", language: "node_js", node_js: "9", sudo: false, script: "node test/travis-ufuzz run" } } })); })(); } else { console.log("Usage: test/travis-ufuzz.js [branch] [repository] [concurrency]"); } function spawn(endTime) { var child = child_process.spawn("node", [ "--max-old-space-size=2048", "test/ufuzz" ], { stdio: [ "ignore", "pipe", "pipe" ] }).on("exit", respawn); var line = ""; child.stdout.on("data", function(data) { line += data; }); child.stderr.on("data", function() { process.exitCode = 1; }).pipe(process.stdout); var keepAlive = setInterval(function() { var end = line.lastIndexOf("\r"); console.log(line.slice(line.lastIndexOf("\r", end - 1) + 1, end)); line = line.slice(end + 1); }, ping); var timer = setTimeout(function() { clearInterval(keepAlive); child.removeListener("exit", respawn); child.kill(); }, endTime - Date.now()); function respawn() { console.log(line); clearInterval(keepAlive); clearTimeout(timer); spawn(endTime); } } terser-4.1.2/test/ufuzz.js000066400000000000000000001200621351061312300155160ustar00rootroot00000000000000// ufuzz.js // derived from https://github.com/qfox/uglyfuzzer by Peter van der Zee "use strict"; // check both CLI and file modes of nodejs (!). See #1695 for details. and the various settings of uglify. // bin/uglifyjs s.js -c && bin/uglifyjs s.js -c passes=3 && bin/uglifyjs s.js -c passes=3 -m // cat s.js | node && node s.js && bin/uglifyjs s.js -c | node && bin/uglifyjs s.js -c passes=3 | node && bin/uglifyjs s.js -c passes=3 -m | node require("../tools/exit"); var UglifyJS = require("../dist/bundle"); var randomBytes = require("crypto").randomBytes; var sandbox = require("./sandbox"); var MAX_GENERATED_TOPLEVELS_PER_RUN = 1; var MAX_GENERATION_RECURSION_DEPTH = 12; var INTERVAL_COUNT = 100; var STMT_ARG_TO_ID = Object.create(null); var STMTS_TO_USE = []; function STMT_(name) { return STMT_ARG_TO_ID[name] = STMTS_TO_USE.push(STMTS_TO_USE.length) - 1; } var STMT_BLOCK = STMT_("block"); var STMT_IF_ELSE = STMT_("ifelse"); var STMT_DO_WHILE = STMT_("dowhile"); var STMT_WHILE = STMT_("while"); var STMT_FOR_LOOP = STMT_("forloop"); var STMT_FOR_IN = STMT_("forin"); var STMT_SEMI = STMT_("semi"); var STMT_EXPR = STMT_("expr"); var STMT_SWITCH = STMT_("switch"); var STMT_VAR = STMT_("var"); var STMT_RETURN_ETC = STMT_("stop"); var STMT_FUNC_EXPR = STMT_("funcexpr"); var STMT_TRY = STMT_("try"); var STMT_C = STMT_("c"); var STMT_FIRST_LEVEL_OVERRIDE = -1; var STMT_SECOND_LEVEL_OVERRIDE = -1; var STMT_COUNT_FROM_GLOBAL = true; // count statement depth from nearest function scope or just global scope? var num_iterations = +process.argv[2] || 1/0; var verbose = false; // log every generated test var verbose_interval = false; // log every 100 generated tests var use_strict = false; var catch_redef = require.main === module; var generate_directive = require.main === module; for (var i = 2; i < process.argv.length; ++i) { switch (process.argv[i]) { case '-v': verbose = true; break; case '-V': verbose_interval = true; break; case '-t': MAX_GENERATED_TOPLEVELS_PER_RUN = +process.argv[++i]; if (!MAX_GENERATED_TOPLEVELS_PER_RUN) throw new Error('Must generate at least one toplevel per run'); break; case '-r': MAX_GENERATION_RECURSION_DEPTH = +process.argv[++i]; if (!MAX_GENERATION_RECURSION_DEPTH) throw new Error('Recursion depth must be at least 1'); break; case '-s1': var name = process.argv[++i]; STMT_FIRST_LEVEL_OVERRIDE = STMT_ARG_TO_ID[name]; if (!(STMT_FIRST_LEVEL_OVERRIDE >= 0)) throw new Error('Unknown statement name; use -? to get a list'); break; case '-s2': var name = process.argv[++i]; STMT_SECOND_LEVEL_OVERRIDE = STMT_ARG_TO_ID[name]; if (!(STMT_SECOND_LEVEL_OVERRIDE >= 0)) throw new Error('Unknown statement name; use -? to get a list'); break; case '--no-catch-redef': catch_redef = false; break; case '--no-directive': generate_directive = false; break; case '--use-strict': use_strict = true; break; case '--stmt-depth-from-func': STMT_COUNT_FROM_GLOBAL = false; break; case '--only-stmt': STMTS_TO_USE = process.argv[++i].split(',').map(function(name){ return STMT_ARG_TO_ID[name]; }); break; case '--without-stmt': // meh. it runs once it's fine. process.argv[++i].split(',').forEach(function(name){ var omit = STMT_ARG_TO_ID[name]; STMTS_TO_USE = STMTS_TO_USE.filter(function(id){ return id !== omit; }) }); break; case '--help': case '-h': case '-?': println('** UglifyJS fuzzer help **'); println('Valid options (optional):'); println(': generate this many cases (if used must be first arg)'); println('-v: print every generated test case'); println('-V: print every 100th generated test case'); println('-t : generate this many toplevels per run (more take longer)'); println('-r : maximum recursion depth for generator (higher takes longer)'); println('-s1 : force the first level statement to be this one (see list below)'); println('-s2 : force the second level statement to be this one (see list below)'); println('--no-catch-redef: do not redefine catch variables'); println('--no-directive: do not generate directives'); println('--use-strict: generate "use strict"'); println('--stmt-depth-from-func: reset statement depth counter at each function, counts from global otherwise'); println('--only-stmt : a comma delimited white list of statements that may be generated'); println('--without-stmt : a comma delimited black list of statements never to generate'); println('List of accepted statement names: ' + Object.keys(STMT_ARG_TO_ID)); println('** UglifyJS fuzzer exiting **'); return 0; default: // first arg may be a number. if (i > 2 || !parseInt(process.argv[i], 10)) throw new Error('Unknown argument[' + process.argv[i] + ']; see -h for help'); } } var VALUES = [ '"a"', '"b"', '"c"', '""', 'true', 'false', ' /[a2][^e]+$/ ', '(-1)', '(-2)', '(-3)', '(-4)', '(-5)', '0', '1', '2', '3', '4', '5', '22', '-0', // 0/-0 !== 0 '23..toString()', '24 .toString()', '25. ', '0x26.toString()', 'NaN', 'undefined', 'Infinity', 'null', '[]', '[,0][1]', // an array with elisions... but this is always false '([,0].length === 2)', // an array with elisions... this is always true '({})', // wrapped the object causes too many syntax errors in statements '"foo"', '"bar"', '"undefined"', '"object"', '"number"', '"function"', 'this', ]; var BINARY_OPS_NO_COMMA = [ ' + ', // spaces needed to disambiguate with ++ cases (could otherwise cause syntax errors) ' - ', '/', '*', '&', '|', '^', '<', '<=', '>', '>=', '==', '===', '!=', '!==', '<<', '>>', '>>>', '%', '&&', '||', '^' ]; var BINARY_OPS = [','].concat(BINARY_OPS_NO_COMMA); var ASSIGNMENTS = [ '=', '=', '=', '=', '=', '=', '=', '=', '=', '=', '=', '=', '=', '=', '=', '=', '=', '=', '=', '=', '+=', '+=', '+=', '+=', '+=', '+=', '+=', '+=', '+=', '+=', '-=', '*=', '/=', '&=', '|=', '^=', '<<=', '>>=', '>>>=', '%=', ]; var UNARY_SAFE = [ '+', '-', '~', '!', 'void ', 'delete ', ]; var UNARY_POSTFIX = [ '++', '--', ]; var UNARY_PREFIX = UNARY_POSTFIX.concat(UNARY_SAFE); var NO_COMMA = true; var COMMA_OK = false; var MAYBE = true; var MANDATORY = false; var CAN_THROW = true; var CANNOT_THROW = false; var CAN_BREAK = true; var CANNOT_BREAK = false; var CAN_CONTINUE = true; var CANNOT_CONTINUE = false; var CAN_RETURN = false; var CANNOT_RETURN = true; var NO_DEFUN = false; var DEFUN_OK = true; var DONT_STORE = true; var VAR_NAMES = [ 'a', 'a', 'a', 'a', 'b', 'b', 'b', 'b', 'c', // prevent redeclaring this, avoid assigning to this 'foo', 'foo', 'bar', 'bar', 'undefined', 'NaN', 'Infinity', 'arguments', 'Math', 'parseInt', ]; var INITIAL_NAMES_LEN = VAR_NAMES.length; var TYPEOF_OUTCOMES = [ 'function', 'undefined', 'string', 'number', 'object', 'boolean', 'special', 'unknown', 'symbol', 'crap' ]; var unique_vars = []; var loops = 0; var funcs = 0; var called = Object.create(null); var labels = 10000; function rng(max) { var r = randomBytes(2).readUInt16LE(0) / 65536; return Math.floor(max * r); } function strictMode() { return use_strict && rng(4) == 0 ? '"use strict";' : ''; } function createTopLevelCode() { VAR_NAMES.length = INITIAL_NAMES_LEN; // prune any previous names still in the list unique_vars.length = 0; loops = 0; funcs = 0; called = Object.create(null); return [ strictMode(), 'var _calls_ = 10, a = 100, b = 10, c = 0;', rng(2) == 0 ? createStatements(3, MAX_GENERATION_RECURSION_DEPTH, CANNOT_THROW, CANNOT_BREAK, CANNOT_CONTINUE, CANNOT_RETURN, 0) : createFunctions(rng(MAX_GENERATED_TOPLEVELS_PER_RUN) + 1, MAX_GENERATION_RECURSION_DEPTH, DEFUN_OK, CANNOT_THROW, 0), // preceding `null` makes for a cleaner output (empty string still shows up etc) 'console.log(null, a, b, c, Infinity, NaN, undefined);' ].join('\n'); } function createFunctions(n, recurmax, allowDefun, canThrow, stmtDepth) { if (--recurmax < 0) { return ';'; } var s = ''; while (n-- > 0) { s += createFunction(recurmax, allowDefun, canThrow, stmtDepth) + '\n'; } return s; } function createParams() { var params = []; for (var n = rng(4); --n >= 0;) { params.push(createVarName(MANDATORY)); } return params.join(', '); } function createArgs(recurmax, stmtDepth, canThrow) { var args = []; for (var n = rng(4); --n >= 0;) { args.push(rng(2) ? createValue() : createExpression(recurmax - 1, COMMA_OK, stmtDepth, canThrow)); } return args.join(', '); } function filterDirective(s) { if (!generate_directive && !s[1] && /\("/.test(s[2])) s[2] = ';' + s[2]; return s; } function createFunction(recurmax, allowDefun, canThrow, stmtDepth) { if (--recurmax < 0) { return ';'; } if (!STMT_COUNT_FROM_GLOBAL) stmtDepth = 0; var namesLenBefore = VAR_NAMES.length; var name; if (allowDefun || rng(5) > 0) { name = 'f' + funcs++; } else { unique_vars.push('a', 'b', 'c'); name = createVarName(MANDATORY, !allowDefun); unique_vars.length -= 3; } var s = [ 'function ' + name + '(' + createParams() + '){', strictMode() ]; if (rng(5) === 0) { // functions with functions. lower the recursion to prevent a mess. s.push(createFunctions(rng(5) + 1, Math.ceil(recurmax * 0.7), DEFUN_OK, canThrow, stmtDepth)); } else { // functions with statements s.push(createStatements(3, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth)); } s.push('}', ''); s = filterDirective(s).join('\n'); VAR_NAMES.length = namesLenBefore; if (!allowDefun) { // avoid "function statements" (decl inside statements) s = 'var ' + createVarName(MANDATORY) + ' = ' + s; s += '(' + createArgs(recurmax, stmtDepth, canThrow) + ')'; } else if (!(name in called) || rng(3) > 0) { s += 'var ' + createVarName(MANDATORY) + ' = ' + name; s += '(' + createArgs(recurmax, stmtDepth, canThrow) + ')'; } return s + ';'; } function createStatements(n, recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) { if (--recurmax < 0) { return ';'; } var s = ''; while (--n > 0) { s += createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + '\n'; } return s; } function enableLoopControl(flag, defaultValue) { return Array.isArray(flag) && !flag.includes("") ? flag.concat("") : flag || defaultValue; } function createLabel(canBreak, canContinue) { var label; if (rng(10) < 3) { label = ++labels; if (Array.isArray(canBreak)) { canBreak = canBreak.slice(); } else { canBreak = canBreak ? [ "" ] : []; } canBreak.push(label); if (Array.isArray(canContinue)) { canContinue = canContinue.slice(); } else { canContinue = canContinue ? [ "" ] : []; } canContinue.push(label); } return { break: canBreak, continue: canContinue, target: label ? "L" + label + ": " : "" }; } function getLabel(label) { if (!Array.isArray(label)) return ""; label = label[rng(label.length)]; return label && " L" + label; } function createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth, target) { ++stmtDepth; var loop = ++loops; if (--recurmax < 0) { return createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ';'; } // allow to forcefully generate certain structures at first or second recursion level if (target === undefined) { if (stmtDepth === 1 && STMT_FIRST_LEVEL_OVERRIDE >= 0) target = STMT_FIRST_LEVEL_OVERRIDE; else if (stmtDepth === 2 && STMT_SECOND_LEVEL_OVERRIDE >= 0) target = STMT_SECOND_LEVEL_OVERRIDE; else target = STMTS_TO_USE[rng(STMTS_TO_USE.length)]; } switch (target) { case STMT_BLOCK: var label = createLabel(canBreak); return label.target + '{' + createStatements(rng(5) + 1, recurmax, canThrow, label.break, canContinue, cannotReturn, stmtDepth) + '}'; case STMT_IF_ELSE: return 'if (' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ')' + createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + (rng(2) === 1 ? ' else ' + createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) : ''); case STMT_DO_WHILE: var label = createLabel(canBreak, canContinue); canBreak = label.break || enableLoopControl(canBreak, CAN_BREAK); canContinue = label.continue || enableLoopControl(canContinue, CAN_CONTINUE); return '{var brake' + loop + ' = 5; ' + label.target + 'do {' + createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + '} while ((' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ') && --brake' + loop + ' > 0);}'; case STMT_WHILE: var label = createLabel(canBreak, canContinue); canBreak = label.break || enableLoopControl(canBreak, CAN_BREAK); canContinue = label.continue || enableLoopControl(canContinue, CAN_CONTINUE); return '{var brake' + loop + ' = 5; ' + label.target + 'while ((' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ') && --brake' + loop + ' > 0)' + createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + '}'; case STMT_FOR_LOOP: var label = createLabel(canBreak, canContinue); canBreak = label.break || enableLoopControl(canBreak, CAN_BREAK); canContinue = label.continue || enableLoopControl(canContinue, CAN_CONTINUE); return label.target + 'for (var brake' + loop + ' = 5; (' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ') && brake' + loop + ' > 0; --brake' + loop + ')' + createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth); case STMT_FOR_IN: var label = createLabel(canBreak, canContinue); canBreak = label.break || enableLoopControl(canBreak, CAN_BREAK); canContinue = label.continue || enableLoopControl(canContinue, CAN_CONTINUE); var optElementVar = ''; if (rng(5) > 1) { optElementVar = 'c = 1 + c; var ' + createVarName(MANDATORY) + ' = expr' + loop + '[key' + loop + ']; '; } return '{var expr' + loop + ' = ' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + '; ' + label.target + ' for (var key' + loop + ' in expr' + loop + ') {' + optElementVar + createStatement(recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + '}}'; case STMT_SEMI: return use_strict && rng(20) === 0 ? '"use strict";' : ';'; case STMT_EXPR: return createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ';'; case STMT_SWITCH: // note: case args are actual expressions // note: default does not _need_ to be last return 'switch (' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ') { ' + createSwitchParts(recurmax, 4, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + '}'; case STMT_VAR: switch (rng(3)) { case 0: unique_vars.push('c'); var name = createVarName(MANDATORY); unique_vars.pop(); return 'var ' + name + ';'; case 1: // initializer can only have one expression unique_vars.push('c'); var name = createVarName(MANDATORY); unique_vars.pop(); return 'var ' + name + ' = ' + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ';'; default: // initializer can only have one expression unique_vars.push('c'); var n1 = createVarName(MANDATORY); var n2 = createVarName(MANDATORY); unique_vars.pop(); return 'var ' + n1 + ' = ' + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ', ' + n2 + ' = ' + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ';'; } case STMT_RETURN_ETC: switch (rng(8)) { case 0: case 1: case 2: case 3: if (canBreak && rng(5) === 0) return 'break' + getLabel(canBreak) + ';'; if (canContinue && rng(5) === 0) return 'continue' + getLabel(canContinue) + ';'; if (cannotReturn) return createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ';'; if (rng(3) == 0) return '/*3*/return;'; return 'return ' + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ';'; case 4: // this is actually more like a parser test, but perhaps it hits some dead code elimination traps // must wrap in curlies to prevent orphaned `else` statement // note: you can't `throw` without an expression so don't put a `throw` option in this case if (cannotReturn) return createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ';'; return '{ /*2*/ return\n' + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + '}'; default: // must wrap in curlies to prevent orphaned `else` statement if (canThrow && rng(5) === 0) return '{ throw ' + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + '}'; if (cannotReturn) return createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ';'; return '{ return ' + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + '}'; } case STMT_FUNC_EXPR: // "In non-strict mode code, functions can only be declared at top level, inside a block, or ..." // (dont both with func decls in `if`; it's only a parser thing because you cant call them without a block) return '{' + createFunction(recurmax, NO_DEFUN, canThrow, stmtDepth) + '}'; case STMT_TRY: // catch var could cause some problems // note: the "blocks" are syntactically mandatory for try/catch/finally var n = rng(3); // 0=only catch, 1=only finally, 2=catch+finally var s = 'try {' + createStatement(recurmax, n === 1 ? CANNOT_THROW : CAN_THROW, canBreak, canContinue, cannotReturn, stmtDepth) + ' }'; if (n !== 1) { // the catch var should only be accessible in the catch clause... // we have to do go through some trouble here to prevent leaking it var nameLenBefore = VAR_NAMES.length; var catchName = createVarName(MANDATORY); var freshCatchName = VAR_NAMES.length !== nameLenBefore; if (!catch_redef) unique_vars.push(catchName); s += ' catch (' + catchName + ') { ' + createStatements(3, recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + ' }'; // remove catch name if (!catch_redef) unique_vars.pop(); if (freshCatchName) VAR_NAMES.splice(nameLenBefore, 1); } if (n !== 0) s += ' finally { ' + createStatements(3, recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) + ' }'; return s; case STMT_C: return 'c = c + 1;'; default: throw 'no'; } } function createSwitchParts(recurmax, n, canThrow, canBreak, canContinue, cannotReturn, stmtDepth) { var hadDefault = false; var s = ['']; canBreak = enableLoopControl(canBreak, CAN_BREAK); while (n-- > 0) { //hadDefault = n > 0; // disables weird `default` clause positioning (use when handling destabilizes) if (hadDefault || rng(5) > 0) { s.push( 'case ' + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ':', createStatements(rng(3) + 1, recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth), rng(10) > 0 ? ' break;' : '/* fall-through */', '' ); } else { hadDefault = true; s.push( 'default:', createStatements(rng(3) + 1, recurmax, canThrow, canBreak, canContinue, cannotReturn, stmtDepth), '' ); } } return s.join('\n'); } function createExpression(recurmax, noComma, stmtDepth, canThrow) { if (--recurmax < 0) { return '(c = 1 + c, ' + createNestedBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ')'; // note: should return a simple non-recursing expression value! } // since `a` and `b` are our canaries we want them more frequently than other expressions (1/3rd chance of a canary) switch (rng(6)) { case 0: return '(a++ + (' + _createExpression(recurmax, noComma, stmtDepth, canThrow) + '))'; case 1: return '((--b) + (' + _createExpression(recurmax, noComma, stmtDepth, canThrow) + '))'; case 2: return '((c = c + 1) + (' + _createExpression(recurmax, noComma, stmtDepth, canThrow) + '))'; // c only gets incremented default: return '(' + _createExpression(recurmax, noComma, stmtDepth, canThrow) + ')'; } } function _createExpression(recurmax, noComma, stmtDepth, canThrow) { var p = 0; switch (rng(_createExpression.N)) { case p++: case p++: return createUnaryPrefix() + (rng(2) === 1 ? 'a' : 'b'); case p++: case p++: return (rng(2) === 1 ? 'a' : 'b') + createUnaryPostfix(); case p++: case p++: // parens needed because assignments aren't valid unless they're the left-most op(s) in an expression return 'b ' + createAssignment() + ' a'; case p++: case p++: return rng(2) + ' === 1 ? a : b'; case p++: case p++: return createValue(); case p++: case p++: return getVarName(); case p++: return getVarName() + createAssignment() + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow); case p++: return createExpression(recurmax, COMMA_OK, stmtDepth, canThrow); case p++: return createExpression(recurmax, noComma, stmtDepth, canThrow) + '?' + createExpression(recurmax, NO_COMMA, stmtDepth, canThrow) + ':' + createExpression(recurmax, noComma, stmtDepth, canThrow); case p++: case p++: var nameLenBefore = VAR_NAMES.length; unique_vars.push('c'); var name = createVarName(MAYBE); // note: this name is only accessible from _within_ the function. and immutable at that. unique_vars.pop(); var s = []; switch (rng(5)) { case 0: s.push( '(function ' + name + '(){', strictMode(), createStatements(rng(5) + 1, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth), rng(2) == 0 ? '})' : '})()' ); break; case 1: s.push( '+function ' + name + '(){', strictMode(), createStatements(rng(5) + 1, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth), '}()' ); break; case 2: s.push( '!function ' + name + '(){', strictMode(), createStatements(rng(5) + 1, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth), '}()' ); break; case 3: s.push( 'void function ' + name + '(){', strictMode(), createStatements(rng(5) + 1, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth), '}()' ); break; default: var instantiate = rng(4) ? 'new ' : ''; s.push( instantiate + 'function ' + name + '(){', strictMode() ); if (instantiate) for (var i = rng(4); --i >= 0;) { if (rng(2)) s.push('this.' + getDotKey(true) + createAssignment() + _createBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ';'); else s.push('this[' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ']' + createAssignment() + _createBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ';'); } s.push( createStatements(rng(5) + 1, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth), rng(2) == 0 ? '}' : '}()' ); break; } VAR_NAMES.length = nameLenBefore; return filterDirective(s).join('\n'); case p++: case p++: return createTypeofExpr(recurmax, stmtDepth, canThrow); case p++: case p++: // more like a parser test but perhaps comment nodes mess up the analysis? // note: parens not needed for post-fix (since that's the default when ambiguous) // for prefix ops we need parens to prevent accidental syntax errors. switch (rng(6)) { case 0: return 'a/* ignore */++'; case 1: return 'b/* ignore */--'; case 2: return '++/* ignore */a'; case 3: return '--/* ignore */b'; case 4: // only groups that wrap a single variable return a "Reference", so this is still valid. // may just be a parser edge case that is invisible to uglify... return '--(b)'; case 5: // classic 0.3-0.1 case; 1-0.1-0.1-0.1 is not 0.7 :) return 'b + 1-0.1-0.1-0.1'; default: return '--/* ignore */b'; } case p++: case p++: return createNestedBinaryExpr(recurmax, noComma, stmtDepth, canThrow); case p++: case p++: return createUnarySafePrefix() + '(' + createNestedBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ')'; case p++: return " ((" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ") || a || 3).toString() "; case p++: return " /[abc4]/.test(((" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ") || b || 5).toString()) "; case p++: return " ((" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ") || " + rng(10) + ").toString()[" + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + "] "; case p++: return createArrayLiteral(recurmax, stmtDepth, canThrow); case p++: return createObjectLiteral(recurmax, stmtDepth, canThrow); case p++: return createArrayLiteral(recurmax, stmtDepth, canThrow) + '[' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ']'; case p++: return createObjectLiteral(recurmax, stmtDepth, canThrow) + '[' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ']'; case p++: return createArrayLiteral(recurmax, stmtDepth, canThrow) + '.' + getDotKey(); case p++: return createObjectLiteral(recurmax, stmtDepth, canThrow) + '.' + getDotKey(); case p++: var name = getVarName(); return name + ' && ' + name + '[' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ']'; case p++: var name = getVarName(); return name + ' && ' + name + '.' + getDotKey(); case p++: case p++: case p++: case p++: var name = rng(3) == 0 ? getVarName() : 'f' + rng(funcs + 2); called[name] = true; return 'typeof ' + name + ' == "function" && --_calls_ >= 0 && ' + name + '(' + createArgs(recurmax, stmtDepth, canThrow) + ')'; } _createExpression.N = p; return _createExpression(recurmax, noComma, stmtDepth, canThrow); } function createArrayLiteral(recurmax, stmtDepth, canThrow) { recurmax--; var arr = "["; for (var i = rng(6); --i >= 0;) { // in rare cases produce an array hole element var element = rng(20) ? createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) : ""; arr += element + ", "; } return arr + "]"; } var SAFE_KEYS = [ "length", "foo", "a", "b", "c", "undefined", "null", "NaN", "Infinity", "in", "var", ]; var KEYS = [ "''", '"\t"', '"-2"', "0", "1.5", "3", ].concat(SAFE_KEYS); function getDotKey(assign) { var key; do { key = SAFE_KEYS[rng(SAFE_KEYS.length)]; } while (assign && key == "length"); return key; } function createAccessor(recurmax, stmtDepth, canThrow) { var namesLenBefore = VAR_NAMES.length; var s; var prop1 = getDotKey(); if (rng(2) == 0) { s = [ 'get ' + prop1 + '(){', strictMode(), createStatements(2, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth), createStatement(recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth, STMT_RETURN_ETC), '},' ]; } else { var prop2; do { prop2 = getDotKey(); } while (prop1 == prop2); s = [ 'set ' + prop1 + '(' + createVarName(MANDATORY) + '){', strictMode(), createStatements(2, recurmax, canThrow, CANNOT_BREAK, CANNOT_CONTINUE, CAN_RETURN, stmtDepth), 'this.' + prop2 + createAssignment() + _createBinaryExpr(recurmax, COMMA_OK, stmtDepth, canThrow) + ';', '},' ]; } VAR_NAMES.length = namesLenBefore; return filterDirective(s).join('\n'); } function createObjectLiteral(recurmax, stmtDepth, canThrow) { recurmax--; var obj = ['({']; for (var i = rng(6); --i >= 0;) { if (rng(20) == 0) { obj.push(createAccessor(recurmax, stmtDepth, canThrow)); } else { var key = KEYS[rng(KEYS.length)]; obj.push(key + ':(' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + '),'); } } obj.push('})'); return obj.join('\n'); } function createNestedBinaryExpr(recurmax, noComma, stmtDepth, canThrow) { recurmax = 3; // note that this generates 2^recurmax expression parts... make sure to cap it return _createSimpleBinaryExpr(recurmax, noComma, stmtDepth, canThrow); } function _createBinaryExpr(recurmax, noComma, stmtDepth, canThrow) { return '(' + _createSimpleBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + createBinaryOp(noComma) + _createSimpleBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ')'; } function _createSimpleBinaryExpr(recurmax, noComma, stmtDepth, canThrow) { // intentionally generate more hardcore ops if (--recurmax < 0) return createValue(); var assignee, expr; switch (rng(30)) { case 0: return '(c = c + 1, ' + _createSimpleBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ')'; case 1: return '(' + createUnarySafePrefix() + '(' + _createSimpleBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + '))'; case 2: assignee = getVarName(); return '(' + assignee + createAssignment() + _createBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ')'; case 3: assignee = getVarName(); expr = '(' + assignee + '[' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ']' + createAssignment() + _createBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ')'; return canThrow && rng(10) == 0 ? expr : '(' + assignee + ' && ' + expr + ')'; case 4: assignee = getVarName(); expr = '(' + assignee + '.' + getDotKey(true) + createAssignment() + _createBinaryExpr(recurmax, noComma, stmtDepth, canThrow) + ')'; return canThrow && rng(10) == 0 ? expr : '(' + assignee + ' && ' + expr + ')'; default: return _createBinaryExpr(recurmax, noComma, stmtDepth, canThrow); } } function createTypeofExpr(recurmax, stmtDepth, canThrow) { switch (rng(8)) { case 0: return '(typeof ' + createVarName(MANDATORY, DONT_STORE) + ' === "' + TYPEOF_OUTCOMES[rng(TYPEOF_OUTCOMES.length)] + '")'; case 1: return '(typeof ' + createVarName(MANDATORY, DONT_STORE) + ' !== "' + TYPEOF_OUTCOMES[rng(TYPEOF_OUTCOMES.length)] + '")'; case 2: return '(typeof ' + createVarName(MANDATORY, DONT_STORE) + ' == "' + TYPEOF_OUTCOMES[rng(TYPEOF_OUTCOMES.length)] + '")'; case 3: return '(typeof ' + createVarName(MANDATORY, DONT_STORE) + ' != "' + TYPEOF_OUTCOMES[rng(TYPEOF_OUTCOMES.length)] + '")'; case 4: return '(typeof ' + createVarName(MANDATORY, DONT_STORE) + ')'; default: return '(typeof ' + createExpression(recurmax, COMMA_OK, stmtDepth, canThrow) + ')'; } } function createValue() { return VALUES[rng(VALUES.length)]; } function createBinaryOp(noComma) { if (noComma) return BINARY_OPS_NO_COMMA[rng(BINARY_OPS_NO_COMMA.length)]; return BINARY_OPS[rng(BINARY_OPS.length)]; } function createAssignment() { return ASSIGNMENTS[rng(ASSIGNMENTS.length)]; } function createUnarySafePrefix() { return UNARY_SAFE[rng(UNARY_SAFE.length)]; } function createUnaryPrefix() { return UNARY_PREFIX[rng(UNARY_PREFIX.length)]; } function createUnaryPostfix() { return UNARY_POSTFIX[rng(UNARY_POSTFIX.length)]; } function getVarName() { // try to get a generated name reachable from current scope. default to just `a` return VAR_NAMES[INITIAL_NAMES_LEN + rng(VAR_NAMES.length - INITIAL_NAMES_LEN)] || 'a'; } function createVarName(maybe, dontStore) { if (!maybe || rng(2)) { var suffix = rng(3); var name; do { name = VAR_NAMES[rng(VAR_NAMES.length)]; if (suffix) name += '_' + suffix; } while (unique_vars.includes(name)); if (suffix && !dontStore) VAR_NAMES.push(name); return name; } return ''; } if (require.main !== module) { exports.createTopLevelCode = createTopLevelCode; exports.num_iterations = num_iterations; return; } function println(msg) { if (typeof msg != "undefined") process.stdout.write(msg); process.stdout.write("\n"); } function errorln(msg) { if (typeof msg != "undefined") process.stderr.write(msg); process.stderr.write("\n"); } function try_beautify(code, result, printfn) { var beautified = UglifyJS.minify(code, { compress: false, mangle: false, output: { beautify: true, braces: true, }, }); if (beautified.error) { printfn("// !!! beautify failed !!!"); printfn(beautified.error.stack); } else if (sandbox.same_stdout(sandbox.run_code(beautified.code), result)) { printfn("// (beautified)"); printfn(beautified.code); return; } printfn("//"); printfn(code); } var default_options = UglifyJS.default_options(); function log_suspects(minify_options, component) { var options = component in minify_options ? minify_options[component] : true; if (!options) return; if (typeof options != "object") options = {}; var defs = default_options[component]; var suspects = Object.keys(defs).filter(function(name) { var flip = name == "keep_fargs"; if (flip ? name in options : (name in options ? options : defs)[name]) { var m = JSON.parse(JSON.stringify(minify_options)); var o = JSON.parse(JSON.stringify(options)); o[name] = flip; m[component] = o; var result = UglifyJS.minify(original_code, m); if (result.error) { errorln("Error testing options." + component + "." + name); errorln(result.error.stack); } else { var r = sandbox.run_code(result.code); return sandbox.same_stdout(original_result, r); } } }); if (suspects.length > 0) { errorln("Suspicious " + component + " options:"); suspects.forEach(function(name) { errorln(" " + name); }); errorln(); } } function log_rename(options) { var m = JSON.parse(JSON.stringify(options)); m.rename = false; var result = UglifyJS.minify(original_code, m); if (result.error) { errorln("Error testing options.rename"); errorln(result.error.stack); } else { var r = sandbox.run_code(result.code); if (sandbox.same_stdout(original_result, r)) { errorln("Suspicious options:"); errorln(" rename"); errorln(); } } } function log(options) { if (!ok) errorln('\n\n\n\n\n\n!!!!!!!!!!\n\n\n'); errorln("//============================================================="); if (!ok) errorln("// !!!!!! Failed... round " + round); errorln("// original code"); try_beautify(original_code, original_result, errorln); errorln(); errorln(); errorln("//-------------------------------------------------------------"); if (typeof uglify_code == "string") { errorln("// uglified code"); try_beautify(uglify_code, uglify_result, errorln); errorln(); errorln(); errorln("original result:"); errorln(typeof original_result == "string" ? original_result : original_result.stack); errorln("uglified result:"); errorln(typeof uglify_result == "string" ? uglify_result : uglify_result.stack); } else { errorln("// !!! uglify failed !!!"); errorln(uglify_code.stack); if (typeof original_result != "string") { errorln(); errorln(); errorln("original stacktrace:"); errorln(original_result.stack); } } errorln("minify(options):"); options = JSON.parse(options); errorln(JSON.stringify(options, null, 2)); errorln(); if (!ok && typeof uglify_code == "string") { Object.keys(default_options).forEach(log_suspects.bind(null, options)); log_rename(options); errorln("!!!!!! Failed... round " + round); } } var fallback_options = [ JSON.stringify({ compress: false, mangle: false }) ]; var minify_options = require("./ufuzz.json").map(JSON.stringify); var original_code, original_result; var uglify_code, uglify_result, ok; for (var round = 1; round <= num_iterations; round++) { process.stdout.write(round + " of " + num_iterations + "\r"); original_code = createTopLevelCode(); original_result = sandbox.run_code(original_code); (typeof original_result != "string" ? fallback_options : minify_options).forEach(function(options) { uglify_code = UglifyJS.minify(original_code, JSON.parse(options)); if (!uglify_code.error) { uglify_code = uglify_code.code; uglify_result = sandbox.run_code(uglify_code); ok = sandbox.same_stdout(original_result, uglify_result); } else { uglify_code = uglify_code.error; if (typeof original_result != "string") { ok = uglify_code.name == original_result.name; } } if (verbose || (verbose_interval && !(round % INTERVAL_COUNT)) || !ok) log(options); else if (typeof original_result != "string") { println("//============================================================="); println("// original code"); try_beautify(original_code, original_result, println); println(); println(); println("original result:"); println(original_result.stack); println(); } if (!ok && isFinite(num_iterations)) { println(); process.exit(1); } }); } println(); terser-4.1.2/test/ufuzz.json000066400000000000000000000014341351061312300160540ustar00rootroot00000000000000[ { "compress": false, "mangle": false, "output": { "beautify": true, "braces": true }, "rename": true }, { "compress": false }, { "mangle": false }, {}, { "toplevel": true }, { "compress": { "passes": 1e6, "unsafe": true }, "toplevel": true }, { "compress": { "arguments": true, "keep_fargs": false, "passes": 1e6, "sequences": 1e6, "unsafe": true, "unsafe_Function": true, "unsafe_math": true, "unsafe_proto": true, "unsafe_regexp": true } }, { "safari10": true } ] terser-4.1.2/tools/000077500000000000000000000000001351061312300141555ustar00rootroot00000000000000terser-4.1.2/tools/colorless-console.js000066400000000000000000000004061351061312300201600ustar00rootroot00000000000000"use strict" if (Number((/([0-9]+)\./.exec(process.version) || [])[1]) >= 10) { var Console = require("console").Console; global.console = new Console({ stdout: process.stdout, stderr: process.stderr, colorMode: false }); } terser-4.1.2/tools/domprops.js000066400000000000000000003535071351061312300163730ustar00rootroot00000000000000export var domprops = [ "$&", "$'", "$*", "$+", "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9", "$_", "$`", "$input", "@@iterator", "ABORT_ERR", "ACTIVE", "ACTIVE_ATTRIBUTES", "ACTIVE_TEXTURE", "ACTIVE_UNIFORMS", "ADDITION", "ALIASED_LINE_WIDTH_RANGE", "ALIASED_POINT_SIZE_RANGE", "ALLOW_KEYBOARD_INPUT", "ALLPASS", "ALPHA", "ALPHA_BITS", "ALT_MASK", "ALWAYS", "ANY_TYPE", "ANY_UNORDERED_NODE_TYPE", "ARRAY_BUFFER", "ARRAY_BUFFER_BINDING", "ATTACHED_SHADERS", "ATTRIBUTE_NODE", "AT_TARGET", "AddSearchProvider", "AnalyserNode", "AnimationEvent", "AnonXMLHttpRequest", "ApplicationCache", "ApplicationCacheErrorEvent", "Array", "ArrayBuffer", "Attr", "Audio", "AudioBuffer", "AudioBufferSourceNode", "AudioContext", "AudioDestinationNode", "AudioListener", "AudioNode", "AudioParam", "AudioProcessingEvent", "AudioStreamTrack", "AutocompleteErrorEvent", "BACK", "BAD_BOUNDARYPOINTS_ERR", "BANDPASS", "BLEND", "BLEND_COLOR", "BLEND_DST_ALPHA", "BLEND_DST_RGB", "BLEND_EQUATION", "BLEND_EQUATION_ALPHA", "BLEND_EQUATION_RGB", "BLEND_SRC_ALPHA", "BLEND_SRC_RGB", "BLUE_BITS", "BLUR", "BOOL", "BOOLEAN_TYPE", "BOOL_VEC2", "BOOL_VEC3", "BOOL_VEC4", "BOTH", "BROWSER_DEFAULT_WEBGL", "BUBBLING_PHASE", "BUFFER_SIZE", "BUFFER_USAGE", "BYTE", "BYTES_PER_ELEMENT", "BarProp", "BaseHref", "BatteryManager", "BeforeLoadEvent", "BeforeUnloadEvent", "BiquadFilterNode", "Blob", "BlobEvent", "Boolean", "CAPTURING_PHASE", "CCW", "CDATASection", "CDATA_SECTION_NODE", "CHANGE", "CHARSET_RULE", "CHECKING", "CLAMP_TO_EDGE", "CLICK", "CLOSED", "CLOSING", "COLOR_ATTACHMENT0", "COLOR_BUFFER_BIT", "COLOR_CLEAR_VALUE", "COLOR_WRITEMASK", "COMMENT_NODE", "COMPILE_STATUS", "COMPRESSED_RGBA_S3TC_DXT1_EXT", "COMPRESSED_RGBA_S3TC_DXT3_EXT", "COMPRESSED_RGBA_S3TC_DXT5_EXT", "COMPRESSED_RGB_S3TC_DXT1_EXT", "COMPRESSED_TEXTURE_FORMATS", "CONNECTING", "CONSTANT_ALPHA", "CONSTANT_COLOR", "CONSTRAINT_ERR", "CONTEXT_LOST_WEBGL", "CONTROL_MASK", "COUNTER_STYLE_RULE", "CSS", "CSS2Properties", "CSSCharsetRule", "CSSConditionRule", "CSSCounterStyleRule", "CSSFontFaceRule", "CSSFontFeatureValuesRule", "CSSGroupingRule", "CSSImportRule", "CSSKeyframeRule", "CSSKeyframesRule", "CSSMediaRule", "CSSMozDocumentRule", "CSSNameSpaceRule", "CSSPageRule", "CSSPrimitiveValue", "CSSRule", "CSSRuleList", "CSSStyleDeclaration", "CSSStyleRule", "CSSStyleSheet", "CSSSupportsRule", "CSSUnknownRule", "CSSValue", "CSSValueList", "CSSVariablesDeclaration", "CSSVariablesRule", "CSSViewportRule", "CSS_ATTR", "CSS_CM", "CSS_COUNTER", "CSS_CUSTOM", "CSS_DEG", "CSS_DIMENSION", "CSS_EMS", "CSS_EXS", "CSS_FILTER_BLUR", "CSS_FILTER_BRIGHTNESS", "CSS_FILTER_CONTRAST", "CSS_FILTER_CUSTOM", "CSS_FILTER_DROP_SHADOW", "CSS_FILTER_GRAYSCALE", "CSS_FILTER_HUE_ROTATE", "CSS_FILTER_INVERT", "CSS_FILTER_OPACITY", "CSS_FILTER_REFERENCE", "CSS_FILTER_SATURATE", "CSS_FILTER_SEPIA", "CSS_GRAD", "CSS_HZ", "CSS_IDENT", "CSS_IN", "CSS_INHERIT", "CSS_KHZ", "CSS_MATRIX", "CSS_MATRIX3D", "CSS_MM", "CSS_MS", "CSS_NUMBER", "CSS_PC", "CSS_PERCENTAGE", "CSS_PERSPECTIVE", "CSS_PRIMITIVE_VALUE", "CSS_PT", "CSS_PX", "CSS_RAD", "CSS_RECT", "CSS_RGBCOLOR", "CSS_ROTATE", "CSS_ROTATE3D", "CSS_ROTATEX", "CSS_ROTATEY", "CSS_ROTATEZ", "CSS_S", "CSS_SCALE", "CSS_SCALE3D", "CSS_SCALEX", "CSS_SCALEY", "CSS_SCALEZ", "CSS_SKEW", "CSS_SKEWX", "CSS_SKEWY", "CSS_STRING", "CSS_TRANSLATE", "CSS_TRANSLATE3D", "CSS_TRANSLATEX", "CSS_TRANSLATEY", "CSS_TRANSLATEZ", "CSS_UNKNOWN", "CSS_URI", "CSS_VALUE_LIST", "CSS_VH", "CSS_VMAX", "CSS_VMIN", "CSS_VW", "CULL_FACE", "CULL_FACE_MODE", "CURRENT_PROGRAM", "CURRENT_VERTEX_ATTRIB", "CUSTOM", "CW", "CanvasGradient", "CanvasPattern", "CanvasRenderingContext2D", "CaretPosition", "ChannelMergerNode", "ChannelSplitterNode", "CharacterData", "ClientRect", "ClientRectList", "Clipboard", "ClipboardEvent", "CloseEvent", "Collator", "CommandEvent", "Comment", "CompositionEvent", "Console", "Controllers", "ConvolverNode", "Counter", "Crypto", "CryptoKey", "CustomEvent", "DATABASE_ERR", "DATA_CLONE_ERR", "DATA_ERR", "DBLCLICK", "DECR", "DECR_WRAP", "DELETE_STATUS", "DEPTH_ATTACHMENT", "DEPTH_BITS", "DEPTH_BUFFER_BIT", "DEPTH_CLEAR_VALUE", "DEPTH_COMPONENT", "DEPTH_COMPONENT16", "DEPTH_FUNC", "DEPTH_RANGE", "DEPTH_STENCIL", "DEPTH_STENCIL_ATTACHMENT", "DEPTH_TEST", "DEPTH_WRITEMASK", "DIRECTION_DOWN", "DIRECTION_LEFT", "DIRECTION_RIGHT", "DIRECTION_UP", "DISABLED", "DISPATCH_REQUEST_ERR", "DITHER", "DOCUMENT_FRAGMENT_NODE", "DOCUMENT_NODE", "DOCUMENT_POSITION_CONTAINED_BY", "DOCUMENT_POSITION_CONTAINS", "DOCUMENT_POSITION_DISCONNECTED", "DOCUMENT_POSITION_FOLLOWING", "DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC", "DOCUMENT_POSITION_PRECEDING", "DOCUMENT_TYPE_NODE", "DOMCursor", "DOMError", "DOMException", "DOMImplementation", "DOMImplementationLS", "DOMMatrix", "DOMMatrixReadOnly", "DOMParser", "DOMPoint", "DOMPointReadOnly", "DOMQuad", "DOMRect", "DOMRectList", "DOMRectReadOnly", "DOMRequest", "DOMSTRING_SIZE_ERR", "DOMSettableTokenList", "DOMStringList", "DOMStringMap", "DOMTokenList", "DOMTransactionEvent", "DOM_DELTA_LINE", "DOM_DELTA_PAGE", "DOM_DELTA_PIXEL", "DOM_INPUT_METHOD_DROP", "DOM_INPUT_METHOD_HANDWRITING", "DOM_INPUT_METHOD_IME", "DOM_INPUT_METHOD_KEYBOARD", "DOM_INPUT_METHOD_MULTIMODAL", "DOM_INPUT_METHOD_OPTION", "DOM_INPUT_METHOD_PASTE", "DOM_INPUT_METHOD_SCRIPT", "DOM_INPUT_METHOD_UNKNOWN", "DOM_INPUT_METHOD_VOICE", "DOM_KEY_LOCATION_JOYSTICK", "DOM_KEY_LOCATION_LEFT", "DOM_KEY_LOCATION_MOBILE", "DOM_KEY_LOCATION_NUMPAD", "DOM_KEY_LOCATION_RIGHT", "DOM_KEY_LOCATION_STANDARD", "DOM_VK_0", "DOM_VK_1", "DOM_VK_2", "DOM_VK_3", "DOM_VK_4", "DOM_VK_5", "DOM_VK_6", "DOM_VK_7", "DOM_VK_8", "DOM_VK_9", "DOM_VK_A", "DOM_VK_ACCEPT", "DOM_VK_ADD", "DOM_VK_ALT", "DOM_VK_ALTGR", "DOM_VK_AMPERSAND", "DOM_VK_ASTERISK", "DOM_VK_AT", "DOM_VK_ATTN", "DOM_VK_B", "DOM_VK_BACKSPACE", "DOM_VK_BACK_QUOTE", "DOM_VK_BACK_SLASH", "DOM_VK_BACK_SPACE", "DOM_VK_C", "DOM_VK_CANCEL", "DOM_VK_CAPS_LOCK", "DOM_VK_CIRCUMFLEX", "DOM_VK_CLEAR", "DOM_VK_CLOSE_BRACKET", "DOM_VK_CLOSE_CURLY_BRACKET", "DOM_VK_CLOSE_PAREN", "DOM_VK_COLON", "DOM_VK_COMMA", "DOM_VK_CONTEXT_MENU", "DOM_VK_CONTROL", "DOM_VK_CONVERT", "DOM_VK_CRSEL", "DOM_VK_CTRL", "DOM_VK_D", "DOM_VK_DECIMAL", "DOM_VK_DELETE", "DOM_VK_DIVIDE", "DOM_VK_DOLLAR", "DOM_VK_DOUBLE_QUOTE", "DOM_VK_DOWN", "DOM_VK_E", "DOM_VK_EISU", "DOM_VK_END", "DOM_VK_ENTER", "DOM_VK_EQUALS", "DOM_VK_EREOF", "DOM_VK_ESCAPE", "DOM_VK_EXCLAMATION", "DOM_VK_EXECUTE", "DOM_VK_EXSEL", "DOM_VK_F", "DOM_VK_F1", "DOM_VK_F10", "DOM_VK_F11", "DOM_VK_F12", "DOM_VK_F13", "DOM_VK_F14", "DOM_VK_F15", "DOM_VK_F16", "DOM_VK_F17", "DOM_VK_F18", "DOM_VK_F19", "DOM_VK_F2", "DOM_VK_F20", "DOM_VK_F21", "DOM_VK_F22", "DOM_VK_F23", "DOM_VK_F24", "DOM_VK_F25", "DOM_VK_F26", "DOM_VK_F27", "DOM_VK_F28", "DOM_VK_F29", "DOM_VK_F3", "DOM_VK_F30", "DOM_VK_F31", "DOM_VK_F32", "DOM_VK_F33", "DOM_VK_F34", "DOM_VK_F35", "DOM_VK_F36", "DOM_VK_F4", "DOM_VK_F5", "DOM_VK_F6", "DOM_VK_F7", "DOM_VK_F8", "DOM_VK_F9", "DOM_VK_FINAL", "DOM_VK_FRONT", "DOM_VK_G", "DOM_VK_GREATER_THAN", "DOM_VK_H", "DOM_VK_HANGUL", "DOM_VK_HANJA", "DOM_VK_HASH", "DOM_VK_HELP", "DOM_VK_HK_TOGGLE", "DOM_VK_HOME", "DOM_VK_HYPHEN_MINUS", "DOM_VK_I", "DOM_VK_INSERT", "DOM_VK_J", "DOM_VK_JUNJA", "DOM_VK_K", "DOM_VK_KANA", "DOM_VK_KANJI", "DOM_VK_L", "DOM_VK_LEFT", "DOM_VK_LEFT_TAB", "DOM_VK_LESS_THAN", "DOM_VK_M", "DOM_VK_META", "DOM_VK_MODECHANGE", "DOM_VK_MULTIPLY", "DOM_VK_N", "DOM_VK_NONCONVERT", "DOM_VK_NUMPAD0", "DOM_VK_NUMPAD1", "DOM_VK_NUMPAD2", "DOM_VK_NUMPAD3", "DOM_VK_NUMPAD4", "DOM_VK_NUMPAD5", "DOM_VK_NUMPAD6", "DOM_VK_NUMPAD7", "DOM_VK_NUMPAD8", "DOM_VK_NUMPAD9", "DOM_VK_NUM_LOCK", "DOM_VK_O", "DOM_VK_OEM_1", "DOM_VK_OEM_102", "DOM_VK_OEM_2", "DOM_VK_OEM_3", "DOM_VK_OEM_4", "DOM_VK_OEM_5", "DOM_VK_OEM_6", "DOM_VK_OEM_7", "DOM_VK_OEM_8", "DOM_VK_OEM_COMMA", "DOM_VK_OEM_MINUS", "DOM_VK_OEM_PERIOD", "DOM_VK_OEM_PLUS", "DOM_VK_OPEN_BRACKET", "DOM_VK_OPEN_CURLY_BRACKET", "DOM_VK_OPEN_PAREN", "DOM_VK_P", "DOM_VK_PA1", "DOM_VK_PAGEDOWN", "DOM_VK_PAGEUP", "DOM_VK_PAGE_DOWN", "DOM_VK_PAGE_UP", "DOM_VK_PAUSE", "DOM_VK_PERCENT", "DOM_VK_PERIOD", "DOM_VK_PIPE", "DOM_VK_PLAY", "DOM_VK_PLUS", "DOM_VK_PRINT", "DOM_VK_PRINTSCREEN", "DOM_VK_PROCESSKEY", "DOM_VK_PROPERITES", "DOM_VK_Q", "DOM_VK_QUESTION_MARK", "DOM_VK_QUOTE", "DOM_VK_R", "DOM_VK_REDO", "DOM_VK_RETURN", "DOM_VK_RIGHT", "DOM_VK_S", "DOM_VK_SCROLL_LOCK", "DOM_VK_SELECT", "DOM_VK_SEMICOLON", "DOM_VK_SEPARATOR", "DOM_VK_SHIFT", "DOM_VK_SLASH", "DOM_VK_SLEEP", "DOM_VK_SPACE", "DOM_VK_SUBTRACT", "DOM_VK_T", "DOM_VK_TAB", "DOM_VK_TILDE", "DOM_VK_U", "DOM_VK_UNDERSCORE", "DOM_VK_UNDO", "DOM_VK_UNICODE", "DOM_VK_UP", "DOM_VK_V", "DOM_VK_VOLUME_DOWN", "DOM_VK_VOLUME_MUTE", "DOM_VK_VOLUME_UP", "DOM_VK_W", "DOM_VK_WIN", "DOM_VK_WINDOW", "DOM_VK_WIN_ICO_00", "DOM_VK_WIN_ICO_CLEAR", "DOM_VK_WIN_ICO_HELP", "DOM_VK_WIN_OEM_ATTN", "DOM_VK_WIN_OEM_AUTO", "DOM_VK_WIN_OEM_BACKTAB", "DOM_VK_WIN_OEM_CLEAR", "DOM_VK_WIN_OEM_COPY", "DOM_VK_WIN_OEM_CUSEL", "DOM_VK_WIN_OEM_ENLW", "DOM_VK_WIN_OEM_FINISH", "DOM_VK_WIN_OEM_FJ_JISHO", "DOM_VK_WIN_OEM_FJ_LOYA", "DOM_VK_WIN_OEM_FJ_MASSHOU", "DOM_VK_WIN_OEM_FJ_ROYA", "DOM_VK_WIN_OEM_FJ_TOUROKU", "DOM_VK_WIN_OEM_JUMP", "DOM_VK_WIN_OEM_PA1", "DOM_VK_WIN_OEM_PA2", "DOM_VK_WIN_OEM_PA3", "DOM_VK_WIN_OEM_RESET", "DOM_VK_WIN_OEM_WSCTRL", "DOM_VK_X", "DOM_VK_XF86XK_ADD_FAVORITE", "DOM_VK_XF86XK_APPLICATION_LEFT", "DOM_VK_XF86XK_APPLICATION_RIGHT", "DOM_VK_XF86XK_AUDIO_CYCLE_TRACK", "DOM_VK_XF86XK_AUDIO_FORWARD", "DOM_VK_XF86XK_AUDIO_LOWER_VOLUME", "DOM_VK_XF86XK_AUDIO_MEDIA", "DOM_VK_XF86XK_AUDIO_MUTE", "DOM_VK_XF86XK_AUDIO_NEXT", "DOM_VK_XF86XK_AUDIO_PAUSE", "DOM_VK_XF86XK_AUDIO_PLAY", "DOM_VK_XF86XK_AUDIO_PREV", "DOM_VK_XF86XK_AUDIO_RAISE_VOLUME", "DOM_VK_XF86XK_AUDIO_RANDOM_PLAY", "DOM_VK_XF86XK_AUDIO_RECORD", "DOM_VK_XF86XK_AUDIO_REPEAT", "DOM_VK_XF86XK_AUDIO_REWIND", "DOM_VK_XF86XK_AUDIO_STOP", "DOM_VK_XF86XK_AWAY", "DOM_VK_XF86XK_BACK", "DOM_VK_XF86XK_BACK_FORWARD", "DOM_VK_XF86XK_BATTERY", "DOM_VK_XF86XK_BLUE", "DOM_VK_XF86XK_BLUETOOTH", "DOM_VK_XF86XK_BOOK", "DOM_VK_XF86XK_BRIGHTNESS_ADJUST", "DOM_VK_XF86XK_CALCULATOR", "DOM_VK_XF86XK_CALENDAR", "DOM_VK_XF86XK_CD", "DOM_VK_XF86XK_CLOSE", "DOM_VK_XF86XK_COMMUNITY", "DOM_VK_XF86XK_CONTRAST_ADJUST", "DOM_VK_XF86XK_COPY", "DOM_VK_XF86XK_CUT", "DOM_VK_XF86XK_CYCLE_ANGLE", "DOM_VK_XF86XK_DISPLAY", "DOM_VK_XF86XK_DOCUMENTS", "DOM_VK_XF86XK_DOS", "DOM_VK_XF86XK_EJECT", "DOM_VK_XF86XK_EXCEL", "DOM_VK_XF86XK_EXPLORER", "DOM_VK_XF86XK_FAVORITES", "DOM_VK_XF86XK_FINANCE", "DOM_VK_XF86XK_FORWARD", "DOM_VK_XF86XK_FRAME_BACK", "DOM_VK_XF86XK_FRAME_FORWARD", "DOM_VK_XF86XK_GAME", "DOM_VK_XF86XK_GO", "DOM_VK_XF86XK_GREEN", "DOM_VK_XF86XK_HIBERNATE", "DOM_VK_XF86XK_HISTORY", "DOM_VK_XF86XK_HOME_PAGE", "DOM_VK_XF86XK_HOT_LINKS", "DOM_VK_XF86XK_I_TOUCH", "DOM_VK_XF86XK_KBD_BRIGHTNESS_DOWN", "DOM_VK_XF86XK_KBD_BRIGHTNESS_UP", "DOM_VK_XF86XK_KBD_LIGHT_ON_OFF", "DOM_VK_XF86XK_LAUNCH0", "DOM_VK_XF86XK_LAUNCH1", "DOM_VK_XF86XK_LAUNCH2", "DOM_VK_XF86XK_LAUNCH3", "DOM_VK_XF86XK_LAUNCH4", "DOM_VK_XF86XK_LAUNCH5", "DOM_VK_XF86XK_LAUNCH6", "DOM_VK_XF86XK_LAUNCH7", "DOM_VK_XF86XK_LAUNCH8", "DOM_VK_XF86XK_LAUNCH9", "DOM_VK_XF86XK_LAUNCH_A", "DOM_VK_XF86XK_LAUNCH_B", "DOM_VK_XF86XK_LAUNCH_C", "DOM_VK_XF86XK_LAUNCH_D", "DOM_VK_XF86XK_LAUNCH_E", "DOM_VK_XF86XK_LAUNCH_F", "DOM_VK_XF86XK_LIGHT_BULB", "DOM_VK_XF86XK_LOG_OFF", "DOM_VK_XF86XK_MAIL", "DOM_VK_XF86XK_MAIL_FORWARD", "DOM_VK_XF86XK_MARKET", "DOM_VK_XF86XK_MEETING", "DOM_VK_XF86XK_MEMO", "DOM_VK_XF86XK_MENU_KB", "DOM_VK_XF86XK_MENU_PB", "DOM_VK_XF86XK_MESSENGER", "DOM_VK_XF86XK_MON_BRIGHTNESS_DOWN", "DOM_VK_XF86XK_MON_BRIGHTNESS_UP", "DOM_VK_XF86XK_MUSIC", "DOM_VK_XF86XK_MY_COMPUTER", "DOM_VK_XF86XK_MY_SITES", "DOM_VK_XF86XK_NEW", "DOM_VK_XF86XK_NEWS", "DOM_VK_XF86XK_OFFICE_HOME", "DOM_VK_XF86XK_OPEN", "DOM_VK_XF86XK_OPEN_URL", "DOM_VK_XF86XK_OPTION", "DOM_VK_XF86XK_PASTE", "DOM_VK_XF86XK_PHONE", "DOM_VK_XF86XK_PICTURES", "DOM_VK_XF86XK_POWER_DOWN", "DOM_VK_XF86XK_POWER_OFF", "DOM_VK_XF86XK_RED", "DOM_VK_XF86XK_REFRESH", "DOM_VK_XF86XK_RELOAD", "DOM_VK_XF86XK_REPLY", "DOM_VK_XF86XK_ROCKER_DOWN", "DOM_VK_XF86XK_ROCKER_ENTER", "DOM_VK_XF86XK_ROCKER_UP", "DOM_VK_XF86XK_ROTATE_WINDOWS", "DOM_VK_XF86XK_ROTATION_KB", "DOM_VK_XF86XK_ROTATION_PB", "DOM_VK_XF86XK_SAVE", "DOM_VK_XF86XK_SCREEN_SAVER", "DOM_VK_XF86XK_SCROLL_CLICK", "DOM_VK_XF86XK_SCROLL_DOWN", "DOM_VK_XF86XK_SCROLL_UP", "DOM_VK_XF86XK_SEARCH", "DOM_VK_XF86XK_SEND", "DOM_VK_XF86XK_SHOP", "DOM_VK_XF86XK_SPELL", "DOM_VK_XF86XK_SPLIT_SCREEN", "DOM_VK_XF86XK_STANDBY", "DOM_VK_XF86XK_START", "DOM_VK_XF86XK_STOP", "DOM_VK_XF86XK_SUBTITLE", "DOM_VK_XF86XK_SUPPORT", "DOM_VK_XF86XK_SUSPEND", "DOM_VK_XF86XK_TASK_PANE", "DOM_VK_XF86XK_TERMINAL", "DOM_VK_XF86XK_TIME", "DOM_VK_XF86XK_TOOLS", "DOM_VK_XF86XK_TOP_MENU", "DOM_VK_XF86XK_TO_DO_LIST", "DOM_VK_XF86XK_TRAVEL", "DOM_VK_XF86XK_USER1KB", "DOM_VK_XF86XK_USER2KB", "DOM_VK_XF86XK_USER_PB", "DOM_VK_XF86XK_UWB", "DOM_VK_XF86XK_VENDOR_HOME", "DOM_VK_XF86XK_VIDEO", "DOM_VK_XF86XK_VIEW", "DOM_VK_XF86XK_WAKE_UP", "DOM_VK_XF86XK_WEB_CAM", "DOM_VK_XF86XK_WHEEL_BUTTON", "DOM_VK_XF86XK_WLAN", "DOM_VK_XF86XK_WORD", "DOM_VK_XF86XK_WWW", "DOM_VK_XF86XK_XFER", "DOM_VK_XF86XK_YELLOW", "DOM_VK_XF86XK_ZOOM_IN", "DOM_VK_XF86XK_ZOOM_OUT", "DOM_VK_Y", "DOM_VK_Z", "DOM_VK_ZOOM", "DONE", "DONT_CARE", "DOWNLOADING", "DRAGDROP", "DST_ALPHA", "DST_COLOR", "DYNAMIC_DRAW", "DataChannel", "DataTransfer", "DataTransferItem", "DataTransferItemList", "DataView", "Date", "DateTimeFormat", "DelayNode", "DesktopNotification", "DesktopNotificationCenter", "DeviceLightEvent", "DeviceMotionEvent", "DeviceOrientationEvent", "DeviceProximityEvent", "DeviceStorage", "DeviceStorageChangeEvent", "Document", "DocumentFragment", "DocumentType", "DragEvent", "DynamicsCompressorNode", "E", "ELEMENT_ARRAY_BUFFER", "ELEMENT_ARRAY_BUFFER_BINDING", "ELEMENT_NODE", "EMPTY", "ENCODING_ERR", "ENDED", "END_TO_END", "END_TO_START", "ENTITY_NODE", "ENTITY_REFERENCE_NODE", "EPSILON", "EQUAL", "EQUALPOWER", "ERROR", "EXPONENTIAL_DISTANCE", "Element", "ElementQuery", "Entity", "EntityReference", "Error", "ErrorEvent", "EvalError", "Event", "EventException", "EventSource", "EventTarget", "External", "FASTEST", "FIDOSDK", "FILTER_ACCEPT", "FILTER_INTERRUPT", "FILTER_REJECT", "FILTER_SKIP", "FINISHED_STATE", "FIRST_ORDERED_NODE_TYPE", "FLOAT", "FLOAT_MAT2", "FLOAT_MAT3", "FLOAT_MAT4", "FLOAT_VEC2", "FLOAT_VEC3", "FLOAT_VEC4", "FOCUS", "FONT_FACE_RULE", "FONT_FEATURE_VALUES_RULE", "FRAGMENT_SHADER", "FRAGMENT_SHADER_DERIVATIVE_HINT_OES", "FRAMEBUFFER", "FRAMEBUFFER_ATTACHMENT_OBJECT_NAME", "FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE", "FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE", "FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL", "FRAMEBUFFER_BINDING", "FRAMEBUFFER_COMPLETE", "FRAMEBUFFER_INCOMPLETE_ATTACHMENT", "FRAMEBUFFER_INCOMPLETE_DIMENSIONS", "FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT", "FRAMEBUFFER_UNSUPPORTED", "FRONT", "FRONT_AND_BACK", "FRONT_FACE", "FUNC_ADD", "FUNC_REVERSE_SUBTRACT", "FUNC_SUBTRACT", "Feed", "FeedEntry", "File", "FileError", "FileList", "FileReader", "FindInPage", "Float32Array", "Float64Array", "FocusEvent", "FontFace", "FormData", "Function", "GENERATE_MIPMAP_HINT", "GEQUAL", "GREATER", "GREEN_BITS", "GainNode", "Gamepad", "GamepadButton", "GamepadEvent", "GestureEvent", "HAVE_CURRENT_DATA", "HAVE_ENOUGH_DATA", "HAVE_FUTURE_DATA", "HAVE_METADATA", "HAVE_NOTHING", "HEADERS_RECEIVED", "HIDDEN", "HIERARCHY_REQUEST_ERR", "HIGHPASS", "HIGHSHELF", "HIGH_FLOAT", "HIGH_INT", "HORIZONTAL", "HORIZONTAL_AXIS", "HRTF", "HTMLAllCollection", "HTMLAnchorElement", "HTMLAppletElement", "HTMLAreaElement", "HTMLAudioElement", "HTMLBRElement", "HTMLBaseElement", "HTMLBaseFontElement", "HTMLBlockquoteElement", "HTMLBodyElement", "HTMLButtonElement", "HTMLCanvasElement", "HTMLCollection", "HTMLCommandElement", "HTMLContentElement", "HTMLDListElement", "HTMLDataElement", "HTMLDataListElement", "HTMLDetailsElement", "HTMLDialogElement", "HTMLDirectoryElement", "HTMLDivElement", "HTMLDocument", "HTMLElement", "HTMLEmbedElement", "HTMLFieldSetElement", "HTMLFontElement", "HTMLFormControlsCollection", "HTMLFormElement", "HTMLFrameElement", "HTMLFrameSetElement", "HTMLHRElement", "HTMLHeadElement", "HTMLHeadingElement", "HTMLHtmlElement", "HTMLIFrameElement", "HTMLImageElement", "HTMLInputElement", "HTMLIsIndexElement", "HTMLKeygenElement", "HTMLLIElement", "HTMLLabelElement", "HTMLLegendElement", "HTMLLinkElement", "HTMLMapElement", "HTMLMarqueeElement", "HTMLMediaElement", "HTMLMenuElement", "HTMLMenuItemElement", "HTMLMetaElement", "HTMLMeterElement", "HTMLModElement", "HTMLOListElement", "HTMLObjectElement", "HTMLOptGroupElement", "HTMLOptionElement", "HTMLOptionsCollection", "HTMLOutputElement", "HTMLParagraphElement", "HTMLParamElement", "HTMLPictureElement", "HTMLPreElement", "HTMLProgressElement", "HTMLPropertiesCollection", "HTMLQuoteElement", "HTMLScriptElement", "HTMLSelectElement", "HTMLShadowElement", "HTMLSourceElement", "HTMLSpanElement", "HTMLStyleElement", "HTMLTableCaptionElement", "HTMLTableCellElement", "HTMLTableColElement", "HTMLTableElement", "HTMLTableRowElement", "HTMLTableSectionElement", "HTMLTemplateElement", "HTMLTextAreaElement", "HTMLTimeElement", "HTMLTitleElement", "HTMLTrackElement", "HTMLUListElement", "HTMLUnknownElement", "HTMLVideoElement", "HashChangeEvent", "Headers", "History", "ICE_CHECKING", "ICE_CLOSED", "ICE_COMPLETED", "ICE_CONNECTED", "ICE_FAILED", "ICE_GATHERING", "ICE_WAITING", "IDBCursor", "IDBCursorWithValue", "IDBDatabase", "IDBDatabaseException", "IDBFactory", "IDBFileHandle", "IDBFileRequest", "IDBIndex", "IDBKeyRange", "IDBMutableFile", "IDBObjectStore", "IDBOpenDBRequest", "IDBRequest", "IDBTransaction", "IDBVersionChangeEvent", "IDLE", "IMPLEMENTATION_COLOR_READ_FORMAT", "IMPLEMENTATION_COLOR_READ_TYPE", "IMPORT_RULE", "INCR", "INCR_WRAP", "INDEX_SIZE_ERR", "INT", "INT_VEC2", "INT_VEC3", "INT_VEC4", "INUSE_ATTRIBUTE_ERR", "INVALID_ACCESS_ERR", "INVALID_CHARACTER_ERR", "INVALID_ENUM", "INVALID_EXPRESSION_ERR", "INVALID_FRAMEBUFFER_OPERATION", "INVALID_MODIFICATION_ERR", "INVALID_NODE_TYPE_ERR", "INVALID_OPERATION", "INVALID_STATE_ERR", "INVALID_VALUE", "INVERSE_DISTANCE", "INVERT", "IceCandidate", "Image", "ImageBitmap", "ImageData", "Infinity", "InputEvent", "InputMethodContext", "InstallTrigger", "Int16Array", "Int32Array", "Int8Array", "Intent", "InternalError", "Intl", "IsSearchProviderInstalled", "Iterator", "JSON", "KEEP", "KEYDOWN", "KEYFRAMES_RULE", "KEYFRAME_RULE", "KEYPRESS", "KEYUP", "KeyEvent", "KeyboardEvent", "LENGTHADJUST_SPACING", "LENGTHADJUST_SPACINGANDGLYPHS", "LENGTHADJUST_UNKNOWN", "LEQUAL", "LESS", "LINEAR", "LINEAR_DISTANCE", "LINEAR_MIPMAP_LINEAR", "LINEAR_MIPMAP_NEAREST", "LINES", "LINE_LOOP", "LINE_STRIP", "LINE_WIDTH", "LINK_STATUS", "LIVE", "LN10", "LN2", "LOADED", "LOADING", "LOG10E", "LOG2E", "LOWPASS", "LOWSHELF", "LOW_FLOAT", "LOW_INT", "LSException", "LSParserFilter", "LUMINANCE", "LUMINANCE_ALPHA", "LocalMediaStream", "Location", "MAX_COMBINED_TEXTURE_IMAGE_UNITS", "MAX_CUBE_MAP_TEXTURE_SIZE", "MAX_FRAGMENT_UNIFORM_VECTORS", "MAX_RENDERBUFFER_SIZE", "MAX_SAFE_INTEGER", "MAX_TEXTURE_IMAGE_UNITS", "MAX_TEXTURE_MAX_ANISOTROPY_EXT", "MAX_TEXTURE_SIZE", "MAX_VALUE", "MAX_VARYING_VECTORS", "MAX_VERTEX_ATTRIBS", "MAX_VERTEX_TEXTURE_IMAGE_UNITS", "MAX_VERTEX_UNIFORM_VECTORS", "MAX_VIEWPORT_DIMS", "MEDIA_ERR_ABORTED", "MEDIA_ERR_DECODE", "MEDIA_ERR_ENCRYPTED", "MEDIA_ERR_NETWORK", "MEDIA_ERR_SRC_NOT_SUPPORTED", "MEDIA_KEYERR_CLIENT", "MEDIA_KEYERR_DOMAIN", "MEDIA_KEYERR_HARDWARECHANGE", "MEDIA_KEYERR_OUTPUT", "MEDIA_KEYERR_SERVICE", "MEDIA_KEYERR_UNKNOWN", "MEDIA_RULE", "MEDIUM_FLOAT", "MEDIUM_INT", "META_MASK", "MIN_SAFE_INTEGER", "MIN_VALUE", "MIRRORED_REPEAT", "MODE_ASYNCHRONOUS", "MODE_SYNCHRONOUS", "MODIFICATION", "MOUSEDOWN", "MOUSEDRAG", "MOUSEMOVE", "MOUSEOUT", "MOUSEOVER", "MOUSEUP", "MOZ_KEYFRAMES_RULE", "MOZ_KEYFRAME_RULE", "MOZ_SOURCE_CURSOR", "MOZ_SOURCE_ERASER", "MOZ_SOURCE_KEYBOARD", "MOZ_SOURCE_MOUSE", "MOZ_SOURCE_PEN", "MOZ_SOURCE_TOUCH", "MOZ_SOURCE_UNKNOWN", "MSGESTURE_FLAG_BEGIN", "MSGESTURE_FLAG_CANCEL", "MSGESTURE_FLAG_END", "MSGESTURE_FLAG_INERTIA", "MSGESTURE_FLAG_NONE", "MSPOINTER_TYPE_MOUSE", "MSPOINTER_TYPE_PEN", "MSPOINTER_TYPE_TOUCH", "MS_ASYNC_CALLBACK_STATUS_ASSIGN_DELEGATE", "MS_ASYNC_CALLBACK_STATUS_CANCEL", "MS_ASYNC_CALLBACK_STATUS_CHOOSEANY", "MS_ASYNC_CALLBACK_STATUS_ERROR", "MS_ASYNC_CALLBACK_STATUS_JOIN", "MS_ASYNC_OP_STATUS_CANCELED", "MS_ASYNC_OP_STATUS_ERROR", "MS_ASYNC_OP_STATUS_SUCCESS", "MS_MANIPULATION_STATE_ACTIVE", "MS_MANIPULATION_STATE_CANCELLED", "MS_MANIPULATION_STATE_COMMITTED", "MS_MANIPULATION_STATE_DRAGGING", "MS_MANIPULATION_STATE_INERTIA", "MS_MANIPULATION_STATE_PRESELECT", "MS_MANIPULATION_STATE_SELECTING", "MS_MANIPULATION_STATE_STOPPED", "MS_MEDIA_ERR_ENCRYPTED", "MS_MEDIA_KEYERR_CLIENT", "MS_MEDIA_KEYERR_DOMAIN", "MS_MEDIA_KEYERR_HARDWARECHANGE", "MS_MEDIA_KEYERR_OUTPUT", "MS_MEDIA_KEYERR_SERVICE", "MS_MEDIA_KEYERR_UNKNOWN", "Map", "Math", "MediaController", "MediaDevices", "MediaElementAudioSourceNode", "MediaEncryptedEvent", "MediaError", "MediaKeyError", "MediaKeyEvent", "MediaKeyMessageEvent", "MediaKeyNeededEvent", "MediaKeySession", "MediaKeyStatusMap", "MediaKeySystemAccess", "MediaKeys", "MediaList", "MediaQueryList", "MediaQueryListEvent", "MediaRecorder", "MediaSource", "MediaStream", "MediaStreamAudioDestinationNode", "MediaStreamAudioSourceNode", "MediaStreamEvent", "MediaStreamTrack", "MediaStreamTrackEvent", "MessageChannel", "MessageEvent", "MessagePort", "Methods", "MimeType", "MimeTypeArray", "MouseEvent", "MouseScrollEvent", "MozAnimation", "MozAnimationDelay", "MozAnimationDirection", "MozAnimationDuration", "MozAnimationFillMode", "MozAnimationIterationCount", "MozAnimationName", "MozAnimationPlayState", "MozAnimationTimingFunction", "MozAppearance", "MozBackfaceVisibility", "MozBinding", "MozBorderBottomColors", "MozBorderEnd", "MozBorderEndColor", "MozBorderEndStyle", "MozBorderEndWidth", "MozBorderImage", "MozBorderLeftColors", "MozBorderRightColors", "MozBorderStart", "MozBorderStartColor", "MozBorderStartStyle", "MozBorderStartWidth", "MozBorderTopColors", "MozBoxAlign", "MozBoxDirection", "MozBoxFlex", "MozBoxOrdinalGroup", "MozBoxOrient", "MozBoxPack", "MozBoxSizing", "MozCSSKeyframeRule", "MozCSSKeyframesRule", "MozColumnCount", "MozColumnFill", "MozColumnGap", "MozColumnRule", "MozColumnRuleColor", "MozColumnRuleStyle", "MozColumnRuleWidth", "MozColumnWidth", "MozColumns", "MozContactChangeEvent", "MozFloatEdge", "MozFontFeatureSettings", "MozFontLanguageOverride", "MozForceBrokenImageIcon", "MozHyphens", "MozImageRegion", "MozMarginEnd", "MozMarginStart", "MozMmsEvent", "MozMmsMessage", "MozMobileMessageThread", "MozOSXFontSmoothing", "MozOrient", "MozOutlineRadius", "MozOutlineRadiusBottomleft", "MozOutlineRadiusBottomright", "MozOutlineRadiusTopleft", "MozOutlineRadiusTopright", "MozPaddingEnd", "MozPaddingStart", "MozPerspective", "MozPerspectiveOrigin", "MozPowerManager", "MozSettingsEvent", "MozSmsEvent", "MozSmsMessage", "MozStackSizing", "MozTabSize", "MozTextAlignLast", "MozTextDecorationColor", "MozTextDecorationLine", "MozTextDecorationStyle", "MozTextSizeAdjust", "MozTransform", "MozTransformOrigin", "MozTransformStyle", "MozTransition", "MozTransitionDelay", "MozTransitionDuration", "MozTransitionProperty", "MozTransitionTimingFunction", "MozUserFocus", "MozUserInput", "MozUserModify", "MozUserSelect", "MozWindowDragging", "MozWindowShadow", "MutationEvent", "MutationObserver", "MutationRecord", "NAMESPACE_ERR", "NAMESPACE_RULE", "NEAREST", "NEAREST_MIPMAP_LINEAR", "NEAREST_MIPMAP_NEAREST", "NEGATIVE_INFINITY", "NETWORK_EMPTY", "NETWORK_ERR", "NETWORK_IDLE", "NETWORK_LOADED", "NETWORK_LOADING", "NETWORK_NO_SOURCE", "NEVER", "NEW", "NEXT", "NEXT_NO_DUPLICATE", "NICEST", "NODE_AFTER", "NODE_BEFORE", "NODE_BEFORE_AND_AFTER", "NODE_INSIDE", "NONE", "NON_TRANSIENT_ERR", "NOTATION_NODE", "NOTCH", "NOTEQUAL", "NOT_ALLOWED_ERR", "NOT_FOUND_ERR", "NOT_READABLE_ERR", "NOT_SUPPORTED_ERR", "NO_DATA_ALLOWED_ERR", "NO_ERR", "NO_ERROR", "NO_MODIFICATION_ALLOWED_ERR", "NUMBER_TYPE", "NUM_COMPRESSED_TEXTURE_FORMATS", "NaN", "NamedNodeMap", "Navigator", "NearbyLinks", "NetworkInformation", "Node", "NodeFilter", "NodeIterator", "NodeList", "Notation", "Notification", "NotifyPaintEvent", "Number", "NumberFormat", "OBSOLETE", "ONE", "ONE_MINUS_CONSTANT_ALPHA", "ONE_MINUS_CONSTANT_COLOR", "ONE_MINUS_DST_ALPHA", "ONE_MINUS_DST_COLOR", "ONE_MINUS_SRC_ALPHA", "ONE_MINUS_SRC_COLOR", "OPEN", "OPENED", "OPENING", "ORDERED_NODE_ITERATOR_TYPE", "ORDERED_NODE_SNAPSHOT_TYPE", "OUT_OF_MEMORY", "Object", "OfflineAudioCompletionEvent", "OfflineAudioContext", "OfflineResourceList", "Option", "OscillatorNode", "OverflowEvent", "PACK_ALIGNMENT", "PAGE_RULE", "PARSE_ERR", "PATHSEG_ARC_ABS", "PATHSEG_ARC_REL", "PATHSEG_CLOSEPATH", "PATHSEG_CURVETO_CUBIC_ABS", "PATHSEG_CURVETO_CUBIC_REL", "PATHSEG_CURVETO_CUBIC_SMOOTH_ABS", "PATHSEG_CURVETO_CUBIC_SMOOTH_REL", "PATHSEG_CURVETO_QUADRATIC_ABS", "PATHSEG_CURVETO_QUADRATIC_REL", "PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS", "PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL", "PATHSEG_LINETO_ABS", "PATHSEG_LINETO_HORIZONTAL_ABS", "PATHSEG_LINETO_HORIZONTAL_REL", "PATHSEG_LINETO_REL", "PATHSEG_LINETO_VERTICAL_ABS", "PATHSEG_LINETO_VERTICAL_REL", "PATHSEG_MOVETO_ABS", "PATHSEG_MOVETO_REL", "PATHSEG_UNKNOWN", "PATH_EXISTS_ERR", "PEAKING", "PERMISSION_DENIED", "PERSISTENT", "PI", "PLAYING_STATE", "POINTS", "POLYGON_OFFSET_FACTOR", "POLYGON_OFFSET_FILL", "POLYGON_OFFSET_UNITS", "POSITION_UNAVAILABLE", "POSITIVE_INFINITY", "PREV", "PREV_NO_DUPLICATE", "PROCESSING_INSTRUCTION_NODE", "PageChangeEvent", "PageTransitionEvent", "PaintRequest", "PaintRequestList", "PannerNode", "Path2D", "Performance", "PerformanceEntry", "PerformanceMark", "PerformanceMeasure", "PerformanceNavigation", "PerformanceResourceTiming", "PerformanceTiming", "PeriodicWave", "Plugin", "PluginArray", "PopStateEvent", "PopupBlockedEvent", "ProcessingInstruction", "ProgressEvent", "Promise", "PropertyNodeList", "Proxy", "PushManager", "PushSubscription", "Q", "QUOTA_ERR", "QUOTA_EXCEEDED_ERR", "QueryInterface", "READ_ONLY", "READ_ONLY_ERR", "READ_WRITE", "RED_BITS", "REMOVAL", "RENDERBUFFER", "RENDERBUFFER_ALPHA_SIZE", "RENDERBUFFER_BINDING", "RENDERBUFFER_BLUE_SIZE", "RENDERBUFFER_DEPTH_SIZE", "RENDERBUFFER_GREEN_SIZE", "RENDERBUFFER_HEIGHT", "RENDERBUFFER_INTERNAL_FORMAT", "RENDERBUFFER_RED_SIZE", "RENDERBUFFER_STENCIL_SIZE", "RENDERBUFFER_WIDTH", "RENDERER", "RENDERING_INTENT_ABSOLUTE_COLORIMETRIC", "RENDERING_INTENT_AUTO", "RENDERING_INTENT_PERCEPTUAL", "RENDERING_INTENT_RELATIVE_COLORIMETRIC", "RENDERING_INTENT_SATURATION", "RENDERING_INTENT_UNKNOWN", "REPEAT", "REPLACE", "RGB", "RGB565", "RGB5_A1", "RGBA", "RGBA4", "RGBColor", "ROTATION_CLOCKWISE", "ROTATION_COUNTERCLOCKWISE", "RTCDataChannelEvent", "RTCIceCandidate", "RTCPeerConnectionIceEvent", "RTCRtpReceiver", "RTCRtpSender", "RTCSessionDescription", "RTCStatsReport", "RadioNodeList", "Range", "RangeError", "RangeException", "RecordErrorEvent", "Rect", "ReferenceError", "RegExp", "Request", "Response", "SAMPLER_2D", "SAMPLER_CUBE", "SAMPLES", "SAMPLE_ALPHA_TO_COVERAGE", "SAMPLE_BUFFERS", "SAMPLE_COVERAGE", "SAMPLE_COVERAGE_INVERT", "SAMPLE_COVERAGE_VALUE", "SAWTOOTH", "SCHEDULED_STATE", "SCISSOR_BOX", "SCISSOR_TEST", "SCROLL_PAGE_DOWN", "SCROLL_PAGE_UP", "SDP_ANSWER", "SDP_OFFER", "SDP_PRANSWER", "SECURITY_ERR", "SELECT", "SERIALIZE_ERR", "SEVERITY_ERROR", "SEVERITY_FATAL_ERROR", "SEVERITY_WARNING", "SHADER_COMPILER", "SHADER_TYPE", "SHADING_LANGUAGE_VERSION", "SHIFT_MASK", "SHORT", "SHOWING", "SHOW_ALL", "SHOW_ATTRIBUTE", "SHOW_CDATA_SECTION", "SHOW_COMMENT", "SHOW_DOCUMENT", "SHOW_DOCUMENT_FRAGMENT", "SHOW_DOCUMENT_TYPE", "SHOW_ELEMENT", "SHOW_ENTITY", "SHOW_ENTITY_REFERENCE", "SHOW_NOTATION", "SHOW_PROCESSING_INSTRUCTION", "SHOW_TEXT", "SINE", "SOUNDFIELD", "SQLException", "SQRT1_2", "SQRT2", "SQUARE", "SRC_ALPHA", "SRC_ALPHA_SATURATE", "SRC_COLOR", "START_TO_END", "START_TO_START", "STATIC_DRAW", "STENCIL_ATTACHMENT", "STENCIL_BACK_FAIL", "STENCIL_BACK_FUNC", "STENCIL_BACK_PASS_DEPTH_FAIL", "STENCIL_BACK_PASS_DEPTH_PASS", "STENCIL_BACK_REF", "STENCIL_BACK_VALUE_MASK", "STENCIL_BACK_WRITEMASK", "STENCIL_BITS", "STENCIL_BUFFER_BIT", "STENCIL_CLEAR_VALUE", "STENCIL_FAIL", "STENCIL_FUNC", "STENCIL_INDEX", "STENCIL_INDEX8", "STENCIL_PASS_DEPTH_FAIL", "STENCIL_PASS_DEPTH_PASS", "STENCIL_REF", "STENCIL_TEST", "STENCIL_VALUE_MASK", "STENCIL_WRITEMASK", "STREAM_DRAW", "STRING_TYPE", "STYLE_RULE", "SUBPIXEL_BITS", "SUPPORTS_RULE", "SVGAElement", "SVGAltGlyphDefElement", "SVGAltGlyphElement", "SVGAltGlyphItemElement", "SVGAngle", "SVGAnimateColorElement", "SVGAnimateElement", "SVGAnimateMotionElement", "SVGAnimateTransformElement", "SVGAnimatedAngle", "SVGAnimatedBoolean", "SVGAnimatedEnumeration", "SVGAnimatedInteger", "SVGAnimatedLength", "SVGAnimatedLengthList", "SVGAnimatedNumber", "SVGAnimatedNumberList", "SVGAnimatedPreserveAspectRatio", "SVGAnimatedRect", "SVGAnimatedString", "SVGAnimatedTransformList", "SVGAnimationElement", "SVGCircleElement", "SVGClipPathElement", "SVGColor", "SVGComponentTransferFunctionElement", "SVGCursorElement", "SVGDefsElement", "SVGDescElement", "SVGDiscardElement", "SVGDocument", "SVGElement", "SVGElementInstance", "SVGElementInstanceList", "SVGEllipseElement", "SVGException", "SVGFEBlendElement", "SVGFEColorMatrixElement", "SVGFEComponentTransferElement", "SVGFECompositeElement", "SVGFEConvolveMatrixElement", "SVGFEDiffuseLightingElement", "SVGFEDisplacementMapElement", "SVGFEDistantLightElement", "SVGFEDropShadowElement", "SVGFEFloodElement", "SVGFEFuncAElement", "SVGFEFuncBElement", "SVGFEFuncGElement", "SVGFEFuncRElement", "SVGFEGaussianBlurElement", "SVGFEImageElement", "SVGFEMergeElement", "SVGFEMergeNodeElement", "SVGFEMorphologyElement", "SVGFEOffsetElement", "SVGFEPointLightElement", "SVGFESpecularLightingElement", "SVGFESpotLightElement", "SVGFETileElement", "SVGFETurbulenceElement", "SVGFilterElement", "SVGFontElement", "SVGFontFaceElement", "SVGFontFaceFormatElement", "SVGFontFaceNameElement", "SVGFontFaceSrcElement", "SVGFontFaceUriElement", "SVGForeignObjectElement", "SVGGElement", "SVGGeometryElement", "SVGGlyphElement", "SVGGlyphRefElement", "SVGGradientElement", "SVGGraphicsElement", "SVGHKernElement", "SVGImageElement", "SVGLength", "SVGLengthList", "SVGLineElement", "SVGLinearGradientElement", "SVGMPathElement", "SVGMarkerElement", "SVGMaskElement", "SVGMatrix", "SVGMetadataElement", "SVGMissingGlyphElement", "SVGNumber", "SVGNumberList", "SVGPaint", "SVGPathElement", "SVGPathSeg", "SVGPathSegArcAbs", "SVGPathSegArcRel", "SVGPathSegClosePath", "SVGPathSegCurvetoCubicAbs", "SVGPathSegCurvetoCubicRel", "SVGPathSegCurvetoCubicSmoothAbs", "SVGPathSegCurvetoCubicSmoothRel", "SVGPathSegCurvetoQuadraticAbs", "SVGPathSegCurvetoQuadraticRel", "SVGPathSegCurvetoQuadraticSmoothAbs", "SVGPathSegCurvetoQuadraticSmoothRel", "SVGPathSegLinetoAbs", "SVGPathSegLinetoHorizontalAbs", "SVGPathSegLinetoHorizontalRel", "SVGPathSegLinetoRel", "SVGPathSegLinetoVerticalAbs", "SVGPathSegLinetoVerticalRel", "SVGPathSegList", "SVGPathSegMovetoAbs", "SVGPathSegMovetoRel", "SVGPatternElement", "SVGPoint", "SVGPointList", "SVGPolygonElement", "SVGPolylineElement", "SVGPreserveAspectRatio", "SVGRadialGradientElement", "SVGRect", "SVGRectElement", "SVGRenderingIntent", "SVGSVGElement", "SVGScriptElement", "SVGSetElement", "SVGStopElement", "SVGStringList", "SVGStyleElement", "SVGSwitchElement", "SVGSymbolElement", "SVGTRefElement", "SVGTSpanElement", "SVGTextContentElement", "SVGTextElement", "SVGTextPathElement", "SVGTextPositioningElement", "SVGTitleElement", "SVGTransform", "SVGTransformList", "SVGUnitTypes", "SVGUseElement", "SVGVKernElement", "SVGViewElement", "SVGViewSpec", "SVGZoomAndPan", "SVGZoomEvent", "SVG_ANGLETYPE_DEG", "SVG_ANGLETYPE_GRAD", "SVG_ANGLETYPE_RAD", "SVG_ANGLETYPE_UNKNOWN", "SVG_ANGLETYPE_UNSPECIFIED", "SVG_CHANNEL_A", "SVG_CHANNEL_B", "SVG_CHANNEL_G", "SVG_CHANNEL_R", "SVG_CHANNEL_UNKNOWN", "SVG_COLORTYPE_CURRENTCOLOR", "SVG_COLORTYPE_RGBCOLOR", "SVG_COLORTYPE_RGBCOLOR_ICCCOLOR", "SVG_COLORTYPE_UNKNOWN", "SVG_EDGEMODE_DUPLICATE", "SVG_EDGEMODE_NONE", "SVG_EDGEMODE_UNKNOWN", "SVG_EDGEMODE_WRAP", "SVG_FEBLEND_MODE_COLOR", "SVG_FEBLEND_MODE_COLOR_BURN", "SVG_FEBLEND_MODE_COLOR_DODGE", "SVG_FEBLEND_MODE_DARKEN", "SVG_FEBLEND_MODE_DIFFERENCE", "SVG_FEBLEND_MODE_EXCLUSION", "SVG_FEBLEND_MODE_HARD_LIGHT", "SVG_FEBLEND_MODE_HUE", "SVG_FEBLEND_MODE_LIGHTEN", "SVG_FEBLEND_MODE_LUMINOSITY", "SVG_FEBLEND_MODE_MULTIPLY", "SVG_FEBLEND_MODE_NORMAL", "SVG_FEBLEND_MODE_OVERLAY", "SVG_FEBLEND_MODE_SATURATION", "SVG_FEBLEND_MODE_SCREEN", "SVG_FEBLEND_MODE_SOFT_LIGHT", "SVG_FEBLEND_MODE_UNKNOWN", "SVG_FECOLORMATRIX_TYPE_HUEROTATE", "SVG_FECOLORMATRIX_TYPE_LUMINANCETOALPHA", "SVG_FECOLORMATRIX_TYPE_MATRIX", "SVG_FECOLORMATRIX_TYPE_SATURATE", "SVG_FECOLORMATRIX_TYPE_UNKNOWN", "SVG_FECOMPONENTTRANSFER_TYPE_DISCRETE", "SVG_FECOMPONENTTRANSFER_TYPE_GAMMA", "SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY", "SVG_FECOMPONENTTRANSFER_TYPE_LINEAR", "SVG_FECOMPONENTTRANSFER_TYPE_TABLE", "SVG_FECOMPONENTTRANSFER_TYPE_UNKNOWN", "SVG_FECOMPOSITE_OPERATOR_ARITHMETIC", "SVG_FECOMPOSITE_OPERATOR_ATOP", "SVG_FECOMPOSITE_OPERATOR_IN", "SVG_FECOMPOSITE_OPERATOR_OUT", "SVG_FECOMPOSITE_OPERATOR_OVER", "SVG_FECOMPOSITE_OPERATOR_UNKNOWN", "SVG_FECOMPOSITE_OPERATOR_XOR", "SVG_INVALID_VALUE_ERR", "SVG_LENGTHTYPE_CM", "SVG_LENGTHTYPE_EMS", "SVG_LENGTHTYPE_EXS", "SVG_LENGTHTYPE_IN", "SVG_LENGTHTYPE_MM", "SVG_LENGTHTYPE_NUMBER", "SVG_LENGTHTYPE_PC", "SVG_LENGTHTYPE_PERCENTAGE", "SVG_LENGTHTYPE_PT", "SVG_LENGTHTYPE_PX", "SVG_LENGTHTYPE_UNKNOWN", "SVG_MARKERUNITS_STROKEWIDTH", "SVG_MARKERUNITS_UNKNOWN", "SVG_MARKERUNITS_USERSPACEONUSE", "SVG_MARKER_ORIENT_ANGLE", "SVG_MARKER_ORIENT_AUTO", "SVG_MARKER_ORIENT_UNKNOWN", "SVG_MASKTYPE_ALPHA", "SVG_MASKTYPE_LUMINANCE", "SVG_MATRIX_NOT_INVERTABLE", "SVG_MEETORSLICE_MEET", "SVG_MEETORSLICE_SLICE", "SVG_MEETORSLICE_UNKNOWN", "SVG_MORPHOLOGY_OPERATOR_DILATE", "SVG_MORPHOLOGY_OPERATOR_ERODE", "SVG_MORPHOLOGY_OPERATOR_UNKNOWN", "SVG_PAINTTYPE_CURRENTCOLOR", "SVG_PAINTTYPE_NONE", "SVG_PAINTTYPE_RGBCOLOR", "SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR", "SVG_PAINTTYPE_UNKNOWN", "SVG_PAINTTYPE_URI", "SVG_PAINTTYPE_URI_CURRENTCOLOR", "SVG_PAINTTYPE_URI_NONE", "SVG_PAINTTYPE_URI_RGBCOLOR", "SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR", "SVG_PRESERVEASPECTRATIO_NONE", "SVG_PRESERVEASPECTRATIO_UNKNOWN", "SVG_PRESERVEASPECTRATIO_XMAXYMAX", "SVG_PRESERVEASPECTRATIO_XMAXYMID", "SVG_PRESERVEASPECTRATIO_XMAXYMIN", "SVG_PRESERVEASPECTRATIO_XMIDYMAX", "SVG_PRESERVEASPECTRATIO_XMIDYMID", "SVG_PRESERVEASPECTRATIO_XMIDYMIN", "SVG_PRESERVEASPECTRATIO_XMINYMAX", "SVG_PRESERVEASPECTRATIO_XMINYMID", "SVG_PRESERVEASPECTRATIO_XMINYMIN", "SVG_SPREADMETHOD_PAD", "SVG_SPREADMETHOD_REFLECT", "SVG_SPREADMETHOD_REPEAT", "SVG_SPREADMETHOD_UNKNOWN", "SVG_STITCHTYPE_NOSTITCH", "SVG_STITCHTYPE_STITCH", "SVG_STITCHTYPE_UNKNOWN", "SVG_TRANSFORM_MATRIX", "SVG_TRANSFORM_ROTATE", "SVG_TRANSFORM_SCALE", "SVG_TRANSFORM_SKEWX", "SVG_TRANSFORM_SKEWY", "SVG_TRANSFORM_TRANSLATE", "SVG_TRANSFORM_UNKNOWN", "SVG_TURBULENCE_TYPE_FRACTALNOISE", "SVG_TURBULENCE_TYPE_TURBULENCE", "SVG_TURBULENCE_TYPE_UNKNOWN", "SVG_UNIT_TYPE_OBJECTBOUNDINGBOX", "SVG_UNIT_TYPE_UNKNOWN", "SVG_UNIT_TYPE_USERSPACEONUSE", "SVG_WRONG_TYPE_ERR", "SVG_ZOOMANDPAN_DISABLE", "SVG_ZOOMANDPAN_MAGNIFY", "SVG_ZOOMANDPAN_UNKNOWN", "SYNTAX_ERR", "SavedPages", "Screen", "ScreenOrientation", "Script", "ScriptProcessorNode", "ScrollAreaEvent", "SecurityPolicyViolationEvent", "Selection", "ServiceWorker", "ServiceWorkerContainer", "ServiceWorkerRegistration", "SessionDescription", "Set", "ShadowRoot", "SharedWorker", "SimpleGestureEvent", "SpeechSynthesisEvent", "SpeechSynthesisUtterance", "StopIteration", "Storage", "StorageEvent", "String", "StyleSheet", "StyleSheetList", "SubtleCrypto", "Symbol", "SyntaxError", "TEMPORARY", "TEXTPATH_METHODTYPE_ALIGN", "TEXTPATH_METHODTYPE_STRETCH", "TEXTPATH_METHODTYPE_UNKNOWN", "TEXTPATH_SPACINGTYPE_AUTO", "TEXTPATH_SPACINGTYPE_EXACT", "TEXTPATH_SPACINGTYPE_UNKNOWN", "TEXTURE", "TEXTURE0", "TEXTURE1", "TEXTURE10", "TEXTURE11", "TEXTURE12", "TEXTURE13", "TEXTURE14", "TEXTURE15", "TEXTURE16", "TEXTURE17", "TEXTURE18", "TEXTURE19", "TEXTURE2", "TEXTURE20", "TEXTURE21", "TEXTURE22", "TEXTURE23", "TEXTURE24", "TEXTURE25", "TEXTURE26", "TEXTURE27", "TEXTURE28", "TEXTURE29", "TEXTURE3", "TEXTURE30", "TEXTURE31", "TEXTURE4", "TEXTURE5", "TEXTURE6", "TEXTURE7", "TEXTURE8", "TEXTURE9", "TEXTURE_2D", "TEXTURE_BINDING_2D", "TEXTURE_BINDING_CUBE_MAP", "TEXTURE_CUBE_MAP", "TEXTURE_CUBE_MAP_NEGATIVE_X", "TEXTURE_CUBE_MAP_NEGATIVE_Y", "TEXTURE_CUBE_MAP_NEGATIVE_Z", "TEXTURE_CUBE_MAP_POSITIVE_X", "TEXTURE_CUBE_MAP_POSITIVE_Y", "TEXTURE_CUBE_MAP_POSITIVE_Z", "TEXTURE_MAG_FILTER", "TEXTURE_MAX_ANISOTROPY_EXT", "TEXTURE_MIN_FILTER", "TEXTURE_WRAP_S", "TEXTURE_WRAP_T", "TEXT_NODE", "TIMEOUT", "TIMEOUT_ERR", "TOO_LARGE_ERR", "TRANSACTION_INACTIVE_ERR", "TRIANGLE", "TRIANGLES", "TRIANGLE_FAN", "TRIANGLE_STRIP", "TYPE_BACK_FORWARD", "TYPE_ERR", "TYPE_MISMATCH_ERR", "TYPE_NAVIGATE", "TYPE_RELOAD", "TYPE_RESERVED", "Text", "TextDecoder", "TextEncoder", "TextEvent", "TextMetrics", "TextTrack", "TextTrackCue", "TextTrackCueList", "TextTrackList", "TimeEvent", "TimeRanges", "Touch", "TouchEvent", "TouchList", "TrackEvent", "TransitionEvent", "TreeWalker", "TypeError", "UIEvent", "UNCACHED", "UNKNOWN_ERR", "UNKNOWN_RULE", "UNMASKED_RENDERER_WEBGL", "UNMASKED_VENDOR_WEBGL", "UNORDERED_NODE_ITERATOR_TYPE", "UNORDERED_NODE_SNAPSHOT_TYPE", "UNPACK_ALIGNMENT", "UNPACK_COLORSPACE_CONVERSION_WEBGL", "UNPACK_FLIP_Y_WEBGL", "UNPACK_PREMULTIPLY_ALPHA_WEBGL", "UNSCHEDULED_STATE", "UNSENT", "UNSIGNED_BYTE", "UNSIGNED_INT", "UNSIGNED_SHORT", "UNSIGNED_SHORT_4_4_4_4", "UNSIGNED_SHORT_5_5_5_1", "UNSIGNED_SHORT_5_6_5", "UNSPECIFIED_EVENT_TYPE_ERR", "UPDATEREADY", "URIError", "URL", "URLSearchParams", "URLUnencoded", "URL_MISMATCH_ERR", "UTC", "Uint16Array", "Uint32Array", "Uint8Array", "Uint8ClampedArray", "UserMessageHandler", "UserMessageHandlersNamespace", "UserProximityEvent", "VALIDATE_STATUS", "VALIDATION_ERR", "VARIABLES_RULE", "VENDOR", "VERSION", "VERSION_CHANGE", "VERSION_ERR", "VERTEX_ATTRIB_ARRAY_BUFFER_BINDING", "VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE", "VERTEX_ATTRIB_ARRAY_ENABLED", "VERTEX_ATTRIB_ARRAY_NORMALIZED", "VERTEX_ATTRIB_ARRAY_POINTER", "VERTEX_ATTRIB_ARRAY_SIZE", "VERTEX_ATTRIB_ARRAY_STRIDE", "VERTEX_ATTRIB_ARRAY_TYPE", "VERTEX_SHADER", "VERTICAL", "VERTICAL_AXIS", "VER_ERR", "VIEWPORT", "VIEWPORT_RULE", "VTTCue", "VTTRegion", "ValidityState", "VideoStreamTrack", "WEBKIT_FILTER_RULE", "WEBKIT_KEYFRAMES_RULE", "WEBKIT_KEYFRAME_RULE", "WEBKIT_REGION_RULE", "WRONG_DOCUMENT_ERR", "WaveShaperNode", "WeakMap", "WeakSet", "WebGLActiveInfo", "WebGLBuffer", "WebGLContextEvent", "WebGLFramebuffer", "WebGLProgram", "WebGLRenderbuffer", "WebGLRenderingContext", "WebGLShader", "WebGLShaderPrecisionFormat", "WebGLTexture", "WebGLUniformLocation", "WebGLVertexArray", "WebKitAnimationEvent", "WebKitBlobBuilder", "WebKitCSSFilterRule", "WebKitCSSFilterValue", "WebKitCSSKeyframeRule", "WebKitCSSKeyframesRule", "WebKitCSSMatrix", "WebKitCSSRegionRule", "WebKitCSSTransformValue", "WebKitDataCue", "WebKitGamepad", "WebKitMediaKeyError", "WebKitMediaKeyMessageEvent", "WebKitMediaKeySession", "WebKitMediaKeys", "WebKitMediaSource", "WebKitMutationObserver", "WebKitNamespace", "WebKitPlaybackTargetAvailabilityEvent", "WebKitPoint", "WebKitShadowRoot", "WebKitSourceBuffer", "WebKitSourceBufferList", "WebKitTransitionEvent", "WebSocket", "WheelEvent", "Window", "Worker", "XMLDocument", "XMLHttpRequest", "XMLHttpRequestEventTarget", "XMLHttpRequestException", "XMLHttpRequestProgressEvent", "XMLHttpRequestUpload", "XMLSerializer", "XMLStylesheetProcessingInstruction", "XPathEvaluator", "XPathException", "XPathExpression", "XPathNSResolver", "XPathResult", "XSLTProcessor", "ZERO", "_XD0M_", "_YD0M_", "__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__", "__opera", "__proto__", "_browserjsran", "a", "aLink", "abbr", "abort", "abs", "absolute", "acceleration", "accelerationIncludingGravity", "accelerator", "accept", "acceptCharset", "acceptNode", "accessKey", "accessKeyLabel", "accuracy", "acos", "acosh", "action", "actionURL", "active", "activeCues", "activeElement", "activeSourceBuffers", "activeSourceCount", "activeTexture", "add", "addBehavior", "addCandidate", "addColorStop", "addCue", "addElement", "addEventListener", "addFilter", "addFromString", "addFromUri", "addIceCandidate", "addImport", "addListener", "addNamed", "addPageRule", "addPath", "addPointer", "addRange", "addRegion", "addRule", "addSearchEngine", "addSourceBuffer", "addStream", "addTextTrack", "addTrack", "addWakeLockListener", "addedNodes", "additionalName", "additiveSymbols", "addons", "adoptNode", "adr", "advance", "alert", "algorithm", "align", "align-content", "align-items", "align-self", "alignContent", "alignItems", "alignSelf", "alignmentBaseline", "alinkColor", "all", "allowFullscreen", "allowedDirections", "alpha", "alt", "altGraphKey", "altHtml", "altKey", "altLeft", "altitude", "altitudeAccuracy", "amplitude", "ancestorOrigins", "anchor", "anchorNode", "anchorOffset", "anchors", "angle", "animVal", "animate", "animatedInstanceRoot", "animatedNormalizedPathSegList", "animatedPathSegList", "animatedPoints", "animation", "animation-delay", "animation-direction", "animation-duration", "animation-fill-mode", "animation-iteration-count", "animation-name", "animation-play-state", "animation-timing-function", "animationDelay", "animationDirection", "animationDuration", "animationFillMode", "animationIterationCount", "animationName", "animationPlayState", "animationStartTime", "animationTimingFunction", "animationsPaused", "anniversary", "app", "appCodeName", "appMinorVersion", "appName", "appNotifications", "appVersion", "append", "appendBuffer", "appendChild", "appendData", "appendItem", "appendMedium", "appendNamed", "appendRule", "appendStream", "appendWindowEnd", "appendWindowStart", "applets", "applicationCache", "apply", "applyElement", "arc", "arcTo", "archive", "areas", "arguments", "arrayBuffer", "asin", "asinh", "assert", "assign", "async", "atEnd", "atan", "atan2", "atanh", "atob", "attachEvent", "attachShader", "attachments", "attack", "attrChange", "attrName", "attributeFilter", "attributeName", "attributeNamespace", "attributeOldValue", "attributes", "audioTracks", "autoIncrement", "autobuffer", "autocapitalize", "autocomplete", "autocorrect", "autofocus", "autoplay", "availHeight", "availLeft", "availTop", "availWidth", "availability", "available", "aversion", "axes", "axis", "azimuth", "b", "back", "backface-visibility", "backfaceVisibility", "background", "background-attachment", "background-blend-mode", "background-clip", "background-color", "background-image", "background-origin", "background-position", "background-repeat", "background-size", "backgroundAttachment", "backgroundBlendMode", "backgroundClip", "backgroundColor", "backgroundImage", "backgroundOrigin", "backgroundPosition", "backgroundPositionX", "backgroundPositionY", "backgroundRepeat", "backgroundSize", "badInput", "balance", "baseFrequencyX", "baseFrequencyY", "baseNode", "baseOffset", "baseURI", "baseVal", "baselineShift", "battery", "bday", "beginElement", "beginElementAt", "beginPath", "behavior", "behaviorCookie", "behaviorPart", "behaviorUrns", "beta", "bezierCurveTo", "bgColor", "bgProperties", "bias", "big", "binaryType", "bind", "bindAttribLocation", "bindBuffer", "bindFramebuffer", "bindRenderbuffer", "bindTexture", "blendColor", "blendEquation", "blendEquationSeparate", "blendFunc", "blendFuncSeparate", "blink", "blob", "blockDirection", "blue", "blur", "body", "bodyUsed", "bold", "bookmarks", "booleanValue", "border", "border-bottom", "border-bottom-color", "border-bottom-left-radius", "border-bottom-right-radius", "border-bottom-style", "border-bottom-width", "border-collapse", "border-color", "border-image", "border-image-outset", "border-image-repeat", "border-image-slice", "border-image-source", "border-image-width", "border-left", "border-left-color", "border-left-style", "border-left-width", "border-radius", "border-right", "border-right-color", "border-right-style", "border-right-width", "border-spacing", "border-style", "border-top", "border-top-color", "border-top-left-radius", "border-top-right-radius", "border-top-style", "border-top-width", "border-width", "borderBottom", "borderBottomColor", "borderBottomLeftRadius", "borderBottomRightRadius", "borderBottomStyle", "borderBottomWidth", "borderCollapse", "borderColor", "borderColorDark", "borderColorLight", "borderImage", "borderImageOutset", "borderImageRepeat", "borderImageSlice", "borderImageSource", "borderImageWidth", "borderLeft", "borderLeftColor", "borderLeftStyle", "borderLeftWidth", "borderRadius", "borderRight", "borderRightColor", "borderRightStyle", "borderRightWidth", "borderSpacing", "borderStyle", "borderTop", "borderTopColor", "borderTopLeftRadius", "borderTopRightRadius", "borderTopStyle", "borderTopWidth", "borderWidth", "bottom", "bottomMargin", "bound", "boundElements", "boundingClientRect", "boundingHeight", "boundingLeft", "boundingTop", "boundingWidth", "bounds", "box-decoration-break", "box-shadow", "box-sizing", "boxDecorationBreak", "boxShadow", "boxSizing", "breakAfter", "breakBefore", "breakInside", "browserLanguage", "btoa", "bubbles", "buffer", "bufferData", "bufferDepth", "bufferSize", "bufferSubData", "buffered", "bufferedAmount", "buildID", "buildNumber", "button", "buttonID", "buttons", "byteLength", "byteOffset", "c", "call", "caller", "canBeFormatted", "canBeMounted", "canBeShared", "canHaveChildren", "canHaveHTML", "canPlayType", "cancel", "cancelAnimationFrame", "cancelBubble", "cancelScheduledValues", "cancelable", "candidate", "canvas", "caption", "caption-side", "captionSide", "captureEvents", "captureStackTrace", "caretPositionFromPoint", "caretRangeFromPoint", "cast", "catch", "category", "cbrt", "cd", "ceil", "cellIndex", "cellPadding", "cellSpacing", "cells", "ch", "chOff", "chain", "challenge", "changedTouches", "channel", "channelCount", "channelCountMode", "channelInterpretation", "char", "charAt", "charCode", "charCodeAt", "charIndex", "characterSet", "characterData", "characterDataOldValue", "charging", "chargingTime", "charset", "checkEnclosure", "checkFramebufferStatus", "checkIntersection", "checkValidity", "checked", "childElementCount", "childList", "childNodes", "children", "chrome", "ciphertext", "cite", "classList", "className", "classid", "clear", "clearAttributes", "clearColor", "clearData", "clearDepth", "clearImmediate", "clearInterval", "clearMarks", "clearMeasures", "clearParameters", "clearRect", "clearResourceTimings", "clearShadow", "clearStencil", "clearTimeout", "clearWatch", "click", "clickCount", "clientHeight", "clientInformation", "clientLeft", "clientRect", "clientRects", "clientTop", "clientWidth", "clientX", "clientY", "clip", "clip-path", "clip-rule", "clipBottom", "clipLeft", "clipPath", "clipPathUnits", "clipRight", "clipRule", "clipTop", "clipboardData", "clone", "cloneContents", "cloneNode", "cloneRange", "close", "closePath", "closed", "closest", "clz", "clz32", "cmp", "code", "codeBase", "codePointAt", "codeType", "colSpan", "collapse", "collapseToEnd", "collapseToStart", "collapsed", "collect", "colno", "color", "color-interpolation", "color-interpolation-filters", "colorDepth", "colorInterpolation", "colorInterpolationFilters", "colorMask", "colorType", "cols", "columnCount", "columnFill", "columnGap", "columnNumber", "columnRule", "columnRuleColor", "columnRuleStyle", "columnRuleWidth", "columnSpan", "columnWidth", "columns", "command", "commitPreferences", "commonAncestorContainer", "compact", "compareBoundaryPoints", "compareDocumentPosition", "compareEndPoints", "compareNode", "comparePoint", "compatMode", "compatible", "compile", "compileShader", "complete", "componentFromPoint", "compositionEndOffset", "compositionStartOffset", "compressedTexImage2D", "compressedTexSubImage2D", "concat", "conditionText", "coneInnerAngle", "coneOuterAngle", "coneOuterGain", "confirm", "confirmComposition", "confirmSiteSpecificTrackingException", "confirmWebWideTrackingException", "connect", "connectEnd", "connectStart", "connected", "connection", "connectionSpeed", "console", "consolidate", "constrictionActive", "constructor", "contactID", "contains", "containsNode", "content", "contentDocument", "contentEditable", "contentOverflow", "contentScriptType", "contentStyleType", "contentType", "contentWindow", "context", "contextMenu", "contextmenu", "continue", "continuous", "control", "controller", "controls", "convertToSpecifiedUnits", "cookie", "cookieEnabled", "coords", "copyFromChannel", "copyTexImage2D", "copyTexSubImage2D", "copyToChannel", "copyWithin", "correspondingElement", "correspondingUseElement", "cos", "cosh", "count", "counter-increment", "counter-reset", "counterIncrement", "counterReset", "cpuClass", "cpuSleepAllowed", "create", "createAnalyser", "createAnswer", "createAttribute", "createAttributeNS", "createBiquadFilter", "createBuffer", "createBufferSource", "createCDATASection", "createCSSStyleSheet", "createCaption", "createChannelMerger", "createChannelSplitter", "createComment", "createContextualFragment", "createControlRange", "createConvolver", "createDTMFSender", "createDataChannel", "createDelay", "createDelayNode", "createDocument", "createDocumentFragment", "createDocumentType", "createDynamicsCompressor", "createElement", "createElementNS", "createEntityReference", "createEvent", "createEventObject", "createExpression", "createFramebuffer", "createFunction", "createGain", "createGainNode", "createHTMLDocument", "createImageBitmap", "createImageData", "createIndex", "createJavaScriptNode", "createLinearGradient", "createMediaElementSource", "createMediaKeys", "createMediaStreamDestination", "createMediaStreamSource", "createMutableFile", "createNSResolver", "createNodeIterator", "createNotification", "createObjectStore", "createObjectURL", "createOffer", "createOscillator", "createPanner", "createPattern", "createPeriodicWave", "createPopup", "createProcessingInstruction", "createProgram", "createRadialGradient", "createRange", "createRangeCollection", "createRenderbuffer", "createSVGAngle", "createSVGLength", "createSVGMatrix", "createSVGNumber", "createSVGPathSegArcAbs", "createSVGPathSegArcRel", "createSVGPathSegClosePath", "createSVGPathSegCurvetoCubicAbs", "createSVGPathSegCurvetoCubicRel", "createSVGPathSegCurvetoCubicSmoothAbs", "createSVGPathSegCurvetoCubicSmoothRel", "createSVGPathSegCurvetoQuadraticAbs", "createSVGPathSegCurvetoQuadraticRel", "createSVGPathSegCurvetoQuadraticSmoothAbs", "createSVGPathSegCurvetoQuadraticSmoothRel", "createSVGPathSegLinetoAbs", "createSVGPathSegLinetoHorizontalAbs", "createSVGPathSegLinetoHorizontalRel", "createSVGPathSegLinetoRel", "createSVGPathSegLinetoVerticalAbs", "createSVGPathSegLinetoVerticalRel", "createSVGPathSegMovetoAbs", "createSVGPathSegMovetoRel", "createSVGPoint", "createSVGRect", "createSVGTransform", "createSVGTransformFromMatrix", "createScriptProcessor", "createSession", "createShader", "createShadowRoot", "createStereoPanner", "createStyleSheet", "createTBody", "createTFoot", "createTHead", "createTextNode", "createTextRange", "createTexture", "createTouch", "createTouchList", "createTreeWalker", "createWaveShaper", "creationTime", "crossOrigin", "crypto", "csi", "cssFloat", "cssRules", "cssText", "cssValueType", "ctrlKey", "ctrlLeft", "cues", "cullFace", "currentNode", "currentPage", "currentScale", "currentScript", "currentSrc", "currentState", "currentStyle", "currentTarget", "currentTime", "currentTranslate", "currentView", "cursor", "curve", "customError", "cx", "cy", "d", "data", "dataFld", "dataFormatAs", "dataPageSize", "dataSrc", "dataTransfer", "database", "dataset", "dateTime", "db", "debug", "debuggerEnabled", "declare", "decode", "decodeAudioData", "decodingInfo", "decodeURI", "decodeURIComponent", "decrypt", "default", "defaultCharset", "defaultChecked", "defaultMuted", "defaultPlaybackRate", "defaultPrevented", "defaultSelected", "defaultStatus", "defaultURL", "defaultValue", "defaultView", "defaultstatus", "defer", "defineMagicFunction", "defineMagicVariable", "defineProperties", "defineProperty", "delayTime", "delete", "deleteBuffer", "deleteCaption", "deleteCell", "deleteContents", "deleteData", "deleteDatabase", "deleteFramebuffer", "deleteFromDocument", "deleteIndex", "deleteMedium", "deleteObjectStore", "deleteProgram", "deleteRenderbuffer", "deleteRow", "deleteRule", "deleteShader", "deleteTFoot", "deleteTHead", "deleteTexture", "deliverChangeRecords", "delivery", "deliveryInfo", "deliveryStatus", "deliveryTimestamp", "delta", "deltaMode", "deltaX", "deltaY", "deltaZ", "depthFunc", "depthMask", "depthRange", "deriveBits", "deriveKey", "description", "deselectAll", "designMode", "destination", "destinationURL", "detach", "detachEvent", "detachShader", "detail", "detune", "devicePixelRatio", "deviceXDPI", "deviceYDPI", "diffuseConstant", "digest", "dimensions", "dir", "dirName", "direction", "dirxml", "disable", "disableVertexAttribArray", "disabled", "dischargingTime", "disconnect", "dispatchEvent", "display", "distanceModel", "divisor", "djsapi", "djsproxy", "doImport", "doNotTrack", "doScroll", "doctype", "document", "documentElement", "documentMode", "documentURI", "dolphin", "dolphinGameCenter", "dolphininfo", "dolphinmeta", "domComplete", "domContentLoadedEventEnd", "domContentLoadedEventStart", "domInteractive", "domLoading", "domain", "domainLookupEnd", "domainLookupStart", "dominant-baseline", "dominantBaseline", "done", "dopplerFactor", "download", "dragDrop", "draggable", "drawArrays", "drawArraysInstancedANGLE", "drawCustomFocusRing", "drawElements", "drawElementsInstancedANGLE", "drawFocusIfNeeded", "drawImage", "drawImageFromRect", "drawSystemFocusRing", "drawingBufferHeight", "drawingBufferWidth", "dropEffect", "droppedVideoFrames", "dropzone", "dump", "duplicate", "duration", "dvname", "dvnum", "dx", "dy", "dynsrc", "e", "edgeMode", "effectAllowed", "elapsedTime", "elementFromPoint", "elements", "elevation", "ellipse", "email", "embeds", "empty", "empty-cells", "emptyCells", "enable", "enableBackground", "enableStyleSheetsForSet", "enableVertexAttribArray", "enabled", "enabledPlugin", "encode", "encodeURI", "encodeURIComponent", "encoding", "encrypt", "enctype", "end", "endContainer", "endElement", "endElementAt", "endOfStream", "endOffset", "endTime", "ended", "endsWith", "entities", "entries", "entryType", "enumerate", "enumerateEditable", "error", "errorCode", "escape", "eval", "evaluate", "event", "eventPhase", "every", "exception", "exec", "execCommand", "execCommandShowHelp", "execScript", "exitFullscreen", "exitPointerLock", "exp", "expand", "expandEntityReferences", "expando", "expansion", "expiryDate", "explicitOriginalTarget", "expm1", "exponent", "exponentialRampToValueAtTime", "exportKey", "extend", "extensions", "extentNode", "extentOffset", "external", "externalResourcesRequired", "extractContents", "extractable", "f", "face", "factoryReset", "fallback", "familyName", "farthestViewportElement", "fastSeek", "fatal", "fetch", "fetchStart", "fftSize", "fgColor", "fileCreatedDate", "fileHandle", "fileModifiedDate", "fileName", "fileSize", "fileUpdatedDate", "filename", "files", "fill", "fill-opacity", "fill-rule", "fillOpacity", "fillRect", "fillRule", "fillStyle", "fillText", "filter", "filterResX", "filterResY", "filterUnits", "filters", "finally", "find", "findIndex", "findRule", "findText", "finish", "fireEvent", "firstChild", "firstElementChild", "firstPage", "fixed", "flex", "flex-basis", "flex-direction", "flex-flow", "flex-grow", "flex-shrink", "flex-wrap", "flexBasis", "flexDirection", "flexFlow", "flexGrow", "flexShrink", "flexWrap", "flipX", "flipY", "float", "flood-color", "flood-opacity", "floodColor", "floodOpacity", "floor", "flush", "focus", "focusNode", "focusOffset", "font", "font-family", "font-feature-settings", "font-kerning", "font-language-override", "font-size", "font-size-adjust", "font-stretch", "font-style", "font-synthesis", "font-variant", "font-variant-alternates", "font-variant-caps", "font-variant-east-asian", "font-variant-ligatures", "font-variant-numeric", "font-variant-position", "font-weight", "fontFamily", "fontFeatureSettings", "fontKerning", "fontLanguageOverride", "fontSize", "fontSizeAdjust", "fontSmoothingEnabled", "fontStretch", "fontStyle", "fontSynthesis", "fontVariant", "fontVariantAlternates", "fontVariantCaps", "fontVariantEastAsian", "fontVariantLigatures", "fontVariantNumeric", "fontVariantPosition", "fontWeight", "fontcolor", "fonts", "fontsize", "for", "forEach", "forceRedraw", "form", "formAction", "formEnctype", "formMethod", "formNoValidate", "formTarget", "format", "forms", "forward", "fr", "frame", "frameBorder", "frameElement", "frameSpacing", "framebufferRenderbuffer", "framebufferTexture2D", "frames", "freeSpace", "freeze", "frequency", "frequencyBinCount", "from", "fromCharCode", "fromCodePoint", "fromElement", "frontFace", "fround", "fullScreen", "fullscreenElement", "fullscreenEnabled", "fx", "fy", "gain", "gamepad", "gamma", "genderIdentity", "generateKey", "generateMipmap", "generateRequest", "geolocation", "gestureObject", "get", "getActiveAttrib", "getActiveUniform", "getAdjacentText", "getAll", "getAllResponseHeaders", "getAsFile", "getAsString", "getAttachedShaders", "getAttribLocation", "getAttribute", "getAttributeNS", "getAttributeNode", "getAttributeNodeNS", "getAudioTracks", "getBBox", "getBattery", "getBlob", "getBookmark", "getBoundingClientRect", "getBufferParameter", "getByteFrequencyData", "getByteTimeDomainData", "getCSSCanvasContext", "getCTM", "getCandidateWindowClientRect", "getChannelData", "getCharNumAtPosition", "getClientRect", "getClientRects", "getCompositionAlternatives", "getComputedStyle", "getComputedTextLength", "getConfiguration", "getContext", "getContextAttributes", "getCounterValue", "getCueAsHTML", "getCueById", "getCurrentPosition", "getCurrentTime", "getData", "getDatabaseNames", "getDate", "getDay", "getDefaultComputedStyle", "getDestinationInsertionPoints", "getDistributedNodes", "getEditable", "getElementById", "getElementsByClassName", "getElementsByName", "getElementsByTagName", "getElementsByTagNameNS", "getEnclosureList", "getEndPositionOfChar", "getEntries", "getEntriesByName", "getEntriesByType", "getError", "getExtension", "getExtentOfChar", "getFeature", "getFile", "getFloat32", "getFloat64", "getFloatFrequencyData", "getFloatTimeDomainData", "getFloatValue", "getFramebufferAttachmentParameter", "getFrequencyResponse", "getFullYear", "getGamepads", "getHours", "getImageData", "getInt16", "getInt32", "getInt8", "getIntersectionList", "getItem", "getItems", "getKey", "getLineDash", "getLocalStreams", "getMarks", "getMatchedCSSRules", "getMeasures", "getMetadata", "getMilliseconds", "getMinutes", "getModifierState", "getMonth", "getNamedItem", "getNamedItemNS", "getNotifier", "getNumberOfChars", "getOverrideHistoryNavigationMode", "getOverrideStyle", "getOwnPropertyDescriptor", "getOwnPropertyNames", "getOwnPropertySymbols", "getParameter", "getPathSegAtLength", "getPointAtLength", "getPreference", "getPreferenceDefault", "getPresentationAttribute", "getPreventDefault", "getProgramInfoLog", "getProgramParameter", "getPropertyCSSValue", "getPropertyPriority", "getPropertyShorthand", "getPropertyValue", "getPrototypeOf", "getRGBColorValue", "getRandomValues", "getRangeAt", "getReceivers", "getRectValue", "getRegistration", "getRemoteStreams", "getRenderbufferParameter", "getResponseHeader", "getRoot", "getRotationOfChar", "getSVGDocument", "getScreenCTM", "getSeconds", "getSelection", "getSenders", "getShaderInfoLog", "getShaderParameter", "getShaderPrecisionFormat", "getShaderSource", "getSimpleDuration", "getSiteIcons", "getSources", "getSpeculativeParserUrls", "getStartPositionOfChar", "getStartTime", "getStats", "getStorageUpdates", "getStreamById", "getStringValue", "getSubStringLength", "getSubscription", "getSupportedExtensions", "getTexParameter", "getTime", "getTimezoneOffset", "getTotalLength", "getTrackById", "getTracks", "getTransformToElement", "getUTCDate", "getUTCDay", "getUTCFullYear", "getUTCHours", "getUTCMilliseconds", "getUTCMinutes", "getUTCMonth", "getUTCSeconds", "getUint16", "getUint32", "getUint8", "getUniform", "getUniformLocation", "getUserMedia", "getValues", "getVarDate", "getVariableValue", "getVertexAttrib", "getVertexAttribOffset", "getVideoPlaybackQuality", "getVideoTracks", "getWakeLockState", "getYear", "givenName", "global", "globalAlpha", "globalCompositeOperation", "glyphOrientationHorizontal", "glyphOrientationVertical", "glyphRef", "go", "gradientTransform", "gradientUnits", "grammars", "green", "group", "groupCollapsed", "groupEnd", "hardwareConcurrency", "has", "hasAttribute", "hasAttributeNS", "hasAttributes", "hasChildNodes", "hasComposition", "hasExtension", "hasFeature", "hasFocus", "hasLayout", "hasOwnProperty", "hash", "head", "headers", "heading", "height", "hidden", "hide", "hideFocus", "high", "hint", "history", "honorificPrefix", "honorificSuffix", "horizontalOverflow", "host", "hostname", "href", "hreflang", "hspace", "html5TagCheckInerface", "htmlFor", "htmlText", "httpEquiv", "hwTimestamp", "hypot", "iccId", "iceConnectionState", "iceGatheringState", "icon", "id", "identifier", "identity", "ignoreBOM", "ignoreCase", "image-orientation", "image-rendering", "imageOrientation", "imageRendering", "images", "ime-mode", "imeMode", "implementation", "importKey", "importNode", "importStylesheet", "imports", "impp", "imul", "in1", "in2", "inBandMetadataTrackDispatchType", "inRange", "includes", "incremental", "indeterminate", "index", "indexNames", "indexOf", "indexedDB", "inertiaDestinationX", "inertiaDestinationY", "info", "init", "initAnimationEvent", "initBeforeLoadEvent", "initClipboardEvent", "initCloseEvent", "initCommandEvent", "initCompositionEvent", "initCustomEvent", "initData", "initDeviceMotionEvent", "initDeviceOrientationEvent", "initDragEvent", "initErrorEvent", "initEvent", "initFocusEvent", "initGestureEvent", "initHashChangeEvent", "initKeyEvent", "initKeyboardEvent", "initMSManipulationEvent", "initMessageEvent", "initMouseEvent", "initMouseScrollEvent", "initMouseWheelEvent", "initMutationEvent", "initNSMouseEvent", "initOverflowEvent", "initPageEvent", "initPageTransitionEvent", "initPointerEvent", "initPopStateEvent", "initProgressEvent", "initScrollAreaEvent", "initSimpleGestureEvent", "initStorageEvent", "initTextEvent", "initTimeEvent", "initTouchEvent", "initTransitionEvent", "initUIEvent", "initWebKitAnimationEvent", "initWebKitTransitionEvent", "initWebKitWheelEvent", "initWheelEvent", "initialTime", "initialize", "initiatorType", "inner", "innerHTML", "innerHeight", "innerText", "innerWidth", "input", "inputBuffer", "inputEncoding", "inputMethod", "insertAdjacentElement", "insertAdjacentHTML", "insertAdjacentText", "insertBefore", "insertCell", "insertData", "insertItemBefore", "insertNode", "insertRow", "insertRule", "instanceRoot", "intercept", "interimResults", "internalSubset", "intersectsNode", "interval", "invalidIteratorState", "inverse", "invertSelf", "is", "is2D", "isAlternate", "isArray", "isBingCurrentSearchDefault", "isBuffer", "isCandidateWindowVisible", "isChar", "isCollapsed", "isComposing", "isContentEditable", "isContentHandlerRegistered", "isContextLost", "isDefaultNamespace", "isDisabled", "isEnabled", "isEqual", "isEqualNode", "isExtensible", "isFinite", "isFramebuffer", "isFrozen", "isGenerator", "isId", "isInjected", "isInteger", "isMap", "isMultiLine", "isNaN", "isOpen", "isPointInFill", "isPointInPath", "isPointInRange", "isPointInStroke", "isPrefAlternate", "isPrimary", "isProgram", "isPropertyImplicit", "isProtocolHandlerRegistered", "isPrototypeOf", "isRenderbuffer", "isSafeInteger", "isSameNode", "isSealed", "isShader", "isSupported", "isTextEdit", "isTexture", "isTrusted", "isTypeSupported", "isView", "isolation", "italics", "item", "itemId", "itemProp", "itemRef", "itemScope", "itemType", "itemValue", "iterateNext", "iterator", "javaEnabled", "jobTitle", "join", "json", "justify-content", "justifyContent", "k1", "k2", "k3", "k4", "kernelMatrix", "kernelUnitLengthX", "kernelUnitLengthY", "kerning", "key", "keyCode", "keyFor", "keyIdentifier", "keyLightEnabled", "keyLocation", "keyPath", "keySystem", "keyText", "keyUsage", "keys", "keytype", "kind", "knee", "label", "labels", "lang", "language", "languages", "largeArcFlag", "lastChild", "lastElementChild", "lastEventId", "lastIndex", "lastIndexOf", "lastMatch", "lastMessageSubject", "lastMessageType", "lastModified", "lastModifiedDate", "lastPage", "lastParen", "lastState", "lastStyleSheetSet", "latitude", "layerX", "layerY", "layoutFlow", "layoutGrid", "layoutGridChar", "layoutGridLine", "layoutGridMode", "layoutGridType", "lbound", "left", "leftContext", "leftMargin", "length", "lengthAdjust", "lengthComputable", "letter-spacing", "letterSpacing", "level", "lighting-color", "lightingColor", "limitingConeAngle", "line", "line-height", "lineAlign", "lineBreak", "lineCap", "lineDashOffset", "lineHeight", "lineJoin", "lineNumber", "lineTo", "lineWidth", "linearRampToValueAtTime", "lineno", "link", "linkColor", "linkProgram", "links", "list", "list-style", "list-style-image", "list-style-position", "list-style-type", "listStyle", "listStyleImage", "listStylePosition", "listStyleType", "listener", "load", "loadEventEnd", "loadEventStart", "loadTimes", "loaded", "localDescription", "localName", "localStorage", "locale", "localeCompare", "location", "locationbar", "lock", "lockedFile", "log", "log10", "log1p", "log2", "logicalXDPI", "logicalYDPI", "longDesc", "longitude", "lookupNamespaceURI", "lookupPrefix", "loop", "loopEnd", "loopStart", "looping", "low", "lower", "lowerBound", "lowerOpen", "lowsrc", "m11", "m12", "m13", "m14", "m21", "m22", "m23", "m24", "m31", "m32", "m33", "m34", "m41", "m42", "m43", "m44", "manifest", "map", "mapping", "margin", "margin-bottom", "margin-left", "margin-right", "margin-top", "marginBottom", "marginHeight", "marginLeft", "marginRight", "marginTop", "marginWidth", "mark", "marker", "marker-end", "marker-mid", "marker-offset", "marker-start", "markerEnd", "markerHeight", "markerMid", "markerOffset", "markerStart", "markerUnits", "markerWidth", "marks", "mask", "mask-type", "maskContentUnits", "maskType", "maskUnits", "match", "matchMedia", "matchMedium", "matches", "matrix", "matrixTransform", "max", "max-height", "max-width", "maxAlternatives", "maxChannelCount", "maxConnectionsPerServer", "maxDecibels", "maxDistance", "maxHeight", "maxLength", "maxTouchPoints", "maxValue", "maxWidth", "measure", "measureText", "media", "mediaCapabilities", "mediaDevices", "mediaElement", "mediaGroup", "mediaKeys", "mediaText", "meetOrSlice", "memory", "menubar", "mergeAttributes", "message", "messageClass", "messageHandlers", "metaKey", "method", "mimeType", "mimeTypes", "min", "min-height", "min-width", "minDecibels", "minHeight", "minValue", "minWidth", "miterLimit", "mix-blend-mode", "mixBlendMode", "mode", "modify", "mount", "move", "moveBy", "moveEnd", "moveFirst", "moveFocusDown", "moveFocusLeft", "moveFocusRight", "moveFocusUp", "moveNext", "moveRow", "moveStart", "moveTo", "moveToBookmark", "moveToElementText", "moveToPoint", "mozAdd", "mozAnimationStartTime", "mozAnon", "mozApps", "mozAudioCaptured", "mozAudioChannelType", "mozAutoplayEnabled", "mozCancelAnimationFrame", "mozCancelFullScreen", "mozCancelRequestAnimationFrame", "mozCaptureStream", "mozCaptureStreamUntilEnded", "mozClearDataAt", "mozContact", "mozContacts", "mozCreateFileHandle", "mozCurrentTransform", "mozCurrentTransformInverse", "mozCursor", "mozDash", "mozDashOffset", "mozDecodedFrames", "mozExitPointerLock", "mozFillRule", "mozFragmentEnd", "mozFrameDelay", "mozFullScreen", "mozFullScreenElement", "mozFullScreenEnabled", "mozGetAll", "mozGetAllKeys", "mozGetAsFile", "mozGetDataAt", "mozGetMetadata", "mozGetUserMedia", "mozHasAudio", "mozHasItem", "mozHidden", "mozImageSmoothingEnabled", "mozIndexedDB", "mozInnerScreenX", "mozInnerScreenY", "mozInputSource", "mozIsTextField", "mozItem", "mozItemCount", "mozItems", "mozLength", "mozLockOrientation", "mozMatchesSelector", "mozMovementX", "mozMovementY", "mozOpaque", "mozOrientation", "mozPaintCount", "mozPaintedFrames", "mozParsedFrames", "mozPay", "mozPointerLockElement", "mozPresentedFrames", "mozPreservesPitch", "mozPressure", "mozPrintCallback", "mozRTCIceCandidate", "mozRTCPeerConnection", "mozRTCSessionDescription", "mozRemove", "mozRequestAnimationFrame", "mozRequestFullScreen", "mozRequestPointerLock", "mozSetDataAt", "mozSetImageElement", "mozSourceNode", "mozSrcObject", "mozSystem", "mozTCPSocket", "mozTextStyle", "mozTypesAt", "mozUnlockOrientation", "mozUserCancelled", "mozVisibilityState", "msAnimation", "msAnimationDelay", "msAnimationDirection", "msAnimationDuration", "msAnimationFillMode", "msAnimationIterationCount", "msAnimationName", "msAnimationPlayState", "msAnimationStartTime", "msAnimationTimingFunction", "msBackfaceVisibility", "msBlockProgression", "msCSSOMElementFloatMetrics", "msCaching", "msCachingEnabled", "msCancelRequestAnimationFrame", "msCapsLockWarningOff", "msClearImmediate", "msClose", "msContentZoomChaining", "msContentZoomFactor", "msContentZoomLimit", "msContentZoomLimitMax", "msContentZoomLimitMin", "msContentZoomSnap", "msContentZoomSnapPoints", "msContentZoomSnapType", "msContentZooming", "msConvertURL", "msCrypto", "msDoNotTrack", "msElementsFromPoint", "msElementsFromRect", "msExitFullscreen", "msExtendedCode", "msFillRule", "msFirstPaint", "msFlex", "msFlexAlign", "msFlexDirection", "msFlexFlow", "msFlexItemAlign", "msFlexLinePack", "msFlexNegative", "msFlexOrder", "msFlexPack", "msFlexPositive", "msFlexPreferredSize", "msFlexWrap", "msFlowFrom", "msFlowInto", "msFontFeatureSettings", "msFullscreenElement", "msFullscreenEnabled", "msGetInputContext", "msGetRegionContent", "msGetUntransformedBounds", "msGraphicsTrustStatus", "msGridColumn", "msGridColumnAlign", "msGridColumnSpan", "msGridColumns", "msGridRow", "msGridRowAlign", "msGridRowSpan", "msGridRows", "msHidden", "msHighContrastAdjust", "msHyphenateLimitChars", "msHyphenateLimitLines", "msHyphenateLimitZone", "msHyphens", "msImageSmoothingEnabled", "msImeAlign", "msIndexedDB", "msInterpolationMode", "msIsStaticHTML", "msKeySystem", "msKeys", "msLaunchUri", "msLockOrientation", "msManipulationViewsEnabled", "msMatchMedia", "msMatchesSelector", "msMaxTouchPoints", "msOrientation", "msOverflowStyle", "msPerspective", "msPerspectiveOrigin", "msPlayToDisabled", "msPlayToPreferredSourceUri", "msPlayToPrimary", "msPointerEnabled", "msRegionOverflow", "msReleasePointerCapture", "msRequestAnimationFrame", "msRequestFullscreen", "msSaveBlob", "msSaveOrOpenBlob", "msScrollChaining", "msScrollLimit", "msScrollLimitXMax", "msScrollLimitXMin", "msScrollLimitYMax", "msScrollLimitYMin", "msScrollRails", "msScrollSnapPointsX", "msScrollSnapPointsY", "msScrollSnapType", "msScrollSnapX", "msScrollSnapY", "msScrollTranslation", "msSetImmediate", "msSetMediaKeys", "msSetPointerCapture", "msTextCombineHorizontal", "msTextSizeAdjust", "msToBlob", "msTouchAction", "msTouchSelect", "msTraceAsyncCallbackCompleted", "msTraceAsyncCallbackStarting", "msTraceAsyncOperationCompleted", "msTraceAsyncOperationStarting", "msTransform", "msTransformOrigin", "msTransformStyle", "msTransition", "msTransitionDelay", "msTransitionDuration", "msTransitionProperty", "msTransitionTimingFunction", "msUnlockOrientation", "msUpdateAsyncCallbackRelation", "msUserSelect", "msVisibilityState", "msWrapFlow", "msWrapMargin", "msWrapThrough", "msWriteProfilerMark", "msZoom", "msZoomTo", "mt", "multiEntry", "multiSelectionObj", "multiline", "multiple", "multiply", "multiplySelf", "mutableFile", "muted", "n", "name", "nameProp", "namedItem", "namedRecordset", "names", "namespaceURI", "namespaces", "naturalHeight", "naturalWidth", "navigate", "navigation", "navigationMode", "navigationStart", "navigator", "near", "nearestViewportElement", "negative", "netscape", "networkState", "newScale", "newTranslate", "newURL", "newValue", "newValueSpecifiedUnits", "newVersion", "newhome", "next", "nextElementSibling", "nextNode", "nextPage", "nextSibling", "nickname", "noHref", "noResize", "noShade", "noValidate", "noWrap", "nodeName", "nodeType", "nodeValue", "normalize", "normalizedPathSegList", "notationName", "notations", "note", "noteGrainOn", "noteOff", "noteOn", "now", "numOctaves", "number", "numberOfChannels", "numberOfInputs", "numberOfItems", "numberOfOutputs", "numberValue", "oMatchesSelector", "object", "object-fit", "object-position", "objectFit", "objectPosition", "objectStore", "objectStoreNames", "observe", "of", "offscreenBuffering", "offset", "offsetHeight", "offsetLeft", "offsetNode", "offsetParent", "offsetTop", "offsetWidth", "offsetX", "offsetY", "ok", "oldURL", "oldValue", "oldVersion", "olderShadowRoot", "onLine", "onabort", "onactivate", "onactive", "onaddstream", "onaddtrack", "onafterprint", "onafterscriptexecute", "onafterupdate", "onaudioend", "onaudioprocess", "onaudiostart", "onautocomplete", "onautocompleteerror", "onbeforeactivate", "onbeforecopy", "onbeforecut", "onbeforedeactivate", "onbeforeeditfocus", "onbeforepaste", "onbeforeprint", "onbeforescriptexecute", "onbeforeunload", "onbeforeupdate", "onblocked", "onblur", "onbounce", "onboundary", "oncached", "oncancel", "oncandidatewindowhide", "oncandidatewindowshow", "oncandidatewindowupdate", "oncanplay", "oncanplaythrough", "oncellchange", "onchange", "onchargingchange", "onchargingtimechange", "onchecking", "onclick", "onclose", "oncompassneedscalibration", "oncomplete", "oncontextmenu", "oncontrolselect", "oncopy", "oncuechange", "oncut", "ondataavailable", "ondatachannel", "ondatasetchanged", "ondatasetcomplete", "ondblclick", "ondeactivate", "ondevicelight", "ondevicemotion", "ondeviceorientation", "ondeviceproximity", "ondischargingtimechange", "ondisplay", "ondownloading", "ondrag", "ondragend", "ondragenter", "ondragleave", "ondragover", "ondragstart", "ondrop", "ondurationchange", "onemptied", "onencrypted", "onend", "onended", "onenter", "onerror", "onerrorupdate", "onexit", "onfilterchange", "onfinish", "onfocus", "onfocusin", "onfocusout", "onfullscreenchange", "onfullscreenerror", "ongesturechange", "ongestureend", "ongesturestart", "ongotpointercapture", "onhashchange", "onhelp", "onicecandidate", "oniceconnectionstatechange", "oninactive", "oninput", "oninvalid", "onkeydown", "onkeypress", "onkeyup", "onlanguagechange", "onlayoutcomplete", "onlevelchange", "onload", "onloadeddata", "onloadedmetadata", "onloadend", "onloadstart", "onlosecapture", "onlostpointercapture", "only", "onmark", "onmessage", "onmousedown", "onmouseenter", "onmouseleave", "onmousemove", "onmouseout", "onmouseover", "onmouseup", "onmousewheel", "onmove", "onmoveend", "onmovestart", "onmozfullscreenchange", "onmozfullscreenerror", "onmozorientationchange", "onmozpointerlockchange", "onmozpointerlockerror", "onmscontentzoom", "onmsfullscreenchange", "onmsfullscreenerror", "onmsgesturechange", "onmsgesturedoubletap", "onmsgestureend", "onmsgesturehold", "onmsgesturestart", "onmsgesturetap", "onmsgotpointercapture", "onmsinertiastart", "onmslostpointercapture", "onmsmanipulationstatechanged", "onmsneedkey", "onmsorientationchange", "onmspointercancel", "onmspointerdown", "onmspointerenter", "onmspointerhover", "onmspointerleave", "onmspointermove", "onmspointerout", "onmspointerover", "onmspointerup", "onmssitemodejumplistitemremoved", "onmsthumbnailclick", "onnegotiationneeded", "onnomatch", "onnoupdate", "onobsolete", "onoffline", "ononline", "onopen", "onorientationchange", "onpagechange", "onpagehide", "onpageshow", "onpaste", "onpause", "onplay", "onplaying", "onpluginstreamstart", "onpointercancel", "onpointerdown", "onpointerenter", "onpointerleave", "onpointerlockchange", "onpointerlockerror", "onpointermove", "onpointerout", "onpointerover", "onpointerup", "onpopstate", "onprogress", "onpropertychange", "onratechange", "onreadystatechange", "onremovestream", "onremovetrack", "onreset", "onresize", "onresizeend", "onresizestart", "onresourcetimingbufferfull", "onresult", "onresume", "onrowenter", "onrowexit", "onrowsdelete", "onrowsinserted", "onscroll", "onsearch", "onseeked", "onseeking", "onselect", "onselectionchange", "onselectstart", "onshow", "onsignalingstatechange", "onsoundend", "onsoundstart", "onspeechend", "onspeechstart", "onstalled", "onstart", "onstatechange", "onstop", "onstorage", "onstoragecommit", "onsubmit", "onsuccess", "onsuspend", "ontextinput", "ontimeout", "ontimeupdate", "ontoggle", "ontouchcancel", "ontouchend", "ontouchmove", "ontouchstart", "ontransitionend", "onunload", "onupdateready", "onupgradeneeded", "onuserproximity", "onversionchange", "onvoiceschanged", "onvolumechange", "onwaiting", "onwarning", "onwebkitanimationend", "onwebkitanimationiteration", "onwebkitanimationstart", "onwebkitcurrentplaybacktargetiswirelesschanged", "onwebkitfullscreenchange", "onwebkitfullscreenerror", "onwebkitkeyadded", "onwebkitkeyerror", "onwebkitkeymessage", "onwebkitneedkey", "onwebkitorientationchange", "onwebkitplaybacktargetavailabilitychanged", "onwebkitpointerlockchange", "onwebkitpointerlockerror", "onwebkitresourcetimingbufferfull", "onwebkittransitionend", "onwheel", "onzoom", "opacity", "open", "openCursor", "openDatabase", "openKeyCursor", "opener", "opera", "operationType", "operator", "opr", "optimum", "options", "order", "orderX", "orderY", "ordered", "org", "orient", "orientAngle", "orientType", "orientation", "origin", "originalTarget", "orphans", "oscpu", "outerHTML", "outerHeight", "outerText", "outerWidth", "outline", "outline-color", "outline-offset", "outline-style", "outline-width", "outlineColor", "outlineOffset", "outlineStyle", "outlineWidth", "outputBuffer", "overflow", "overflow-x", "overflow-y", "overflowX", "overflowY", "overrideMimeType", "oversample", "ownerDocument", "ownerElement", "ownerNode", "ownerRule", "ownerSVGElement", "owningElement", "p1", "p2", "p3", "p4", "pad", "padding", "padding-bottom", "padding-left", "padding-right", "padding-top", "paddingBottom", "paddingLeft", "paddingRight", "paddingTop", "page", "page-break-after", "page-break-before", "page-break-inside", "pageBreakAfter", "pageBreakBefore", "pageBreakInside", "pageCount", "pageX", "pageXOffset", "pageY", "pageYOffset", "pages", "paint-order", "paintOrder", "paintRequests", "paintType", "palette", "panningModel", "parent", "parentElement", "parentNode", "parentRule", "parentStyleSheet", "parentTextEdit", "parentWindow", "parse", "parseFloat", "parseFromString", "parseInt", "participants", "password", "pasteHTML", "path", "pathLength", "pathSegList", "pathSegType", "pathSegTypeAsLetter", "pathname", "pattern", "patternContentUnits", "patternMismatch", "patternTransform", "patternUnits", "pause", "pauseAnimations", "pauseOnExit", "paused", "pending", "performance", "permission", "persisted", "personalbar", "perspective", "perspective-origin", "perspectiveOrigin", "phoneticFamilyName", "phoneticGivenName", "photo", "ping", "pitch", "pixelBottom", "pixelDepth", "pixelHeight", "pixelLeft", "pixelRight", "pixelStorei", "pixelTop", "pixelUnitToMillimeterX", "pixelUnitToMillimeterY", "pixelWidth", "placeholder", "platform", "play", "playbackRate", "playbackState", "playbackTime", "played", "plugins", "pluginspage", "pname", "pointer-events", "pointerBeforeReferenceNode", "pointerEnabled", "pointerEvents", "pointerId", "pointerLockElement", "pointerType", "points", "pointsAtX", "pointsAtY", "pointsAtZ", "polygonOffset", "pop", "popupWindowFeatures", "popupWindowName", "popupWindowURI", "port", "port1", "port2", "ports", "posBottom", "posHeight", "posLeft", "posRight", "posTop", "posWidth", "position", "positionAlign", "postError", "postMessage", "poster", "pow", "powerOff", "preMultiplySelf", "precision", "preferredStyleSheetSet", "preferredStylesheetSet", "prefix", "preload", "preserveAlpha", "preserveAspectRatio", "preserveAspectRatioString", "pressed", "pressure", "prevValue", "preventDefault", "preventExtensions", "previousElementSibling", "previousNode", "previousPage", "previousScale", "previousSibling", "previousTranslate", "primaryKey", "primitiveType", "primitiveUnits", "principals", "print", "privateKey", "probablySupportsContext", "process", "processIceMessage", "product", "productSub", "profile", "profileEnd", "profiles", "prompt", "properties", "propertyIsEnumerable", "propertyName", "protocol", "protocolLong", "prototype", "pseudoClass", "pseudoElement", "publicId", "publicKey", "published", "push", "pushNotification", "pushState", "put", "putImageData", "quadraticCurveTo", "qualifier", "queryCommandEnabled", "queryCommandIndeterm", "queryCommandState", "queryCommandSupported", "queryCommandText", "queryCommandValue", "querySelector", "querySelectorAll", "quote", "quotes", "r", "r1", "r2", "race", "radiogroup", "radiusX", "radiusY", "random", "range", "rangeCount", "rangeMax", "rangeMin", "rangeOffset", "rangeOverflow", "rangeParent", "rangeUnderflow", "rate", "ratio", "raw", "read", "readAsArrayBuffer", "readAsBinaryString", "readAsBlob", "readAsDataURL", "readAsText", "readOnly", "readPixels", "readReportRequested", "readyState", "reason", "reboot", "receiver", "receivers", "recordNumber", "recordset", "rect", "red", "redirectCount", "redirectEnd", "redirectStart", "reduce", "reduceRight", "reduction", "refDistance", "refX", "refY", "referenceNode", "referrer", "refresh", "region", "regionAnchorX", "regionAnchorY", "regionId", "regions", "register", "registerContentHandler", "registerElement", "registerProtocolHandler", "reject", "rel", "relList", "relatedNode", "relatedTarget", "release", "releaseCapture", "releaseEvents", "releasePointerCapture", "releaseShaderCompiler", "reliable", "reload", "remainingSpace", "remoteDescription", "remove", "removeAllRanges", "removeAttribute", "removeAttributeNS", "removeAttributeNode", "removeBehavior", "removeChild", "removeCue", "removeEventListener", "removeFilter", "removeImport", "removeItem", "removeListener", "removeNamedItem", "removeNamedItemNS", "removeNode", "removeParameter", "removeProperty", "removeRange", "removeRegion", "removeRule", "removeSiteSpecificTrackingException", "removeSourceBuffer", "removeStream", "removeTrack", "removeVariable", "removeWakeLockListener", "removeWebWideTrackingException", "removedNodes", "renderbufferStorage", "renderedBuffer", "renderingMode", "repeat", "replace", "replaceAdjacentText", "replaceChild", "replaceData", "replaceId", "replaceItem", "replaceNode", "replaceState", "replaceTrack", "replaceWholeText", "reportValidity", "requestAnimationFrame", "requestAutocomplete", "requestData", "requestFullscreen", "requestMediaKeySystemAccess", "requestPermission", "requestPointerLock", "requestStart", "requestingWindow", "required", "requiredExtensions", "requiredFeatures", "reset", "resetTransform", "resize", "resizeBy", "resizeTo", "resolve", "response", "responseBody", "responseEnd", "responseStart", "responseText", "responseType", "responseURL", "responseXML", "restore", "result", "resultType", "resume", "returnValue", "rev", "reverse", "reversed", "revocable", "revokeObjectURL", "rgbColor", "right", "rightContext", "rightMargin", "rolloffFactor", "root", "rootElement", "rotate", "rotateAxisAngle", "rotateAxisAngleSelf", "rotateFromVector", "rotateFromVectorSelf", "rotateSelf", "rotation", "rotationRate", "round", "rowIndex", "rowSpan", "rows", "rubyAlign", "rubyOverhang", "rubyPosition", "rules", "runtime", "runtimeStyle", "rx", "ry", "safari", "sampleCoverage", "sampleRate", "sandbox", "save", "scale", "scale3d", "scale3dSelf", "scaleNonUniform", "scaleNonUniformSelf", "scaleSelf", "scheme", "scissor", "scope", "scopeName", "scoped", "screen", "screenBrightness", "screenEnabled", "screenLeft", "screenPixelToMillimeterX", "screenPixelToMillimeterY", "screenTop", "screenX", "screenY", "scripts", "scroll", "scroll-behavior", "scrollAmount", "scrollBehavior", "scrollBy", "scrollByLines", "scrollByPages", "scrollDelay", "scrollHeight", "scrollIntoView", "scrollIntoViewIfNeeded", "scrollLeft", "scrollLeftMax", "scrollMaxX", "scrollMaxY", "scrollTo", "scrollTop", "scrollTopMax", "scrollWidth", "scrollX", "scrollY", "scrollbar3dLightColor", "scrollbarArrowColor", "scrollbarBaseColor", "scrollbarDarkShadowColor", "scrollbarFaceColor", "scrollbarHighlightColor", "scrollbarShadowColor", "scrollbarTrackColor", "scrollbars", "scrolling", "sdp", "sdpMLineIndex", "sdpMid", "seal", "search", "searchBox", "searchBoxJavaBridge_", "searchParams", "sectionRowIndex", "secureConnectionStart", "security", "seed", "seekable", "seeking", "select", "selectAllChildren", "selectNode", "selectNodeContents", "selectNodes", "selectSingleNode", "selectSubString", "selected", "selectedIndex", "selectedOptions", "selectedStyleSheetSet", "selectedStylesheetSet", "selection", "selectionDirection", "selectionEnd", "selectionStart", "selector", "selectorText", "self", "send", "sendAsBinary", "sendBeacon", "sender", "sentTimestamp", "separator", "serializeToString", "serviceWorker", "sessionId", "sessionStorage", "set", "setActive", "setAlpha", "setAttribute", "setAttributeNS", "setAttributeNode", "setAttributeNodeNS", "setBaseAndExtent", "setBingCurrentSearchDefault", "setCapture", "setColor", "setCompositeOperation", "setCurrentTime", "setCustomValidity", "setData", "setDate", "setDragImage", "setEnd", "setEndAfter", "setEndBefore", "setEndPoint", "setFillColor", "setFilterRes", "setFloat32", "setFloat64", "setFloatValue", "setFullYear", "setHours", "setImmediate", "setInt16", "setInt32", "setInt8", "setInterval", "setItem", "setLineCap", "setLineDash", "setLineJoin", "setLineWidth", "setLocalDescription", "setMatrix", "setMatrixValue", "setMediaKeys", "setMilliseconds", "setMinutes", "setMiterLimit", "setMonth", "setNamedItem", "setNamedItemNS", "setNonUserCodeExceptions", "setOrientToAngle", "setOrientToAuto", "setOrientation", "setOverrideHistoryNavigationMode", "setPaint", "setParameter", "setPeriodicWave", "setPointerCapture", "setPosition", "setPreference", "setProperty", "setPrototypeOf", "setRGBColor", "setRGBColorICCColor", "setRadius", "setRangeText", "setRemoteDescription", "setRequestHeader", "setResizable", "setResourceTimingBufferSize", "setRotate", "setScale", "setSeconds", "setSelectionRange", "setServerCertificate", "setShadow", "setSkewX", "setSkewY", "setStart", "setStartAfter", "setStartBefore", "setStdDeviation", "setStringValue", "setStrokeColor", "setSuggestResult", "setTargetAtTime", "setTargetValueAtTime", "setTime", "setTimeout", "setTransform", "setTranslate", "setUTCDate", "setUTCFullYear", "setUTCHours", "setUTCMilliseconds", "setUTCMinutes", "setUTCMonth", "setUTCSeconds", "setUint16", "setUint32", "setUint8", "setUri", "setValueAtTime", "setValueCurveAtTime", "setVariable", "setVelocity", "setVersion", "setYear", "settingName", "settingValue", "sex", "shaderSource", "shadowBlur", "shadowColor", "shadowOffsetX", "shadowOffsetY", "shadowRoot", "shape", "shape-rendering", "shapeRendering", "sheet", "shift", "shiftKey", "shiftLeft", "show", "showHelp", "showModal", "showModalDialog", "showModelessDialog", "showNotification", "sidebar", "sign", "signalingState", "sin", "singleNodeValue", "sinh", "size", "sizeToContent", "sizes", "skewX", "skewXSelf", "skewY", "skewYSelf", "slice", "slope", "small", "smooth", "smil", "smoothingTimeConstant", "snapToLines", "snapshotItem", "snapshotLength", "some", "sort", "source", "sourceBuffer", "sourceBuffers", "sourceIndex", "spacing", "span", "speakAs", "speaking", "specified", "specularConstant", "specularExponent", "speechSynthesis", "speed", "speedOfSound", "spellcheck", "splice", "split", "splitText", "spreadMethod", "sqrt", "src", "srcElement", "srcFilter", "srcUrn", "srcdoc", "srclang", "srcset", "stack", "stackTraceLimit", "stacktrace", "standalone", "standby", "start", "startContainer", "startIce", "startOffset", "startRendering", "startTime", "startsWith", "state", "status", "statusMessage", "statusText", "statusbar", "stdDeviationX", "stdDeviationY", "stencilFunc", "stencilFuncSeparate", "stencilMask", "stencilMaskSeparate", "stencilOp", "stencilOpSeparate", "step", "stepDown", "stepMismatch", "stepUp", "sticky", "stitchTiles", "stop", "stop-color", "stop-opacity", "stopColor", "stopImmediatePropagation", "stopOpacity", "stopPropagation", "storageArea", "storageName", "storageStatus", "storeSiteSpecificTrackingException", "storeWebWideTrackingException", "stpVersion", "stream", "strike", "stringValue", "stringify", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "strokeDasharray", "strokeDashoffset", "strokeLinecap", "strokeLinejoin", "strokeMiterlimit", "strokeOpacity", "strokeRect", "strokeStyle", "strokeText", "strokeWidth", "style", "styleFloat", "styleMedia", "styleSheet", "styleSheetSets", "styleSheets", "sub", "subarray", "subject", "submit", "subscribe", "substr", "substring", "substringData", "subtle", "subtree", "suffix", "suffixes", "summary", "sup", "supports", "surfaceScale", "surroundContents", "suspend", "suspendRedraw", "swapCache", "swapNode", "sweepFlag", "symbols", "system", "systemCode", "systemId", "systemLanguage", "systemXDPI", "systemYDPI", "tBodies", "tFoot", "tHead", "tabIndex", "table", "table-layout", "tableLayout", "tableValues", "tag", "tagName", "tagUrn", "tags", "taintEnabled", "takeRecords", "tan", "tanh", "target", "targetElement", "targetTouches", "targetX", "targetY", "tel", "terminate", "test", "texImage2D", "texParameterf", "texParameteri", "texSubImage2D", "text", "text-align", "text-anchor", "text-decoration", "text-decoration-color", "text-decoration-line", "text-decoration-style", "text-indent", "text-overflow", "text-rendering", "text-shadow", "text-transform", "textAlign", "textAlignLast", "textAnchor", "textAutospace", "textBaseline", "textContent", "textDecoration", "textDecorationBlink", "textDecorationColor", "textDecorationLine", "textDecorationLineThrough", "textDecorationNone", "textDecorationOverline", "textDecorationStyle", "textDecorationUnderline", "textIndent", "textJustify", "textJustifyTrim", "textKashida", "textKashidaSpace", "textLength", "textOverflow", "textRendering", "textShadow", "textTracks", "textTransform", "textUnderlinePosition", "then", "threadId", "threshold", "tiltX", "tiltY", "time", "timeEnd", "timeStamp", "timeout", "timestamp", "timestampOffset", "timing", "title", "toArray", "toBlob", "toDataURL", "toDateString", "toElement", "toExponential", "toFixed", "toFloat32Array", "toFloat64Array", "toGMTString", "toISOString", "toJSON", "toLocaleDateString", "toLocaleFormat", "toLocaleLowerCase", "toLocaleString", "toLocaleTimeString", "toLocaleUpperCase", "toLowerCase", "toMethod", "toPrecision", "toSdp", "toSource", "toStaticHTML", "toString", "toStringTag", "toTimeString", "toUTCString", "toUpperCase", "toggle", "toggleLongPressEnabled", "tooLong", "toolbar", "top", "topMargin", "total", "totalFrameDelay", "totalVideoFrames", "touchAction", "touches", "trace", "track", "transaction", "transactions", "transform", "transform-origin", "transform-style", "transformOrigin", "transformPoint", "transformString", "transformStyle", "transformToDocument", "transformToFragment", "transition", "transition-delay", "transition-duration", "transition-property", "transition-timing-function", "transitionDelay", "transitionDuration", "transitionProperty", "transitionTimingFunction", "translate", "translateSelf", "translationX", "translationY", "trim", "trimLeft", "trimRight", "trueSpeed", "trunc", "truncate", "type", "typeDetail", "typeMismatch", "typeMustMatch", "types", "ubound", "undefined", "unescape", "uneval", "unicode-bidi", "unicodeBidi", "uniform1f", "uniform1fv", "uniform1i", "uniform1iv", "uniform2f", "uniform2fv", "uniform2i", "uniform2iv", "uniform3f", "uniform3fv", "uniform3i", "uniform3iv", "uniform4f", "uniform4fv", "uniform4i", "uniform4iv", "uniformMatrix2fv", "uniformMatrix3fv", "uniformMatrix4fv", "unique", "uniqueID", "uniqueNumber", "unitType", "units", "unloadEventEnd", "unloadEventStart", "unlock", "unmount", "unobserve", "unpause", "unpauseAnimations", "unreadCount", "unregister", "unregisterContentHandler", "unregisterProtocolHandler", "unscopables", "unselectable", "unshift", "unsubscribe", "unsuspendRedraw", "unsuspendRedrawAll", "unwatch", "unwrapKey", "update", "updateCommands", "updateIce", "updateInterval", "updateSettings", "updated", "updating", "upload", "upper", "upperBound", "upperOpen", "uri", "url", "urn", "urns", "usages", "useCurrentView", "useMap", "useProgram", "usedSpace", "userAgent", "userLanguage", "username", "v8BreakIterator", "vAlign", "vLink", "valid", "validateProgram", "validationMessage", "validity", "value", "valueAsDate", "valueAsNumber", "valueAsString", "valueInSpecifiedUnits", "valueMissing", "valueOf", "valueText", "valueType", "values", "vector-effect", "vectorEffect", "velocityAngular", "velocityExpansion", "velocityX", "velocityY", "vendor", "vendorSub", "verify", "version", "vertexAttrib1f", "vertexAttrib1fv", "vertexAttrib2f", "vertexAttrib2fv", "vertexAttrib3f", "vertexAttrib3fv", "vertexAttrib4f", "vertexAttrib4fv", "vertexAttribDivisorANGLE", "vertexAttribPointer", "vertical", "vertical-align", "verticalAlign", "verticalOverflow", "vibrate", "videoHeight", "videoTracks", "videoWidth", "view", "viewBox", "viewBoxString", "viewTarget", "viewTargetString", "viewport", "viewportAnchorX", "viewportAnchorY", "viewportElement", "visibility", "visibilityState", "visible", "vlinkColor", "voice", "volume", "vrml", "vspace", "w", "wand", "warn", "wasClean", "watch", "watchPosition", "webdriver", "webkitAddKey", "webkitAnimation", "webkitAnimationDelay", "webkitAnimationDirection", "webkitAnimationDuration", "webkitAnimationFillMode", "webkitAnimationIterationCount", "webkitAnimationName", "webkitAnimationPlayState", "webkitAnimationTimingFunction", "webkitAppearance", "webkitAudioContext", "webkitAudioDecodedByteCount", "webkitAudioPannerNode", "webkitBackfaceVisibility", "webkitBackground", "webkitBackgroundAttachment", "webkitBackgroundClip", "webkitBackgroundColor", "webkitBackgroundImage", "webkitBackgroundOrigin", "webkitBackgroundPosition", "webkitBackgroundPositionX", "webkitBackgroundPositionY", "webkitBackgroundRepeat", "webkitBackgroundSize", "webkitBackingStorePixelRatio", "webkitBorderImage", "webkitBorderImageOutset", "webkitBorderImageRepeat", "webkitBorderImageSlice", "webkitBorderImageSource", "webkitBorderImageWidth", "webkitBoxAlign", "webkitBoxDirection", "webkitBoxFlex", "webkitBoxOrdinalGroup", "webkitBoxOrient", "webkitBoxPack", "webkitBoxSizing", "webkitCancelAnimationFrame", "webkitCancelFullScreen", "webkitCancelKeyRequest", "webkitCancelRequestAnimationFrame", "webkitClearResourceTimings", "webkitClosedCaptionsVisible", "webkitConvertPointFromNodeToPage", "webkitConvertPointFromPageToNode", "webkitCreateShadowRoot", "webkitCurrentFullScreenElement", "webkitCurrentPlaybackTargetIsWireless", "webkitDirectionInvertedFromDevice", "webkitDisplayingFullscreen", "webkitEnterFullScreen", "webkitEnterFullscreen", "webkitExitFullScreen", "webkitExitFullscreen", "webkitExitPointerLock", "webkitFullScreenKeyboardInputAllowed", "webkitFullscreenElement", "webkitFullscreenEnabled", "webkitGenerateKeyRequest", "webkitGetAsEntry", "webkitGetDatabaseNames", "webkitGetEntries", "webkitGetEntriesByName", "webkitGetEntriesByType", "webkitGetFlowByName", "webkitGetGamepads", "webkitGetImageDataHD", "webkitGetNamedFlows", "webkitGetRegionFlowRanges", "webkitGetUserMedia", "webkitHasClosedCaptions", "webkitHidden", "webkitIDBCursor", "webkitIDBDatabase", "webkitIDBDatabaseError", "webkitIDBDatabaseException", "webkitIDBFactory", "webkitIDBIndex", "webkitIDBKeyRange", "webkitIDBObjectStore", "webkitIDBRequest", "webkitIDBTransaction", "webkitImageSmoothingEnabled", "webkitIndexedDB", "webkitInitMessageEvent", "webkitIsFullScreen", "webkitKeys", "webkitLineDashOffset", "webkitLockOrientation", "webkitMatchesSelector", "webkitMediaStream", "webkitNotifications", "webkitOfflineAudioContext", "webkitOrientation", "webkitPeerConnection00", "webkitPersistentStorage", "webkitPointerLockElement", "webkitPostMessage", "webkitPreservesPitch", "webkitPutImageDataHD", "webkitRTCPeerConnection", "webkitRegionOverset", "webkitRequestAnimationFrame", "webkitRequestFileSystem", "webkitRequestFullScreen", "webkitRequestFullscreen", "webkitRequestPointerLock", "webkitResolveLocalFileSystemURL", "webkitSetMediaKeys", "webkitSetResourceTimingBufferSize", "webkitShadowRoot", "webkitShowPlaybackTargetPicker", "webkitSlice", "webkitSpeechGrammar", "webkitSpeechGrammarList", "webkitSpeechRecognition", "webkitSpeechRecognitionError", "webkitSpeechRecognitionEvent", "webkitStorageInfo", "webkitSupportsFullscreen", "webkitTemporaryStorage", "webkitTextSizeAdjust", "webkitTransform", "webkitTransformOrigin", "webkitTransition", "webkitTransitionDelay", "webkitTransitionDuration", "webkitTransitionProperty", "webkitTransitionTimingFunction", "webkitURL", "webkitUnlockOrientation", "webkitUserSelect", "webkitVideoDecodedByteCount", "webkitVisibilityState", "webkitWirelessVideoPlaybackDisabled", "webkitdropzone", "webstore", "weight", "whatToShow", "wheelDelta", "wheelDeltaX", "wheelDeltaY", "which", "white-space", "whiteSpace", "wholeText", "widows", "width", "will-change", "willChange", "willValidate", "window", "withCredentials", "word-break", "word-spacing", "word-wrap", "wordBreak", "wordSpacing", "wordWrap", "wrap", "wrapKey", "write", "writeln", "writingMode", "x", "x1", "x2", "xChannelSelector", "xmlEncoding", "xmlStandalone", "xmlVersion", "xmlbase", "xmllang", "xmlspace", "y", "y1", "y2", "yChannelSelector", "yandex", "z", "z-index", "zIndex", "zoom", "zoomAndPan", "zoomRectScreen" ] terser-4.1.2/tools/exit.js000066400000000000000000000007251351061312300154700ustar00rootroot00000000000000// workaround for tty output truncation upon process.exit() var exit = process.exit; process.exit = function() { var args = [].slice.call(arguments); process.once("uncaughtException", function() { (function callback() { if (process.stdout.bufferSize || process.stderr.bufferSize) { setImmediate(callback); } else { exit.apply(process, args); } })(); }); throw exit; }; terser-4.1.2/tools/node.js000066400000000000000000000006761351061312300154510ustar00rootroot00000000000000import { minify } from "../lib/minify"; export function default_options() { const defs = {}; Object.keys(infer_options({ 0: 0 })).forEach((component) => { const options = infer_options({ [component]: {0: 0} }); if (options) defs[component] = options; }); return defs; } function infer_options(options) { var result = minify("", options); return result.error && result.error.defs; } terser-4.1.2/tools/props.html000066400000000000000000000027001351061312300162050ustar00rootroot00000000000000 terser-4.1.2/tools/terser.d.ts000066400000000000000000000444001351061312300162550ustar00rootroot00000000000000/// import { RawSourceMap } from 'source-map'; export type ECMA = 5 | 6 | 7 | 8 | 9; export interface ParseOptions { bare_returns?: boolean; ecma?: ECMA; html5_comments?: boolean; shebang?: boolean; } export interface CompressOptions { arguments?: boolean; arrows?: boolean; booleans?: boolean; collapse_vars?: boolean; comparisons?: boolean; computed_props?: boolean; conditionals?: boolean; dead_code?: boolean; defaults?: boolean; directives?: boolean; drop_console?: boolean; drop_debugger?: boolean; ecma?: ECMA; evaluate?: boolean; expression?: boolean; global_defs?: object; hoist_funs?: boolean; hoist_props?: boolean; hoist_vars?: boolean; if_return?: boolean; inline?: boolean | InlineFunctions; join_vars?: boolean; keep_classnames?: boolean | RegExp; keep_fargs?: boolean; keep_fnames?: boolean | RegExp; keep_infinity?: boolean; loops?: boolean; module?: boolean; negate_iife?: boolean; passes?: number; properties?: boolean; pure_funcs?: string[]; pure_getters?: boolean | 'strict'; reduce_funcs?: boolean; reduce_vars?: boolean; sequences?: boolean | number; side_effects?: boolean; switches?: boolean; toplevel?: boolean; top_retain?: null | string | string[] | RegExp; typeofs?: boolean; unsafe?: boolean; unsafe_arrows?: boolean; unsafe_comps?: boolean; unsafe_Function?: boolean; unsafe_math?: boolean; unsafe_methods?: boolean; unsafe_proto?: boolean; unsafe_regexp?: boolean; unsafe_undefined?: boolean; unused?: boolean; warnings?: boolean; } export enum InlineFunctions { Disabled = 0, SimpleFunctions = 1, WithArguments = 2, WithArgumentsAndVariables = 3 } export interface MangleOptions { eval?: boolean; keep_classnames?: boolean | RegExp; keep_fnames?: boolean | RegExp; module?: boolean; properties?: boolean | ManglePropertiesOptions; reserved?: string[]; safari10?: boolean; toplevel?: boolean; } export interface ManglePropertiesOptions { builtins?: boolean; debug?: boolean; keep_quoted?: boolean; regex?: RegExp | string; reserved?: string[]; } export interface OutputOptions { ascii_only?: boolean; beautify?: boolean; braces?: boolean; comments?: boolean | 'all' | 'some' | RegExp; ecma?: ECMA; indent_level?: number; indent_start?: boolean; inline_script?: boolean; ie8?: boolean; keep_quoted_props?: boolean; max_line_len?: boolean; preamble?: string; quote_keys?: boolean; quote_style?: OutputQuoteStyle; safari10?: boolean; semicolons?: boolean; shebang?: boolean; shorthand?: boolean; source_map?: SourceMapOptions; webkit?: boolean; width?: number; wrap_iife?: boolean; } export enum OutputQuoteStyle { PreferDouble = 0, AlwaysSingle = 1, AlwaysDouble = 2, AlwaysOriginal = 3 } export interface MinifyOptions { compress?: boolean | CompressOptions; ecma?: ECMA; ie8?: boolean; keep_classnames?: boolean | RegExp; keep_fnames?: boolean | RegExp; mangle?: boolean | MangleOptions; module?: boolean; nameCache?: object; output?: OutputOptions; parse?: ParseOptions; safari10?: boolean; sourceMap?: boolean | SourceMapOptions; toplevel?: boolean; warnings?: boolean | 'verbose'; } export interface MinifyOutput { ast?: AST_Node; code?: string; error?: Error; map?: string; warnings?: string[]; } export interface SourceMapOptions { content?: RawSourceMap; includeSources?: boolean; filename?: string; root?: string; url?: string | 'inline'; } declare function parse(text: string, options?: ParseOptions): AST_Node; export class TreeWalker { constructor(callback: (node: AST_Node, descend?: (node: AST_Node) => void) => boolean | undefined); directives: object; find_parent(type: AST_Node): AST_Node | undefined; has_directive(type: string): boolean; loopcontrol_target(node: AST_Node): AST_Node | undefined; parent(n: number): AST_Node | undefined; pop(): void; push(node: AST_Node): void; self(): AST_Node | undefined; stack: AST_Node[]; visit: (node: AST_Node, descend: boolean) => any; } export class TreeTransformer extends TreeWalker { constructor( before: (node: AST_Node, descend?: (node: AST_Node, tw: TreeWalker) => void, in_list?: boolean) => AST_Node | undefined, after?: (node: AST_Node, in_list?: boolean) => AST_Node | undefined ); before: (node: AST_Node) => AST_Node; after?: (node: AST_Node) => AST_Node; } export function push_uniq(array: T[], el: T): void; export function minify(files: string | string[] | { [file: string]: string } | AST_Node, options?: MinifyOptions): MinifyOutput; export class AST_Node { constructor(props?: object); static BASE?: AST_Node; static PROPS: string[]; static SELF_PROPS: string[]; static SUBCLASSES: AST_Node[]; static documentation: string; static propdoc?: Record; static expressions?: AST_Node[]; static warn?: (text: string, props: any) => void; static from_mozilla_ast?: (node: AST_Node) => any; walk: (visitor: TreeWalker) => void; print_to_string: (options?: OutputOptions) => string; transform: (tt: TreeTransformer, in_list?: boolean) => AST_Node; TYPE: string; CTOR: typeof AST_Node; } declare class SymbolDef { constructor(scope?: AST_Scope, orig?: object, init?: object); name: string; orig: AST_SymbolRef[]; init: AST_SymbolRef; eliminated: number; scope: AST_Scope; references: AST_SymbolRef[]; replaced: number; global: boolean; export: boolean; mangled_name: null | string; undeclared: boolean; id: number; } type ArgType = AST_SymbolFunarg | AST_DefaultAssign | AST_Destructuring | AST_Expansion; declare class AST_Statement extends AST_Node { constructor(props?: object); } declare class AST_Debugger extends AST_Statement { constructor(props?: object); } declare class AST_Directive extends AST_Statement { constructor(props?: object); value: string; quote: string; } declare class AST_SimpleStatement extends AST_Statement { constructor(props?: object); body: AST_Node[]; } declare class AST_Block extends AST_Statement { constructor(props?: object); body: AST_Node[]; block_scope: AST_Scope | null; } declare class AST_BlockStatement extends AST_Block { constructor(props?: object); } declare class AST_Scope extends AST_Block { constructor(props?: object); variables: any; functions: any; uses_with: boolean; uses_eval: boolean; parent_scope: AST_Scope | null; enclosed: any; cname: any; } declare class AST_Toplevel extends AST_Scope { constructor(props?: object); globals: any; } declare class AST_Lambda extends AST_Scope { constructor(props?: object); name: AST_SymbolDeclaration | null; argnames: ArgType[]; uses_arguments: boolean; is_generator: boolean; async: boolean; } declare class AST_Accessor extends AST_Lambda { constructor(props?: object); } declare class AST_Function extends AST_Lambda { constructor(props?: object); inlined: boolean; } declare class AST_Arrow extends AST_Lambda { constructor(props?: object); inlined: boolean; } declare class AST_Defun extends AST_Lambda { constructor(props?: object); inlined: boolean; } declare class AST_Class extends AST_Scope { constructor(props?: object); name: AST_SymbolClass | AST_SymbolDefClass | null; extends: AST_Node | null; properties: AST_ObjectProperty[]; inlined: boolean; } declare class AST_DefClass extends AST_Class { constructor(props?: object); } declare class AST_ClassExpression extends AST_Class { constructor(props?: object); } declare class AST_Switch extends AST_Block { constructor(props?: object); expression: AST_Node; } declare class AST_SwitchBranch extends AST_Block { constructor(props?: object); } declare class AST_Default extends AST_SwitchBranch { constructor(props?: object); } declare class AST_Case extends AST_SwitchBranch { constructor(props?: object); expression: AST_Node; } declare class AST_Try extends AST_Block { constructor(props?: object); bcatch: AST_Catch; bfinally: null | AST_Finally; } declare class AST_Catch extends AST_Block { constructor(props?: object); argname: ArgType; } declare class AST_Finally extends AST_Block { constructor(props?: object); } declare class AST_EmptyStatement extends AST_Statement { constructor(props?: object); } declare class AST_StatementWithBody extends AST_Statement { constructor(props?: object); body: AST_Node[]; } declare class AST_LabeledStatement extends AST_StatementWithBody { constructor(props?: object); label: AST_Label; } declare class AST_IterationStatement extends AST_StatementWithBody { constructor(props?: object); block_scope: AST_Scope | null; } declare class AST_DWLoop extends AST_IterationStatement { constructor(props?: object); condition: AST_Node; } declare class AST_Do extends AST_DWLoop { constructor(props?: object); } declare class AST_While extends AST_DWLoop { constructor(props?: object); } declare class AST_For extends AST_IterationStatement { constructor(props?: object); init: AST_Node | null; condition: AST_Node | null; step: AST_Node | null; } declare class AST_ForIn extends AST_IterationStatement { constructor(props?: object); init: AST_Node | null; object: AST_Node; } declare class AST_ForOf extends AST_ForIn { constructor(props?: object); await: boolean; } declare class AST_With extends AST_StatementWithBody { constructor(props?: object); expression: AST_Node; } declare class AST_If extends AST_StatementWithBody { constructor(props?: object); condition: AST_Node; alternative: AST_Node | null; } declare class AST_Jump extends AST_Statement { constructor(props?: object); } declare class AST_Exit extends AST_Jump { constructor(props?: object); value: AST_Node | null; } declare class AST_Return extends AST_Exit { constructor(props?: object); } declare class AST_Throw extends AST_Exit { constructor(props?: object); } declare class AST_LoopControl extends AST_Jump { constructor(props?: object); label: null | AST_LabelRef; } declare class AST_Break extends AST_LoopControl { constructor(props?: object); } declare class AST_Continue extends AST_LoopControl { constructor(props?: object); } declare class AST_Definitions extends AST_Statement { constructor(props?: object); definitions: AST_VarDef[]; } declare class AST_Var extends AST_Definitions { constructor(props?: object); } declare class AST_Let extends AST_Definitions { constructor(props?: object); } declare class AST_Const extends AST_Definitions { constructor(props?: object); } declare class AST_Export extends AST_Statement { constructor(props?: object); exported_definition: AST_Definitions | AST_Lambda | AST_DefClass | null; exported_value: AST_Node | null; is_default: boolean; exported_names: AST_NameMapping[]; module_name: AST_String; } declare class AST_Expansion extends AST_Node { constructor(props?: object); expression: AST_Node; } declare class AST_Destructuring extends AST_Node { constructor(props?: object); names: AST_Node[]; is_array: boolean; } declare class AST_PrefixedTemplateString extends AST_Node { constructor(props?: object); template_string: AST_TemplateString; prefix: AST_Node; } declare class AST_TemplateString extends AST_Node { constructor(props?: object); segments: AST_Node[]; } declare class AST_TemplateSegment extends AST_Node { constructor(props?: object); value: string; raw: string; } declare class AST_NameMapping extends AST_Node { constructor(props?: object); foreign_name: AST_Symbol; name: AST_SymbolExport | AST_SymbolImport; } declare class AST_Import extends AST_Node { constructor(props?: object); imported_name: null | AST_SymbolImport; imported_names: AST_NameMapping[]; module_name: AST_String; } declare class AST_VarDef extends AST_Node { constructor(props?: object); name: AST_Destructuring | AST_SymbolConst | AST_SymbolLet | AST_SymbolVar; value: AST_Node | null; } declare class AST_Call extends AST_Node { constructor(props?: object); expression: AST_Node; args: AST_Node[]; } declare class AST_New extends AST_Call { constructor(props?: object); } declare class AST_Sequence extends AST_Node { constructor(props?: object); expressions: AST_Node[]; } declare class AST_PropAccess extends AST_Node { constructor(props?: object); expression: AST_Node; property: AST_Node | string; } declare class AST_Dot extends AST_PropAccess { constructor(props?: object); } declare class AST_Sub extends AST_PropAccess { constructor(props?: object); } declare class AST_Unary extends AST_Node { constructor(props?: object); operator: string; expression: AST_Node; } declare class AST_UnaryPrefix extends AST_Unary { constructor(props?: object); } declare class AST_UnaryPostfix extends AST_Unary { constructor(props?: object); } declare class AST_Binary extends AST_Node { constructor(props?: object); operator: string; left: AST_Node; right: AST_Node; } declare class AST_Assign extends AST_Binary { constructor(props?: object); } declare class AST_DefaultAssign extends AST_Binary { constructor(props?: object); } declare class AST_Conditional extends AST_Node { constructor(props?: object); condition: AST_Node; consequent: AST_Node; alternative: AST_Node; } declare class AST_Array extends AST_Node { constructor(props?: object); elements: AST_Node[]; } declare class AST_Object extends AST_Node { constructor(props?: object); properties: AST_ObjectProperty[]; } declare class AST_ObjectProperty extends AST_Node { constructor(props?: object); key: string | number | AST_Node; value: AST_Node; } declare class AST_ObjectKeyVal extends AST_ObjectProperty { constructor(props?: object); quote: string; } declare class AST_ObjectSetter extends AST_ObjectProperty { constructor(props?: object); quote: string; static: boolean; } declare class AST_ObjectGetter extends AST_ObjectProperty { constructor(props?: object); quote: string; static: boolean; } declare class AST_ConciseMethod extends AST_ObjectProperty { constructor(props?: object); quote: string; static: boolean; is_generator: boolean; async: boolean; } declare class AST_Symbol extends AST_Node { constructor(props?: object); scope: AST_Scope; name: string; thedef: SymbolDef; } declare class AST_SymbolDeclaration extends AST_Symbol { constructor(props?: object); init: AST_Node | null; } declare class AST_SymbolVar extends AST_SymbolDeclaration { constructor(props?: object); } declare class AST_SymbolFunarg extends AST_SymbolVar { constructor(props?: object); } declare class AST_SymbolBlockDeclaration extends AST_SymbolDeclaration { constructor(props?: object); } declare class AST_SymbolConst extends AST_SymbolBlockDeclaration { constructor(props?: object); } declare class AST_SymbolLet extends AST_SymbolBlockDeclaration { constructor(props?: object); } declare class AST_SymbolDefClass extends AST_SymbolBlockDeclaration { constructor(props?: object); } declare class AST_SymbolCatch extends AST_SymbolBlockDeclaration { constructor(props?: object); } declare class AST_SymbolImport extends AST_SymbolBlockDeclaration { constructor(props?: object); } declare class AST_SymbolDefun extends AST_SymbolDeclaration { constructor(props?: object); } declare class AST_SymbolLambda extends AST_SymbolDeclaration { constructor(props?: object); } declare class AST_SymbolClass extends AST_SymbolDeclaration { constructor(props?: object); } declare class AST_SymbolMethod extends AST_Symbol { constructor(props?: object); } declare class AST_SymbolImportForeign extends AST_Symbol { constructor(props?: object); } declare class AST_Label extends AST_Symbol { constructor(props?: object); references: AST_LoopControl | null; } declare class AST_SymbolRef extends AST_Symbol { constructor(props?: object); } declare class AST_SymbolExport extends AST_SymbolRef { constructor(props?: object); } declare class AST_SymbolExportForeign extends AST_Symbol { constructor(props?: object); } declare class AST_LabelRef extends AST_Symbol { constructor(props?: object); } declare class AST_This extends AST_Symbol { constructor(props?: object); } declare class AST_Super extends AST_This { constructor(props?: object); } declare class AST_NewTarget extends AST_Node { constructor(props?: object); } declare class AST_Constant extends AST_Node { constructor(props?: object); } declare class AST_String extends AST_Constant { constructor(props?: object); value: string; quote: string; } declare class AST_Number extends AST_Constant { constructor(props?: object); value: number; literal: string; } declare class AST_RegExp extends AST_Constant { constructor(props?: object); value: RegExp; } declare class AST_Atom extends AST_Constant { constructor(props?: object); } declare class AST_Null extends AST_Atom { constructor(props?: object); } declare class AST_NaN extends AST_Atom { constructor(props?: object); } declare class AST_Undefined extends AST_Atom { constructor(props?: object); } declare class AST_Hole extends AST_Atom { constructor(props?: object); } declare class AST_Infinity extends AST_Atom { constructor(props?: object); } declare class AST_Boolean extends AST_Atom { constructor(props?: object); } declare class AST_False extends AST_Boolean { constructor(props?: object); } declare class AST_True extends AST_Boolean { constructor(props?: object); } declare class AST_Await extends AST_Node { constructor(props?: object); expression: AST_Node; } declare class AST_Yield extends AST_Node { constructor(props?: object); expression: AST_Node; is_star: boolean; }