prettier / angular-html-parser

An HTML parser extracted from Angular with some modifications
https://github.com/prettier/angular-html-parser/blob/dev/packages/angular-html-parser
MIT License
43 stars 13 forks source link

feat(getTagContentType): add `prefix` and `hasParent` parameters #13

Closed ikatyang closed 4 years ago

ikatyang commented 4 years ago

Context: https://github.com/ikatyang/angular-html-parser/issues/11#issuecomment-620560801

This PR adds two parameters for getTagContentType so that Vue SFC could be correctly parsed:

The implementation for hasParent is a bit hacky, it

The reason why I implemented it this way is that I don't want to duplicate the entire parsing process in the lexer, though there are some drawbacks for the current implementation:

But I think it should be fine for the Vue SFC parsing since no one would encounter these edge cases in real life IMO.

This PR also contains a test case for Vue SFC parsing.

cc @fisker @thorn0 @sosukesuzuki

fisker commented 4 years ago

Seems there is no attribute info, so will this work?

<template lang="pug">
  #container
    some-component(tag='<some-tag>')
</template>
ikatyang commented 4 years ago

I've checked vuejs/vue-next:

https://github.com/ikatyang/angular-html-parser/issues/11#issuecomment-621613078

And also I've checked that <template lang="something-else"> is parsed just like normal <template>s, which means we don't need additional information (e.g., attributes) to distinguish them.

fisker commented 4 years ago

Okay, good know, thanks.

ikatyang commented 4 years ago

👉 https://github.com/ikatyang/angular-html-parser/releases/tag/v1.6.0