fix caching with preserveWhiteSpace

This commit is contained in:
Evan You 2016-04-12 20:15:56 -04:00
parent 0ab0600599
commit fa46e8f88e

View File

@ -1,10 +1,12 @@
import { parse } from './html-parser' import { parse } from './html-parser'
import { generate } from './codegen/index' import { generate } from './codegen/index'
const cache = Object.create(null) const cache1 = Object.create(null)
const cache2 = Object.create(null)
export function compile (html, preserveWhiteSpace) { export function compile (html, preserveWhiteSpace) {
html = html.trim() html = html.trim()
const cache = preserveWhiteSpace ? cache1 : cache2
const hit = cache[html] const hit = cache[html]
return hit || (cache[html] = generate(parse(html, preserveWhiteSpace))) return hit || (cache[html] = generate(parse(html, preserveWhiteSpace)))
} }