feat(compiler): transform component slots

This commit is contained in:
Evan You
2019-09-27 22:25:32 -04:00
parent ee66ce78b7
commit 32666c7708
6 changed files with 194 additions and 19 deletions

View File

@@ -27,7 +27,8 @@ export const enum NodeTypes {
JS_CALL_EXPRESSION,
JS_OBJECT_EXPRESSION,
JS_PROPERTY,
JS_ARRAY_EXPRESSION
JS_ARRAY_EXPRESSION,
JS_SLOT_FUNCTION
}
export const enum ElementTypes {
@@ -157,6 +158,7 @@ export type JSChildNode =
| ObjectExpression
| ArrayExpression
| ExpressionNode
| SlotFunctionExpression
export interface CallExpression extends Node {
type: NodeTypes.JS_CALL_EXPRESSION
@@ -180,6 +182,12 @@ export interface ArrayExpression extends Node {
elements: Array<string | JSChildNode>
}
export interface SlotFunctionExpression extends Node {
type: NodeTypes.JS_SLOT_FUNCTION
params: ExpressionNode | undefined
returns: ChildNode[]
}
export function createArrayExpression(
elements: ArrayExpression['elements'],
loc: SourceLocation
@@ -264,3 +272,16 @@ export function createCallExpression(
arguments: args
}
}
export function createFunctionExpression(
params: ExpressionNode | undefined,
returns: ChildNode[],
loc: SourceLocation
): SlotFunctionExpression {
return {
type: NodeTypes.JS_SLOT_FUNCTION,
params,
returns,
loc
}
}