-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A function call or IIFE with an immediately preceding comment containing `@__PURE__` or `#__PURE__` is deemed to be a side-effect-free pure function call and can potentially be dropped. Depends on `side_effects` option. `[#@]__PURE__` hint will be removed from comment when pure call is dropped. fixes #1261 closes #1448
- Loading branch information
Showing
3 changed files
with
151 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
pure_function_calls: { | ||
options = { | ||
evaluate : true, | ||
conditionals : true, | ||
comparisons : true, | ||
side_effects : true, | ||
booleans : true, | ||
unused : true, | ||
if_return : true, | ||
join_vars : true, | ||
cascade : true, | ||
negate_iife : true, | ||
} | ||
input: { | ||
// pure top-level IIFE will be dropped | ||
// @__PURE__ - comment | ||
(function() { | ||
console.log("iife0"); | ||
})(); | ||
|
||
// pure top-level IIFE assigned to unreferenced var will not be dropped | ||
var iife1 = /*@__PURE__*/(function() { | ||
console.log("iife1"); | ||
function iife1() {} | ||
return iife1; | ||
})(); | ||
|
||
(function(){ | ||
// pure IIFE in function scope assigned to unreferenced var will be dropped | ||
var iife2 = /*#__PURE__*/(function() { | ||
console.log("iife2"); | ||
function iife2() {} | ||
return iife2; | ||
})(); | ||
})(); | ||
|
||
// comment #__PURE__ comment | ||
bar(), baz(), quux(); | ||
a.b(), /* @__PURE__ */ c.d.e(), f.g(); | ||
} | ||
expect: { | ||
var iife1 = function() { | ||
console.log("iife1"); | ||
function iife1() {} | ||
return iife1; | ||
}(); | ||
|
||
baz(), quux(); | ||
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]", | ||
] | ||
} | ||
|
||
pure_function_calls_toplevel: { | ||
options = { | ||
evaluate : true, | ||
conditionals : true, | ||
comparisons : true, | ||
side_effects : true, | ||
booleans : true, | ||
unused : true, | ||
if_return : true, | ||
join_vars : true, | ||
cascade : true, | ||
negate_iife : true, | ||
toplevel : true, | ||
} | ||
input: { | ||
// pure top-level IIFE will be dropped | ||
// @__PURE__ - comment | ||
(function() { | ||
console.log("iife0"); | ||
})(); | ||
|
||
// pure top-level IIFE assigned to unreferenced var will be dropped | ||
var iife1 = /*@__PURE__*/(function() { | ||
console.log("iife1"); | ||
function iife1() {} | ||
return iife1; | ||
})(); | ||
|
||
(function(){ | ||
// pure IIFE in function scope assigned to unreferenced var will be dropped | ||
var iife2 = /*#__PURE__*/(function() { | ||
console.log("iife2"); | ||
function iife2() {} | ||
return iife2; | ||
})(); | ||
})(); | ||
|
||
// comment #__PURE__ comment | ||
bar(), baz(), quux(); | ||
a.b(), /* @__PURE__ */ c.d.e(), f.g(); | ||
} | ||
expect: { | ||
baz(), quux(); | ||
a.b(), f.g(); | ||
} | ||
expect_warnings: [ | ||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:79,8]", | ||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:79,8]", | ||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:92,37]", | ||
"WARN: Dropping unused variable iife2 [test/compress/issue-1261.js:92,16]", | ||
"WARN: Dropping side-effect-free statement [test/compress/issue-1261.js:90,8]", | ||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:100,8]", | ||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:101,31]", | ||
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:84,33]", | ||
"WARN: Dropping unused variable iife1 [test/compress/issue-1261.js:84,12]", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters