SourceLocation
} from '@vue/compiler-core'
import { RawSourceMap } from 'source-map'
+import LRUCache from 'lru-cache'
import { generateCodeFrame } from '@vue/shared'
export interface SFCParseOptions {
customBlocks: SFCBlock[]
}
+const SFC_CACHE_MAX_SIZE = 500
+const sourceToSFC = new LRUCache<string, SFCDescriptor>(SFC_CACHE_MAX_SIZE)
export function parse(
source: string,
{
sourceRoot = ''
}: SFCParseOptions = {}
): SFCDescriptor {
- // TODO check cache
+ const sourceKey = source + needMap + filename + sourceRoot
+ const cache = sourceToSFC.get(sourceKey)
+ if (cache) {
+ return cache
+ }
const sfc: SFCDescriptor = {
filename,
if (needMap) {
// TODO source map
}
- // TODO set cache
+ sourceToSFC.set(sourceKey, sfc)
return sfc
}
dependencies:
jest-diff "^24.3.0"
+"@types/lru-cache@^5.1.0":
+ version "5.1.0"
+ resolved "https://registry.yarnpkg.com/@types/lru-cache/-/lru-cache-5.1.0.tgz#57f228f2b80c046b4a1bd5cac031f81f207f4f03"
+ integrity sha512-RaE0B+14ToE4l6UqdarKPnXwVDuigfFv+5j9Dze/Nqr23yyuqdNvzcZi3xB+3Agvi5R4EOgAksfv3lXX4vBt9w==
+
"@types/minimatch@*":
version "3.0.3"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"