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

Updating arbitrary properties #8

Closed
aleclarson opened this issue May 22, 2018 · 1 comment
Closed

Updating arbitrary properties #8

aleclarson opened this issue May 22, 2018 · 1 comment
Labels
enhancement New feature or request

Comments

@aleclarson
Copy link
Collaborator

aleclarson commented May 22, 2018

While the set method currently only works with properties that typically contain a Node object or an array of Node objects, it should work with any property that makes sense to update.

Supporting this will require a new module that exports an object like so:

exports.VariableDeclaration = {
  setKind(value, output) {
    output.overwrite(this.start, this.start + this.kind.length, value);
  }
};

Then, node.set('kind', 'var') would turn let a = 1 into var a = 1.

The exports would be restructured (on startup) into something like:

exports.set = {
  VariableDeclaration: {
    kind(value, output) { /* ... */ }
  }
};

The push, unshift, and splice methods might have their own edge cases, too. These would be handled similarly with insertProperty-style functions.

Same for the remove method with removeProperty-style functions.

@aleclarson aleclarson added the enhancement New feature or request label May 22, 2018
@aleclarson
Copy link
Collaborator Author

aleclarson commented Mar 23, 2021

This is supported as of v2.0.0 in the src/mutation.ts module. (see the replacers export)

You'll need to implement a property setter for the property you want to update. PRs welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant