aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/compress.js4
-rw-r--r--test/compress.js2
-rw-r--r--test/compress/const.js20
-rw-r--r--test/compress/let.js23
4 files changed, 47 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 647c97e1..d8f689c3 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -7598,7 +7598,9 @@ merge(Compressor.prototype, {
// typeof always returns a non-empty string, thus it's
// always true in booleans
AST_Node.warn("Boolean expression always true [{file}:{line},{col}]", self.start);
- return (exp instanceof AST_SymbolRef ? make_node(AST_True, self) : make_sequence(self, [
+ return (exp instanceof AST_SymbolRef && all(exp.definition().orig, function(sym) {
+ return !(sym instanceof AST_SymbolConst || sym instanceof AST_SymbolLet);
+ }) ? make_node(AST_True, self) : make_sequence(self, [
exp,
make_node(AST_True, self)
])).optimize(compressor);
diff --git a/test/compress.js b/test/compress.js
index 77b09f0d..3d9b1a63 100644
--- a/test/compress.js
+++ b/test/compress.js
@@ -386,7 +386,7 @@ function test_case(test) {
mangle: test.mangle
});
var actual = stdout[toplevel ? 1 : 0];
- if (test.expect_stdout === true) {
+ if (test.expect_stdout === true || test.expect_stdout instanceof Error && test.expect_stdout.name === actual.name) {
test.expect_stdout = actual;
}
if (!sandbox.same_stdout(test.expect_stdout, actual)) {
diff --git a/test/compress/const.js b/test/compress/const.js
index 694c9d16..2f88975e 100644
--- a/test/compress/const.js
+++ b/test/compress/const.js
@@ -1084,3 +1084,23 @@ issue_4231: {
}
expect_stdout: "function"
}
+
+issue_4245: {
+ options = {
+ booleans: true,
+ }
+ input: {
+ const a = f();
+ function f() {
+ typeof a;
+ }
+ }
+ expect: {
+ const a = f();
+ function f() {
+ a,
+ 1;
+ }
+ }
+ expect_stdout: true
+}
diff --git a/test/compress/let.js b/test/compress/let.js
index 8374db9a..deb48120 100644
--- a/test/compress/let.js
+++ b/test/compress/let.js
@@ -893,3 +893,26 @@ issue_4231: {
expect_stdout: "function"
node_version: ">=4"
}
+
+issue_4245: {
+ options = {
+ booleans: true,
+ }
+ input: {
+ "use strict";
+ let a = f();
+ function f() {
+ typeof a;
+ }
+ }
+ expect: {
+ "use strict";
+ let a = f();
+ function f() {
+ a,
+ 1;
+ }
+ }
+ expect_stdout: ReferenceError("a is not defined")
+ node_version: ">=4"
+}