feat(compiler): element codegen
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import {
|
||||
ComponentInternalInstance,
|
||||
Data,
|
||||
currentInstance,
|
||||
Component,
|
||||
SetupContext
|
||||
} from './component'
|
||||
@@ -11,9 +10,7 @@ import {
|
||||
isString,
|
||||
isObject,
|
||||
isArray,
|
||||
EMPTY_OBJ,
|
||||
capitalize,
|
||||
camelize
|
||||
EMPTY_OBJ
|
||||
} from '@vue/shared'
|
||||
import { computed } from './apiReactivity'
|
||||
import { watch, WatchOptions, CleanupRegistrator } from './apiWatch'
|
||||
@@ -29,12 +26,10 @@ import {
|
||||
onUnmounted
|
||||
} from './apiLifecycle'
|
||||
import { DebuggerEvent, reactive } from '@vue/reactivity'
|
||||
import { warn } from './warning'
|
||||
import { ComponentPropsOptions, ExtractPropTypes } from './componentProps'
|
||||
import { Directive } from './directives'
|
||||
import { VNodeChild } from './vnode'
|
||||
import { ComponentPublicInstance } from './componentPublicInstanceProxy'
|
||||
import { currentRenderingInstance } from './componentRenderUtils'
|
||||
|
||||
interface ComponentOptionsBase<
|
||||
Props,
|
||||
@@ -387,32 +382,3 @@ function applyMixins(
|
||||
applyOptions(instance, mixins[i], true)
|
||||
}
|
||||
}
|
||||
|
||||
export function resolveComponent(name: string): Component | undefined {
|
||||
return resolveAsset('components', name) as any
|
||||
}
|
||||
|
||||
export function resolveDirective(name: string): Directive | undefined {
|
||||
return resolveAsset('directives', name) as any
|
||||
}
|
||||
|
||||
function resolveAsset(type: 'components' | 'directives', name: string) {
|
||||
const instance = currentRenderingInstance || currentInstance
|
||||
if (instance) {
|
||||
let camelized
|
||||
const registry = instance[type]
|
||||
const res =
|
||||
registry[name] ||
|
||||
registry[(camelized = camelize(name))] ||
|
||||
registry[capitalize(camelized)]
|
||||
if (__DEV__ && !res) {
|
||||
warn(`Failed to resolve ${type.slice(0, -1)}: ${name}`)
|
||||
}
|
||||
return res
|
||||
} else if (__DEV__) {
|
||||
warn(
|
||||
`resolve${capitalize(type.slice(0, -1))} ` +
|
||||
`can only be used in render() or setup().`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ export const PublicInstanceProxyHandlers = {
|
||||
// return the value from propsProxy for ref unwrapping and readonly
|
||||
return (propsProxy as any)[key]
|
||||
} else {
|
||||
// TODO simplify this?
|
||||
switch (key) {
|
||||
case '$data':
|
||||
return data
|
||||
@@ -79,6 +80,7 @@ export const PublicInstanceProxyHandlers = {
|
||||
},
|
||||
has(target: ComponentInternalInstance, key: string): boolean {
|
||||
const { renderContext, data, props } = target
|
||||
// TODO handle $xxx properties
|
||||
return (
|
||||
(data !== EMPTY_OBJ && hasOwn(data, key)) ||
|
||||
hasOwn(renderContext, key) ||
|
||||
|
||||
2
packages/runtime-core/src/helpers/renderList.ts
Normal file
2
packages/runtime-core/src/helpers/renderList.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
// TODO
|
||||
export function renderList() {}
|
||||
34
packages/runtime-core/src/helpers/resolveAssets.ts
Normal file
34
packages/runtime-core/src/helpers/resolveAssets.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { currentRenderingInstance } from '../componentRenderUtils'
|
||||
import { currentInstance, Component } from '../component'
|
||||
import { Directive } from '../directives'
|
||||
import { camelize, capitalize } from '@vue/shared'
|
||||
import { warn } from '../warning'
|
||||
|
||||
export function resolveComponent(name: string): Component | undefined {
|
||||
return resolveAsset('components', name) as any
|
||||
}
|
||||
|
||||
export function resolveDirective(name: string): Directive | undefined {
|
||||
return resolveAsset('directives', name) as any
|
||||
}
|
||||
|
||||
function resolveAsset(type: 'components' | 'directives', name: string) {
|
||||
const instance = currentRenderingInstance || currentInstance
|
||||
if (instance) {
|
||||
let camelized
|
||||
const registry = instance[type]
|
||||
const res =
|
||||
registry[name] ||
|
||||
registry[(camelized = camelize(name))] ||
|
||||
registry[capitalize(camelized)]
|
||||
if (__DEV__ && !res) {
|
||||
warn(`Failed to resolve ${type.slice(0, -1)}: ${name}`)
|
||||
}
|
||||
return res
|
||||
} else if (__DEV__) {
|
||||
warn(
|
||||
`resolve${capitalize(type.slice(0, -1))} ` +
|
||||
`can only be used in render() or setup().`
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,8 @@ export {
|
||||
|
||||
// Internal, for compiler generated code
|
||||
export { applyDirectives } from './directives'
|
||||
export { resolveComponent, resolveDirective } from './componentOptions'
|
||||
export { resolveComponent, resolveDirective } from './helpers/resolveAssets'
|
||||
export { renderList } from './helpers/renderList'
|
||||
|
||||
// Internal, for integration with runtime compiler
|
||||
export { registerRuntimeCompiler } from './component'
|
||||
|
||||
Reference in New Issue
Block a user