[Pkg-javascript-commits] [uglifyjs] 345/491: drop property assignment to constants (#2612)
Jonas Smedegaard
dr at jones.dk
Wed Feb 14 19:51:51 UTC 2018
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.
commit 0b0eac1d5dc6e1cc1e9bf3682871cafdda59066d
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Mon Dec 18 12:07:53 2017 +0800
drop property assignment to constants (#2612)
---
lib/compress.js | 15 +++++++++++++--
test/compress/properties.js | 40 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+), 2 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index 52c3096..735b4d2 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1708,6 +1708,11 @@ merge(Compressor.prototype, {
return this.consequent._dot_throw(compressor)
|| this.alternative._dot_throw(compressor);
})
+ def(AST_Dot, function(compressor) {
+ if (!is_strict(compressor)) return false;
+ if (this.expression instanceof AST_Function && this.property == "prototype") return false;
+ return true;
+ });
def(AST_Sequence, function(compressor) {
return this.tail_node()._dot_throw(compressor);
});
@@ -3184,8 +3189,14 @@ merge(Compressor.prototype, {
}
});
def(AST_Assign, function(compressor){
- this.write_only = !this.left.has_side_effects(compressor);
- return this;
+ var left = this.left;
+ if (left.has_side_effects(compressor)) return this;
+ this.write_only = true;
+ while (left instanceof AST_PropAccess) {
+ left = left.expression;
+ }
+ if (left instanceof AST_Symbol) return this;
+ return this.right.drop_side_effect_free(compressor);
});
def(AST_Conditional, function(compressor){
var consequent = this.consequent.drop_side_effect_free(compressor);
diff --git a/test/compress/properties.js b/test/compress/properties.js
index 6d4c028..16374ef 100644
--- a/test/compress/properties.js
+++ b/test/compress/properties.js
@@ -1054,3 +1054,43 @@ issue_2513: {
"undefined undefined",
]
}
+
+const_prop_assign_strict: {
+ options = {
+ pure_getters: "strict",
+ side_effects: true,
+ }
+ input: {
+ function Simulator() {
+ /abc/.index = 1;
+ this._aircraft = [];
+ }
+ (function() {}).prototype.destroy = x();
+ }
+ expect: {
+ function Simulator() {
+ this._aircraft = [];
+ }
+ x();
+ }
+}
+
+const_prop_assign_pure: {
+ options = {
+ pure_getters: true,
+ side_effects: true,
+ }
+ input: {
+ function Simulator() {
+ /abc/.index = 1;
+ this._aircraft = [];
+ }
+ (function() {}).prototype.destroy = x();
+ }
+ expect: {
+ function Simulator() {
+ this._aircraft = [];
+ }
+ x();
+ }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list