Skip to content

Commit

Permalink
Bugfix: compile negative numbers to unary exprs
Browse files Browse the repository at this point in the history
Made a typo earlier and there was no unit test to catch it.  There is
now.
  • Loading branch information
anko committed Nov 11, 2015
1 parent c589ac5 commit 3d97b22
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/compile.ls
Original file line number Diff line number Diff line change
@@ -4,8 +4,6 @@ looks-like-positive-number = (atom-text) ->
atom-text.match /^\d+(\.\d+)?$/
looks-like-negative-number = (atom-text) ->
atom-text.match /^-\d+(\.\d+)?$/
looks-like-number = ->
(looks-like-positive-number it) || (looks-like-negative-number it)

string-to-estree = ->
type : \Literal
@@ -54,7 +52,7 @@ atom-to-estree = (name) ->
| \true => lit true
| \false => lit false
| otherwise switch
| looks-like-number name
| looks-like-positive-number name
type : \Literal
value : Number name
raw : name
6 changes: 5 additions & 1 deletion test.ls
Original file line number Diff line number Diff line change
@@ -21,10 +21,14 @@ test "first-line shebang" ->
esl "#!something goes here\n(hello)\n"
..`@equals` "hello();"

test "plain literal" ->
test "plain numeric literal" ->
esl "3"
..`@equals` "3;"

test "plain negative numeric literal" ->
esl "-3"
..`@equals` "-3;"

test "plain literal with trailing digits" ->
esl "asd39"
..`@equals` "asd39;"

0 comments on commit 3d97b22

Please sign in to comment.