-
Notifications
You must be signed in to change notification settings - Fork 236
Operators #686
base: master
Are you sure you want to change the base?
Operators #686
Conversation
Update 2 merge good
Oh the latest issue made me realize I didn't even put in I think I should reset the files to atom:master to retry fixing this |
Shouldn't we also include "??=" in operators? |
"delete" is not listed as an operator like typeof... not changing for now
add "optional", "**=", and other test
I added the missing operators but I broke something and the tests are failing |
Hi @icecream17 could you take a look into the failing tests? |
Current status
Oh yeah. That's added For later testing: |
ok no syntax stuff now
See the previous result
359 fails, now down to 66, though 6f32f5a has only 13 errors, so maybe I should just use that instead.... maybe I should provide less updates? |
very verbose code!
fixes something at line 782...
It's possible that the eslint package messed things up....
Thanks Co-authored-by: Sadick <sadickjunior@gmail.com>
To check later (I don't have atom on this machine) The colon, which is part of the ternary operator, may also be parsed at part of a: label - https://github.com/tree-sitter/tree-sitter-javascript/blob/master/src/grammar.json#L1304 switch case - https://github.com/tree-sitter/tree-sitter-javascript/blob/master/src/grammar.json#L1359 switch default - https://github.com/tree-sitter/tree-sitter-javascript/blob/master/src/grammar.json#L1380 Generators, e.g. function* https://github.com/tree-sitter/tree-sitter-javascript/blob/master/src/grammar.json#L2676 A JSX fragment, ```<></>```, is also in the grammar, and will obviously fail. Resources I found https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence https://github.com/tree-sitter/tree-sitter-javascript/blob/master/src/grammar.json with ctrl+f "type": "STRING"
There's some precedence thing with the operator parsing. I'm not sure how it works. I found the actual parser: https://github.com/tree-sitter/tree-sitter-javascript Note to self: https://github.com/atom/language-javascript/blob/master/grammars/tree-sitter-javascript.cson just maps parsed nodes to names. |
The colon is used for a lot of different things. I'm using what the non-tree sitter labels them. Although there's probably better names.
The atom console is outdated
This is a visual commit. Really it's about precedence, how specific the selectors are. Since they're the same it should work no matter what. The reason ?. isn't detected is because of the parser itself. See https://github.com/jcs-PR/tree-sitter-javascript/pull/1/files and tree-sitter/tree-sitter-javascript#150
The tree-sitter parser atom uses can't actually parse some operators yet. Will update when it can. Edit: The tests at the repo above show that it does support optional chaining.... but it doesn't parse correctly still Edit 3?: ...see tree-sitter/tree-sitter-javascript#152 Edit 6: See #692 |
Empty string "" times infinity is why Undo the undo
Update from atom
Update: |
Ok, even though it still doesn't work in tree-sitter (see blocking), it could still be merged as long as there's no bad changes. Incompatible changesCurrently I've "added scopes" in 743fcd5 but https://github.com/atom/language-javascript/pull/690/files takes care of that. However the scopes for |
The non-tree sitter version is almost completely copied so nothing to say there. There are some inconsistencies/missing operators in the tree-sitter version, for example: - `this` - `new.target` - `import.meta` - The keyword.operator order looks more wrong the more I look at it but that's for another day because of the possible scope regularity change in the future: atom/language-javascript#690 - btw atom/language-javascript#691 looks good to me I should probably do that Even though tree-sitter will have some above changes I added the new operators (`** **= ?? &&= ||= ??= void`) anyway. Well `void` is not new it's just missing. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators for a list of operators. Of course while the comma is technically an operator, hopefully it's used more to separate elements in arrays or properties in objects. Also `delete` is an operator not control.
Previously blocked by Add more operators tree-sitter/tree-sitter-javascript#152(and other updating prs)Previously blocked by ⬆️ update tree-sitter packages to 0.19.0 #692Description of the Change
Edit: update
Adds optional chaining
a?.b
a?.[5]
a?.()
Adds
**=
Adds logical assignment
&&= ||= ??=
Add
shift
class to>>= >>>= <<=
Add
**
Ugh unfinished edit this later
Alternate Designs
I don't see how to make the ?. and . distinct without making everything that uses it seperate:It's much bigger than this but the idea is the same:
Original:
"var.prop" -> "variable" "meta.delimiter.period" "property"
Two way I thought of to support ?.
"var(?. or .)prop" -> "var" "meta.delimiter" "property"
or
I still added ?. as "meta.delimiter.optional" in the tree-sitter, but in the non-tree-sitter, they're the same.Edit: They're separate selectors, there's a later update below.
I've added tests for the ?. operator, and included ?? in the logic operator test. (Works!!!!!)
Benefits
Fixes #680
Fixes #640
Fixes #715 (duplicate)
Possible Drawbacks
A lot of comments
There might be a way to make them separate without adding a bunch of redundant code, but I haven't figured it out yet.I actually did figure it out, again there's an update belowApplicable Issues
#640 #680