Skip to content

Commit 4576548

Browse files
committed
feat(compiler-sfc): expose parseCache
So that users can adjust cache's max size. close #8202
1 parent de87e6e commit 4576548

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

packages/compiler-sfc/src/cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import LRU from 'lru-cache'
22

3-
export function createCache<T>(size = 500) {
3+
export function createCache<T>(size = 500): Map<string, T> & { max?: number } {
44
if (__GLOBAL__ || __ESM_BROWSER__) {
55
return new Map<string, T>()
66
}

packages/compiler-sfc/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const version = __VERSION__
22

33
// API
4-
export { parse } from './parse'
4+
export { parse, parseCache } from './parse'
55
export { compileTemplate } from './compileTemplate'
66
export { compileStyle, compileStyleAsync } from './compileStyle'
77
export { compileScript } from './compileScript'

packages/compiler-sfc/src/parse.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export interface SFCParseResult {
9393
errors: (CompilerError | SyntaxError)[]
9494
}
9595

96-
const sourceToSFC = createCache<SFCParseResult>()
96+
export const parseCache = createCache<SFCParseResult>()
9797

9898
export function parse(
9999
source: string,
@@ -108,7 +108,7 @@ export function parse(
108108
): SFCParseResult {
109109
const sourceKey =
110110
source + sourceMap + filename + sourceRoot + pad + compiler.parse
111-
const cache = sourceToSFC.get(sourceKey)
111+
const cache = parseCache.get(sourceKey)
112112
if (cache) {
113113
return cache
114114
}
@@ -284,7 +284,7 @@ export function parse(
284284
descriptor,
285285
errors
286286
}
287-
sourceToSFC.set(sourceKey, result)
287+
parseCache.set(sourceKey, result)
288288
return result
289289
}
290290

0 commit comments

Comments
 (0)