-
Notifications
You must be signed in to change notification settings - Fork 660
feature(rome_js_semantic): matching declarations and scopes #2690
Conversation
Deploying with Cloudflare Pages
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked the JS spec on what introduces a new scope? I believe this is (partially) the relevant section. https://tc39.es/ecma262/#sec-static-semantics-lexicallydeclarednames
Another alternative would be to look at rome classic's implementation. Maybe @ematipico has a pointer for you?
Rome classic had a nice way to test things, although it was via snapshot tests: https://github.com/rome/tools/blob/archived-js/internal/compiler/scope/Scope.test.md Maybe you can use it as inspiration. This is where we stored all the globals: https://github.com/rome/tools/blob/archived-js/internal/compiler/scope/globals.ts, they were excluded from being tracked as bindings inside scopes. This is where the bindings were created, and as you can see they have different kinds: https://github.com/rome/tools/blob/archived-js/internal/compiler/scope/bindings.ts The creation of the scopes was done at node level by using the evaluators. I believe this is pretty nifty for various reasons:
Here's the list of evaluators: https://github.com/rome/tools/tree/archived-js/internal/compiler/scope/evaluators We use the function |
* variable declaration pointing to its parent scope
This PR is the part that matches declarations and scopes of the main PR (#2489).
For more details: #2488
This is just the first PR for this match, as we are solving only the most naive cases.
This also introduces a new assertion to test if the declaration is actually pointing to the correct scope. The important part here would be the
@A
, which means that the current declaration should be pointing to a scope namedA
.Better Diagnostics
Now the diagnostic specifies more clearly which test failed.