Skip to content

Commit 34bcc02

Browse files
committed
remove preserveWhitespace config option
1 parent d813c59 commit 34bcc02

File tree

11 files changed

+50
-88
lines changed

11 files changed

+50
-88
lines changed

flow/compiler.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ declare type CompilerOptions = {
1212
transforms?: Array<Function>, // a list of transforms on parsed AST before codegen
1313

1414
// runtime user-configurable
15-
preserveWhitespace?: boolean, // whether to keep whitespaces between elements
1615
delimiters?: [string, string] // template delimiters
1716
}
1817

src/compiler/parser/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@ export function parse (
202202
text = currentParent.tag === 'pre' || text.trim()
203203
? decodeHTMLCached(text)
204204
// only preserve whitespace if its not right after a starting tag
205-
: options.preserveWhitespace && currentParent.children.length
206-
? ' '
207-
: ''
205+
: currentParent.children.length ? ' ' : ''
208206
if (text) {
209207
let expression
210208
if (!inPre && text !== ' ' && (expression = parseText(text, delimiters))) {

src/core/config.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import { no } from 'shared/util'
44

55
export type Config = {
6-
preserveWhitespace: boolean,
76
optionMergeStrategies: { [key: string]: Function },
87
silent: boolean,
8+
errorHandler: ?Function,
99
isReservedTag: (x?: string) => boolean,
1010
isUnknownElement: (x?: string) => boolean,
1111
mustUseProp: (x?: string) => boolean,
@@ -17,12 +17,6 @@ export type Config = {
1717
}
1818

1919
const config: Config = {
20-
21-
/**
22-
* Preserve whitespaces between elements.
23-
*/
24-
preserveWhitespace: true,
25-
2620
/**
2721
* Option merge strategies (used in core/util/options)
2822
*/

src/entries/web-runtime-with-compiler.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* @flow */
22

33
import Vue from './web-runtime'
4-
import config from 'core/config'
54
import { warn, cached } from 'core/util/index'
65
import { query } from 'web/util/index'
76
import { compileToFunctions } from 'web/compiler/index'
@@ -39,7 +38,6 @@ Vue.prototype.$mount = function (
3938
}
4039
if (template) {
4140
const { render, staticRenderFns } = compileToFunctions(template, {
42-
preserveWhitespace: config.preserveWhitespace,
4341
delimiters: options.delimiters,
4442
warn
4543
}, this)

src/platforms/web/compiler/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ import modules from './modules/index'
88
import directives from './directives/index'
99
import { isIE, isReservedTag, isUnaryTag, mustUseProp, getTagNamespace } from '../util/index'
1010

11-
const cache1: { [key: string]: CompiledFunctionResult } = Object.create(null)
12-
const cache2: { [key: string]: CompiledFunctionResult } = Object.create(null)
11+
const cache: { [key: string]: CompiledFunctionResult } = Object.create(null)
1312

1413
export const baseOptions: CompilerOptions = {
1514
isIE,
1615
expectHTML: true,
17-
preserveWhitespace: true,
1816
modules,
1917
staticKeys: genStaticKeys(modules),
2018
directives,
@@ -57,7 +55,6 @@ export function compileToFunctions (
5755
}
5856
}
5957
}
60-
const cache = options && options.preserveWhitespace === false ? cache1 : cache2
6158
const key = options && options.delimiters
6259
? String(options.delimiters) + template
6360
: template

test/unit/features/component/component-slot.spec.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ describe('Component slot', () => {
6161
`,
6262
parentContent: '<p slot="b">slot b</p>'
6363
})
64-
expect(child.$el.childNodes.length).toBe(2)
65-
expect(child.$el.firstChild.textContent).toBe('fallback a')
66-
expect(child.$el.lastChild.textContent).toBe('slot b')
64+
expect(child.$el.children.length).toBe(2)
65+
expect(child.$el.children[0].textContent).toBe('fallback a')
66+
expect(child.$el.children[1].textContent).toBe('slot b')
6767
})
6868

6969
it('fallback content with mixed named/unamed slots', () => {
@@ -76,9 +76,9 @@ describe('Component slot', () => {
7676
`,
7777
parentContent: '<p slot="b">slot b</p>'
7878
})
79-
expect(child.$el.childNodes.length).toBe(2)
80-
expect(child.$el.firstChild.textContent).toBe('fallback a')
81-
expect(child.$el.lastChild.textContent).toBe('slot b')
79+
expect(child.$el.children.length).toBe(2)
80+
expect(child.$el.children[0].textContent).toBe('fallback a')
81+
expect(child.$el.children[1].textContent).toBe('slot b')
8282
})
8383

8484
it('selector matching multiple elements', () => {
@@ -100,16 +100,16 @@ describe('Component slot', () => {
100100
`,
101101
parentContent: '<div>foo</div><p slot="a">1</p><p slot="b">2</p>'
102102
})
103-
expect(child.$el.innerHTML).toBe('<p>1</p><div>foo</div><p>2</p>')
103+
expect(child.$el.innerHTML).toBe('<p>1</p> <div>foo</div> <p>2</p>')
104104
})
105105

106106
it('name should only match children', function () {
107107
mount({
108108
childTemplate: `
109109
<div>
110110
<slot name="a"><p>fallback a</p></slot>
111-
<slot name="b">fallback b</slot>
112-
<slot name="c">fallback c</slot>
111+
<slot name="b"><p>fallback b</p></slot>
112+
<slot name="c"><p>fallback c</p></slot>
113113
</div>
114114
`,
115115
parentContent: `
@@ -118,10 +118,10 @@ describe('Component slot', () => {
118118
'<span><p slot="c">nested c</p></span>
119119
`
120120
})
121-
expect(child.$el.childNodes.length).toBe(3)
122-
expect(child.$el.firstChild.textContent).toBe('fallback a')
123-
expect(child.$el.childNodes[1].textContent).toBe('select b')
124-
expect(child.$el.lastChild.textContent).toBe('fallback c')
121+
expect(child.$el.children.length).toBe(3)
122+
expect(child.$el.children[0].textContent).toBe('fallback a')
123+
expect(child.$el.children[1].textContent).toBe('select b')
124+
expect(child.$el.children[2].textContent).toBe('fallback c')
125125
})
126126

127127
it('should accept expressions in slot attribute and slot names', () => {

test/unit/features/directives/if.spec.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,31 @@ describe('Directive v-if', () => {
6060
`,
6161
data: { foo: true }
6262
}).$mount()
63-
expect(vm.$el.innerHTML).toBe('<span>hello</span>')
63+
expect(vm.$el.innerHTML.trim()).toBe('<span>hello</span>')
6464
vm.foo = false
6565
waitForUpdate(() => {
66-
expect(vm.$el.innerHTML).toBe('<span>bye</span>')
66+
expect(vm.$el.innerHTML.trim()).toBe('<span>bye</span>')
6767
vm.foo = {}
6868
}).then(() => {
69-
expect(vm.$el.innerHTML).toBe('<span>hello</span>')
69+
expect(vm.$el.innerHTML.trim()).toBe('<span>hello</span>')
7070
vm.foo = 0
7171
}).then(() => {
72-
expect(vm.$el.innerHTML).toBe('<span>bye</span>')
72+
expect(vm.$el.innerHTML.trim()).toBe('<span>bye</span>')
7373
vm.foo = []
7474
}).then(() => {
75-
expect(vm.$el.innerHTML).toBe('<span>hello</span>')
75+
expect(vm.$el.innerHTML.trim()).toBe('<span>hello</span>')
7676
vm.foo = null
7777
}).then(() => {
78-
expect(vm.$el.innerHTML).toBe('<span>bye</span>')
78+
expect(vm.$el.innerHTML.trim()).toBe('<span>bye</span>')
7979
vm.foo = '0'
8080
}).then(() => {
81-
expect(vm.$el.innerHTML).toBe('<span>hello</span>')
81+
expect(vm.$el.innerHTML.trim()).toBe('<span>hello</span>')
8282
vm.foo = undefined
8383
}).then(() => {
84-
expect(vm.$el.innerHTML).toBe('<span>bye</span>')
84+
expect(vm.$el.innerHTML.trim()).toBe('<span>bye</span>')
8585
vm.foo = 1
8686
}).then(() => {
87-
expect(vm.$el.innerHTML).toBe('<span>hello</span>')
87+
expect(vm.$el.innerHTML.trim()).toBe('<span>hello</span>')
8888
}).then(done)
8989
})
9090

@@ -132,16 +132,16 @@ describe('Directive v-if', () => {
132132
]
133133
}
134134
}).$mount()
135-
expect(vm.$el.innerHTML).toBe('<span>hello</span><span>bye</span><span>hello</span>')
135+
expect(vm.$el.innerHTML.trim()).toBe('<span>hello</span><span>bye</span><span>hello</span>')
136136
vm.list[0].value = false
137137
waitForUpdate(() => {
138-
expect(vm.$el.innerHTML).toBe('<span>bye</span><span>bye</span><span>hello</span>')
138+
expect(vm.$el.innerHTML.trim()).toBe('<span>bye</span><span>bye</span><span>hello</span>')
139139
vm.list.push({ value: true })
140140
}).then(() => {
141-
expect(vm.$el.innerHTML).toBe('<span>bye</span><span>bye</span><span>hello</span><span>hello</span>')
141+
expect(vm.$el.innerHTML.trim()).toBe('<span>bye</span><span>bye</span><span>hello</span><span>hello</span>')
142142
vm.list.splice(1, 2)
143143
}).then(() => {
144-
expect(vm.$el.innerHTML).toBe('<span>bye</span><span>hello</span>')
144+
expect(vm.$el.innerHTML.trim()).toBe('<span>bye</span><span>hello</span>')
145145
}).then(done)
146146
})
147147
})

