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

[vue] process hangs due to babel parser error #12112

Closed
lkho opened this issue Jan 18, 2022 · 1 comment · Fixed by #12113
Closed

[vue] process hangs due to babel parser error #12112

lkho opened this issue Jan 18, 2022 · 1 comment · Fixed by #12113
Assignees
Labels
area:multiparser Issues with printing one language inside another, like CSS-in-JS lang:vue Issues affecting Vue type:bug Issues identifying ugly output, or a defect in the program

Comments

@lkho
Copy link

lkho commented Jan 18, 2022

Prettier 2.5.1
Playground1

Input 1:

<template>
  <div>
    <div v-for=" a in ">aaaaa</div>
  </div>
</template>

Output 1:

SyntaxError: Unexpected token (1:1)
> 1 |
    | ^

Playground2

Input 2:

<template>
  <div>
    <div v-for=" a in">aaaaa</div>
  </div>
</template>

Output 2:

TypeError: Cannot destructure property 'left' of '(intermediate value)(...)' as it is undefined.
    at printVueFor (https://prettier.io/lib/standalone.js:40:13897)
    at mz (https://prettier.io/lib/standalone.js:40:16762)
    at Object.yz [as embed] (https://prettier.io/lib/standalone.js:40:19230)
    at Object.printSubtree (https://prettier.io/lib/standalone.js:1:220684)
    at yD (https://prettier.io/lib/standalone.js:1:222198)
    at a (https://prettier.io/lib/standalone.js:1:221787)
    at s (https://prettier.io/lib/standalone.js:1:221610)
    at https://prettier.io/lib/standalone.js:40:9647
    at https://prettier.io/lib/standalone.js:1:219866
    at iD.each (https://prettier.io/lib/standalone.js:1:219698)

Expected behavior:

Output 2 should be the expected behavior of both Input 1 and Input 2 since both inputs is a vue syntax error missing the RHS of a v-for

The current problem is, while the playground here successfully return Output 1 as an error, however, Output 1 is thrown at the babel-parser level. When you try to run this Input 1 yourself in your own CLI, with the default highlighting turned on, the parser error will bubbles to the top and go through the highlighting process by codeFrameColumns (from @babel/code-frame), with an empty text = "" value.

error.codeFrame = codeFrameColumns(text, loc, { highlightCode: true });

When you step into the implementation, the code loops infinitely inside the tokenize* generator function.

TL;DR

So the current behavior is, when you run Input 1 in a CLI terminal (i.e. save the code in a file e.g. abc.vue and run $ prettier abc.vue) with highlighting turned on, the process hangs, and CPU is at 100%.

@fisker fisker added area:multiparser Issues with printing one language inside another, like CSS-in-JS lang:vue Issues affecting Vue type:bug Issues identifying ugly output, or a defect in the program labels Jan 18, 2022
@fisker fisker self-assigned this Jan 18, 2022
@lkho
Copy link
Author

lkho commented Jan 19, 2022

@babel fix: babel/babel#14165

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area:multiparser Issues with printing one language inside another, like CSS-in-JS lang:vue Issues affecting Vue type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants