Просмотр исходного кода

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

Evan You 10 лет назад
Родитель
Сommit
d048b44ae2
4 измененных файлов с 7 добавлено и 11 удалено
  1. 0 1
      src/compiler/codegen/index.js
  2. 2 3
      src/compiler/html-parser.js
  3. 2 2
      src/compiler/index.js
  4. 3 5
      src/with-compiler.js

+ 0 - 1
src/compiler/codegen/index.js

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

+ 2 - 3
src/compiler/html-parser.js

@@ -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) {

+ 2 - 2
src/compiler/index.js

@@ -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)))
 }

+ 3 - 5
src/with-compiler.js

@@ -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)
 }