Convert sweet.js argument into string -
How can you create a sweet.js macro string from an argument? For example:
let foo = macro {rule {$ name} = & gt; {Console.log ('$ name', $ name); }} Var x = 42; Foo x will output:
console.log (x, x); When I like it in output:
console.log ('x', x); So the first argument is the quote around it.
You can use case macros:
let's foo = Macro {case {_ $ name} = & gt; {Letstx $ name_str = [makeValue (Inevitable syntax (# {$ name}), # {here})]; Return # {console.log ($ name_str, $ name); }}} Var x = 42; Foo x The basic idea is that you can use a new string token ( makeValue ) using the string value of the identifiers transmitted through $ name. ) / Code> ( opening syntax gives us the value of the syntax given to the object, in the case of an identifier this identifier is a string). Then letstx allows us to force our newly created syntax object for use inside the template.
Comments
Post a Comment