Skip to content

Commit 8b5a84f

Browse files
committedMar 7, 2014
Fix parsing of hash-arrows in hashes with symbol keys and no whitespace
1 parent 5be5dd8 commit 8b5a84f

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed
 

‎CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## edge
22

3+
* Fix parsing `=>` in hash literals where it would sometimes incorrectly
4+
parse as a key name.
5+
36
## 0.6.0 2014-03-05
47

58
* Fix parsing of escapes in single-strings ('foo\n'). Only ' and \

‎lib/opal/parser/lexer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ def process_identifier(matched, cmd_start)
510510
result = :tIDENTIFIER
511511
else
512512
if @lex_state == :expr_fname
513-
if scan(/\=/)
513+
if !check(/\=\>/) and scan(/\=/)
514514
result = :tIDENTIFIER
515515
matched += scanner.matched
516516
end

‎spec/cli/parser/literal_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@
9494
parsed("{ a: 1 }").should == [:hash, [:sym, :a], [:int, 1]]
9595
parsed("{ a: 1, b: 2 }").should == [:hash, [:sym, :a], [:int, 1], [:sym, :b], [:int, 2]]
9696
end
97+
98+
it "parses hash arrows without spaces around arguments" do
99+
parsed("{1=>2}").should == [:hash, [:int, 1], [:int, 2]]
100+
parsed("{:foo=>2}").should == [:hash, [:sym, :foo], [:int, 2]]
101+
end
97102
end
98103

99104
describe "parsing regexps" do

0 commit comments

Comments
 (0)
Please sign in to comment.