opal 0.9.0 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1220,7 +1220,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1220
1220
  exc = val[1] || s(:array)
1221
1221
  exc << new_assign(val[2], val[2], s(:gvar, '$!'.intern)) if val[2]
1222
1222
  result = [s(:resbody, exc, val[4])]
1223
- result.push val[5].first if val[5]
1223
+ result.concat val[5] if val[5]
1224
1224
  }
1225
1225
  | # none
1226
1226
  {
@@ -1,10 +1,4 @@
1
- require 'rack/file'
2
- require 'rack/static'
3
- require 'rack/urlmap'
4
- require 'rack/builder'
5
- require 'rack/deflater'
6
- require 'rack/directory'
7
- require 'rack/showexceptions'
1
+ require 'rack'
8
2
  require 'opal/source_map'
9
3
  require 'sprockets'
10
4
  require 'sourcemap'
@@ -79,8 +73,6 @@ module Opal
79
73
  use Index, server if server.use_index
80
74
  if source_map_enabled
81
75
  map(maps_prefix) do
82
- require 'rack/conditionalget'
83
- require 'rack/etag'
84
76
  use Rack::ConditionalGet
85
77
  use Rack::ETag
86
78
  run maps_app
data/lib/opal/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  # WHEN RELEASING:
3
3
  # Remember to update RUBY_ENGINE_VERSION in opal/corelib/constants.rb too!
4
- VERSION = '0.9.0'
4
+ VERSION = '0.9.2'
5
5
  end
@@ -1,8 +1,8 @@
1
1
  RUBY_PLATFORM = 'opal'
2
2
  RUBY_ENGINE = 'opal'
3
3
  RUBY_VERSION = '2.2.3'
4
- RUBY_ENGINE_VERSION = '0.9.0'
5
- RUBY_RELEASE_DATE = '2015-12-20'
4
+ RUBY_ENGINE_VERSION = '0.9.2'
5
+ RUBY_RELEASE_DATE = '2016-01-10'
6
6
  RUBY_PATCHLEVEL = 0
7
7
  RUBY_REVISION = 0
8
8
  RUBY_COPYRIGHT = 'opal - Copyright (C) 2013-2015 Adam Beynon'
@@ -133,6 +133,123 @@ describe Opal::Compiler do
133
133
  end
134
134
  end
135
135
  end
136
+
137
+ describe 'truthy check' do
138
+ context 'no parentheses' do
139
+ context 'with operators' do
140
+ it 'excludes nil check for primitives' do
141
+ expect_compiled('foo = 42 if 2 > 3').to include('if ($rb_gt(2, 3))')
142
+ expect_compiled('foo = 42 if 2.5 > 3.5').to include('if ($rb_gt(2.5, 3.5))')
143
+ expect_compiled('foo = 42 if true > false').to include('if ($rb_gt(true, false))')
144
+
145
+ expect_compiled('foo = 42 if 2 == 3').to include("if ((2)['$=='](3))")
146
+ expect_compiled('foo = 42 if 2.5 == 3.5').to include("if ((2.5)['$=='](3.5))")
147
+ expect_compiled('foo = 42 if true == false').to include("if (true['$=='](false))")
148
+ end
149
+
150
+ it 'adds nil check for strings' do
151
+ expect_compiled('foo = 42 if "test" > "bar"').to include('if ((($a = $rb_gt("test", "bar")) !== nil && (!$a.$$is_boolean || $a == true)))')
152
+ end
153
+
154
+ it 'specifically == excludes nil check for strings' do
155
+ expect_compiled('foo = 42 if "test" == "bar"').to include("if (\"test\"['$=='](\"bar\"))")
156
+ end
157
+
158
+ it 'adds nil check for lvars' do
159
+ expect_compiled("bar = 4\nfoo = 42 if bar > 5").to include('if ((($a = $rb_gt(bar, 5)) !== nil && (!$a.$$is_boolean || $a == true)))')
160
+ end
161
+
162
+ it 'specifically == excludes nil check for lvars' do
163
+ expect_compiled("bar = 4\nfoo = 42 if bar == 5").to include("if (bar['$=='](5))")
164
+ end
165
+
166
+ it 'adds nil check for constants' do
167
+ expect_compiled("foo = 42 if Test > 4").to include("if ((($a = $rb_gt($scope.get('Test'), 4)) !== nil && (!$a.$$is_boolean || $a == true))) ")
168
+ end
169
+
170
+ it 'specifically == excludes nil check for constants' do
171
+ expect_compiled("foo = 42 if Test == 4").to include("if ($scope.get('Test')['$=='](4))")
172
+ end
173
+ end
174
+
175
+ context 'without operators' do
176
+ it 'adds nil check for primitives' do
177
+ expect_compiled('foo = 42 if 2').to include('if ((($a = 2) !== nil && (!$a.$$is_boolean || $a == true)))')
178
+ expect_compiled('foo = 42 if 2.5').to include('if ((($a = 2.5) !== nil && (!$a.$$is_boolean || $a == true)))')
179
+ expect_compiled('foo = 42 if true').to include('if ((($a = true) !== nil && (!$a.$$is_boolean || $a == true)))')
180
+ end
181
+
182
+ it 'adds nil check for boolean method calls' do
183
+ expect_compiled('foo = 42 if true.something').to include('if ((($a = true.$something()) !== nil && (!$a.$$is_boolean || $a == true)))')
184
+ end
185
+
186
+ it 'adds nil check for strings' do
187
+ expect_compiled('foo = 42 if "test"').to include('if ((($a = "test") !== nil && (!$a.$$is_boolean || $a == true)))')
188
+ end
189
+
190
+ it 'adds nil check for lvars' do
191
+ expect_compiled("bar = 4\nfoo = 42 if bar").to include('if (bar !== false && bar !== nil)')
192
+ end
193
+
194
+ it 'adds nil check for constants' do
195
+ expect_compiled("foo = 42 if Test").to include("if ((($a = $scope.get('Test')) !== nil && (!$a.$$is_boolean || $a == true)))")
196
+ end
197
+ end
198
+ end
199
+
200
+ context 'parentheses' do
201
+ context 'with operators' do
202
+ it 'adds nil check for primitives' do
203
+ expect_compiled('foo = 42 if (2 > 3)').to include('if ((($a = ($rb_gt(2, 3))) !== nil && (!$a.$$is_boolean || $a == true)))')
204
+ expect_compiled('foo = 42 if (2.5 > 3.5)').to include('if ((($a = ($rb_gt(2.5, 3.5))) !== nil && (!$a.$$is_boolean || $a == true)))')
205
+ expect_compiled('foo = 42 if (true > false)').to include('if ((($a = ($rb_gt(true, false))) !== nil && (!$a.$$is_boolean || $a == true)))')
206
+
207
+ expect_compiled('foo = 42 if (2 == 3)').to include("if ((($a = ((2)['$=='](3))) !== nil && (!$a.$$is_boolean || $a == true)))")
208
+ expect_compiled('foo = 42 if (2.5 == 3.5)').to include("if ((($a = ((2.5)['$=='](3.5))) !== nil && (!$a.$$is_boolean || $a == true)))")
209
+ expect_compiled('foo = 42 if (true == false)').to include("if ((($a = (true['$=='](false))) !== nil && (!$a.$$is_boolean || $a == true)))")
210
+ end
211
+
212
+ it 'adds nil check for strings' do
213
+ expect_compiled('foo = 42 if ("test" > "bar")').to include('if ((($a = ($rb_gt("test", "bar"))) !== nil && (!$a.$$is_boolean || $a == true)))')
214
+ expect_compiled('foo = 42 if ("test" == "bar")').to include("if ((($a = (\"test\"['$=='](\"bar\"))) !== nil && (!$a.$$is_boolean || $a == true)))")
215
+ end
216
+
217
+ it 'adds nil check for lvars' do
218
+ expect_compiled("bar = 4\nfoo = 42 if (bar > 5)").to include('if ((($a = ($rb_gt(bar, 5))) !== nil && (!$a.$$is_boolean || $a == true)))')
219
+ expect_compiled("bar = 4\nfoo = 42 if (bar == 5)").to include("if ((($a = (bar['$=='](5))) !== nil && (!$a.$$is_boolean || $a == true))) ")
220
+ end
221
+
222
+ it 'adds nil check for constants' do
223
+ expect_compiled("foo = 42 if (Test > 4)").to include("if ((($a = ($rb_gt($scope.get('Test'), 4))) !== nil && (!$a.$$is_boolean || $a == true)))")
224
+ expect_compiled("foo = 42 if (Test == 4)").to include("if ((($a = ($scope.get('Test')['$=='](4))) !== nil && (!$a.$$is_boolean || $a == true)))")
225
+ end
226
+ end
227
+
228
+ context 'without operators' do
229
+ it 'adds nil check for primitives' do
230
+ expect_compiled('foo = 42 if (2)').to include('if ((($a = (2)) !== nil && (!$a.$$is_boolean || $a == true)))')
231
+ expect_compiled('foo = 42 if (2.5)').to include('if ((($a = (2.5)) !== nil && (!$a.$$is_boolean || $a == true)))')
232
+ expect_compiled('foo = 42 if (true)').to include('if ((($a = (true)) !== nil && (!$a.$$is_boolean || $a == true)))')
233
+ end
234
+
235
+ it 'adds nil check for boolean method calls' do
236
+ expect_compiled('foo = 42 if (true.something)').to include('if ((($a = (true.$something())) !== nil && (!$a.$$is_boolean || $a == true)))')
237
+ end
238
+
239
+ it 'adds nil check for strings' do
240
+ expect_compiled('foo = 42 if ("test")').to include('if ((($a = ("test")) !== nil && (!$a.$$is_boolean || $a == true)))')
241
+ end
242
+
243
+ it 'adds nil check for lvars' do
244
+ expect_compiled("bar = 4\nfoo = 42 if (bar)").to include('if ((($a = (bar)) !== nil && (!$a.$$is_boolean || $a == true)))')
245
+ end
246
+
247
+ it 'adds nil check for constants' do
248
+ expect_compiled("foo = 42 if (Test)").to include("if ((($a = ($scope.get('Test'))) !== nil && (!$a.$$is_boolean || $a == true)))")
249
+ end
250
+ end
251
+ end
252
+ end
136
253
 
137
254
  def expect_compiled(*args)
138
255
  expect(Opal::Compiler.new(*args).compile)
@@ -35,4 +35,27 @@ describe "The rescue keyword" do
35
35
  it "returns nil if no expr given in rescue body" do
36
36
  RescueReturningSpec.new.empty_rescue.should be_nil
37
37
  end
38
+
39
+ it 'Fix using more than two "rescue" in sequence #1269' do
40
+ # As a statement
41
+ begin
42
+ raise IOError, 'foo'
43
+ rescue RangeError # this one is correct
44
+ rescue TypeError # miss a return
45
+ rescue IOError # following two lines disappear in js
46
+ $ScratchPad << "I got #{$!.message}"
47
+ end
48
+ $ScratchPad.last.should == "I got foo"
49
+
50
+ # As an expression
51
+ a = begin
52
+ raise IOError, 'foo'
53
+ rescue RangeError # this one is correct
54
+ rescue TypeError # miss a return
55
+ rescue IOError # following two lines disappear in js
56
+ "I got #{$!.message}"
57
+ end
58
+ a.should == "I got foo"
59
+ end
60
+
38
61
  end
@@ -4,6 +4,14 @@ class Boolean
4
4
  end
5
5
  end
6
6
 
7
+ class JsNil
8
+ def <(other)
9
+ %x{
10
+ return nil;
11
+ }
12
+ end
13
+ end
14
+
7
15
  describe "Opal truthyness" do
8
16
  it "should evaluate to true using js `true` as an object" do
9
17
  if true.self_as_an_object
@@ -20,4 +28,10 @@ describe "Opal truthyness" do
20
28
 
21
29
  called.should be_nil
22
30
  end
31
+
32
+ it "should evaluate to false if js `nil` is used with an operator" do
33
+ is_falsey = JsNil.new < 2 ? false : true
34
+
35
+ is_falsey.should be_true
36
+ end
23
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Beynon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-20 00:00:00.000000000 Z
11
+ date: 2016-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sourcemap