Skip to content

Commit

Permalink
fix(compiler-sfc): respect sfc parse options in cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 30, 2023
1 parent b010cb9 commit b8d58ec
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions packages/compiler-sfc/src/parse.ts
Expand Up @@ -103,9 +103,30 @@ export interface SFCParseResult {

export const parseCache = createCache<SFCParseResult>()

function genCacheKey(source: string, options: SFCParseOptions): string {
return (
source +
JSON.stringify(
{
...options,
compiler: { parse: options.compiler?.parse },
},
(_, val) => (typeof val === 'function' ? val.toString() : val),
)
)
}

export function parse(
source: string,
{
options: SFCParseOptions = {},
): SFCParseResult {
const sourceKey = genCacheKey(source, options)
const cache = parseCache.get(sourceKey)
if (cache) {
return cache
}

const {
sourceMap = true,
filename = DEFAULT_FILENAME,
sourceRoot = '',
Expand All @@ -114,14 +135,7 @@ export function parse(
compiler = CompilerDOM,
templateParseOptions = {},
parseExpressions = true,
}: SFCParseOptions = {},
): SFCParseResult {
const sourceKey =
source + sourceMap + filename + sourceRoot + pad + compiler.parse
const cache = parseCache.get(sourceKey)
if (cache) {
return cache
}
} = options

const descriptor: SFCDescriptor = {
filename,
Expand Down

0 comments on commit b8d58ec

Please sign in to comment.