Skip to content

Commit

Permalink
chore(semantic): copy tests from typescript-eslint’s scope-manager (#…
Browse files Browse the repository at this point in the history
…3990)

close:  #2947

These fixtures were copied from https://github.com/typescript-eslint/typescript-eslint/tree/a5b652da1ebb09ecbca8f4b032bf05ebc0e03dc9/packages/scope-manager/tests/fixtures. We used them to test out semantic `ScopeTree` and `SymbolTable`
  • Loading branch information
Dunqing committed Jul 17, 2024
1 parent 1108f2a commit 48724a0
Show file tree
Hide file tree
Showing 573 changed files with 15,655 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/oxc_semantic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ indexmap = { workspace = true }
insta = { workspace = true, features = ["glob"] }
phf = { workspace = true, features = ["macros"] }
rustc-hash = { workspace = true }
serde_json = { workspace = true }

[features]
default = []
Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_semantic/src/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ impl Reference {
self.symbol_id = Some(symbol_id);
}

pub fn flag_mut(&mut self) -> &mut ReferenceFlag {
&mut self.flag
}

pub fn flag(&self) -> &ReferenceFlag {
&self.flag
}

pub fn flag_mut(&mut self) -> &mut ReferenceFlag {
&mut self.flag
}

/// Returns `true` if the identifier value was read. This is not mutually
/// exclusive with [`#is_write`]
pub fn is_read(&self) -> bool {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
These fixtures were copied from https://github.com/typescript-eslint/typescript-eslint/tree/a5b652da1ebb09ecbca8f4b032bf05ebc0e03dc9/packages/scope-manager/tests/fixtures. We used them to test out semantic [ScopeTree](../../src/scope.rs) and [SymbolTable](../../src/symbol.rs)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
source: crates/oxc_semantic/tests/main.rs
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/block/inherited-scope.ts
---
[
{
"children": [
{
"children": [],
"flag": "ScopeFlags(StrictMode)",
"id": 1,
"node": "BlockStatement",
"symbols": []
}
],
"flag": "ScopeFlags(StrictMode | Top)",
"id": 0,
"node": "Program",
"symbols": [
{
"flag": "SymbolFlags(BlockScopedVariable | ConstVariable)",
"id": 0,
"name": "a",
"node": "VariableDeclarator",
"references": [
{
"flag": "ReferenceFlag(Read)",
"id": 0,
"name": "a",
"node_id": 7
}
]
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const a = 1;

{
a;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
source: crates/oxc_semantic/tests/main.rs
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/block/scope.ts
---
[
{
"children": [
{
"children": [],
"flag": "ScopeFlags(StrictMode)",
"id": 1,
"node": "BlockStatement",
"symbols": [
{
"flag": "SymbolFlags(BlockScopedVariable)",
"id": 0,
"name": "i",
"node": "VariableDeclarator",
"references": [
{
"flag": "ReferenceFlag(Read)",
"id": 0,
"name": "i",
"node_id": 11
}
]
},
{
"flag": "SymbolFlags(BlockScopedVariable)",
"id": 1,
"name": "j",
"node": "VariableDeclarator",
"references": []
}
]
}
],
"flag": "ScopeFlags(StrictMode | Top)",
"id": 0,
"node": "Program",
"symbols": []
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
let i = 20;
let j = 1;
i;
}

j;
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
source: crates/oxc_semantic/tests/main.rs
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/call-expression/call-expression.ts
---
[
{
"children": [
{
"children": [],
"flag": "ScopeFlags(StrictMode | Function | Arrow)",
"id": 1,
"node": "ArrowFunctionExpression",
"symbols": []
}
],
"flag": "ScopeFlags(StrictMode | Top)",
"id": 0,
"node": "Program",
"symbols": [
{
"flag": "SymbolFlags(BlockScopedVariable | ConstVariable)",
"id": 0,
"name": "foo",
"node": "VariableDeclarator",
"references": [
{
"flag": "ReferenceFlag(Read)",
"id": 0,
"name": "foo",
"node_id": 15
},
{
"flag": "ReferenceFlag(Read)",
"id": 1,
"name": "foo",
"node_id": 21
}
]
},
{
"flag": "SymbolFlags(BlockScopedVariable | ConstVariable)",
"id": 1,
"name": "a",
"node": "VariableDeclarator",
"references": [
{
"flag": "ReferenceFlag(Read)",
"id": 0,
"name": "a",
"node_id": 14
},
{
"flag": "ReferenceFlag(Read)",
"id": 1,
"name": "a",
"node_id": 20
}
]
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const foo = () => {};
const a = 1;

foo(a);
foo?.(a);
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
source: crates/oxc_semantic/tests/main.rs
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/call-expression/type-parameters1.ts
---
[
{
"children": [
{
"children": [],
"flag": "ScopeFlags(StrictMode)",
"id": 1,
"node": "TSTypeAliasDeclaration",
"symbols": []
}
],
"flag": "ScopeFlags(StrictMode | Top)",
"id": 0,
"node": "Program",
"symbols": [
{
"flag": "SymbolFlags(TypeAlias)",
"id": 0,
"name": "T",
"node": "TSTypeAliasDeclaration",
"references": [
{
"flag": "ReferenceFlag(Type)",
"id": 0,
"name": "T",
"node_id": 11
}
]
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type T = 1;
foo<T>();
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
source: crates/oxc_semantic/tests/main.rs
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/call-expression/type-parameters2.ts
---
[
{
"children": [],
"flag": "ScopeFlags(StrictMode | Top)",
"id": 0,
"node": "Program",
"symbols": [
{
"flag": "SymbolFlags(BlockScopedVariable | ConstVariable)",
"id": 0,
"name": "T",
"node": "VariableDeclarator",
"references": []
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const T = 1;
foo<T>(); // should not resolve to value
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
source: crates/oxc_semantic/tests/main.rs
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/catch/inherited-scope.ts
---
[
{
"children": [
{
"children": [],
"flag": "ScopeFlags(StrictMode)",
"id": 1,
"node": "BlockStatement",
"symbols": []
},
{
"children": [
{
"children": [],
"flag": "ScopeFlags(StrictMode)",
"id": 3,
"node": "BlockStatement",
"symbols": [
{
"flag": "SymbolFlags(FunctionScopedVariable | CatchVariable)",
"id": 1,
"name": "e",
"node": "CatchParameter",
"references": []
}
]
}
],
"flag": "ScopeFlags(StrictMode | CatchClause)",
"id": 2,
"node": "CatchClause",
"symbols": [
{
"flag": "SymbolFlags(FunctionScopedVariable | CatchVariable)",
"id": 1,
"name": "e",
"node": "CatchParameter",
"references": []
}
]
}
],
"flag": "ScopeFlags(StrictMode | Top)",
"id": 0,
"node": "Program",
"symbols": [
{
"flag": "SymbolFlags(BlockScopedVariable | ConstVariable)",
"id": 0,
"name": "a",
"node": "VariableDeclarator",
"references": [
{
"flag": "ReferenceFlag(Read)",
"id": 0,
"name": "a",
"node_id": 12
}
]
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const a = 1;
try {
} catch (e) {
a;
}
Loading

0 comments on commit 48724a0

Please sign in to comment.