Skip to content

Commit

Permalink
Merge branch 'main' into feature-ref-update
Browse files Browse the repository at this point in the history
  • Loading branch information
Doctor-wu authored Apr 28, 2024
2 parents 5c86b2a + e42fecb commit 7feda2e
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 37 deletions.
11 changes: 2 additions & 9 deletions packages/compiler-vapor/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
type VaporDirectiveNode,
} from './ir'
import { isConstantExpression } from './utils'
import { newDynamic } from './transforms/utils'
import { newBlock, newDynamic } from './transforms/utils'

export type NodeTransform = (
node: RootNode | TemplateChildNode,
Expand Down Expand Up @@ -211,14 +211,7 @@ export function transform(
source: node.source,
template: [],
component: new Set(),
block: {
type: IRNodeTypes.BLOCK,
node,
dynamic: newDynamic(),
effect: [],
operation: [],
returns: [],
},
block: newBlock(node),
}

const context = new TransformContext(ir, node, options)
Expand Down
16 changes: 15 additions & 1 deletion packages/compiler-vapor/src/transforms/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,27 @@ import {
createSimpleExpression,
} from '@vue/compiler-dom'
import { extend } from '@vue/shared'
import { DynamicFlag, type IRDynamicInfo } from '../ir'
import {
type BlockIRNode,
DynamicFlag,
type IRDynamicInfo,
IRNodeTypes,
} from '../ir'

export const newDynamic = (): IRDynamicInfo => ({
flags: DynamicFlag.REFERENCED,
children: [],
})

export const newBlock = (node: BlockIRNode['node']): BlockIRNode => ({
type: IRNodeTypes.BLOCK,
node,
dynamic: newDynamic(),
effect: [],
operation: [],
returns: [],
})

export function wrapTemplate(node: ElementNode, dirs: string[]): TemplateNode {
if (node.tagType === ElementTypes.TEMPLATE) {
return node
Expand Down
11 changes: 2 additions & 9 deletions packages/compiler-vapor/src/transforms/vFor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
type VaporDirectiveNode,
} from '../ir'
import { findProp, propToExpression } from '../utils'
import { newDynamic, wrapTemplate } from './utils'
import { newBlock, wrapTemplate } from './utils'

export const transformVFor = createStructuralDirectiveTransform(
'for',
Expand Down Expand Up @@ -48,14 +48,7 @@ export function processFor(
context.node = node = wrapTemplate(node, ['for'])
context.dynamic.flags |= DynamicFlag.NON_TEMPLATE | DynamicFlag.INSERT
const id = context.reference()
const render: BlockIRNode = {
type: IRNodeTypes.BLOCK,
node,
dynamic: newDynamic(),
effect: [],
operation: [],
returns: [],
}
const render: BlockIRNode = newBlock(node)
const exitBlock = context.enterBlock(render, true)
context.reference()

Expand Down
12 changes: 2 additions & 10 deletions packages/compiler-vapor/src/transforms/vIf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
type VaporDirectiveNode,
} from '../ir'
import { extend } from '@vue/shared'
import { newDynamic, wrapTemplate } from './utils'
import { newBlock, wrapTemplate } from './utils'
import { getSiblingIf } from './transformComment'

export const transformVIf = createStructuralDirectiveTransform(
Expand Down Expand Up @@ -114,15 +114,7 @@ export function createIfBranch(
): [BlockIRNode, () => void] {
context.node = node = wrapTemplate(node, ['if', 'else-if', 'else'])

const branch: BlockIRNode = {
type: IRNodeTypes.BLOCK,
node,
dynamic: newDynamic(),
effect: [],
operation: [],
returns: [],
}

const branch: BlockIRNode = newBlock(node)
const exitBlock = context.enterBlock(branch)
context.reference()
return [branch, exitBlock]
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-vapor/__tests__/renderEffect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ describe('renderEffect', () => {
}).rejects.toThrow('error in beforeUpdate')

expect(
'[Vue warn] Unhandled error during execution of beforeUpdate hook',
'[Vue warn]: Unhandled error during execution of beforeUpdate hook',
).toHaveBeenWarned()
})

Expand Down Expand Up @@ -210,7 +210,7 @@ describe('renderEffect', () => {
}).rejects.toThrow('error in updated')

expect(
'[Vue warn] Unhandled error during execution of updated',
'[Vue warn]: Unhandled error during execution of updated',
).toHaveBeenWarned()
})

Expand Down
44 changes: 39 additions & 5 deletions packages/runtime-vapor/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ import type { Data } from '@vue/shared'
export type Component = FunctionalComponent | ObjectComponent

export type SetupFn = (props: any, ctx: SetupContext) => Block | Data | void
export type FunctionalComponent = SetupFn & Omit<ObjectComponent, 'setup'>
export type FunctionalComponent = SetupFn &
Omit<ObjectComponent, 'setup'> & {
displayName?: string
}

export type SetupContext<E = EmitsOptions> = E extends any
? {
Expand Down Expand Up @@ -96,15 +99,46 @@ export function createSetupContext(
}
}

export interface ObjectComponent {
props?: ComponentPropsOptions
export interface ObjectComponent extends ComponentInternalOptions {
setup?: SetupFn
inheritAttrs?: boolean
props?: ComponentPropsOptions
emits?: EmitsOptions
setup?: SetupFn
render?(ctx: any): Block

name?: string
vapor?: boolean
}

// Note: can't mark this whole interface internal because some public interfaces
// extend it.
export interface ComponentInternalOptions {
/**
* @internal
*/
__scopeId?: string
/**
* @internal
*/
__cssModules?: Data
/**
* @internal
*/
__hmrId?: string
/**
* Compat build only, for bailing out of certain compatibility behavior
*/
__isBuiltIn?: boolean
/**
* This one should be exposed so that devtools can make use of it
*/
__file?: string
/**
* name inferred from filename
*/
__name?: string
}

type LifecycleHook<TFn = Function> = TFn[] | null

export const componentKey = Symbol(__DEV__ ? `componentKey` : ``)
Expand All @@ -121,7 +155,7 @@ export interface ComponentInternalInstance {

provides: Data
scope: EffectScope
component: FunctionalComponent | ObjectComponent
component: Component
comps: Set<ComponentInternalInstance>
dirs: Map<Node, DirectiveBinding[]>

Expand Down
4 changes: 4 additions & 0 deletions packages/runtime-vapor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export {
getCurrentWatcher,
} from '@vue/reactivity'

import { NOOP } from '@vue/shared'
import { warn as _warn } from './warning'
export const warn = (__DEV__ ? _warn : NOOP) as typeof _warn

export { nextTick } from './scheduler'
export {
getCurrentInstance,
Expand Down
Loading

0 comments on commit 7feda2e

Please sign in to comment.