diff --git a/packages/compiler-sfc/__tests__/compileTemplate.spec.ts b/packages/compiler-sfc/__tests__/compileTemplate.spec.ts
index 7ab64bb2667..45dc54a69db 100644
--- a/packages/compiler-sfc/__tests__/compileTemplate.spec.ts
+++ b/packages/compiler-sfc/__tests__/compileTemplate.spec.ts
@@ -427,6 +427,31 @@ test('prefixing edge case for reused AST', () => {
expect(code).not.toMatch(`_ctx.t`)
})
+test('prefixing edge case for reused AST ssr mode', () => {
+ const src = `
+
+
+
+
+
+
+ `
+ const { descriptor } = parse(src)
+ // compileScript triggers importUsageCheck
+ compileScript(descriptor, { id: 'xxx' })
+ expect(() =>
+ compileTemplate({
+ id: 'xxx',
+ filename: 'test.vue',
+ ast: descriptor.template!.ast,
+ source: descriptor.template!.content,
+ ssr: true,
+ }),
+ ).not.toThrowError()
+})
+
interface Pos {
line: number
column: number
diff --git a/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts b/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts
index c179cd50cf7..3146a90a2d6 100644
--- a/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts
+++ b/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts
@@ -55,7 +55,7 @@ import {
ssrProcessTransitionGroup,
ssrTransformTransitionGroup,
} from './ssrTransformTransitionGroup'
-import { extend, isArray, isObject, isSymbol } from '@vue/shared'
+import { extend, isArray, isObject, isPlainObject, isSymbol } from '@vue/shared'
import { buildSSRProps } from './ssrTransformElement'
import {
ssrProcessTransition,
@@ -121,6 +121,8 @@ export const ssrTransformComponent: NodeTransform = (node, context) => {
const vnodeBranches: ReturnStatement[] = []
const clonedNode = clone(node)
+ console.log(clonedNode)
+
return function ssrPostTransformComponent() {
// Using the cloned node, build the normal VNode-based branches (for
// fallback in case the child is render-fn based). Store them in an array
@@ -371,10 +373,10 @@ function subTransform(
function clone(v: any): any {
if (isArray(v)) {
return v.map(clone)
- } else if (isObject(v)) {
+ } else if (isPlainObject(v)) {
const res: any = {}
for (const key in v) {
- res[key] = clone(v[key])
+ res[key] = clone(v[key as keyof typeof v])
}
return res
} else {