remove [#@]__PURE__ hint from comment when pure call dropped
This commit is contained in:
parent
58036cd0cc
commit
d35b92cff6
|
|
@ -1273,21 +1273,26 @@ merge(Compressor.prototype, {
|
||||||
def(AST_Constant, return_false);
|
def(AST_Constant, return_false);
|
||||||
def(AST_This, return_false);
|
def(AST_This, return_false);
|
||||||
|
|
||||||
var pure_regex = /[@#]__PURE__/;
|
var pure_regex = /[@#]__PURE__/g;
|
||||||
function has_pure_annotation(node) {
|
function has_pure_annotation(node) {
|
||||||
if (node.pure !== undefined) return node.pure;
|
if (node.pure !== undefined) return node.pure;
|
||||||
var pure = false;
|
var pure = false;
|
||||||
|
var comments, last_comment;
|
||||||
if (node.start
|
if (node.start
|
||||||
&& node.start.comments_before
|
&& (comments = node.start.comments_before)
|
||||||
&& node.start.comments_before.length
|
&& comments.length
|
||||||
&& pure_regex.test(node.start.comments_before[node.start.comments_before.length - 1].value)) {
|
&& pure_regex.test((last_comment = comments[comments.length - 1]).value)) {
|
||||||
|
last_comment.value = last_comment.value.replace(pure_regex, ' ');
|
||||||
pure = true;
|
pure = true;
|
||||||
}
|
}
|
||||||
return node.pure = pure;
|
return node.pure = pure;
|
||||||
}
|
}
|
||||||
|
|
||||||
def(AST_Call, function(compressor){
|
def(AST_Call, function(compressor){
|
||||||
if (has_pure_annotation(this)) return false;
|
if (has_pure_annotation(this)) {
|
||||||
|
compressor.warn("Dropping __PURE__ call [{file}:{line},{col}]", this.start);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
var pure = compressor.option("pure_funcs");
|
var pure = compressor.option("pure_funcs");
|
||||||
if (!pure) return true;
|
if (!pure) return true;
|
||||||
if (typeof pure == "function") return pure(this);
|
if (typeof pure == "function") return pure(this);
|
||||||
|
|
|
||||||
|
|
@ -48,4 +48,13 @@ pure_function_calls: {
|
||||||
baz(), quux();
|
baz(), quux();
|
||||||
a.b(), f.g();
|
a.b(), f.g();
|
||||||
}
|
}
|
||||||
|
expect_warnings: [
|
||||||
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:17,8]",
|
||||||
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:17,8]",
|
||||||
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:30,37]",
|
||||||
|
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:30,16]",
|
||||||
|
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:28,8]",
|
||||||
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:38,8]",
|
||||||
|
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:39,31]"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -95,4 +95,19 @@ describe("minify", function() {
|
||||||
assert.strictEqual(code, "var a=function(n){return n};");
|
assert.strictEqual(code, "var a=function(n){return n};");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#__PURE__", function() {
|
||||||
|
it("should drop #__PURE__ hint after use", function() {
|
||||||
|
var result = Uglify.minify('//@__PURE__ comment1 #__PURE__ comment2\n foo(), bar();', {
|
||||||
|
fromString: true,
|
||||||
|
output: {
|
||||||
|
comments: "all",
|
||||||
|
beautify: false,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var code = result.code;
|
||||||
|
assert.strictEqual(code, "// comment1 comment2\nbar();");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user