test/unit/features/directives/model-radio.spec.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ describe('Directive v-model radio', () => {
1414
`
1515
}).$mount()
1616
document.body.appendChild(vm.$el)
17-
expect(vm.$el.childNodes[0].checked).toBe(true)
18-
expect(vm.$el.childNodes[1].checked).toBe(false)
17+
expect(vm.$el.children[0].checked).toBe(true)
18+
expect(vm.$el.children[1].checked).toBe(false)
1919
vm.test = '2'
2020
waitForUpdate(() => {
21-
expect(vm.$el.childNodes[0].checked).toBe(false)
22-
expect(vm.$el.childNodes[1].checked).toBe(true)
23-
vm.$el.childNodes[0].click()
24-
expect(vm.$el.childNodes[0].checked).toBe(true)
25-
expect(vm.$el.childNodes[1].checked).toBe(false)
21+
expect(vm.$el.children[0].checked).toBe(false)
22+
expect(vm.$el.children[1].checked).toBe(true)
23+
vm.$el.children[0].click()
24+
expect(vm.$el.children[0].checked).toBe(true)
25+
expect(vm.$el.children[1].checked).toBe(false)
2626
expect(vm.test).toBe('1')
2727
}).then(() => {
2828
document.body.removeChild(vm.$el)
@@ -42,15 +42,15 @@ describe('Directive v-model radio', () => {
4242
`
4343
}).$mount()
4444
document.body.appendChild(vm.$el)
45-
expect(vm.$el.childNodes[0].checked).toBe(true)
46-
expect(vm.$el.childNodes[1].checked).toBe(false)
45+
expect(vm.$el.children[0].checked).toBe(true)
46+
expect(vm.$el.children[1].checked).toBe(false)
4747
vm.test = 2
4848
waitForUpdate(() => {
49-
expect(vm.$el.childNodes[0].checked).toBe(false)
50-
expect(vm.$el.childNodes[1].checked).toBe(true)
51-
vm.$el.childNodes[0].click()
52-
expect(vm.$el.childNodes[0].checked).toBe(true)
53-
expect(vm.$el.childNodes[1].checked).toBe(false)
49+
expect(vm.$el.children[0].checked).toBe(false)
50+
expect(vm.$el.children[1].checked).toBe(true)
51+
vm.$el.children[0].click()
52+
expect(vm.$el.children[0].checked).toBe(true)
53+
expect(vm.$el.children[1].checked).toBe(false)
5454
expect(vm.test).toBe(1)
5555
}).then(() => {
5656
document.body.removeChild(vm.$el)

test/unit/features/directives/once.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ describe('Directive v-once', () => {
2929
}).$mount()
3030
expect(vm.$children.length).toBe(1)
3131
expect(vm.$el.innerHTML)
32-
.toBe('<span>hello</span><div>hello</div>')
32+
.toBe('<span>hello</span> <div>hello</div>')
3333
vm.a = 'world'
3434
waitForUpdate(() => {
3535
expect(vm.$el.innerHTML)
36-
.toBe('<span>hello</span><div>hello</div>')
36+
.toBe('<span>hello</span> <div>hello</div>')
3737
}).then(done)
3838
})
3939

