SBoudrias / AST-query

Tentative to a simple JavaScript AST modification library
MIT License
243 stars 26 forks source link

Question: Adding an element to a shorthand object #33

Open duro opened 7 years ago

duro commented 7 years ago

I am trying to edit a file that has a block like this

const reducers = combineReducers({
    app,
    home
});

I have been able to add a new key to it using this command:

tree.callExpression('combineReducers').arguments.at(0).key('test').value('test')

This ends up creating code like this:

const reducers = combineReducers({
    app,
    home,
    test: test
});

How can I get it to result in this??:

const reducers = combineReducers({
    app,
    home,
    test
});
SBoudrias commented 7 years ago

Do you know what is the AST tree of the desired syntax?