File tree Expand file tree Collapse file tree 1 file changed +23
-9
lines changed
packages/compiler-sfc/src Expand file tree Collapse file tree 1 file changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -103,9 +103,30 @@ export interface SFCParseResult {
103
103
104
104
export const parseCache = createCache < SFCParseResult > ( )
105
105
106
+ function genCacheKey ( source : string , options : SFCParseOptions ) : string {
107
+ return (
108
+ source +
109
+ JSON . stringify (
110
+ {
111
+ ...options ,
112
+ compiler : { parse : options . compiler ?. parse } ,
113
+ } ,
114
+ ( _ , val ) => ( typeof val === 'function' ? val . toString ( ) : val ) ,
115
+ )
116
+ )
117
+ }
118
+
106
119
export function parse (
107
120
source : string ,
108
- {
121
+ options : SFCParseOptions = { } ,
122
+ ) : SFCParseResult {
123
+ const sourceKey = genCacheKey ( source , options )
124
+ const cache = parseCache . get ( sourceKey )
125
+ if ( cache ) {
126
+ return cache
127
+ }
128
+
129
+ const {
109
130
sourceMap = true ,
110
131
filename = DEFAULT_FILENAME ,
111
132
sourceRoot = '' ,
@@ -114,14 +135,7 @@ export function parse(
114
135
compiler = CompilerDOM ,
115
136
templateParseOptions = { } ,
116
137
parseExpressions = true ,
117
- } : SFCParseOptions = { } ,
118
- ) : SFCParseResult {
119
- const sourceKey =
120
- source + sourceMap + filename + sourceRoot + pad + compiler . parse
121
- const cache = parseCache . get ( sourceKey )
122
- if ( cache ) {
123
- return cache
124
- }
138
+ } = options
125
139
126
140
const descriptor : SFCDescriptor = {
127
141
filename,
You can’t perform that action at this time.
0 commit comments