export type OptionMergeFunction = (to: unknown, from: unknown) => any
-export interface AppConfig {
- // @private
- readonly isNativeTag: (tag: string) => boolean
-
- performance: boolean
- optionMergeStrategies: Record<string, OptionMergeFunction>
- globalProperties: ComponentCustomProperties & Record<string, any>
+/**
+ * Shared app config between vdom and vapor
+ */
+export interface GenericAppConfig {
+ performance?: boolean
errorHandler?: (
err: unknown,
instance: ComponentPublicInstance | null,
trace: string,
) => void
- /**
- * Options to pass to `@vue/compiler-dom`.
- * Only supported in runtime compiler build.
- */
- compilerOptions: RuntimeCompilerOptions
-
- /**
- * @deprecated use config.compilerOptions.isCustomElement
- */
- isCustomElement?: (tag: string) => boolean
-
/**
* TODO document for 3.5
* Enable warnings for computed getters that recursively trigger itself.
idPrefix?: string
}
-export interface AppContext {
+export interface AppConfig extends GenericAppConfig {
+ // @private
+ readonly isNativeTag: (tag: string) => boolean
+
+ optionMergeStrategies: Record<string, OptionMergeFunction>
+ globalProperties: ComponentCustomProperties & Record<string, any>
+
+ /**
+ * Options to pass to `@vue/compiler-dom`.
+ * Only supported in runtime compiler build.
+ */
+ compilerOptions: RuntimeCompilerOptions
+
+ /**
+ * @deprecated use config.compilerOptions.isCustomElement
+ */
+ isCustomElement?: (tag: string) => boolean
+}
+
+/**
+ * Minimal app context shared between vdom and vapor
+ */
+export interface GenericAppContext {
app: App // for devtools
+ config: GenericAppConfig
+ provides: Record<string | symbol, any>
+ components?: Record<string, Component>
+ directives?: Record<string, Directive>
+ /**
+ * HMR only
+ * @internal
+ */
+ reload?: () => void
+}
+
+export interface AppContext extends GenericAppContext {
config: AppConfig
- mixins: ComponentOptions[]
components: Record<string, Component>
directives: Record<string, Directive>
- provides: Record<string | symbol, any>
+ mixins: ComponentOptions[]
/**
* Cache for merged/normalized component options
* @internal
*/
emitsCache: WeakMap<ConcreteComponent, ObjectEmitsOptions | null>
- /**
- * HMR only
- * @internal
- */
- reload?: () => void
/**
* v2 compat only
* @internal
import {
type AppConfig,
type AppContext,
+ type GenericAppContext,
createAppContext,
} from './apiCreateApp'
import { type Directive, validateDirectiveName } from './directives'
uid: number
type: GenericComponent
parent: GenericComponentInstance | null
- appContext: AppContext
+ appContext: GenericAppContext
/**
* Object containing values this component provides for its descendants
* @internal
event: string,
...rawArgs: any[]
): ComponentPublicInstance | null | undefined {
- if (instance.isUnmounted) return
return baseEmit(
instance,
instance.vnode.props || EMPTY_OBJ,
event: string,
...rawArgs: any[]
): ComponentPublicInstance | null | undefined {
+ if (instance.isUnmounted) return
if (__DEV__) {
const { emitsOptions, propsOptions } = instance
if (emitsOptions) {
const isModelListener = event.startsWith('update:')
// for v-model update:xxx events, apply modifiers on args
+ // it's ok to use static get because modelModifiers can only be in the static
+ // part of the props
const modifiers = isModelListener && getModelModifiers(props, event.slice(7))
if (modifiers) {
if (modifiers.trim) {
App,
AppConfig,
AppContext,
+ GenericAppContext,
Plugin,
ObjectPlugin,
FunctionPlugin,
type LifecycleHook,
nextUid,
} from './component'
+export { pushWarningContext, popWarningContext } from './warning'
type ComponentTraceStack = TraceEntry[]
+/**
+ * @internal
+ */
export function pushWarningContext(
ctx: GenericComponentInstance | VNode,
): void {
stack.push(ctx)
}
+/**
+ * @internal
+ */
export function popWarningContext(): void {
stack.pop()
}
import {
- type AppContext,
type ComponentInternalOptions,
type ComponentPropsOptions,
EffectScope,
type EmitsOptions,
+ type GenericAppContext,
type GenericComponentInstance,
type LifecycleHook,
type NormalizedPropsOptions,
type ObjectEmitsOptions,
nextUid,
+ popWarningContext,
+ pushWarningContext,
} from '@vue/runtime-core'
import type { Block } from '../block'
import type { Data } from '@vue/runtime-shared'
currentInstance = instance
instance.scope.on()
+ if (__DEV__) {
+ pushWarningContext(instance)
+ }
+
const setupFn = isFunction(component) ? component : component.setup
const setupContext = setupFn!.length > 1 ? new SetupContext(instance) : null
instance.block = setupFn!(
})
}
+ if (__DEV__) {
+ popWarningContext()
+ }
+
instance.scope.off()
currentInstance = prevInstance
resetTracking()
export let currentInstance: VaporComponentInstance | null = null
+const emptyContext: GenericAppContext = {
+ app: null as any,
+ config: {},
+ provides: /*@__PURE__*/ Object.create(null),
+}
+
export class VaporComponentInstance implements GenericComponentInstance {
uid: number
type: VaporComponent
parent: GenericComponentInstance | null
- appContext: AppContext
+ appContext: GenericAppContext
block: Block
scope: EffectScope
this.uid = nextUid()
this.type = comp
this.parent = currentInstance
- // @ts-expect-error TODO use proper appContext
- this.appContext = currentInstance ? currentInstance.appContext : {}
+ this.appContext = currentInstance
+ ? currentInstance.appContext
+ : emptyContext
this.block = null! // to be set
this.scope = new EffectScope(true)
type VaporComponentInstance,
currentInstance,
} from './component'
-import { NOOP, hasOwn, isArray } from '@vue/shared'
+import { EMPTY_OBJ, NOOP, hasOwn, isArray } from '@vue/shared'
import { resolveSource } from './componentProps'
/**
event: string,
...rawArgs: any[]
): void {
- const rawProps = instance.rawProps
- if (!rawProps || instance.isUnmounted) return
- baseEmit(instance, rawProps, propGetter, event, ...rawArgs)
+ baseEmit(
+ instance,
+ instance.rawProps || EMPTY_OBJ,
+ propGetter,
+ event,
+ ...rawArgs,
+ )
}
function propGetter(rawProps: Record<string, any>, key: string) {