feat(compiler): element transform

This commit is contained in:
Evan You
2019-09-21 17:42:12 -04:00
parent 93440bba97
commit baa8954884
13 changed files with 349 additions and 160 deletions

View File

@@ -73,8 +73,7 @@ export interface ElementNode extends Node {
tag: string
tagType: ElementTypes
isSelfClosing: boolean
attrs: AttributeNode[]
directives: DirectiveNode[]
props: Array<AttributeNode | DirectiveNode>
children: ChildNode[]
codegenNode: CallExpression | undefined
}
@@ -161,3 +160,64 @@ export interface ArrayExpression extends Node {
type: NodeTypes.ARRAY_EXPRESSION
elements: Array<CodegenNode>
}
export function createArrayExpression(
elements: ArrayExpression['elements'],
loc: SourceLocation
): ArrayExpression {
return {
type: NodeTypes.ARRAY_EXPRESSION,
loc,
elements
}
}
export function createObjectExpression(
properties: Property[],
loc: SourceLocation
): ObjectExpression {
return {
type: NodeTypes.OBJECT_EXPRESSION,
loc,
properties
}
}
export function createObjectProperty(
key: ExpressionNode,
value: ExpressionNode,
loc: SourceLocation
): Property {
return {
type: NodeTypes.PROPERTY,
loc,
key,
value
}
}
export function createExpression(
content: string,
isStatic: boolean,
loc: SourceLocation
): ExpressionNode {
return {
type: NodeTypes.EXPRESSION,
loc,
content,
isStatic
}
}
export function createCallExpression(
callee: string,
args: CallExpression['arguments'],
loc: SourceLocation
): CallExpression {
return {
type: NodeTypes.CALL_EXPRESSION,
loc,
callee,
arguments: args
}
}