Escape Parentheses in sweet.js Macro Name

91 Views Asked by At

I want to write a spread macro, but in order to do so, I need to override how functions are called like so:

someFn(..>someArray)

Which needs to output:

someFn.apply(null, someArray)

I have tried by creating a macro named (. I've seen that you do not need to escape parentheses in a macro body, and parentheses are used to escape multi-token names...but so far I have had issues trying to create a macro with that name.

With that name, it errors on parsing the macro with Error: Line 16: Unexpected end of input. Is there an escape character that I can use, or is this something that needs to be reported in Github?

1

There are 1 best solutions below

0
On

So ( is not a valid token you can use for a macro. This is because all delimiters must be balanced before any macro expansion happens (this is the reader portion of sweet.js). Thus, the error saying unexpected end of input, the reader is still looking for the closing delimiter.

I don't think we have a good way of overriding function calls right now. We have some ideas about how to go about this (see a somewhat related issue here) but nothing implemented yet.