aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-04-24 18:29:42 +0100
committerGitHub <noreply@github.com>2020-04-25 01:29:42 +0800
commit3a4497a1c3db3a2069d6a5a0d1d8a8295c3ef568 (patch)
tree0aa1f1dc0a75ef5c6c9c1d84b0718288b2e86c0f /lib/compress.js
parent3ee13cae02174e565ca40462d7b15c4974265871 (diff)
downloadtracifyjs-3a4497a1c3db3a2069d6a5a0d1d8a8295c3ef568.tar.gz
tracifyjs-3a4497a1c3db3a2069d6a5a0d1d8a8295c3ef568.zip
fix corner case in `typeofs` (#3818)
fixes #3817
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js33
1 files changed, 24 insertions, 9 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 9420d8d2..3d1b17f3 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -5194,16 +5194,17 @@ merge(Compressor.prototype, {
return if_break_in_loop(self, compressor);
});
- function mark_locally_defined(condition, consequent, alternative, operator) {
+ function mark_locally_defined(condition, consequent, alternative) {
if (!(condition instanceof AST_Binary)) return;
if (!(condition.left instanceof AST_String)) {
- if (!operator) operator = condition.operator;
- if (condition.operator != operator) return;
- switch (operator) {
+ switch (condition.operator) {
case "&&":
+ mark_locally_defined(condition.left, consequent);
+ mark_locally_defined(condition.right, consequent);
+ break;
case "||":
- mark_locally_defined(condition.left, consequent, alternative, operator);
- mark_locally_defined(condition.right, consequent, alternative, operator);
+ mark_locally_defined(negate(condition.left), alternative);
+ mark_locally_defined(negate(condition.right), alternative);
break;
}
return;
@@ -5235,6 +5236,20 @@ merge(Compressor.prototype, {
if (node instanceof AST_SymbolRef && node.definition() === def) node.defined = true;
});
body.walk(tw);
+
+ function negate(node) {
+ if (!(node instanceof AST_Binary)) return;
+ switch (node.operator) {
+ case "==":
+ node = node.clone();
+ node.operator = "!=";
+ return node;
+ case "!=":
+ node = node.clone();
+ node.operator = "==";
+ return node;
+ }
+ }
}
OPT(AST_If, function(self, compressor) {
@@ -6623,7 +6638,7 @@ merge(Compressor.prototype, {
(self.left.is_number(compressor) && self.right.is_number(compressor)) ||
(self.left.is_boolean(compressor) && self.right.is_boolean(compressor)) ||
self.left.equivalent_to(self.right)) {
- self.operator = self.operator.substr(0, 2);
+ self.operator = self.operator.slice(0, 2);
}
// XXX: intentionally falling down to the next case
case "==":
@@ -7102,10 +7117,10 @@ merge(Compressor.prototype, {
}
if (compressor.option("typeofs")) switch (self.operator) {
case "&&":
- mark_locally_defined(self.left, self.right, null, "&&");
+ mark_locally_defined(self.left, self.right, null);
break;
case "||":
- mark_locally_defined(self.left, null, self.right, "||");
+ mark_locally_defined(self.left, null, self.right);
break;
}
if (compressor.option("unsafe")) {
ass='msg-avail'>...* gnu/packages/linphone.scm (lime): New variable. Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Raghav Gururajan 2021-03-29gnu: belle-sip: Enable mDNS support....* gnu/packages/linphone.scm (belle-sip)[configure-flags]: Enable mDNS support. [phases]{patch}: Force the detection of avahi. [inputs]: Add avahi. Raghav Gururajan 2021-03-29gnu: belle-sip: Enable tests....* gnu/packages/linphone.scm (belle-sip)[outputs]: New "tester" output. [tests?]: Remove argument, enabling tests. [phases]{check}: Override phase. {separate-outputs}: New phase. [inputs]: Remove antlr3, anttlr3c and java. Modified-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Raghav Gururajan 2021-03-29gnu: belle-sip: Update to 4.4.34....* gnu/packages/linphone.scm (belle-sip)[source]: Switch to git repository. [version]: Update to 4.4.34. [home-page]: Update. [license]: Update to GPLv3+. Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Raghav Gururajan 2021-03-29gnu: mediastreamer2: Enable PCAP, port-audio and G729B support....* gnu/packages/linphone.scm (mediastreamer2) [configure-flags]: Add the ENABLE_PCAP, ENABLE_PORTAUDIO and ENABLE_G729B_CNG flags. [phases]{patch-source}: New phase. Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Raghav Gururajan 2021-03-29gnu: mediastreamer2: Enable tests....* gnu/packages/linphone.scm (mediastreamer2) [arguments]: Remove tests? argument, enabling tests. [phases]{pre-check}: New phase. {check}: Replace with custom phase. [native-inputs]: Add xorg-server-for-tests. Modified-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Raghav Gururajan 2021-03-29gnu: mediastreamer2: Update to 4.4.34....* gnu/packages/linphone.scm (mediastreamer2)[source]: Switch to git repository. [version]: Update to 4.4.34. [patches]: Remove field. [configure-flags]: Remove the ENABLE_STRICT, ENABLE_BV16, CMAKE_C_FLAGS and CMAKE_CXX_FLAGS flags. [phases]{fix-version}: New phase. {separate-outputs}: Modify. [native-inputs]: Replace python with python-wrapper. [home-page]: Update. [license]: Upgrade to GPLv3+. * gnu/packages/patches/mediastreamer2-srtp2.patch: Remove file. * gnu/local.mk (dist_patch_DATA): Remove it. Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Raghav Gururajan 2021-03-29gnu: ortp: Update to 4.4.34....* gnu/packages/linphone.scm (ortp)[source]: Switch to git repository. [version]: Update to 4.4.34. [outputs]{doc, tester}: New outputs. [configure-flag]: Enable tests. [phases]{fix-version-strings, separate-outputs}: New phases. [home-page]: Update. [license]: Upgrade to GPLv3+. Co-authored-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Raghav Gururajan 2021-03-29gnu: bzrtp: Update to 4.4.34 and enable tests....* gnu/packages/linphone.scm (bzrtp)[source]: Switch to git repository. [version]: Update to 4.4.34. [configure-flags]: Enable tests. [license]: Upgrade to GPLv3+. Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Raghav Gururajan 2021-03-29gnu: belcard: Update to 4.4.34 and enable tests....* gnu/packages/linphone.scm (belcard)[source]: Switch to git repository. [version]: Update to 4.4.34. [outputs]: Add the tester and debug outputs. [arguments]: Enable tests. [phases]{patch-vcard-grammar-location, install-tester, check}: New phases. Co-authored-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Raghav Gururajan 2021-03-29gnu: belr: Update to 4.4.34 and enable tests....* gnu/packages/linphone.scm (belr)[source]: Switch to git repository. [version]: Update to 4.4.34. [arguments]: Remove the tests? argument to enable tests. [phases]{move-tester, check}: New phases. Modified-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Raghav Gururajan 2021-03-29gnu: bctoolbox: Update to 4.4.34 and enable libdecaf, tests....* gnu/packages/linphone.scm (bctoolbox)[version]: Update to 4.4.34. [source]: Switch to git repository. [outputs]: Add a debug output. [arguments]: Remove tests? argument, enabling tests. [phases]{patch-cmake, skip-problematic-tests} {fix-installed-resource-directory-detection}: New phases. {check}: Override phase. [inputs]: Add libdecaf. [license]: Update to GPLv3+. Co-authored-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Raghav Gururajan 2021-03-26gnu: bcmatroska2: Fetch the sources from git....* gnu/packages/linphone.scm (bcmatroska2)[source]: Fetch sources from git. [description]: Expound description. [license]: Add the gpl2+ license to the list. Remove broken URLs. Raghav Gururajan 2021-03-26gnu: bcg729: Enable tests and update home page, license....* gnu/packages/linphone.scm (bcg729)[source]: Remove '.git' suffix from URL. [tests?]: Remove argument. [configure-flags]: Enable tests. [phases]{copy-inputs}: New phase. {check}: Override. [native-inputs]: Add perl, test-patterns and unzip. [home-page]: Update. [license]: Upgrade to GPLv3+. Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Raghav Gururajan 2021-03-24gnu: bcunit: Update to 3.0.2-0.74021cc and enable more features....* gnu/packages/linphone.scm (bcunit)[source]: Switch to git repository. [version]: Update to 3.0.2-0.74021cc. [outputs]: Add a "doc" output. [arguments]: Remove the tests? argument, enabling tests. [configure-flags]: Enable curses, doc, examples, tests and memtrace. [phases]{patch-source, move-doc}: New phases. {check}: Override phase. [inputs]: Add ncurses. [description]: Fix typo. Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Raghav Gururajan