Skip to content

Conversation

@BobVarioa
Copy link

@BobVarioa BobVarioa commented Apr 26, 2021

Adds support for function based macros

Examples :

assert(jscc("$_HI()", '', {
   values: {
       _HI: () => "hi"
   }
}).code === "hi")
assert(jscc('$_HI("one", "two", "three")', '', {
   values: {
       _HI: (...args) => args.join(",")
   }
}).code === "one,two,three")
assert(jscc('$_HI("one", "two", "three")', '', {
   values: {
       _HI: "hi"
   }
}).code === 'hi("one", "two", "three")') // doesn't change existing behavior of non functional values

Function based macros can only be a the top level (e.g. no $_LIB.fs.blah.read(/*etc.*/)) and arguments must be either a string or a number.

I tried to keep the same style as your code and I wrote a few tests (but since they are so simple I didn't really know what else to test).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant