Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(binder): bind symbol for declare function #8039

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/oxc_semantic/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ impl<'a> Binder<'a> for Function<'a> {
builder.current_node_id,
);
ident.symbol_id.set(Some(symbol_id));
} else if self.r#type == FunctionType::FunctionDeclaration {
} else if self.r#type == FunctionType::FunctionDeclaration
|| self.r#type == FunctionType::TSDeclareFunction
{
// The visitor is already inside the function scope,
// retrieve the parent scope for the function id to bind to.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/oxc_semantic/tests/main.rs
assertion_line: 147
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/decorators/class-deco-with-object-param.ts
snapshot_kind: text
---
Expand All @@ -14,7 +15,7 @@ snapshot_kind: text
"symbols": [
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 0,
"id": 1,
"name": "param",
"node": "BindingRestElement",
"references": []
Expand All @@ -33,9 +34,23 @@ snapshot_kind: text
"id": 0,
"node": "Program",
"symbols": [
{
"flags": "SymbolFlags(BlockScopedVariable | Function)",
"id": 0,
"name": "deco",
"node": "Function(deco)",
"references": [
{
"flags": "ReferenceFlags(Read)",
"id": 0,
"name": "deco",
"node_id": 19
}
]
},
{
"flags": "SymbolFlags(Class)",
"id": 1,
"id": 2,
"name": "Foo",
"node": "Class(Foo)",
"references": []
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
source: crates/oxc_semantic/tests/main.rs
assertion_line: 147
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/function-declaration/declare-function.ts
snapshot_kind: text
---
[
{
"children": [
{
"children": [],
"flags": "ScopeFlags(StrictMode | Function)",
"id": 1,
"node": "Function(A)",
"symbols": []
},
{
"children": [],
"flags": "ScopeFlags(StrictMode | Function)",
"id": 2,
"node": "Function(B)",
"symbols": []
}
],
"flags": "ScopeFlags(StrictMode | Top)",
"id": 0,
"node": "Program",
"symbols": [
{
"flags": "SymbolFlags(BlockScopedVariable | Function)",
"id": 0,
"name": "A",
"node": "Function(A)",
"references": []
},
{
"flags": "SymbolFlags(BlockScopedVariable | Function)",
"id": 1,
"name": "B",
"node": "Function(B)",
"references": []
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function A(): void;
function B(): void { };
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/oxc_semantic/tests/main.rs
assertion_line: 147
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/function-declaration/overload.ts
snapshot_kind: text
---
Expand All @@ -14,14 +15,14 @@ snapshot_kind: text
"symbols": [
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 0,
"id": 1,
"name": "a",
"node": "FormalParameter(a)",
"references": []
},
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 1,
"id": 2,
"name": "b",
"node": "FormalParameter(b)",
"references": []
Expand Down Expand Up @@ -64,7 +65,7 @@ snapshot_kind: text
"symbols": [
{
"flags": "SymbolFlags(BlockScopedVariable | Function)",
"id": 2,
"id": 0,
"name": "foo",
"node": "Function(foo)",
"references": []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/oxc_semantic/tests/main.rs
assertion_line: 147
input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaration/literal-type3.ts
snapshot_kind: text
---
Expand Down Expand Up @@ -28,7 +29,7 @@ snapshot_kind: text
"symbols": [
{
"flags": "SymbolFlags(FunctionScopedVariable)",
"id": 2,
"id": 3,
"name": "value",
"node": "FormalParameter(value)",
"references": []
Expand Down Expand Up @@ -67,6 +68,13 @@ snapshot_kind: text
"node_id": 31
}
]
},
{
"flags": "SymbolFlags(BlockScopedVariable | Function)",
"id": 2,
"name": "setAlignment",
"node": "Function(setAlignment)",
"references": []
}
]
}
Expand Down
Loading