mirror of
https://github.com/vuejs/vue.git
synced 2024-11-22 04:39:46 +00:00
refactor so that compiler is decoupled from the rest of the codebase
This commit is contained in:
parent
e918476447
commit
d048b44ae2
@ -1,4 +1,3 @@
|
||||
import config from '../../config'
|
||||
import { genEvents, addHandler } from './events'
|
||||
import { genModel } from './model'
|
||||
import {
|
||||
|
@ -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) {
|
||||
|
@ -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)))
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user