fix(compiler-vapor): hoist template with inline option

This commit is contained in:
三咲智子 Kevin Deng 2024-02-07 17:56:32 +08:00
parent 99da2e5abe
commit b7e6e1eceb
No known key found for this signature in database
GPG Key ID: 69992F2250DFD93E
11 changed files with 112 additions and 204 deletions

View File

@ -1,8 +1,7 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`compile > bindings 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setText as _setText } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setText as _setText, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -14,8 +13,7 @@ export function render(_ctx) {
`;
exports[`compile > custom directive > basic 1`] = `
"import { template as _template, children as _children, resolveDirective as _resolveDirective, withDirectives as _withDirectives } from 'vue/vapor';
"import { children as _children, resolveDirective as _resolveDirective, withDirectives as _withDirectives, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -27,8 +25,7 @@ export function render(_ctx) {
`;
exports[`compile > directives > custom directive > basic 1`] = `
"import { template as _template, children as _children, withDirectives as _withDirectives } from 'vue/vapor';
"import { children as _children, withDirectives as _withDirectives, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -40,8 +37,7 @@ export function render(_ctx) {
`;
exports[`compile > directives > custom directive > binding value 1`] = `
"import { template as _template, children as _children, withDirectives as _withDirectives } from 'vue/vapor';
"import { children as _children, withDirectives as _withDirectives, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -53,8 +49,7 @@ export function render(_ctx) {
`;
exports[`compile > directives > custom directive > dynamic parameters 1`] = `
"import { template as _template, children as _children, withDirectives as _withDirectives } from 'vue/vapor';
"import { children as _children, withDirectives as _withDirectives, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -66,8 +61,7 @@ export function render(_ctx) {
`;
exports[`compile > directives > custom directive > modifiers 1`] = `
"import { template as _template, children as _children, withDirectives as _withDirectives } from 'vue/vapor';
"import { children as _children, withDirectives as _withDirectives, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -79,8 +73,7 @@ export function render(_ctx) {
`;
exports[`compile > directives > custom directive > modifiers w/o binding 1`] = `
"import { template as _template, children as _children, withDirectives as _withDirectives } from 'vue/vapor';
"import { children as _children, withDirectives as _withDirectives, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -92,8 +85,7 @@ export function render(_ctx) {
`;
exports[`compile > directives > custom directive > static parameters 1`] = `
"import { template as _template, children as _children, withDirectives as _withDirectives } from 'vue/vapor';
"import { children as _children, withDirectives as _withDirectives, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -105,8 +97,7 @@ export function render(_ctx) {
`;
exports[`compile > directives > custom directive > static parameters and modifiers 1`] = `
"import { template as _template, children as _children, withDirectives as _withDirectives } from 'vue/vapor';
"import { children as _children, withDirectives as _withDirectives, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -119,7 +110,6 @@ export function render(_ctx) {
exports[`compile > directives > v-cloak > basic 1`] = `
"import { template as _template } from 'vue/vapor';
const t0 = _template("<div>test</div>")
export function render(_ctx) {
@ -130,7 +120,6 @@ export function render(_ctx) {
exports[`compile > directives > v-pre > basic 1`] = `
"import { template as _template } from 'vue/vapor';
const t0 = _template("<div :id=\\"foo\\"><Comp></Comp>{{ bar }}</div>")
export function render(_ctx) {
@ -140,8 +129,7 @@ export function render(_ctx) {
`;
exports[`compile > directives > v-pre > self-closing v-pre 1`] = `
"import { template as _template, children as _children, createTextNode as _createTextNode, append as _append, renderEffect as _renderEffect, setText as _setText, setDynamicProp as _setDynamicProp } from 'vue/vapor';
"import { children as _children, createTextNode as _createTextNode, append as _append, renderEffect as _renderEffect, setText as _setText, setDynamicProp as _setDynamicProp, template as _template } from 'vue/vapor';
const t0 = _template("<div></div><div><Comp></Comp></div>")
export function render(_ctx) {
@ -156,8 +144,7 @@ export function render(_ctx) {
`;
exports[`compile > directives > v-pre > should not affect siblings after it 1`] = `
"import { template as _template, children as _children, createTextNode as _createTextNode, append as _append, renderEffect as _renderEffect, setText as _setText, setDynamicProp as _setDynamicProp } from 'vue/vapor';
"import { children as _children, createTextNode as _createTextNode, append as _append, renderEffect as _renderEffect, setText as _setText, setDynamicProp as _setDynamicProp, template as _template } from 'vue/vapor';
const t0 = _template("<div :id=\\"foo\\"><Comp></Comp>{{ bar }}</div><div><Comp></Comp></div>")
export function render(_ctx) {
@ -182,8 +169,7 @@ export function render(_ctx) {
`;
exports[`compile > dynamic root nodes and interpolation 1`] = `
"import { template as _template, children as _children, on as _on, renderEffect as _renderEffect, setText as _setText, setDynamicProp as _setDynamicProp } from 'vue/vapor';
"import { children as _children, on as _on, renderEffect as _renderEffect, setText as _setText, setDynamicProp as _setDynamicProp, template as _template } from 'vue/vapor';
const t0 = _template("<button></button>")
export function render(_ctx) {
@ -205,9 +191,7 @@ exports[`compile > expression parsing > interpolation 1`] = `
`;
exports[`compile > expression parsing > v-bind 1`] = `
"
const t0 = _template("<div></div>")
(() => {
"(() => {
const n0 = t0()
const { 0: [n1],} = _children(n0)
_renderEffect(() => _setDynamicProps(n1, { [key.value+1]: _unref(foo)[key.value+1]() }))
@ -217,7 +201,6 @@ const t0 = _template("<div></div>")
exports[`compile > fragment 1`] = `
"import { template as _template } from 'vue/vapor';
const t0 = _template("<p></p><span></span><div></div>")
export function render(_ctx) {
@ -238,7 +221,6 @@ export function render(_ctx) {
exports[`compile > static template 1`] = `
"import { template as _template } from 'vue/vapor';
const t0 = _template("<div><p>hello</p><input><span></span></div>")
export function render(_ctx) {

View File

@ -1,8 +1,7 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`compiler: element transform > props merging: class 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setClass as _setClass } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setClass as _setClass, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -14,8 +13,7 @@ export function render(_ctx) {
`;
exports[`compiler: element transform > props merging: style 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setStyle as _setStyle } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setStyle as _setStyle, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -28,7 +26,6 @@ export function render(_ctx) {
exports[`compiler: element transform > static props 1`] = `
"import { template as _template } from 'vue/vapor';
const t0 = _template("<div id=\\"foo\\" class=\\"bar\\"></div>")
export function render(_ctx) {
@ -38,8 +35,7 @@ export function render(_ctx) {
`;
exports[`compiler: element transform > v-bind="obj" 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setDynamicProps as _setDynamicProps } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setDynamicProps as _setDynamicProps, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -51,8 +47,7 @@ export function render(_ctx) {
`;
exports[`compiler: element transform > v-bind="obj" after static prop 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setDynamicProps as _setDynamicProps } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setDynamicProps as _setDynamicProps, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -64,8 +59,7 @@ export function render(_ctx) {
`;
exports[`compiler: element transform > v-bind="obj" before static prop 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setDynamicProps as _setDynamicProps } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setDynamicProps as _setDynamicProps, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -77,8 +71,7 @@ export function render(_ctx) {
`;
exports[`compiler: element transform > v-bind="obj" between static props 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setDynamicProps as _setDynamicProps } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setDynamicProps as _setDynamicProps, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {

View File

@ -1,8 +1,7 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`compiler v-bind > .attr modifier 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setAttr as _setAttr } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setAttr as _setAttr, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -14,8 +13,7 @@ export function render(_ctx) {
`;
exports[`compiler v-bind > .attr modifier w/ no expression 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setAttr as _setAttr } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setAttr as _setAttr, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -27,8 +25,7 @@ export function render(_ctx) {
`;
exports[`compiler v-bind > .camel modifier 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setDynamicProp as _setDynamicProp } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setDynamicProp as _setDynamicProp, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -41,8 +38,7 @@ export function render(_ctx) {
exports[`compiler v-bind > .camel modifier w/ dynamic arg 1`] = `
"import { camelize as _camelize } from 'vue';
import { template as _template, children as _children, renderEffect as _renderEffect, setDynamicProps as _setDynamicProps } from 'vue/vapor';
import { children as _children, renderEffect as _renderEffect, setDynamicProps as _setDynamicProps, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -54,8 +50,7 @@ export function render(_ctx) {
`;
exports[`compiler v-bind > .camel modifier w/ no expression 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setDynamicProp as _setDynamicProp } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setDynamicProp as _setDynamicProp, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -67,8 +62,7 @@ export function render(_ctx) {
`;
exports[`compiler v-bind > .prop modifier (shortband) w/ no expression 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setDOMProp as _setDOMProp } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setDOMProp as _setDOMProp, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -80,8 +74,7 @@ export function render(_ctx) {
`;
exports[`compiler v-bind > .prop modifier (shorthand) 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setDOMProp as _setDOMProp } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setDOMProp as _setDOMProp, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -93,8 +86,7 @@ export function render(_ctx) {
`;
exports[`compiler v-bind > .prop modifier 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setDOMProp as _setDOMProp } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setDOMProp as _setDOMProp, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -106,8 +98,7 @@ export function render(_ctx) {
`;
exports[`compiler v-bind > .prop modifier w/ dynamic arg 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setDynamicProps as _setDynamicProps } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setDynamicProps as _setDynamicProps, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -119,8 +110,7 @@ export function render(_ctx) {
`;
exports[`compiler v-bind > .prop modifier w/ no expression 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setDOMProp as _setDOMProp } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setDOMProp as _setDOMProp, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -132,8 +122,7 @@ export function render(_ctx) {
`;
exports[`compiler v-bind > basic 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setDynamicProp as _setDynamicProp } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setDynamicProp as _setDynamicProp, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -145,8 +134,7 @@ export function render(_ctx) {
`;
exports[`compiler v-bind > dynamic arg 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setDynamicProps as _setDynamicProps } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setDynamicProps as _setDynamicProps, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -158,8 +146,7 @@ export function render(_ctx) {
`;
exports[`compiler v-bind > dynamic arg w/ static attribute 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setDynamicProps as _setDynamicProps } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setDynamicProps as _setDynamicProps, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -171,8 +158,7 @@ export function render(_ctx) {
`;
exports[`compiler v-bind > no expression (shorthand) 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setDynamicProp as _setDynamicProp } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setDynamicProp as _setDynamicProp, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -184,8 +170,7 @@ export function render(_ctx) {
`;
exports[`compiler v-bind > no expression 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setDynamicProp as _setDynamicProp } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setDynamicProp as _setDynamicProp, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -198,7 +183,6 @@ export function render(_ctx) {
exports[`compiler v-bind > should error if empty expression 1`] = `
"import { template as _template } from 'vue/vapor';
const t0 = _template("<div arg=\\"\\"></div>")
export function render(_ctx) {

View File

@ -1,8 +1,7 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`compiler: v-for > basic v-for 1`] = `
"import { template as _template, children as _children, on as _on, renderEffect as _renderEffect, setText as _setText, createFor as _createFor } from 'vue/vapor';
"import { children as _children, on as _on, renderEffect as _renderEffect, setText as _setText, createFor as _createFor, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -21,8 +20,7 @@ export function render(_ctx) {
`;
exports[`compiler: v-for > multi effect 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setDynamicProp as _setDynamicProp, createFor as _createFor } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setDynamicProp as _setDynamicProp, createFor as _createFor, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -44,8 +42,7 @@ export function render(_ctx) {
`;
exports[`compiler: v-for > w/o value 1`] = `
"import { template as _template, createFor as _createFor } from 'vue/vapor';
"import { createFor as _createFor, template as _template } from 'vue/vapor';
const t0 = _template("<div>item</div>")
export function render(_ctx) {

View File

@ -1,8 +1,7 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`v-html > should convert v-html to innerHTML 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setHtml as _setHtml } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setHtml as _setHtml, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -14,8 +13,7 @@ export function render(_ctx) {
`;
exports[`v-html > should raise error and ignore children when v-html is present 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setHtml as _setHtml } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setHtml as _setHtml, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -27,8 +25,7 @@ export function render(_ctx) {
`;
exports[`v-html > should raise error if has no expression 1`] = `
"import { template as _template, children as _children, setHtml as _setHtml } from 'vue/vapor';
"import { children as _children, setHtml as _setHtml, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {

View File

@ -1,8 +1,7 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`compiler: v-if > basic v-if 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setText as _setText, createIf as _createIf } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setText as _setText, createIf as _createIf, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -17,8 +16,7 @@ export function render(_ctx) {
`;
exports[`compiler: v-if > comment between branches 1`] = `
"import { template as _template, children as _children, createIf as _createIf, prepend as _prepend, renderEffect as _renderEffect, setText as _setText } from 'vue/vapor';
"import { children as _children, createIf as _createIf, prepend as _prepend, renderEffect as _renderEffect, setText as _setText, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
const t1 = _template("<!--foo--><p></p>")
const t2 = _template("<!--bar-->fine")
@ -44,8 +42,7 @@ export function render(_ctx) {
`;
exports[`compiler: v-if > dedupe same template 1`] = `
"import { template as _template, createIf as _createIf } from 'vue/vapor';
"import { createIf as _createIf, template as _template } from 'vue/vapor';
const t0 = _template("<div>hello</div>")
export function render(_ctx) {
@ -62,8 +59,7 @@ export function render(_ctx) {
`;
exports[`compiler: v-if > template v-if 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setText as _setText, createIf as _createIf } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setText as _setText, createIf as _createIf, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>hello<p></p>")
export function render(_ctx) {
@ -78,8 +74,7 @@ export function render(_ctx) {
`;
exports[`compiler: v-if > v-if + v-else 1`] = `
"import { template as _template, createIf as _createIf } from 'vue/vapor';
"import { createIf as _createIf, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
const t1 = _template("<p></p>")
@ -96,8 +91,7 @@ export function render(_ctx) {
`;
exports[`compiler: v-if > v-if + v-else-if + v-else 1`] = `
"import { template as _template, createIf as _createIf } from 'vue/vapor';
"import { createIf as _createIf, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
const t1 = _template("<p></p>")
const t2 = _template("fine")
@ -118,8 +112,7 @@ export function render(_ctx) {
`;
exports[`compiler: v-if > v-if + v-else-if 1`] = `
"import { template as _template, createIf as _createIf } from 'vue/vapor';
"import { createIf as _createIf, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
const t1 = _template("<p></p>")

View File

@ -1,8 +1,7 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`v-on > case conversion for kebab-case events 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -14,8 +13,7 @@ export function render(_ctx) {
`;
exports[`v-on > complex member expression w/ prefixIdentifiers: true 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -27,8 +25,7 @@ export function render(_ctx) {
`;
exports[`v-on > dynamic arg 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, on as _on } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -40,8 +37,7 @@ export function render(_ctx) {
`;
exports[`v-on > dynamic arg with complex exp prefixing 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, on as _on } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -53,8 +49,7 @@ export function render(_ctx) {
`;
exports[`v-on > dynamic arg with prefixing 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, on as _on } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -66,8 +61,7 @@ export function render(_ctx) {
`;
exports[`v-on > event modifier 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<a></a><form></form><a></a><div></div><div></div><a></a><div></div><input><input><input><input><input><input><input><input><input><input><input><input><input><input><input>")
export function render(_ctx) {
@ -139,8 +133,7 @@ export function render(_ctx) {
`;
exports[`v-on > function expression w/ prefixIdentifiers: true 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -152,8 +145,7 @@ export function render(_ctx) {
`;
exports[`v-on > inline statement w/ prefixIdentifiers: true 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -165,8 +157,7 @@ export function render(_ctx) {
`;
exports[`v-on > multiple inline statements w/ prefixIdentifiers: true 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -178,8 +169,7 @@ export function render(_ctx) {
`;
exports[`v-on > should NOT add a prefix to $event if the expression is a function expression 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -191,8 +181,7 @@ export function render(_ctx) {
`;
exports[`v-on > should NOT wrap as function if expression is already function expression (with Typescript) 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -204,8 +193,7 @@ export function render(_ctx) {
`;
exports[`v-on > should NOT wrap as function if expression is already function expression (with newlines) 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -221,8 +209,7 @@ export function render(_ctx) {
`;
exports[`v-on > should NOT wrap as function if expression is already function expression 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -234,8 +221,7 @@ export function render(_ctx) {
`;
exports[`v-on > should NOT wrap as function if expression is complex member expression 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -247,8 +233,7 @@ export function render(_ctx) {
`;
exports[`v-on > should handle multi-line statement 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -263,8 +248,7 @@ _ctx.bar()
`;
exports[`v-on > should handle multiple inline statement 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -276,8 +260,7 @@ export function render(_ctx) {
`;
exports[`v-on > should not prefix member expression 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -289,8 +272,7 @@ export function render(_ctx) {
`;
exports[`v-on > should not wrap keys guard if no key modifier is present 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -304,8 +286,7 @@ export function render(_ctx) {
`;
exports[`v-on > should support multiple events and modifiers options w/ prefixIdentifiers: true 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -322,8 +303,7 @@ export function render(_ctx) {
`;
exports[`v-on > should support multiple modifiers and event options w/ prefixIdentifiers: true 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -337,8 +317,7 @@ export function render(_ctx) {
`;
exports[`v-on > should transform click.middle 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -352,8 +331,7 @@ export function render(_ctx) {
`;
exports[`v-on > should transform click.middle 2`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, on as _on } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -368,8 +346,7 @@ export function render(_ctx) {
`;
exports[`v-on > should transform click.right 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -383,8 +360,7 @@ export function render(_ctx) {
`;
exports[`v-on > should transform click.right 2`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, on as _on } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -400,8 +376,7 @@ export function render(_ctx) {
`;
exports[`v-on > should wrap as function if expression is inline statement 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -413,8 +388,7 @@ export function render(_ctx) {
`;
exports[`v-on > should wrap both for dynamic key event w/ left/right modifiers 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, on as _on } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -430,9 +404,7 @@ export function render(_ctx) {
`;
exports[`v-on > should wrap in unref if identifier is setup-maybe-ref w/ inline: true 1`] = `
"
const t0 = _template("<div></div><div></div><div></div>")
(() => {
"(() => {
const n0 = t0()
const { 0: [n1], 1: [n2], 2: [n3],} = _children(n0)
_on(n1, "click", () => $event => (x.value=_unref(y)))
@ -443,8 +415,7 @@ const t0 = _template("<div></div><div></div><div></div>")
`;
exports[`v-on > should wrap keys guard for keyboard events or dynamic events 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -459,8 +430,7 @@ export function render(_ctx) {
`;
exports[`v-on > should wrap keys guard for static key event w/ left/right modifiers 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -474,8 +444,7 @@ export function render(_ctx) {
`;
exports[`v-on > simple expression 1`] = `
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
"import { children as _children, on as _on, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {

View File

@ -1,8 +1,7 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`compiler: v-once > as root node 1`] = `
"import { template as _template, children as _children, setDynamicProp as _setDynamicProp } from 'vue/vapor';
"import { children as _children, setDynamicProp as _setDynamicProp, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -14,8 +13,7 @@ export function render(_ctx) {
`;
exports[`compiler: v-once > basic 1`] = `
"import { template as _template, children as _children, createTextNode as _createTextNode, setText as _setText, setClass as _setClass, prepend as _prepend } from 'vue/vapor';
"import { children as _children, createTextNode as _createTextNode, setText as _setText, setClass as _setClass, prepend as _prepend, template as _template } from 'vue/vapor';
const t0 = _template("<div><span></span></div>")
export function render(_ctx) {
@ -31,7 +29,6 @@ export function render(_ctx) {
exports[`compiler: v-once > inside v-once 1`] = `
"import { template as _template } from 'vue/vapor';
const t0 = _template("<div><div></div></div>")
export function render(_ctx) {
@ -41,8 +38,7 @@ export function render(_ctx) {
`;
exports[`compiler: v-once > on nested plain element 1`] = `
"import { template as _template, children as _children, setDynamicProp as _setDynamicProp } from 'vue/vapor';
"import { children as _children, setDynamicProp as _setDynamicProp, template as _template } from 'vue/vapor';
const t0 = _template("<div><div></div></div>")
export function render(_ctx) {

View File

@ -1,8 +1,7 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`v-text > should convert v-text to textContent 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setText as _setText } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setText as _setText, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -14,8 +13,7 @@ export function render(_ctx) {
`;
exports[`v-text > should raise error and ignore children when v-text is present 1`] = `
"import { template as _template, children as _children, renderEffect as _renderEffect, setText as _setText } from 'vue/vapor';
"import { children as _children, renderEffect as _renderEffect, setText as _setText, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
@ -27,8 +25,7 @@ export function render(_ctx) {
`;
exports[`v-text > should raise error if has no expression 1`] = `
"import { template as _template, children as _children, setText as _setText } from 'vue/vapor';
"import { children as _children, setText as _setText, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {

View File

@ -7,11 +7,15 @@ import {
advancePositionWithMutation,
locStub,
} from '@vue/compiler-dom'
import type { IREffect, RootIRNode, VaporHelper } from './ir'
import type {
IREffect,
RootIRNode,
TemplateFactoryIRNode,
VaporHelper,
} from './ir'
import { SourceMapGenerator } from 'source-map-js'
import { extend, isArray, isString, remove } from '@vue/shared'
import type { ParserPlugin } from '@babel/parser'
import { genTemplate } from './generators/template'
import { genBlockFunctionContent } from './generators/block'
interface CodegenOptions extends BaseCodegenOptions {
@ -149,13 +153,6 @@ export function generate(
const context = new CodegenContext(ir, options)
const { push, helpers, vaporHelpers } = context
if (ir.template.length) {
ir.template.forEach((template, i) =>
push(...genTemplate(template, i, context)),
)
push(NEWLINE)
}
const functionName = 'render'
const isSetupInlined = options.inline
if (isSetupInlined) {
@ -174,9 +171,18 @@ export function generate(
push('}')
}
const preamble = genHelperImports(context)
let codegen = genCodeFragment(context)
// TODO source map?
const templates = ir.template.length ? genTemplates(ir.template, context) : ''
const imports = genHelperImports(context)
const preamble = imports + templates
const newlineCount = [...preamble].filter(c => c === '\n').length
if (newlineCount && !isSetupInlined) {
context.code.unshift(...new Array<CodeFragment>(newlineCount).fill(LF))
}
let codegen = genCodeFragment(context)
if (!isSetupInlined) {
codegen = preamble + codegen
}
@ -290,16 +296,26 @@ export function buildCodeFragment(...frag: CodeFragment[]) {
function genHelperImports({ helpers, vaporHelpers, code }: CodegenContext) {
let imports = ''
if (helpers.size) {
code.unshift(LF)
imports += `import { ${[...helpers]
.map(h => `${h} as _${h}`)
.join(', ')} } from 'vue';\n`
}
if (vaporHelpers.size) {
code.unshift(LF)
imports += `import { ${[...vaporHelpers]
.map(h => `${h} as _${h}`)
.join(', ')} } from 'vue/vapor';\n`
}
return imports
}
export function genTemplates(
templates: TemplateFactoryIRNode[],
{ vaporHelper }: CodegenContext,
) {
return templates
.map(
(template, i) =>
`const t${i} = ${vaporHelper('template')}(${JSON.stringify(template.template)})\n`,
)
.join('')
}

View File

@ -1,16 +0,0 @@
import { type CodeFragment, type CodegenContext, NEWLINE } from '../generate'
import type { TemplateFactoryIRNode } from '../ir'
export function genTemplate(
node: TemplateFactoryIRNode,
index: number,
{ vaporHelper }: CodegenContext,
): CodeFragment[] {
// TODO source map?
return [
NEWLINE,
`const t${index} = ${vaporHelper('template')}(${JSON.stringify(
node.template,
)})`,
]
}