refactor so that compiler is decoupled from the rest of the codebase

This commit is contained in:
Evan You 2016-04-12 18:10:41 -04:00
parent e918476447
commit d048b44ae2
4 changed files with 7 additions and 11 deletions

View File

@ -1,4 +1,3 @@
import config from '../../config'
import { genEvents, addHandler } from './events'
import { genModel } from './model'
import {

View File

@ -1,4 +1,3 @@
import config from '../config'
import { decodeHTML } from 'entities'
/**
@ -8,7 +7,7 @@ import { decodeHTML } from 'entities'
* @return {Object}
*/
export function parse (html) {
export function parse (html, preserveWhiteSpace) {
let root
let currentParent
let stack = []
@ -43,7 +42,7 @@ export function parse (html) {
? text
: text.trim()
? text
: config.preserveWhiteSpace
: preserveWhiteSpace
? ' '
: null
if (text) {

View File

@ -3,8 +3,8 @@ import { generate } from './codegen/index'
const cache = Object.create(null)
export function compile (html) {
export function compile (html, preserveWhiteSpace) {
html = html.trim()
const hit = cache[html]
return hit || (cache[html] = generate(parse(html)))
return hit || (cache[html] = generate(parse(html, preserveWhiteSpace)))
}

View File

@ -1,14 +1,12 @@
import config from './config'
import { compile } from './compiler/index'
import { getOuterHTML, query } from './util/index'
import Component from './instance/index'
export default function Vue (options) {
if (!options.render) {
if (options.template) {
options.render = compile(options.template)
} else if (options.el) {
options.render = compile(getOuterHTML(query(options.el)))
}
const template = options.template || getOuterHTML(query(options.el))
options.render = compile(template, config.preserveWhiteSpace)
}
return new Component(options)
}