Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Nov 26, 2024
1 parent 351f0ed commit dd514ba
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1656,7 +1656,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
self.visit_ts_type_annotation(return_type);
}

if func.params.has_parameter() {
if func.params.has_parameter() || func.return_type.is_some() {
// `function foo({bar: identifier_reference}) {}`
// ^^^^^^^^^^^^^^^^^^^^
// `function foo<SomeType>(v: SomeType): SomeType { return v; }`
Expand Down Expand Up @@ -1731,7 +1731,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
self.visit_ts_type_annotation(return_type);
}

if expr.params.has_parameter() {
if expr.params.has_parameter() || expr.return_type.is_some() {
// `let foo = ({bar: identifier_reference}) => {};`
// ^^^^^^^^^^^^^^^^^^^^
// `let foo = <SomeType>(v: SomeType): SomeType => v;`
Expand Down
102 changes: 102 additions & 0 deletions crates/oxc_semantic/tests/fixtures/oxc/ts/functions/return-type.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
source: crates/oxc_semantic/tests/main.rs
input_file: crates/oxc_semantic/tests/fixtures/oxc/ts/functions/return-type.ts
---
[
{
"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(Foo)",
"symbols": [
{
"flags": "SymbolFlags(TypeAlias)",
"id": 2,
"name": "T",
"node": "TSTypeAliasDeclaration",
"references": []
}
]
},
{
"children": [
{
"children": [],
"flags": "ScopeFlags(StrictMode)",
"id": 5,
"node": "TSTypeAliasDeclaration",
"symbols": []
}
],
"flags": "ScopeFlags(StrictMode | Function | Arrow)",
"id": 4,
"node": "ArrowFunctionExpression",
"symbols": [
{
"flags": "SymbolFlags(TypeAlias)",
"id": 4,
"name": "T",
"node": "TSTypeAliasDeclaration",
"references": []
}
]
}
],
"flags": "ScopeFlags(StrictMode | Top)",
"id": 0,
"node": "Program",
"symbols": [
{
"flags": "SymbolFlags(TypeAlias)",
"id": 0,
"name": "T",
"node": "TSTypeAliasDeclaration",
"references": [
{
"flags": "ReferenceFlags(Type)",
"id": 0,
"name": "T",
"node_id": 12
},
{
"flags": "ReferenceFlags(Type)",
"id": 1,
"name": "T",
"node_id": 27
}
]
},
{
"flags": "SymbolFlags(BlockScopedVariable | Function)",
"id": 1,
"name": "Foo",
"node": "Function(Foo)",
"references": []
},
{
"flags": "SymbolFlags(BlockScopedVariable | ConstVariable)",
"id": 3,
"name": "Bar",
"node": "VariableDeclarator(Bar)",
"references": []
}
]
}
]
12 changes: 12 additions & 0 deletions crates/oxc_semantic/tests/fixtures/oxc/ts/functions/return-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export type T = number;

function Foo(): T {
type T = string;
return 0;
}

const Bar = (): T => {
type T = string;
return 0;
}

0 comments on commit dd514ba

Please sign in to comment.