@@ -4,14 +4,32 @@ import { initDev } from './dev'
44import { compile , CompilerOptions , CompilerError } from '@vue/compiler-dom'
55import { registerRuntimeCompiler , RenderFunction , warn } from '@vue/runtime-dom'
66import * as runtimeDom from '@vue/runtime-dom'
7- import { isString , NOOP , generateCodeFrame , extend } from '@vue/shared'
7+ import {
8+ isString ,
9+ NOOP ,
10+ generateCodeFrame ,
11+ extend ,
12+ EMPTY_OBJ
13+ } from '@vue/shared'
814import { InternalRenderFunction } from 'packages/runtime-core/src/component'
915
1016if ( __DEV__ ) {
1117 initDev ( )
1218}
1319
14- const compileCache : Record < string , RenderFunction > = Object . create ( null )
20+ const compileCache = new WeakMap <
21+ CompilerOptions ,
22+ Record < string , RenderFunction >
23+ > ( )
24+
25+ function getCache ( options ?: CompilerOptions ) {
26+ let c = compileCache . get ( options ?? EMPTY_OBJ )
27+ if ( ! c ) {
28+ c = Object . create ( null ) as Record < string , RenderFunction >
29+ compileCache . set ( options ?? EMPTY_OBJ , c )
30+ }
31+ return c
32+ }
1533
1634function compileToFunction (
1735 template : string | HTMLElement ,
@@ -27,7 +45,8 @@ function compileToFunction(
2745 }
2846
2947 const key = template
30- const cached = compileCache [ key ]
48+ const cache = getCache ( options )
49+ const cached = cache [ key ]
3150 if ( cached ) {
3251 return cached
3352 }
@@ -84,7 +103,7 @@ function compileToFunction(
84103 // mark the function as runtime compiled
85104 ; ( render as InternalRenderFunction ) . _rc = true
86105
87- return ( compileCache [ key ] = render )
106+ return ( cache [ key ] = render )
88107}
89108
90109registerRuntimeCompiler ( compileToFunction )
0 commit comments