Skip to content

Commit 49d429a

Browse files
committed
use JSON.stringify in caching parse results
1 parent c494c69 commit 49d429a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/parse.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,18 @@ export function parse(options: ParseOptions): SFCDescriptor {
5353
needMap = true
5454
} = options
5555
const cacheKey = hash(filename + source)
56-
let output: SFCDescriptor = cache.get(cacheKey)
57-
if (output) return output
58-
output = compiler.parseComponent(source, compilerParseOptions)
56+
const cachedOutput: string = cache.get(cacheKey)
57+
if (cachedOutput) {
58+
try {
59+
return JSON.parse(cachedOutput) as SFCDescriptor
60+
} catch (_) {
61+
// do nothing
62+
}
63+
}
64+
const output: SFCDescriptor = compiler.parseComponent(
65+
source,
66+
compilerParseOptions
67+
)
5968
if (needMap) {
6069
if (output.script && !output.script.src) {
6170
output.script.map = generateSourceMap(
@@ -78,7 +87,7 @@ export function parse(options: ParseOptions): SFCDescriptor {
7887
})
7988
}
8089
}
81-
cache.set(cacheKey, output)
90+
cache.set(cacheKey, JSON.stringify(output))
8291
return output
8392
}
8493

0 commit comments

Comments
 (0)