Testing all leading comments against being PURE comments (#2305)

This commit is contained in:
Mateusz Burzyński
2017-09-09 20:08:15 +02:00
committed by Alex Lam S.L
parent aacf3edc68
commit 8158b1bdcf
2 changed files with 40 additions and 29 deletions

View File

@@ -1980,12 +1980,14 @@ merge(Compressor.prototype, {
if (!compressor.option("side_effects")) return false;
if (this.pure !== undefined) return this.pure;
var pure = false;
var comments, last_comment;
var comments, pure_comment;
if (this.start
&& (comments = this.start.comments_before)
&& comments.length
&& /[@#]__PURE__/.test((last_comment = comments[comments.length - 1]).value)) {
pure = last_comment;
&& (pure_comment = find_if(function (comment) {
return /[@#]__PURE__/.test(comment.value);
}, comments))) {
pure = pure_comment;
}
return this.pure = pure;
});