-
-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(semantic): infer ReferenceFlags from Visit methods
- Loading branch information
Showing
5 changed files
with
271 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
crates/oxc_semantic/tests/fixtures/oxc/assignment/nested-assignment.snap.new
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] |
120 changes: 120 additions & 0 deletions
120
crates/oxc_semantic/tests/fixtures/oxc/assignment/read-write-operators.snap.new
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] |
20 changes: 20 additions & 0 deletions
20
crates/oxc_semantic/tests/fixtures/oxc/assignment/read-write-operators.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
72 changes: 72 additions & 0 deletions
72
crates/oxc_semantic/tests/fixtures/oxc/ts/assignments/ts-syntax-left-hand.snap.new
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] |
11 changes: 11 additions & 0 deletions
11
crates/oxc_semantic/tests/fixtures/oxc/ts/assignments/ts-syntax-left-hand.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |