mirror of https://github.com/vuejs/core.git
fix(compiler-sfc): respect sfc parse options in cache key
This commit is contained in:
parent
b010cb9939
commit
b8d58ec4f4
|
@ -103,9 +103,30 @@ export interface SFCParseResult {
|
||||||
|
|
||||||
export const parseCache = createCache<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(
|
export function parse(
|
||||||
source: string,
|
source: string,
|
||||||
{
|
options: SFCParseOptions = {},
|
||||||
|
): SFCParseResult {
|
||||||
|
const sourceKey = genCacheKey(source, options)
|
||||||
|
const cache = parseCache.get(sourceKey)
|
||||||
|
if (cache) {
|
||||||
|
return cache
|
||||||
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
sourceMap = true,
|
sourceMap = true,
|
||||||
filename = DEFAULT_FILENAME,
|
filename = DEFAULT_FILENAME,
|
||||||
sourceRoot = '',
|
sourceRoot = '',
|
||||||
|
@ -114,14 +135,7 @@ export function parse(
|
||||||
compiler = CompilerDOM,
|
compiler = CompilerDOM,
|
||||||
templateParseOptions = {},
|
templateParseOptions = {},
|
||||||
parseExpressions = true,
|
parseExpressions = true,
|
||||||
}: SFCParseOptions = {},
|
} = options
|
||||||
): SFCParseResult {
|
|
||||||
const sourceKey =
|
|
||||||
source + sourceMap + filename + sourceRoot + pad + compiler.parse
|
|
||||||
const cache = parseCache.get(sourceKey)
|
|
||||||
if (cache) {
|
|
||||||
return cache
|
|
||||||
}
|
|
||||||
|
|
||||||
const descriptor: SFCDescriptor = {
|
const descriptor: SFCDescriptor = {
|
||||||
filename,
|
filename,
|
||||||
|
|
Loading…
Reference in New Issue