Skip to content

Commit 91819db

Browse files
committed
Allow transform macros to return null
It means they wish for there to be no output; which is pretty drastic for a transform macro, but hey, user freedom.
1 parent 24ea0be commit 91819db

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/translate.ls

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ module.exports = (root-env, ast, options={}) ->
1919
statements = ast.content
2020

2121
transform-macros .for-each (macro) ->
22-
statements := macro.apply null, statements
22+
statements := (macro.apply null, statements)
23+
.filter (isnt null)
2324

2425
program-ast =
2526
type : \Program

test.ls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,11 @@ test "transform-macro can replace contents" ->
10271027
esl "(+ 1 2)" transform-macros : [ wrapper ]
10281028
.. `@equals` "3 * 4;"
10291029
1030+
test "transform-macro can return null" ->
1031+
wrapper = -> null
1032+
esl "(+ 1 2)" transform-macros : [ wrapper ]
1033+
.. `@equals` ""
1034+
10301035
test "transform-macro can receive arguments" ->
10311036
wrapper = (...args) ->
10321037
[ { atom : "hi" } ].concat args

0 commit comments

Comments
 (0)