Skip to content

Commit 3a835b4

Browse files
committed
feat(semantic): add symbol_id to ts function type binding idents
1 parent bec7a7d commit 3a835b4

File tree

25 files changed

+2478
-2331
lines changed

25 files changed

+2478
-2331
lines changed

crates/oxc_linter/src/rules/eslint/no_unused_vars/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,15 @@ impl NoUnusedVars {
357357
return true;
358358
}
359359

360+
let node_id = symbol.declaration().id();
361+
if flags.intersects(SymbolFlags::FunctionScopedVariable)
362+
&& let AstKind::FormalParameters(formal_parameters) =
363+
symbol.nodes().parent_node(node_id).kind()
364+
&& formal_parameters.kind.is_signature()
365+
{
366+
return true;
367+
}
368+
360369
// In some cases (e.g. "jsx": "react" in tsconfig.json), React imports
361370
// get used in generated code. We don't have a way to detect
362371
// "jsxPragmas" or whether TSX files are using "jsx": "react-jsx", so we

crates/oxc_semantic/src/binder.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,10 @@ impl<'a> Binder<'a> for BindingRestElement<'a> {
185185
// Binds the FormalParameters's rest of a function or method.
186186
fn bind(&self, builder: &mut SemanticBuilder) {
187187
let parent_kind = builder.nodes.parent_kind(builder.current_node_id);
188-
let AstKind::FormalParameters(parameters) = parent_kind else {
188+
let AstKind::FormalParameters(_) = parent_kind else {
189189
return;
190190
};
191191

192-
if parameters.kind.is_signature() {
193-
return;
194-
}
195-
196192
let includes = SymbolFlags::FunctionScopedVariable;
197193
let excludes =
198194
SymbolFlags::FunctionScopedVariable | SymbolFlags::FunctionScopedVariableExcludes;
@@ -209,10 +205,6 @@ impl<'a> Binder<'a> for FormalParameter<'a> {
209205
let parent_kind = builder.nodes.parent_kind(builder.current_node_id);
210206
let AstKind::FormalParameters(parameters) = parent_kind else { unreachable!() };
211207

212-
if parameters.kind.is_signature() {
213-
return;
214-
}
215-
216208
let includes = SymbolFlags::FunctionScopedVariable;
217209

218210
let is_not_allowed_duplicate_parameters = matches!(

crates/oxc_semantic/tests/fixtures/typescript-eslint/decorators/class-deco-with-object-param.snap

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/decorators/clas
1212
"flags": "ScopeFlags(StrictMode)",
1313
"id": 2,
1414
"node": "TSFunctionType",
15-
"symbols": []
15+
"symbols": [
16+
{
17+
"flags": "SymbolFlags(FunctionScopedVariable)",
18+
"id": 2,
19+
"name": "param",
20+
"node": "BindingRestElement",
21+
"references": []
22+
}
23+
]
1624
}
1725
],
1826
"flags": "ScopeFlags(StrictMode | Function)",
@@ -56,7 +64,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/decorators/clas
5664
},
5765
{
5866
"flags": "SymbolFlags(Class)",
59-
"id": 2,
67+
"id": 3,
6068
"name": "Foo",
6169
"node": "Class(Foo)",
6270
"references": []

crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaration/conditional3.snap

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
1414
"flags": "ScopeFlags(StrictMode)",
1515
"id": 3,
1616
"node": "TSFunctionType",
17-
"symbols": []
17+
"symbols": [
18+
{
19+
"flags": "SymbolFlags(FunctionScopedVariable)",
20+
"id": 2,
21+
"name": "k",
22+
"node": "FormalParameter(k)",
23+
"references": []
24+
}
25+
]
1826
}
1927
],
2028
"flags": "ScopeFlags(StrictMode | TsConditional)",
@@ -23,7 +31,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
2331
"symbols": [
2432
{
2533
"flags": "SymbolFlags(TypeParameter)",
26-
"id": 2,
34+
"id": 3,
2735
"name": "I",
2836
"node": "TSTypeParameter(I)",
2937
"references": [

crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaration/conditional5.snap

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,29 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
1616
"flags": "ScopeFlags(StrictMode)",
1717
"id": 4,
1818
"node": "TSFunctionType",
19-
"symbols": []
19+
"symbols": [
20+
{
21+
"flags": "SymbolFlags(FunctionScopedVariable)",
22+
"id": 3,
23+
"name": "arg2",
24+
"node": "FormalParameter(arg2)",
25+
"references": []
26+
}
27+
]
2028
}
2129
],
2230
"flags": "ScopeFlags(StrictMode)",
2331
"id": 3,
2432
"node": "TSFunctionType",
25-
"symbols": []
33+
"symbols": [
34+
{
35+
"flags": "SymbolFlags(FunctionScopedVariable)",
36+
"id": 2,
37+
"name": "arg",
38+
"node": "FormalParameter(arg)",
39+
"references": []
40+
}
41+
]
2642
}
2743
],
2844
"flags": "ScopeFlags(StrictMode | TsConditional)",
@@ -31,7 +47,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
3147
"symbols": [
3248
{
3349
"flags": "SymbolFlags(TypeParameter)",
34-
"id": 2,
50+
"id": 4,
3551
"name": "I",
3652
"node": "TSTypeParameter(I)",
3753
"references": [

crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaration/function/constructor-generics1.snap

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
1919
"flags": "ScopeFlags(StrictMode)",
2020
"id": 3,
2121
"node": "TSConstructorType",
22-
"symbols": []
22+
"symbols": [
23+
{
24+
"flags": "SymbolFlags(FunctionScopedVariable)",
25+
"id": 3,
26+
"name": "arg",
27+
"node": "FormalParameter(arg)",
28+
"references": []
29+
}
30+
]
2331
}
2432
],
2533
"flags": "ScopeFlags(StrictMode)",

crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaration/function/constructor-generics2.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
3333
"node_id": 16
3434
}
3535
]
36+
},
37+
{
38+
"flags": "SymbolFlags(FunctionScopedVariable)",
39+
"id": 3,
40+
"name": "arg",
41+
"node": "FormalParameter(arg)",
42+
"references": []
3643
}
3744
]
3845
}

crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaration/function/constructor.snap

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
1919
"flags": "ScopeFlags(StrictMode)",
2020
"id": 3,
2121
"node": "TSConstructorType",
22-
"symbols": []
22+
"symbols": [
23+
{
24+
"flags": "SymbolFlags(FunctionScopedVariable)",
25+
"id": 2,
26+
"name": "arg",
27+
"node": "FormalParameter(arg)",
28+
"references": []
29+
}
30+
]
2331
}
2432
],
2533
"flags": "ScopeFlags(StrictMode)",

crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaration/function/function-generics1.snap

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
1919
"flags": "ScopeFlags(StrictMode)",
2020
"id": 3,
2121
"node": "TSFunctionType",
22-
"symbols": []
22+
"symbols": [
23+
{
24+
"flags": "SymbolFlags(FunctionScopedVariable)",
25+
"id": 3,
26+
"name": "arg",
27+
"node": "FormalParameter(arg)",
28+
"references": []
29+
}
30+
]
2331
}
2432
],
2533
"flags": "ScopeFlags(StrictMode)",

crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaration/function/function-generics2.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
3333
"node_id": 16
3434
}
3535
]
36+
},
37+
{
38+
"flags": "SymbolFlags(FunctionScopedVariable)",
39+
"id": 3,
40+
"name": "arg",
41+
"node": "FormalParameter(arg)",
42+
"references": []
3643
}
3744
]
3845
}

0 commit comments

Comments
 (0)