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
refactor(wasm)!: make current*
, is*
, and has*
methods properties
#3103
Conversation
currentNode
/currentFieldId
/currentFieldName
propertiescurrentNode
, isMissing
, etc. properties
2821547
to
ab6cd84
Compare
@verhovsky Just curious - do you have thoughts on which interface makes more sense? We should definitely make the two interfaces consistent, but which interface should we change, the Node one, or this one? From an idiomatic JS perspective, when should we use getters and when not? |
I'm fine with making breaking changes, but I want to be open to making breaking changes in the other direction (to the Node binding) since we're already making breaking changes there due to the NAPI stuff. I just want to check in about which methods make sense to be getters. One of the principles I was going for with the interface was to make the API feel somewhat like the most standard JS API for accessing trees, which is the web DOM APIs. I remember the DOM uses a lot of getters, but I don't remember the detailed shape of the APIs. Curious if you (or other folks who use this web binding) have thoughts. |
ab6cd84
to
1bcc777
Compare
The way this PR is, we'll need breaking changes in Node as well, to isNamed: boolean; // <- not a function
hasChanges(): boolean;
hasError(): boolean;
isMissing(): boolean;
readonly currentNode: SyntaxNode;
readonly currentFieldName: string; and in Wasm isNamed(): boolean;
hasChanges(): boolean;
hasError(): boolean;
isError(): boolean;
isMissing(): boolean;
currentNode(): SyntaxNode;
currentFieldId(): number;
currentFieldName(): string;
I think it makes sense for these to be properties because they don't change state or iterate the tree or perform any action really, just copy bytes from the given object from C into a JavaScript object and return it. The DOM seems to consistently follow this too, things like It doesn't make sense to me to make things that don't modify state in any meaningful way be functions. I could understand things that require traversing the tree being functions though. It's a minor annoyance to have to type |
I think
This too. |
currentNode
, isMissing
, etc. propertiescurrentNode
, currentFieldId
and currentFieldName
and isNamed
, hasError
, hasChanges
, isError
and isMissing
properties
Yeah, I agree with |
currentNode
, currentFieldId
and currentFieldName
and isNamed
, hasError
, hasChanges
, isError
and isMissing
properties6846957
to
7b96bd8
Compare
People seemed opposed to changing the other methods to properties on Discord so I undid that change so this PR can be merged. We will still have to change But I'm still convinced that these things should be properties. For the most part they're just reading a value that already exists in memory, wrapping it in a JavaScript object and returning it. Lines 464 to 466 in 7b96bd8
Line 222 in 2d652c9
Line 215 in 2d652c9
None of them change state. The ones that do any sort of computation, like tree-sitter/lib/binding_web/binding.js Lines 577 to 580 in 7b96bd8
So we have That being said, more breaking changes will be really annoying, and since it's not as necessary as changing |
Ok, I'm ok with either direction of change, to make the two bindings consistent. |
87a272a
to
b37b802
Compare
current*
, is*
, and has*
methods properties
This is a breaking change to make the Wasm and Node bindings more interchangeable
Closes #2195