2023-12-01 23:30:21 +08:00
|
|
|
import type {
|
2024-01-21 13:43:23 +08:00
|
|
|
BindingTypes,
|
2023-12-06 00:15:57 +08:00
|
|
|
CompoundExpressionNode,
|
2023-12-05 17:13:25 +08:00
|
|
|
DirectiveNode,
|
2023-12-01 23:30:21 +08:00
|
|
|
RootNode,
|
2023-12-05 17:13:25 +08:00
|
|
|
SimpleExpressionNode,
|
2023-12-01 23:30:21 +08:00
|
|
|
SourceLocation,
|
2024-01-28 01:31:20 +08:00
|
|
|
TemplateChildNode,
|
2023-12-01 23:30:21 +08:00
|
|
|
} from '@vue/compiler-dom'
|
2023-12-03 14:52:11 +08:00
|
|
|
import type { Prettify } from '@vue/shared'
|
|
|
|
import type { DirectiveTransform, NodeTransform } from './transform'
|
2023-11-24 11:07:31 +08:00
|
|
|
|
2023-11-29 22:09:46 +08:00
|
|
|
export enum IRNodeTypes {
|
2023-11-24 11:07:31 +08:00
|
|
|
ROOT,
|
2023-11-26 03:53:47 +08:00
|
|
|
TEMPLATE_FACTORY,
|
|
|
|
FRAGMENT_FACTORY,
|
|
|
|
|
2023-11-24 11:07:31 +08:00
|
|
|
SET_PROP,
|
|
|
|
SET_TEXT,
|
|
|
|
SET_EVENT,
|
2023-11-24 14:44:57 +08:00
|
|
|
SET_HTML,
|
2024-01-20 23:48:10 +08:00
|
|
|
SET_REF,
|
2024-01-21 02:16:30 +08:00
|
|
|
SET_MODEL_VALUE,
|
2023-11-24 11:07:31 +08:00
|
|
|
|
|
|
|
INSERT_NODE,
|
2023-11-27 06:22:10 +08:00
|
|
|
PREPEND_NODE,
|
2023-11-27 05:16:21 +08:00
|
|
|
APPEND_NODE,
|
2023-11-26 03:12:02 +08:00
|
|
|
CREATE_TEXT_NODE,
|
2023-12-03 18:36:01 +08:00
|
|
|
|
|
|
|
WITH_DIRECTIVE,
|
2024-01-28 01:31:20 +08:00
|
|
|
|
|
|
|
IF,
|
|
|
|
BLOCK_FUNCTION,
|
2023-11-24 11:07:31 +08:00
|
|
|
}
|
|
|
|
|
2023-12-01 23:30:21 +08:00
|
|
|
export interface BaseIRNode {
|
2023-11-24 11:07:31 +08:00
|
|
|
type: IRNodeTypes
|
|
|
|
loc: SourceLocation
|
|
|
|
}
|
|
|
|
|
2023-12-01 05:18:20 +08:00
|
|
|
// TODO refactor
|
|
|
|
export type VaporHelper = keyof typeof import('../../runtime-vapor/src')
|
|
|
|
|
2024-01-28 01:31:20 +08:00
|
|
|
export interface BlockFunctionIRNode extends BaseIRNode {
|
|
|
|
type: IRNodeTypes.BLOCK_FUNCTION
|
|
|
|
node: RootNode | TemplateChildNode
|
|
|
|
templateIndex: number
|
2023-12-01 23:30:21 +08:00
|
|
|
dynamic: IRDynamicInfo
|
|
|
|
effect: IREffect[]
|
2023-11-24 15:02:47 +08:00
|
|
|
operation: OperationNode[]
|
2023-11-24 11:07:31 +08:00
|
|
|
}
|
|
|
|
|
2024-01-28 01:31:20 +08:00
|
|
|
export interface RootIRNode extends Omit<BlockFunctionIRNode, 'type'> {
|
|
|
|
type: IRNodeTypes.ROOT
|
|
|
|
node: RootNode
|
|
|
|
source: string
|
|
|
|
template: Array<TemplateFactoryIRNode | FragmentFactoryIRNode>
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface IfIRNode extends BaseIRNode {
|
|
|
|
type: IRNodeTypes.IF
|
|
|
|
id: number
|
|
|
|
condition: IRExpression
|
|
|
|
positive: BlockFunctionIRNode
|
|
|
|
negative?: BlockFunctionIRNode
|
|
|
|
}
|
|
|
|
|
2023-12-01 23:30:21 +08:00
|
|
|
export interface TemplateFactoryIRNode extends BaseIRNode {
|
2023-11-26 03:53:47 +08:00
|
|
|
type: IRNodeTypes.TEMPLATE_FACTORY
|
2023-11-24 11:07:31 +08:00
|
|
|
template: string
|
|
|
|
}
|
|
|
|
|
2023-12-01 23:30:21 +08:00
|
|
|
export interface FragmentFactoryIRNode extends BaseIRNode {
|
2023-11-26 03:53:47 +08:00
|
|
|
type: IRNodeTypes.FRAGMENT_FACTORY
|
|
|
|
}
|
|
|
|
|
2023-12-01 23:30:21 +08:00
|
|
|
export interface SetPropIRNode extends BaseIRNode {
|
2023-11-24 11:07:31 +08:00
|
|
|
type: IRNodeTypes.SET_PROP
|
|
|
|
element: number
|
2023-12-09 04:06:46 +08:00
|
|
|
key: IRExpression
|
2023-12-01 23:30:21 +08:00
|
|
|
value: IRExpression
|
2024-01-22 23:03:39 +08:00
|
|
|
modifier?: '.' | '^'
|
2023-12-09 18:41:59 +08:00
|
|
|
runtimeCamelize: boolean
|
2023-11-24 11:07:31 +08:00
|
|
|
}
|
|
|
|
|
2023-12-01 23:30:21 +08:00
|
|
|
export interface SetTextIRNode extends BaseIRNode {
|
2023-11-24 11:07:31 +08:00
|
|
|
type: IRNodeTypes.SET_TEXT
|
|
|
|
element: number
|
2023-12-01 23:30:21 +08:00
|
|
|
value: IRExpression
|
2023-11-24 11:07:31 +08:00
|
|
|
}
|
|
|
|
|
2023-12-10 00:06:20 +08:00
|
|
|
export type KeyOverride = [find: string, replacement: string]
|
2023-12-01 23:30:21 +08:00
|
|
|
export interface SetEventIRNode extends BaseIRNode {
|
2023-11-24 11:07:31 +08:00
|
|
|
type: IRNodeTypes.SET_EVENT
|
|
|
|
element: number
|
2023-12-09 04:06:46 +08:00
|
|
|
key: IRExpression
|
2023-12-10 00:06:20 +08:00
|
|
|
value?: SimpleExpressionNode
|
2023-12-03 03:49:44 +08:00
|
|
|
modifiers: {
|
|
|
|
// modifiers for addEventListener() options, e.g. .passive & .capture
|
|
|
|
options: string[]
|
|
|
|
// modifiers that needs runtime guards, withKeys
|
|
|
|
keys: string[]
|
|
|
|
// modifiers that needs runtime guards, withModifiers
|
|
|
|
nonKeys: string[]
|
|
|
|
}
|
2023-12-10 00:06:20 +08:00
|
|
|
keyOverride?: KeyOverride
|
2023-11-24 11:07:31 +08:00
|
|
|
}
|
|
|
|
|
2023-12-01 23:30:21 +08:00
|
|
|
export interface SetHtmlIRNode extends BaseIRNode {
|
2023-11-24 14:44:57 +08:00
|
|
|
type: IRNodeTypes.SET_HTML
|
|
|
|
element: number
|
2023-12-01 23:30:21 +08:00
|
|
|
value: IRExpression
|
2023-11-24 14:44:57 +08:00
|
|
|
}
|
|
|
|
|
2024-01-20 23:48:10 +08:00
|
|
|
export interface SetRefIRNode extends BaseIRNode {
|
|
|
|
type: IRNodeTypes.SET_REF
|
|
|
|
element: number
|
|
|
|
value: IRExpression
|
|
|
|
}
|
|
|
|
|
2024-01-21 02:16:30 +08:00
|
|
|
export interface SetModelValueIRNode extends BaseIRNode {
|
|
|
|
type: IRNodeTypes.SET_MODEL_VALUE
|
|
|
|
element: number
|
|
|
|
key: IRExpression
|
|
|
|
value: IRExpression
|
2024-01-21 13:43:23 +08:00
|
|
|
bindingType?: BindingTypes
|
2024-01-21 02:16:30 +08:00
|
|
|
isComponent: boolean
|
|
|
|
}
|
|
|
|
|
2023-12-01 23:30:21 +08:00
|
|
|
export interface CreateTextNodeIRNode extends BaseIRNode {
|
2023-11-26 03:12:02 +08:00
|
|
|
type: IRNodeTypes.CREATE_TEXT_NODE
|
2023-11-24 11:07:31 +08:00
|
|
|
id: number
|
2023-12-01 23:30:21 +08:00
|
|
|
value: IRExpression
|
2023-11-24 11:07:31 +08:00
|
|
|
}
|
|
|
|
|
2023-12-01 23:30:21 +08:00
|
|
|
export interface InsertNodeIRNode extends BaseIRNode {
|
2023-11-24 11:07:31 +08:00
|
|
|
type: IRNodeTypes.INSERT_NODE
|
2023-11-27 06:22:10 +08:00
|
|
|
element: number | number[]
|
|
|
|
parent: number
|
|
|
|
anchor: number
|
|
|
|
}
|
|
|
|
|
2023-12-01 23:30:21 +08:00
|
|
|
export interface PrependNodeIRNode extends BaseIRNode {
|
2023-11-27 06:22:10 +08:00
|
|
|
type: IRNodeTypes.PREPEND_NODE
|
|
|
|
elements: number[]
|
2023-11-24 11:07:31 +08:00
|
|
|
parent: number
|
2023-11-27 05:16:21 +08:00
|
|
|
}
|
|
|
|
|
2023-12-01 23:30:21 +08:00
|
|
|
export interface AppendNodeIRNode extends BaseIRNode {
|
2023-11-27 05:16:21 +08:00
|
|
|
type: IRNodeTypes.APPEND_NODE
|
|
|
|
elements: number[]
|
|
|
|
parent: number
|
2023-11-24 11:07:31 +08:00
|
|
|
}
|
|
|
|
|
2023-12-03 18:36:01 +08:00
|
|
|
export interface WithDirectiveIRNode extends BaseIRNode {
|
|
|
|
type: IRNodeTypes.WITH_DIRECTIVE
|
|
|
|
element: number
|
2023-12-07 01:41:17 +08:00
|
|
|
dir: VaporDirectiveNode
|
2024-01-21 02:16:30 +08:00
|
|
|
builtin?: string
|
2023-12-03 18:36:01 +08:00
|
|
|
}
|
|
|
|
|
2023-12-01 23:30:21 +08:00
|
|
|
export type IRNode =
|
|
|
|
| OperationNode
|
|
|
|
| RootIRNode
|
|
|
|
| TemplateFactoryIRNode
|
|
|
|
| FragmentFactoryIRNode
|
2023-11-24 15:25:34 +08:00
|
|
|
export type OperationNode =
|
|
|
|
| SetPropIRNode
|
|
|
|
| SetTextIRNode
|
|
|
|
| SetEventIRNode
|
|
|
|
| SetHtmlIRNode
|
2024-01-20 23:48:10 +08:00
|
|
|
| SetRefIRNode
|
2024-01-21 02:16:30 +08:00
|
|
|
| SetModelValueIRNode
|
2023-11-26 03:12:02 +08:00
|
|
|
| CreateTextNodeIRNode
|
2023-11-24 15:25:34 +08:00
|
|
|
| InsertNodeIRNode
|
2023-11-27 06:22:10 +08:00
|
|
|
| PrependNodeIRNode
|
2023-11-27 05:16:21 +08:00
|
|
|
| AppendNodeIRNode
|
2023-12-03 18:36:01 +08:00
|
|
|
| WithDirectiveIRNode
|
2024-01-28 01:31:20 +08:00
|
|
|
| IfIRNode
|
|
|
|
|
|
|
|
export type BlockIRNode = RootIRNode | BlockFunctionIRNode
|
2023-11-24 11:07:31 +08:00
|
|
|
|
2023-12-01 23:30:21 +08:00
|
|
|
export interface IRDynamicInfo {
|
2023-11-24 11:07:31 +08:00
|
|
|
id: number | null
|
2023-11-27 05:16:21 +08:00
|
|
|
referenced: boolean
|
|
|
|
/** created by DOM API */
|
2023-11-26 03:08:35 +08:00
|
|
|
ghost: boolean
|
2023-11-27 05:16:21 +08:00
|
|
|
placeholder: number | null
|
2023-12-01 23:30:21 +08:00
|
|
|
children: IRDynamicChildren
|
|
|
|
}
|
|
|
|
export type IRDynamicChildren = Record<number, IRDynamicInfo>
|
|
|
|
|
2023-12-05 17:13:25 +08:00
|
|
|
export type IRExpression = SimpleExpressionNode | string
|
2023-12-01 23:30:21 +08:00
|
|
|
export interface IREffect {
|
|
|
|
// TODO multi-expression effect
|
|
|
|
expressions: IRExpression[]
|
|
|
|
operations: OperationNode[]
|
2023-11-24 11:07:31 +08:00
|
|
|
}
|
2023-12-03 14:52:11 +08:00
|
|
|
|
|
|
|
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> &
|
|
|
|
Pick<U, Extract<keyof U, keyof T>>
|
|
|
|
|
|
|
|
export type HackOptions<T> = Prettify<
|
|
|
|
Overwrite<
|
|
|
|
T,
|
|
|
|
{
|
|
|
|
nodeTransforms?: NodeTransform[]
|
|
|
|
directiveTransforms?: Record<string, DirectiveTransform | undefined>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
>
|
2023-12-05 17:13:25 +08:00
|
|
|
|
2023-12-06 00:15:57 +08:00
|
|
|
export type VaporDirectiveNode = Overwrite<
|
2023-12-05 17:13:25 +08:00
|
|
|
DirectiveNode,
|
|
|
|
{
|
2023-12-06 00:15:57 +08:00
|
|
|
exp: Exclude<DirectiveNode['exp'], CompoundExpressionNode>
|
|
|
|
arg: Exclude<DirectiveNode['arg'], CompoundExpressionNode>
|
2023-12-05 17:13:25 +08:00
|
|
|
}
|
|
|
|
>
|