Skip to content

Commit

Permalink
Fix unsafe_comps test
Browse files Browse the repository at this point in the history
  • Loading branch information
lautis committed Mar 11, 2018
1 parent 70e0906 commit 72aa83c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions spec/uglifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -511,21 +511,23 @@
describe 'unsafe_comps' do
let(:code) do
<<-JS
var obj1 = {
valueOf: function() {triggeredFirst();}
}
var obj2 = 2;
var result1 = obj1 <= obj2;
var obj1, obj2;
obj1 <= obj2 ? f1() : g1();
JS
end

let(:options) do
{ :comparisons => true, :reduce_vars => false, :collapse_vars => false }
{
:comparisons => true,
:conditionals => true,
:reduce_vars => false,
:collapse_vars => false
}
end

it 'keeps unsafe comparisons by default' do
compiled = Uglifier.compile(code, :mangle => false, :compress => options)
expect(compiled).to include("result1=obj1<=obj2")
expect(compiled).to include("obj1<=obj2")
end

it 'optimises unsafe comparisons when unsafe_comps is enabled' do
Expand All @@ -534,7 +536,7 @@
:mangle => false,
:compress => options.merge(:unsafe_comps => true)
)
expect(compiled).to include("result1=obj2>=obj1")
expect(compiled).to include("obj2<obj1")
end
end

Expand Down

0 comments on commit 72aa83c

Please sign in to comment.