Skip to content

Commit e094b00

Browse files
committed
add preserveWhitespace option
1 parent 8f5a69b commit e094b00

File tree

3 files changed

+14
-31
lines changed

3 files changed

+14
-31
lines changed

src/compiler/codegen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import config from '../config'
12
import { parseText } from './text-parser'
23
import { isArray } from '../util/index'
34

@@ -25,7 +26,7 @@ function genElement (el, key) {
2526
}
2627

2728
function genIf (el, exp) {
28-
return `(${exp}) ? ${genElement(el)} : ''`
29+
return `(${exp}) ? ${genElement(el)} : null`
2930
}
3031

3132
function genFor (el, exp) {
@@ -101,7 +102,6 @@ function genData (el, key) {
101102
if (hasEvents) {
102103
data += genEvents(events)
103104
}
104-
console.log(data)
105105
return data.replace(/,$/, '') + '}'
106106
}
107107

src/compiler/html-parser.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import config from '../config'
2+
13
/**
24
* Convert HTML string to AST
35
*
@@ -37,8 +39,14 @@ export function parse (html) {
3739
chars (text) {
3840
text = currentParent.tag === 'pre'
3941
? text
40-
: text.trim() ? text : ' '
41-
currentParent.children.push(text)
42+
: text.trim()
43+
? text
44+
: config.preserveWhiteSpace
45+
? ' '
46+
: null
47+
if (text) {
48+
currentParent.children.push(text)
49+
}
4250
}
4351
})
4452
return root

src/config.js

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
export default {
22

33
/**
4-
* Whether to print debug messages.
5-
* Also enables stack trace for warnings.
6-
*
7-
* @type {Boolean}
4+
* Preserve whitespaces between elements.
85
*/
96

10-
debug: false,
7+
preserveWhiteSpace: true,
118

129
/**
1310
* Whether to suppress warnings.
@@ -17,35 +14,13 @@ export default {
1714

1815
silent: false,
1916

20-
/**
21-
* Whether to use async rendering.
22-
*/
23-
24-
async: true,
25-
2617
/**
2718
* Whether to warn against errors caught when evaluating
2819
* expressions.
2920
*/
3021

3122
warnExpressionErrors: true,
3223

33-
/**
34-
* Whether to allow devtools inspection.
35-
* Disabled by default in production builds.
36-
*/
37-
38-
devtools: process.env.NODE_ENV !== 'production',
39-
40-
/**
41-
* Internal flag to indicate the delimiters have been
42-
* changed.
43-
*
44-
* @type {Boolean}
45-
*/
46-
47-
_delimitersChanged: true,
48-
4924
/**
5025
* List of asset types that a component can own.
5126
*

0 commit comments

Comments
 (0)