Subscribe on changes!

Can we support parse v-pre to props in @vue/compiler-sfc?

avatar
Nov 19th 2021

What problem does this feature solve?

When I use @vue/compiler-sfc to parse a component's ast, I found it can't parse v-pre to props. Any other directives can be found in the AST parsing results of the corresponding attributes. So it's on purpose or it's a bug?

image

What does the proposed API look like?

support parse v-pre in ast

avatar
Nov 22nd 2021

When I use @vue/compiler-sfc to parse a component's ast, I found it can't parse v-pre to props. Any other directives can be found in the AST parsing results of the corresponding attributes. So it's on purpose or it's a bug?

https://github.com/vuejs/vue-next/blob/61720231b48dc57eeda8930eae11b5a03d9210a3/packages/compiler-core/src/parse.ts#L547-L559

It is indeed on purpose.

avatar
Nov 22nd 2021

but v-pre isn't contained in props, the props is empty.😂

avatar
Nov 22nd 2021

it's not contained in the final props because it's explicitly filtered out of the props during parsing in line 558 in the code snippet above.

avatar
Nov 22nd 2021

So it's on purpose or it's a bug? Now I have to use regexp to match v-pre attribute between tags😥

avatar
Nov 22nd 2021

What's the purpose of getting the v-pre tag?

Note that v-pre is a special directive that affects AST shape in that inside an element with v-pre:

  1. Mustaches are ignored and treated as plain text
  2. Directives inside v-pre are parsed as plain attributes

This is similar to how you won't find v-if or v-for in node props because they are directives that directly affect the resulting AST.

avatar
Nov 22nd 2021

What's the purpose of getting the v-pre tag?

Note that v-pre is a special directive that affects AST shape in that inside an element with v-pre:

  1. Mustaches are ignored and treated as plain text
  2. Directives inside v-pre are parsed as plain attributes

This is similar to how you won't find v-if or v-for in node props because they are directives that directly affect the resulting AST.

Sorry for that I didn't explain my purpose clearly. My project is to find and convert Chinese characters to function CallExpresssion in the code by parsing AST, so we can manage international copywriting automatically. In the process of parsing the AST, if meet v-pre, I will skip this element and its child element.

avatar
Nov 23rd 2021

I think you should maybe use some other attributes for this purpose since v-pre has its own special meaning in templates.

avatar
Nov 23rd 2021

emmm..., any chinese characters in an element with v-pre, I don't need to get and convert them. But the AST node's props is Empty so I can't judge this element with v-pre whether or not.😂That's the code link, If you have free time, you can see it.