fix(es/parser): Fix failure of TS instantiation followed by satisfies (#9583)

**Related issue:**

it's already ok when followed by `as`.

Closes https://github.com/swc-project/swc/issues/8627
This commit is contained in:
CPunisher 2024-10-01 10:41:58 +08:00 committed by GitHub
parent 74e3d0466a
commit 77900d808e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 257 additions and 1 deletions

View File

@ -0,0 +1,6 @@
---
swc_ecma_parser: patch
swc_core: patch
---
fix(es/parser): Fix failure of TS instantiation followed by satisfies

View File

@ -1245,7 +1245,7 @@ impl<I: Tokens> Parser<I> {
)
.map(|expr| (expr.into(), true))
.map(Some)
} else if is_one_of!(p, '=', "as") {
} else if is_one_of!(p, '=', "as", "satisfies") {
Ok(Some((
TsInstantiation {
span: span!(p, start),

View File

@ -0,0 +1,3 @@
class Module<T> {}
export default Module<number> as unknown;

View File

@ -0,0 +1,122 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 62
},
"body": [
{
"type": "ClassDeclaration",
"identifier": {
"type": "Identifier",
"span": {
"start": 7,
"end": 13
},
"ctxt": 0,
"value": "Module",
"optional": false
},
"declare": false,
"span": {
"start": 1,
"end": 19
},
"ctxt": 0,
"decorators": [],
"body": [],
"superClass": null,
"isAbstract": false,
"typeParams": {
"type": "TsTypeParameterDeclaration",
"span": {
"start": 13,
"end": 16
},
"parameters": [
{
"type": "TsTypeParameter",
"span": {
"start": 14,
"end": 15
},
"name": {
"type": "Identifier",
"span": {
"start": 14,
"end": 15
},
"ctxt": 0,
"value": "T",
"optional": false
},
"in": false,
"out": false,
"const": false,
"constraint": null,
"default": null
}
]
},
"superTypeParams": null,
"implements": []
},
{
"type": "ExportDefaultExpression",
"span": {
"start": 21,
"end": 62
},
"expression": {
"type": "TsAsExpression",
"span": {
"start": 36,
"end": 61
},
"expression": {
"type": "TsInstantiation",
"span": {
"start": 36,
"end": 50
},
"expression": {
"type": "Identifier",
"span": {
"start": 36,
"end": 42
},
"ctxt": 0,
"value": "Module",
"optional": false
},
"typeArguments": {
"type": "TsTypeParameterInstantiation",
"span": {
"start": 42,
"end": 50
},
"params": [
{
"type": "TsKeywordType",
"span": {
"start": 43,
"end": 49
},
"kind": "number"
}
]
}
},
"typeAnnotation": {
"type": "TsKeywordType",
"span": {
"start": 54,
"end": 61
},
"kind": "unknown"
}
}
}
],
"interpreter": null
}

View File

@ -0,0 +1,3 @@
class Module<T> {}
export default Module<number> satisfies unknown;

View File

@ -0,0 +1,122 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 69
},
"body": [
{
"type": "ClassDeclaration",
"identifier": {
"type": "Identifier",
"span": {
"start": 7,
"end": 13
},
"ctxt": 0,
"value": "Module",
"optional": false
},
"declare": false,
"span": {
"start": 1,
"end": 19
},
"ctxt": 0,
"decorators": [],
"body": [],
"superClass": null,
"isAbstract": false,
"typeParams": {
"type": "TsTypeParameterDeclaration",
"span": {
"start": 13,
"end": 16
},
"parameters": [
{
"type": "TsTypeParameter",
"span": {
"start": 14,
"end": 15
},
"name": {
"type": "Identifier",
"span": {
"start": 14,
"end": 15
},
"ctxt": 0,
"value": "T",
"optional": false
},
"in": false,
"out": false,
"const": false,
"constraint": null,
"default": null
}
]
},
"superTypeParams": null,
"implements": []
},
{
"type": "ExportDefaultExpression",
"span": {
"start": 21,
"end": 69
},
"expression": {
"type": "TsSatisfiesExpression",
"span": {
"start": 36,
"end": 68
},
"expression": {
"type": "TsInstantiation",
"span": {
"start": 36,
"end": 50
},
"expression": {
"type": "Identifier",
"span": {
"start": 36,
"end": 42
},
"ctxt": 0,
"value": "Module",
"optional": false
},
"typeArguments": {
"type": "TsTypeParameterInstantiation",
"span": {
"start": 42,
"end": 50
},
"params": [
{
"type": "TsKeywordType",
"span": {
"start": 43,
"end": 49
},
"kind": "number"
}
]
}
},
"typeAnnotation": {
"type": "TsKeywordType",
"span": {
"start": 61,
"end": 68
},
"kind": "unknown"
}
}
}
],
"interpreter": null
}