Skip to content

Commit f51bc54

Browse files
committed
fix(semantic): allow arguments as argument name inside TSFunctionType
1 parent ee761de commit f51bc54

File tree

6 files changed

+18
-9
lines changed

6 files changed

+18
-9
lines changed

crates/oxc_semantic/src/checker/javascript.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ pub fn check_binding_identifier(ident: &BindingIdentifier, ctx: &SemanticBuilder
116116
// declare function f(eval: number, arguments: number): number; // OK
117117
// declare function f(...eval): number; // OK
118118
// declare function f(...arguments): number; // OK
119+
// type K = (arguments: any[]) => void; // OK
119120
// declare function g({eval, arguments}: {eval: number, arguments: number}): number; // Error
120121
// declare function h([eval, arguments]: [number, number]): number; // Error
121122
let is_declare_function = |kind: &AstKind| {
@@ -126,7 +127,14 @@ pub fn check_binding_identifier(ident: &BindingIdentifier, ctx: &SemanticBuilder
126127
let parent = ctx.nodes.parent_node(ctx.current_node_id);
127128
let is_ok = match parent.kind() {
128129
AstKind::Function(func) => matches!(func.r#type, FunctionType::TSDeclareFunction),
129-
AstKind::FormalParameter(_) => is_declare_function(&ctx.nodes.parent_kind(parent.id())),
130+
AstKind::FormalParameter(_) => {
131+
is_declare_function(&ctx.nodes.parent_kind(parent.id()))
132+
|| ctx
133+
.nodes
134+
.ancestor_kinds(parent.id())
135+
.nth(1)
136+
.is_some_and(|node| matches!(node, AstKind::TSFunctionType(_)))
137+
}
130138
AstKind::BindingRestElement(_) => {
131139
let grand_parent = ctx.nodes.parent_node(parent.id());
132140
matches!(grand_parent.kind(), AstKind::FormalParameters(_))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type K = (arguments: any[]) => void;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
codegen_misc Summary:
2-
AST Parsed : 43/43 (100.00%)
3-
Positive Passed: 43/43 (100.00%)
2+
AST Parsed : 44/44 (100.00%)
3+
Positive Passed: 44/44 (100.00%)

tasks/coverage/snapshots/parser_misc.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
parser_misc Summary:
2-
AST Parsed : 43/43 (100.00%)
3-
Positive Passed: 43/43 (100.00%)
2+
AST Parsed : 44/44 (100.00%)
3+
Positive Passed: 44/44 (100.00%)
44
Negative Passed: 47/47 (100.00%)
55

66
× Identifier `b` has already been declared

tasks/coverage/snapshots/semantic_misc.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
semantic_misc Summary:
2-
AST Parsed : 43/43 (100.00%)
3-
Positive Passed: 27/43 (62.79%)
2+
AST Parsed : 44/44 (100.00%)
3+
Positive Passed: 28/44 (63.64%)
44
semantic Error: tasks/coverage/misc/pass/oxc-11593.ts
55
Scope children mismatch:
66
after transform: ScopeId(0): [ScopeId(1)]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
transformer_misc Summary:
2-
AST Parsed : 43/43 (100.00%)
3-
Positive Passed: 43/43 (100.00%)
2+
AST Parsed : 44/44 (100.00%)
3+
Positive Passed: 44/44 (100.00%)

0 commit comments

Comments
 (0)