Skip to content

Commit

Permalink
feat(compiler-sfc): expose parseCache
Browse files Browse the repository at this point in the history
So that users can adjust cache's max size.
close #8202
  • Loading branch information
yyx990803 committed May 1, 2023
1 parent de87e6e commit 4576548
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/cache.ts
@@ -1,6 +1,6 @@
import LRU from 'lru-cache'

export function createCache<T>(size = 500) {
export function createCache<T>(size = 500): Map<string, T> & { max?: number } {
if (__GLOBAL__ || __ESM_BROWSER__) {
return new Map<string, T>()
}
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/index.ts
@@ -1,7 +1,7 @@
export const version = __VERSION__

// API
export { parse } from './parse'
export { parse, parseCache } from './parse'
export { compileTemplate } from './compileTemplate'
export { compileStyle, compileStyleAsync } from './compileStyle'
export { compileScript } from './compileScript'
Expand Down
6 changes: 3 additions & 3 deletions packages/compiler-sfc/src/parse.ts
Expand Up @@ -93,7 +93,7 @@ export interface SFCParseResult {
errors: (CompilerError | SyntaxError)[]
}

const sourceToSFC = createCache<SFCParseResult>()
export const parseCache = createCache<SFCParseResult>()

export function parse(
source: string,
Expand All @@ -108,7 +108,7 @@ export function parse(
): SFCParseResult {
const sourceKey =
source + sourceMap + filename + sourceRoot + pad + compiler.parse
const cache = sourceToSFC.get(sourceKey)
const cache = parseCache.get(sourceKey)
if (cache) {
return cache
}
Expand Down Expand Up @@ -284,7 +284,7 @@ export function parse(
descriptor,
errors
}
sourceToSFC.set(sourceKey, result)
parseCache.set(sourceKey, result)
return result
}

Expand Down

0 comments on commit 4576548

Please sign in to comment.