fix(build): remove __RUNTIME_COMPILE__ flag

behavior should be consistent in all builds. fix #817
This commit is contained in:
Evan You 2020-03-11 16:39:26 -04:00
parent f59779706b
commit 206640a2d8
6 changed files with 16 additions and 29 deletions

View File

@ -19,7 +19,7 @@ const { createRecord, rerender, reload } = __VUE_HMR_RUNTIME__
function compileToFunction(template: string) { function compileToFunction(template: string) {
const { code } = baseCompile(template) const { code } = baseCompile(template)
const render = new Function('Vue', code)(runtimeTest) as RenderFunction const render = new Function('Vue', code)(runtimeTest) as RenderFunction
render.isRuntimeCompiled = true render._rc = true // isRuntimeCompiled
return render return render
} }

View File

@ -96,7 +96,7 @@ export interface SetupContext {
export type RenderFunction = { export type RenderFunction = {
(): VNodeChild (): VNodeChild
isRuntimeCompiled?: boolean _rc?: boolean // isRuntimeCompiled
} }
export interface ComponentInternalInstance { export interface ComponentInternalInstance {
@ -437,29 +437,24 @@ function finishComponentSetup(
instance.render = Component.render as RenderFunction instance.render = Component.render as RenderFunction
} }
} else if (!instance.render) { } else if (!instance.render) {
if (__RUNTIME_COMPILE__ && Component.template && !Component.render) { if (compile && Component.template && !Component.render) {
// __RUNTIME_COMPILE__ ensures `compile` is provided Component.render = compile(Component.template, {
Component.render = compile!(Component.template, {
isCustomElement: instance.appContext.config.isCustomElement || NO isCustomElement: instance.appContext.config.isCustomElement || NO
}) })
// mark the function as runtime compiled // mark the function as runtime compiled
;(Component.render as RenderFunction).isRuntimeCompiled = true ;(Component.render as RenderFunction)._rc = true
} }
if (__DEV__ && !Component.render) { if (__DEV__ && !Component.render) {
/* istanbul ignore if */ /* istanbul ignore if */
if (!__RUNTIME_COMPILE__ && Component.template) { if (!compile && Component.template) {
warn( warn(
`Component provides template but the build of Vue you are running ` + `Component provides template but the build of Vue you are running ` +
`does not support runtime template compilation. Either use the ` + `does not support runtime template compilation. Either use the ` +
`full build or pre-compile the template using Vue CLI.` `full build or pre-compile the template using Vue CLI.`
) )
} else { } else {
warn( warn(`Component is missing template or render function.`)
`Component is missing${
__RUNTIME_COMPILE__ ? ` template or` : ``
} render function.`
)
} }
} }
@ -468,7 +463,7 @@ function finishComponentSetup(
// for runtime-compiled render functions using `with` blocks, the render // for runtime-compiled render functions using `with` blocks, the render
// proxy used needs a different `has` handler which is more performant and // proxy used needs a different `has` handler which is more performant and
// also only allows a whitelist of globals to fallthrough. // also only allows a whitelist of globals to fallthrough.
if (__RUNTIME_COMPILE__ && instance.render.isRuntimeCompiled) { if (instance.render._rc) {
instance.withProxy = new Proxy( instance.withProxy = new Proxy(
instance, instance,
runtimeCompiledRenderProxyHandlers runtimeCompiledRenderProxyHandlers

View File

@ -75,10 +75,6 @@ const enum AccessTypes {
export const PublicInstanceProxyHandlers: ProxyHandler<any> = { export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
get(target: ComponentInternalInstance, key: string) { get(target: ComponentInternalInstance, key: string) {
// fast path for unscopables when using `with` block
if (__RUNTIME_COMPILE__ && (key as any) === Symbol.unscopables) {
return
}
const { const {
renderContext, renderContext,
data, data,
@ -189,6 +185,13 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
export const runtimeCompiledRenderProxyHandlers = { export const runtimeCompiledRenderProxyHandlers = {
...PublicInstanceProxyHandlers, ...PublicInstanceProxyHandlers,
get(target: ComponentInternalInstance, key: string) {
// fast path for unscopables when using `with` block
if ((key as any) === Symbol.unscopables) {
return
}
return PublicInstanceProxyHandlers.get!(target, key, target)
},
has(_target: ComponentInternalInstance, key: string) { has(_target: ComponentInternalInstance, key: string) {
return key[0] !== '_' && !isGloballyWhitelisted(key) return key[0] !== '_' && !isGloballyWhitelisted(key)
} }

View File

@ -58,12 +58,7 @@ export const createApp = ((...args) => {
const container = normalizeContainer(containerOrSelector) const container = normalizeContainer(containerOrSelector)
if (!container) return if (!container) return
const component = app._component const component = app._component
if ( if (!isFunction(component) && !component.render && !component.template) {
__RUNTIME_COMPILE__ &&
!isFunction(component) &&
!component.render &&
!component.template
) {
component.template = container.innerHTML component.template = container.innerHTML
} }
// clear content before mounting // clear content before mounting

View File

@ -13,7 +13,6 @@
], ],
"buildOptions": { "buildOptions": {
"name": "Vue", "name": "Vue",
"isRuntimeCompileBuild": true,
"formats": [ "formats": [
"esm-bundler", "esm-bundler",
"esm-bundler-runtime", "esm-bundler-runtime",

View File

@ -77,7 +77,6 @@ function createConfig(format, output, plugins = []) {
const isRawESMBuild = format === 'esm' const isRawESMBuild = format === 'esm'
const isNodeBuild = format === 'cjs' const isNodeBuild = format === 'cjs'
const isBundlerESMBuild = /esm-bundler/.test(format) const isBundlerESMBuild = /esm-bundler/.test(format)
const isRuntimeCompileBuild = packageOptions.isRuntimeCompileBuild
if (isGlobalBuild) { if (isGlobalBuild) {
output.name = packageOptions.name output.name = packageOptions.name
@ -132,7 +131,6 @@ function createConfig(format, output, plugins = []) {
// isBrowserBuild? // isBrowserBuild?
(isGlobalBuild || isRawESMBuild || isBundlerESMBuild) && (isGlobalBuild || isRawESMBuild || isBundlerESMBuild) &&
!packageOptions.enableNonBrowserBranches, !packageOptions.enableNonBrowserBranches,
isRuntimeCompileBuild,
isGlobalBuild, isGlobalBuild,
isNodeBuild isNodeBuild
), ),
@ -152,7 +150,6 @@ function createReplacePlugin(
isProduction, isProduction,
isBundlerESMBuild, isBundlerESMBuild,
isBrowserBuild, isBrowserBuild,
isRuntimeCompileBuild,
isGlobalBuild, isGlobalBuild,
isNodeBuild isNodeBuild
) { ) {
@ -170,8 +167,6 @@ function createReplacePlugin(
__BROWSER__: isBrowserBuild, __BROWSER__: isBrowserBuild,
// is targeting bundlers? // is targeting bundlers?
__BUNDLER__: isBundlerESMBuild, __BUNDLER__: isBundlerESMBuild,
// support compile in browser?
__RUNTIME_COMPILE__: isRuntimeCompileBuild,
__GLOBAL__: isGlobalBuild, __GLOBAL__: isGlobalBuild,
// is targeting Node (SSR)? // is targeting Node (SSR)?
__NODE_JS__: isNodeBuild, __NODE_JS__: isNodeBuild,