- `pure_getters` -- the default is `false`. If you pass `true` for
this, UglifyJS 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`.
- `pure_funcs` -- default `null`. You can pass an array of names and
UglifyJS will assume that those functions do not produce side
negate_iife : !false_by_default,
passes : 1,
properties : !false_by_default,
- pure_getters : false,
+ pure_getters : !false_by_default && "strict",
pure_funcs : null,
reduce_vars : !false_by_default,
screw_ie8 : true,
// may_eq_null()
// returns true if this node may evaluate to null or undefined
(function(def) {
- def(AST_Node, return_true);
+ function is_strict(compressor) {
+ return /strict/.test(compressor.option("pure_getters"));
+ }
+
+ def(AST_Node, function(compressor) {
+ return !is_strict(compressor);
+ });
def(AST_Null, return_true);
def(AST_Undefined, return_true);
def(AST_Constant, return_false);
def(AST_Seq, function(compressor) {
return this.cdr.may_eq_null(compressor);
});
- def(AST_PropAccess, function(compressor) {
- return !compressor.option("unsafe");
- });
def(AST_SymbolRef, function(compressor) {
if (this.is_undefined) return true;
- if (compressor.option("unsafe")) return false;
+ if (!is_strict(compressor)) return false;
var fixed = this.fixed_value();
return !fixed || fixed.may_eq_null(compressor);
});
-side_effects: {
+strict: {
options = {
- pure_getters: true,
+ pure_getters: "strict",
reduce_vars: false,
side_effects: true,
toplevel: true,
- unsafe: false,
}
input: {
var a, b = null, c = {};
}
}
-side_effects_reduce_vars: {
+strict_reduce_vars: {
options = {
- pure_getters: true,
+ pure_getters: "strict",
reduce_vars: true,
side_effects: true,
toplevel: true,
- unsafe: false,
}
input: {
var a, b = null, c = {};
}
}
-side_effects_unsafe: {
+unsafe: {
options = {
pure_getters: true,
reduce_vars: false,
side_effects: true,
toplevel: true,
- unsafe: 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_vars: true,
+ side_effects: true,
+ toplevel: true,
}
input: {
var a, b = null, c = {};