fix comments output & improve /*@__PURE__*/
- fix whitespace around comments - fix comment parsing around parentheses - consider parentheses when parsing `/*@__PURE__*/` - remove all `/*@__PURE__*/` on output fixes #2638
This commit is contained in:
@@ -2292,29 +2292,13 @@ merge(Compressor.prototype, {
|
||||
});
|
||||
});
|
||||
|
||||
AST_Call.DEFMETHOD("has_pure_annotation", function(compressor) {
|
||||
if (!compressor.option("side_effects")) return false;
|
||||
if (this.pure !== undefined) return this.pure;
|
||||
var pure = false;
|
||||
var comments, pure_comment;
|
||||
if (this.start
|
||||
&& (comments = this.start.comments_before)
|
||||
&& comments.length
|
||||
&& (pure_comment = find_if(function (comment) {
|
||||
return /[@#]__PURE__/.test(comment.value);
|
||||
}, comments))) {
|
||||
pure = pure_comment;
|
||||
}
|
||||
return this.pure = 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_expr_pure", function(compressor) {
|
||||
if (compressor.option("unsafe")) {
|
||||
var expr = this.expression;
|
||||
if (is_undeclared_ref(expr) && global_pure_fns(expr.name)) return true;
|
||||
}
|
||||
return this.has_pure_annotation(compressor) || !compressor.pure_funcs(this);
|
||||
return this.pure || !compressor.pure_funcs(this);
|
||||
});
|
||||
|
||||
// determine if expression has side effects
|
||||
@@ -3164,7 +3148,6 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
if (this.pure) {
|
||||
compressor.warn("Dropping __PURE__ call [{file}:{line},{col}]", this.start);
|
||||
this.pure.value = this.pure.value.replace(/[@#]__PURE__/g, ' ');
|
||||
}
|
||||
var args = trim(this.args, compressor, first_in_statement);
|
||||
return args && make_sequence(this, args);
|
||||
@@ -3961,7 +3944,7 @@ merge(Compressor.prototype, {
|
||||
&& (def = exp.definition()).references.length == 1
|
||||
&& !recursive_ref(compressor, def)
|
||||
&& fn.is_constant_expression(exp.scope))
|
||||
&& !self.has_pure_annotation(compressor)
|
||||
&& !self.pure
|
||||
&& !fn.contains_this()
|
||||
&& (scope = can_flatten_args(fn))
|
||||
&& (value = flatten_body(stat))) {
|
||||
|
||||
Reference in New Issue
Block a user