]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(build): remove __RUNTIME_COMPILE__ flag
authorEvan You <yyx990803@gmail.com>
Wed, 11 Mar 2020 20:39:26 +0000 (16:39 -0400)
committerEvan You <yyx990803@gmail.com>
Wed, 11 Mar 2020 20:39:26 +0000 (16:39 -0400)
behavior should be consistent in all builds. fix #817

packages/runtime-core/__tests__/hmr.spec.ts
packages/runtime-core/src/component.ts
packages/runtime-core/src/componentProxy.ts
packages/runtime-dom/src/index.ts
packages/vue/package.json
rollup.config.js

index 08b734fa3ca35f0ebdc181fdd87d79d1c9a6e050..400ef30b07ac2e3ee1b411fedded895accd091ee 100644 (file)
@@ -19,7 +19,7 @@ const { createRecord, rerender, reload } = __VUE_HMR_RUNTIME__
 function compileToFunction(template: string) {
   const { code } = baseCompile(template)
   const render = new Function('Vue', code)(runtimeTest) as RenderFunction
-  render.isRuntimeCompiled = true
+  render._rc = true // isRuntimeCompiled
   return render
 }
 
index 05112c70f74a4521437518570644caf1f891385f..5bccb756d322197ef09ffa27b6e263264664d0eb 100644 (file)
@@ -96,7 +96,7 @@ export interface SetupContext {
 
 export type RenderFunction = {
   (): VNodeChild
-  isRuntimeCompiled?: boolean
+  _rc?: boolean // isRuntimeCompiled
 }
 
 export interface ComponentInternalInstance {
@@ -437,29 +437,24 @@ 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 (compile && Component.template && !Component.render) {
+      Component.render = compile(Component.template, {
         isCustomElement: instance.appContext.config.isCustomElement || NO
       })
       // mark the function as runtime compiled
-      ;(Component.render as RenderFunction).isRuntimeCompiled = true
+      ;(Component.render as RenderFunction)._rc = true
     }
 
     if (__DEV__ && !Component.render) {
       /* istanbul ignore if */
-      if (!__RUNTIME_COMPILE__ && Component.template) {
+      if (!compile && Component.template) {
         warn(
           `Component provides template but the build of Vue you are running ` +
             `does not support runtime template compilation. Either use the ` +
             `full build or pre-compile the template using Vue CLI.`
         )
       } else {
-        warn(
-          `Component is missing${
-            __RUNTIME_COMPILE__ ? ` template or` : ``
-          } render function.`
-        )
+        warn(`Component is missing template or render function.`)
       }
     }
 
@@ -468,7 +463,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 (instance.render._rc) {
       instance.withProxy = new Proxy(
         instance,
         runtimeCompiledRenderProxyHandlers
index 4770fd9b4648e393fc0fcd6804121beb579391bc..fcbc406478a6673aac401fbe39ab45e550ed693f 100644 (file)
@@ -75,10 +75,6 @@ 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) {
-      return
-    }
     const {
       renderContext,
       data,
@@ -189,6 +185,13 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
 
 export const runtimeCompiledRenderProxyHandlers = {
   ...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) {
     return key[0] !== '_' && !isGloballyWhitelisted(key)
   }
index d3743e4febe3ae48d97faebc0170e6e484d07e0b..148b08ca8a7e062b7a75328bc7f2dbbc55249116 100644 (file)
@@ -58,12 +58,7 @@ export const createApp = ((...args) => {
     const container = normalizeContainer(containerOrSelector)
     if (!container) return
     const component = app._component
-    if (
-      __RUNTIME_COMPILE__ &&
-      !isFunction(component) &&
-      !component.render &&
-      !component.template
-    ) {
+    if (!isFunction(component) && !component.render && !component.template) {
       component.template = container.innerHTML
     }
     // clear content before mounting
index 557a78ba27e634518215b3b2e42ad5471dbb7442..0d422893e7b9cfc7d7b89aa853c39796c8af85a3 100644 (file)
@@ -13,7 +13,6 @@
   ],
   "buildOptions": {
     "name": "Vue",
-    "isRuntimeCompileBuild": true,
     "formats": [
       "esm-bundler",
       "esm-bundler-runtime",
index 46f3d3fccd7e30d9748241835550883a20f72516..c90f4e03c74a0ef1197585108f74d65e76546809 100644 (file)
@@ -77,7 +77,6 @@ function createConfig(format, output, plugins = []) {
   const isRawESMBuild = format === 'esm'
   const isNodeBuild = format === 'cjs'
   const isBundlerESMBuild = /esm-bundler/.test(format)
-  const isRuntimeCompileBuild = packageOptions.isRuntimeCompileBuild
 
   if (isGlobalBuild) {
     output.name = packageOptions.name
@@ -132,7 +131,6 @@ function createConfig(format, output, plugins = []) {
         // isBrowserBuild?
         (isGlobalBuild || isRawESMBuild || isBundlerESMBuild) &&
           !packageOptions.enableNonBrowserBranches,
-        isRuntimeCompileBuild,
         isGlobalBuild,
         isNodeBuild
       ),
@@ -152,7 +150,6 @@ function createReplacePlugin(
   isProduction,
   isBundlerESMBuild,
   isBrowserBuild,
-  isRuntimeCompileBuild,
   isGlobalBuild,
   isNodeBuild
 ) {
@@ -170,8 +167,6 @@ function createReplacePlugin(
     __BROWSER__: isBrowserBuild,
     // is targeting bundlers?
     __BUNDLER__: isBundlerESMBuild,
-    // support compile in browser?
-    __RUNTIME_COMPILE__: isRuntimeCompileBuild,
     __GLOBAL__: isGlobalBuild,
     // is targeting Node (SSR)?
     __NODE_JS__: isNodeBuild,