提交 8fdb4d84 编写于 作者: fxy060608's avatar fxy060608

wip(uts): 修复 v-once

上级 92ae3050
......@@ -34,7 +34,7 @@ describe('compiler:codegen', () => {
assert(
`<view/>`,
`
function PagesIndexIndexRender(): VNode | null {\nconst _ctx = this\nconst _cache = this.$!.renderCache\n return createElementVNode("view")\n}`,
function PagesIndexIndexRender(): VNode | null {\nconst _ctx = this\nconst _cache = this.$.renderCache\n return createElementVNode("view")\n}`,
{
targetLanguage: 'kotlin',
mode: 'function',
......@@ -44,7 +44,7 @@ function PagesIndexIndexRender(): VNode | null {\nconst _ctx = this\nconst _cach
test(`UTSComponents`, () => {
assert(
`<view><uts-hello/><uts-hello/></view>`,
`import { UtsHelloElement } from 'uts.sdk.modules.utsHello';\nfunction PagesIndexIndexRender(): VNode | null {\nconst _ctx = this\nconst _cache = this.$!.renderCache\n return createElementVNode("view", null, [\n createElementVNode(uts.sdk.modules.utsHello.UtsHelloComponent.name),\n createElementVNode(uts.sdk.modules.utsHello.UtsHelloComponent.name)\n ])\n}`,
`import { UtsHelloElement } from 'uts.sdk.modules.utsHello';\nfunction PagesIndexIndexRender(): VNode | null {\nconst _ctx = this\nconst _cache = this.$.renderCache\n return createElementVNode("view", null, [\n createElementVNode(uts.sdk.modules.utsHello.UtsHelloComponent.name),\n createElementVNode(uts.sdk.modules.utsHello.UtsHelloComponent.name)\n ])\n}`,
{
targetLanguage: 'kotlin',
mode: 'function',
......@@ -61,7 +61,7 @@ function PagesIndexIndexRender(): VNode | null {\nconst _ctx = this\nconst _cach
)
assert(
`<view><uts-hello/><uts-hello/><uts-hello1/></view>`,
`import { UtsHelloElement } from 'uts.sdk.modules.utsHello';import { UtsHello1Element } from 'uts.sdk.modules.utsHello';\nfunction PagesIndexIndexRender(): VNode | null {\nconst _ctx = this\nconst _cache = this.$!.renderCache\n return createElementVNode("view", null, [\n createElementVNode(uts.sdk.modules.utsHello.UtsHelloComponent.name),\n createElementVNode(uts.sdk.modules.utsHello.UtsHelloComponent.name),\n createElementVNode(uts.sdk.modules.utsHello.UtsHello1Component.name)\n ])\n}`,
`import { UtsHelloElement } from 'uts.sdk.modules.utsHello';import { UtsHello1Element } from 'uts.sdk.modules.utsHello';\nfunction PagesIndexIndexRender(): VNode | null {\nconst _ctx = this\nconst _cache = this.$.renderCache\n return createElementVNode("view", null, [\n createElementVNode(uts.sdk.modules.utsHello.UtsHelloComponent.name),\n createElementVNode(uts.sdk.modules.utsHello.UtsHelloComponent.name),\n createElementVNode(uts.sdk.modules.utsHello.UtsHello1Component.name)\n ])\n}`,
{
targetLanguage: 'kotlin',
mode: 'function',
......@@ -92,7 +92,7 @@ import _easycom_custom1 from '@/components/custom1/custom1.vue'
import _easycom_index from '@/components/index/index.vue'
function PagesIndexIndexRender(): VNode | null {
const _ctx = this
const _cache = this.$!.renderCache
const _cache = this.$.renderCache
const _component_custom = resolveEasyComponent("custom",_easycom_custom)
const _component_custom1 = resolveEasyComponent("custom1",_easycom_custom1)
const _component_index = resolveEasyComponent("index",_easycom_index)
......@@ -121,7 +121,7 @@ const _component_index1 = resolveComponent("index1")
`
function PagesIndexIndexRender(): VNode | null {
const _ctx = this
const _cache = this.$!.renderCache
const _cache = this.$.renderCache
const _component_index = resolveComponent("index", true)
return createVNode(_component_index)
......@@ -141,7 +141,7 @@ import _easycom_custom1 from '@/components/custom1/custom1.vue'
import _easycom_index from '@/components/index/index.vue'
function PagesIndexIndexRender(): VNode | null {
const _ctx = this
const _cache = this.$!.renderCache
const _cache = this.$.renderCache
const _component_custom = resolveEasyComponent("custom",_easycom_custom)
const _component_custom1 = resolveEasyComponent("custom1",_easycom_custom1)
const _component_index = resolveEasyComponent("index",_easycom_index)
......@@ -185,7 +185,7 @@ import _imports_0 from './logo.png'
function PagesIndexIndexRender(): VNode | null {
const _ctx = this
const _cache = this.$!.renderCache
const _cache = this.$.renderCache
return createElementVNode(\"image\", utsMapOf({ src: _imports_0 }))
}`,
{
......
......@@ -4,7 +4,7 @@ exports[`compiler: v-memo transform on component 1`] = `
"
function Render(): VNode | null {
const _ctx = this
const _cache = this.$!.renderCache
const _cache = this.$.renderCache
const _component_Comp = resolveComponent("Comp")
return createElementVNode("view", null, [
......@@ -17,7 +17,7 @@ exports[`compiler: v-memo transform on normal element 1`] = `
"
function Render(): VNode | null {
const _ctx = this
const _cache = this.$!.renderCache
const _cache = this.$.renderCache
return createElementVNode("view", null, [
withMemo([_ctx.x], (): VNode => createElementVNode("view"), _cache, 0)
])
......@@ -28,7 +28,7 @@ exports[`compiler: v-memo transform on root element 1`] = `
"
function Render(): VNode | null {
const _ctx = this
const _cache = this.$!.renderCache
const _cache = this.$.renderCache
return withMemo([_ctx.x], (): VNode => createElementVNode("view"), _cache, 0)
}"
`;
......@@ -37,7 +37,7 @@ exports[`compiler: v-memo transform on template v-for 1`] = `
"
function Render(): VNode | null {
const _ctx = this
const _cache = this.$!.renderCache
const _cache = this.$.renderCache
return createElementVNode("view", null, [
createElementVNode(Fragment, null, RenderHelpers.renderList(_ctx.list, ({ x, y }, _, _, _cached): VNode => {
const _memo: Array<any | null> = ([x, y === _ctx.z])
......@@ -54,7 +54,7 @@ exports[`compiler: v-memo transform on v-for 1`] = `
"
function Render(): VNode | null {
const _ctx = this
const _cache = this.$!.renderCache
const _cache = this.$.renderCache
return createElementVNode("view", null, [
createElementVNode(Fragment, null, RenderHelpers.renderList(_ctx.list, ({ x, y }, _, _, _cached): VNode => {
const _memo: Array<any | null> = ([x, y === _ctx.z])
......@@ -73,7 +73,7 @@ exports[`compiler: v-memo transform on v-if 1`] = `
"
function Render(): VNode | null {
const _ctx = this
const _cache = this.$!.renderCache
const _cache = this.$.renderCache
const _component_Comp = resolveComponent("Comp")
return createElementVNode("view", null, [
......
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`compiler: v-once transform as root node 1`] = `
"_cache[0] ?? run((): VNode | null => {
"resolveCache(_cache, 0, (): VNode => {
setBlockTracking(-1)
_cache[0] = createElementVNode("view", utsMapOf({ id: foo }), null, 8 /* PROPS */, ["id"])
setBlockTracking(1)
return _cache[0] as VNode | null
return _cache[0] as VNode
})"
`;
exports[`compiler: v-once transform on component 1`] = `
"createElementVNode("view", null, [
_cache[0] ?? run((): VNode | null => {
resolveCache(_cache, 0, (): VNode => {
setBlockTracking(-1)
_cache[0] = createVNode(_component_Comp, utsMapOf({ id: foo }), null, 8 /* PROPS */, ["id"])
setBlockTracking(1)
return _cache[0] as VNode | null
return _cache[0] as VNode
})
])"
`;
exports[`compiler: v-once transform on nested plain element 1`] = `
"createElementVNode("view", null, [
_cache[0] ?? run((): VNode | null => {
resolveCache(_cache, 0, (): VNode => {
setBlockTracking(-1)
_cache[0] = createElementVNode("view", utsMapOf({ id: foo }), null, 8 /* PROPS */, ["id"])
setBlockTracking(1)
return _cache[0] as VNode | null
return _cache[0] as VNode
})
])"
`;
exports[`compiler: v-once transform on slot outlet 1`] = `
"createElementVNode("view", null, [
_cache[0] ?? run((): VNode | null => {
resolveCache(_cache, 0, (): VNode => {
setBlockTracking(-1)
_cache[0] = renderSlot($slots, "default")
setBlockTracking(1)
return _cache[0] as VNode | null
return _cache[0] as VNode
})
])"
`;
......@@ -7,7 +7,7 @@ describe('compiler: component', () => {
`
function PagesIndexIndexRender(): VNode | null {
const _ctx = this
const _cache = this.$!.renderCache
const _cache = this.$.renderCache
const _component_Foo = resolveComponent("Foo")
return createElementVNode("view", null, [
......
......@@ -95,7 +95,7 @@ describe('compiler: slot', () => {
`
function PagesIndexIndexRender(): VNode | null {
const _ctx = this
const _cache = this.$!.renderCache
const _cache = this.$.renderCache
return createElementVNode("view", null, [
renderSlot(_ctx.$slots, "default", utsMapOf({ data: "data" }))
])
......@@ -113,7 +113,7 @@ const _cache = this.$!.renderCache
`
function PagesIndexIndexRender(): VNode | null {
const _ctx = this
const _cache = this.$!.renderCache
const _cache = this.$.renderCache
const _component_Foo = resolveComponent("Foo")
return createElementVNode("view", null, [
......@@ -150,7 +150,7 @@ const _component_Foo = resolveComponent("Foo")
`
function PagesIndexIndexRender(): VNode | null {
const _ctx = this
const _cache = this.$!.renderCache
const _cache = this.$.renderCache
const _component_Foo = resolveComponent("Foo")
return createElementVNode("view", null, [
......@@ -175,7 +175,7 @@ const _component_Foo = resolveComponent("Foo")
`
function PagesIndexIndexRender(): VNode | null {
const _ctx = this
const _cache = this.$!.renderCache
const _cache = this.$.renderCache
const _component_Foo = resolveComponent("Foo")
return createElementVNode("view", null, [
......
......@@ -45,6 +45,7 @@ import { addEasyComponentAutoImports, genRenderFunctionDecl } from './utils'
import {
IS_TRUE,
RENDER_LIST,
RESOLVE_CACHE,
RESOLVE_COMPONENT,
RESOLVE_DIRECTIVE,
RESOLVE_EASY_COMPONENT,
......@@ -214,7 +215,7 @@ export function generate(
newline()
push(`const _ctx = this`)
newline()
push(`const _cache = this.$!.renderCache`)
push(`const _cache = this.$.renderCache`)
// generate asset resolution statements
if (ast.components.length) {
newline()
......@@ -822,7 +823,7 @@ function genConditionalExpression(
function genCacheExpression(node: CacheExpression, context: CodegenContext) {
const { push, helper, indent, deindent, newline } = context
push(`_cache[${node.index}] ?? run((): VNode | null => {`)
push(`${helperNameMap[RESOLVE_CACHE]}(_cache, ${node.index}, (): VNode => {`)
if (node.isVNode) {
indent()
push(`${helper(SET_BLOCK_TRACKING)}(-1)`)
......@@ -834,7 +835,7 @@ function genCacheExpression(node: CacheExpression, context: CodegenContext) {
newline()
push(`${helper(SET_BLOCK_TRACKING)}(1)`)
newline()
push(`return _cache[${node.index}] as VNode | null`)
push(`return _cache[${node.index}] as VNode`)
deindent()
}
push(`})`)
......
......@@ -15,6 +15,8 @@ export const V_ON_WITH_MODIFIERS = Symbol(`vOnModifiersGuard`)
export const WITH_SLOT_CTX = Symbol(`withSlotCtx`)
export const WITH_SCOPED_SLOT_CTX = Symbol(`withScopedSlotCtx`)
export const RESOLVE_CACHE = Symbol(`resolveCache`)
registerRuntimeHelpers({
[IS_TRUE]: 'isTrue',
[V_SHOW]: 'vShow',
......@@ -28,4 +30,5 @@ registerRuntimeHelpers({
[V_ON_WITH_MODIFIERS]: `withModifiers`,
[WITH_SLOT_CTX]: `withSlotCtx`,
[WITH_SCOPED_SLOT_CTX]: `withScopedSlotCtx`,
[RESOLVE_CACHE]: `resolveCache`,
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册