Skip to content

Commit de862aa

Browse files
author
Song Gao
committed
fix(binder): bind symbol for declare function
1 parent ac097e9 commit de862aa

File tree

6 files changed

+80
-7
lines changed

6 files changed

+80
-7
lines changed

crates/oxc_semantic/src/binder.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ impl<'a> Binder<'a> for Function<'a> {
161161
builder.current_node_id,
162162
);
163163
ident.symbol_id.set(Some(symbol_id));
164-
} else if self.r#type == FunctionType::FunctionDeclaration {
164+
} else if self.r#type == FunctionType::FunctionDeclaration
165+
|| self.r#type == FunctionType::TSDeclareFunction
166+
{
165167
// The visitor is already inside the function scope,
166168
// retrieve the parent scope for the function id to bind to.
167169

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

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
3+
assertion_line: 147
34
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/decorators/class-deco-with-object-param.ts
45
snapshot_kind: text
56
---
@@ -14,7 +15,7 @@ snapshot_kind: text
1415
"symbols": [
1516
{
1617
"flags": "SymbolFlags(FunctionScopedVariable)",
17-
"id": 0,
18+
"id": 1,
1819
"name": "param",
1920
"node": "BindingRestElement",
2021
"references": []
@@ -33,9 +34,23 @@ snapshot_kind: text
3334
"id": 0,
3435
"node": "Program",
3536
"symbols": [
37+
{
38+
"flags": "SymbolFlags(BlockScopedVariable | Function)",
39+
"id": 0,
40+
"name": "deco",
41+
"node": "Function(deco)",
42+
"references": [
43+
{
44+
"flags": "ReferenceFlags(Read)",
45+
"id": 0,
46+
"name": "deco",
47+
"node_id": 19
48+
}
49+
]
50+
},
3651
{
3752
"flags": "SymbolFlags(Class)",
38-
"id": 1,
53+
"id": 2,
3954
"name": "Foo",
4055
"node": "Class(Foo)",
4156
"references": []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
source: crates/oxc_semantic/tests/main.rs
3+
assertion_line: 147
4+
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/function-declaration/declare-function.ts
5+
snapshot_kind: text
6+
---
7+
[
8+
{
9+
"children": [
10+
{
11+
"children": [],
12+
"flags": "ScopeFlags(StrictMode | Function)",
13+
"id": 1,
14+
"node": "Function(A)",
15+
"symbols": []
16+
},
17+
{
18+
"children": [],
19+
"flags": "ScopeFlags(StrictMode | Function)",
20+
"id": 2,
21+
"node": "Function(B)",
22+
"symbols": []
23+
}
24+
],
25+
"flags": "ScopeFlags(StrictMode | Top)",
26+
"id": 0,
27+
"node": "Program",
28+
"symbols": [
29+
{
30+
"flags": "SymbolFlags(BlockScopedVariable | Function)",
31+
"id": 0,
32+
"name": "A",
33+
"node": "Function(A)",
34+
"references": []
35+
},
36+
{
37+
"flags": "SymbolFlags(BlockScopedVariable | Function)",
38+
"id": 1,
39+
"name": "B",
40+
"node": "Function(B)",
41+
"references": []
42+
}
43+
]
44+
}
45+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare function A(): void;
2+
function B(): void { };

crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/function-declaration/overload.snap

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
3+
assertion_line: 147
34
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/function-declaration/overload.ts
45
snapshot_kind: text
56
---
@@ -14,14 +15,14 @@ snapshot_kind: text
1415
"symbols": [
1516
{
1617
"flags": "SymbolFlags(FunctionScopedVariable)",
17-
"id": 0,
18+
"id": 1,
1819
"name": "a",
1920
"node": "FormalParameter(a)",
2021
"references": []
2122
},
2223
{
2324
"flags": "SymbolFlags(FunctionScopedVariable)",
24-
"id": 1,
25+
"id": 2,
2526
"name": "b",
2627
"node": "FormalParameter(b)",
2728
"references": []
@@ -64,7 +65,7 @@ snapshot_kind: text
6465
"symbols": [
6566
{
6667
"flags": "SymbolFlags(BlockScopedVariable | Function)",
67-
"id": 2,
68+
"id": 0,
6869
"name": "foo",
6970
"node": "Function(foo)",
7071
"references": []

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
source: crates/oxc_semantic/tests/main.rs
3+
assertion_line: 147
34
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaration/literal-type3.ts
45
snapshot_kind: text
56
---
@@ -28,7 +29,7 @@ snapshot_kind: text
2829
"symbols": [
2930
{
3031
"flags": "SymbolFlags(FunctionScopedVariable)",
31-
"id": 2,
32+
"id": 3,
3233
"name": "value",
3334
"node": "FormalParameter(value)",
3435
"references": []
@@ -67,6 +68,13 @@ snapshot_kind: text
6768
"node_id": 31
6869
}
6970
]
71+
},
72+
{
73+
"flags": "SymbolFlags(BlockScopedVariable | Function)",
74+
"id": 2,
75+
"name": "setAlignment",
76+
"node": "Function(setAlignment)",
77+
"references": []
7078
}
7179
]
7280
}

0 commit comments

Comments
 (0)