pax_global_header00006660000000000000000000000064144564721760014532gustar00rootroot0000000000000052 comment=8f220355859aa0dfa49cce2ed8ac2c3bf907f8a5 terser-5.19.2/000077500000000000000000000000001445647217600131345ustar00rootroot00000000000000terser-5.19.2/.editorconfig000066400000000000000000000003351445647217600156120ustar00rootroot00000000000000# 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-5.19.2/.gitattributes000066400000000000000000000000241445647217600160230ustar00rootroot00000000000000*.js text eol=lf terser-5.19.2/.github/000077500000000000000000000000001445647217600144745ustar00rootroot00000000000000terser-5.19.2/.github/FUNDING.yml000066400000000000000000000000301445647217600163020ustar00rootroot00000000000000open_collective: terser terser-5.19.2/.github/ISSUE_TEMPLATE.md000066400000000000000000000015731445647217600172070ustar00rootroot00000000000000 **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-5.19.2/.github/workflows/000077500000000000000000000000001445647217600165315ustar00rootroot00000000000000terser-5.19.2/.github/workflows/ci.yml000066400000000000000000000034421445647217600176520ustar00rootroot00000000000000name: CI pipeline on: push: branches: [master] pull_request: permissions: read-all jobs: build: name: "Build ${{ matrix.os }} node${{ matrix.node-version }}" runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [ ubuntu-latest, windows-latest ] node-version: [ 10.x, 12.x, 14.x, 16.x, 20.x ] steps: - name: Checkout repository uses: actions/checkout@v3 # Tooling setup - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} # Build and test validation - name: Install dependencies run: | npm ci - name: Build the app run: | npm run build --if-present - if: matrix.node-version != '10.x' name: Run compress tests run: | npm run test:compress - if: matrix.node-version != '10.x' name: Run mocha tests env: TERSER_TEST_ALL: 1 run: | npm run test:mocha -- --timeout 80000 # Tests for node 10 - if: matrix.node-version == '10.x' name: Run compress tests (Node 10.x only) run: | node --require esm test/compress.js - if: matrix.node-version == '10.x' name: Run mocha tests (Node 10.x only) run: | npm run test:mocha -- --require esm --timeout 80000 # Functional tests - if: matrix.os == 'ubuntu-latest' && matrix.node-version == '16.x' name: Run functional tests (Ubuntu Node 16.x only) run: | ./test/functional.sh # Fuzz tests - if: matrix.node-version == '20.x' name: Run fuzz tests (Node 20.x only) run: | node ./test/ufuzz.js 1000 --seed 1234 terser-5.19.2/.gitignore000066400000000000000000000001011445647217600151140ustar00rootroot00000000000000/.idea/ /node_modules/ /npm-debug.log tmp/ dist/ coverage/ .tmp/ terser-5.19.2/.ls-lint.yml000066400000000000000000000003561445647217600153230ustar00rootroot00000000000000ls: '{lib,tools,test}': .js: kebab-case .ts: kebab-case .d.ts: kebab-case .html: kebab-case .json: kebab-case ignore: - test/input - test/compress - lib/utils/first_in_statement.js terser-5.19.2/CHANGELOG.md000066400000000000000000000641101445647217600147470ustar00rootroot00000000000000# Changelog ## v5.19.2 - fix performance hit from avoiding HTML comments in the output ## v5.19.1 - Better avoid outputting `` and HTML comments. - Fix unused variables in class static blocks not being dropped correctly. - Fix sourcemap names of methods that are `async` or `static` ## v5.19.0 - Allow `/*@__MANGLE_PROP__*/` annotation in `object.property`, in addition to property declarations. ## v5.18.2 - Stop using recursion in hoisted defuns fix. ## v5.18.1 - Fix major performance issue caused by hoisted defuns' scopes bugfix. ## v5.18.0 - Add new `/*@__MANGLE_PROP__*/` annotation, to mark properties that should be mangled. ## v5.17.7 - Update some dependencies - Add consistent sorting for `v` RegExp flag - Add `inert` DOM attribute to domprops ## v5.17.6 - Fixes to mozilla AST input and output, for class properties, private properties and static blocks - Fix outputting a shorthand property in quotes when safari10 and ecma=2015 options are enabled - `configurable` and `enumerable`, used in Object.defineProperty, added to domprops (#1393) ## v5.17.5 - Take into account the non-deferred bits of a class, such as static properties, while dropping unused code. ## v5.17.4 - Fix crash when trying to negate a class (`!class{}`) - Avoid outputting comments between `yield`/`await` and its argument - Fix detection of left-hand-side of assignment, to avoid optimizing it like any other expression in some edge cases ## v5.17.3 - Fix issue with trimming a static class property's contents accessing the class as `this`. ## v5.17.2 - Be less conservative when detecting use-before-definition of `var` in hoisted functions. - Support unusual (but perfectly valid) initializers of for-in and for-of loops. - Fix issue where hoisted function would be dropped if it was after a `continue` statement ## v5.17.1 - Fix evaluating `.length` when the source array might've been mutated ## v5.17.0 - Drop vestigial `= undefined` default argument in IIFE calls (#1366) - Evaluate known arrays' `.length` property when statically determinable - Add `@__KEY__` annotation to mangle string literals (#1365) ## v5.16.9 - Fix parentheses in output of optional chains (`a?.b`) (#1374) - More documentation on source maps (#1368) - New `lhs_constants` option, allowing to stop Terser from swapping comparison operands (#1361) ## v5.16.8 - Become even less conservative around function definitions for `reduce_vars` - Fix parsing context of `import.meta` expressions such that method calls are allowed ## v5.16.6 - Become less conservative with analyzing function definitions for `reduce_vars` - Parse `import.meta` as a real AST node and not an `object.property` ## v5.16.5 - Correctly handle AST transform functions that mutate children arrays - Don't mutate the options object passed to Terser (#1342) - Do not treat BigInt like a number ## v5.16.4 - Keep `(defaultArg = undefined) => ...`, because default args don't count for function length - Prevent inlining variables into `?.` optional chains - Avoid removing unused arguments while transforming - Optimize iterating AST node lists - Make sure `catch` and `finally` aren't children of `try` in the AST - Use modern unicode property escapes (`\p{...}`) to parse identifiers when available ## v5.16.3 - Ensure function definitions, don't assume the values of variables defined after them. ## v5.16.2 - Fix sourcemaps with non-ascii characters (#1318) - Support string module name and export * as (#1336) - Do not move `let` out of `for` initializers, as it can change scoping - Fix a corner case that would generate the invalid syntax `if (something) let x` ("let" in braceless if body) - Knowledge of more native object properties (#1330) - Got rid of Travis (#1323) - Added semi-secret `asObject` sourcemap option to typescript defs (#1321) ## v5.16.1 - Properly handle references in destructurings (`const { [reference]: val } = ...`) - Allow parsing of `.#privatefield` in nested classes - Do not evaluate operations that return large strings if that would make the output code larger - Make `collapse_vars` handle block scope correctly - Internal improvements: Typos (#1311), more tests, small-scale refactoring ## v5.16.0 - Disallow private fields in object bodies (#1011) - Parse `#privatefield in object` (#1279) - Compress `#privatefield in object` ## v5.15.1 - Fixed missing parentheses around optional chains - Avoid bare `let` or `const` as the bodies of `if` statements (#1253) - Small internal fixes (#1271) - Avoid inlining a class twice and creating two equivalent but `!==` classes. ## v5.15.0 - Basic support for ES2022 class static initializer blocks. - Add `AudioWorkletNode` constructor options to domprops list (#1230) - Make identity function inliner not inline `id(...expandedArgs)` ## v5.14.2 - Security fix for RegExps that should not be evaluated (regexp DDOS) - Source maps improvements (#1211) - Performance improvements in long property access evaluation (#1213) ## v5.14.1 - keep_numbers option added to TypeScript defs (#1208) - Fixed parsing of nested template strings (#1204) ## v5.14.0 - Switched to @jridgewell/source-map for sourcemap generation (#1190, #1181) - Fixed source maps with non-terminated segments (#1106) - Enabled typescript types to be imported from the package (#1194) - Extra DOM props have been added (#1191) - Delete the AST while generating code, as a means to save RAM ## v5.13.1 - Removed self-assignments (`varname=varname`) (closes #1081) - Separated inlining code (for inlining things into references, or removing IIFEs) - Allow multiple identifiers with the same name in `var` destructuring (eg `var { a, a } = x`) (#1176) ## v5.13.0 - All calls to eval() were removed (#1171, #1184) - `source-map` was updated to 0.8.0-beta.0 (#1164) - NavigatorUAData was added to domprops to avoid property mangling (#1166) ## v5.12.1 - Fixed an issue with function definitions inside blocks (#1155) - Fixed parens of `new` in some situations (closes #1159) ## v5.12.0 - `TERSER_DEBUG_DIR` environment variable - @copyright comments are now preserved with the comments="some" option (#1153) ## v5.11.0 - Unicode code point escapes (`\u{abcde}`) are not emitted inside RegExp literals anymore (#1147) - acorn is now a regular dependency ## v5.10.0 - Massive optimization to max_line_len (#1109) - Basic support for import assertions - Marked ES2022 Object.hasOwn as a pure function - Fix `delete optional?.property` - New CI/CD pipeline with github actions (#1057) - Fix reordering of switch branches (#1092), (#1084) - Fix error when creating a class property called `get` - Acorn dependency is now an optional peerDependency - Fix mangling collision with exported variables (#1072) - Fix an issue with `return someVariable = (async () => { ... })()` (#1073) ## v5.9.0 - Collapsing switch cases with the same bodies (even if they're not next to each other) (#1070). - Fix evaluation of optional chain expressions (#1062) - Fix mangling collision in ESM exports (#1063) - Fix issue with mutating function objects after a second pass (#1047) - Fix for inlining object spread `{ ...obj }` (#1071) - Typescript typings fix (#1069) ## v5.8.0 - Fixed shadowing variables while moving code in some cases (#1065) - Stop mangling computed & quoted properties when keep_quoted is enabled. - Fix for mangling private getter/setter and .#private access (#1060, #1068) - Array.from has a new optimization when the unsafe option is set (#737) - Mangle/propmangle let you generate your own identifiers through the nth_identifier option (#1061) - More optimizations to switch statements (#1044) ## v5.7.2 - Fixed issues with compressing functions defined in `global_defs` option (#1036) - New recipe for using Terser in gulp was added to RECIPES.md (#1035) - Fixed issues with `??` and `?.` (#1045) - Future reserved words such as `package` no longer require you to disable strict mode to be used as names. - Refactored huge compressor file into multiple more focused files. - Avoided unparenthesized `in` operator in some for loops (it breaks parsing because of for..in loops) - Improved documentation (#1021, #1025) - More type definitions (#1021) ## v5.7.1 - Avoided collapsing assignments together if it would place a chain assignment on the left hand side, which is invalid syntax (`a?.b = c`) - Removed undefined from object expansions (`{ ...void 0 }` -> `{}`) - Fix crash when checking if something is nullish or undefined (#1009) - Fixed comparison of private class properties (#1015) - Minor performance improvements (#993) - Fixed scope of function defs in strict mode (they are block scoped) ## v5.7.0 - Several compile-time evaluation and inlining fixes - Allow `reduce_funcs` to be disabled again. - Add `spidermonkey` options to parse and format (#974) - Accept `{get = "default val"}` and `{set = "default val"}` in destructuring arguments. - Change package.json export map to help require.resolve (#971) - Improve docs - Fix `export default` of an anonymous class with `extends` ## v5.6.1 - Mark assignments to the `.prototype` of a class as pure - Parenthesize `await` on the left of `**` (while accepting legacy non-parenthesised input) - Avoided outputting NUL bytes in optimized RegExps, to stop the output from breaking other tools - Added `exports` to domprops (#939) - Fixed a crash when spreading `...this` - Fixed the computed size of arrow functions, which improves their inlining ## v5.6.0 - Added top-level await - Beautify option has been removed in #895 - Private properties, getters and setters have been added in #913 and some more commits - Docs improvements: #896, #903, #916 ## v5.5.1 - Fixed object properties with unicode surrogates on safari. ## v5.5.0 - Fixed crash when inlining uninitialized variable into template string. - The sourcemap for dist was removed for being too large. ## v5.4.0 - Logical assignment - Change `let x = undefined` to just `let x` - Removed some optimizations for template strings, placing them behind `unsafe` options. Reason: adding strings is not equivalent to template strings, due to valueOf differences. - The AST_Token class was slimmed down in order to use less memory. ## v5.3.8 - Restore node 13 support ## v5.3.7 Hotfix release, fixes package.json "engines" syntax ## v5.3.6 - Fixed parentheses when outputting `??` mixed with `||` and `&&` - Improved hygiene of the symbol generator ## v5.3.5 - Avoid moving named functions into default exports. - Enabled transform() for chain expressions. This allows AST transformers to reach inside chain expressions. ## v5.3.4 - Fixed a crash when hoisting (with `hoist_vars`) a destructuring variable declaration ## v5.3.3 - `source-map` library has been updated, bringing memory usage and CPU time improvements when reading input source maps (the SourceMapConsumer is now WASM based). - The `wrap_func_args` option now also wraps arrow functions, as opposed to only function expressions. ## v5.3.2 - Prevented spread operations from being expanded when the expanded array/object contains getters, setters, or array holes. - Fixed _very_ slow self-recursion in some cases of removing extraneous parentheses from `+` operations. ## v5.3.1 - An issue with destructuring declarations when `pure_getters` is enabled has been fixed - Fixed a crash when chain expressions need to be shallowly compared - Made inlining functions more conservative to make sure a function that contains a reference to itself isn't moved into a place that can create multiple instances of itself. ## v5.3.0 - Fixed a crash when compressing object spreads in some cases - Fixed compiletime evaluation of optional chains (caused typeof a?.b to always return "object") - domprops has been updated to contain every single possible prop ## v5.2.1 - The parse step now doesn't accept an `ecma` option, so that all ES code is accepted. - Optional dotted chains now accept keywords, just like dotted expressions (`foo?.default`) ## v5.2.0 - Optional chaining syntax is now supported. - Consecutive await expressions don't have unnecessary parens - Taking the variable name's length (after mangling) into consideration when deciding to inline ## v5.1.0 - `import.meta` is now supported - Typescript typings have been improved ## v5.0.0 - `in` operator now taken into account during property mangle. - Fixed infinite loop in face of a reference loop in some situations. - Kept exports and imports around even if there's something which will throw before them. - The main exported bundle for commonjs, dist/bundle.min.js is no longer minified. ## v5.0.0-beta.0 - BREAKING: `minify()` is now async and rejects a promise instead of returning an error. - BREAKING: Internal AST is no longer exposed, so that it can be improved without releasing breaking changes. - BREAKING: Lowest supported node version is 10 - BREAKING: There are no more warnings being emitted - Module is now distributed as a dual package - You can `import` and `require()` too. - Inline improvements were made ----- ## v4.8.1 (backport) - Security fix for RegExps that should not be evaluated (regexp DDOS) ## v4.8.0 - Support for numeric separators (`million = 1_000_000`) was added. - Assigning properties to a class is now assumed to be pure. - Fixed bug where `yield` wasn't considered a valid property key in generators. ## v4.7.0 - A bug was fixed where an arrow function would have the wrong size - `arguments` object is now considered safe to retrieve properties from (useful for `length`, or `0`) even when `pure_getters` is not set. - Fixed erroneous `const` declarations without value (which is invalid) in some corner cases when using `collapse_vars`. ## v4.6.13 - Fixed issue where ES5 object properties were being turned into ES6 object properties due to more lax unicode rules. - Fixed parsing of BigInt with lowercase `e` in them. ## v4.6.12 - Fixed subtree comparison code, making it see that `[1,[2, 3]]` is different from `[1, 2, [3]]` - Printing of unicode identifiers has been improved ## v4.6.11 - Read unused classes' properties and method keys, to figure out if they use other variables. - Prevent inlining into block scopes when there are name collisions - Functions are no longer inlined into parameter defaults, because they live in their own special scope. - When inlining identity functions, take into account the fact they may be used to drop `this` in function calls. - Nullish coalescing operator (`x ?? y`), plus basic optimization for it. - Template literals in binary expressions such as `+` have been further optimized ## v4.6.10 - Do not use reduce_vars when classes are present ## v4.6.9 - Check if block scopes actually exist in blocks ## v4.6.8 - Take into account "executed bits" of classes like static properties or computed keys, when checking if a class evaluation might throw or have side effects. ## v4.6.7 - Some new performance gains through a `AST_Node.size()` method which measures a node's source code length without printing it to a string first. - An issue with setting `--comments` to `false` in the CLI has been fixed. - Fixed some issues with inlining - `unsafe_symbols` compress option was added, which turns `Symbol("name")` into just `Symbol()` - Brought back compress performance improvement through the `AST_Node.equivalent_to(other)` method (which was reverted in v4.6.6). ## v4.6.6 (hotfix release) - Reverted code to 4.6.4 to allow for more time to investigate an issue. ## v4.6.5 (REVERTED) - Improved compress performance through using a new method to see if two nodes are equivalent, instead of printing them to a string. ## v4.6.4 - The `"some"` value in the `comments` output option now preserves `@lic` and other important comments when using `//` - `` is now better escaped in regex, and in comments, when using the `inline_script` output option - Fixed an issue when transforming `new RegExp` into `/.../` when slashes are included in the source - `AST_Node.prototype.constructor` now exists, allowing for easier debugging of crashes - Multiple if statements with the same consequents are now collapsed - Typescript typings improvements - Optimizations while looking for surrogate pairs in strings ## v4.6.3 - Annotations such as `/*#__NOINLINE__*/` and `/*#__PURE__*/` may now be preserved using the `preserve_annotations` output option - A TypeScript definition update for the `keep_quoted` output option. ## v4.6.2 - A bug where functions were inlined into other functions with scope conflicts has been fixed. - `/*#__NOINLINE__*/` annotation fixed for more use cases where inlining happens. ## v4.6.1 - Fixed an issue where a class is duplicated by reduce_vars when there's a recursive reference to the class. ## v4.6.0 - Fixed issues with recursive class references. - BigInt evaluation has been prevented, stopping Terser from evaluating BigInts like it would do regular numbers. - Class property support has been added ## v4.5.1 (hotfix release) - Fixed issue where `() => ({})[something]` was not parenthesised correctly. ## v4.5.0 - Inlining has been improved - An issue where keep_fnames combined with functions declared through variables was causing name shadowing has been fixed - You can now set the ES version through their year - The output option `keep_numbers` has been added, which prevents Terser from turning `1000` into `1e3` and such - Internal small optimisations and refactors ## v4.4.3 - Number and BigInt parsing has been fixed - `/*#__INLINE__*/` annotation fixed for arrow functions with non-block bodies. - Functional tests have been added, using [this repository](https://github.com/terser/terser-functional-tests). - A memory leak, where the entire AST lives on after compression, has been plugged. ## v4.4.2 - Fixed a problem with inlining identity functions ## v4.4.1 *note:* This introduced a feature, therefore it should have been a minor release. - Fixed a crash when `unsafe` was enabled. - An issue has been fixed where `let` statements might be collapsed out of their scope. - Some error messages have been improved by adding quotes around variable names. ## v4.4.0 - Added `/*#__INLINE__*/` and `/*#__NOINLINE__*/` annotations for calls. If a call has one of these, it either forces or forbids inlining. ## v4.3.11 - Fixed a problem where `window` was considered safe to access, even though there are situations where it isn't (Node.js, workers...) - Fixed an error where `++` and `--` were considered side-effect free - `Number(x)` now needs both `unsafe` and and `unsafe_math` to be compressed into `+x` because `x` might be a `BigInt` - `keep_fnames` now correctly supports regexes when the function is in a variable declaration ## v4.3.10 - Fixed syntax error when repeated semicolons were encountered in classes - Fixed invalid output caused by the creation of empty sequences internally - Scopes are now updated when scopes are inlined into them ## v4.3.9 - Fixed issue with mangle's `keep_fnames` option, introduced when adding code to keep variable names of anonymous functions ## v4.3.8 - Typescript typings fix ## v4.3.7 - Parsing of regex options in the CLI (which broke in v4.3.5) was fixed. - typescript definition updates ## v4.3.6 (crash hotfix) ## v4.3.5 - Fixed an issue with DOS line endings strings separated by `\` and a new line. - Improved fix for the output size regression related to unused references within the extends section of a class. - Variable names of anonymous functions (eg: `const x = () => { ... }` or `var func = function () {...}`) are now preserved when keep_fnames is true. - Fixed performance degradation introduced for large payloads in v4.2.0 ## v4.3.4 - Fixed a regression where the output size was increased when unused classes were referred to in the extends clause of a class. - Small typescript typings fixes. - Comments with `@preserve`, `@license`, `@cc_on` as well as comments starting with `/*!` and `/**!` are now preserved by default. ## v4.3.3 - Fixed a problem where parsing template strings would mix up octal notation and a slash followed by a zero representing a null character. - Started accepting the name `async` in destructuring arguments with default value. - Now Terser takes into account side effects inside class `extends` clauses. - Added parens whenever there's a comment between a return statement and the returned value, to prevent issues with ASI. - Stopped using raw RegExp objects, since the spec is going to continue to evolve. This ensures Terser is able to process new, unknown RegExp flags and features. This is a breaking change in the AST node AST_RegExp. ## v4.3.2 - Typescript typing fix - Ensure that functions can't be inlined, by reduce_vars, into places where they're accessing variables with the same name, but from somewhere else. ## v4.3.1 - Fixed an issue from 4.3.0 where any block scope within a for loop erroneously had its parent set to the function scopee - Fixed an issue where compressing IIFEs with argument expansions would result in some parameters becoming undefined - addEventListener options argument's properties are now part of the DOM properties list. ## v4.3.0 - Do not drop computed object keys with side effects - Functions passed to other functions in calls are now wrapped in parentheses by default, which speeds up loading most modules - Objects with computed properties are now less likely to be hoisted - Speed and memory efficiency optimizations - Fixed scoping issues with `try` and `switch` ## v4.2.1 - Minor refactors - Fixed a bug similar to #369 in collapse_vars - Functions can no longer be inlined into a place where they're going to be compared with themselves. - reduce_funcs option is now legacy, as using reduce_vars without reduce_funcs caused some weird corner cases. As a result, it is now implied in reduce_vars and can't be turned off without turning off reduce_vars. - Bug which would cause a random stack overflow has now been fixed. ## v4.2.0 - When the source map URL is `inline`, don't write it to a file. - Fixed output parens when a lambda literal is the tag on a tagged template string. - The `mangle.properties.undeclared` option was added. This enables the property mangler to mangle properties of variables which can be found in the name cache, but whose properties are not known to this Terser run. - The v8 bug where the toString and source representations of regexes like `RegExp("\\\n")` includes an actual newline is now fixed. - Now we're guaranteed to not have duplicate comments in the output - Domprops updates ## v4.1.4 - Fixed a crash when inlining a function into somewhere else when it has interdependent, non-removable variables. ## v4.1.3 - Several issues with the `reduce_vars` option were fixed. - Starting this version, we only have a dist/bundle.min.js ## 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/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-5.19.2/CONTRIBUTING.md000066400000000000000000000134251445647217600153720ustar00rootroot00000000000000# 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](#code-of-conduct), please follow it in all your interactions with the project. In general also try to be nice to others. ## Pull Request Process 1. When fixing a bug, include one or more tests which prove that your changes are correct, and that they fix something wrong. When adding a feature, include tests that show it in practice. 2. Update the README.md with details of changes to the interface, this includes new environment variables, options, useful file locations and others. ## Documentation Every new feature and API change should be accompanied by a README addition. ## Node version To install Terser's dev dependencies and run tests locally, oftentimes you will need the latest stable version of node. This is the highest even numbered version that's available. ## Testing All features and bugs should have tests that verify the fix. You can run all tests using `npm test`. There are two kinds of tests: * compress tests, located in `test/compress` and run with `npm run test:compress`, optionally with a test file name argument. * mocha-based tests, located in `test/mocha` and run with `npm run test:mocha` To run both of these tests at once, use `npm test`. The most common type of test are tests that verify input and output of the compress step. 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. - Line length should be at most 80 cols, except when it is easier to read a longer line. - 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 def_optimize(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); } } ``` ## 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/ terser-5.19.2/LICENSE000066400000000000000000000025021445647217600141400ustar00rootroot00000000000000Terser 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-5.19.2/PATRONS.md000066400000000000000000000006241445647217600146060ustar00rootroot00000000000000# Our patrons These are the first-tier patrons from Patreon (notice: **The Terser Patreon is shutting down in favor of opencollective**). My appreciation goes to everyone on this list for supporting the project! * 38elements * Alan Orozco * Aria Buckles * CKEditor * Mariusz Nowak * Nakshatra Mukhopadhyay * Philippe Léger * Piotrek Koszuliński * Serhiy Shyyko * Viktor Hubert * 龙腾道 terser-5.19.2/README.md000066400000000000000000001655301445647217600144250ustar00rootroot00000000000000

Terser

[![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][downloads-url] [![CI pipeline][ci-image]][ci-url] [![Opencollective financial contributors][opencollective-contributors]][opencollective-url] A JavaScript mangler/compressor toolkit for ES6+. *note*: You can support this project on patreon: [link] **The Terser Patreon is shutting down in favor of opencollective**. Check out [PATRONS.md](https://github.com/terser/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). Find the changelog in [CHANGELOG.md](https://github.com/terser/terser/blob/master/CHANGELOG.md) [npm-image]: https://img.shields.io/npm/v/terser.svg [npm-url]: https://npmjs.org/package/terser [downloads-image]: https://img.shields.io/npm/dm/terser.svg [downloads-url]: https://npmjs.org/package/terser [ci-image]: https://github.com/terser/terser/actions/workflows/ci.yml/badge.svg [ci-url]: https://github.com/terser/terser/actions/workflows/ci.yml [opencollective-contributors]: https://opencollective.com/terser/tiers/badge.svg [opencollective-url]: https://opencollective.com/terser 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. Command line arguments that take options (like --parse, --compress, --mangle and --format) can take in a comma-separated list of default option overrides. For instance: terser input.js --compress ecma=2015,computed_props=false 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 and DOM API props. `debug` Add debug prefix and suffix. `keep_quoted` Only mangle unquoted properties, quoted properties are automatically reserved. `strict` disables quoted properties being automatically reserved. `regex` Only mangle matched property names. `only_annotated` Only mangle properties defined with /*@__MANGLE_PROP__*/. `reserved` List of names that should not be mangled. -f, --format [options] Specify format 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. `wrap_func_args` Wrap function arguments in parenthesis. -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 e.g. "@license", or start with "!". You can optionally pass one of the following arguments to this flag: - "all" to keep all comments - `false` to omit comments in the output - 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, 2015, 2016, etc. -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 `format` 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 `format` 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. --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 end 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 passes=2 -m --mangle-props ``` ```javascript var x={o:3,t:1,i:function(){return this.t+this.o},s:2};console.log(x.i()); ``` Mangle all properties except for `reserved` properties (still very unsafe): ```bash $ terser example.js -c passes=2 -m --mangle-props reserved=[foo_,bar_] ``` ```javascript var x={o:3,foo_:1,t:function(){return this.foo_+this.o},bar_:2};console.log(x.t()); ``` Mangle all properties matching a `regex` (not as unsafe but still unsafe): ```bash $ terser example.js -c passes=2 -m --mangle-props regex=/_$/ ``` ```javascript var x={o:3,t:1,calc:function(){return this.t+this.o},i:2};console.log(x.calc()); ``` Combining mangle properties options: ```bash $ terser example.js -c passes=2 -m --mangle-props regex=/_$/,reserved=[bar_] ``` ```javascript var x={o:3,t:1,calc:function(){return this.t+this.o},bar_:2};console.log(x.calc()); ``` In order for this to be of any use, we avoid mangling standard JS names and DOM API properties by default (`--mangle-props builtins` to override). 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 const { minify } = require("terser"); ``` Or, ```javascript import { minify } from "terser"; ``` Browser loading is also supported: ```html ``` There is a single async high level function, **`async minify(code, options)`**, which will perform all minification [phases](#minify-options) in a configurable manner. By default `minify()` will enable [`compress`](#compress-options) and [`mangle`](#mangle-options). Example: ```javascript var code = "function add(first, second) { return first + second; }"; var result = await minify(code, { sourceMap: true }); console.log(result.code); // minified output: function add(n,d){return n+d} console.log(result.map); // source map ``` 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 = await 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 = await minify(code, options); console.log(result.code); // console.log(3+7); ``` The `nameCache` option: ```javascript var options = { mangle: { toplevel: true, }, nameCache: {} }; var result1 = await minify({ "file1.js": "function add(first, second) { return first + second; }" }, options); var result2 = await 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", await minify({ "file1.js": fs.readFileSync("file1.js", "utf8"), "file2.js": fs.readFileSync("file2.js", "utf8") }, options).code, "utf8"); fs.writeFileSync("part2.js", await 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 }, format: { preamble: "/* minified */" } }; var result = await minify(code, options); console.log(result.code); // /* minified */ // alert(10);" ``` An error example: ```javascript try { const result = await minify({"foo.js" : "if (0) else console.log(1);"}); // Do something with result } catch (error) { const { message, filename, line, col, pos } = error; // Do something with error } ``` ## Minify options - `ecma` (default `undefined`) - pass `5`, `2015`, `2016`, etc to override `compress` and `format`'s `ecma` options. - `enclose` (default `false`) - pass `true`, or a string in the format of `"args[:values]"`, where `args` and `values` are comma-separated argument names and values, respectively, to embed the output in a big function with the configurable arguments and values. - `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. - `format` or `output` (default `null`) — pass an object if you wish to specify additional [format options](#format-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 function 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 [`format`](#format-options) for details. ## Minify options structure ```javascript { parse: { // parse options }, compress: { // compress options }, mangle: { // mangle options properties: { // mangle property options } }, format: { // format options (can also use `output` for backwards compatibility) }, sourceMap: { // source map options }, ecma: 5, // specify one of: 5, 2015, 2016, etc. enclose: false, // or specify true, or "args:values" keep_classnames: false, keep_fnames: false, ie8: false, module: false, nameCache: null, // or specify a name cache object safari10: false, toplevel: false } ``` ### Source map options To generate a source map: ```javascript var result = await 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 = await 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 = await 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`. If you happen to need the source map as a raw object, set `sourceMap.asObject` to `true`. ## Parse options - `bare_returns` (default `false`) -- support top level `return` statements - `html5_comments` (default `true`) - `shebang` (default `true`) -- support `#!command` as the first line - `spidermonkey` (default `false`) -- accept a Spidermonkey (Mozilla) AST ## Compress options - `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. - `arrows` (default: `true`) -- Class and object literal methods are converted will also be converted to arrow expressions if the resultant code is shorter: `m(){return x}` becomes `m:()=>x`. To do this to regular ES5 functions which don't use `this` or `arguments`, see `unsafe_arrows`. - `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. Note: `comparisons` works best with `lhs_constants` enabled. - `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 - `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 `2015` 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`, `let` and `const` 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-options). - `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-options). - `keep_infinity` (default: `false`) -- Pass `true` to prevent `Infinity` from being compressed into `1/0`, which may cause performance issues on Chrome. - `lhs_constants` (default: `true`) -- Moves constant values to the left-hand side of binary nodes. `foo == 42 → 42 == foo` - `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_vars` (default: `true`) -- Improve optimization on variables assigned with and used as constant values. - `reduce_funcs` (default: `true`) -- Inline single-use functions when possible. Depends on `reduce_vars` being enabled. Disabling this option sometimes improves performance of the output code. - `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`) -- Remove expressions which have no side effects and whose results aren't used. - `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 `2015` 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_symbols` (default: `false`) -- removes keys from native Symbol declarations, e.g `Symbol("kDog")` becomes `Symbol()`. - `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"`) ## 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 function 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`. - `nth_identifier` (default: an internal mangler that weights based on character frequency analysis) -- Pass an object with a `get(n)` function that converts an ordinal into the nth most favored (usually shortest) identifier. Optionally also provide `reset()`, `sort()`, and `consider(chars, delta)` to use character frequency analysis of the source code. - `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` [format option](#format-options). Examples: ```javascript // test.js var globalVar; function funcName(firstLongName, anotherLongName) { var myVariable = firstLongName + anotherLongName; } ``` ```javascript var code = fs.readFileSync("test.js", "utf8"); await minify(code).code; // 'function funcName(a,n){}var globalVar;' await minify(code, { mangle: { reserved: ['firstLongName'] } }).code; // 'function funcName(firstLongName,a){}var globalVar;' await 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`) — How quoting properties (`{"prop": ...}` and `obj["prop"]`) controls what gets mangled. - `"strict"` (recommended) -- `obj.prop` is mangled. - `false` -- `obj["prop"]` is mangled. - `true` -- `obj.prop` is mangled unless there is `obj["prop"]` elsewhere in the code. - `nth_identifer` (default: an internal mangler that weights based on character frequency analysis) -- Pass an object with a `get(n)` function that converts an ordinal into the nth most favored (usually shortest) identifier. Optionally also provide `reset()`, `sort()`, and `consider(chars, delta)` to use character frequency analysis of the source code. - `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. - `undeclared` (default: `false`) - Mangle those names when they are accessed as properties of known top level variables but their declarations are never found in input code. May be useful when only minifying parts of a project. See [#397](https://github.com/terser/terser/issues/397) for more details. ## Format options These options control the format of Terser's output code. Previously known as "output options". - `ascii_only` (default `false`) -- escape Unicode characters in strings and regexps (affects directives with non-ascii characters becoming invalid) - `beautify` (default `false`) -- (DEPRECATED) whether to beautify the output. When using the legacy `-b` CLI flag, this is set to true by default. - `braces` (default `false`) -- always insert braces in `if`, `for`, `do`, `while` or `with` statements, even if their body is a single statement. - `comments` (default `"some"`) -- by default it keeps JSDoc-style comments that contain "@license", "@copyright", "@preserve" or start with `!`, pass `true` or `"all"` to preserve all comments, `false` to omit comments in the output, a regular expression string (e.g. `/^!/`) or a function. - `ecma` (default `5`) -- set desired EcmaScript standard version for output. Set `ecma` to `2015` 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 your input will still be output as is. For example: an `ecma` setting of `5` will **not** convert modern 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_numbers` (default `false`) -- keep number literals as it was in original code (disables optimizations like converting `1000000` into `1e6`) - `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 - `preserve_annotations` -- (default `false`) -- Preserve [Terser annotations](#annotations) in the output. - `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) - `spidermonkey` (default `false`) -- produce a Spidermonkey (Mozilla) AST - `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. - `wrap_func_args` (default `true`) -- pass `false` if you do not want to wrap function expressions that are passed as arguments, in parenthesis. See [OptimizeJS](https://github.com/nolanlawson/optimize-js) 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 comments starting with "!" and JSDoc-style comments that contain "@preserve", "@copyright", "@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 ]` - `Array.from([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`. 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 = await 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 await minify("alert('hello');", { compress: { global_defs: { "@alert": "console.log" } } }).code; // returns: 'console.log("hello");' ``` Otherwise it would be replaced as string literal: ```javascript await minify("alert('hello');", { compress: { global_defs: { "alert": "console.log" } } }).code; // returns: '"console.log"("hello");' ``` ### Annotations Annotations in Terser are a way to tell it to treat a certain function call differently. The following annotations are available: * `/*@__INLINE__*/` - forces a function to be inlined somewhere. * `/*@__NOINLINE__*/` - Makes sure the called function is not inlined into the call site. * `/*@__PURE__*/` - Marks a function call as pure. That means, it can safely be dropped. * `/*@__KEY__*/` - Marks a string literal as a property to also mangle it when mangling properties. * `/*@__MANGLE_PROP__*/` - Opts-in an object property (or class field) for mangling, when the property mangler is enabled. You can use either a `@` sign at the start, or a `#`. Here are some examples on how to use them: ```javascript /*@__INLINE__*/ function_always_inlined_here() /*#__NOINLINE__*/ function_cant_be_inlined_into_here() const x = /*#__PURE__*/i_am_dropped_if_x_is_not_used() function lookup(object, key) { return object[key]; } lookup({ i_will_be_mangled_too: "bar" }, /*@__KEY__*/ "i_will_be_mangled_too"); ``` ### 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. `spidermonkey` is also available in `minify` as `parse` and `format` options to accept and/or produce a spidermonkey 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 await 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`. When debugging, make sure you enable the **"map scopes"** feature to map mangled variable names back to their original names. Without this, all variable values will be `undefined`. See https://github.com/terser/terser/issues/1367 for more details.

![image](https://user-images.githubusercontent.com/27283110/230441652-ac5cf6b0-5dc5-4ffc-9d8b-bd02875484f4.png) ### 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()`). - `document.all` is not `== null` - Assigning properties to a class doesn't have side effects and does not throw. ### 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 ## A minimal, reproducible example You're expected to provide a [minimal reproducible example] of input code that will demonstrate your issue. To get to this example, you can remove bits of your code and stop if your issue ceases to reproduce. ## Obtaining the source code given to Terser Because users often don't control the call to `await minify()` or its arguments, Terser provides a `TERSER_DEBUG_DIR` environment variable to make terser output some debug logs. These logs will contain the input code and options of each `minify()` call. ```bash TERSER_DEBUG_DIR=/tmp/terser-log-dir command-that-uses-terser ls /tmp/terser-log-dir terser-debug-123456.log ``` If you're not sure how to set an environment variable on your shell (the above example works in bash), you can try using cross-env: ``` > npx cross-env TERSER_DEBUG_DIR=/path/to/logs command-that-uses-terser ``` ## Stack traces 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 help you write good issues. # README.md Patrons: *note*: You can support this project on patreon: [link] **The Terser Patreon is shutting down in favor of opencollective**. Check out [PATRONS.md](https://github.com/terser/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) ## Contributors ### Code Contributors This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)]. ### Financial Contributors Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/terser/contribute)] #### Individuals #### Organizations Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/terser/contribute)] terser-5.19.2/RECIPES.md000066400000000000000000000025101445647217600145460ustar00rootroot00000000000000## Terser for Gulp An example of how you can use the Terser plugin in your Gulp build. ```javascript const { src, dest, series } = require('gulp'); const { minify } = require('terser'); function js() { const options = { parse: { bare_returns: true, // (default false) -- support top level return statements. html5_comments: true, // (default true) shebang: true // (default true) -- support #!command as the first line. } }; return src('app/**/*.js') .on('data', function(file) { async function getJs() { const result = await minify(file.contents.toString(), options); return await minify(result) } (async function() { try { file.contents = Buffer.from(JSON.parse(Buffer.from(JSON.stringify(await getJs()))).code) } catch (error) { const { message, line, col, pos } = error console.log('message: ' + message) console.log('filename: ' + file.basename) console.log('line: ' + line) console.log('col: ' + col) console.log('pos: ' + pos) } })(); }) .pipe(dest('build')) } exports.js = series(js) ``` terser-5.19.2/bin/000077500000000000000000000000001445647217600137045ustar00rootroot00000000000000terser-5.19.2/bin/package.json000066400000000000000000000003761445647217600162000ustar00rootroot00000000000000{ "name": "bin", "private": true, "version": "1.0.0", "main": "terser", "type": "commonjs", "author": "", "license": "BSD-2-Clause", "description": "A package to hold the Terser bin bundle as commonjs while keeping the rest of it ESM." } terser-5.19.2/bin/terser000077500000000000000000000006741445647217600151450ustar00rootroot00000000000000#!/usr/bin/env node "use strict"; require("../tools/exit.cjs"); try { require("source-map-support").install(); } catch (err) {} const fs = require("fs"); const path = require("path"); const program = require("commander"); const packageJson = require("../package.json"); const { _run_cli: run_cli } = require(".."); run_cli({ program, packageJson, fs, path }).catch((error) => { console.error(error); process.exitCode = 1; }); terser-5.19.2/bin/uglifyjs000077500000000000000000000003661445647217600154730ustar00rootroot00000000000000#!/usr/bin/env node // -*- js -*- /* eslint-env node */ "use strict"; process.stderr.write( "DEPRECATION WARNING: uglifyjs binary will soon be discontinued!\n"); process.stderr.write("Please use \"terser\" instead.\n\n"); require("./terser"); terser-5.19.2/dist/000077500000000000000000000000001445647217600140775ustar00rootroot00000000000000terser-5.19.2/dist/.gitkeep000066400000000000000000000000001445647217600155160ustar00rootroot00000000000000terser-5.19.2/dist/package.json000066400000000000000000000004341445647217600163660ustar00rootroot00000000000000{ "name": "dist", "private": true, "version": "1.0.0", "main": "bundle.min.js", "type": "commonjs", "author": "", "license": "BSD-2-Clause", "description": "A package to hold the Terser dist bundle as commonjs while keeping the rest of it ESM. Nothing to see here." } terser-5.19.2/lib/000077500000000000000000000000001445647217600137025ustar00rootroot00000000000000terser-5.19.2/lib/ast.js000066400000000000000000002770061445647217600150430ustar00rootroot00000000000000/*********************************************************************** 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. ***********************************************************************/ import { HOP, MAP, noop } from "./utils/index.js"; import { parse } from "./parse.js"; function DEFNODE(type, props, ctor, 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); const proto = base && Object.create(base.prototype); if (proto) { ctor.prototype = proto; ctor.BASE = base; } if (base) base.SUBCLASSES.push(ctor); ctor.prototype.CTOR = ctor; ctor.prototype.constructor = ctor; ctor.PROPS = props || null; ctor.SELF_PROPS = self_props; ctor.SUBCLASSES = []; if (type) { ctor.prototype.TYPE = ctor.TYPE = type; } if (methods) for (let 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; } const has_tok_flag = (tok, flag) => Boolean(tok.flags & flag); const set_tok_flag = (tok, flag, truth) => { if (truth) { tok.flags |= flag; } else { tok.flags &= ~flag; } }; const TOK_FLAG_NLB = 0b0001; const TOK_FLAG_QUOTE_SINGLE = 0b0010; const TOK_FLAG_QUOTE_EXISTS = 0b0100; const TOK_FLAG_TEMPLATE_END = 0b1000; class AST_Token { constructor(type, value, line, col, pos, nlb, comments_before, comments_after, file) { this.flags = (nlb ? 1 : 0); this.type = type; this.value = value; this.line = line; this.col = col; this.pos = pos; this.comments_before = comments_before; this.comments_after = comments_after; this.file = file; Object.seal(this); } // Return a string summary of the token for node.js console.log [Symbol.for("nodejs.util.inspect.custom")](_depth, options) { const special = str => options.stylize(str, "special"); const quote = typeof this.value === "string" && this.value.includes("`") ? "'" : "`"; const value = `${quote}${this.value}${quote}`; return `${special("[AST_Token")} ${value} at ${this.line}:${this.col}${special("]")}`; } get nlb() { return has_tok_flag(this, TOK_FLAG_NLB); } set nlb(new_nlb) { set_tok_flag(this, TOK_FLAG_NLB, new_nlb); } get quote() { return !has_tok_flag(this, TOK_FLAG_QUOTE_EXISTS) ? "" : (has_tok_flag(this, TOK_FLAG_QUOTE_SINGLE) ? "'" : '"'); } set quote(quote_type) { set_tok_flag(this, TOK_FLAG_QUOTE_SINGLE, quote_type === "'"); set_tok_flag(this, TOK_FLAG_QUOTE_EXISTS, !!quote_type); } get template_end() { return has_tok_flag(this, TOK_FLAG_TEMPLATE_END); } set template_end(new_template_end) { set_tok_flag(this, TOK_FLAG_TEMPLATE_END, new_template_end); } } var AST_Node = DEFNODE("Node", "start end", function AST_Node(props) { if (props) { this.start = props.start; this.end = props.end; } this.flags = 0; }, { _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 }, _children_backwards: () => {} }, null); /* -----[ statements ]----- */ var AST_Statement = DEFNODE("Statement", null, function AST_Statement(props) { if (props) { this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Base class of all statements", }); var AST_Debugger = DEFNODE("Debugger", null, function AST_Debugger(props) { if (props) { this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Represents a debugger statement", }, AST_Statement); var AST_Directive = DEFNODE("Directive", "value quote", function AST_Directive(props) { if (props) { this.value = props.value; this.quote = props.quote; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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", function AST_SimpleStatement(props) { if (props) { this.body = props.body; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { push(this.body); } }, AST_Statement); function walk_body(node, visitor) { const body = node.body; 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) { clone.block_scope = this.block_scope.clone(); } return clone; } var AST_Block = DEFNODE("Block", "body block_scope", function AST_Block(props) { if (props) { this.body = props.body; this.block_scope = props.block_scope; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { let i = this.body.length; while (i--) push(this.body[i]); }, clone: clone_block_scope }, AST_Statement); var AST_BlockStatement = DEFNODE("BlockStatement", null, function AST_BlockStatement(props) { if (props) { this.body = props.body; this.block_scope = props.block_scope; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A block statement", }, AST_Block); var AST_EmptyStatement = DEFNODE("EmptyStatement", null, function AST_EmptyStatement(props) { if (props) { this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "The empty statement (empty block or simply a semicolon)" }, AST_Statement); var AST_StatementWithBody = DEFNODE("StatementWithBody", "body", function AST_StatementWithBody(props) { if (props) { this.body = props.body; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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", function AST_LabeledStatement(props) { if (props) { this.label = props.label; this.body = props.body; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { push(this.body); push(this.label); }, 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", function AST_IterationStatement(props) { if (props) { this.block_scope = props.block_scope; this.body = props.body; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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", function AST_DWLoop(props) { if (props) { this.condition = props.condition; this.block_scope = props.block_scope; this.body = props.body; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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, function AST_Do(props) { if (props) { this.condition = props.condition; this.block_scope = props.block_scope; this.body = props.body; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A `do` statement", _walk: function(visitor) { return visitor._visit(this, function() { this.body._walk(visitor); this.condition._walk(visitor); }); }, _children_backwards(push) { push(this.condition); push(this.body); } }, AST_DWLoop); var AST_While = DEFNODE("While", null, function AST_While(props) { if (props) { this.condition = props.condition; this.block_scope = props.block_scope; this.body = props.body; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A `while` statement", _walk: function(visitor) { return visitor._visit(this, function() { this.condition._walk(visitor); this.body._walk(visitor); }); }, _children_backwards(push) { push(this.body); push(this.condition); }, }, AST_DWLoop); var AST_For = DEFNODE("For", "init condition step", function AST_For(props) { if (props) { this.init = props.init; this.condition = props.condition; this.step = props.step; this.block_scope = props.block_scope; this.body = props.body; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { push(this.body); if (this.step) push(this.step); if (this.condition) push(this.condition); if (this.init) push(this.init); }, }, AST_IterationStatement); var AST_ForIn = DEFNODE("ForIn", "init object", function AST_ForIn(props) { if (props) { this.init = props.init; this.object = props.object; this.block_scope = props.block_scope; this.body = props.body; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { push(this.body); if (this.object) push(this.object); if (this.init) push(this.init); }, }, AST_IterationStatement); var AST_ForOf = DEFNODE("ForOf", "await", function AST_ForOf(props) { if (props) { this.await = props.await; this.init = props.init; this.object = props.object; this.block_scope = props.block_scope; this.body = props.body; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A `for ... of` statement", }, AST_ForIn); var AST_With = DEFNODE("With", "expression", function AST_With(props) { if (props) { this.expression = props.expression; this.body = props.body; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { push(this.body); push(this.expression); }, }, AST_StatementWithBody); /* -----[ scope and functions ]----- */ var AST_Scope = DEFNODE( "Scope", "variables uses_with uses_eval parent_scope enclosed cname", function AST_Scope(props) { if (props) { this.variables = props.variables; this.uses_with = props.uses_with; this.uses_eval = props.uses_eval; this.parent_scope = props.parent_scope; this.enclosed = props.enclosed; this.cname = props.cname; this.body = props.body; this.block_scope = props.block_scope; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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", 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, toplevel) { var node = this._clone(deep); if (deep && this.variables && toplevel && !this._block_scope) { node.figure_out_scope({}, { toplevel: toplevel, parent_scope: this.parent_scope }); } else { if (this.variables) node.variables = new Map(this.variables); if (this.enclosed) node.enclosed = this.enclosed.slice(); if (this._block_scope) node._block_scope = this._block_scope; } return node; }, pinned: function() { return this.uses_eval || this.uses_with; } }, AST_Block ); var AST_Toplevel = DEFNODE("Toplevel", "globals", function AST_Toplevel(props) { if (props) { this.globals = props.globals; this.variables = props.variables; this.uses_with = props.uses_with; this.uses_eval = props.uses_eval; this.parent_scope = props.parent_scope; this.enclosed = props.enclosed; this.cname = props.cname; this.body = props.body; this.block_scope = props.block_scope; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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", function AST_Expansion(props) { if (props) { this.expression = props.expression; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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) { return visitor._visit(this, function() { this.expression.walk(visitor); }); }, _children_backwards(push) { push(this.expression); }, }); var AST_Lambda = DEFNODE( "Lambda", "name argnames uses_arguments is_generator async", function AST_Lambda(props) { if (props) { this.name = props.name; this.argnames = props.argnames; this.uses_arguments = props.uses_arguments; this.is_generator = props.is_generator; this.async = props.async; this.variables = props.variables; this.uses_with = props.uses_with; this.uses_eval = props.uses_eval; this.parent_scope = props.parent_scope; this.enclosed = props.enclosed; this.cname = props.cname; this.body = props.body; this.block_scope = props.block_scope; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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.push(...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); }); }, _children_backwards(push) { let i = this.body.length; while (i--) push(this.body[i]); i = this.argnames.length; while (i--) push(this.argnames[i]); if (this.name) push(this.name); }, is_braceless() { return this.body[0] instanceof AST_Return && this.body[0].value; }, // Default args and expansion don't count, so .argnames.length doesn't cut it length_property() { let length = 0; for (const arg of this.argnames) { if (arg instanceof AST_SymbolFunarg || arg instanceof AST_Destructuring) { length++; } } return length; } }, AST_Scope ); var AST_Accessor = DEFNODE("Accessor", null, function AST_Accessor(props) { if (props) { this.name = props.name; this.argnames = props.argnames; this.uses_arguments = props.uses_arguments; this.is_generator = props.is_generator; this.async = props.async; this.variables = props.variables; this.uses_with = props.uses_with; this.uses_eval = props.uses_eval; this.parent_scope = props.parent_scope; this.enclosed = props.enclosed; this.cname = props.cname; this.body = props.body; this.block_scope = props.block_scope; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A setter/getter function. The `name` property is always null." }, AST_Lambda); var AST_Function = DEFNODE("Function", null, function AST_Function(props) { if (props) { this.name = props.name; this.argnames = props.argnames; this.uses_arguments = props.uses_arguments; this.is_generator = props.is_generator; this.async = props.async; this.variables = props.variables; this.uses_with = props.uses_with; this.uses_eval = props.uses_eval; this.parent_scope = props.parent_scope; this.enclosed = props.enclosed; this.cname = props.cname; this.body = props.body; this.block_scope = props.block_scope; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A function expression" }, AST_Lambda); var AST_Arrow = DEFNODE("Arrow", null, function AST_Arrow(props) { if (props) { this.name = props.name; this.argnames = props.argnames; this.uses_arguments = props.uses_arguments; this.is_generator = props.is_generator; this.async = props.async; this.variables = props.variables; this.uses_with = props.uses_with; this.uses_eval = props.uses_eval; this.parent_scope = props.parent_scope; this.enclosed = props.enclosed; this.cname = props.cname; this.body = props.body; this.block_scope = props.block_scope; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "An ES6 Arrow function ((a) => b)" }, AST_Lambda); var AST_Defun = DEFNODE("Defun", null, function AST_Defun(props) { if (props) { this.name = props.name; this.argnames = props.argnames; this.uses_arguments = props.uses_arguments; this.is_generator = props.is_generator; this.async = props.async; this.variables = props.variables; this.uses_with = props.uses_with; this.uses_eval = props.uses_eval; this.parent_scope = props.parent_scope; this.enclosed = props.enclosed; this.cname = props.cname; this.body = props.body; this.block_scope = props.block_scope; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A function definition" }, AST_Lambda); /* -----[ DESTRUCTURING ]----- */ var AST_Destructuring = DEFNODE("Destructuring", "names is_array", function AST_Destructuring(props) { if (props) { this.names = props.names; this.is_array = props.is_array; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }); }, _children_backwards(push) { let i = this.names.length; while (i--) push(this.names[i]); }, all_symbols: function() { var out = []; walk(this, node => { if (node instanceof AST_SymbolDeclaration) { out.push(node); } if (node instanceof AST_Lambda) { return true; } }); return out; } }); var AST_PrefixedTemplateString = DEFNODE( "PrefixedTemplateString", "template_string prefix", function AST_PrefixedTemplateString(props) { if (props) { this.template_string = props.template_string; this.prefix = props.prefix; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A templatestring with a prefix, such as String.raw`foobarbaz`", $propdoc: { template_string: "[AST_TemplateString] The template string", prefix: "[AST_Node] The prefix, which will get called." }, _walk: function(visitor) { return visitor._visit(this, function () { this.prefix._walk(visitor); this.template_string._walk(visitor); }); }, _children_backwards(push) { push(this.template_string); push(this.prefix); }, } ); var AST_TemplateString = DEFNODE("TemplateString", "segments", function AST_TemplateString(props) { if (props) { this.segments = props.segments; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }); }, _children_backwards(push) { let i = this.segments.length; while (i--) push(this.segments[i]); } }); var AST_TemplateSegment = DEFNODE("TemplateSegment", "value raw", function AST_TemplateSegment(props) { if (props) { this.value = props.value; this.raw = props.raw; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A segment of a template string literal", $propdoc: { value: "Content of the segment", raw: "Raw source of the segment", } }); /* -----[ JUMPS ]----- */ var AST_Jump = DEFNODE("Jump", null, function AST_Jump(props) { if (props) { this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Base class for “jumps” (for now that's `return`, `throw`, `break` and `continue`)" }, AST_Statement); /** Base class for “exits” (`return` and `throw`) */ var AST_Exit = DEFNODE("Exit", "value", function AST_Exit(props) { if (props) { this.value = props.value; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { if (this.value) push(this.value); }, }, AST_Jump); var AST_Return = DEFNODE("Return", null, function AST_Return(props) { if (props) { this.value = props.value; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A `return` statement" }, AST_Exit); var AST_Throw = DEFNODE("Throw", null, function AST_Throw(props) { if (props) { this.value = props.value; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A `throw` statement" }, AST_Exit); var AST_LoopControl = DEFNODE("LoopControl", "label", function AST_LoopControl(props) { if (props) { this.label = props.label; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { if (this.label) push(this.label); }, }, AST_Jump); var AST_Break = DEFNODE("Break", null, function AST_Break(props) { if (props) { this.label = props.label; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A `break` statement" }, AST_LoopControl); var AST_Continue = DEFNODE("Continue", null, function AST_Continue(props) { if (props) { this.label = props.label; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A `continue` statement" }, AST_LoopControl); var AST_Await = DEFNODE("Await", "expression", function AST_Await(props) { if (props) { this.expression = props.expression; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { push(this.expression); }, }); var AST_Yield = DEFNODE("Yield", "expression is_star", function AST_Yield(props) { if (props) { this.expression = props.expression; this.is_star = props.is_star; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { if (this.expression) push(this.expression); } }); /* -----[ IF ]----- */ var AST_If = DEFNODE("If", "condition alternative", function AST_If(props) { if (props) { this.condition = props.condition; this.alternative = props.alternative; this.body = props.body; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { if (this.alternative) { push(this.alternative); } push(this.body); push(this.condition); } }, AST_StatementWithBody); /* -----[ SWITCH ]----- */ var AST_Switch = DEFNODE("Switch", "expression", function AST_Switch(props) { if (props) { this.expression = props.expression; this.body = props.body; this.block_scope = props.block_scope; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { let i = this.body.length; while (i--) push(this.body[i]); push(this.expression); } }, AST_Block); var AST_SwitchBranch = DEFNODE("SwitchBranch", null, function AST_SwitchBranch(props) { if (props) { this.body = props.body; this.block_scope = props.block_scope; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Base class for `switch` branches", }, AST_Block); var AST_Default = DEFNODE("Default", null, function AST_Default(props) { if (props) { this.body = props.body; this.block_scope = props.block_scope; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A `default` switch branch", }, AST_SwitchBranch); var AST_Case = DEFNODE("Case", "expression", function AST_Case(props) { if (props) { this.expression = props.expression; this.body = props.body; this.block_scope = props.block_scope; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { let i = this.body.length; while (i--) push(this.body[i]); push(this.expression); }, }, AST_SwitchBranch); /* -----[ EXCEPTIONS ]----- */ var AST_Try = DEFNODE("Try", "body bcatch bfinally", function AST_Try(props) { if (props) { this.body = props.body; this.bcatch = props.bcatch; this.bfinally = props.bfinally; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A `try` statement", $propdoc: { body: "[AST_TryBlock] the try block", 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() { this.body._walk(visitor); if (this.bcatch) this.bcatch._walk(visitor); if (this.bfinally) this.bfinally._walk(visitor); }); }, _children_backwards(push) { if (this.bfinally) push(this.bfinally); if (this.bcatch) push(this.bcatch); push(this.body); }, }, AST_Statement); var AST_TryBlock = DEFNODE("TryBlock", null, function AST_TryBlock(props) { if (props) { this.body = props.body; this.block_scope = props.block_scope; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "The `try` block of a try statement" }, AST_Block); var AST_Catch = DEFNODE("Catch", "argname", function AST_Catch(props) { if (props) { this.argname = props.argname; this.body = props.body; this.block_scope = props.block_scope; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { let i = this.body.length; while (i--) push(this.body[i]); if (this.argname) push(this.argname); }, }, AST_Block); var AST_Finally = DEFNODE("Finally", null, function AST_Finally(props) { if (props) { this.body = props.body; this.block_scope = props.block_scope; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A `finally` node; only makes sense as part of a `try` statement" }, AST_Block); /* -----[ VAR/CONST ]----- */ var AST_Definitions = DEFNODE("Definitions", "definitions", function AST_Definitions(props) { if (props) { this.definitions = props.definitions; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); } }); }, _children_backwards(push) { let i = this.definitions.length; while (i--) push(this.definitions[i]); }, }, AST_Statement); var AST_Var = DEFNODE("Var", null, function AST_Var(props) { if (props) { this.definitions = props.definitions; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A `var` statement" }, AST_Definitions); var AST_Let = DEFNODE("Let", null, function AST_Let(props) { if (props) { this.definitions = props.definitions; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A `let` statement" }, AST_Definitions); var AST_Const = DEFNODE("Const", null, function AST_Const(props) { if (props) { this.definitions = props.definitions; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A `const` statement" }, AST_Definitions); var AST_VarDef = DEFNODE("VarDef", "name value", function AST_VarDef(props) { if (props) { this.name = props.name; this.value = props.value; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { if (this.value) push(this.value); push(this.name); }, declarations_as_names() { if (this.name instanceof AST_SymbolDeclaration) { return [this]; } else { return this.name.all_symbols(); } } }); var AST_NameMapping = DEFNODE("NameMapping", "foreign_name name", function AST_NameMapping(props) { if (props) { this.foreign_name = props.foreign_name; this.name = props.name; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { push(this.name); push(this.foreign_name); }, }); var AST_Import = DEFNODE( "Import", "imported_name imported_names module_name assert_clause", function AST_Import(props) { if (props) { this.imported_name = props.imported_name; this.imported_names = props.imported_names; this.module_name = props.module_name; this.assert_clause = props.assert_clause; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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", assert_clause: "[AST_Object?] The import assertion" }, _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); }); }, _children_backwards(push) { push(this.module_name); if (this.imported_names) { let i = this.imported_names.length; while (i--) push(this.imported_names[i]); } if (this.imported_name) push(this.imported_name); }, } ); var AST_ImportMeta = DEFNODE("ImportMeta", null, function AST_ImportMeta(props) { if (props) { this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A reference to import.meta", }); var AST_Export = DEFNODE( "Export", "exported_definition exported_value is_default exported_names module_name assert_clause", function AST_Export(props) { if (props) { this.exported_definition = props.exported_definition; this.exported_value = props.exported_value; this.is_default = props.is_default; this.exported_names = props.exported_names; this.module_name = props.module_name; this.assert_clause = props.assert_clause; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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", assert_clause: "[AST_Object?] The import assertion" }, _walk: function (visitor) { return 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); } }); }, _children_backwards(push) { if (this.module_name) push(this.module_name); if (this.exported_names) { let i = this.exported_names.length; while (i--) push(this.exported_names[i]); } if (this.exported_value) push(this.exported_value); if (this.exported_definition) push(this.exported_definition); } }, AST_Statement ); /* -----[ OTHER ]----- */ var AST_Call = DEFNODE( "Call", "expression args optional _annotations", function AST_Call(props) { if (props) { this.expression = props.expression; this.args = props.args; this.optional = props.optional; this._annotations = props._annotations; this.start = props.start; this.end = props.end; this.initialize(); } this.flags = 0; }, { $documentation: "A function call expression", $propdoc: { expression: "[AST_Node] expression to invoke as function", args: "[AST_Node*] array of arguments", optional: "[boolean] whether this is an optional call (IE ?.() )", _annotations: "[number] bitfield containing information about the call" }, initialize() { if (this._annotations == null) this._annotations = 0; }, _walk(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); // TODO why do we need to crawl this last? }); }, _children_backwards(push) { let i = this.args.length; while (i--) push(this.args[i]); push(this.expression); }, } ); var AST_New = DEFNODE("New", null, function AST_New(props) { if (props) { this.expression = props.expression; this.args = props.args; this.optional = props.optional; this._annotations = props._annotations; this.start = props.start; this.end = props.end; this.initialize(); } this.flags = 0; }, { $documentation: "An object instantiation. Derives from a function call since it has exactly the same properties" }, AST_Call); var AST_Sequence = DEFNODE("Sequence", "expressions", function AST_Sequence(props) { if (props) { this.expressions = props.expressions; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }); }, _children_backwards(push) { let i = this.expressions.length; while (i--) push(this.expressions[i]); }, }); var AST_PropAccess = DEFNODE( "PropAccess", "expression property optional", function AST_PropAccess(props) { if (props) { this.expression = props.expression; this.property = props.property; this.optional = props.optional; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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 & AST_DotHash this is always a plain string, while for AST_Sub it's an arbitrary AST_Node", optional: "[boolean] whether this is an optional property access (IE ?.)" } } ); var AST_Dot = DEFNODE("Dot", "quote", function AST_Dot(props) { if (props) { this.quote = props.quote; this.expression = props.expression; this.property = props.property; this.optional = props.optional; this._annotations = props._annotations; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { push(this.expression); }, }, AST_PropAccess); var AST_DotHash = DEFNODE("DotHash", "", function AST_DotHash(props) { if (props) { this.expression = props.expression; this.property = props.property; this.optional = props.optional; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A dotted property access to a private property", _walk: function(visitor) { return visitor._visit(this, function() { this.expression._walk(visitor); }); }, _children_backwards(push) { push(this.expression); }, }, AST_PropAccess); var AST_Sub = DEFNODE("Sub", null, function AST_Sub(props) { if (props) { this.expression = props.expression; this.property = props.property; this.optional = props.optional; this._annotations = props._annotations; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { push(this.property); push(this.expression); }, }, AST_PropAccess); var AST_Chain = DEFNODE("Chain", "expression", function AST_Chain(props) { if (props) { this.expression = props.expression; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A chain expression like a?.b?.(c)?.[d]", $propdoc: { expression: "[AST_Call|AST_Dot|AST_DotHash|AST_Sub] chain element." }, _walk: function (visitor) { return visitor._visit(this, function() { this.expression._walk(visitor); }); }, _children_backwards(push) { push(this.expression); }, }); var AST_Unary = DEFNODE("Unary", "operator expression", function AST_Unary(props) { if (props) { this.operator = props.operator; this.expression = props.expression; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { push(this.expression); }, }); var AST_UnaryPrefix = DEFNODE("UnaryPrefix", null, function AST_UnaryPrefix(props) { if (props) { this.operator = props.operator; this.expression = props.expression; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Unary prefix expression, i.e. `typeof i` or `++i`" }, AST_Unary); var AST_UnaryPostfix = DEFNODE("UnaryPostfix", null, function AST_UnaryPostfix(props) { if (props) { this.operator = props.operator; this.expression = props.expression; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Unary postfix expression, i.e. `i++`" }, AST_Unary); var AST_Binary = DEFNODE("Binary", "operator left right", function AST_Binary(props) { if (props) { this.operator = props.operator; this.left = props.left; this.right = props.right; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { push(this.right); push(this.left); }, }); var AST_Conditional = DEFNODE( "Conditional", "condition consequent alternative", function AST_Conditional(props) { if (props) { this.condition = props.condition; this.consequent = props.consequent; this.alternative = props.alternative; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { push(this.alternative); push(this.consequent); push(this.condition); }, } ); var AST_Assign = DEFNODE("Assign", "logical", function AST_Assign(props) { if (props) { this.logical = props.logical; this.operator = props.operator; this.left = props.left; this.right = props.right; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "An assignment expression — `a = b + 5`", $propdoc: { logical: "Whether it's a logical assignment" } }, AST_Binary); var AST_DefaultAssign = DEFNODE("DefaultAssign", null, function AST_DefaultAssign(props) { if (props) { this.operator = props.operator; this.left = props.left; this.right = props.right; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A default assignment expression like in `(a = 3) => a`" }, AST_Binary); /* -----[ LITERALS ]----- */ var AST_Array = DEFNODE("Array", "elements", function AST_Array(props) { if (props) { this.elements = props.elements; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); } }); }, _children_backwards(push) { let i = this.elements.length; while (i--) push(this.elements[i]); }, }); var AST_Object = DEFNODE("Object", "properties", function AST_Object(props) { if (props) { this.properties = props.properties; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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); } }); }, _children_backwards(push) { let i = this.properties.length; while (i--) push(this.properties[i]); }, }); var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", function AST_ObjectProperty(props) { if (props) { this.key = props.key; this.value = props.value; this.start = props.start; this.end = props.end; this._annotations = props._annotations; } this.flags = 0; }, { $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); }); }, _children_backwards(push) { push(this.value); if (this.key instanceof AST_Node) push(this.key); } }); var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", "quote", function AST_ObjectKeyVal(props) { if (props) { this.quote = props.quote; this.key = props.key; this.value = props.value; this.start = props.start; this.end = props.end; this._annotations = props._annotations; } this.flags = 0; }, { $documentation: "A key: value object property", $propdoc: { quote: "[string] the original quote character" }, computed_key() { return this.key instanceof AST_Node; } }, AST_ObjectProperty); var AST_PrivateSetter = DEFNODE("PrivateSetter", "static", function AST_PrivateSetter(props) { if (props) { this.static = props.static; this.key = props.key; this.value = props.value; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $propdoc: { static: "[boolean] whether this is a static private setter" }, $documentation: "A private setter property", computed_key() { return false; } }, AST_ObjectProperty); var AST_PrivateGetter = DEFNODE("PrivateGetter", "static", function AST_PrivateGetter(props) { if (props) { this.static = props.static; this.key = props.key; this.value = props.value; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $propdoc: { static: "[boolean] whether this is a static private getter" }, $documentation: "A private getter property", computed_key() { return false; } }, AST_ObjectProperty); var AST_ObjectSetter = DEFNODE("ObjectSetter", "quote static", function AST_ObjectSetter(props) { if (props) { this.quote = props.quote; this.static = props.static; this.key = props.key; this.value = props.value; this.start = props.start; this.end = props.end; this._annotations = props._annotations; } this.flags = 0; }, { $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", computed_key() { return !(this.key instanceof AST_SymbolMethod); } }, AST_ObjectProperty); var AST_ObjectGetter = DEFNODE("ObjectGetter", "quote static", function AST_ObjectGetter(props) { if (props) { this.quote = props.quote; this.static = props.static; this.key = props.key; this.value = props.value; this.start = props.start; this.end = props.end; this._annotations = props._annotations; } this.flags = 0; }, { $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", computed_key() { return !(this.key instanceof AST_SymbolMethod); } }, AST_ObjectProperty); var AST_ConciseMethod = DEFNODE( "ConciseMethod", "quote static is_generator async", function AST_ConciseMethod(props) { if (props) { this.quote = props.quote; this.static = props.static; this.is_generator = props.is_generator; this.async = props.async; this.key = props.key; this.value = props.value; this.start = props.start; this.end = props.end; this._annotations = props._annotations; } this.flags = 0; }, { $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", computed_key() { return !(this.key instanceof AST_SymbolMethod); } }, AST_ObjectProperty ); var AST_PrivateMethod = DEFNODE("PrivateMethod", "", function AST_PrivateMethod(props) { if (props) { this.quote = props.quote; this.static = props.static; this.is_generator = props.is_generator; this.async = props.async; this.key = props.key; this.value = props.value; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A private class method inside a class", }, AST_ConciseMethod); var AST_Class = DEFNODE("Class", "name extends properties", function AST_Class(props) { if (props) { this.name = props.name; this.extends = props.extends; this.properties = props.properties; this.variables = props.variables; this.uses_with = props.uses_with; this.uses_eval = props.uses_eval; this.parent_scope = props.parent_scope; this.enclosed = props.enclosed; this.cname = props.cname; this.body = props.body; this.block_scope = props.block_scope; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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((prop) => prop._walk(visitor)); }); }, _children_backwards(push) { let i = this.properties.length; while (i--) push(this.properties[i]); if (this.extends) push(this.extends); if (this.name) push(this.name); }, /** go through the bits that are executed instantly, not when the class is `new`'d. Doesn't walk the name. */ visit_nondeferred_class_parts(visitor) { if (this.extends) { this.extends._walk(visitor); } this.properties.forEach((prop) => { if (prop instanceof AST_ClassStaticBlock) { prop._walk(visitor); return; } if (prop.computed_key()) { visitor.push(prop); prop.key._walk(visitor); visitor.pop(); } if ((prop instanceof AST_ClassPrivateProperty || prop instanceof AST_ClassProperty) && prop.static && prop.value) { visitor.push(prop); prop.value._walk(visitor); visitor.pop(); } }); }, /** go through the bits that are executed later, when the class is `new`'d or a static method is called */ visit_deferred_class_parts(visitor) { this.properties.forEach((prop) => { if (prop instanceof AST_ConciseMethod) { prop.walk(visitor); } else if (prop instanceof AST_ClassProperty && !prop.static && prop.value) { visitor.push(prop); prop.value._walk(visitor); visitor.pop(); } }); }, }, AST_Scope /* TODO a class might have a scope but it's not a scope */); var AST_ClassProperty = DEFNODE("ClassProperty", "static quote", function AST_ClassProperty(props) { if (props) { this.static = props.static; this.quote = props.quote; this.key = props.key; this.value = props.value; this.start = props.start; this.end = props.end; this._annotations = props._annotations; } this.flags = 0; }, { $documentation: "A class property", $propdoc: { static: "[boolean] whether this is a static key", quote: "[string] which quote is being used" }, _walk: function(visitor) { return visitor._visit(this, function() { if (this.key instanceof AST_Node) this.key._walk(visitor); if (this.value instanceof AST_Node) this.value._walk(visitor); }); }, _children_backwards(push) { if (this.value instanceof AST_Node) push(this.value); if (this.key instanceof AST_Node) push(this.key); }, computed_key() { return !(this.key instanceof AST_SymbolClassProperty); } }, AST_ObjectProperty); var AST_ClassPrivateProperty = DEFNODE("ClassPrivateProperty", "", function AST_ClassPrivateProperty(props) { if (props) { this.static = props.static; this.quote = props.quote; this.key = props.key; this.value = props.value; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A class property for a private property", }, AST_ClassProperty); var AST_PrivateIn = DEFNODE("PrivateIn", "key value", function AST_PrivateIn(props) { if (props) { this.key = props.key; this.value = props.value; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "An `in` binop when the key is private, eg #x in this", _walk: function(visitor) { return visitor._visit(this, function() { this.key._walk(visitor); this.value._walk(visitor); }); }, _children_backwards(push) { push(this.value); push(this.key); }, }); var AST_DefClass = DEFNODE("DefClass", null, function AST_DefClass(props) { if (props) { this.name = props.name; this.extends = props.extends; this.properties = props.properties; this.variables = props.variables; this.uses_with = props.uses_with; this.uses_eval = props.uses_eval; this.parent_scope = props.parent_scope; this.enclosed = props.enclosed; this.cname = props.cname; this.body = props.body; this.block_scope = props.block_scope; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A class definition", }, AST_Class); var AST_ClassStaticBlock = DEFNODE("ClassStaticBlock", "body block_scope", function AST_ClassStaticBlock (props) { this.body = props.body; this.block_scope = props.block_scope; this.start = props.start; this.end = props.end; }, { $documentation: "A block containing statements to be executed in the context of the class", $propdoc: { body: "[AST_Statement*] an array of statements", }, _walk: function(visitor) { return visitor._visit(this, function() { walk_body(this, visitor); }); }, _children_backwards(push) { let i = this.body.length; while (i--) push(this.body[i]); }, clone: clone_block_scope, computed_key: () => false }, AST_Scope); var AST_ClassExpression = DEFNODE("ClassExpression", null, function AST_ClassExpression(props) { if (props) { this.name = props.name; this.extends = props.extends; this.properties = props.properties; this.variables = props.variables; this.uses_with = props.uses_with; this.uses_eval = props.uses_eval; this.parent_scope = props.parent_scope; this.enclosed = props.enclosed; this.cname = props.cname; this.body = props.body; this.block_scope = props.block_scope; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A class expression." }, AST_Class); var AST_Symbol = DEFNODE("Symbol", "scope name thedef", function AST_Symbol(props) { if (props) { this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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, function AST_NewTarget(props) { if (props) { this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A reference to new.target" }); var AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init", function AST_SymbolDeclaration(props) { if (props) { this.init = props.init; this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A declaration symbol (symbol in var/const, function name or argument, symbol in catch)", }, AST_Symbol); var AST_SymbolVar = DEFNODE("SymbolVar", null, function AST_SymbolVar(props) { if (props) { this.init = props.init; this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Symbol defining a variable", }, AST_SymbolDeclaration); var AST_SymbolBlockDeclaration = DEFNODE( "SymbolBlockDeclaration", null, function AST_SymbolBlockDeclaration(props) { if (props) { this.init = props.init; this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Base class for block-scoped declaration symbols" }, AST_SymbolDeclaration ); var AST_SymbolConst = DEFNODE("SymbolConst", null, function AST_SymbolConst(props) { if (props) { this.init = props.init; this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A constant declaration" }, AST_SymbolBlockDeclaration); var AST_SymbolLet = DEFNODE("SymbolLet", null, function AST_SymbolLet(props) { if (props) { this.init = props.init; this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A block-scoped `let` declaration" }, AST_SymbolBlockDeclaration); var AST_SymbolFunarg = DEFNODE("SymbolFunarg", null, function AST_SymbolFunarg(props) { if (props) { this.init = props.init; this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Symbol naming a function argument", }, AST_SymbolVar); var AST_SymbolDefun = DEFNODE("SymbolDefun", null, function AST_SymbolDefun(props) { if (props) { this.init = props.init; this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Symbol defining a function", }, AST_SymbolDeclaration); var AST_SymbolMethod = DEFNODE("SymbolMethod", null, function AST_SymbolMethod(props) { if (props) { this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Symbol in an object defining a method", }, AST_Symbol); var AST_SymbolClassProperty = DEFNODE("SymbolClassProperty", null, function AST_SymbolClassProperty(props) { if (props) { this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Symbol for a class property", }, AST_Symbol); var AST_SymbolLambda = DEFNODE("SymbolLambda", null, function AST_SymbolLambda(props) { if (props) { this.init = props.init; this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Symbol naming a function expression", }, AST_SymbolDeclaration); var AST_SymbolDefClass = DEFNODE("SymbolDefClass", null, function AST_SymbolDefClass(props) { if (props) { this.init = props.init; this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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, function AST_SymbolClass(props) { if (props) { this.init = props.init; this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Symbol naming a class's name. Lexically scoped to the class." }, AST_SymbolDeclaration); var AST_SymbolCatch = DEFNODE("SymbolCatch", null, function AST_SymbolCatch(props) { if (props) { this.init = props.init; this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Symbol naming the exception in catch", }, AST_SymbolBlockDeclaration); var AST_SymbolImport = DEFNODE("SymbolImport", null, function AST_SymbolImport(props) { if (props) { this.init = props.init; this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Symbol referring to an imported name", }, AST_SymbolBlockDeclaration); var AST_SymbolImportForeign = DEFNODE("SymbolImportForeign", null, function AST_SymbolImportForeign(props) { if (props) { this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.quote = props.quote; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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", function AST_Label(props) { if (props) { this.references = props.references; this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; this.initialize(); } this.flags = 0; }, { $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, function AST_SymbolRef(props) { if (props) { this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Reference to some symbol (not definition/declaration)", }, AST_Symbol); var AST_SymbolExport = DEFNODE("SymbolExport", null, function AST_SymbolExport(props) { if (props) { this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.quote = props.quote; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Symbol referring to a name to export", }, AST_SymbolRef); var AST_SymbolExportForeign = DEFNODE("SymbolExportForeign", null, function AST_SymbolExportForeign(props) { if (props) { this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.quote = props.quote; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $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, function AST_LabelRef(props) { if (props) { this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Reference to a label symbol", }, AST_Symbol); var AST_SymbolPrivateProperty = DEFNODE("SymbolPrivateProperty", null, function AST_SymbolPrivateProperty(props) { if (props) { this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A symbol that refers to a private property", }, AST_Symbol); var AST_This = DEFNODE("This", null, function AST_This(props) { if (props) { this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "The `this` symbol", }, AST_Symbol); var AST_Super = DEFNODE("Super", null, function AST_Super(props) { if (props) { this.scope = props.scope; this.name = props.name; this.thedef = props.thedef; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "The `super` symbol", }, AST_This); var AST_Constant = DEFNODE("Constant", null, function AST_Constant(props) { if (props) { this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Base class for all constants", getValue: function() { return this.value; } }); var AST_String = DEFNODE("String", "value quote", function AST_String(props) { if (props) { this.value = props.value; this.quote = props.quote; this.start = props.start; this.end = props.end; this._annotations = props._annotations; } this.flags = 0; }, { $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 raw", function AST_Number(props) { if (props) { this.value = props.value; this.raw = props.raw; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A number literal", $propdoc: { value: "[number] the numeric value", raw: "[string] numeric value as string" } }, AST_Constant); var AST_BigInt = DEFNODE("BigInt", "value", function AST_BigInt(props) { if (props) { this.value = props.value; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A big int literal", $propdoc: { value: "[string] big int value" } }, AST_Constant); var AST_RegExp = DEFNODE("RegExp", "value", function AST_RegExp(props) { if (props) { this.value = props.value; this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A regexp literal", $propdoc: { value: "[RegExp] the actual regexp", } }, AST_Constant); var AST_Atom = DEFNODE("Atom", null, function AST_Atom(props) { if (props) { this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Base class for atoms", }, AST_Constant); var AST_Null = DEFNODE("Null", null, function AST_Null(props) { if (props) { this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "The `null` atom", value: null }, AST_Atom); var AST_NaN = DEFNODE("NaN", null, function AST_NaN(props) { if (props) { this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "The impossible value", value: 0/0 }, AST_Atom); var AST_Undefined = DEFNODE("Undefined", null, function AST_Undefined(props) { if (props) { this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "The `undefined` value", value: (function() {}()) }, AST_Atom); var AST_Hole = DEFNODE("Hole", null, function AST_Hole(props) { if (props) { this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "A hole in an array", value: (function() {}()) }, AST_Atom); var AST_Infinity = DEFNODE("Infinity", null, function AST_Infinity(props) { if (props) { this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "The `Infinity` value", value: 1/0 }, AST_Atom); var AST_Boolean = DEFNODE("Boolean", null, function AST_Boolean(props) { if (props) { this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "Base class for booleans", }, AST_Atom); var AST_False = DEFNODE("False", null, function AST_False(props) { if (props) { this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "The `false` atom", value: false }, AST_Boolean); var AST_True = DEFNODE("True", null, function AST_True(props) { if (props) { this.start = props.start; this.end = props.end; } this.flags = 0; }, { $documentation: "The `true` atom", value: true }, AST_Boolean); /* -----[ Walk function ]---- */ /** * Walk nodes in depth-first search fashion. * Callback can return `walk_abort` symbol to stop iteration. * It can also return `true` to stop iteration just for child nodes. * Iteration can be stopped and continued by passing the `to_visit` argument, * which is given to the callback in the second argument. **/ function walk(node, cb, to_visit = [node]) { const push = to_visit.push.bind(to_visit); while (to_visit.length) { const node = to_visit.pop(); const ret = cb(node, to_visit); if (ret) { if (ret === walk_abort) return true; continue; } node._children_backwards(push); } return false; } /** * Walks an AST node and its children. * * {cb} can return `walk_abort` to interrupt the walk. * * @param node * @param cb {(node, info: { parent: (nth) => any }) => (boolean | undefined)} * * @returns {boolean} whether the walk was aborted * * @example * const found_some_cond = walk_parent(my_ast_node, (node, { parent }) => { * if (some_cond(node, parent())) return walk_abort * }); */ function walk_parent(node, cb, initial_stack) { const to_visit = [node]; const push = to_visit.push.bind(to_visit); const stack = initial_stack ? initial_stack.slice() : []; const parent_pop_indices = []; let current; const info = { parent: (n = 0) => { if (n === -1) { return current; } // [ p1 p0 ] [ 1 0 ] if (initial_stack && n >= stack.length) { n -= stack.length; return initial_stack[ initial_stack.length - (n + 1) ]; } return stack[stack.length - (1 + n)]; }, }; while (to_visit.length) { current = to_visit.pop(); while ( parent_pop_indices.length && to_visit.length == parent_pop_indices[parent_pop_indices.length - 1] ) { stack.pop(); parent_pop_indices.pop(); } const ret = cb(current, info); if (ret) { if (ret === walk_abort) return true; continue; } const visit_length = to_visit.length; current._children_backwards(push); // Push only if we're going to traverse the children if (to_visit.length > visit_length) { stack.push(current); parent_pop_indices.push(visit_length - 1); } } return false; } const walk_abort = Symbol("abort walk"); /* -----[ TreeWalker ]----- */ class TreeWalker { constructor(callback) { this.visit = callback; this.stack = []; this.directives = Object.create(null); } _visit(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(n) { return this.stack[this.stack.length - 2 - (n || 0)]; } push(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() { var node = this.stack.pop(); if (node instanceof AST_Lambda || node instanceof AST_Class) { this.directives = Object.getPrototypeOf(this.directives); } } self() { return this.stack[this.stack.length - 1]; } find_parent(type) { var stack = this.stack; for (var i = stack.length; --i >= 0;) { var x = stack[i]; if (x instanceof type) return x; } } find_scope() { var stack = this.stack; for (var i = stack.length; --i >= 0;) { const p = stack[i]; if (p instanceof AST_Toplevel) return p; if (p instanceof AST_Lambda) return p; if (p.block_scope) return p.block_scope; } } has_directive(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(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; } } const _PURE = 0b00000001; const _INLINE = 0b00000010; const _NOINLINE = 0b00000100; const _KEY = 0b00001000; const _MANGLEPROP = 0b00010000; 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_Chain, AST_Class, AST_ClassExpression, AST_ClassPrivateProperty, AST_PrivateIn, AST_ClassProperty, AST_ClassStaticBlock, 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_DotHash, 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_ImportMeta, 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_PrivateGetter, AST_PrivateMethod, AST_PrivateSetter, 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_SymbolClassProperty, 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_SymbolPrivateProperty, AST_This, AST_Throw, AST_Token, AST_Toplevel, AST_True, AST_Try, AST_TryBlock, AST_Unary, AST_UnaryPostfix, AST_UnaryPrefix, AST_Undefined, AST_Var, AST_VarDef, AST_While, AST_With, AST_Yield, // Walkers TreeTransformer, TreeWalker, walk, walk_abort, walk_body, walk_parent, // annotations _INLINE, _NOINLINE, _PURE, _KEY, _MANGLEPROP, }; terser-5.19.2/lib/cli.js000066400000000000000000000436761445647217600150270ustar00rootroot00000000000000import { minify, _default_options } from "../main.js"; import { parse } from "./parse.js"; import { AST_Assign, AST_Array, AST_Constant, AST_Node, AST_PropAccess, AST_RegExp, AST_Sequence, AST_Symbol, AST_Token, walk } from "./ast.js"; import { OutputStream } from "./output.js"; export async function run_cli({ program, packageJson, fs, path }) { const skip_keys = new Set([ "cname", "parent_scope", "scope", "uses_eval", "uses_with" ]); var files = {}; var options = { compress: false, mangle: false }; const default_options = await _default_options(); program.version(packageJson.name + " " + packageJson.version); program.parseArgv = program.parse; program.parse = undefined; if (process.argv.includes("ast")) program.helpInformation = describe_ast; else if (process.argv.includes("options")) program.helpInformation = function() { var text = []; for (var option in default_options) { text.push("--" + (option === "sourceMap" ? "source-map" : option) + " options:"); text.push(format_object(default_options[option])); text.push(""); } return text.join("\n"); }; program.option("-p, --parse ", "Specify parser options.", parse_js()); program.option("-c, --compress [options]", "Enable compressor/specify compressor options.", parse_js()); program.option("-m, --mangle [options]", "Mangle names/specify mangler options.", parse_js()); program.option("--mangle-props [options]", "Mangle properties/specify mangler options.", parse_js()); program.option("-f, --format [options]", "Format options.", parse_js()); program.option("-b, --beautify [options]", "Alias for --format.", parse_js()); program.option("-o, --output ", "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, 2015, 2016 or 2017..."); program.option("-e, --enclose [arg[,...][:value[,...]]]", "Embed output in a big function with configurable arguments and values."); program.option("--ie8", "Support non-standard Internet Explorer 8."); program.option("--keep-classnames", "Do not mangle/drop class names."); program.option("--keep-fnames", "Do not mangle/drop function names. Useful for code relying on Function.prototype.name."); program.option("--module", "Input is an ES6 module"); program.option("--name-cache ", "File to hold mangled name mappings."); program.option("--rename", "Force symbol expansion."); program.option("--no-rename", "Disable symbol expansion."); program.option("--safari10", "Support non-standard Safari 10."); program.option("--source-map [options]", "Enable source map/specify source map options.", parse_js()); program.option("--timings", "Display operations run time on STDERR."); program.option("--toplevel", "Compress and/or mangle variables in toplevel scope."); program.option("--wrap ", "Embed everything as a function with “exports” corresponding to “name” globally."); program.arguments("[files...]").parseArgv(process.argv); if (program.configFile) { options = JSON.parse(read_file(program.configFile)); } if (!program.output && program.sourceMap && program.sourceMap.url != "inline") { fatal("ERROR: cannot write source map to STDOUT"); } [ "compress", "enclose", "ie8", "mangle", "module", "safari10", "sourceMap", "toplevel", "wrap" ].forEach(function(name) { if (name in program) { options[name] = program[name]; } }); if ("ecma" in program) { if (program.ecma != (program.ecma | 0)) fatal("ERROR: ecma must be an integer"); const ecma = program.ecma | 0; if (ecma > 5 && ecma < 2015) options.ecma = ecma + 2009; else options.ecma = ecma; } if (program.format || program.beautify) { const chosenOption = program.format || program.beautify; options.format = typeof chosenOption === "object" ? chosenOption : {}; } if (program.comments) { if (typeof options.format != "object") options.format = {}; options.format.comments = typeof program.comments == "string" ? (program.comments == "false" ? false : program.comments) : "some"; } if (program.define) { if (typeof options.compress != "object") options.compress = {}; if (typeof options.compress.global_defs != "object") options.compress.global_defs = {}; for (var expr in program.define) { options.compress.global_defs[expr] = program.define[expr]; } } if (program.keepClassnames) { options.keep_classnames = true; } if (program.keepFnames) { options.keep_fnames = true; } if (program.mangleProps) { if (program.mangleProps.domprops) { delete program.mangleProps.domprops; } else { if (typeof program.mangleProps != "object") program.mangleProps = {}; if (!Array.isArray(program.mangleProps.reserved)) program.mangleProps.reserved = []; } if (typeof options.mangle != "object") options.mangle = {}; options.mangle.properties = program.mangleProps; } if (program.nameCache) { options.nameCache = JSON.parse(read_file(program.nameCache, "{}")); } if (program.output == "ast") { options.format = { ast: true, code: false }; } if (program.parse) { if (!program.parse.acorn && !program.parse.spidermonkey) { options.parse = program.parse; } else if (program.sourceMap && program.sourceMap.content == "inline") { fatal("ERROR: inline source map only works with built-in parser"); } } if (~program.rawArgs.indexOf("--rename")) { options.rename = true; } else if (!program.rename) { options.rename = false; } let convert_path = name => name; if (typeof program.sourceMap == "object" && "base" in program.sourceMap) { convert_path = function() { var base = program.sourceMap.base; delete options.sourceMap.base; return function(name) { return path.relative(base, name); }; }(); } let filesList; if (options.files && options.files.length) { filesList = options.files; delete options.files; } else if (program.args.length) { filesList = program.args; } if (filesList) { simple_glob(filesList).forEach(function(name) { files[convert_path(name)] = read_file(name); }); } else { await new Promise((resolve) => { var chunks = []; process.stdin.setEncoding("utf8"); process.stdin.on("data", function(chunk) { chunks.push(chunk); }).on("end", function() { files = [ chunks.join("") ]; resolve(); }); process.stdin.resume(); }); } await run_cli(); function convert_ast(fn) { return AST_Node.from_mozilla_ast(Object.keys(files).reduce(fn, null)); } async function run_cli() { var content = program.sourceMap && program.sourceMap.content; if (content && content !== "inline") { options.sourceMap.content = read_file(content, content); } if (program.timings) options.timings = true; try { if (program.parse) { if (program.parse.acorn) { files = convert_ast(function(toplevel, name) { return require("acorn").parse(files[name], { ecmaVersion: 2018, locations: true, program: toplevel, sourceFile: name, sourceType: options.module || program.parse.module ? "module" : "script" }); }); } else if (program.parse.spidermonkey) { files = convert_ast(function(toplevel, name) { var obj = JSON.parse(files[name]); if (!toplevel) return obj; toplevel.body = toplevel.body.concat(obj.body); return toplevel; }); } } } catch (ex) { fatal(ex); } let result; try { result = await minify(files, options, fs); } catch (ex) { if (ex.name == "SyntaxError") { print_error("Parse error at " + ex.filename + ":" + ex.line + "," + ex.col); var col = ex.col; var lines = files[ex.filename].split(/\r?\n/); var line = lines[ex.line - 1]; if (!line && !col) { line = lines[ex.line - 2]; col = line.length; } if (line) { var limit = 70; if (col > limit) { line = line.slice(col - limit); col = limit; } print_error(line.slice(0, 80)); print_error(line.slice(0, col).replace(/\S/g, " ") + "^"); } } if (ex.defs) { print_error("Supported options:"); print_error(format_object(ex.defs)); } fatal(ex); return; } if (program.output == "ast") { if (!options.compress && !options.mangle) { result.ast.figure_out_scope({}); } console.log(JSON.stringify(result.ast, function(key, value) { if (value) switch (key) { case "thedef": return symdef(value); case "enclosed": return value.length ? value.map(symdef) : undefined; case "variables": case "globals": return value.size ? collect_from_map(value, symdef) : undefined; } if (skip_keys.has(key)) return; if (value instanceof AST_Token) return; if (value instanceof Map) return; if (value instanceof AST_Node) { var result = { _class: "AST_" + value.TYPE }; if (value.block_scope) { result.variables = value.block_scope.variables; result.enclosed = value.block_scope.enclosed; } value.CTOR.PROPS.forEach(function(prop) { if (prop !== "block_scope") { result[prop] = value[prop]; } }); return result; } return value; }, 2)); } else if (program.output == "spidermonkey") { try { const minified = await minify( result.code, { compress: false, mangle: false, format: { ast: true, code: false } }, fs ); console.log(JSON.stringify(minified.ast.to_mozilla_ast(), null, 2)); } catch (ex) { fatal(ex); return; } } else if (program.output) { fs.writeFileSync(program.output, result.code); if (options.sourceMap && options.sourceMap.url !== "inline" && result.map) { fs.writeFileSync(program.output + ".map", result.map); } } else { console.log(result.code); } if (program.nameCache) { fs.writeFileSync(program.nameCache, JSON.stringify(options.nameCache)); } if (result.timings) for (var phase in result.timings) { print_error("- " + phase + ": " + result.timings[phase].toFixed(3) + "s"); } } function fatal(message) { if (message instanceof Error) message = message.stack.replace(/^\S*?Error:/, "ERROR:"); print_error(message); process.exit(1); } // A file glob function that only supports "*" and "?" wildcards in the basename. // Example: "foo/bar/*baz??.*.js" // Argument `glob` may be a string or an array of strings. // Returns an array of strings. Garbage in, garbage out. function simple_glob(glob) { if (Array.isArray(glob)) { return [].concat.apply([], glob.map(simple_glob)); } if (glob && glob.match(/[*?]/)) { var dir = path.dirname(glob); try { var entries = fs.readdirSync(dir); } catch (ex) {} if (entries) { var pattern = "^" + path.basename(glob) .replace(/[.+^$[\]\\(){}]/g, "\\$&") .replace(/\*/g, "[^/\\\\]*") .replace(/\?/g, "[^/\\\\]") + "$"; var mod = process.platform === "win32" ? "i" : ""; var rx = new RegExp(pattern, mod); var results = entries.filter(function(name) { return rx.test(name); }).map(function(name) { return path.join(dir, name); }); if (results.length) return results; } } return [ glob ]; } function read_file(path, default_value) { try { return fs.readFileSync(path, "utf8"); } catch (ex) { if ((ex.code == "ENOENT" || ex.code == "ENAMETOOLONG") && default_value != null) return default_value; fatal(ex); } } function parse_js(flag) { return function(value, options) { options = options || {}; try { walk(parse(value, { expression: true }), node => { if (node instanceof AST_Assign) { var name = node.left.print_to_string(); var value = node.right; if (flag) { options[name] = value; } else if (value instanceof AST_Array) { options[name] = value.elements.map(to_string); } else if (value instanceof AST_RegExp) { value = value.value; options[name] = new RegExp(value.source, value.flags); } else { options[name] = to_string(value); } return true; } if (node instanceof AST_Symbol || node instanceof AST_PropAccess) { var name = node.print_to_string(); options[name] = true; return true; } if (!(node instanceof AST_Sequence)) throw node; function to_string(value) { return value instanceof AST_Constant ? value.getValue() : value.print_to_string({ quote_keys: true }); } }); } catch(ex) { if (flag) { fatal("Error parsing arguments for '" + flag + "': " + value); } else { options[value] = null; } } return options; }; } function symdef(def) { var ret = (1e6 + def.id) + " " + def.name; if (def.mangled_name) ret += " " + def.mangled_name; return ret; } function collect_from_map(map, callback) { var result = []; map.forEach(function (def) { result.push(callback(def)); }); return result; } function format_object(obj) { var lines = []; var padding = ""; Object.keys(obj).map(function(name) { if (padding.length < name.length) padding = Array(name.length + 1).join(" "); return [ name, JSON.stringify(obj[name]) ]; }).forEach(function(tokens) { lines.push(" " + tokens[0] + padding.slice(tokens[0].length - 2) + tokens[1]); }); return lines.join("\n"); } function print_error(msg) { process.stderr.write(msg); process.stderr.write("\n"); } function describe_ast() { var out = OutputStream({ beautify: true }); function doitem(ctor) { out.print("AST_" + ctor.TYPE); const props = ctor.SELF_PROPS.filter(prop => !/^\$/.test(prop)); if (props.length > 0) { out.space(); out.with_parens(function() { props.forEach(function(prop, i) { if (i) out.space(); out.print(prop); }); }); } if (ctor.documentation) { out.space(); out.print_string(ctor.documentation); } if (ctor.SUBCLASSES.length > 0) { out.space(); out.with_block(function() { ctor.SUBCLASSES.forEach(function(ctor) { out.indent(); doitem(ctor); out.newline(); }); }); } } doitem(AST_Node); return out + "\n"; } } terser-5.19.2/lib/compress/000077500000000000000000000000001445647217600155355ustar00rootroot00000000000000terser-5.19.2/lib/compress/common.js000066400000000000000000000256261445647217600173760ustar00rootroot00000000000000/*********************************************************************** 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. ***********************************************************************/ import { AST_Array, AST_Arrow, AST_BlockStatement, AST_Call, AST_Chain, AST_Class, AST_Const, AST_Constant, AST_DefClass, AST_Defun, AST_EmptyStatement, AST_Export, AST_False, AST_Function, AST_Import, AST_Infinity, AST_LabeledStatement, AST_Lambda, AST_Let, AST_LoopControl, AST_NaN, AST_Node, AST_Null, AST_Number, AST_Object, AST_ObjectKeyVal, AST_PropAccess, AST_RegExp, AST_Scope, AST_Sequence, AST_SimpleStatement, AST_Statement, AST_String, AST_SymbolRef, AST_True, AST_UnaryPrefix, AST_Undefined, TreeWalker, walk, walk_abort, walk_parent, } from "../ast.js"; import { make_node, regexp_source_fix, string_template, makePredicate } from "../utils/index.js"; import { first_in_statement } from "../utils/first_in_statement.js"; import { has_flag, TOP } from "./compressor-flags.js"; export function merge_sequence(array, node) { if (node instanceof AST_Sequence) { array.push(...node.expressions); } else { array.push(node); } return array; } export function make_sequence(orig, expressions) { if (expressions.length == 1) return expressions[0]; if (expressions.length == 0) throw new Error("trying to create a sequence with length zero!"); return make_node(AST_Sequence, orig, { expressions: expressions.reduce(merge_sequence, []) }); } export 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: { source: regexp_source_fix(val.source), flags: val.flags } }); } throw new Error(string_template("Can't handle constant of type: {type}", { type: typeof val })); } } export function best_of_expression(ast1, ast2) { return ast1.size() > ast2.size() ? ast2 : ast1; } export 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; } /** Find which node is smaller, and return that */ export function best_of(compressor, ast1, ast2) { if (first_in_statement(compressor)) { return best_of_statement(ast1, ast2); } else { return best_of_expression(ast1, ast2); } } /** Simplify an object property's key, if possible */ export function get_simple_key(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; } export function read_property(obj, key) { key = get_simple_key(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; } export 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; } // we shouldn't compress (1,func)(something) to // func(something) because that changes the meaning of // the func (becomes lexical instead of global). export 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_Chain || val instanceof AST_PropAccess || val instanceof AST_SymbolRef && val.name == "eval" ) ) { const zero = make_node(AST_Number, orig, { value: 0 }); return make_sequence(orig, [ zero, val ]); } else { return val; } } export function is_func_expr(node) { return node instanceof AST_Arrow || node instanceof AST_Function; } /** * Used to determine whether the node can benefit from negation. * Not the case with arrow functions (you need an extra set of parens). */ export function is_iife_call(node) { if (node.TYPE != "Call") return false; return node.expression instanceof AST_Function || is_iife_call(node.expression); } export 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; } export const identifier_atom = makePredicate("Infinity NaN undefined"); export function is_identifier_atom(node) { return node instanceof AST_Infinity || node instanceof AST_NaN || node instanceof AST_Undefined; } /** Check if this is a SymbolRef node which has one def of a certain AST type */ export 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; } } /**Can we turn { block contents... } into just the block contents ? * Not if one of these is inside. **/ export 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 ); } export 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"); } export function is_reachable(scope_node, defs) { const find_ref = node => { if (node instanceof AST_SymbolRef && defs.includes(node.definition())) { return walk_abort; } }; return walk_parent(scope_node, (node, info) => { if (node instanceof AST_Scope && node !== scope_node) { var parent = info.parent(); if ( parent instanceof AST_Call && parent.expression === node // Async/Generators aren't guaranteed to sync evaluate all of // their body steps, so it's possible they close over the variable. && !(node.async || node.is_generator) ) { return; } if (walk(node, find_ref)) return walk_abort; return true; } }); } /** Check if a ref refers to the name of a function/class it's defined within */ export function is_recursive_ref(compressor, def) { var node; for (var i = 0; node = compressor.parent(i); i++) { if (node instanceof AST_Lambda || node instanceof AST_Class) { var name = node.name; if (name && name.definition() === def) { return true; } } } return false; } // TODO this only works with AST_Defun, shouldn't it work for other ways of defining functions? export function retain_top_func(fn, compressor) { return compressor.top_retain && fn instanceof AST_Defun && has_flag(fn, TOP) && fn.name && compressor.top_retain(fn.name); } terser-5.19.2/lib/compress/compressor-flags.js000066400000000000000000000053771445647217600213750ustar00rootroot00000000000000/*********************************************************************** 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. ***********************************************************************/ // bitfield flags to be stored in node.flags. // These are set and unset during compression, and store information in the node without requiring multiple fields. export const UNUSED = 0b00000001; export const TRUTHY = 0b00000010; export const FALSY = 0b00000100; export const UNDEFINED = 0b00001000; export const INLINED = 0b00010000; // Nodes to which values are ever written. Used when keep_assign is part of the unused option string. export const WRITE_ONLY = 0b00100000; // information specific to a single compression pass export const SQUEEZED = 0b0000000100000000; export const OPTIMIZED = 0b0000001000000000; export const TOP = 0b0000010000000000; export const CLEAR_BETWEEN_PASSES = SQUEEZED | OPTIMIZED | TOP; export const has_flag = (node, flag) => node.flags & flag; export const set_flag = (node, flag) => { node.flags |= flag; }; export const clear_flag = (node, flag) => { node.flags &= ~flag; }; terser-5.19.2/lib/compress/drop-side-effect-free.js000066400000000000000000000316461445647217600221440ustar00rootroot00000000000000/*********************************************************************** 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. ***********************************************************************/ import { AST_Accessor, AST_Array, AST_Arrow, AST_Assign, AST_Binary, AST_Call, AST_Chain, AST_Class, AST_ClassStaticBlock, AST_ClassProperty, AST_ConciseMethod, AST_Conditional, AST_Constant, AST_DefClass, AST_Dot, AST_Expansion, AST_Function, AST_Node, AST_Number, AST_Object, AST_ObjectGetter, AST_ObjectKeyVal, AST_ObjectProperty, AST_ObjectSetter, AST_PropAccess, AST_Scope, AST_Sequence, AST_SimpleStatement, AST_Sub, AST_SymbolRef, AST_TemplateSegment, AST_TemplateString, AST_This, AST_Unary, } from "../ast.js"; import { make_node, return_null, return_this } from "../utils/index.js"; import { first_in_statement } from "../utils/first_in_statement.js"; import { pure_prop_access_globals } from "./native-objects.js"; import { lazy_op, unary_side_effects, is_nullish_shortcircuited } from "./inference.js"; import { WRITE_ONLY, set_flag, clear_flag } from "./compressor-flags.js"; import { make_sequence, is_func_expr, is_iife_call } from "./common.js"; // AST_Node#drop_side_effect_free() gets called when we don't care about the value, // only about side effects. We'll be defining this method for each node type in this module // // Examples: // foo++ -> foo++ // 1 + func() -> func() // 10 -> (nothing) // knownPureFunc(foo++) -> foo++ function def_drop_side_effect_free(node, func) { node.DEFMETHOD("drop_side_effect_free", func); } // 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 (is_nullish_shortcircuited(this, compressor)) { return this.expression.drop_side_effect_free(compressor, first_in_statement); } if (!this.is_callee_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; } 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_Class, function (compressor) { const with_effects = []; const trimmed_extends = this.extends && this.extends.drop_side_effect_free(compressor); if (trimmed_extends) with_effects.push(trimmed_extends); for (const prop of this.properties) { if (prop instanceof AST_ClassStaticBlock) { if (prop.has_side_effects(compressor)) { return this; // Be cautious about these } } else { const trimmed_prop = prop.drop_side_effect_free(compressor); if (trimmed_prop) { if (trimmed_prop.contains_this()) return this; with_effects.push(trimmed_prop); } } } if (!with_effects.length) return null; const exprs = make_sequence(this, with_effects); if (this instanceof AST_DefClass) { // We want a statement return make_node(AST_SimpleStatement, this, { body: exprs }); } else { return exprs; } }); def_drop_side_effect_free(AST_ClassProperty, function (compressor) { const key = this.computed_key() && this.key.drop_side_effect_free(compressor); const value = this.static && this.value && this.value.drop_side_effect_free(compressor); if (key && value) return make_sequence(this, [key, value]); return key || value || 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) { if (this.logical) return this; 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; } set_flag(this, WRITE_ONLY); 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)) { if (!this.expression.has_side_effects(compressor)) { set_flag(this, WRITE_ONLY); } else { clear_flag(this, WRITE_ONLY); } 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) { const safe_access = this.is_declared(compressor) || pure_prop_access_globals.has(this.name); return safe_access ? 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) { const computed_key = this instanceof AST_ObjectKeyVal && this.key instanceof AST_Node; const key = computed_key && this.key.drop_side_effect_free(compressor, first_in_statement); const value = this.value && this.value.drop_side_effect_free(compressor, first_in_statement); if (key && value) { return make_sequence(this, [key, value]); } return key || value; }); def_drop_side_effect_free(AST_ConciseMethod, function () { return this.computed_key() ? this.key : null; }); def_drop_side_effect_free(AST_ObjectGetter, function () { return this.computed_key() ? this.key : null; }); def_drop_side_effect_free(AST_ObjectSetter, function () { return this.computed_key() ? this.key : null; }); 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 (is_nullish_shortcircuited(this, compressor)) { return this.expression.drop_side_effect_free(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 (is_nullish_shortcircuited(this, compressor)) { return this.expression.drop_side_effect_free(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_Chain, function (compressor, first_in_statement) { return this.expression.drop_side_effect_free(compressor, first_in_statement); }); 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); if (!expressions.length) { return make_node(AST_Number, this, { value: 0 }); } 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); }); terser-5.19.2/lib/compress/drop-unused.js000066400000000000000000000470551445647217600203530ustar00rootroot00000000000000/*********************************************************************** 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. ***********************************************************************/ import { AST_Accessor, AST_Assign, AST_BlockStatement, AST_Class, AST_ClassExpression, AST_ClassStaticBlock, AST_DefaultAssign, AST_DefClass, AST_Definitions, AST_Defun, AST_Destructuring, AST_EmptyStatement, AST_Expansion, AST_Export, AST_For, AST_ForIn, AST_Function, AST_LabeledStatement, AST_Lambda, AST_Number, AST_Scope, AST_SimpleStatement, AST_SymbolBlockDeclaration, AST_SymbolCatch, AST_SymbolDeclaration, AST_SymbolFunarg, AST_SymbolRef, AST_SymbolVar, AST_Toplevel, AST_Unary, AST_Var, TreeTransformer, TreeWalker, walk, _INLINE, _NOINLINE, _PURE } from "../ast.js"; import { keep_name, make_node, map_add, MAP, remove, return_false, } from "../utils/index.js"; import { SymbolDef } from "../scope.js"; import { WRITE_ONLY, UNUSED, has_flag, set_flag, } from "./compressor-flags.js"; import { make_sequence, maintain_this_binding, is_empty, is_ref_of, can_be_evicted_from_block, } from "./common.js"; const r_keep_assign = /keep_assign/; /** Drop unused variables from this scope */ 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; const assign_as_unused = r_keep_assign.test(compressor.option("unused")) ? return_false : function(node) { if (node instanceof AST_Assign && !node.logical && (has_flag(node, WRITE_ONLY) || node.operator == "=") ) { return node.left; } if (node instanceof AST_Unary && has_flag(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(); // 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_Class) { if (node.has_side_effects(compressor)) { node.visit_nondeferred_class_parts(tw); } } if (node instanceof AST_Defun || node instanceof AST_DefClass) { var node_def = node.name.definition(); const 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) { const 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) { walk(def.name, node => { if (node instanceof AST_SymbolDeclaration) { const def = node.definition(); if (def.global && !in_use_ids.has(def.id)) { in_use_ids.set(def.id, def); } } }); } if (def.name instanceof AST_Destructuring) { def.walk(tw); } if (def.name instanceof AST_SymbolDeclaration && def.value) { 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; } 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) { const 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 in_list ? MAP.skip : 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 of sorts if ( !(sym instanceof AST_Destructuring) && !in_use_ids.has(sym.definition().id) ) { set_flag(sym, UNUSED); if (trim) { a.pop(); } } else { trim = false; } } } if (node instanceof AST_DefClass && node !== self) { const def = node.name.definition(); descend(node, this); const keep_class = def.global && !drop_funcs || in_use_ids.has(def.id); if (!keep_class) { const kept = node.drop_side_effect_free(compressor); if (kept == null) { def.eliminated++; return in_list ? MAP.skip : make_node(AST_EmptyStatement, node); } return kept; } return node; } if (node instanceof AST_Defun && node !== self) { const def = node.name.definition(); const keep = def.global && !drop_funcs || in_use_ids.has(def.id); if (!keep) { def.eliminated++; return in_list ? MAP.skip : 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)) { 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: "=", logical: false, 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) { side_effects.push(value); } 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 }); } } // 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 && !(node instanceof AST_ClassStaticBlock)) { const save_scope = scope; scope = node; descend(node, this); scope = save_scope; return node; } } ); self.transform(tt); function scan_ref_scoped(node, descend) { var node_def; const 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.orig[0] instanceof AST_SymbolCatch) { const redef = node_def.scope.is_block_scope() && node_def.scope.get_defun_scope().variables.get(node_def.name); if (redef) in_use_ids.set(redef.id, redef); } } return true; } if (node instanceof AST_Class) { descend(); return true; } if (node instanceof AST_Scope && !(node instanceof AST_ClassStaticBlock)) { var save_scope = scope; scope = node; descend(); scope = save_scope; return true; } } }); terser-5.19.2/lib/compress/evaluate.js000066400000000000000000000370271445647217600177120ustar00rootroot00000000000000/*********************************************************************** 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. ***********************************************************************/ import { HOP, makePredicate, return_this, string_template, regexp_source_fix, regexp_is_safe, } from "../utils/index.js"; import { AST_Array, AST_BigInt, AST_Binary, AST_Call, AST_Chain, AST_Class, AST_Conditional, AST_Constant, AST_Dot, AST_Expansion, AST_Function, AST_Lambda, AST_New, AST_Node, AST_Object, AST_PropAccess, AST_RegExp, AST_Statement, AST_Symbol, AST_SymbolRef, AST_TemplateString, AST_UnaryPrefix, AST_With, } from "../ast.js"; import { is_undeclared_ref} from "./inference.js"; import { is_pure_native_value, is_pure_native_fn, is_pure_native_method } from "./native-objects.js"; // methods to evaluate a constant expression function def_eval(node, func) { node.DEFMETHOD("_eval", func); } // Used to propagate a nullish short-circuit signal upwards through the chain. export const nullish = Symbol("This AST_Chain is nullish"); // 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" || val == nullish) return this; // Evaluated strings can be larger than the original expression if (typeof val === "string") { const unevaluated_size = this.size(compressor); if (val.length + 2 > unevaluated_size) 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_BigInt, return_this); def_eval(AST_RegExp, function (compressor) { let evaluated = compressor.evaluated_regexps.get(this.value); if (evaluated === undefined && regexp_is_safe(this.value.source)) { try { const { source, flags } = this.value; evaluated = new RegExp(source, flags); } catch (e) { evaluated = null; } compressor.evaluated_regexps.set(this.value, evaluated); } return evaluated || this; }); 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 = () => this.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("&& || ?? === !=="); const identity_comparison = makePredicate("== != === !=="); const has_identity = value => typeof value === "object" || typeof value === "function" || typeof value === "symbol"; 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; if (left != null && right != null && identity_comparison.has(this.operator) && has_identity(left) && has_identity(right) && typeof left === typeof right) { // Do not compare by reference return this; } switch (this.operator) { case "&&": result = left && right; break; case "||": result = left || right; break; case "??": result = left != null ? 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; }); // Set of AST_SymbolRef which are currently being evaluated. // Avoids infinite recursion of ._eval() const reentrant_ref_eval = new Set(); def_eval(AST_SymbolRef, function (compressor, depth) { if (reentrant_ref_eval.has(this)) return this; var fixed = this.fixed_value(); if (!fixed) return this; reentrant_ref_eval.add(this); const value = fixed._eval(compressor, depth); reentrant_ref_eval.delete(this); if (value === fixed) return this; if (value && typeof value == "object") { var escaped = this.definition().escaped; if (escaped && depth > escaped) return this; } return value; }); const global_objs = { Array, Math, Number, Object, String }; const regexp_flags = new Set([ "dotAll", "global", "ignoreCase", "multiline", "sticky", "unicode", ]); def_eval(AST_PropAccess, function (compressor, depth) { let obj = this.expression._eval(compressor, depth + 1); if (obj === nullish || (this.optional && obj == null)) return nullish; // `.length` of strings and arrays is always safe if (this.property === "length") { if (typeof obj === "string") { return obj.length; } const is_spreadless_array = obj instanceof AST_Array && obj.elements.every(el => !(el instanceof AST_Expansion)); if ( is_spreadless_array && obj.elements.every(el => !el.has_side_effects(compressor)) ) { return obj.elements.length; } } 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; 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(); } if (!is_pure_native_value(exp.name, key)) return this; obj = global_objs[exp.name]; } else { if (obj instanceof RegExp) { if (key == "source") { return regexp_source_fix(obj.source); } else if (key == "flags" || regexp_flags.has(key)) { return obj[key]; } } if (!obj || obj === exp || !HOP(obj, key)) return this; if (typeof obj == "function") switch (key) { case "name": return obj.node.name ? obj.node.name.name : ""; case "length": return obj.node.length_property(); default: return this; } } return obj[key]; } return this; }); def_eval(AST_Chain, function (compressor, depth) { const evaluated = this.expression._eval(compressor, depth); return evaluated === nullish ? undefined : evaluated === this.expression ? this : evaluated; }); def_eval(AST_Call, function (compressor, depth) { var exp = this.expression; const callee = exp._eval(compressor, depth); if (callee === nullish || (this.optional && callee == null)) return nullish; 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(); } if (!is_pure_native_fn(e.name, key)) return this; val = global_objs[e.name]; } else { val = e._eval(compressor, depth + 1); if (val === e || !val) return this; if (!is_pure_native_method(val.constructor.name, 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; if (arg instanceof AST_Lambda) return this; args.push(value); } try { return val[key].apply(val, args); } catch (ex) { // We don't really care } } return this; }); // Also a subclass of AST_Call def_eval(AST_New, return_this); terser-5.19.2/lib/compress/index.js000066400000000000000000004216211445647217600172100ustar00rootroot00000000000000/*********************************************************************** 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. ***********************************************************************/ import { AST_Accessor, AST_Array, AST_Arrow, AST_Assign, AST_BigInt, AST_Binary, AST_Block, AST_BlockStatement, AST_Boolean, AST_Break, AST_Call, AST_Catch, AST_Chain, AST_Class, AST_ClassProperty, AST_ClassStaticBlock, AST_ConciseMethod, AST_Conditional, AST_Const, AST_Constant, AST_Debugger, AST_Default, AST_DefaultAssign, 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_For, AST_ForIn, AST_Function, AST_Hole, AST_If, AST_Import, AST_Infinity, AST_LabeledStatement, AST_Lambda, AST_Let, AST_NaN, AST_New, AST_Node, AST_Null, AST_Number, AST_Object, 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_SymbolClassProperty, AST_SymbolDeclaration, AST_SymbolDefun, AST_SymbolExport, AST_SymbolFunarg, AST_SymbolLambda, AST_SymbolLet, AST_SymbolMethod, AST_SymbolRef, 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, walk_abort, _INLINE, _NOINLINE, _PURE } from "../ast.js"; import { defaults, HOP, make_node, makePredicate, MAP, remove, return_false, return_true, regexp_source_fix, has_annotation, regexp_is_safe, } from "../utils/index.js"; import { first_in_statement } from "../utils/first_in_statement.js"; import { equivalent_to } from "../equivalent-to.js"; import { is_basic_identifier_string, JS_Parse_Error, parse, PRECEDENCE, } from "../parse.js"; import { OutputStream } from "../output.js"; import { base54, format_mangler_options } from "../scope.js"; import "../size.js"; import "./evaluate.js"; import "./drop-side-effect-free.js"; import "./drop-unused.js"; import "./reduce-vars.js"; import { is_undeclared_ref, lazy_op, is_nullish, is_undefined, is_lhs, aborts, } from "./inference.js"; import { SQUEEZED, OPTIMIZED, CLEAR_BETWEEN_PASSES, TOP, UNDEFINED, UNUSED, TRUTHY, FALSY, has_flag, set_flag, clear_flag, } from "./compressor-flags.js"; import { make_sequence, best_of, best_of_expression, make_node_from_constant, merge_sequence, get_simple_key, has_break_or_continue, maintain_this_binding, is_empty, is_identifier_atom, is_reachable, can_be_evicted_from_block, as_statement_array, retain_top_func, is_func_expr, } from "./common.js"; import { tighten_body, trim_unreachable_code } from "./tighten-body.js"; import { inline_into_symbolref, inline_into_call } from "./inline.js"; class Compressor extends TreeWalker { constructor(options, { false_by_default = false, mangle_options = false }) { 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, lhs_constants : !false_by_default, 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_symbols: false, unsafe_methods: false, unsafe_proto : false, unsafe_regexp : false, unsafe_undefined: false, unused : !false_by_default, warnings : false // legacy }, 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.evaluated_regexps = new Map(); this._toplevel = undefined; this.mangle_options = mangle_options ? format_mangler_options(mangle_options) : mangle_options; } 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.operator == "??" ) || p instanceof AST_Conditional || p.tail_node() === self ) { self = p; } else { return false; } } } get_toplevel() { return this._toplevel; } compress(toplevel) { toplevel = toplevel.resolve_defines(this); this._toplevel = toplevel; if (this.option("expression")) { this._toplevel.process_expression(true); } var passes = +this.options.passes || 1; var min_count = 1 / 0; var stopping = false; var nth_identifier = this.mangle_options && this.mangle_options.nth_identifier || base54; var mangle = { ie8: this.option("ie8"), nth_identifier: nth_identifier }; for (var pass = 0; pass < passes; pass++) { this._toplevel.figure_out_scope(mangle); if (pass === 0 && this.option("drop_console")) { // must be run before reduce_vars and compress pass this._toplevel = this._toplevel.drop_console(); } if (pass > 0 || this.option("reduce_vars")) { this._toplevel.reset_opt_flags(this); } this._toplevel = this._toplevel.transform(this); if (passes > 1) { let count = 0; walk(this._toplevel, () => { count++; }); if (count < min_count) { min_count = count; stopping = false; } else if (stopping) { break; } else { stopping = true; } } } if (this.option("expression")) { this._toplevel.process_expression(false); } toplevel = this._toplevel; this._toplevel = undefined; return toplevel; } before(node, descend) { if (has_flag(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) set_flag(opt, SQUEEZED); return opt; } /** Alternative to plain is_lhs() which doesn't work within .optimize() */ is_lhs() { const self = this.stack[this.stack.length - 1]; const parent = this.stack[this.stack.length - 2]; return is_lhs(self, parent); } } function def_optimize(node, optimizer) { node.DEFMETHOD("optimize", function(compressor) { var self = this; if (has_flag(self, OPTIMIZED)) return self; if (compressor.has_directive("use asm")) return self; var opt = optimizer(self, compressor); set_flag(opt, OPTIMIZED); return opt; }); } def_optimize(AST_Node, function(self) { 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 equivalent_to(this, node); }); 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); }); AST_Toplevel.DEFMETHOD("reset_opt_flags", function(compressor) { const self = this; const reduce_vars = compressor.option("reduce_vars"); const preparation = new TreeWalker(function(node, descend) { clear_flag(node, CLEAR_BETWEEN_PASSES); if (reduce_vars) { if (compressor.top_retain && node instanceof AST_Defun // Only functions are retained && preparation.parent() === self ) { set_flag(node, TOP); } return node.reduce_vars(preparation, 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 preparation.safe_ids = Object.create(null); preparation.in_loop = null; preparation.loop_ids = new Map(); preparation.defs_to_safe_ids = new Map(); self.walk(preparation); }); AST_Symbol.DEFMETHOD("fixed_value", function() { var fixed = this.thedef.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 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); } 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); }); /* -----[ optimizers ]----- */ var directives = new Set(["use asm", "use strict"]); def_optimize(AST_Directive, function(self, compressor) { if (compressor.option("directives") && (!directives.has(self.value) || 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("hoist_declarations", function(compressor) { var self = this; if (compressor.has_directive("use asm")) 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. walk(self, 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.some(def => def.name instanceof AST_Destructuring) ) { node.definitions.forEach(function(def) { 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) { self.body.splice(i, 1, ...self.body[i].body); 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("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 hoister = new TreeTransformer(function(node, descend) { if (node instanceof AST_VarDef) { const sym = node.name; let def; let 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 && !value.properties.some(prop => prop instanceof AST_Expansion || prop.computed_key() ) ) { descend(node, this); const defs = new Map(); const assignments = []; value.properties.forEach(({ key, value }) => { const scope = hoister.find_scope(); const symbol = self.create_symbol(sym.CTOR, { source: sym, scope, conflict_scopes: new Set([ scope, ...sym.definition().references.map(ref => ref.scope) ]), tentative_name: sym.name + "_" + key }); defs.set(String(key), symbol.definition()); assignments.push(make_node(AST_VarDef, node, { name: symbol, value })); }); defs_by_id.set(def.id, defs); return MAP.splice(assignments); } } else if (node instanceof AST_PropAccess && node.expression instanceof AST_SymbolRef ) { const defs = defs_by_id.get(node.expression.definition().id); if (defs) { const def = defs.get(String(get_simple_key(node.property))); const sym = make_node(AST_SymbolRef, node, { name: def.name, scope: node.expression.scope, thedef: def }); sym.reference({}); return sym; } } }); return self.transform(hoister); }); def_optimize(AST_SimpleStatement, function(self, compressor) { if (compressor.option("side_effects")) { var body = self.body; var node = body.drop_side_effect_free(compressor, true); if (!node) { 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; }); 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 })); } trim_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 = []; trim_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, 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) { var body = []; trim_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)) { var body = []; body.push(make_node(AST_SimpleStatement, self.condition, { body: self.condition })); body.push(self.body); if (self.alternative) { trim_unreachable_code(compressor, self.alternative, body); } return make_node(AST_BlockStatement, self, { body: body }).optimize(compressor); } } var negated = self.condition.negate(compressor); var self_condition_length = self.condition.size(); var negated_length = negated.size(); 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; } } } body.push(branch); } while (i < len) eliminate_branch(self.body[i++], body[body.length - 1]); self.body = body; let default_or_exact = default_branch || exact_match; default_branch = null; exact_match = null; // group equivalent branches so they will be located next to each other, // that way the next micro-optimization will merge them. // ** bail micro-optimization if not a simple switch case with breaks if (body.every((branch, i) => (branch === default_or_exact || branch.expression instanceof AST_Constant) && (branch.body.length === 0 || aborts(branch) || body.length - 1 === i)) ) { for (let i = 0; i < body.length; i++) { const branch = body[i]; for (let j = i + 1; j < body.length; j++) { const next = body[j]; if (next.body.length === 0) continue; const last_branch = j === (body.length - 1); const equivalentBranch = branches_equivalent(next, branch, false); if (equivalentBranch || (last_branch && branches_equivalent(next, branch, true))) { if (!equivalentBranch && last_branch) { next.body.push(make_node(AST_Break)); } // let's find previous siblings with inert fallthrough... let x = j - 1; let fallthroughDepth = 0; while (x > i) { if (is_inert_body(body[x--])) { fallthroughDepth++; } else { break; } } const plucked = body.splice(j - fallthroughDepth, 1 + fallthroughDepth); body.splice(i + 1, 0, ...plucked); i += plucked.length; } } } } // merge equivalent branches in a row for (let i = 0; i < body.length; i++) { let branch = body[i]; if (branch.body.length === 0) continue; if (!aborts(branch)) continue; for (let j = i + 1; j < body.length; i++, j++) { let next = body[j]; if (next.body.length === 0) continue; if ( branches_equivalent(next, branch, false) || (j === body.length - 1 && branches_equivalent(next, branch, true)) ) { branch.body = []; branch = next; continue; } break; } } // Prune any empty branches at the end of the switch statement. { let i = body.length - 1; for (; i >= 0; i--) { let bbody = body[i].body; if (is_break(bbody[bbody.length - 1], compressor)) bbody.pop(); if (!is_inert_body(body[i])) break; } // i now points to the index of a branch that contains a body. By incrementing, it's // pointing to the first branch that's empty. i++; if (!default_or_exact || body.indexOf(default_or_exact) >= i) { // The default behavior is to do nothing. We can take advantage of that to // remove all case expressions that are side-effect free that also do // nothing, since they'll default to doing nothing. But we can't remove any // case expressions before one that would side-effect, since they may cause // the side-effect to be skipped. for (let j = body.length - 1; j >= i; j--) { let branch = body[j]; if (branch === default_or_exact) { default_or_exact = null; body.pop(); } else if (!branch.expression.has_side_effects(compressor)) { body.pop(); } else { break; } } } } // Prune side-effect free branches that fall into default. DEFAULT: if (default_or_exact) { let default_index = body.indexOf(default_or_exact); let default_body_index = default_index; for (; default_body_index < body.length - 1; default_body_index++) { if (!is_inert_body(body[default_body_index])) break; } if (default_body_index < body.length - 1) { break DEFAULT; } let side_effect_index = body.length - 1; for (; side_effect_index >= 0; side_effect_index--) { let branch = body[side_effect_index]; if (branch === default_or_exact) continue; if (branch.expression.has_side_effects(compressor)) break; } // If the default behavior comes after any side-effect case expressions, // then we can fold all side-effect free cases into the default branch. // If the side-effect case is after the default, then any side-effect // free cases could prevent the side-effect from occurring. if (default_body_index > side_effect_index) { let prev_body_index = default_index - 1; for (; prev_body_index >= 0; prev_body_index--) { if (!is_inert_body(body[prev_body_index])) break; } let before = Math.max(side_effect_index, prev_body_index) + 1; let after = default_index; if (side_effect_index > default_index) { // If the default falls into the same body as a side-effect // case, then we need preserve that case and only prune the // cases after it. after = side_effect_index; body[side_effect_index].body = body[default_body_index].body; } else { // The default will be the last branch. default_or_exact.body = body[default_body_index].body; } // Prune everything after the default (or last side-effect case) // until the next case with a body. body.splice(after + 1, default_body_index - after); // Prune everything before the default that falls into it. body.splice(before, default_index - before); } } // See if we can remove the switch entirely if all cases (the default) fall into the same case body. DEFAULT: if (default_or_exact) { let i = body.findIndex(branch => !is_inert_body(branch)); let caseBody; // `i` is equal to one of the following: // - `-1`, there is no body in the switch statement. // - `body.length - 1`, all cases fall into the same body. // - anything else, there are multiple bodies in the switch. if (i === body.length - 1) { // All cases fall into the case body. let branch = body[i]; if (has_nested_break(self)) break DEFAULT; // This is the last case body, and we've already pruned any breaks, so it's // safe to hoist. caseBody = make_node(AST_BlockStatement, branch, { body: branch.body }); branch.body = []; } else if (i !== -1) { // If there are multiple bodies, then we cannot optimize anything. break DEFAULT; } let sideEffect = body.find(branch => { return ( branch !== default_or_exact && branch.expression.has_side_effects(compressor) ); }); // If no cases cause a side-effect, we can eliminate the switch entirely. if (!sideEffect) { return make_node(AST_BlockStatement, self, { body: decl.concat( statement(self.expression), default_or_exact.expression ? statement(default_or_exact.expression) : [], caseBody || [] ) }).optimize(compressor); } // If we're this far, either there was no body or all cases fell into the same body. // If there was no body, then we don't need a default branch (because the default is // do nothing). If there was a body, we'll extract it to after the switch, so the // switch's new default is to do nothing and we can still prune it. const default_index = body.indexOf(default_or_exact); body.splice(default_index, 1); default_or_exact = null; if (caseBody) { // Recurse into switch statement one more time so that we can append the case body // outside of the switch. This recursion will only happen once since we've pruned // the default case. return make_node(AST_BlockStatement, self, { body: decl.concat(self, caseBody) }).optimize(compressor); } // If we fall here, there is a default branch somewhere, there are no case bodies, // and there's a side-effect somewhere. Just let the below paths take care of it. } if (body.length > 0) { body[0].body = decl.concat(body[0].body); } if (body.length == 0) { return make_node(AST_BlockStatement, self, { body: decl.concat(statement(self.expression)) }).optimize(compressor); } if (body.length == 1 && !has_nested_break(self)) { // This is the last case body, and we've already pruned any breaks, so it's // safe to hoist. let branch = body[0]; return make_node(AST_If, self, { condition: make_node(AST_Binary, self, { operator: "===", left: self.expression, right: branch.expression, }), body: make_node(AST_BlockStatement, branch, { body: branch.body }), alternative: null }).optimize(compressor); } if (body.length === 2 && default_or_exact && !has_nested_break(self)) { let branch = body[0] === default_or_exact ? body[1] : body[0]; let exact_exp = default_or_exact.expression && statement(default_or_exact.expression); if (aborts(body[0])) { // Only the first branch body could have a break (at the last statement) let first = body[0]; if (is_break(first.body[first.body.length - 1], compressor)) { first.body.pop(); } return make_node(AST_If, self, { condition: make_node(AST_Binary, self, { operator: "===", left: self.expression, right: branch.expression, }), body: make_node(AST_BlockStatement, branch, { body: branch.body }), alternative: make_node(AST_BlockStatement, default_or_exact, { body: [].concat( exact_exp || [], default_or_exact.body ) }) }).optimize(compressor); } let operator = "==="; let consequent = make_node(AST_BlockStatement, branch, { body: branch.body, }); let always = make_node(AST_BlockStatement, default_or_exact, { body: [].concat( exact_exp || [], default_or_exact.body ) }); if (body[0] === default_or_exact) { operator = "!=="; let tmp = always; always = consequent; consequent = tmp; } return make_node(AST_BlockStatement, self, { body: [ make_node(AST_If, self, { condition: make_node(AST_Binary, self, { operator: operator, left: self.expression, right: branch.expression, }), body: consequent, alternative: null }) ].concat(always) }).optimize(compressor); } return self; function eliminate_branch(branch, prev) { if (prev && !aborts(prev)) { prev.body = prev.body.concat(branch.body); } else { trim_unreachable_code(compressor, branch, decl); } } function branches_equivalent(branch, prev, insertBreak) { let bbody = branch.body; let pbody = prev.body; if (insertBreak) { bbody = bbody.concat(make_node(AST_Break)); } if (bbody.length !== pbody.length) return false; let bblock = make_node(AST_BlockStatement, branch, { body: bbody }); let pblock = make_node(AST_BlockStatement, prev, { body: pbody }); return bblock.equivalent_to(pblock); } function statement(expression) { return make_node(AST_SimpleStatement, expression, { body: expression }); } function has_nested_break(root) { let has_break = false; let tw = new TreeWalker(node => { if (has_break) return true; if (node instanceof AST_Lambda) return true; if (node instanceof AST_SimpleStatement) return true; if (!is_break(node, tw)) return; let parent = tw.parent(); if ( parent instanceof AST_SwitchBranch && parent.body[parent.body.length - 1] === node ) { return; } has_break = true; }); root.walk(tw); return has_break; } function is_break(node, stack) { return node instanceof AST_Break && stack.loopcontrol_target(node) === self; } function is_inert_body(branch) { return !aborts(branch) && !make_node(AST_BlockStatement, branch, { body: branch.body }).has_side_effects(compressor); } }); def_optimize(AST_Try, function(self, compressor) { if (self.bcatch && self.bfinally && self.bfinally.body.every(is_empty)) self.bfinally = null; if (compressor.option("dead_code") && self.body.body.every(is_empty)) { var body = []; if (self.bcatch) { trim_unreachable_code(compressor, self.bcatch, body); } if (self.bfinally) body.push(...self.bfinally.body); return make_node(AST_BlockStatement, self, { body: body }).optimize(compressor); } return self; }); AST_Definitions.DEFMETHOD("to_assignments", function(compressor) { var reduce_vars = compressor.option("reduce_vars"); var assignments = []; for (const def of this.definitions) { if (def.value) { var name = make_node(AST_SymbolRef, def.name, def.name); assignments.push(make_node(AST_Assign, def, { operator : "=", logical: false, left : name, right : def.value })); if (reduce_vars) name.definition().fixed = false; } const thedef = def.name.definition(); thedef.eliminated++; thedef.replaced--; } if (assignments.length == 0) return null; return make_sequence(this, assignments); }); def_optimize(AST_Definitions, function(self) { if (self.definitions.length == 0) { return make_node(AST_EmptyStatement, self); } return self; }); def_optimize(AST_VarDef, function(self, compressor) { if ( self.name instanceof AST_SymbolLet && self.value != null && is_undefined(self.value, compressor) ) { self.value = null; } return self; }); def_optimize(AST_Import, function(self) { return self; }); def_optimize(AST_Call, function(self, compressor) { var exp = self.expression; var fn = exp; inline_array_like_spread(self.args); var simple_args = self.args.every((arg) => !(arg instanceof AST_Expansion) ); if (compressor.option("reduce_vars") && fn instanceof AST_SymbolRef && !has_annotation(self, _NOINLINE) ) { const fixed = fn.fixed_value(); if (!retain_top_func(fixed, compressor)) { fn = fixed; } } var is_func = fn instanceof AST_Lambda; if (is_func && fn.pinned()) return self; if (compressor.option("unused") && simple_args && is_func && !fn.uses_arguments) { var pos = 0, last = 0; for (var i = 0, len = self.args.length; i < len; i++) { if (fn.argnames[i] instanceof AST_Expansion) { if (has_flag(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 || has_flag(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 (exp instanceof AST_Dot && exp.start.value === "Array" && exp.property === "from" && self.args.length === 1) { const [argument] = self.args; if (argument instanceof AST_Array) { return make_node(AST_Array, argument, { elements: argument.elements }).optimize(compressor); } } 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 && compressor.option("unsafe_math")) { return make_node(AST_UnaryPrefix, self, { expression: self.args[0], operator: "+" }).optimize(compressor); } break; case "Symbol": if (self.args.length == 1 && self.args[0] instanceof AST_String && compressor.option("unsafe_symbols")) self.args.length = 0; break; 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.length >= 1 && self.args.length <= 2 && self.args.every((arg) => { var value = arg.evaluate(compressor); params.push(value); return arg !== value; }) && regexp_is_safe(params[0]) ) { let [ source, flags ] = params; source = regexp_source_fix(new RegExp(source).source); const rx = make_node(AST_RegExp, self, { value: { source, flags } }); if (rx._eval(compressor) !== rx) { return rx; } } 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, optional: false, 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); var nth_identifier = compressor.mangle_options && compressor.mangle_options.nth_identifier || base54; 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"), nth_identifier: nth_identifier }; ast.figure_out_scope(mangle); var comp = new Compressor(compressor.options, { mangle_options: compressor.mangle_options }); ast = ast.transform(comp); ast.figure_out_scope(mangle); ast.compute_char_frequency(mangle); ast.mangle_names(mangle); var fun; walk(ast, node => { if (is_func_expr(node)) { fun = node; return walk_abort; } }); 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)) { throw ex; } // Otherwise, it crashes at runtime. Or maybe it's nonstandard syntax. } } } return inline_into_call(self, fn, compressor); }); 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 || e instanceof AST_Chain || is_identifier_atom(e) ) ) { 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 // And we don't need to check if it's undeclared, because in typeof, that's OK 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 (compressor.option("lhs_constants") && 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); // x == void 0 => x == null } else if (!is_strict_comparison && is_undefined(self.right, compressor)) { self.right = make_node(AST_Null, self.right); } 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 (compressor.option("typeofs") // typeof x === "undefined" => x === undefined && self.left instanceof AST_UnaryPrefix && self.left.operator == "typeof" && self.right instanceof AST_String && self.right.value == "undefined") { var expr = self.left.expression; if (expr instanceof AST_SymbolRef ? expr.is_declared(compressor) : !(expr instanceof AST_PropAccess && compressor.option("ie8"))) { self.left = expr; self.right = make_node(AST_Undefined, self.right).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") { return make_sequence(self, [ self.right, make_node(AST_True, self) ]).optimize(compressor); } if (rr && typeof rr == "string") { 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; } } if (compressor.option("evaluate")) { switch (self.operator) { case "&&": var ll = has_flag(self.left, TRUTHY) ? true : has_flag(self.left, FALSY) ? false : self.left.evaluate(compressor); if (!ll) { return maintain_this_binding(compressor.parent(), compressor.self(), self.left).optimize(compressor); } else if (!(ll instanceof AST_Node)) { return make_sequence(self, [ self.left, self.right ]).optimize(compressor); } var rr = self.right.evaluate(compressor); if (!rr) { if (compressor.in_boolean_context()) { return make_sequence(self, [ self.left, make_node(AST_False, self) ]).optimize(compressor); } else { set_flag(self, FALSY); } } else if (!(rr instanceof AST_Node)) { var parent = compressor.parent(); if (parent.operator == "&&" && parent.left === compressor.self() || compressor.in_boolean_context()) { 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 = has_flag(self.left, TRUTHY) ? true : has_flag(self.left, FALSY) ? false : self.left.evaluate(compressor); if (!ll) { return make_sequence(self, [ self.left, self.right ]).optimize(compressor); } else if (!(ll instanceof AST_Node)) { 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()) { return self.left.optimize(compressor); } } else if (!(rr instanceof AST_Node)) { if (compressor.in_boolean_context()) { return make_sequence(self, [ self.left, make_node(AST_True, self) ]).optimize(compressor); } else { set_flag(self, TRUTHY); } } 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; case "??": if (is_nullish(self.left, compressor)) { return self.right; } var ll = self.left.evaluate(compressor); if (!(ll instanceof AST_Node)) { // if we know the value for sure we can simply compute right away. return ll == null ? self.right : self.left; } if (compressor.in_boolean_context()) { const rr = self.right.evaluate(compressor); if (!(rr instanceof AST_Node) && !rr) { return self.left; } } } var associative = true; switch (self.operator) { case "+": // (x + "foo") + "bar" => x + "foobar" if (self.right instanceof AST_Constant && self.left instanceof AST_Binary && self.left.operator == "+" && self.left.is_string(compressor)) { var binary = make_node(AST_Binary, self, { operator: "+", left: self.left.right, right: self.right, }); var r = binary.optimize(compressor); if (binary !== r) { self = make_node(AST_Binary, self, { operator: "+", left: self.left.left, right: r }); } } // (x + "foo") + ("bar" + y) => (x + "foobar") + y if (self.left instanceof AST_Binary && self.left.operator == "+" && self.left.is_string(compressor) && self.right instanceof AST_Binary && self.right.operator == "+" && self.right.is_string(compressor)) { var binary = make_node(AST_Binary, self, { operator: "+", left: self.left.right, right: self.right.left, }); var m = binary.optimize(compressor); if (binary !== m) { self = make_node(AST_Binary, self, { operator: "+", left: make_node(AST_Binary, self.left, { operator: "+", left: self.left.left, right: m }), 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; } // `foo${bar}baz` + 1 => `foo${bar}baz1` if (self.left instanceof AST_TemplateString) { var l = self.left; var r = self.right.evaluate(compressor); if (r != self.right) { l.segments[l.segments.length - 1].value += String(r); return l; } } // 1 + `foo${bar}baz` => `1foo${bar}baz` if (self.right instanceof AST_TemplateString) { var r = self.right; var l = self.left.evaluate(compressor); if (l != self.left) { r.segments[0].value = String(l) + r.segments[0].value; return r; } } // `1${bar}2` + `foo${bar}baz` => `1${bar}2foo${bar}baz` if (self.left instanceof AST_TemplateString && self.right instanceof AST_TemplateString) { var l = self.left; var segments = l.segments; var r = self.right; segments[segments.length - 1].value += r.segments[0].value; for (var i = 1; i < r.segments.length; i++) { segments.push(r.segments[i]); } return l; } 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.transform(compressor), right : self.right.left.transform(compressor) }); self.right = self.right.right.transform(compressor); 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) { return self; }); def_optimize(AST_SymbolRef, function(self, compressor) { if ( !compressor.option("ie8") && is_undeclared_ref(self) && !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); } } if (compressor.option("reduce_vars") && !compressor.is_lhs()) { return inline_into_symbolref(self, compressor); } else { return self; } }); 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 }); set_flag(ref, UNDEFINED); return ref; } } var lhs = compressor.is_lhs(); 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 = compressor.is_lhs(); 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 = compressor.is_lhs(); 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; }); const ASSIGN_OPS = makePredicate("+ - / * % >> << >>> | ^ &"); const ASSIGN_OPS_COMMUTATIVE = makePredicate("* | ^ &"); def_optimize(AST_Assign, function(self, compressor) { if (self.logical) { return self.lift_sequences(compressor); } var def; // x = x ---> x if ( self.operator === "=" && self.left instanceof AST_SymbolRef && self.left.name !== "arguments" && !(def = self.left.definition()).undeclared && self.right.equivalent_to(self.left) ) { return self.right; } 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) { function may_assignment_throw() { const right = self.right; self.right = make_node(AST_Null, right); const may_throw = node.may_throw(compressor); self.right = right; return may_throw; } var stop_at = self.left.definition().scope.get_defun_scope(); var parent; while ((parent = compressor.parent(level++)) !== stop_at) { if (parent instanceof AST_Try) { if (parent.bfinally) return true; if (parent.bcatch && may_assignment_throw()) 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` // `(arg = undefined) => ...` ---> `(arg) => ...` (unless `keep_fargs`) // `((arg = undefined) => ...)()` ---> `((arg) => ...)()` let lambda, iife; if (evaluateRight === undefined) { if ( (lambda = compressor.parent()) instanceof AST_Lambda ? ( compressor.option("keep_fargs") === false || (iife = compressor.parent(1)).TYPE === "Call" && iife.expression === lambda ) : true ) { 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; }); function is_nullish_check(check, check_subject, compressor) { if (check_subject.may_throw(compressor)) return false; let nullish_side; // foo == null if ( check instanceof AST_Binary && check.operator === "==" // which side is nullish? && ( (nullish_side = is_nullish(check.left, compressor) && check.left) || (nullish_side = is_nullish(check.right, compressor) && check.right) ) // is the other side the same as the check_subject && ( nullish_side === check.left ? check.right : check.left ).equivalent_to(check_subject) ) { return true; } // foo === null || foo === undefined if (check instanceof AST_Binary && check.operator === "||") { let null_cmp; let undefined_cmp; const find_comparison = cmp => { if (!( cmp instanceof AST_Binary && (cmp.operator === "===" || cmp.operator === "==") )) { return false; } let found = 0; let defined_side; if (cmp.left instanceof AST_Null) { found++; null_cmp = cmp; defined_side = cmp.right; } if (cmp.right instanceof AST_Null) { found++; null_cmp = cmp; defined_side = cmp.left; } if (is_undefined(cmp.left, compressor)) { found++; undefined_cmp = cmp; defined_side = cmp.right; } if (is_undefined(cmp.right, compressor)) { found++; undefined_cmp = cmp; defined_side = cmp.left; } if (found !== 1) { return false; } if (!defined_side.equivalent_to(check_subject)) { return false; } return true; }; if (!find_comparison(check.left)) return false; if (!find_comparison(check.right)) return false; if (null_cmp && undefined_cmp && null_cmp !== undefined_cmp) { return true; } } return false; } 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) { return maintain_this_binding(compressor.parent(), compressor.self(), self.consequent); } else { 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.logical === alternative.logical && 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, logical: consequent.logical, 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; } // a ? b : c ? b : d --> (a || c) ? b : d if (alternative instanceof AST_Conditional && consequent.equivalent_to(alternative.consequent)) { return make_node(AST_Conditional, self, { condition: make_node(AST_Binary, self, { operator: "||", left: condition, right: alternative.condition }), consequent: consequent, alternative: alternative.alternative }).optimize(compressor); } // a == null ? b : a -> a ?? b if ( compressor.option("ecma") >= 2020 && is_nullish_check(condition, alternative, compressor) ) { return make_node(AST_Binary, self, { operator: "??", left: alternative, right: consequent }).optimize(compressor); } // a ? b : (c, b) --> (a || c), b if (alternative instanceof AST_Sequence && consequent.equivalent_to(alternative.expressions[alternative.expressions.length - 1])) { return make_sequence(self, [ make_node(AST_Binary, self, { operator: "||", left: condition, right: make_sequence(self, alternative.expressions.slice(0, -1)) }), consequent ]).optimize(compressor); } // a ? b : (c && b) --> (a || c) && b if (alternative instanceof AST_Binary && alternative.operator == "&&" && consequent.equivalent_to(alternative.right)) { return make_node(AST_Binary, self, { operator: "&&", left: make_node(AST_Binary, self, { operator: "||", left: condition, right: alternative.left }), right: consequent }).optimize(compressor); } // 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); } const 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 == "!=")) { 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; if (!(value instanceof AST_Lambda || value instanceof AST_Class)) return true; if (!(value instanceof AST_Lambda && value.contains_this())) return true; return compressor.parent() instanceof AST_New; } AST_PropAccess.DEFMETHOD("flatten_object", function(key, compressor) { if (!compressor.option("properties")) return; if (key === "__proto__") return; var arrows = compressor.option("unsafe_arrows") && compressor.option("ecma") >= 2015; 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) { const all_props_flattenable = props.every((p) => (p instanceof AST_ObjectKeyVal || arrows && p instanceof AST_ConciseMethod && !p.is_generator ) && !p.computed_key() ); if (!all_props_flattenable) return; if (!safe_to_flatten(prop.value, compressor)) return; 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_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_basic_identifier_string(property) && property.length <= prop.size() + 1) { return make_node(AST_Dot, self, { expression: expr, optional: self.optional, 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 = fn.create_symbol(AST_SymbolFunarg, { source: fn, scope: fn, tentative_name: "argument_" + fn.argnames.length, }); fn.argnames.push(argname); } } if (argname) { var sym = make_node(AST_SymbolRef, self, argname); sym.reference({}); clear_flag(argname, UNUSED); return sym; } } if (compressor.is_lhs()) 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; }); def_optimize(AST_Chain, function (self, compressor) { if (is_nullish(self.expression, compressor)) { let parent = compressor.parent(); // It's valid to delete a nullish optional chain, but if we optimized // this to `delete undefined` then it would appear to be a syntax error // when we try to optimize the delete. Thankfully, `delete 0` is fine. if (parent instanceof AST_UnaryPrefix && parent.operator === "delete") { return make_node_from_constant(0, self); } return make_node(AST_Undefined, self); } return self; }); def_optimize(AST_Dot, function(self, compressor) { const parent = compressor.parent(); if (compressor.is_lhs()) 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: { source: "t", flags: "" } }); break; case "String": self.expression = make_node(AST_String, self.expression, { value: "" }); break; } } if (!(parent instanceof AST_Call) || !has_annotation(parent, _NOINLINE)) { const sub = self.flatten_object(self.property, compressor); if (sub) return sub.optimize(compressor); } if (self.expression instanceof AST_PropAccess && parent instanceof AST_PropAccess) { return self; } let 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(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 && !expr.elements.some(elm => elm instanceof AST_Hole) ) { elements.splice(i, 1, ...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. } } } def_optimize(AST_Array, function(self, compressor) { var optimized = literals_in_boolean_context(self, compressor); if (optimized !== self) { return optimized; } inline_array_like_spread(self.elements); return self; }); function inline_object_prop_spread(props, compressor) { for (var i = 0; i < props.length; i++) { var prop = props[i]; if (prop instanceof AST_Expansion) { const expr = prop.expression; if ( expr instanceof AST_Object && expr.properties.every(prop => prop instanceof AST_ObjectKeyVal) ) { props.splice(i, 1, ...expr.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); i--; } else if (is_nullish(expr, compressor)) { // Likewise, null and undefined can be silently removed. props.splice(i, 1); i--; } } } } def_optimize(AST_Object, function(self, compressor) { var optimized = literals_in_boolean_context(self, compressor); if (optimized !== self) { return optimized; } inline_object_prop_spread(self.properties, compressor); 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, opt_AST_Lambda); def_optimize(AST_Function, function(self, compressor) { self = opt_AST_Lambda(self, compressor); if (compressor.option("unsafe_arrows") && compressor.option("ecma") >= 2015 && !self.name && !self.is_generator && !self.uses_arguments && !self.pinned()) { const uses_this = walk(self, node => { if (node instanceof AST_This) return walk_abort; }); if (!uses_this) return make_node(AST_Arrow, self, self).optimize(compressor); } return self; }); def_optimize(AST_Class, function(self) { // 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_ClassStaticBlock, function(self, compressor) { tighten_body(self.body, compressor); 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.size() + "${}".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; } // `before ${`innerBefore ${any} innerAfter`} after` => `before innerBefore ${any} innerAfter after` // TODO: // `before ${'test' + foo} after` => `before innerBefore ${any} innerAfter after` // `before ${foo + 'test} after` => `before innerBefore ${any} innerAfter after` if (segment instanceof AST_TemplateString) { var inners = segment.segments; segments[segments.length - 1].value += inners[0].value; for (var j = 1; j < inners.length; j++) { segment = inners[j]; segments.push(segment); } continue; } } segments.push(segment); } self.segments = segments; // `foo` => "foo" if (segments.length == 1) { return make_node(AST_String, self, segments[0]); } if ( segments.length === 3 && segments[1] instanceof AST_Node && ( segments[1].is_string(compressor) || segments[1].is_number(compressor) || is_nullish(segments[1], compressor) || compressor.option("unsafe") ) ) { // `foo${bar}` => "foo" + bar if (segments[2].value === "") { return make_node(AST_Binary, self, { operator: "+", left: make_node(AST_String, self, { value: segments[0].value, }), right: segments[1], }); } // `${bar}baz` => bar + "baz" if (segments[0].value === "") { return make_node(AST_Binary, self, { operator: "+", left: segments[1], right: make_node(AST_String, self, { value: segments[2].value, }), }); } } return self; }); def_optimize(AST_PrefixedTemplateString, function(self) { 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; // allow certain 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.quote = self.key.quote; self.key = self.key.value; } else if (self instanceof AST_ClassProperty) { self.quote = self.key.quote; self.key = make_node(AST_SymbolClassProperty, self.key, { name: self.key.value }); } else { self.quote = self.key.quote; 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") >= 2015 && (!(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) && !(self.names[self.names.length - 1] instanceof AST_Expansion)) { 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-5.19.2/lib/compress/inference.js000066400000000000000000001117241445647217600200370ustar00rootroot00000000000000/*********************************************************************** 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. ***********************************************************************/ import { AST_Array, AST_Arrow, AST_Assign, AST_BigInt, AST_Binary, AST_Block, AST_BlockStatement, AST_Call, AST_Case, AST_Chain, AST_Class, AST_DefClass, AST_ClassStaticBlock, AST_ClassProperty, AST_ConciseMethod, AST_Conditional, AST_Constant, AST_Definitions, AST_Dot, AST_EmptyStatement, AST_Expansion, AST_False, AST_ForIn, AST_Function, AST_If, AST_Import, AST_ImportMeta, AST_Jump, AST_LabeledStatement, AST_Lambda, AST_New, AST_Node, AST_Null, AST_Number, AST_Object, AST_ObjectGetter, AST_ObjectKeyVal, AST_ObjectProperty, AST_ObjectSetter, AST_PropAccess, AST_RegExp, AST_Return, AST_Scope, AST_Sequence, AST_SimpleStatement, AST_Statement, AST_String, AST_Sub, AST_Switch, AST_SwitchBranch, AST_SymbolClassProperty, AST_SymbolDeclaration, AST_SymbolRef, AST_TemplateSegment, AST_TemplateString, AST_This, AST_Toplevel, AST_True, AST_Try, AST_Unary, AST_UnaryPostfix, AST_UnaryPrefix, AST_Undefined, AST_VarDef, TreeTransformer, walk, walk_abort, _PURE } from "../ast.js"; import { makePredicate, return_true, return_false, return_null, return_this, make_node, member, noop, has_annotation, HOP } from "../utils/index.js"; import { make_node_from_constant, make_sequence, best_of_expression, read_property } from "./common.js"; import { INLINED, UNDEFINED, has_flag } from "./compressor-flags.js"; import { pure_prop_access_globals, is_pure_native_fn, is_pure_native_method } from "./native-objects.js"; // Functions and methods to infer certain facts about expressions // It's not always possible to be 100% sure about something just by static analysis, // so `true` means yes, and `false` means maybe export const is_undeclared_ref = (node) => node instanceof AST_SymbolRef && node.definition().undeclared; export const lazy_op = makePredicate("&& || ??"); export const unary_side_effects = makePredicate("delete ++ --"); // 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); const unary = makePredicate("+ - ~ ++ --"); def_is_number(AST_Unary, function() { return unary.has(this.operator) && !(this.expression instanceof AST_BigInt); }); const numeric_ops = makePredicate("- * / % & | ^ << >> >>>"); def_is_number(AST_Binary, function(compressor) { return numeric_ops.has(this.operator) || this.operator == "+" && this.left.is_number(compressor) && this.right.is_number(compressor); }); def_is_number(AST_Assign, function(compressor) { return numeric_ops.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, return_true); 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); }); export function is_undefined(node, compressor) { return ( has_flag(node, UNDEFINED) || node instanceof AST_Undefined || node instanceof AST_UnaryPrefix && node.operator == "void" && !node.expression.has_side_effects(compressor) ); } // Is the node explicitly null or undefined. function is_null_or_undefined(node, compressor) { let fixed; return ( node instanceof AST_Null || is_undefined(node, compressor) || ( node instanceof AST_SymbolRef && (fixed = node.definition().fixed) instanceof AST_Node && is_nullish(fixed, compressor) ) ); } // Find out if this expression is optionally chained from a base-point that we // can statically analyze as null or undefined. export function is_nullish_shortcircuited(node, compressor) { if (node instanceof AST_PropAccess || node instanceof AST_Call) { return ( (node.optional && is_null_or_undefined(node.expression, compressor)) || is_nullish_shortcircuited(node.expression, compressor) ); } if (node instanceof AST_Chain) return is_nullish_shortcircuited(node.expression, compressor); return false; } // Find out if something is == null, or can short circuit into nullish. // Used to optimize ?. and ?? export function is_nullish(node, compressor) { if (is_null_or_undefined(node, compressor)) return true; return is_nullish_shortcircuited(node, compressor); } // Determine if expression might cause side effects // If there's a possibility that a node may change something when it's executed, this returns true (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_callee_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 this.body.has_side_effects(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_ImportMeta, return_false); 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, function (compressor) { if (this.extends && this.extends.has_side_effects(compressor)) { return true; } return any(this.properties, compressor); }); def_has_side_effects(AST_ClassStaticBlock, function(compressor) { return any(this.body, compressor); }); 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) && !pure_prop_access_globals.has(this.name); }); def_has_side_effects(AST_SymbolClassProperty, return_false); 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) { return ( this.computed_key() && this.key.has_side_effects(compressor) || this.value && this.value.has_side_effects(compressor) ); }); def_has_side_effects(AST_ClassProperty, function(compressor) { return ( this.computed_key() && this.key.has_side_effects(compressor) || this.static && this.value && this.value.has_side_effects(compressor) ); }); def_has_side_effects(AST_ConciseMethod, function(compressor) { return this.computed_key() && this.key.has_side_effects(compressor); }); def_has_side_effects(AST_ObjectGetter, function(compressor) { return this.computed_key() && this.key.has_side_effects(compressor); }); def_has_side_effects(AST_ObjectSetter, function(compressor) { return this.computed_key() && this.key.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) { if (is_nullish(this, compressor)) return false; return !this.optional && this.expression.may_throw_on_access(compressor) || this.expression.has_side_effects(compressor); }); def_has_side_effects(AST_Sub, function(compressor) { if (is_nullish(this, compressor)) return false; return !this.optional && this.expression.may_throw_on_access(compressor) || this.expression.has_side_effects(compressor) || this.property.has_side_effects(compressor); }); def_has_side_effects(AST_Chain, function (compressor) { return this.expression.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() { 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_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); def_may_throw(AST_ImportMeta, 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_Class, function(compressor) { if (this.extends && this.extends.may_throw(compressor)) return true; return any(this.properties, compressor); }); def_may_throw(AST_ClassStaticBlock, function (compressor) { return any(this.body, compressor); }); 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 (is_nullish(this, compressor)) return false; if (any(this.args, compressor)) return true; if (this.is_callee_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_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) { // TODO key may throw too return this.value ? this.value.may_throw(compressor) : false; }); def_may_throw(AST_ClassProperty, function(compressor) { return ( this.computed_key() && this.key.may_throw(compressor) || this.static && this.value && this.value.may_throw(compressor) ); }); def_may_throw(AST_ConciseMethod, function(compressor) { return this.computed_key() && this.key.may_throw(compressor); }); def_may_throw(AST_ObjectGetter, function(compressor) { return this.computed_key() && this.key.may_throw(compressor); }); def_may_throw(AST_ObjectSetter, function(compressor) { return this.computed_key() && this.key.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_Dot, function(compressor) { if (is_nullish(this, compressor)) return false; return !this.optional && this.expression.may_throw_on_access(compressor) || this.expression.may_throw(compressor); }); def_may_throw(AST_Sub, function(compressor) { if (is_nullish(this, compressor)) return false; return !this.optional && this.expression.may_throw_on_access(compressor) || this.expression.may_throw(compressor) || this.property.may_throw(compressor); }); def_may_throw(AST_Chain, function(compressor) { return this.expression.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) && !pure_prop_access_globals.has(this.name); }); def_may_throw(AST_SymbolClassProperty, return_false); def_may_throw(AST_Try, function(compressor) { return this.bcatch ? this.bcatch.may_throw(compressor) : this.body.may_throw(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) { let result = true; walk(this, node => { if (node instanceof AST_SymbolRef) { if (has_flag(this, INLINED)) { result = false; return walk_abort; } var def = node.definition(); if ( member(def, this.enclosed) && !this.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 walk_abort; } return true; } if (node instanceof AST_This && this instanceof AST_Arrow) { result = false; return walk_abort; } }); 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) { if (this.extends && !this.extends.is_constant_expression(scope)) { return false; } for (const prop of this.properties) { if (prop.computed_key() && !prop.key.is_constant_expression(scope)) { return false; } if (prop.static && prop.value && !prop.value.is_constant_expression(scope)) { return false; } if (prop instanceof AST_ClassStaticBlock) { return false; } } return all_refs_local.call(this, 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 && this.value.is_constant_expression()); }); })(function(node, func) { node.DEFMETHOD("is_constant_expression", func); }); // 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; }); // Do not be as strict with classes as we are with objects. // Hopefully the community is not going to abuse static getters and setters. // https://github.com/terser/terser/issues/724#issuecomment-643655656 def_may_throw_on_access(AST_Class, 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.operator == "??") && (this.left._dot_throw(compressor) || this.right._dot_throw(compressor)); }); def_may_throw_on_access(AST_Assign, function(compressor) { if (this.logical) return true; 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.property == "prototype") { return !( this.expression instanceof AST_Function || this.expression instanceof AST_Class ); } return true; }); def_may_throw_on_access(AST_Chain, function(compressor) { return this.expression._dot_throw(compressor); }); 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.name === "arguments" && this.scope instanceof AST_Lambda) return false; if (has_flag(this, 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); }); export 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; if (parent instanceof AST_ForIn && parent.init === node) return node; } (function(def_find_defs) { function to_node(value, orig) { if (value instanceof AST_Node) { if (!(value instanceof AST_Constant)) { // Value may be a function, an array including functions and even a complex assign / block expression, // so it should never be shared in different places. // Otherwise wrong information may be used in the compression phase value = value.clone(true); } 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); } 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)) { return; } return def; })); }); def_find_defs(AST_Node, noop); def_find_defs(AST_Chain, function(compressor, suffix) { return this.expression._find_defs(compressor, suffix); }); def_find_defs(AST_Dot, function(compressor, suffix) { return this.expression._find_defs(compressor, "." + this.property + suffix); }); def_find_defs(AST_SymbolDeclaration, function() { if (!this.global()) return; }); 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); }); def_find_defs(AST_ImportMeta, function(compressor, suffix) { var defines = compressor.option("global_defs"); var name = "import.meta" + suffix; if (HOP(defines, name)) return to_node(defines[name], this); }); })(function(node, func) { node.DEFMETHOD("_find_defs", 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_Class, 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); }); }); // Is the callee of this function pure? 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_callee_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) && is_pure_native_fn(expr.expression.name, expr.property) ) { return true; } } return !!has_annotation(this, _PURE) || !compressor.pure_funcs(this); }); // If I call this, is it a pure function? 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 native_obj; if (expr instanceof AST_Array) { native_obj = "Array"; } else if (expr.is_boolean()) { native_obj = "Boolean"; } else if (expr.is_number(compressor)) { native_obj = "Number"; } else if (expr instanceof AST_RegExp) { native_obj = "RegExp"; } else if (expr.is_string(compressor)) { native_obj = "String"; } else if (!this.may_throw_on_access(compressor)) { native_obj = "Object"; } return native_obj != null && is_pure_native_method(native_obj, this.property); }); // tell me if a statement aborts export const aborts = (thing) => thing && thing.aborts(); (function(def_aborts) { def_aborts(AST_Statement, return_null); def_aborts(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_aborts(AST_Import, return_null); def_aborts(AST_BlockStatement, block_aborts); def_aborts(AST_SwitchBranch, block_aborts); def_aborts(AST_DefClass, function () { for (const prop of this.properties) { if (prop instanceof AST_ClassStaticBlock) { if (prop.aborts()) return prop; } } return null; }); def_aborts(AST_ClassStaticBlock, block_aborts); def_aborts(AST_If, function() { return this.alternative && aborts(this.body) && aborts(this.alternative) && this; }); })(function(node, func) { node.DEFMETHOD("aborts", func); }); AST_Node.DEFMETHOD("contains_this", function() { return walk(this, node => { if (node instanceof AST_This) return walk_abort; if ( node !== this && node instanceof AST_Scope && !(node instanceof AST_Arrow) ) { return true; } }); }); export 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_callee_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); } } terser-5.19.2/lib/compress/inline.js000066400000000000000000000526441445647217600173640ustar00rootroot00000000000000/*********************************************************************** 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. ***********************************************************************/ import { AST_Array, AST_Assign, AST_Block, AST_Call, AST_Catch, AST_Class, AST_ClassExpression, AST_DefaultAssign, AST_DefClass, AST_Defun, AST_Destructuring, AST_EmptyStatement, AST_Expansion, AST_Export, AST_Function, AST_IterationStatement, AST_Lambda, AST_Node, AST_Number, AST_Object, AST_ObjectKeyVal, AST_PropAccess, AST_Return, AST_Scope, AST_SimpleStatement, AST_Statement, AST_SymbolDefun, AST_SymbolFunarg, AST_SymbolLambda, AST_SymbolRef, AST_SymbolVar, AST_This, AST_Toplevel, AST_UnaryPrefix, AST_Undefined, AST_Var, AST_VarDef, walk, _INLINE, _NOINLINE, _PURE } from "../ast.js"; import { make_node, has_annotation } from "../utils/index.js"; import "../size.js"; import "./evaluate.js"; import "./drop-side-effect-free.js"; import "./reduce-vars.js"; import { SQUEEZED, INLINED, UNUSED, has_flag, set_flag, } from "./compressor-flags.js"; import { make_sequence, best_of, make_node_from_constant, identifier_atom, is_empty, is_func_expr, is_iife_call, is_reachable, is_recursive_ref, retain_top_func, } from "./common.js"; /** * Module that contains the inlining logic. * * @module * * The stars of the show are `inline_into_symbolref` and `inline_into_call`. */ 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; } function scope_encloses_variables_in_this_scope(scope, pulled_scope) { for (const enclosed of pulled_scope.enclosed) { if (pulled_scope.variables.has(enclosed.name)) { continue; } const looked_up = scope.find_variable(enclosed.name); if (looked_up) { if (looked_up === enclosed) continue; return true; } } return false; } export function inline_into_symbolref(self, compressor) { const parent = compressor.parent(); const def = self.definition(); const nearest_scope = compressor.find_scope(); if (compressor.top_retain && def.global && compressor.top_retain(def)) { def.fixed = false; def.single_use = false; return self; } let fixed = self.fixed_value(); let single_use = def.single_use && !(parent instanceof AST_Call && (parent.is_callee_pure(compressor)) || has_annotation(parent, _NOINLINE)) && !(parent instanceof AST_Export && fixed instanceof AST_Lambda && fixed.name); if (single_use && fixed instanceof AST_Node) { single_use = !fixed.has_side_effects(compressor) && !fixed.may_throw(compressor); } if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) { if (retain_top_func(fixed, compressor)) { single_use = false; } else if (def.scope !== self.scope && (def.escaped == 1 || has_flag(fixed, INLINED) || within_array_or_object_literal(compressor) || !compressor.option("reduce_funcs"))) { single_use = false; } else if (is_recursive_ref(compressor, def)) { single_use = false; } else if (def.scope !== self.scope || def.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)) { set_flag(scope, INLINED); } } while (scope = scope.parent_scope); } } } if (single_use && (fixed instanceof AST_Lambda || fixed instanceof AST_Class)) { single_use = def.scope === self.scope && !scope_encloses_variables_in_this_scope(nearest_scope, fixed) || parent instanceof AST_Call && parent.expression === self && !scope_encloses_variables_in_this_scope(nearest_scope, fixed) && !(fixed.name && fixed.name.definition().recursive_refs > 0); } if (single_use && fixed) { if (fixed instanceof AST_DefClass) { set_flag(fixed, SQUEEZED); fixed = make_node(AST_ClassExpression, fixed, fixed); } if (fixed instanceof AST_Defun) { set_flag(fixed, SQUEEZED); fixed = make_node(AST_Function, fixed, fixed); } if (def.recursive_refs > 0 && fixed.name instanceof AST_SymbolDefun) { const defun_def = fixed.name.definition(); let lambda_def = fixed.variables.get(fixed.name.name); let name = lambda_def && lambda_def.orig[0]; if (!(name instanceof AST_SymbolLambda)) { name = make_node(AST_SymbolLambda, fixed.name, fixed.name); name.scope = fixed; fixed.name = name; lambda_def = fixed.def_function(name); } walk(fixed, node => { if (node instanceof AST_SymbolRef && node.definition() === defun_def) { node.thedef = lambda_def; lambda_def.references.push(node); } }); } if ( (fixed instanceof AST_Lambda || fixed instanceof AST_Class) && fixed.parent_scope !== nearest_scope ) { fixed = fixed.clone(true, compressor.get_toplevel()); nearest_scope.add_child_scope(fixed); } return fixed.optimize(compressor); } // multiple uses if (fixed) { let replace; if (fixed instanceof AST_This) { if (!(def.orig[0] instanceof AST_SymbolFunarg) && def.references.every((ref) => def.scope === ref.scope )) { replace = fixed; } } else { var ev = fixed.evaluate(compressor); if ( ev !== fixed && (compressor.option("unsafe_regexp") || !(ev instanceof RegExp)) ) { replace = make_node_from_constant(ev, fixed); } } if (replace) { const name_length = self.size(compressor); const replace_size = replace.size(compressor); let overhead = 0; if (compressor.option("unused") && !compressor.exposed(def)) { overhead = (name_length + 2 + replace_size) / (def.references.length - def.assignments); } if (replace_size <= name_length + overhead) { return replace; } } } return self; } export function inline_into_call(self, fn, compressor) { var exp = self.expression; var simple_args = self.args.every((arg) => !(arg instanceof AST_Expansion)); if (compressor.option("reduce_vars") && fn instanceof AST_SymbolRef && !has_annotation(self, _NOINLINE) ) { const fixed = fn.fixed_value(); if (!retain_top_func(fixed, compressor)) { fn = fixed; } } var is_func = fn instanceof AST_Lambda; var stat = is_func && fn.body[0]; var is_regular_func = is_func && !fn.is_generator && !fn.async; var can_inline = is_regular_func && compressor.option("inline") && !self.is_callee_pure(compressor); if (can_inline && stat instanceof AST_Return) { let returned = stat.value; if (!returned || returned.is_constant_expression()) { if (returned) { returned = returned.clone(true); } else { returned = make_node(AST_Undefined, self); } const args = self.args.concat(returned); return make_sequence(self, args).optimize(compressor); } // optimize identity function if ( fn.argnames.length === 1 && (fn.argnames[0] instanceof AST_SymbolFunarg) && self.args.length < 2 && !(self.args[0] instanceof AST_Expansion) && returned instanceof AST_SymbolRef && returned.name === fn.argnames[0].name ) { const replacement = (self.args[0] || make_node(AST_Undefined)).optimize(compressor); let parent; if ( replacement instanceof AST_PropAccess && (parent = compressor.parent()) instanceof AST_Call && parent.expression === self ) { // identity function was being used to remove `this`, like in // // id(bag.no_this)(...) // // Replace with a larger but more effish (0, bag.no_this) wrapper. return make_sequence(self, [ make_node(AST_Number, self, { value: 0 }), replacement ]); } // replace call with first argument or undefined if none passed return replacement; } } if (can_inline) { var scope, in_loop, level = -1; let def; let returned_value; let nearest_scope; if (simple_args && !fn.uses_arguments && !(compressor.parent() instanceof AST_Class) && !(fn.name && fn instanceof AST_Function) && (returned_value = can_flatten_body(stat)) && (exp === fn || has_annotation(self, _INLINE) || compressor.option("unused") && (def = exp.definition()).references.length == 1 && !is_recursive_ref(compressor, def) && fn.is_constant_expression(exp.scope)) && !has_annotation(self, _PURE | _NOINLINE) && !fn.contains_this() && can_inject_symbols() && (nearest_scope = compressor.find_scope()) && !scope_encloses_variables_in_this_scope(nearest_scope, fn) && !(function in_default_assign() { // Due to the fact function parameters have their own scope // which can't use `var something` in the function body within, // we simply don't inline into DefaultAssign. let i = 0; let p; while ((p = compressor.parent(i++))) { if (p instanceof AST_DefaultAssign) return true; if (p instanceof AST_Block) break; } return false; })() && !(scope instanceof AST_Class) ) { set_flag(fn, SQUEEZED); nearest_scope.add_child_scope(fn); return make_sequence(self, flatten_fn(returned_value)).optimize(compressor); } } if (can_inline && has_annotation(self, _INLINE)) { set_flag(fn, SQUEEZED); fn = make_node(fn.CTOR === AST_Defun ? AST_Function : fn.CTOR, fn, fn); fn = fn.clone(true); fn.figure_out_scope({}, { parent_scope: compressor.find_scope(), toplevel: compressor.get_toplevel() }); return make_node(AST_Call, self, { expression: fn, args: self.args, }).optimize(compressor); } const can_drop_this_call = is_regular_func && compressor.option("side_effects") && fn.body.every(is_empty); if (can_drop_this_call) { 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; 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 (has_flag(arg.left, UNUSED)) continue; return false; } if (arg instanceof AST_Destructuring) return false; if (arg instanceof AST_Expansion) { if (has_flag(arg.expression, UNUSED)) continue; return false; } if (has_flag(arg, UNUSED)) continue; if (!safe_to_inject || block_scoped.has(arg.name) || identifier_atom.has(arg.name) || scope.conflicting_def(arg.name)) { return false; } if (in_loop) in_loop.push(arg.definition()); } 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.conflicting_def(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() && 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) { // TODO can we delete? AST_Catch is a block scope. 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)); 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; return !in_loop || in_loop.length == 0 || !is_reachable(fn, in_loop); } function append_var(decls, expressions, name, value) { var def = name.definition(); // Name already exists, only when a function argument had the same name const already_appended = scope.variables.has(name.name); if (!already_appended) { scope.variables.set(name.name, def); scope.enclosed.push(def); 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: "=", logical: false, 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 (has_flag(name, UNUSED) || !name.name || scope.conflicting_def(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: "=", logical: false, left: sym, right: make_node(AST_Undefined, name) })); } } } } function flatten_fn(returned_value) { var decls = []; var expressions = []; flatten_args(decls, expressions); flatten_vars(decls, expressions); expressions.push(returned_value); if (decls.length) { const i = scope.body.indexOf(compressor.parent(level - 1)) + 1; scope.body.splice(i, 0, make_node(AST_Var, fn, { definitions: decls })); } return expressions.map(exp => exp.clone(true)); } } terser-5.19.2/lib/compress/native-objects.js000066400000000000000000000122251445647217600210120ustar00rootroot00000000000000/*********************************************************************** 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. ***********************************************************************/ import { makePredicate } from "../utils/index.js"; // Lists of native methods, useful for `unsafe` option which assumes they exist. // Note: Lots of methods and functions are missing here, in case they aren't pure // or not available in all JS environments. function make_nested_lookup(obj) { const out = new Map(); for (var key of Object.keys(obj)) { out.set(key, makePredicate(obj[key])); } const does_have = (global_name, fname) => { const inner_map = out.get(global_name); return inner_map != null && inner_map.has(fname); }; return does_have; } // Objects which are safe to access without throwing or causing a side effect. // Usually we'd check the `unsafe` option first but these are way too common for that export const pure_prop_access_globals = new Set([ "Number", "String", "Array", "Object", "Function", "Promise", ]); const object_methods = [ "constructor", "toString", "valueOf", ]; export const is_pure_native_method = make_nested_lookup({ Array: [ "at", "flat", "includes", "indexOf", "join", "lastIndexOf", "slice", ...object_methods, ], Boolean: object_methods, Function: object_methods, Number: [ "toExponential", "toFixed", "toPrecision", ...object_methods, ], Object: object_methods, RegExp: [ "test", ...object_methods, ], String: [ "at", "charAt", "charCodeAt", "charPointAt", "concat", "endsWith", "fromCharCode", "fromCodePoint", "includes", "indexOf", "italics", "lastIndexOf", "localeCompare", "match", "matchAll", "normalize", "padStart", "padEnd", "repeat", "replace", "replaceAll", "search", "slice", "split", "startsWith", "substr", "substring", "repeat", "toLocaleLowerCase", "toLocaleUpperCase", "toLowerCase", "toUpperCase", "trim", "trimEnd", "trimStart", ...object_methods, ], }); export const is_pure_native_fn = make_nested_lookup({ 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", "hasOwn", "keys", ], String: [ "fromCharCode", ], }); // Known numeric values which come with JS environments export const is_pure_native_value = make_nested_lookup({ Math: [ "E", "LN10", "LN2", "LOG2E", "LOG10E", "PI", "SQRT1_2", "SQRT2", ], Number: [ "MAX_VALUE", "MIN_VALUE", "NaN", "NEGATIVE_INFINITY", "POSITIVE_INFINITY", ], }); terser-5.19.2/lib/compress/reduce-vars.js000066400000000000000000000573271445647217600203310ustar00rootroot00000000000000/*********************************************************************** 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. ***********************************************************************/ import { AST_Accessor, AST_Array, AST_Assign, AST_Await, AST_Binary, AST_Block, AST_Call, AST_Case, AST_Chain, AST_Class, AST_ClassStaticBlock, AST_ClassExpression, AST_Conditional, AST_Default, AST_Defun, AST_Destructuring, AST_Do, AST_Exit, AST_Expansion, AST_For, AST_ForIn, AST_If, AST_LabeledStatement, AST_Lambda, AST_New, AST_Node, AST_Number, AST_ObjectKeyVal, AST_PropAccess, AST_Scope, AST_Sequence, AST_SimpleStatement, AST_Symbol, AST_SymbolCatch, AST_SymbolConst, AST_SymbolDeclaration, AST_SymbolDefun, AST_SymbolFunarg, AST_SymbolLambda, AST_SymbolRef, AST_This, AST_Toplevel, AST_Try, AST_Unary, AST_UnaryPrefix, AST_Undefined, AST_VarDef, AST_While, AST_Yield, walk, walk_body, TreeWalker, _INLINE, _NOINLINE, _PURE } from "../ast.js"; import { HOP, make_node, noop } from "../utils/index.js"; import { lazy_op, is_modified, is_lhs } from "./inference.js"; import { INLINED, clear_flag } from "./compressor-flags.js"; import { read_property, has_break_or_continue, is_recursive_ref } from "./common.js"; /** * Define the method AST_Node#reduce_vars, which goes through the AST in * execution order to perform basic flow analysis */ function def_reduce_vars(node, func) { node.DEFMETHOD("reduce_vars", func); } def_reduce_vars(AST_Node, noop); /** Clear definition properties */ function reset_def(compressor, def) { def.assignments = 0; def.chained = false; def.direct_access = false; def.escaped = 0; def.recursive_refs = 0; def.references = []; def.single_use = undefined; if ( def.scope.pinned() || (def.orig[0] instanceof AST_SymbolFunarg && def.scope.uses_arguments) ) { def.fixed = false; } else if (def.orig[0] instanceof AST_SymbolConst || !compressor.exposed(def)) { def.fixed = def.init; } else { def.fixed = false; } } function reset_variables(tw, compressor, node) { node.variables.forEach(function(def) { reset_def(compressor, def); if (def.fixed === null) { tw.defs_to_safe_ids.set(def.id, tw.safe_ids); mark(tw, def, true); } else if (def.fixed) { tw.loop_ids.set(def.id, tw.in_loop); mark(tw, def, true); } }); } function reset_block_variables(compressor, node) { if (node.block_scope) node.block_scope.variables.forEach((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, scope, value) { if (def.fixed === undefined) return true; let def_safe_ids; if (def.fixed === null && (def_safe_ids = tw.defs_to_safe_ids.get(def.id)) ) { def_safe_ids[def.id] = false; tw.defs_to_safe_ids.delete(def.id); 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; if (def.fixed instanceof AST_Defun) { return value instanceof AST_Node && def.fixed.parent_scope === scope; } 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.get(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; } // A definition "escapes" when its value can leave the point of use. // Example: `a = b || c` // In this example, "b" and "c" are escaping, because they're going into "a" // // def.escaped is != 0 when it escapes. // // When greater than 1, it means that N chained properties will be read off // of that def before an escape occurs. This is useful for evaluating // property accesses, where you need to know when to stop. function mark_escaped(tw, d, scope, node, value, level = 0, depth = 1) { 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 === "=" || parent.logical) && 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; } const suppress = node => walk(node, 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_Assign, function(tw, descend, compressor) { var node = this; if (node.left instanceof AST_Destructuring) { suppress(node.left); return; } const finish_walk = () => { if (node.logical) { node.left.walk(tw); push(tw); node.right.walk(tw); pop(tw); return true; } }; var sym = node.left; if (!(sym instanceof AST_SymbolRef)) return finish_walk(); var def = sym.definition(); var safe = safe_to_assign(tw, def, sym.scope, node.right); def.assignments++; if (!safe) return finish_walk(); var fixed = def.fixed; if (!fixed && node.operator != "=" && !node.logical) return finish_walk(); var eq = node.operator == "="; var value = eq ? node.right : node; if (is_modified(compressor, tw, node, value, 0)) return finish_walk(); def.references.push(sym); if (!node.logical) { if (!eq) def.chained = true; def.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 }); }; } if (node.logical) { mark(tw, def, false); push(tw); node.right.walk(tw); pop(tw); return true; } mark(tw, def, false); node.right.walk(tw); mark(tw, def, true); mark_escaped(tw, def, 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_Class, function(tw, descend) { clear_flag(this, INLINED); push(tw); descend(); pop(tw); return true; }); def_reduce_vars(AST_ClassStaticBlock, function(tw, descend, compressor) { reset_block_variables(compressor, this); }); 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_Chain, function(tw, descend) { // Chains' conditions apply left-to-right, cumulatively. // If we walk normally we don't go in that order because we would pop before pushing again // Solution: AST_PropAccess and AST_Call push when they are optional, and never pop. // Then we pop everything when they are done being walked. const safe_ids = tw.safe_ids; descend(); // Unroll back to start tw.safe_ids = safe_ids; return true; }); def_reduce_vars(AST_Call, function (tw) { this.expression.walk(tw); if (this.optional) { // Never pop -- it's popped at AST_Chain above push(tw); } for (const arg of this.args) arg.walk(tw); return true; }); def_reduce_vars(AST_PropAccess, function (tw) { if (!this.optional) return; this.expression.walk(tw); // Never pop -- it's popped at AST_Chain above push(tw); if (this.property instanceof AST_Node) this.property.walk(tw); return true; }); def_reduce_vars(AST_Default, function(tw, descend) { push(tw); descend(); pop(tw); return true; }); function mark_lambda(tw, descend, compressor) { clear_flag(this, INLINED); push(tw); reset_variables(tw, compressor, this); var iife; if (!this.name && !this.uses_arguments && !this.pinned() && (iife = tw.parent()) instanceof AST_Call && iife.expression === this && !iife.args.some(arg => arg instanceof AST_Expansion) && this.argnames.every(arg_name => arg_name instanceof AST_Symbol) ) { // 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. this.argnames.forEach((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 && (!this.uses_arguments || tw.has_directive("use strict"))) { d.fixed = function() { return iife.args[i] || make_node(AST_Undefined, iife); }; tw.loop_ids.set(d.id, tw.in_loop); mark(tw, d, true); } else { d.fixed = false; } }); } descend(); pop(tw); handle_defined_after_hoist(this); return true; } /** * It's possible for a hoisted function to use something that's not defined yet. Example: * * hoisted(); * var defined_after = true; * function hoisted() { * // use defined_after * } * * This function is called on the parent to handle this issue. */ function handle_defined_after_hoist(parent) { const defuns = []; walk(parent, node => { if (node === parent) return; if (node instanceof AST_Defun) defuns.push(node); if ( node instanceof AST_Scope || node instanceof AST_SimpleStatement ) return true; }); const symbols_of_interest = new Set(); const defuns_of_interest = new Set(); const potential_conflicts = []; for (const defun of defuns) { const fname_def = defun.name.definition(); const found_self_ref_in_other_defuns = defuns.some( d => d !== defun && d.enclosed.indexOf(fname_def) !== -1 ); for (const def of defun.enclosed) { if ( def.fixed === false || def === fname_def || def.scope.get_defun_scope() !== parent ) { continue; } // defun is hoisted, so always safe if ( def.assignments === 0 && def.orig.length === 1 && def.orig[0] instanceof AST_SymbolDefun ) { continue; } if (found_self_ref_in_other_defuns) { def.fixed = false; continue; } // for the slower checks below this loop potential_conflicts.push({ defun, def, fname_def }); symbols_of_interest.add(def.id); symbols_of_interest.add(fname_def.id); defuns_of_interest.add(defun); } } // linearize all symbols, and locate defs that are read after the defun if (potential_conflicts.length) { // All "symbols of interest", that is, defuns or defs, that we found. // These are placed in order so we can check which is after which. const found_symbols = []; // Indices of `found_symbols` which are writes const found_symbol_writes = new Set(); // Defun ranges are recorded because we don't care if a function uses the def internally const defun_ranges = new Map(); let tw; parent.walk((tw = new TreeWalker((node, descend) => { if (node instanceof AST_Defun && defuns_of_interest.has(node)) { const start = found_symbols.length; descend(); const end = found_symbols.length; defun_ranges.set(node, { start, end }); return true; } // if we found a defun on the list, mark IN_DEFUN=id and descend if (node instanceof AST_Symbol && node.thedef) { const id = node.definition().id; if (symbols_of_interest.has(id)) { if (node instanceof AST_SymbolDeclaration || is_lhs(node, tw)) { found_symbol_writes.add(found_symbols.length); } found_symbols.push(id); } } }))); for (const { def, defun, fname_def } of potential_conflicts) { const defun_range = defun_ranges.get(defun); // find the index in `found_symbols`, with some special rules: const find = (sym_id, starting_at = 0, must_be_write = false) => { let index = starting_at; for (;;) { index = found_symbols.indexOf(sym_id, index); if (index === -1) { break; } else if (index >= defun_range.start && index < defun_range.end) { index = defun_range.end; continue; } else if (must_be_write && !found_symbol_writes.has(index)) { index++; continue; } else { break; } } return index; }; const read_defun_at = find(fname_def.id); const wrote_def_at = find(def.id, read_defun_at + 1, true); const wrote_def_after_reading_defun = read_defun_at != -1 && wrote_def_at != -1 && wrote_def_at > read_defun_at; if (wrote_def_after_reading_defun) { def.fixed = false; } } } } def_reduce_vars(AST_Lambda, mark_lambda); def_reduce_vars(AST_Do, function(tw, descend, compressor) { reset_block_variables(compressor, this); const 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); const 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); suppress(this.init); this.object.walk(tw); const saved_loop = tw.in_loop; tw.in_loop = this; push(tw); this.body.walk(tw); pop(tw); tw.in_loop = saved_loop; return true; }); 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.set(d.id, tw.in_loop); } var fixed_value; if (d.fixed === undefined || !safe_to_read(tw, d)) { d.fixed = false; } else if (d.fixed) { fixed_value = this.fixed_value(); if ( fixed_value instanceof AST_Lambda && is_recursive_ref(tw, d) ) { d.recursive_refs++; } else if (fixed_value && !compressor.exposed(d) && ref_once(tw, compressor, d) ) { d.single_use = fixed_value instanceof AST_Lambda && !fixed_value.pinned() || fixed_value instanceof AST_Class || d.scope === this.scope && fixed_value.is_constant_expression(); } else { d.single_use = false; } if (is_modified(compressor, tw, this, fixed_value, 0, is_immutable(fixed_value))) { if (d.single_use) { d.single_use = "m"; } else { d.fixed = false; } } } mark_escaped(tw, d, this.scope, this, fixed_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); descend(); handle_defined_after_hoist(this); return true; }); def_reduce_vars(AST_Try, function(tw, descend, compressor) { reset_block_variables(compressor, this); push(tw); this.body.walk(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) { var node = this; if (node.operator !== "++" && node.operator !== "--") return; var exp = node.expression; if (!(exp instanceof AST_SymbolRef)) return; var def = exp.definition(); var safe = safe_to_assign(tw, def, exp.scope, true); def.assignments++; if (!safe) return; var fixed = def.fixed; if (!fixed) return; def.references.push(exp); def.chained = true; def.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, def, true); return true; }); def_reduce_vars(AST_VarDef, function(tw, descend) { var node = this; if (node.name instanceof AST_Destructuring) { suppress(node.name); return; } var d = node.name.definition(); if (node.value) { if (safe_to_assign(tw, d, node.name.scope, node.value)) { d.fixed = function() { return node.value; }; tw.loop_ids.set(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); const saved_loop = tw.in_loop; tw.in_loop = this; push(tw); descend(); pop(tw); tw.in_loop = saved_loop; return true; }); terser-5.19.2/lib/compress/tighten-body.js000066400000000000000000001641321445647217600204770ustar00rootroot00000000000000/*********************************************************************** 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. ***********************************************************************/ import { AST_Array, AST_Arrow, AST_Assign, AST_Await, AST_Binary, AST_Block, AST_BlockStatement, AST_Break, AST_Call, AST_Case, AST_Chain, AST_Class, AST_Conditional, AST_Const, AST_Constant, AST_Continue, AST_Debugger, AST_Default, AST_Definitions, AST_Defun, AST_Destructuring, AST_Directive, AST_Dot, AST_DWLoop, AST_EmptyStatement, AST_Exit, AST_Expansion, AST_Export, AST_For, AST_ForIn, AST_If, AST_Import, AST_IterationStatement, AST_Lambda, AST_Let, AST_LoopControl, AST_Node, AST_Number, AST_Object, AST_ObjectKeyVal, AST_PropAccess, AST_RegExp, AST_Return, AST_Scope, AST_Sequence, AST_SimpleStatement, AST_Sub, AST_Switch, AST_Symbol, AST_SymbolConst, AST_SymbolDeclaration, AST_SymbolDefun, AST_SymbolFunarg, AST_SymbolLambda, AST_SymbolLet, AST_SymbolRef, AST_SymbolVar, AST_This, AST_Try, AST_TryBlock, AST_Unary, AST_UnaryPostfix, AST_UnaryPrefix, AST_Undefined, AST_Var, AST_VarDef, AST_With, AST_Yield, TreeTransformer, TreeWalker, walk, walk_abort, _NOINLINE } from "../ast.js"; import { make_node, MAP, member, remove, has_annotation } from "../utils/index.js"; import { pure_prop_access_globals } from "./native-objects.js"; import { lazy_op, unary_side_effects, is_modified, is_lhs, aborts } from "./inference.js"; import { WRITE_ONLY, clear_flag } from "./compressor-flags.js"; import { make_sequence, merge_sequence, maintain_this_binding, is_func_expr, is_identifier_atom, is_ref_of, can_be_evicted_from_block, as_statement_array, } from "./common.js"; function loop_body(x) { if (x instanceof AST_IterationStatement) { return x.body instanceof AST_BlockStatement ? x.body : x; } return x; } 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; } /** var a = 1 --> var a*/ function remove_initializers(var_statement) { var decls = []; var_statement.definitions.forEach(function(def) { if (def.name instanceof AST_SymbolDeclaration) { def.value = null; decls.push(def); } else { def.declarations_as_names().forEach(name => { decls.push(make_node(AST_VarDef, def, { name, value: null })); }); } }); return decls.length ? make_node(AST_Var, var_statement, { definitions: decls }) : null; } /** Called on code which we know is unreachable, to keep elements that affect outside of it. */ export function trim_unreachable_code(compressor, stat, target) { walk(stat, node => { if (node instanceof AST_Var) { const no_initializers = remove_initializers(node); if (no_initializers) target.push(no_initializers); 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_Export || node instanceof AST_Import) { target.push(node); return true; } if (node instanceof AST_Scope) { return true; } }); } /** Tighten a bunch of statements together, and perform statement-level optimization. */ export function tighten_body(statements, compressor) { const nearest_scope = compressor.find_scope(); const defun_scope = nearest_scope.get_defun_scope(); const { in_loop, in_try } = 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, in_loop = false, in_try = false; do { if (node instanceof AST_IterationStatement) { in_loop = true; } else if (node instanceof AST_Scope) { break; } else if (node instanceof AST_TryBlock) { in_try = true; } } while (node = compressor.parent(level++)); return { in_loop, in_try }; } // 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 (nearest_scope.pinned() || defun_scope.pinned()) return statements; var args; var candidates = []; var stat_index = statements.length; var scanner = 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 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.logical || 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_Call || node instanceof AST_PropAccess) && node.optional || node instanceof AST_Debugger || node instanceof AST_Destructuring || node instanceof AST_Expansion && node.expression instanceof AST_Symbol && ( node.expression instanceof AST_This || 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 || node instanceof AST_Class || parent instanceof AST_For && node !== parent.init || !replace_all && ( node instanceof AST_SymbolRef && !node.is_declared(compressor) && !pure_prop_access_globals.has(node) ) || node instanceof AST_SymbolRef && parent instanceof AST_Call && has_annotation(parent, _NOINLINE) ) { 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) && !shadows(scanner.find_scope() || nearest_scope, lvalues) ) { if (stop_if_hit) { abort = true; return node; } if (is_lhs(node, parent)) { if (value_def) replaced++; return node; } else { replaced++; if (value_def && candidate instanceof AST_VarDef) return node; } CHANGED = abort = true; if (candidate instanceof AST_UnaryPostfix) { return make_node(AST_UnaryPrefix, candidate, candidate); } if (candidate instanceof AST_VarDef) { 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: "=", logical: false, left: make_node(AST_SymbolRef, candidate.name, candidate.name), right: value }); } clear_flag(candidate, WRITE_ONLY); 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.has(node.name) && lvalues.get(node.name).modified) || 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, { def: lhs.definition(), modified: 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 ( let 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 redefined_within_scope(def, scope) { if (def.global) return false; let cur_scope = def.scope; while (cur_scope && cur_scope !== scope) { if (cur_scope.variables.has(def.name)) { return true; } cur_scope = cur_scope.parent_scope; } return false; } 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) || redefined_within_scope(node.definition(), fn))) { var s = node.definition().scope; if (s !== defun_scope) while (s = s.parent_scope) { if (s === defun_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]; // The following two line fix is a duplicate of the fix at // https://github.com/terser/terser/commit/011d3eb08cefe6922c7d1bdfa113fc4aeaca1b75 // This might mean that these two pieces of code (one here in collapse_vars and another in reduce_vars // Might be doing the exact same thing. const def = sym.definition && sym.definition(); const is_reassigned = def && def.orig.length > 1; if (is_reassigned) continue; 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) && !(expr.right instanceof AST_Chain)) { 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 && !has_annotation(expr, _NOINLINE)) { 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) { 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 && !(expr.value instanceof AST_Chain)) { 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.logical && !(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_Assign && expr.logical) { return false; } else 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 { const lhs = expr instanceof AST_Assign ? expr.left : expr.expression; return !is_ref_of(lhs, AST_SymbolConst) && !is_ref_of(lhs, AST_SymbolLet) && lhs; } } function get_rvalue(expr) { if (expr instanceof AST_Assign) { return expr.right; } else { return expr.value; } } function get_lvalues(expr) { var lvalues = new Map(); if (expr instanceof AST_Unary) return lvalues; var tw = new TreeWalker(function (node) { var sym = node; while (sym instanceof AST_PropAccess) sym = sym.expression; if (sym instanceof AST_SymbolRef) { const prev = lvalues.get(sym.name); if (!prev || !prev.modified) { lvalues.set(sym.name, { def: sym.definition(), modified: 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 = node.name instanceof AST_SymbolConst ? make_node(AST_Undefined, node.value) // `const` always needs 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.get_defun_scope() === defun_scope && !(in_loop && (lvalues.has(lhs.name) || candidate instanceof AST_Unary || (candidate instanceof AST_Assign && !candidate.logical && candidate.operator != "="))); } function value_has_side_effects(expr) { if (expr instanceof AST_Unary) return unary_side_effects.has(expr.operator); 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() !== defun_scope) return true; return def.references.some((ref) => ref.scope.get_defun_scope() !== defun_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.get_defun_scope() !== defun_scope; } return false; } /** * Will any of the pulled-in lvalues shadow a variable in newScope or parents? * similar to scope_encloses_variables_in_this_scope */ function shadows(my_scope, lvalues) { for (const { def } of lvalues.values()) { const looked_up = my_scope.find_variable(def.name); if (looked_up) { if (looked_up === def) continue; return true; } } 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); statements.splice(i, 1, ...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) { let ab, new_else; ab = aborts(stat.body); if ( can_merge_flow(ab) && (new_else = as_statement_array_with_return(stat.body, ab)) ) { if (ab.label) { remove(ab.label.thedef.references, ab); } CHANGED = true; stat = stat.clone(); stat.condition = stat.condition.negate(compressor); stat.body = make_node(AST_BlockStatement, stat, { body: as_statement_array(stat.alternative).concat(extract_functions()) }); stat.alternative = make_node(AST_BlockStatement, stat, { body: new_else }); statements[i] = stat.transform(compressor); continue; } ab = aborts(stat.alternative); if ( can_merge_flow(ab) && (new_else = as_statement_array_with_return(stat.alternative, 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()) }); stat.alternative = make_node(AST_BlockStatement, stat.alternative, { body: new_else }); 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); if (ab !== body[body.length - 1]) { return undefined; } body = body.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) { trim_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 || line instanceof AST_Const || line instanceof AST_Let) { 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)) { const abort = walk(prev.body, node => { if (node instanceof AST_Scope) return true; if (node instanceof AST_Binary && node.operator === "in") { return walk_abort; } }); 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 && !body.logical) { 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(nearest_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") < 2015 && 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 instanceof AST_Var && stat.init instanceof AST_Var && 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; } } } terser-5.19.2/lib/equivalent-to.js000066400000000000000000000201571445647217600170420ustar00rootroot00000000000000import { AST_Array, AST_Atom, AST_Await, AST_BigInt, AST_Binary, AST_Block, AST_Call, AST_Catch, AST_Chain, AST_Class, AST_ClassProperty, AST_ConciseMethod, AST_Conditional, AST_Debugger, AST_Definitions, AST_Destructuring, AST_Directive, AST_Do, AST_Dot, AST_DotHash, AST_EmptyStatement, AST_Expansion, AST_Export, AST_Finally, AST_For, AST_ForIn, AST_ForOf, AST_If, AST_Import, AST_ImportMeta, AST_Jump, AST_LabeledStatement, AST_Lambda, AST_LoopControl, AST_NameMapping, AST_NewTarget, AST_Node, AST_Number, AST_Object, AST_ObjectGetter, AST_ObjectKeyVal, AST_ObjectProperty, AST_ObjectSetter, AST_PrefixedTemplateString, AST_PropAccess, AST_RegExp, AST_Sequence, AST_SimpleStatement, AST_String, AST_Super, AST_Switch, AST_SwitchBranch, AST_Symbol, AST_TemplateSegment, AST_TemplateString, AST_This, AST_Toplevel, AST_Try, AST_Unary, AST_VarDef, AST_While, AST_With, AST_Yield } from "./ast.js"; const shallow_cmp = (node1, node2) => { return ( node1 === null && node2 === null || node1.TYPE === node2.TYPE && node1.shallow_cmp(node2) ); }; export const equivalent_to = (tree1, tree2) => { if (!shallow_cmp(tree1, tree2)) return false; const walk_1_state = [tree1]; const walk_2_state = [tree2]; const walk_1_push = walk_1_state.push.bind(walk_1_state); const walk_2_push = walk_2_state.push.bind(walk_2_state); while (walk_1_state.length && walk_2_state.length) { const node_1 = walk_1_state.pop(); const node_2 = walk_2_state.pop(); if (!shallow_cmp(node_1, node_2)) return false; node_1._children_backwards(walk_1_push); node_2._children_backwards(walk_2_push); if (walk_1_state.length !== walk_2_state.length) { // Different number of children return false; } } return walk_1_state.length == 0 && walk_2_state.length == 0; }; const pass_through = () => true; AST_Node.prototype.shallow_cmp = function () { throw new Error("did not find a shallow_cmp function for " + this.constructor.name); }; AST_Debugger.prototype.shallow_cmp = pass_through; AST_Directive.prototype.shallow_cmp = function(other) { return this.value === other.value; }; AST_SimpleStatement.prototype.shallow_cmp = pass_through; AST_Block.prototype.shallow_cmp = pass_through; AST_EmptyStatement.prototype.shallow_cmp = pass_through; AST_LabeledStatement.prototype.shallow_cmp = function(other) { return this.label.name === other.label.name; }; AST_Do.prototype.shallow_cmp = pass_through; AST_While.prototype.shallow_cmp = pass_through; AST_For.prototype.shallow_cmp = function(other) { return (this.init == null ? other.init == null : this.init === other.init) && (this.condition == null ? other.condition == null : this.condition === other.condition) && (this.step == null ? other.step == null : this.step === other.step); }; AST_ForIn.prototype.shallow_cmp = pass_through; AST_ForOf.prototype.shallow_cmp = pass_through; AST_With.prototype.shallow_cmp = pass_through; AST_Toplevel.prototype.shallow_cmp = pass_through; AST_Expansion.prototype.shallow_cmp = pass_through; AST_Lambda.prototype.shallow_cmp = function(other) { return this.is_generator === other.is_generator && this.async === other.async; }; AST_Destructuring.prototype.shallow_cmp = function(other) { return this.is_array === other.is_array; }; AST_PrefixedTemplateString.prototype.shallow_cmp = pass_through; AST_TemplateString.prototype.shallow_cmp = pass_through; AST_TemplateSegment.prototype.shallow_cmp = function(other) { return this.value === other.value; }; AST_Jump.prototype.shallow_cmp = pass_through; AST_LoopControl.prototype.shallow_cmp = pass_through; AST_Await.prototype.shallow_cmp = pass_through; AST_Yield.prototype.shallow_cmp = function(other) { return this.is_star === other.is_star; }; AST_If.prototype.shallow_cmp = function(other) { return this.alternative == null ? other.alternative == null : this.alternative === other.alternative; }; AST_Switch.prototype.shallow_cmp = pass_through; AST_SwitchBranch.prototype.shallow_cmp = pass_through; AST_Try.prototype.shallow_cmp = function(other) { return (this.body === other.body) && (this.bcatch == null ? other.bcatch == null : this.bcatch === other.bcatch) && (this.bfinally == null ? other.bfinally == null : this.bfinally === other.bfinally); }; AST_Catch.prototype.shallow_cmp = function(other) { return this.argname == null ? other.argname == null : this.argname === other.argname; }; AST_Finally.prototype.shallow_cmp = pass_through; AST_Definitions.prototype.shallow_cmp = pass_through; AST_VarDef.prototype.shallow_cmp = function(other) { return this.value == null ? other.value == null : this.value === other.value; }; AST_NameMapping.prototype.shallow_cmp = pass_through; AST_Import.prototype.shallow_cmp = function(other) { return (this.imported_name == null ? other.imported_name == null : this.imported_name === other.imported_name) && (this.imported_names == null ? other.imported_names == null : this.imported_names === other.imported_names); }; AST_ImportMeta.prototype.shallow_cmp = pass_through; AST_Export.prototype.shallow_cmp = function(other) { return (this.exported_definition == null ? other.exported_definition == null : this.exported_definition === other.exported_definition) && (this.exported_value == null ? other.exported_value == null : this.exported_value === other.exported_value) && (this.exported_names == null ? other.exported_names == null : this.exported_names === other.exported_names) && this.module_name === other.module_name && this.is_default === other.is_default; }; AST_Call.prototype.shallow_cmp = pass_through; AST_Sequence.prototype.shallow_cmp = pass_through; AST_PropAccess.prototype.shallow_cmp = pass_through; AST_Chain.prototype.shallow_cmp = pass_through; AST_Dot.prototype.shallow_cmp = function(other) { return this.property === other.property; }; AST_DotHash.prototype.shallow_cmp = function(other) { return this.property === other.property; }; AST_Unary.prototype.shallow_cmp = function(other) { return this.operator === other.operator; }; AST_Binary.prototype.shallow_cmp = function(other) { return this.operator === other.operator; }; AST_Conditional.prototype.shallow_cmp = pass_through; AST_Array.prototype.shallow_cmp = pass_through; AST_Object.prototype.shallow_cmp = pass_through; AST_ObjectProperty.prototype.shallow_cmp = pass_through; AST_ObjectKeyVal.prototype.shallow_cmp = function(other) { return this.key === other.key; }; AST_ObjectSetter.prototype.shallow_cmp = function(other) { return this.static === other.static; }; AST_ObjectGetter.prototype.shallow_cmp = function(other) { return this.static === other.static; }; AST_ConciseMethod.prototype.shallow_cmp = function(other) { return this.static === other.static && this.is_generator === other.is_generator && this.async === other.async; }; AST_Class.prototype.shallow_cmp = function(other) { return (this.name == null ? other.name == null : this.name === other.name) && (this.extends == null ? other.extends == null : this.extends === other.extends); }; AST_ClassProperty.prototype.shallow_cmp = function(other) { return this.static === other.static; }; AST_Symbol.prototype.shallow_cmp = function(other) { return this.name === other.name; }; AST_NewTarget.prototype.shallow_cmp = pass_through; AST_This.prototype.shallow_cmp = pass_through; AST_Super.prototype.shallow_cmp = pass_through; AST_String.prototype.shallow_cmp = function(other) { return this.value === other.value; }; AST_Number.prototype.shallow_cmp = function(other) { return this.value === other.value; }; AST_BigInt.prototype.shallow_cmp = function(other) { return this.value === other.value; }; AST_RegExp.prototype.shallow_cmp = function (other) { return ( this.value.flags === other.value.flags && this.value.source === other.value.source ); }; AST_Atom.prototype.shallow_cmp = pass_through; terser-5.19.2/lib/minify.js000066400000000000000000000325361445647217600155440ustar00rootroot00000000000000"use strict"; /* eslint-env browser, es6, node */ import { defaults, map_from_object, map_to_object, HOP, } from "./utils/index.js"; import { AST_Toplevel, AST_Node, walk, AST_Scope } 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, mangle_private_properties, reserve_quoted_keys, find_annotated_props, } from "./propmangle.js"; // to/from base64 functions // Prefer built-in Buffer, if available, then use hack // https://developer.mozilla.org/en-US/docs/Glossary/Base64#The_Unicode_Problem var to_ascii = typeof Buffer !== "undefined" ? (b64) => Buffer.from(b64, "base64").toString() : (b64) => decodeURIComponent(escape(atob(b64))); var to_base64 = typeof Buffer !== "undefined" ? (str) => Buffer.from(str).toString("base64") : (str) => btoa(unescape(encodeURIComponent(str))); function read_source_map(code) { var match = /(?:^|[^.])\/\/# sourceMappingURL=data:application\/json(;[\w=-]*)?;base64,([+/0-9A-Za-z]*=*)\s*$/.exec(code); if (!match) { console.warn("inline source map not found"); return null; } return to_ascii(match[2]); } function set_shorthand(name, options, keys) { if (options[name]) { keys.forEach(function(key) { if (options[key]) { if (typeof options[key] != "object") options[key] = {}; if (!(name in options[key])) options[key][name] = options[name]; } }); } } function init_cache(cache) { if (!cache) return; if (!("props" in cache)) { cache.props = new Map(); } else if (!(cache.props instanceof Map)) { cache.props = map_from_object(cache.props); } } function cache_to_json(cache) { return { props: map_to_object(cache.props) }; } function log_input(files, options, fs, debug_folder) { if (!(fs && fs.writeFileSync && fs.mkdirSync)) { return; } try { fs.mkdirSync(debug_folder); } catch (e) { if (e.code !== "EEXIST") throw e; } const log_path = `${debug_folder}/terser-debug-${(Math.random() * 9999999) | 0}.log`; options = options || {}; const options_str = JSON.stringify(options, (_key, thing) => { if (typeof thing === "function") return "[Function " + thing.toString() + "]"; if (thing instanceof RegExp) return "[RegExp " + thing.toString() + "]"; return thing; }, 4); const files_str = (file) => { if (typeof file === "object" && options.parse && options.parse.spidermonkey) { return JSON.stringify(file, null, 2); } else if (typeof file === "object") { return Object.keys(file) .map((key) => key + ": " + files_str(file[key])) .join("\n\n"); } else if (typeof file === "string") { return "```\n" + file + "\n```"; } else { return file; // What do? } }; fs.writeFileSync(log_path, "Options: \n" + options_str + "\n\nInput files:\n\n" + files_str(files) + "\n"); } async function minify(files, options, _fs_module) { if ( _fs_module && typeof process === "object" && process.env && typeof process.env.TERSER_DEBUG_DIR === "string" ) { log_input(files, options, _fs_module, process.env.TERSER_DEBUG_DIR); } options = defaults(options, { compress: {}, ecma: undefined, enclose: false, ie8: false, keep_classnames: undefined, keep_fnames: false, mangle: {}, module: false, nameCache: null, output: null, format: null, parse: {}, rename: undefined, safari10: false, sourceMap: false, spidermonkey: false, timings: false, toplevel: false, warnings: false, wrap: false, }, true); var timings = options.timings && { start: Date.now() }; if (options.keep_classnames === undefined) { options.keep_classnames = options.keep_fnames; } if (options.rename === undefined) { options.rename = options.compress && options.mangle; } if (options.output && options.format) { throw new Error("Please only specify either output or format option, preferrably format."); } options.format = options.format || options.output || {}; set_shorthand("ecma", options, [ "parse", "compress", "format" ]); set_shorthand("ie8", options, [ "compress", "mangle", "format" ]); set_shorthand("keep_classnames", options, [ "compress", "mangle" ]); set_shorthand("keep_fnames", options, [ "compress", "mangle" ]); set_shorthand("module", options, [ "parse", "compress", "mangle" ]); set_shorthand("safari10", options, [ "mangle", "format" ]); set_shorthand("toplevel", options, [ "compress", "mangle" ]); set_shorthand("warnings", options, [ "compress" ]); // legacy var quoted_props; if (options.mangle) { options.mangle = defaults(options.mangle, { cache: options.nameCache && (options.nameCache.vars || {}), eval: false, ie8: false, keep_classnames: false, keep_fnames: false, module: false, nth_identifier: base54, properties: false, reserved: [], safari10: false, toplevel: false, }, true); if (options.mangle.properties) { if (typeof options.mangle.properties != "object") { options.mangle.properties = {}; } if (options.mangle.properties.keep_quoted) { quoted_props = options.mangle.properties.reserved; if (!Array.isArray(quoted_props)) quoted_props = []; options.mangle.properties.reserved = quoted_props; } if (options.nameCache && !("cache" in options.mangle.properties)) { options.mangle.properties.cache = options.nameCache.props || {}; } } init_cache(options.mangle.cache); init_cache(options.mangle.properties.cache); } if (options.sourceMap) { options.sourceMap = defaults(options.sourceMap, { asObject: false, content: null, filename: null, includeSources: false, root: null, url: null, }, true); } // -- Parse phase -- if (timings) timings.parse = Date.now(); var toplevel; if (files instanceof AST_Toplevel) { toplevel = files; } else { if (typeof files == "string" || (options.parse.spidermonkey && !Array.isArray(files))) { files = [ files ]; } options.parse = options.parse || {}; options.parse.toplevel = null; if (options.parse.spidermonkey) { options.parse.toplevel = AST_Node.from_mozilla_ast(Object.keys(files).reduce(function(toplevel, name) { if (!toplevel) return files[name]; toplevel.body = toplevel.body.concat(files[name].body); return toplevel; }, null)); } else { delete options.parse.spidermonkey; for (var name in files) if (HOP(files, name)) { options.parse.filename = name; options.parse.toplevel = parse(files[name], options.parse); if (options.sourceMap && options.sourceMap.content == "inline") { if (Object.keys(files).length > 1) throw new Error("inline source map only works with singular input"); options.sourceMap.content = read_source_map(files[name]); } } } toplevel = options.parse.toplevel; } if (quoted_props && options.mangle.properties.keep_quoted !== "strict") { reserve_quoted_keys(toplevel, quoted_props); } var annotated_props; if (options.mangle && options.mangle.properties) { annotated_props = find_annotated_props(toplevel); } 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); } // -- Compress phase -- if (timings) timings.compress = Date.now(); if (options.compress) { toplevel = new Compressor(options.compress, { mangle_options: options.mangle }).compress(toplevel); } // -- Mangle phase -- if (timings) timings.scope = Date.now(); if (options.mangle) toplevel.figure_out_scope(options.mangle); if (timings) timings.mangle = Date.now(); if (options.mangle) { toplevel.compute_char_frequency(options.mangle); toplevel.mangle_names(options.mangle); toplevel = mangle_private_properties(toplevel, options.mangle); } if (timings) timings.properties = Date.now(); if (options.mangle && options.mangle.properties) { toplevel = mangle_properties(toplevel, options.mangle.properties, annotated_props); } // Format phase if (timings) timings.format = Date.now(); var result = {}; if (options.format.ast) { result.ast = toplevel; } if (options.format.spidermonkey) { result.ast = toplevel.to_mozilla_ast(); } let format_options; if (!HOP(options.format, "code") || options.format.code) { // Make a shallow copy so that we can modify without mutating the user's input. format_options = {...options.format}; if (!format_options.ast) { // Destroy stuff to save RAM. (unless the deprecated `ast` option is on) format_options._destroy_ast = true; walk(toplevel, node => { if (node instanceof AST_Scope) { node.variables = undefined; node.enclosed = undefined; node.parent_scope = undefined; } if (node.block_scope) { node.block_scope.variables = undefined; node.block_scope.enclosed = undefined; node.parent_scope = undefined; } }); } if (options.sourceMap) { if (options.sourceMap.includeSources && files instanceof AST_Toplevel) { throw new Error("original source content unavailable"); } format_options.source_map = await SourceMap({ file: options.sourceMap.filename, orig: options.sourceMap.content, root: options.sourceMap.root, files: options.sourceMap.includeSources ? files : null, }); } delete format_options.ast; delete format_options.code; delete format_options.spidermonkey; var stream = OutputStream(format_options); toplevel.print(stream); result.code = stream.get(); if (options.sourceMap) { Object.defineProperty(result, "map", { configurable: true, enumerable: true, get() { const map = format_options.source_map.getEncoded(); return (result.map = options.sourceMap.asObject ? map : JSON.stringify(map)); }, set(value) { Object.defineProperty(result, "map", { value, writable: true, }); } }); result.decoded_map = format_options.source_map.getDecoded(); if (options.sourceMap.url == "inline") { var sourceMap = typeof result.map === "object" ? JSON.stringify(result.map) : result.map; result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(sourceMap); } else if (options.sourceMap.url) { result.code += "\n//# sourceMappingURL=" + options.sourceMap.url; } } } if (options.nameCache && options.mangle) { if (options.mangle.cache) options.nameCache.vars = cache_to_json(options.mangle.cache); if (options.mangle.properties && options.mangle.properties.cache) { options.nameCache.props = cache_to_json(options.mangle.properties.cache); } } if (format_options && format_options.source_map) { format_options.source_map.destroy(); } if (timings) { timings.end = Date.now(); result.timings = { parse: 1e-3 * (timings.rename - timings.parse), rename: 1e-3 * (timings.compress - timings.rename), compress: 1e-3 * (timings.scope - timings.compress), scope: 1e-3 * (timings.mangle - timings.scope), mangle: 1e-3 * (timings.properties - timings.mangle), properties: 1e-3 * (timings.format - timings.properties), format: 1e-3 * (timings.end - timings.format), total: 1e-3 * (timings.end - timings.start) }; } return result; } export { minify, to_ascii, }; terser-5.19.2/lib/mozilla-ast.js000066400000000000000000001673511445647217600165110ustar00rootroot00000000000000/*********************************************************************** 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. ***********************************************************************/ import { make_node } from "./utils/index.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_Chain, AST_Class, AST_ClassStaticBlock, AST_ClassExpression, AST_ClassProperty, AST_ClassPrivateProperty, 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_DotHash, 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_ImportMeta, 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_PrivateGetter, AST_PrivateMethod, AST_PrivateSetter, AST_PrivateIn, 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_SymbolClassProperty, AST_SymbolPrivateProperty, 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_TryBlock, AST_Unary, AST_UnaryPostfix, AST_UnaryPrefix, AST_Var, AST_VarDef, AST_While, AST_With, AST_Yield, } from "./ast.js"; import { is_basic_identifier_string } from "./parse.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; }; const assert_clause_from_moz = (assertions) => { if (assertions && assertions.length > 0) { return new AST_Object({ start: my_start_token(assertions), end: my_end_token(assertions), properties: assertions.map((assertion_kv) => new AST_ObjectKeyVal({ start: my_start_token(assertion_kv), end: my_end_token(assertion_kv), key: assertion_kv.key.name || assertion_kv.key.value, value: from_moz(assertion_kv.value) }) ) }); } return null; }; 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) { return new AST_DefaultAssign({ 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) { const body = M.body.type === "BlockStatement" ? from_moz(M.body).body : [make_node(AST_Return, {}, { value: from_moz(M.body) })]; return new AST_Arrow({ start: my_start_token(M), end: my_end_token(M), argnames: M.params.map(from_moz), 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 : new AST_TryBlock(from_moz(M.block)), 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) { const is_private = M.key.type === "PrivateIdentifier"; const key = M.computed ? from_moz(M.key) : new AST_SymbolMethod({ name: M.key.name || M.key.value }); var args = { start : my_start_token(M), end : my_end_token(M), key, value : from_moz(M.value), static : M.static, }; if (M.kind == "get") { return new (is_private ? AST_PrivateGetter : AST_ObjectGetter)(args); } if (M.kind == "set") { return new (is_private ? AST_PrivateSetter : AST_ObjectSetter)(args); } args.is_generator = M.value.generator; args.async = M.value.async; return new (is_private ? AST_PrivateMethod : AST_ConciseMethod)(args); }, FieldDefinition: function(M) { let key; if (M.computed) { key = from_moz(M.key); } else { if (M.key.type !== "Identifier") throw new Error("Non-Identifier key in FieldDefinition"); key = from_moz(M.key); } return new AST_ClassProperty({ start : my_start_token(M), end : my_end_token(M), key, value : from_moz(M.value), static : M.static, }); }, PropertyDefinition: function(M) { let key; if (M.computed) { key = from_moz(M.key); } else if (M.key.type === "PrivateIdentifier") { return new AST_ClassPrivateProperty({ start : my_start_token(M), end : my_end_token(M), key : from_moz(M.key), value : from_moz(M.value), static : M.static, }); } else { if (M.key.type !== "Identifier") { throw new Error("Non-Identifier key in PropertyDefinition"); } key = from_moz(M.key); } return new AST_ClassProperty({ start : my_start_token(M), end : my_end_token(M), key, value : from_moz(M.value), static : M.static, }); }, PrivateIdentifier: function (M) { return new AST_SymbolPrivateProperty({ start: my_start_token(M), end: my_end_token(M), name: M.name }); }, StaticBlock: function(M) { return new AST_ClassStaticBlock({ start : my_start_token(M), end : my_end_token(M), body : M.body.map(from_moz), }); }, 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) { if (M.property.type === "PrivateIdentifier") { return new AST_DotHash({ start : my_start_token(M), end : my_end_token(M), property : M.property.name, expression : from_moz(M.object), optional : M.optional || false }); } 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), optional : M.optional || false }); }, ChainExpression: function(M) { return new AST_Chain({ start : my_start_token(M), end : my_end_token(M), expression : from_moz(M.expression) }); }, 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" || specifier.type === "ImportNamespaceSpecifier") { if (!imported_names) { imported_names = []; } imported_names.push(from_moz(specifier)); } else if (specifier.type === "ImportDefaultSpecifier") { imported_name = from_moz(specifier); } }); 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), assert_clause: assert_clause_from_moz(M.assertions) }); }, ImportSpecifier: function(M) { return new AST_NameMapping({ start: my_start_token(M), end: my_end_token(M), foreign_name: from_moz(M.imported), name: from_moz(M.local) }); }, ImportDefaultSpecifier: function(M) { return from_moz(M.local); }, ImportNamespaceSpecifier: function(M) { return new AST_NameMapping({ start: my_start_token(M), end: my_end_token(M), foreign_name: new AST_SymbolImportForeign({ name: "*" }), name: from_moz(M.local) }); }, ExportAllDeclaration: function(M) { var foreign_name = M.exported == null ? new AST_SymbolExportForeign({ name: "*" }) : from_moz(M.exported); 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: foreign_name }) ], module_name: from_moz(M.source), assert_clause: assert_clause_from_moz(M.assertions) }); }, 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 from_moz(specifier); }) : null, module_name: from_moz(M.source), assert_clause: assert_clause_from_moz(M.assertions) }); }, 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 }); }, ExportSpecifier: function(M) { return new AST_NameMapping({ foreign_name: from_moz(M.exported), name: from_moz(M.local) }); }, Literal: function(M) { var val = M.value, args = { start : my_start_token(M), end : my_end_token(M) }; var rx = M.regex; if (rx && rx.pattern) { // RegExpLiteral as per ESTree AST spec args.value = { source: rx.pattern, flags: rx.flags }; return new AST_RegExp(args); } else if (rx) { // support legacy RegExp const rx_source = M.raw || val; const match = rx_source.match(/^\/(.*)\/(\w*)$/); if (!match) throw new Error("Invalid regex source " + rx_source); const [_, source, flags] = match; args.value = { source, flags }; return new AST_RegExp(args); } if (val === null) return new AST_Null(args); switch (typeof val) { case "string": args.quote = "\""; var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2]; if (p.type == "ImportSpecifier") { args.name = val; return new AST_SymbolImportForeign(args); } else if (p.type == "ExportSpecifier") { args.name = val; if (M == p.exported) { return new AST_SymbolExportForeign(args); } else { return new AST_SymbolExport(args); } } else if (p.type == "ExportAllDeclaration" && M == p.exported) { args.name = val; return new AST_SymbolExportForeign(args); } args.value = val; return new AST_String(args); case "number": args.value = val; args.raw = M.raw || val.toString(); 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) }); } else if (M.meta.name === "import" && M.property.name === "meta") { return new AST_ImportMeta({ 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 == "PropertyDefinition" || p.type === "FieldDefinition" ? (p.key === M && p.computed || p.value === M ? AST_SymbolRef : AST_SymbolClassProperty) : 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 }); }, EmptyStatement: function(M) { return new AST_EmptyStatement({ start: my_start_token(M), end: my_end_token(M) }); }, BlockStatement: function(M) { return new AST_BlockStatement({ start: my_start_token(M), end: my_end_token(M), body: M.body.map(from_moz) }); }, IfStatement: function(M) { return new AST_If({ start: my_start_token(M), end: my_end_token(M), condition: from_moz(M.test), body: from_moz(M.consequent), alternative: from_moz(M.alternate) }); }, LabeledStatement: function(M) { return new AST_LabeledStatement({ start: my_start_token(M), end: my_end_token(M), label: from_moz(M.label), body: from_moz(M.body) }); }, BreakStatement: function(M) { return new AST_Break({ start: my_start_token(M), end: my_end_token(M), label: from_moz(M.label) }); }, ContinueStatement: function(M) { return new AST_Continue({ start: my_start_token(M), end: my_end_token(M), label: from_moz(M.label) }); }, WithStatement: function(M) { return new AST_With({ start: my_start_token(M), end: my_end_token(M), expression: from_moz(M.object), body: from_moz(M.body) }); }, SwitchStatement: function(M) { return new AST_Switch({ start: my_start_token(M), end: my_end_token(M), expression: from_moz(M.discriminant), body: M.cases.map(from_moz) }); }, ReturnStatement: function(M) { return new AST_Return({ start: my_start_token(M), end: my_end_token(M), value: from_moz(M.argument) }); }, ThrowStatement: function(M) { return new AST_Throw({ start: my_start_token(M), end: my_end_token(M), value: from_moz(M.argument) }); }, WhileStatement: function(M) { return new AST_While({ start: my_start_token(M), end: my_end_token(M), condition: from_moz(M.test), body: from_moz(M.body) }); }, DoWhileStatement: function(M) { return new AST_Do({ start: my_start_token(M), end: my_end_token(M), condition: from_moz(M.test), body: from_moz(M.body) }); }, ForStatement: function(M) { return new AST_For({ start: my_start_token(M), end: my_end_token(M), init: from_moz(M.init), condition: from_moz(M.test), step: from_moz(M.update), body: from_moz(M.body) }); }, ForInStatement: function(M) { return new AST_ForIn({ start: my_start_token(M), end: my_end_token(M), init: from_moz(M.left), object: from_moz(M.right), body: from_moz(M.body) }); }, ForOfStatement: function(M) { return new AST_ForOf({ start: my_start_token(M), end: my_end_token(M), init: from_moz(M.left), object: from_moz(M.right), body: from_moz(M.body), await: M.await }); }, AwaitExpression: function(M) { return new AST_Await({ start: my_start_token(M), end: my_end_token(M), expression: from_moz(M.argument) }); }, YieldExpression: function(M) { return new AST_Yield({ start: my_start_token(M), end: my_end_token(M), expression: from_moz(M.argument), is_star: M.delegate }); }, DebuggerStatement: function(M) { return new AST_Debugger({ start: my_start_token(M), end: my_end_token(M) }); }, VariableDeclarator: function(M) { return new AST_VarDef({ start: my_start_token(M), end: my_end_token(M), name: from_moz(M.id), value: from_moz(M.init) }); }, CatchClause: function(M) { return new AST_Catch({ start: my_start_token(M), end: my_end_token(M), argname: from_moz(M.param), body: from_moz(M.body).body }); }, ThisExpression: function(M) { return new AST_This({ start: my_start_token(M), end: my_end_token(M) }); }, Super: function(M) { return new AST_Super({ start: my_start_token(M), end: my_end_token(M) }); }, BinaryExpression: function(M) { if (M.left.type === "PrivateIdentifier") { return new AST_PrivateIn({ start: my_start_token(M), end: my_end_token(M), key: new AST_SymbolPrivateProperty({ start: my_start_token(M.left), end: my_end_token(M.left), name: M.left.name }), value: from_moz(M.right), }); } return new AST_Binary({ start: my_start_token(M), end: my_end_token(M), operator: M.operator, left: from_moz(M.left), right: from_moz(M.right) }); }, LogicalExpression: function(M) { return new AST_Binary({ start: my_start_token(M), end: my_end_token(M), operator: M.operator, left: from_moz(M.left), right: from_moz(M.right) }); }, AssignmentExpression: function(M) { return new AST_Assign({ start: my_start_token(M), end: my_end_token(M), operator: M.operator, left: from_moz(M.left), right: from_moz(M.right) }); }, ConditionalExpression: function(M) { return new AST_Conditional({ start: my_start_token(M), end: my_end_token(M), condition: from_moz(M.test), consequent: from_moz(M.consequent), alternative: from_moz(M.alternate) }); }, NewExpression: function(M) { return new AST_New({ start: my_start_token(M), end: my_end_token(M), expression: from_moz(M.callee), args: M.arguments.map(from_moz) }); }, CallExpression: function(M) { return new AST_Call({ start: my_start_token(M), end: my_end_token(M), expression: from_moz(M.callee), optional: M.optional, args: M.arguments.map(from_moz) }); } }; 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) }); }; def_to_moz(AST_EmptyStatement, function To_Moz_EmptyStatement() { return { type: "EmptyStatement" }; }); def_to_moz(AST_BlockStatement, function To_Moz_BlockStatement(M) { return { type: "BlockStatement", body: M.body.map(to_moz) }; }); def_to_moz(AST_If, function To_Moz_IfStatement(M) { return { type: "IfStatement", test: to_moz(M.condition), consequent: to_moz(M.body), alternate: to_moz(M.alternative) }; }); def_to_moz(AST_LabeledStatement, function To_Moz_LabeledStatement(M) { return { type: "LabeledStatement", label: to_moz(M.label), body: to_moz(M.body) }; }); def_to_moz(AST_Break, function To_Moz_BreakStatement(M) { return { type: "BreakStatement", label: to_moz(M.label) }; }); def_to_moz(AST_Continue, function To_Moz_ContinueStatement(M) { return { type: "ContinueStatement", label: to_moz(M.label) }; }); def_to_moz(AST_With, function To_Moz_WithStatement(M) { return { type: "WithStatement", object: to_moz(M.expression), body: to_moz(M.body) }; }); def_to_moz(AST_Switch, function To_Moz_SwitchStatement(M) { return { type: "SwitchStatement", discriminant: to_moz(M.expression), cases: M.body.map(to_moz) }; }); def_to_moz(AST_Return, function To_Moz_ReturnStatement(M) { return { type: "ReturnStatement", argument: to_moz(M.value) }; }); def_to_moz(AST_Throw, function To_Moz_ThrowStatement(M) { return { type: "ThrowStatement", argument: to_moz(M.value) }; }); def_to_moz(AST_While, function To_Moz_WhileStatement(M) { return { type: "WhileStatement", test: to_moz(M.condition), body: to_moz(M.body) }; }); def_to_moz(AST_Do, function To_Moz_DoWhileStatement(M) { return { type: "DoWhileStatement", test: to_moz(M.condition), body: to_moz(M.body) }; }); def_to_moz(AST_For, function To_Moz_ForStatement(M) { return { type: "ForStatement", init: to_moz(M.init), test: to_moz(M.condition), update: to_moz(M.step), body: to_moz(M.body) }; }); def_to_moz(AST_ForIn, function To_Moz_ForInStatement(M) { return { type: "ForInStatement", left: to_moz(M.init), right: to_moz(M.object), body: to_moz(M.body) }; }); def_to_moz(AST_ForOf, function To_Moz_ForOfStatement(M) { return { type: "ForOfStatement", left: to_moz(M.init), right: to_moz(M.object), body: to_moz(M.body), await: M.await }; }); def_to_moz(AST_Await, function To_Moz_AwaitExpression(M) { return { type: "AwaitExpression", argument: to_moz(M.expression) }; }); def_to_moz(AST_Yield, function To_Moz_YieldExpression(M) { return { type: "YieldExpression", argument: to_moz(M.expression), delegate: M.is_star }; }); def_to_moz(AST_Debugger, function To_Moz_DebuggerStatement() { return { type: "DebuggerStatement" }; }); def_to_moz(AST_VarDef, function To_Moz_VariableDeclarator(M) { return { type: "VariableDeclarator", id: to_moz(M.name), init: to_moz(M.value) }; }); def_to_moz(AST_Catch, function To_Moz_CatchClause(M) { return { type: "CatchClause", param: to_moz(M.argname), body: to_moz_block(M) }; }); def_to_moz(AST_This, function To_Moz_ThisExpression() { return { type: "ThisExpression" }; }); def_to_moz(AST_Super, function To_Moz_Super() { return { type: "Super" }; }); def_to_moz(AST_Binary, function To_Moz_BinaryExpression(M) { return { type: "BinaryExpression", operator: M.operator, left: to_moz(M.left), right: to_moz(M.right) }; }); def_to_moz(AST_Binary, function To_Moz_LogicalExpression(M) { return { type: "LogicalExpression", operator: M.operator, left: to_moz(M.left), right: to_moz(M.right) }; }); def_to_moz(AST_Assign, function To_Moz_AssignmentExpression(M) { return { type: "AssignmentExpression", operator: M.operator, left: to_moz(M.left), right: to_moz(M.right) }; }); def_to_moz(AST_Conditional, function To_Moz_ConditionalExpression(M) { return { type: "ConditionalExpression", test: to_moz(M.condition), consequent: to_moz(M.consequent), alternate: to_moz(M.alternative) }; }); def_to_moz(AST_New, function To_Moz_NewExpression(M) { return { type: "NewExpression", callee: to_moz(M.expression), arguments: M.args.map(to_moz) }; }); def_to_moz(AST_Call, function To_Moz_CallExpression(M) { return { type: "CallExpression", callee: to_moz(M.expression), optional: M.optional, arguments: M.args.map(to_moz) }; }); 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) { 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 = { type: "BlockStatement", body: M.body.map(to_moz) }; 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, raw: M.print_to_string() }, directive: 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.body), 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) }; }); const assert_clause_to_moz = assert_clause => { const assertions = []; if (assert_clause) { for (const { key, value } of assert_clause.properties) { const key_moz = is_basic_identifier_string(key) ? { type: "Identifier", name: key } : { type: "Literal", value: key, raw: JSON.stringify(key) }; assertions.push({ type: "ImportAttribute", key: key_moz, value: to_moz(value) }); } } return assertions; }; def_to_moz(AST_Export, function To_Moz_ExportDeclaration(M) { if (M.exported_names) { var first_exported = M.exported_names[0]; var first_exported_name = first_exported.name; if (first_exported_name.name === "*" && !first_exported_name.quote) { var foreign_name = first_exported.foreign_name; var exported = foreign_name.name === "*" && !foreign_name.quote ? null : to_moz(foreign_name); return { type: "ExportAllDeclaration", source: to_moz(M.module_name), exported: exported, assertions: assert_clause_to_moz(M.assert_clause) }; } 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), assertions: assert_clause_to_moz(M.assert_clause) }; } 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) { var first_imported_foreign_name = M.imported_names[0].foreign_name; if (first_imported_foreign_name.name === "*" && !first_imported_foreign_name.quote) { specifiers.push({ type: "ImportNamespaceSpecifier", local: to_moz(M.imported_names[0].name) }); } else { 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), assertions: assert_clause_to_moz(M.assert_clause) }; }); def_to_moz(AST_ImportMeta, function To_Moz_MetaProperty() { return { type: "MetaProperty", meta: { type: "Identifier", name: "import" }, property: { type: "Identifier", name: "meta" } }; }); def_to_moz(AST_Sequence, function To_Moz_SequenceExpression(M) { return { type: "SequenceExpression", expressions: M.expressions.map(to_moz) }; }); def_to_moz(AST_DotHash, function To_Moz_PrivateMemberExpression(M) { return { type: "MemberExpression", object: to_moz(M.expression), computed: false, property: { type: "PrivateIdentifier", name: M.property }, optional: M.optional }; }); 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}, optional: M.optional }; }); def_to_moz(AST_Chain, function To_Moz_ChainExpression(M) { return { type: "ChainExpression", expression: to_moz(M.expression) }; }); 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) }; } const type = M.operator == "&&" || M.operator == "||" || M.operator === "??" ? "LogicalExpression" : "BinaryExpression"; return { type, left: to_moz(M.left), operator: M.operator, right: to_moz(M.right) }; }); def_to_moz(AST_PrivateIn, function To_Moz_BinaryExpression_PrivateIn(M) { return { type: "BinaryExpression", left: { type: "PrivateIdentifier", name: M.key.name }, operator: "in", right: to_moz(M.value), }; }); 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 (M instanceof AST_PrivateGetter || M instanceof AST_PrivateSetter) { const kind = M instanceof AST_PrivateGetter ? "get" : "set"; return { type: "MethodDefinition", computed: false, kind: kind, static: M.static, key: { type: "PrivateIdentifier", name: M.key.name }, value: to_moz(M.value) }; } if (M instanceof AST_ClassPrivateProperty) { return { type: "PropertyDefinition", key: { type: "PrivateIdentifier", name: M.key.name }, value: to_moz(M.value), computed: false, static: M.static }; } if (M instanceof AST_ClassProperty) { return { type: "PropertyDefinition", key, value: to_moz(M.value), computed, static: M.static }; } 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) }; } const key = M instanceof AST_PrivateMethod ? { type: "PrivateIdentifier", name: M.key.name } : to_moz(M.key); return { type: "MethodDefinition", kind: M.key === "constructor" ? "constructor" : "method", key, value: to_moz(M.value), computed: !(M.key instanceof AST_Symbol) || M.key instanceof AST_SymbolRef, static: M.static, }; }); 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_ClassStaticBlock, function To_Moz_StaticBlock(M) { return { type: "StaticBlock", body: M.body.map(to_moz), }; }); def_to_moz(AST_NewTarget, function To_Moz_MetaProperty() { 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) || (( M instanceof AST_SymbolImportForeign || M instanceof AST_SymbolExportForeign || M instanceof AST_SymbolExport ) && M.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) { const pattern = M.value.source; const flags = M.value.flags; return { type: "Literal", value: null, raw: M.print_to_string(), regex: { pattern, flags } }; }); def_to_moz(AST_Constant, function To_Moz_Literal(M) { var value = M.value; return { type: "Literal", value: value, raw: M.raw || M.print_to_string() }; }); 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 my_start_token(moznode) { var loc = moznode.loc, start = loc && loc.start; var range = moznode.range; return new AST_Token( "", "", start && start.line || 0, start && start.column || 0, range ? range [0] : moznode.start, false, [], [], loc && loc.source, ); } function my_end_token(moznode) { var loc = moznode.loc, end = loc && loc.end; var range = moznode.range; return new AST_Token( "", "", end && end.line || 0, end && end.column || 0, range ? range [0] : moznode.end, false, [], [], loc && loc.source, ); } 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) { var start = mynode.start; var end = mynode.end; if (!(start && end)) { return moznode; } 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-5.19.2/lib/output.js000066400000000000000000002360411445647217600156060ustar00rootroot00000000000000/*********************************************************************** 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, regexp_source_fix, sort_regexp_flags, return_false, return_true, } from "./utils/index.js"; import { first_in_statement, left_is_object } 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_Chain, AST_Class, AST_ClassExpression, AST_ClassPrivateProperty, AST_ClassProperty, AST_ClassStaticBlock, AST_ConciseMethod, AST_PrivateGetter, AST_PrivateMethod, AST_SymbolPrivateProperty, AST_PrivateSetter, AST_PrivateIn, 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_DotHash, 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_ImportMeta, 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_SymbolClassProperty, AST_SymbolMethod, AST_SymbolRef, AST_TemplateSegment, AST_TemplateString, AST_This, AST_Throw, AST_Toplevel, AST_Try, AST_TryBlock, AST_Unary, AST_UnaryPostfix, AST_UnaryPrefix, AST_Var, AST_VarDef, AST_While, AST_With, AST_Yield, TreeWalker, walk, walk_abort } from "./ast.js"; import { get_full_char_code, get_full_char, is_identifier_char, is_basic_identifier_string, is_identifier_string, PRECEDENCE, ALL_RESERVED_WORDS, } from "./parse.js"; const EXPECT_DIRECTIVE = /^$|[;{][\s\n]*$/; const CODE_LINE_BREAK = 10; const CODE_SPACE = 32; const r_annotation = /[@#]__(PURE|INLINE|NOINLINE)__/g; function is_some_comments(comment) { // multiline comment return ( (comment.type === "comment2" || comment.type === "comment1") && /@preserve|@copyright|@lic|@cc_on|^\**!/i.test(comment.value) ); } class Rope { constructor() { this.committed = ""; this.current = ""; } append(str) { this.current += str; } insertAt(char, index) { const { committed, current } = this; if (index < committed.length) { this.committed = committed.slice(0, index) + char + committed.slice(index); } else if (index === committed.length) { this.committed += char; } else { index -= committed.length; this.committed += current.slice(0, index) + char; this.current = current.slice(index); } } charAt(index) { const { committed } = this; if (index < committed.length) return committed[index]; return this.current[index - committed.length]; } curLength() { return this.current.length; } length() { return this.committed.length + this.current.length; } toString() { return this.committed + this.current; } } function OutputStream(options) { var readonly = !options; options = defaults(options, { ascii_only : false, beautify : false, braces : false, comments : "some", ecma : 5, ie8 : false, indent_level : 4, indent_start : 0, inline_script : true, keep_numbers : false, keep_quoted_props : false, max_line_len : false, preamble : null, preserve_annotations : false, quote_keys : false, quote_style : 0, safari10 : false, semicolons : true, shebang : true, shorthand : undefined, source_map : null, webkit : false, width : 80, wrap_iife : false, wrap_func_args : true, _destroy_ast : false }, true); if (options.shorthand === undefined) options.shorthand = options.ecma > 5; // Convert comment option to RegExp if necessary and set up comments filter var comment_filter = return_false; // Default case, throw all comments away if (options.comments) { let 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 = new Rope(); let printed_comments = new Set(); var to_utf8 = options.ascii_only ? function(str, identifier = false, regexp = false) { if (options.ecma >= 2015 && !options.safari10 && !regexp) { 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) { return str.replace(/[\ud800-\udbff][\udc00-\udfff]|([\ud800-\udbff]|[\udc00-\udfff])/g, function(match, lone) { if (lone) { return "\\u" + lone.charCodeAt(0).toString(16); } return match; }); }; 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 { let { name, token } = mapping; if (name !== false) { if (token.type == "name" || token.type === "privatename") { name = token.value; } else if (name instanceof AST_Symbol) { name = token.type === "string" ? token.value : name.name; } } options.source_map.add( mapping.token.file, mapping.line, mapping.col, mapping.token.line, mapping.token.col, is_basic_identifier_string(name) ? name : undefined ); } catch(ex) { // Ignore bad mapping } }); mappings = []; } : noop; var ensure_line_len = options.max_line_len ? function() { if (current_col > options.max_line_len) { if (might_add_newline) { OUTPUT.insertAt("\n", might_add_newline); const curLength = OUTPUT.curLength(); if (mappings) { var delta = curLength - current_col; mappings.forEach(function(mapping) { mapping.line++; mapping.col += delta; }); } current_line++; current_pos++; current_col = curLength; } } 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.append(";"); current_col++; current_pos++; } else { ensure_line_len(); if (current_col > 0) { OUTPUT.append("\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.append(" "); 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.append(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.charAt(newline_insert) != "\n") { OUTPUT.insertAt("\n", 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.toString(); } function has_nlb() { const output = OUTPUT.toString(); 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 filter_comment(comment) { if (!options.preserve_annotations) { comment = comment.replace(r_annotation, " "); } if (/^\s*$/.test(comment)) { return ""; } return comment.replace(/(<\s*\/\s*)(script)/i, "<\\/$2"); } function prepend_comments(node) { var self = this; var start = node.start; if (!start) return; var printed_comments = self.printed_comments; // There cannot be a newline between return/yield and its value. const keyword_with_value = node instanceof AST_Exit && node.value || (node instanceof AST_Await || node instanceof AST_Yield) && node.expression; if ( start.comments_before && printed_comments.has(start.comments_before) ) { if (keyword_with_value) { start.comments_before = []; } else { return; } } var comments = start.comments_before; if (!comments) { comments = start.comments_before = []; } printed_comments.add(comments); if (keyword_with_value) { var tw = new TreeWalker(function(node) { var parent = tw.parent(); if (parent instanceof AST_Exit || parent instanceof AST_Await || parent instanceof AST_Yield || 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 && !printed_comments.has(text)) { printed_comments.add(text); comments = comments.concat(text); } } else { return true; } }); tw.push(node); keyword_with_value.walk(tw); } if (current_pos == 0) { if (comments.length > 0 && options.shebang && comments[0].type === "comment5" && !printed_comments.has(comments[0])) { 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).filter(c => !printed_comments.has(c)); if (comments.length == 0) return; var last_nlb = has_nlb(); comments.forEach(function(c, i) { printed_comments.add(c); if (!last_nlb) { if (c.nlb) { print("\n"); indent(); last_nlb = true; } else if (i > 0) { space(); } } if (/comment[134]/.test(c.type)) { var value = filter_comment(c.value); if (value) { print("//" + value + "\n"); indent(); } last_nlb = true; } else if (c.type == "comment2") { var value = filter_comment(c.value); if (value) { print("/*" + value + "*/"); } 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 printed_comments = self.printed_comments; var comments = token[tail ? "comments_before" : "comments_after"]; if (!comments || printed_comments.has(comments)) return; if (!(node instanceof AST_Statement || comments.every((c) => !/comment[134]/.test(c.type) ))) return; printed_comments.add(comments); var insert = OUTPUT.length(); comments.filter(comment_filter, node).forEach(function(c, i) { if (printed_comments.has(c)) return; printed_comments.add(c); 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)) { const value = filter_comment(c.value); if (value) { print("//" + value); } need_newline_indented = true; } else if (c.type == "comment2") { const value = filter_comment(c.value); if (value) { print("/*" + value + "*/"); } need_space = true; } }); if (OUTPUT.length() > insert) newline_insert = insert; } /** * When output.option("_destroy_ast") is enabled, destroy the function. * Call this after printing it. */ const gc_scope = options["_destroy_ast"] ? function gc_scope(scope) { scope.body.length = 0; scope.argnames.length = 0; } : noop; var stack = []; return { get : get, toString : get, indent : indent, in_directive : false, use_asm : null, active_scope : null, 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.toString())) { 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]; }, gc_scope, printed_comments: printed_comments, 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); } AST_Node.DEFMETHOD("print", function(output, force_parens) { var self = this, generator = self._codegen; if (self instanceof AST_Scope) { output.active_scope = self; } else if (!output.use_asm && self instanceof AST_Directive && self.value == "use asm") { output.use_asm = output.active_scope; } function doit() { output.prepend_comments(self); self.add_source_map(output); generator(self, output); output.append_comments(self); } output.push_node(self); if (force_parens || self.needs_parens(output)) { output.with_parens(doit); } else { doit(); } output.pop_node(); if (self === output.use_asm) { output.use_asm = null; } }); AST_Node.DEFMETHOD("_print", AST_Node.prototype.print); AST_Node.DEFMETHOD("print_to_string", function(options) { var output = OutputStream(options); this.print(output); return output.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(); if (p instanceof AST_Call && p.expression === this) { return true; } } if (output.option("wrap_func_args")) { var p = output.parent(); if (p instanceof AST_Call && p.args.includes(this)) { return true; } } return false; }); PARENS(AST_Arrow, function(output) { var p = output.parent(); if ( output.option("wrap_func_args") && p instanceof AST_Call && p.args.includes(this) ) { return true; } return p instanceof AST_PropAccess && p.expression === this; }); // same goes for an object literal (as in AST_Function), because // otherwise {...} 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 || p instanceof AST_Binary && p.operator === "**" && p.left === 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) { const po = p.operator; const so = this.operator; if (so === "??" && (po === "||" || po === "&&")) { return true; } if (po === "??" && (so === "||" || so === "&&")) { return true; } const pp = PRECEDENCE[po]; const 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_Chain, function(output) { var p = output.parent(); if (!(p instanceof AST_Call || p instanceof AST_PropAccess)) return false; return p.expression === this; }); 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. return walk(this, node => { if (node instanceof AST_Scope) return true; if (node instanceof AST_Call) { return walk_abort; // makes walk() return true. } }); } }); 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 (this.args.length === 0 && (p instanceof AST_PropAccess // (new Date).getTime(), (new Date)["getTime"]() || p instanceof AST_Call && p.expression === this || p instanceof AST_PrefixedTemplateString && p.prefix === 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; output.in_directive = allow_directives; body.forEach(function(stmt, i) { if (output.in_directive === true && !(stmt instanceof AST_Directive || stmt instanceof AST_EmptyStatement || (stmt instanceof AST_SimpleStatement && stmt.body instanceof AST_String) )) { output.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 (output.in_directive === true && stmt instanceof AST_SimpleStatement && stmt.body instanceof AST_String ) { output.in_directive = false; } }); output.in_directive = false; } AST_StatementWithBody.DEFMETHOD("_do_print_body", function(output) { print_maybe_braced_body(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.add_mapping(self.end); 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); output.add_mapping(self.end); }); } 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); output.gc_scope(self); }); DEFPRINT(AST_PrefixedTemplateString, function(self, output) { var tag = self.prefix; var parenthesize_tag = tag instanceof AST_Lambda || tag instanceof AST_Binary || tag instanceof AST_Conditional || tag instanceof AST_Sequence || tag instanceof AST_Unary || tag instanceof AST_Dot && tag.expression instanceof AST_Object; 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("`"); }); DEFPRINT(AST_TemplateSegment, function(self, output) { output.print_template_string_chars(self.value); }); 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(); const first_statement = self.body[0]; if ( self.body.length === 1 && first_statement instanceof AST_Return ) { const returned = first_statement.value; if (!returned) { output.print("{}"); } else if (left_is_object(returned)) { output.print("("); returned.print(output); output.print(")"); } else { returned.print(output); } } else { print_braced(self, output); } if (needs_parens) { output.print(")"); } output.gc_scope(self); }); /* -----[ exits ]----- */ AST_Exit.DEFMETHOD("_do_print", function(output, kind) { output.print(kind); if (this.value) { output.space(); const comments = this.value.start.comments_before; if (comments && comments.length && !output.printed_comments.has(comments)) { output.print("("); this.value.print(output); output.print(")"); } else { 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 || e instanceof AST_Await || e instanceof AST_Object ); 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; } print_maybe_braced_body(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 print_maybe_braced_body(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(); self.body.print(output); if (self.bcatch) { output.space(); self.bcatch.print(output); } if (self.bfinally) { output.space(); self.bfinally.print(output); } }); DEFPRINT(AST_TryBlock, function(self, output) { print_braced(self, 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].foreign_name.quote) { 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); if (self.assert_clause) { output.print("assert"); self.assert_clause.print(output); } output.semicolon(); }); DEFPRINT(AST_ImportMeta, function(self, output) { output.print("import.meta"); }); DEFPRINT(AST_NameMapping, function(self, output) { var is_import = output.parent() instanceof AST_Import; var definition = self.name.definition(); var foreign_name = self.foreign_name; var names_are_different = (definition && definition.mangled_name || self.name.name) !== foreign_name.name; if (!names_are_different && foreign_name.name === "*" && foreign_name.quote != self.name.quote) { // export * as "*" names_are_different = true; } var foreign_name_is_name = foreign_name.quote == null; if (names_are_different) { if (is_import) { if (foreign_name_is_name) { output.print(foreign_name.name); } else { output.print_string(foreign_name.name, foreign_name.quote); } } else { if (self.name.quote == null) { self.name.print(output); } else { output.print_string(self.name.name, self.name.quote); } } output.space(); output.print("as"); output.space(); if (is_import) { self.name.print(output); } else { if (foreign_name_is_name) { output.print(foreign_name.name); } else { output.print_string(foreign_name.name, foreign_name.quote); } } } else { if (self.name.quote == null) { self.name.print(output); } else { output.print_string(self.name.name, self.name.quote); } } }); 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].name.quote) { 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.assert_clause) { output.print("assert"); self.assert_clause.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) { parens = walk(node, node => { // Don't go into scopes -- except arrow functions: // https://github.com/terser/terser/issues/1019#issuecomment-877642607 if (node instanceof AST_Scope && !(node instanceof AST_Arrow)) { return true; } if ( node instanceof AST_Binary && node.operator == "in" || node instanceof AST_PrivateIn ) { return walk_abort; // makes walk() 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 && self.args.length === 0) return; if (self.expression instanceof AST_Call || self.expression instanceof AST_Lambda) { output.add_mapping(self.start); } if (self.optional) output.print("?."); 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; var print_computed = ALL_RESERVED_WORDS.has(prop) ? output.option("ie8") : !is_identifier_string( prop, output.option("ecma") >= 2015 && !output.option("safari10") ); if (self.optional) output.print("?."); if (print_computed) { 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("."); } } if (!self.optional) output.print("."); // the name after dot would be mapped about here. output.add_mapping(self.end); output.print_name(prop); } }); DEFPRINT(AST_DotHash, function(self, output) { var expr = self.expression; expr.print(output); var prop = self.property; if (self.optional) output.print("?"); output.print(".#"); output.add_mapping(self.end); output.print_name(prop); }); DEFPRINT(AST_Sub, function(self, output) { self.expression.print(output); if (self.optional) output.print("?."); output.print("["); self.property.print(output); output.print("]"); }); DEFPRINT(AST_Chain, function(self, output) { self.expression.print(output); }); DEFPRINT(AST_UnaryPrefix, function(self, output) { var op = self.operator; if (op === "--" && output.last().endsWith("!")) { // avoid printing " output.print(" "); } else { // the space is optional depending on "beautify" output.space(); } output.print(op); output.space(); self.right.print(output); }); DEFPRINT(AST_Conditional, function(self, output) { self.condition.print(output); output.space(); output.print("?"); output.space(); self.consequent.print(output); output.space(); output.colon(); self.alternative.print(output); }); /* -----[ literals ]----- */ DEFPRINT(AST_Array, function(self, output) { output.with_square(function() { var a = self.elements, len = a.length; if (len > 0) output.space(); a.forEach(function(exp, i) { if (i) output.comma(); exp.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 && exp instanceof AST_Hole) output.comma(); }); if (len > 0) output.space(); }); }); DEFPRINT(AST_Object, function(self, output) { if (self.properties.length > 0) output.with_block(function() { self.properties.forEach(function(prop, i) { if (i) { output.print(","); output.newline(); } output.indent(); prop.print(output); }); output.newline(); }); else print_braced_empty(self, output); }); DEFPRINT(AST_Class, function(self, output) { output.print("class"); output.space(); if (self.name) { self.name.print(output); output.space(); } if (self.extends) { var parens = ( !(self.extends instanceof AST_SymbolRef) && !(self.extends instanceof AST_PropAccess) && !(self.extends instanceof AST_ClassExpression) && !(self.extends instanceof AST_Function) ); output.print("extends"); if (parens) { output.print("("); } else { output.space(); } self.extends.print(output); if (parens) { output.print(")"); } else { output.space(); } } if (self.properties.length > 0) output.with_block(function() { self.properties.forEach(function(prop, i) { if (i) { output.newline(); } output.indent(); prop.print(output); }); output.newline(); }); else output.print("{}"); }); DEFPRINT(AST_NewTarget, function(self, output) { output.print("new.target"); }); /** Prints a prop name. Returns whether it can be used as a shorthand. */ function print_property_name(key, quote, output) { if (output.option("quote_keys")) { output.print_string(key); return false; } if ("" + +key == key && key >= 0) { if (output.option("keep_numbers")) { output.print(key); return false; } output.print(make_num(key)); return false; } var print_string = ALL_RESERVED_WORDS.has(key) ? output.option("ie8") : ( output.option("ecma") < 2015 || output.option("safari10") ? !is_basic_identifier_string(key) : !is_identifier_string(key, true) ); if (print_string || (quote && output.option("keep_quoted_props"))) { output.print_string(key, quote); return false; } output.print_name(key); return true; } DEFPRINT(AST_ObjectKeyVal, function(self, output) { function get_name(self) { var def = self.definition(); return def ? def.mangled_name || def.name : self.name; } const try_shorthand = output.option("shorthand") && !(self.key instanceof AST_Node); if ( try_shorthand && self.value instanceof AST_Symbol && get_name(self.value) === self.key && !ALL_RESERVED_WORDS.has(self.key) ) { const was_shorthand = print_property_name(self.key, self.quote, output); if (!was_shorthand) { output.colon(); self.value.print(output); } } else if ( try_shorthand && self.value instanceof AST_DefaultAssign && self.value.left instanceof AST_Symbol && get_name(self.value.left) === self.key ) { const was_shorthand = print_property_name(self.key, self.quote, output); if (!was_shorthand) { output.colon(); self.value.left.print(output); } output.space(); output.print("="); output.space(); self.value.right.print(output); } else { if (!(self.key instanceof AST_Node)) { print_property_name(self.key, self.quote, output); } else { output.with_square(function() { self.key.print(output); }); } output.colon(); self.value.print(output); } }); DEFPRINT(AST_ClassPrivateProperty, (self, output) => { if (self.static) { output.print("static"); output.space(); } output.print("#"); print_property_name(self.key.name, self.quote, output); if (self.value) { output.print("="); self.value.print(output); } output.semicolon(); }); DEFPRINT(AST_ClassProperty, (self, output) => { if (self.static) { output.print("static"); output.space(); } if (self.key instanceof AST_SymbolClassProperty) { print_property_name(self.key.name, self.quote, output); } else { output.print("["); self.key.print(output); output.print("]"); } if (self.value) { output.print("="); self.value.print(output); } output.semicolon(); }); AST_ObjectProperty.DEFMETHOD("_print_getter_setter", function(type, is_private, output) { var self = this; if (self.static) { output.print("static"); output.space(); } if (type) { output.print(type); output.space(); } if (self.key instanceof AST_SymbolMethod) { if (is_private) output.print("#"); print_property_name(self.key.name, self.quote, output); self.key.add_source_map(output); } else { output.with_square(function() { self.key.print(output); }); } self.value._do_print(output, true); }); DEFPRINT(AST_ObjectSetter, function(self, output) { self._print_getter_setter("set", false, output); }); DEFPRINT(AST_ObjectGetter, function(self, output) { self._print_getter_setter("get", false, output); }); DEFPRINT(AST_PrivateSetter, function(self, output) { self._print_getter_setter("set", true, output); }); DEFPRINT(AST_PrivateGetter, function(self, output) { self._print_getter_setter("get", true, output); }); DEFPRINT(AST_PrivateMethod, function(self, output) { var type; if (self.is_generator && self.async) { type = "async*"; } else if (self.is_generator) { type = "*"; } else if (self.async) { type = "async"; } self._print_getter_setter(type, true, output); }); DEFPRINT(AST_PrivateIn, function(self, output) { self.key.print(output); output.space(); output.print("in"); output.space(); self.value.print(output); }); DEFPRINT(AST_SymbolPrivateProperty, function(self, output) { output.print("#" + self.name); }); DEFPRINT(AST_ConciseMethod, function(self, output) { var type; if (self.is_generator && self.async) { type = "async*"; } else if (self.is_generator) { type = "*"; } else if (self.async) { type = "async"; } self._print_getter_setter(type, false, output); }); DEFPRINT(AST_ClassStaticBlock, function (self, output) { output.print("static"); output.space(); print_braced(self, output); }); AST_Symbol.DEFMETHOD("_do_print", function(output) { var def = this.definition(); output.print_name(def ? def.mangled_name || def.name : this.name); }); DEFPRINT(AST_Symbol, function (self, output) { self._do_print(output); }); DEFPRINT(AST_Hole, noop); DEFPRINT(AST_This, function(self, output) { output.print("this"); }); DEFPRINT(AST_Super, function(self, output) { output.print("super"); }); DEFPRINT(AST_Constant, function(self, output) { output.print(self.getValue()); }); DEFPRINT(AST_String, function(self, output) { output.print_string(self.getValue(), self.quote, output.in_directive); }); DEFPRINT(AST_Number, function(self, output) { if ((output.option("keep_numbers") || output.use_asm) && self.raw) { output.print(self.raw); } else { output.print(make_num(self.getValue())); } }); DEFPRINT(AST_BigInt, function(self, output) { output.print(self.getValue() + "n"); }); const r_slash_script = /(<\s*\/\s*script)/i; const r_starts_with_script = /^\s*script/i; const slash_script_replace = (_, $1) => $1.replace("/", "\\/"); DEFPRINT(AST_RegExp, function(self, output) { let { source, flags } = self.getValue(); source = regexp_source_fix(source); flags = flags ? sort_regexp_flags(flags) : ""; // Avoid outputting end of script tag source = source.replace(r_slash_script, slash_script_replace); if (r_starts_with_script.test(source) && output.last().endsWith("<")) { output.print(" "); } output.print(output.to_utf8(`/${source}/${flags}`, false, true)); const parent = output.parent(); if ( parent instanceof AST_Binary && /^\w/.test(parent.operator) && parent.left === self ) { output.print(" "); } }); /** if, for, while, may or may not have braces surrounding its body */ function print_maybe_braced_body(stat, output) { if (output.option("braces")) { make_block(stat, output); } else { if (!stat || stat instanceof AST_EmptyStatement) output.force_semicolon(); else if (stat instanceof AST_Let || stat instanceof AST_Const || stat instanceof AST_Class) make_block(stat, output); else stat.print(output); } } function best_of(a) { var best = a[0], len = best.length; for (var i = 1; i < a.length; ++i) { if (a[i].length < len) { best = a[i]; len = best.length; } } return best; } function make_num(num) { var str = num.toString(10).replace(/^0\./, ".").replace("e+", "e"); var candidates = [ str ]; if (Math.floor(num) === num) { if (num < 0) { candidates.push("-0x" + (-num).toString(16).toLowerCase()); } else { candidates.push("0x" + num.toString(16).toLowerCase()); } } var match, len, digits; if (match = /^\.0+/.exec(str)) { len = match[0].length; digits = str.slice(len); candidates.push(digits + "e-" + (digits.length + len - 1)); } else if (match = /0+$/.exec(str)) { len = match[0].length; candidates.push(str.slice(0, -len) + "e" + len); } else if (match = /^(\d)\.(\d+)e(-?\d+)$/.exec(str)) { candidates.push(match[1] + match[2] + "e" + (match[3] - match[2].length)); } return best_of(candidates); } function make_block(stmt, output) { if (!stmt || stmt instanceof AST_EmptyStatement) output.print("{}"); else if (stmt instanceof AST_BlockStatement) stmt.print(output); else output.with_block(function() { output.indent(); stmt.print(output); output.newline(); }); } /* -----[ source map generators ]----- */ function DEFMAP(nodetype, generator) { nodetype.forEach(function(nodetype) { nodetype.DEFMETHOD("add_source_map", generator); }); } DEFMAP([ // We could easily add info for ALL nodes, but it seems to me that // would be quite wasteful, hence this noop in the base class. AST_Node, // since the label symbol will mark it AST_LabeledStatement, AST_Toplevel, ], noop); // XXX: I'm not exactly sure if we need it for all of these nodes, // or if we should add even more. DEFMAP([ AST_Array, AST_BlockStatement, AST_Catch, AST_Class, AST_Constant, AST_Debugger, AST_Definitions, AST_Directive, AST_Finally, AST_Jump, AST_Lambda, AST_New, AST_Object, AST_StatementWithBody, AST_Symbol, AST_Switch, AST_SwitchBranch, AST_TemplateString, AST_TemplateSegment, AST_Try, ], function(output) { output.add_mapping(this.start); }); DEFMAP([ AST_ObjectGetter, AST_ObjectSetter, AST_PrivateGetter, AST_PrivateSetter, AST_ConciseMethod, AST_PrivateMethod, ], function(output) { output.add_mapping(this.start, false /*name handled below*/); }); DEFMAP([ AST_SymbolMethod, AST_SymbolPrivateProperty ], function(output) { const tok_type = this.end && this.end.type; if (tok_type === "name" || tok_type === "privatename") { output.add_mapping(this.end, this.name); } else { output.add_mapping(this.end); } }); DEFMAP([ AST_ObjectProperty ], function(output) { output.add_mapping(this.start, this.key); }); })(); export { OutputStream, }; terser-5.19.2/lib/parse.js000066400000000000000000003666161445647217600153740ustar00rootroot00000000000000/*********************************************************************** 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 Parser based on parse-js (http://marijn.haverbeke.nl/parse-js/). 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 { characters, defaults, makePredicate, set_annotation, } from "./utils/index.js"; import { AST_Accessor, AST_Array, AST_Arrow, AST_Assign, AST_Await, AST_BigInt, AST_Binary, AST_BlockStatement, AST_Break, AST_Call, AST_Case, AST_Catch, AST_Chain, AST_ClassExpression, AST_ClassPrivateProperty, AST_ClassProperty, AST_ClassStaticBlock, AST_ConciseMethod, AST_PrivateIn, AST_PrivateGetter, AST_PrivateMethod, AST_PrivateSetter, AST_Conditional, AST_Const, AST_Continue, AST_Debugger, AST_Default, AST_DefaultAssign, AST_DefClass, AST_Definitions, AST_Defun, AST_Destructuring, AST_Directive, AST_Do, AST_Dot, AST_DotHash, 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_ImportMeta, AST_IterationStatement, AST_Label, AST_LabeledStatement, AST_LabelRef, 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_String, AST_Sub, AST_Super, AST_Switch, AST_SymbolCatch, AST_SymbolClass, AST_SymbolClassProperty, 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_SymbolPrivateProperty, AST_Throw, AST_Token, AST_Toplevel, AST_True, AST_Try, AST_TryBlock, AST_UnaryPostfix, AST_UnaryPrefix, AST_Var, AST_VarDef, AST_While, AST_With, AST_Yield, _INLINE, _NOINLINE, _PURE, _KEY, _MANGLEPROP, } from "./ast.js"; var LATEST_RAW = ""; // Only used for numbers and template strings var TEMPLATE_RAWS = new Map(); // Raw template strings var KEYWORDS = "break case catch class const continue debugger default delete do else export extends finally for function if in instanceof let new return switch throw try typeof var void while with"; var KEYWORDS_ATOM = "false null true"; var RESERVED_WORDS = "enum import super this " + KEYWORDS_ATOM + " " + KEYWORDS; var ALL_RESERVED_WORDS = "implements interface package private protected public static " + RESERVED_WORDS; var KEYWORDS_BEFORE_EXPRESSION = "return new delete throw else case yield await"; KEYWORDS = makePredicate(KEYWORDS); RESERVED_WORDS = makePredicate(RESERVED_WORDS); KEYWORDS_BEFORE_EXPRESSION = makePredicate(KEYWORDS_BEFORE_EXPRESSION); KEYWORDS_ATOM = makePredicate(KEYWORDS_ATOM); ALL_RESERVED_WORDS = makePredicate(ALL_RESERVED_WORDS); var OPERATOR_CHARS = makePredicate(characters("+-*&%=<>!?|~^")); var RE_NUM_LITERAL = /[0-9a-f]/i; var RE_HEX_NUMBER = /^0x[0-9a-f]+$/i; var RE_OCT_NUMBER = /^0[0-7]+$/; var RE_ES6_OCT_NUMBER = /^0o[0-7]+$/i; var RE_BIN_NUMBER = /^0b[01]+$/i; var RE_DEC_NUMBER = /^\d*\.?\d*(?:e[+-]?\d*(?:\d\.?|\.?\d)\d*)?$/i; var RE_BIG_INT = /^(0[xob])?[0-9a-f]+n$/i; var OPERATORS = makePredicate([ "in", "instanceof", "typeof", "new", "void", "delete", "++", "--", "+", "-", "!", "~", "&", "|", "^", "*", "**", "/", "%", ">>", "<<", ">>>", "<", ">", "<=", ">=", "==", "===", "!=", "!==", "?", "=", "+=", "-=", "||=", "&&=", "??=", "/=", "*=", "**=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=", "&&", "??", "||", ]); var WHITESPACE_CHARS = makePredicate(characters(" \u00a0\n\r\t\f\u000b\u200b\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\uFEFF")); var NEWLINE_CHARS = makePredicate(characters("\n\r\u2028\u2029")); var PUNC_AFTER_EXPRESSION = makePredicate(characters(";]),:")); var PUNC_BEFORE_EXPRESSION = makePredicate(characters("[{(,;:")); var PUNC_CHARS = makePredicate(characters("[]{}(),;:")); /* -----[ Tokenizer ]----- */ // surrogate safe regexps adapted from https://github.com/mathiasbynens/unicode-8.0.0/tree/89b412d8a71ecca9ed593d9e9fa073ab64acfebe/Binary_Property var UNICODE = { ID_Start: /[$A-Z_a-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B4\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]/, ID_Continue: /(?:[$0-9A-Z_a-z\xAA\xB5\xB7\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B4\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1369-\u1371\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF])+/, }; try { UNICODE = { // https://262.ecma-international.org/13.0/#prod-IdentifierStartChar // $, _, ID_Start ID_Start: new RegExp("[_$\\p{ID_Start}]", "u"), // https://262.ecma-international.org/13.0/#prod-IdentifierPartChar // $, zero-width-joiner, zero-width-non-joiner, ID_Continue ID_Continue: new RegExp("[$\\u200C\\u200D\\p{ID_Continue}]+", "u"), }; } catch(e) { // Could not use modern JS \p{...}. UNICODE is already defined above so let's continue } function get_full_char(str, pos) { if (is_surrogate_pair_head(str.charCodeAt(pos))) { if (is_surrogate_pair_tail(str.charCodeAt(pos + 1))) { return str.charAt(pos) + str.charAt(pos + 1); } } else if (is_surrogate_pair_tail(str.charCodeAt(pos))) { if (is_surrogate_pair_head(str.charCodeAt(pos - 1))) { return str.charAt(pos - 1) + str.charAt(pos); } } return str.charAt(pos); } function get_full_char_code(str, pos) { // https://en.wikipedia.org/wiki/Universal_Character_Set_characters#Surrogates if (is_surrogate_pair_head(str.charCodeAt(pos))) { return 0x10000 + (str.charCodeAt(pos) - 0xd800 << 10) + str.charCodeAt(pos + 1) - 0xdc00; } return str.charCodeAt(pos); } function get_full_char_length(str) { var surrogates = 0; for (var i = 0; i < str.length; i++) { if (is_surrogate_pair_head(str.charCodeAt(i)) && is_surrogate_pair_tail(str.charCodeAt(i + 1))) { surrogates++; i++; } } return str.length - surrogates; } function from_char_code(code) { // Based on https://github.com/mathiasbynens/String.fromCodePoint/blob/master/fromcodepoint.js if (code > 0xFFFF) { code -= 0x10000; return (String.fromCharCode((code >> 10) + 0xD800) + String.fromCharCode((code % 0x400) + 0xDC00)); } return String.fromCharCode(code); } function is_surrogate_pair_head(code) { return code >= 0xd800 && code <= 0xdbff; } function is_surrogate_pair_tail(code) { return code >= 0xdc00 && code <= 0xdfff; } function is_digit(code) { return code >= 48 && code <= 57; } function is_identifier_start(ch) { return UNICODE.ID_Start.test(ch); } function is_identifier_char(ch) { return UNICODE.ID_Continue.test(ch); } const BASIC_IDENT = /^[a-z_$][a-z0-9_$]*$/i; function is_basic_identifier_string(str) { return BASIC_IDENT.test(str); } function is_identifier_string(str, allow_surrogates) { if (BASIC_IDENT.test(str)) { return true; } if (!allow_surrogates && /[\ud800-\udfff]/.test(str)) { return false; } var match = UNICODE.ID_Start.exec(str); if (!match || match.index !== 0) { return false; } str = str.slice(match[0].length); if (!str) { return true; } match = UNICODE.ID_Continue.exec(str); return !!match && match[0].length === str.length; } function parse_js_number(num, allow_e = true) { if (!allow_e && num.includes("e")) { return NaN; } if (RE_HEX_NUMBER.test(num)) { return parseInt(num.substr(2), 16); } else if (RE_OCT_NUMBER.test(num)) { return parseInt(num.substr(1), 8); } else if (RE_ES6_OCT_NUMBER.test(num)) { return parseInt(num.substr(2), 8); } else if (RE_BIN_NUMBER.test(num)) { return parseInt(num.substr(2), 2); } else if (RE_DEC_NUMBER.test(num)) { return parseFloat(num); } else { var val = parseFloat(num); if (val == num) return val; } } class JS_Parse_Error extends Error { constructor(message, filename, line, col, pos) { super(); this.name = "SyntaxError"; this.message = message; this.filename = filename; this.line = line; this.col = col; this.pos = pos; } } function js_error(message, filename, line, col, pos) { throw new JS_Parse_Error(message, filename, line, col, pos); } function is_token(token, type, val) { return token.type == type && (val == null || token.value == val); } var EX_EOF = {}; function tokenizer($TEXT, filename, html5_comments, shebang) { var S = { text : $TEXT, filename : filename, pos : 0, tokpos : 0, line : 1, tokline : 0, col : 0, tokcol : 0, newline_before : false, regex_allowed : false, brace_counter : 0, template_braces : [], comments_before : [], directives : {}, directive_stack : [] }; function peek() { return get_full_char(S.text, S.pos); } // Used because parsing ?. involves a lookahead for a digit function is_option_chain_op() { const must_be_dot = S.text.charCodeAt(S.pos + 1) === 46; if (!must_be_dot) return false; const cannot_be_digit = S.text.charCodeAt(S.pos + 2); return cannot_be_digit < 48 || cannot_be_digit > 57; } function next(signal_eof, in_string) { var ch = get_full_char(S.text, S.pos++); if (signal_eof && !ch) throw EX_EOF; if (NEWLINE_CHARS.has(ch)) { S.newline_before = S.newline_before || !in_string; ++S.line; S.col = 0; if (ch == "\r" && peek() == "\n") { // treat a \r\n sequence as a single \n ++S.pos; ch = "\n"; } } else { if (ch.length > 1) { ++S.pos; ++S.col; } ++S.col; } return ch; } function forward(i) { while (i--) next(); } function looking_at(str) { return S.text.substr(S.pos, str.length) == str; } function find_eol() { var text = S.text; for (var i = S.pos, n = S.text.length; i < n; ++i) { var ch = text[i]; if (NEWLINE_CHARS.has(ch)) return i; } return -1; } function find(what, signal_eof) { var pos = S.text.indexOf(what, S.pos); if (signal_eof && pos == -1) throw EX_EOF; return pos; } function start_token() { S.tokline = S.line; S.tokcol = S.col; S.tokpos = S.pos; } var prev_was_dot = false; var previous_token = null; function token(type, value, is_comment) { S.regex_allowed = ((type == "operator" && !UNARY_POSTFIX.has(value)) || (type == "keyword" && KEYWORDS_BEFORE_EXPRESSION.has(value)) || (type == "punc" && PUNC_BEFORE_EXPRESSION.has(value))) || (type == "arrow"); if (type == "punc" && (value == "." || value == "?.")) { prev_was_dot = true; } else if (!is_comment) { prev_was_dot = false; } const line = S.tokline; const col = S.tokcol; const pos = S.tokpos; const nlb = S.newline_before; const file = filename; let comments_before = []; let comments_after = []; if (!is_comment) { comments_before = S.comments_before; comments_after = S.comments_before = []; } S.newline_before = false; const tok = new AST_Token(type, value, line, col, pos, nlb, comments_before, comments_after, file); if (!is_comment) previous_token = tok; return tok; } function skip_whitespace() { while (WHITESPACE_CHARS.has(peek())) next(); } function read_while(pred) { var ret = "", ch, i = 0; while ((ch = peek()) && pred(ch, i++)) ret += next(); return ret; } function parse_error(err) { js_error(err, filename, S.tokline, S.tokcol, S.tokpos); } function read_num(prefix) { var has_e = false, after_e = false, has_x = false, has_dot = prefix == ".", is_big_int = false, numeric_separator = false; var num = read_while(function(ch, i) { if (is_big_int) return false; var code = ch.charCodeAt(0); switch (code) { case 95: // _ return (numeric_separator = true); case 98: case 66: // bB return (has_x = true); // Can occur in hex sequence, don't return false yet case 111: case 79: // oO case 120: case 88: // xX return has_x ? false : (has_x = true); case 101: case 69: // eE return has_x ? true : has_e ? false : (has_e = after_e = true); case 45: // - return after_e || (i == 0 && !prefix); case 43: // + return after_e; case (after_e = false, 46): // . return (!has_dot && !has_x && !has_e) ? (has_dot = true) : false; } if (ch === "n") { is_big_int = true; return true; } return RE_NUM_LITERAL.test(ch); }); if (prefix) num = prefix + num; LATEST_RAW = num; if (RE_OCT_NUMBER.test(num) && next_token.has_directive("use strict")) { parse_error("Legacy octal literals are not allowed in strict mode"); } if (numeric_separator) { if (num.endsWith("_")) { parse_error("Numeric separators are not allowed at the end of numeric literals"); } else if (num.includes("__")) { parse_error("Only one underscore is allowed as numeric separator"); } num = num.replace(/_/g, ""); } if (num.endsWith("n")) { const without_n = num.slice(0, -1); const allow_e = RE_HEX_NUMBER.test(without_n); const valid = parse_js_number(without_n, allow_e); if (!has_dot && RE_BIG_INT.test(num) && !isNaN(valid)) return token("big_int", without_n); parse_error("Invalid or unexpected token"); } var valid = parse_js_number(num); if (!isNaN(valid)) { return token("num", valid); } else { parse_error("Invalid syntax: " + num); } } function is_octal(ch) { return ch >= "0" && ch <= "7"; } function read_escaped_char(in_string, strict_hex, template_string) { var ch = next(true, in_string); switch (ch.charCodeAt(0)) { case 110 : return "\n"; case 114 : return "\r"; case 116 : return "\t"; case 98 : return "\b"; case 118 : return "\u000b"; // \v case 102 : return "\f"; case 120 : return String.fromCharCode(hex_bytes(2, strict_hex)); // \x case 117 : // \u if (peek() == "{") { next(true); if (peek() === "}") parse_error("Expecting hex-character between {}"); while (peek() == "0") next(true); // No significance var result, length = find("}", true) - S.pos; // Avoid 32 bit integer overflow (1 << 32 === 1) // We know first character isn't 0 and thus out of range anyway if (length > 6 || (result = hex_bytes(length, strict_hex)) > 0x10FFFF) { parse_error("Unicode reference out of bounds"); } next(true); return from_char_code(result); } return String.fromCharCode(hex_bytes(4, strict_hex)); case 10 : return ""; // newline case 13 : // \r if (peek() == "\n") { // DOS newline next(true, in_string); return ""; } } if (is_octal(ch)) { if (template_string && strict_hex) { const represents_null_character = ch === "0" && !is_octal(peek()); if (!represents_null_character) { parse_error("Octal escape sequences are not allowed in template strings"); } } return read_octal_escape_sequence(ch, strict_hex); } return ch; } function read_octal_escape_sequence(ch, strict_octal) { // Read var p = peek(); if (p >= "0" && p <= "7") { ch += next(true); if (ch[0] <= "3" && (p = peek()) >= "0" && p <= "7") ch += next(true); } // Parse if (ch === "0") return "\0"; if (ch.length > 0 && next_token.has_directive("use strict") && strict_octal) parse_error("Legacy octal escape sequences are not allowed in strict mode"); return String.fromCharCode(parseInt(ch, 8)); } function hex_bytes(n, strict_hex) { var num = 0; for (; n > 0; --n) { if (!strict_hex && isNaN(parseInt(peek(), 16))) { return parseInt(num, 16) || ""; } var digit = next(true); if (isNaN(parseInt(digit, 16))) parse_error("Invalid hex-character pattern in string"); num += digit; } return parseInt(num, 16); } var read_string = with_eof_error("Unterminated string constant", function() { const start_pos = S.pos; var quote = next(), ret = []; for (;;) { var ch = next(true, true); if (ch == "\\") ch = read_escaped_char(true, true); else if (ch == "\r" || ch == "\n") parse_error("Unterminated string constant"); else if (ch == quote) break; ret.push(ch); } var tok = token("string", ret.join("")); LATEST_RAW = S.text.slice(start_pos, S.pos); tok.quote = quote; return tok; }); var read_template_characters = with_eof_error("Unterminated template", function(begin) { if (begin) { S.template_braces.push(S.brace_counter); } var content = "", raw = "", ch, tok; next(true, true); while ((ch = next(true, true)) != "`") { if (ch == "\r") { if (peek() == "\n") ++S.pos; ch = "\n"; } else if (ch == "$" && peek() == "{") { next(true, true); S.brace_counter++; tok = token(begin ? "template_head" : "template_substitution", content); TEMPLATE_RAWS.set(tok, raw); tok.template_end = false; return tok; } raw += ch; if (ch == "\\") { var tmp = S.pos; var prev_is_tag = previous_token && (previous_token.type === "name" || previous_token.type === "punc" && (previous_token.value === ")" || previous_token.value === "]")); ch = read_escaped_char(true, !prev_is_tag, true); raw += S.text.substr(tmp, S.pos - tmp); } content += ch; } S.template_braces.pop(); tok = token(begin ? "template_head" : "template_substitution", content); TEMPLATE_RAWS.set(tok, raw); tok.template_end = true; return tok; }); function skip_line_comment(type) { var regex_allowed = S.regex_allowed; var i = find_eol(), ret; if (i == -1) { ret = S.text.substr(S.pos); S.pos = S.text.length; } else { ret = S.text.substring(S.pos, i); S.pos = i; } S.col = S.tokcol + (S.pos - S.tokpos); S.comments_before.push(token(type, ret, true)); S.regex_allowed = regex_allowed; return next_token; } var skip_multiline_comment = with_eof_error("Unterminated multiline comment", function() { var regex_allowed = S.regex_allowed; var i = find("*/", true); var text = S.text.substring(S.pos, i).replace(/\r\n|\r|\u2028|\u2029/g, "\n"); // update stream position forward(get_full_char_length(text) /* text length doesn't count \r\n as 2 char while S.pos - i does */ + 2); S.comments_before.push(token("comment2", text, true)); S.newline_before = S.newline_before || text.includes("\n"); S.regex_allowed = regex_allowed; return next_token; }); var read_name = with_eof_error("Unterminated identifier name", function() { var name = [], ch, escaped = false; var read_escaped_identifier_char = function() { escaped = true; next(); if (peek() !== "u") { parse_error("Expecting UnicodeEscapeSequence -- uXXXX or u{XXXX}"); } return read_escaped_char(false, true); }; // Read first character (ID_Start) if ((ch = peek()) === "\\") { ch = read_escaped_identifier_char(); if (!is_identifier_start(ch)) { parse_error("First identifier char is an invalid identifier char"); } } else if (is_identifier_start(ch)) { next(); } else { return ""; } name.push(ch); // Read ID_Continue while ((ch = peek()) != null) { if ((ch = peek()) === "\\") { ch = read_escaped_identifier_char(); if (!is_identifier_char(ch)) { parse_error("Invalid escaped identifier char"); } } else { if (!is_identifier_char(ch)) { break; } next(); } name.push(ch); } const name_str = name.join(""); if (RESERVED_WORDS.has(name_str) && escaped) { parse_error("Escaped characters are not allowed in keywords"); } return name_str; }); var read_regexp = with_eof_error("Unterminated regular expression", function(source) { var prev_backslash = false, ch, in_class = false; while ((ch = next(true))) if (NEWLINE_CHARS.has(ch)) { parse_error("Unexpected line terminator"); } else if (prev_backslash) { source += "\\" + ch; prev_backslash = false; } else if (ch == "[") { in_class = true; source += ch; } else if (ch == "]" && in_class) { in_class = false; source += ch; } else if (ch == "/" && !in_class) { break; } else if (ch == "\\") { prev_backslash = true; } else { source += ch; } const flags = read_name(); return token("regexp", "/" + source + "/" + flags); }); function read_operator(prefix) { function grow(op) { if (!peek()) return op; var bigger = op + peek(); if (OPERATORS.has(bigger)) { next(); return grow(bigger); } else { return op; } } return token("operator", grow(prefix || next())); } function handle_slash() { next(); switch (peek()) { case "/": next(); return skip_line_comment("comment1"); case "*": next(); return skip_multiline_comment(); } return S.regex_allowed ? read_regexp("") : read_operator("/"); } function handle_eq_sign() { next(); if (peek() === ">") { next(); return token("arrow", "=>"); } else { return read_operator("="); } } function handle_dot() { next(); if (is_digit(peek().charCodeAt(0))) { return read_num("."); } if (peek() === ".") { next(); // Consume second dot next(); // Consume third dot return token("expand", "..."); } return token("punc", "."); } function read_word() { var word = read_name(); if (prev_was_dot) return token("name", word); return KEYWORDS_ATOM.has(word) ? token("atom", word) : !KEYWORDS.has(word) ? token("name", word) : OPERATORS.has(word) ? token("operator", word) : token("keyword", word); } function read_private_word() { next(); return token("privatename", read_name()); } function with_eof_error(eof_error, cont) { return function(x) { try { return cont(x); } catch(ex) { if (ex === EX_EOF) parse_error(eof_error); else throw ex; } }; } function next_token(force_regexp) { if (force_regexp != null) return read_regexp(force_regexp); if (shebang && S.pos == 0 && looking_at("#!")) { start_token(); forward(2); skip_line_comment("comment5"); } for (;;) { skip_whitespace(); start_token(); if (html5_comments) { if (looking_at("") && 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 63: { if (!is_option_chain_op()) break; // Handled below next(); // ? next(); // . return token("punc", "?."); } 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(); if (code == 35) return read_private_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 LOGICAL_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) { // maps start tokens to count of comments found outside of their parens // Example: /* I count */ ( /* I don't */ foo() ) // Useful because comments_before property of call with parens outside // contains both comments inside and outside these parens. Used to find the // right #__PURE__ comments for an expression const outer_comments_before_counts = new WeakMap(); options = defaults(options, { bare_returns : false, ecma : null, // Legacy 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 can_await() { return ( S.in_async === S.in_function || S.in_function === 0 && S.input.has_directive("use strict") ); } 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 _embed_tokens_wrapper(...args) { const start = S.token; const expr = parser(...args); expr.start = start; expr.end = prev(); 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 statement(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 (!LATEST_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": case "privatename": if(is("privatename") && !S.in_class) croak("Private field must be used in an enclosing class"); 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", "(") && !is_token(peek(), "punc", ".")) { next(); var node = import_statement(); 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, is_export_default); 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_statement(); 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 (!can_await()) { 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 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 }); }; class UsedParametersTracker { constructor(is_parameter, strict, duplicates_ok = false) { this.is_parameter = is_parameter; this.duplicates_ok = duplicates_ok; this.parameters = new Set(); this.duplicate = null; this.default_assignment = false; this.spread = false; this.strict_mode = !!strict; } add_parameter(token) { if (this.parameters.has(token.value)) { if (this.duplicate === null) { this.duplicate = token; } this.check_strict(); } else { this.parameters.add(token.value); if (this.is_parameter) { switch (token.value) { case "arguments": case "eval": case "yield": if (this.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(token) { if (this.default_assignment === false) { this.default_assignment = token; } } mark_spread(token) { if (this.spread === false) { this.spread = token; } } mark_strict_mode() { this.strict_mode = true; } is_strict() { return this.default_assignment !== false || this.spread !== false || this.strict_mode; } check_strict() { if (this.is_strict() && this.duplicate !== null && !this.duplicates_ok) { token_error(this.duplicate, "Parameter " + this.duplicate.value + " was used already"); } } } function parameters(params) { var used_parameters = new UsedParametersTracker(true, S.input.has_directive("use strict")); expect("("); while (!is("punc", ")")) { var param = parameter(used_parameters); params.push(param); if (!is("punc", ")")) { expect(","); } if (param instanceof AST_Expansion) { break; } } next(); } function parameter(used_parameters, symbol_type) { var param; var expand = false; if (used_parameters === undefined) { used_parameters = new UsedParametersTracker(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) { const strict = S.input.has_directive("use strict"); const duplicates_ok = symbol_type === AST_SymbolVar; used_parameters = new UsedParametersTracker(false, strict, duplicates_ok); } 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", ")")) { 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 = [new AST_Return({ start: S.token, value: expression(false), end: S.token })]; } --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 (!can_await()) { 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, bcatch = null, bfinally = null; body = new AST_TryBlock({ start : S.token, body : block_(), end : prev(), }); 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 }); } /** * var * vardef1 = 2, * vardef2 = 3; */ function vardefs(no_in, kind) { var var_defs = []; var def; for (;;) { var sym_type = kind === "var" ? AST_SymbolVar : kind === "const" ? AST_SymbolConst : kind === "let" ? AST_SymbolLet : null; // var { a } = b 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"); } var_defs.push(def); if (!is("punc", ",")) break; next(); } return var_defs; } 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(")", true); } else { args = []; } var call = new AST_New({ start : start, expression : newexp, args : args, end : prev() }); annotate(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, raw: LATEST_RAW }); 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 }); annotate(ret); break; case "regexp": const [_, source, flags] = tok.value.match(/^\/(.*)\/(\w*)$/); ret = new AST_RegExp({ start: tok, end: tok, value: { source, flags } }); 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(prop => to_fun_args(prop)) }), default_seen_above); } else if (ex instanceof AST_ObjectKeyVal) { ex.value = to_fun_args(ex.value); 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(name => to_fun_args(name)); 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(elm => to_fun_args(elm)) }), default_seen_above); } else if (ex instanceof AST_Assign) { return insert_default(to_fun_args(ex.left, ex.right), default_seen_above); } else if (ex instanceof AST_DefaultAssign) { ex.left = to_fun_args(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); } if (is("name", "import") && is_token(peek(), "punc", ".")) { return import_meta(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(e => to_fun_args(e)), !!async); } var ex = async ? new AST_Call({ expression: async, args: exprs }) : exprs.length == 1 ? exprs[0] : new AST_Sequence({ expressions: exprs }); if (ex.start) { const outer_comments_before = start.comments_before.length; outer_comments_before_counts.set(start, outer_comments_before); ex.start.comments_before.unshift(...start.comments_before); start.comments_before = ex.start.comments_before; if (outer_comments_before == 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; ex.end.comments_after.push(...end.comments_after); end.comments_after = ex.end.comments_after; } ex.end = end; if (ex instanceof AST_Call) annotate(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(), allow_calls); } if (is("privatename")) { if(!S.in_class) { croak("Private field must be used in an enclosing class"); } const start = S.token; const key = new AST_SymbolPrivateProperty({ start, name: start.value, end: start }); next(); expect_token("operator", "in"); const private_in = new AST_PrivateIn({ start, key, value: subscripts(as_atom_node(), allow_calls), end: prev() }); return subscripts(private_in, allow_calls); } if (ATOMIC_START_TOKEN.has(S.token.type)) { return subscripts(as_atom_node(), allow_calls); } unexpected(); }; function template_string() { var segments = [], start = S.token; segments.push(new AST_TemplateSegment({ start: S.token, raw: TEMPLATE_RAWS.get(S.token), value: S.token.value, end: S.token })); while (!S.token.template_end) { next(); handle_regexp(); segments.push(expression(true)); segments.push(new AST_TemplateSegment({ start: S.token, raw: TEMPLATE_RAWS.get(S.token), 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((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; } if(is("privatename")) { croak("private fields are not allowed in an object"); } 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), logical: false, end: prev() }); } // Create property const kv = new AST_ObjectKeyVal({ start: start, quote: start.quote, key: name instanceof AST_Node ? name : "" + name, value: value, end: prev() }); a.push(annotate(kv)); } next(); return new AST_Object({ properties: a }); }); function class_(KindOfClass, is_export_default) { 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) { if (is_export_default) { KindOfClass = AST_ClassExpression; } else { unexpected(); } } if (S.token.value == "extends") { next(); extends_ = expression(true); } expect("{"); // mark in class feild, const save_in_class = S.in_class; S.in_class = true; while (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); while (is("punc", ";")) { next(); } } // mark in class feild, S.in_class = save_in_class; 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) { const get_symbol_ast = (name, SymbolClass = AST_SymbolMethod) => { if (typeof name === "string" || typeof name === "number") { return new SymbolClass({ start, name: "" + name, end: prev() }); } else if (name === null) { unexpected(); } return name; }; const is_not_method_start = () => !is("punc", "(") && !is("punc", ",") && !is("punc", "}") && !is("punc", ";") && !is("operator", "="); var is_async = false; var is_static = false; var is_generator = false; var is_private = false; var accessor_type = null; if (is_class && name === "static" && is_not_method_start()) { const static_block = class_static_block(); if (static_block != null) { return static_block; } is_static = true; name = as_property_name(); } if (name === "async" && is_not_method_start()) { is_async = true; name = as_property_name(); } if (prev().type === "operator" && prev().value === "*") { is_generator = true; name = as_property_name(); } if ((name === "get" || name === "set") && is_not_method_start()) { accessor_type = name; name = as_property_name(); } if (prev().type === "privatename") { is_private = true; } const property_token = prev(); if (accessor_type != null) { if (!is_private) { const AccessorClass = accessor_type === "get" ? AST_ObjectGetter : AST_ObjectSetter; name = get_symbol_ast(name); return annotate(new AccessorClass({ start, static: is_static, key: name, quote: name instanceof AST_SymbolMethod ? property_token.quote : undefined, value: create_accessor(), end: prev() })); } else { const AccessorClass = accessor_type === "get" ? AST_PrivateGetter : AST_PrivateSetter; return annotate(new AccessorClass({ start, static: is_static, key: get_symbol_ast(name), value: create_accessor(), end: prev(), })); } } if (is("punc", "(")) { name = get_symbol_ast(name); const AST_MethodVariant = is_private ? AST_PrivateMethod : AST_ConciseMethod; var node = new AST_MethodVariant({ 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 annotate(node); } if (is_class) { const key = get_symbol_ast(name, AST_SymbolClassProperty); const quote = key instanceof AST_SymbolClassProperty ? property_token.quote : undefined; const AST_ClassPropertyVariant = is_private ? AST_ClassPrivateProperty : AST_ClassProperty; if (is("operator", "=")) { next(); return annotate( new AST_ClassPropertyVariant({ start, static: is_static, quote, key, value: expression(false), end: prev() }) ); } else if ( is("name") || is("privatename") || is("operator", "*") || is("punc", ";") || is("punc", "}") ) { return annotate( new AST_ClassPropertyVariant({ start, static: is_static, quote, key, end: prev() }) ); } } } function class_static_block() { if (!is("punc", "{")) { return null; } const start = S.token; const body = []; next(); while (!is("punc", "}")) { body.push(statement()); } next(); return new AST_ClassStaticBlock({ start, body, end: prev() }); } function maybe_import_assertion() { if (is("name", "assert") && !has_newline_before(S.token)) { next(); return object_or_destructuring_(); } return null; } function import_statement() { 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(); const assert_clause = maybe_import_assertion(); return new AST_Import({ start, imported_name, imported_names, module_name: new AST_String({ start: mod_str, value: mod_str.value, quote: mod_str.quote, end: mod_str, }), assert_clause, end: S.token, }); } function import_meta(allow_calls) { var start = S.token; expect_token("name", "import"); expect_token("punc", "."); expect_token("name", "meta"); return subscripts(new AST_ImportMeta({ start: start, end: prev() }), allow_calls); } function map_name(is_import) { function make_symbol(type, quote) { return new type({ name: as_property_name(), quote: quote || undefined, 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, start.quote); } else { name = make_symbol(type, start.quote); } if (is("name", "as")) { next(); // The "as" word if (is_import) { name = make_symbol(type); } else { foreign_name = make_symbol(foreign_type, S.token.quote); } } 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, import_or_export_foreign_name) { var foreign_type = is_import ? AST_SymbolImportForeign : AST_SymbolExportForeign; var type = is_import ? AST_SymbolImport : AST_SymbolExport; var start = S.token; var name, foreign_name; var end = prev(); if (is_import) { name = import_or_export_foreign_name; } else { foreign_name = import_or_export_foreign_name; } name = name || new type({ start: start, name: "*", end: end, }); foreign_name = foreign_name || new foreign_type({ start: start, name: "*", 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("name", "as")) { next(); // The "as" word name = is_import ? as_symbol(AST_SymbolImport) : as_symbol_or_string(AST_SymbolExportForeign); } names = [map_nameAsterisk(is_import, name)]; } return names; } function export_statement() { 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(); const assert_clause = maybe_import_assertion(); 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(), assert_clause }); } 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_Defun || node instanceof AST_DefClass ) { exported_definition = node; } else if ( node instanceof AST_ClassExpression || node instanceof AST_Function ) { exported_value = 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(), assert_clause: null }); } 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); } /* falls through */ case "name": case "privatename": 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" && tmp.type != "privatename") 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 as_symbol_or_string(type) { if (!is("name")) { if (!is("string")) { croak("Name or string expected"); } var tok = S.token; var ret = new type({ start : tok, end : tok, name : tok.value, quote : tok.quote }); next(); return ret; } var sym = _make_symbol(type); _verify_symbol(sym); next(); return sym; } // Annotate AST_Call, AST_Lambda or AST_New with the special comments function annotate(node, before_token = node.start) { var comments = before_token.comments_before; const comments_outside_parens = outer_comments_before_counts.get(before_token); var i = comments_outside_parens != null ? comments_outside_parens : comments.length; while (--i >= 0) { var comment = comments[i]; if (/[@#]__/.test(comment.value)) { if (/[@#]__PURE__/.test(comment.value)) { set_annotation(node, _PURE); break; } if (/[@#]__INLINE__/.test(comment.value)) { set_annotation(node, _INLINE); break; } if (/[@#]__NOINLINE__/.test(comment.value)) { set_annotation(node, _NOINLINE); break; } if (/[@#]__KEY__/.test(comment.value)) { set_annotation(node, _KEY); break; } if (/[@#]__MANGLE_PROP__/.test(comment.value)) { set_annotation(node, _MANGLEPROP); break; } } } return node; } var subscripts = function(expr, allow_calls, is_chain) { var start = expr.start; if (is("punc", ".")) { next(); if(is("privatename") && !S.in_class) croak("Private field must be used in an enclosing class"); const AST_DotVariant = is("privatename") ? AST_DotHash : AST_Dot; return annotate(subscripts(new AST_DotVariant({ start : start, expression : expr, optional : false, property : as_name(), end : prev() }), allow_calls, is_chain)); } if (is("punc", "[")) { next(); var prop = expression(true); expect("]"); return annotate(subscripts(new AST_Sub({ start : start, expression : expr, optional : false, property : prop, end : prev() }), allow_calls, is_chain)); } if (allow_calls && is("punc", "(")) { next(); var call = new AST_Call({ start : start, expression : expr, optional : false, args : call_args(), end : prev() }); annotate(call); return subscripts(call, true, is_chain); } if (is("punc", "?.")) { next(); let chain_contents; if (allow_calls && is("punc", "(")) { next(); const call = new AST_Call({ start, optional: true, expression: expr, args: call_args(), end: prev() }); annotate(call); chain_contents = subscripts(call, true, true); } else if (is("name") || is("privatename")) { if(is("privatename") && !S.in_class) croak("Private field must be used in an enclosing class"); const AST_DotVariant = is("privatename") ? AST_DotHash : AST_Dot; chain_contents = annotate(subscripts(new AST_DotVariant({ start, expression: expr, optional: true, property: as_name(), end: prev() }), allow_calls, true)); } else if (is("punc", "[")) { next(); const property = expression(true); expect("]"); chain_contents = annotate(subscripts(new AST_Sub({ start, expression: expr, optional: true, property, end: prev() }), allow_calls, true)); } if (!chain_contents) unexpected(); if (chain_contents instanceof AST_Chain) return chain_contents; return new AST_Chain({ start, expression: chain_contents, end: prev() }); } if (is("template_head")) { if (is_chain) { // a?.b`c` is a syntax error unexpected(); } return subscripts(new AST_PrefixedTemplateString({ start: start, prefix: expr, template_string: template_string(), end: prev() }), allow_calls); } return expr; }; 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(","); } } next(); return args; } var maybe_unary = function(allow_calls, allow_arrows) { var start = S.token; if (start.type == "name" && start.value == "await" && can_await()) { next(); return _await_expression(); } 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), logical : LOGICAL_ASSIGNMENT.has(val), 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 parse_toplevel() { 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 }); } TEMPLATE_RAWS = new Map(); return toplevel; })(); } export { get_full_char_code, get_full_char, is_identifier_char, is_basic_identifier_string, is_identifier_string, is_surrogate_pair_head, is_surrogate_pair_tail, js_error, JS_Parse_Error, parse, PRECEDENCE, ALL_RESERVED_WORDS, tokenizer, }; terser-5.19.2/lib/propmangle.js000066400000000000000000000350441445647217600164120ustar00rootroot00000000000000/*********************************************************************** 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, has_annotation, clear_annotation, } from "./utils/index.js"; import { base54 } from "./scope.js"; import { AST_Binary, AST_Call, AST_ClassPrivateProperty, AST_Conditional, AST_Dot, AST_DotHash, AST_ObjectKeyVal, AST_ObjectProperty, AST_PrivateMethod, AST_PrivateGetter, AST_PrivateSetter, AST_PrivateIn, AST_Sequence, AST_String, AST_Sub, TreeTransformer, TreeWalker, _KEY, _MANGLEPROP, walk, } 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] || function() {}; }); [ "null", "true", "false", "NaN", "Infinity", "-Infinity", "undefined", ].forEach(add); [ Object, Array, Function, Number, String, Boolean, Error, Math, Date, RegExp, objects.Symbol, ArrayBuffer, DataView, decodeURI, decodeURIComponent, encodeURI, encodeURIComponent, eval, EvalError, Float32Array, Float64Array, Int8Array, Int16Array, Int32Array, isFinite, isNaN, JSON, objects.Map, parseFloat, parseInt, objects.Promise, objects.Proxy, RangeError, ReferenceError, objects.Reflect, objects.Set, SyntaxError, TypeError, Uint8Array, Uint8ClampedArray, Uint16Array, Uint32Array, URIError, objects.WeakMap, objects.WeakSet ].forEach(function(ctor) { Object.getOwnPropertyNames(ctor).map(add); if (ctor.prototype) { Object.getOwnPropertyNames(ctor.prototype).map(add); } }); function add(name) { reserved.add(name); } } function reserve_quoted_keys(ast, reserved) { function add(name) { push_uniq(reserved, name); } ast.walk(new TreeWalker(function(node) { if (node instanceof AST_ObjectKeyVal && node.quote) { add(node.key); } else if (node instanceof AST_ObjectProperty && node.quote) { add(node.key.name); } else if (node instanceof AST_Sub) { addStrings(node.property, add); } })); } function addStrings(node, add) { node.walk(new TreeWalker(function(node) { if (node instanceof AST_Sequence) { addStrings(node.tail_node(), add); } else if (node instanceof AST_String) { add(node.value); } else if (node instanceof AST_Conditional) { addStrings(node.consequent, add); addStrings(node.alternative, add); } return true; })); } function mangle_private_properties(ast, options) { var cprivate = -1; var private_cache = new Map(); var nth_identifier = options.nth_identifier || base54; ast = ast.transform(new TreeTransformer(function(node) { if ( node instanceof AST_ClassPrivateProperty || node instanceof AST_PrivateMethod || node instanceof AST_PrivateGetter || node instanceof AST_PrivateSetter || node instanceof AST_PrivateIn ) { node.key.name = mangle_private(node.key.name); } else if (node instanceof AST_DotHash) { node.property = mangle_private(node.property); } })); return ast; function mangle_private(name) { let mangled = private_cache.get(name); if (!mangled) { mangled = nth_identifier.get(++cprivate); private_cache.set(name, mangled); } return mangled; } } function find_annotated_props(ast) { var annotated_props = new Set(); walk(ast, node => { if ( node instanceof AST_ClassPrivateProperty || node instanceof AST_PrivateMethod || node instanceof AST_PrivateGetter || node instanceof AST_PrivateSetter || node instanceof AST_DotHash ) { // handled by mangle_private_properties } else if (node instanceof AST_ObjectKeyVal) { if (typeof node.key == "string" && has_annotation(node, _MANGLEPROP)) { annotated_props.add(node.key); } } else if (node instanceof AST_ObjectProperty) { // setter or getter, since KeyVal is handled above if (has_annotation(node, _MANGLEPROP)) { annotated_props.add(node.key.name); } } else if (node instanceof AST_Dot) { if (has_annotation(node, _MANGLEPROP)) { annotated_props.add(node.property); } } else if (node instanceof AST_Sub) { if (node.property instanceof AST_String && has_annotation(node, _MANGLEPROP)) { annotated_props.add(node.property.value); } } }); return annotated_props; } function mangle_properties(ast, options, annotated_props = find_annotated_props(ast)) { options = defaults(options, { builtins: false, cache: null, debug: false, keep_quoted: false, nth_identifier: base54, only_cache: false, regex: null, reserved: null, undeclared: false, only_annotated: false, }, true); var nth_identifier = options.nth_identifier; 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; } else { cache = new Map(); } var only_annotated = options.only_annotated; 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(); // Track each already-mangled name to prevent nth_identifier from generating // the same name. cache.forEach((mangled_name) => unmangleable.add(mangled_name)); var keep_quoted = !!options.keep_quoted; // step 1: find candidates to mangle ast.walk(new TreeWalker(function(node) { if ( node instanceof AST_ClassPrivateProperty || node instanceof AST_PrivateMethod || node instanceof AST_PrivateGetter || node instanceof AST_PrivateSetter || node instanceof AST_DotHash ) { // handled by mangle_private_properties } else if (node instanceof AST_ObjectKeyVal) { if (typeof node.key == "string" && (!keep_quoted || !node.quote)) { add(node.key); } } else if (node instanceof AST_ObjectProperty) { // setter or getter, since KeyVal is handled above if (!keep_quoted || !node.quote) { add(node.key.name); } } else if (node instanceof AST_Dot) { var declared = !!options.undeclared; if (!declared) { var root = node; while (root.expression) { root = root.expression; } declared = !(root.thedef && root.thedef.undeclared); } if (declared && (!keep_quoted || !node.quote)) { add(node.property); } } else if (node instanceof AST_Sub) { if (!keep_quoted) { addStrings(node.property, add); } } else if (node instanceof AST_Call && node.expression.print_to_string() == "Object.defineProperty") { addStrings(node.args[1], add); } else if (node instanceof AST_Binary && node.operator === "in") { addStrings(node.left, add); } else if (node instanceof AST_String && has_annotation(node, _KEY)) { add(node.value); } })); // step 2: transform the tree, renaming properties return ast.transform(new TreeTransformer(function(node) { if ( node instanceof AST_ClassPrivateProperty || node instanceof AST_PrivateMethod || node instanceof AST_PrivateGetter || node instanceof AST_PrivateSetter || node instanceof AST_DotHash ) { // handled by mangle_private_properties } else if (node instanceof AST_ObjectKeyVal) { if (typeof node.key == "string" && (!keep_quoted || !node.quote)) { node.key = mangle(node.key); } } else if (node instanceof AST_ObjectProperty) { // setter, getter, method or class field if (!keep_quoted || !node.quote) { node.key.name = mangle(node.key.name); } } else if (node instanceof AST_Dot) { if (!keep_quoted || !node.quote) { node.property = mangle(node.property); } } else if (!keep_quoted && node instanceof AST_Sub) { node.property = mangleStrings(node.property); } else if (node instanceof AST_Call && node.expression.print_to_string() == "Object.defineProperty") { node.args[1] = mangleStrings(node.args[1]); } else if (node instanceof AST_Binary && node.operator === "in") { node.left = mangleStrings(node.left); } else if (node instanceof AST_String && has_annotation(node, _KEY)) { // Clear _KEY annotation to prevent double mangling clear_annotation(node, _KEY); node.value = mangle(node.value); } })); // 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 (only_annotated && !annotated_props.has(name)) return false; if (regex && !regex.test(name)) { return annotated_props.has(name); } 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 = nth_identifier.get(++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) { // Clear _KEY annotation to prevent double mangling clear_annotation(node, _KEY); 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, mangle_private_properties, find_annotated_props, }; terser-5.19.2/lib/scope.js000066400000000000000000001046311445647217600153560ustar00rootroot00000000000000/*********************************************************************** 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, mergeSort, push_uniq, make_node, return_false, return_this, return_true, string_template, } from "./utils/index.js"; import { AST_Arrow, AST_Block, AST_Call, AST_Class, AST_Conditional, AST_DefClass, AST_Defun, AST_Destructuring, AST_Dot, AST_DotHash, AST_Export, AST_For, AST_ForIn, AST_ForOf, AST_Function, AST_Import, AST_IterationStatement, AST_Label, AST_LabeledStatement, AST_LabelRef, AST_Lambda, AST_LoopControl, AST_NameMapping, AST_Node, AST_Scope, AST_Sequence, AST_String, AST_Sub, AST_Switch, AST_SwitchBranch, AST_Symbol, AST_SymbolBlockDeclaration, AST_SymbolCatch, AST_SymbolClass, AST_SymbolConst, AST_SymbolDefClass, AST_SymbolDefun, AST_SymbolExport, AST_SymbolFunarg, AST_SymbolImport, AST_SymbolLambda, AST_SymbolLet, AST_SymbolMethod, AST_SymbolRef, AST_SymbolVar, AST_Toplevel, AST_VarDef, AST_With, TreeWalker, walk, walk_abort } from "./ast.js"; import { ALL_RESERVED_WORDS, js_error, } from "./parse.js"; const MASK_EXPORT_DONT_MANGLE = 1 << 0; const MASK_EXPORT_WANT_MANGLE = 1 << 1; let function_defs = null; let unmangleable_names = null; /** * When defined, there is a function declaration somewhere that's inside of a block. * See https://tc39.es/ecma262/multipage/additional-ecmascript-features-for-web-browsers.html#sec-block-level-function-declarations-web-legacy-compatibility-semantics */ let scopes_with_block_defuns = null; class SymbolDef { constructor(scope, orig, init) { this.name = orig.name; this.orig = [ orig ]; this.init = init; this.eliminated = 0; this.assignments = 0; this.scope = scope; this.replaced = 0; this.global = false; this.export = 0; this.mangled_name = null; this.undeclared = false; this.id = SymbolDef.next_id++; this.chained = false; this.direct_access = false; this.escaped = 0; this.recursive_refs = 0; this.references = []; this.should_replace = undefined; this.single_use = false; this.fixed = false; Object.seal(this); } fixed_value() { if (!this.fixed || this.fixed instanceof AST_Node) return this.fixed; return this.fixed(); } unmangleable(options) { if (!options) options = {}; if ( function_defs && function_defs.has(this.id) && keep_name(options.keep_fnames, this.orig[0].name) ) return true; return this.global && !options.toplevel || (this.export & MASK_EXPORT_DONT_MANGLE) || this.undeclared || !options.eval && this.scope.pinned() || (this.orig[0] instanceof AST_SymbolLambda || this.orig[0] instanceof AST_SymbolDefun) && keep_name(options.keep_fnames, this.orig[0].name) || this.orig[0] instanceof AST_SymbolMethod || (this.orig[0] instanceof AST_SymbolClass || this.orig[0] instanceof AST_SymbolDefClass) && keep_name(options.keep_classnames, this.orig[0].name); } mangle(options) { const cache = options.cache && options.cache.props; if (this.global && cache && cache.has(this.name)) { this.mangled_name = cache.get(this.name); } else if (!this.mangled_name && !this.unmangleable(options)) { var s = this.scope; var sym = this.orig[0]; if (options.ie8 && sym instanceof AST_SymbolLambda) s = s.parent_scope; const redefinition = redefined_catch_def(this); this.mangled_name = redefinition ? redefinition.mangled_name || redefinition.name : s.next_mangled(options, this); if (this.global && cache) { cache.set(this.name, this.mangled_name); } } } } SymbolDef.next_id = 1; function redefined_catch_def(def) { if (def.orig[0] instanceof AST_SymbolCatch && def.scope.is_block_scope() ) { return def.scope.get_defun_scope().variables.get(def.name); } } AST_Scope.DEFMETHOD("figure_out_scope", function(options, { parent_scope = null, toplevel = this } = {}) { options = defaults(options, { cache: null, ie8: false, safari10: false, }); if (!(toplevel instanceof AST_Toplevel)) { throw new Error("Invalid toplevel scope"); } // pass 1: setup scope chaining and handle definitions var scope = this.parent_scope = parent_scope; var labels = new Map(); var defun = null; var in_destructuring = null; var for_scopes = []; var tw = new TreeWalker((node, descend) => { if (node.is_block_scope()) { const save_scope = scope; node.block_scope = scope = new AST_Scope(node); scope._block_scope = true; scope.init_scope_vars(save_scope); scope.uses_with = save_scope.uses_with; scope.uses_eval = save_scope.uses_eval; if (options.safari10) { if (node instanceof AST_For || node instanceof AST_ForIn || node instanceof AST_ForOf) { for_scopes.push(scope); } } if (node instanceof AST_Switch) { // XXX: HACK! Ensure the switch expression gets the correct scope (the parent scope) and the body gets the contained scope // AST_Switch has a scope within the body, but it itself "is a block scope" // This means the switched expression has to belong to the outer scope // while the body inside belongs to the switch itself. // This is pretty nasty and warrants an AST change const the_block_scope = scope; scope = save_scope; node.expression.walk(tw); scope = the_block_scope; for (let i = 0; i < node.body.length; i++) { node.body[i].walk(tw); } } else { descend(); } scope = save_scope; return true; } if (node instanceof AST_Destructuring) { const save_destructuring = in_destructuring; in_destructuring = node; descend(); in_destructuring = save_destructuring; return true; } if (node instanceof AST_Scope) { node.init_scope_vars(scope); var save_scope = scope; var save_defun = defun; var save_labels = labels; defun = scope = node; labels = new Map(); descend(); scope = save_scope; defun = save_defun; labels = save_labels; return true; // don't descend again in TreeWalker } if (node instanceof AST_LabeledStatement) { var l = node.label; if (labels.has(l.name)) { throw new Error(string_template("Label {name} defined twice", l)); } labels.set(l.name, l); descend(); labels.delete(l.name); return true; // no descend again } if (node instanceof AST_With) { for (var s = scope; s; s = s.parent_scope) s.uses_with = true; return; } if (node instanceof AST_Symbol) { node.scope = scope; } if (node instanceof AST_Label) { node.thedef = node; node.references = []; } if (node instanceof AST_SymbolLambda) { defun.def_function(node, node.name == "arguments" ? undefined : defun); } else if (node instanceof AST_SymbolDefun) { // Careful here, the scope where this should be defined is // the parent scope. The reason is that we enter a new // scope when we encounter the AST_Defun node (which is // instanceof AST_Scope) but we get to the symbol a bit // later. const closest_scope = defun.parent_scope; // In strict mode, function definitions are block-scoped node.scope = tw.directives["use strict"] ? closest_scope : closest_scope.get_defun_scope(); mark_export(node.scope.def_function(node, defun), 1); } else if (node instanceof AST_SymbolClass) { mark_export(defun.def_variable(node, defun), 1); } else if (node instanceof AST_SymbolImport) { scope.def_variable(node); } else if (node instanceof AST_SymbolDefClass) { // This deals with the name of the class being available // inside the class. mark_export((node.scope = defun.parent_scope).def_function(node, defun), 1); } else if ( node instanceof AST_SymbolVar || node instanceof AST_SymbolLet || node instanceof AST_SymbolConst || node instanceof AST_SymbolCatch ) { var def; if (node instanceof AST_SymbolBlockDeclaration) { def = scope.def_variable(node, null); } else { def = defun.def_variable(node, node.TYPE == "SymbolVar" ? null : undefined); } if (!def.orig.every((sym) => { if (sym === node) return true; if (node instanceof AST_SymbolBlockDeclaration) { return sym instanceof AST_SymbolLambda; } return !(sym instanceof AST_SymbolLet || sym instanceof AST_SymbolConst); })) { js_error( `"${node.name}" is redeclared`, node.start.file, node.start.line, node.start.col, node.start.pos ); } if (!(node instanceof AST_SymbolFunarg)) mark_export(def, 2); if (defun !== scope) { node.mark_enclosed(); var def = scope.find_variable(node); if (node.thedef !== def) { node.thedef = def; node.reference(); } } } else if (node instanceof AST_LabelRef) { var sym = labels.get(node.name); if (!sym) throw new Error(string_template("Undefined label {name} [{line},{col}]", { name: node.name, line: node.start.line, col: node.start.col })); node.thedef = sym; } if (!(scope instanceof AST_Toplevel) && (node instanceof AST_Export || node instanceof AST_Import)) { js_error( `"${node.TYPE}" statement may only appear at the top level`, node.start.file, node.start.line, node.start.col, node.start.pos ); } }); this.walk(tw); function mark_export(def, level) { if (in_destructuring) { var i = 0; do { level++; } while (tw.parent(i++) !== in_destructuring); } var node = tw.parent(level); if (def.export = node instanceof AST_Export ? MASK_EXPORT_DONT_MANGLE : 0) { var exported = node.exported_definition; if ((exported instanceof AST_Defun || exported instanceof AST_DefClass) && node.is_default) { def.export = MASK_EXPORT_WANT_MANGLE; } } } // pass 2: find back references and eval const is_toplevel = this instanceof AST_Toplevel; if (is_toplevel) { this.globals = new Map(); } var tw = new TreeWalker(node => { if (node instanceof AST_LoopControl && node.label) { node.label.thedef.references.push(node); return true; } if (node instanceof AST_SymbolRef) { var name = node.name; if (name == "eval" && tw.parent() instanceof AST_Call) { for (var s = node.scope; s && !s.uses_eval; s = s.parent_scope) { s.uses_eval = true; } } var sym; if (tw.parent() instanceof AST_NameMapping && tw.parent(1).module_name || !(sym = node.scope.find_variable(name))) { sym = toplevel.def_global(node); if (node instanceof AST_SymbolExport) sym.export = MASK_EXPORT_DONT_MANGLE; } else if (sym.scope instanceof AST_Lambda && name == "arguments") { sym.scope.get_defun_scope().uses_arguments = true; } node.thedef = sym; node.reference(); if (node.scope.is_block_scope() && !(sym.orig[0] instanceof AST_SymbolBlockDeclaration)) { node.scope = node.scope.get_defun_scope(); } return true; } // ensure mangling works if catch reuses a scope variable var def; if (node instanceof AST_SymbolCatch && (def = redefined_catch_def(node.definition()))) { var s = node.scope; while (s) { push_uniq(s.enclosed, def); if (s === def.scope) break; s = s.parent_scope; } } }); this.walk(tw); // pass 3: work around IE8 and Safari catch scope bugs if (options.ie8 || options.safari10) { walk(this, node => { if (node instanceof AST_SymbolCatch) { var name = node.name; var refs = node.thedef.references; var scope = node.scope.get_defun_scope(); var def = scope.find_variable(name) || toplevel.globals.get(name) || scope.def_variable(node); refs.forEach(function(ref) { ref.thedef = def; ref.reference(); }); node.thedef = def; node.reference(); return true; } }); } // pass 4: add symbol definitions to loop scopes // Safari/Webkit bug workaround - loop init let variable shadowing argument. // https://github.com/mishoo/UglifyJS2/issues/1753 // https://bugs.webkit.org/show_bug.cgi?id=171041 if (options.safari10) { for (const scope of for_scopes) { scope.parent_scope.variables.forEach(function(def) { push_uniq(scope.enclosed, def); }); } } }); AST_Toplevel.DEFMETHOD("def_global", function(node) { var globals = this.globals, name = node.name; if (globals.has(name)) { return globals.get(name); } else { var g = new SymbolDef(this, node); g.undeclared = true; g.global = true; globals.set(name, g); return g; } }); AST_Scope.DEFMETHOD("init_scope_vars", function(parent_scope) { this.variables = new Map(); // map name to AST_SymbolVar (variables defined in this scope; includes functions) this.uses_with = false; // will be set to true if this or some nested scope uses the `with` statement this.uses_eval = false; // will be set to true if this or nested scope uses the global `eval` this.parent_scope = parent_scope; // the parent scope this.enclosed = []; // a list of variables from this or outer scope(s) that are referenced from this or inner scopes this.cname = -1; // the current index for mangling functions/variables }); AST_Scope.DEFMETHOD("conflicting_def", function (name) { return ( this.enclosed.find(def => def.name === name) || this.variables.has(name) || (this.parent_scope && this.parent_scope.conflicting_def(name)) ); }); AST_Scope.DEFMETHOD("conflicting_def_shallow", function (name) { return ( this.enclosed.find(def => def.name === name) || this.variables.has(name) ); }); AST_Scope.DEFMETHOD("add_child_scope", function (scope) { // `scope` is going to be moved into `this` right now. // Update the required scopes' information if (scope.parent_scope === this) return; scope.parent_scope = this; // Propagate to this.uses_arguments from arrow functions if ((scope instanceof AST_Arrow) && !this.uses_arguments) { this.uses_arguments = walk(scope, node => { if ( node instanceof AST_SymbolRef && node.scope instanceof AST_Lambda && node.name === "arguments" ) { return walk_abort; } if (node instanceof AST_Lambda && !(node instanceof AST_Arrow)) { return true; } }); } this.uses_with = this.uses_with || scope.uses_with; this.uses_eval = this.uses_eval || scope.uses_eval; const scope_ancestry = (() => { const ancestry = []; let cur = this; do { ancestry.push(cur); } while ((cur = cur.parent_scope)); ancestry.reverse(); return ancestry; })(); const new_scope_enclosed_set = new Set(scope.enclosed); const to_enclose = []; for (const scope_topdown of scope_ancestry) { to_enclose.forEach(e => push_uniq(scope_topdown.enclosed, e)); for (const def of scope_topdown.variables.values()) { if (new_scope_enclosed_set.has(def)) { push_uniq(to_enclose, def); push_uniq(scope_topdown.enclosed, def); } } } }); function find_scopes_visible_from(scopes) { const found_scopes = new Set(); for (const scope of new Set(scopes)) { (function bubble_up(scope) { if (scope == null || found_scopes.has(scope)) return; found_scopes.add(scope); bubble_up(scope.parent_scope); })(scope); } return [...found_scopes]; } // Creates a symbol during compression AST_Scope.DEFMETHOD("create_symbol", function(SymClass, { source, tentative_name, scope, conflict_scopes = [scope], init = null } = {}) { let symbol_name; conflict_scopes = find_scopes_visible_from(conflict_scopes); if (tentative_name) { // Implement hygiene (no new names are conflicting with existing names) tentative_name = symbol_name = tentative_name.replace(/(?:^[^a-z_$]|[^a-z0-9_$])/ig, "_"); let i = 0; while (conflict_scopes.find(s => s.conflicting_def_shallow(symbol_name))) { symbol_name = tentative_name + "$" + i++; } } if (!symbol_name) { throw new Error("No symbol name could be generated in create_symbol()"); } const symbol = make_node(SymClass, source, { name: symbol_name, scope }); this.def_variable(symbol, init || null); symbol.mark_enclosed(); return symbol; }); AST_Node.DEFMETHOD("is_block_scope", return_false); AST_Class.DEFMETHOD("is_block_scope", return_false); AST_Lambda.DEFMETHOD("is_block_scope", return_false); AST_Toplevel.DEFMETHOD("is_block_scope", return_false); AST_SwitchBranch.DEFMETHOD("is_block_scope", return_false); AST_Block.DEFMETHOD("is_block_scope", return_true); AST_Scope.DEFMETHOD("is_block_scope", function () { return this._block_scope || false; }); AST_IterationStatement.DEFMETHOD("is_block_scope", return_true); AST_Lambda.DEFMETHOD("init_scope_vars", function() { AST_Scope.prototype.init_scope_vars.apply(this, arguments); this.uses_arguments = false; this.def_variable(new AST_SymbolFunarg({ name: "arguments", start: this.start, end: this.end })); }); AST_Arrow.DEFMETHOD("init_scope_vars", function() { AST_Scope.prototype.init_scope_vars.apply(this, arguments); this.uses_arguments = false; }); AST_Symbol.DEFMETHOD("mark_enclosed", function() { var def = this.definition(); var s = this.scope; while (s) { push_uniq(s.enclosed, def); if (s === def.scope) break; s = s.parent_scope; } }); AST_Symbol.DEFMETHOD("reference", function() { this.definition().references.push(this); this.mark_enclosed(); }); AST_Scope.DEFMETHOD("find_variable", function(name) { if (name instanceof AST_Symbol) name = name.name; return this.variables.get(name) || (this.parent_scope && this.parent_scope.find_variable(name)); }); AST_Scope.DEFMETHOD("def_function", function(symbol, init) { var def = this.def_variable(symbol, init); if (!def.init || def.init instanceof AST_Defun) def.init = init; 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) { let defun_scope; if ( scopes_with_block_defuns && (defun_scope = scope.get_defun_scope()) && scopes_with_block_defuns.has(defun_scope) ) { scope = defun_scope; } var ext = scope.enclosed; var nth_identifier = options.nth_identifier; out: while (true) { var m = nth_identifier.get(++scope.cname); if (ALL_RESERVED_WORDS.has(m)) continue; // skip over "do" // https://github.com/mishoo/UglifyJS2/issues/242 -- do not // shadow a name reserved from mangling. if (options.reserved.has(m)) continue; // Functions with short names might collide with base54 output // and therefore cause collisions when keep_fnames is true. if (unmangleable_names && unmangleable_names.has(m)) continue out; // we must ensure that the mangled name does not shadow a name // from some parent scope that is referenced in this or in // inner scopes. for (let i = ext.length; --i >= 0;) { const def = ext[i]; const name = def.mangled_name || (def.unmangleable(options) && def.name); if (m == name) continue out; } return m; } } AST_Scope.DEFMETHOD("next_mangled", function(options) { return next_mangled(this, options); }); AST_Toplevel.DEFMETHOD("next_mangled", function(options) { let name; const mangled_names = this.mangled_names; do { name = next_mangled(this, options); } while (mangled_names.has(name)); return name; }); AST_Function.DEFMETHOD("next_mangled", function(options, def) { // #179, #326 // in Safari strict mode, something like (function x(x){...}) is a syntax error; // a function expression's argument cannot shadow the function expression's name var tricky_def = def.orig[0] instanceof AST_SymbolFunarg && this.name && this.name.definition(); // the function's mangled_name is null when keep_fnames is true var tricky_name = tricky_def ? tricky_def.mangled_name || tricky_def.name : null; while (true) { var name = next_mangled(this, options); if (!tricky_name || tricky_name != name) return name; } }); AST_Symbol.DEFMETHOD("unmangleable", function(options) { var def = this.definition(); return !def || def.unmangleable(options); }); // labels are always mangleable AST_Label.DEFMETHOD("unmangleable", return_false); AST_Symbol.DEFMETHOD("unreferenced", function() { return !this.definition().references.length && !this.scope.pinned(); }); AST_Symbol.DEFMETHOD("definition", function() { return this.thedef; }); AST_Symbol.DEFMETHOD("global", function() { return this.thedef.global; }); /** * Format the mangler options (if any) into their appropriate types */ export function format_mangler_options(options) { options = defaults(options, { eval : false, nth_identifier : base54, ie8 : false, keep_classnames: false, keep_fnames : false, module : false, reserved : [], toplevel : false, }); if (options.module) options.toplevel = true; if (!Array.isArray(options.reserved) && !(options.reserved instanceof Set) ) { options.reserved = []; } options.reserved = new Set(options.reserved); // Never mangle arguments options.reserved.add("arguments"); return options; } AST_Toplevel.DEFMETHOD("mangle_names", function(options) { options = format_mangler_options(options); var nth_identifier = options.nth_identifier; // We only need to mangle declaration nodes. Special logic wired // into the code generator will display the mangled name if it's // present (and for AST_SymbolRef-s it'll use the mangled name of // the AST_SymbolDeclaration that it points to). var lname = -1; var to_mangle = []; if (options.keep_fnames) { function_defs = new Set(); } const mangled_names = this.mangled_names = new Set(); unmangleable_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_Defun && !(tw.parent() instanceof AST_Scope) ) { scopes_with_block_defuns = scopes_with_block_defuns || new Set(); scopes_with_block_defuns.add(node.parent_scope.get_defun_scope()); } if (node instanceof AST_Scope) { node.variables.forEach(collect); return; } if (node.is_block_scope()) { node.block_scope.variables.forEach(collect); return; } if ( function_defs && node instanceof AST_VarDef && node.value instanceof AST_Lambda && !node.value.name && keep_name(options.keep_fnames, node.name.name) ) { function_defs.add(node.name.definition().id); return; } if (node instanceof AST_Label) { let name; do { name = nth_identifier.get(++lname); } while (ALL_RESERVED_WORDS.has(name)); node.mangled_name = name; return true; } if (!(options.ie8 || options.safari10) && node instanceof AST_SymbolCatch) { to_mangle.push(node.definition()); return; } }); this.walk(tw); if (options.keep_fnames || options.keep_classnames) { // Collect a set of short names which are unmangleable, // for use in avoiding collisions in next_mangled. to_mangle.forEach(def => { if (def.name.length < 6 && def.unmangleable(options)) { unmangleable_names.add(def.name); } }); } to_mangle.forEach(def => { def.mangle(options); }); function_defs = null; unmangleable_names = null; scopes_with_block_defuns = null; function collect(symbol) { if (symbol.export & MASK_EXPORT_DONT_MANGLE) { unmangleable_names.add(symbol.name); } else if (!options.reserved.has(symbol.name)) { to_mangle.push(symbol); } } }); AST_Toplevel.DEFMETHOD("find_colliding_names", function(options) { const cache = options.cache && options.cache.props; const avoid = new Set(); options.reserved.forEach(to_avoid); this.globals.forEach(add_def); this.walk(new TreeWalker(function(node) { if (node instanceof AST_Scope) node.variables.forEach(add_def); if (node instanceof AST_SymbolCatch) add_def(node.definition()); })); return avoid; function to_avoid(name) { avoid.add(name); } function add_def(def) { var name = def.name; if (def.global && cache && cache.has(name)) name = cache.get(name); else if (!def.unmangleable(options)) return; to_avoid(name); } }); AST_Toplevel.DEFMETHOD("expand_names", function(options) { options = format_mangler_options(options); var nth_identifier = options.nth_identifier; if (nth_identifier.reset && nth_identifier.sort) { nth_identifier.reset(); nth_identifier.sort(); } 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 = nth_identifier.get(cname++); } while (avoid.has(name) || ALL_RESERVED_WORDS.has(name)); return name; } function rename(def) { if (def.global && options.cache) return; if (def.unmangleable(options)) return; if (options.reserved.has(def.name)) return; const redefinition = redefined_catch_def(def); const name = def.name = redefinition ? redefinition.name : next_name(); def.orig.forEach(function(sym) { sym.name = name; }); def.references.forEach(function(sym) { sym.name = name; }); } }); AST_Node.DEFMETHOD("tail_node", return_this); AST_Sequence.DEFMETHOD("tail_node", function() { return this.expressions[this.expressions.length - 1]; }); AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options) { options = format_mangler_options(options); var nth_identifier = options.nth_identifier; if (!nth_identifier.reset || !nth_identifier.consider || !nth_identifier.sort) { // If the identifier mangler is invariant, skip computing character frequency. return; } nth_identifier.reset(); try { AST_Node.prototype.print = function(stream, force_parens) { this._print(stream, force_parens); if (this instanceof AST_Symbol && !this.unmangleable(options)) { nth_identifier.consider(this.name, -1); } else if (options.properties) { if (this instanceof AST_DotHash) { nth_identifier.consider("#" + this.property, -1); } else if (this instanceof AST_Dot) { nth_identifier.consider(this.property, -1); } else if (this instanceof AST_Sub) { skip_string(this.property); } } }; nth_identifier.consider(this.print_to_string(), 1); } finally { AST_Node.prototype.print = AST_Node.prototype._print; } nth_identifier.sort(); function skip_string(node) { if (node instanceof AST_String) { nth_identifier.consider(node.value, -1); } else if (node instanceof AST_Conditional) { skip_string(node.consequent); skip_string(node.alternative); } else if (node instanceof AST_Sequence) { skip_string(node.tail_node()); } } }); const base54 = (() => { const leading = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_".split(""); const digits = "0123456789".split(""); let chars; let frequency; function reset() { frequency = new Map(); leading.forEach(function(ch) { frequency.set(ch, 0); }); digits.forEach(function(ch) { frequency.set(ch, 0); }); } function consider(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); } function sort() { chars = mergeSort(leading, compare).concat(mergeSort(digits, compare)); } // Ensure this is in a usable initial state. reset(); sort(); 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 { get: base54, consider, reset, sort }; })(); export { base54, SymbolDef, }; terser-5.19.2/lib/size.js000066400000000000000000000262111445647217600152140ustar00rootroot00000000000000import { AST_Accessor, AST_Array, AST_Arrow, AST_Await, AST_BigInt, AST_Binary, AST_Block, AST_Break, AST_Call, AST_Case, AST_Class, AST_ClassStaticBlock, AST_ClassPrivateProperty, AST_ClassProperty, AST_ConciseMethod, AST_Conditional, AST_Const, AST_Continue, AST_Debugger, AST_Default, AST_Defun, AST_Destructuring, AST_Directive, AST_Do, AST_Dot, AST_DotHash, AST_EmptyStatement, AST_Expansion, AST_Export, AST_False, AST_For, AST_ForIn, AST_Function, AST_Hole, AST_If, AST_Import, AST_ImportMeta, AST_Infinity, AST_LabeledStatement, AST_Let, AST_NameMapping, AST_NaN, AST_New, AST_NewTarget, AST_Node, AST_Null, AST_Number, AST_Object, AST_ObjectKeyVal, AST_ObjectGetter, AST_ObjectSetter, AST_PrivateGetter, AST_PrivateMethod, AST_PrivateSetter, AST_PrivateIn, AST_RegExp, AST_Return, AST_Sequence, AST_String, AST_Sub, AST_Super, AST_Switch, AST_Symbol, AST_SymbolClassProperty, AST_SymbolExportForeign, AST_SymbolImportForeign, AST_SymbolRef, AST_SymbolDeclaration, AST_TemplateSegment, AST_TemplateString, AST_This, AST_Throw, AST_Toplevel, AST_True, AST_Try, AST_Catch, AST_Finally, AST_Unary, AST_Undefined, AST_Var, AST_VarDef, AST_While, AST_With, AST_Yield, walk_parent } from "./ast.js"; import { first_in_statement } from "./utils/first_in_statement.js"; let mangle_options = undefined; AST_Node.prototype.size = function (compressor, stack) { mangle_options = compressor && compressor.mangle_options; let size = 0; walk_parent(this, (node, info) => { size += node._size(info); // Braceless arrow functions have fake "return" statements if (node instanceof AST_Arrow && node.is_braceless()) { size += node.body[0].value._size(info); return true; } }, stack || (compressor && compressor.stack)); // just to save a bit of memory mangle_options = undefined; return size; }; AST_Node.prototype._size = () => 0; AST_Debugger.prototype._size = () => 8; AST_Directive.prototype._size = function () { // TODO string encoding stuff return 2 + this.value.length; }; /** Count commas/semicolons necessary to show a list of expressions/statements */ const list_overhead = (array) => array.length && array.length - 1; AST_Block.prototype._size = function () { return 2 + list_overhead(this.body); }; AST_Toplevel.prototype._size = function() { return list_overhead(this.body); }; AST_EmptyStatement.prototype._size = () => 1; AST_LabeledStatement.prototype._size = () => 2; // x: AST_Do.prototype._size = () => 9; AST_While.prototype._size = () => 7; AST_For.prototype._size = () => 8; AST_ForIn.prototype._size = () => 8; // AST_ForOf inherits ^ AST_With.prototype._size = () => 6; AST_Expansion.prototype._size = () => 3; const lambda_modifiers = func => (func.is_generator ? 1 : 0) + (func.async ? 6 : 0); AST_Accessor.prototype._size = function () { return lambda_modifiers(this) + 4 + list_overhead(this.argnames) + list_overhead(this.body); }; AST_Function.prototype._size = function (info) { const first = !!first_in_statement(info); return (first * 2) + lambda_modifiers(this) + 12 + list_overhead(this.argnames) + list_overhead(this.body); }; AST_Defun.prototype._size = function () { return lambda_modifiers(this) + 13 + list_overhead(this.argnames) + list_overhead(this.body); }; AST_Arrow.prototype._size = function () { let args_and_arrow = 2 + list_overhead(this.argnames); if ( !( this.argnames.length === 1 && this.argnames[0] instanceof AST_Symbol ) ) { args_and_arrow += 2; // parens around the args } const body_overhead = this.is_braceless() ? 0 : list_overhead(this.body) + 2; return lambda_modifiers(this) + args_and_arrow + body_overhead; }; AST_Destructuring.prototype._size = () => 2; AST_TemplateString.prototype._size = function () { return 2 + (Math.floor(this.segments.length / 2) * 3); /* "${}" */ }; AST_TemplateSegment.prototype._size = function () { return this.value.length; }; AST_Return.prototype._size = function () { return this.value ? 7 : 6; }; AST_Throw.prototype._size = () => 6; AST_Break.prototype._size = function () { return this.label ? 6 : 5; }; AST_Continue.prototype._size = function () { return this.label ? 9 : 8; }; AST_If.prototype._size = () => 4; AST_Switch.prototype._size = function () { return 8 + list_overhead(this.body); }; AST_Case.prototype._size = function () { return 5 + list_overhead(this.body); }; AST_Default.prototype._size = function () { return 8 + list_overhead(this.body); }; AST_Try.prototype._size = () => 3; AST_Catch.prototype._size = function () { let size = 7 + list_overhead(this.body); if (this.argname) { size += 2; } return size; }; AST_Finally.prototype._size = function () { return 7 + list_overhead(this.body); }; AST_Var.prototype._size = function () { return 4 + list_overhead(this.definitions); }; AST_Let.prototype._size = function () { return 4 + list_overhead(this.definitions); }; AST_Const.prototype._size = function () { return 6 + list_overhead(this.definitions); }; AST_VarDef.prototype._size = function () { return this.value ? 1 : 0; }; AST_NameMapping.prototype._size = function () { // foreign name isn't mangled return this.name ? 4 : 0; }; AST_Import.prototype._size = function () { // import let size = 6; if (this.imported_name) size += 1; // from if (this.imported_name || this.imported_names) size += 5; // braces, and the commas if (this.imported_names) { size += 2 + list_overhead(this.imported_names); } return size; }; AST_ImportMeta.prototype._size = () => 11; AST_Export.prototype._size = function () { let size = 7 + (this.is_default ? 8 : 0); if (this.exported_value) { size += this.exported_value._size(); } if (this.exported_names) { // Braces and commas size += 2 + list_overhead(this.exported_names); } if (this.module_name) { // "from " size += 5; } return size; }; AST_Call.prototype._size = function () { if (this.optional) { return 4 + list_overhead(this.args); } return 2 + list_overhead(this.args); }; AST_New.prototype._size = function () { return 6 + list_overhead(this.args); }; AST_Sequence.prototype._size = function () { return list_overhead(this.expressions); }; AST_Dot.prototype._size = function () { if (this.optional) { return this.property.length + 2; } return this.property.length + 1; }; AST_DotHash.prototype._size = function () { if (this.optional) { return this.property.length + 3; } return this.property.length + 2; }; AST_Sub.prototype._size = function () { return this.optional ? 4 : 2; }; AST_Unary.prototype._size = function () { if (this.operator === "typeof") return 7; if (this.operator === "void") return 5; return this.operator.length; }; AST_Binary.prototype._size = function (info) { if (this.operator === "in") return 4; let size = this.operator.length; if ( (this.operator === "+" || this.operator === "-") && this.right instanceof AST_Unary && this.right.operator === this.operator ) { // 1+ +a > needs space between the + size += 1; } if (this.needs_parens(info)) { size += 2; } return size; }; AST_Conditional.prototype._size = () => 3; AST_Array.prototype._size = function () { return 2 + list_overhead(this.elements); }; AST_Object.prototype._size = function (info) { let base = 2; if (first_in_statement(info)) { base += 2; // parens } return base + list_overhead(this.properties); }; /*#__INLINE__*/ const key_size = key => typeof key === "string" ? key.length : 0; AST_ObjectKeyVal.prototype._size = function () { return key_size(this.key) + 1; }; /*#__INLINE__*/ const static_size = is_static => is_static ? 7 : 0; AST_ObjectGetter.prototype._size = function () { return 5 + static_size(this.static) + key_size(this.key); }; AST_ObjectSetter.prototype._size = function () { return 5 + static_size(this.static) + key_size(this.key); }; AST_ConciseMethod.prototype._size = function () { return static_size(this.static) + key_size(this.key) + lambda_modifiers(this); }; AST_PrivateMethod.prototype._size = function () { return AST_ConciseMethod.prototype._size.call(this) + 1; }; AST_PrivateGetter.prototype._size = AST_PrivateSetter.prototype._size = function () { return AST_ConciseMethod.prototype._size.call(this) + 4; }; AST_PrivateIn.prototype._size = function () { return 5; // "#", and " in " }; AST_Class.prototype._size = function () { return ( (this.name ? 8 : 7) + (this.extends ? 8 : 0) ); }; AST_ClassStaticBlock.prototype._size = function () { // "class{}" + semicolons return 7 + list_overhead(this.body); }; AST_ClassProperty.prototype._size = function () { return ( static_size(this.static) + (typeof this.key === "string" ? this.key.length + 2 : 0) + (this.value ? 1 : 0) ); }; AST_ClassPrivateProperty.prototype._size = function () { return AST_ClassProperty.prototype._size.call(this) + 1; }; AST_Symbol.prototype._size = function () { if (!(mangle_options && this.thedef && !this.thedef.unmangleable(mangle_options))) { return this.name.length; } else { return 1; } }; // TODO take propmangle into account AST_SymbolClassProperty.prototype._size = function () { return this.name.length; }; AST_SymbolRef.prototype._size = AST_SymbolDeclaration.prototype._size = function () { if (this.name === "arguments") return 9; return AST_Symbol.prototype._size.call(this); }; AST_NewTarget.prototype._size = () => 10; AST_SymbolImportForeign.prototype._size = function () { return this.name.length; }; AST_SymbolExportForeign.prototype._size = function () { return this.name.length; }; AST_This.prototype._size = () => 4; AST_Super.prototype._size = () => 5; AST_String.prototype._size = function () { return this.value.length + 2; }; AST_Number.prototype._size = function () { const { value } = this; if (value === 0) return 1; if (value > 0 && Math.floor(value) === value) { return Math.floor(Math.log10(value) + 1); } return value.toString().length; }; AST_BigInt.prototype._size = function () { return this.value.length; }; AST_RegExp.prototype._size = function () { return this.value.toString().length; }; AST_Null.prototype._size = () => 4; AST_NaN.prototype._size = () => 3; AST_Undefined.prototype._size = () => 6; // "void 0" AST_Hole.prototype._size = () => 0; // comma is taken into account by list_overhead() AST_Infinity.prototype._size = () => 8; AST_True.prototype._size = () => 4; AST_False.prototype._size = () => 5; AST_Await.prototype._size = () => 6; AST_Yield.prototype._size = () => 6; terser-5.19.2/lib/sourcemap.js000066400000000000000000000115551445647217600162450ustar00rootroot00000000000000/*********************************************************************** 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 {SourceMapConsumer, SourceMapGenerator} from "@jridgewell/source-map"; import {defaults, HOP} from "./utils/index.js"; // a small wrapper around source-map and @jridgewell/source-map async function SourceMap(options) { options = defaults(options, { file : null, root : null, orig : null, files: {}, }); var orig_map; var generator = new SourceMapGenerator({ file : options.file, sourceRoot : options.root }); let sourcesContent = {__proto__: null}; let files = options.files; for (var name in files) if (HOP(files, name)) { sourcesContent[name] = files[name]; } if (options.orig) { // We support both @jridgewell/source-map (which has a sync // SourceMapConsumer) and source-map (which has an async // SourceMapConsumer). orig_map = await new SourceMapConsumer(options.orig); if (orig_map.sourcesContent) { orig_map.sources.forEach(function(source, i) { var content = orig_map.sourcesContent[i]; if (content) { sourcesContent[source] = content; } }); } } function add(source, gen_line, gen_col, orig_line, orig_col, name) { let generatedPos = { line: gen_line, column: gen_col }; if (orig_map) { var info = orig_map.originalPositionFor({ line: orig_line, column: orig_col }); if (info.source === null) { generator.addMapping({ generated: generatedPos, original: null, source: null, name: null }); return; } source = info.source; orig_line = info.line; orig_col = info.column; name = info.name || name; } generator.addMapping({ generated : generatedPos, original : { line: orig_line, column: orig_col }, source : source, name : name }); generator.setSourceContent(source, sourcesContent[source]); } function clean(map) { const allNull = map.sourcesContent && map.sourcesContent.every(c => c == null); if (allNull) delete map.sourcesContent; if (map.file === undefined) delete map.file; if (map.sourceRoot === undefined) delete map.sourceRoot; return map; } function getDecoded() { if (!generator.toDecodedMap) return null; return clean(generator.toDecodedMap()); } function getEncoded() { return clean(generator.toJSON()); } function destroy() { // @jridgewell/source-map's SourceMapConsumer does not need to be // manually freed. if (orig_map && orig_map.destroy) orig_map.destroy(); } return { add, getDecoded, getEncoded, destroy, }; } export { SourceMap, }; terser-5.19.2/lib/transform.js000066400000000000000000000232161445647217600162570ustar00rootroot00000000000000/*********************************************************************** 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_PrivateIn, AST_Block, AST_Call, AST_Case, AST_Catch, AST_Chain, AST_Class, AST_ClassStaticBlock, AST_Conditional, AST_Definitions, AST_Destructuring, AST_Do, AST_Exit, AST_Expansion, AST_Export, AST_For, AST_ForIn, AST_If, AST_Import, AST_LabeledStatement, AST_Lambda, AST_LoopControl, AST_NameMapping, AST_Node, AST_Number, AST_Object, AST_ObjectProperty, AST_PrefixedTemplateString, AST_PropAccess, 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 as do_list, noop, } from "./utils/index.js"; function def_transform(node, descend) { node.DEFMETHOD("transform", function(tw, in_list) { let transformed = undefined; tw.push(this); if (tw.before) transformed = tw.before(this, descend, in_list); if (transformed === undefined) { transformed = this; descend(transformed, tw); if (tw.after) { const after_ret = tw.after(transformed, in_list); if (after_ret !== undefined) transformed = after_ret; } } tw.pop(); return transformed; }); } def_transform(AST_Node, noop); def_transform(AST_LabeledStatement, function(self, tw) { self.label = self.label.transform(tw); self.body = self.body.transform(tw); }); def_transform(AST_SimpleStatement, function(self, tw) { self.body = self.body.transform(tw); }); def_transform(AST_Block, function(self, tw) { self.body = do_list(self.body, tw); }); def_transform(AST_Do, function(self, tw) { self.body = self.body.transform(tw); self.condition = self.condition.transform(tw); }); def_transform(AST_While, function(self, tw) { self.condition = self.condition.transform(tw); self.body = self.body.transform(tw); }); def_transform(AST_For, function(self, tw) { if (self.init) self.init = self.init.transform(tw); if (self.condition) self.condition = self.condition.transform(tw); if (self.step) self.step = self.step.transform(tw); self.body = self.body.transform(tw); }); def_transform(AST_ForIn, function(self, tw) { self.init = self.init.transform(tw); self.object = self.object.transform(tw); self.body = self.body.transform(tw); }); def_transform(AST_With, function(self, tw) { self.expression = self.expression.transform(tw); self.body = self.body.transform(tw); }); def_transform(AST_Exit, function(self, tw) { if (self.value) self.value = self.value.transform(tw); }); def_transform(AST_LoopControl, function(self, tw) { if (self.label) self.label = self.label.transform(tw); }); def_transform(AST_If, function(self, tw) { self.condition = self.condition.transform(tw); self.body = self.body.transform(tw); if (self.alternative) self.alternative = self.alternative.transform(tw); }); def_transform(AST_Switch, function(self, tw) { self.expression = self.expression.transform(tw); self.body = do_list(self.body, tw); }); def_transform(AST_Case, function(self, tw) { self.expression = self.expression.transform(tw); self.body = do_list(self.body, tw); }); def_transform(AST_Try, function(self, tw) { self.body = self.body.transform(tw); if (self.bcatch) self.bcatch = self.bcatch.transform(tw); if (self.bfinally) self.bfinally = self.bfinally.transform(tw); }); def_transform(AST_Catch, function(self, tw) { if (self.argname) self.argname = self.argname.transform(tw); self.body = do_list(self.body, tw); }); def_transform(AST_Definitions, function(self, tw) { self.definitions = do_list(self.definitions, tw); }); def_transform(AST_VarDef, function(self, tw) { self.name = self.name.transform(tw); if (self.value) self.value = self.value.transform(tw); }); def_transform(AST_Destructuring, function(self, tw) { self.names = do_list(self.names, tw); }); def_transform(AST_Lambda, function(self, tw) { if (self.name) self.name = self.name.transform(tw); self.argnames = do_list(self.argnames, tw, /* allow_splicing */ false); if (self.body instanceof AST_Node) { self.body = self.body.transform(tw); } else { self.body = do_list(self.body, tw); } }); def_transform(AST_Call, function(self, tw) { self.expression = self.expression.transform(tw); self.args = do_list(self.args, tw, /* allow_splicing */ false); }); def_transform(AST_Sequence, function(self, tw) { const result = do_list(self.expressions, tw); self.expressions = result.length ? result : [new AST_Number({ value: 0 })]; }); def_transform(AST_PropAccess, function(self, tw) { self.expression = self.expression.transform(tw); }); def_transform(AST_Sub, function(self, tw) { self.expression = self.expression.transform(tw); self.property = self.property.transform(tw); }); def_transform(AST_Chain, function(self, tw) { self.expression = self.expression.transform(tw); }); def_transform(AST_Yield, function(self, tw) { if (self.expression) self.expression = self.expression.transform(tw); }); def_transform(AST_Await, function(self, tw) { self.expression = self.expression.transform(tw); }); def_transform(AST_Unary, function(self, tw) { self.expression = self.expression.transform(tw); }); def_transform(AST_Binary, function(self, tw) { self.left = self.left.transform(tw); self.right = self.right.transform(tw); }); def_transform(AST_PrivateIn, function(self, tw) { self.key = self.key.transform(tw); self.value = self.value.transform(tw); }); def_transform(AST_Conditional, function(self, tw) { self.condition = self.condition.transform(tw); self.consequent = self.consequent.transform(tw); self.alternative = self.alternative.transform(tw); }); def_transform(AST_Array, function(self, tw) { self.elements = do_list(self.elements, tw); }); def_transform(AST_Object, function(self, tw) { self.properties = do_list(self.properties, tw); }); def_transform(AST_ObjectProperty, function(self, tw) { if (self.key instanceof AST_Node) { self.key = self.key.transform(tw); } if (self.value) self.value = self.value.transform(tw); }); def_transform(AST_Class, function(self, tw) { if (self.name) self.name = self.name.transform(tw); if (self.extends) self.extends = self.extends.transform(tw); self.properties = do_list(self.properties, tw); }); def_transform(AST_ClassStaticBlock, function(self, tw) { self.body = do_list(self.body, tw); }); def_transform(AST_Expansion, function(self, tw) { self.expression = self.expression.transform(tw); }); def_transform(AST_NameMapping, function(self, tw) { self.foreign_name = self.foreign_name.transform(tw); self.name = self.name.transform(tw); }); def_transform(AST_Import, function(self, tw) { if (self.imported_name) self.imported_name = self.imported_name.transform(tw); if (self.imported_names) do_list(self.imported_names, tw); self.module_name = self.module_name.transform(tw); }); def_transform(AST_Export, function(self, tw) { if (self.exported_definition) self.exported_definition = self.exported_definition.transform(tw); if (self.exported_value) self.exported_value = self.exported_value.transform(tw); if (self.exported_names) do_list(self.exported_names, tw); if (self.module_name) self.module_name = self.module_name.transform(tw); }); def_transform(AST_TemplateString, function(self, tw) { self.segments = do_list(self.segments, tw); }); def_transform(AST_PrefixedTemplateString, function(self, tw) { self.prefix = self.prefix.transform(tw); self.template_string = self.template_string.transform(tw); }); terser-5.19.2/lib/utils/000077500000000000000000000000001445647217600150425ustar00rootroot00000000000000terser-5.19.2/lib/utils/first_in_statement.js000066400000000000000000000041211445647217600212770ustar00rootroot00000000000000import { AST_Binary, AST_Conditional, AST_Chain, AST_Dot, AST_Object, AST_Sequence, AST_Statement, AST_Sub, AST_UnaryPostfix, AST_PrefixedTemplateString } from "../ast.js"; // return true if the node at the top of the stack (that means the // innermost node in the current output) is lexically the first in // a statement. function first_in_statement(stack) { let node = stack.parent(-1); for (let i = 0, p; p = stack.parent(i); i++) { if (p instanceof AST_Statement && p.body === node) return true; if ((p instanceof AST_Sequence && p.expressions[0] === node) || (p.TYPE === "Call" && p.expression === node) || (p instanceof AST_PrefixedTemplateString && p.prefix === node) || (p instanceof AST_Dot && p.expression === node) || (p instanceof AST_Sub && p.expression === node) || (p instanceof AST_Chain && p.expression === node) || (p instanceof AST_Conditional && p.condition === node) || (p instanceof AST_Binary && p.left === node) || (p instanceof AST_UnaryPostfix && p.expression === node) ) { node = p; } else { return false; } } } // Returns whether the leftmost item in the expression is an object function left_is_object(node) { if (node instanceof AST_Object) return true; if (node instanceof AST_Sequence) return left_is_object(node.expressions[0]); if (node.TYPE === "Call") return left_is_object(node.expression); if (node instanceof AST_PrefixedTemplateString) return left_is_object(node.prefix); if (node instanceof AST_Dot || node instanceof AST_Sub) return left_is_object(node.expression); if (node instanceof AST_Chain) return left_is_object(node.expression); if (node instanceof AST_Conditional) return left_is_object(node.condition); if (node instanceof AST_Binary) return left_is_object(node.left); if (node instanceof AST_UnaryPostfix) return left_is_object(node.expression); return false; } export { first_in_statement, left_is_object }; terser-5.19.2/lib/utils/index.js000066400000000000000000000176221445647217600165170ustar00rootroot00000000000000/*********************************************************************** 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_Node } from "../ast.js"; 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 = {}; } else if (args != null && typeof args === "object") { args = {...args}; } const ret = args || {}; if (croak) for (const i in ret) if (HOP(ret, i) && !HOP(defs, i)) { throw new DefaultsError("`" + i + "` is not a supported option", defs); } for (const i in defs) if (HOP(defs, i)) { if (!args || !HOP(args, i)) { ret[i] = defs[i]; } else if (i === "ecma") { let ecma = args[i] | 0; if (ecma > 5 && ecma < 2015) ecma += 2009; ret[i] = ecma; } else { ret[i] = (args && HOP(args, i)) ? args[i] : defs[i]; } } return ret; } function noop() {} function return_false() { return false; } function return_true() { return true; } function return_this() { return this; } function return_null() { return null; } var MAP = (function() { function MAP(a, tw, allow_splicing = true) { const new_a = []; for (let i = 0; i < a.length; ++i) { let item = a[i]; let ret = item.transform(tw, allow_splicing); if (ret instanceof AST_Node) { new_a.push(ret); } else if (ret instanceof Splice) { new_a.push(...ret.v); } } return new_a; } MAP.splice = function(val) { return new Splice(val); }; MAP.skip = {}; function Splice(val) { this.v = val; } return MAP; })(); function make_node(ctor, orig, props) { if (!props) props = {}; if (orig) { if (!props.start) props.start = orig.start; if (!props.end) props.end = orig.end; } return new ctor(props); } function push_uniq(array, el) { if (!array.includes(el)) array.push(el); } function string_template(text, props) { return text.replace(/{(.+?)}/g, function(str, p) { return props && props[p]; }); } function remove(array, el) { for (var i = array.length; --i >= 0;) { if (array[i] === el) array.splice(i, 1); } } function mergeSort(array, cmp) { if (array.length < 2) return array.slice(); function merge(a, b) { var r = [], ai = 0, bi = 0, i = 0; while (ai < a.length && bi < b.length) { cmp(a[ai], b[bi]) <= 0 ? r[i++] = a[ai++] : r[i++] = b[bi++]; } if (ai < a.length) r.push.apply(r, a.slice(ai)); if (bi < b.length) r.push.apply(r, b.slice(bi)); return r; } function _ms(a) { if (a.length <= 1) return a; var m = Math.floor(a.length / 2), left = a.slice(0, m), right = a.slice(m); left = _ms(left); right = _ms(right); return merge(left, right); } return _ms(array); } function makePredicate(words) { if (!Array.isArray(words)) words = words.split(" "); return new Set(words.sort()); } function map_add(map, key, value) { if (map.has(key)) { map.get(key).push(value); } else { map.set(key, [ value ]); } } function map_from_object(obj) { var map = new Map(); for (var key in obj) { if (HOP(obj, key) && key.charAt(0) === "$") { map.set(key.substr(1), obj[key]); } } return map; } function map_to_object(map) { var obj = Object.create(null); map.forEach(function (value, key) { obj["$" + key] = value; }); return obj; } function HOP(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } function keep_name(keep_setting, name) { return keep_setting === true || (keep_setting instanceof RegExp && keep_setting.test(name)); } var lineTerminatorEscape = { "\0": "0", "\n": "n", "\r": "r", "\u2028": "u2028", "\u2029": "u2029", }; function regexp_source_fix(source) { // V8 does not escape line terminators in regexp patterns in node 12 // We'll also remove literal \0 return source.replace(/[\0\n\r\u2028\u2029]/g, function (match, offset) { var escaped = source[offset - 1] == "\\" && (source[offset - 2] != "\\" || /(?:^|[^\\])(?:\\{2})*$/.test(source.slice(0, offset - 1))); return (escaped ? "" : "\\") + lineTerminatorEscape[match]; }); } // Subset of regexps that is not going to cause regexp based DDOS // https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS const re_safe_regexp = /^[\\/|\0\s\w^$.[\]()]*$/; /** Check if the regexp is safe for Terser to create without risking a RegExp DOS */ export const regexp_is_safe = (source) => re_safe_regexp.test(source); const all_flags = "dgimsuyv"; function sort_regexp_flags(flags) { const existing_flags = new Set(flags.split("")); let out = ""; for (const flag of all_flags) { if (existing_flags.has(flag)) { out += flag; existing_flags.delete(flag); } } if (existing_flags.size) { // Flags Terser doesn't know about existing_flags.forEach(flag => { out += flag; }); } return out; } function has_annotation(node, annotation) { return node._annotations & annotation; } function set_annotation(node, annotation) { node._annotations |= annotation; } function clear_annotation(node, annotation) { node._annotations &= ~annotation; } export { characters, defaults, HOP, keep_name, make_node, makePredicate, map_add, map_from_object, map_to_object, MAP, member, mergeSort, noop, push_uniq, regexp_source_fix, remove, return_false, return_null, return_this, return_true, sort_regexp_flags, string_template, has_annotation, set_annotation, clear_annotation, }; terser-5.19.2/main.js000066400000000000000000000011701445647217600144150ustar00rootroot00000000000000import "./lib/transform.js"; import "./lib/mozilla-ast.js"; import { minify } from "./lib/minify.js"; export { minify } from "./lib/minify.js"; export { run_cli as _run_cli } from "./lib/cli.js"; export async 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; } async function infer_options(options) { try { await minify("", options); } catch (error) { return error.defs; } } terser-5.19.2/package-lock.json000066400000000000000000005054721445647217600163650ustar00rootroot00000000000000{ "name": "terser", "version": "5.19.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "terser", "version": "5.19.2", "license": "BSD-2-Clause", "dependencies": { "@jridgewell/source-map": "^0.3.3", "acorn": "^8.8.2", "commander": "^2.20.0", "source-map-support": "~0.5.20" }, "bin": { "terser": "bin/terser" }, "devDependencies": { "@ls-lint/ls-lint": "^1.11.2", "astring": "^1.8.5", "eslint": "^7.32.0", "eslump": "^3.0.0", "esm": "^3.2.25", "mocha": "^9.2.0", "pre-commit": "^1.2.2", "rollup": "^2.56.3", "semver": "^7.5.1", "source-map": "~0.8.0-beta.0" }, "engines": { "node": ">=10" } }, "node_modules/@aashutoshrathi/word-wrap": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", "integrity": "sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==", "dev": true, "engines": { "node": ">=0.10.0" } }, "node_modules/@babel/code-frame": { "version": "7.12.11", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.12.11.tgz", "integrity": "sha512-Zt1yodBx1UcyiePMSkWnU4hPqhwq7hGi2nFL1LeA3EUl+q2LQx16MISgJ0+z7dnmgvP9QtIleuETGOiOH1RcIw==", "dev": true, "dependencies": { "@babel/highlight": "^7.10.4" } }, "node_modules/@babel/helper-validator-identifier": { "version": "7.19.1", "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz", "integrity": "sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/highlight": { "version": "7.18.6", "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.18.6.tgz", "integrity": "sha512-u7stbOuYjaPezCuLj29hNW1v64M2Md2qupEKP1fHc7WdOA3DgLh37suiSrZYY7haUB7iBeQZ9P1uiRF359do3g==", "dev": true, "dependencies": { "@babel/helper-validator-identifier": "^7.18.6", "chalk": "^2.0.0", "js-tokens": "^4.0.0" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/highlight/node_modules/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, "dependencies": { "color-convert": "^1.9.0" }, "engines": { "node": ">=4" } }, "node_modules/@babel/highlight/node_modules/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, "dependencies": { "ansi-styles": "^3.2.1", "escape-string-regexp": "^1.0.5", "supports-color": "^5.3.0" }, "engines": { "node": ">=4" } }, "node_modules/@babel/highlight/node_modules/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, "dependencies": { "color-name": "1.1.3" } }, "node_modules/@babel/highlight/node_modules/color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", "dev": true }, "node_modules/@babel/highlight/node_modules/escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", "dev": true, "engines": { "node": ">=0.8.0" } }, "node_modules/@babel/highlight/node_modules/has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", "dev": true, "engines": { "node": ">=4" } }, "node_modules/@babel/highlight/node_modules/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, "dependencies": { "has-flag": "^3.0.0" }, "engines": { "node": ">=4" } }, "node_modules/@eslint/eslintrc": { "version": "0.4.3", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.4.3.tgz", "integrity": "sha512-J6KFFz5QCYUJq3pf0mjEcCJVERbzv71PUIDczuh9JkwGEzced6CO5ADLHB1rbf/+oPBtoPfMYNOpGDzCANlbXw==", "dev": true, "dependencies": { "ajv": "^6.12.4", "debug": "^4.1.1", "espree": "^7.3.0", "globals": "^13.9.0", "ignore": "^4.0.6", "import-fresh": "^3.2.1", "js-yaml": "^3.13.1", "minimatch": "^3.0.4", "strip-json-comments": "^3.1.1" }, "engines": { "node": "^10.12.0 || >=12.0.0" } }, "node_modules/@humanwhocodes/config-array": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.5.0.tgz", "integrity": "sha512-FagtKFz74XrTl7y6HCzQpwDfXP0yhxe9lHLD1UZxjvZIcbyRz8zTFF/yYNfSfzU414eDwZ1SrO0Qvtyf+wFMQg==", "dev": true, "dependencies": { "@humanwhocodes/object-schema": "^1.2.0", "debug": "^4.1.1", "minimatch": "^3.0.4" }, "engines": { "node": ">=10.10.0" } }, "node_modules/@humanwhocodes/object-schema": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", "dev": true }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz", "integrity": "sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==", "dependencies": { "@jridgewell/set-array": "^1.0.1", "@jridgewell/sourcemap-codec": "^1.4.10", "@jridgewell/trace-mapping": "^0.3.9" }, "engines": { "node": ">=6.0.0" } }, "node_modules/@jridgewell/resolve-uri": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==", "engines": { "node": ">=6.0.0" } }, "node_modules/@jridgewell/set-array": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz", "integrity": "sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==", "engines": { "node": ">=6.0.0" } }, "node_modules/@jridgewell/source-map": { "version": "0.3.5", "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.5.tgz", "integrity": "sha512-UTYAUj/wviwdsMfzoSJspJxbkH5o1snzwX0//0ENX1u/55kkZZkcTZP6u9bwKGkv+dkk9at4m1Cpt0uY80kcpQ==", "dependencies": { "@jridgewell/gen-mapping": "^0.3.0", "@jridgewell/trace-mapping": "^0.3.9" } }, "node_modules/@jridgewell/sourcemap-codec": { "version": "1.4.15", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==" }, "node_modules/@jridgewell/trace-mapping": { "version": "0.3.18", "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.18.tgz", "integrity": "sha512-w+niJYzMHdd7USdiH2U6869nqhD2nbfZXND5Yp93qIbEmnDNk7PD48o+YchRVpzMU7M6jVCbenTR7PA1FLQ9pA==", "dependencies": { "@jridgewell/resolve-uri": "3.1.0", "@jridgewell/sourcemap-codec": "1.4.14" } }, "node_modules/@jridgewell/trace-mapping/node_modules/@jridgewell/sourcemap-codec": { "version": "1.4.14", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==" }, "node_modules/@ls-lint/ls-lint": { "version": "1.11.2", "resolved": "https://registry.npmjs.org/@ls-lint/ls-lint/-/ls-lint-1.11.2.tgz", "integrity": "sha512-kX+CCjgNz+NHCaOcFyJLSBLRgAoyOxN18QFLpgucz5ILvbr60BGjwKaoPYTv/rBV/77L+Oz82lpP24mzJ2wGsQ==", "cpu": [ "x64", "arm64" ], "dev": true, "os": [ "darwin", "linux", "win32" ], "bin": { "ls-lint": "bin/cli.js" } }, "node_modules/@ungap/promise-all-settled": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz", "integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==", "dev": true }, "node_modules/acorn": { "version": "8.10.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.10.0.tgz", "integrity": "sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==", "bin": { "acorn": "bin/acorn" }, "engines": { "node": ">=0.4.0" } }, "node_modules/acorn-jsx": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", "dev": true, "peerDependencies": { "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", "dev": true, "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", "json-schema-traverse": "^0.4.1", "uri-js": "^4.2.2" }, "funding": { "type": "github", "url": "https://github.com/sponsors/epoberezkin" } }, "node_modules/ansi-colors": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", "integrity": "sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==", "dev": true, "engines": { "node": ">=6" } }, "node_modules/ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", "dev": true, "engines": { "node": ">=8" } }, "node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", "dev": true, "dependencies": { "color-convert": "^2.0.1" }, "engines": { "node": ">=8" }, "funding": { "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, "node_modules/anymatch": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", "dev": true, "dependencies": { "normalize-path": "^3.0.0", "picomatch": "^2.0.4" }, "engines": { "node": ">= 8" } }, "node_modules/argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", "dev": true, "dependencies": { "sprintf-js": "~1.0.2" } }, "node_modules/astral-regex": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-2.0.0.tgz", "integrity": "sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==", "dev": true, "engines": { "node": ">=8" } }, "node_modules/astring": { "version": "1.8.5", "resolved": "https://registry.npmjs.org/astring/-/astring-1.8.5.tgz", "integrity": "sha512-TuBbdn7jWVzf8dmFGTaRpW8qgANtWLi1qJLnkfGO5uVf6jf9f/F4B1H35tnOI+qVYZo3p3i8WZlbZOuPAE0wEA==", "dev": true, "bin": { "astring": "bin/astring" } }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, "node_modules/binary-extensions": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", "dev": true, "engines": { "node": ">=8" } }, "node_modules/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, "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" } }, "node_modules/braces": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", "dev": true, "dependencies": { "fill-range": "^7.0.1" }, "engines": { "node": ">=8" } }, "node_modules/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 }, "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" }, "node_modules/callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", "dev": true, "engines": { "node": ">=6" } }, "node_modules/camelcase": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", "dev": true, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", "dev": true, "dependencies": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" }, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/chalk/chalk?sponsor=1" } }, "node_modules/chokidar": { "version": "3.5.3", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", "dev": true, "funding": [ { "type": "individual", "url": "https://paulmillr.com/funding/" } ], "dependencies": { "anymatch": "~3.1.2", "braces": "~3.0.2", "glob-parent": "~5.1.2", "is-binary-path": "~2.1.0", "is-glob": "~4.0.1", "normalize-path": "~3.0.0", "readdirp": "~3.6.0" }, "engines": { "node": ">= 8.10.0" }, "optionalDependencies": { "fsevents": "~2.3.2" } }, "node_modules/cliui": { "version": "7.0.4", "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", "dev": true, "dependencies": { "string-width": "^4.2.0", "strip-ansi": "^6.0.0", "wrap-ansi": "^7.0.0" } }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", "dev": true, "dependencies": { "color-name": "~1.1.4" }, "engines": { "node": ">=7.0.0" } }, "node_modules/color-name": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, "node_modules/commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "dev": true }, "node_modules/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, "engines": [ "node >= 0.8" ], "dependencies": { "buffer-from": "^1.0.0", "inherits": "^2.0.3", "readable-stream": "^2.2.2", "typedarray": "^0.0.6" } }, "node_modules/core-util-is": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", "dev": true }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", "dev": true, "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", "which": "^2.0.1" }, "engines": { "node": ">= 8" } }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", "dev": true, "dependencies": { "ms": "2.1.2" }, "engines": { "node": ">=6.0" }, "peerDependenciesMeta": { "supports-color": { "optional": true } } }, "node_modules/decamelize": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-4.0.0.tgz", "integrity": "sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==", "dev": true, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/deep-is": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", "dev": true }, "node_modules/diff": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", "dev": true, "engines": { "node": ">=0.3.1" } }, "node_modules/doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", "dev": true, "dependencies": { "esutils": "^2.0.2" }, "engines": { "node": ">=6.0.0" } }, "node_modules/emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", "dev": true }, "node_modules/enquirer": { "version": "2.3.6", "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz", "integrity": "sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==", "dev": true, "dependencies": { "ansi-colors": "^4.1.1" }, "engines": { "node": ">=8.6" } }, "node_modules/escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", "dev": true, "engines": { "node": ">=6" } }, "node_modules/escape-string-regexp": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", "dev": true, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/eslint": { "version": "7.32.0", "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.32.0.tgz", "integrity": "sha512-VHZ8gX+EDfz+97jGcgyGCyRia/dPOd6Xh9yPv8Bl1+SoaIwD+a/vlrOmGRUyOYu7MwUhc7CxqeaDZU13S4+EpA==", "dev": true, "dependencies": { "@babel/code-frame": "7.12.11", "@eslint/eslintrc": "^0.4.3", "@humanwhocodes/config-array": "^0.5.0", "ajv": "^6.10.0", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", "debug": "^4.0.1", "doctrine": "^3.0.0", "enquirer": "^2.3.5", "escape-string-regexp": "^4.0.0", "eslint-scope": "^5.1.1", "eslint-utils": "^2.1.0", "eslint-visitor-keys": "^2.0.0", "espree": "^7.3.1", "esquery": "^1.4.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", "file-entry-cache": "^6.0.1", "functional-red-black-tree": "^1.0.1", "glob-parent": "^5.1.2", "globals": "^13.6.0", "ignore": "^4.0.6", "import-fresh": "^3.0.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "js-yaml": "^3.13.1", "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.4.1", "lodash.merge": "^4.6.2", "minimatch": "^3.0.4", "natural-compare": "^1.4.0", "optionator": "^0.9.1", "progress": "^2.0.0", "regexpp": "^3.1.0", "semver": "^7.2.1", "strip-ansi": "^6.0.0", "strip-json-comments": "^3.1.0", "table": "^6.0.9", "text-table": "^0.2.0", "v8-compile-cache": "^2.0.3" }, "bin": { "eslint": "bin/eslint.js" }, "engines": { "node": "^10.12.0 || >=12.0.0" }, "funding": { "url": "https://opencollective.com/eslint" } }, "node_modules/eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", "dev": true, "dependencies": { "esrecurse": "^4.3.0", "estraverse": "^4.1.1" }, "engines": { "node": ">=8.0.0" } }, "node_modules/eslint-utils": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.1.0.tgz", "integrity": "sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg==", "dev": true, "dependencies": { "eslint-visitor-keys": "^1.1.0" }, "engines": { "node": ">=6" }, "funding": { "url": "https://github.com/sponsors/mysticatea" } }, "node_modules/eslint-utils/node_modules/eslint-visitor-keys": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz", "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==", "dev": true, "engines": { "node": ">=4" } }, "node_modules/eslint-visitor-keys": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz", "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==", "dev": true, "engines": { "node": ">=10" } }, "node_modules/eslump": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/eslump/-/eslump-3.0.0.tgz", "integrity": "sha512-TAhAytVHCHMk0yDxCbS881uuAEPfoqdnmp2mkwDgBoM5lVBfoE9nYxq0LCdgJS8NASV8V8NIUF3N4YjhiuuTBg==", "dev": true, "dependencies": { "@babel/code-frame": "^7.12.13", "mkdirp": "^1.0.4", "optionator": "^0.9.1", "random-int": "^2.0.1", "random-item": "^3.1.0", "shift-codegen": "^7.0.3", "shift-fuzzer": "^2.0.0", "shift-parser": "^7.0.3", "shift-reducer": "^6.0.0" }, "bin": { "eslump": "src/cli-runner.js" } }, "node_modules/eslump/node_modules/@babel/code-frame": { "version": "7.21.4", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.21.4.tgz", "integrity": "sha512-LYvhNKfwWSPpocw8GI7gpK2nq3HSDuEPC/uSYaALSJu9xjsalaaYFOq0Pwt5KmVqwEbZlDu81aLXwBOmD/Fv9g==", "dev": true, "dependencies": { "@babel/highlight": "^7.18.6" }, "engines": { "node": ">=6.9.0" } }, "node_modules/esm": { "version": "3.2.25", "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz", "integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==", "dev": true, "engines": { "node": ">=6" } }, "node_modules/espree": { "version": "7.3.1", "resolved": "https://registry.npmjs.org/espree/-/espree-7.3.1.tgz", "integrity": "sha512-v3JCNCE64umkFpmkFGqzVKsOT0tN1Zr+ueqLZfpV1Ob8e+CEgPWa+OxCoGH3tnhimMKIaBm4m/vaRpJ/krRz2g==", "dev": true, "dependencies": { "acorn": "^7.4.0", "acorn-jsx": "^5.3.1", "eslint-visitor-keys": "^1.3.0" }, "engines": { "node": "^10.12.0 || >=12.0.0" } }, "node_modules/espree/node_modules/acorn": { "version": "7.4.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", "dev": true, "bin": { "acorn": "bin/acorn" }, "engines": { "node": ">=0.4.0" } }, "node_modules/espree/node_modules/eslint-visitor-keys": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz", "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==", "dev": true, "engines": { "node": ">=4" } }, "node_modules/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, "bin": { "esparse": "bin/esparse.js", "esvalidate": "bin/esvalidate.js" }, "engines": { "node": ">=4" } }, "node_modules/esquery": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz", "integrity": "sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==", "dev": true, "dependencies": { "estraverse": "^5.1.0" }, "engines": { "node": ">=0.10" } }, "node_modules/esquery/node_modules/estraverse": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", "dev": true, "engines": { "node": ">=4.0" } }, "node_modules/esrecurse": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", "dev": true, "dependencies": { "estraverse": "^5.2.0" }, "engines": { "node": ">=4.0" } }, "node_modules/esrecurse/node_modules/estraverse": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", "dev": true, "engines": { "node": ">=4.0" } }, "node_modules/estraverse": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", "dev": true, "engines": { "node": ">=4.0" } }, "node_modules/esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", "dev": true, "engines": { "node": ">=0.10.0" } }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, "node_modules/fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", "dev": true }, "node_modules/fast-levenshtein": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", "dev": true }, "node_modules/file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", "integrity": "sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==", "dev": true, "dependencies": { "flat-cache": "^3.0.4" }, "engines": { "node": "^10.12.0 || >=12.0.0" } }, "node_modules/fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", "dev": true, "dependencies": { "to-regex-range": "^5.0.1" }, "engines": { "node": ">=8" } }, "node_modules/find-up": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", "dev": true, "dependencies": { "locate-path": "^6.0.0", "path-exists": "^4.0.0" }, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/flat": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", "dev": true, "bin": { "flat": "cli.js" } }, "node_modules/flat-cache": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz", "integrity": "sha512-dm9s5Pw7Jc0GvMYbshN6zchCA9RgQlzzEZX3vylR9IqFfS8XciblUXOKfW6SiuJ0e13eDYZoZV5wdrev7P3Nwg==", "dev": true, "dependencies": { "flatted": "^3.1.0", "rimraf": "^3.0.2" }, "engines": { "node": "^10.12.0 || >=12.0.0" } }, "node_modules/flatted": { "version": "3.2.7", "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.7.tgz", "integrity": "sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==", "dev": true }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "dev": true }, "node_modules/fsevents": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", "dev": true, "hasInstallScript": true, "optional": true, "os": [ "darwin" ], "engines": { "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, "node_modules/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": "sha512-dsKNQNdj6xA3T+QlADDA7mOSlX0qiMINjn0cgr+eGHGsbSHzTabcIogz2+p/iqP1Xs6EP/sS2SbqH+brGTbq0g==", "dev": true }, "node_modules/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, "engines": { "node": "6.* || 8.* || >= 10.*" } }, "node_modules/glob": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", "dev": true, "dependencies": { "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" }, "engines": { "node": "*" }, "funding": { "url": "https://github.com/sponsors/isaacs" } }, "node_modules/glob-parent": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", "dev": true, "dependencies": { "is-glob": "^4.0.1" }, "engines": { "node": ">= 6" } }, "node_modules/globals": { "version": "13.20.0", "resolved": "https://registry.npmjs.org/globals/-/globals-13.20.0.tgz", "integrity": "sha512-Qg5QtVkCy/kv3FUSlu4ukeZDVf9ee0iXLAUYX13gbR17bnejFTzr4iS9bY7kwCf1NztRNm1t91fjOiyx4CSwPQ==", "dev": true, "dependencies": { "type-fest": "^0.20.2" }, "engines": { "node": ">=8" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/growl": { "version": "1.10.5", "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", "dev": true, "engines": { "node": ">=4.x" } }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", "dev": true, "engines": { "node": ">=8" } }, "node_modules/he": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", "dev": true, "bin": { "he": "bin/he" } }, "node_modules/ignore": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", "dev": true, "engines": { "node": ">= 4" } }, "node_modules/import-fresh": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", "dev": true, "dependencies": { "parent-module": "^1.0.0", "resolve-from": "^4.0.0" }, "engines": { "node": ">=6" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", "dev": true, "engines": { "node": ">=0.8.19" } }, "node_modules/inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", "dev": true, "dependencies": { "once": "^1.3.0", "wrappy": "1" } }, "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true }, "node_modules/is-binary-path": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", "dev": true, "dependencies": { "binary-extensions": "^2.0.0" }, "engines": { "node": ">=8" } }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", "dev": true, "engines": { "node": ">=0.10.0" } }, "node_modules/is-fullwidth-code-point": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", "dev": true, "engines": { "node": ">=8" } }, "node_modules/is-glob": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", "dev": true, "dependencies": { "is-extglob": "^2.1.1" }, "engines": { "node": ">=0.10.0" } }, "node_modules/is-number": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", "dev": true, "engines": { "node": ">=0.12.0" } }, "node_modules/is-plain-obj": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", "dev": true, "engines": { "node": ">=8" } }, "node_modules/is-unicode-supported": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", "integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==", "dev": true, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", "dev": true }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true }, "node_modules/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 }, "node_modules/js-yaml": { "version": "3.14.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", "dev": true, "dependencies": { "argparse": "^1.0.7", "esprima": "^4.0.0" }, "bin": { "js-yaml": "bin/js-yaml.js" } }, "node_modules/json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", "dev": true }, "node_modules/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": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", "dev": true }, "node_modules/levn": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", "dev": true, "dependencies": { "prelude-ls": "^1.2.1", "type-check": "~0.4.0" }, "engines": { "node": ">= 0.8.0" } }, "node_modules/locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", "dev": true, "dependencies": { "p-locate": "^5.0.0" }, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", "dev": true }, "node_modules/lodash.sortby": { "version": "4.7.0", "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", "integrity": "sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==", "dev": true }, "node_modules/lodash.truncate": { "version": "4.4.2", "resolved": "https://registry.npmjs.org/lodash.truncate/-/lodash.truncate-4.4.2.tgz", "integrity": "sha512-jttmRe7bRse52OsWIMDLaXxWqRAmtIUccAQ3garviCqJjafXOfNMO0yMfNpdD6zbGaTU0P5Nz7e7gAT6cKmJRw==", "dev": true }, "node_modules/log-symbols": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", "dev": true, "dependencies": { "chalk": "^4.1.0", "is-unicode-supported": "^0.1.0" }, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/lru-cache": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", "dev": true, "dependencies": { "yallist": "^4.0.0" }, "engines": { "node": ">=10" } }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "dev": true, "dependencies": { "brace-expansion": "^1.1.7" }, "engines": { "node": "*" } }, "node_modules/mkdirp": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", "dev": true, "bin": { "mkdirp": "bin/cmd.js" }, "engines": { "node": ">=10" } }, "node_modules/mocha": { "version": "9.2.2", "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.2.2.tgz", "integrity": "sha512-L6XC3EdwT6YrIk0yXpavvLkn8h+EU+Y5UcCHKECyMbdUIxyMuZj4bX4U9e1nvnvUUvQVsV2VHQr5zLdcUkhW/g==", "dev": true, "dependencies": { "@ungap/promise-all-settled": "1.1.2", "ansi-colors": "4.1.1", "browser-stdout": "1.3.1", "chokidar": "3.5.3", "debug": "4.3.3", "diff": "5.0.0", "escape-string-regexp": "4.0.0", "find-up": "5.0.0", "glob": "7.2.0", "growl": "1.10.5", "he": "1.2.0", "js-yaml": "4.1.0", "log-symbols": "4.1.0", "minimatch": "4.2.1", "ms": "2.1.3", "nanoid": "3.3.1", "serialize-javascript": "6.0.0", "strip-json-comments": "3.1.1", "supports-color": "8.1.1", "which": "2.0.2", "workerpool": "6.2.0", "yargs": "16.2.0", "yargs-parser": "20.2.4", "yargs-unparser": "2.0.0" }, "bin": { "_mocha": "bin/_mocha", "mocha": "bin/mocha" }, "engines": { "node": ">= 12.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/mochajs" } }, "node_modules/mocha/node_modules/ansi-colors": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", "dev": true, "engines": { "node": ">=6" } }, "node_modules/mocha/node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", "dev": true }, "node_modules/mocha/node_modules/debug": { "version": "4.3.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz", "integrity": "sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==", "dev": true, "dependencies": { "ms": "2.1.2" }, "engines": { "node": ">=6.0" }, "peerDependenciesMeta": { "supports-color": { "optional": true } } }, "node_modules/mocha/node_modules/debug/node_modules/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 }, "node_modules/mocha/node_modules/js-yaml": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", "dev": true, "dependencies": { "argparse": "^2.0.1" }, "bin": { "js-yaml": "bin/js-yaml.js" } }, "node_modules/mocha/node_modules/minimatch": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-4.2.1.tgz", "integrity": "sha512-9Uq1ChtSZO+Mxa/CL1eGizn2vRn3MlLgzhT0Iz8zaY8NdvxvB0d5QdPFmCKf7JKA9Lerx5vRrnwO03jsSfGG9g==", "dev": true, "dependencies": { "brace-expansion": "^1.1.7" }, "engines": { "node": ">=10" } }, "node_modules/mocha/node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "dev": true }, "node_modules/mocha/node_modules/supports-color": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", "dev": true, "dependencies": { "has-flag": "^4.0.0" }, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/chalk/supports-color?sponsor=1" } }, "node_modules/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 }, "node_modules/multimap": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/multimap/-/multimap-1.1.0.tgz", "integrity": "sha512-0ZIR9PasPxGXmRsEF8jsDzndzHDj7tIav+JUmvIFB/WHswliFnquxECT/De7GR4yg99ky/NlRKJT82G1y271bw==", "dev": true }, "node_modules/nanoid": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.1.tgz", "integrity": "sha512-n6Vs/3KGyxPQd6uO0eH4Bv0ojGSUvuLlIHtC3Y0kEO23YRge8H9x1GCzLn28YX0H66pMkxuaeESFq4tKISKwdw==", "dev": true, "bin": { "nanoid": "bin/nanoid.cjs" }, "engines": { "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" } }, "node_modules/natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", "dev": true }, "node_modules/normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", "dev": true, "engines": { "node": ">=0.10.0" } }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", "dev": true, "engines": { "node": ">=0.10.0" } }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", "dev": true, "dependencies": { "wrappy": "1" } }, "node_modules/optionator": { "version": "0.9.3", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.3.tgz", "integrity": "sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==", "dev": true, "dependencies": { "@aashutoshrathi/word-wrap": "^1.2.3", "deep-is": "^0.1.3", "fast-levenshtein": "^2.0.6", "levn": "^0.4.1", "prelude-ls": "^1.2.1", "type-check": "^0.4.0" }, "engines": { "node": ">= 0.8.0" } }, "node_modules/os-shim": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/os-shim/-/os-shim-0.1.3.tgz", "integrity": "sha512-jd0cvB8qQ5uVt0lvCIexBaROw1KyKm5sbulg2fWOHjETisuCzWyt+eTZKEMs8v6HwzoGs8xik26jg7eCM6pS+A==", "dev": true, "engines": { "node": ">= 0.4.0" } }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", "dev": true, "dependencies": { "yocto-queue": "^0.1.0" }, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/p-locate": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", "dev": true, "dependencies": { "p-limit": "^3.0.2" }, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", "dev": true, "dependencies": { "callsites": "^3.0.0" }, "engines": { "node": ">=6" } }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", "dev": true, "engines": { "node": ">=8" } }, "node_modules/path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", "dev": true, "engines": { "node": ">=0.10.0" } }, "node_modules/path-key": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", "dev": true, "engines": { "node": ">=8" } }, "node_modules/picomatch": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", "dev": true, "engines": { "node": ">=8.6" }, "funding": { "url": "https://github.com/sponsors/jonschlinkert" } }, "node_modules/pre-commit": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/pre-commit/-/pre-commit-1.2.2.tgz", "integrity": "sha512-qokTiqxD6GjODy5ETAIgzsRgnBWWQHQH2ghy86PU7mIn/wuWeTwF3otyNQZxWBwVn8XNr8Tdzj/QfUXpH+gRZA==", "dev": true, "hasInstallScript": true, "dependencies": { "cross-spawn": "^5.0.1", "spawn-sync": "^1.0.15", "which": "1.2.x" } }, "node_modules/pre-commit/node_modules/cross-spawn": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", "integrity": "sha512-pTgQJ5KC0d2hcY8eyL1IzlBPYjTkyH72XRZPnLyKus2mBfNjQs3klqbJU2VILqZryAZUt9JOb3h/mWMy23/f5A==", "dev": true, "dependencies": { "lru-cache": "^4.0.1", "shebang-command": "^1.2.0", "which": "^1.2.9" } }, "node_modules/pre-commit/node_modules/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, "dependencies": { "pseudomap": "^1.0.2", "yallist": "^2.1.2" } }, "node_modules/pre-commit/node_modules/shebang-command": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", "integrity": "sha512-EV3L1+UQWGor21OmnvojK36mhg+TyIKDh3iFBKBohr5xeXIhNBcx8oWdgkTEEQ+BEFFYdLRuqMfd5L84N1V5Vg==", "dev": true, "dependencies": { "shebang-regex": "^1.0.0" }, "engines": { "node": ">=0.10.0" } }, "node_modules/pre-commit/node_modules/shebang-regex": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", "integrity": "sha512-wpoSFAxys6b2a2wHZ1XpDSgD7N9iVjg29Ph9uV/uaP9Ex/KXlkTZTeddxDPSYQpgvzKLGJke2UU0AzoGCjNIvQ==", "dev": true, "engines": { "node": ">=0.10.0" } }, "node_modules/pre-commit/node_modules/which": { "version": "1.2.14", "resolved": "https://registry.npmjs.org/which/-/which-1.2.14.tgz", "integrity": "sha512-16uPglFkRPzgiUXYMi1Jf8Z5EzN1iB4V0ZtMXcHZnwsBtQhhHeCqoWw7tsUY42hJGNDWtUsVLTjakIa5BgAxCw==", "dev": true, "dependencies": { "isexe": "^2.0.0" }, "bin": { "which": "bin/which" } }, "node_modules/pre-commit/node_modules/yallist": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", "integrity": "sha512-ncTzHV7NvsQZkYe1DW7cbDLm0YpzHmZF5r/iyP3ZnQtMiJ+pjzisCiMNI+Sj+xQF5pXhSHxSB3uDbsBTzY/c2A==", "dev": true }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true, "engines": { "node": ">= 0.8.0" } }, "node_modules/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 }, "node_modules/progress": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", "dev": true, "engines": { "node": ">=0.4.0" } }, "node_modules/pseudomap": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", "integrity": "sha512-b/YwNhb8lk1Zz2+bXXpS/LK9OisiZZ1SNsSLxN1x2OXVEhW2Ckr/7mWE5vrC1ZTiJlD9g19jWszTmJsB+oEpFQ==", "dev": true }, "node_modules/punycode": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==", "dev": true, "engines": { "node": ">=6" } }, "node_modules/random-int": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/random-int/-/random-int-2.0.1.tgz", "integrity": "sha512-YALjWK2Rt9EMIv9BF/3mvlzFWQathsvb5UZmN1QmhfIOfcQYXc/UcLzg0ablqesSBpBVLt2Tlwv/eTuBh4LXUQ==", "dev": true, "engines": { "node": ">=8" } }, "node_modules/random-item": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/random-item/-/random-item-3.1.0.tgz", "integrity": "sha512-0DyAT8LYBNQKSkqcPjia/HNoWCZ5JWBdAQWjBQVh5DMVv3Fv7V90I8/AuUf8NW4zdFn27i9qj8Kp6wI5JsiiOA==", "dev": true, "engines": { "node": ">=8" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", "dev": true, "dependencies": { "safe-buffer": "^5.1.0" } }, "node_modules/readable-stream": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", "dev": true, "dependencies": { "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" } }, "node_modules/readable-stream/node_modules/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 }, "node_modules/readdirp": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", "dev": true, "dependencies": { "picomatch": "^2.2.1" }, "engines": { "node": ">=8.10.0" } }, "node_modules/regexpp": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz", "integrity": "sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==", "dev": true, "engines": { "node": ">=8" }, "funding": { "url": "https://github.com/sponsors/mysticatea" } }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", "dev": true, "engines": { "node": ">=0.10.0" } }, "node_modules/require-from-string": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", "dev": true, "engines": { "node": ">=0.10.0" } }, "node_modules/resolve-from": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", "dev": true, "engines": { "node": ">=4" } }, "node_modules/rimraf": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", "dev": true, "dependencies": { "glob": "^7.1.3" }, "bin": { "rimraf": "bin.js" }, "funding": { "url": "https://github.com/sponsors/isaacs" } }, "node_modules/rollup": { "version": "2.79.1", "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.1.tgz", "integrity": "sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==", "dev": true, "bin": { "rollup": "dist/bin/rollup" }, "engines": { "node": ">=10.0.0" }, "optionalDependencies": { "fsevents": "~2.3.2" } }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", "dev": true, "funding": [ { "type": "github", "url": "https://github.com/sponsors/feross" }, { "type": "patreon", "url": "https://www.patreon.com/feross" }, { "type": "consulting", "url": "https://feross.org/support" } ] }, "node_modules/semver": { "version": "7.5.4", "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dev": true, "dependencies": { "lru-cache": "^6.0.0" }, "bin": { "semver": "bin/semver.js" }, "engines": { "node": ">=10" } }, "node_modules/serialize-javascript": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz", "integrity": "sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==", "dev": true, "dependencies": { "randombytes": "^2.1.0" } }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", "dev": true, "dependencies": { "shebang-regex": "^3.0.0" }, "engines": { "node": ">=8" } }, "node_modules/shebang-regex": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", "dev": true, "engines": { "node": ">=8" } }, "node_modules/shift-ast": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/shift-ast/-/shift-ast-6.1.0.tgz", "integrity": "sha512-Vj4XUIJIFPIh6VcBGJ1hjH/kM88XGer94Pr7Rvxa+idEylDsrwtLw268HoxGo5xReL6T3DdRl/9/Pr1XihZ/8Q==", "dev": true }, "node_modules/shift-codegen": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/shift-codegen/-/shift-codegen-7.0.3.tgz", "integrity": "sha512-dfCVVdBF0qZ6pkajQ3bjxRdNEltyxEITVe7tBJkQt2eCI3znUkSxq0VSe/tTWq1LKHeAS4HuOiqYEuHMFkSq9w==", "dev": true, "dependencies": { "esutils": "^2.0.2", "object-assign": "^4.1.0", "shift-reducer": "6.0.0" } }, "node_modules/shift-fuzzer": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shift-fuzzer/-/shift-fuzzer-2.0.0.tgz", "integrity": "sha512-hgV4jqXELYR0UpEDlTnYcv0GXvhXV/y3lyYNyGtTq1Q6EdFIC9LLHjlrfVFt7d1VyzJqPkl/fME31ta0KrHiTQ==", "dev": true, "dependencies": { "shift-ast": "6.1.0" } }, "node_modules/shift-parser": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/shift-parser/-/shift-parser-7.0.3.tgz", "integrity": "sha512-uYX2ORyZfKZrUc4iKKkO9KOhzUSxCrSBk7QK6ZmShId+BOo1gh1IwecVy97ynyOTpmhPWUttjC8BzsnQl65Zew==", "dev": true, "dependencies": { "multimap": "^1.0.2", "shift-ast": "6.0.0", "shift-reducer": "6.0.0", "shift-regexp-acceptor": "2.0.3" } }, "node_modules/shift-parser/node_modules/shift-ast": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/shift-ast/-/shift-ast-6.0.0.tgz", "integrity": "sha512-XXxDcEBWVBzqWXfNYJlLyJ1/9kMvOXVRXiqPjkOrTCC5qRsBvEMJMRLLFhU3tn8ue56Y7IZyBE6bexFum5QLUw==", "dev": true }, "node_modules/shift-reducer": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/shift-reducer/-/shift-reducer-6.0.0.tgz", "integrity": "sha512-2rJraRP8drIOjvaE/sALa+0tGJmMVUzlmS3wIJerJbaYuCjpFAiF0WjkTOFVtz1144Nm/ECmqeG+7yRhuMVsMg==", "dev": true, "dependencies": { "shift-ast": "6.0.0" } }, "node_modules/shift-reducer/node_modules/shift-ast": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/shift-ast/-/shift-ast-6.0.0.tgz", "integrity": "sha512-XXxDcEBWVBzqWXfNYJlLyJ1/9kMvOXVRXiqPjkOrTCC5qRsBvEMJMRLLFhU3tn8ue56Y7IZyBE6bexFum5QLUw==", "dev": true }, "node_modules/shift-regexp-acceptor": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/shift-regexp-acceptor/-/shift-regexp-acceptor-2.0.3.tgz", "integrity": "sha512-sxL7e5JNUFxm+gutFRXktX2D6KVgDAHNuDsk5XHB9Z+N5yXooZG6pdZ1GEbo3Jz6lF7ETYLBC4WAjIFm2RKTmA==", "dev": true, "dependencies": { "unicode-match-property-ecmascript": "1.0.4", "unicode-match-property-value-ecmascript": "1.0.2", "unicode-property-aliases-ecmascript": "1.0.4" } }, "node_modules/slice-ansi": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-4.0.0.tgz", "integrity": "sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==", "dev": true, "dependencies": { "ansi-styles": "^4.0.0", "astral-regex": "^2.0.0", "is-fullwidth-code-point": "^3.0.0" }, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/chalk/slice-ansi?sponsor=1" } }, "node_modules/source-map": { "version": "0.8.0-beta.0", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.8.0-beta.0.tgz", "integrity": "sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==", "dev": true, "dependencies": { "whatwg-url": "^7.0.0" }, "engines": { "node": ">= 8" } }, "node_modules/source-map-support": { "version": "0.5.21", "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", "dependencies": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" } }, "node_modules/source-map-support/node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", "engines": { "node": ">=0.10.0" } }, "node_modules/spawn-sync": { "version": "1.0.15", "resolved": "https://registry.npmjs.org/spawn-sync/-/spawn-sync-1.0.15.tgz", "integrity": "sha512-9DWBgrgYZzNghseho0JOuh+5fg9u6QWhAWa51QC7+U5rCheZ/j1DrEZnyE0RBBRqZ9uEXGPgSSM0nky6burpVw==", "dev": true, "hasInstallScript": true, "dependencies": { "concat-stream": "^1.4.7", "os-shim": "^0.1.2" } }, "node_modules/sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==", "dev": true }, "node_modules/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, "dependencies": { "safe-buffer": "~5.1.0" } }, "node_modules/string_decoder/node_modules/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 }, "node_modules/string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", "dev": true, "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", "strip-ansi": "^6.0.1" }, "engines": { "node": ">=8" } }, "node_modules/strip-ansi": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", "dev": true, "dependencies": { "ansi-regex": "^5.0.1" }, "engines": { "node": ">=8" } }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", "dev": true, "engines": { "node": ">=8" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", "dev": true, "dependencies": { "has-flag": "^4.0.0" }, "engines": { "node": ">=8" } }, "node_modules/table": { "version": "6.8.1", "resolved": "https://registry.npmjs.org/table/-/table-6.8.1.tgz", "integrity": "sha512-Y4X9zqrCftUhMeH2EptSSERdVKt/nEdijTOacGD/97EKjhQ/Qs8RTlEGABSJNNN8lac9kheH+af7yAkEWlgneA==", "dev": true, "dependencies": { "ajv": "^8.0.1", "lodash.truncate": "^4.4.2", "slice-ansi": "^4.0.0", "string-width": "^4.2.3", "strip-ansi": "^6.0.1" }, "engines": { "node": ">=10.0.0" } }, "node_modules/table/node_modules/ajv": { "version": "8.12.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz", "integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==", "dev": true, "dependencies": { "fast-deep-equal": "^3.1.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2", "uri-js": "^4.2.2" }, "funding": { "type": "github", "url": "https://github.com/sponsors/epoberezkin" } }, "node_modules/table/node_modules/json-schema-traverse": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", "dev": true }, "node_modules/text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", "dev": true }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", "dev": true, "dependencies": { "is-number": "^7.0.0" }, "engines": { "node": ">=8.0" } }, "node_modules/tr46": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/tr46/-/tr46-1.0.1.tgz", "integrity": "sha512-dTpowEjclQ7Kgx5SdBkqRzVhERQXov8/l9Ft9dVM9fmg0W0KQSVaXX9T4i6twCPNtYiZM53lpSSUAwJbFPOHxA==", "dev": true, "dependencies": { "punycode": "^2.1.0" } }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", "dev": true, "dependencies": { "prelude-ls": "^1.2.1" }, "engines": { "node": ">= 0.8.0" } }, "node_modules/type-fest": { "version": "0.20.2", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", "dev": true, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/typedarray": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==", "dev": true }, "node_modules/unicode-canonical-property-names-ecmascript": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz", "integrity": "sha512-jDrNnXWHd4oHiTZnx/ZG7gtUTVp+gCcTTKr8L0HjlwphROEW3+Him+IpvC+xcJEFegapiMZyZe02CyuOnRmbnQ==", "dev": true, "engines": { "node": ">=4" } }, "node_modules/unicode-match-property-ecmascript": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/unicode-match-property-ecmascript/-/unicode-match-property-ecmascript-1.0.4.tgz", "integrity": "sha512-L4Qoh15vTfntsn4P1zqnHulG0LdXgjSO035fEpdtp6YxXhMT51Q6vgM5lYdG/5X3MjS+k/Y9Xw4SFCY9IkR0rg==", "dev": true, "dependencies": { "unicode-canonical-property-names-ecmascript": "^1.0.4", "unicode-property-aliases-ecmascript": "^1.0.4" }, "engines": { "node": ">=4" } }, "node_modules/unicode-match-property-value-ecmascript": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unicode-match-property-value-ecmascript/-/unicode-match-property-value-ecmascript-1.0.2.tgz", "integrity": "sha512-Rx7yODZC1L/T8XKo/2kNzVAQaRE88AaMvI1EF/Xnj3GW2wzN6fop9DDWuFAKUVFH7vozkz26DzP0qyWLKLIVPQ==", "dev": true, "engines": { "node": ">=4" } }, "node_modules/unicode-property-aliases-ecmascript": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-1.0.4.tgz", "integrity": "sha512-2WSLa6OdYd2ng8oqiGIWnJqyFArvhn+5vgx5GTxMbUYjCYKUcuKS62YLFF0R/BDGlB1yzXjQOLtPAfHsgirEpg==", "dev": true, "engines": { "node": ">=4" } }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", "dev": true, "dependencies": { "punycode": "^2.1.0" } }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "dev": true }, "node_modules/v8-compile-cache": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", "integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==", "dev": true }, "node_modules/webidl-conversions": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz", "integrity": "sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==", "dev": true }, "node_modules/whatwg-url": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-7.1.0.tgz", "integrity": "sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==", "dev": true, "dependencies": { "lodash.sortby": "^4.7.0", "tr46": "^1.0.1", "webidl-conversions": "^4.0.2" } }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", "dev": true, "dependencies": { "isexe": "^2.0.0" }, "bin": { "node-which": "bin/node-which" }, "engines": { "node": ">= 8" } }, "node_modules/workerpool": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.2.0.tgz", "integrity": "sha512-Rsk5qQHJ9eowMH28Jwhe8HEbmdYDX4lwoMWshiCXugjtHqMD9ZbiqSDLxcsfdqsETPzVUtX5s1Z5kStiIM6l4A==", "dev": true }, "node_modules/wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", "dev": true, "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", "strip-ansi": "^6.0.0" }, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", "dev": true }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", "dev": true, "engines": { "node": ">=10" } }, "node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "dev": true }, "node_modules/yargs": { "version": "16.2.0", "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", "dev": true, "dependencies": { "cliui": "^7.0.2", "escalade": "^3.1.1", "get-caller-file": "^2.0.5", "require-directory": "^2.1.1", "string-width": "^4.2.0", "y18n": "^5.0.5", "yargs-parser": "^20.2.2" }, "engines": { "node": ">=10" } }, "node_modules/yargs-parser": { "version": "20.2.4", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.4.tgz", "integrity": "sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==", "dev": true, "engines": { "node": ">=10" } }, "node_modules/yargs-unparser": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-2.0.0.tgz", "integrity": "sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA==", "dev": true, "dependencies": { "camelcase": "^6.0.0", "decamelize": "^4.0.0", "flat": "^5.0.2", "is-plain-obj": "^2.1.0" }, "engines": { "node": ">=10" } }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", "dev": true, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } } }, "dependencies": { "@aashutoshrathi/word-wrap": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", "integrity": "sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==", "dev": true }, "@babel/code-frame": { "version": "7.12.11", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.12.11.tgz", "integrity": "sha512-Zt1yodBx1UcyiePMSkWnU4hPqhwq7hGi2nFL1LeA3EUl+q2LQx16MISgJ0+z7dnmgvP9QtIleuETGOiOH1RcIw==", "dev": true, "requires": { "@babel/highlight": "^7.10.4" } }, "@babel/helper-validator-identifier": { "version": "7.19.1", "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz", "integrity": "sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w==", "dev": true }, "@babel/highlight": { "version": "7.18.6", "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.18.6.tgz", "integrity": "sha512-u7stbOuYjaPezCuLj29hNW1v64M2Md2qupEKP1fHc7WdOA3DgLh37suiSrZYY7haUB7iBeQZ9P1uiRF359do3g==", "dev": true, "requires": { "@babel/helper-validator-identifier": "^7.18.6", "chalk": "^2.0.0", "js-tokens": "^4.0.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" } }, "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" } }, "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": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", "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": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", "dev": true }, "has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", "dev": true }, "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" } } } }, "@eslint/eslintrc": { "version": "0.4.3", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.4.3.tgz", "integrity": "sha512-J6KFFz5QCYUJq3pf0mjEcCJVERbzv71PUIDczuh9JkwGEzced6CO5ADLHB1rbf/+oPBtoPfMYNOpGDzCANlbXw==", "dev": true, "requires": { "ajv": "^6.12.4", "debug": "^4.1.1", "espree": "^7.3.0", "globals": "^13.9.0", "ignore": "^4.0.6", "import-fresh": "^3.2.1", "js-yaml": "^3.13.1", "minimatch": "^3.0.4", "strip-json-comments": "^3.1.1" } }, "@humanwhocodes/config-array": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.5.0.tgz", "integrity": "sha512-FagtKFz74XrTl7y6HCzQpwDfXP0yhxe9lHLD1UZxjvZIcbyRz8zTFF/yYNfSfzU414eDwZ1SrO0Qvtyf+wFMQg==", "dev": true, "requires": { "@humanwhocodes/object-schema": "^1.2.0", "debug": "^4.1.1", "minimatch": "^3.0.4" } }, "@humanwhocodes/object-schema": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", "dev": true }, "@jridgewell/gen-mapping": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz", "integrity": "sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==", "requires": { "@jridgewell/set-array": "^1.0.1", "@jridgewell/sourcemap-codec": "^1.4.10", "@jridgewell/trace-mapping": "^0.3.9" } }, "@jridgewell/resolve-uri": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==" }, "@jridgewell/set-array": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz", "integrity": "sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==" }, "@jridgewell/source-map": { "version": "0.3.5", "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.5.tgz", "integrity": "sha512-UTYAUj/wviwdsMfzoSJspJxbkH5o1snzwX0//0ENX1u/55kkZZkcTZP6u9bwKGkv+dkk9at4m1Cpt0uY80kcpQ==", "requires": { "@jridgewell/gen-mapping": "^0.3.0", "@jridgewell/trace-mapping": "^0.3.9" } }, "@jridgewell/sourcemap-codec": { "version": "1.4.15", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==" }, "@jridgewell/trace-mapping": { "version": "0.3.18", "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.18.tgz", "integrity": "sha512-w+niJYzMHdd7USdiH2U6869nqhD2nbfZXND5Yp93qIbEmnDNk7PD48o+YchRVpzMU7M6jVCbenTR7PA1FLQ9pA==", "requires": { "@jridgewell/resolve-uri": "3.1.0", "@jridgewell/sourcemap-codec": "1.4.14" }, "dependencies": { "@jridgewell/sourcemap-codec": { "version": "1.4.14", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==" } } }, "@ls-lint/ls-lint": { "version": "1.11.2", "resolved": "https://registry.npmjs.org/@ls-lint/ls-lint/-/ls-lint-1.11.2.tgz", "integrity": "sha512-kX+CCjgNz+NHCaOcFyJLSBLRgAoyOxN18QFLpgucz5ILvbr60BGjwKaoPYTv/rBV/77L+Oz82lpP24mzJ2wGsQ==", "dev": true }, "@ungap/promise-all-settled": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz", "integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==", "dev": true }, "acorn": { "version": "8.10.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.10.0.tgz", "integrity": "sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==" }, "acorn-jsx": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", "dev": true, "requires": {} }, "ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", "dev": true, "requires": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", "json-schema-traverse": "^0.4.1", "uri-js": "^4.2.2" } }, "ansi-colors": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", "integrity": "sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==", "dev": true }, "ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", "dev": true }, "ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", "dev": true, "requires": { "color-convert": "^2.0.1" } }, "anymatch": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", "dev": true, "requires": { "normalize-path": "^3.0.0", "picomatch": "^2.0.4" } }, "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" } }, "astral-regex": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-2.0.0.tgz", "integrity": "sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==", "dev": true }, "astring": { "version": "1.8.5", "resolved": "https://registry.npmjs.org/astring/-/astring-1.8.5.tgz", "integrity": "sha512-TuBbdn7jWVzf8dmFGTaRpW8qgANtWLi1qJLnkfGO5uVf6jf9f/F4B1H35tnOI+qVYZo3p3i8WZlbZOuPAE0wEA==", "dev": true }, "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, "binary-extensions": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", "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" } }, "braces": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", "dev": true, "requires": { "fill-range": "^7.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.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" }, "callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", "dev": true }, "camelcase": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", "dev": true }, "chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", "dev": true, "requires": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" } }, "chokidar": { "version": "3.5.3", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", "dev": true, "requires": { "anymatch": "~3.1.2", "braces": "~3.0.2", "fsevents": "~2.3.2", "glob-parent": "~5.1.2", "is-binary-path": "~2.1.0", "is-glob": "~4.0.1", "normalize-path": "~3.0.0", "readdirp": "~3.6.0" } }, "cliui": { "version": "7.0.4", "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", "dev": true, "requires": { "string-width": "^4.2.0", "strip-ansi": "^6.0.0", "wrap-ansi": "^7.0.0" } }, "color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", "dev": true, "requires": { "color-name": "~1.1.4" } }, "color-name": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, "commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "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-util-is": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", "dev": true }, "cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", "dev": true, "requires": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", "which": "^2.0.1" } }, "debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", "dev": true, "requires": { "ms": "2.1.2" } }, "decamelize": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-4.0.0.tgz", "integrity": "sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==", "dev": true }, "deep-is": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", "dev": true }, "diff": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", "dev": true }, "doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", "dev": true, "requires": { "esutils": "^2.0.2" } }, "emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", "dev": true }, "enquirer": { "version": "2.3.6", "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz", "integrity": "sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==", "dev": true, "requires": { "ansi-colors": "^4.1.1" } }, "escalade": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", "dev": true }, "escape-string-regexp": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", "dev": true }, "eslint": { "version": "7.32.0", "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.32.0.tgz", "integrity": "sha512-VHZ8gX+EDfz+97jGcgyGCyRia/dPOd6Xh9yPv8Bl1+SoaIwD+a/vlrOmGRUyOYu7MwUhc7CxqeaDZU13S4+EpA==", "dev": true, "requires": { "@babel/code-frame": "7.12.11", "@eslint/eslintrc": "^0.4.3", "@humanwhocodes/config-array": "^0.5.0", "ajv": "^6.10.0", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", "debug": "^4.0.1", "doctrine": "^3.0.0", "enquirer": "^2.3.5", "escape-string-regexp": "^4.0.0", "eslint-scope": "^5.1.1", "eslint-utils": "^2.1.0", "eslint-visitor-keys": "^2.0.0", "espree": "^7.3.1", "esquery": "^1.4.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", "file-entry-cache": "^6.0.1", "functional-red-black-tree": "^1.0.1", "glob-parent": "^5.1.2", "globals": "^13.6.0", "ignore": "^4.0.6", "import-fresh": "^3.0.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "js-yaml": "^3.13.1", "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.4.1", "lodash.merge": "^4.6.2", "minimatch": "^3.0.4", "natural-compare": "^1.4.0", "optionator": "^0.9.1", "progress": "^2.0.0", "regexpp": "^3.1.0", "semver": "^7.2.1", "strip-ansi": "^6.0.0", "strip-json-comments": "^3.1.0", "table": "^6.0.9", "text-table": "^0.2.0", "v8-compile-cache": "^2.0.3" } }, "eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", "dev": true, "requires": { "esrecurse": "^4.3.0", "estraverse": "^4.1.1" } }, "eslint-utils": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.1.0.tgz", "integrity": "sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg==", "dev": true, "requires": { "eslint-visitor-keys": "^1.1.0" }, "dependencies": { "eslint-visitor-keys": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz", "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==", "dev": true } } }, "eslint-visitor-keys": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz", "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==", "dev": true }, "eslump": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/eslump/-/eslump-3.0.0.tgz", "integrity": "sha512-TAhAytVHCHMk0yDxCbS881uuAEPfoqdnmp2mkwDgBoM5lVBfoE9nYxq0LCdgJS8NASV8V8NIUF3N4YjhiuuTBg==", "dev": true, "requires": { "@babel/code-frame": "^7.12.13", "mkdirp": "^1.0.4", "optionator": "^0.9.1", "random-int": "^2.0.1", "random-item": "^3.1.0", "shift-codegen": "^7.0.3", "shift-fuzzer": "^2.0.0", "shift-parser": "^7.0.3", "shift-reducer": "^6.0.0" }, "dependencies": { "@babel/code-frame": { "version": "7.21.4", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.21.4.tgz", "integrity": "sha512-LYvhNKfwWSPpocw8GI7gpK2nq3HSDuEPC/uSYaALSJu9xjsalaaYFOq0Pwt5KmVqwEbZlDu81aLXwBOmD/Fv9g==", "dev": true, "requires": { "@babel/highlight": "^7.18.6" } } } }, "esm": { "version": "3.2.25", "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz", "integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==", "dev": true }, "espree": { "version": "7.3.1", "resolved": "https://registry.npmjs.org/espree/-/espree-7.3.1.tgz", "integrity": "sha512-v3JCNCE64umkFpmkFGqzVKsOT0tN1Zr+ueqLZfpV1Ob8e+CEgPWa+OxCoGH3tnhimMKIaBm4m/vaRpJ/krRz2g==", "dev": true, "requires": { "acorn": "^7.4.0", "acorn-jsx": "^5.3.1", "eslint-visitor-keys": "^1.3.0" }, "dependencies": { "acorn": { "version": "7.4.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", "dev": true }, "eslint-visitor-keys": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz", "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==", "dev": true } } }, "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 }, "esquery": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz", "integrity": "sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==", "dev": true, "requires": { "estraverse": "^5.1.0" }, "dependencies": { "estraverse": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", "dev": true } } }, "esrecurse": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", "dev": true, "requires": { "estraverse": "^5.2.0" }, "dependencies": { "estraverse": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", "dev": true } } }, "estraverse": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", "dev": true }, "esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", "dev": true }, "fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, "fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", "dev": true }, "fast-levenshtein": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", "dev": true }, "file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", "integrity": "sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==", "dev": true, "requires": { "flat-cache": "^3.0.4" } }, "fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", "dev": true, "requires": { "to-regex-range": "^5.0.1" } }, "find-up": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", "dev": true, "requires": { "locate-path": "^6.0.0", "path-exists": "^4.0.0" } }, "flat": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", "dev": true }, "flat-cache": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz", "integrity": "sha512-dm9s5Pw7Jc0GvMYbshN6zchCA9RgQlzzEZX3vylR9IqFfS8XciblUXOKfW6SiuJ0e13eDYZoZV5wdrev7P3Nwg==", "dev": true, "requires": { "flatted": "^3.1.0", "rimraf": "^3.0.2" } }, "flatted": { "version": "3.2.7", "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.7.tgz", "integrity": "sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==", "dev": true }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "dev": true }, "fsevents": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", "dev": true, "optional": 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": "sha512-dsKNQNdj6xA3T+QlADDA7mOSlX0qiMINjn0cgr+eGHGsbSHzTabcIogz2+p/iqP1Xs6EP/sS2SbqH+brGTbq0g==", "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 }, "glob": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", "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" } }, "glob-parent": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", "dev": true, "requires": { "is-glob": "^4.0.1" } }, "globals": { "version": "13.20.0", "resolved": "https://registry.npmjs.org/globals/-/globals-13.20.0.tgz", "integrity": "sha512-Qg5QtVkCy/kv3FUSlu4ukeZDVf9ee0iXLAUYX13gbR17bnejFTzr4iS9bY7kwCf1NztRNm1t91fjOiyx4CSwPQ==", "dev": true, "requires": { "type-fest": "^0.20.2" } }, "growl": { "version": "1.10.5", "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", "dev": true }, "has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", "dev": true }, "he": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", "dev": true }, "ignore": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", "dev": true }, "import-fresh": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", "dev": true, "requires": { "parent-module": "^1.0.0", "resolve-from": "^4.0.0" } }, "imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", "dev": true }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", "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 }, "is-binary-path": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", "dev": true, "requires": { "binary-extensions": "^2.0.0" } }, "is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", "dev": true }, "is-fullwidth-code-point": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", "dev": true }, "is-glob": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", "dev": true, "requires": { "is-extglob": "^2.1.1" } }, "is-number": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", "dev": true }, "is-plain-obj": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", "dev": true }, "is-unicode-supported": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", "integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==", "dev": true }, "isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", "dev": true }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true }, "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 }, "js-yaml": { "version": "3.14.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", "dev": true, "requires": { "argparse": "^1.0.7", "esprima": "^4.0.0" } }, "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", "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": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", "dev": true }, "levn": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", "dev": true, "requires": { "prelude-ls": "^1.2.1", "type-check": "~0.4.0" } }, "locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", "dev": true, "requires": { "p-locate": "^5.0.0" } }, "lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", "dev": true }, "lodash.sortby": { "version": "4.7.0", "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", "integrity": "sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==", "dev": true }, "lodash.truncate": { "version": "4.4.2", "resolved": "https://registry.npmjs.org/lodash.truncate/-/lodash.truncate-4.4.2.tgz", "integrity": "sha512-jttmRe7bRse52OsWIMDLaXxWqRAmtIUccAQ3garviCqJjafXOfNMO0yMfNpdD6zbGaTU0P5Nz7e7gAT6cKmJRw==", "dev": true }, "log-symbols": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", "dev": true, "requires": { "chalk": "^4.1.0", "is-unicode-supported": "^0.1.0" } }, "lru-cache": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", "dev": true, "requires": { "yallist": "^4.0.0" } }, "minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "dev": true, "requires": { "brace-expansion": "^1.1.7" } }, "mkdirp": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", "dev": true }, "mocha": { "version": "9.2.2", "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.2.2.tgz", "integrity": "sha512-L6XC3EdwT6YrIk0yXpavvLkn8h+EU+Y5UcCHKECyMbdUIxyMuZj4bX4U9e1nvnvUUvQVsV2VHQr5zLdcUkhW/g==", "dev": true, "requires": { "@ungap/promise-all-settled": "1.1.2", "ansi-colors": "4.1.1", "browser-stdout": "1.3.1", "chokidar": "3.5.3", "debug": "4.3.3", "diff": "5.0.0", "escape-string-regexp": "4.0.0", "find-up": "5.0.0", "glob": "7.2.0", "growl": "1.10.5", "he": "1.2.0", "js-yaml": "4.1.0", "log-symbols": "4.1.0", "minimatch": "4.2.1", "ms": "2.1.3", "nanoid": "3.3.1", "serialize-javascript": "6.0.0", "strip-json-comments": "3.1.1", "supports-color": "8.1.1", "which": "2.0.2", "workerpool": "6.2.0", "yargs": "16.2.0", "yargs-parser": "20.2.4", "yargs-unparser": "2.0.0" }, "dependencies": { "ansi-colors": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", "dev": true }, "argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", "dev": true }, "debug": { "version": "4.3.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz", "integrity": "sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==", "dev": true, "requires": { "ms": "2.1.2" }, "dependencies": { "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 } } }, "js-yaml": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", "dev": true, "requires": { "argparse": "^2.0.1" } }, "minimatch": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-4.2.1.tgz", "integrity": "sha512-9Uq1ChtSZO+Mxa/CL1eGizn2vRn3MlLgzhT0Iz8zaY8NdvxvB0d5QdPFmCKf7JKA9Lerx5vRrnwO03jsSfGG9g==", "dev": true, "requires": { "brace-expansion": "^1.1.7" } }, "ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "dev": true }, "supports-color": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", "dev": true, "requires": { "has-flag": "^4.0.0" } } } }, "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 }, "multimap": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/multimap/-/multimap-1.1.0.tgz", "integrity": "sha512-0ZIR9PasPxGXmRsEF8jsDzndzHDj7tIav+JUmvIFB/WHswliFnquxECT/De7GR4yg99ky/NlRKJT82G1y271bw==", "dev": true }, "nanoid": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.1.tgz", "integrity": "sha512-n6Vs/3KGyxPQd6uO0eH4Bv0ojGSUvuLlIHtC3Y0kEO23YRge8H9x1GCzLn28YX0H66pMkxuaeESFq4tKISKwdw==", "dev": true }, "natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", "dev": true }, "normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", "dev": true }, "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", "dev": true }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", "dev": true, "requires": { "wrappy": "1" } }, "optionator": { "version": "0.9.3", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.3.tgz", "integrity": "sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==", "dev": true, "requires": { "@aashutoshrathi/word-wrap": "^1.2.3", "deep-is": "^0.1.3", "fast-levenshtein": "^2.0.6", "levn": "^0.4.1", "prelude-ls": "^1.2.1", "type-check": "^0.4.0" } }, "os-shim": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/os-shim/-/os-shim-0.1.3.tgz", "integrity": "sha512-jd0cvB8qQ5uVt0lvCIexBaROw1KyKm5sbulg2fWOHjETisuCzWyt+eTZKEMs8v6HwzoGs8xik26jg7eCM6pS+A==", "dev": true }, "p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", "dev": true, "requires": { "yocto-queue": "^0.1.0" } }, "p-locate": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", "dev": true, "requires": { "p-limit": "^3.0.2" } }, "parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", "dev": true, "requires": { "callsites": "^3.0.0" } }, "path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", "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": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", "dev": true }, "path-key": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", "dev": true }, "picomatch": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", "dev": true }, "pre-commit": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/pre-commit/-/pre-commit-1.2.2.tgz", "integrity": "sha512-qokTiqxD6GjODy5ETAIgzsRgnBWWQHQH2ghy86PU7mIn/wuWeTwF3otyNQZxWBwVn8XNr8Tdzj/QfUXpH+gRZA==", "dev": true, "requires": { "cross-spawn": "^5.0.1", "spawn-sync": "^1.0.15", "which": "1.2.x" }, "dependencies": { "cross-spawn": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", "integrity": "sha512-pTgQJ5KC0d2hcY8eyL1IzlBPYjTkyH72XRZPnLyKus2mBfNjQs3klqbJU2VILqZryAZUt9JOb3h/mWMy23/f5A==", "dev": true, "requires": { "lru-cache": "^4.0.1", "shebang-command": "^1.2.0", "which": "^1.2.9" } }, "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" } }, "shebang-command": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", "integrity": "sha512-EV3L1+UQWGor21OmnvojK36mhg+TyIKDh3iFBKBohr5xeXIhNBcx8oWdgkTEEQ+BEFFYdLRuqMfd5L84N1V5Vg==", "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": "sha512-wpoSFAxys6b2a2wHZ1XpDSgD7N9iVjg29Ph9uV/uaP9Ex/KXlkTZTeddxDPSYQpgvzKLGJke2UU0AzoGCjNIvQ==", "dev": true }, "which": { "version": "1.2.14", "resolved": "https://registry.npmjs.org/which/-/which-1.2.14.tgz", "integrity": "sha512-16uPglFkRPzgiUXYMi1Jf8Z5EzN1iB4V0ZtMXcHZnwsBtQhhHeCqoWw7tsUY42hJGNDWtUsVLTjakIa5BgAxCw==", "dev": true, "requires": { "isexe": "^2.0.0" } }, "yallist": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", "integrity": "sha512-ncTzHV7NvsQZkYe1DW7cbDLm0YpzHmZF5r/iyP3ZnQtMiJ+pjzisCiMNI+Sj+xQF5pXhSHxSB3uDbsBTzY/c2A==", "dev": true } } }, "prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "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": "sha512-b/YwNhb8lk1Zz2+bXXpS/LK9OisiZZ1SNsSLxN1x2OXVEhW2Ckr/7mWE5vrC1ZTiJlD9g19jWszTmJsB+oEpFQ==", "dev": true }, "punycode": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==", "dev": true }, "random-int": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/random-int/-/random-int-2.0.1.tgz", "integrity": "sha512-YALjWK2Rt9EMIv9BF/3mvlzFWQathsvb5UZmN1QmhfIOfcQYXc/UcLzg0ablqesSBpBVLt2Tlwv/eTuBh4LXUQ==", "dev": true }, "random-item": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/random-item/-/random-item-3.1.0.tgz", "integrity": "sha512-0DyAT8LYBNQKSkqcPjia/HNoWCZ5JWBdAQWjBQVh5DMVv3Fv7V90I8/AuUf8NW4zdFn27i9qj8Kp6wI5JsiiOA==", "dev": true }, "randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", "dev": true, "requires": { "safe-buffer": "^5.1.0" } }, "readable-stream": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", "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" }, "dependencies": { "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 } } }, "readdirp": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", "dev": true, "requires": { "picomatch": "^2.2.1" } }, "regexpp": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz", "integrity": "sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==", "dev": true }, "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", "dev": true }, "require-from-string": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", "dev": true }, "resolve-from": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", "dev": true }, "rimraf": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", "dev": true, "requires": { "glob": "^7.1.3" } }, "rollup": { "version": "2.79.1", "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.1.tgz", "integrity": "sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==", "dev": true, "requires": { "fsevents": "~2.3.2" } }, "safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", "dev": true }, "semver": { "version": "7.5.4", "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dev": true, "requires": { "lru-cache": "^6.0.0" } }, "serialize-javascript": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz", "integrity": "sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==", "dev": true, "requires": { "randombytes": "^2.1.0" } }, "shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", "dev": true, "requires": { "shebang-regex": "^3.0.0" } }, "shebang-regex": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", "dev": true }, "shift-ast": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/shift-ast/-/shift-ast-6.1.0.tgz", "integrity": "sha512-Vj4XUIJIFPIh6VcBGJ1hjH/kM88XGer94Pr7Rvxa+idEylDsrwtLw268HoxGo5xReL6T3DdRl/9/Pr1XihZ/8Q==", "dev": true }, "shift-codegen": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/shift-codegen/-/shift-codegen-7.0.3.tgz", "integrity": "sha512-dfCVVdBF0qZ6pkajQ3bjxRdNEltyxEITVe7tBJkQt2eCI3znUkSxq0VSe/tTWq1LKHeAS4HuOiqYEuHMFkSq9w==", "dev": true, "requires": { "esutils": "^2.0.2", "object-assign": "^4.1.0", "shift-reducer": "6.0.0" } }, "shift-fuzzer": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shift-fuzzer/-/shift-fuzzer-2.0.0.tgz", "integrity": "sha512-hgV4jqXELYR0UpEDlTnYcv0GXvhXV/y3lyYNyGtTq1Q6EdFIC9LLHjlrfVFt7d1VyzJqPkl/fME31ta0KrHiTQ==", "dev": true, "requires": { "shift-ast": "6.1.0" } }, "shift-parser": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/shift-parser/-/shift-parser-7.0.3.tgz", "integrity": "sha512-uYX2ORyZfKZrUc4iKKkO9KOhzUSxCrSBk7QK6ZmShId+BOo1gh1IwecVy97ynyOTpmhPWUttjC8BzsnQl65Zew==", "dev": true, "requires": { "multimap": "^1.0.2", "shift-ast": "6.0.0", "shift-reducer": "6.0.0", "shift-regexp-acceptor": "2.0.3" }, "dependencies": { "shift-ast": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/shift-ast/-/shift-ast-6.0.0.tgz", "integrity": "sha512-XXxDcEBWVBzqWXfNYJlLyJ1/9kMvOXVRXiqPjkOrTCC5qRsBvEMJMRLLFhU3tn8ue56Y7IZyBE6bexFum5QLUw==", "dev": true } } }, "shift-reducer": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/shift-reducer/-/shift-reducer-6.0.0.tgz", "integrity": "sha512-2rJraRP8drIOjvaE/sALa+0tGJmMVUzlmS3wIJerJbaYuCjpFAiF0WjkTOFVtz1144Nm/ECmqeG+7yRhuMVsMg==", "dev": true, "requires": { "shift-ast": "6.0.0" }, "dependencies": { "shift-ast": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/shift-ast/-/shift-ast-6.0.0.tgz", "integrity": "sha512-XXxDcEBWVBzqWXfNYJlLyJ1/9kMvOXVRXiqPjkOrTCC5qRsBvEMJMRLLFhU3tn8ue56Y7IZyBE6bexFum5QLUw==", "dev": true } } }, "shift-regexp-acceptor": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/shift-regexp-acceptor/-/shift-regexp-acceptor-2.0.3.tgz", "integrity": "sha512-sxL7e5JNUFxm+gutFRXktX2D6KVgDAHNuDsk5XHB9Z+N5yXooZG6pdZ1GEbo3Jz6lF7ETYLBC4WAjIFm2RKTmA==", "dev": true, "requires": { "unicode-match-property-ecmascript": "1.0.4", "unicode-match-property-value-ecmascript": "1.0.2", "unicode-property-aliases-ecmascript": "1.0.4" } }, "slice-ansi": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-4.0.0.tgz", "integrity": "sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==", "dev": true, "requires": { "ansi-styles": "^4.0.0", "astral-regex": "^2.0.0", "is-fullwidth-code-point": "^3.0.0" } }, "source-map": { "version": "0.8.0-beta.0", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.8.0-beta.0.tgz", "integrity": "sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==", "dev": true, "requires": { "whatwg-url": "^7.0.0" } }, "source-map-support": { "version": "0.5.21", "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", "requires": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" }, "dependencies": { "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" } } }, "spawn-sync": { "version": "1.0.15", "resolved": "https://registry.npmjs.org/spawn-sync/-/spawn-sync-1.0.15.tgz", "integrity": "sha512-9DWBgrgYZzNghseho0JOuh+5fg9u6QWhAWa51QC7+U5rCheZ/j1DrEZnyE0RBBRqZ9uEXGPgSSM0nky6burpVw==", "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": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==", "dev": true }, "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" }, "dependencies": { "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 } } }, "string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", "dev": true, "requires": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", "strip-ansi": "^6.0.1" } }, "strip-ansi": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", "dev": true, "requires": { "ansi-regex": "^5.0.1" } }, "strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", "dev": true }, "supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", "dev": true, "requires": { "has-flag": "^4.0.0" } }, "table": { "version": "6.8.1", "resolved": "https://registry.npmjs.org/table/-/table-6.8.1.tgz", "integrity": "sha512-Y4X9zqrCftUhMeH2EptSSERdVKt/nEdijTOacGD/97EKjhQ/Qs8RTlEGABSJNNN8lac9kheH+af7yAkEWlgneA==", "dev": true, "requires": { "ajv": "^8.0.1", "lodash.truncate": "^4.4.2", "slice-ansi": "^4.0.0", "string-width": "^4.2.3", "strip-ansi": "^6.0.1" }, "dependencies": { "ajv": { "version": "8.12.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz", "integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==", "dev": true, "requires": { "fast-deep-equal": "^3.1.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2", "uri-js": "^4.2.2" } }, "json-schema-traverse": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", "dev": true } } }, "text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", "dev": true }, "to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", "dev": true, "requires": { "is-number": "^7.0.0" } }, "tr46": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/tr46/-/tr46-1.0.1.tgz", "integrity": "sha512-dTpowEjclQ7Kgx5SdBkqRzVhERQXov8/l9Ft9dVM9fmg0W0KQSVaXX9T4i6twCPNtYiZM53lpSSUAwJbFPOHxA==", "dev": true, "requires": { "punycode": "^2.1.0" } }, "type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", "dev": true, "requires": { "prelude-ls": "^1.2.1" } }, "type-fest": { "version": "0.20.2", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", "dev": true }, "typedarray": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==", "dev": true }, "unicode-canonical-property-names-ecmascript": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz", "integrity": "sha512-jDrNnXWHd4oHiTZnx/ZG7gtUTVp+gCcTTKr8L0HjlwphROEW3+Him+IpvC+xcJEFegapiMZyZe02CyuOnRmbnQ==", "dev": true }, "unicode-match-property-ecmascript": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/unicode-match-property-ecmascript/-/unicode-match-property-ecmascript-1.0.4.tgz", "integrity": "sha512-L4Qoh15vTfntsn4P1zqnHulG0LdXgjSO035fEpdtp6YxXhMT51Q6vgM5lYdG/5X3MjS+k/Y9Xw4SFCY9IkR0rg==", "dev": true, "requires": { "unicode-canonical-property-names-ecmascript": "^1.0.4", "unicode-property-aliases-ecmascript": "^1.0.4" } }, "unicode-match-property-value-ecmascript": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unicode-match-property-value-ecmascript/-/unicode-match-property-value-ecmascript-1.0.2.tgz", "integrity": "sha512-Rx7yODZC1L/T8XKo/2kNzVAQaRE88AaMvI1EF/Xnj3GW2wzN6fop9DDWuFAKUVFH7vozkz26DzP0qyWLKLIVPQ==", "dev": true }, "unicode-property-aliases-ecmascript": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-1.0.4.tgz", "integrity": "sha512-2WSLa6OdYd2ng8oqiGIWnJqyFArvhn+5vgx5GTxMbUYjCYKUcuKS62YLFF0R/BDGlB1yzXjQOLtPAfHsgirEpg==", "dev": true }, "uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", "dev": true, "requires": { "punycode": "^2.1.0" } }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "dev": true }, "v8-compile-cache": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", "integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==", "dev": true }, "webidl-conversions": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz", "integrity": "sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==", "dev": true }, "whatwg-url": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-7.1.0.tgz", "integrity": "sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==", "dev": true, "requires": { "lodash.sortby": "^4.7.0", "tr46": "^1.0.1", "webidl-conversions": "^4.0.2" } }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", "dev": true, "requires": { "isexe": "^2.0.0" } }, "workerpool": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.2.0.tgz", "integrity": "sha512-Rsk5qQHJ9eowMH28Jwhe8HEbmdYDX4lwoMWshiCXugjtHqMD9ZbiqSDLxcsfdqsETPzVUtX5s1Z5kStiIM6l4A==", "dev": true }, "wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", "dev": true, "requires": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", "strip-ansi": "^6.0.0" } }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", "dev": true }, "y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", "dev": true }, "yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", "dev": true }, "yargs": { "version": "16.2.0", "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", "dev": true, "requires": { "cliui": "^7.0.2", "escalade": "^3.1.1", "get-caller-file": "^2.0.5", "require-directory": "^2.1.1", "string-width": "^4.2.0", "y18n": "^5.0.5", "yargs-parser": "^20.2.2" } }, "yargs-parser": { "version": "20.2.4", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.4.tgz", "integrity": "sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==", "dev": true }, "yargs-unparser": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-2.0.0.tgz", "integrity": "sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA==", "dev": true, "requires": { "camelcase": "^6.0.0", "decamelize": "^4.0.0", "flat": "^5.0.2", "is-plain-obj": "^2.1.0" } }, "yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", "dev": true } } } terser-5.19.2/package.json000066400000000000000000000062161445647217600154270ustar00rootroot00000000000000{ "name": "terser", "description": "JavaScript parser, mangler/compressor and beautifier toolkit for ES6+", "homepage": "https://terser.org", "author": "Mihai Bazon (http://lisperator.net/)", "license": "BSD-2-Clause", "version": "5.19.2", "engines": { "node": ">=10" }, "maintainers": [ "Fábio Santos " ], "repository": "https://github.com/terser/terser", "main": "dist/bundle.min.js", "type": "module", "module": "./main.js", "exports": { ".": [ { "types": "./tools/terser.d.ts", "import": "./main.js", "require": "./dist/bundle.min.js" }, "./dist/bundle.min.js" ], "./package": "./package.json", "./package.json": "./package.json", "./bin/terser": "./bin/terser" }, "types": "tools/terser.d.ts", "bin": { "terser": "bin/terser" }, "files": [ "bin", "dist", "lib", "tools", "LICENSE", "README.md", "CHANGELOG.md", "PATRONS.md", "main.js" ], "dependencies": { "@jridgewell/source-map": "^0.3.3", "acorn": "^8.8.2", "commander": "^2.20.0", "source-map-support": "~0.5.20" }, "devDependencies": { "@ls-lint/ls-lint": "^1.11.2", "astring": "^1.8.5", "eslint": "^7.32.0", "eslump": "^3.0.0", "esm": "^3.2.25", "mocha": "^9.2.0", "pre-commit": "^1.2.2", "rollup": "^2.56.3", "semver": "^7.5.1", "source-map": "~0.8.0-beta.0" }, "scripts": { "test": "node test/compress.js && mocha test/mocha", "test:compress": "node test/compress.js", "test:mocha": "mocha test/mocha", "lint": "eslint lib", "lint-fix": "eslint --fix lib", "ls-lint": "ls-lint", "build": "rollup --config --silent", "prepare": "npm run build", "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", "ecmaVersion": 2020 }, "env": { "node": true, "browser": true, "es2020": true }, "globals": { "describe": false, "it": false, "require": false, "before": false, "after": false, "global": false, "process": false }, "rules": { "brace-style": [ "error", "1tbs", { "allowSingleLine": true } ], "quotes": [ "error", "double", "avoid-escape" ], "no-debugger": "error", "no-undef": "error", "no-unused-vars": [ "error", { "varsIgnorePattern": "^_" } ], "no-tabs": "error", "semi": [ "error", "always" ], "no-extra-semi": "error", "no-irregular-whitespace": "error", "space-before-blocks": [ "error", "always" ] } }, "pre-commit": [ "build", "lint-fix", "ls-lint", "test" ] } terser-5.19.2/renovate.json000066400000000000000000000003421445647217600156510ustar00rootroot00000000000000{ "extends": [ "config:base" ], "packageRules": [ { "depTypeList": ["dependencies"], "updateTypes": ["major"] }, { "depTypeList": ["devDependencies"], "enabled": false } ] } terser-5.19.2/rollup.config.js000066400000000000000000000007011445647217600162510ustar00rootroot00000000000000export default () => { return { input: "main.js", output: { file: "dist/bundle.min.js", format: "umd", globals: { "@jridgewell/source-map": "sourceMap", }, name: "Terser", sourcemap: false, sourcemapExcludeSources: true, esModule: false, indent: false }, external: "source-map", }; }; terser-5.19.2/test/000077500000000000000000000000001445647217600141135ustar00rootroot00000000000000terser-5.19.2/test/benchmark.cjs000066400000000000000000000053351445647217600165540ustar00rootroot00000000000000#! /usr/bin/env node // -*- js -*- "use strict"; var createHash = require("crypto").createHash; var fork = require("child_process").fork; var zlib = require("zlib"); var fetch = require("./fetch.cjs"); 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 terser = fork("bin/terser", args, { silent: true }); res.on("data", function(data) { results[url].input += data.length; }).pipe(terser.stdin); terser.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(); }); terser.stderr.setEncoding("utf8"); terser.stderr.on("data", function(data) { results[url].log += data; }); terser.on("exit", function(code) { results[url].code = code; done(); }); }); }); terser-5.19.2/test/benchmark.js000066400000000000000000000053071445647217600164100ustar00rootroot00000000000000#! /usr/bin/env node // -*- js -*- "use strict"; import { createHash } from "crypto"; import fetch from "./fetch.cjs"; import { fork } from "child_process"; import zlib from "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 terser = fork("bin/terser", args, { silent: true }); res.on("data", function(data) { results[url].input += data.length; }).pipe(terser.stdin); terser.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(); }); terser.stderr.setEncoding("utf8"); terser.stderr.on("data", function(data) { results[url].log += data; }); terser.on("exit", function(code) { results[url].code = code; done(); }); }); }); terser-5.19.2/test/colorless-console.js000066400000000000000000000002431445647217600201150ustar00rootroot00000000000000"use strict" import { Console } from "console"; global.console = new Console({ stdout: process.stdout, stderr: process.stderr, colorMode: false }); terser-5.19.2/test/compress.js000066400000000000000000000537621445647217600163210ustar00rootroot00000000000000/* globals module, __dirname, console */ import "source-map-support/register.js"; import path from "path"; import fs from "fs"; import assert from "assert"; import semver from "semver"; import { fileURLToPath } from "url"; import { minify } from "../main.js"; import * as AST from "../lib/ast.js"; import { parse } from "../lib/parse.js"; import { OutputStream } from "../lib/output.js"; import { Compressor } from "../lib/compress/index.js"; import { reserve_quoted_keys, mangle_properties, mangle_private_properties, } from "../lib/propmangle.js"; import { base54 } from "../lib/scope.js"; import { string_template, defaults } from "../lib/utils/index.js"; import * as sandbox from "./sandbox.js" const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); var tests_dir = __dirname; var failed_files = {}; var minify_options = JSON.parse(fs.readFileSync(path.join(__dirname, "ufuzz.json"), 'utf-8')).map(JSON.stringify); const already_logged = new Set() run_compress_tests().catch(e => { console.error(e); process.exit(1); }); /* -----[ utils ]----- */ function HOP(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } function tmpl() { return string_template.apply(this, arguments); } function log(test, ...args) { if (test) log_test(test); var txt = tmpl.apply(this, args); console.log("%s", txt); } function log_directory(dir) { log(null, "*** Entering [{dir}]", { dir: dir }); } function log_test(test) { if (already_logged.has(test)) return already_logged.add(test) log(null, "--- Running test [{name}]", { name: test.name }); log(null, " {file}", { file: test.file }); } 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 AST.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 AST.AST_SimpleStatement && stat.body instanceof AST.AST_String) input.body[i] = new AST.AST_Directive(stat.body); else break; } var toplevel = new AST.AST_Toplevel(input); toplevel.figure_out_scope(mangle_options); return toplevel; } async function run_compress_tests() { var test_failures = 0; var test_cases = 0; const enable_js_sandbox = !process.env.TEST_NO_SANDBOX && semver.satisfies(process.version, ">=16") var dir = test_directory("compress"); log_directory("test/compress"); var files = find_test_files(dir); async function test_file(file) { async function test_case(test) { var output_options = test.beautify || test.format || {}; 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, "!!! Test cannot have an `expect_error` with other expect clauses\n", {}); return false; } if (test.input instanceof AST.AST_SimpleStatement && test.input.body instanceof AST.AST_TemplateString) { if (test.input.body.segments.length == 1) { try { var input = parse(test.input.body.segments[0].value); } catch (ex) { if (!test.expect_error) { log(test, "!!! Test is missing an `expect_error` clause\n", {}); return false; } if (test.expect_error instanceof AST.AST_SimpleStatement && test.expect_error.body instanceof AST.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(test, "!!! 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, "!!! 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, "!!! 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, "!!! 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, { ecma: 2015, beautify: true, quote_style: 3, keep_quoted_props: true }); } try { parse(input_code); } catch (ex) { log(test, "!!! Cannot parse input\n---INPUT---\n{input}\n--PARSE ERROR--\n{error}\n\n", { input: input_formatted, error: ex, }); return false; } if (!test.no_mozilla_ast) { try { var ast = input.to_mozilla_ast(); var mozilla_options = { ecma: output_options.ecma, ascii_only: output_options.ascii_only, comments: false, }; var ast_as_string = AST.AST_Node.from_mozilla_ast(ast).print_to_string(mozilla_options); var input_string = input.print_to_string(mozilla_options); if (input_string !== ast_as_string) { log(test, "!!! 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; } } catch (moz_ast_error) { log(test, "!!! Mozilla AST I/O crashed\n---INPUT---\n{input}", { input: input_formatted, }); console.error(moz_ast_error); return false; } } var options = defaults(test.options, { }); 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") { reserve_quoted_keys(input, quoted_props); } } if (test.rename) { input.figure_out_scope(test.mangle); input.expand_names(test.mangle); } var cmp = new Compressor(options, { false_by_default: options.defaults === undefined ? true : !options.defaults, mangle_options: test.mangle }); var output = cmp.compress(input); output.figure_out_scope(test.mangle); if (test.mangle) { 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); mangle_private_properties(output, test.mangle); if (test.mangle.properties) { output = 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 && !process.env.TEST_NO_COMPARE) { log(test, "!!! 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 { parse(output); } catch (ex) { log(test, "!!! 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_stdout && (!test.node_version || semver.satisfies(process.version, test.node_version)) && enable_js_sandbox ) { var stdout = sandbox.run_code(input_code, test.prepend_code); if (test.expect_stdout === true) { test.expect_stdout = stdout; } if (!sandbox.same_stdout(test.expect_stdout, stdout)) { log(test, "!!! 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, test.prepend_code); if (!sandbox.same_stdout(test.expect_stdout, stdout)) { log(test, "!!! 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 && !await reminify(test, input_code, input_formatted)) { return false; } } return true; } var tests = parse_test(path.resolve(dir, file)); let { GREP } = process.env; for (var i in tests) if (tests.hasOwnProperty(i)) { if (GREP && !i.includes(GREP)) continue; test_cases++; if (!await test_case(tests[i])) { test_failures++; failed_files[file] = 1; if (process.env.TEST_FAIL_FAST) return false; } } return true; } for (const file of files) { if (!await test_file(file)) { break; } } if (test_failures) { console.error("\n!!! Failed " + test_failures + " test cases."); console.error("!!! " + Object.keys(failed_files).join(", ")); process.exit(1); } else { console.log("\nPassed " + test_cases + " test cases."); } } 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 = 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 AST.TreeWalker(function(node, descend) { if ( node instanceof AST.AST_LabeledStatement && tw.parent() instanceof AST.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(file, name, node.body); return true; } if (node instanceof AST.AST_Directive) return true; if (!(node instanceof AST.AST_Toplevel)) croak(node); }); ast.walk(tw); const only_tests = Object.entries(tests).filter(([_name, test]) => test.only); return only_tests.length > 0 ? Object.fromEntries(only_tests) : 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 AST.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(file, name, block) { var test = { file: file.replace(/.+\/(test\/compress\/\w+\.js)/, "$1") + ':' + block.start.line, name: name, options: {}, reminify: true, only: false }; var tw = new AST.TreeWalker(function(node, descend) { if (node instanceof AST.AST_Assign) { if (!(node.left instanceof AST.AST_SymbolRef)) { croak(node); } var name = node.left.name; test[name] = evaluate(node.right); return true; } if (node instanceof AST.AST_LabeledStatement) { var label = node.label; assert.ok( [ "input", "prepend_code", "expect", "expect_error", "expect_exact", "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 AST.AST_Boolean) { test[label.name] = body.value; } else if (body instanceof AST.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 AST.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 if (label.name === "prepend_code") { test[label.name] = read_string(stat); } else { test[label.name] = stat; } return true; } }); block.walk(tw); return test; } } function make_code(ast, options) { var stream = OutputStream(options); ast.print(stream); return stream.get(); } function evaluate(code) { if (code instanceof AST.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. async function reminify(test, input_code, input_formatted) { if (process.env.TEST_NO_REMINIFY) return true; const { options: orig_options, expect_stdout } = test; 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 = await minify(input_code, options); if (result.error) { log(test, "!!! failed input reminify\n---INPUT---\n{input}\n--ERROR---\n{error}\n\n", { input: input_formatted, error: result.error.stack, }); return false; } else if (!process.env.TEST_NO_SANDBOX) { var stdout = sandbox.run_code(result.code, test.prepend_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(test, "!!! 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-5.19.2/test/compress/000077500000000000000000000000001445647217600157465ustar00rootroot00000000000000terser-5.19.2/test/compress/.eslintrc000066400000000000000000000005541445647217600175760ustar00rootroot00000000000000{ "globals": { "options": true, "mangle": true, "rename": true, "beautify": true, "mozilla_ast": true, "console": false, "window": false, "global": false, "pass": false, "fail": false, "leak": false, "id": false }, "rules": { "semi": "off" } } terser-5.19.2/test/compress/arguments.js000066400000000000000000000227521445647217600203210ustar00rootroot00000000000000replace_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" } issue_687: { options = { defaults: true, toplevel: true } input: { function shouldBePure() { return arguments.length } shouldBePure(); } expect: { // *Poof!* } } terser-5.19.2/test/compress/array-constructor.js000066400000000000000000000023531445647217600220100ustar00rootroot00000000000000array_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-5.19.2/test/compress/arrays.js000066400000000000000000000214271445647217600176130ustar00rootroot00000000000000// 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" } array_from: { options = { unsafe: true, unused: true, } input: { var a = Array.from([1]); var b = Array.from([1], a => a); var c = Array.from(1); var d = Array.from("String"); var e = Array.from({ }); console.log(a[0], b[0], c, d[3], e); } expect: { var a = [1]; var b = Array.from([1], a => a); var c = Array.from(1); var d = Array.from("String"); var e = Array.from({}); console.log(a[0], b[0], c, d[3], e); } expect_stdout: "1 1 [] i []" } terser-5.19.2/test/compress/arrow.js000066400000000000000000000370521445647217600174450ustar00rootroot00000000000000arrow_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: 2015, } 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: 2015, 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: 2015, 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: 2015, 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: 2015, 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: 2015, 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: 2015, 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: 2015, 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: 2015, 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: 2015, 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: 2015, 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: 2015, 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" } object_parens: { input: { () => ({}); () => {return {}}; () => {return {}[0]}; () => {return {}?1:0}; () => {return ({}, 1)}; () => {return (1, 2)}; () => {foo()}; } expect_exact: "()=>({});()=>({});()=>({}[0]);()=>({}?1:0);()=>(({},1));()=>(1,2);()=>{foo()};" } terser-5.19.2/test/compress/ascii.js000066400000000000000000000057771445647217600174140ustar00rootroot00000000000000ascii_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_true_identifier_es5: { options = {} beautify = { ecma : 5, ascii_only : true, ie8 : false, beautify : false, } input: { function f() { var o = { 𝒜: true }; return o.𝒜; } } expect_exact: 'function f(){var o={"\\ud835\\udc9c":true};return o["\\ud835\\udc9c"]}' } ascii_only_true_identifier_es2015: { options = {} beautify = { ecma : 2015, ascii_only : true, ie8 : false, beautify : false, } input: { function f() { var o = { 𝒜: true }; return o.𝒜; } } expect_exact: "function f(){var o={\\u{1d49c}:true};return o.\\u{1d49c}}" } 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\'}' } ascii_only_false_identifier_es5: { options = {} beautify = { ecma : 5, ascii_only : false, ie8 : false, beautify : false, } input: { function f() { var o = { 𝒜: true }; return o.𝒜; } } expect_exact: 'function f(){var o={"𝒜":true};return o["𝒜"]}' } ascii_only_false_identifier_es2015: { options = {} beautify = { ecma : 2015, ascii_only : false, ie8 : false, beautify : false, } input: { function f() { var o = { 𝒜: true }; return o.𝒜; } } expect_exact: "function f(){var o={𝒜:true};return o.𝒜}" } terser-5.19.2/test/compress/asm.js000066400000000000000000000116771445647217600171000ustar00rootroot00000000000000asm_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, lhs_constants: true, 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-5.19.2/test/compress/assignment.js000066400000000000000000000107261445647217600204620ustar00rootroot00000000000000op_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; } } spurious_assignment: { options = {} input: { var x = "PASS"; x = x; console.log(x); } expect: { var x = "PASS"; x; console.log(x); } expect_stdout: "PASS" } terser-5.19.2/test/compress/async.js000066400000000000000000000253141445647217600174260ustar00rootroot00000000000000await_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 invoke(x, y) { return x(y); } invoke( async function(){ return await 1; } ); invoke( 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 invoke(x, y){return x(y)} invoke(async function(){return await 1}); invoke(async function(x){await console.log(x)}, 2); console.log("top"); !async function(){console.log("async_top")}(); } expect_stdout: [ "4", "2", "top", "async_top", ] } 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-5.19.2/test/compress/big_int.js000066400000000000000000000022601445647217600177170ustar00rootroot00000000000000big_int_positive: { input: { 1000n } expect_exact: "1000n;" } big_int_negative: { input: { -15n } expect_exact: "-15n;" } big_int_hex: { input: { 0x20n 0xfabn } expect_exact: "0x20n;0xfabn;" } regression_big_int_hex_lower_with_e: { input: { 0xaefen; } expect_exact: "0xaefen;" } big_int_binary: { input: { 0b101n } expect_exact: "0b101n;" } big_int_octal: { input: { 0o7n } expect_exact: "0o7n;" } big_int_no_e: { input: `1e3n` expect_error: ({ name: "SyntaxError", message: "Invalid or unexpected token" }) } big_int_bad_digits_for_base: { input: `0o9n` expect_error: ({ name: "SyntaxError", message: "Invalid or unexpected token" }) } big_int_math: { options = { defaults: true } input: { const sum = 10n + 15n; const exp = 5n ** 10n; const sub = 1n - 3n; const mul = 5n * 5n; const div = 15n / 5n; const regular_number = 1 * 10; } expect_exact: "const sum=10n+15n,exp=5n**10n,sub=1n-3n,mul=5n*5n,div=15n/5n,regular_number=10;" } terser-5.19.2/test/compress/block-scope.js000066400000000000000000000134561445647217600205160ustar00rootroot00000000000000 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; } } } } drop_undefined_vardef: { input: { let x = undefined; const y = undefined; } expect: { let x; const y = void 0; } } 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({one:"PASS"}); console.log(b.inner()); } expect_stdout: "PASS" } 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: { (function (A) { A.x || console.log(A) }("Hello World!")); } expect_stdout: "Hello World!"; } issue_508: { options = { defaults: true, toplevel: true, pure_getters: true } input : { const foo = () => { let a; { let b = []; { console.log(); } a = b; { let c = a; let b = 123456; console.log(b); c.push(b); } } }; foo(); } expect_stdout: [ "", "123456" ] } terser-5.19.2/test/compress/blocks.js000066400000000000000000000120711445647217600175620ustar00rootroot00000000000000remove_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_t1155_function_in_block: { options = { unused: false } mangle = {} input: { function f1() { if ("aaaaaaa") { function f2() { return 1; } const var1 = "bbbbbbb"; } } } expect: { function f1() { if ("aaaaaaa") { function a() { return 1; } const b = "bbbbbbb"; } } } } issue_t1155_function_in_other_block: { options = { unused: false } mangle = {} input: { function f1() { if ("aaaaaaaaaannnnnnn") { function f2() { return 1; } } if ("aaaaaaaaaannnnnnn") { const f2 = "aaaaaaaaaannnnnnn"; } } } expect: { function f1() { if ("aaaaaaaaaannnnnnn") function a() { return 1; } if ("aaaaaaaaaannnnnnn") { const n = "aaaaaaaaaannnnnnn"; } } } } 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-5.19.2/test/compress/class-properties.js000066400000000000000000000234751445647217600216160ustar00rootroot00000000000000basic_class_properties: { input: { class A { static foo bar static fil = "P" another = "A"; get; set = "S"; #private; #private2 = "S"; toString() { if ('bar' in this && 'foo' in A) { return A.fil + this.another + this.set + this.#private2 } } } console.log(new A().toString()) } expect_stdout: "PASS" } computed_class_properties: { input: { const x = "FOO" const y = "BAR" class X { [x] = "PASS" static [y] } if ("BAR" in X) { console.log(new X()[x]) } } expect_stdout: "PASS" } static_class_properties_side_effects: { input: { class A { foo = console.log("PASS2") static bar = console.log("PASS1"); } new A(); } expect_stdout: [ "PASS1", "PASS2" ] } class_expression_properties_side_effects: { options = { side_effects: true, unused: true, } input: { global.side = () => { console.log("PASS") }; (class { static foo = side(); [side()]() {}; [side()] = 4 }); } expect: { global.side = () => { console.log("PASS") }; side(),side(),side(); } expect_stdout: [ "PASS", "PASS", "PASS" ] } class_expression_not_constant: { options = { collapse_vars: true, join_vars: true, properties: true, reduce_vars: true, side_effects: true, unused: true, } input: { const obj = {}; leak(); obj.Class1 = class { static foo = leak() }; obj.Class2 = class extends Obj.Class1 {}; new obj.Class2(); } expect: { const obj = {} // Class1 not inlined into object leak(); obj.Class1 = class { static foo = leak() }; obj.Class2 = class extends Obj.Class1 {}; new obj.Class2; } } class_expression_constant: { options = { collapse_vars: true, join_vars: true, properties: true, reduce_vars: true, side_effects: true, unused: true, } input: { const obj = {}; obj.Class1 = class { static foo = "constant" }; obj.Class2 = class extends Obj.Class1 {}; new obj.Class2(); } expect: { const obj = { Class1: class { static foo = "constant" } }; obj.Class2 = class extends Obj.Class1 {}; new obj.Class2(); } } static_property_side_effects: { options = { toplevel: true, unused: true, } input: { let x = "FAIL" class cls { static [x = "PASS"] } console.log(x) class cls2 { static [console.log("PASS")] } } expect_stdout: ["PASS", "PASS"] } static_means_execution: { options = { toplevel: true, reduce_vars: true, unused: true, } input: { let x = 0; class NoProps { } class WithProps { prop = (x = x === 1 ? "PASS" : "FAIL") } class WithStaticProps { static prop = (x = x === 0 ? 1 : "FAIL") } new NoProps(); new WithProps(); new WithStaticProps(); console.log(x); } expect: { let x = 0; // Does not get inlined as it contains an immediate side effect class WithStaticProps { static prop = (x = x === 0 ? 1 : "FAIL") } new class {}; new class { prop = (x = x === 1 ? "PASS" : "FAIL") }; new WithStaticProps(); console.log(x); } expect_stdout: "PASS" } mangle_class_properties: { mangle = { properties: {} } input: { class Foo { bar = "bar"; static zzz = "zzz" toString() { return this.bar + Foo.zzz; } } } expect: { class Foo { t = "bar"; static o = "zzz" toString() { return this.t + Foo.o; } } } } mangle_class_properties_keep_quoted: { mangle = { properties: { keep_quoted: true } } input: { class Foo { "bar" = "bar"; static "zzz" = "zzz" toString() { return this.bar + Foo.zzz; } } } expect: { class Foo { "bar" = "bar"; static "zzz" = "zzz" toString() { return this.bar + Foo.zzz; } } } } private_class_properties: { options = { ecma: 2015 } input: { class Foo { #bar = "FooBar" get bar() { return this.#bar; } } console.log(new Foo().bar) } expect: { class Foo { #bar = "FooBar" get bar() { return this.#bar; } } console.log(new Foo().bar) } expect_stdout: "FooBar" } same_name_public_private: { input: { class A { static foo bar static fil = "P" another = "A"; #fil; #another = "SS"; ["#another"] = "XX"; toString() { if ('bar' in this && 'foo' in A && !("fil" in this)) { return A.fil + this.another + this.#another; } } } console.log(new A().toString()) } expect_stdout: "PASS" } static_private_fields: { input: { class A { static #a = "P"; b = "A"; #c = "SS"; toString() { return A.#a + this.b + this.#c; } } console.log(new A().toString()) } expect_stdout: "PASS" } optional_chaining_private_fields: { input: { class A { #opt = undefined; toString() { return this?.#opt ?? "PASS"; } } console.log(new A().toString()) } expect: { class A { #opt = void 0; toString() { return this?.#opt ?? "PASS"; } } console.log(new A().toString()) } expect_stdout: "PASS" } private_properties_can_be_mangled: { mangle = { properties: true } input: { class X { aaaaaa = "P" #aaaaaa = "A" #bbbbbb() { return "SS" } get #cccccc() {} set #dddddd(v) {} log() { console.log(this.aaaaaa + this.#aaaaaa + this.#bbbbbb() + this.#cccccc + this.#dddddd) } } new X().log() } expect: { class X { t = "P" #a = "A" #s() { return "SS" } get #c() {} set #t(a) {} log() { console.log(this.t + this.#a + this.#s() + this.#c + this.#t) } } new X().log() } } nested_private_properties_can_be_mangled: { mangle = { properties: true } input: { class X { #test = "PASS" #aaaaaa = this; #bbbbbb() { return this; } get #cccccc() { return this; } log() { console.log(this.#test); console.log(this.#aaaaaa.#test); console.log(this.#bbbbbb().#test); console.log(this.#cccccc.#test); console.log(this?.#test); console.log(this?.#aaaaaa.#test); console.log(this?.#bbbbbb().#test); console.log(this?.#cccccc.#test); console.log(this.#test); console.log(this.#aaaaaa?.#test); console.log(this.#bbbbbb?.().#test); console.log(this.#bbbbbb()?.#test); console.log(this.#cccccc?.#test); } } new X().log() } expect: { class X { #s = "PASS"; #o = this; #t() { return this; } get #c() { return this; } log() { console.log(this.#s); console.log(this.#o.#s); console.log(this.#t().#s); console.log(this.#c.#s); console.log(this?.#s); console.log(this?.#o.#s); console.log(this?.#t().#s); console.log(this?.#c.#s); console.log(this.#s); console.log(this.#o?.#s); console.log(this.#t?.().#s); console.log(this.#t()?.#s); console.log(this.#c?.#s); } } new X().log(); } } allow_private_field_with_in_operator : { mangle = { properties: true } input: { class A { #p; isA (input) { #p in input; #p in this; return #p in this; } } } expect:{class A{#i;i(i){#i in i;#i in this;return #i in this}}} } allow_subscript_private_field: { options = { defaults: true } input: { class A { #p; constructor(p) { this.#p = p; } isA (input) { console.log(#p in this && "PASS"); console.log(input.#p); } } new A("FAIL").isA(new A("PASS")) } expect_stdout: [ "PASS", "PASS" ] } terser-5.19.2/test/compress/classes.js000066400000000000000000000144521445647217600177470ustar00rootroot00000000000000class_recursive_refs: { options = { defaults: true, toplevel: true } input: { class a { set() { class b { set [b] (c) {} } } } class b { constructor() { b(); } } class c { [c] = 42; } class d { dee = d; } class e { static eee = e; } } expect: { } } class_duplication: { options = { defaults: true, toplevel: true } input: { class Foo { foo() { leak(new Foo()) } } // Export the class. export default Foo; } expect: { class Foo { foo() { leak(new Foo()) } } // Export the class. export default Foo; } } class_duplication_2: { options = { defaults: true, toplevel: true } input: { class Foo { foo() { leak(new Foo()) } } leak(Foo); } expect: { class Foo { foo() { leak(new Foo()) } } leak(Foo); } } export_default_class_expr: { options = { defaults: true, module: true } input: { export default class extends Foo { } } expect: { export default class extends Foo { } } } pure_prop_assignment_for_classes: { options = { defaults: true, toplevel: true } input: { class A {} A.staticProp = "A" class B { static get danger() { } } B.staticProp = "" } expect: { } } private_class_methods: { input: { class A { #method() { return "PA" } static async* #method2() { return "S" } ["#method"]() { return "S" } async print() { console.log(this.#method() + (await A.#method2().next()).value + this["#method"]()); } } new A().print(); } expect: { class A { #method() { return "PA" } static async* #method2() { return "S" } ["#method"]() { return "S" } async print() { console.log(this.#method() + (await A.#method2().next()).value + this["#method"]()); } } new A().print(); } // expect_stdout: "PASS" // < tested in chrome, fails with nodejs 14 (current LTS) } private_class_accessors: { input: { class A { #accessorInternal = "FAIL" get #accessor() { return this.#accessorInternal } set #accessor(v) { this.#accessorInternal = v; } static get #accessor2() { return "S" } get ["#accessor"]() { return "S" } async print() { this.#accessor = "PA" console.log(this.#accessor + A.#accessor2 + this["#accessor"]); } } new A().print(); } expect: { class A { #accessorInternal = "FAIL" get #accessor() { return this.#accessorInternal } set #accessor(v) { this.#accessorInternal = v; } static get #accessor2() { return "S" } get ["#accessor"]() { return "S" } async print() { this.#accessor = "PA" console.log(this.#accessor + A.#accessor2 + this["#accessor"]); } } new A().print(); } // expect_stdout: "PASS" // < tested in chrome, fails with nodejs 14 (current LTS) } class_static_blocks: { node_version = ">=16" input: { class A { static { this.hello = 'PASS' } print() { console.log(A.hello) } } new A().print(); console.log(A.hello + "2"); } expect: { class A { static { this.hello = 'PASS' } print() { console.log(A.hello) } } new A().print(); console.log(A.hello + "2"); } expect_stdout: ["PASS", "PASS2"] } class_static_blocks_empty: { node_version = ">=16" options = { toplevel: true, defaults: true } input: { class EmptyBlock { static { 1 + 1 } } } expect: { } } class_static_not_empty_blocks: { node_version = ">=16" options = { toplevel: true, defaults: true } input: { class EmptyBlock { static { this.PASS = "PASS" console.log(this.PASS) } } console.log(EmptyBlock.PASS) } expect_stdout: ["PASS", "PASS"] } class_static_block_pinned: { node_version = ">=16" options = { toplevel: true, defaults: true } input: { const x = "PASS"; class X { static { console.log(x); } } console.log(X); } expect: { class X { static { console.log("PASS"); } } console.log(X); } expect_stdout: true } class_static_block_hoisting: { node_version = ">=16" options = { toplevel: true, defaults: true } input: { var y = "PASS"; class A { static field = "FAIL"; static { var y = this.field; } } console.log(y); } expect_stdout: "PASS" } class_static_block_scope_2: { node_version = ">=16" options = { toplevel: true, defaults: true } input: { var y = "PASS"; class A { static { var y = "FAIL"; } static { console.log(y) } } console.log(y); } expect_stdout: ["PASS", "PASS"] } terser-5.19.2/test/compress/collapse_vars.js000066400000000000000000004155221445647217600211520ustar00rootroot00000000000000collapse_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 (c === 77); } 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 (c === 77); } 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; } 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_unary_2: { options = { collapse_vars: true } input: { global.leak = n => console.log(n); global.num = 4; let counter = -1; for (const i in [0,1,2,3,4,5]) { counter++, i == num && leak(counter); } } expect_stdout: "4" } 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:', x * 2); } 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 = x.y * 2; 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:', x.y * 2); } 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) { b.toString(); })(--a,a |= 10); 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_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 XMLHttpRequest() { this.onreadystatechange = 'PASS' } global.xhrDesc = {} function foo() { return bar(); } function bar() { if (xhrDesc) { var req = new XMLHttpRequest(); var result = req.onreadystatechange; Object.defineProperty(XMLHttpRequest.prototype, 'onreadystatechange', xhrDesc || {}); return result; } } console.log(foo()); } expect_stdout: "PASS" } issue_2437_2: { 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 XMLHttpRequest() { this.onreadystatechange = 'PASS' } global.SYMBOL_FAKE_ONREADYSTATECHANGE_1 = Symbol() global.xhrDesc = null function foo() { return bar(); } function bar() { if (!xhrDesc) { 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_stdout: "false" } 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 = void 0; log(42); } 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_997: { options = { defaults: true, } input: { function main(e) { console.log(e.length); let other = "12"; for (let e; e = 0;) console.log(e); } main("foo"); } expect_stdout: ["3"] } 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_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" } issue_348: { options = { collapse_vars: true, unused: true } input: { console.log(function x(EEE) { return function (tee) { if (tee) { const EEE = tee; if (EEE) return EEE; } }(EEE); }('PASS')) } expect_stdout: 'PASS' } noinline_annotation: { options = { collapse_vars: true, unused: true, toplevel: true } input: { const x = () => console.log() /*#__NOINLINE__*/x() } expect: { const x = () => console.log() x() } } ignore_class: { options = { defaults: true, toplevel: true } input: { global.leak = x => class dummy { get pass() { return x } } global.module = {}; (function () { const SuperClass = leak("PASS") class TheClass extends SuperClass {} module.exports = TheClass }()) console.log(new module.exports().pass) } expect_stdout: "PASS" } do_not_place_chain_on_lhs_1: { options = { collapse_vars: true, toplevel: true } input: { var a = b?.c; a.d = e; } expect: { var a = b?.c; a.d = e; } } do_not_place_chain_on_lhs_2: { options = { collapse_vars: true, toplevel: true } input: { var a; a = b?.c; a.d = e; } expect: { var a; a = b?.c; a.d = e; } } optional_chain_call_argument_side_effect: { options = { collapse_vars: true, } input: { ((this_is_null) => { const results = console.log("PASS"); this_is_null?.(results); })(id(null)); } expect: { ((this_is_null) => { const results = console.log("PASS"); this_is_null?.(results); })(id(null)); } expect_stdout: "PASS" } optional_chain_call_prop_side_effect: { options = { collapse_vars: true, } input: { ((this_is_null) => { const results = console.log("PASS"); this_is_null?.[results]; })(id(null)); } expect: { ((this_is_null) => { const results = console.log("PASS"); this_is_null?.[results]; })(id(null)); } expect_stdout: "PASS" } shadowed_variable: { options = { pure_getters: true, collapse_vars: true, unused: true, } input: { function test(e) { const result = {}; const test = e.test; { const e = random(test); result.discretized = e } return result; } } expect: { function test(e) { const result = {}; const test = e.test; { const e = random(test); result.discretized = e; } return result; } } } shadowed_variable_2: { options = { pure_getters: true, collapse_vars: true, unused: true, } input: { function test(e) { const result = {}; const test = e.test; { { result.discretized = random(test); } const e = random(); console.log(e); } return result; } } expect: { function test(e) { const result = {}; const test = e.test; { result.discretized = random(test); const e = random(); console.log(e); } return result; } } } shadowed_variable_3: { options = { pure_getters: true, collapse_vars: true, unused: true, } input: { if(1) { var object = 1 var object2 = "PASS" let temp_variable = id(true) ? object2 : object { let object = temp_variable console.log(object) console.log(object) } } } expect: { if(1) { var object = 1 var object2 = "PASS" let temp_variable = id(true) ? object2 : object { let object = temp_variable console.log(object) console.log(object) } } } expect_stdout: ["PASS", "PASS"] } terser-5.19.2/test/compress/comments.js000066400000000000000000000025071445647217600201350ustar00rootroot00000000000000print_every_comment_only_once: { beautify = { comments: true } input: { var foo = {}; // this is a comment line (foo.bar = {}).test = 123; var foo2 = {}; /* this is a block line */ (foo2.bar = {}).test = 123; } expect_exact: [ "var foo={};", "// this is a comment line", "(foo.bar={}).test=123;var foo2={};", "/* this is a block line */(foo2.bar={}).test=123;", ] } preserve_comments_by_default: { beautify = { comments: "some" } input: { var foo = {}; /* @license */ // @lic /**! foo */ /*! foo */ /* lost */ /* @copyright …info… */ } expect_exact: [ "var foo={};", "/* @license */", "// @lic", "/**! foo */", "/*! foo */", "/* @copyright …info… */", ] } comment_moved_between_return_and_value: { beautify = { comments: "some" } input: { console.log(function (same_name) { /* @license Foo bar */ function licensed(same_name) { return same_name.toUpperCase() } console.log("PASS") return licensed("PA") + "SS" }()) } expect_stdout: [ "PASS", "PASS" ] } terser-5.19.2/test/compress/comparing.js000066400000000000000000000207631445647217600202730ustar00rootroot00000000000000keep_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, lhs_constants: 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, lhs_constants: 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, lhs_constants: 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, lhs_constants: 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, lhs_constants: 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, lhs_constants: 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" } bigint_vs_number: { options = { comparisons: true, } input: { if (-1 !== -1n) console.log("PASS"); } expect: { if (-1 !== -1n) console.log("PASS"); } expect_stdout: "PASS" } terser-5.19.2/test/compress/concat-strings.js000066400000000000000000000123341445647217600212450ustar00rootroot00000000000000concat_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 concatenation 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-5.19.2/test/compress/conditionals.js000066400000000000000000000732111445647217600207760ustar00rootroot00000000000000ifs_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 foo(); var jj; // 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 || 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(i & 4, i & 2, i & 1)); } 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 } ifs_same_consequent: { options = { conditionals: true, } input: { if (foo) { x(); } else if (bar) { x(); } else if (baz) { x(); } if (foo) { x(); } else if (bar) { x(); } else if (baz) { x(); } else { x(); } if (foo) { x(); } else if (bar) { x(); } else if (baz) { x(); } else { y(); } } expect: { (foo || bar || baz) && x(); (foo || bar || baz), x(); (foo || bar || baz) ? x() : y(); } } terser-5.19.2/test/compress/const.js000066400000000000000000000102741445647217600174360ustar00rootroot00000000000000issue_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(a & 1); } 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-5.19.2/test/compress/dead-code.js000066400000000000000000000714621445647217600201230ustar00rootroot00000000000000dead_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 || (x + "0"))) { console.log("unreachable"); var foo; } 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 a ^ 1; }()); } 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" } issue_718: { options = { dead_code: true } input: { throw 'error' // Keep imports and exports please import 'x' export {y} } expect: { throw 'error' import 'x' export {y} } } issue_1029_1: { options = { dead_code: true, } input: { function asyncFn() { let promise; return promise = (async () => { await true; console.log(promise); })() } asyncFn({}); } expect: { function asyncFn() { let promise; return promise = (async () => { await true; console.log(promise); })(); } asyncFn({}); } } issue_1029_2: { options = { dead_code: true, } input: { function asyncFn() { let promise; return promise = (async () => { console.log(promise); })() } asyncFn({}); } expect: { function asyncFn() { let promise; return promise = (async () => { console.log(promise); })(); } asyncFn({}); } } issue_1029_3: { options = { dead_code: true, } input: { function genFn() { let gen; return gen = function*() { console.log(gen); }(); } genFn({}).next(); } expect: { function genFn() { let gen; return gen = function* () { console.log(gen); }(); } genFn({}).next(); } } issue_1029_4: { options = { dead_code: true, } input: { function fn() { let val return val = function() { console.log(val); return {}; }(); } fn(); } expect: { function fn() { let val return function() { console.log(val); return {}; }(); } fn(); } } issue_1029_5: { options = { dead_code: true, } input: { function fn() { let val return val = function() { setTimeout(() => console.log(val)); return {}; }(); } fn(); } expect: { function fn() { let val return val = function() { setTimeout(() => console.log(val)); return {}; }(); } fn(); } } issue_1029_6: { options = { dead_code: true, } input: { function fn() { let val return val = function() { setTimeout(() => { (() => console.log(val))(); }) return {}; }(); } fn(); } expect: { function fn() { let val return val = function() { setTimeout(() => { (() => console.log(val))(); }) return {}; }(); } fn(); } } terser-5.19.2/test/compress/debugger.js000066400000000000000000000004771445647217600201000ustar00rootroot00000000000000keep_debugger: { options = { drop_debugger: false, } input: { debugger; } expect: { debugger; } } drop_debugger: { options = { drop_debugger: true, } input: { debugger; if (foo) debugger; } expect: { if (foo); } } terser-5.19.2/test/compress/defaults.js000066400000000000000000000027651445647217600201250ustar00rootroot00000000000000defaults_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-5.19.2/test/compress/destructuring.js000066400000000000000000001051121445647217600212060ustar00rootroot00000000000000destructuring_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: 2015 } input: { var {cc,} = foo; } expect_exact: "var{cc}=foo;" } nested_destructuring_objects: { beautify = { ecma: 2015 } 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: 2015 } 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: 2015 } 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: 2015 } 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: 2015 } 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: 2015 } 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: 2015 } 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: 2015 } 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: 2015 } 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: 2015, } 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: 2015, } 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_decl_6: { options = { pure_getters: true, toplevel: true, unused: true, } input: { const { a, b: c, ...d } = { b: 7 }; let { e, f: g, ...h } = { e: 8 }; var { w, x: y, ...z } = { w: 4, x: 5, y: 6 }; console.log(c, e, z.y); } expect: { const { a, b: c, ...d } = { b: 7 }; let { e, f: g, ...h } = { e: 8 }; var { w, x: y, ...z } = { w: 4, x: 5, y: 6 }; console.log(c, e, z.y); } expect_stdout: "7 8 6" } 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: 2015, } 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-5.19.2/test/compress/directives.js000066400000000000000000000024011445647217600204420ustar00rootroot00000000000000class_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-5.19.2/test/compress/drop-console.js000066400000000000000000000016241445647217600207130ustar00rootroot00000000000000drop_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-5.19.2/test/compress/drop-unused.js000066400000000000000000001720001445647217600205510ustar00rootroot00000000000000unused_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 a; })(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() { 0; try { 0; 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_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() { function bar(x) { var value = (4 - 1) * (x || never_called()); console.log(value == 6 ? "PASS" : value); } Baz = function(x) { bar.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() { function bar (x) { var value = (4 - 1) * (x || never_called()); console.log(value == 6 ? "PASS" : value); } Baz = function(x) { bar.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(); }; 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" } function_argument_modified_by_function_statement: { options = { unused: true, collapse_vars: true, } input: { var printTest = function(ret) { function ret() { console.log("PASS"); } return ret; }("FAIL"); printTest(); } expect_stdout: "PASS" } 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, 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, y * 4); } 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" } unused_seq_elements: { options = { defaults: true, toplevel: true } input: { var a = 0, b = 0; console.log("just-make-sure-it-is-compilable") && (a++, b++); } expect_stdout: "just-make-sure-it-is-compilable" } unused_class_with_static_props_side_effects: { options = { toplevel: true } input: { let x = "FAIL" class X { static _ = (x = "PASS") } console.log(x) } expect_stdout: "PASS" } unused_class_with_static_props_this: { options = { toplevel: true, unused: true } input: { let _classThis; var Foo = class { static _ = Foo = _classThis = this; }; const x = Foo = _classThis; leak(x); } expect: { let _classThis; (class { static _ = _classThis = this; }); const x = _classThis; leak(x); } } unused_class_with_static_props_this_2: { options = { toplevel: true, unused: true, } input: { let Foo = (()=>{ let _classThis; var Foo = class { static _ = (()=>{ Foo = _classThis = this; })(); foo(){ return "PASS"; } }; return Foo = _classThis; })(); console.log(new Foo().foo()); } expect: { let Foo = (()=>{ let _classThis; (class{static _=(()=>{_classThis=this})();foo(){return "PASS"}}); return _classThis })(); console.log((new Foo).foo()); } expect_stdout: "PASS" } unused_class_with_static_props_side_effects_2: { options = { toplevel: true } input: { let x = "FAIL" function impure() { x = "PASS" } class Unused { static _ = impure() } console.log(x) } expect_stdout: "PASS" } unused_class_which_extends_might_throw: { options = { toplevel: true } input: { let x = "FAIL" try { class X extends might_throw_lol() { constructor() {} } } catch(e) { x = "PASS" } console.log(x) } expect_stdout: "PASS" } unused_class_which_might_throw: { options = { toplevel: true } input: { let x = "FAIL" try { class X { static _ = ima_throw_lol() } } catch(e) { x = "PASS" } console.log(x) } expect_stdout: "PASS" } unused_class_which_might_throw_2: { options = { toplevel: true } input: { let x = "FAIL" try { class X { [ima_throw_lol()] = null } } catch(e) { x = "PASS" } console.log(x) } expect_stdout: "PASS" } unused_class_which_might_throw_3: { options = { toplevel: true } input: { let x = "FAIL" try { class X { [ima_throw_lol()]() { return null } } } catch(e) { x = "PASS" } console.log(x) } expect_stdout: "PASS" } unused_class_which_might_throw_4: { options = { toplevel: true } input: { let x = "FAIL" try { class X { get [ima_throw_lol()]() { return null } } } catch(e) { x = "PASS" } console.log(x) } expect_stdout: "PASS" } variable_refs_outside_unused_class: { options = { toplevel: true, unused: true } input: { var symbols = id({ prop: 'method' }) var input = id({ prop: class {} }) var staticProp = id({ prop: 'foo' }) class unused extends input.prop { static prop = staticProp.prop; [symbols.prop]() { console.log('PASS') } } console.log("PASS") // Basically, don't crash } expect_stdout: "PASS" } unused_null_conditional_chain: { options = { defaults: true, sequences: false, evaluate: false } input: { null?.unused; null?.[side_effect()]; null?.unused.i_will_throw; null?.call(1); null?.(2); null?.maybe_call?.(3); } expect: { } } unused_null_conditional_chain_2: { options = { toplevel: true, defaults: true, passes: 5, } input: { let i = 0; (i++, null)?.unused; (i++, null)?.[side_effect()]; (i++, null)?.unused.i_will_throw; (i++, null)?.call(1); (i++, null)?.(2); (i++, null)?.maybe_call?.(3); } expect: { } } unused_null_conditional_chain_3: { options = { toplevel: true, defaults: true, passes: 5, } input: { (side_effect(), null)?.unused; (side_effect(), null)?.[side_effect()]; (side_effect(), null)?.unused.i_will_throw; (side_effect(), null)?.call(1); (side_effect(), null)?.(2); (side_effect(), null)?.maybe_call?.(3); } expect: { // TODO: Elminate everything after ?. (side_effect(), null)?.unused, (side_effect(), null)?.[side_effect()], (side_effect(), null)?.unused.i_will_throw, (side_effect(), null)?.call(1), (side_effect(), null)?.(2), (side_effect(), null)?.maybe_call?.(3); } } unused_null_conditional_chain_4: { options = { toplevel: true, defaults: true, passes: 5, } input: { function nullish() { side_effect(); return null; } nullish()?.unused; nullish()?.[side_effect()]; nullish()?.unused.i_will_throw; nullish()?.call(1); nullish()?.(2); nullish()?.maybe_call?.(3); } expect: { // TODO: Elminate everything after ?. function nullish() { return side_effect(), null; } nullish()?.unused, nullish()?.[side_effect()], nullish()?.unused.i_will_throw, nullish()?.call(1), nullish()?.(2), nullish()?.maybe_call?.(3); } } unused_null_conditional_chain_5: { options = { toplevel: true, defaults: true, passes: 5, } input: { export const obj = { side_effect() { side_effect(); return { null: null }; } } obj.side_effect().null?.unused; obj.side_effect().null?.[side_effect()]; obj.side_effect().null?.unused.i_will_throw; obj.side_effect().null?.call(1); obj.side_effect().null?.(2); obj.side_effect().null?.maybe_call?.(3); } expect: { export const obj = { side_effect: () => (side_effect(), {null: null}) } // TODO: Elminate everything after ?. obj.side_effect().null?.unused, obj.side_effect().null?.[side_effect()], obj.side_effect().null?.unused.i_will_throw, obj.side_effect().null?.call(1), obj.side_effect().null?.(2), obj.side_effect().null?.maybe_call?.(3); } } issue_t1392: { options = { unused: true, side_effects: true }; input: { class RelatedClass {} class BaseClass {} class SubClass extends BaseClass { static field = new RelatedClass; } SubClass } expect: { class RelatedClass {} class BaseClass {} class SubClass extends BaseClass { static field = new RelatedClass; } } expect_stdout: true } issue_t1392_2: { options = { unused: true, side_effects: true }; input: { class BaseClass {} class SubClass { static { new BaseClass() } } SubClass } expect: { class BaseClass {} class SubClass { static { new BaseClass() } } } expect_stdout: true } issue_t1392_3: { options = { unused: true, side_effects: true }; input: { class BaseClass {} class SubClass { static [new BaseClass()] = 1 } SubClass } expect: { class BaseClass {} class SubClass { static [new BaseClass()] = 1 } } expect_stdout: true } issue_t1392_4: { options = { unused: true, side_effects: true }; input: { class BaseClass {} class SubClass { static [new BaseClass()]() {} } SubClass } expect: { class BaseClass {} class SubClass { static [new BaseClass()]() {} } } expect_stdout: true } issue_t1392_5: { options = { unused: true, side_effects: true }; input: { (function test() { class RelatedClass {} class BaseClass {} class SubClass extends BaseClass { static field = new RelatedClass; } const subclassUser = { oneUse: SubClass, otherUse() { return new SubClass } }; })() } expect: { (function(){ class RelatedClass{} class BaseClass{} new RelatedClass() })(); } expect_stdout: true } issue_t1412_1: { options = { toplevel: true, unused: true, side_effects: true }; input: { var unused_var; class C { static { unused_var = 1234; } } } expect: { } } issue_t1412_2: { options = { toplevel: true, unused: true, side_effects: true }; input: { class C { static { side_eff(); } } } expect: { class C { static { side_eff(); } } } } terser-5.19.2/test/compress/evaluate.js000066400000000000000000001217441445647217600201230ustar00rootroot00000000000000and: { 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 } safe_array_string_length: { options = { reduce_vars: true, evaluate: true, } input: { const array_ref = [1, leak("side effect")] console.log( "Hi!!".length, [1, 2].length, array_ref.length, [id("side eff")] ); } expect: { const array_ref = [1, leak("side effect")] console.log(4, 2, array_ref.length, [id("side eff")]); } expect_stdout: "4 2 2 [ 'side eff' ]" } 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 } issue_2231_2: { options = { evaluate: true, unsafe: true, } input: { console.log(Object.getOwnPropertyNames(null)); } expect: { console.log(Object.getOwnPropertyNames(null)); } expect_stdout: true } 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 } 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, not_counted = true, ...also_not_counted) { console.log(f.name.length, f.length); })(); } expect: { (function f(a, not_counted = true, ...also_not_counted) { 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) } } issue_399: { options = { unsafe: true, evaluate: true, unsafe_regexp: true } input: { console.log(RegExp("\\\nfo\n[\n]o\\bbb")); console.log(RegExp("\n")); console.log(RegExp("\\n")); console.log(RegExp("\\\n")); console.log(RegExp("\\\\n")); console.log(RegExp("\\\\\n")); console.log(RegExp("\\\\\\n")); console.log(RegExp("\\\\\\\n")); console.log(RegExp("\r")); console.log(RegExp("\u2028")); console.log(RegExp("\u2029")); console.log(RegExp("\n\r\u2028\u2029")); } expect: { console.log(/\nfo\n[\n]o\bbb/); console.log(/\n/); console.log(/\n/); console.log(/\n/); console.log(/\\n/); console.log(/\\\n/); console.log(/\\\n/); console.log(/\\\n/); console.log(/\r/); console.log(/\u2028/); console.log(/\u2029/); console.log(/\n\r\u2028\u2029/); } } null_conditional_chain_eval: { options = { evaluate: true, side_effects: true } input: { null?.unused null?.[side_effect()] null?.unused.but_might_throw null?.call(1) null?.(2) null?.maybe_call?.(3) } expect: { } } null_conditional_chain_eval_2: { options = { evaluate: true, side_effects: true } input: { null.deep?.unused null.deep?.[side_effect()] null.deep?.unused.but_might_throw null.deep?.call(1) null.deep?.(2) null.deep?.maybe_call?.(3) } expect: { null.deep?.unused null.deep?.[side_effect()] null.deep?.unused.but_might_throw null.deep?.call(1) null.deep?.(2) null.deep?.maybe_call?.(3) } } avoid_higher_order_functions: { input: { (function () { var b = "PASS"; console.log('FAIL FAIL'.replace(/FAIL/g, function () { return b; })); console.log('FAIL FAIL'.replace(/FAIL/g, () => b)); }()); } expect_stdout: [ "PASS PASS", "PASS PASS" ] } regexp_property_eval: { options = { evaluate: true, unsafe: true } input: { console.log(/abc/i.source); console.log(/abc/i.flags); console.log(/abc/i.dotAll); console.log(/abc/i.global); console.log(/abc/i.ignoreCase); console.log(/abc/i.multiline); console.log(/abc/i.sticky); console.log(/abc/i.unicode); } expect: { console.log("abc"); console.log("i"); console.log(false); console.log(false); console.log(true); console.log(false); console.log(false); console.log(false); } } issue_t790_strings_larger_than_refs: { options = { defaults: true, sequences: false } input: { const string = "aaa"; aa(string); aa(string); aa(string); aa(string); } expect: { const string = "aaa"; aa("aaa"); aa("aaa"); aa("aaa"); aa("aaa"); } } issue_t790_strings_larger_than_refs_mangle: { options = { defaults: true, sequences: false } mangle = { module: true } input: { const aaaaa = "aaa"; aa(aaaaa); aa(aaaaa); aa(aaaaa); aa(aaaaa); } expect: { const a = "aaa"; aa(a); aa(a); aa(a); aa(a); } } issue_t790_strings_smaller_than_refs: { options = { defaults: true, sequences: false } input: { const _string_ = "str"; id(_string_); id(_string_); id(_string_); id(_string_); } expect: { const _string_ = "str"; id("str"); id("str"); id("str"); id("str"); } } issue_t790_complex_expression_smaller: { options = { defaults: true, toplevel: true, sequences: false } mangle = { toplevel: true } input: { const $read$ = "oooo"; const $only$ = "llll"; const $readonly$ = $read$ + $only$; console.log($read$); console.log($read$); console.log($only$); console.log($only$); console.log($readonly$); console.log($readonly$); } expect: { const o = "oooo", l = "llll", c = o + l; console.log(o); console.log(o); console.log(l); console.log(l); console.log(c); console.log(c); } expect_stdout: [ "oooo", "oooo", "llll", "llll", "oooollll", "oooollll", ] } unsafe_deep_chain: { options = { evaluate: true, unsafe: true, } input: { a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z; } expect: { a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z; } } terser-5.19.2/test/compress/expansions.js000066400000000000000000000060701445647217600204760ustar00rootroot00000000000000 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", ] } object_spread_regression: { options = { hoist_props: true } input: { const x = () => { let o = { ...{} } } } expect: { const x = () => { let o = {} } } } object_spread: { options = { defaults: true } input: { let obj = { ...{} } console.log(Object.keys(obj)) let objWithKeys = { a: 1, ...{ b: 2 } } console.log(Object.keys(objWithKeys).join(",")) } expect_stdout: [ "[]", "a,b", ] } object_spread_nullish_undefined: { input: { let o = { ...undefined, ...{a: true} } id(o); } expect: { let o = {a: true}; id(o) } } object_spread_nullish_null: { input: { let o = { ...null, ...{a: true} } id(o); } expect: { let o = {a: true}; id(o) } } avoid_spread_hole: { input: { let x = [...[,]] let y = [,] console.log(0 in x, 0 in y) } expect_stdout: "true false" } avoid_spread_holes_call: { input: { let x = (a, b) => [a, b] let y = x(...[,], 1) console.log(...y) } expect_stdout: "undefined 1" } avoid_spread_getset_object: { input: { let x = { ...{ get x() { return 1 } } } let y = { ...{ set y(_) { console.log(_) } } } console.log(x.x, y.y, x.x = 2, y.y = 3, x.x, y.y) } expect_stdout: "1 undefined 2 3 2 3" } avoid_spread_this: { input: { function foo() { const defaults = { SS: 2 }; return { ...this, ...defaults }; } console.log(Object.keys(foo.call({ PA: 1 }))); } expect_stdout: "[ 'PA', 'SS' ]" } terser-5.19.2/test/compress/export.js000066400000000000000000000525031445647217600176320ustar00rootroot00000000000000issue_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 }; } } export_object_property_mangle: { module = true options = { reduce_vars: false, } mangle = true input: { const n = null; export const o = { o: n }; } expect: { const n = null; export const o = {o: n}; } } export_object_property_mangle_2: { module = true mangle = true input: { const n = null; const o = { o: n }; export { o }; } expect: { const n = null; const o = {o: n}; export {o}; } } import_string: { input: { import { "F-oo" as Foo } from "lel"; import { "*" as Bar } from "lel"; } expect_exact: 'import{"F-oo"as Foo}from"lel";import{"*"as Bar}from"lel";' } import_multiple_string: { input: { import { "F-oo" as Foo, "*" as Bar } from "lel"; } expect_exact: 'import{"F-oo"as Foo,"*"as Bar}from"lel";' } export_named_string: { input: { export { Foo as "F-oo" }; export { Bar as "B-ar" } from "lel"; export { star as "*" } from "lel"; export { "B-ax" } from "lel"; export { "B-ar" as "F-oo" } from "lel"; export { "*" } from "lel"; export { "*" as star } from "lel"; export { "*" as "s-tar" } from "lel"; } expect_exact: 'export{Foo as"F-oo"};export{Bar as"B-ar"}from"lel";export{star as"*"}from"lel";export{"B-ax"}from"lel";export{"B-ar"as"F-oo"}from"lel";export{"*"}from"lel";export{"*"as star}from"lel";export{"*"as"s-tar"}from"lel";' } export_default_string: { input: { export { default as "F-oo" }; export { default as "*" }; export { default as "B-ar" } from "lel"; export { default as "*" } from "lel"; } expect_exact: 'export{default as"F-oo"};export{default as"*"};export{default as"B-ar"}from"lel";export{default as"*"}from"lel";' } export_multiple_named_default_string: { input: { export { default as "F-oo", default as "*" }; export { Foo as "F-oo", Bar as "B-ar", star as "*", "B-ax", "B-ar" as "F-oo", "*", "*" as star, "*" as "s-tar", default as "F-oo", default as "*", } from "lel"; } expect_exact: 'export{default as"F-oo",default as"*"};export{Foo as"F-oo",Bar as"B-ar",star as"*","B-ax","B-ar"as"F-oo","*","*"as star,"*"as"s-tar",default as"F-oo",default as"*"}from"lel";' } export_namespace_as: { input: { export * as foo from "lel"; } expect_exact: 'export*as foo from"lel";' } export_namespace_as_string: { input: { export * as "f-oo" from "lel"; export * as "*" from "lel"; } expect_exact: 'export*as"f-oo"from"lel";export*as"*"from"lel";' } terser-5.19.2/test/compress/expression.js000066400000000000000000000020521445647217600205020ustar00rootroot00000000000000pow: { 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-5.19.2/test/compress/functions.js000066400000000000000000001612611445647217600203230ustar00rootroot00000000000000non_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", ] } scope_funs_strict: { mangle = { } input: { 'use strict'; function x() { if (true) { let name1 = "nnnnffff" function name2() {} } } } expect: { 'use strict'; function x() { if (true) { let n = "nnnnffff" function f() {} } } } } 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; }(); }(1), function(a) { return function(a) { return a === undefined; }(); }(2)); } expect: { console.log(function (a) { return a + 1; }(1), function (a) { return a === void 0; }()); } expect_stdout: "2 true" } 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() { if (NaN === 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() { 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_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: { void console.log("pass".toUpperCase()); } 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, passes: 2, 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 + "ING"; var b; }("PASS")); } expect: { console.log((b = "PASS", b + "ING")); var b; } expect_stdout: "PASSING" } 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, passes: 2, 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: { console.log(JSON.stringify({ a: 1 }), JSON.stringify({ a: 2, b: 3 })); } 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}' } avoid_generating_duplicate_functions_compared_together: { options = { reduce_vars: true, unused: true, toplevel: true } input: { const x = () => null; const y = () => x; console.log(y() === y()); } expect_stdout: "true" } avoid_generating_duplicate_functions_compared_together_2: { options = { reduce_vars: true, unused: true, toplevel: true } input: { const defaultArg = input => input; const fn = (arg = defaultArg) => arg; console.log(fn() === fn()); } expect_stdout: "true" } avoid_generating_duplicate_functions_compared_together_3: { options = { reduce_vars: true, unused: true, toplevel: true } input: { const x = () => null; console.log(id(x) === id(x)); } expect_stdout: "true" } avoid_generating_duplicate_functions_compared_together_4: { options = { reduce_vars: true, unused: true, toplevel: true } input: { const x = () => null; const y = () => x; const fns = [y(), y()] console.log(fns[0] === fns[1]); const fns_obj = {a: y(), b: y()} console.log(fns_obj.a === fns_obj.b); } expect_stdout: ["true", "true"] } terser-5.19.2/test/compress/global_defs.js000066400000000000000000000105261445647217600205510ustar00rootroot00000000000000must_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); } } 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); } } conditional_chains: { options = { global_defs: { "a.b.c": "d", }, } input: { console.log(a?.b.c); } expect: { console.log("d"); } } terser-5.19.2/test/compress/harmony.js000066400000000000000000001243651445647217600177740ustar00rootroot00000000000000arrow_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){}" } classes_extending_classes_out_of_pure_iifes: { options = { toplevel: true, unused: true, } input: { let Base = /*@__PURE__*/ (() => { class A {} A.sub = Sub return A; })(); class Sub extends Base { } } expect: { } } 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 * as Lel from 'lel'; } expect_exact: 'import*as Lel from"lel";' } import_meta: { input: { import.meta; import.meta.url; } expect_exact: 'import.meta;import.meta.url;' } 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_from_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_assertions: { input: { import "hello" assert { key: 'value' }; } expect_exact: 'import"hello"assert{key:"value"};' } import_assertions_with_spaces_in_obj: { input: { import "hello" assert { 'k e y': 'value' }; } expect_exact: 'import"hello"assert{"k e y":"value"};' } export_from_assertions: { input: { export * from "hello" assert { key: 'value' }; } expect_exact: 'export*from"hello"assert{key:"value"};' } export_named_from_assertions: { input: { export { x } from "hello" assert { key: 'value' }; } expect_exact: 'export{x}from"hello"assert{key:"value"};' } 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: 2015, 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: 2015, } 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 } shorthand_safari: { beautify = { ecma: 2015, safari10: true, } input: { var ä = "PASS"; console.log({ ä }); } expect_exact: 'var ä="PASS";console.log({"ä":ä});' 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 => { return value = letters[key] + key, () => console.log(value); var value; }); })().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), letters = [ "A", "B", "C" ], key = keys.shift(), () => console.log(letters[key] + key); var letters, 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 (arguments.length == 1) data = [data]; return data; } console.log(JSON.stringify([foo(), foo(null), foo(5, 6)])); } expect_stdout: "[[],[null],5]" } terser-5.19.2/test/compress/hoist.js000066400000000000000000000030201445647217600174250ustar00rootroot00000000000000 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-5.19.2/test/compress/hoist_props.js000066400000000000000000000531501445647217600206610ustar00rootroot00000000000000issue_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 = value * 10; } }; 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 = value * 10; } }; 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 ((6 + 5) / 2) * 1; } 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" } does_not_hoist_objects_with_computed_props: { options = { hoist_props: true, reduce_vars: true, toplevel: true } input: { const x = { [console.log("PASS")]: 123 } } expect_stdout: "PASS" } issue_851_hoist_to_conflicting_name: { options = { hoist_props: true, reduce_vars: true, toplevel: true } input: { const BBB = { CCC: "PASS" } if (id(true)) { const BBB_CCC = BBB.CCC console.log(BBB_CCC) } } expect: { const BBB_CCC$0 = "PASS"; if (id(true)) { const BBB_CCC = BBB_CCC$0; console.log(BBB_CCC); } } expect_stdout: "PASS" } terser-5.19.2/test/compress/hoist_vars.js000066400000000000000000000042301445647217600204640ustar00rootroot00000000000000statements: { 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-5.19.2/test/compress/html_comments.js000066400000000000000000000037031445647217600211600ustar00rootroot00000000000000html_comment_in_expression: { input: { function f(a, b, x, y) { return a < !--b && x-- > y; } } expect_exact: "function f(a,b,x,y){return ay}"; } html_comment_in_less_than: { input: { function f(a, b) { return a < !--b; } } expect_exact: "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"}'; } script_tag_in_comparison: { input: { function f() { return 0 < (/script>/).test(); } } expect_exact: 'function f(){return 0< /script>/.test()}'; } html_comment_in_negated_comparison: { input: { function f() { return 1 < (!--x + 1); } } expect_exact: 'function f(){return 1 1; } } expect_exact: 'function f(){return!x-- >1}'; } html_comment_after_multiline_comment: { input: { var foo; /* */--> var bar; var foobar; } expect_exact: "var foo;var foobar;" } terser-5.19.2/test/compress/identity.js000066400000000000000000000120571445647217600201420ustar00rootroot00000000000000inline_identity: { options = { inline: true, reduce_vars: true, unused: true, toplevel: true } input: { const id = x => x; console.log(id(1), id(2)); } expect: { console.log(1, 2); } expect_stdout: "1 2" } inline_identity_function: { options = { inline: true, reduce_vars: true, unused: true, toplevel: true } input: { function id(x) { return x }; console.log(id(1), id(2)); } expect: { console.log(1, 2); } expect_stdout: "1 2" } inline_identity_undefined: { options = { inline: true, reduce_vars: true, unused: true, toplevel: true } input: { const id = x => x; console.log(id(), id(undefined)); } expect: { console.log(void 0, void 0); } expect_stdout: "undefined undefined" } inline_identity_extra_params: { options = { inline: true, reduce_vars: true, unused: true, toplevel: true } input: { const id = x => x; console.log(id(1, console.log(2)), id(3, 4)); } expect: { const id = x => x; console.log(id(1, console.log(2)), 3); } expect_stdout: ["2", "1 3"] } inline_identity_higher_order: { options = { inline: true, reduce_vars: true, unused: true, toplevel: true } input: { const id = x => x; const inc = x => x + 1; console.log(id(inc(1)), id(inc)(2)); } expect: { const inc = x => x + 1; console.log(inc(1), inc(2)); } expect_stdout: "2 3" } inline_identity_inline_function: { options = { evaluate: true, inline: true, passes: 3, reduce_vars: true, side_effects: true, unused: true, toplevel: true } input: { const id = x => x; console.log(id(x => x + 1)(1), id((x => x + 1)(2))); } expect: { console.log(2, 3); } expect_stdout: "2 3" } inline_identity_duplicate_arg_var: { options = { inline: true, reduce_vars: true, unused: true, toplevel: true } input: { const id = x => { return x; var x; }; console.log(id(1), id(2)); } expect: { console.log(1, 2); } expect_stdout: "1 2" } inline_identity_inner_ref: { options = { inline: true, reduce_vars: true, unused: true, toplevel: true } input: { const id = a => (function() { return a; })(); const undef = a => (a => a)(); console.log(id(1), id(2), undef(3), undef(4)); } expect: { console.log(1, 2, void 0, void 0); } expect_stdout: "1 2 undefined undefined" } inline_identity_async: { options = { inline: true, reduce_vars: true, unused: true, toplevel: true } input: { const id = x => x; id(async () => await 1)(); id(async x => await console.log(2))(); } expect: { (async () => await 1)(); (async x => await console.log(2))(); } expect_stdout: "2" node_version: ">=8" } inline_identity_regression: { options = { defaults: true } input: { global.id = x => x const foo = ({bar}) => id(bar); console.log(foo({bar: 'PASS'})); } expect_stdout: "PASS" } inline_identity_lose_this: { options = { inline: true, toplevel: true, reduce_vars: true } input: { "use strict"; const id = x => x; const func_bag = { func: function () { return this === undefined ? "PASS" : "FAIL"; } }; func_bag.func2 = function () { return this === undefined ? "PASS" : "FAIL"; }; console.log(id(func_bag.func)()); console.log(id(func_bag.func2)()); } expect: { "use strict"; const id = x => x; const func_bag = { func: function () { return this === void 0 ? "PASS" : "FAIL"; } }; func_bag.func2 = function () { return this === void 0 ? "PASS" : "FAIL"; }; console.log((0, func_bag.func)()); console.log((0, func_bag.func2)()); } expect_stdout: [ "PASS", "PASS" ] } inline_identity_dont_lose_this_when_arg: { options = { inline: true, toplevel: true, reduce_vars: true } input: { "use strict"; const id = x => x; const func_bag = { leak }; leak(id(func_bag.leak)); } expect: { "use strict"; const id = x => x; const func_bag = { leak }; leak(func_bag.leak); } } inline_trivial_fns_unless_arg_is_expansion: { options = { toplevel: true, inline: true, } input: { function n (n) { return n; } (function(...o) { const c=n(...o);console.log(c) })("PASS"); } expect_stdout: "PASS" } terser-5.19.2/test/compress/ie8.js000066400000000000000000000160271445647217600167770ustar00rootroot00000000000000do_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 o===void 0 } } 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-5.19.2/test/compress/if_return.js000066400000000000000000000255561445647217600203160ustar00rootroot00000000000000if_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 (baz === 0) return null; let r; return r = baz > 2 ? 4 : 5, r; } console.log(f(0), f(1), f(3)); } expect_stdout: "null 5 4" } if_return_same_value: { options = { conditionals: true, if_return: true, sequences: true, } input: { function f() { if (foo) { return x(); } if (bar) { return x(); } } function g() { if (foo) { return x(); } if (bar) { return x(); } return x(); } function h() { if (foo) { return x(); } if (bar) { return x(); } return y(); } } expect: { function f() { return (foo || bar) ? x() : void 0 } function g() { return (foo || bar), x() } function h() { return (foo || bar) ? x() : y() } } } issue_t833: { options = { if_return: true, } input: { var a = id(1), object = {PASS: 1}; for (var p in object) { if (a) { test(); continue; function test() {console.log(p)} } } } expect: { var a = id(1), object = {PASS: 1}; for (var p in object) if (a) { test(); continue; function test(){console.log(p)} } } expect_stdout: "PASS" } terser-5.19.2/test/compress/import-meta.js000066400000000000000000000031471445647217600205470ustar00rootroot00000000000000 import_meta_basic: { options = { defaults: true } input: { import.meta import.meta.something import.meta?.something import.meta.url.includes() } expect: { import.meta, import.meta.something, import.meta?.something, import.meta.url.includes() } } propmangle: { mangle = { properties: { keep_quoted: "strict", undeclared: true, debug: true, } } input: { import.meta import.meta.prop1 import.meta["kept"] } expect: { import.meta import.meta._$prop1$_ import.meta["kept"] } } pure_getters: { options = { defaults: true, pure_getters: true, unused: false, } input: { import.meta } expect: { import.meta } } global_defs: { options = { global_defs: { "import.meta.LIT": 123, "@import.meta.OBJ": "{'hello': 123}", "@import.meta.FUNC": "() => false" } } input: { import.meta; leak(import.meta.LIT) leak(import.meta.OBJ) leak(import.meta.FUNC) } expect: { import.meta; leak(123); leak({hello: 123}); leak(() => false); } } global_defs_whole: { options = { defaults: true, global_defs: { "import.meta": { url: "http://example.com", }, } } input: { console.log(import.meta.url); } expect: { console.log("http://example.com"); } } terser-5.19.2/test/compress/inline.js000066400000000000000000000251301445647217600175630ustar00rootroot00000000000000inline_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, collapse_vars: false, unused: true, toplevel: true } input: { 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: { class Baz 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); } } console.log(new Baz(1, "PASS", 3).second()); } expect_stdout: "PASS" } dont_inline_side_effects: { options = { inline: true, toplevel: true } input: { class X extends (console.log("PASS 1"), null) { static [(console.log("PASS 2"), 'prop')] = "PASS 4" } console.log("PASS 3") console.log(X.prop) } expect: { class X extends (console.log("PASS 1"), null) { static [(console.log("PASS 2"), 'prop')] = "PASS 4" } console.log("PASS 3") console.log(X.prop) } expect_stdout: [ "PASS 1", "PASS 2", "PASS 3", "PASS 4" ] node_version: ">=14" } 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()); }; } } inline_into_scope_conflict: { options = { reduce_vars: true, inline: true, unused: true, toplevel: true } input: { var mod = pass const c = function c() { mod() } const b = function b() { for (;;) { c(); break } } ;(function () { var mod = id(mod); b(); })() } expect_stdout: "PASS" } inline_into_scope_conflict_enclosed: { options = { reduce_vars: true, inline: true, unused: true, toplevel: true } input: { global.same_name = "PASS" function $(same_name) { if (same_name) indirection_1(same_name) } function indirection_2() { console.log(same_name) } function indirection_1() { indirection_2() } $("FAIL") } expect_stdout: "PASS" } inline_into_scope_conflict_enclosed_2: { options = { reduce_vars: true, inline: true, unused: true, toplevel: true } input: { global.same_name = () => console.log("PASS") function $(same_name) { console.log(same_name === undefined ? "PASS" : "FAIL") indirection_1(); } function indirection_1() { return indirection_2() } function indirection_2() { for (const x of [1]) { same_name(); return; } } $(); } expect_stdout: [ "PASS", "PASS" ] } issue_1267_inline_breaks_compare_identity: { options = { toplevel: true } input: { class ClassA { } class ClassB { MyA = ClassA; }; console.log(new ClassB().MyA == new ClassB().MyA) } expect_stdout: ["true"] } issue_1267_inline_breaks_compare_identity_2: { options = { toplevel: true } input: { class ClassA { } const objA = { prop: ClassA } const objB = { prop: ClassA } console.log(objA.prop === objB.prop) } expect_stdout: ["true"] } noinline_annotation: { options = { reduce_vars: true, inline: true, toplevel: true } input: { function no_inline() { return 123; } /*#__NOINLINE__*/no_inline(); /*#__NOINLINE__*/no_inline(); } expect: { function no_inline() { return 123; } no_inline(); no_inline(); } } noinline_annotation_2: { options = { reduce_vars: true, inline: true, toplevel: true } input: { /*#__NOINLINE__*/ (() => { external() })() } expect: { (() => { external() })() } } noinline_annotation_3: { options = { reduce_vars: true, inline: true, unused: true } input: { (function() { function foo(val) { return val; } function bar() { var pass = 1; pass = /*@__NOINLINE__*/ foo(pass); window.data = pass; } window.bar = bar; bar(); })(); } expect: { (function() { function foo(val) { return val; } function bar() { var pass = 1; pass = foo(pass); window.data = pass; } window.bar = bar; bar(); })(); } } inline_annotation: { options = { reduce_vars: true, inline: true, toplevel: true, unused: true } input: { function inline() { return external(); } /*#__INLINE__*/inline(); /*#__INLINE__*/inline(); } expect: { external(); external(); } } inline_annotation_2: { options = { toplevel: true, passes: 3, defaults: true } input: { const shouldInline = n => +n; const a = /*@__INLINE__*/ shouldInline("42.0"); const b = /*@__INLINE__*/ shouldInline("abc"); console.log(a, b); } expect: { console.log(42, NaN) } expect_stdout: "42 NaN" } inline_func_with_name_existing_in_block_scope: { options = { toplevel: true, defaults: true } input: { let something = "PASS"; function getSomething() { return something; } function setSomething() { something = { value: 42 }; } function main() { if (typeof somethingElse == "undefined") { const something = getSomething(); console.log(something); } } main(); } expect_stdout: "PASS" } dont_inline_funcs_into_default_param: { options = { toplevel: true, unused: true, inline: true, } input: { "use strict" const getData = (val) => { return {val} } const print = function (data = getData(id("PASS"))) { console.log(data.val); } print(); } expect_stdout: "PASS" } dont_inline_funcs_into_default_param_2: { options = { toplevel: true } input: { "use strict"; const foo = () => 42; const getData = (val) => { return {val} } const print = (data = getData(foo())) => { data.val === 42 && pass(); } print(); } expect_stdout: "PASS" } do_not_repeat_when_variable_larger_than_inlined_node: { options = { toplevel: true, reduce_vars: true, inline: true } mangle = { toplevel: true } input: { const _string_ = "string"; pass(_string_); pass(_string_); pass(_string_); pass(_string_); pass(_string_); } expect: { const s = "string"; pass(s); pass(s); pass(s); pass(s); pass(s); } } inline_using_correct_arguments: { options = { reduce_vars: true, inline: true, passes: 2, toplevel: true, unused: true } input: { function run (s, t) { return s.run(t); } /*#__INLINE__*/ run(a, "foo"); /*#__INLINE__*/ run(a, "bar"); /*#__INLINE__*/ run(a, "123"); } expect: { s = a, t = "foo", s.run(t); var s, t; (function(s, t) { return s.run("bar") })(a); (function(s, t) { return s.run("123") })(a); } } terser-5.19.2/test/compress/issue-1001.js000066400000000000000000000002151445647217600200110ustar00rootroot00000000000000parenthesis_strings_in_parenthesis: { input: { var foo = ('('); a(')'); } expect_exact: 'var foo="(";a(")");' } terser-5.19.2/test/compress/issue-1003.js000066400000000000000000000005151445647217600200160ustar00rootroot00000000000000nullish_coalescing_boolean_expr: { options = { booleans: true, ecma: true, } input: { (function(a, b) { if(!(a ?? b)) throw new Error("Some error"); })() } expect: { (function(a, b) { if(!(a ?? b)) throw new Error("Some error"); })() } }terser-5.19.2/test/compress/issue-1006.js000066400000000000000000000007241445647217600200230ustar00rootroot00000000000000issue_1006: { options = { defaults: true, } input: { function func(foo) { function bar() { return; } let baz = foo(); if (baz !== undefined) { let qux = bar(baz.qux); } } } expect: { function func(foo) { let baz = foo(); if (void 0 !== baz) { baz.qux; } } } } terser-5.19.2/test/compress/issue-1007.js000066400000000000000000000007531445647217600200260ustar00rootroot00000000000000optional_chaining_boolean_expr: { options = { booleans: true, ecma: true, } input: { (function(option) { if (!(option.container?.tagName === "DIV")) throw new Error("Invalid `container` and/or `viewer` option."); })() } expect: { (function(option) { if (option.container?.tagName !== "DIV") throw new Error("Invalid `container` and/or `viewer` option."); })() } }terser-5.19.2/test/compress/issue-1034.js000066400000000000000000000134731445647217600200310ustar00rootroot00000000000000non_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 } } } } non_hoisted_function_after_return_2a: { options = { booleans: true, collapse_vars: false, comparisons: true, conditionals: true, dead_code: true, evaluate: true, hoist_funs: false, if_return: true, join_vars: true, keep_fargs: true, loops: true, passes: 2, side_effects: true, unused: true, } input: { function foo(x) { if (x) { return bar(1); var a = not_called(1); } else { return bar(2); var b = not_called(2); } var c = bar(3); function bar(x) { return 7 - x; } function nope() {} return b || c; } } expect: { function foo(x) { return bar(x ? 1 : 2); function bar(x) { return 7 - x; } } } } 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; } } } } 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" } non_hoisted_function_after_return_2a_strict: { options = { booleans: true, collapse_vars: false, comparisons: true, conditionals: true, dead_code: true, evaluate: true, hoist_funs: false, if_return: true, join_vars: true, keep_fargs: true, loops: true, passes: 2, side_effects: true, unused: true, } input: { "use strict"; function foo(x) { if (x) { return bar(1); var a = not_called(1); } else { return bar(2); var b = not_called(2); } var c = bar(3); function bar(x) { return 7 - x; } function nope() {} return b || c; } console.log(foo(0), foo(1)); } expect: { "use strict"; function foo(x) { return bar(x ? 1 : 2); function bar(x) { return 7 - x; } } console.log(foo(0), foo(1)); } expect_stdout: "5 6" } 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" } terser-5.19.2/test/compress/issue-1041.js000066400000000000000000000012201445647217600200120ustar00rootroot00000000000000const_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-5.19.2/test/compress/issue-1043.js000066400000000000000000000011531445647217600200210ustar00rootroot00000000000000issue_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 (end == null) { end = start; start = 0; } for (let i = start; i < end; i += step) yield i; } } } terser-5.19.2/test/compress/issue-1044.js000066400000000000000000000003511445647217600200210ustar00rootroot00000000000000issue_1044: { options = { evaluate: true, conditionals: true }; input: { const mixed = Base ? class extends Base {} : class {} } expect: { const mixed = Base ? class extends Base {} : class {} } } terser-5.19.2/test/compress/issue-1052.js000066400000000000000000000062151445647217600200250ustar00rootroot00000000000000multiple_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-5.19.2/test/compress/issue-1105.js000066400000000000000000000155541445647217600200320ustar00rootroot00000000000000with_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-5.19.2/test/compress/issue-12.js000066400000000000000000000024631445647217600176610ustar00rootroot00000000000000keep_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-5.19.2/test/compress/issue-1202.js000066400000000000000000000017271445647217600200250ustar00rootroot00000000000000mangle_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-5.19.2/test/compress/issue-1212.js000066400000000000000000000033751445647217600200270ustar00rootroot00000000000000issue_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-5.19.2/test/compress/issue-1248.js000066400000000000000000000021531445647217600200310ustar00rootroot00000000000000brackets_with_const: { options = { defaults: false, }; input: { if (a) { var b; var c; const d = d(); const e = e(); } } expect: { if(a){var b;var c;const d=d();const e=e()} } } brackets_with_const_defaults: { options = { defaults: true, }; input: { if (a) { var b; var c; const d = d(); const e = e(); } } expect: { if(a){var b,c;const d=d(),e=e()} } } brackets_with_const_let_mix_0: { options = { defaults: true, }; input: { if (a) { var b; var c; const d = d(); let e = e(); } } expect: { if(a){var b,c;const d=d();let e=e()} } } brackets_with_const_let_mix_1: { options = { defaults: true, }; input: { if (a) { let b = b(); var c; var d; const e = e(); } } expect: { if(a){let b=b();var c,d;const e=e()} } } terser-5.19.2/test/compress/issue-126.js000066400000000000000000000015071445647217600177450ustar00rootroot00000000000000concatenate_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-5.19.2/test/compress/issue-1261.js000066400000000000000000000053101445647217600200220ustar00rootroot00000000000000pure_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(); } } 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(); } } terser-5.19.2/test/compress/issue-1275.js000066400000000000000000000024351445647217600200340ustar00rootroot00000000000000string_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-5.19.2/test/compress/issue-1321.js000066400000000000000000000021111445647217600200130ustar00rootroot00000000000000issue_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-5.19.2/test/compress/issue-143.js000066400000000000000000000021111445647217600177340ustar00rootroot00000000000000/** * 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 */ transformation_sort_order_equal: { options = { comparisons: true, } input: { (a = parseInt('100')) == a } expect: { (a = parseInt('100')) == a } } transformation_sort_order_unequal: { options = { comparisons: true, } input: { (a = parseInt('100')) != a } expect: { (a = parseInt('100')) != a } } transformation_sort_order_lesser_or_equal: { options = { comparisons: true, } input: { (a = parseInt('100')) <= a } expect: { (a = parseInt('100')) <= a } } transformation_sort_order_greater_or_equal: { options = { comparisons: true, } input: { (a = parseInt('100')) >= a } expect: { (a = parseInt('100')) >= a } } terser-5.19.2/test/compress/issue-1431.js000066400000000000000000000063001445647217600200210ustar00rootroot00000000000000level_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(r) { return r * r; } 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(r) { return r * r; } 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(t) { return t * t; } return function() { function n(t) { return t * t; } 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(u) { return function() { function r(u) { return u * u; } return [ function() { function t(u) { return u * u; } return t; }, function() { function n(u) { return u * u; } return u(n); } ]; }; } } } terser-5.19.2/test/compress/issue-1443.js000066400000000000000000000024021445647217600200230ustar00rootroot00000000000000// 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(r) { return r * r; } return a ? b : c ? d : r; }; } } } terser-5.19.2/test/compress/issue-1446.js000066400000000000000000000034221445647217600200310ustar00rootroot00000000000000typeof_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 = typeof b != "undefined"; b = a !== void 0; var c = d.e !== void 0; 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 = typeof b != "undefined"; b = a !== void 0; var c = typeof d.e != "undefined"; 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 n===void 0}" } 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 r===void 0}" } terser-5.19.2/test/compress/issue-1447.js000066400000000000000000000015561445647217600200400ustar00rootroot00000000000000else_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-5.19.2/test/compress/issue-1466.js000066400000000000000000000244721445647217600200430ustar00rootroot00000000000000same_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-5.19.2/test/compress/issue-1569.js000066400000000000000000000005311445647217600200350ustar00rootroot00000000000000inner_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-5.19.2/test/compress/issue-1588.js000066400000000000000000000035561445647217600200500ustar00rootroot00000000000000screw_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-5.19.2/test/compress/issue-1609.js000066400000000000000000000021101445647217600200230ustar00rootroot00000000000000chained_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-5.19.2/test/compress/issue-1639.js000066400000000000000000000032341445647217600200360ustar00rootroot00000000000000 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-5.19.2/test/compress/issue-1656.js000066400000000000000000000017661445647217600200450ustar00rootroot00000000000000f7: { 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-5.19.2/test/compress/issue-1673.js000066400000000000000000000062721445647217600200410ustar00rootroot00000000000000side_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-5.19.2/test/compress/issue-1704.js000066400000000000000000000210731445647217600200300ustar00rootroot00000000000000mangle_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-5.19.2/test/compress/issue-1733.js000066400000000000000000000042051445647217600200300ustar00rootroot00000000000000function_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-5.19.2/test/compress/issue-1750.js000066400000000000000000000015431445647217600200310ustar00rootroot00000000000000case_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; if (true === (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; if (0 === a) a = 3; console.log(a, b); } expect_stdout: "3 1" } terser-5.19.2/test/compress/issue-1770.js000066400000000000000000000035121445647217600200310ustar00rootroot00000000000000mangle_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-5.19.2/test/compress/issue-1787.js000066400000000000000000000005301445647217600200360ustar00rootroot00000000000000unary_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-5.19.2/test/compress/issue-1833.js000066400000000000000000000045771445647217600200450ustar00rootroot00000000000000iife_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-5.19.2/test/compress/issue-1943.js000066400000000000000000000005721445647217600200360ustar00rootroot00000000000000operator: { 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-5.19.2/test/compress/issue-2001.js000066400000000000000000000122711445647217600200170ustar00rootroot00000000000000export_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-5.19.2/test/compress/issue-203.js000066400000000000000000000023741445647217600177440ustar00rootroot00000000000000 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: 2015 } beautify = { ecma: 2015 } 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: 2015, } beautify = { ecma: 2015 } 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-5.19.2/test/compress/issue-208.js000066400000000000000000000017641445647217600177530ustar00rootroot00000000000000do_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; } } terser-5.19.2/test/compress/issue-22.js000066400000000000000000000005341445647217600176570ustar00rootroot00000000000000return_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-5.19.2/test/compress/issue-229.js000066400000000000000000000002541445647217600177470ustar00rootroot00000000000000template_strings: { input: { var x = {}; var y = {...x}; y.hello = 'world'; } expect_exact: "var x={};var y={...x};y.hello=\"world\";" }terser-5.19.2/test/compress/issue-2652.js000066400000000000000000000007351445647217600200350ustar00rootroot00000000000000insert_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-5.19.2/test/compress/issue-267.js000066400000000000000000000003221445647217600177450ustar00rootroot00000000000000issue_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-5.19.2/test/compress/issue-269.js000066400000000000000000000030411445647217600177500ustar00rootroot00000000000000issue_269_1: { options = { unsafe: true, unsafe_math: 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"); } } terser-5.19.2/test/compress/issue-2719.js000066400000000000000000000011431445647217600200330ustar00rootroot00000000000000warn: { 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); } } terser-5.19.2/test/compress/issue-281.js000066400000000000000000000234151445647217600177510ustar00rootroot00000000000000collapse_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-5.19.2/test/compress/issue-2871.js000066400000000000000000000012131445647217600200300ustar00rootroot00000000000000comparison_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: { a == null; a != null; a === void 0; a !== void 0; null == a; null != a; void 0 === a; void 0 !== a; null == a; null != a; void 0 === a; void 0 !== a; } } terser-5.19.2/test/compress/issue-2989.js000066400000000000000000000006351445647217600200510ustar00rootroot00000000000000inline_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-5.19.2/test/compress/issue-368.js000066400000000000000000000024711445647217600177560ustar00rootroot00000000000000collapse: { 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 (typeof b === 'function' ? b() : b) !== void 0 && c(); } function f2(b) { return 'stirng' == typeof (typeof (b = c()) === 'function' ? 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-5.19.2/test/compress/issue-417.js000066400000000000000000000016761445647217600177570ustar00rootroot00000000000000test_unexpected_crash: { prepend_code: "x();" reminify: false input: { function x() { var getsInlined = function () { var leakedVariable1 = 3; var leakedVariable2 = 1 + 2 * leakedVariable1; console.log(leakedVariable1); console.log(leakedVariable2); }; var getsDropped = getsInlined(); } } expect_stdout: [ "3", "7" ] } test_unexpected_crash_2: { prepend_code: "x();" reminify: false input: { function x() { var getsInlined = function () { var leakedVariable1 = 3; var leakedVariable2 = 1 + leakedVariable1[0]; console.log(leakedVariable1); console.log(leakedVariable2); }; var getsDropped = getsInlined(); } } expect_stdout: [ "3", "NaN" ] } terser-5.19.2/test/compress/issue-427.js000066400000000000000000000011251445647217600177450ustar00rootroot00000000000000wrap_func_args: { options = { negate_iife: false, } beautify = { wrap_func_args: true, } input: { console.log(function() { return "test"; }, () => null); } expect_exact: 'console.log((function(){return"test"}),(()=>null));' } no_wrap_func_args: { options = { negate_iife: false, } beautify = { wrap_func_args: false, } input: { console.log(function() { return "test"; }, () => null); } expect_exact: 'console.log(function(){return"test"},()=>null);' } terser-5.19.2/test/compress/issue-44.js000066400000000000000000000011611445647217600176600ustar00rootroot00000000000000issue_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-5.19.2/test/compress/issue-59.js000066400000000000000000000010471445647217600176710ustar00rootroot00000000000000keep_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-5.19.2/test/compress/issue-597.js000066400000000000000000000062511445647217600177620ustar00rootroot00000000000000NaN_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: '([].length===0)%(1/0)?console.log("PASS"):console.log("FAIL");' expect_stdout: "PASS" } terser-5.19.2/test/compress/issue-611.js000066400000000000000000000005051445647217600177410ustar00rootroot00000000000000issue_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-5.19.2/test/compress/issue-637.js000066400000000000000000000006241445647217600177530ustar00rootroot00000000000000wrongly_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-5.19.2/test/compress/issue-640.js000066400000000000000000000150541445647217600177500ustar00rootroot00000000000000cond_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-5.19.2/test/compress/issue-747.js000066400000000000000000000013641445647217600177570ustar00rootroot00000000000000dont_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-5.19.2/test/compress/issue-751.js000066400000000000000000000010551445647217600177470ustar00rootroot00000000000000negate_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-5.19.2/test/compress/issue-782.js000066400000000000000000000010521445647217600177500ustar00rootroot00000000000000remove_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-5.19.2/test/compress/issue-892.js000066400000000000000000000014651445647217600177620ustar00rootroot00000000000000dont_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-5.19.2/test/compress/issue-913.js000066400000000000000000000005651445647217600177540ustar00rootroot00000000000000keep_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-5.19.2/test/compress/issue-926.js000066400000000000000000000003521445647217600177520ustar00rootroot00000000000000template_strings: { input: { foo( `${contents}`, `${text}` ); } expect_exact: "foo(`${contents}`,`${text}`);" } terser-5.19.2/test/compress/issue-973.js000066400000000000000000000047261445647217600177650ustar00rootroot00000000000000this_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-5.19.2/test/compress/issue-976.js000066400000000000000000000052741445647217600177670ustar00rootroot00000000000000eval_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-5.19.2/test/compress/issue-979.js000066400000000000000000000044311445647217600177640ustar00rootroot00000000000000issue979_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, lhs_constants: 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, lhs_constants: 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-5.19.2/test/compress/issue-t120.js000066400000000000000000000111271445647217600201220ustar00rootroot00000000000000issue_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/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-5.19.2/test/compress/issue-t1371.js000066400000000000000000000023531445647217600202140ustar00rootroot00000000000000issue_t1321: { options = { } input: { (foo?.bar()).baz = true; ((foo?.bar())).baz = true; (foo?.bar)(); (foo?.bar).baz; new (foo?.bar)(); (foo?.())(); (foo?.()).bar; new (foo?.())(); (foo?.bar()); (foo?.bar) + 42; (foo?.bar), 42; } expect: { (foo?.bar()).baz = true; (foo?.bar()).baz = true; (foo?.bar)(); (foo?.bar).baz; new (foo?.bar)(); (foo?.())(); (foo?.()).bar; new (foo?.())(); foo?.bar(); foo?.bar + 42; foo?.bar, 42; } } issue_t1321_call_parentheses: { options = { } input: { (function(o) { console.log(o.f("FAIL"), (o.f)("FAIL"), (0, o.f)(42)); console.log(o?.f("FAIL"), (o?.f)("FAIL"), (0, o?.f)(42)); })({ a: "PASS", f(b) { return this.a || b; }, }); } expect_exact: '(function(o){console.log(o.f("FAIL"),o.f("FAIL"),(0,o.f)(42));console.log(o?.f("FAIL"),(o?.f)("FAIL"),(0,o?.f)(42))})({a:"PASS",f(b){return this.a||b}});' expect_stdout: [ "PASS PASS 42", "PASS PASS 42", ] } terser-5.19.2/test/compress/issue-t1372.js000066400000000000000000000011071445647217600202110ustar00rootroot00000000000000 issue_t1372_maintain_this_binding: { options = { side_effects: true, } input: { (function(o) { console.log((0, o.f)("PASS"), (0, o?.f)("PASS")); })({ a: "FAIL", f(b) { return this.a || b; }, }); } expect: { (function(o) { console.log((0, o.f)("PASS"), (0, o?.f)("PASS")); })({ a: "FAIL", f(b) { return this.a || b; }, }); } expect_stdout: [ "PASS PASS", ] } terser-5.19.2/test/compress/issue-t292.js000066400000000000000000000041111445647217600201270ustar00rootroot00000000000000no_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 = test * 2; return console.log(problem), g[problem]; }(function(arg) { return problem(arg); }("a"))); } expect_stdout: [ "0", "a", ] } terser-5.19.2/test/compress/issue-t50.js000066400000000000000000001063251445647217600200510ustar00rootroot00000000000000issue_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-5.19.2/test/compress/issue_1014.js000066400000000000000000000044701445647217600201060ustar00rootroot00000000000000ternary_and_private_fields: { options = { conditionals: true, } input: { class A { #fail = false; #pass = "PASS"; print() { console.log(this.#fail ? this.#fail : this.#pass); } } new A().print(); } expect: { class A { #fail = false; #pass = "PASS"; print() { console.log(this.#fail ? this.#fail : this.#pass); } } new A().print(); } expect_stdout: "PASS" } ternary_and_private_public_fields: { options = { conditionals: true, } input: { class A { fail = false; #pass = "PASS"; print() { console.log(this.fail ? this.fail : this.#pass); } } new A().print(); } expect: { class A { fail = false; #pass = "PASS"; print() { console.log(this.fail ? this.fail : this.#pass); } } new A().print(); } expect_stdout: "PASS" } ternary_and_private_methods: { options = { conditionals: true, } input: { class A { #fail() { return false; } get #pass() { return "PASS"; } print() { console.log(this.#fail() ? this.#fail() : this.#pass); } } new A().print(); } expect: { class A { #fail() { return false; } get #pass() { return "PASS"; } print() { console.log(this.#fail() ? this.#fail() : this.#pass); } } new A().print(); } expect_stdout: "PASS" } ternary_and_private_static_fields: { options = { conditionals: true, } input: { class A { static #fail = false; static #pass = "PASS"; print() { console.log(A.#fail ? A.#fail : A.#pass); } } new A().print(); } expect: { class A { static #fail = false; static #pass = "PASS"; print() { console.log(A.#fail ? A.#fail : A.#pass); } } new A().print(); } expect_stdout: "PASS" } terser-5.19.2/test/compress/issue_999.js000066400000000000000000000015501445647217600200470ustar00rootroot00000000000000switch_case_and_private_fields: { options = { switches: true, dead_code: true, } input: { class A { #a = "FAIL"; #b = "PASS"; print(variant) { switch (variant) { case 1: return this.#a; case 2: return this.#b; } } } console.log(new A().print(2)); } expect: { class A { #a = "FAIL"; #b = "PASS"; print(variant) { switch (variant) { case 1: return this.#a; case 2: return this.#b; } } } console.log(new A().print(2)); } expect_stdout: "PASS" } terser-5.19.2/test/compress/join-vars.js000066400000000000000000000035671445647217600202270ustar00rootroot00000000000000only_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'; } } join_vars_lose_other_var: { options = { defaults: false, inline: true, reduce_vars: true, unused: true, side_effects: true, join_vars: true, } input: { global.exports = { set a(a) { console.log(a().get_b()) const incremented = a() incremented.inc_b() console.log(incremented.get_b()) } }; (function (factory) { factory(exports) })((function (exports) { exports.a = function () { var b = "PASS", _this = {}; _this.get_b = function () { return b; } _this.inc_b = function () { b += "PASS"; } return _this; }; })); } expect_stdout: [ "PASS", "PASSPASS" ] } terser-5.19.2/test/compress/keep_names.js000066400000000000000000000065261445647217600204240ustar00rootroot00000000000000drop_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"; } } } } keep_var_fnames: { mangle = { keep_fnames: true, toplevel: true, } input: { const foo = function () { return "barfoo" } const bar = () => "foobar" } expect: { const foo = function () { return "barfoo" } const bar = () => "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); var aElement = () => {}; array.map(aElement); array.map(aElement); var bElement = function () {}; array.map(bElement); array.map(bElement); } } expect: { function foo() { var a = []; a.map(function() {}); a.map(function barElement() {}); var aElement = () => {}; a.map(aElement); a.map(aElement); var bElement = function () {}; a.map(bElement); a.map(bElement); } } } keep_some_classnames: { mangle = { keep_classnames: /Element$/, } input: { function foo() { class Bar {} class BarElement {} } } expect: { function foo() { class s {} class BarElement {} } } } keep_fnames_and_avoid_collisions: { mangle = { keep_fnames: true } input: { global.t = 'ttttttttttttttttttttt'; (function testBug() { var param1 = 'PASS' return () => { console.log(param1) var t = function () {}; return t; }; })()() } expect_stdout: "PASS" } terser-5.19.2/test/compress/keep_quoted_strict.js000066400000000000000000000033431445647217600222040ustar00rootroot00000000000000keep_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-5.19.2/test/compress/labels.js000066400000000000000000000065441445647217600175570ustar00rootroot00000000000000labels_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-5.19.2/test/compress/lhs_constants.js000066400000000000000000000021431445647217600211660ustar00rootroot00000000000000lhs_constants: { options = { lhs_constants: true, } input: { function test(a, b, c, d) { var x; x = a == 42; x = a === 42; x = a != 42; x = a !== 42; x = a * 42; x = a & 42; x = a | 42; x = a ^ 42; x = a == 42n; x = a == "moo"; x = a == null; x = a == ~42; x = a == void 0; x = a == +42; x = a == /moo/; a & 42 & 2; a == 42 & 2; } } expect: { function test(a, b, c, d) { var x; x = 42 == a; x = 42 === a; x = 42 != a; x = 42 !== a; x = 42 * a; x = 42 & a; x = 42 | a; x = 42 ^ a; x = 42n == a; x = "moo" == a; x = null == a; x = ~42 == a; x = void 0 == a; x = +42 == a; x = a == /moo/; 42 & a & 2; 42 == a & 2; } } } terser-5.19.2/test/compress/logical-assignment.js000066400000000000000000000075261445647217600220760ustar00rootroot00000000000000prematurely_evaluate_assignment: { options = { toplevel: true, reduce_vars: true, evaluate: true, unused: true } input: { var or = null var null_coalesce = null var and = 'FAIL' or ||= 'PASS' null_coalesce ??= 'PASS' and &&= 'PASS' console.log(or, null_coalesce, and) } expect: { var or = null var null_coalesce = null var and = 'FAIL' or ||= 'PASS' null_coalesce ??= 'PASS' and &&= 'PASS' console.log(or, null_coalesce, and) } expect_stdout: ["PASS PASS PASS"] node_version = ">=15" } prematurely_evaluate_assignment_inv: { options = { toplevel: true, reduce_vars: true, evaluate: true, unused: true } input: { var or = 'PASS' var null_coalesce = 'PASS' var and = 'FAIL' or ||= 'FAIL' null_coalesce ??= 'FAIL' and &&= 'PASS' console.log(or, null_coalesce, and) } expect: { var or = 'PASS' var null_coalesce = 'PASS' var and = 'FAIL' or ||= 'FAIL' null_coalesce ??= 'FAIL' and &&= 'PASS' console.log(or, null_coalesce, and) } expect_stdout: ["PASS PASS PASS"] node_version = ">=15" } assign_in_conditional_part: { options = { toplevel: true, evaluate: true, reduce_vars: true, unused: true } input: { var status = 'PASS' var nil = null var nil_prop = { prop: null } nil &&= console.log(status = 'FAIL') nil_prop.prop &&= console.log(status = 'FAIL') console.log(status) } expect: { var status = 'PASS'; var nil = null; nil &&= console.log(status = 'FAIL'); ({prop: null}).prop &&= console.log(status = 'FAIL'); console.log(status); } expect_stdout: "PASS" node_version = ">=15" } assign_in_conditional_part_reused: { options = { toplevel: true, evaluate: true, reduce_vars: true, unused: true } input: { var status = 'PASS' var nil = null var nil_prop = { prop: null } nil &&= console.log(status = 'FAIL') nil_prop.prop &&= console.log(status = 'FAIL') console.log(status, nil, nil_prop.prop) } expect: { var status = 'PASS' var nil = null var nil_prop = { prop: null } nil &&= console.log(status = 'FAIL') nil_prop.prop &&= console.log(status = 'FAIL') console.log(status, nil, nil_prop.prop) } expect_stdout: "PASS null null" node_version = ">=15" } assignment_in_left_part: { options = { toplevel: true, evaluate: true, reduce_vars: true, unused: true } input: { var status = 'FAIL' var x = {} x[status = 'PASS'] ||= 1 console.log(status) } /* expect: { } */ expect_stdout: "PASS" node_version = ">=15" } assignment_in_left_part_2: { options = { toplevel: true, evaluate: true, reduce_vars: true, unused: true } input: { var status = 'FAIL' var x = {'PASS': false} x[status = id('PASS')] ||= 'PASS' console.log(status, x.PASS) } expect: { var status; var x = {'PASS': false} x[status = id('PASS')] ||= 'PASS' console.log(status, x.PASS) } expect_stdout: "PASS PASS" node_version = ">=15" } logical_assignment_not_always_happens: { options = { defaults: true, toplevel: true } input: { let result = 'PASS' let x; x &&= result = 'FAIL' console.log(result) } expect_stdout: "PASS" node_version: ">=15" } terser-5.19.2/test/compress/loops.js000066400000000000000000000326141445647217600174460ustar00rootroot00000000000000while_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); } } // Avoid for turning into for..in 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;);' } in_parenthesis_3: { input: { for (var x = a => (b in c);0;); } expect_exact: 'for(var x=(a=>b in c);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" } issue_t1234: { options = {} input: { for ({ x: 0 }.x of [1, 2]) console.log(123); } expect: { for ({ x: 0 }.x of [1, 2]) console.log(123); } expect_stdout: ["123", "123"] } terser-5.19.2/test/compress/mangleprops-computed.js000066400000000000000000000255251445647217600224620ustar00rootroot00000000000000computed_props_keep_quoted_inlined_sub_1: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = '_foo'; let o = { [prop]: 'bar' }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } computed_props_keep_quoted_inlined_sub_2: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = '_foo'; let o = { [prop]() { return 'bar' } }; console.log(o[id('_foo')]()); } expect_stdout: 'bar' } computed_props_keep_quoted_inlined_sub_3: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = '_foo'; let o = { get [prop]() { return 'bar' } }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } computed_props_keep_quoted_inlined_sub_4: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = '_foo'; let o = class { static [prop] = 'bar' }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } computed_props_keep_quoted_inlined_sub_5: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = '_foo'; let o = class { static [prop]() { return 'bar' } }; console.log(o[id('_foo')]()); } expect_stdout: 'bar' } computed_props_keep_quoted_inlined_sub_6: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = '_foo'; let o = class { static get [prop]() { return 'bar' } }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } computed_props_keep_quoted_inlined_sub_7: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = '_foo'; let o = new class { [prop] = 'bar' }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } computed_props_keep_quoted_inlined_sub_8: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = '_foo'; let o = new class { [prop]() { return 'bar' } }; console.log(o[id('_foo')]()); } expect_stdout: 'bar' } computed_props_keep_quoted_inlined_sub_9: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = '_foo'; let o = new class { get [prop]() { return 'bar' } }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } computed_props_keep_quoted_inlined_sub_10: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = '_foo'; let { [prop]: val } = { [id('_foo')]: 'bar' }; console.log(val); } expect_stdout: 'bar' } no_computed_props_keep_quoted_inlined_sub_1: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = '_foo'; let o = { [prop]: 'bar' }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } no_computed_props_keep_quoted_inlined_sub_2: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = '_foo'; let o = { [prop]() { return 'bar' } }; console.log(o[id('_foo')]()); } expect_stdout: 'bar' } no_computed_props_keep_quoted_inlined_sub_3: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = '_foo'; let o = { get [prop]() { return 'bar' } }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } no_computed_props_keep_quoted_inlined_sub_4: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = '_foo'; let o = class { static [prop] = 'bar' }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } no_computed_props_keep_quoted_inlined_sub_5: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = '_foo'; let o = class { static [prop]() { return 'bar' } }; console.log(o[id('_foo')]()); } expect_stdout: 'bar' } no_computed_props_keep_quoted_inlined_sub_6: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = '_foo'; let o = class { static get [prop]() { return 'bar' } }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } no_computed_props_keep_quoted_inlined_sub_7: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = '_foo'; let o = new class { [prop] = 'bar' }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } no_computed_props_keep_quoted_inlined_sub_8: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = '_foo'; let o = new class { [prop]() { return 'bar' } }; console.log(o[id('_foo')]()); } expect_stdout: 'bar' } no_computed_props_keep_quoted_inlined_sub_9: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = '_foo'; let o = new class { get [prop]() { return 'bar' } }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } no_computed_props_keep_quoted_inlined_sub_10: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = '_foo'; let { [prop]: val } = { [id('_foo')]: 'bar' }; console.log(val); } expect_stdout: 'bar' } no_computed_props_keep_quoted_property_access_sub: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = 'foo_'; let o = { [id('foo_')]: 'bar' }; console.log(o[prop]); } expect_stdout: 'bar' } computed_props_keep_quoted_property_access_sub: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = 'foo_'; let o = { [id('foo_')]: 'bar' }; console.log(o[prop]); } expect_stdout: 'bar' } no_computed_props_keep_quoted_optional_property_access_sub: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = 'foo_'; let o = { [id('foo_')]: 'bar' }; console.log(o?.[prop]); } expect_stdout: 'bar' } computed_props_keep_quoted_optional_property_access_sub: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: true, }, } input: { let prop = 'foo_'; let o = { [id('foo_')]: 'bar' }; console.log(o?.[prop]); } expect_stdout: 'bar' } terser-5.19.2/test/compress/mangleprops-key-annotation.js000066400000000000000000000033401445647217600235710ustar00rootroot00000000000000key_annotation_negative_case: { options = { defaults: false, inline: false, }; mangle = { properties: true, }; input: { function lookup(object, key) { return object[key]; } lookup({ someprop: "bar" }, "someprop"); } expect: { function lookup(o, p) { return o[p]; } lookup({ o: "bar" }, "someprop"); } } key_annotation_basic_use: { options = { defaults: false, inline: false, }; mangle = { properties: true, }; input: { function lookup(object, key) { return object[key]; } lookup({ someprop: "bar" }, /*@__KEY__*/ "someprop"); } expect: { function lookup(o,p){ return o[p] } lookup({o:"bar"},"o"); } } key_annotation_in_operator: { options = { defaults: false, inline: false, }; mangle = { properties: true, }; input: { const object = { someprop: "bar", o: true} "someprop" in object; /*@__KEY__*/ "someprop" in object; } expect: { const object={o:"bar", p : true}; "o"in object; "o"in object; } } key_annotation_in_operator_tricky_case: { options = { defaults: false, inline: false, }; mangle = { properties: true, }; input: { // By default someprop mangles to "o", add key "o" to try and trip up the mangler const object = { someprop: "bar", o: true} "someprop" in object; /*@__KEY__*/ "someprop" in object; } expect: { const object={o:"bar", p: true}; "o"in object; "o"in object; } } terser-5.19.2/test/compress/mangleprops-mangleprop-annotation.js000066400000000000000000000144161445647217600251530ustar00rootroot00000000000000mangleprop_annotation: { options = { toplevel: true, }; mangle = { properties: { only_annotated: true, }, }; input: { class Foo { /*@__MANGLE_PROP__*/ prop = "prop" /*@__MANGLE_PROP__*/ static static_prop = "static_prop" /*@__MANGLE_PROP__*/ meth() {return "meth"} /*@__MANGLE_PROP__*/ async meth2() {} /*@__MANGLE_PROP__*/ async *meth3() {} /*@__MANGLE_PROP__*/ *gen() { return "gen" } } const foo = { /*@__MANGLE_PROP__*/ prop: "prop", /*@__MANGLE_PROP__*/ meth() {return "meth"}, /*@__MANGLE_PROP__*/ async meth2() {}, /*@__MANGLE_PROP__*/ async *meth3() {}, /*@__MANGLE_PROP__*/ *gen() { return "gen" }, } console.log(new Foo().prop, foo.prop); console.log(new Foo().meth(), foo.meth()); console.log(new Foo().gen().next().value, foo.gen().next().value); } expect_stdout: [ "prop prop", "meth meth", "gen gen", ] } mangleprop_annotation_partial: { options = { toplevel: true, }; mangle = { properties: { only_annotated: true, }, }; input: { class Foo { /*@__MANGLE_PROP__*/ manglethis = "manglethis" manglethistoo = "manglethistoo" dontmanglethis = "dontmanglethis" } const foo = { manglethis: "manglethis", /*@__MANGLE_PROP__*/ manglethistoo: "manglethistoo", dontmanglethis: "dontmanglethis" } console.log(new Foo().manglethis, foo.manglethis); console.log(new Foo().manglethistoo, foo.manglethistoo); console.log(new Foo().dontmanglethis, foo.dontmanglethis); } expect: { class Foo { /*@__MANGLE_PROP__*/ o = "manglethis" t = "manglethistoo" dontmanglethis = "dontmanglethis" } const foo = { o: "manglethis", /*@__MANGLE_PROP__*/ t: "manglethistoo", dontmanglethis: "dontmanglethis" } console.log(new Foo().o, foo.o); console.log(new Foo().t, foo.t); console.log(new Foo().dontmanglethis, foo.dontmanglethis); } expect_stdout: [ "manglethis manglethis", "manglethistoo manglethistoo", "dontmanglethis dontmanglethis", ] } mangleprop_annotation_wrongregex: { options = { toplevel: true, }; mangle = { properties: { regex: /matchedbyregex/ }, }; input: { class Foo { /*@__MANGLE_PROP__*/ manglethis = "manglethis" manglethistoo = "manglethistoo" dontmanglethis = "dontmanglethis" matchedbyregex = "matchedbyregex" } const foo = { manglethis: "manglethis", /*@__MANGLE_PROP__*/ manglethistoo: "manglethistoo", dontmanglethis: "dontmanglethis", matchedbyregex: "matchedbyregex", } console.log(new Foo().manglethis, foo.manglethis); console.log(new Foo().manglethistoo, foo.manglethistoo); console.log(new Foo().dontmanglethis, foo.dontmanglethis); console.log(new Foo().matchedbyregex, foo.matchedbyregex); } expect: { class Foo { /*@__MANGLE_PROP__*/ o = "manglethis" t = "manglethistoo" dontmanglethis = "dontmanglethis" l = "matchedbyregex" } const foo = { o: "manglethis", /*@__MANGLE_PROP__*/ t: "manglethistoo", dontmanglethis: "dontmanglethis", l: "matchedbyregex", } console.log(new Foo().o, foo.o); console.log(new Foo().t, foo.t); console.log(new Foo().dontmanglethis, foo.dontmanglethis); console.log(new Foo().l, foo.l); } expect_stdout: [ "manglethis manglethis", "manglethistoo manglethistoo", "dontmanglethis dontmanglethis", "matchedbyregex matchedbyregex", ] } mangleprop_annotation_and_key: { options = { toplevel: true, }; mangle = { properties: { only_annotated: true }, }; input: { const object = { /**@__MANGLE_PROP__*/someprop: "ppppppppp", o: 'o', } "someprop" in object; /*@__KEY__*/"someprop" in object; object.hasOwnProperty("someprop"); object.hasOwnProperty(/*@__KEY__*/"someprop"); console.log(Object.values(object)); } expect: { const object = { p: "ppppppppp", o: 'o', } "p" in object; /*@__KEY__*/"p" in object; object.hasOwnProperty("someprop"); object.hasOwnProperty(/*@__KEY__*/"p"); console.log(Object.values(object)); } expect_stdout: true } mangleprop_annotation_in_propassign: { options = { toplevel: true, }; mangle = { properties: { only_annotated: true }, }; input: { /*@__MANGLE_PROP__*/ this.keepthis.manglethis = "manglethis"; /*@__MANGLE_PROP__*/ this.keepthis.manglethis = "manglethis"; (/*@__MANGLE_PROP__*/ this.manglethis_).keepthis_ = "manglethis_"; (/*@__MANGLE_PROP__*/ this.manglethis_).keepthis_ = "manglethis_"; /*@__MANGLE_PROP__*/ this.keepthis__["manglethis__"] = "manglethis__"; /*@__MANGLE_PROP__*/ this.keepthis__["manglethis__"] = "manglethis__"; (/*@__MANGLE_PROP__*/ this["manglethis___"]).keepthis___ = "manglethis___"; (/*@__MANGLE_PROP__*/ this["manglethis___"]).keepthis___ = "manglethis___"; } expect: { this.keepthis.h = "manglethis"; this.keepthis.h = "manglethis"; this.i.keepthis_ = "manglethis_"; this.i.keepthis_ = "manglethis_"; this.keepthis__["t"] = "manglethis__"; this.keepthis__["t"] = "manglethis__"; this["_"].keepthis___ = "manglethis___"; this["_"].keepthis___ = "manglethis___"; } } mangleprop_annotation_in_prop: { options = { toplevel: true, }; mangle = { properties: { only_annotated: true }, }; input: { /*@__MANGLE_PROP__*/ this.keepthis.manglethis; } expect: { this.keepthis.h; } } terser-5.19.2/test/compress/mangleprops-strict-computed.js000066400000000000000000000256651445647217600237750ustar00rootroot00000000000000computed_props_keep_quoted_inlined_sub_1: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = '_foo'; let o = { [prop]: 'bar' }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } computed_props_keep_quoted_inlined_sub_2: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = '_foo'; let o = { [prop]() { return 'bar' } }; console.log(o[id('_foo')]()); } expect_stdout: 'bar' } computed_props_keep_quoted_inlined_sub_3: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = '_foo'; let o = { get [prop]() { return 'bar' } }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } computed_props_keep_quoted_inlined_sub_4: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = '_foo'; let o = class { static [prop] = 'bar' }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } computed_props_keep_quoted_inlined_sub_5: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = '_foo'; let o = class { static [prop]() { return 'bar' } }; console.log(o[id('_foo')]()); } expect_stdout: 'bar' } computed_props_keep_quoted_inlined_sub_6: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = '_foo'; let o = class { static get [prop]() { return 'bar' } }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } computed_props_keep_quoted_inlined_sub_7: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = '_foo'; let o = new class { [prop] = 'bar' }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } computed_props_keep_quoted_inlined_sub_8: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = '_foo'; let o = new class { [prop]() { return 'bar' } }; console.log(o[id('_foo')]()); } expect_stdout: 'bar' } computed_props_keep_quoted_inlined_sub_9: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = '_foo'; let o = new class { get [prop]() { return 'bar' } }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } computed_props_keep_quoted_inlined_sub_10: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = '_foo'; let { [prop]: val } = { [id('_foo')]: 'bar' }; console.log(val); } expect_stdout: 'bar' } no_computed_props_keep_quoted_inlined_sub_1: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = '_foo'; let o = { [prop]: 'bar' }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } no_computed_props_keep_quoted_inlined_sub_2: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = '_foo'; let o = { [prop]() { return 'bar' } }; console.log(o[id('_foo')]()); } expect_stdout: 'bar' } no_computed_props_keep_quoted_inlined_sub_3: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = '_foo'; let o = { get [prop]() { return 'bar' } }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } no_computed_props_keep_quoted_inlined_sub_4: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = '_foo'; let o = class { static [prop] = 'bar' }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } no_computed_props_keep_quoted_inlined_sub_5: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = '_foo'; let o = class { static [prop]() { return 'bar' } }; console.log(o[id('_foo')]()); } expect_stdout: 'bar' } no_computed_props_keep_quoted_inlined_sub_6: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = '_foo'; let o = class { static get [prop]() { return 'bar' } }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } no_computed_props_keep_quoted_inlined_sub_7: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = '_foo'; let o = new class { [prop] = 'bar' }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } no_computed_props_keep_quoted_inlined_sub_8: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = '_foo'; let o = new class { [prop]() { return 'bar' } }; console.log(o[id('_foo')]()); } expect_stdout: 'bar' } no_computed_props_keep_quoted_inlined_sub_9: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = '_foo'; let o = new class { get [prop]() { return 'bar' } }; console.log(o[id('_foo')]); } expect_stdout: 'bar' } no_computed_props_keep_quoted_inlined_sub_10: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = '_foo'; let { [prop]: val } = { [id('_foo')]: 'bar' }; console.log(val); } expect_stdout: 'bar' } no_computed_props_keep_quoted_property_access_sub: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = 'foo_'; let o = { [id('foo_')]: 'bar' }; console.log(o[prop]); } expect_stdout: 'bar' } computed_props_keep_quoted_property_access_sub: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = 'foo_'; let o = { [id('foo_')]: 'bar' }; console.log(o[prop]); } expect_stdout: 'bar' } no_computed_props_keep_quoted_optional_property_access_sub: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: false, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = 'foo_'; let o = { [id('foo_')]: 'bar' }; console.log(o?.[prop]); } expect_stdout: 'bar' } computed_props_keep_quoted_optional_property_access_sub: { options = { defaults: false, reduce_vars: true, unused: true, toplevel: true, computed_props: true, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let prop = 'foo_'; let o = { [id('foo_')]: 'bar' }; console.log(o?.[prop]); } expect_stdout: 'bar' } terser-5.19.2/test/compress/mangleprops-strict.js000066400000000000000000000173671445647217600221570ustar00rootroot00000000000000inline_string_keep_quoted_strict: { options = { defaults: false, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let quoted_obj = { '_obj_prop': 'bar', '_obj_method'() {}, get '_obj_getter'() {}, }; let quoted_static_class = class { static '_static_prop' = 'bar'; static '_static_method'() {} static get '_static_getter'() {} }; let quoted_instance_class = class { '_instance_prop' = 'bar'; '_instance_method'() {} get '_instance_getter'() {} }; global['_sub']; global?.['_optional_sub']; global?.deep['_deep_optional_sub']; let { '_destructure': quoted_destructure } = global; let obj = { _obj_prop: 'bar', _obj_method() {}, get _obj_getter() {}, }; let static_class = class { static _static_prop = 'bar'; static _static_method() {} static get _static_getter() {} }; let instance_class = class { _instance_prop = 'bar'; _instance_method() {} get _instance_getter() {} }; global._sub; global?._optional_sub; global?.deep._deep_optional_sub; let { _destructure: destructure } = global; } expect: { let quoted_obj = { '_obj_prop': 'bar', '_obj_method'() {}, get '_obj_getter'() {}, }; let quoted_static_class = class { static '_static_prop' = 'bar'; static '_static_method'() {} static get '_static_getter'() {} }; let quoted_instance_class = class { '_instance_prop' = 'bar'; '_instance_method'() {} get '_instance_getter'() {} }; global['_sub']; global?.['_optional_sub']; global?.deep['_deep_optional_sub']; let { '_destructure': quoted_destructure } = global; let obj = { t: "bar", _() {}, get l() {} }; let static_class = class { static o = "bar"; static i() {} static get g() {} }; let instance_class = class { p = "bar"; u() {} get j() {} }; global._sub; global?._optional_sub; global?.deep._deep_optional_sub; let { h: destructure } = global; } } computed_inline_string_keep_quoted_strict_no_computed_props: { options = { defaults: false, computed_props: false, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let quoted_obj = { ['_obj_prop']: 'bar', ['_obj_method']() {}, get ['_obj_getter']() {}, }; let quoted_static_class = class { static ['_static_prop'] = 'bar'; static ['_static_method']() {} static get ['_static_getter']() {} }; let quoted_instance_class = class { ['_instance_prop'] = 'bar'; ['_instance_method']() {} get ['_instance_getter']() {} }; global['_sub']; global?.['_optional_sub']; global?.deep['_deep_optional_sub']; let { ['_destructure']: quoted_destructure } = global; let obj = { _obj_prop: 'bar', _obj_method() {}, get _obj_getter() {}, }; let static_class = class { static _static_prop = 'bar'; static _static_method() {} static get _static_getter() {} }; let instance_class = class { _instance_prop = 'bar'; _instance_method() {} get _instance_getter() {} }; global._sub; global?._optional_sub; global?.deep._deep_optional_sub; let { _destructure: destructure } = global; } expect: { let quoted_obj = { ['_obj_prop']: 'bar', ['_obj_method']() {}, get ['_obj_getter']() {}, }; let quoted_static_class = class { static ['_static_prop'] = 'bar'; static ['_static_method']() {} static get ['_static_getter']() {} }; let quoted_instance_class = class { ['_instance_prop'] = 'bar'; ['_instance_method']() {} get ['_instance_getter']() {} }; global['_sub']; global?.['_optional_sub']; global?.deep['_deep_optional_sub']; let { ['_destructure']: quoted_destructure } = global; let obj = { _: "bar", l() {}, get o() {} }; let static_class = class { static i = 'bar'; static g() {} static get p() {} }; let instance_class = class { u = 'bar'; j() {} get h() {} }; global._sub; global?._optional_sub; global?.deep._deep_optional_sub; let { m: destructure } = global; } } computed_inline_string_keep_quoted_strict_computed_props: { options = { defaults: false, computed_props: true, } mangle = { properties: { keep_quoted: 'strict', }, } input: { let quoted_obj = { ['_obj_prop']: 'bar', ['_obj_method']() {}, get ['_obj_getter']() {}, }; let quoted_static_class = class { static ['_static_prop'] = 'bar'; static ['_static_method']() {} static get ['_static_getter']() {} }; let quoted_instance_class = class { ['_instance_prop'] = 'bar'; ['_instance_method']() {} get ['_instance_getter']() {} }; global['_sub']; global?.['_optional_sub']; global?.deep['_deep_optional_sub']; let { ['_destructure']: quoted_destructure } = global; let obj = { _obj_prop: 'bar', _obj_method() {}, get _obj_getter() {}, }; let static_class = class { static _static_prop = 'bar'; static _static_method() {} static get _static_getter() {} }; let instance_class = class { _instance_prop = 'bar'; _instance_method() {} get _instance_getter() {} }; global._sub; global?._optional_sub; global?.deep._deep_optional_sub; let { _destructure: destructure } = global; } expect: { let quoted_obj = { _obj_prop: 'bar', _obj_method() {}, get _obj_getter() {}, }; let quoted_static_class = class { static _static_prop = 'bar'; static _static_method() {} static get _static_getter() {} }; let quoted_instance_class = class { _instance_prop = 'bar'; _instance_method() {} get _instance_getter() {} }; global['_sub']; global?.['_optional_sub']; global?.deep['_deep_optional_sub']; let { _destructure: quoted_destructure } = global; let obj = { t: "bar", _() {}, get l() {} }; let static_class = class { static o = "bar"; static i() {} static get g() {} }; let instance_class = class { p = "bar"; u() {} get j() {} }; global._sub; global?._optional_sub; global?.deep._deep_optional_sub; let { h: destructure } = global; } } terser-5.19.2/test/compress/mangleprops.js000066400000000000000000000175161445647217600206450ustar00rootroot00000000000000inline_string_keep_quoted: { options = { defaults: false, } mangle = { properties: { keep_quoted: true, }, } input: { let quoted_obj = { '_obj_prop': 'bar', '_obj_method'() {}, get '_obj_getter'() {}, }; let quoted_static_class = class { static '_static_prop' = 'bar'; static '_static_method'() {} static get '_static_getter'() {} }; let quoted_instance_class = class { '_instance_prop' = 'bar'; '_instance_method'() {} get '_instance_getter'() {} }; global['_sub']; global?.['_optional_sub']; global?.deep['_deep_optional_sub']; let { '_destructure': quoted_destructure } = global; let obj = { _obj_prop: 'bar', _obj_method() {}, get _obj_getter() {}, }; let static_class = class { static _static_prop = 'bar'; static _static_method() {} static get _static_getter() {} }; let instance_class = class { _instance_prop = 'bar'; _instance_method() {} get _instance_getter() {} }; global._sub; global?._optional_sub; global?.deep._deep_optional_sub; let { _destructure: destructure } = global; } expect: { let quoted_obj = { '_obj_prop': 'bar', '_obj_method'() {}, get '_obj_getter'() {}, }; let quoted_static_class = class { static '_static_prop' = 'bar'; static '_static_method'() {} static get '_static_getter'() {} }; let quoted_instance_class = class { '_instance_prop' = 'bar'; '_instance_method'() {} get '_instance_getter'() {} }; global['_sub']; global?.['_optional_sub']; global?.deep['_deep_optional_sub']; let { '_destructure': quoted_destructure } = global; let obj = { _obj_prop: 'bar', _obj_method() {}, get _obj_getter() {}, }; let static_class = class { static _static_prop = 'bar'; static _static_method() {} static get _static_getter() {} }; let instance_class = class { _instance_prop = 'bar'; _instance_method() {} get _instance_getter() {} }; global._sub; global?._optional_sub; global?.deep._deep_optional_sub; let { _destructure: destructure } = global; } } computed_inline_string_keep_quoted_no_computed_props: { options = { defaults: false, computed_props: false, } mangle = { properties: { keep_quoted: true, }, } input: { let quoted_obj = { ['_obj_prop']: 'bar', ['_obj_method']() {}, get ['_obj_getter']() {}, }; let quoted_static_class = class { static ['_static_prop'] = 'bar'; static ['_static_method']() {} static get ['_static_getter']() {} }; let quoted_instance_class = class { ['_instance_prop'] = 'bar'; ['_instance_method']() {} get ['_instance_getter']() {} }; global['_sub']; global?.['_optional_sub']; global?.deep['_deep_optional_sub']; let { ['_destructure']: quoted_destructure } = global; let obj = { _obj_prop: 'bar', _obj_method() {}, get _obj_getter() {}, }; let static_class = class { static _static_prop = 'bar'; static _static_method() {} static get _static_getter() {} }; let instance_class = class { _instance_prop = 'bar'; _instance_method() {} get _instance_getter() {} }; global._sub; global?._optional_sub; global?.deep._deep_optional_sub; let { _destructure: destructure } = global; } expect: { let quoted_obj = { ['_obj_prop']: 'bar', ['_obj_method']() {}, get ['_obj_getter']() {}, }; let quoted_static_class = class { static ['_static_prop'] = 'bar'; static ['_static_method']() {} static get ['_static_getter']() {} }; let quoted_instance_class = class { ['_instance_prop'] = 'bar'; ['_instance_method']() {} get ['_instance_getter']() {} }; global['_sub']; global?.['_optional_sub']; global?.deep['_deep_optional_sub']; let { ['_destructure']: quoted_destructure } = global; let obj = { _: "bar", l() {}, get o() {} }; let static_class = class { static i = 'bar'; static g() {} static get p() {} }; let instance_class = class { u = 'bar'; j() {} get h() {} }; global._sub; global?._optional_sub; global?.deep._deep_optional_sub; let { m: destructure } = global; } } computed_inline_string_keep_quoted_computed_props: { options = { defaults: false, computed_props: true, } mangle = { properties: { keep_quoted: true, }, } input: { let quoted_obj = { ['_obj_prop']: 'bar', ['_obj_method']() {}, get ['_obj_getter']() {}, }; let quoted_static_class = class { static ['_static_prop'] = 'bar'; static ['_static_method']() {} static get ['_static_getter']() {} }; let quoted_instance_class = class { ['_instance_prop'] = 'bar'; ['_instance_method']() {} get ['_instance_getter']() {} }; global['_sub']; global?.['_optional_sub']; global?.deep['_deep_optional_sub']; let { ['_destructure']: quoted_destructure } = global; let obj = { _obj_prop: 'bar', _obj_method() {}, get _obj_getter() {}, }; let static_class = class { static _static_prop = 'bar'; static _static_method() {} static get _static_getter() {} }; let instance_class = class { _instance_prop = 'bar'; _instance_method() {} get _instance_getter() {} }; global._sub; global?._optional_sub; global?.deep._deep_optional_sub; let { _destructure: destructure } = global; } expect: { let quoted_obj = { _obj_prop: 'bar', _obj_method() {}, get _obj_getter() {}, }; let quoted_static_class = class { static _static_prop = 'bar'; static _static_method() {} static get _static_getter() {} }; let quoted_instance_class = class { _instance_prop = 'bar'; _instance_method() {} get _instance_getter() {} }; global['_sub']; global?.['_optional_sub']; global?.deep['_deep_optional_sub']; let { _destructure: quoted_destructure } = global; let obj = { t: "bar", _() {}, get l() {} }; let static_class = class { static o = "bar"; static i() {} static get g() {} }; let instance_class = class { p = "bar"; u() {} get j() {} }; global._sub; global?._optional_sub; global?.deep._deep_optional_sub; let { h: destructure } = global; } } terser-5.19.2/test/compress/max_line_len.js000066400000000000000000000010751445647217600207410ustar00rootroot00000000000000too_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"}}', ] } 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"}', '}', ] } terser-5.19.2/test/compress/negate-iife.js000066400000000000000000000210101445647217600204530ustar00rootroot00000000000000negate_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-5.19.2/test/compress/new.js000066400000000000000000000064751445647217600171110ustar00rootroot00000000000000new_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-5.19.2/test/compress/node_version.js000066400000000000000000000002531445647217600207760ustar00rootroot00000000000000eval_let_6: { input: { eval("let a;"); console.log(); } expect: { eval("let a;"); console.log(); } expect_stdout: "" } terser-5.19.2/test/compress/nullish.js000066400000000000000000000066531445647217600177740ustar00rootroot00000000000000 conditional_to_nullish_coalescing: { options = { ecma: 2020, toplevel: true, conditionals: true } input: { const foo = id('something'); leak(foo == null ? bar : foo); } expect: { const foo = id('something'); leak(foo ?? bar); } } conditional_to_nullish_coalescing_2: { options = { ecma: 2020, toplevel: true, conditionals: true } input: { const foo = id('something') console.log('negative cases') foo === null || foo === null ? bar : foo; foo === undefined || foo === undefined ? bar : foo; foo === null || foo === undefined ? foo : bar; some_global === null || some_global === undefined ? bar : some_global; console.log('positive cases') foo === null || foo === void 0 ? bar : foo; foo === null || foo === undefined ? bar : foo; foo === undefined || foo === null ? bar : foo; } expect: { const foo = id('something') console.log('negative cases') foo === null || foo === null ? bar : foo; foo === void 0 || foo === void 0 ? bar : foo; foo === null || foo === void 0 ? foo : bar; some_global === null || some_global === void 0 ? bar : some_global; console.log('positive cases') foo ?? bar; foo ?? bar; foo ?? bar; } } simplify_nullish_coalescing: { options = { ecma: 2020, defaults: true, sequences: false, toplevel: true } input: { const y = id("one") const is_null = null const not_null = "two" console.log(is_null ?? y); console.log(not_null ?? y); } expect: { const y = id("one") console.log(y) console.log("two") } node_version: ">=14" expect_stdout: [ "one", "two" ] } nullish_coalescing_boolean_context: { options = { ecma: 2020, toplevel: true, conditionals: true, evaluate: true, booleans: true, side_effects: true, reduce_vars: true } input: { if (null ?? unknown) { pass() } if (unknown ?? false) { pass() } if (4 + 4 ?? unknown) { pass() } } expect: { unknown&&pass(); unknown&&pass(); pass(); } } nullish_coalescing_mandatory_parens: { input: { (x ?? y) || z; x || (y ?? z); } expect_exact: "(x??y)||z;x||(y??z);" } nullish_coalescing_parens: { input: { console.log((false || null) ?? "PASS"); console.log(null ?? (true && "PASS")); console.log((null ?? 0) || "PASS"); console.log(null || (null ?? "PASS")); } node_version: ">=14" expect_stdout: [ "PASS", "PASS", "PASS", "PASS", ] } delete_nullish: { input: { delete obj?.key; const other = { key: true }; delete other?.key; } expect: { delete obj?.key; const other = { key: true }; delete other?.key; } } delete_nullish_2: { options = { defaults: true, evaluate: true, passes: 3, } input: { delete null?.key; delete null?.deep.key; delete null.deep?.key; delete null?.deep?.key; } expect: { delete null.deep?.key; } } terser-5.19.2/test/compress/numbers.js000066400000000000000000000146331445647217600177660ustar00rootroot00000000000000hex_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( ~x == 42, 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, x * 1 * 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; } } no_number_function_transform_without_unsafe_math: { options = { unsafe: true } input: { Number(1234); } expect: { Number(1234); } } number_function_transform_with_unsafe_math: { options = { unsafe: true, unsafe_math: true } input: { Number(1234); } expect: { +1234; } } keep_numbers: { beautify = { keep_numbers: true } input: { const exp = 1000000000000; const negativeExp = 0.00000001; const huge = 1000000000001; const big = 100000000001; const fractional = 100.2300200; const numeric_separators = 1_000_000_000_000; } expect_exact: "const exp=1000000000000;const negativeExp=0.00000001;const huge=1000000000001;const big=100000000001;const fractional=100.2300200;const numeric_separators=1_000_000_000_000;" } keep_numbers_in_properties_as_is: { beautify = { keep_numbers: true } input: { var Foo = { 1000000: 80000000000 } } expect_exact: "var Foo={1000000:80000000000};" } numeric_separators: { input: { const one = 1_000; const two = 1_000_000; const bin = 0b0101_0101; const oct = 0o0123_4567; const hex = 0xDEAD_BEEF; const fractional = 1_000.000_100; const identifier = _1000; const negate_identifier = -_1000; } expect_exact: "const one=1e3;const two=1e6;const bin=85;const oct=342391;const hex=3735928559;const fractional=1000.0001;const identifier=_1000;const negate_identifier=-_1000;" } numeric_separator_trailing_underscore: { input: `const trailing = 1000_` expect_error: ({ name: "SyntaxError", message: "Numeric separators are not allowed at the end of numeric literals" }) } numeric_separator_double_underscore: { input: `const double = 1__000` expect_error: ({ name: "SyntaxError", message: "Only one underscore is allowed as numeric separator" }) } terser-5.19.2/test/compress/object.js000066400000000000000000000550431445647217600175610ustar00rootroot00000000000000getter_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: 2015 } 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: 2015 } 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"}};' } computed_property_names_side_effects: { options = { unused: true, toplevel: true } input: { const foo = { [console.log("PASS")]: 42 }; } expect: { console.log("PASS"); } expect_stdout: "PASS" } 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: 2015 } 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: 2015 } 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_exact: "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: 2015, 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: 2015, 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: 2015, } 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: 2017, 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: 2015, 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: 2015, 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: 2015, 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: 2015, 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-5.19.2/test/compress/parameters.js000066400000000000000000000135361445647217600204570ustar00rootroot00000000000000arrow_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: 2015 } 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(){})}={};" } destructuring_parameters_get_set: { beautify = { ecma: 2015 } input: { function default_get({ get = "PASS" }) { return get } function default_set({ set = "PASS" }) { return set } const default_get_arrow = ({ get = "PASS" }) => { return get } const default_set_arrow = ({ set = "PASS" }) => { return set } console.log(default_get({})) console.log(default_set({})) console.log(default_get_arrow({})) console.log(default_set_arrow({})) } expect_stdout: [ "PASS", "PASS", "PASS", "PASS", ] } default_arguments: { beautify = { ecma: 2015 } 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]){}" } keep_default_arg_when_undefined: { options = { keep_fargs: true, evaluate: true, } input: { function x(a = void 0) { } console.log(x.length) } expect: { function x(a = void 0) { } console.log(x.length) } } drop_default_arg_when_undefined_and_iife: { options = { keep_fargs: true, evaluate: true, } input: { console.log((function x(a = void 0) { })()) } expect: { console.log((function x(a) { })()) } } default_values_in_destructurings: { beautify = { ecma: 2015 } 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}){} } } accept_destructuring_async_word_with_default: { input: { console.log((({ async = "PASS" }) => async)({})) } expect_stdout: "PASS" } terser-5.19.2/test/compress/parse_errors.js000066400000000000000000000010751445647217600210150ustar00rootroot00000000000000basic_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, }) } invalid_template_string_example: { input: ` console.log(\`foo \${100 + 23} ` expect_error: ({ name: "SyntaxError", message: "Unterminated template", line: 2, col: 35, }) } terser-5.19.2/test/compress/properties.js000066400000000000000000001772331445647217600205150ustar00rootroot00000000000000keep_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_nth_identifier: { mangle = { properties: { nth_identifier: (function () { function get(n) { return "zyxwvutsrq"[n]; } return { get }; })() }, } input: { var a = {}; a.foo = "bar"; x = { baz: "ban" }; } expect: { var a = {}; a.v = "bar"; x = { u: "ban" }; } } 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: 2015, 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: 2015, 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: 2015, 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: 2015, 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: 2015, 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: 2015, 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: 2015, 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"; } } lhs_prop_3: { options = { evaluate: true, properties: true, unsafe: true, } input: { ({ prop: 'do not put me in the LHS!' })["prop"] = 1; } expect: { ({ prop: 'do not put me in the LHS!' }).prop = 1; } } 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({ a: "bar", [console.log("foo")]: 42, }.a); } 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(); (class {}).prototype.destroy = y(); } expect: { function Simulator() { this._aircraft = []; } x(); y(); } } const_prop_assign_pure: { options = { pure_getters: true, side_effects: true, } input: { function Simulator() { /abc/.index = 1; this._aircraft = []; } (function() {}).prototype.destroy = x(); (class {}).prototype.destroy = y(); } expect: { function Simulator() { this._aircraft = []; } x(); y(); } } 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: 2015, 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: 2015, 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: 2015, 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: 2015, 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", ] } dont_flatten_computed_property: { options = { properties: true } input: { console.log({ a: "FAIL", [String.fromCharCode(97)]: "PASS" }.a); } expect_stdout: "PASS" } dont_flatten_proto: { options = { properties: true } input: { console.log(typeof { __proto__: "FAIL", }.__proto__); } expect_stdout: "object" } 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.t }, t: !0 }; console.log(acd); } } skip_undeclared_properties_by_default: { mangle = { cache: { props: { '$Bar': 'a' } }, properties: {}, toplevel: true } input: { var Foo = { foo: function() { return Bar.bar() } }; } expect: { var r={o:function(){return a.bar()}}; } } mangle_undeclared_properties: { mangle = { cache: { props: { '$Bar': 'a' } }, properties: { undeclared: true }, toplevel: true } input: { var Foo = { foo: function() { return Bar.bar() } }; } expect: { var r={o:function(){return a.t()}}; } } terser-5.19.2/test/compress/pure_funcs.js000066400000000000000000000347431445647217600204700ustar00rootroot00000000000000array: { 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", preserve_annotations: true, } input: { /*@__PURE__*/ a(); /*@__PURE__*/ (b()); (/*@__PURE__*/ c)(); (/*@__PURE__*/ d()); } expect_exact: [ "/*@__PURE__*/c();", ] } issue_2629_2: { options = { side_effects: true, } beautify = { comments: "all", preserve_annotations: true, } 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: [ "/*@__PURE__*/e(1)(2)(3);", "/*@__PURE__*/f(1)(2)(3);", "/*@__PURE__*/g(1)(2)(3);", ] } issue_2629_3: { options = { side_effects: true, } beautify = { comments: "all", preserve_annotations: true, } 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: [ "/*@__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);", ] } 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", preserve_annotations: true, } input: { /*@__PURE__*/(g() || h())(x(), y()); (/*@__PURE__*/ (a() || b()))(c(), d()); } expect_exact: [ "/*@__PURE__*/x(),y();", "/*@__PURE__*/(a()||b())(c(),d());", ] } issue_2705_1: { options = { side_effects: true, } beautify = { comments: "all", preserve_annotations: true, } input: { /*@__PURE__*/ new a(); /*@__PURE__*/ (new b()); new (/*@__PURE__*/ c)(); (/*@__PURE__*/ new d()); } expect_exact: [ "new/*@__PURE__*/c;", ] } issue_2705_2: { options = { side_effects: true, } beautify = { comments: "all", preserve_annotations: true, } 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/*@__PURE__*/e(1)(2)(3);", "/*@__PURE__*/new f(1)(2)(3);", "/*@__PURE__*/new g(1)(2)(3);", ] } issue_2705_3: { options = { side_effects: true, } beautify = { comments: "all", preserve_annotations: true, } 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/*@__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);", ] } 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", preserve_annotations: true, } input: { /*@__PURE__*/new (g() || h())(x(), y()); /* */ new (/*@__PURE__*/ (a() || b()))(c(), d()); } expect_exact: [ "/*@__PURE__*/x(),y();", "new(/*@__PURE__*/a()||b())(c(),d());", ] } issue_526_1: { 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-5.19.2/test/compress/pure_getters.js000066400000000000000000000575571445647217600210370ustar00rootroot00000000000000strict: { 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-5.19.2/test/compress/pure_globals.js000066400000000000000000000010111445647217600207530ustar00rootroot00000000000000 window_access_is_impure: { options = { defaults: true } input: { try { window; } catch(e) { console.log("PASS"); } } expect_stdout: "PASS" } globals_whose_access_is_pure: { options = { defaults: true, } input: { try { Promise; Number; Object; String; Array; } catch(e) { console.log("side effect!"); } } expect: { } } terser-5.19.2/test/compress/reduce_vars.js000066400000000000000000004550621445647217600206220ustar00rootroot00000000000000reduce_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" } 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 (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; } } } 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_1: { 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_reference_indirection_1: { options = { toplevel: true, reduce_vars: true, unused: true, evaluate: true } input: { if (id(true)) { var first = indirection(); var on = true; function indirection() { log_on() } function log_on() { console.log(on) } } } expect: { if (id(true)) { (function () { log_on(); })(); var on = true; function log_on() { console.log(on); } } } expect_stdout: "undefined" } defun_reference_indirection_2: { options = { toplevel: true, reduce_vars: true, unused: true, evaluate: true } input: { if (id(true)) { var first = indirection_2(); var on = true; function log_on() { console.log(on) } function indirection_2() { log_on() } } } expect: { if (id(true)) { (function () { log_on(); })(); var on = true; function log_on() { console.log(on); } } } expect_stdout: "undefined" } defun_reference_used_before_def: { options = { toplevel: true, reduce_vars: true, unused: true, evaluate: true } input: { var first = log_on(); var on = true; function log_on() { console.log(on) } } expect: { (function () { console.log(on) })(); var on = true; } expect_stdout: "undefined" } defun_reference_fixed_var: { options = { toplevel: true, reduce_vars: true, unused: true, evaluate: true } input: { if (id(true)) { var on = true; var first = log_on(); function log_on() { console.log(on) } } } expect: { if (id(true)) { (function () { console.log(true) })(); } } expect_stdout: "true" } issue_t1382: { options = { module: true, reduce_vars: true, unused: true, evaluate: true, } input: { const qDev = false; function assertEqual() { if (qDev) { throw new Error('SHOULD BE REMOVED') } } export {assertEqual} export class ReadWriteProxyHandler { set() { if (qDev) if (invokeCtx) {} } } } expect: { function assertEqual(){ if(false) throw new Error("SHOULD BE REMOVED") } export{assertEqual}; export class ReadWriteProxyHandler{ set(){if(false)if(invokeCtx);} } } } defun_reference_fixed_let: { options = { toplevel: true, reduce_vars: true, unused: true, evaluate: true, } input: { let on = true; function log_on() { console.log(on) } var first = log_on(); } expect: { (function () { console.log(true) })(); } expect_stdout: "true" } 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 = { evaluate: true, 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 1; } } } 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 () { return 3; }); return 3 + 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; } b.inject = []; (function () { return 4; }); return 1 + 2 + 4; } } } 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; a === void 0 ? 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; a === void 0 ? 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) { if (1 === (a = 1)) console.log(a); else 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() { var arguments = 42; return typeof arguments; } 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; }(), function() { var arguments = 42; return typeof arguments; }(), 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; }(), function() { var arguments = 42; return typeof arguments; }(), 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 (a) { 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" } issue_1107: { options = { reduce_vars: true, unused: true, } input: { function foo() { let bar = "PASS 2"; try { const bar = "PASS 1"; console.log(bar); } finally { console.log(bar); } } foo(); } expect_stdout: [ "PASS 1", "PASS 2" ] } 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 aaaa = "32"; !function() { var b = aaaa + 1; !function(a) { console.log(b, a++); }(0); }(); } expect: { const aaaa = "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_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_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_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" } 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" } /* https://github.com/terser/terser/issues/431 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: { console.log("number", "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: { console.log("number", "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" } named_function_with_recursive_ref_reuse: { options = { toplevel: true, evaluate: true, inline: true, reduce_vars: true, unused: true } input: { var result = []; var do_not_inline = function foo() { result.push(foo) }; [0, 1].map(() => do_not_inline()); console.log(result[0] === result[1]); } expect: { var result = []; var do_not_inline = function foo() { result.push(foo) }; [0, 1].map(() => do_not_inline()); console.log(result[0] === result[1]); } expect_stdout: "true" } 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) { function g(i) { return i && i + g(i - 1); } return function(j) { return g(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 a ^ 1; }()); } 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" } variables_collision_in_immediately_invoked_func: { options = { defaults: true } input: { (function(callback) { callback(); })(function() { window.used = function() { var A = window.foo, B = window.bar, C = window.foobar; return (function(A, c) { if (-1 === c) return A; return $(A, c); })(B, C); }.call(this); }); } expect: { !function () { window.used = function () { return ( window.foo, function (A, c) { return -1 === c ? A : $(A,c) }(window.bar, window.foobar) ); }.call(this); }(); } } issue_308: { options = { defaults: true, passes: 2 }; input: { exports.withStyles = withStyles; function _inherits(superClass) { if (typeof superClass !== "function") { throw new TypeError(); } Object.create(superClass); } function withStyles() { var a = EXTERNAL(); return function(_a){ _inherits(_a); function d() {} }(a); } } expect: { function _inherits(superClass) { if ("function" != typeof superClass) throw new TypeError(); Object.create(superClass); } function withStyles() { _inherits(EXTERNAL()); } exports.withStyles = withStyles; } } issue_294: { options = { defaults: true, passes: 2 }; input: { module.exports = (function(constructor) { return constructor(); })(function() { return function(input) { var keyToMap = input.key; return { mappedKey: (function(value) { return value || "CONDITIONAL_DEFAULT_VALUE"; })(keyToMap) }; }; }); } expect: { module.exports = function (input) { var value; return {mappedKey: (value = input.key, value || "CONDITIONAL_DEFAULT_VALUE")}; }; } } issue_432_1: { options = { defaults: true, toplevel: true } input: { const selectServer = () => { selectServers(); } function selectServers() { const retrySelection = () => { var descriptionChangedHandler = () => { selectServers(); }; }; retrySelection(); } leak(() => Topology) console.log('PASS') } expect_stdout: "PASS" } issue_432_2: { options = { defaults: true, toplevel: true } input: { const selectServer = () => { selectServers(); } function selectServers() { function retrySelection() { var descriptionChangedHandler = () => { selectServers(); }; leak(descriptionChangedHandler) }; retrySelection(); } leak(() => Topology) console.log("PASS") } expect_stdout: "PASS" } issue_379: { input: { global.a = ((...args) => ((a1, a2) => a1.foo === a2.foo))(...args) } expect: { global.a = ((...args) => ((a1, a2) => a1.foo === a2.foo))(...args) } } issue_443: { options = { unused: true, reduce_vars: true, toplevel: true } input: { const one_name = "PASS"; var get_one = () => { if (one_name) return one_name; } { let one_name = get_one(); console.log(one_name) } } expect_stdout: "PASS" } reduce_class_with_side_effects_in_extends: { options = { unused: true, reduce_vars: true, toplevel: true } input: { let x = "" class Y extends (x += "PA", Array) { } class X extends (x += "SS", Array) { } global.something = [new X(), new Y()] console.log(x) } expect_stdout: "PASS" } reduce_class_with_side_effects_in_properties: { options = { unused: true, reduce_vars: true, toplevel: true } input: { let x = "" class Y { static _ = (x += "PA") } class X { static _ = (x += "SS") } global.something = [new X(), new Y()] console.log(x) } expect_stdout: "PASS" } issue_581: { options = { unused: true, reduce_vars: true, } input: { class Yellow { method() { const errorMessage = "FAIL"; return applyCb(errorMessage, () => console.log(this.message())); } message() { return "PASS"; } } function applyCb(errorMessage, callback) { return callback(errorMessage) } (new Yellow()).method() } expect_stdout: "PASS" } issue_581_2: { options = { unused: true, reduce_vars: true, } input: { (function () { return function(callback) { return callback() }(() => { console.log(this.message) }); }).call({ message: 'PASS' }) } expect: { (function () { return function(callback) { return callback() }(() => { console.log(this.message) }); }).call({ message: 'PASS' }) } expect_stdout: "PASS" } issue_639: { input: { const path = id({ extname: (name) => { console.log('PASS:' + name) } }) global.getExtFn = function getExtFn() { return function(path) { return getExt(path); } } function getExt(name) { let ext; if (!ext) { ext = getExtInner(name); } return ext; } function getExtInner(name) { return path.extname(name); } getExtFn()('name') } expect_stdout: [ "PASS:name" ] } issue_741_reference_cycle: { input: { for (var a = console.log, s = 1; s <= 3;) { var c = s; a(c); s++; } } expect_stdout: ["1", "2", "3"] } issue_741_2: { input: { var a = console.log var might_change = 0; global.problem = () => { var c = might_change a(c) } global.increment = () => { might_change++ } increment() problem() increment() problem() } expect_stdout: ["1", "2"] } conditional_chain_call: { options = { toplevel: true, evaluate: true, inline: true, reduce_vars: true, unused: true, } input: { global.a = { b: null } let foo = "PASS" a.b?.c(foo = "FAIL") console.log(foo) } expect: { global.a = { b: null } let foo = "PASS" a.b?.c(foo = "FAIL") console.log(foo) } expect_stdout: ["PASS"] node_version = ">=14" } conditional_chain_call_direct: { options = { toplevel: true, evaluate: true, inline: true, reduce_vars: true, unused: true, } input: { global.a = { b: null } let foo = "PASS" a.b?.(foo = "FAIL") console.log(foo) } expect: { global.a = { b: null } let foo = "PASS" a.b?.(foo = "FAIL") console.log(foo) } expect_stdout: ["PASS"] node_version = ">=14" } conditional_chain_prop: { options = { toplevel: true, evaluate: true, inline: true, reduce_vars: true, unused: true, } input: { global.a = null let foo = "PASS" a?.b[foo = "FAIL"] console.log(foo) } expect: { global.a = null let foo = "PASS" a?.b[foo = "FAIL"] console.log(foo) } expect_stdout: ["PASS"] node_version = ">=14" } conditional_chain_prop_direct: { options = { toplevel: true, evaluate: true, inline: true, reduce_vars: true, unused: true, } input: { global.a = { b: null } let foo = "PASS" a.b?.[foo = "FAIL"] console.log(foo) } expect: { global.a = { b: null } let foo = "PASS" a.b?.[foo = "FAIL"] console.log(foo) } expect_stdout: ["PASS"] node_version = ">=14" } conditional_chain_certain_part: { options = { toplevel: true, evaluate: true, inline: true, reduce_vars: true, unused: true, } input: { global.a = { b: null } let foo = "FAIL" a.b.c(foo = "PASS")?.x console.log(foo) } expect: { global.a = { b: null } let foo = "FAIL" a.b.c(foo = "PASS")?.x // "PASS" here because we know `foo = "PASS"` always happens. console.log("PASS") } } conditional_chain_certain_and_uncertain_part: { options = { toplevel: true, evaluate: true, inline: true, reduce_vars: true, unused: true, } input: { global.a = { b: null } let foo = "FAIL" a.b?.[foo = "PASS"]?.d(foo = "FAIL") console.log(foo) } expect: { global.a = { b: null } let foo = "FAIL" a.b?.[foo = "PASS"]?.d(foo = "FAIL") console.log(foo) } } terser-5.19.2/test/compress/regexp.js000066400000000000000000000033171445647217600176020ustar00rootroot00000000000000regexp_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("(pass)", "ig")))); } expect: { console.log(JSON.stringify("COMPASS? Overpass.".match(/(pass)/gi))); } expect_stdout: '["PASS","pass"]' } unsafe_slashes: { options = { defaults: true, unsafe: true } input: { console.log(new RegExp("^https//")) } expect: { console.log(/^https\/\//) } } unsafe_nul_byte: { options = { defaults: true, unsafe: true } input: { console.log(new RegExp("\0")) } expect: { console.log(/\0/) } } inline_script: { options = {} beautify = { inline_script: true, comments: "all" } input: { /* */ /[]/ } expect_exact: '/* <\\/script> */\n/[<\\/script>]/;' } regexp_no_ddos: { options = { unsafe: true, evaluate: true } input: { console.log(/(b+)b+/.test("bbb")) console.log(RegExp("(b+)b+").test("bbb")) } expect: { console.log(/(b+)b+/.test("bbb")) console.log(RegExp("(b+)b+").test("bbb")) } expect_stdout: ["true", "true"] } terser-5.19.2/test/compress/rename.js000066400000000000000000000261661445647217600175660ustar00rootroot00000000000000mangle_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" } mangle_catch_nth_identifier: { rename = true options = { ie8: false, toplevel: true, } mangle = { ie8: false, toplevel: true, nth_identifier: (function () { function get(n) { return "foo"; } return { get }; })() } input: { try { throw "FAIL1"; } catch (a) { var a = "FAIL2"; } console.log(a); } expect_exact: 'try{throw"FAIL1"}catch(foo){var foo="FAIL2"}console.log(foo);' 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-5.19.2/test/compress/return_undefined.js000066400000000000000000000056351445647217600216550ustar00rootroot00000000000000return_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-5.19.2/test/compress/sandbox.js000066400000000000000000000003701445647217600177420ustar00rootroot00000000000000console_log: { input: { console.log("%% %s"); console.log("%% %s", "%s"); } expect: { console.log("%% %s"); console.log("%% %s", "%s"); } expect_stdout: [ "%% %s", "% %s", ] } terser-5.19.2/test/compress/sequences.js000066400000000000000000000435401445647217600203050ustar00rootroot00000000000000make_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" } lift_sequences_6: { options = { sequences: true, toplevel: true, } input: { var a = 2; a &&= (leak(), a = 4, 3); console.log(a); } expect: { var a = 2; a &&= (leak(), a = 4, 3), console.log(a); } expect_stdout: "3" } 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-5.19.2/test/compress/string-literal.js000066400000000000000000000013551445647217600212500ustar00rootroot00000000000000octal_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-5.19.2/test/compress/super.js000066400000000000000000000002051445647217600174370ustar00rootroot00000000000000 super_can_be_parsed: { input: { super(1,2); super.meth(); } expect_exact: "super(1,2);super.meth();" } terser-5.19.2/test/compress/switch.js000066400000000000000000001662371445647217600176240ustar00rootroot00000000000000constant_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: { if (foo === "bar") baz(); } } drop_default_2: { options = { dead_code: true, switches: true, } input: { switch (foo) { case 'bar': baz(); break; default: break; } } expect: { if (foo === "bar") baz(); } } keep_default: { options = { dead_code: true, switches: true, } input: { switch (foo) { case 'bar': baz(); default: something(); break; } } expect: { if (foo === 'bar') baz(); something(); } } remove_switch_1: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case 1: 1; case 2: invariant(); case 3: default: doSomething(); } function invariant() { /* production build */ } } expect: { foo; doSomething(); } } remove_switch_2: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case 1: doSomething(); break; default: doSomething(); break; } } expect: { foo; doSomething(); } } remove_switch_3: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { default: doSomething(); break; case 1: doSomething(); break; } } expect: { foo; doSomething(); } } remove_switch_4: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case 1: doSomething(); break; default: doSomething(); break; case 2: doSomething(); break; } } expect: { foo; doSomething(); } } remove_switch_5: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case "bar": doSomething(); break; default: doSomething(); break; case "qux": doSomething(); break; } } expect: { foo; doSomething(); } } remove_switch_6: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case 1: doSomething(); break; default: doSomething(); break; case 2: doSomething(); } } expect: { foo; doSomething(); } } remove_switch_7: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: doSomething(); break; default: doSomething(); break; case qux: doSomething(); break; } } expect: { switch (foo) { case bar: case qux: } doSomething(); } } remove_switch_8: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { function test(foo) { switch (foo) { case 1: return 1; case 2: default: case 3: } } console.log(test(1)); } expect: { console.log(function (foo) { if (foo === 1) return 1; }(1)); } } remove_switch_9: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case 1: doSomethting(); break; case 2: default: break; case 3: } } expect: { if (foo === 1) doSomethting(); } } remove_switch_10: { options = { dead_code: true, switches: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (1) { case 0: var x = 1; case bar(): default: case bar(): case 1: console.log(x); } function bar() {} } expect: { var x; switch (1) { case bar(): case bar(): } console.log(x); function bar() {} } expect_stdout: ["undefined"] } remove_switch_11: { options = { dead_code: true, switches: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (1) { case 0: var x = 1; case 1: console.log(x); } } expect: { var x; console.log(x); } expect_stdout: ["undefined"] } remove_switch_12: { options = { dead_code: true, switches: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (1) { case 0: var x = 1; case foo(): console.log('foo'); case 1: console.log(x); } function foo() {} } expect: { if (1 === foo()) { var x; console.log('foo'); } console.log(x); function foo() {} } expect_stdout: ["undefined"] } remove_switch_13: { options = { dead_code: true, switches: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (1) { case 0: var x = 1; case foo(): console.log('foo'); break; case 1: console.log(x); } function foo() {} } expect: { if (1 === foo()) { var x; console.log('foo'); } else console.log(x); function foo() {} } expect_stdout: ["undefined"] } remove_switch_14: { options = { dead_code: true, switches: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { function test(foo) { var x = 1; switch (foo) { case 0: case 1: default: case x--: console.log(x); } } test(0); test(1); test(2); } expect: { function test(foo) { var x = 1; switch (foo) { case 0: case 1: case x--: } console.log(x); } test(0); test(1); test(2); } expect_stdout: ["1", "1", "0"] } remove_switch_15: { options = { dead_code: true, switches: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { function test(foo) { var x = 1; switch (foo) { case 0: default: case x--: console.log(x); } } test(0); test(1); test(2); } expect: { function test(foo) { var x = 1; switch (foo) { case 0: case x--: } console.log(x); } test(0); test(1); test(2); } expect_stdout: ["1", "0", "0"] } remove_switch_16: { options = { dead_code: true, switches: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { function test(foo) { var x = 1; switch (foo) { case 0: default: case x--: } console.log(x); } test(0); test(1); test(2); } expect: { function test(foo) { var x = 1; switch (foo) { case 0: case x--: } console.log(x); } test(0); test(1); test(2); } expect_stdout: ["1", "0", "0"] } collapse_into_default_1: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case 'bar': bar(); case 'baz': baz(); case 'qux': default: other(); } } expect: { switch (foo) { case 'bar': bar(); case 'baz': baz(); default: other(); } } } collapse_into_default_2: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case 'bar': bar(); case 'baz': baz(); default: case 'qux': other(); } } expect: { switch (foo) { case 'bar': bar(); case 'baz': baz(); default: other(); } } } collapse_into_default_3: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: bar(); case baz: baz(); case qux: default: other(); } } expect: { switch (foo) { case bar: bar(); case baz: baz(); case qux: default: other(); } } } collapse_into_default_4: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: bar(); case baz: baz(); default: case qux: other(); } } expect: { switch (foo) { case bar: bar(); case baz: baz(); default: case qux: other(); } } } collapse_into_default_5: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: bar(); case baz: baz(); case 'qux': case qux: default: other(); } } expect: { switch (foo) { case bar: bar(); case baz: baz(); case 'qux': case qux: default: other(); } } } collapse_into_default_6: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: bar(); case baz: baz(); case qux: case 'qux': default: other(); } } expect: { switch (foo) { case bar: bar(); case baz: baz(); case qux: default: other(); } } } collapse_into_default_7: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: bar(); case baz: baz(); default: case 'qux': case qux: other(); } } expect: { switch (foo) { case bar: bar(); case baz: baz(); default: case 'qux': case qux: other(); } } } collapse_into_default_8: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: bar(); case baz: baz(); default: case qux: case 'qux': other(); } } expect: { switch (foo) { case bar: bar(); case baz: baz(); default: case qux: other(); } } } collapse_into_default_9: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: bar(); case baz: baz(); case 'qux': default: case qux: other(); } } expect: { switch (foo) { case bar: bar(); case baz: baz(); case 'qux': default: case qux: other(); } } } collapse_into_default_10: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: bar(); case baz: baz(); case qux: default: case 'qux': other(); } } expect: { switch (foo) { case bar: bar(); case baz: baz(); case qux: default: other(); } } } collapse_into_default_11: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: bar(); case 'qux': case qux: default: other(); case 'baz': baz(); } } expect: { switch (foo) { case bar: bar(); case 'qux': case qux: default: other(); case 'baz': baz(); } } } collapse_into_default_12: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: bar(); case qux: case 'qux': default: other(); case 'baz': baz(); } } expect: { switch (foo) { case bar: bar(); case qux: case 'qux': default: other(); case 'baz': baz(); } } } collapse_into_default_13: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: bar(); default: case 'qux': case qux: other(); case 'baz': baz(); } } expect: { switch (foo) { case bar: bar(); default: case 'qux': case qux: other(); case 'baz': baz(); } } } collapse_into_default_14: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: bar(); default: case qux: case 'qux': other(); case 'baz': baz(); } } expect: { switch (foo) { case bar: bar(); default: case qux: case 'qux': other(); case 'baz': baz(); } } } collapse_into_default_15: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: bar(); case 'qux': default: case qux: other(); case 'baz': baz(); } } expect: { switch (foo) { case bar: bar(); case 'qux': default: case qux: other(); case 'baz': baz(); } } } collapse_into_default_16: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: bar(); case qux: default: case 'qux': other(); case 'baz': baz(); } } expect: { switch (foo) { case bar: bar(); case qux: default: case 'qux': other(); case 'baz': baz(); } } } collapse_into_default_17: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: bar(); case 'qux': case qux: default: other(); case baz: baz(); } } expect: { switch (foo) { case bar: bar(); case 'qux': case qux: default: other(); case baz: baz(); } } } collapse_into_default_18: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: bar(); case qux: case 'qux': default: other(); case baz: baz(); } } expect: { switch (foo) { case bar: bar(); case qux: case 'qux': default: other(); case baz: baz(); } } } collapse_into_default_19: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: bar(); default: case 'qux': case qux: other(); case baz: baz(); } } expect: { switch (foo) { case bar: bar(); default: case 'qux': case qux: other(); case baz: baz(); } } } collapse_into_default_20: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: bar(); default: case qux: case 'qux': other(); case baz: baz(); } } expect: { switch (foo) { case bar: bar(); default: case qux: case 'qux': other(); case baz: baz(); } } } collapse_into_default_21: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: bar(); case 'qux': default: case qux: other(); case baz: baz(); } } expect: { switch (foo) { case bar: bar(); case 'qux': default: case qux: other(); case baz: baz(); } } } collapse_into_default_22: { options = { dead_code: true, switches: true, reduce_vars: true, side_effects: true, unused: true, module: true, evaluate: true, } input: { switch (foo) { case bar: bar(); case qux: default: case 'qux': other(); case baz: baz(); } } expect: { switch (foo) { case bar: bar(); case qux: default: case 'qux': other(); case baz: baz(); } } } 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: { if (foo === 'bar') baz(); } } drop_case_2: { options = { dead_code: true, switches: true, } input: { switch (foo) { case 'bar': bar(); break; case 'moo': case moo: case 'baz': break; } } expect: { switch (foo) { case 'bar': bar(); case 'moo': case moo: } } } keep_case: { options = { dead_code: true, switches: true, } input: { switch (foo) { case 'bar': baz(); break; case moo: break; } } expect: { switch (foo) { case 'bar': baz(); case moo: } } } if_else: { options = { dead_code: true, switches: true, } input: { switch (foo) { case 'bar': bar(); break; default: other(); } } expect: { if (foo === 'bar') bar(); else other(); } } if_else2: { options = { dead_code: true, switches: true, } input: { switch (foo) { case 'bar': bar(); default: other(); } } expect: { if (foo === 'bar') bar(); other(); } } if_else3: { options = { dead_code: true, switches: true, } input: { switch (foo) { default: other(); break; case 'bar': bar(); } } expect: { if (foo === 'bar') bar(); else other(); } } if_else4: { options = { dead_code: true, switches: true, } input: { switch (foo) { default: other(); case 'bar': bar(); } } expect: { if (foo !== 'bar') other(); bar(); } } if_else5: { options = { dead_code: true, switches: true, evaluate: true, } input: { switch (1) { case bar: bar(); break; case 1: other(); } } expect: { if (1 === bar) bar(); else { 1; other(); } } } if_else6: { options = { dead_code: true, switches: true, evaluate: true, } input: { switch (1) { case bar: bar(); case 1: other(); } } expect: { if (1 === bar) bar(); 1; other(); } } if_else7: { options = { dead_code: true, switches: true, } input: { switch (foo) { case 'bar': break; bar(); default: other(); } } expect: { if (foo === 'bar'); else other(); } } if_else8: { options = { defaults: true, } input: { function test(foo) { switch (foo) { case 'bar': return 'PASS'; default: return 'FAIL'; } } console.log(test('bar')); } expect: { function test(foo) { return 'bar' === foo ? 'PASS' : 'FAIL'; } console.log(test('bar')); } expect_stdout: ["PASS"] } 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: { if (true === 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: } qux(); } } issue_441_2: { options = { dead_code: true, switches: true, } input: { switch (foo) { case bar: qux(); break; case fall: case baz: qux(); break; default: qux(); break; } } expect: { switch (foo) { case bar: case fall: case baz: } qux(); } } issue_441_3: { options = { dead_code: true, switches: true, } input: { switch (foo) { case bar: qux(); break; case fall: case baz: qux(); break; } } expect: { switch (foo) { case bar: case fall: case baz: qux(); } } } issue_441_4: { options = { dead_code: true, switches: true, } input: { switch (foo) { case 1: qux(); break; case fall1: case 2: qux(); break; case 3: other(); break; case 4: qux(); break; case fall2: case 5: qux(); break; } } expect: { switch (foo) { case 1: case fall1: case 2: qux(); break; case 3: other(); break; case 4: case fall2: case 5: 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, conditionals: true, side_effects: 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--: a--; case (a++): } } f(); console.log(a, b); } expect_stdout: ["99 8"] } 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--: case b: var c; case a: case a--: } console.log(a, b); } expect_stdout: ["99 10"] } 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; if (a !== 0) console.log("FAIL"); } 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" } issue_445: { mangle = true; input: { const leak = () => {} function scan() { let len = leak(); let ch = 0; switch (ch = 123) { case "never-reached": const ch = leak(); leak(ch); } return len === 123 ? "FAIL" : "PASS"; } console.log(scan()); } expect_stdout: "PASS" } collapse_same_branches: { options = { switches: true, dead_code: true } input: { switch (id(1)) { case 1: console.log("PASS"); break case 2: console.log("PASS"); break } } expect: { switch (id(1)) { case 1: case 2: console.log("PASS"); } } expect_stdout: "PASS" } // Not when the branches are break-less collapse_same_branches_2: { options = { switches: true, dead_code: true } input: { switch (id(1)) { case 1: console.log("PASS"); case 2: console.log("PASS"); } } expect: { switch (id(1)) { case 1: console.log("PASS"); case 2: console.log("PASS"); } } expect_stdout: ["PASS", "PASS"] } collapse_same_branches_not_in_a_row: { options = { switches: true, dead_code: true } input: { switch (id(1)) { case 1: console.log("PASS") break; case 2: console.log("FAIL"); break; case 3: console.log("PASS"); break; } } expect: { switch (id(1)) { case 1: case 3: console.log("PASS"); break; case 2: console.log("FAIL"); } } expect_stdout: ["PASS"] } collapse_same_branches_not_in_a_row2: { options = { switches: true, dead_code: true } input: { switch (id(1)) { case 1: console.log("PASS"); break; case 2: console.log("FAIL"); break; case 3: console.log("PASS"); break; case 4: console.log("PASS"); break; } } expect: { switch (id(1)) { case 1: case 3: case 4: console.log("PASS"); break; case 2: console.log("FAIL"); } } expect_stdout: ["PASS"] } collapse_same_branches_not_in_a_row_including_fallthrough_with_same_body: { options = { switches: true, dead_code: true } input: { switch (id(1)) { case 1: console.log("PASS"); break; case 2: console.log("FAIL"); break; case 3: case 4: console.log("PASS"); break; case 9: console.log("FAIL"); break; case 5: case 6: case 7: case 8: console.log("PASS"); break; } } expect: { switch (id(1)) { case 1: case 3: case 4: case 5: case 6: case 7: case 8: console.log("PASS"); break; case 2: case 9: console.log("FAIL"); } } expect_stdout: ["PASS"] } collapse_same_branches_not_in_a_row_ensure_no_side_effects: { options = { switches: true, dead_code: true } input: { let i = 1; switch (id(2)) { case 1: console.log(1); break; case 2: console.log(2); break; case ++i: console.log(1); break; } } expect: { let i = 1; switch (id(2)) { case 1: console.log(1); break; case 2: console.log(2); break; case ++i: console.log(1); } } expect_stdout: ["2"] } collapse_same_branches_not_in_a_row_ensure_no_evaluate_elad: { options = { switches: true, dead_code: true } input: { let i = 1; switch (true) { case 3 == i: console.log(i); break; case 5 == i: console.log(5); break; case 1 == i: console.log(i); break; } } expect: { let i = 1; switch (true) { case 3 == i: console.log(i); break; case 5 == i: console.log(5); break; case 1 == i: console.log(i); } } expect_stdout: ["1"] } collapse_same_branches_not_in_a_row_even_if_last_case_without_abort: { options = { switches: true, dead_code: true } input: { switch (id(3)) { case 1: console.log(1); break; case 2: console.log(2); break; case 3: console.log(1); } } expect: { switch (id(3)) { case 1: case 3: console.log(1); break; case 2: console.log(2); } } expect_stdout: ["1"] } collapse_same_branches_as_default_not_in_a_row: { options = { switches: true, dead_code: true } input: { switch (id(1)) { case 1: console.log("PASS"); break; case 2: console.log("FAIL"); break; case 3: console.log("PREVENT_IFS"); break; case 4: console.log("PASS"); break; default: console.log("PASS"); break; } } expect: { switch (id(1)) { case 1: case 4: default: console.log("PASS"); break; case 2: console.log("FAIL"); break; case 3: console.log("PREVENT_IFS"); } } expect_stdout: ["PASS"] } collapse_same_branches_in_a_row2: { options = { switches: true, dead_code: true } input: { switch (id(1)) { case 1: console.log("PASS"); break; case 2: console.log("FAIL"); break; case 3: console.log("PASS"); break; case 4: console.log("FAIL"); break; } } expect: { switch (id(1)) { case 1: case 3: console.log("PASS"); break; case 2: case 4: console.log("FAIL"); } } expect_stdout: ["PASS"] } collapse_same_branches_in_a_row_with_return: { options = { switches: true, dead_code: true } input: { function fn() { switch (id(1)) { case 1: return "PASS"; case 2: return "FAIL"; case 3: return "PASS"; case 4: return "FAIL"; } } console.log(fn()) } expect: { function fn() { switch (id(1)) { case 1: case 3: return "PASS"; case 2: case 4: return "FAIL"; } } console.log(fn()) } expect_stdout: ["PASS"] } // Empty branches at the end of the switch get trimmed trim_empty_last_branches: { options = { switches: true, dead_code: true } input: { switch (id(1)) { case 1: console.log("PASS") case 2: // break should be removed too break case 3: {} case 4: } } expect: { if (id(1) === 1) console.log("PASS") } expect_stdout: "PASS" } // ... But break should be kept if we're breaking to somewhere else trim_empty_last_branches_2: { options = { switches: true, dead_code: true } input: { somewhere_else: if (id(true)) { switch (id(1)) { case 1: console.log("PASS") case 2: break somewhere_else case 3: {} case 4: } } } expect: { somewhere_else: if (id(true)) switch (id(1)) { case 1: console.log("PASS") case 2: break somewhere_else } } expect_stdout: "PASS" } trim_empty_last_branches_3: { options = { switches: true, dead_code: true } input: { switch (id(1)) { case 1: console.log("PASS") case 2: "no side effect" } } expect: { if (id(1) === 1) console.log("PASS") } expect_stdout: "PASS" } trim_side_effect_free_branches_falling_into_default: { options = { switches: true, dead_code: true } input: { switch (id(1)) { case 0: "no side effect" case 1: // Not here either default: console.log("PASS default") case 2: console.log("PASS 2") } } expect: { switch (id(1)) { case 0: "no side effect" case 1: // Not here either default: console.log("PASS default") case 2: console.log("PASS 2") } } } trim_side_effect_free_branches_falling_into_default_2: { options = { switches: true, dead_code: true } input: { switch (id(1)) { default: case 0: "no side effect" case 1: console.log("PASS default") case 2: console.log("PASS 2") } } expect: { switch (id(1)) { default: case 0: "no side effect" case 1: console.log("PASS default") case 2: console.log("PASS 2") } } } gut_entire_switch: { options = { switches: true, dead_code: true } input: { switch (id(123)) { case 1: case 2: case 3: default: console.log("PASS"); } } expect: { id(123); console.log("PASS"); } expect_stdout: "PASS" } gut_entire_switch_2: { options = { switches: true, dead_code: true } input: { switch (id(123)) { case 1: "no side effect" case 1: // Not here either default: console.log("PASS"); } } expect: { id(123); console.log("PASS"); } expect_stdout: "PASS" } turn_into_if: { options = { switches: true, dead_code: true } input: { switch (id(1)) { case id(2): console.log("FAIL"); } console.log("PASS"); } expect: { if (id(1) === id(2)) console.log("FAIL"); console.log("PASS"); } expect_stdout: "PASS" } turn_into_if_2: { options = { switches: true, dead_code: true } input: { switch (id(1)) { case id(2): console.log("FAIL"); default: console.log("PASS"); } } expect: { if (id(1) === id(2)) console.log("FAIL"); console.log("PASS"); } expect_stdout: "PASS" } issue_1083_1: { options = { switches: true, dead_code: true } input: { function test(definitely_true, maybe_true) { switch (true) { case definitely_true: default: console.log("PASS"); break; case maybe_true: console.log("FAIL"); break; } } test(true, false); test(true, true); } expect: { function test(definitely_true, maybe_true) { switch (true) { case definitely_true: default: console.log("PASS"); break; case maybe_true: console.log("FAIL"); } } test(true, false); test(true, true); } expect_stdout: ["PASS", "PASS"] } issue_1083_2: { options = { switches: true, dead_code: true } input: { function test(definitely_true, maybe_true) { switch (true) { case definitely_true: default: console.log("PASS"); break; case maybe_true: console.log("FAIL"); break; } } test(true, false); test(true, true); } expect: { function test(definitely_true, maybe_true) { switch (true) { case definitely_true: default: console.log("PASS"); break; case maybe_true: console.log("FAIL"); } } test(true, false); test(true, true); } expect_stdout: ["PASS", "PASS"] } issue_1083_3: { options = { switches: true, dead_code: true } input: { function test(definitely_true, maybe_true) { switch (true) { case maybe_true: console.log("maybe"); break; default: case definitely_true: console.log("definitely"); break; } } test(true, false); test(true, true); } expect: { function test(definitely_true, maybe_true) { if (true === maybe_true) console.log("maybe"); else console.log("definitely"); } test(true, false); test(true, true); } expect_stdout: ["definitely", "maybe"] } issue_1083_4: { options = { switches: true, dead_code: true } input: { function test(definitely_true, maybe_true) { switch (true) { case maybe_true: console.log("maybe"); break; case definitely_true: default: console.log("definitely"); break; } } test(true, false); test(true, true); } expect: { function test(definitely_true, maybe_true) { if (true === maybe_true) console.log("maybe"); else console.log("definitely"); } test(true, false); test(true, true); } expect_stdout: ["definitely", "maybe"] } issue_1083_5: { options = { switches: true, dead_code: true } input: { function test(definitely_true, maybe_true) { switch (true) { default: console.log("definitely"); break; case maybe_true: console.log("maybe"); break; case definitely_true: console.log("definitely"); break; } } test(true, false); test(true, true); } expect: { function test(definitely_true, maybe_true) { switch (true) { default: console.log("definitely"); break; case maybe_true: console.log("maybe"); break; case definitely_true: console.log("definitely"); } } test(true, false); test(true, true); } expect_stdout: ["definitely", "maybe"] } issue_1083_6: { options = { switches: true, dead_code: true } input: { function test(definitely_true, maybe_true) { switch (true) { case definitely_true: console.log("definitely"); break; case maybe_true: console.log("maybe"); break; default: console.log("definitely"); break; } } test(true, false); test(true, true); } expect: { function test(definitely_true, maybe_true) { switch (true) { case definitely_true: console.log("definitely"); break; case maybe_true: console.log("maybe"); break; default: console.log("definitely"); } } test(true, false); test(true, true); } expect_stdout: ["definitely", "definitely"] } terser-5.19.2/test/compress/syntax-errors.js000066400000000000000000000157201445647217600211510ustar00rootroot00000000000000 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 }) } invalid_privatename_in_object: { input: ` const myObject = { foo: 'bar', #something: 5, } ` expect_error: ({ name: "SyntaxError", message: "private fields are not allowed in an object", line: 4, col: 12 }) } private_field_out_of_class_field: { input: ` function test() { return this.#p; } ` expect_error: ({ name: "SyntaxError", message: "Private field must be used in an enclosing class", line: 3, col: 24 }) } private_field_out_of_class_field_in_operator: { input: ` function test(input) { #p in input; return 10; } ` expect_error:({ name: "SyntaxError", message: "Private field must be used in an enclosing class", line: 3, col: 12 }) } invaild__in_operator_expression_in_class_field: { input: ` class A { #p; isA () { #p + 10; return this.#p; } } ` expect_error: ({ name: "SyntaxError", message: "Unexpected token operator «+», expected operator «in»", line: 5, col: 19 }) } terser-5.19.2/test/compress/template-string.js000066400000000000000000000505361445647217600214340ustar00rootroot00000000000000tagged_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 concatenation 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, unsafe: 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(); } } template_evaluate_undefined: { options = { evaluate: true, reduce_vars: true } input: { // test.js () => { let x; console.log(x + `?ts=${Date.now()}`); }; } expect: { () => { let x; console.log(`undefined?ts=${Date.now()}`); }; } } evaluate_nested_templates: { options = { evaluate: true } beautify = { quote_style: 0 } input: { var foo = `${`${`${`foo`}`}`}`; var bar = `before ${`innerBefore ${any} innerAfter`} after`; var baz = `1 ${2 + `3 ${any} 4` + 5} 6`; } expect: { var foo = "foo"; var bar = `before innerBefore ${any} innerAfter after`; var baz = `1 23 ${any} 45 6`; } } 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", ] } 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", ] } 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" } 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", ] } 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}" } 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" ] } 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" } tagged_template_function_inline_1: { options = { defaults: true, toplevel: true } input: { var tpl = () => {}; tpl`test`; } expect_exact: "(()=>{})`test`;" } tagged_template_function_inline_2: { options = { defaults: true, toplevel: true } input: { var tpl = function(){}; tpl`test`; } expect_exact: "(function(){})`test`;" } tagged_template_function_inline_3: { options = { defaults: true, toplevel: true } input: { function tpl(){}; tpl`test`; } expect_exact: "(function(){})`test`;" } tagged_template_function_inline_4: { options = { defaults: true, toplevel: true } input: { const t = { pl: function () {} } t.pl`test`; } expect_exact: "(function(){})`test`;" } tagged_template_function_inline_5: { options = { defaults: true, toplevel: true } input: { const t = { pl() {} } t.pl`test`; } expect_exact: "({pl(){}}.pl)`test`;" } allow_null_character: { output = { ascii_only: true } input: { `\0`; `\0${x}`; } expect_exact: "`\\0`;`\\0${x}`;" } template_literal_plus: { options = { evaluate: true, } input: { console.log(`foo${any}baz` + 1); console.log(1 + `foo${any}baz`); console.log(`1${any}2` + `foo${any}baz`); } expect: { console.log(`foo${any}baz1`); console.log(`1foo${any}baz`); console.log(`1${any}2foo${any}baz`); } } template_literal_plus_grouping: { options = { evaluate: true, } input: { console.log((`foo${any}baz` + 'middle') + 'test'); console.log('test' + ('middle' + `foo${any}baz`)); console.log((`1${any}2` + '3') + ('4' + `foo${any}baz`)); console.log((1 + `2${any}3` + '4') + ('5' + `foo${any}baz` + 6)); } expect: { console.log(`foo${any}bazmiddletest`); console.log(`testmiddlefoo${any}baz`); console.log(`1${any}234foo${any}baz`); console.log(`12${any}345foo${any}baz6`); } } array_join: { options = { evaluate: true, unsafe: true, } input: { var foo = [`1 ${any} 2`].join(''); var bar = ["before", `1 ${any} 2`].join(''); var baz = [`1 ${any} 2`, "after"].join(''); var qux = ["before", `1 ${any} 2`, "after"].join(''); } expect: { var foo = `1 ${any} 2`; var bar = `before1 ${any} 2`; var baz = `1 ${any} 2after`; var qux = `before1 ${any} 2after`; } } equality: { options = { evaluate: true, comparisons: true, } input: { var a = `1${any}2` === '12' var b = `1${any}2` === `12` } expect: { var a = `1${any}2` == "12" var b = `1${any}2` == "12" } } coerce_to_string: { options = { evaluate: true, unsafe: true } input: { var str = `${any}`; } expect: { var str = '' + any; } } special_chars_in_string: { options = { evaluate: true, } input: { var str = `foo ${'`;\n`${any}'} bar`; var concat = `foo ${any} bar` + '`;\n`${any}'; var template = `foo ${'`;\n`${any}'} ${any} bar`; } expect: { var str="foo `;\n`${any} bar"; var concat=`foo ${any} bar\`;\n\`\${any}`; var template=`foo \`;\n\`\${any} ${any} bar`; } } template_string_new_parens: { input: { new Thing()`` } expect_exact: "(new Thing)``;" } template_string_nested: { input: { console.log(`${`${2,0}`} ${1}`) console.log(`${String.raw`${2,0}\n`} ${1}`) } expect_stdout: [ "0 1", "0\\n 1", ] } terser-5.19.2/test/compress/toplevel-await.js000066400000000000000000000007321445647217600212430ustar00rootroot00000000000000'use strict' // Tests for toplevel await need strict mode which messes with the other tests in async.js /* eslint-ignore */ toplevel_await: { input: { 'use strict'; await x; } expect: { 'use strict'; await x; } } toplevel_await_for: { input: { 'use strict' for await (const x of y) { foo(); } } expect: { 'use strict' for await (const x of y) foo(); } } terser-5.19.2/test/compress/transform.js000066400000000000000000000044201445647217600203170ustar00rootroot00000000000000booleans_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-5.19.2/test/compress/try-catch.js000066400000000000000000000056361445647217600202140ustar00rootroot00000000000000catch_destructuring_with_sequence: { beautify = { ecma: 2015 } 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" } parent_scope_of_catch_block_is_not_the_try_block: { mangle = {} input: { function test(foo, bar) { try { const bar = {}; throw 'PASS' } catch (error) { return bar(error); } } console.log(test(null, x => x)); } expect_stdout: "PASS" } issue_452: { options = { toplevel: true, unused: true } input: { try { const arr = ['PASS']; for (const x of arr) { console.log(x) } } catch(e) { } } expect_stdout: 'PASS' } terser-5.19.2/test/compress/typeof.js000066400000000000000000000136371445647217600176240ustar00rootroot00000000000000typeof_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 h() { console.log("YUP"); } console.log("YES"); 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(typeof arguments); })(); } 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-5.19.2/test/compress/unicode.js000066400000000000000000000117651445647217600177440ustar00rootroot00000000000000unicode_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; } } keep_quoted_unicode_props_es5: { beautify = { ecma: 5 } input: { console.log({ "\uA7A0": "2139" }); } expect_exact: 'console.log({"Ꞡ":"2139"});' } keep_quoted_unicode_props_safari: { beautify = { safari10: true, ecma: 2020 } input: { console.log({ "\uA7A0": "2139" }); } expect_exact: 'console.log({"Ꞡ":"2139"});' } unicode_props_safari: { beautify = { safari10: true, ecma: 2020 } input: { console.log({ 𝒶: "foo" }) } expect_exact: 'console.log({"𝒶":"foo"});' } unicode_escaped_identifier_2015: { beautify = {ecma: 2015} input: { var \u{61} = "foo"; var \u{10000} = "bar"; } expect_exact: 'var a="foo";var \u{10000}="bar";'; } unicode_escaped_identifier_safari: { beautify = {ecma: 2020, safari10: true} input: { var \u{61} = "foo"; } expect_exact: 'var a="foo";'; } unicode_escaped_identifier_es5_as_is: { beautify = {ecma: 5} input: ` var \u{10000} = "bar"; ` expect_exact: 'var \u{10000}="bar";' } unicode_identifier_ascii_only: { beautify = {ascii_only: true, ecma: 2015} 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: 2015} 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: 2015} 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: 2015} 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: 2015} input: { var µþ = "µþ"; } expect_exact: 'var \\u00b5\\u00fe="\\xb5\\xfe";' } non_escape_2_non_escape: { beautify = {ascii_only: false, ecma: 2015} 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 ]" } issue_1147: { format = { ecma: 2015, ascii_only: true, safari10: false } input: { console.log(/📞/.test("📞")) } expect_exact: 'console.log(/\\ud83d\\udcde/.test("\\u{1f4de}"));' expect_stdout: "true" } terser-5.19.2/test/compress/unsafe_symbols.js000066400000000000000000000004361445647217600213400ustar00rootroot00000000000000unsafe_symbols_1: { options = {} input: { Symbol("kDog"); } expect_exact: 'Symbol("kDog");' } unsafe_symbols_2: { options = { unsafe: true, unsafe_symbols: true } input: { Symbol("kDog"); } expect_exact: 'Symbol();' }terser-5.19.2/test/compress/wrap_iife.js000066400000000000000000000016731445647217600202600ustar00rootroot00000000000000wrap_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-5.19.2/test/compress/yield.js000066400000000000000000000164051445647217600174200ustar00rootroot00000000000000generators: { 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_await_comment: { options = { toplevel: true, reduce_vars: true, inline: true, evaluate: true, unused: true } input: { const apiWithComments = () => /**! @preserve 1 */ http.get("1"); const apiWithComments2 = () => /**! @preserve 2 */ http.get("2"); const apiWithComments3 = () => /**! @preserve 3 */ http.get("3"); export function* test() { (yield apiWithComments()).data; } export async function test2() { (await apiWithComments2(await apiWithComments3())).data; } } expect_exact: [ "export function*test(){(", "/**! @preserve 1 */", "yield http.get(\"1\")).data}export async function test2(){(", "/**! @preserve 3 */", "await(await http.get(\"3\"),", "/**! @preserve 2 */", "http.get(\"2\"))).data}", ] } 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-5.19.2/test/fetch.cjs000066400000000000000000000015651445647217600157140ustar00rootroot00000000000000var 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-5.19.2/test/functional.sh000077500000000000000000000010131445647217600166070ustar00rootroot00000000000000#!/bin/bash set -exuo pipefail workdir=$(pwd) # for tests that need terser-under-test path and @terser/require-terser export TERSER_PATH="$workdir" # build terser npm run build # grab the functional tests mkdir -p terser-functional-tests cd terser-functional-tests git checkout . || true git clone https://github.com/terser/terser-functional-tests --depth 1 . || true git pull # install packages and link terser in (can't npm link .., it crashes) npm ci (cd node_modules && rm -rf terser && ln -s ../.. terser) npm t terser-5.19.2/test/fuzz.cjs000077500000000000000000000027131445647217600156200ustar00rootroot00000000000000#! /usr/bin/env node /* eslint-env node */ var acorn = require("acorn"); var generateRandomJS = require("eslump").generateRandomJS; var minify = require("..").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: ", "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-5.19.2/test/input/000077500000000000000000000000001445647217600152525ustar00rootroot00000000000000terser-5.19.2/test/input/comments/000077500000000000000000000000001445647217600170775ustar00rootroot00000000000000terser-5.19.2/test/input/comments/filter.js000066400000000000000000000000341445647217600207170ustar00rootroot00000000000000// foo /*@preserve*/ // bar terser-5.19.2/test/input/config-file/000077500000000000000000000000001445647217600174345ustar00rootroot00000000000000terser-5.19.2/test/input/config-file/1.js000066400000000000000000000000261445647217600201300ustar00rootroot00000000000000console.log("First"); terser-5.19.2/test/input/config-file/2.js000066400000000000000000000000271445647217600201320ustar00rootroot00000000000000console.log("Second"); terser-5.19.2/test/input/config-file/cf.json000066400000000000000000000001201445647217600207100ustar00rootroot00000000000000{ "files": ["test/input/config-file/1.js", "test/input/config-file/2.js"] } terser-5.19.2/test/input/defaults/000077500000000000000000000000001445647217600170615ustar00rootroot00000000000000terser-5.19.2/test/input/defaults/input.js000066400000000000000000000000461445647217600205560ustar00rootroot00000000000000if (true) { console.log(1 + 2); } terser-5.19.2/test/input/enclose/000077500000000000000000000000001445647217600167025ustar00rootroot00000000000000terser-5.19.2/test/input/enclose/input.js000066400000000000000000000001031445647217600203710ustar00rootroot00000000000000function enclose() { console.log("test enclose"); } enclose(); terser-5.19.2/test/input/global_defs/000077500000000000000000000000001445647217600175135ustar00rootroot00000000000000terser-5.19.2/test/input/global_defs/nested.js000066400000000000000000000000271445647217600213320ustar00rootroot00000000000000console.log(C.V, C.D); terser-5.19.2/test/input/global_defs/simple.js000066400000000000000000000000201445647217600213320ustar00rootroot00000000000000console.log(D); terser-5.19.2/test/input/invalid/000077500000000000000000000000001445647217600167005ustar00rootroot00000000000000terser-5.19.2/test/input/invalid/assign_1.js000066400000000000000000000000271445647217600207410ustar00rootroot00000000000000console.log(1 || 5--); terser-5.19.2/test/input/invalid/assign_2.js000066400000000000000000000000501445647217600207360ustar00rootroot00000000000000console.log(2 || (Math.random() /= 2)); terser-5.19.2/test/input/invalid/assign_3.js000066400000000000000000000000321445647217600207370ustar00rootroot00000000000000console.log(3 || ++this); terser-5.19.2/test/input/invalid/assign_4.js000066400000000000000000000000071445647217600207420ustar00rootroot00000000000000++null terser-5.19.2/test/input/invalid/eof.js000066400000000000000000000000121445647217600200000ustar00rootroot00000000000000foo, bar( terser-5.19.2/test/input/invalid/loop-no-body.js000066400000000000000000000000351445647217600215520ustar00rootroot00000000000000for (var i = 0; i < 1; i++) terser-5.19.2/test/input/invalid/simple.js000066400000000000000000000000171445647217600205250ustar00rootroot00000000000000function f(a{} terser-5.19.2/test/input/invalid/tab.js000066400000000000000000000000231445647217600177770ustar00rootroot00000000000000 foo( xyz, 0abc); terser-5.19.2/test/input/issue-1236/000077500000000000000000000000001445647217600167735ustar00rootroot00000000000000terser-5.19.2/test/input/issue-1236/simple.js000066400000000000000000000002001445647217600206120ustar00rootroot00000000000000"use strict"; var foo = function foo(x) { return "foo " + x; }; console.log(foo("bar")); //# sourceMappingURL=simple.js.map terser-5.19.2/test/input/issue-1236/simple.js.map000066400000000000000000000004371445647217600214020ustar00rootroot00000000000000{ "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-5.19.2/test/input/issue-1242/000077500000000000000000000000001445647217600167705ustar00rootroot00000000000000terser-5.19.2/test/input/issue-1242/bar.es5000066400000000000000000000001051445647217600201460ustar00rootroot00000000000000function bar(x) { var triple = x * (2 + 1); return triple; } terser-5.19.2/test/input/issue-1242/baz.es5000066400000000000000000000000731445647217600201620ustar00rootroot00000000000000function baz(x) { var half = x / 2; return half; } terser-5.19.2/test/input/issue-1242/foo.es5000066400000000000000000000001541445647217600201710ustar00rootroot00000000000000var print = console.log.bind(console); function foo(x) { var twice = x * 2; print('Foo:', twice); } terser-5.19.2/test/input/issue-1242/qux.js000066400000000000000000000001141445647217600201370ustar00rootroot00000000000000var x = bar(1+2); var y = baz(3+9); print('q' + 'u' + 'x', x, y); foo(5+6); terser-5.19.2/test/input/issue-1323/000077500000000000000000000000001445647217600167705ustar00rootroot00000000000000terser-5.19.2/test/input/issue-1323/sample.js000066400000000000000000000001421445647217600206040ustar00rootroot00000000000000var bar = (function () { function foo (bar) { return bar; } return foo; })();terser-5.19.2/test/input/issue-1431/000077500000000000000000000000001445647217600167705ustar00rootroot00000000000000terser-5.19.2/test/input/issue-1431/sample.js000066400000000000000000000003121445647217600206030ustar00rootroot00000000000000function 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-5.19.2/test/input/issue-1482/000077500000000000000000000000001445647217600167765ustar00rootroot00000000000000terser-5.19.2/test/input/issue-1482/braces.js000066400000000000000000000014361445647217600205770ustar00rootroot00000000000000if (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-5.19.2/test/input/issue-1482/default.js000066400000000000000000000006561445647217600207670ustar00rootroot00000000000000if (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-5.19.2/test/input/issue-1482/input.js000066400000000000000000000006251445647217600204760ustar00rootroot00000000000000if (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-5.19.2/test/input/issue-1632/000077500000000000000000000000001445647217600167735ustar00rootroot00000000000000terser-5.19.2/test/input/issue-1632/^{foo}[bar](baz)+$.js000066400000000000000000000000171445647217600225520ustar00rootroot00000000000000console.log(x);terser-5.19.2/test/input/issue-2082/000077500000000000000000000000001445647217600167735ustar00rootroot00000000000000terser-5.19.2/test/input/issue-2082/sample.js000066400000000000000000000000171445647217600206100ustar00rootroot00000000000000console.log(x);terser-5.19.2/test/input/issue-2082/sample.js.map000066400000000000000000000000671445647217600213710ustar00rootroot00000000000000{"version": 3,"sources": ["index.js"],"mappings": ";"} terser-5.19.2/test/input/issue-2310/000077500000000000000000000000001445647217600167655ustar00rootroot00000000000000terser-5.19.2/test/input/issue-2310/input.js000066400000000000000000000002001445647217600204520ustar00rootroot00000000000000function foo() { return function() { console.log("PASS"); }; } (function() { var f = foo(); f(); })(); terser-5.19.2/test/input/issue-483/000077500000000000000000000000001445647217600167165ustar00rootroot00000000000000terser-5.19.2/test/input/issue-483/input.js000066400000000000000000000001721445647217600204130ustar00rootroot00000000000000function func1(obj) { obj._somePrivateProperty = false; } function func2(obj) { obj.nonPrivateProperty = true; } terser-5.19.2/test/input/issue-505/000077500000000000000000000000001445647217600167115ustar00rootroot00000000000000terser-5.19.2/test/input/issue-505/input.js000066400000000000000000000001461445647217600204070ustar00rootroot00000000000000function test(callback) { 'aaaaaaaaaaaaaaaa'; callback(err, data); callback(err, data); } terser-5.19.2/test/input/issue-505/output.js000066400000000000000000000005041445647217600206060ustar00rootroot00000000000000function test(a){ "aaaaaaaaaaaaaaaa" ;a(err,data),a(err,data) } //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJ0ZXN0IiwiY2FsbGJhY2siLCJlcnIiLCJkYXRhIl0sInNvdXJjZXMiOlsiMCJdLCJtYXBwaW5ncyI6IkFBQUEsU0FBU0EsS0FBS0M7QUFDVjtDQUNBQSxFQUFTQyxJQUFLQyxNQUNkRixFQUFTQyxJQUFLQztBQUNsQiJ9terser-5.19.2/test/input/issue-520/000077500000000000000000000000001445647217600167065ustar00rootroot00000000000000terser-5.19.2/test/input/issue-520/input.js000066400000000000000000000011241445647217600204010ustar00rootroot00000000000000var 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-5.19.2/test/input/issue-520/output.js000066400000000000000000000005351445647217600206070ustar00rootroot00000000000000new function(){console.log(3)}; //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJjb25zb2xlIiwibG9nIl0sInNvdXJjZXMiOlsic3RkaW4iXSwic291cmNlc0NvbnRlbnQiOlsiY2xhc3MgRm9vIHsgY29uc3RydWN0b3IoKXtjb25zb2xlLmxvZygxKzIpO30gfSBuZXcgRm9vKCk7XG4iXSwibWFwcGluZ3MiOiJBQUErQyxJQUFyQyxXQUFnQkEsUUFBUUMsSUFBSSxFQUFLIn0= terser-5.19.2/test/input/issue-585/000077500000000000000000000000001445647217600167215ustar00rootroot00000000000000terser-5.19.2/test/input/issue-585/input.js000066400000000000000000000002041445647217600204120ustar00rootroot00000000000000/*! * This comment should get removed in output if command * line argument --comment has been set to false. * * @license ISC */terser-5.19.2/test/input/module/000077500000000000000000000000001445647217600165375ustar00rootroot00000000000000terser-5.19.2/test/input/module/input.js000066400000000000000000000000461445647217600202340ustar00rootroot00000000000000let foo = 1, bar = 2; export { foo }; terser-5.19.2/test/input/rename/000077500000000000000000000000001445647217600165215ustar00rootroot00000000000000terser-5.19.2/test/input/rename/input.js000066400000000000000000000001171445647217600202150ustar00rootroot00000000000000function f(x) { return g(x); function g(x) { return x; } } terser-5.19.2/test/input/source-maps/000077500000000000000000000000001445647217600175105ustar00rootroot00000000000000terser-5.19.2/test/input/source-maps/expect.js000066400000000000000000000024161445647217600213410ustar00rootroot00000000000000"use strict";var __awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){function adopt(value){return value instanceof P?value:new P((function(resolve){resolve(value)}))}return new(P||(P=Promise))((function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator["throw"](value))}catch(e){reject(e)}}function step(result){result.done?resolve(result.value):adopt(result.value).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())}))};function somePromiseFn(){return __awaiter(this,void 0,void 0,(function*(){let value="promise-value";return value}))}somePromiseFn().then((d=>console.info(d))); //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJzb21lUHJvbWlzZUZuIiwidmFsdWUiLCJ0aGVuIiwiZCIsImNvbnNvbGUiLCJpbmZvIl0sInNvdXJjZXMiOlsiaW5wdXQudHN4Il0sInNvdXJjZXNDb250ZW50IjpbImFzeW5jIGZ1bmN0aW9uIHNvbWVQcm9taXNlRm4oKTogUHJvbWlzZTxzdHJpbmc+IHtcbiAgbGV0IHZhbHVlID0gJ3Byb21pc2UtdmFsdWUnO1xuICByZXR1cm4gdmFsdWU7IFxufVxuXG5zb21lUHJvbWlzZUZuKCkudGhlbihkID0+IGNvbnNvbGUuaW5mbyhkKSk7Il0sIm1hcHBpbmdzIjoieWpCQUFBLFNBQWVBLGdCLGlEQUNiLElBQUlDLE1BQVEsZ0JBQ1osT0FBT0EsS0FDVCxHLENBRUFELGdCQUFnQkUsTUFBS0MsR0FBS0MsUUFBUUMsS0FBS0YifQ== terser-5.19.2/test/input/source-maps/input.js000066400000000000000000000015751445647217600212150ustar00rootroot00000000000000"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; function somePromiseFn() { return __awaiter(this, void 0, void 0, function* () { let value = 'promise-value'; return value; }); } somePromiseFn().then(d => console.info(d)); terser-5.19.2/test/input/source-maps/input.js.map000066400000000000000000000007571445647217600217720ustar00rootroot00000000000000{ "version": 3, "file": "input.js", "sourceRoot": "", "sources": [ "input.tsx" ], "names": [], "mappings": ";;;;;;;;;;AAAA,SAAe,aAAa;;QAC1B,IAAI,KAAK,GAAG,eAAe,CAAC;QAC5B,OAAO,KAAK,CAAC;IACf,CAAC;CAAA;AAED,aAAa,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC", "sourcesContent": [ "async function somePromiseFn(): Promise {\n let value = 'promise-value';\n return value; \n}\n\nsomePromiseFn().then(d => console.info(d));" ] } terser-5.19.2/test/input/spidermonkey/000077500000000000000000000000001445647217600177635ustar00rootroot00000000000000terser-5.19.2/test/input/spidermonkey/input.js000066400000000000000000000065721445647217600214720ustar00rootroot00000000000000import "mod-name"; import Foo from "bar"; import * as Food from "food" import { Bar, Baz } from "lel"; import Bar1, { Foo2 } from "lel"; import { Bar2 as kex, Baz as food } from "lel"; const x = 0b01; let y = 6; import.meta; console.log(import.meta.url); export default x; export const z = 4; export function fun() {} export * from "a.js"; export {A} from "a.js"; export {A1, B1} from "a.js"; (a, [b], {c:foo = 3}, ...d) => 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]() {} "%"(){} 1(){} property valued_property = 1 [computed_property] = 2 static static_property = 3 static [computed_static_property] = 4 #private_property = 5 static #private_static_property = 6 get #private_getter() {} set #private_setter(value) {} static { this.#private_static_property = 7; #private_static_property in this; } } 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; } const logicalExpression = 1 || 2; ``; `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; /[\\/]/; // Nullish coalescing hello?.foo?.["bar"]?.baz?.() ?? "default"; // Conditional assignments a ||= b; a &&= b; a ??= b; terser-5.19.2/test/jetstream.cjs000066400000000000000000000076421445647217600166230ustar00rootroot00000000000000#! /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.cjs"); 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 terser = child_process.fork("bin/terser", args, { silent: true }).on("exit", function(code) { console.log("terser", url.slice(site.length + 1), args.join(" ")); console.log(stderr); if (code) throw new Error("terser failed with code " + code); }); terser.stderr.on("data", function(data) { stderr += data; }).setEncoding("utf8"); terser.stdout.pipe(response); res.pipe(terser.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-5.19.2/test/mocha/000077500000000000000000000000001445647217600152025ustar00rootroot00000000000000terser-5.19.2/test/mocha/annotations.js000066400000000000000000000021051445647217600200730ustar00rootroot00000000000000import assert from "assert"; import { parse } from "../../lib/parse.js"; import { _PURE, _INLINE, _NOINLINE } from "../../lib/ast.js"; import { has_annotation } from "../../lib/utils/index.js"; describe("annotations", () => { describe("#__PURE__", function() { it("Should add a 'pure' annotation to the AST node", () => { const ast = parse("/*@__PURE__*/foo.bar.baz();impure()"); const [{body: call}, {body: call2}] = ast.body; assert(has_annotation(call, _PURE)); assert(!has_annotation(call2, _PURE)); }); }); describe("#__INLINE__", () => { it("Adds an annotation", () => { const ast = parse("/*@__INLINE__*/foo();"); const [{body: call}] = ast.body; assert(has_annotation(call, _INLINE)); }); }); describe("#__NOINLINE__", () => { it("Adds an annotation", () => { const ast = parse("/*@__NOINLINE__*/foo();"); const [{body: call}] = ast.body; assert(has_annotation(call, _NOINLINE)); }); }); }); terser-5.19.2/test/mocha/arguments.js000066400000000000000000000343411445647217600175520ustar00rootroot00000000000000import assert from "assert"; import "../../main.js"; import { AST_DefaultAssign, AST_Defun, AST_Destructuring, AST_Expansion, AST_Number, AST_ObjectKeyVal, AST_SymbolFunarg, AST_SymbolRef, } from "../../lib/ast.js"; import {parse} from "../../lib/parse.js"; describe("arguments", function() { it("Should known that arguments in functions are local scoped", function() { var ast = 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 = 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 = parse("function foo(a = 123) {}"); assert(ast.body[0] instanceof AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // First argument assert(ast.body[0].argnames[0] instanceof AST_DefaultAssign); assert(ast.body[0].argnames[0].left instanceof AST_SymbolFunarg); assert.strictEqual(ast.body[0].argnames[0].operator, "="); assert(ast.body[0].argnames[0].right instanceof AST_Number); ast = parse("function foo(a = a) {}"); assert(ast.body[0] instanceof AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // First argument assert(ast.body[0].argnames[0] instanceof AST_DefaultAssign); assert(ast.body[0].argnames[0].left instanceof AST_SymbolFunarg); assert.strictEqual(ast.body[0].argnames[0].operator, "="); assert(ast.body[0].argnames[0].right instanceof AST_SymbolRef); }); it("Should parse a function containing default assignments in destructuring correctly", function() { var ast = parse("function foo([a = 123]) {}"); assert(ast.body[0] instanceof AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // First argument assert(ast.body[0].argnames[0] instanceof 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 AST_DefaultAssign); assert(ast.body[0].argnames[0].names[0].left instanceof AST_SymbolFunarg); assert.strictEqual(ast.body[0].argnames[0].names[0].operator, "="); assert(ast.body[0].argnames[0].names[0].right instanceof AST_Number); ast = parse("function foo({a = 123}) {}"); assert(ast.body[0] instanceof AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // First argument assert(ast.body[0].argnames[0] instanceof 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 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 AST_DefaultAssign); assert(ast.body[0].argnames[0].names[0].value.left instanceof AST_SymbolFunarg); assert.strictEqual(ast.body[0].argnames[0].names[0].value.operator, "="); assert(ast.body[0].argnames[0].names[0].value.right instanceof AST_Number); ast = parse("function foo({a: a = 123}) {}"); assert(ast.body[0] instanceof AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // First argument assert(ast.body[0].argnames[0] instanceof 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 AST_ObjectKeyVal); assert.strictEqual(ast.body[0].argnames[0].names[0].key, "a"); assert(ast.body[0].argnames[0].names[0].value instanceof AST_DefaultAssign); // Property a of first argument assert(ast.body[0].argnames[0].names[0].value instanceof AST_DefaultAssign); assert(ast.body[0].argnames[0].names[0].value.left instanceof AST_SymbolFunarg); assert.strictEqual(ast.body[0].argnames[0].names[0].value.operator, "="); assert(ast.body[0].argnames[0].names[0].value.right instanceof AST_Number); }); it("Should parse a function containing default assignments in complex destructuring correctly", function() { var ast = parse("function foo([a, [b = 123]]){}"); assert(ast.body[0] instanceof AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // Check first argument assert(ast.body[0].argnames[0] instanceof 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 AST_SymbolFunarg); assert(ast.body[0].argnames[0].names[1] instanceof 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 AST_DefaultAssign); assert(ast.body[0].argnames[0].names[1].names[0].left instanceof 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 AST_Number); ast = parse("function foo([a, {b: c = 123}]){}"); assert(ast.body[0] instanceof AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // Check first argument assert(ast.body[0].argnames[0] instanceof 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 AST_SymbolFunarg); assert(ast.body[0].argnames[0].names[1] instanceof 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 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 AST_DefaultAssign); // Property b of second argument assert(ast.body[0].argnames[0].names[1].names[0].value instanceof AST_DefaultAssign); assert(ast.body[0].argnames[0].names[1].names[0].value.left instanceof 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 AST_Number); ast = parse("function foo({a, b: {b = 123}}){}"); assert(ast.body[0] instanceof AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // Check first argument assert(ast.body[0].argnames[0] instanceof 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 AST_ObjectKeyVal); assert.strictEqual(ast.body[0].argnames[0].names[0].key, "a"); assert(ast.body[0].argnames[0].names[0].value instanceof AST_SymbolFunarg); assert(ast.body[0].argnames[0].names[1] instanceof AST_ObjectKeyVal); assert.strictEqual(ast.body[0].argnames[0].names[1].key, "b"); assert(ast.body[0].argnames[0].names[1].value instanceof 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 AST_ObjectKeyVal); assert.strictEqual(content.names[0].key, "b"); assert(content.names[0].value instanceof AST_DefaultAssign); assert(content.names[0].value.left instanceof AST_SymbolFunarg); assert.strictEqual(content.names[0].value.operator, "="); assert(content.names[0].value.right instanceof AST_Number); ast = parse("function foo({a: {b = 123}}){}"); assert(ast.body[0] instanceof AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // Check first argument assert(ast.body[0].argnames[0] instanceof 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 AST_ObjectKeyVal); assert.strictEqual(ast.body[0].argnames[0].names[0].key, "a"); assert(ast.body[0].argnames[0].names[0].value instanceof 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 AST_ObjectKeyVal); assert.strictEqual(content.names[0].key, "b"); assert(content.names[0].value instanceof AST_DefaultAssign); assert(content.names[0].value.left instanceof AST_SymbolFunarg); assert.strictEqual(content.names[0].value.operator, "="); assert(content.names[0].value.right instanceof AST_Number); }); it("Should parse spread correctly", function() { var ast = parse("function foo(a, b, ...c){}"); assert(ast.body[0] instanceof AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 3); // Check parameters assert(ast.body[0].argnames[0] instanceof AST_SymbolFunarg); assert(ast.body[0].argnames[1] instanceof AST_SymbolFunarg); assert(ast.body[0].argnames[2] instanceof AST_Expansion); assert(ast.body[0].argnames[2].expression instanceof AST_SymbolFunarg); ast = parse("function foo([a, b, ...c]){}"); assert(ast.body[0] instanceof AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // Check first parameter assert(ast.body[0].argnames[0] instanceof 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 AST_SymbolFunarg); assert(ast.body[0].argnames[0].names[1] instanceof AST_SymbolFunarg); assert(ast.body[0].argnames[0].names[2] instanceof AST_Expansion); assert(ast.body[0].argnames[0].names[2].expression instanceof AST_SymbolFunarg); ast = parse("function foo([a, b, [c, ...d]]){}"); assert(ast.body[0] instanceof AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // Check first parameter assert(ast.body[0].argnames[0] instanceof 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 AST_SymbolFunarg); assert(ast.body[0].argnames[0].names[1] instanceof AST_SymbolFunarg); assert(ast.body[0].argnames[0].names[2] instanceof 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 AST_SymbolFunarg); assert(ast.body[0].argnames[0].names[2].names[1] instanceof AST_Expansion); assert(ast.body[0].argnames[0].names[2].names[1].expression instanceof AST_SymbolFunarg); ast = parse("function foo({a: [b, ...c]}){}"); assert(ast.body[0] instanceof AST_Defun); assert.strictEqual(ast.body[0].argnames.length, 1); // Check first parameter assert(ast.body[0].argnames[0] instanceof 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 AST_ObjectKeyVal); assert.strictEqual(ast.body[0].argnames[0].names[0].key, "a"); assert(ast.body[0].argnames[0].names[0].value instanceof 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 AST_SymbolFunarg); assert(ast.body[0].argnames[0].names[0].value.names[1] instanceof AST_Expansion); assert(ast.body[0].argnames[0].names[0].value.names[1].expression instanceof AST_SymbolFunarg); }); }); terser-5.19.2/test/mocha/arrow.js000066400000000000000000000547321445647217600167050ustar00rootroot00000000000000import assert from "assert"; import { minify } from "../../main.js"; import { parse } from "../../lib/parse.js"; import * as AST from "../../lib/ast.js"; 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() { parse(code); }; }; var error = function(e) { return 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", async function() { var tests = [ "f = ({, , ...x} = [1, 2]) => {};" ]; var test = function(code) { return function() { parse(code); }; }; var error = function(e) { return 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", async 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() { parse(code); }; }; var error = function(e) { return 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", async 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() { parse(code); }, function(e) { return /^Unexpected /.test(e.message); }, code); }); }); it("Should parse a function containing default assignment correctly", async function() { var ast = parse("var a = (a = 123) => {}"); assert(ast.body[0] instanceof AST.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof AST.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof AST.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof AST.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 AST.AST_DefaultAssign); assert(ast.body[0].definitions[0].value.argnames[0].left instanceof AST.AST_SymbolFunarg); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].operator, "="); assert(ast.body[0].definitions[0].value.argnames[0].right instanceof AST.AST_Number); ast = parse("var a = (a = a) => {}"); assert(ast.body[0] instanceof AST.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof AST.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof AST.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof AST.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 AST.AST_DefaultAssign); assert(ast.body[0].definitions[0].value.argnames[0].left instanceof AST.AST_SymbolFunarg); assert.strictEqual(ast.body[0].definitions[0].value.argnames[0].operator, "="); assert(ast.body[0].definitions[0].value.argnames[0].right instanceof AST.AST_SymbolRef); }); it("Should parse a function containing default assignments in destructuring correctly", async function() { var ast = parse("var a = ([a = 123]) => {}"); assert(ast.body[0] instanceof AST.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof AST.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof AST.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof AST.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 AST.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 AST.AST_DefaultAssign); assert(ast.body[0].definitions[0].value.argnames[0].names[0].left instanceof AST.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 AST.AST_Number); ast = parse("var a = ({a = 123}) => {}"); assert(ast.body[0] instanceof AST.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof AST.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof AST.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof AST.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 AST.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 AST.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 AST.AST_DefaultAssign); assert(ast.body[0].definitions[0].value.argnames[0].names[0].value.left instanceof AST.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 AST.AST_Number); ast = parse("var a = ({a: a = 123}) => {}"); assert(ast.body[0] instanceof AST.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof AST.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof AST.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof AST.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 AST.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 AST.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 AST.AST_DefaultAssign); assert(ast.body[0].definitions[0].value.argnames[0].names[0].value.left instanceof AST.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 AST.AST_Number); }); it("Should parse a function containing default assignments in complex destructuring correctly", async function() { var ast = parse("var a = ([a, [b = 123]]) => {}"); assert(ast.body[0] instanceof AST.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof AST.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof AST.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof AST.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 AST.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 AST.AST_SymbolFunarg); assert(ast.body[0].definitions[0].value.argnames[0].names[1] instanceof AST.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 AST.AST_DefaultAssign); assert(ast.body[0].definitions[0].value.argnames[0].names[1].names[0].left instanceof AST.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 AST.AST_Number); ast = parse("var a = ([a, {b: c = 123}]) => {}"); assert(ast.body[0] instanceof AST.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof AST.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof AST.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof AST.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 AST.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 AST.AST_SymbolFunarg); assert(ast.body[0].definitions[0].value.argnames[0].names[1] instanceof AST.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 AST.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 AST.AST_DefaultAssign); assert(ast.body[0].definitions[0].value.argnames[0].names[1].names[0].value.left instanceof AST.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 AST.AST_Number); ast = parse("var a = ({a, b: {b = 123}}) => {}"); assert(ast.body[0] instanceof AST.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof AST.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof AST.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof AST.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 AST.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 AST.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 AST.AST_SymbolFunarg); // First argument, property 2 assert(ast.body[0].definitions[0].value.argnames[0].names[1] instanceof AST.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 AST.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 AST.AST_ObjectKeyVal); // Content of first property in nested destructuring assert.strictEqual(content.names[0].key, "b"); assert(content.names[0].value instanceof AST.AST_DefaultAssign); assert(content.names[0].value.left instanceof AST.AST_SymbolFunarg); assert.strictEqual(content.names[0].value.operator, "="); assert(content.names[0].value.right instanceof AST.AST_Number); ast = parse("var a = ({a: {b = 123}}) => {}"); assert(ast.body[0] instanceof AST.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof AST.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof AST.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof AST.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 AST.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 AST.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 AST.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 AST.AST_ObjectKeyVal); // Check first property of nested destructuring assert.strictEqual(content.names[0].key, "b"); assert(content.names[0].value instanceof AST.AST_DefaultAssign); assert(content.names[0].value.left instanceof AST.AST_SymbolFunarg); assert.strictEqual(content.names[0].value.operator, "="); assert(content.names[0].value.right instanceof AST.AST_Number); }); it("Should parse spread correctly", async function() { var ast = parse("var a = (a, b, ...c) => {}"); assert(ast.body[0] instanceof AST.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof AST.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof AST.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof AST.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 AST.AST_SymbolFunarg); assert(ast.body[0].definitions[0].value.argnames[1] instanceof AST.AST_SymbolFunarg); assert(ast.body[0].definitions[0].value.argnames[2] instanceof AST.AST_Expansion); assert(ast.body[0].definitions[0].value.argnames[2].expression instanceof AST.AST_SymbolFunarg); ast = parse("var a = ([a, b, ...c]) => {}"); assert(ast.body[0] instanceof AST.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof AST.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof AST.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof AST.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 AST.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 AST.AST_SymbolFunarg); assert(ast.body[0].definitions[0].value.argnames[0].names[1] instanceof AST.AST_SymbolFunarg); assert(ast.body[0].definitions[0].value.argnames[0].names[2] instanceof AST.AST_Expansion); assert(ast.body[0].definitions[0].value.argnames[0].names[2].expression instanceof AST.AST_SymbolFunarg); ast = parse("var a = ([a, b, [c, ...d]]) => {}"); assert(ast.body[0] instanceof AST.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof AST.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof AST.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof AST.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 AST.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 AST.AST_SymbolFunarg); assert(ast.body[0].definitions[0].value.argnames[0].names[1] instanceof AST.AST_SymbolFunarg); assert(ast.body[0].definitions[0].value.argnames[0].names[2] instanceof AST.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 AST.AST_SymbolFunarg); assert(ast.body[0].definitions[0].value.argnames[0].names[2].names[1] instanceof AST.AST_Expansion); assert(ast.body[0].definitions[0].value.argnames[0].names[2].names[1].expression instanceof AST.AST_SymbolFunarg); ast = parse("var a = ({a: [b, ...c]}) => {}"); assert(ast.body[0] instanceof AST.AST_Var); assert.strictEqual(ast.body[0].definitions.length, 1); assert(ast.body[0].definitions[0] instanceof AST.AST_VarDef); assert(ast.body[0].definitions[0].name instanceof AST.AST_SymbolVar); assert(ast.body[0].definitions[0].value instanceof AST.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 AST.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 AST.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 AST.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 AST.AST_SymbolFunarg); assert(ast.body[0].definitions[0].value.argnames[0].names[0].value.names[1] instanceof AST.AST_Expansion); assert(ast.body[0].definitions[0].value.argnames[0].names[0].value.names[1].expression instanceof AST.AST_SymbolFunarg); }); it("Should handle arrow function with bind", async function() { async function min(code) { return (await minify(code, { mangle: false })).code; } assert.strictEqual( await min(await min("test(((index) => { console.log(this, index); }).bind(this, 1));")), "test((index=>{console.log(this,index)}).bind(this,1));" ); assert.strictEqual( await min(await min('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", async function() { async function min(code) { return (await minify(code, { mangle:false })).code; } assert.strictEqual( await min("export function foo(x) { bar = () => x; return 2};"), "export function foo(x){return bar=()=>x,2}" ); }); }); terser-5.19.2/test/mocha/builtins.js000066400000000000000000000031031445647217600173660ustar00rootroot00000000000000import { minify } from "../../main.js"; import assert from "assert"; describe("builtins", function() { it("Should not mangle builtins", async 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 = (await 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-5.19.2/test/mocha/class.js000066400000000000000000000044201445647217600166450ustar00rootroot00000000000000import assert from "assert"; import { parse } from "../../lib/parse.js"; import { minify } from "../../main.js"; describe("Class", function() { it("Should not accept spread on non-last parameters in methods", async 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() { parse(code); }; }; var error = function(e) { return /^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", async 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 = 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); } }); it("should work properly with class properties", async () => { const input = `class A { static a a; static fil = 1 another = ""; }`; const result = (await minify(input)).code; assert.strictEqual(result, 'class A{static a;a;static fil=1;another=""}'); }); }); terser-5.19.2/test/mocha/cli-2.js000066400000000000000000000174031445647217600164530ustar00rootroot00000000000000import assert from "assert"; import { exec } from "child_process"; import { readFileSync } from "fs"; function read(path) { return readFileSync(path, "utf8"); } describe("bin/terser (2)", function() { var tersercmd = '"' + process.argv[0] + '" bin/terser'; it("Should handle literal string as source map input", function(done) { var command = [ tersercmd, "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,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJmb28iLCJ4IiwiY29uc29sZSIsImxvZyJdLCJzb3VyY2VzIjpbImluZGV4LmpzIl0sIm1hcHBpbmdzIjoiYUFBQSxJQUFJQSxJQUFNLFNBQU5BLElBQU1DLEdBQUEsTUFBSyxPQUFTQSxDQUFkLEVBQ1ZDLFFBQVFDLElBQUlILElBQUkifQ==", "" ].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 = [ tersercmd, "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,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJmb28iLCJjb25zb2xlIiwibG9nIiwiZiJdLCJzb3VyY2VzIjpbInRlc3QvaW5wdXQvaXNzdWUtMjMxMC9pbnB1dC5qcyJdLCJtYXBwaW5ncyI6IkFBQUEsU0FBU0EsTUFDTCxPQUFPLFdBQ0hDLFFBQVFDLElBQUksT0FDaEIsQ0FDSixDQUdZRixLQUNSRyJ9", "" ].join("\n")); done(); }); }); it("Should dump AST as JSON", function(done) { var command = tersercmd + " 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 = tersercmd + " test/input/comments/filter.js -f 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 = tersercmd + " 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 = tersercmd + " 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 = tersercmd + " 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 = tersercmd + " 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 = tersercmd + " 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 = tersercmd + " 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 = tersercmd + " 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 = tersercmd + " 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 = tersercmd + " 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 = tersercmd + " 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 = tersercmd + " --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(); }); }); it("should parse regex options correctly", done => { var command = tersercmd + " --toplevel -m keep_fnames=/1$/ --mangle-props regex=/^_/ test/input/issue-483/input.js"; exec(command, function(err, stdout, stderr) { if (err) throw err; assert.strictEqual(stdout, "function func1(n){n.u=false}function n(n){n.nonPrivateProperty=true}\n"); done(); }); }); }); terser-5.19.2/test/mocha/cli.js000066400000000000000000000252031445647217600163110ustar00rootroot00000000000000import assert from "assert"; import { exec } from "child_process"; import fs from "fs"; import rimraf from "rimraf"; import { assertCodeWithInlineMapEquals } from "./utils.js"; function read(path) { return fs.readFileSync(path, "utf8"); } describe("bin/terser", function() { var tersercmd = '"' + process.argv[0] + '" bin/terser'; it("Should be able to filter comments correctly with `--comments all`", function(done) { var command = tersercmd + ' 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 = tersercmd + ' 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 = tersercmd + ' 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 = tersercmd + " 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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QvaW5wdXQvaXNzdWUtMTMyMy9zYW1wbGUuanMiXSwibmFtZXMiOlsiYmFyIiwiZm9vIl0sIm1hcHBpbmdzIjoiQUFBQSxJQUFJQSxJQUFNLFdBQ04sU0FBU0MsSUFBS0QsS0FDVixPQUFPQSxHQUNYLENBRUEsT0FBT0MsR0FDVixDQU5TIn0=\n"); done(); }); }); it("Should not append source map to output when not using --source-map url=inline", function(done) { var command = tersercmd + ' 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(); }); }); before(() => { try { fs.mkdirSync("./tmp"); } catch (e) { if (e.code != "EEXIST") throw e; } }); after(() => { rimraf.sync("./tmp"); }); it("Should not load source map before finish reading from STDIN", function(done) { var mapFile = "tmp/input.js.map"; var command = [ tersercmd, "--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 log its options into a file when given an env variable", (done) => { const command = [tersercmd, "tmp/input2.js", "-mc unused=false"].join(" "); fs.writeFileSync("tmp/input2.js", "hello(1 + 1)"); const dir = "tmp/debug-input"; exec(command, { env: { TERSER_DEBUG_DIR: dir }}, (err, stdout) => { if (err) throw err; assert(stdout.includes("hello(2)"), "make sure output isn't changed"); const inputLogs = fs.readdirSync(dir); assert(inputLogs.length == 1); const logFileContents = fs.readFileSync(dir + "/" + inputLogs.pop(), "utf-8"); assert(logFileContents.includes('"unused": false'), "includes the options"); assert(logFileContents.includes("input2.js: ```\nhello(1 + 1)\n```"), "includes the input"); done(); }); }); it("Should work with --keep-fnames (mangle only)", function(done) { var command = tersercmd + ' 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(r){return r*r}return r(n)}}function g(r){return r(1)+r(2)}console.log(f(g)()==5);\n"); done(); }); }); it("Should work with --keep-fnames (mangle & compress)", function(done) { var command = tersercmd + ' 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(r){return r*r}return r(n)}}function g(r){return r(1)+r(2)}console.log(5==f(g)());\n"); done(); }); }); it("Should work with keep_fnames under mangler options", function(done) { var command = tersercmd + ' 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(r){return r*r}return r(n)}}function g(r){return r(1)+r(2)}console.log(f(g)()==5);\n"); done(); }); }); it("Should work with --define (simple)", function(done) { var command = tersercmd + ' 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 = tersercmd + ' 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 = tersercmd + ' 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 alias `--beautify` with `--format`", function(done) { var command1 = tersercmd + ' test/input/enclose/input.js --beautify preamble=oops'; var command2 = tersercmd + ' test/input/enclose/input.js --format preamble=oops'; exec(command1, function (err, stdout1) { if (err) throw err; exec(command2, function(err, stdout2) { if (err) throw err; assert.strictEqual(stdout1, stdout2); done(); }); }); }); it("Should process inline source map", function(done) { var command = tersercmd + " 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 fail with multiple input and inline source map", function(done) { this.timeout(60000); var command = tersercmd + " 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 = tersercmd + " 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 = tersercmd + " 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 = tersercmd + ' 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 = tersercmd + ' 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 = tersercmd + ' 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-5.19.2/test/mocha/comments.js000066400000000000000000000331341445647217600173710ustar00rootroot00000000000000import assert from "assert"; import { minify } from "../../main.js"; import { parse } from "../../lib/parse.js"; import { OutputStream } from "../../lib/output.js"; import { for_each_async } from "./utils.js" describe("comments", function() { it("Should recognize eol of single line comments", async 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.message === "Unexpected token: operator (>)" && e.line === 2 && e.col === 0; }; for (var i = 0; i < tests.length; i++) { assert.throws(() => parse(tests[i]), fail, tests[i]); } }); it("Should update the position of a multiline comment correctly", async 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.message === "Unexpected token: operator (>)" && e.line === 5 && e.col === 0; } for (var i = 0; i < tests.length; i++) { assert.throws(() => parse(tests[i]), fail, tests[i]); } }); it("Should handle comment within return correctly", async function() { var result = await 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", async function() { var result = await 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", async function() { var code = "/* boo */\nx();"; var ast = parse(code); var out1 = OutputStream({ beautify: true, comments: "all", }); ast.print(out1); var out2 = OutputStream({ beautify: true, comments: "all", }); ast.print(out2); assert.strictEqual(out1.get(), code); assert.strictEqual(out2.get(), out1.get()); }); it("Should retain trailing comments", async 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 = await 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", async function() { var code = [ "{/* foo */}", "a({/* foo */});", "while (a) {/* foo */}", "switch (a) {/* foo */}", "if (a) {/* foo */} else {/* bar */}", ].join("\n\n"); var result = await 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", async function() { await for_each_async([ [ "// 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();", ], async function(code) { var result = await 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", async function() { var code = [ "function f(){", "/* foo */bar()}", ].join("\n"); var result = await 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", async function() { var result = await 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", async function() { var result = await 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.", async function() { var result = await 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.", async function() { var result = await 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", async function() { var ast = 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", async function() { var ast = 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", async function() { var ast = parse("// foo\n/*@preserve*/\n// bar\n/*@license*/\n//@lic two slashes\n/*@cc_on something*/"); assert.strictEqual(ast.print_to_string({comments: "some"}), "/*@preserve*/\n/*@license*/\n//@lic two slashes\n/*@cc_on something*/"); }); it("Should be able to filter comments by passing a function", async function() { var ast = 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", async function() { var ast = 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", async function() { var ast = 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", async function() { var ast = 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)", async function() { var ast = 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", async function() { var ast = 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", async function() { const options = { comments: /ok/ }; assert.strictEqual(parse("/* ok */function a(){}").print_to_string(options), "/* ok */function a(){}"); assert.strictEqual(parse("/* ok */function a(){}").print_to_string(options), "/* ok */function a(){}"); assert.strictEqual(parse("/* ok */function a(){}").print_to_string(options), "/* ok */function a(){}"); }); it("Should handle shebang and preamble correctly", async function() { var code = (await 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", async function() { var code = (await 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", async 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 = await minify(js, { mangle: false }); assert.strictEqual(result.code, "function lots_of_comments(x){return 7-x}"); }); }); }); terser-5.19.2/test/mocha/destructuring.js000066400000000000000000000106311445647217600204430ustar00rootroot00000000000000import assert from "assert"; import { minify } from "../../main.js"; import { parse } from "../../lib/parse.js"; import * as AST from "../../lib/ast.js"; describe("Destructuring", function() { it("Should generate similar trees for destructuring in left hand side expressions, definitions, functions and arrow functions", async 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: AST.AST_SymbolRef, tree: function (ast) { return ast.body[0].body.left; }, generate: function (code) { return "(" + code + " = a)"; } }, { name: "var", symbolType: AST.AST_SymbolVar, tree: function (ast) { return ast.body[0].definitions[0].name; }, generate: function (code) { return "var " + code + " = a"; } }, { name: "function", symbolType: AST.AST_SymbolFunarg, tree: function (ast) { return ast.body[0].argnames[0]; }, generate: function (code) { return "function a(" + code + ") {}"; } }, { name: "arrow", symbolType: AST.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 AST.TreeWalker(function(node) { if (w.parent() instanceof AST.AST_DefaultAssign && w.parent().right === node ) { return true; // Don't check the content of the default assignment } else if (node instanceof AST.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 AST.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( 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-5.19.2/test/mocha/directives.js000066400000000000000000000450051445647217600177050ustar00rootroot00000000000000import assert from "assert"; import { minify } from "../../main.js"; import * as AST from "../../lib/ast.js"; import { parse, tokenizer } from "../../lib/parse.js"; import { OutputStream } from "../../lib/output.js"; import { for_each_async } from "./utils.js"; describe("Directives", function() { it("Should allow tokenizer to store directives state", async function() { var tok = tokenizer("", "foo.js"); // Stack level 0 assert.strictEqual(tok.has_directive("use strict"), false); assert.strictEqual(tok.has_directive("use asm"), false); assert.strictEqual(tok.has_directive("use thing"), false); // Stack level 2 tok.push_directives_stack(); tok.push_directives_stack(); tok.add_directive("use strict"); assert.strictEqual(tok.has_directive("use strict"), true); assert.strictEqual(tok.has_directive("use asm"), false); assert.strictEqual(tok.has_directive("use thing"), false); // Stack level 3 tok.push_directives_stack(); tok.add_directive("use strict"); tok.add_directive("use asm"); assert.strictEqual(tok.has_directive("use strict"), true); assert.strictEqual(tok.has_directive("use asm"), true); assert.strictEqual(tok.has_directive("use thing"), false); // Stack level 2 tok.pop_directives_stack(); assert.strictEqual(tok.has_directive("use strict"), true); assert.strictEqual(tok.has_directive("use asm"), false); assert.strictEqual(tok.has_directive("use thing"), false); // Stack level 3 tok.push_directives_stack(); tok.add_directive("use thing"); tok.add_directive("use\\\nasm"); assert.strictEqual(tok.has_directive("use strict"), true); assert.strictEqual(tok.has_directive("use asm"), false); // Directives are strict! assert.strictEqual(tok.has_directive("use thing"), true); // Stack level 2 tok.pop_directives_stack(); assert.strictEqual(tok.has_directive("use strict"), true); assert.strictEqual(tok.has_directive("use asm"), false); assert.strictEqual(tok.has_directive("use thing"), false); // Stack level 1 tok.pop_directives_stack(); assert.strictEqual(tok.has_directive("use strict"), false); assert.strictEqual(tok.has_directive("use asm"), false); assert.strictEqual(tok.has_directive("use thing"), false); // Stack level 0 tok.pop_directives_stack(); assert.strictEqual(tok.has_directive("use strict"), false); assert.strictEqual(tok.has_directive("use asm"), false); assert.strictEqual(tok.has_directive("use thing"), false); }); it("Should know which strings are directive and which ones are not", async function() { var test_directive = function(tok, test) { test.directives.map(function(directive) { assert.strictEqual(tok.has_directive(directive), true, "Didn't found directive `" + directive + "` at the end of `" + test.input + '`'); }); test.non_directives.map(function(fake_directive) { assert.strictEqual(tok.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 tok = tokenizer(tests[i].input + "]", "foo.js"); try { var parser = parse(tok); throw new Error("Expected parser to fail"); } catch (e) { assert.strictEqual(e.message, "Unexpected token: punc (])"); } test_directive(tok, 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 tok = tokenizer(test[0] + "]", "foo.js"); assert.throws(function() { parse(tok); }, function(e) { return e.message === "Unexpected token: punc (])" }, test[0]); test[1].forEach(function(directive) { assert.strictEqual(tok.has_directive(directive), true, directive + " in " + test[0]); }); test[2].forEach(function(fake_directive) { assert.strictEqual(tok.has_directive(fake_directive), false, fake_directive + " in " + test[0]); }); }); }); it("Should test EXPECT_DIRECTIVE RegExp", async 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 = 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", async function() { var result = await 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", async function() { await for_each_async([ [ '{"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"}' ] ], async function(test) { var result = await 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", async function() { var result = await 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", async function() { await for_each_async([ // 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\"';", ], ], async function(test) { var result = await 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", async function() { await for_each_async([ [ '"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(){}' ], ], async function(test) { var result = await 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", async 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 AST.TreeWalker(function(node, descend) { if (node instanceof AST.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 = parse(tests[i].input); ast.walk(checkWalker); if (!checked) { throw "No _check_ symbol found in " + tests[i].input; } } }); }); terser-5.19.2/test/mocha/eof.js000066400000000000000000000020551445647217600163130ustar00rootroot00000000000000import assert from "assert"; import { parse } from "../../lib/parse.js"; describe("EOF", function() { it("Should test code for at least throwing syntax error when incomplete", async function() { // 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-5.19.2/test/mocha/equivalent-to.js000066400000000000000000000012411445647217600203330ustar00rootroot00000000000000"use strict"; import assert from "assert"; import "../../main.js" import { parse } from "../../lib/parse.js"; describe("equivalent_to", () => { it("(regression) two regexes should not be equivalent if their source or flags differ", async () => { const ast = parse("/^\s*$/u"); const ast2 = parse("/^\s*\*/u"); assert.equal(ast.equivalent_to(ast2), false); }); it("nested calls should not be equivalent even if a tree walk reveals equivalent nodes", async () => { const ast = parse("hello(1, world(2), 3)"); const ast2 = parse("hello(1, world(2, 3))"); assert.equal(ast.equivalent_to(ast2), false); }); }); terser-5.19.2/test/mocha/export.js000066400000000000000000000067401445647217600170700ustar00rootroot00000000000000import assert from "assert"; import { minify } from "../../main.js"; import { parse } from "../../lib/parse.js"; import * as AST from "../../lib/ast.js"; describe("Export/Import", function() { it("Should parse export directives", async 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 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 AST.AST_Toplevel); assert.equal(ast.body.length, 1); var st = ast.body[0]; assert(st instanceof AST.AST_Export); var actualNames = extractNames(st.exported_names); assert.deepEqual(actualNames, names); assert.equal(st.module_name.value, filename); } }); it("Should parse export with classes and functions", async function() { var inputs = [ ["export class X {}", "export class X{}"], ["export function X(){}", "export function X(){}"], ["export default function X(){}", "export default function X(){}"], ["export default class X{}", "export default class X{}"], ["export default class X extends Y{}", "export default class X extends Y{}"], ["export default class extends Y{}", "export default class extends Y{}"], ]; for (const [input, output] of inputs) { const minified = await minify(input); assert.equal(minified.code, output); } }); it("Should not parse invalid uses of export", async function() { await assert.rejects(() => minify("export"), { message: "Unexpected token: eof (undefined)" }); await assert.rejects(() => minify("export;"), { message: "Unexpected token: punc (;)" }); await assert.rejects(() => minify("export();"), { message: "Unexpected token: keyword (export)" }); await assert.rejects(() => minify("export(1);"), { message: "Unexpected token: keyword (export)" }); await assert.rejects(() => minify("var export;"), { message: "Name expected" }); await assert.rejects(() => minify("var export = 1;"), { message: "Name expected" }); await assert.rejects(() => minify("function f(export){}"), { message: "Invalid function parameter" }); }); it("Should not parse invalid uses of import", async function() { await assert.rejects(() => minify("import"), { message: "Unexpected token: eof (undefined)" }); await assert.rejects(() => minify("import;"), { message: "Unexpected token: punc (;)" }); await assert.rejects(() => minify("var import;"), { message: "Unexpected token: import" }); await assert.rejects(() => minify("var import = 1;"), { message: "Unexpected token: import" }); await assert.rejects(() => minify("function f(import){}"), { message: "Unexpected token: name (import)" }); }); }); terser-5.19.2/test/mocha/expression.js000066400000000000000000000013611445647217600177400ustar00rootroot00000000000000import assert from "assert"; import { parse } from "../../lib/parse.js"; describe("Expression", function() { it("Should not allow the first exponentiation operator to be prefixed with an unary operator", async 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 /^Unexpected token: operator \((?:[!+~-]|void|typeof|delete)\)/.test(e.message); } for (var i = 0; i < tests.length; i++) { assert.throws(() => parse(tests[i]), fail, tests[i]); } }); }); terser-5.19.2/test/mocha/function.js000066400000000000000000000227051445647217600173730ustar00rootroot00000000000000import assert from "assert"; import { minify } from "../../main.js"; import { parse } from "../../lib/parse.js"; import * as AST from "../../lib/ast.js"; describe("Function", function() { it("Should parse binding patterns correctly", async 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 = parse('(function ({a, b}) {})').body[0].body; var destr_fun2 = parse('(function ([a, [b]]) {})').body[0].body; var destr_fun3 = parse('({a, b}) => null').body[0].body; var destr_fun4 = 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 AST.AST_Destructuring); assert(destruct2 instanceof AST.AST_Destructuring); assert(destruct3 instanceof AST.AST_Destructuring); assert(destruct4 instanceof AST.AST_Destructuring); assert(destruct2.names[1] instanceof AST.AST_Destructuring); assert(destruct4.names[1] instanceof AST.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 () { parse('(function ( { a, [ b ] } ) { })') }); assert.throws(function () { parse('(function (1) { })'); }, /Invalid function parameter/); assert.throws(function () { parse('(function (this) { })'); }); assert.throws(function () { parse('(function ([1]) { })'); }, /Invalid function parameter/); assert.throws(function () { parse('(function [a] { })'); }); // generators var generators_def = parse('function* fn() {}').body[0]; assert.equal(generators_def.is_generator, true); assert.throws(function () { parse('function* (){ }'); }); var generators_yield_def = 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", async 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() { parse(code); }; } var error = function(e) { return /^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", async function() { var tests = [ "(function(,){})()", ]; var test = function(code) { return function() { parse(code, { ecma: 5 }); }; } var error = function(e) { return e instanceof Error; } for (var i = 0; i < tests.length; i++) { assert.throws(test(tests[i]), error, tests[i]); } }); it("Should not accept invalid trailing commas", async function() { var tests = [ "f(, );", "(, ) => {};", "(...p, ) => {};", "function f(, ) {}", "function f(...p, ) {}", "function foo(a, b, , ) {}", 'console.log("hello", , );', ]; var test = function(code) { return function() { parse(code, { ecma: 2017 }); }; } var error = function(e) { return e instanceof 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", async function() { var tests = [ "(function(...a = b){})()", "(function(a, ...b = [c, d]))" ]; var test = function(code) { return function () { parse(code); }; } var error = function (e) { return e instanceof 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", async 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 () { parse(code); }; } var error = function (e) { return /^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-5.19.2/test/mocha/glob.js000066400000000000000000000054501445647217600164670ustar00rootroot00000000000000import assert from "assert"; import { exec } from "child_process"; import path from "path"; describe("bin/terser with input file globs", function() { var tersercmd = '"' + process.argv[0] + '" bin/terser'; it("bin/terser with one input file extension glob.", function(done) { var command = tersercmd + ' "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/terser with one input file name glob.", function(done) { var command = tersercmd + ' "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/terser with multiple input file globs.", function(done) { var command = tersercmd + ' "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 = tersercmd + ' "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 = tersercmd + ' "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 = tersercmd + ' "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 = tersercmd + ' "' + [ 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-5.19.2/test/mocha/input-sourcemaps.js000066400000000000000000000101371445647217600210600ustar00rootroot00000000000000import assert from "assert"; import { minify } from "../../main.js"; import source_map from "source-map" const { SourceMapConsumer, SourceMapGenerator } = source_map 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\"));"] }; } async 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 = await minify(transpiled, { sourceMap: { content: transpilemap } }); map = await new SourceMapConsumer(result.map); } beforeEach(async function () { await prepareMap(); }); it("Should copy over original sourcesContent", async function() { assert.equal(map.sourceContentFor("index.js"), transpilemap.sourcesContent[0]); }); it("Should copy sourcesContent if sources are relative", async function() { var relativeMap = getMap(); relativeMap.sources = ['./index.js']; await 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)", async 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); }) }); it("Should preserve unmapped segments in output source map", async function() { var generator = new SourceMapGenerator(); generator.addMapping({ source: "source.ts", generated: {line: 1, column: 0}, original: {line: 1, column: 0}, }); generator.addMapping({ source: null, generated: {line: 1, column: 37}, original: null, }); generator.addMapping({ source: "source.ts", generated: {line: 1, column: 50}, original: {line: 2, column: 0}, }); generator.setSourceContent("source.ts", `function say(msg) {console.log(msg)};say('hello');\nprocess.exit(1);`) // Everything except the "say('hello');" part is mapped to "source.ts". The "say" // function call is not mapped to any original source location. e.g. this can // happen when a code transformer inserts generated code in between existing code. var inputFile = "function say(msg) {console.log(msg)};say('hello');process.exit(1);"; var result = await minify(inputFile, { sourceMap: { content: JSON.parse(generator.toString()), url: 'inline' } }); var transformedMap = await new SourceMapConsumer(result.map); var hasMappedSource = true; for (let i = 0; i < result.code.length; i++) { var info = transformedMap.originalPositionFor({line: 1, column: i}); hasMappedSource = hasMappedSource && !!info.source; } assert.equal(hasMappedSource, false, "Expected transformed source map to preserve the " + "mapping without original source location"); assert.doesNotThrow(() => SourceMapGenerator.fromSourceMap(transformedMap)); }); }); terser-5.19.2/test/mocha/issue-585.js000066400000000000000000000010031445647217600172010ustar00rootroot00000000000000import assert from "assert"; import { exec } from "child_process"; describe("bin/terser", function() { var tersercmd = '"' + process.argv[0] + '" bin/terser'; it("Should be able to filter comments correctly with `--comments false`", function(done) { var command = tersercmd + " test/input/issue-585/input.js --comments false"; exec(command, function (err, stdout) { if (err) throw err; assert.strictEqual(stdout, "\n"); done(); }); }); }); terser-5.19.2/test/mocha/lhs-expressions.js000066400000000000000000000320701445647217600207100ustar00rootroot00000000000000import assert from "assert"; import { minify } from "../../main.js"; import * as AST from "../../lib/ast.js"; import { parse } from "../../lib/parse.js"; describe("Left-hand side expressions", function () { it("Should parse destructuring with const/let/var correctly", async function() { var decls = 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 = 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 = 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 = 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", async function() { var ast = parse('["foo", "bar"]'); assert(ast.body[0] instanceof AST.AST_SimpleStatement); assert(ast.body[0].body instanceof AST.AST_Array); ast = parse('a = ["foo"]'); assert(ast.body[0] instanceof AST.AST_SimpleStatement); assert(ast.body[0].body instanceof AST.AST_Assign); assert(ast.body[0].body.left instanceof AST.AST_SymbolRef); assert.equal(ast.body[0].body.operator, "="); assert(ast.body[0].body.right instanceof AST.AST_Array); }); it("Parser should use AST_Object for object literals", async function() { var ast = parse('({foo: "bar"})'); assert(ast.body[0] instanceof AST.AST_SimpleStatement); assert(ast.body[0].body instanceof AST.AST_Object); // This example should be fine though ast = parse('a = {foo: "bar"}'); assert(ast.body[0] instanceof AST.AST_SimpleStatement); assert(ast.body[0].body instanceof AST.AST_Assign); assert(ast.body[0].body.left instanceof AST.AST_SymbolRef); assert.equal(ast.body[0].body.operator, "="); assert(ast.body[0].body.right instanceof AST.AST_Object); }); it("Parser should use AST_Destructuring for array assignment patterns", async function() { var ast = parse('[foo, bar] = [1, 2]'); assert(ast.body[0] instanceof AST.AST_SimpleStatement); assert(ast.body[0].body instanceof AST.AST_Assign); assert(ast.body[0].body.left instanceof AST.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 AST.AST_Array); }); it("Parser should use AST_Destructuring for object assignment patterns", async function() { var ast = parse('({a: b, b: c} = {b: "c", c: "d"})'); assert(ast.body[0] instanceof AST.AST_SimpleStatement); assert(ast.body[0].body instanceof AST.AST_Assign); assert(ast.body[0].body.left instanceof AST.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 AST.AST_Object); }); it("Parser should be able to handle nested destructuring", async function() { var ast = parse('[{a,b},[d, e, f, {g, h}]] = [{a: 1, b: 2}, [3, 4, 5, {g: 6, h: 7}]]'); assert(ast.body[0] instanceof AST.AST_SimpleStatement); assert(ast.body[0].body instanceof AST.AST_Assign); assert(ast.body[0].body.left instanceof AST.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 AST.AST_Array); assert(ast.body[0].body.left.names[0] instanceof AST.AST_Destructuring); assert.strictEqual(ast.body[0].body.left.names[0].is_array, false); assert(ast.body[0].body.left.names[1] instanceof AST.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 AST.AST_Destructuring); assert.strictEqual(ast.body[0].body.left.names[1].names[3].is_array, false); }); it("Should handle spread operator in destructuring", async function() { var ast = parse("[a, b, ...c] = [1, 2, 3, 4, 5]"); assert(ast.body[0] instanceof AST.AST_SimpleStatement); assert(ast.body[0].body instanceof AST.AST_Assign); assert(ast.body[0].body.left instanceof AST.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 AST.AST_Array); assert(ast.body[0].body.left.names[0] instanceof AST.AST_SymbolRef); assert(ast.body[0].body.left.names[1] instanceof AST.AST_SymbolRef); assert(ast.body[0].body.left.names[2] instanceof AST.AST_Expansion); }); it("Should handle default assignments in destructuring", async function() { var ast = parse("({x: v, z = z + 5} = obj);"); assert(ast.body[0] instanceof AST.AST_SimpleStatement); assert(ast.body[0].body instanceof AST.AST_Assign); assert(ast.body[0].body.left instanceof AST.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 AST.AST_SymbolRef); assert(ast.body[0].body.left.names[0].value instanceof AST.AST_SymbolRef); assert.strictEqual(ast.body[0].body.left.names[0].start.value, "x"); assert(ast.body[0].body.left.names[1].value instanceof AST.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 AST.AST_SymbolRef); assert.strictEqual(ast.body[0].body.left.names[1].value.operator, "="); assert(ast.body[0].body.left.names[1].value.right instanceof AST.AST_Binary); ast = parse("({x = 123} = obj);"); assert(ast.body[0] instanceof AST.AST_SimpleStatement); assert(ast.body[0].body instanceof AST.AST_Assign); assert(ast.body[0].body.left instanceof AST.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 AST.AST_SymbolRef); assert(ast.body[0].body.left.names[0].value instanceof AST.AST_DefaultAssign); assert.strictEqual(ast.body[0].body.left.names[0].value.operator, "="); assert(ast.body[0].body.left.names[0].value.left instanceof AST.AST_SymbolRef); ast = parse("[x, y = 5] = foo"); assert(ast.body[0] instanceof AST.AST_SimpleStatement); assert(ast.body[0].body instanceof AST.AST_Assign); assert(ast.body[0].body.left instanceof AST.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 AST.AST_SymbolRef); assert(ast.body[0].body.left.names[0] instanceof AST.AST_SymbolRef); assert.strictEqual(ast.body[0].body.left.names[0].start.value, "x"); assert(ast.body[0].body.left.names[1] instanceof AST.AST_DefaultAssign); assert(ast.body[0].body.left.names[1].left instanceof AST.AST_SymbolRef); assert.strictEqual(ast.body[0].body.left.names[1].start.value, "y"); }); it("Should handle default assignments containing assignments in a destructuring", async function() { var ast = parse("[x, y = z = 2] = a;"); assert(ast.body[0] instanceof AST.AST_SimpleStatement); assert(ast.body[0].body instanceof AST.AST_Assign); assert(ast.body[0].body.left instanceof AST.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 AST.AST_SymbolRef); assert(ast.body[0].body.left.names[0] instanceof AST.AST_SymbolRef); assert(ast.body[0].body.left.names[1] instanceof AST.AST_DefaultAssign); assert(ast.body[0].body.left.names[1].left instanceof AST.AST_SymbolRef); assert.equal(ast.body[0].body.left.names[1].operator, "="); assert(ast.body[0].body.left.names[1].right instanceof AST.AST_Assign); assert(ast.body[0].body.left.names[1].right.left instanceof AST.AST_SymbolRef); assert.equal(ast.body[0].body.left.names[1].right.operator, "="); assert(ast.body[0].body.left.names[1].right.right instanceof AST.AST_Number); ast = parse("({a: a = 123} = obj)"); assert(ast.body[0] instanceof AST.AST_SimpleStatement); assert(ast.body[0].body instanceof AST.AST_Assign); assert(ast.body[0].body.left instanceof AST.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 AST.AST_SymbolRef); assert(ast.body[0].body.left.names[0] instanceof AST.AST_ObjectProperty); assert.strictEqual(ast.body[0].body.left.names[0].key, "a"); assert(ast.body[0].body.left.names[0].value instanceof AST.AST_DefaultAssign); assert(ast.body[0].body.left.names[0].value.left instanceof AST.AST_SymbolRef); assert.strictEqual(ast.body[0].body.left.names[0].value.operator, "="); assert(ast.body[0].body.left.names[0].value.right instanceof AST.AST_Number); }); it("Should allow multiple spread in array literals", async function() { var ast = parse("var a = [1, 2, 3], b = [4, 5, 6], joined; joined = [...a, ...b]"); assert(ast.body[0] instanceof AST.AST_Var); assert(ast.body[1] instanceof AST.AST_SimpleStatement); // Check statement containing array with spreads assert(ast.body[1].body instanceof AST.AST_Assign); assert(ast.body[1].body.left instanceof AST.AST_SymbolRef); assert.equal(ast.body[1].body.operator, "="); assert(ast.body[1].body.right instanceof AST.AST_Array); // Check array content assert.strictEqual(ast.body[1].body.right.elements.length, 2); assert(ast.body[1].body.right.elements[0] instanceof AST.AST_Expansion); assert(ast.body[1].body.right.elements[0].expression instanceof AST.AST_SymbolRef); assert(ast.body[1].body.right.elements[0].expression.name, "a"); assert(ast.body[1].body.right.elements[1] instanceof AST.AST_Expansion); assert(ast.body[1].body.right.elements[1].expression instanceof AST.AST_SymbolRef); assert(ast.body[1].body.right.elements[1].expression.name, "b"); }); it("Should not allow spread on invalid locations", async function() { var expect = function(input, expected) { var execute = function(input) { return function() { parse(input); }; } var check = function(e) { return 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-5.19.2/test/mocha/line-endings.js000066400000000000000000000035611445647217600201210ustar00rootroot00000000000000import assert from "assert"; import { minify } from "../../main.js"; import { parse } from "../../lib/parse.js"; 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", async function() { var js = '/*!one\n2\n3*///comment\nfunction f(x) {\n if (x)\n//comment\n return 3;\n}\n'; var result = await minify(js, options); assert.strictEqual(result.code, expected_code); }); it("Should parse CR/LF line endings", async 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 = await minify(js, options); assert.strictEqual(result.code, expected_code); }); it("Should parse CR line endings", async function() { var js = '/*!one\r2\r3*///comment\rfunction f(x) {\r if (x)\r//comment\r return 3;\r}\r'; var result = await minify(js, options); assert.strictEqual(result.code, expected_code); }); it("Should not allow line terminators in regexp", async function() { var inputs = [ "/\n/", "/\r/", "/\u2028/", "/\u2029/", "/\\\n/", "/\\\r/", "/\\\u2028/", "/\\\u2029/", "/someRandomTextLike[]()*AndThen\n/" ] var test = function(input) { return function() { parse(input); }; } var fail = function(e) { return e.message === "Unexpected line terminator"; } for (var i = 0; i < inputs.length; i++) { assert.throws(test(inputs[i]), fail); } }); }); terser-5.19.2/test/mocha/minify-file-map.js000066400000000000000000000032011445647217600205170ustar00rootroot00000000000000import assert from "assert"; import { minify } from "../../main.js"; describe("Input file as map", function() { it("Should accept object", async function() { var jsMap = { '/scripts/foo.js': 'var foo = {"x": 1, y: 2, \'z\': 3};' }; var result = await 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 = await minify(jsMap); assert.strictEqual(result.map, undefined); result = await minify(jsMap, {sourceMap: {filename: 'out.js'}}); map = JSON.parse(result.map); assert.strictEqual(map.file, 'out.js'); }); it("Should accept array of strings", async function() { var jsSeq = [ 'var foo = {"x": 1, y: 2, \'z\': 3};', 'var bar = 15;' ]; var result = await 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", async function() { var jsMap = { '/scripts/foo.js': 'var foo = {"x": 1, y: 2, \'z\': 3};' }; var result = await 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-5.19.2/test/mocha/minify.js000066400000000000000000000515331445647217600170420ustar00rootroot00000000000000import assert from "assert"; import { readFileSync } from "fs"; import { run_code } from "../sandbox.js"; import { for_each_async } from "./utils.js"; import { minify } from "../../main.js"; function read(path) { return readFileSync(path, "utf8"); } describe("minify", function() { it("Should test basic sanity of minify with default options", async function() { var js = "function foo(bar) { if (bar) return 3; else return 7; var u = not_called(); }"; var result = await minify(js); assert.strictEqual(result.code, "function foo(n){return n?3:7}"); }); it("Should skip inherited keys from `files`", async function() { var files = Object.create({ skip: this }); files[0] = "alert(1 + 1)"; var result = await minify(files); assert.strictEqual(result.code, "alert(2);"); }); it("Should not mutate options", async function () { const options = { compress: true }; const options_snapshot = JSON.stringify(options); await minify("x()", options); assert.strictEqual(JSON.stringify(options), options_snapshot); }); it("Should not mutate options, BUT mutate the nameCache", async function () { const nameCache = {}; const options = { nameCache, toplevel: true, mangle: { properties: true }, compress: false }; await minify("const a_var = { a_prop: 'long' }", options); assert.deepEqual(Object.keys(nameCache.vars.props), ["$a_var"]); assert.deepEqual(Object.keys(nameCache.props.props), ["$a_prop"]); }); it("Should be able to use a dotted property to reach nameCache", async function () { const nameCache = {}; const options = { nameCache, toplevel: true, mangle: { properties: true }, compress: false }; await minify("const a_var = { a_prop: 'long' }", options); assert.deepEqual(Object.keys(options.nameCache.vars.props), ["$a_var"]); assert.deepEqual(Object.keys(options.nameCache.props.props), ["$a_prop"]); }); it("Should accept new `format` options as well as `output` options", async function() { const { code } = await minify("x(1,2);", { format: { beautify: true }}); assert.strictEqual(code, "x(1, 2);"); }); it("Should refuse `format` and `output` option together", async function() { await assert.rejects(() => minify("x(1,2);", { format: { beautify: true }, output: { beautify: true } })); }); it("Should work with mangle.cache", async function() { var cache = {}; var original = ""; var compressed = ""; await for_each_async([ "bar.es5", "baz.es5", "foo.es5", "qux.js", ], async function(file) { var code = read("test/input/issue-1242/" + file); var result = await 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", async function() { var cache = {}; var original = ""; var compressed = ""; await for_each_async([ "bar.es5", "baz.es5", "foo.es5", "qux.js", ], async function(file) { var code = read("test/input/issue-1242/" + file); var result = await 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("Should avoid mangled names in cache", async function() { var cache = {}; var original = ""; var compressed = ""; const nth_identifier = { get(n) { return String.fromCharCode(n + "a".charCodeAt(0)); } }; await for_each_async([ '"xxxyy";var i={prop1:1};', '"xxyyy";var j={prop2:2,prop3:3},k=4;', "console.log(i.prop1,j.prop2,j.prop3,k);", "console.log(i.prop2 === undefined, j.prop1 === undefined);", ], async function(code) { var result = await minify(code, { compress: false, mangle: { properties: { nth_identifier, }, toplevel: true, }, nameCache: cache }); original += code; compressed += result.code; }); assert.strictEqual(compressed, [ '"xxxyy";var x={g:1};', '"xxyyy";var p={h:2,i:3},r=4;', "console.log(x.g,p.h,p.i,r);", "console.log(x.h===undefined,p.g===undefined);" ].join("")); assert.strictEqual(run_code(compressed), run_code(original)); }); it("Should consistently rename properties colliding with a mangled name", async function() { var cache = {}; var original = ""; var compressed = ""; await for_each_async([ "function fn1(obj) { obj.prop = 1; obj.i = 2; }", "function fn2(obj) { obj.prop = 1; obj.i = 2; }", "let o1 = {}, o2 = {}; fn1(o1); fn2(o2);", "console.log(o1.prop === o2.prop, o2.prop === 1, o1.i === o2.i, o2.i === 2);", ], async function(code) { var result = await minify(code, { compress: false, mangle: { properties: true, toplevel: true }, nameCache: cache }); original += code; compressed += result.code; }); assert.strictEqual(compressed, [ // It's important that the `n.i` here conflicts with the original's // `obj.i`, so `obj.i` gets consistently renamed to `n.o`. "function n(n){n.i=1;n.o=2}", "function c(n){n.i=1;n.o=2}", "let f={},e={};n(f);c(e);", "console.log(f.i===e.i,e.i===1,f.o===e.o,e.o===2);", ].join("")); assert.equal(run_code(compressed), run_code(original)); }); it("Should not parse invalid use of reserved words", async function() { await assert.doesNotReject(() => minify("function enum(){}")); await assert.doesNotReject(() => minify("function static(){}")); await assert.rejects(() => minify("function super(){}"), {message: "Unexpected token: name (super)" }); await assert.rejects(() => minify("function this(){}"), {message: "Unexpected token: name (this)" }); }); describe("keep_quoted_props", function() { it("Should preserve quotes in object literals", async function() { var js = 'var foo = {"x": 1, y: 2, \'z\': 3};'; var result = await 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", async function() { var js = 'var foo = {"x": 1, y: 2, \'z\': 3};'; var result = await 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", async function() { var js = 'var foo = {"x": 1, y: 2, \'z\': 3};'; var result = await 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("Shouldn't mangle quoted properties", async function() { var js = 'var a = {}; a["foo"] = "bar"; a.color = "red"; x = {"bar": 10};'; var result = await minify(js, { compress: { properties: false }, mangle: { properties: { builtins: true, keep_quoted: true } }, output: { keep_quoted_props: true, quote_style: 3 } }); assert.strictEqual(result.code, 'var a={foo:"bar",r:"red"};x={"bar":10};'); }); it("Should not mangle quoted property within dead code", async function() { var result = await 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)", async function() { var result = await 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", async function() { var code = (await 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 fail with multiple input and inline source map", async function() { await assert.rejects( () => minify([ read("./test/input/issue-520/input.js"), read("./test/input/issue-520/output.js") ], { sourceMap: { content: "inline", url: "inline" } }), { message: "inline source map only works with singular input" } ); }); }); describe("sourceMapInline", function() { it("should append source map to output js when sourceMapInline is enabled", async function() { var result = await 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,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJhIiwiZm9vIl0sInNvdXJjZXMiOlsiMCJdLCJtYXBwaW5ncyI6IkFBQUEsSUFBSUEsRUFBSSxTQUFTQyxHQUFPLE9BQU9BLENBQUsifQ=="); }); it("should not append source map to output js when sourceMapInline is not enabled", async function() { var result = await 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", async function() { var result = await 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("JS_Parse_Error", function() { it("Should return syntax error", async function() { await assert.rejects( () => minify("function f(a{}"), {message: "Unexpected token punc «{», expected punc «,»"} ); }); it("Should reject duplicated label name", async function() { await assert.rejects( () => minify("L:{L:{}}"), {message: "Label L defined twice"} ); }); }); describe("global_defs", function() { it("Should throw for non-trivial expressions", async function() { await assert.rejects( () => minify("alert(42);", { compress: { global_defs: { "@alert": "debugger" } } }), { message: "Unexpected token: keyword (debugger)"} ); }); it("Should skip inherited properties", async function() { var foo = Object.create({ skip: this }); foo.bar = 42; var result = await minify("alert(FOO);", { compress: { global_defs: { FOO: foo } } }); assert.strictEqual(result.code, "alert({bar:42});"); }); }); it("duplicated block-scoped declarations", async () => { await for_each_async([ "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];", ], async code => { await assert.doesNotReject( () => minify(code, { compress: false, mangle: false }), JSON.stringify(code) + " should be compressed" ); await assert.rejects( () => minify(code), { message: '"a" is redeclared' }, JSON.stringify(code) + " should throw a SyntaxError" ); }); }); // rename is disabled on harmony due to expand_names bug in for-of loops if (0) describe("rename", function() { it("Should be repeatable", async function() { var code = "!function(x){return x(x)}(y);"; for (var i = 0; i < 2; i++) { assert.strictEqual(await minify(code, { compress: { toplevel: true, }, rename: true, }).code, "var a;(a=y)(a);"); } }); }); it("should work with compress defaults disabled", async function() { var code = "if (true) { console.log(1 + 2); }"; var options = { compress: { defaults: false, } }; assert.strictEqual((await minify(code, options)).code, "if(true)console.log(1+2);"); }); it("should work with compress defaults disabled and evaluate enabled", async function() { var code = "if (true) { console.log(1 + 2); }"; var options = { compress: { defaults: false, evaluate: true, } }; assert.strictEqual((await minify(code, options)).code, "if(true)console.log(3);"); }); describe("enclose", function() { var code = read("test/input/enclose/input.js"); it("Should work with true", async function() { var result = await 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", async function() { var result = await 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", async function() { var result = await 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", async function() { var result = await 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", async function() { await for_each_async([ [ "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" ], ], async function(entry) { var code = entry[0]; var expected_error = entry[1]; if (!expected_error) { await assert.doesNotReject(() => minify(code)); } else { await assert.rejects( () => minify(code), {message: expected_error}, JSON.stringify(entry) ); } }); }); }); }); terser-5.19.2/test/mocha/no-mutate-input.js000066400000000000000000000015331445647217600206100ustar00rootroot00000000000000import assert from "assert"; import { minify } from "../../main.js"; describe("no-mutate-input", function() { it("does not modify the options object", async function() { const config = { format: {}, sourceMap: true, }; await minify('"foo";', config); assert.deepEqual(config, { format: {}, sourceMap: true, }); }); it("does not clobber source maps with a subsequent minification", async function() { const config = { format: {}, sourceMap: true, }; const fooResult = await minify('"foo";', config); const barResult = await minify('module.exports = "bar";', config); const fooMap = fooResult.map; const barMap = barResult.map; assert.notEqual(barMap, fooMap); }); }); terser-5.19.2/test/mocha/number-literal.js000066400000000000000000000011071445647217600204610ustar00rootroot00000000000000import assert from "assert"; import { parse } from "../../lib/parse.js"; describe("Number literals", function () { it("Should not allow legacy octal literals in strict mode", async function() { var inputs = [ '"use strict";00;', '"use strict"; var foo = 00;' ]; var error = function(e) { return e.message === "Legacy octal literals are not allowed in strict mode"; }; for (var i = 0; i < inputs.length; i++) { assert.throws(() => parse(inputs[i]), error, inputs[i]); } }); }); terser-5.19.2/test/mocha/object.js000066400000000000000000000020561445647217600170110ustar00rootroot00000000000000import assert from "assert"; import { minify } from "../../main.js"; import { parse } from "../../lib/parse.js"; describe("Object", function() { it("Should allow objects to have a methodDefinition as property", async () => { var code = "var a = {test() {return true;}}"; assert.equal((await minify(code, { compress: { arrows: false } })).code, "var a={test(){return!0}};"); }); it("Should not allow objects to use static keywords like in classes", async () => { var code = "{static test() {}}"; assert.throws(() => parse(code)); }); it("Should not allow objects to have static computed properties like in classes", async () => { var code = "var foo = {static [123](){}}"; assert.throws(() => parse(code)); }); it("Should be able to use shorthand properties", async () => { var ast = parse("var foo = 123\nvar obj = {foo: foo}"); assert.strictEqual(ast.print_to_string({ecma: 2015}), "var foo=123;var obj={foo};"); }); }); terser-5.19.2/test/mocha/operator.js000066400000000000000000000512131445647217600173750ustar00rootroot00000000000000import assert from "assert"; import "../../main.js"; import { parse } from "../../lib/parse.js"; describe("operator", function() { it("Should handle mixing of ++/+/--/- correctly", async 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 terser = evaluate(parse(exp).print_to_string()); assert.strictEqual(orig.a, terser.a); assert.strictEqual(orig.b, terser.b); assert.strictEqual(orig.c, terser.c); var beautify = evaluate(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", async 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(parse(exp[0]).print_to_string(), exp[1] + ";"); }); }); }); terser-5.19.2/test/mocha/release.js000066400000000000000000000030361445647217600171620ustar00rootroot00000000000000import os from "os"; import assert from "assert"; import semver from "semver"; import { spawn } from "child_process"; function run(command, args, done) { spawn(command, args, { stdio: [ "ignore", 1, 2 ] }).on("exit", function(code) { assert.strictEqual(code, 0); done(); }); } describe('release', () => { if (!process.env.TERSER_TEST_ALL || !semver.satisfies(process.version, "16") || process.platform !== "linux" ) { return; } describe("test/benchmark.cjs", function() { this.timeout(10 * 60 * 1000); [ "-mc toplevel", "-mc keep_fargs=false,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.cjs"); args.push("-f", "webkit"); run(process.argv[0], args, done); }); }); }); describe("test/jetstream.cjs", function() { this.timeout(20 * 60 * 1000); [ "-mc", "-mc keep_fargs=false,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.cjs"); run(process.argv[0], args, done); }); }); }); }); terser-5.19.2/test/mocha/scope.js000066400000000000000000000113431445647217600166530ustar00rootroot00000000000000"use strict"; import assert from "assert"; import "../../main.js"; import { parse } from "../../lib/parse.js"; import * as AST from "../../lib/ast.js" const sample_code = ` var x = 'x' leak() function y(z) { scope("defun") var x = 'y' { scope("block") let x = 'z' } leak(x) } class Foo extends extendee { static foo = scope("class") method() { scope("method") var x x() } } `; const scopes_simplified = { name: "toplevel", variables: ["x", "y", "Foo"], refs: { }, children: [ { name: "defun", variables: ["arguments", "z", "x"], refs: { x: "defun", }, children: [ { name: "block", variables: ["x"], refs: {}, children: [] }, ] }, { name: "class", variables: [], refs: { // TODO this is not the right place. extendee: "global" }, children: [{ name: "method", variables: ["arguments", "x"], children: [], refs: { x: "method" } }] } ] }; const draw_scopes = toplevel => { let current_scope = { scope: toplevel, name: "toplevel", children: [], refs: {} }; const scopes_to_drawn = new Map([ [toplevel, current_scope] ]); toplevel.walk(new AST.TreeWalker((node, descend) => { if (node === toplevel) return; const scope = node instanceof AST.AST_Scope ? node : node.is_block_scope() ? node.block_scope : null; if (scope) { const save_current_scope = current_scope; current_scope = Object.seal({ scope, name: "", children: [], refs: {} }); scopes_to_drawn.set(current_scope.scope, current_scope); if (save_current_scope) save_current_scope.children.push(current_scope); descend(); current_scope = save_current_scope; return true; } if (node instanceof AST.AST_Call && node.expression.name === "scope") { current_scope.name = node.args[0].value; } })); // Find refs toplevel.walk(new AST.TreeWalker((node) => { if (node instanceof AST.AST_SymbolRef) { if (node.name === "scope") return; if (node.name === "leak") return; const drawn_closest_scope = scopes_to_drawn.get(node.scope); const drawn_def_scope = scopes_to_drawn.get(node.thedef.scope); if (drawn_def_scope.scope === toplevel && node.thedef.global) { drawn_closest_scope.refs[node.name] = "global"; } else { drawn_closest_scope.refs[node.name] = drawn_def_scope.name; } } })); return (function simplify(scope) { return { name: scope.name, variables: [...scope.scope.variables.keys()], children: scope.children.map(c => simplify(c)), refs: scope.refs }; })(current_scope); }; describe("figure_out_scope", () => { it("can figure out the scope by calling figure_out_scope on the toplevel", async () => { const ast = parse(sample_code); ast.figure_out_scope(); const simplified = draw_scopes(ast); assert.deepEqual(simplified, scopes_simplified); }); it("can figure out scope partially after first figure_out_scope has been called", async () => { const toplevel = parse(sample_code); toplevel.figure_out_scope(); const reference = draw_scopes(toplevel); const removal_points = [ [toplevel.body, 2], [toplevel.body, 3] ]; for (const [obj, prop] of removal_points) { obj[prop].figure_out_scope({}, { toplevel, parent_scope: toplevel }); const after = draw_scopes(toplevel); assert.deepEqual(after, reference); obj[prop] = (function reparse(node) { const string = node.print_to_string(); try { return parse(string).body[0]; } catch (e) { return parse(`(${string})`).body[0].body; } })(obj[prop]); obj[prop].figure_out_scope({}, { toplevel, parent_scope: toplevel }); const afterReParse = draw_scopes(toplevel); assert.deepEqual(afterReParse, reference); } }); }); terser-5.19.2/test/mocha/size.js000066400000000000000000000006001445647217600165060ustar00rootroot00000000000000import assert from "assert"; import { parse } from "../../lib/parse.js"; import "../../lib/size.js"; import "../../lib/output.js"; describe("size", () => { it("approximates the size of expression", () => { assert.equal(parse("()=>{return}").size(), 12); assert.equal(parse("()=>{return 2}").size(), 5); assert.equal(parse("()=>2").size(), 5); }); }); terser-5.19.2/test/mocha/sourcemaps.js000066400000000000000000000312471445647217600177300ustar00rootroot00000000000000import assert from "assert"; import { readFileSync } from "fs"; import source_map_module from "source-map"; import { assertCodeWithInlineMapEquals } from "./utils.js"; import { to_ascii } from "../../lib/minify.js"; import { minify } from "../../main.js"; const { SourceMapConsumer } = source_map_module; function read(path) { return readFileSync(path, "utf8"); } async function source_map(code) { return JSON.parse((await 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() } ] }; } async 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 = await 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", async function() { var map = await source_map("var x = 1 + 1;"); assert.strictEqual(map.version, 3); assert.deepEqual(map.names, [ "x" ]); }); it("Should give correct names", async function() { var map = await source_map([ "({", " get enabled() {", " return 3;", " },", " set enabled(x) {", " ;", " }", "});", ].join("\n")); assert.deepEqual(map.names, [ "enabled", "x" ]); }); it("Should mark array/object literals", async function() { var result = await minify([ "var obj = {};", "obj.wat([]);", ].join("\n"), { sourceMap: true, toplevel: true, }); if (result.error) throw result.error; assert.strictEqual(result.code, "({}).wat([]);"); assert.deepStrictEqual(JSON.parse(result.map), { version: 3, sources: ["0"], names: ["wat"], mappings: "CAAU,CAAC,GACPA,IAAI", }); }); it("Should mark class literals", async function() { var result = await 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.deepStrictEqual(JSON.parse(result.map), { version: 3, sources: ["0"], names: ["wat"], mappings: "CACU,SACNA,IAFJ", }); }); it("Should give correct sourceRoot", async function() { var code = "console.log(42);"; var result = await minify(code, { sourceMap: { root: "//foo.bar/", }, }); if (result.error) throw result.error; assert.strictEqual(result.code, code); assert.deepStrictEqual(JSON.parse(result.map), { version: 3, sources: ["0"], names: ["console","log"], mappings: "AAAAA,QAAQC,IAAI", sourceRoot: "//foo.bar/", }); }); it("Should return source map as object when asObject is given", async function() { var code = "console.log(42);"; var result = await minify(code, { sourceMap: { asObject: true, }, }); if (result.error) throw result.error; assert.strictEqual(result.code, code); assert.deepStrictEqual(result.map, { version: 3, sources: ["0"], names: ["console","log"], mappings: "AAAAA,QAAQC,IAAI", }); }); it("Should grab names from methods and properties correctly", async () => { const code = `class Foo { property = 6 method () {} async async_method() {} static static_method() {} 404() {} "quoted method name" () {} get getter(){} set setter(){} #private = 4 #private_method() {} get #private_getter() {} set #private_setter() {} test() { this.property; this.method; this.async_method; this.static_method; this[404]; this["quoted method name"]; this.getter; this.setter; this.#private; this.#private_method; this.#private_getter; this.#private_setter; } }`; const result = await minify(code, { sourceMap: { asObject: true }, mangle: { properties: true }, }); assert.deepStrictEqual(result.map.names, [ "Foo", "property", "method", "async_method", "static_method", "getter", "setter", "private", "private_method", "private_getter", "private_setter", "test", "this", ]); }); describe("inSourceMap", function() { it("Should read the given string filename correctly when sourceMapIncludeSources is enabled", async function() { var result = await 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.deepEqual(map.sources, ["index.js"]); assert.deepEqual(map.sourcesContent, ['let foo = x => "foo " + x;\nconsole.log(foo("bar"));']); }); it("Should process inline source map", async function() { var result = await 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")); }); }); describe("sourceMapInline", function() { it("Should append source map to output js when sourceMapInline is enabled", async function() { var result = await 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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIjAiXSwibmFtZXMiOlsiYSIsImZvbyJdLCJtYXBwaW5ncyI6IkFBQUEsSUFBSUEsRUFBSSxTQUFTQyxHQUFPLE9BQU9BLENBQUsifQ=="); }); it("Should not append source map to output js when sourceMapInline is not enabled", async function() { var result = await 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", async function() { var result = await 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", async function() { var code = [ "var tëst = '→unicøde←';", "alert(tëst);", ].join("\n"); var result = await 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(to_ascii(encoded).toString()); assert.strictEqual(map.sourcesContent.length, 1); assert.strictEqual(map.sourcesContent[0], code); result = await minify(result.code, { sourceMap: { content: "inline", includeSources: true, } }); if (result.error) throw result.error; map = JSON.parse(result.map); assert.strictEqual(map.names.length, 1); // We don't add non-ascii-identifier names // assert.strictEqual(map.names[0], "tëst"); assert.strictEqual(map.names[0], "alert"); }); it("Should append source map to file when asObject is present", async function() { var result = await minify("var a = function(foo) { return foo; };", { sourceMap: { url: "inline", asObject: true } }); 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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIjAiXSwibmFtZXMiOlsiYSIsImZvbyJdLCJtYXBwaW5ncyI6IkFBQUEsSUFBSUEsRUFBSSxTQUFTQyxHQUFPLE9BQU9BLENBQUsifQ=="); }); }); describe("input sourcemaps", function() { it("Should copy over original sourcesContent", async function() { var orig = get_map(); var map = await prepare_map(orig); assert.equal(map.sourceContentFor("index.js"), orig.sourcesContent[0]); }); it("Should copy over original sourcesContent for section sourcemaps", async function() { var orig = get_sections_map(); var map = await prepare_map(orig); assert.equal(map.sourceContentFor("index.js"), orig.sections[0].map.sourcesContent[0]); }); it("Should copy sourcesContent if sources are relative", async function() { var relativeMap = get_map(); relativeMap.sources = ["./index.js"]; var map = await 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", async function() { var map = await 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-5.19.2/test/mocha/spidermonkey.js000066400000000000000000000143221445647217600202530ustar00rootroot00000000000000import assert from "assert"; import fs from "fs"; import * as acorn from "acorn"; import * as astring from "astring"; import * as AST from "../../lib/ast.js"; import { parse } from "../../lib/parse.js"; import { minify } from "../../main.js"; const acornParse = acorn.default ? acorn.default.parse : acorn.parse; const astringGenerate = astring.default ? astring.default.generate : astring.generate; describe("spidermonkey export/import sanity test", function() { it("Should judge between directives and strings correctly on import", async 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 AST.TreeWalker(node => { if (node instanceof AST.AST_String) { counter_strings++; } else if (node instanceof AST.AST_Directive) { counter_directives++; } }); for (var i = 0; i < tests.length; i++) { counter_directives = 0; counter_strings = 0; var ast = parse(tests[i].input); var moz_ast = ast.to_mozilla_ast(); var from_moz_ast = AST.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", async function() { var code = fs.readFileSync("test/input/spidermonkey/input.js", "utf-8"); var terser_ast = parse(code); var moz_ast = terser_ast.to_mozilla_ast(); var from_moz_ast = AST.AST_Node.from_mozilla_ast(moz_ast); assert.strictEqual( from_moz_ast.print_to_string(), terser_ast.print_to_string() ); }); it("should be capable of importing from acorn", async function() { var code = fs.readFileSync("test/input/spidermonkey/input.js", "utf-8"); var terser_ast = parse(code); var moz_ast = acornParse(code, { sourceType: "module", ecmaVersion: 2023 }); var from_moz_ast = AST.AST_Node.from_mozilla_ast(moz_ast); assert.strictEqual( from_moz_ast.print_to_string(), terser_ast.print_to_string() ); }); it("should accept a spidermonkey AST w/ `parse.spidermonkey: true`", async function() { var moz_ast = acornParse("var a = 1 + 2", { sourceType: "module", ecmaVersion: 2023 }); var result = await minify(moz_ast, {ecma: 2015, parse: {spidermonkey: true}}); assert.deepStrictEqual(result.code, "var a=3;"); }); it("should produce a spidermonkey AST w/ `format.spidermonkey: true`", async function() { const code = "var a = 1 + 2"; var result = await minify(code, {ecma: 2015, format: {spidermonkey: true}}); assert.deepStrictEqual(astringGenerate(result.ast), "var a = 3;\n"); }); it("should correctly minify AST from from_moz_ast with default destructure", async () => { const code = "const { a = 1, b: [b = 2] = []} = {}"; const acornAst = acornParse(code, { locations: true, ecmaVersion: 2015 }); const terserAst = AST.AST_Node.from_mozilla_ast(acornAst); const result = await minify(terserAst, {ecma: 2015}); assert.strictEqual( result.code, "const{a=1,b:[b=2]=[]}={};" ); }); it("should correctly minify AST from from_moz_ast with default function parameter", async () => { const code = "function run(x = 2){}"; const acornAst = acornParse(code, { locations: true, ecmaVersion: 2023 }); const terserAst = AST.AST_Node.from_mozilla_ast(acornAst); const result = await minify(terserAst); assert.strictEqual( result.code, "function run(x=2){}" ); }); it("should produce an AST compatible with astring", async function() { var code = fs.readFileSync("test/input/spidermonkey/input.js", "utf-8"); var terser_ast = parse(code); var moz_ast = terser_ast.to_mozilla_ast(); var generated = astringGenerate(moz_ast); var parsed = acornParse(generated, { sourceType: "module", ecmaVersion: 2023 }); assert.strictEqual( AST.AST_Node.from_mozilla_ast(parsed).print_to_string(), terser_ast.print_to_string() ); }); }); terser-5.19.2/test/mocha/string-literal.js000066400000000000000000000066141445647217600205070ustar00rootroot00000000000000import assert from "assert"; import { minify } from "../../main.js"; import { parse } from "../../lib/parse.js"; describe("String literals", function() { it("Should throw syntax error if a string literal contains a newline", async function() { var inputs = [ "'\n'", "'\r'", '"\r\n"' ]; var error = function(e) { return e.message === "Unterminated string constant"; }; for (var input of inputs) { assert.throws(() => parse(input), error); } }); it("Should not throw syntax error if a string has a line continuation", async function() { var output = 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", async 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 error = function(e) { return e.message === "Legacy octal escape sequences are not allowed in strict mode"; } for (var input of inputs) { assert.throws(() => parse(input), error); } }); it("Should not throw error outside strict mode if string contains escaped octalIntegerLiteral", async 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";"\u0007";'] ]; for (var [input, output] of tests) { assert.equal(parse(input).print_to_string(), output); } }); it("Should not throw error when digit is 8 or 9", async function() { assert.equal(parse('"use strict";"\\08";').print_to_string(), '"use strict";"\\x008";'); assert.equal(parse('"use strict";"\\09";').print_to_string(), '"use strict";"\\x009";'); }); it("Should not unescape unpaired surrogates", async 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 = await 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 = await 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-5.19.2/test/mocha/template-string.js000066400000000000000000000025401445647217600206600ustar00rootroot00000000000000import assert from "assert"; import "../../main.js"; import { parse } from "../../lib/parse.js"; describe("Template string", function() { it("Should not accept invalid sequences", async 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() { parse(test); }; }; var fail = function(e) { return /^Unexpected token: /.test(e.message); }; for (const test of tests) { assert.throws(() => parse(test), fail, test); } }); it("Should process all line terminators as LF", async function() { [ "`a\rb`", "`a\nb`", "`a\r\nb`", ].forEach(function(code) { assert.strictEqual(parse(code).print_to_string(), "`a\\nb`;"); }); }); it("Should not throw on extraneous escape (#231)", async function() { assert.doesNotThrow(function() { parse("`\\a`"); }); }); }); terser-5.19.2/test/mocha/tokens.js000066400000000000000000000033421445647217600170450ustar00rootroot00000000000000import assert from "assert"; import * as AST from "../../lib/ast.js"; import { parse } from "../../lib/parse.js"; describe("tokens", function() { it("Should give correct line in the face of DOS line endings \\r\\n", async () => { const end_at_line_2 = (code) => { const ast = parse(code); let found; ast.walk(new AST.TreeWalker(node => { if (node.name === "end") { assert.equal(node.start.line, 2); found = true; } })); assert(found); }; end_at_line_2("`A\nB`;end"); end_at_line_2("`A\r\nB`;end"); end_at_line_2("`A\\\nB`;end"); end_at_line_2("`A\\\r\nB`;end"); end_at_line_2("'A\\\nB';end"); end_at_line_2("'A\\\r\nB';end"); }); it("Should give correct positions for accessors", async function() { // location 0 1 2 3 4 // 01234567890123456789012345678901234567890123456789 var ast = parse("var obj = { get latest() { return undefined; } }"); // test all AST_ObjectProperty tokens are set as expected var found = false; ast.walk(new AST.TreeWalker(function(node) { if (node instanceof AST.AST_ObjectProperty) { found = true; assert.equal(node.start.pos, 12); assert(node.key instanceof AST.AST_SymbolMethod); assert.equal(node.key.start.pos, 12); assert(node.value instanceof AST.AST_Accessor); assert.equal(node.value.start.pos, 22); } })); assert(found, "AST_ObjectProperty not found"); }); }); terser-5.19.2/test/mocha/unicode.js000066400000000000000000000076661445647217600172050ustar00rootroot00000000000000import assert from "assert"; import { parse } from "../../lib/parse.js"; import { minify } from "../../main.js"; import { for_each_async } from "./utils.js"; describe("Unicode", function() { it("Should throw error if escaped first identifier char is not part of ID_start", async 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 fail = function(e) { return e.message === "First identifier char is an invalid identifier char"; } for (var i = 0; i < tests.length; i++) { assert.throws(() => parse(tests[i]), fail); } }); it("Should throw error if escaped non-first identifier char is not part of ID_start", async function() { var tests = [ 'var a\\u{0} = "foo";', 'var a\\u{10ffff} = "bar";', 'var z\\u000a = "what\'s up";' ]; var fail = function(e) { return e.message === "Invalid escaped identifier char"; } for (var i = 0; i < tests.length; i++) { assert.throws(() => parse(tests[i]), fail); } }); it("Should throw error if identifier is a keyword with a escape sequences", async 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 fail = function(e) { return e.message === "Escaped characters are not allowed in keywords"; } for (var i = 0; i < tests.length; i++) { assert.throws(() => parse(tests[i]), fail); } }); it("Should read strings containing surrogates correctly", async 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((await minify(tests[i][0], { output: { ascii_only: true, ecma: 2015 } })).code, tests[i][1]); } }); it("Should parse raw characters correctly", async function() { var ast = parse('console.log("\\udbff");'); assert.strictEqual(ast.print_to_string(), 'console.log("\\udbff");'); ast = parse(ast.print_to_string()); assert.strictEqual(ast.print_to_string(), 'console.log("\\udbff");'); }); it("Should not unescape unpaired surrogates", async function() { this.timeout(20000); var code = []; for (var i = 0; i <= 0x1001; i++) { code.push("\\u{" + i.toString(16) + "}"); } for (var i = 0x19000; i <= 0x20001; i++) { code.push("\\u{" + i.toString(16) + "}"); } code = '"' + code.join() + '"'; await for_each_async([true, false], async function(ascii_only) { await for_each_async([5, 2015], async function(ecma) { var result = await minify(code, { compress: false, mangle: false, output: { ascii_only: ascii_only }, ecma: ecma }); if (result.error) throw result.error; if (ecma >= 2015) assert.ok(code.length > result.code.length); assert.strictEqual(eval(code), eval(result.code)); }); }); }); }); terser-5.19.2/test/mocha/utils.js000066400000000000000000000015441445647217600167040ustar00rootroot00000000000000import assert from "assert"; function decodeMap(mapData) { const buffer = new Buffer(mapData.replace('data:application/json;charset=utf-8;base64,', ''), 'base64'); return JSON.parse(buffer.toString()); } export 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}); } export async function for_each_async (array, async_fn) { for (const item of array) { await async_fn(item) } } terser-5.19.2/test/mocha/with.js000066400000000000000000000015241445647217600165150ustar00rootroot00000000000000import assert from "assert"; import "../../main.js"; import { parse } from "../../lib/parse.js"; describe("With", function() { it("Should throw syntaxError when using with statement in strict mode", async function() { var code = '"use strict";\nthrow NotEarlyError;\nwith ({}) { }'; var error = function(e) { return e.message === "Strict mode may not include a with statement"; } assert.throws(() => parse(code), error); }); it("Should set uses_with for scopes involving With statements", async function() { var ast = 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-5.19.2/test/mocha/yield.js000066400000000000000000000037451445647217600166570ustar00rootroot00000000000000import assert from "assert"; import { minify } from "../../main.js"; import { parse } from "../../lib/parse.js"; describe("Yield", function() { it("Should not delete statements after yield", async function() { var js = "function *foo(bar) { yield 1; yield 2; return 3; }"; var result = await 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", async function() { var js = "function* test() {yield*\n;}"; var expect = function(e) { return e.message === "Unexpected token: punc (;)"; }; assert.throws(() => parse(js), expect); }); it("Should not allow yield with next token star on next line", async function() { var js = "function* test() {yield\n*123;}"; var test = function() { parse(js); }; var expect = function(e) { return e.message === "Unexpected token: operator (*)"; }; assert.throws(test, expect); }); it("Should be able to compress its expression", async function() { assert.strictEqual( (await 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", async function() { assert.strictEqual( (await 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", async function() { assert.strictEqual( (await minify("function *f() { yield undefined; yield; yield* undefined; yield void 0}", {compress: true})).code, "function*f(){yield,yield,yield*void 0,yield}" ); }); }); terser-5.19.2/test/sandbox.js000066400000000000000000000052761445647217600161210ustar00rootroot00000000000000import vm from "vm"; import "./colorless-console.js"; 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"); export function run_code(code, prepend_code = '') { var stdout = ""; var original_write = process.stdout.write; process.stdout.write = function(chunk) { stdout += chunk; }; try { const global = { 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); })); } }, id: x => x, leak: () => {}, pass: () => { global.console.log("PASS"); }, fail: () => { global.console.log("FAIL"); } }; global.global = global; vm.runInNewContext([ FUNC_TOSTRING, "!function() {", prepend_code + code, "}();", ].join("\n"), global, { timeout: process.env.CI ? 20000 : 5000 }); return stdout; } catch (ex) { return ex; } finally { process.stdout.write = original_write; } } export function same_stdout(expected, actual) { return typeof expected == typeof actual && strip_func_ids(expected) == strip_func_ids(actual); } terser-5.19.2/test/travis-ufuzz.cjs000066400000000000000000000052621445647217600173120ustar00rootroot00000000000000"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] || "terser-js/terser"); 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-5.19.2/test/ufuzz.js000066400000000000000000001225231445647217600156410ustar00rootroot00000000000000// 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 terser. // bin/terser s.js -c && bin/terser s.js -c passes=3 && bin/terser s.js -c passes=3 -m // cat s.js | node && node s.js && bin/terser s.js -c | node && bin/terser s.js -c passes=3 | node && bin/terser s.js -c passes=3 -m | node import { readFileSync } from "fs"; import { fileURLToPath } from "url"; import path from "path"; import { randomBytes } from "crypto"; import "../tools/exit.cjs"; import * as sandbox from "./sandbox.js"; import { minify } from "../main.js"; import { defaults } from "../lib/utils/index.js"; const minify_catch_error = async (...args) => minify(...args).catch(error => ({ error })) const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); var MAX_GENERATED_TOPLEVELS_PER_RUN = 1; var MAX_GENERATION_RECURSION_DEPTH = 12; var INTERVAL_COUNT = 100; var RANDOM_SEED = Date.now(); 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 = true; var generate_directive = true; 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 '--seed': RANDOM_SEED = Number(process.argv[++i]); if (isNaN(RANDOM_SEED)) { throw new Error('invalid random seed ' + process.argv[i]) } 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('** Terser 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('--seed: initialize the random seed, for determinism'); 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('** Terser fuzzer exiting **'); process.exit(); 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; // LCG deterministic random number generator. // https://stackoverflow.com/a/72732727/1011311 (adapted) function makeRng(seed) { var m = 2**35 - 31 var a = 185852 var s = seed % m return function (max) { const rand_float = ((s = s * a % m) / m); return Math.floor(max * rand_float); } } const rng = makeRng(RANDOM_SEED); 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 terser... 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 ''; } 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"); } async function try_beautify(code, result, printfn) { var beautified = await minify_catch_error(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 = defaults(); async 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 = []; for (const name of Object.keys(defs)) { 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 = await minify_catch_error(original_code, m); if (result.error) { errorln("Error testing options." + component + "." + name); errorln(result.error.stack); } else { var r = sandbox.run_code(result.code); const same_stdout = sandbox.same_stdout(original_result, r); if (same_stdout) { suspects.push(name); } } } } if (suspects.length > 0) { errorln("Suspicious " + component + " options:"); suspects.forEach(function(name) { errorln(" " + name); }); errorln(); } } async function log_rename(options) { var m = JSON.parse(JSON.stringify(options)); m.rename = false; var result = await minify_catch_error(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(); } } } async function log(options, round) { if (!ok) errorln('\n\n\n\n\n\n!!!!!!!!!!\n\n\n'); errorln("//============================================================="); if (!ok) errorln("// !!!!!! Failed... round " + round); errorln("// original code"); await try_beautify(original_code, original_result, errorln); errorln(); errorln(); errorln("//-------------------------------------------------------------"); if (typeof terser_code == "string") { errorln("// uglified code"); await try_beautify(terser_code, terser_result, errorln); errorln(); errorln(); errorln("original result:"); errorln(typeof original_result == "string" ? original_result : original_result.stack); errorln("uglified result:"); errorln(typeof terser_result == "string" ? terser_result : terser_result.stack); } else { errorln("// !!! terser failed !!!"); errorln(terser_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 terser_code == "string") { for (const key of Object.keys(default_options)) { await log_suspects(options); } await log_rename(options); errorln("!!!!!! Failed... round " + round); } } var fallback_options = [ JSON.stringify({ compress: false, mangle: false }) ]; var minify_options = JSON.parse(readFileSync(path.join(__dirname, 'ufuzz.json'), 'utf-8')).map(JSON.stringify); var original_code, original_result; var terser_code, terser_result, ok; async function main() { for (var round = 1; round <= num_iterations; round++) { if (!process.env.CI || round % 100 === 0 || round === 1) { process.stdout.write(round + " of " + num_iterations + "\r"); } original_code = createTopLevelCode(); original_result = sandbox.run_code(original_code); const options_sets = (typeof original_result != "string" ? fallback_options : minify_options) for (const options of options_sets) { terser_code = await minify_catch_error(original_code, JSON.parse(options)); if (!terser_code.error) { terser_code = terser_code.code; terser_result = sandbox.run_code(terser_code); ok = sandbox.same_stdout(original_result, terser_result); } else { terser_code = terser_code.error; if (typeof original_result != "string") { ok = terser_code.name == original_result.name; } } if (verbose || (verbose_interval && !(round % INTERVAL_COUNT)) || !ok) await log(options, round); else if (typeof original_result != "string") { println("//============================================================="); println("// original code"); await 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(); } main().catch(e => { console.error(e); process.exit(1) }) terser-5.19.2/test/ufuzz.json000066400000000000000000000015531445647217600161750ustar00rootroot00000000000000[ { "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 }, { "compress": { "reduce_funcs": false } } ] terser-5.19.2/tools/000077500000000000000000000000001445647217600142745ustar00rootroot00000000000000terser-5.19.2/tools/domprops.js000066400000000000000000005144151445647217600165070ustar00rootroot00000000000000export var domprops = [ "$&", "$'", "$*", "$+", "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9", "$_", "$`", "$input", "-moz-animation", "-moz-animation-delay", "-moz-animation-direction", "-moz-animation-duration", "-moz-animation-fill-mode", "-moz-animation-iteration-count", "-moz-animation-name", "-moz-animation-play-state", "-moz-animation-timing-function", "-moz-appearance", "-moz-backface-visibility", "-moz-border-end", "-moz-border-end-color", "-moz-border-end-style", "-moz-border-end-width", "-moz-border-image", "-moz-border-start", "-moz-border-start-color", "-moz-border-start-style", "-moz-border-start-width", "-moz-box-align", "-moz-box-direction", "-moz-box-flex", "-moz-box-ordinal-group", "-moz-box-orient", "-moz-box-pack", "-moz-box-sizing", "-moz-float-edge", "-moz-font-feature-settings", "-moz-font-language-override", "-moz-force-broken-image-icon", "-moz-hyphens", "-moz-image-region", "-moz-margin-end", "-moz-margin-start", "-moz-orient", "-moz-osx-font-smoothing", "-moz-outline-radius", "-moz-outline-radius-bottomleft", "-moz-outline-radius-bottomright", "-moz-outline-radius-topleft", "-moz-outline-radius-topright", "-moz-padding-end", "-moz-padding-start", "-moz-perspective", "-moz-perspective-origin", "-moz-tab-size", "-moz-text-size-adjust", "-moz-transform", "-moz-transform-origin", "-moz-transform-style", "-moz-transition", "-moz-transition-delay", "-moz-transition-duration", "-moz-transition-property", "-moz-transition-timing-function", "-moz-user-focus", "-moz-user-input", "-moz-user-modify", "-moz-user-select", "-moz-window-dragging", "-webkit-align-content", "-webkit-align-items", "-webkit-align-self", "-webkit-animation", "-webkit-animation-delay", "-webkit-animation-direction", "-webkit-animation-duration", "-webkit-animation-fill-mode", "-webkit-animation-iteration-count", "-webkit-animation-name", "-webkit-animation-play-state", "-webkit-animation-timing-function", "-webkit-appearance", "-webkit-backface-visibility", "-webkit-background-clip", "-webkit-background-origin", "-webkit-background-size", "-webkit-border-bottom-left-radius", "-webkit-border-bottom-right-radius", "-webkit-border-image", "-webkit-border-radius", "-webkit-border-top-left-radius", "-webkit-border-top-right-radius", "-webkit-box-align", "-webkit-box-direction", "-webkit-box-flex", "-webkit-box-ordinal-group", "-webkit-box-orient", "-webkit-box-pack", "-webkit-box-shadow", "-webkit-box-sizing", "-webkit-filter", "-webkit-flex", "-webkit-flex-basis", "-webkit-flex-direction", "-webkit-flex-flow", "-webkit-flex-grow", "-webkit-flex-shrink", "-webkit-flex-wrap", "-webkit-justify-content", "-webkit-line-clamp", "-webkit-mask", "-webkit-mask-clip", "-webkit-mask-composite", "-webkit-mask-image", "-webkit-mask-origin", "-webkit-mask-position", "-webkit-mask-position-x", "-webkit-mask-position-y", "-webkit-mask-repeat", "-webkit-mask-size", "-webkit-order", "-webkit-perspective", "-webkit-perspective-origin", "-webkit-text-fill-color", "-webkit-text-size-adjust", "-webkit-text-stroke", "-webkit-text-stroke-color", "-webkit-text-stroke-width", "-webkit-transform", "-webkit-transform-origin", "-webkit-transform-style", "-webkit-transition", "-webkit-transition-delay", "-webkit-transition-duration", "-webkit-transition-property", "-webkit-transition-timing-function", "-webkit-user-select", "0", "1", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "2", "20", "3", "4", "5", "6", "7", "8", "9", "@@iterator", "ABORT_ERR", "ACTIVE", "ACTIVE_ATTRIBUTES", "ACTIVE_TEXTURE", "ACTIVE_UNIFORMS", "ACTIVE_UNIFORM_BLOCKS", "ADDITION", "ALIASED_LINE_WIDTH_RANGE", "ALIASED_POINT_SIZE_RANGE", "ALLOW_KEYBOARD_INPUT", "ALLPASS", "ALPHA", "ALPHA_BITS", "ALREADY_SIGNALED", "ALT_MASK", "ALWAYS", "ANY_SAMPLES_PASSED", "ANY_SAMPLES_PASSED_CONSERVATIVE", "ANY_TYPE", "ANY_UNORDERED_NODE_TYPE", "ARRAY_BUFFER", "ARRAY_BUFFER_BINDING", "ATTACHED_SHADERS", "ATTRIBUTE_NODE", "AT_TARGET", "AbortController", "AbortSignal", "AbsoluteOrientationSensor", "AbstractRange", "Accelerometer", "AddSearchProvider", "AggregateError", "AnalyserNode", "Animation", "AnimationEffect", "AnimationEvent", "AnimationPlaybackEvent", "AnimationTimeline", "AnonXMLHttpRequest", "Any", "ApplicationCache", "ApplicationCacheErrorEvent", "Array", "ArrayBuffer", "ArrayType", "Atomics", "Attr", "Audio", "AudioBuffer", "AudioBufferSourceNode", "AudioContext", "AudioDestinationNode", "AudioListener", "AudioNode", "AudioParam", "AudioParamMap", "AudioProcessingEvent", "AudioScheduledSourceNode", "AudioStreamTrack", "AudioWorklet", "AudioWorkletNode", "AuthenticatorAssertionResponse", "AuthenticatorAttestationResponse", "AuthenticatorResponse", "AutocompleteErrorEvent", "BACK", "BAD_BOUNDARYPOINTS_ERR", "BAD_REQUEST", "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", "BackgroundFetchManager", "BackgroundFetchRecord", "BackgroundFetchRegistration", "BarProp", "BarcodeDetector", "BaseAudioContext", "BaseHref", "BatteryManager", "BeforeInstallPromptEvent", "BeforeLoadEvent", "BeforeUnloadEvent", "BigInt", "BigInt64Array", "BigUint64Array", "BiquadFilterNode", "Blob", "BlobEvent", "Bluetooth", "BluetoothCharacteristicProperties", "BluetoothDevice", "BluetoothRemoteGATTCharacteristic", "BluetoothRemoteGATTDescriptor", "BluetoothRemoteGATTServer", "BluetoothRemoteGATTService", "BluetoothUUID", "Boolean", "BroadcastChannel", "ByteLengthQueuingStrategy", "CAPTURING_PHASE", "CCW", "CDATASection", "CDATA_SECTION_NODE", "CHANGE", "CHARSET_RULE", "CHECKING", "CLAMP_TO_EDGE", "CLICK", "CLOSED", "CLOSING", "COLOR", "COLOR_ATTACHMENT0", "COLOR_ATTACHMENT1", "COLOR_ATTACHMENT10", "COLOR_ATTACHMENT11", "COLOR_ATTACHMENT12", "COLOR_ATTACHMENT13", "COLOR_ATTACHMENT14", "COLOR_ATTACHMENT15", "COLOR_ATTACHMENT2", "COLOR_ATTACHMENT3", "COLOR_ATTACHMENT4", "COLOR_ATTACHMENT5", "COLOR_ATTACHMENT6", "COLOR_ATTACHMENT7", "COLOR_ATTACHMENT8", "COLOR_ATTACHMENT9", "COLOR_BUFFER_BIT", "COLOR_CLEAR_VALUE", "COLOR_WRITEMASK", "COMMENT_NODE", "COMPARE_REF_TO_TEXTURE", "COMPILE_STATUS", "COMPLETION_STATUS_KHR", "COMPRESSED_RGBA_S3TC_DXT1_EXT", "COMPRESSED_RGBA_S3TC_DXT3_EXT", "COMPRESSED_RGBA_S3TC_DXT5_EXT", "COMPRESSED_RGB_S3TC_DXT1_EXT", "COMPRESSED_TEXTURE_FORMATS", "CONDITION_SATISFIED", "CONFIGURATION_UNSUPPORTED", "CONNECTING", "CONSTANT_ALPHA", "CONSTANT_COLOR", "CONSTRAINT_ERR", "CONTEXT_LOST_WEBGL", "CONTROL_MASK", "COPY_READ_BUFFER", "COPY_READ_BUFFER_BINDING", "COPY_WRITE_BUFFER", "COPY_WRITE_BUFFER_BINDING", "COUNTER_STYLE_RULE", "CSS", "CSS2Properties", "CSSAnimation", "CSSCharsetRule", "CSSConditionRule", "CSSCounterStyleRule", "CSSFontFaceRule", "CSSFontFeatureValuesRule", "CSSGroupingRule", "CSSImageValue", "CSSImportRule", "CSSKeyframeRule", "CSSKeyframesRule", "CSSKeywordValue", "CSSMathInvert", "CSSMathMax", "CSSMathMin", "CSSMathNegate", "CSSMathProduct", "CSSMathSum", "CSSMathValue", "CSSMatrixComponent", "CSSMediaRule", "CSSMozDocumentRule", "CSSNameSpaceRule", "CSSNamespaceRule", "CSSNumericArray", "CSSNumericValue", "CSSPageRule", "CSSPerspective", "CSSPositionValue", "CSSPrimitiveValue", "CSSRotate", "CSSRule", "CSSRuleList", "CSSScale", "CSSSkew", "CSSSkewX", "CSSSkewY", "CSSStyleDeclaration", "CSSStyleRule", "CSSStyleSheet", "CSSStyleValue", "CSSSupportsRule", "CSSTransformComponent", "CSSTransformValue", "CSSTransition", "CSSTranslate", "CSSUnitValue", "CSSUnknownRule", "CSSUnparsedValue", "CSSValue", "CSSValueList", "CSSVariableReferenceValue", "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_QUERY", "CURRENT_VERTEX_ATTRIB", "CUSTOM", "CW", "Cache", "CacheStorage", "CanvasCaptureMediaStream", "CanvasCaptureMediaStreamTrack", "CanvasGradient", "CanvasPattern", "CanvasRenderingContext2D", "CaretPosition", "ChannelMergerNode", "ChannelSplitterNode", "CharacterData", "ClientRect", "ClientRectList", "Clipboard", "ClipboardEvent", "ClipboardItem", "CloseEvent", "Collator", "CommandEvent", "Comment", "CompileError", "CompositionEvent", "CompressionStream", "Console", "ConstantSourceNode", "Controllers", "ConvolverNode", "CountQueuingStrategy", "Counter", "Credential", "CredentialsContainer", "Crypto", "CryptoKey", "CustomElementRegistry", "CustomEvent", "DATABASE_ERR", "DATA_CLONE_ERR", "DATA_ERR", "DBLCLICK", "DECR", "DECR_WRAP", "DELETE_STATUS", "DEPTH", "DEPTH24_STENCIL8", "DEPTH32F_STENCIL8", "DEPTH_ATTACHMENT", "DEPTH_BITS", "DEPTH_BUFFER_BIT", "DEPTH_CLEAR_VALUE", "DEPTH_COMPONENT", "DEPTH_COMPONENT16", "DEPTH_COMPONENT24", "DEPTH_COMPONENT32F", "DEPTH_FUNC", "DEPTH_RANGE", "DEPTH_STENCIL", "DEPTH_STENCIL_ATTACHMENT", "DEPTH_TEST", "DEPTH_WRITEMASK", "DEVICE_INELIGIBLE", "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", "DRAW_BUFFER0", "DRAW_BUFFER1", "DRAW_BUFFER10", "DRAW_BUFFER11", "DRAW_BUFFER12", "DRAW_BUFFER13", "DRAW_BUFFER14", "DRAW_BUFFER15", "DRAW_BUFFER2", "DRAW_BUFFER3", "DRAW_BUFFER4", "DRAW_BUFFER5", "DRAW_BUFFER6", "DRAW_BUFFER7", "DRAW_BUFFER8", "DRAW_BUFFER9", "DRAW_FRAMEBUFFER", "DRAW_FRAMEBUFFER_BINDING", "DST_ALPHA", "DST_COLOR", "DYNAMIC_COPY", "DYNAMIC_DRAW", "DYNAMIC_READ", "DataChannel", "DataTransfer", "DataTransferItem", "DataTransferItemList", "DataView", "Date", "DateTimeFormat", "DecompressionStream", "DelayNode", "DeprecationReportBody", "DesktopNotification", "DesktopNotificationCenter", "DeviceLightEvent", "DeviceMotionEvent", "DeviceMotionEventAcceleration", "DeviceMotionEventRotationRate", "DeviceOrientationEvent", "DeviceProximityEvent", "DeviceStorage", "DeviceStorageChangeEvent", "Directory", "DisplayNames", "Document", "DocumentFragment", "DocumentTimeline", "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", "ElementInternals", "ElementQuery", "EnterPictureInPictureEvent", "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_32_UNSIGNED_INT_24_8_REV", "FLOAT_MAT2", "FLOAT_MAT2x3", "FLOAT_MAT2x4", "FLOAT_MAT3", "FLOAT_MAT3x2", "FLOAT_MAT3x4", "FLOAT_MAT4", "FLOAT_MAT4x2", "FLOAT_MAT4x3", "FLOAT_VEC2", "FLOAT_VEC3", "FLOAT_VEC4", "FOCUS", "FONT_FACE_RULE", "FONT_FEATURE_VALUES_RULE", "FRAGMENT_SHADER", "FRAGMENT_SHADER_DERIVATIVE_HINT", "FRAGMENT_SHADER_DERIVATIVE_HINT_OES", "FRAMEBUFFER", "FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE", "FRAMEBUFFER_ATTACHMENT_BLUE_SIZE", "FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING", "FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE", "FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE", "FRAMEBUFFER_ATTACHMENT_GREEN_SIZE", "FRAMEBUFFER_ATTACHMENT_OBJECT_NAME", "FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE", "FRAMEBUFFER_ATTACHMENT_RED_SIZE", "FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE", "FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE", "FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER", "FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL", "FRAMEBUFFER_BINDING", "FRAMEBUFFER_COMPLETE", "FRAMEBUFFER_DEFAULT", "FRAMEBUFFER_INCOMPLETE_ATTACHMENT", "FRAMEBUFFER_INCOMPLETE_DIMENSIONS", "FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT", "FRAMEBUFFER_INCOMPLETE_MULTISAMPLE", "FRAMEBUFFER_UNSUPPORTED", "FRONT", "FRONT_AND_BACK", "FRONT_FACE", "FUNC_ADD", "FUNC_REVERSE_SUBTRACT", "FUNC_SUBTRACT", "FeaturePolicy", "FeaturePolicyViolationReportBody", "FederatedCredential", "Feed", "FeedEntry", "File", "FileError", "FileList", "FileReader", "FileSystem", "FileSystemDirectoryEntry", "FileSystemDirectoryReader", "FileSystemEntry", "FileSystemFileEntry", "FinalizationRegistry", "FindInPage", "Float32Array", "Float64Array", "FocusEvent", "FontFace", "FontFaceSet", "FontFaceSetLoadEvent", "FormData", "FormDataEvent", "FragmentDirective", "Function", "GENERATE_MIPMAP_HINT", "GEQUAL", "GREATER", "GREEN_BITS", "GainNode", "Gamepad", "GamepadAxisMoveEvent", "GamepadButton", "GamepadButtonEvent", "GamepadEvent", "GamepadHapticActuator", "GamepadPose", "Geolocation", "GeolocationCoordinates", "GeolocationPosition", "GeolocationPositionError", "GestureEvent", "Global", "Gyroscope", "HALF_FLOAT", "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", "HTMLSlotElement", "HTMLSourceElement", "HTMLSpanElement", "HTMLStyleElement", "HTMLTableCaptionElement", "HTMLTableCellElement", "HTMLTableColElement", "HTMLTableElement", "HTMLTableRowElement", "HTMLTableSectionElement", "HTMLTemplateElement", "HTMLTextAreaElement", "HTMLTimeElement", "HTMLTitleElement", "HTMLTrackElement", "HTMLUListElement", "HTMLUnknownElement", "HTMLVideoElement", "HashChangeEvent", "Headers", "History", "Hz", "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", "IIRFilterNode", "IMPLEMENTATION_COLOR_READ_FORMAT", "IMPLEMENTATION_COLOR_READ_TYPE", "IMPORT_RULE", "INCR", "INCR_WRAP", "INDEX_SIZE_ERR", "INT", "INTERLEAVED_ATTRIBS", "INT_2_10_10_10_REV", "INT_SAMPLER_2D", "INT_SAMPLER_2D_ARRAY", "INT_SAMPLER_3D", "INT_SAMPLER_CUBE", "INT_VEC2", "INT_VEC3", "INT_VEC4", "INUSE_ATTRIBUTE_ERR", "INVALID_ACCESS_ERR", "INVALID_CHARACTER_ERR", "INVALID_ENUM", "INVALID_EXPRESSION_ERR", "INVALID_FRAMEBUFFER_OPERATION", "INVALID_INDEX", "INVALID_MODIFICATION_ERR", "INVALID_NODE_TYPE_ERR", "INVALID_OPERATION", "INVALID_STATE_ERR", "INVALID_VALUE", "INVERSE_DISTANCE", "INVERT", "IceCandidate", "IdleDeadline", "Image", "ImageBitmap", "ImageBitmapRenderingContext", "ImageCapture", "ImageData", "Infinity", "InputDeviceCapabilities", "InputDeviceInfo", "InputEvent", "InputMethodContext", "InstallTrigger", "InstallTriggerImpl", "Instance", "Int16Array", "Int32Array", "Int8Array", "Intent", "InternalError", "IntersectionObserver", "IntersectionObserverEntry", "Intl", "IsSearchProviderInstalled", "Iterator", "JSON", "KEEP", "KEYDOWN", "KEYFRAMES_RULE", "KEYFRAME_RULE", "KEYPRESS", "KEYUP", "KeyEvent", "Keyboard", "KeyboardEvent", "KeyboardLayoutMap", "KeyframeEffect", "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", "LargestContentfulPaint", "LayoutShift", "LayoutShiftAttribution", "LinearAccelerationSensor", "LinkError", "ListFormat", "LocalMediaStream", "Locale", "Location", "Lock", "LockManager", "MAX", "MAX_3D_TEXTURE_SIZE", "MAX_ARRAY_TEXTURE_LAYERS", "MAX_CLIENT_WAIT_TIMEOUT_WEBGL", "MAX_COLOR_ATTACHMENTS", "MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS", "MAX_COMBINED_TEXTURE_IMAGE_UNITS", "MAX_COMBINED_UNIFORM_BLOCKS", "MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS", "MAX_CUBE_MAP_TEXTURE_SIZE", "MAX_DRAW_BUFFERS", "MAX_ELEMENTS_INDICES", "MAX_ELEMENTS_VERTICES", "MAX_ELEMENT_INDEX", "MAX_FRAGMENT_INPUT_COMPONENTS", "MAX_FRAGMENT_UNIFORM_BLOCKS", "MAX_FRAGMENT_UNIFORM_COMPONENTS", "MAX_FRAGMENT_UNIFORM_VECTORS", "MAX_PROGRAM_TEXEL_OFFSET", "MAX_RENDERBUFFER_SIZE", "MAX_SAFE_INTEGER", "MAX_SAMPLES", "MAX_SERVER_WAIT_TIMEOUT", "MAX_TEXTURE_IMAGE_UNITS", "MAX_TEXTURE_LOD_BIAS", "MAX_TEXTURE_MAX_ANISOTROPY_EXT", "MAX_TEXTURE_SIZE", "MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS", "MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS", "MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS", "MAX_UNIFORM_BLOCK_SIZE", "MAX_UNIFORM_BUFFER_BINDINGS", "MAX_VALUE", "MAX_VARYING_COMPONENTS", "MAX_VARYING_VECTORS", "MAX_VERTEX_ATTRIBS", "MAX_VERTEX_OUTPUT_COMPONENTS", "MAX_VERTEX_TEXTURE_IMAGE_UNITS", "MAX_VERTEX_UNIFORM_BLOCKS", "MAX_VERTEX_UNIFORM_COMPONENTS", "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", "MIDIAccess", "MIDIConnectionEvent", "MIDIInput", "MIDIInputMap", "MIDIMessageEvent", "MIDIOutput", "MIDIOutputMap", "MIDIPort", "MIN", "MIN_PROGRAM_TEXEL_OFFSET", "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", "MathMLElement", "MediaCapabilities", "MediaCapabilitiesInfo", "MediaController", "MediaDeviceInfo", "MediaDevices", "MediaElementAudioSourceNode", "MediaEncryptedEvent", "MediaError", "MediaKeyError", "MediaKeyEvent", "MediaKeyMessageEvent", "MediaKeyNeededEvent", "MediaKeySession", "MediaKeyStatusMap", "MediaKeySystemAccess", "MediaKeys", "MediaList", "MediaMetadata", "MediaQueryList", "MediaQueryListEvent", "MediaRecorder", "MediaRecorderErrorEvent", "MediaSession", "MediaSettingsRange", "MediaSource", "MediaStream", "MediaStreamAudioDestinationNode", "MediaStreamAudioSourceNode", "MediaStreamEvent", "MediaStreamTrack", "MediaStreamTrackAudioSourceNode", "MediaStreamTrackEvent", "Memory", "MessageChannel", "MessageEvent", "MessagePort", "Methods", "MimeType", "MimeTypeArray", "Module", "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", "MozOsxFontSmoothing", "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", "NavigationPreloadManager", "Navigator", "NearbyLinks", "NetworkInformation", "Node", "NodeFilter", "NodeIterator", "NodeList", "Notation", "Notification", "NotifyPaintEvent", "Number", "NumberFormat", "OBJECT_TYPE", "OBSOLETE", "OK", "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", "OTHER_ERROR", "OUT_OF_MEMORY", "Object", "OfflineAudioCompletionEvent", "OfflineAudioContext", "OfflineResourceList", "OffscreenCanvas", "OffscreenCanvasRenderingContext2D", "Option", "OrientationSensor", "OscillatorNode", "OverconstrainedError", "OverflowEvent", "PACK_ALIGNMENT", "PACK_ROW_LENGTH", "PACK_SKIP_PIXELS", "PACK_SKIP_ROWS", "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", "PIXEL_PACK_BUFFER", "PIXEL_PACK_BUFFER_BINDING", "PIXEL_UNPACK_BUFFER", "PIXEL_UNPACK_BUFFER_BINDING", "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", "PasswordCredential", "Path2D", "PaymentAddress", "PaymentInstruments", "PaymentManager", "PaymentMethodChangeEvent", "PaymentRequest", "PaymentRequestUpdateEvent", "PaymentResponse", "Performance", "PerformanceElementTiming", "PerformanceEntry", "PerformanceEventTiming", "PerformanceLongTaskTiming", "PerformanceMark", "PerformanceMeasure", "PerformanceNavigation", "PerformanceNavigationTiming", "PerformanceObserver", "PerformanceObserverEntryList", "PerformancePaintTiming", "PerformanceResourceTiming", "PerformanceServerTiming", "PerformanceTiming", "PeriodicSyncManager", "PeriodicWave", "PermissionStatus", "Permissions", "PhotoCapabilities", "PictureInPictureWindow", "Plugin", "PluginArray", "PluralRules", "PointerEvent", "PopStateEvent", "PopupBlockedEvent", "Presentation", "PresentationAvailability", "PresentationConnection", "PresentationConnectionAvailableEvent", "PresentationConnectionCloseEvent", "PresentationConnectionList", "PresentationReceiver", "PresentationRequest", "ProcessingInstruction", "ProgressEvent", "Promise", "PromiseRejectionEvent", "PropertyNodeList", "Proxy", "PublicKeyCredential", "PushManager", "PushSubscription", "PushSubscriptionOptions", "Q", "QUERY_RESULT", "QUERY_RESULT_AVAILABLE", "QUOTA_ERR", "QUOTA_EXCEEDED_ERR", "QueryInterface", "R11F_G11F_B10F", "R16F", "R16I", "R16UI", "R32F", "R32I", "R32UI", "R8", "R8I", "R8UI", "R8_SNORM", "RASTERIZER_DISCARD", "READ_BUFFER", "READ_FRAMEBUFFER", "READ_FRAMEBUFFER_BINDING", "READ_ONLY", "READ_ONLY_ERR", "READ_WRITE", "RED", "RED_BITS", "RED_INTEGER", "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_SAMPLES", "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", "RG", "RG16F", "RG16I", "RG16UI", "RG32F", "RG32I", "RG32UI", "RG8", "RG8I", "RG8UI", "RG8_SNORM", "RGB", "RGB10_A2", "RGB10_A2UI", "RGB16F", "RGB16I", "RGB16UI", "RGB32F", "RGB32I", "RGB32UI", "RGB565", "RGB5_A1", "RGB8", "RGB8I", "RGB8UI", "RGB8_SNORM", "RGB9_E5", "RGBA", "RGBA16F", "RGBA16I", "RGBA16UI", "RGBA32F", "RGBA32I", "RGBA32UI", "RGBA4", "RGBA8", "RGBA8I", "RGBA8UI", "RGBA8_SNORM", "RGBA_INTEGER", "RGBColor", "RGB_INTEGER", "RG_INTEGER", "ROTATION_CLOCKWISE", "ROTATION_COUNTERCLOCKWISE", "RTCCertificate", "RTCDTMFSender", "RTCDTMFToneChangeEvent", "RTCDataChannel", "RTCDataChannelEvent", "RTCDtlsTransport", "RTCError", "RTCErrorEvent", "RTCIceCandidate", "RTCIceTransport", "RTCPeerConnection", "RTCPeerConnectionIceErrorEvent", "RTCPeerConnectionIceEvent", "RTCRtpReceiver", "RTCRtpSender", "RTCRtpTransceiver", "RTCSctpTransport", "RTCSessionDescription", "RTCStatsReport", "RTCTrackEvent", "RadioNodeList", "Range", "RangeError", "RangeException", "ReadableStream", "ReadableStreamDefaultReader", "RecordErrorEvent", "Rect", "ReferenceError", "Reflect", "RegExp", "RelativeOrientationSensor", "RelativeTimeFormat", "RemotePlayback", "Report", "ReportBody", "ReportingObserver", "Request", "ResizeObserver", "ResizeObserverEntry", "ResizeObserverSize", "Response", "RuntimeError", "SAMPLER_2D", "SAMPLER_2D_ARRAY", "SAMPLER_2D_ARRAY_SHADOW", "SAMPLER_2D_SHADOW", "SAMPLER_3D", "SAMPLER_BINDING", "SAMPLER_CUBE", "SAMPLER_CUBE_SHADOW", "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", "SEPARATE_ATTRIBS", "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", "SIGNALED", "SIGNED_NORMALIZED", "SINE", "SOUNDFIELD", "SQLException", "SQRT1_2", "SQRT2", "SQUARE", "SRC_ALPHA", "SRC_ALPHA_SATURATE", "SRC_COLOR", "SRGB", "SRGB8", "SRGB8_ALPHA8", "START_TO_END", "START_TO_START", "STATIC_COPY", "STATIC_DRAW", "STATIC_READ", "STENCIL", "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_COPY", "STREAM_DRAW", "STREAM_READ", "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", "SYNC_CONDITION", "SYNC_FENCE", "SYNC_FLAGS", "SYNC_FLUSH_COMMANDS_BIT", "SYNC_GPU_COMMANDS_COMPLETE", "SYNC_STATUS", "SYNTAX_ERR", "SavedPages", "Screen", "ScreenOrientation", "Script", "ScriptProcessorNode", "ScrollAreaEvent", "SecurityPolicyViolationEvent", "Selection", "Sensor", "SensorErrorEvent", "ServiceWorker", "ServiceWorkerContainer", "ServiceWorkerRegistration", "SessionDescription", "Set", "ShadowRoot", "SharedArrayBuffer", "SharedWorker", "SimpleGestureEvent", "SourceBuffer", "SourceBufferList", "SpeechSynthesis", "SpeechSynthesisErrorEvent", "SpeechSynthesisEvent", "SpeechSynthesisUtterance", "SpeechSynthesisVoice", "StaticRange", "StereoPannerNode", "StopIteration", "Storage", "StorageEvent", "StorageManager", "String", "StructType", "StylePropertyMap", "StylePropertyMapReadOnly", "StyleSheet", "StyleSheetList", "SubmitEvent", "SubtleCrypto", "Symbol", "SyncManager", "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_2D_ARRAY", "TEXTURE_3D", "TEXTURE_BASE_LEVEL", "TEXTURE_BINDING_2D", "TEXTURE_BINDING_2D_ARRAY", "TEXTURE_BINDING_3D", "TEXTURE_BINDING_CUBE_MAP", "TEXTURE_COMPARE_FUNC", "TEXTURE_COMPARE_MODE", "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_IMMUTABLE_FORMAT", "TEXTURE_IMMUTABLE_LEVELS", "TEXTURE_MAG_FILTER", "TEXTURE_MAX_ANISOTROPY_EXT", "TEXTURE_MAX_LEVEL", "TEXTURE_MAX_LOD", "TEXTURE_MIN_FILTER", "TEXTURE_MIN_LOD", "TEXTURE_WRAP_R", "TEXTURE_WRAP_S", "TEXTURE_WRAP_T", "TEXT_NODE", "TIMEOUT", "TIMEOUT_ERR", "TIMEOUT_EXPIRED", "TIMEOUT_IGNORED", "TOO_LARGE_ERR", "TRANSACTION_INACTIVE_ERR", "TRANSFORM_FEEDBACK", "TRANSFORM_FEEDBACK_ACTIVE", "TRANSFORM_FEEDBACK_BINDING", "TRANSFORM_FEEDBACK_BUFFER", "TRANSFORM_FEEDBACK_BUFFER_BINDING", "TRANSFORM_FEEDBACK_BUFFER_MODE", "TRANSFORM_FEEDBACK_BUFFER_SIZE", "TRANSFORM_FEEDBACK_BUFFER_START", "TRANSFORM_FEEDBACK_PAUSED", "TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN", "TRANSFORM_FEEDBACK_VARYINGS", "TRIANGLE", "TRIANGLES", "TRIANGLE_FAN", "TRIANGLE_STRIP", "TYPE_BACK_FORWARD", "TYPE_ERR", "TYPE_MISMATCH_ERR", "TYPE_NAVIGATE", "TYPE_RELOAD", "TYPE_RESERVED", "Table", "TaskAttributionTiming", "Text", "TextDecoder", "TextDecoderStream", "TextEncoder", "TextEncoderStream", "TextEvent", "TextMetrics", "TextTrack", "TextTrackCue", "TextTrackCueList", "TextTrackList", "TimeEvent", "TimeRanges", "Touch", "TouchEvent", "TouchList", "TrackEvent", "TransformStream", "TransitionEvent", "TreeWalker", "TrustedHTML", "TrustedScript", "TrustedScriptURL", "TrustedTypePolicy", "TrustedTypePolicyFactory", "TypeError", "TypedObject", "U2F", "UIEvent", "UNCACHED", "UNIFORM_ARRAY_STRIDE", "UNIFORM_BLOCK_ACTIVE_UNIFORMS", "UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES", "UNIFORM_BLOCK_BINDING", "UNIFORM_BLOCK_DATA_SIZE", "UNIFORM_BLOCK_INDEX", "UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER", "UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER", "UNIFORM_BUFFER", "UNIFORM_BUFFER_BINDING", "UNIFORM_BUFFER_OFFSET_ALIGNMENT", "UNIFORM_BUFFER_SIZE", "UNIFORM_BUFFER_START", "UNIFORM_IS_ROW_MAJOR", "UNIFORM_MATRIX_STRIDE", "UNIFORM_OFFSET", "UNIFORM_SIZE", "UNIFORM_TYPE", "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_IMAGE_HEIGHT", "UNPACK_PREMULTIPLY_ALPHA_WEBGL", "UNPACK_ROW_LENGTH", "UNPACK_SKIP_IMAGES", "UNPACK_SKIP_PIXELS", "UNPACK_SKIP_ROWS", "UNSCHEDULED_STATE", "UNSENT", "UNSIGNALED", "UNSIGNED_BYTE", "UNSIGNED_INT", "UNSIGNED_INT_10F_11F_11F_REV", "UNSIGNED_INT_24_8", "UNSIGNED_INT_2_10_10_10_REV", "UNSIGNED_INT_5_9_9_9_REV", "UNSIGNED_INT_SAMPLER_2D", "UNSIGNED_INT_SAMPLER_2D_ARRAY", "UNSIGNED_INT_SAMPLER_3D", "UNSIGNED_INT_SAMPLER_CUBE", "UNSIGNED_INT_VEC2", "UNSIGNED_INT_VEC3", "UNSIGNED_INT_VEC4", "UNSIGNED_NORMALIZED", "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", "USB", "USBAlternateInterface", "USBConfiguration", "USBConnectionEvent", "USBDevice", "USBEndpoint", "USBInTransferResult", "USBInterface", "USBIsochronousInTransferPacket", "USBIsochronousInTransferResult", "USBIsochronousOutTransferPacket", "USBIsochronousOutTransferResult", "USBOutTransferResult", "UTC", "Uint16Array", "Uint32Array", "Uint8Array", "Uint8ClampedArray", "UserActivation", "UserMessageHandler", "UserMessageHandlersNamespace", "UserProximityEvent", "VALIDATE_STATUS", "VALIDATION_ERR", "VARIABLES_RULE", "VENDOR", "VERSION", "VERSION_CHANGE", "VERSION_ERR", "VERTEX_ARRAY_BINDING", "VERTEX_ATTRIB_ARRAY_BUFFER_BINDING", "VERTEX_ATTRIB_ARRAY_DIVISOR", "VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE", "VERTEX_ATTRIB_ARRAY_ENABLED", "VERTEX_ATTRIB_ARRAY_INTEGER", "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", "VRDisplay", "VRDisplayCapabilities", "VRDisplayEvent", "VREyeParameters", "VRFieldOfView", "VRFrameData", "VRPose", "VRStageParameters", "VTTCue", "VTTRegion", "ValidityState", "VideoPlaybackQuality", "VideoStreamTrack", "VisualViewport", "WAIT_FAILED", "WEBKIT_FILTER_RULE", "WEBKIT_KEYFRAMES_RULE", "WEBKIT_KEYFRAME_RULE", "WEBKIT_REGION_RULE", "WRONG_DOCUMENT_ERR", "WakeLock", "WakeLockSentinel", "WasmAnyRef", "WaveShaperNode", "WeakMap", "WeakRef", "WeakSet", "WebAssembly", "WebGL2RenderingContext", "WebGLActiveInfo", "WebGLBuffer", "WebGLContextEvent", "WebGLFramebuffer", "WebGLProgram", "WebGLQuery", "WebGLRenderbuffer", "WebGLRenderingContext", "WebGLSampler", "WebGLShader", "WebGLShaderPrecisionFormat", "WebGLSync", "WebGLTexture", "WebGLTransformFeedback", "WebGLUniformLocation", "WebGLVertexArray", "WebGLVertexArrayObject", "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", "WebkitAlignContent", "WebkitAlignItems", "WebkitAlignSelf", "WebkitAnimation", "WebkitAnimationDelay", "WebkitAnimationDirection", "WebkitAnimationDuration", "WebkitAnimationFillMode", "WebkitAnimationIterationCount", "WebkitAnimationName", "WebkitAnimationPlayState", "WebkitAnimationTimingFunction", "WebkitAppearance", "WebkitBackfaceVisibility", "WebkitBackgroundClip", "WebkitBackgroundOrigin", "WebkitBackgroundSize", "WebkitBorderBottomLeftRadius", "WebkitBorderBottomRightRadius", "WebkitBorderImage", "WebkitBorderRadius", "WebkitBorderTopLeftRadius", "WebkitBorderTopRightRadius", "WebkitBoxAlign", "WebkitBoxDirection", "WebkitBoxFlex", "WebkitBoxOrdinalGroup", "WebkitBoxOrient", "WebkitBoxPack", "WebkitBoxShadow", "WebkitBoxSizing", "WebkitFilter", "WebkitFlex", "WebkitFlexBasis", "WebkitFlexDirection", "WebkitFlexFlow", "WebkitFlexGrow", "WebkitFlexShrink", "WebkitFlexWrap", "WebkitJustifyContent", "WebkitLineClamp", "WebkitMask", "WebkitMaskClip", "WebkitMaskComposite", "WebkitMaskImage", "WebkitMaskOrigin", "WebkitMaskPosition", "WebkitMaskPositionX", "WebkitMaskPositionY", "WebkitMaskRepeat", "WebkitMaskSize", "WebkitOrder", "WebkitPerspective", "WebkitPerspectiveOrigin", "WebkitTextFillColor", "WebkitTextSizeAdjust", "WebkitTextStroke", "WebkitTextStrokeColor", "WebkitTextStrokeWidth", "WebkitTransform", "WebkitTransformOrigin", "WebkitTransformStyle", "WebkitTransition", "WebkitTransitionDelay", "WebkitTransitionDuration", "WebkitTransitionProperty", "WebkitTransitionTimingFunction", "WebkitUserSelect", "WheelEvent", "Window", "Worker", "Worklet", "WritableStream", "WritableStreamDefaultWriter", "XMLDocument", "XMLHttpRequest", "XMLHttpRequestEventTarget", "XMLHttpRequestException", "XMLHttpRequestProgressEvent", "XMLHttpRequestUpload", "XMLSerializer", "XMLStylesheetProcessingInstruction", "XPathEvaluator", "XPathException", "XPathExpression", "XPathNSResolver", "XPathResult", "XRBoundedReferenceSpace", "XRDOMOverlayState", "XRFrame", "XRHitTestResult", "XRHitTestSource", "XRInputSource", "XRInputSourceArray", "XRInputSourceEvent", "XRInputSourcesChangeEvent", "XRLayer", "XRPose", "XRRay", "XRReferenceSpace", "XRReferenceSpaceEvent", "XRRenderState", "XRRigidTransform", "XRSession", "XRSessionEvent", "XRSpace", "XRSystem", "XRTransientInputHitTestResult", "XRTransientInputHitTestSource", "XRView", "XRViewerPose", "XRViewport", "XRWebGLLayer", "XSLTProcessor", "ZERO", "_XD0M_", "_YD0M_", "__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__", "__opera", "__proto__", "_browserjsran", "a", "aLink", "abbr", "abort", "aborted", "abs", "absolute", "acceleration", "accelerationIncludingGravity", "accelerator", "accept", "acceptCharset", "acceptNode", "accessKey", "accessKeyLabel", "accuracy", "acos", "acosh", "action", "actionURL", "actions", "activated", "active", "activeCues", "activeElement", "activeSourceBuffers", "activeSourceCount", "activeTexture", "activeVRDisplays", "actualBoundingBoxAscent", "actualBoundingBoxDescent", "actualBoundingBoxLeft", "actualBoundingBoxRight", "add", "addAll", "addBehavior", "addCandidate", "addColorStop", "addCue", "addElement", "addEventListener", "addFilter", "addFromString", "addFromUri", "addIceCandidate", "addImport", "addListener", "addModule", "addNamed", "addPageRule", "addPath", "addPointer", "addRange", "addRegion", "addRule", "addSearchEngine", "addSourceBuffer", "addStream", "addTextTrack", "addTrack", "addTransceiver", "addWakeLockListener", "added", "addedNodes", "additionalName", "additiveSymbols", "addons", "address", "addressLine", "adoptNode", "adoptedStyleSheets", "adr", "advance", "after", "album", "alert", "algorithm", "align", "align-content", "align-items", "align-self", "alignContent", "alignItems", "alignSelf", "alignmentBaseline", "alinkColor", "all", "allSettled", "allow", "allowFullscreen", "allowPaymentRequest", "allowedDirections", "allowedFeatures", "allowedToPlay", "allowsFeature", "alpha", "alt", "altGraphKey", "altHtml", "altKey", "altLeft", "alternate", "alternateSetting", "alternates", "altitude", "altitudeAccuracy", "amplitude", "ancestorOrigins", "anchor", "anchorNode", "anchorOffset", "anchors", "and", "angle", "angularAcceleration", "angularVelocity", "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", "antialias", "anticipatedRemoval", "any", "app", "appCodeName", "appMinorVersion", "appName", "appNotifications", "appVersion", "appearance", "append", "appendBuffer", "appendChild", "appendData", "appendItem", "appendMedium", "appendNamed", "appendRule", "appendStream", "appendWindowEnd", "appendWindowStart", "applets", "applicationCache", "applicationServerKey", "apply", "applyConstraints", "applyElement", "arc", "arcTo", "architecture", "archive", "areas", "arguments", "ariaAtomic", "ariaAutoComplete", "ariaBusy", "ariaChecked", "ariaColCount", "ariaColIndex", "ariaColSpan", "ariaCurrent", "ariaDescription", "ariaDisabled", "ariaExpanded", "ariaHasPopup", "ariaHidden", "ariaKeyShortcuts", "ariaLabel", "ariaLevel", "ariaLive", "ariaModal", "ariaMultiLine", "ariaMultiSelectable", "ariaOrientation", "ariaPlaceholder", "ariaPosInSet", "ariaPressed", "ariaReadOnly", "ariaRelevant", "ariaRequired", "ariaRoleDescription", "ariaRowCount", "ariaRowIndex", "ariaRowSpan", "ariaSelected", "ariaSetSize", "ariaSort", "ariaValueMax", "ariaValueMin", "ariaValueNow", "ariaValueText", "arrayBuffer", "artist", "artwork", "as", "asIntN", "asUintN", "asin", "asinh", "assert", "assign", "assignedElements", "assignedNodes", "assignedSlot", "async", "asyncIterator", "atEnd", "atan", "atan2", "atanh", "atob", "attachEvent", "attachInternals", "attachShader", "attachShadow", "attachments", "attack", "attestationObject", "attrChange", "attrName", "attributeFilter", "attributeName", "attributeNamespace", "attributeOldValue", "attributeStyleMap", "attributes", "attribution", "audioBitsPerSecond", "audioTracks", "audioWorklet", "authenticatedSignedWrites", "authenticatorData", "autoIncrement", "autobuffer", "autocapitalize", "autocomplete", "autocorrect", "autofocus", "automationRate", "autoplay", "availHeight", "availLeft", "availTop", "availWidth", "availability", "available", "aversion", "ax", "axes", "axis", "ay", "azimuth", "b", "back", "backface-visibility", "backfaceVisibility", "background", "background-attachment", "background-blend-mode", "background-clip", "background-color", "background-image", "background-origin", "background-position", "background-position-x", "background-position-y", "background-repeat", "background-size", "backgroundAttachment", "backgroundBlendMode", "backgroundClip", "backgroundColor", "backgroundFetch", "backgroundImage", "backgroundOrigin", "backgroundPosition", "backgroundPositionX", "backgroundPositionY", "backgroundRepeat", "backgroundSize", "badInput", "badge", "balance", "baseFrequencyX", "baseFrequencyY", "baseLatency", "baseLayer", "baseNode", "baseOffset", "baseURI", "baseVal", "baselineShift", "battery", "bday", "before", "beginElement", "beginElementAt", "beginPath", "beginQuery", "beginTransformFeedback", "behavior", "behaviorCookie", "behaviorPart", "behaviorUrns", "beta", "bezierCurveTo", "bgColor", "bgProperties", "bias", "big", "bigint64", "biguint64", "binaryType", "bind", "bindAttribLocation", "bindBuffer", "bindBufferBase", "bindBufferRange", "bindFramebuffer", "bindRenderbuffer", "bindSampler", "bindTexture", "bindTransformFeedback", "bindVertexArray", "bitness", "blendColor", "blendEquation", "blendEquationSeparate", "blendFunc", "blendFuncSeparate", "blink", "blitFramebuffer", "blob", "block-size", "blockDirection", "blockSize", "blockedURI", "blue", "bluetooth", "blur", "body", "bodyUsed", "bold", "bookmarks", "booleanValue", "border", "border-block", "border-block-color", "border-block-end", "border-block-end-color", "border-block-end-style", "border-block-end-width", "border-block-start", "border-block-start-color", "border-block-start-style", "border-block-start-width", "border-block-style", "border-block-width", "border-bottom", "border-bottom-color", "border-bottom-left-radius", "border-bottom-right-radius", "border-bottom-style", "border-bottom-width", "border-collapse", "border-color", "border-end-end-radius", "border-end-start-radius", "border-image", "border-image-outset", "border-image-repeat", "border-image-slice", "border-image-source", "border-image-width", "border-inline", "border-inline-color", "border-inline-end", "border-inline-end-color", "border-inline-end-style", "border-inline-end-width", "border-inline-start", "border-inline-start-color", "border-inline-start-style", "border-inline-start-width", "border-inline-style", "border-inline-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-start-end-radius", "border-start-start-radius", "border-style", "border-top", "border-top-color", "border-top-left-radius", "border-top-right-radius", "border-top-style", "border-top-width", "border-width", "borderBlock", "borderBlockColor", "borderBlockEnd", "borderBlockEndColor", "borderBlockEndStyle", "borderBlockEndWidth", "borderBlockStart", "borderBlockStartColor", "borderBlockStartStyle", "borderBlockStartWidth", "borderBlockStyle", "borderBlockWidth", "borderBottom", "borderBottomColor", "borderBottomLeftRadius", "borderBottomRightRadius", "borderBottomStyle", "borderBottomWidth", "borderBoxSize", "borderCollapse", "borderColor", "borderColorDark", "borderColorLight", "borderEndEndRadius", "borderEndStartRadius", "borderImage", "borderImageOutset", "borderImageRepeat", "borderImageSlice", "borderImageSource", "borderImageWidth", "borderInline", "borderInlineColor", "borderInlineEnd", "borderInlineEndColor", "borderInlineEndStyle", "borderInlineEndWidth", "borderInlineStart", "borderInlineStartColor", "borderInlineStartStyle", "borderInlineStartWidth", "borderInlineStyle", "borderInlineWidth", "borderLeft", "borderLeftColor", "borderLeftStyle", "borderLeftWidth", "borderRadius", "borderRight", "borderRightColor", "borderRightStyle", "borderRightWidth", "borderSpacing", "borderStartEndRadius", "borderStartStartRadius", "borderStyle", "borderTop", "borderTopColor", "borderTopLeftRadius", "borderTopRightRadius", "borderTopStyle", "borderTopWidth", "borderWidth", "bottom", "bottomMargin", "bound", "boundElements", "boundingClientRect", "boundingHeight", "boundingLeft", "boundingTop", "boundingWidth", "bounds", "boundsGeometry", "box-decoration-break", "box-shadow", "box-sizing", "boxDecorationBreak", "boxShadow", "boxSizing", "brand", "brands", "break-after", "break-before", "break-inside", "breakAfter", "breakBefore", "breakInside", "broadcast", "browserLanguage", "btoa", "bubbles", "buffer", "bufferData", "bufferDepth", "bufferSize", "bufferSubData", "buffered", "bufferedAmount", "bufferedAmountLowThreshold", "buildID", "buildNumber", "button", "buttonID", "buttons", "byteLength", "byteOffset", "bytesWritten", "c", "cache", "caches", "call", "caller", "canBeFormatted", "canBeMounted", "canBeShared", "canHaveChildren", "canHaveHTML", "canInsertDTMF", "canMakePayment", "canPlayType", "canPresent", "canTrickleIceCandidates", "cancel", "cancelAndHoldAtTime", "cancelAnimationFrame", "cancelBubble", "cancelIdleCallback", "cancelScheduledValues", "cancelVideoFrameCallback", "cancelWatchAvailability", "cancelable", "candidate", "canonicalUUID", "canvas", "capabilities", "caption", "caption-side", "captionSide", "capture", "captureEvents", "captureStackTrace", "captureStream", "caret-color", "caretBidiLevel", "caretColor", "caretPositionFromPoint", "caretRangeFromPoint", "cast", "catch", "category", "cbrt", "cd", "ceil", "cellIndex", "cellPadding", "cellSpacing", "cells", "ch", "chOff", "chain", "challenge", "changeType", "changedTouches", "channel", "channelCount", "channelCountMode", "channelInterpretation", "char", "charAt", "charCode", "charCodeAt", "charIndex", "charLength", "characterData", "characterDataOldValue", "characterSet", "characteristic", "charging", "chargingTime", "charset", "check", "checkEnclosure", "checkFramebufferStatus", "checkIntersection", "checkValidity", "checked", "childElementCount", "childList", "childNodes", "children", "chrome", "ciphertext", "cite", "city", "claimInterface", "claimed", "classList", "className", "classid", "clear", "clearAppBadge", "clearAttributes", "clearBufferfi", "clearBufferfv", "clearBufferiv", "clearBufferuiv", "clearColor", "clearData", "clearDepth", "clearHalt", "clearImmediate", "clearInterval", "clearLiveSeekableRange", "clearMarks", "clearMaxGCPauseAccumulator", "clearMeasures", "clearParameters", "clearRect", "clearResourceTimings", "clearShadow", "clearStencil", "clearTimeout", "clearWatch", "click", "clickCount", "clientDataJSON", "clientHeight", "clientInformation", "clientLeft", "clientRect", "clientRects", "clientTop", "clientWaitSync", "clientWidth", "clientX", "clientY", "clip", "clip-path", "clip-rule", "clipBottom", "clipLeft", "clipPath", "clipPathUnits", "clipRight", "clipRule", "clipTop", "clipboard", "clipboardData", "clone", "cloneContents", "cloneNode", "cloneRange", "close", "closePath", "closed", "closest", "clz", "clz32", "cm", "cmp", "code", "codeBase", "codePointAt", "codeType", "colSpan", "collapse", "collapseToEnd", "collapseToStart", "collapsed", "collect", "colno", "color", "color-adjust", "color-interpolation", "color-interpolation-filters", "colorAdjust", "colorDepth", "colorInterpolation", "colorInterpolationFilters", "colorMask", "colorType", "cols", "column-count", "column-fill", "column-gap", "column-rule", "column-rule-color", "column-rule-style", "column-rule-width", "column-span", "column-width", "columnCount", "columnFill", "columnGap", "columnNumber", "columnRule", "columnRuleColor", "columnRuleStyle", "columnRuleWidth", "columnSpan", "columnWidth", "columns", "command", "commit", "commitPreferences", "commitStyles", "commonAncestorContainer", "compact", "compareBoundaryPoints", "compareDocumentPosition", "compareEndPoints", "compareExchange", "compareNode", "comparePoint", "compatMode", "compatible", "compile", "compileShader", "compileStreaming", "complete", "component", "componentFromPoint", "composed", "composedPath", "composite", "compositionEndOffset", "compositionStartOffset", "compressedTexImage2D", "compressedTexImage3D", "compressedTexSubImage2D", "compressedTexSubImage3D", "computedStyleMap", "concat", "conditionText", "coneInnerAngle", "coneOuterAngle", "coneOuterGain", "configurable", "configuration", "configurationName", "configurationValue", "configurations", "confirm", "confirmComposition", "confirmSiteSpecificTrackingException", "confirmWebWideTrackingException", "connect", "connectEnd", "connectShark", "connectStart", "connected", "connection", "connectionList", "connectionSpeed", "connectionState", "connections", "console", "consolidate", "constraint", "constrictionActive", "construct", "constructor", "contactID", "contain", "containerId", "containerName", "containerSrc", "containerType", "contains", "containsNode", "content", "contentBoxSize", "contentDocument", "contentEditable", "contentHint", "contentOverflow", "contentRect", "contentScriptType", "contentStyleType", "contentType", "contentWindow", "context", "contextMenu", "contextmenu", "continue", "continuePrimaryKey", "continuous", "control", "controlTransferIn", "controlTransferOut", "controller", "controls", "controlsList", "convertPointFromNode", "convertQuadFromNode", "convertRectFromNode", "convertToBlob", "convertToSpecifiedUnits", "cookie", "cookieEnabled", "coords", "copyBufferSubData", "copyFromChannel", "copyTexImage2D", "copyTexSubImage2D", "copyTexSubImage3D", "copyToChannel", "copyWithin", "correspondingElement", "correspondingUseElement", "corruptedVideoFrames", "cos", "cosh", "count", "countReset", "counter-increment", "counter-reset", "counter-set", "counterIncrement", "counterReset", "counterSet", "country", "cpuClass", "cpuSleepAllowed", "create", "createAnalyser", "createAnswer", "createAttribute", "createAttributeNS", "createBiquadFilter", "createBuffer", "createBufferSource", "createCDATASection", "createCSSStyleSheet", "createCaption", "createChannelMerger", "createChannelSplitter", "createComment", "createConstantSource", "createContextualFragment", "createControlRange", "createConvolver", "createDTMFSender", "createDataChannel", "createDelay", "createDelayNode", "createDocument", "createDocumentFragment", "createDocumentType", "createDynamicsCompressor", "createElement", "createElementNS", "createEntityReference", "createEvent", "createEventObject", "createExpression", "createFramebuffer", "createFunction", "createGain", "createGainNode", "createHTML", "createHTMLDocument", "createIIRFilter", "createImageBitmap", "createImageData", "createIndex", "createJavaScriptNode", "createLinearGradient", "createMediaElementSource", "createMediaKeys", "createMediaStreamDestination", "createMediaStreamSource", "createMediaStreamTrackSource", "createMutableFile", "createNSResolver", "createNodeIterator", "createNotification", "createObjectStore", "createObjectURL", "createOffer", "createOscillator", "createPanner", "createPattern", "createPeriodicWave", "createPolicy", "createPopup", "createProcessingInstruction", "createProgram", "createQuery", "createRadialGradient", "createRange", "createRangeCollection", "createReader", "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", "createSampler", "createScript", "createScriptProcessor", "createScriptURL", "createSession", "createShader", "createShadowRoot", "createStereoPanner", "createStyleSheet", "createTBody", "createTFoot", "createTHead", "createTextNode", "createTextRange", "createTexture", "createTouch", "createTouchList", "createTransformFeedback", "createTreeWalker", "createVertexArray", "createWaveShaper", "creationTime", "credentials", "crossOrigin", "crossOriginIsolated", "crypto", "csi", "csp", "cssFloat", "cssRules", "cssText", "cssValueType", "ctrlKey", "ctrlLeft", "cues", "cullFace", "currentDirection", "currentLocalDescription", "currentNode", "currentPage", "currentRect", "currentRemoteDescription", "currentScale", "currentScript", "currentSrc", "currentState", "currentStyle", "currentTarget", "currentTime", "currentTranslate", "currentView", "cursor", "curve", "customElements", "customError", "cx", "cy", "d", "data", "dataFld", "dataFormatAs", "dataLoss", "dataLossMessage", "dataPageSize", "dataSrc", "dataTransfer", "database", "databases", "dataset", "dateTime", "db", "debug", "debuggerEnabled", "declare", "decode", "decodeAudioData", "decodeURI", "decodeURIComponent", "decodedBodySize", "decoding", "decodingInfo", "decrypt", "default", "defaultCharset", "defaultChecked", "defaultMuted", "defaultPlaybackRate", "defaultPolicy", "defaultPrevented", "defaultRequest", "defaultSelected", "defaultStatus", "defaultURL", "defaultValue", "defaultView", "defaultstatus", "defer", "define", "defineMagicFunction", "defineMagicVariable", "defineProperties", "defineProperty", "deg", "delay", "delayTime", "delegatesFocus", "delete", "deleteBuffer", "deleteCaption", "deleteCell", "deleteContents", "deleteData", "deleteDatabase", "deleteFramebuffer", "deleteFromDocument", "deleteIndex", "deleteMedium", "deleteObjectStore", "deleteProgram", "deleteProperty", "deleteQuery", "deleteRenderbuffer", "deleteRow", "deleteRule", "deleteSampler", "deleteShader", "deleteSync", "deleteTFoot", "deleteTHead", "deleteTexture", "deleteTransformFeedback", "deleteVertexArray", "deliverChangeRecords", "delivery", "deliveryInfo", "deliveryStatus", "deliveryTimestamp", "delta", "deltaMode", "deltaX", "deltaY", "deltaZ", "dependentLocality", "depthFar", "depthFunc", "depthMask", "depthNear", "depthRange", "deref", "deriveBits", "deriveKey", "description", "deselectAll", "designMode", "desiredSize", "destination", "destinationURL", "detach", "detachEvent", "detachShader", "detail", "details", "detect", "detune", "device", "deviceClass", "deviceId", "deviceMemory", "devicePixelContentBoxSize", "devicePixelRatio", "deviceProtocol", "deviceSubclass", "deviceVersionMajor", "deviceVersionMinor", "deviceVersionSubminor", "deviceXDPI", "deviceYDPI", "didTimeout", "diffuseConstant", "digest", "dimensions", "dir", "dirName", "direction", "dirxml", "disable", "disablePictureInPicture", "disableRemotePlayback", "disableVertexAttribArray", "disabled", "dischargingTime", "disconnect", "disconnectShark", "dispatchEvent", "display", "displayId", "displayName", "disposition", "distanceModel", "div", "divisor", "djsapi", "djsproxy", "doImport", "doNotTrack", "doScroll", "doctype", "document", "documentElement", "documentMode", "documentURI", "dolphin", "dolphinGameCenter", "dolphininfo", "dolphinmeta", "domComplete", "domContentLoadedEventEnd", "domContentLoadedEventStart", "domInteractive", "domLoading", "domOverlayState", "domain", "domainLookupEnd", "domainLookupStart", "dominant-baseline", "dominantBaseline", "done", "dopplerFactor", "dotAll", "downDegrees", "downlink", "download", "downloadTotal", "downloaded", "dpcm", "dpi", "dppx", "dragDrop", "draggable", "drawArrays", "drawArraysInstanced", "drawArraysInstancedANGLE", "drawBuffers", "drawCustomFocusRing", "drawElements", "drawElementsInstanced", "drawElementsInstancedANGLE", "drawFocusIfNeeded", "drawImage", "drawImageFromRect", "drawRangeElements", "drawSystemFocusRing", "drawingBufferHeight", "drawingBufferWidth", "dropEffect", "droppedVideoFrames", "dropzone", "dtmf", "dump", "dumpProfile", "duplicate", "durability", "duration", "dvname", "dvnum", "dx", "dy", "dynsrc", "e", "edgeMode", "effect", "effectAllowed", "effectiveDirective", "effectiveType", "elapsedTime", "element", "elementFromPoint", "elementTiming", "elements", "elementsFromPoint", "elevation", "ellipse", "em", "email", "embeds", "emma", "empty", "empty-cells", "emptyCells", "emptyHTML", "emptyScript", "emulatedPosition", "enable", "enableBackground", "enableDelegations", "enableStyleSheetsForSet", "enableVertexAttribArray", "enabled", "enabledPlugin", "encode", "encodeInto", "encodeURI", "encodeURIComponent", "encodedBodySize", "encoding", "encodingInfo", "encrypt", "enctype", "end", "endContainer", "endElement", "endElementAt", "endOfStream", "endOffset", "endQuery", "endTime", "endTransformFeedback", "ended", "endpoint", "endpointNumber", "endpoints", "endsWith", "enterKeyHint", "entities", "entries", "entryType", "enumerable", "enumerate", "enumerateDevices", "enumerateEditable", "environmentBlendMode", "equals", "error", "errorCode", "errorDetail", "errorText", "escape", "estimate", "eval", "evaluate", "event", "eventPhase", "every", "ex", "exception", "exchange", "exec", "execCommand", "execCommandShowHelp", "execScript", "exitFullscreen", "exitPictureInPicture", "exitPointerLock", "exitPresent", "exp", "expand", "expandEntityReferences", "expando", "expansion", "expiration", "expirationTime", "expires", "expiryDate", "explicitOriginalTarget", "expm1", "exponent", "exponentialRampToValueAtTime", "exportKey", "exports", "extend", "extensions", "extentNode", "extentOffset", "external", "externalResourcesRequired", "extractContents", "extractable", "eye", "f", "face", "factoryReset", "failureReason", "fallback", "family", "familyName", "farthestViewportElement", "fastSeek", "fatal", "featureId", "featurePolicy", "featureSettings", "features", "fenceSync", "fetch", "fetchStart", "fftSize", "fgColor", "fieldOfView", "file", "fileCreatedDate", "fileHandle", "fileModifiedDate", "fileName", "fileSize", "fileUpdatedDate", "filename", "files", "filesystem", "fill", "fill-opacity", "fill-rule", "fillLightMode", "fillOpacity", "fillRect", "fillRule", "fillStyle", "fillText", "filter", "filterResX", "filterResY", "filterUnits", "filters", "finally", "find", "findIndex", "findRule", "findText", "finish", "finished", "fireEvent", "firesTouchEvents", "firstChild", "firstElementChild", "firstPage", "fixed", "flags", "flat", "flatMap", "flex", "flex-basis", "flex-direction", "flex-flow", "flex-grow", "flex-shrink", "flex-wrap", "flexBasis", "flexDirection", "flexFlow", "flexGrow", "flexShrink", "flexWrap", "flipX", "flipY", "float", "float32", "float64", "flood-color", "flood-opacity", "floodColor", "floodOpacity", "floor", "flush", "focus", "focusNode", "focusOffset", "font", "font-family", "font-feature-settings", "font-kerning", "font-language-override", "font-optical-sizing", "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-variation-settings", "font-weight", "fontFamily", "fontFeatureSettings", "fontKerning", "fontLanguageOverride", "fontOpticalSizing", "fontSize", "fontSizeAdjust", "fontSmoothingEnabled", "fontStretch", "fontStyle", "fontSynthesis", "fontVariant", "fontVariantAlternates", "fontVariantCaps", "fontVariantEastAsian", "fontVariantLigatures", "fontVariantNumeric", "fontVariantPosition", "fontVariationSettings", "fontWeight", "fontcolor", "fontfaces", "fonts", "fontsize", "for", "forEach", "force", "forceRedraw", "form", "formAction", "formData", "formEnctype", "formMethod", "formNoValidate", "formTarget", "format", "formatToParts", "forms", "forward", "forwardX", "forwardY", "forwardZ", "foundation", "fr", "fragmentDirective", "frame", "frameBorder", "frameElement", "frameSpacing", "framebuffer", "framebufferHeight", "framebufferRenderbuffer", "framebufferTexture2D", "framebufferTextureLayer", "framebufferWidth", "frames", "freeSpace", "freeze", "frequency", "frequencyBinCount", "from", "fromCharCode", "fromCodePoint", "fromElement", "fromEntries", "fromFloat32Array", "fromFloat64Array", "fromMatrix", "fromPoint", "fromQuad", "fromRect", "frontFace", "fround", "fullPath", "fullScreen", "fullVersionList", "fullscreen", "fullscreenElement", "fullscreenEnabled", "fx", "fy", "gain", "gamepad", "gamma", "gap", "gatheringState", "gatt", "genderIdentity", "generateCertificate", "generateKey", "generateMipmap", "generateRequest", "geolocation", "gestureObject", "get", "getActiveAttrib", "getActiveUniform", "getActiveUniformBlockName", "getActiveUniformBlockParameter", "getActiveUniforms", "getAdjacentText", "getAll", "getAllKeys", "getAllResponseHeaders", "getAllowlistForFeature", "getAnimations", "getAsFile", "getAsString", "getAttachedShaders", "getAttribLocation", "getAttribute", "getAttributeNS", "getAttributeNames", "getAttributeNode", "getAttributeNodeNS", "getAttributeType", "getAudioTracks", "getAvailability", "getBBox", "getBattery", "getBigInt64", "getBigUint64", "getBlob", "getBookmark", "getBoundingClientRect", "getBounds", "getBoxQuads", "getBufferParameter", "getBufferSubData", "getByteFrequencyData", "getByteTimeDomainData", "getCSSCanvasContext", "getCTM", "getCandidateWindowClientRect", "getCanonicalLocales", "getCapabilities", "getChannelData", "getCharNumAtPosition", "getCharacteristic", "getCharacteristics", "getClientExtensionResults", "getClientRect", "getClientRects", "getCoalescedEvents", "getCompositionAlternatives", "getComputedStyle", "getComputedTextLength", "getComputedTiming", "getConfiguration", "getConstraints", "getContext", "getContextAttributes", "getContributingSources", "getCounterValue", "getCueAsHTML", "getCueById", "getCurrentPosition", "getCurrentTime", "getData", "getDatabaseNames", "getDate", "getDay", "getDefaultComputedStyle", "getDescriptor", "getDescriptors", "getDestinationInsertionPoints", "getDevices", "getDirectory", "getDisplayMedia", "getDistributedNodes", "getEditable", "getElementById", "getElementsByClassName", "getElementsByName", "getElementsByTagName", "getElementsByTagNameNS", "getEnclosureList", "getEndPositionOfChar", "getEntries", "getEntriesByName", "getEntriesByType", "getError", "getExtension", "getExtentOfChar", "getEyeParameters", "getFeature", "getFile", "getFiles", "getFilesAndDirectories", "getFingerprints", "getFloat32", "getFloat64", "getFloatFrequencyData", "getFloatTimeDomainData", "getFloatValue", "getFragDataLocation", "getFrameData", "getFramebufferAttachmentParameter", "getFrequencyResponse", "getFullYear", "getGamepads", "getHighEntropyValues", "getHitTestResults", "getHitTestResultsForTransientInput", "getHours", "getIdentityAssertion", "getIds", "getImageData", "getIndexedParameter", "getInstalledRelatedApps", "getInt16", "getInt32", "getInt8", "getInternalformatParameter", "getIntersectionList", "getItem", "getItems", "getKey", "getKeyframes", "getLayers", "getLayoutMap", "getLineDash", "getLocalCandidates", "getLocalParameters", "getLocalStreams", "getMarks", "getMatchedCSSRules", "getMaxGCPauseSinceClear", "getMeasures", "getMetadata", "getMilliseconds", "getMinutes", "getModifierState", "getMonth", "getNamedItem", "getNamedItemNS", "getNativeFramebufferScaleFactor", "getNotifications", "getNotifier", "getNumberOfChars", "getOffsetReferenceSpace", "getOutputTimestamp", "getOverrideHistoryNavigationMode", "getOverrideStyle", "getOwnPropertyDescriptor", "getOwnPropertyDescriptors", "getOwnPropertyNames", "getOwnPropertySymbols", "getParameter", "getParameters", "getParent", "getPathSegAtLength", "getPhotoCapabilities", "getPhotoSettings", "getPointAtLength", "getPose", "getPredictedEvents", "getPreference", "getPreferenceDefault", "getPresentationAttribute", "getPreventDefault", "getPrimaryService", "getPrimaryServices", "getProgramInfoLog", "getProgramParameter", "getPropertyCSSValue", "getPropertyPriority", "getPropertyShorthand", "getPropertyType", "getPropertyValue", "getPrototypeOf", "getQuery", "getQueryParameter", "getRGBColorValue", "getRandomValues", "getRangeAt", "getReader", "getReceivers", "getRectValue", "getRegistration", "getRegistrations", "getRemoteCandidates", "getRemoteCertificates", "getRemoteParameters", "getRemoteStreams", "getRenderbufferParameter", "getResponseHeader", "getRoot", "getRootNode", "getRotationOfChar", "getSVGDocument", "getSamplerParameter", "getScreenCTM", "getSeconds", "getSelectedCandidatePair", "getSelection", "getSenders", "getService", "getSettings", "getShaderInfoLog", "getShaderParameter", "getShaderPrecisionFormat", "getShaderSource", "getSimpleDuration", "getSiteIcons", "getSources", "getSpeculativeParserUrls", "getStartPositionOfChar", "getStartTime", "getState", "getStats", "getStatusForPolicy", "getStorageUpdates", "getStreamById", "getStringValue", "getSubStringLength", "getSubscription", "getSupportedConstraints", "getSupportedExtensions", "getSupportedFormats", "getSyncParameter", "getSynchronizationSources", "getTags", "getTargetRanges", "getTexParameter", "getTime", "getTimezoneOffset", "getTiming", "getTotalLength", "getTrackById", "getTracks", "getTransceivers", "getTransform", "getTransformFeedbackVarying", "getTransformToElement", "getTransports", "getType", "getTypeMapping", "getUTCDate", "getUTCDay", "getUTCFullYear", "getUTCHours", "getUTCMilliseconds", "getUTCMinutes", "getUTCMonth", "getUTCSeconds", "getUint16", "getUint32", "getUint8", "getUniform", "getUniformBlockIndex", "getUniformIndices", "getUniformLocation", "getUserMedia", "getVRDisplays", "getValues", "getVarDate", "getVariableValue", "getVertexAttrib", "getVertexAttribOffset", "getVideoPlaybackQuality", "getVideoTracks", "getViewerPose", "getViewport", "getVoices", "getWakeLockState", "getWriter", "getYear", "givenName", "global", "globalAlpha", "globalCompositeOperation", "globalThis", "glyphOrientationHorizontal", "glyphOrientationVertical", "glyphRef", "go", "grabFrame", "grad", "gradientTransform", "gradientUnits", "grammars", "green", "grid", "grid-area", "grid-auto-columns", "grid-auto-flow", "grid-auto-rows", "grid-column", "grid-column-end", "grid-column-gap", "grid-column-start", "grid-gap", "grid-row", "grid-row-end", "grid-row-gap", "grid-row-start", "grid-template", "grid-template-areas", "grid-template-columns", "grid-template-rows", "gridArea", "gridAutoColumns", "gridAutoFlow", "gridAutoRows", "gridColumn", "gridColumnEnd", "gridColumnGap", "gridColumnStart", "gridGap", "gridRow", "gridRowEnd", "gridRowGap", "gridRowStart", "gridTemplate", "gridTemplateAreas", "gridTemplateColumns", "gridTemplateRows", "gripSpace", "group", "groupCollapsed", "groupEnd", "groupId", "hadRecentInput", "hand", "handedness", "hapticActuators", "hardwareConcurrency", "has", "hasAttribute", "hasAttributeNS", "hasAttributes", "hasBeenActive", "hasChildNodes", "hasComposition", "hasEnrolledInstrument", "hasExtension", "hasExternalDisplay", "hasFeature", "hasFocus", "hasInstance", "hasLayout", "hasOrientation", "hasOwnProperty", "hasPointerCapture", "hasPosition", "hasReading", "hasStorageAccess", "hash", "head", "headers", "heading", "height", "hidden", "hide", "hideFocus", "high", "highWaterMark", "hint", "history", "honorificPrefix", "honorificSuffix", "horizontalOverflow", "host", "hostCandidate", "hostname", "href", "hrefTranslate", "hreflang", "hspace", "html5TagCheckInerface", "htmlFor", "htmlText", "httpEquiv", "httpRequestStatusCode", "hwTimestamp", "hyphens", "hypot", "iccId", "iceConnectionState", "iceGatheringState", "iceTransport", "icon", "iconURL", "id", "identifier", "identity", "idpLoginUrl", "ignoreBOM", "ignoreCase", "ignoreDepthValues", "image-orientation", "image-rendering", "imageHeight", "imageOrientation", "imageRendering", "imageSizes", "imageSmoothingEnabled", "imageSmoothingQuality", "imageSrcset", "imageWidth", "images", "ime-mode", "imeMode", "implementation", "importKey", "importNode", "importStylesheet", "imports", "impp", "imul", "in", "in1", "in2", "inBandMetadataTrackDispatchType", "inRange", "includes", "incremental", "indeterminate", "index", "indexNames", "indexOf", "indexedDB", "indicate", "inert", "inertiaDestinationX", "inertiaDestinationY", "info", "init", "initAnimationEvent", "initBeforeLoadEvent", "initClipboardEvent", "initCloseEvent", "initCommandEvent", "initCompositionEvent", "initCustomEvent", "initData", "initDataType", "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", "inline-size", "inlineSize", "inlineVerticalFieldOfView", "inner", "innerHTML", "innerHeight", "innerText", "innerWidth", "input", "inputBuffer", "inputEncoding", "inputMethod", "inputMode", "inputSource", "inputSources", "inputType", "inputs", "insertAdjacentElement", "insertAdjacentHTML", "insertAdjacentText", "insertBefore", "insertCell", "insertDTMF", "insertData", "insertItemBefore", "insertNode", "insertRow", "insertRule", "inset", "inset-block", "inset-block-end", "inset-block-start", "inset-inline", "inset-inline-end", "inset-inline-start", "insetBlock", "insetBlockEnd", "insetBlockStart", "insetInline", "insetInlineEnd", "insetInlineStart", "installing", "instanceRoot", "instantiate", "instantiateStreaming", "instruments", "int16", "int32", "int8", "integrity", "interactionMode", "intercept", "interfaceClass", "interfaceName", "interfaceNumber", "interfaceProtocol", "interfaceSubclass", "interfaces", "interimResults", "internalSubset", "interpretation", "intersectionRatio", "intersectionRect", "intersectsNode", "interval", "invalidIteratorState", "invalidateFramebuffer", "invalidateSubFramebuffer", "inverse", "invertSelf", "is", "is2D", "isActive", "isAlternate", "isArray", "isBingCurrentSearchDefault", "isBuffer", "isCandidateWindowVisible", "isChar", "isCollapsed", "isComposing", "isConcatSpreadable", "isConnected", "isContentEditable", "isContentHandlerRegistered", "isContextLost", "isDefaultNamespace", "isDirectory", "isDisabled", "isEnabled", "isEqual", "isEqualNode", "isExtensible", "isExternalCTAP2SecurityKeySupported", "isFile", "isFinite", "isFramebuffer", "isFrozen", "isGenerator", "isHTML", "isHistoryNavigation", "isId", "isIdentity", "isInjected", "isInteger", "isIntersecting", "isLockFree", "isMap", "isMultiLine", "isNaN", "isOpen", "isPointInFill", "isPointInPath", "isPointInRange", "isPointInStroke", "isPrefAlternate", "isPresenting", "isPrimary", "isProgram", "isPropertyImplicit", "isProtocolHandlerRegistered", "isPrototypeOf", "isQuery", "isRenderbuffer", "isSafeInteger", "isSameNode", "isSampler", "isScript", "isScriptURL", "isSealed", "isSecureContext", "isSessionSupported", "isShader", "isSupported", "isSync", "isTextEdit", "isTexture", "isTransformFeedback", "isTrusted", "isTypeSupported", "isUserVerifyingPlatformAuthenticatorAvailable", "isVertexArray", "isView", "isVisible", "isochronousTransferIn", "isochronousTransferOut", "isolation", "italics", "item", "itemId", "itemProp", "itemRef", "itemScope", "itemType", "itemValue", "items", "iterateNext", "iterationComposite", "iterator", "javaEnabled", "jobTitle", "join", "json", "justify-content", "justify-items", "justify-self", "justifyContent", "justifyItems", "justifySelf", "k1", "k2", "k3", "k4", "kHz", "keepalive", "kernelMatrix", "kernelUnitLengthX", "kernelUnitLengthY", "kerning", "key", "keyCode", "keyFor", "keyIdentifier", "keyLightEnabled", "keyLocation", "keyPath", "keyStatuses", "keySystem", "keyText", "keyUsage", "keyboard", "keys", "keytype", "kind", "knee", "label", "labels", "lang", "language", "languages", "largeArcFlag", "lastChild", "lastElementChild", "lastEventId", "lastIndex", "lastIndexOf", "lastInputTime", "lastMatch", "lastMessageSubject", "lastMessageType", "lastModified", "lastModifiedDate", "lastPage", "lastParen", "lastState", "lastStyleSheetSet", "latitude", "layerX", "layerY", "layoutFlow", "layoutGrid", "layoutGridChar", "layoutGridLine", "layoutGridMode", "layoutGridType", "lbound", "left", "leftContext", "leftDegrees", "leftMargin", "leftProjectionMatrix", "leftViewMatrix", "length", "lengthAdjust", "lengthComputable", "letter-spacing", "letterSpacing", "level", "lighting-color", "lightingColor", "limitingConeAngle", "line", "line-break", "line-height", "lineAlign", "lineBreak", "lineCap", "lineDashOffset", "lineHeight", "lineJoin", "lineNumber", "lineTo", "lineWidth", "linearAcceleration", "linearRampToValueAtTime", "linearVelocity", "lineno", "lines", "link", "linkColor", "linkProgram", "links", "list", "list-style", "list-style-image", "list-style-position", "list-style-type", "listStyle", "listStyleImage", "listStylePosition", "listStyleType", "listener", "load", "loadEventEnd", "loadEventStart", "loadTime", "loadTimes", "loaded", "loading", "localDescription", "localName", "localService", "localStorage", "locale", "localeCompare", "location", "locationbar", "lock", "locked", "lockedFile", "locks", "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", "makeXRCompatible", "manifest", "manufacturer", "manufacturerName", "map", "mapping", "margin", "margin-block", "margin-block-end", "margin-block-start", "margin-bottom", "margin-inline", "margin-inline-end", "margin-inline-start", "margin-left", "margin-right", "margin-top", "marginBlock", "marginBlockEnd", "marginBlockStart", "marginBottom", "marginHeight", "marginInline", "marginInlineEnd", "marginInlineStart", "marginLeft", "marginRight", "marginTop", "marginWidth", "mark", "marker", "marker-end", "marker-mid", "marker-offset", "marker-start", "markerEnd", "markerHeight", "markerMid", "markerOffset", "markerStart", "markerUnits", "markerWidth", "marks", "mask", "mask-clip", "mask-composite", "mask-image", "mask-mode", "mask-origin", "mask-position", "mask-position-x", "mask-position-y", "mask-repeat", "mask-size", "mask-type", "maskClip", "maskComposite", "maskContentUnits", "maskImage", "maskMode", "maskOrigin", "maskPosition", "maskPositionX", "maskPositionY", "maskRepeat", "maskSize", "maskType", "maskUnits", "match", "matchAll", "matchMedia", "matchMedium", "matches", "matrix", "matrixTransform", "max", "max-block-size", "max-height", "max-inline-size", "max-width", "maxActions", "maxAlternatives", "maxBlockSize", "maxChannelCount", "maxChannels", "maxConnectionsPerServer", "maxDecibels", "maxDistance", "maxHeight", "maxInlineSize", "maxLayers", "maxLength", "maxMessageSize", "maxPacketLifeTime", "maxRetransmits", "maxTouchPoints", "maxValue", "maxWidth", "measure", "measureText", "media", "mediaCapabilities", "mediaDevices", "mediaElement", "mediaGroup", "mediaKeys", "mediaSession", "mediaStream", "mediaText", "meetOrSlice", "memory", "menubar", "mergeAttributes", "message", "messageClass", "messageHandlers", "messageType", "metaKey", "metadata", "method", "methodDetails", "methodName", "mid", "mimeType", "mimeTypes", "min", "min-block-size", "min-height", "min-inline-size", "min-width", "minBlockSize", "minDecibels", "minHeight", "minInlineSize", "minLength", "minValue", "minWidth", "miterLimit", "mix-blend-mode", "mixBlendMode", "mm", "mobile", "mode", "model", "modify", "mount", "move", "moveBy", "moveEnd", "moveFirst", "moveFocusDown", "moveFocusLeft", "moveFocusRight", "moveFocusUp", "moveNext", "moveRow", "moveStart", "moveTo", "moveToBookmark", "moveToElementText", "moveToPoint", "movementX", "movementY", "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", "ms", "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", "mul", "multiEntry", "multiSelectionObj", "multiline", "multiple", "multiply", "multiplySelf", "mutableFile", "muted", "n", "name", "nameProp", "namedItem", "namedRecordset", "names", "namespaceURI", "namespaces", "naturalHeight", "naturalWidth", "navigate", "navigation", "navigationMode", "navigationPreload", "navigationStart", "navigator", "near", "nearestViewportElement", "negative", "negotiated", "netscape", "networkState", "newScale", "newTranslate", "newURL", "newValue", "newValueSpecifiedUnits", "newVersion", "newhome", "next", "nextElementSibling", "nextHopProtocol", "nextNode", "nextPage", "nextSibling", "nickname", "noHref", "noModule", "noResize", "noShade", "noValidate", "noWrap", "node", "nodeName", "nodeType", "nodeValue", "nonce", "normalize", "normalizedPathSegList", "notationName", "notations", "note", "noteGrainOn", "noteOff", "noteOn", "notify", "now", "numOctaves", "number", "numberOfChannels", "numberOfInputs", "numberOfItems", "numberOfOutputs", "numberValue", "oMatchesSelector", "object", "object-fit", "object-position", "objectFit", "objectPosition", "objectStore", "objectStoreNames", "objectType", "observe", "of", "offscreenBuffering", "offset", "offset-anchor", "offset-distance", "offset-path", "offset-rotate", "offsetAnchor", "offsetDistance", "offsetHeight", "offsetLeft", "offsetNode", "offsetParent", "offsetPath", "offsetRotate", "offsetTop", "offsetWidth", "offsetX", "offsetY", "ok", "oldURL", "oldValue", "oldVersion", "olderShadowRoot", "onLine", "onabort", "onabsolutedeviceorientation", "onactivate", "onactive", "onaddsourcebuffer", "onaddstream", "onaddtrack", "onafterprint", "onafterscriptexecute", "onafterupdate", "onanimationcancel", "onanimationend", "onanimationiteration", "onanimationstart", "onappinstalled", "onaudioend", "onaudioprocess", "onaudiostart", "onautocomplete", "onautocompleteerror", "onauxclick", "onbeforeactivate", "onbeforecopy", "onbeforecut", "onbeforedeactivate", "onbeforeeditfocus", "onbeforeinstallprompt", "onbeforepaste", "onbeforeprint", "onbeforescriptexecute", "onbeforeunload", "onbeforeupdate", "onbeforexrselect", "onbegin", "onblocked", "onblur", "onbounce", "onboundary", "onbufferedamountlow", "oncached", "oncancel", "oncandidatewindowhide", "oncandidatewindowshow", "oncandidatewindowupdate", "oncanplay", "oncanplaythrough", "once", "oncellchange", "onchange", "oncharacteristicvaluechanged", "onchargingchange", "onchargingtimechange", "onchecking", "onclick", "onclose", "onclosing", "oncompassneedscalibration", "oncomplete", "onconnect", "onconnecting", "onconnectionavailable", "onconnectionstatechange", "oncontextmenu", "oncontrollerchange", "oncontrolselect", "oncopy", "oncuechange", "oncut", "ondataavailable", "ondatachannel", "ondatasetchanged", "ondatasetcomplete", "ondblclick", "ondeactivate", "ondevicechange", "ondevicelight", "ondevicemotion", "ondeviceorientation", "ondeviceorientationabsolute", "ondeviceproximity", "ondischargingtimechange", "ondisconnect", "ondisplay", "ondownloading", "ondrag", "ondragend", "ondragenter", "ondragexit", "ondragleave", "ondragover", "ondragstart", "ondrop", "ondurationchange", "onemptied", "onencrypted", "onend", "onended", "onenter", "onenterpictureinpicture", "onerror", "onerrorupdate", "onexit", "onfilterchange", "onfinish", "onfocus", "onfocusin", "onfocusout", "onformdata", "onfreeze", "onfullscreenchange", "onfullscreenerror", "ongatheringstatechange", "ongattserverdisconnected", "ongesturechange", "ongestureend", "ongesturestart", "ongotpointercapture", "onhashchange", "onhelp", "onicecandidate", "onicecandidateerror", "oniceconnectionstatechange", "onicegatheringstatechange", "oninactive", "oninput", "oninputsourceschange", "oninvalid", "onkeydown", "onkeypress", "onkeystatuseschange", "onkeyup", "onlanguagechange", "onlayoutcomplete", "onleavepictureinpicture", "onlevelchange", "onload", "onloadeddata", "onloadedmetadata", "onloadend", "onloading", "onloadingdone", "onloadingerror", "onloadstart", "onlosecapture", "onlostpointercapture", "only", "onmark", "onmessage", "onmessageerror", "onmidimessage", "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", "onmute", "onnegotiationneeded", "onnomatch", "onnoupdate", "onobsolete", "onoffline", "ononline", "onopen", "onorientationchange", "onpagechange", "onpagehide", "onpageshow", "onpaste", "onpause", "onpayerdetailchange", "onpaymentmethodchange", "onplay", "onplaying", "onpluginstreamstart", "onpointercancel", "onpointerdown", "onpointerenter", "onpointerleave", "onpointerlockchange", "onpointerlockerror", "onpointermove", "onpointerout", "onpointerover", "onpointerrawupdate", "onpointerup", "onpopstate", "onprocessorerror", "onprogress", "onpropertychange", "onratechange", "onreading", "onreadystatechange", "onrejectionhandled", "onrelease", "onremove", "onremovesourcebuffer", "onremovestream", "onremovetrack", "onrepeat", "onreset", "onresize", "onresizeend", "onresizestart", "onresourcetimingbufferfull", "onresult", "onresume", "onrowenter", "onrowexit", "onrowsdelete", "onrowsinserted", "onscroll", "onsearch", "onsecuritypolicyviolation", "onseeked", "onseeking", "onselect", "onselectedcandidatepairchange", "onselectend", "onselectionchange", "onselectstart", "onshippingaddresschange", "onshippingoptionchange", "onshow", "onsignalingstatechange", "onsoundend", "onsoundstart", "onsourceclose", "onsourceclosed", "onsourceended", "onsourceopen", "onspeechend", "onspeechstart", "onsqueeze", "onsqueezeend", "onsqueezestart", "onstalled", "onstart", "onstatechange", "onstop", "onstorage", "onstoragecommit", "onsubmit", "onsuccess", "onsuspend", "onterminate", "ontextinput", "ontimeout", "ontimeupdate", "ontoggle", "ontonechange", "ontouchcancel", "ontouchend", "ontouchmove", "ontouchstart", "ontrack", "ontransitioncancel", "ontransitionend", "ontransitionrun", "ontransitionstart", "onunhandledrejection", "onunload", "onunmute", "onupdate", "onupdateend", "onupdatefound", "onupdateready", "onupdatestart", "onupgradeneeded", "onuserproximity", "onversionchange", "onvisibilitychange", "onvoiceschanged", "onvolumechange", "onvrdisplayactivate", "onvrdisplayconnect", "onvrdisplaydeactivate", "onvrdisplaydisconnect", "onvrdisplaypresentchange", "onwaiting", "onwaitingforkey", "onwarning", "onwebkitanimationend", "onwebkitanimationiteration", "onwebkitanimationstart", "onwebkitcurrentplaybacktargetiswirelesschanged", "onwebkitfullscreenchange", "onwebkitfullscreenerror", "onwebkitkeyadded", "onwebkitkeyerror", "onwebkitkeymessage", "onwebkitneedkey", "onwebkitorientationchange", "onwebkitplaybacktargetavailabilitychanged", "onwebkitpointerlockchange", "onwebkitpointerlockerror", "onwebkitresourcetimingbufferfull", "onwebkittransitionend", "onwheel", "onzoom", "opacity", "open", "openCursor", "openDatabase", "openKeyCursor", "opened", "opener", "opera", "operationType", "operator", "opr", "optimum", "options", "or", "order", "orderX", "orderY", "ordered", "org", "organization", "orient", "orientAngle", "orientType", "orientation", "orientationX", "orientationY", "orientationZ", "origin", "originalPolicy", "originalTarget", "orphans", "oscpu", "outerHTML", "outerHeight", "outerText", "outerWidth", "outline", "outline-color", "outline-offset", "outline-style", "outline-width", "outlineColor", "outlineOffset", "outlineStyle", "outlineWidth", "outputBuffer", "outputChannelCount", "outputLatency", "outputs", "overflow", "overflow-anchor", "overflow-block", "overflow-inline", "overflow-wrap", "overflow-x", "overflow-y", "overflowAnchor", "overflowBlock", "overflowInline", "overflowWrap", "overflowX", "overflowY", "overrideMimeType", "oversample", "overscroll-behavior", "overscroll-behavior-block", "overscroll-behavior-inline", "overscroll-behavior-x", "overscroll-behavior-y", "overscrollBehavior", "overscrollBehaviorBlock", "overscrollBehaviorInline", "overscrollBehaviorX", "overscrollBehaviorY", "ownKeys", "ownerDocument", "ownerElement", "ownerNode", "ownerRule", "ownerSVGElement", "owningElement", "p1", "p2", "p3", "p4", "packetSize", "packets", "pad", "padEnd", "padStart", "padding", "padding-block", "padding-block-end", "padding-block-start", "padding-bottom", "padding-inline", "padding-inline-end", "padding-inline-start", "padding-left", "padding-right", "padding-top", "paddingBlock", "paddingBlockEnd", "paddingBlockStart", "paddingBottom", "paddingInline", "paddingInlineEnd", "paddingInlineStart", "paddingLeft", "paddingRight", "paddingTop", "page", "page-break-after", "page-break-before", "page-break-inside", "pageBreakAfter", "pageBreakBefore", "pageBreakInside", "pageCount", "pageLeft", "pageTop", "pageX", "pageXOffset", "pageY", "pageYOffset", "pages", "paint-order", "paintOrder", "paintRequests", "paintType", "paintWorklet", "palette", "pan", "panningModel", "parameterData", "parameters", "parent", "parentElement", "parentNode", "parentRule", "parentStyleSheet", "parentTextEdit", "parentWindow", "parse", "parseAll", "parseFloat", "parseFromString", "parseInt", "part", "participants", "passive", "password", "pasteHTML", "path", "pathLength", "pathSegList", "pathSegType", "pathSegTypeAsLetter", "pathname", "pattern", "patternContentUnits", "patternMismatch", "patternTransform", "patternUnits", "pause", "pauseAnimations", "pauseOnExit", "pauseProfilers", "pauseTransformFeedback", "paused", "payerEmail", "payerName", "payerPhone", "paymentManager", "pc", "peerIdentity", "pending", "pendingLocalDescription", "pendingRemoteDescription", "percent", "performance", "periodicSync", "permission", "permissionState", "permissions", "persist", "persisted", "personalbar", "perspective", "perspective-origin", "perspectiveOrigin", "phone", "phoneticFamilyName", "phoneticGivenName", "photo", "pictureInPictureElement", "pictureInPictureEnabled", "pictureInPictureWindow", "ping", "pipeThrough", "pipeTo", "pitch", "pixelBottom", "pixelDepth", "pixelHeight", "pixelLeft", "pixelRight", "pixelStorei", "pixelTop", "pixelUnitToMillimeterX", "pixelUnitToMillimeterY", "pixelWidth", "place-content", "place-items", "place-self", "placeContent", "placeItems", "placeSelf", "placeholder", "platformVersion", "platform", "platforms", "play", "playEffect", "playState", "playbackRate", "playbackState", "playbackTime", "played", "playoutDelayHint", "playsInline", "plugins", "pluginspage", "pname", "pointer-events", "pointerBeforeReferenceNode", "pointerEnabled", "pointerEvents", "pointerId", "pointerLockElement", "pointerType", "points", "pointsAtX", "pointsAtY", "pointsAtZ", "polygonOffset", "pop", "populateMatrix", "popupWindowFeatures", "popupWindowName", "popupWindowURI", "port", "port1", "port2", "ports", "posBottom", "posHeight", "posLeft", "posRight", "posTop", "posWidth", "pose", "position", "positionAlign", "positionX", "positionY", "positionZ", "postError", "postMessage", "postalCode", "poster", "pow", "powerEfficient", "powerOff", "preMultiplySelf", "precision", "preferredStyleSheetSet", "preferredStylesheetSet", "prefix", "preload", "prepend", "presentation", "preserveAlpha", "preserveAspectRatio", "preserveAspectRatioString", "pressed", "pressure", "prevValue", "preventDefault", "preventExtensions", "preventSilentAccess", "previousElementSibling", "previousNode", "previousPage", "previousRect", "previousScale", "previousSibling", "previousTranslate", "primaryKey", "primitiveType", "primitiveUnits", "principals", "print", "priority", "privateKey", "probablySupportsContext", "process", "processIceMessage", "processingEnd", "processingStart", "processorOptions", "product", "productId", "productName", "productSub", "profile", "profileEnd", "profiles", "projectionMatrix", "promise", "prompt", "properties", "propertyIsEnumerable", "propertyName", "protocol", "protocolLong", "prototype", "provider", "pseudoClass", "pseudoElement", "pt", "publicId", "publicKey", "published", "pulse", "push", "pushManager", "pushNotification", "pushState", "put", "putImageData", "px", "quadraticCurveTo", "qualifier", "quaternion", "query", "queryCommandEnabled", "queryCommandIndeterm", "queryCommandState", "queryCommandSupported", "queryCommandText", "queryCommandValue", "querySelector", "querySelectorAll", "queueMicrotask", "quote", "quotes", "r", "r1", "r2", "race", "rad", "radiogroup", "radiusX", "radiusY", "random", "range", "rangeCount", "rangeMax", "rangeMin", "rangeOffset", "rangeOverflow", "rangeParent", "rangeUnderflow", "rate", "ratio", "raw", "rawId", "read", "readAsArrayBuffer", "readAsBinaryString", "readAsBlob", "readAsDataURL", "readAsText", "readBuffer", "readEntries", "readOnly", "readPixels", "readReportRequested", "readText", "readValue", "readable", "ready", "readyState", "reason", "reboot", "receivedAlert", "receiver", "receivers", "recipient", "reconnect", "recordNumber", "recordsAvailable", "recordset", "rect", "red", "redEyeReduction", "redirect", "redirectCount", "redirectEnd", "redirectStart", "redirected", "reduce", "reduceRight", "reduction", "refDistance", "refX", "refY", "referenceNode", "referenceSpace", "referrer", "referrerPolicy", "refresh", "region", "regionAnchorX", "regionAnchorY", "regionId", "regions", "register", "registerContentHandler", "registerElement", "registerProperty", "registerProtocolHandler", "reject", "rel", "relList", "relatedAddress", "relatedNode", "relatedPort", "relatedTarget", "release", "releaseCapture", "releaseEvents", "releaseInterface", "releaseLock", "releasePointerCapture", "releaseShaderCompiler", "reliable", "reliableWrite", "reload", "rem", "remainingSpace", "remote", "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", "removed", "removedNodes", "renderHeight", "renderState", "renderTime", "renderWidth", "renderbufferStorage", "renderbufferStorageMultisample", "renderedBuffer", "renderingMode", "renotify", "repeat", "replace", "replaceAdjacentText", "replaceAll", "replaceChild", "replaceChildren", "replaceData", "replaceId", "replaceItem", "replaceNode", "replaceState", "replaceSync", "replaceTrack", "replaceWholeText", "replaceWith", "reportValidity", "request", "requestAnimationFrame", "requestAutocomplete", "requestData", "requestDevice", "requestFrame", "requestFullscreen", "requestHitTestSource", "requestHitTestSourceForTransientInput", "requestId", "requestIdleCallback", "requestMIDIAccess", "requestMediaKeySystemAccess", "requestPermission", "requestPictureInPicture", "requestPointerLock", "requestPresent", "requestReferenceSpace", "requestSession", "requestStart", "requestStorageAccess", "requestSubmit", "requestVideoFrameCallback", "requestingWindow", "requireInteraction", "required", "requiredExtensions", "requiredFeatures", "reset", "resetPose", "resetTransform", "resize", "resizeBy", "resizeTo", "resolve", "response", "responseBody", "responseEnd", "responseReady", "responseStart", "responseText", "responseType", "responseURL", "responseXML", "restartIce", "restore", "result", "resultIndex", "resultType", "results", "resume", "resumeProfilers", "resumeTransformFeedback", "retry", "returnValue", "rev", "reverse", "reversed", "revocable", "revokeObjectURL", "rgbColor", "right", "rightContext", "rightDegrees", "rightMargin", "rightProjectionMatrix", "rightViewMatrix", "role", "rolloffFactor", "root", "rootBounds", "rootElement", "rootMargin", "rotate", "rotateAxisAngle", "rotateAxisAngleSelf", "rotateFromVector", "rotateFromVectorSelf", "rotateSelf", "rotation", "rotationAngle", "rotationRate", "round", "row-gap", "rowGap", "rowIndex", "rowSpan", "rows", "rtcpTransport", "rtt", "ruby-align", "ruby-position", "rubyAlign", "rubyOverhang", "rubyPosition", "rules", "runtime", "runtimeStyle", "rx", "ry", "s", "safari", "sample", "sampleCoverage", "sampleRate", "samplerParameterf", "samplerParameteri", "sandbox", "save", "saveData", "scale", "scale3d", "scale3dSelf", "scaleNonUniform", "scaleNonUniformSelf", "scaleSelf", "scheme", "scissor", "scope", "scopeName", "scoped", "screen", "screenBrightness", "screenEnabled", "screenLeft", "screenPixelToMillimeterX", "screenPixelToMillimeterY", "screenTop", "screenX", "screenY", "scriptURL", "scripts", "scroll", "scroll-behavior", "scroll-margin", "scroll-margin-block", "scroll-margin-block-end", "scroll-margin-block-start", "scroll-margin-bottom", "scroll-margin-inline", "scroll-margin-inline-end", "scroll-margin-inline-start", "scroll-margin-left", "scroll-margin-right", "scroll-margin-top", "scroll-padding", "scroll-padding-block", "scroll-padding-block-end", "scroll-padding-block-start", "scroll-padding-bottom", "scroll-padding-inline", "scroll-padding-inline-end", "scroll-padding-inline-start", "scroll-padding-left", "scroll-padding-right", "scroll-padding-top", "scroll-snap-align", "scroll-snap-type", "scrollAmount", "scrollBehavior", "scrollBy", "scrollByLines", "scrollByPages", "scrollDelay", "scrollHeight", "scrollIntoView", "scrollIntoViewIfNeeded", "scrollLeft", "scrollLeftMax", "scrollMargin", "scrollMarginBlock", "scrollMarginBlockEnd", "scrollMarginBlockStart", "scrollMarginBottom", "scrollMarginInline", "scrollMarginInlineEnd", "scrollMarginInlineStart", "scrollMarginLeft", "scrollMarginRight", "scrollMarginTop", "scrollMaxX", "scrollMaxY", "scrollPadding", "scrollPaddingBlock", "scrollPaddingBlockEnd", "scrollPaddingBlockStart", "scrollPaddingBottom", "scrollPaddingInline", "scrollPaddingInlineEnd", "scrollPaddingInlineStart", "scrollPaddingLeft", "scrollPaddingRight", "scrollPaddingTop", "scrollRestoration", "scrollSnapAlign", "scrollSnapType", "scrollTo", "scrollTop", "scrollTopMax", "scrollWidth", "scrollX", "scrollY", "scrollbar-color", "scrollbar-width", "scrollbar3dLightColor", "scrollbarArrowColor", "scrollbarBaseColor", "scrollbarColor", "scrollbarDarkShadowColor", "scrollbarFaceColor", "scrollbarHighlightColor", "scrollbarShadowColor", "scrollbarTrackColor", "scrollbarWidth", "scrollbars", "scrolling", "scrollingElement", "sctp", "sctpCauseCode", "sdp", "sdpLineNumber", "sdpMLineIndex", "sdpMid", "seal", "search", "searchBox", "searchBoxJavaBridge_", "searchParams", "sectionRowIndex", "secureConnectionStart", "security", "seed", "seekToNextFrame", "seekable", "seeking", "select", "selectAllChildren", "selectAlternateInterface", "selectConfiguration", "selectNode", "selectNodeContents", "selectNodes", "selectSingleNode", "selectSubString", "selected", "selectedIndex", "selectedOptions", "selectedStyleSheetSet", "selectedStylesheetSet", "selection", "selectionDirection", "selectionEnd", "selectionStart", "selector", "selectorText", "self", "send", "sendAsBinary", "sendBeacon", "sender", "sentAlert", "sentTimestamp", "separator", "serialNumber", "serializeToString", "serverTiming", "service", "serviceWorker", "session", "sessionId", "sessionStorage", "set", "setActionHandler", "setActive", "setAlpha", "setAppBadge", "setAttribute", "setAttributeNS", "setAttributeNode", "setAttributeNodeNS", "setBaseAndExtent", "setBigInt64", "setBigUint64", "setBingCurrentSearchDefault", "setCapture", "setCodecPreferences", "setColor", "setCompositeOperation", "setConfiguration", "setCurrentTime", "setCustomValidity", "setData", "setDate", "setDragImage", "setEnd", "setEndAfter", "setEndBefore", "setEndPoint", "setFillColor", "setFilterRes", "setFloat32", "setFloat64", "setFloatValue", "setFormValue", "setFullYear", "setHeaderValue", "setHours", "setIdentityProvider", "setImmediate", "setInt16", "setInt32", "setInt8", "setInterval", "setItem", "setKeyframes", "setLineCap", "setLineDash", "setLineJoin", "setLineWidth", "setLiveSeekableRange", "setLocalDescription", "setMatrix", "setMatrixValue", "setMediaKeys", "setMilliseconds", "setMinutes", "setMiterLimit", "setMonth", "setNamedItem", "setNamedItemNS", "setNonUserCodeExceptions", "setOrientToAngle", "setOrientToAuto", "setOrientation", "setOverrideHistoryNavigationMode", "setPaint", "setParameter", "setParameters", "setPeriodicWave", "setPointerCapture", "setPosition", "setPositionState", "setPreference", "setProperty", "setPrototypeOf", "setRGBColor", "setRGBColorICCColor", "setRadius", "setRangeText", "setRemoteDescription", "setRequestHeader", "setResizable", "setResourceTimingBufferSize", "setRotate", "setScale", "setSeconds", "setSelectionRange", "setServerCertificate", "setShadow", "setSinkId", "setSkewX", "setSkewY", "setStart", "setStartAfter", "setStartBefore", "setStdDeviation", "setStreams", "setStringValue", "setStrokeColor", "setSuggestResult", "setTargetAtTime", "setTargetValueAtTime", "setTime", "setTimeout", "setTransform", "setTranslate", "setUTCDate", "setUTCFullYear", "setUTCHours", "setUTCMilliseconds", "setUTCMinutes", "setUTCMonth", "setUTCSeconds", "setUint16", "setUint32", "setUint8", "setUri", "setValidity", "setValueAtTime", "setValueCurveAtTime", "setVariable", "setVelocity", "setVersion", "setYear", "settingName", "settingValue", "sex", "shaderSource", "shadowBlur", "shadowColor", "shadowOffsetX", "shadowOffsetY", "shadowRoot", "shape", "shape-image-threshold", "shape-margin", "shape-outside", "shape-rendering", "shapeImageThreshold", "shapeMargin", "shapeOutside", "shapeRendering", "sheet", "shift", "shiftKey", "shiftLeft", "shippingAddress", "shippingOption", "shippingType", "show", "showHelp", "showModal", "showModalDialog", "showModelessDialog", "showNotification", "sidebar", "sign", "signal", "signalingState", "signature", "silent", "sin", "singleNodeValue", "sinh", "sinkId", "sittingToStandingTransform", "size", "sizeToContent", "sizeX", "sizeZ", "sizes", "skewX", "skewXSelf", "skewY", "skewYSelf", "slice", "slope", "slot", "small", "smil", "smooth", "smoothingTimeConstant", "snapToLines", "snapshotItem", "snapshotLength", "some", "sort", "sortingCode", "source", "sourceBuffer", "sourceBuffers", "sourceCapabilities", "sourceFile", "sourceIndex", "sources", "spacing", "span", "speak", "speakAs", "speaking", "species", "specified", "specularConstant", "specularExponent", "speechSynthesis", "speed", "speedOfSound", "spellcheck", "splice", "split", "splitText", "spreadMethod", "sqrt", "src", "srcElement", "srcFilter", "srcObject", "srcUrn", "srcdoc", "srclang", "srcset", "stack", "stackTraceLimit", "stacktrace", "stageParameters", "standalone", "standby", "start", "startContainer", "startIce", "startMessages", "startNotifications", "startOffset", "startProfiling", "startRendering", "startShark", "startTime", "startsWith", "state", "status", "statusCode", "statusMessage", "statusText", "statusbar", "stdDeviationX", "stdDeviationY", "stencilFunc", "stencilFuncSeparate", "stencilMask", "stencilMaskSeparate", "stencilOp", "stencilOpSeparate", "step", "stepDown", "stepMismatch", "stepUp", "sticky", "stitchTiles", "stop", "stop-color", "stop-opacity", "stopColor", "stopImmediatePropagation", "stopNotifications", "stopOpacity", "stopProfiling", "stopPropagation", "stopShark", "stopped", "storage", "storageArea", "storageName", "storageStatus", "store", "storeSiteSpecificTrackingException", "storeWebWideTrackingException", "stpVersion", "stream", "streams", "stretch", "strike", "string", "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", "styleMap", "styleMedia", "styleSheet", "styleSheetSets", "styleSheets", "sub", "subarray", "subject", "submit", "submitFrame", "submitter", "subscribe", "substr", "substring", "substringData", "subtle", "subtree", "suffix", "suffixes", "summary", "sup", "supported", "supportedContentEncodings", "supportedEntryTypes", "supports", "supportsSession", "surfaceScale", "surroundContents", "suspend", "suspendRedraw", "swapCache", "swapNode", "sweepFlag", "symbols", "sync", "sysexEnabled", "system", "systemCode", "systemId", "systemLanguage", "systemXDPI", "systemYDPI", "tBodies", "tFoot", "tHead", "tabIndex", "table", "table-layout", "tableLayout", "tableValues", "tag", "tagName", "tagUrn", "tags", "taintEnabled", "takePhoto", "takeRecords", "tan", "tangentialPressure", "tanh", "target", "targetElement", "targetRayMode", "targetRaySpace", "targetTouches", "targetX", "targetY", "tcpType", "tee", "tel", "terminate", "test", "texImage2D", "texImage3D", "texParameterf", "texParameteri", "texStorage2D", "texStorage3D", "texSubImage2D", "texSubImage3D", "text", "text-align", "text-align-last", "text-anchor", "text-combine-upright", "text-decoration", "text-decoration-color", "text-decoration-line", "text-decoration-skip-ink", "text-decoration-style", "text-decoration-thickness", "text-emphasis", "text-emphasis-color", "text-emphasis-position", "text-emphasis-style", "text-indent", "text-justify", "text-orientation", "text-overflow", "text-rendering", "text-shadow", "text-transform", "text-underline-offset", "text-underline-position", "textAlign", "textAlignLast", "textAnchor", "textAutospace", "textBaseline", "textCombineUpright", "textContent", "textDecoration", "textDecorationBlink", "textDecorationColor", "textDecorationLine", "textDecorationLineThrough", "textDecorationNone", "textDecorationOverline", "textDecorationSkipInk", "textDecorationStyle", "textDecorationThickness", "textDecorationUnderline", "textEmphasis", "textEmphasisColor", "textEmphasisPosition", "textEmphasisStyle", "textIndent", "textJustify", "textJustifyTrim", "textKashida", "textKashidaSpace", "textLength", "textOrientation", "textOverflow", "textRendering", "textShadow", "textTracks", "textTransform", "textUnderlineOffset", "textUnderlinePosition", "then", "threadId", "threshold", "thresholds", "tiltX", "tiltY", "time", "timeEnd", "timeLog", "timeOrigin", "timeRemaining", "timeStamp", "timecode", "timeline", "timelineTime", "timeout", "timestamp", "timestampOffset", "timing", "title", "to", "toArray", "toBlob", "toDataURL", "toDateString", "toElement", "toExponential", "toFixed", "toFloat32Array", "toFloat64Array", "toGMTString", "toISOString", "toJSON", "toLocaleDateString", "toLocaleFormat", "toLocaleLowerCase", "toLocaleString", "toLocaleTimeString", "toLocaleUpperCase", "toLowerCase", "toMatrix", "toMethod", "toPrecision", "toPrimitive", "toSdp", "toSource", "toStaticHTML", "toString", "toStringTag", "toSum", "toTimeString", "toUTCString", "toUpperCase", "toggle", "toggleAttribute", "toggleLongPressEnabled", "tone", "toneBuffer", "tooLong", "tooShort", "toolbar", "top", "topMargin", "total", "totalFrameDelay", "totalVideoFrames", "touch-action", "touchAction", "touched", "touches", "trace", "track", "trackVisibility", "transaction", "transactions", "transceiver", "transferControlToOffscreen", "transferFromImageBitmap", "transferImageBitmap", "transferIn", "transferOut", "transferSize", "transferToImageBitmap", "transform", "transform-box", "transform-origin", "transform-style", "transformBox", "transformFeedbackVaryings", "transformOrigin", "transformPoint", "transformString", "transformStyle", "transformToDocument", "transformToFragment", "transition", "transition-delay", "transition-duration", "transition-property", "transition-timing-function", "transitionDelay", "transitionDuration", "transitionProperty", "transitionTimingFunction", "translate", "translateSelf", "translationX", "translationY", "transport", "trim", "trimEnd", "trimLeft", "trimRight", "trimStart", "trueSpeed", "trunc", "truncate", "trustedTypes", "turn", "twist", "type", "typeDetail", "typeMismatch", "typeMustMatch", "types", "u2f", "ubound", "uint16", "uint32", "uint8", "uint8Clamped", "undefined", "unescape", "uneval", "unicode", "unicode-bidi", "unicodeBidi", "unicodeRange", "uniform1f", "uniform1fv", "uniform1i", "uniform1iv", "uniform1ui", "uniform1uiv", "uniform2f", "uniform2fv", "uniform2i", "uniform2iv", "uniform2ui", "uniform2uiv", "uniform3f", "uniform3fv", "uniform3i", "uniform3iv", "uniform3ui", "uniform3uiv", "uniform4f", "uniform4fv", "uniform4i", "uniform4iv", "uniform4ui", "uniform4uiv", "uniformBlockBinding", "uniformMatrix2fv", "uniformMatrix2x3fv", "uniformMatrix2x4fv", "uniformMatrix3fv", "uniformMatrix3x2fv", "uniformMatrix3x4fv", "uniformMatrix4fv", "uniformMatrix4x2fv", "uniformMatrix4x3fv", "unique", "uniqueID", "uniqueNumber", "unit", "unitType", "units", "unloadEventEnd", "unloadEventStart", "unlock", "unmount", "unobserve", "unpause", "unpauseAnimations", "unreadCount", "unregister", "unregisterContentHandler", "unregisterProtocolHandler", "unscopables", "unselectable", "unshift", "unsubscribe", "unsuspendRedraw", "unsuspendRedrawAll", "unwatch", "unwrapKey", "upDegrees", "upX", "upY", "upZ", "update", "updateCommands", "updateIce", "updateInterval", "updatePlaybackRate", "updateRenderState", "updateSettings", "updateTiming", "updateViaCache", "updateWith", "updated", "updating", "upgrade", "upload", "uploadTotal", "uploaded", "upper", "upperBound", "upperOpen", "uri", "url", "urn", "urns", "usages", "usb", "usbVersionMajor", "usbVersionMinor", "usbVersionSubminor", "useCurrentView", "useMap", "useProgram", "usedSpace", "user-select", "userActivation", "userAgent", "userAgentData", "userChoice", "userHandle", "userHint", "userLanguage", "userSelect", "userVisibleOnly", "username", "usernameFragment", "utterance", "uuid", "v8BreakIterator", "vAlign", "vLink", "valid", "validate", "validateProgram", "validationMessage", "validity", "value", "valueAsDate", "valueAsNumber", "valueAsString", "valueInSpecifiedUnits", "valueMissing", "valueOf", "valueText", "valueType", "values", "variable", "variant", "variationSettings", "vector-effect", "vectorEffect", "velocityAngular", "velocityExpansion", "velocityX", "velocityY", "vendor", "vendorId", "vendorSub", "verify", "version", "vertexAttrib1f", "vertexAttrib1fv", "vertexAttrib2f", "vertexAttrib2fv", "vertexAttrib3f", "vertexAttrib3fv", "vertexAttrib4f", "vertexAttrib4fv", "vertexAttribDivisor", "vertexAttribDivisorANGLE", "vertexAttribI4i", "vertexAttribI4iv", "vertexAttribI4ui", "vertexAttribI4uiv", "vertexAttribIPointer", "vertexAttribPointer", "vertical", "vertical-align", "verticalAlign", "verticalOverflow", "vh", "vibrate", "vibrationActuator", "videoBitsPerSecond", "videoHeight", "videoTracks", "videoWidth", "view", "viewBox", "viewBoxString", "viewTarget", "viewTargetString", "viewport", "viewportAnchorX", "viewportAnchorY", "viewportElement", "views", "violatedDirective", "visibility", "visibilityState", "visible", "visualViewport", "vlinkColor", "vmax", "vmin", "voice", "voiceURI", "volume", "vrml", "vspace", "vw", "w", "wait", "waitSync", "waiting", "wake", "wakeLock", "wand", "warn", "wasClean", "wasDiscarded", "watch", "watchAvailability", "watchPosition", "webdriver", "webkitAddKey", "webkitAlignContent", "webkitAlignItems", "webkitAlignSelf", "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", "webkitBorderBottomLeftRadius", "webkitBorderBottomRightRadius", "webkitBorderImage", "webkitBorderImageOutset", "webkitBorderImageRepeat", "webkitBorderImageSlice", "webkitBorderImageSource", "webkitBorderImageWidth", "webkitBorderRadius", "webkitBorderTopLeftRadius", "webkitBorderTopRightRadius", "webkitBoxAlign", "webkitBoxDirection", "webkitBoxFlex", "webkitBoxOrdinalGroup", "webkitBoxOrient", "webkitBoxPack", "webkitBoxShadow", "webkitBoxSizing", "webkitCancelAnimationFrame", "webkitCancelFullScreen", "webkitCancelKeyRequest", "webkitCancelRequestAnimationFrame", "webkitClearResourceTimings", "webkitClosedCaptionsVisible", "webkitConvertPointFromNodeToPage", "webkitConvertPointFromPageToNode", "webkitCreateShadowRoot", "webkitCurrentFullScreenElement", "webkitCurrentPlaybackTargetIsWireless", "webkitDecodedFrameCount", "webkitDirectionInvertedFromDevice", "webkitDisplayingFullscreen", "webkitDroppedFrameCount", "webkitEnterFullScreen", "webkitEnterFullscreen", "webkitEntries", "webkitExitFullScreen", "webkitExitFullscreen", "webkitExitPointerLock", "webkitFilter", "webkitFlex", "webkitFlexBasis", "webkitFlexDirection", "webkitFlexFlow", "webkitFlexGrow", "webkitFlexShrink", "webkitFlexWrap", "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", "webkitJustifyContent", "webkitKeys", "webkitLineClamp", "webkitLineDashOffset", "webkitLockOrientation", "webkitMask", "webkitMaskClip", "webkitMaskComposite", "webkitMaskImage", "webkitMaskOrigin", "webkitMaskPosition", "webkitMaskPositionX", "webkitMaskPositionY", "webkitMaskRepeat", "webkitMaskSize", "webkitMatchesSelector", "webkitMediaStream", "webkitNotifications", "webkitOfflineAudioContext", "webkitOrder", "webkitOrientation", "webkitPeerConnection00", "webkitPersistentStorage", "webkitPerspective", "webkitPerspectiveOrigin", "webkitPointerLockElement", "webkitPostMessage", "webkitPreservesPitch", "webkitPutImageDataHD", "webkitRTCPeerConnection", "webkitRegionOverset", "webkitRelativePath", "webkitRequestAnimationFrame", "webkitRequestFileSystem", "webkitRequestFullScreen", "webkitRequestFullscreen", "webkitRequestPointerLock", "webkitResolveLocalFileSystemURL", "webkitSetMediaKeys", "webkitSetResourceTimingBufferSize", "webkitShadowRoot", "webkitShowPlaybackTargetPicker", "webkitSlice", "webkitSpeechGrammar", "webkitSpeechGrammarList", "webkitSpeechRecognition", "webkitSpeechRecognitionError", "webkitSpeechRecognitionEvent", "webkitStorageInfo", "webkitSupportsFullscreen", "webkitTemporaryStorage", "webkitTextFillColor", "webkitTextSizeAdjust", "webkitTextStroke", "webkitTextStrokeColor", "webkitTextStrokeWidth", "webkitTransform", "webkitTransformOrigin", "webkitTransformStyle", "webkitTransition", "webkitTransitionDelay", "webkitTransitionDuration", "webkitTransitionProperty", "webkitTransitionTimingFunction", "webkitURL", "webkitUnlockOrientation", "webkitUserSelect", "webkitVideoDecodedByteCount", "webkitVisibilityState", "webkitWirelessVideoPlaybackDisabled", "webkitdirectory", "webkitdropzone", "webstore", "weight", "whatToShow", "wheelDelta", "wheelDeltaX", "wheelDeltaY", "whenDefined", "which", "white-space", "whiteSpace", "wholeText", "widows", "width", "will-change", "willChange", "willValidate", "window", "withCredentials", "word-break", "word-spacing", "word-wrap", "wordBreak", "wordSpacing", "wordWrap", "workerStart", "wow64", "wrap", "wrapKey", "writable", "writableAuxiliaries", "write", "writeText", "writeValue", "writeWithoutResponse", "writeln", "writing-mode", "writingMode", "x", "x1", "x2", "xChannelSelector", "xmlEncoding", "xmlStandalone", "xmlVersion", "xmlbase", "xmllang", "xmlspace", "xor", "xr", "y", "y1", "y2", "yChannelSelector", "yandex", "z", "z-index", "zIndex", "zoom", "zoomAndPan", "zoomRectScreen", ]; terser-5.19.2/tools/exit.cjs000066400000000000000000000003711445647217600157470ustar00rootroot00000000000000// workaround for tty output truncation upon process.exit() // https://github.com/nodejs/node/issues/6456 [process.stdout, process.stderr].forEach((s) => { s && s.isTTY && s._handle && s._handle.setBlocking && s._handle.setBlocking(true) }); terser-5.19.2/tools/props.html000066400000000000000000000027001445647217600163240ustar00rootroot00000000000000 terser-5.19.2/tools/terser.d.ts000066400000000000000000000137771445647217600164110ustar00rootroot00000000000000/// import { SectionedSourceMapInput, EncodedSourceMap, DecodedSourceMap } from '@jridgewell/source-map'; export type ECMA = 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020; export interface ParseOptions { bare_returns?: boolean; /** @deprecated legacy option. Currently, all supported EcmaScript is valid to parse. */ ecma?: ECMA; html5_comments?: boolean; shebang?: boolean; } export interface CompressOptions { arguments?: boolean; arrows?: boolean; booleans_as_integers?: 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; ie8?: 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_arrows?: boolean; unsafe?: boolean; unsafe_comps?: boolean; unsafe_Function?: boolean; unsafe_math?: boolean; unsafe_symbols?: boolean; unsafe_methods?: boolean; unsafe_proto?: boolean; unsafe_regexp?: boolean; unsafe_undefined?: boolean; unused?: 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; nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler; properties?: boolean | ManglePropertiesOptions; reserved?: string[]; safari10?: boolean; toplevel?: boolean; } /** * An identifier mangler for which the output is invariant with respect to the source code. */ export interface SimpleIdentifierMangler { /** * Obtains the nth most favored (usually shortest) identifier to rename a variable to. * The mangler will increment n and retry until the return value is not in use in scope, and is not a reserved word. * This function is expected to be stable; Evaluating get(n) === get(n) should always return true. * @param n The ordinal of the identifier. */ get(n: number): string; } /** * An identifier mangler that leverages character frequency analysis to determine identifier precedence. */ export interface WeightedIdentifierMangler extends SimpleIdentifierMangler { /** * Modifies the internal weighting of the input characters by the specified delta. * Will be invoked on the entire printed AST, and then deduct mangleable identifiers. * @param chars The characters to modify the weighting of. * @param delta The numeric weight to add to the characters. */ consider(chars: string, delta: number): number; /** * Resets character weights. */ reset(): void; /** * Sorts identifiers by character frequency, in preparation for calls to get(n). */ sort(): void; } export interface ManglePropertiesOptions { builtins?: boolean; debug?: boolean; keep_quoted?: boolean | 'strict'; nth_identifier?: SimpleIdentifierMangler | WeightedIdentifierMangler; regex?: RegExp | string; reserved?: string[]; } export interface FormatOptions { ascii_only?: boolean; /** @deprecated Not implemented anymore */ beautify?: boolean; braces?: boolean; comments?: boolean | 'all' | 'some' | RegExp | ( (node: any, comment: { value: string, type: 'comment1' | 'comment2' | 'comment3' | 'comment4', pos: number, line: number, col: number, }) => boolean ); ecma?: ECMA; ie8?: boolean; keep_numbers?: boolean; indent_level?: number; indent_start?: number; inline_script?: boolean; keep_quoted_props?: boolean; max_line_len?: number | false; preamble?: string; preserve_annotations?: boolean; quote_keys?: boolean; quote_style?: OutputQuoteStyle; safari10?: boolean; semicolons?: boolean; shebang?: boolean; shorthand?: boolean; source_map?: SourceMapOptions; webkit?: boolean; width?: number; wrap_iife?: boolean; wrap_func_args?: boolean; } export enum OutputQuoteStyle { PreferDouble = 0, AlwaysSingle = 1, AlwaysDouble = 2, AlwaysOriginal = 3 } export interface MinifyOptions { compress?: boolean | CompressOptions; ecma?: ECMA; enclose?: boolean | string; ie8?: boolean; keep_classnames?: boolean | RegExp; keep_fnames?: boolean | RegExp; mangle?: boolean | MangleOptions; module?: boolean; nameCache?: object; format?: FormatOptions; /** @deprecated */ output?: FormatOptions; parse?: ParseOptions; safari10?: boolean; sourceMap?: boolean | SourceMapOptions; toplevel?: boolean; } export interface MinifyOutput { code?: string; map?: EncodedSourceMap | string; decoded_map?: DecodedSourceMap | null; } export interface SourceMapOptions { /** Source map object, 'inline' or source map file content */ content?: SectionedSourceMapInput | string; includeSources?: boolean; filename?: string; root?: string; asObject?: boolean; url?: string | 'inline'; } export function minify(files: string | string[] | { [file: string]: string }, options?: MinifyOptions): Promise;