-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(parser): handle import types before function types
This fixes the 'Expected =>, got :' error when parsing function parameters with import type annotations. The issue occurred because the parser was trying to parse import types as function types. By checking for import types first in parse_ts_non_conditional_type, we ensure they are parsed correctly. Fixes #9802 Co-Authored-By: 강동윤 <kdy.1997.dev@gmail.com>
- Loading branch information
1 parent
3397257
commit 078c305
Showing
3 changed files
with
215 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
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,3 @@ | ||
function validate(input: string): import("typia").IValidation<import("typia").Primitive<number>> { | ||
return null as any; | ||
} |
207 changes: 207 additions & 0 deletions
207
crates/swc_ecma_parser/tests/tsc/import-type-param/output.json
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,207 @@ | ||
{ | ||
"type": "Module", | ||
"span": { | ||
"start": 0, | ||
"end": 102, | ||
"ctxt": 0 | ||
}, | ||
"body": [ | ||
{ | ||
"type": "FunctionDeclaration", | ||
"identifier": { | ||
"type": "Identifier", | ||
"span": { | ||
"start": 9, | ||
"end": 17, | ||
"ctxt": 0 | ||
}, | ||
"value": "validate", | ||
"optional": false | ||
}, | ||
"declare": false, | ||
"params": [ | ||
{ | ||
"type": "Parameter", | ||
"span": { | ||
"start": 18, | ||
"end": 31, | ||
"ctxt": 0 | ||
}, | ||
"decorators": [], | ||
"pat": { | ||
"type": "Identifier", | ||
"span": { | ||
"start": 18, | ||
"end": 23, | ||
"ctxt": 0 | ||
}, | ||
"value": "input", | ||
"optional": false, | ||
"typeAnnotation": { | ||
"type": "TsTypeAnnotation", | ||
"span": { | ||
"start": 23, | ||
"end": 31, | ||
"ctxt": 0 | ||
}, | ||
"typeAnnotation": { | ||
"type": "TsKeywordType", | ||
"span": { | ||
"start": 25, | ||
"end": 31, | ||
"ctxt": 0 | ||
}, | ||
"kind": "string" | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"span": { | ||
"start": 0, | ||
"end": 102, | ||
"ctxt": 0 | ||
}, | ||
"body": { | ||
"type": "BlockStatement", | ||
"span": { | ||
"start": 84, | ||
"end": 102, | ||
"ctxt": 0 | ||
}, | ||
"stmts": [ | ||
{ | ||
"type": "ReturnStatement", | ||
"span": { | ||
"start": 90, | ||
"end": 100, | ||
"ctxt": 0 | ||
}, | ||
"argument": { | ||
"type": "TsAsExpression", | ||
"span": { | ||
"start": 90, | ||
"end": 100, | ||
"ctxt": 0 | ||
}, | ||
"expression": { | ||
"type": "NullLiteral", | ||
"span": { | ||
"start": 90, | ||
"end": 94, | ||
"ctxt": 0 | ||
} | ||
}, | ||
"typeAnnotation": { | ||
"type": "TsKeywordType", | ||
"span": { | ||
"start": 96, | ||
"end": 100, | ||
"ctxt": 0 | ||
}, | ||
"kind": "any" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"generator": false, | ||
"async": false, | ||
"typeParameters": null, | ||
"returnType": { | ||
"type": "TsTypeAnnotation", | ||
"span": { | ||
"start": 31, | ||
"end": 83, | ||
"ctxt": 0 | ||
}, | ||
"typeAnnotation": { | ||
"type": "TsImportType", | ||
"span": { | ||
"start": 33, | ||
"end": 83, | ||
"ctxt": 0 | ||
}, | ||
"argument": { | ||
"type": "StringLiteral", | ||
"span": { | ||
"start": 40, | ||
"end": 47, | ||
"ctxt": 0 | ||
}, | ||
"value": "typia", | ||
"raw": "\"typia\"" | ||
}, | ||
"qualifier": { | ||
"type": "Identifier", | ||
"span": { | ||
"start": 48, | ||
"end": 59, | ||
"ctxt": 0 | ||
}, | ||
"value": "IValidation", | ||
"optional": false | ||
}, | ||
"typeArguments": { | ||
"type": "TsTypeParameterInstantiation", | ||
"span": { | ||
"start": 59, | ||
"end": 83, | ||
"ctxt": 0 | ||
}, | ||
"params": [ | ||
{ | ||
"type": "TsImportType", | ||
"span": { | ||
"start": 60, | ||
"end": 82, | ||
"ctxt": 0 | ||
}, | ||
"argument": { | ||
"type": "StringLiteral", | ||
"span": { | ||
"start": 67, | ||
"end": 74, | ||
"ctxt": 0 | ||
}, | ||
"value": "typia", | ||
"raw": "\"typia\"" | ||
}, | ||
"qualifier": { | ||
"type": "Identifier", | ||
"span": { | ||
"start": 75, | ||
"end": 84, | ||
"ctxt": 0 | ||
}, | ||
"value": "Primitive", | ||
"optional": false | ||
}, | ||
"typeArguments": { | ||
"type": "TsTypeParameterInstantiation", | ||
"span": { | ||
"start": 75, | ||
"end": 82, | ||
"ctxt": 0 | ||
}, | ||
"params": [ | ||
{ | ||
"type": "TsKeywordType", | ||
"span": { | ||
"start": 76, | ||
"end": 82, | ||
"ctxt": 0 | ||
}, | ||
"kind": "number" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"interpreter": null | ||
} |