Skip to content

Commit

Permalink
refactor(semantic): infer ReferenceFlags from Visit methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Nov 21, 2024
1 parent be152c0 commit f3b83b8
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
source: crates/oxc_semantic/tests/main.rs
assertion_line: 146
input_file: crates/oxc_semantic/tests/fixtures/oxc/assignment/nested-assignment.ts
snapshot_kind: text
---
[
{
"children": [],
"flags": "ScopeFlags(StrictMode | Top)",
"id": 0,
"node": "Program",
"symbols": [
{
"flags": "SymbolFlags(BlockScopedVariable)",
"id": 0,
"name": "y",
"node": "VariableDeclarator(y)",
"references": [
{
"flags": "ReferenceFlags(Write)",
"id": 0,
"name": "y",
"node_id": 10
},
{
"flags": "ReferenceFlags(Write)",
"id": 1,
"name": "y",
"node_id": 23
},
{
"flags": "ReferenceFlags(Write)",
"id": 2,
"name": "y",
"node_id": 41
},
{
"flags": "ReferenceFlags(Read)",
"id": 4,
"name": "y",
"node_id": 51
}
]
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
---
source: crates/oxc_semantic/tests/main.rs
assertion_line: 146
input_file: crates/oxc_semantic/tests/fixtures/oxc/assignment/read-write-operators.ts
snapshot_kind: text
---
[
{
"children": [],
"flags": "ScopeFlags(StrictMode | Top)",
"id": 0,
"node": "Program",
"symbols": [
{
"flags": "SymbolFlags(BlockScopedVariable)",
"id": 0,
"name": "Foo",
"node": "VariableDeclarator(Foo)",
"references": [
{
"flags": "ReferenceFlags(Write)",
"id": 0,
"name": "Foo",
"node_id": 9
},
{
"flags": "ReferenceFlags(Read | Write)",
"id": 1,
"name": "Foo",
"node_id": 15
},
{
"flags": "ReferenceFlags(Read | Write)",
"id": 2,
"name": "Foo",
"node_id": 21
},
{
"flags": "ReferenceFlags(Read | Write)",
"id": 3,
"name": "Foo",
"node_id": 27
},
{
"flags": "ReferenceFlags(Read | Write)",
"id": 4,
"name": "Foo",
"node_id": 33
},
{
"flags": "ReferenceFlags(Read | Write)",
"id": 5,
"name": "Foo",
"node_id": 39
},
{
"flags": "ReferenceFlags(Read | Write)",
"id": 6,
"name": "Foo",
"node_id": 45
},
{
"flags": "ReferenceFlags(Read | Write)",
"id": 7,
"name": "Foo",
"node_id": 51
},
{
"flags": "ReferenceFlags(Read | Write)",
"id": 8,
"name": "Foo",
"node_id": 57
},
{
"flags": "ReferenceFlags(Read | Write)",
"id": 9,
"name": "Foo",
"node_id": 63
},
{
"flags": "ReferenceFlags(Read | Write)",
"id": 10,
"name": "Foo",
"node_id": 69
},
{
"flags": "ReferenceFlags(Read | Write)",
"id": 11,
"name": "Foo",
"node_id": 75
},
{
"flags": "ReferenceFlags(Read | Write)",
"id": 12,
"name": "Foo",
"node_id": 81
},
{
"flags": "ReferenceFlags(Read | Write)",
"id": 13,
"name": "Foo",
"node_id": 87
},
{
"flags": "ReferenceFlags(Read | Write)",
"id": 14,
"name": "Foo",
"node_id": 93
},
{
"flags": "ReferenceFlags(Read | Write)",
"id": 15,
"name": "Foo",
"node_id": 99
}
]
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
let Foo = 0;
// Only this `Foo` should be considered as a write-only reference
Foo = 1;

// Read | Write
Foo += 1;
Foo -= 1;
Foo *= 1;
Foo /= 1;
Foo %= 1;
Foo **= 1;
Foo <<= 1;
Foo >>= 1;
Foo >>>= 1;
Foo &= 1;
Foo ^= 1;
Foo |= 1;
Foo &&= 1;
Foo ||= 1;
Foo ??= 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
source: crates/oxc_semantic/tests/main.rs
assertion_line: 146
input_file: crates/oxc_semantic/tests/fixtures/oxc/ts/assignments/ts-syntax-left-hand.ts
snapshot_kind: text
---
[
{
"children": [],
"flags": "ScopeFlags(StrictMode | Top)",
"id": 0,
"node": "Program",
"symbols": [
{
"flags": "SymbolFlags(BlockScopedVariable)",
"id": 0,
"name": "Foo",
"node": "VariableDeclarator(Foo)",
"references": [
{
"flags": "ReferenceFlags(Read | Write)",
"id": 0,
"name": "Foo",
"node_id": 12
},
{
"flags": "ReferenceFlags(Read | Write)",
"id": 1,
"name": "Foo",
"node_id": 19
},
{
"flags": "ReferenceFlags(Read | Write)",
"id": 2,
"name": "Foo",
"node_id": 27
},
{
"flags": "ReferenceFlags(Read | Write)",
"id": 3,
"name": "Foo",
"node_id": 35
},
{
"flags": "ReferenceFlags(Read)",
"id": 4,
"name": "Foo",
"node_id": 44
},
{
"flags": "ReferenceFlags(Read)",
"id": 5,
"name": "Foo",
"node_id": 53
},
{
"flags": "ReferenceFlags(Read)",
"id": 6,
"name": "Foo",
"node_id": 63
},
{
"flags": "ReferenceFlags(Read)",
"id": 7,
"name": "Foo",
"node_id": 73
}
]
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let Foo: any= 0;

Foo! += 1;
(<any>Foo) = 1;
(Foo as any) = 1;
(Foo satisfies any) = 1;

Foo.bar! += 1;
(<any>Foo.bar) = 1;
(Foo.bar as any) = 1;
(Foo.bar satisfies any) = 1;

0 comments on commit f3b83b8

Please sign in to comment.