Question: can anyone help me write a simple visitor? I'm trying to take a variable declarator and alter it to an assignment expression of a value onto a member expression but it's telling me there's an unexpected .

Asked By
Asked At
2017-09-18 23:39:20

Found 15 possible answers.

User Answered At Possible Answer
drewml 2017-09-18 23:39:47 @realisation a link to a (broken) example on would help
wagonofjustice 2017-09-18 23:39:54 like var a = 5 to thing.a = 5
loganfsmyth 2017-09-18 23:41:18 Yeah you can use the "transform" option on ASTExplorer to put together a transform that we can review easily
wagonofjustice 2017-09-18 23:41:29 ok, neat
drewml 2017-09-18 23:46:48 here is a contrived example -
wagonofjustice 2017-09-18 23:47:07 example coming straight up I hadn't gotten that error on my own machine when using babel with the env preset so that doesn't recognize stringLiteral
drewml 2017-09-18 23:53:34 babel 5 is t.literal() are you trying to write a plugin for 5 or 6?
wagonofjustice 2017-09-18 23:53:47 6
drewml 2017-09-18 23:54:06 make sure to choose babelv6 in the transform dropdown the structure of your transform is babel5 right now
wagonofjustice 2017-09-18 23:55:05 yeah, must restructure
drewml 2017-09-18 23:57:00 also, right now you’re replacing a VariableDeclarator - you’ll want to replace the whole VariableDeclaration if you want to switch to an assignment to a property
wagonofjustice 2017-09-18 23:57:27 it's still a little messed up - I don't really care so much about figuring out what I did as I do about figuring out how to do this correctly I see hmm
drewml 2017-09-18 23:57:36 see my example I linked above it is a correct example of how to create it
wagonofjustice 2017-09-18 23:57:55 what's the difference between VariableDecalarator and VariableDeclaration ? is there a best source for docs here?
drewml 2017-09-18 23:58:33 in var a = 1, b =2 a and b assignments are separate declarators - the entire thing is the declaration you can put example code in ASTExplorer and look in the top right to get a better understanding visually of the structure of the babylon ast for the types of builders, . For writing a plugin in general,

Related Questions