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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Parsing doesn't finish for unmatched bracket in TypeScript type expression #14298

Closed
1 task
woongsikchoi opened this issue Feb 23, 2022 · 1 comment 路 Fixed by #14293
Closed
1 task
Labels
i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@woongsikchoi
Copy link

馃捇

  • Would you like to work on a fix?

How are you using Babel?

@babel/cli

Input code

type Foo = ([;

Configuration file name

babel.config.json

Configuration

{
  "presets": ["@babel/preset-typescript"]
}

Current and expected behavior

Current behavior - parsing does not finish
Expected behavior - a syntax error should be thrown

Environment

System:
OS: Linux 4.4 Ubuntu 20.04.2 LTS (Focal Fossa)
Binaries:
Node: 16.13.1 - ~/local/lib/node-v16.13.1-linux-x64/bin/node
npm: 8.1.2 - ~/local/lib/node-v16.13.1-linux-x64/bin/npm
npmPackages:
@babel/cli: ^7.17.6 => 7.17.6
@babel/core: ^7.17.5 => 7.17.5
@babel/preset-typescript: ^7.16.7 => 7.16.7

Possible solution

The problem seems to occur at tsSkipParameterStart() in packages/babel-parser/src/plugins/typescript/index.js

      if (this.match(tt.bracketL)) {
        let braceStackCounter = 1;
        this.next();

        while (braceStackCounter > 0) {
          if (this.match(tt.bracketL)) {
            ++braceStackCounter;
          } else if (this.match(tt.bracketR)) {
            --braceStackCounter;
          }
          this.next();
        }
        return true;
      }

In the above while loop, a syntax error should be thrown when tt.eof is matched.
(or maybe just returning false would work?)

Additional context

No response

@babel-bot
Copy link
Collaborator

Hey @woongsikchoi! 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.

@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 May 26, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants