templateNode = {
type: IRNodeTypes.TEMPLATE_FACTORY,
template: this.template,
- loc: node.loc,
}
} else {
templateNode = {
type: IRNodeTypes.FRAGMENT_FACTORY,
- loc: node.loc,
}
}
root.template.push(templateNode)
type: IRNodeTypes.ROOT,
node: root,
source: root.source,
- loc: root.loc,
template: [],
templateIndex: -1,
dynamic: extend(genDefaultDynamic(), {
processDynamicChildren(ctx)
}
-function processDynamicChildren(ctx: TransformContext<RootNode | ElementNode>) {
- const { node } = ctx
-
+function processDynamicChildren(
+ context: TransformContext<RootNode | ElementNode>,
+) {
let prevChildren: IRDynamicInfo[] = []
let hasStatic = false
- for (const [index, child] of ctx.dynamic.children.entries()) {
+ for (const [index, child] of context.dynamic.children.entries()) {
if (!child || !(child.flags & DynamicFlag.INSERT)) {
if (prevChildren.length) {
if (hasStatic) {
- ctx.childrenTemplate[index - prevChildren.length] = `<!>`
+ context.childrenTemplate[index - prevChildren.length] = `<!>`
prevChildren[0].flags -= DynamicFlag.NON_TEMPLATE
- const anchor = (prevChildren[0].anchor = ctx.increaseId())
+ const anchor = (prevChildren[0].anchor = context.increaseId())
- ctx.registerOperation({
+ context.registerOperation({
type: IRNodeTypes.INSERT_NODE,
- loc: node.loc,
element: prevChildren.map(child => child.id!),
- parent: ctx.reference(),
+ parent: context.reference(),
anchor,
})
} else {
- ctx.registerOperation({
+ context.registerOperation({
type: IRNodeTypes.PREPEND_NODE,
- loc: node.loc,
elements: prevChildren.map(child => child.id!),
- parent: ctx.reference(),
+ parent: context.reference(),
})
}
}
prevChildren.push(child)
- if (index === ctx.dynamic.children.length - 1) {
- ctx.registerOperation({
+ if (index === context.dynamic.children.length - 1) {
+ context.registerOperation({
type: IRNodeTypes.APPEND_NODE,
- loc: node.loc,
elements: prevChildren.map(child => child.id!),
- parent: ctx.reference(),
+ parent: context.reference(),
})
}
}
const id = context.reference()
const render: BlockFunctionIRNode = {
type: IRNodeTypes.BLOCK_FUNCTION,
- loc: node.loc,
node,
templateIndex: -1,
dynamic: extend(genDefaultDynamic(), {
context.registerOperation({
type: IRNodeTypes.FOR,
id,
- loc: dir.loc,
source: source as SimpleExpressionNode,
value: value as SimpleExpressionNode | undefined,
key: key as SimpleExpressionNode | undefined,
import { IRNodeTypes, type VaporHelper } from '../ir'
export const transformVModel: DirectiveTransform = (dir, node, context) => {
- const { exp, arg, loc } = dir
+ const { exp, arg } = dir
if (!exp) {
context.options.onError(
createCompilerError(ErrorCodes.X_V_MODEL_NO_EXPRESSION, dir.loc),
key: (arg && arg.isStatic ? arg.content : arg) || 'modelValue',
value: exp,
isComponent,
- loc: loc,
})
if (runtimeDirective)
type: IRNodeTypes.WITH_DIRECTIVE,
element: context.reference(),
dir,
- loc,
builtin: runtimeDirective,
})