Skip to content

@vue/shared generateCodeFrame can infinite loop, breaking a build process. #3987

@DV8FromTheWorld

Description

@DV8FromTheWorld

Version

3.1.1

Reproduction link

https://github.com/DV8FromTheWorld/vue3-sfc-compiler-bug-repro-template

Steps to reproduce

  1. Pull the repo and npm install it.
  2. Run npm run serve
  3. Observe how the build process gets stuck and never completes when it is handing the BrokenComponent.vue file.

What is expected?

The build should complete and generate warnings about using undecorated <template> elements in Vue3.

What is actually happening?

The build hangs forever due to an infinite loop when generating the code frame to display with the vue-migration compatibility warning.


I originally encountered this problem when transitioning my application from Vue 2.6 to @vue/compat: 3.1.1. The problem surfaced as a Webpack build that would never complete the compilation step. The Vue-loader would successfully separate the SFC into the specific template/script/style portions and pitch them, but when compiling the template (thus generating migration warnings) the system will get stuck.

In the screenshot below observe that the generateCodeFrame will infinite loop.
image

This will infinite loop because j >= lines.length will resolve to true and hit the continue statement without incrementing count any further.

It is possible that the culprit causing this problem is not so much the generateCodeFrame function itself but instead the function calculating the loc for the start and end of the <template> ... </template>. From my testing, the loc.*.column and loc.*.line for both loc.start and loc.end were accurate, however the loc.*.offset for both seemed to be off by 75 - 110 characters. The generateCodeFrame code uses offset as it's source of truth here and thus could be the problem here.

Additionally, another issue caused by this oddity with the offset is that the code frame actually generated has the ^^^^^^^ pointers multiple times in a very confusing fashion. This is caused by the count not exceeding end fast enough.
image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions