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-template-compiler fails when parsing a template with a comment as a root node. #9407

Closed
elevatebart opened this issue Feb 2, 2019 · 1 comment

Comments

@elevatebart
Copy link
Contributor

elevatebart commented Feb 2, 2019

Version

2.5.22

Reproduction link

https://codesandbox.io/s/52k2p9po54

Steps to reproduce

Go to the codesandbox.
Try to parse the given template with comments on.

<template>
 <!-- here is a nice component template -->
 <button class="buttonComponent">click</button>
</template>

What is expected?

The comment AST node should be attached to the root object.

What is actually happening?

node_modules/vue-template-compiler/build.js:2469:21)
TypeError: Cannot read property 'children' of undefined

(currentParent is undefined)

I am going to try my hand at a PR. Wish me luck ;)

@elevatebart
Copy link
Contributor Author

Ideally we would be able to retrieve this comment the normal way.
But this would mean creating an extra parentNode that I guess we do not want.

How about using the same syntax as babel parser? Use the "leadingComment" property for the node if there is a next sibling. traiingComment the same way.
This way, no need to attach it to a root that does not exist.

The fix would then be 2 fold.

  1. check if there is a currentParent and if there is not, drop the comment.
  2. add a leadingComment and a trailingComment property to each node.

My PR will tke care of 1. I can create another issue for 2.

Lostlover pushed a commit to Lostlover/vue that referenced this issue Dec 10, 2019
…uejs#9408)

In SFC templates, we are allowed to add comments to the root node. If parsing with comments flag
true, we are not anymore. This ignores the root comments in case they cannot be added.

fix vuejs#9407
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant