MCPcopy
hub / github.com/vuejs/core / subTransform

Function subTransform

packages/compiler-ssr/src/transforms/ssrTransformComponent.ts:337–372  ·  view source on GitHub ↗
(
  node: TemplateChildNode,
  options: TransformOptions,
  parentContext: TransformContext,
)

Source from the content-addressed store, hash-verified

335}
336
337function subTransform(
338 node: TemplateChildNode,
339 options: TransformOptions,
340 parentContext: TransformContext,
341) {
342 const childRoot = createRoot([node])
343 const childContext = createTransformContext(childRoot, options)
344 // this sub transform is for vnode fallback branch so it should be handled
345 // like normal render functions
346 childContext.ssr = false
347 // inherit parent scope analysis state
348 childContext.scopes = { ...parentContext.scopes }
349 childContext.identifiers = { ...parentContext.identifiers }
350 childContext.imports = parentContext.imports
351 // traverse
352 traverseNode(childRoot, childContext)
353 // merge helpers/components/directives into parent context
354 ;(['helpers', 'components', 'directives'] as const).forEach(key => {
355 childContext[key].forEach((value: any, helperKey: any) => {
356 if (key === 'helpers') {
357 const parentCount = parentContext.helpers.get(helperKey)
358 if (parentCount === undefined) {
359 parentContext.helpers.set(helperKey, value)
360 } else {
361 parentContext.helpers.set(helperKey, value + parentCount)
362 }
363 } else {
364 ;(parentContext[key] as any).add(value)
365 }
366 })
367 })
368 // imports/hoists are not merged because:
369 // - imports are only used for asset urls and should be consistent between
370 // node/client branches
371 // - hoists are not enabled for the client branch here
372}
373
374function clone(v: any): any {
375 if (isArray(v)) {

Callers 1

createVNodeSlotBranchFunction · 0.85

Calls 6

createTransformContextFunction · 0.85
traverseNodeFunction · 0.85
forEachMethod · 0.80
createRootFunction · 0.50
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected