Skip to content

Commit 206640a

Browse files
committed
fix(build): remove __RUNTIME_COMPILE__ flag
behavior should be consistent in all builds. fix #817
1 parent f597797 commit 206640a

File tree

6 files changed

+16
-29
lines changed

6 files changed

+16
-29
lines changed

packages/runtime-core/__tests__/hmr.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const { createRecord, rerender, reload } = __VUE_HMR_RUNTIME__
1919
function compileToFunction(template: string) {
2020
const { code } = baseCompile(template)
2121
const render = new Function('Vue', code)(runtimeTest) as RenderFunction
22-
render.isRuntimeCompiled = true
22+
render._rc = true // isRuntimeCompiled
2323
return render
2424
}
2525

packages/runtime-core/src/component.ts

+7-12
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export interface SetupContext {
9696

9797
export type RenderFunction = {
9898
(): VNodeChild
99-
isRuntimeCompiled?: boolean
99+
_rc?: boolean // isRuntimeCompiled
100100
}
101101

102102
export interface ComponentInternalInstance {
@@ -437,29 +437,24 @@ function finishComponentSetup(
437437
instance.render = Component.render as RenderFunction
438438
}
439439
} else if (!instance.render) {
440-
if (__RUNTIME_COMPILE__ && Component.template && !Component.render) {
441-
// __RUNTIME_COMPILE__ ensures `compile` is provided
442-
Component.render = compile!(Component.template, {
440+
if (compile && Component.template && !Component.render) {
441+
Component.render = compile(Component.template, {
443442
isCustomElement: instance.appContext.config.isCustomElement || NO
444443
})
445444
// mark the function as runtime compiled
446-
;(Component.render as RenderFunction).isRuntimeCompiled = true
445+
;(Component.render as RenderFunction)._rc = true
447446
}
448447

449448
if (__DEV__ && !Component.render) {
450449
/* istanbul ignore if */
451-
if (!__RUNTIME_COMPILE__ && Component.template) {
450+
if (!compile && Component.template) {
452451
warn(
453452
`Component provides template but the build of Vue you are running ` +
454453
`does not support runtime template compilation. Either use the ` +
455454
`full build or pre-compile the template using Vue CLI.`
456455
)
457456
} else {
458-
warn(
459-
`Component is missing${
460-
__RUNTIME_COMPILE__ ? ` template or` : ``
461-
} render function.`
462-
)
457+
warn(`Component is missing template or render function.`)
463458
}
464459
}
465460

@@ -468,7 +463,7 @@ function finishComponentSetup(
468463
// for runtime-compiled render functions using `with` blocks, the render
469464
// proxy used needs a different `has` handler which is more performant and
470465
// also only allows a whitelist of globals to fallthrough.
471-
if (__RUNTIME_COMPILE__ && instance.render.isRuntimeCompiled) {
466+
if (instance.render._rc) {
472467
instance.withProxy = new Proxy(
473468
instance,
474469
runtimeCompiledRenderProxyHandlers

packages/runtime-core/src/componentProxy.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ const enum AccessTypes {
7575

7676
export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
7777
get(target: ComponentInternalInstance, key: string) {
78-
// fast path for unscopables when using `with` block
79-
if (__RUNTIME_COMPILE__ && (key as any) === Symbol.unscopables) {
80-
return
81-
}
8278
const {
8379
renderContext,
8480
data,
@@ -189,6 +185,13 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
189185

190186
export const runtimeCompiledRenderProxyHandlers = {
191187
...PublicInstanceProxyHandlers,
188+
get(target: ComponentInternalInstance, key: string) {
189+
// fast path for unscopables when using `with` block
190+
if ((key as any) === Symbol.unscopables) {
191+
return
192+
}
193+
return PublicInstanceProxyHandlers.get!(target, key, target)
194+
},
192195
has(_target: ComponentInternalInstance, key: string) {
193196
return key[0] !== '_' && !isGloballyWhitelisted(key)
194197
}

packages/runtime-dom/src/index.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,7 @@ export const createApp = ((...args) => {
5858
const container = normalizeContainer(containerOrSelector)
5959
if (!container) return
6060
const component = app._component
61-
if (
62-
__RUNTIME_COMPILE__ &&
63-
!isFunction(component) &&
64-
!component.render &&
65-
!component.template
66-
) {
61+
if (!isFunction(component) && !component.render && !component.template) {
6762
component.template = container.innerHTML
6863
}
6964
// clear content before mounting

packages/vue/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
],
1414
"buildOptions": {
1515
"name": "Vue",
16-
"isRuntimeCompileBuild": true,
1716
"formats": [
1817
"esm-bundler",
1918
"esm-bundler-runtime",

rollup.config.js

-5
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ function createConfig(format, output, plugins = []) {
7777
const isRawESMBuild = format === 'esm'
7878
const isNodeBuild = format === 'cjs'
7979
const isBundlerESMBuild = /esm-bundler/.test(format)
80-
const isRuntimeCompileBuild = packageOptions.isRuntimeCompileBuild
8180

8281
if (isGlobalBuild) {
8382
output.name = packageOptions.name
@@ -132,7 +131,6 @@ function createConfig(format, output, plugins = []) {
132131
// isBrowserBuild?
133132
(isGlobalBuild || isRawESMBuild || isBundlerESMBuild) &&
134133
!packageOptions.enableNonBrowserBranches,
135-
isRuntimeCompileBuild,
136134
isGlobalBuild,
137135
isNodeBuild
138136
),
@@ -152,7 +150,6 @@ function createReplacePlugin(
152150
isProduction,
153151
isBundlerESMBuild,
154152
isBrowserBuild,
155-
isRuntimeCompileBuild,
156153
isGlobalBuild,
157154
isNodeBuild
158155
) {
@@ -170,8 +167,6 @@ function createReplacePlugin(
170167
__BROWSER__: isBrowserBuild,
171168
// is targeting bundlers?
172169
__BUNDLER__: isBundlerESMBuild,
173-
// support compile in browser?
174-
__RUNTIME_COMPILE__: isRuntimeCompileBuild,
175170
__GLOBAL__: isGlobalBuild,
176171
// is targeting Node (SSR)?
177172
__NODE_JS__: isNodeBuild,

0 commit comments

Comments
 (0)