]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): respect sfc parse options in cache key
authorEvan You <yyx990803@gmail.com>
Sat, 30 Dec 2023 12:38:58 +0000 (20:38 +0800)
committerEvan You <yyx990803@gmail.com>
Sat, 30 Dec 2023 12:38:58 +0000 (20:38 +0800)
packages/compiler-sfc/src/parse.ts

index 0acceb1fabaa836c7602db9f6dfc564e8c186629..00c97867cd0ef151c3fedad7e13e5cefa5e53aef 100644 (file)
@@ -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 = '',
@@ -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,