-import { Component, Data, ComponentInternalInstance } from './component'
+import { Component, Data } from './component'
import { ComponentOptions } from './apiOptions'
import { ComponentPublicInstance } from './componentProxy'
import { Directive } from './directives'
vnode.appContext = context
render(vnode, rootContainer)
isMounted = true
- return (vnode.component as ComponentInternalInstance).renderProxy
+ return vnode.component!.renderProxy
} else if (__DEV__) {
warn(
`App has already been mounted. Create a new app instance instead.`
// implementation, close to no-op
export function createComponent(options: any) {
- return isFunction(options) ? { setup: options } : (options as any)
+ return isFunction(options) ? { setup: options } : options
}
) {
const Component = instance.type as ComponentOptions
// 1. create render proxy
- instance.renderProxy = new Proxy(instance, PublicInstanceProxyHandlers) as any
+ instance.renderProxy = new Proxy(instance, PublicInstanceProxyHandlers)
// 2. create props proxy
// the propsProxy is a reactive AND readonly proxy to the actual props.
// it will be updated in resolveProps() on updates before render
if (__FEATURE_SUSPENSE__) {
// async setup returned Promise.
// bail here and wait for re-entry.
- instance.asyncDep = setupResult as Promise<any>
+ instance.asyncDep = setupResult
} else if (__DEV__) {
warn(
`setup() returned a Promise, but the version of Vue you are using ` +
const SetupProxyHandlers: { [key: string]: ProxyHandler<any> } = {}
;['attrs', 'slots', 'refs'].forEach((type: string) => {
SetupProxyHandlers[type] = {
- get: (instance, key) => (instance[type] as any)[key],
- has: (instance, key) =>
- key === SetupProxySymbol || key in (instance[type] as any),
- ownKeys: instance => Reflect.ownKeys(instance[type] as any),
+ get: (instance, key) => instance[type][key],
+ has: (instance, key) => key === SetupProxySymbol || key in instance[type],
+ ownKeys: instance => Reflect.ownKeys(instance[type]),
// this is necessary for ownKeys to work properly
getOwnPropertyDescriptor: (instance, key) =>
Reflect.getOwnPropertyDescriptor(instance[type], key),
slots: new Proxy(instance, SetupProxyHandlers.slots),
refs: new Proxy(instance, SetupProxyHandlers.refs),
emit: instance.emit
- } as any
+ }
return __DEV__ ? Object.freeze(context) : context
}
_options: ComponentPropsOptions | void
) {
const hasDeclaredProps = _options != null
- const options = normalizePropsOptions(_options) as NormalizedPropsOptions
+ const options = normalizePropsOptions(_options)!
if (!rawProps && !hasDeclaredProps) {
return
}
function normalizePropsOptions(
raw: ComponentPropsOptions | void
-): NormalizedPropsOptions | void {
+): NormalizedPropsOptions | null {
if (!raw) {
- return
+ return null
}
if (normalizationMap.has(raw)) {
return normalizationMap.get(raw)
return renderContext[key]
} else if (hasOwn(props, key)) {
// return the value from propsProxy for ref unwrapping and readonly
- return (propsProxy as any)[key]
+ return propsProxy![key]
} else {
// TODO simplify this?
switch (key) {
currentRenderingInstance = instance
try {
if (vnode.shapeFlag & ShapeFlags.STATEFUL_COMPONENT) {
- result = normalizeVNode((instance.render as Function).call(renderProxy))
+ result = normalizeVNode(instance.render!.call(renderProxy))
} else {
// functional
const render = Component as FunctionalComponent
}
if (patchFlag & PatchFlags.FULL_PROPS) {
// presence of this flag indicates props are always non-null
- return hasPropsChanged(prevProps as Data, nextProps as Data)
+ return hasPropsChanged(prevProps!, nextProps!)
} else if (patchFlag & PatchFlags.PROPS) {
- const dynamicProps = nextVNode.dynamicProps as string[]
+ const dynamicProps = nextVNode.dynamicProps!
for (let i = 0; i < dynamicProps.length; i++) {
const key = dynamicProps[i]
- if ((nextProps as any)[key] !== (prevProps as any)[key]) {
+ if (nextProps![key] !== prevProps![key]) {
return true
}
}
): ReactiveEffectOptions {
return {
scheduler: queueJob,
- onTrack: instance.rtc
- ? e => invokeHooks(instance.rtc as Function[], e)
- : void 0,
- onTrigger: instance.rtg
- ? e => invokeHooks(instance.rtg as Function[], e)
- : void 0
+ onTrack: instance.rtc ? e => invokeHooks(instance.rtc!, e) : void 0,
+ onTrigger: instance.rtg ? e => invokeHooks(instance.rtg!, e) : void 0
}
}
// bail out and go through a full diff because we need to unset the old key
if (patchFlag & PatchFlags.PROPS) {
// if the flag is present then dynamicProps must be non-null
- const propsToUpdate = n2.dynamicProps as string[]
+ const propsToUpdate = n2.dynamicProps!
for (let i = 0; i < propsToUpdate.length; i++) {
const key = propsToUpdate[i]
const prev = oldProps[key]
if (dynamicChildren != null) {
// children fast path
- const olddynamicChildren = n1.dynamicChildren as HostVNode[]
+ const olddynamicChildren = n1.dynamicChildren!
for (let i = 0; i < dynamicChildren.length; i++) {
patch(
olddynamicChildren[i],
isSVG: boolean,
optimized: boolean
) {
- const fragmentStartAnchor = (n2.el = n1
- ? n1.el
- : hostCreateComment('')) as HostNode
+ const fragmentStartAnchor = (n2.el = n1 ? n1.el : hostCreateComment(''))!
const fragmentEndAnchor = (n2.anchor = n1
? n1.anchor
- : hostCreateComment('')) as HostNode
+ : hostCreateComment(''))!
if (n1 == null) {
hostInsert(fragmentStartAnchor, container, anchor)
hostInsert(fragmentEndAnchor, container, anchor)
}
} else {
// update content
- const target = (n2.target = n1.target) as HostElement
+ const target = (n2.target = n1.target)!
if (patchFlag === PatchFlags.TEXT) {
hostSetElementText(target, children as string)
} else if (!optimized) {
isSVG: boolean,
optimized: boolean
) {
- const suspense = (n2.suspense = n1.suspense) as HostSuspsenseBoundary
+ const suspense = (n2.suspense = n1.suspense)!
suspense.vnode = n2
const { content, fallback } = normalizeSuspenseChildren(n2)
const oldSubTree = suspense.subTree
isSVG
)
} else {
- const instance = (n2.component =
- n1.component) as ComponentInternalInstance
+ const instance = (n2.component = n1.component)!
if (shouldUpdateComponent(n1, n2, optimized)) {
if (
}
}
if (n2.ref !== null && parentComponent !== null) {
- setRef(
- n2.ref,
- n1 && n1.ref,
- parentComponent,
- (n2.component as ComponentInternalInstance).renderProxy
- )
+ setRef(n2.ref, n1 && n1.ref, parentComponent, n2.component!.renderProxy)
}
}
return
}
if (__FEATURE_SUSPENSE__ && vnode.type === Suspense) {
- const suspense = vnode.suspense as SuspenseBoundary
+ const suspense = vnode.suspense!
move(
suspense.isResolved ? suspense.subTree : suspense.fallbackTree,
container,
return
}
if (vnode.type === Fragment) {
- hostInsert(vnode.el as HostNode, container, anchor)
+ hostInsert(vnode.el!, container, anchor)
const children = vnode.children as HostVNode[]
for (let i = 0; i < children.length; i++) {
move(children[i], container, anchor)
}
- hostInsert(vnode.anchor as HostNode, container, anchor)
+ hostInsert(vnode.anchor!, container, anchor)
} else {
- hostInsert(vnode.el as HostNode, container, anchor)
+ hostInsert(vnode.el!, container, anchor)
}
}
}
if (doRemove) {
- hostRemove(vnode.el as HostNode)
+ hostRemove(vnode.el!)
if (anchor != null) hostRemove(anchor)
}
doRemove?: boolean
) {
suspense.isUnmounted = true
- unmount(
- suspense.subTree as HostVNode,
- parentComponent,
- parentSuspense,
- doRemove
- )
+ unmount(suspense.subTree, parentComponent, parentSuspense, doRemove)
if (!suspense.isResolved) {
- unmount(
- suspense.fallbackTree as HostVNode,
- parentComponent,
- parentSuspense,
- doRemove
- )
+ unmount(suspense.fallbackTree, parentComponent, parentSuspense, doRemove)
}
}
suspense.isResolved ? suspense.subTree : suspense.fallbackTree
)
}
- return hostNextSibling((anchor || el) as HostNode)
+ return hostNextSibling((anchor || el)!)
}
function setRef(
arg?: string,
modifiers?: DirectiveModifiers
) {
- let valueCacheForDir = valueCache.get(directive) as WeakMap<VNode, any>
+ let valueCacheForDir = valueCache.get(directive)!
if (!valueCacheForDir) {
valueCacheForDir = new WeakMap<VNode, any>()
valueCache.set(directive, valueCacheForDir)
}
for (const key in directive) {
- const hook = directive[key as keyof Directive] as DirectiveHook
+ const hook = directive[key as keyof Directive]!
const hookKey = `vnode` + key[0].toUpperCase() + key.slice(1)
const vnodeHook = (vnode: VNode, prevVNode: VNode | null) => {
let oldValue
}
const existing = props[hookKey]
props[hookKey] = existing
- ? [].concat(existing as any, vnodeHook as any)
+ ? [].concat(existing, vnodeHook as any)
: vnodeHook
}
}
) {
const res = callWithErrorHandling(fn, instance, type, args)
if (res != null && !res._isVue && typeof res.then === 'function') {
- ;(res as Promise<any>).catch(err => {
+ res.catch((err: any) => {
handleError(err, instance, type)
})
}
import { warn } from '../warning'
export function resolveComponent(name: string): Component | undefined {
- return resolveAsset('components', name) as any
+ return resolveAsset('components', name)
}
export function resolveDirective(name: string): Directive | undefined {
- return resolveAsset('directives', name) as any
+ return resolveAsset('directives', name)
}
+// overload 1: components
+function resolveAsset(type: 'components', name: string): Component | undefined
+// overload 2: directives
+function resolveAsset(type: 'directives', name: string): Directive | undefined
+
function resolveAsset(type: 'components' | 'directives', name: string) {
const instance = currentRenderingInstance || currentInstance
if (instance) {
}
while ((job = queue.shift())) {
if (__DEV__) {
- const seen = seenJobs as JobCountMap
+ const seen = seenJobs!
if (!seen.has(job)) {
seen.set(job, 1)
} else {
- const count = seen.get(job) as number
+ const count = seen.get(job)!
if (count > RECURSION_LIMIT) {
throw new Error(
'Maximum recursive updates exceeded. ' +
recurseCount: 0
})
}
- const parentInstance: ComponentInternalInstance | null = (currentVNode.component as ComponentInternalInstance)
+ const parentInstance: ComponentInternalInstance | null = currentVNode.component!
.parent
currentVNode = parentInstance && parentInstance.vnode
}
recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``
const open = padding + `<${formatComponentName(vnode)}`
const close = `>` + postfix
- const rootLabel =
- (vnode.component as ComponentInternalInstance).parent == null
- ? `(Root)`
- : ``
+ const rootLabel = vnode.component!.parent == null ? `(Root)` : ``
return vnode.props
? [open, ...formatProps(vnode.props), close, rootLabel]
: [open + close, rootLabel]