-import type { CompilerOptions } from '@vue/compiler-core'
import { compile } from '../src'
-export function getCompiledString(
- src: string,
- options?: CompilerOptions,
-): string {
+export function getCompiledString(src: string): string {
// Wrap src template in a root div so that it doesn't get injected
// fallthrough attr. This results in less noise in generated snapshots
// but also means this util can only be used for non-root cases.
- const { code } = compile(`<div>${src}</div>`, options)
+ const { code } = compile(`<div>${src}</div>`)
const match = code.match(
/_push\(\`<div\${\s*_ssrRenderAttrs\(_attrs\)\s*}>([^]*)<\/div>\`\)/,
)
type CallExpression,
type CompilerError,
type CompilerOptions,
- type ElementNode,
ElementTypes,
type IfStatement,
type JSChildNode,
if (asFragment) {
context.pushStringPart(`<!--[-->`)
}
-
const { children } = parent
-
for (let i = 0; i < children.length; i++) {
const child = children[i]
switch (child.type) {
break
case ElementTypes.COMPONENT:
ssrProcessComponent(child, context, parent)
-
break
case ElementTypes.SLOT:
ssrProcessSlotOutlet(child, context)
processChildren(parent, childContext, asFragment)
return createBlockStatement(childContext.body)
}
-
-export function isElementWithChildren(
- node: TemplateChildNode,
-): node is ElementNode {
- return (
- node.type === NodeTypes.ELEMENT &&
- node.tagType === ElementTypes.ELEMENT &&
- node.children.length > 0
- )
-}
if (vFor) {
wrapperProps.push(extend({}, vFor))
}
-
const wrapperNode: TemplateNode = {
type: NodeTypes.ELEMENT,
ns: Namespaces.HTML,
loc: locStub,
codegenNode: undefined,
}
-
subTransform(wrapperNode, subOptions, parentContext)
return createReturnStatement(children)
}
context,
needFragmentWrapper,
)
-
// v-for always renders a fragment unless explicitly disabled
if (!disableNestedFragments) {
context.pushStringPart(`<!--[-->`)
(children.length !== 1 || children[0].type !== NodeTypes.ELEMENT) &&
// optimize away nested fragments when the only child is a ForNode
!(children.length === 1 && children[0].type === NodeTypes.FOR)
-
return processChildrenAsStatement(branch, context, needFragmentWrapper)
}
parent?: number
anchor?: number
append?: boolean
- childIndex?: number
}
export interface IRFor {
parent?: number
anchor?: number
append?: boolean
- childIndex?: number
}
export interface SetPropIRNode extends BaseIRNode {
parent?: number
anchor?: number
append?: boolean
- childIndex?: number
scopeId?: string | null
}
parent?: number
anchor?: number
append?: boolean
- childIndex?: number
}
export interface GetTextChildIRNode extends BaseIRNode {
hasDynamicChild?: boolean
operation?: OperationNode
needsKey?: boolean
- isIfBranch?: boolean
}
export interface IREffect {
block: BlockIRNode = this.ir.block
options: Required<
- Omit<TransformOptions, 'vapor' | 'filename' | keyof CompilerCompatOptions>
+ Omit<TransformOptions, 'filename' | keyof CompilerCompatOptions>
>
template: string = ''
}
}
} else {
- context.dynamic.isIfBranch = true
// check the adjacent v-if
const siblingIf = getSiblingIf(context, true)