Skip to content

Commit b8d58ec

Browse files
committed
fix(compiler-sfc): respect sfc parse options in cache key
1 parent b010cb9 commit b8d58ec

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

packages/compiler-sfc/src/parse.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,30 @@ export interface SFCParseResult {
103103

104104
export 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+
106119
export 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,

0 commit comments

Comments
 (0)