-
-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(semantic): resolve function return type to function parent scope
closes #6387
- Loading branch information
Showing
5 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
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
60 changes: 60 additions & 0 deletions
60
crates/oxc_semantic/tests/fixtures/oxc/function/arrow_return_type.snap
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,60 @@ | ||
--- | ||
source: crates/oxc_semantic/tests/main.rs | ||
input_file: crates/oxc_semantic/tests/fixtures/oxc/function/arrow_return_type.ts | ||
snapshot_kind: text | ||
--- | ||
[ | ||
{ | ||
"children": [ | ||
{ | ||
"children": [], | ||
"flags": "ScopeFlags(StrictMode)", | ||
"id": 1, | ||
"node": "TSTypeAliasDeclaration", | ||
"symbols": [] | ||
}, | ||
{ | ||
"children": [ | ||
{ | ||
"children": [], | ||
"flags": "ScopeFlags(StrictMode)", | ||
"id": 3, | ||
"node": "TSTypeAliasDeclaration", | ||
"symbols": [] | ||
} | ||
], | ||
"flags": "ScopeFlags(StrictMode | Function | Arrow)", | ||
"id": 2, | ||
"node": "ArrowFunctionExpression", | ||
"symbols": [ | ||
{ | ||
"flags": "SymbolFlags(TypeAlias)", | ||
"id": 1, | ||
"name": "T", | ||
"node": "TSTypeAliasDeclaration", | ||
"references": [] | ||
} | ||
] | ||
} | ||
], | ||
"flags": "ScopeFlags(StrictMode | Top)", | ||
"id": 0, | ||
"node": "Program", | ||
"symbols": [ | ||
{ | ||
"flags": "SymbolFlags(Export | TypeAlias)", | ||
"id": 0, | ||
"name": "T", | ||
"node": "TSTypeAliasDeclaration", | ||
"references": [ | ||
{ | ||
"flags": "ReferenceFlags(Type)", | ||
"id": 0, | ||
"name": "T", | ||
"node_id": 13 | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] |
5 changes: 5 additions & 0 deletions
5
crates/oxc_semantic/tests/fixtures/oxc/function/arrow_return_type.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,5 @@ | ||
export type T = void; | ||
|
||
((): T => { // Return type `T` resolves to top level `T`, not `T` in function body. | ||
type T = string; | ||
}); |
60 changes: 60 additions & 0 deletions
60
crates/oxc_semantic/tests/fixtures/oxc/function/function_return_type.snap
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,60 @@ | ||
--- | ||
source: crates/oxc_semantic/tests/main.rs | ||
input_file: crates/oxc_semantic/tests/fixtures/oxc/function/function_return_type.ts | ||
snapshot_kind: text | ||
--- | ||
[ | ||
{ | ||
"children": [ | ||
{ | ||
"children": [], | ||
"flags": "ScopeFlags(StrictMode)", | ||
"id": 1, | ||
"node": "TSTypeAliasDeclaration", | ||
"symbols": [] | ||
}, | ||
{ | ||
"children": [ | ||
{ | ||
"children": [], | ||
"flags": "ScopeFlags(StrictMode)", | ||
"id": 3, | ||
"node": "TSTypeAliasDeclaration", | ||
"symbols": [] | ||
} | ||
], | ||
"flags": "ScopeFlags(StrictMode | Function)", | ||
"id": 2, | ||
"node": "Function(<anonymous>)", | ||
"symbols": [ | ||
{ | ||
"flags": "SymbolFlags(TypeAlias)", | ||
"id": 1, | ||
"name": "T", | ||
"node": "TSTypeAliasDeclaration", | ||
"references": [] | ||
} | ||
] | ||
} | ||
], | ||
"flags": "ScopeFlags(StrictMode | Top)", | ||
"id": 0, | ||
"node": "Program", | ||
"symbols": [ | ||
{ | ||
"flags": "SymbolFlags(Export | TypeAlias)", | ||
"id": 0, | ||
"name": "T", | ||
"node": "TSTypeAliasDeclaration", | ||
"references": [ | ||
{ | ||
"flags": "ReferenceFlags(Type)", | ||
"id": 0, | ||
"name": "T", | ||
"node_id": 13 | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] |
5 changes: 5 additions & 0 deletions
5
crates/oxc_semantic/tests/fixtures/oxc/function/function_return_type.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,5 @@ | ||
export type T = void; | ||
|
||
(function (): T { // Return type `T` resolves to top level `T`, not `T` in function body. | ||
type T = string; | ||
}); |