refactor: move compile into compiler-core

This commit is contained in:
Evan You
2019-09-20 12:16:19 -04:00
parent 3e1973f065
commit 8a923f6a52
12 changed files with 106 additions and 77 deletions

View File

@@ -24,6 +24,7 @@ import {
isObject
} from '@vue/shared'
import { SuspenseBoundary } from './suspense'
import { CompilerOptions } from '@vue/compiler-dom'
export type Data = { [key: string]: unknown }
@@ -61,7 +62,7 @@ export interface SetupContext {
emit: Emit
}
type RenderFunction = () => VNodeChild
export type RenderFunction = () => VNodeChild
export interface ComponentInternalInstance {
type: FunctionalComponent | ComponentOptions
@@ -298,8 +299,14 @@ export function handleSetupResult(
finishComponentSetup(instance, parentSuspense)
}
let compile: Function | undefined
export function registerCompiler(_compile: Function) {
type CompileFunction = (
template: string,
options?: CompilerOptions
) => RenderFunction
let compile: CompileFunction | undefined
export function registerRuntimeCompiler(_compile: CompileFunction) {
compile = _compile
}
@@ -311,7 +318,9 @@ function finishComponentSetup(
if (!instance.render) {
if (Component.template && !Component.render) {
if (compile) {
Component.render = compile(Component.template)
Component.render = compile(Component.template, {
onError(err) {}
})
} else if (__DEV__) {
warn(
`Component provides template but the build of Vue you are running ` +

View File

@@ -40,7 +40,7 @@ export { applyDirectives } from './directives'
export { resolveComponent, resolveDirective } from './componentOptions'
// Internal, for integration with runtime compiler
export { registerCompiler } from './component'
export { registerRuntimeCompiler } from './component'
// Types -----------------------------------------------------------------------
@@ -50,7 +50,8 @@ export { VNode, VNodeTypes } from './vnode'
export {
Component,
FunctionalComponent,
ComponentInternalInstance
ComponentInternalInstance,
RenderFunction
} from './component'
export {
ComponentOptions,
@@ -58,6 +59,7 @@ export {
ComponentOptionsWithProps,
ComponentOptionsWithArrayProps
} from './componentOptions'
export { ComponentPublicInstance } from './componentPublicInstanceProxy'
export { RendererOptions } from './createRenderer'
export { Slot, Slots } from './componentSlots'