-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[ts]No syntax error is thrown for invalid type annotation #12180
Copy link
Copy link
Closed
Labels
area: typescripti: regressionoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: parser
Description
Bug Report
- I would like to work on a fix!
Current behavior
Successful parsing:
AST
{
"type": "File",
"start": 0,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 5
}
},
"errors": [],
"program": {
"type": "Program",
"start": 0,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 5
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 5
}
},
"expression": {
"type": "TSTypeCastExpression",
"start": 1,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 4
}
},
"extra": {
"parenthesized": true,
"parenStart": 0
},
"expression": {
"type": "Identifier",
"start": 1,
"end": 2,
"loc": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 1,
"column": 2
},
"identifierName": "a"
},
"name": "a"
},
"typeAnnotation": {
"type": "TSTypeAnnotation",
"start": 2,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 4
}
},
"typeAnnotation": {
"type": "TSTypeReference",
"start": 3,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 4
}
},
"typeName": {
"type": "Identifier",
"start": 3,
"end": 4,
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 4
},
"identifierName": "b"
},
"name": "b"
}
}
}
}
}
],
"directives": []
},
"comments": []
}Input Code
(a:b);Expected behavior
Throw syntax error Did not expect a type annotation here..
Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
Environment
@babel/parser:7.12.0
Possible Solution
Additional context
Found from working on prettier/prettier#9408
This is a 7.12.0 regression
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area: typescripti: regressionoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issueA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: parser