Skip to content

Commit

Permalink
perf: simplify clone
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 4, 2024
1 parent 2c1dbc9 commit a4bcbe8
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions packages/compiler-ssr/src/transforms/ssrTransformComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -371,26 +373,12 @@ function subTransform(
function clone(v: any): any {
if (isArray(v)) {
return v.map(clone)
} else if (isObject(v)) {
if (v instanceof Map) {
const res = new Map()
v.forEach((value: any, key: any) => {
res.set(clone(key), clone(value))
})
return res
} else if (v instanceof Set) {
const res = new Set()
v.forEach((value: any) => {
res.add(clone(value))
})
return res
} else {
const res: any = {}
for (const key in v) {
res[key] = clone(v[key])
}
return res
} else if (isPlainObject(v)) {
const res: any = {}
for (const key in v) {
res[key] = clone(v[key as keyof typeof v])
}
return res
} else {
return v
}
Expand Down

0 comments on commit a4bcbe8

Please sign in to comment.