Skip to content

Commit abd5638

Browse files
authored
fix(compiler-sfc): ensure props bindings register before compiling template (#13922)
close #13920
1 parent b555f02 commit abd5638

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

packages/compiler-sfc/__tests__/__snapshots__/compileTemplate.spec.ts.snap

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,27 @@ export function render(_ctx, _cache) {
1212
}"
1313
`;
1414

15+
exports[`prefixing props edge case in inline mode 1`] = `
16+
"import { defineComponent as _defineComponent } from 'vue'
17+
import { unref as _unref, openBlock as _openBlock, createBlock as _createBlock } from "vue"
18+
19+
20+
export default /*@__PURE__*/_defineComponent({
21+
props: {
22+
Foo: { type: Object, required: true }
23+
},
24+
setup(__props: any) {
25+
26+
27+
28+
return (_ctx: any,_cache: any) => {
29+
return (_openBlock(), _createBlock(_unref(__props["Foo"]).Bar))
30+
}
31+
}
32+
33+
})"
34+
`;
35+
1536
exports[`should not hoist srcset URLs in SSR mode 1`] = `
1637
"import { resolveComponent as _resolveComponent, withCtx as _withCtx, createVNode as _createVNode } from "vue"
1738
import { ssrRenderAttr as _ssrRenderAttr, ssrRenderComponent as _ssrRenderComponent } from "vue/server-renderer"

packages/compiler-sfc/__tests__/compileTemplate.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,22 @@ test('non-identifier expression in legacy filter syntax', () => {
512512
babelParse(compilationResult.code, { sourceType: 'module' })
513513
}).not.toThrow()
514514
})
515+
516+
test('prefixing props edge case in inline mode', () => {
517+
const src = `
518+
<script setup lang="ts">
519+
defineProps<{ Foo: { Bar: unknown } }>()
520+
</script>
521+
<template>
522+
<Foo.Bar/>
523+
</template>
524+
`
525+
const { descriptor } = parse(src)
526+
const { content } = compileScript(descriptor, {
527+
id: 'xxx',
528+
inlineTemplate: true,
529+
})
530+
531+
expect(content).toMatchSnapshot()
532+
expect(content).toMatch(`__props["Foo"]).Bar`)
533+
})

packages/compiler-sfc/src/compileScript.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,8 @@ export function compileScript(
833833
let templateMap
834834
// 9. generate return statement
835835
let returned
836+
// ensure props bindings register before compile template in inline mode
837+
const propsDecl = genRuntimeProps(ctx)
836838
if (
837839
!options.inlineTemplate ||
838840
(!sfc.template && ctx.hasDefaultExportRender)
@@ -965,7 +967,6 @@ export function compileScript(
965967
runtimeOptions += `\n __ssrInlineRender: true,`
966968
}
967969

968-
const propsDecl = genRuntimeProps(ctx)
969970
if (propsDecl) runtimeOptions += `\n props: ${propsDecl},`
970971

971972
const emitsDecl = genRuntimeEmits(ctx)

0 commit comments

Comments
 (0)