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 {
103103
104104export const parseCache = createCache < SFCParseResult > ( )
105105
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+
106119export function parse (
107120 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 {
109130 sourceMap = true ,
110131 filename = DEFAULT_FILENAME ,
111132 sourceRoot = '' ,
@@ -114,14 +135,7 @@ export function parse(
114135 compiler = CompilerDOM ,
115136 templateParseOptions = { } ,
116137 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
125139
126140 const descriptor : SFCDescriptor = {
127141 filename,
You can’t perform that action at this time.
0 commit comments