@@ -53,11 +53,11 @@ describe('Directive v-once', () => {
5353
}).$mount()
5454
expect(vm.$children.length).toBe(1)
5555
expect(vm.$el.innerHTML)
56-
.toBe('<span>hello</span><div>hello</div>')
56+
.toBe('<span>hello</span> <div>hello</div>')
5757
vm.a = 'world'
5858
waitForUpdate(() => {
5959
expect(vm.$el.innerHTML)
60-
.toBe('<span>world</span><div>hello</div>')
60+
.toBe('<span>world</span> <div>hello</div>')
6161
}).then(done)
6262
})
6363

@@ -80,15 +80,15 @@ describe('Directive v-once', () => {
8080
}
8181
}).$mount()
8282
expect(vm.$el.innerHTML)
83-
.toBe('<span>hello</span><div>hello</div><span>?</span>')
83+
.toBe('<span>hello</span> <div>hello</div> <span>?</span>')
8484
vm.a = 'world'
8585
waitForUpdate(() => {
8686
expect(vm.$el.innerHTML)
87-
.toBe('<span>hello</span><div>world</div><span>?</span>')
87+
.toBe('<span>hello</span> <div>world</div> <span>?</span>')
8888
vm.suffix = '!'
8989
}).then(() => {
9090
expect(vm.$el.innerHTML)
91-
.toBe('<span>hello</span><div>world</div><span>!</span>')
91+
.toBe('<span>hello</span> <div>world</div> <span>!</span>')
9292
}).then(done)
9393
})
9494
})

test/unit/features/global-api/config.spec.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
11
import Vue from 'vue'
22

33
describe('Global config', () => {
4-
describe('preserveWhitespace', () => {
5-
it('should preserve whitepspaces when set to true', () => {
6-
// this option is set to false during unit tests.
7-
Vue.config.preserveWhitespace = true
8-
const vm = new Vue({
9-
template: '<div><span>hi</span> <span>ha</span></div>'
10-
}).$mount()
11-
expect(vm.$el.innerHTML).toBe('<span>hi</span> <span>ha</span>')
12-
Vue.config.preserveWhitespace = false
13-
})
14-
15-
it('should remove whitespaces when set to false', () => {
16-
const vm = new Vue({
17-
template: '<div><span>hi</span> <span>ha</span></div>'
18-
}).$mount()
19-
expect(vm.$el.innerHTML).toBe('<span>hi</span><span>ha</span>')
20-
})
21-
})
22-
234
describe('silent', () => {
245
it('should be false by default', () => {
256
Vue.util.warn('foo')

0 commit comments

Comments
 (0)