From c40117b54e62737513126c16715911b0c7eb8b71 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 29 Mar 2018 13:21:05 +0200 Subject: [PATCH 1/2] Supress the warning when comparing `..` with a literal --- lib/ast.js | 2 +- src/ast.ls | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ast.js b/lib/ast.js index 38b267fc8..1929a7a79 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -2278,7 +2278,7 @@ exports.Binary = Binary = (function(superclass){ })) { return this.compileRegexEquals(o, that); } - if (this.op === '===' && (this.first instanceof Literal && this.second instanceof Literal) && this.first.isWhat() !== this.second.isWhat()) { + if (this.op === '===' && (this.first instanceof Literal && this.second instanceof Literal) && this.first.isWhat() !== this.second.isWhat() && ('..' !== this.first.value && '..' !== this.second.value)) { if (!o.noWarn) { this.warn("strict comparison of two different types will always be false: " + this.first.value + " == " + this.second.value); } diff --git a/src/ast.ls b/src/ast.ls index 829a6d1a0..a00281a82 100644 --- a/src/ast.ls +++ b/src/ast.ls @@ -1407,6 +1407,7 @@ class exports.Binary extends Node return @compileRegexEquals o, that if @op is \=== and (@first instanceof Literal and @second instanceof Literal) and @first.is-what! isnt @second.is-what! + and \.. not in [@first.value, @second.value] @warn "strict comparison of two different types will always be false: #{@first.value} == #{@second.value}" unless o.no-warn return @compileChain o if COMPARER.test @op and COMPARER.test @second.op @first <<< {@front} From 246a70b5844bcd640865e0f92d7b0affc36a3f49 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 29 Mar 2018 18:05:50 +0200 Subject: [PATCH 2/2] Test for #1037 --- test/compilation.ls | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/compilation.ls b/test/compilation.ls index 0ff9a97db..4218926c2 100644 --- a/test/compilation.ls +++ b/test/compilation.ls @@ -372,3 +372,15 @@ LiveScript.compile ''' d .e (.f in [2 3]) ''' + + +# testing warnings: start +old-warn = console.warn +console.warn = -> fail "Expected no warnings. Got: #it" + +# [LiveScript#1037](https://github.com/gkz/LiveScript/pull/1037) +# This code should produce no compilation warnings +LiveScript.compile '1 => .. == 1; 1 == ..' + +# testing warnings: end +console.warn = old-warn