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]: Unexpected error thrown when parsing broken template literal #14054

Closed
1 task
fisker opened this issue Dec 14, 2021 · 1 comment 路 Fixed by #14055
Closed
1 task

[Bug]: Unexpected error thrown when parsing broken template literal #14054

fisker opened this issue Dec 14, 2021 · 1 comment 路 Fixed by #14055
Labels
i: needs triage i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@fisker
Copy link
Contributor

fisker commented Dec 14, 2021

馃捇

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

require('@babel/parser').parse('`\\u{prettier}`', {tokens: true, errorRecovery:true})

Configuration file name

No response

Configuration

No response

Current and expected behavior

Uncaught TypeError: Cannot read properties of null (reading 'charCodeAt')
    at babel7CompatTokens (<CWD>\node_modules\@babel\parser\lib\index.js:13359:21)
    at Parser.parseTopLevel (<CWD>\node_modules\@babel\parser\lib\index.js:13430:44)
    at Parser.parse (<CWD>\node_modules\@babel\parser\lib\index.js:15202:10)
    at Object.parse (<CWD>\node_modules\@babel\parser\lib\index.js:15254:38)

Environment

  • Babel v7.16.5

Possible solution

No response

Additional context

This only happens, when {tokens: true, errorRecovery:true}

 require('@babel/parser').parse('`\\u{prettier}`', {errorRecovery:true})
Node {
  type: 'File',
  start: 0,
  end: 14,
  loc: SourceLocation {
    start: Position { line: 1, column: 0 },
    end: Position { line: 1, column: 14 },
    filename: undefined,
    identifierName: undefined
  },
  errors: [
    SyntaxError: Invalid escape sequence in template. (1:2)
 ...
 require('@babel/parser').parse('`\\u{prettier}`', {tokens: true})
Uncaught [SyntaxError: Invalid escape sequence in template. (1:2)
] {
  loc: Position { line: 1, column: 2 },
  pos: 2,
  code: 'BABEL_PARSER_SYNTAX_ERROR',
  reasonCode: 'InvalidEscapeSequenceTemplate'
}

I believe this caused by #13919 @JLHwung

@babel-bot
Copy link
Collaborator

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

@fisker fisker changed the title [Bug]: Unexpected error thrown [Bug]: Unexpected error thrown when parsing broken template literal Dec 14, 2021
@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 Mar 16, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: needs triage i: regression 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.

3 participants