Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow append/prepend API for function bodies / Expose nodes modules #24

Open
Exagram opened this issue Sep 22, 2015 · 1 comment
Open

Comments

@Exagram
Copy link

Exagram commented Sep 22, 2015

Are we able to get append/prepend API for inserting calls in function bodies? Currently the append/prepend API only works for the tree body.

Example:

function test() {
    foo('test');
}

Fails: c.body.node[0].body.append('bar();').

So I looked for workarounds. I tried to manually push this new call into the body array via c.body.node[0].body.body.push('bar();'). But doing so fails because bar(); is a string and not an esprima object. A possible solution is to expose AST-query nodes modules so we can do the above. Or add documentation that the body array requires an esprima object.

I can code this change, just need vision.

@SBoudrias
Copy link
Owner

Hey, can you clarify what you're doing and what is the result you'd expect? Also, when you say something fail, it'd help to have the error trace you're seeing.

A PR is welcomed, looks like you'd just need to make the body node append and prepend function more flexible.

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

No branches or pull requests

2 participants