wip: Sequence & Conditional expressions for AST

This commit is contained in:
Evan You
2019-10-01 09:27:34 -04:00
parent 2f155dbcb8
commit e31fb3c172
6 changed files with 124 additions and 33 deletions

View File

@@ -1,13 +1,15 @@
import { NodeTransform } from '../transform'
import {
NodeTypes,
ChildNode,
TemplateChildNode,
TextNode,
InterpolationNode,
CompoundExpressionNode
} from '../ast'
const isText = (node: ChildNode): node is TextNode | InterpolationNode =>
const isText = (
node: TemplateChildNode
): node is TextNode | InterpolationNode =>
node.type === NodeTypes.INTERPOLATION || node.type === NodeTypes.TEXT
// Merge adjacent text nodes and expressions into a single expression

View File

@@ -10,7 +10,7 @@ import {
ElementTypes,
ExpressionNode,
Property,
ChildNode,
TemplateChildNode,
SourceLocation
} from '../ast'
import { TransformContext, NodeTransform } from '../transform'
@@ -67,7 +67,7 @@ export function buildSlots(
// 2. Iterate through children and check for template slots
// <template v-slot:foo="{ prop }">
let hasTemplateSlots = false
let extraneousChild: ChildNode | undefined = undefined
let extraneousChild: TemplateChildNode | undefined = undefined
const seenSlotNames = new Set<string>()
for (let i = 0; i < children.length; i++) {
const child = children[i]
@@ -135,7 +135,7 @@ export function buildSlots(
function buildSlot(
name: string | ExpressionNode,
slotProps: ExpressionNode | undefined,
children: ChildNode[],
children: TemplateChildNode[],
loc: SourceLocation
): Property {
return createObjectProperty(