Skip to content

Commit

Permalink
fix(runtime-core): replace __RUNTIME_BUILD__ checks by compile function
Browse files Browse the repository at this point in the history
  • Loading branch information
yabab-dev committed Mar 11, 2020
1 parent 7af089d commit 20a9b91
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
15 changes: 7 additions & 8 deletions packages/runtime-core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,11 @@ type CompileFunction = (
options?: CompilerOptions
) => RenderFunction

let compile: CompileFunction | undefined
export let registeredCompileFunction: CompileFunction | undefined

// exported method uses any to avoid d.ts relying on the compiler types.
export function registerRuntimeCompiler(_compile: any) {
compile = _compile
registeredCompileFunction = _compile
}

function finishComponentSetup(
Expand All @@ -437,9 +437,8 @@ function finishComponentSetup(
instance.render = Component.render as RenderFunction
}
} else if (!instance.render) {
if (__RUNTIME_COMPILE__ && Component.template && !Component.render) {
// __RUNTIME_COMPILE__ ensures `compile` is provided
Component.render = compile!(Component.template, {
if (registeredCompileFunction && Component.template && !Component.render) {
Component.render = registeredCompileFunction(Component.template, {
isCustomElement: instance.appContext.config.isCustomElement || NO
})
// mark the function as runtime compiled
Expand All @@ -448,7 +447,7 @@ function finishComponentSetup(

if (__DEV__ && !Component.render) {
/* istanbul ignore if */
if (!__RUNTIME_COMPILE__ && Component.template) {
if (!registeredCompileFunction && Component.template) {
warn(
`Component provides template but the build of Vue you are running ` +
`does not support runtime template compilation. Either use the ` +
Expand All @@ -457,7 +456,7 @@ function finishComponentSetup(
} else {
warn(
`Component is missing${
__RUNTIME_COMPILE__ ? ` template or` : ``
registeredCompileFunction ? ` template or` : ``
} render function.`
)
}
Expand All @@ -468,7 +467,7 @@ function finishComponentSetup(
// for runtime-compiled render functions using `with` blocks, the render
// proxy used needs a different `has` handler which is more performant and
// also only allows a whitelist of globals to fallthrough.
if (__RUNTIME_COMPILE__ && instance.render.isRuntimeCompiled) {
if (registeredCompileFunction && instance.render.isRuntimeCompiled) {
instance.withProxy = new Proxy(
instance,
runtimeCompiledRenderProxyHandlers
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/componentProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const enum AccessTypes {
export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
get(target: ComponentInternalInstance, key: string) {
// fast path for unscopables when using `with` block
if (__RUNTIME_COMPILE__ && (key as any) === Symbol.unscopables) {
if ((key as any) === Symbol.unscopables) {
return
}
const {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export { defineComponent } from './apiDefineComponent'

// For getting a hold of the internal instance in setup() - useful for advanced
// plugins
export { getCurrentInstance } from './component'
export { getCurrentInstance, registeredCompileFunction } from './component'

// For raw render function users
export { h } from './h'
Expand Down
5 changes: 3 additions & 2 deletions packages/runtime-dom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
Renderer,
HydrationRenderer,
App,
RootHydrateFunction
RootHydrateFunction,
registeredCompileFunction
} from '@vue/runtime-core'
import { nodeOps } from './nodeOps'
import { patchProp } from './patchProp'
Expand Down Expand Up @@ -59,7 +60,7 @@ export const createApp = ((...args) => {
if (!container) return
const component = app._component
if (
__RUNTIME_COMPILE__ &&
registeredCompileFunction &&
!isFunction(component) &&
!component.render &&
!component.template
Expand Down

0 comments on commit 20a9b91

Please sign in to comment.