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
Insert a new statement before (or after) a statement.
import{parseModule,generateCode}from"magicast";// Parse to ASTconstmod=parseModule(`export default { }`);// Insert a declaration statement before the `export default` statementmod.exports.before(`const a = "VariableDeclarator";`);// Ensure foo is an arraymod.exports.default.foo||=[];// Add a variable as a new array membermod.exports.default.foo.push("a","var");/** * const a = "VariableDeclarator"; * export default { * foo: [a], * }; */console.log(generateCode(mod).code);
Additional information
Would you be willing to help implement this feature?
The text was updated successfully, but these errors were encountered:
Sounds reasonable. I think we could use $append and $prepend on every node? Prefix with $ indicates it's a special operation and avoids conflicts with the namespace.
Describe the feature
expect
Insert a new statement before (or after) a statement.
Additional information
The text was updated successfully, but these errors were encountered: