Skip to content

Commit

Permalink
Merge pull request #712 from Demivan/fix-empty-text-nodes
Browse files Browse the repository at this point in the history
Fix component interpolation with empty text nodes
  • Loading branch information
exoego authored Sep 7, 2019
2 parents 12a00be + f22a530 commit 77ef025
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/components/interpolation.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ function onlyHasDefaultPlace (params) {

function useLegacyPlaces (children, places) {
const params = places ? createParamsFromPlaces(places) : {}

if (!children) { return params }

// Filter empty text nodes
children = children.filter(child => {
return child.tag || child.text.trim() !== ''
})

const everyPlace = children.every(vnodeHasPlaceAttribute)
if (process.env.NODE_ENV !== 'production' && everyPlace) {
warn('`place` attribute is deprecated in next major version. Please switch to Vue slots.')
Expand Down
19 changes: 19 additions & 0 deletions test/unit/interpolation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@ describe('component interpolation', () => {
})
})

describe('empty text node between components', () => {
it('should NOT be interpolated', done => {
const el = document.createElement('div')
const vm = new Vue({
i18n,
render (h) {
return h('i18n', { props: { path: 'primitive' } }, [
h('p', ['1']),
this._v(''),
h('p', ['2'])
])
}
}).$mount(el)
nextTick(() => {
assert.strictEqual(vm.$el.innerHTML, 'one: <p>1</p>, two: <p>2</p>')
}).then(done)
})
})

describe('components', () => {
it('should be interpolated', done => {
const el = document.createElement('div')
Expand Down

0 comments on commit 77ef025

Please sign in to comment.