diff --git a/src/compiler/transclude.js b/src/compiler/transclude.js index 8387422b6..9b6c04c70 100644 --- a/src/compiler/transclude.js +++ b/src/compiler/transclude.js @@ -151,8 +151,8 @@ function mergeAttrs (from, to) { value = attrs[i].value if (!to.hasAttribute(name) && !specialCharRE.test(name)) { to.setAttribute(name, value) - } else if (name === 'class' && !parseText(value)) { - value.trim().split(/\s+/).forEach(function (cls) { + } else if (name === 'class' && !parseText(value) && (value = value.trim())) { + value.split(/\s+/).forEach(function (cls) { addClass(to, cls) }) } diff --git a/test/unit/specs/compiler/transclude_spec.js b/test/unit/specs/compiler/transclude_spec.js index 348e68a1a..629585285 100644 --- a/test/unit/specs/compiler/transclude_spec.js +++ b/test/unit/specs/compiler/transclude_spec.js @@ -119,6 +119,16 @@ describe('Transclude', function () { expect(res.getAttribute('title')).toBe('child') }) + // #2789 + it('empty class merge', () => { + el.setAttribute('class', '') + options.template = '
' + options.replace = true + options._asComponent = true + var res = transclude(el, options) + expect(res.getAttribute('class')).toBe('test') + }) + it('class merge for svg elements', function () { el.setAttribute('class', 'test') options.template = ''