Skip to content

Commit

Permalink
Merge branch 'master' into feature/codeql
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-ivanov committed Dec 6, 2023
2 parents 517ce79 + 75137cd commit b4e021c
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v5.25.0
- Regex properties added to reserved property mangler (#1471)
- `pure_new` option added to drop unused `new` expressions.

## v5.24.0
- Improve formatting performance in V8 by keeping a small work string and a large output string

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,9 @@ If you happen to need the source map as a raw object, set `sourceMap.asObject` t
Specify `"strict"` to treat `foo.bar` as side-effect-free only when
`foo` is certain to not throw, i.e. not `null` or `undefined`.

- `pure_new` (default: `false`) -- Set to `true` to assume `new X()` never has
side effects.

- `reduce_vars` (default: `true`) -- Improve optimization on variables assigned with and
used as constant values.

Expand Down
1 change: 1 addition & 0 deletions lib/compress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ class Compressor extends TreeWalker {
properties : !false_by_default,
pure_getters : !false_by_default && "strict",
pure_funcs : null,
pure_new : false,
reduce_funcs : !false_by_default,
reduce_vars : !false_by_default,
sequences : !false_by_default,
Expand Down
3 changes: 3 additions & 0 deletions lib/compress/inference.js
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,9 @@ AST_Call.DEFMETHOD("is_callee_pure", function(compressor) {
return true;
}
}
if ((this instanceof AST_New) && compressor.option("pure_new")) {
return true;
}
return !!has_annotation(this, _PURE) || !compressor.pure_funcs(this);
});

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"homepage": "https://terser.org",
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
"license": "BSD-2-Clause",
"version": "5.24.0",
"version": "5.25.0",
"engines": {
"node": ">=10"
},
Expand Down
19 changes: 19 additions & 0 deletions test/compress/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,22 @@ dot_parenthesis_2: {
expect_exact: "console.log(typeof new function(){Math.random()}.constructor);"
expect_stdout: "function"
}

new_pure: {
options = {
pure_new: true,
defaults: true,
}
input: {
new function() {};
(new function() {
this.pass = () => console.log("PASS");
}).pass();
}
expect: {
(new function() {
this.pass = () => console.log("PASS");
}).pass();
}
expect_stdout: "PASS"
}
1 change: 1 addition & 0 deletions tools/terser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface CompressOptions {
passes?: number;
properties?: boolean;
pure_funcs?: string[];
pure_new?: boolean;
pure_getters?: boolean | 'strict';
reduce_funcs?: boolean;
reduce_vars?: boolean;
Expand Down

0 comments on commit b4e021c

Please sign in to comment.