From 60424d113f18d0e2ad1b99aef735bd9d3aff3bb4 Mon Sep 17 00:00:00 2001 From: harttle Date: Thu, 21 Nov 2019 11:19:03 +0800 Subject: [PATCH] fix: multiple parses for the same project --- src/parsers/san-app-parser.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/parsers/san-app-parser.ts b/src/parsers/san-app-parser.ts index 76b87b60..5b644f49 100644 --- a/src/parsers/san-app-parser.ts +++ b/src/parsers/san-app-parser.ts @@ -16,6 +16,7 @@ const debug = debugFactory('component-parser') export class SanAppParser { private root: string private id: number = 0 + private cache: Map = new Map() public project: Project constructor (project: Project) { @@ -72,7 +73,16 @@ export class SanAppParser { } private parseSanSourceFile (sourceFile: SourceFile) { + if (!this.cache.has(sourceFile)) { + this.cache.set(sourceFile, this.doParseSanSourceFile(sourceFile)) + } + console.log('cache size', this.cache.size) + return this.cache.get(sourceFile) + } + + private doParseSanSourceFile (sourceFile: SourceFile) { debug('parseSanSourceFile', sourceFile.getFilePath()) + sourceFile.refreshFromFileSystemSync() const componentClassIdentifier = getComponentClassIdentifier(sourceFile) const sanSourceFile = SanSourceFile.createFromTSSourceFile(sourceFile, componentClassIdentifier)