Vue: improve parsing custom blocks with angular-html-parser@1.5.0 - #8153
Conversation
| recognizeSelfClosing: true, | ||
| isTagNameCaseSensitive: true, | ||
| getTagContentType: (tagname) => { | ||
| if (tagname !== "template") { |
There was a problem hiding this comment.
| if (tagname !== "template") { | |
| if (tagname.toLowerCase() !== "template") { |
There was a problem hiding this comment.
I'm not sure if this is necessary. I haven't seen template tag written with upper case. I also can't find any such mention in the specification or in the source code of the sfc-compiler.
Does it need to be supported by the vue parser? It is supported by the HTML parser(Playground), I think which is sufficient. (We don't have a vue parser tests for it.) |
|
I don't know, but people can use |
|
I'm not a Vue user, but the name of "single file components" implies that there are "multiple file components" that have their templates in separate files. I skimmed through the Vue docs, found some mentions of "in-DOM templates", but there doesn't seem to be a separate page about this. |
|
I forgot about directives. I cannot find about vue app written in only one html file in documentations, but the below code works fine. It would be good that Prettier support this. I'll fix. <html>
<body>
<div id="example">
<p v-if="hello === 'Hello World!'">{{ hello }}</p>
</div>
<script src="https://unpkg.com/vue"></script>
<script>
new Vue({
el: '#example',
data: { hello: 'Hello World!' }
})
</script>
</body>
</html> |
| isTagNameCaseSensitive: true, | ||
| getTagContentType: (tagname) => { | ||
| if (tagname !== "template") { | ||
| if (tagname !== "template" && tagname !== "html") { |
There was a problem hiding this comment.
I'm not sure about template, but I'm sure about html, it can be uppercase :)
There was a problem hiding this comment.
stable prettier does not support it...(Playground). We should open new issue.
parser=vue
Input:
<!DOCTYPE html><HTML>
<body>
<div v-if="foo === 'foo'">
</div>
<script>
new Vue({el: '#app'})
</script>
</body>
</HTML>Output:
<!DOCTYPE html
>><HTML>
<body>
<div v-if="foo === 'foo'">
</div>
<script>
new Vue({el: '#app'})
</script>
</body>
</HTML>There was a problem hiding this comment.
I don't use angular, angular does not support it too
|
ooops, I'll fix.. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I saw the ci running, then I test those two links. thought it's my problem. The commits are missing on your fork too https://github.com/sosukesuzuki/prettier/commits/8106 |
|
I successfully fetched them from the fork. Looks like GitHub's UI is out of sync. |
|
All issues addressed? |
|
Yes all issues were probably fixed. Can we merge this? Should I fix commits history? |
|
I'm good. |
|
I didn't bring this case here #8162 (comment), but you should know. I try to throw SyntaxError in |
|
I reported this situation to GitHub. The commits still aren't visible on the UI. Not sure what happens if we do a merge. BTW, a question on SO relevant to this PR: https://stackoverflow.com/q/61742084/76173 |
|
I use this |
|
Try close and reopen ? |
| } else if (node instanceof Text) { | ||
| node.type = "text"; | ||
| } else { | ||
| console.log(node); |
There was a problem hiding this comment.
oops, I'll remove this
|
@fisker Prettier formats |
I think so too but the behavior is happened by stable Prettier. So we can fix this in other PR. |
|
I think we should open new issues for #8153 (comment) and #8153 (comment) , should not fix in this PR. |
| const getSameLocationNode = (node) => { | ||
| const result = getSecondParse(); | ||
| return result.rootNodes.find((_node) => { | ||
| if (!_node || !_node.startSourceSpan) { | ||
| return false; | ||
| } | ||
| if ( | ||
| node.startSourceSpan.start.offset === | ||
| _node.startSourceSpan.start.offset | ||
| ) { | ||
| return true; | ||
| } | ||
| return false; | ||
| }); | ||
| }; |
There was a problem hiding this comment.
| const getSameLocationNode = (node) => { | |
| const result = getSecondParse(); | |
| return result.rootNodes.find((_node) => { | |
| if (!_node || !_node.startSourceSpan) { | |
| return false; | |
| } | |
| if ( | |
| node.startSourceSpan.start.offset === | |
| _node.startSourceSpan.start.offset | |
| ) { | |
| return true; | |
| } | |
| return false; | |
| }); | |
| }; | |
| const getSameLocationNode = (node) => | |
| getSecondParse().rootNodes.find( | |
| ({ startSourceSpan }) => | |
| startSourceSpan && | |
| startSourceSpan.start.offset === node.startSourceSpan.start.offset | |
| ); |
node can't be false, right?
| const getSecondParse = () => | ||
| secondParseResult | ||
| ? secondParseResult | ||
| : (secondParseResult = doSecondParse()); |
There was a problem hiding this comment.
| const getSecondParse = () => | |
| secondParseResult | |
| ? secondParseResult | |
| : (secondParseResult = doSecondParse()); | |
| const getSecondParse = () => | |
| secondParseResult || (secondParseResult = doSecondParse()); |
| const replaceNode = getSameLocationNode(node); | ||
| if (replaceNode) { | ||
| rootNodes[i] = replaceNode; | ||
| } |
There was a problem hiding this comment.
| const replaceNode = getSameLocationNode(node); | |
| if (replaceNode) { | |
| rootNodes[i] = replaceNode; | |
| } | |
| rootNodes[i] = getSameLocationNode(node) || rootNodes[i]; |
| tagName !== "html" && | ||
| !hasParent && | ||
| (tagName !== "template" || | ||
| attrs.find((attr) => attr.name === "lang" && attr.value !== "html")) |
There was a problem hiding this comment.
| attrs.find((attr) => attr.name === "lang" && attr.value !== "html")) | |
| attrs.some(({name, value}) => name === "lang" && value !== "html")) |
|
@fisker Thank you for your review! I fixed all reviewed points. |
|
Great job! |

Fixes #8108
Fixes #6503
Fixes #6325
Close #7975
changelog_unreleased/*/pr-XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.✨Try the playground for this PR✨