Incorrect pattern matches in "macro" macro
Created by: andreypopp
Hello,
First — Sweet.js is super awesome, thanks!
I'm trying to write a simple macro which will produce an object literal from a list of k-v pairs but passes everything else as-is:
attributes(id) // id
attributes({}) // {}
attributes(k: v, a: 1) // {k: v, a: 1}
Currently my macro looks like this:
macro attributes {
case {_()} => {
return #{null}
}
case {_($($name:ident : $val:expr) (,) ...)} => {
return [makeDelim('{}', #{$($name: $val) (,) ...})]
}
case {_($any:expr)} => {
return #{$any}
}
}
But somehow attributes(id)
matches the second case which is, I believe, wrong.
P.S. this macro is part of the bigger story, which is why I have a special case producing null
for empty arg list.