You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to do some manipulation and I couldn't find a way to insert a property into an ObjectExpression. I dug around and found the value factory (/lib/factory/value.js) that allows to easily create AST elements.
However I couldn't find a way to create an object property, is that supported somehow?
Would be nice to have access to the value factory and be able to create object properties through it.
EDIT: this seems to work:
/**
* Create a property node from a value string
* @param {String} valKey key string
* @param {String} valStr value string
* @return {Object} Property node
*/
exports.createProp = function (valKey, valStr) {
var tree = esprima.parse('var astValFactory = { ' + valKey + ': ' + valStr + '};',esprimaOptions);
tree = escodegen.attachComments(tree, tree.comments, tree.tokens);
return tree.body[0].declarations[0].init.properties[0];
};
Thanks!
The text was updated successfully, but these errors were encountered:
I wanted to do some manipulation and I couldn't find a way to insert a property into an ObjectExpression. I dug around and found the value factory (/lib/factory/value.js) that allows to easily create AST elements.
However I couldn't find a way to create an object property, is that supported somehow?
Would be nice to have access to the value factory and be able to create object properties through it.
EDIT: this seems to work:
Thanks!
The text was updated successfully, but these errors were encountered: