errors: (CompilerError | SyntaxError)[]
}
-export const parseCache:
+export let parseCache:
| Map<string, SFCParseResult>
- | LRUCache<string, SFCParseResult> = createCache<SFCParseResult>(
- COMPILER_CACHE_KEYS.parse,
-)
+ | LRUCache<string, SFCParseResult>
export function parse(
source: string,
...options,
compiler: { parse: options.compiler?.parse },
})
- const cache = parseCache.get(sourceKey)
+ const cache = (
+ parseCache ||
+ (parseCache = createCache<SFCParseResult>(COMPILER_CACHE_KEYS.parse))
+ ).get(sourceKey)
if (cache) {
return cache
}
} from '@vue/compiler-dom'
import { COMPILER_CACHE_KEYS, createCache } from '../cache'
import { camelize, capitalize, isBuiltInDirective } from '@vue/shared'
+import type { LRUCache } from 'lru-cache'
/**
* Check if an identifier is used in the SFC's template.
return resolveTemplateUsedIdentifiers(sfc).has(identifier)
}
-const templateUsageCheckCache = createCache<Set<string>>(
- COMPILER_CACHE_KEYS.templateUsageCheck,
-)
+let templateUsageCheckCache: LRUCache<string, Set<string>>
function resolveTemplateUsedIdentifiers(sfc: SFCDescriptor): Set<string> {
const { content, ast } = sfc.template!
- const cached = templateUsageCheckCache.get(content)
+ const cached = (
+ templateUsageCheckCache ||
+ (templateUsageCheckCache = createCache<Set<string>>(
+ COMPILER_CACHE_KEYS.templateUsageCheck,
+ ) as LRUCache<string, Set<string>>)
+ ).get(content)
if (cached) {
return cached
}
import { dirname, extname, join } from 'path'
import { minimatch as isMatch } from 'minimatch'
import * as process from 'process'
+import type { LRUCache } from 'lru-cache'
export type SimpleTypeResolveOptions = Partial<
Pick<
cache?: TS.ModuleResolutionCache
}
-const tsConfigCache = createCache<CachedConfig[]>(COMPILER_CACHE_KEYS.tsConfig)
+let tsConfigCache: LRUCache<string, CachedConfig[], unknown>
const tsConfigRefMap = new Map<string, string>()
function resolveWithTS(
if (configPath) {
let configs: CachedConfig[]
const normalizedConfigPath = normalizePath(configPath)
- const cached = tsConfigCache.get(normalizedConfigPath)
+ const cached = (
+ tsConfigCache ||
+ (tsConfigCache = createCache<CachedConfig[]>(
+ COMPILER_CACHE_KEYS.tsConfig,
+ ) as LRUCache<string, CachedConfig[], unknown>)
+ ).get(normalizedConfigPath)
if (!cached) {
configs = loadTSConfig(configPath, ts, fs).map(config => ({ config }))
tsConfigCache.set(normalizedConfigPath, configs)
return res
}
-const fileToScopeCache = createCache<TypeScope>(COMPILER_CACHE_KEYS.fileToScope)
+let fileToScopeCache: LRUCache<string, TypeScope>
/**
* @private
*/
export function invalidateTypeCache(filename: string): void {
filename = normalizePath(filename)
- fileToScopeCache.delete(filename)
- tsConfigCache.delete(filename)
- const affectedConfig = tsConfigRefMap.get(filename)
- if (affectedConfig) tsConfigCache.delete(affectedConfig)
+ if (fileToScopeCache) {
+ fileToScopeCache.delete(filename)
+ }
+ if (tsConfigCache) {
+ tsConfigCache.delete(filename)
+ const affectedConfig = tsConfigRefMap.get(filename)
+ if (affectedConfig) tsConfigCache.delete(affectedConfig)
+ }
}
export function fileToScope(
filename: string,
asGlobal = false,
): TypeScope {
- const cached = fileToScopeCache.get(filename)
+ const cached = (
+ fileToScopeCache ||
+ (fileToScopeCache = createCache<TypeScope>(
+ COMPILER_CACHE_KEYS.fileToScope,
+ ) as LRUCache<string, TypeScope>)
+ ).get(filename)
if (cached) {
return cached
}
const body = parseFile(filename, source, fs, ctx.options.babelParserPlugins)
const scope = new TypeScope(filename, source, 0, recordImports(body))
recordTypes(ctx, body, scope, asGlobal)
- fileToScopeCache.set(filename, scope)
+ fileToScopeCache!.set(filename, scope)
return scope
}