Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ba4786fa9a85
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d1612d4b316b
Choose a head ref
  • 2 commits
  • 6 files changed
  • 2 contributors

Commits on Oct 12, 2015

  1. * Update grammar to not forget the last parameter if there is one (va…

    …l[3] is nil if none is supplied)
    
    * Cover all cases
    wied03 committed Oct 12, 2015
    Copy the full SHA
    a73c24e View commit details
  2. Merge pull request #1132 from wied03/method_call_hash_block

    Fix block after hash compilation/parser issue
    elia committed Oct 12, 2015
    Copy the full SHA
    d1612d4 View commit details
Showing with 1,780 additions and 1,743 deletions.
  1. +3 −0 CHANGELOG.md
  2. +1,752 −1,743 lib/opal/parser/grammar.rb
  3. +1 −0 lib/opal/parser/grammar.y
  4. +18 −0 spec/lib/parser/call_spec.rb
  5. +1 −0 spec/opal/core/language/fixtures/send.rb
  6. +5 −0 spec/opal/core/language/send_spec.rb
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -31,6 +31,9 @@

* `OpenStruct` - fixed `#method missing`, `#inspect`, `#to_s`, `#delete_field`. Fully compliant except for frozen and marshal behavior.

* Fix issue where passing a block after a parameter and a hash was causing block to not be passed (e.g. `method1 some_param, 'a' => 1, &block`)


## 0.8.0 2015-07-16

* Update to Sprockets v3.0.
3,495 changes: 1,752 additions & 1,743 deletions lib/opal/parser/grammar.rb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/opal/parser/grammar.y
Original file line number Diff line number Diff line change
@@ -670,6 +670,7 @@ rule
{
result = val[0]
result << new_hash(nil, val[2], nil)
result << val[3] if val[3]
}
| block_arg
{
18 changes: 18 additions & 0 deletions spec/lib/parser/call_spec.rb
Original file line number Diff line number Diff line change
@@ -154,6 +154,24 @@
end
end

describe 'Calls that include a hash' do
it 'parses correctly when a hash followed by a block' do
parsed('foo(a => 2, &block)').should == [:call, nil, :foo, [:arglist, [:hash, [:call, nil, :a, [:arglist]], [:int, 2]],[:block_pass, [:call, nil, :block, [:arglist]]]]]
end

it 'parses correctly when only a hash is passed' do
parsed('foo(a => 2)').should == [:call, nil, :foo, [:arglist, [:hash, [:call, nil, :a, [:arglist]], [:int, 2]]]]
end

it 'parses correctly when ending in hash' do
parsed('foo(1, a => 2)').should == [:call, nil, :foo, [:arglist, [:int, 1], [:hash, [:call, nil, :a, [:arglist]], [:int, 2]]]]
end

it 'parses correctly with another parameter and hash followed by a block' do
parsed('foo(1, a => 2, &block)').should == [:call, nil, :foo, [:arglist, [:int, 1], [:hash, [:call, nil, :a, [:arglist]], [:int, 2]], [:block_pass, [:call, nil, :block, [:arglist]]]]]
end
end

describe 'Calls with trailing comma' do
it 'parses correctly' do
parsed('foo(1,)').should == [:call, nil, :foo, [:arglist, [:int, 1]]]
1 change: 1 addition & 0 deletions spec/opal/core/language/fixtures/send.rb
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ def self.fooM0R(*r); r; end
def self.fooM1R(a, *r); [a, r]; end
def self.fooM0O1R(a=1, *r); [a, r]; end
def self.fooM1O1R(a, b=1, *r); [a, b, r]; end
def self.fooM1O2(a, b={}, &block); [a, b, block]; end

def self.one(a); a; end
def self.oneb(a,&b); [a,yield(b)]; end
5 changes: 5 additions & 0 deletions spec/opal/core/language/send_spec.rb
Original file line number Diff line number Diff line change
@@ -73,6 +73,11 @@
specs.fooM1O1(1,2,3)
}.should raise_error(ArgumentError)
end

it "keeps the block if supplied" do
block = lambda {}
specs.fooM1O2(1, foo: :bar, &block).should == [1, {foo: :bar}, block]
end
end

describe "with a rest argument" do