#Is there a way to import a list of (reserved) keywords? Or check if a name is a valid identifier

6 messages · Page 1 of 1 (latest)

fickle warren
#

I'm writing a codegen utility and I'd like to make sure I don't generate invalid identifiers. I've spent quite a while searching around and digging through the compiler API but I haven't found an easy way yet to check if an identifier name will be valid.

Is there perhaps a publicly exposed method like isValidIdentifier, or some way to create a Node to then try and turn into an Identifier? Or even just a list of reservedKeywords or something

bitter moth
#

js identifier rules (and rules for other languages) are pretty well documented, so if necessary you could do it yourself

ocean hamlet
#

or (new Function(`var ${yourIdentifierName}`))()

bitter moth
#

or wait no