@@ -4,14 +4,32 @@ import { initDev } from './dev'
4
4
import { compile , CompilerOptions , CompilerError } from '@vue/compiler-dom'
5
5
import { registerRuntimeCompiler , RenderFunction , warn } from '@vue/runtime-dom'
6
6
import * 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'
8
14
import { InternalRenderFunction } from 'packages/runtime-core/src/component'
9
15
10
16
if ( __DEV__ ) {
11
17
initDev ( )
12
18
}
13
19
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
+ }
15
33
16
34
function compileToFunction (
17
35
template : string | HTMLElement ,
@@ -27,7 +45,8 @@ function compileToFunction(
27
45
}
28
46
29
47
const key = template
30
- const cached = compileCache [ key ]
48
+ const cache = getCache ( options )
49
+ const cached = cache [ key ]
31
50
if ( cached ) {
32
51
return cached
33
52
}
@@ -84,7 +103,7 @@ function compileToFunction(
84
103
// mark the function as runtime compiled
85
104
; ( render as InternalRenderFunction ) . _rc = true
86
105
87
- return ( compileCache [ key ] = render )
106
+ return ( cache [ key ] = render )
88
107
}
89
108
90
109
registerRuntimeCompiler ( compileToFunction )
0 commit comments