]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
build: reduce runtime build size
authorEvan You <yyx990803@gmail.com>
Wed, 21 Jul 2021 15:11:40 +0000 (11:11 -0400)
committerEvan You <yyx990803@gmail.com>
Wed, 21 Jul 2021 15:11:40 +0000 (11:11 -0400)
packages/runtime-core/__tests__/hmr.spec.ts
packages/runtime-core/src/component.ts
packages/runtime-core/src/componentPublicInstance.ts

index 70af64853c5e659f2d4357b93e644315782e13fd..4f1a5e5ddb66f68e61e951559cf38b8c8f340fbe 100644 (file)
@@ -16,6 +16,8 @@ import { baseCompile } from '@vue/compiler-core'
 declare var __VUE_HMR_RUNTIME__: HMRRuntime
 const { createRecord, rerender, reload } = __VUE_HMR_RUNTIME__
 
+runtimeTest.registerRuntimeCompiler(compileToFunction)
+
 function compileToFunction(template: string) {
   const { code } = baseCompile(template)
   const render = new Function('Vue', code)(
index 7b7ced57d30236fc1bee88afb7383e00ed68dc35..8c1d55a2163cae80b510622dc0c69bb2f83135ea 100644 (file)
@@ -10,12 +10,12 @@ import {
 import {
   ComponentPublicInstance,
   PublicInstanceProxyHandlers,
-  RuntimeCompiledPublicInstanceProxyHandlers,
   createRenderContext,
   exposePropsOnRenderContext,
   exposeSetupStateOnRenderContext,
   ComponentPublicInstanceConstructor,
-  publicPropertiesMap
+  publicPropertiesMap,
+  RuntimeCompiledPublicInstanceProxyHandlers
 } from './componentPublicInstance'
 import {
   ComponentPropsOptions,
@@ -711,9 +711,7 @@ type CompileFunction = (
 ) => InternalRenderFunction
 
 let compile: CompileFunction | undefined
-
-// dev only
-export const isRuntimeOnly = () => !compile
+let installWithProxy: (i: ComponentInternalInstance) => void
 
 /**
  * For runtime-dom to register the compiler.
@@ -721,8 +719,16 @@ export const isRuntimeOnly = () => !compile
  */
 export function registerRuntimeCompiler(_compile: any) {
   compile = _compile
+  installWithProxy = i => {
+    if (i.render!._rc) {
+      i.withProxy = new Proxy(i.ctx, RuntimeCompiledPublicInstanceProxyHandlers)
+    }
+  }
 }
 
+// dev only
+export const isRuntimeOnly = () => !compile
+
 export function finishComponentSetup(
   instance: ComponentInternalInstance,
   isSSR: boolean,
@@ -792,11 +798,8 @@ export 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 (instance.render._rc) {
-      instance.withProxy = new Proxy(
-        instance.ctx,
-        RuntimeCompiledPublicInstanceProxyHandlers
-      )
+    if (installWithProxy) {
+      installWithProxy(instance)
     }
   }
 
index 1e5935b646f8463ea306d1668e98f0595b6f2842..9c0eec149151d50ea7206682206529a10c8bf24a 100644 (file)
@@ -224,7 +224,7 @@ const getPublicInstance = (
   return getPublicInstance(i.parent)
 }
 
-export const publicPropertiesMap: PublicPropertiesMap = extend(
+export const publicPropertiesMap: PublicPropertiesMap = /*#__PURE__*/ extend(
   Object.create(null),
   {
     $: i => i,
@@ -459,7 +459,7 @@ if (__DEV__ && !__TEST__) {
   }
 }
 
-export const RuntimeCompiledPublicInstanceProxyHandlers = extend(
+export const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ extend(
   {},
   PublicInstanceProxyHandlers,
   {