Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ts]No syntax error is thrown for invalid type annotation #12180

Closed
1 task
sosukesuzuki opened this issue Oct 15, 2020 · 2 comments · Fixed by #12185
Closed
1 task

[ts]No syntax error is thrown for invalid type annotation #12180

sosukesuzuki opened this issue Oct 15, 2020 · 2 comments · Fixed by #12185
Assignees
Labels
area: typescript i: bug i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser

Comments

@sosukesuzuki
Copy link
Member

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

@sosukesuzuki sosukesuzuki changed the title No syntax error is thrown for invalid type annotation [ts]No syntax error is thrown for invalid type annotation Oct 15, 2020
@babel-bot
Copy link
Collaborator

Hey @sosukesuzuki! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@existentialism
Copy link
Member

@sosukesuzuki Derp, I know what it is. I'll get a fix up shortly.

@existentialism existentialism self-assigned this Oct 15, 2020
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jan 16, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: typescript i: bug i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants