Skip to content

Commit

Permalink
Source maps for atoms
Browse files Browse the repository at this point in the history
  • Loading branch information
anko committed Nov 24, 2015
1 parent 050435f commit 215cd81
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/compile.ls
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ string-to-self-producer = ->
raw : "\"#{it}\""
]

atom-to-estree = (env, { value : name }) ->
atom-to-estree = (env, { value : name }:ast) ->

lit = ~> type : \Literal, value : it, raw : name
lit = ~>
type : \Literal value : it, raw : name
loc : ast.location

switch name
| \this => type : \ThisExpression
Expand All @@ -47,6 +49,7 @@ atom-to-estree = (env, { value : name }) ->
type : \Literal
value : Number name
raw : name
loc : ast.location
| looks-like-negative-number name
type : \UnaryExpression
operator : \-
Expand All @@ -55,6 +58,7 @@ atom-to-estree = (env, { value : name }) ->
| otherwise
type : \Identifier
name : name
loc : ast.location

atom-to-self-producer = ->
type : \ObjectExpression
Expand Down
14 changes: 13 additions & 1 deletion test.ls
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,18 @@ test "multiple transform-macros are applied in order" ->
esl "zero" transform-macros : [ wrap1, wrap2, wrap3 ]
.. `@equals` "three(two(one(zero)));"

test "identifier source map" ->
esl.source-map "x" filename : "test.esl"
..`@equals` '{"version":3,"sources":["test.esl"],"names":["x"],"mappings":"AAAAA,C","sourcesContent":["x"]}'

test "number literal source map" ->
esl.source-map "true" filename : "test.esl"
..`@equals` '{"version":3,"sources":["test.esl"],"names":[],"mappings":"AAAA,I","sourcesContent":["true"]}'

test "boolean literal source map" ->
esl.source-map "42" filename : "test.esl"
..`@equals` '{"version":3,"sources":["test.esl"],"names":[],"mappings":"AAAA,E","sourcesContent":["42"]}'

test "call expression source map" ->
esl.source-map "(f a b)\n" filename : "test.esl"
..`@equals` '{"version":3,"sources":["test.esl"],"names":[],"mappings":"CAAA,C,CAAA,E,CAAA,C","sourcesContent":["(f a b)\\n"]}'
..`@equals` '{"version":3,"sources":["test.esl"],"names":["f","a","b"],"mappings":"AAACA,CAAD,CAAGC,CAAH,EAAKC,CAAL,C","sourcesContent":["(f a b)\\n"]}'

0 comments on commit 215cd81

Please sign in to comment.