mirror of https://github.com/vuejs/core.git
fix(compiler-sfc): ensure props bindings register before compiling template (#13922)
close #13920
This commit is contained in:
parent
b555f02eed
commit
abd563822a
|
@ -12,6 +12,27 @@ export function render(_ctx, _cache) {
|
||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`prefixing props edge case in inline mode 1`] = `
|
||||||
|
"import { defineComponent as _defineComponent } from 'vue'
|
||||||
|
import { unref as _unref, openBlock as _openBlock, createBlock as _createBlock } from "vue"
|
||||||
|
|
||||||
|
|
||||||
|
export default /*@__PURE__*/_defineComponent({
|
||||||
|
props: {
|
||||||
|
Foo: { type: Object, required: true }
|
||||||
|
},
|
||||||
|
setup(__props: any) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return (_ctx: any,_cache: any) => {
|
||||||
|
return (_openBlock(), _createBlock(_unref(__props["Foo"]).Bar))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
})"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`should not hoist srcset URLs in SSR mode 1`] = `
|
exports[`should not hoist srcset URLs in SSR mode 1`] = `
|
||||||
"import { resolveComponent as _resolveComponent, withCtx as _withCtx, createVNode as _createVNode } from "vue"
|
"import { resolveComponent as _resolveComponent, withCtx as _withCtx, createVNode as _createVNode } from "vue"
|
||||||
import { ssrRenderAttr as _ssrRenderAttr, ssrRenderComponent as _ssrRenderComponent } from "vue/server-renderer"
|
import { ssrRenderAttr as _ssrRenderAttr, ssrRenderComponent as _ssrRenderComponent } from "vue/server-renderer"
|
||||||
|
|
|
@ -512,3 +512,22 @@ test('non-identifier expression in legacy filter syntax', () => {
|
||||||
babelParse(compilationResult.code, { sourceType: 'module' })
|
babelParse(compilationResult.code, { sourceType: 'module' })
|
||||||
}).not.toThrow()
|
}).not.toThrow()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('prefixing props edge case in inline mode', () => {
|
||||||
|
const src = `
|
||||||
|
<script setup lang="ts">
|
||||||
|
defineProps<{ Foo: { Bar: unknown } }>()
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<Foo.Bar/>
|
||||||
|
</template>
|
||||||
|
`
|
||||||
|
const { descriptor } = parse(src)
|
||||||
|
const { content } = compileScript(descriptor, {
|
||||||
|
id: 'xxx',
|
||||||
|
inlineTemplate: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(content).toMatchSnapshot()
|
||||||
|
expect(content).toMatch(`__props["Foo"]).Bar`)
|
||||||
|
})
|
||||||
|
|
|
@ -833,6 +833,8 @@ export function compileScript(
|
||||||
let templateMap
|
let templateMap
|
||||||
// 9. generate return statement
|
// 9. generate return statement
|
||||||
let returned
|
let returned
|
||||||
|
// ensure props bindings register before compile template in inline mode
|
||||||
|
const propsDecl = genRuntimeProps(ctx)
|
||||||
if (
|
if (
|
||||||
!options.inlineTemplate ||
|
!options.inlineTemplate ||
|
||||||
(!sfc.template && ctx.hasDefaultExportRender)
|
(!sfc.template && ctx.hasDefaultExportRender)
|
||||||
|
@ -965,7 +967,6 @@ export function compileScript(
|
||||||
runtimeOptions += `\n __ssrInlineRender: true,`
|
runtimeOptions += `\n __ssrInlineRender: true,`
|
||||||
}
|
}
|
||||||
|
|
||||||
const propsDecl = genRuntimeProps(ctx)
|
|
||||||
if (propsDecl) runtimeOptions += `\n props: ${propsDecl},`
|
if (propsDecl) runtimeOptions += `\n props: ${propsDecl},`
|
||||||
|
|
||||||
const emitsDecl = genRuntimeEmits(ctx)
|
const emitsDecl = genRuntimeEmits(ctx)
|
||||||
|
|
Loading…
Reference in New Issue