This way we can get the class node faster. But I don't know if this is a
good way. In `eslint-plugin-react`, they get class node by scope. But
oxc cannot do the same way
@Boshen
The `ScopeTree.descendants` function would return all scopes starting
from the root, and wasn't truly descendants from a specific scope. To
improve this, I've renamed this function to `descendants_from_root` and
have introduced a new `descendants` function that does support from a
specific scope.
Furthermore, I've introduced helper functions to `SymbolTree` to make
reading symbols/scopes easier.
To verify this functionality, I enabled the `function_name` transformer
(and fixed it), and ran some example transforms. Here's the input:
```js
let fn;
fn = function (a, b, c) {
const d = "";
};
const func = function (arg) {
{
const value = "";
}
};
const f = function (f) {};
```
And the output using _the old implementation_. Note that all function
names are suffixed with a number, this is incorrect, since it was
inheriting far too many scopes.
```js
let fn;
fn = function fn1(a, b, c) {
const d = '';
};
const func = function func1(arg) {
{
const value = '';
}
};
const f = function f2(f) {
};
```
And here's the output with the new implementation. Note that only `f` is
suffixed with a number. That's because it has a shadowed argument of the
same name.
```js
let fn;
fn = function fn(a, b, c) {
const d = '';
};
const func = function func(arg) {
{
const value = '';
}
};
const f = function f1(f) {
};
```
closes#949closes#950closes#951
All minifier tests are disable from this PR.
We are going to fix the compilation errors first, then the behavioral
errors.
Add test cases to `oxc_semantic` that check scope flag behavior.
Also contains these tweaks:
- fix: allow disabling `with_module` on `SourceType`
- refactor: move `SymbolTester` to a separate file
- chore: add `Expect` trait & implement it on `SymbolTester`
When initially written types were not in the symbol table. Now that
types are in the symbol table it makes sense given
```ts
type A = 1
type B = A
```
that you can get to the symbol id for for A from type B = A.
Please correct me if I'm wrong about how I implemented this. I also
verified that occurrence (I believe this is the correct word) behaves
how I would expect.
```ts
type RecursiveType = string | {[x: string]: RecursiveType}
```
Does populate a reference.
---------
Co-authored-by: Boshen <boshenc@gmail.com>
A test harness for checking results of semantic analysis.
I got tired of writing ad-hoc test cases when finding bugs in semantic
analysis, so I made this.
Closes#685
Intend to use this in the following ways in #672.
```rs
let node = ctx.nodes().get_node(reference.node_id());
if !self.type_of && has_typeof_operator(node, ctx) {
return;
}
```
Fixes 11 TS conformance tests and 18 babel tests.
Adds types to the symbol table functionally conformant to TS behavior
but symbol flags implemented slightly differently.
Symbol redeclaration check is also not entirely conformant but fixing
this seems like a separate PR.
For testing purposes - consistent-export-type was also implemented
(WIP).