diff --git a/compiler/generate/visitors/Text.js b/compiler/generate/visitors/Text.js index ead59ed3b3..758c9c4648 100644 --- a/compiler/generate/visitors/Text.js +++ b/compiler/generate/visitors/Text.js @@ -1,5 +1,9 @@ export default { enter ( generator, node ) { + if ( generator.current.namespace && !/\S/.test( node.data ) ) { + return; + } + const name = generator.current.getUniqueName( `text` ); generator.addElement( name, `document.createTextNode( ${JSON.stringify( node.data )} )` ); } diff --git a/compiler/generate/visitors/attributes/addElementAttributes.js b/compiler/generate/visitors/attributes/addElementAttributes.js index 0189f988ea..6a5637e52f 100644 --- a/compiler/generate/visitors/attributes/addElementAttributes.js +++ b/compiler/generate/visitors/attributes/addElementAttributes.js @@ -52,7 +52,11 @@ export default function addElementAttributes ( generator, node, local ) { // static attributes result = JSON.stringify( value.data ); - if ( propertyName ) { + if ( attribute.name === 'xmlns' ) { + // special case + // TODO this attribute must be static – enforce at compile time + local.namespace = value.data; + } else if ( propertyName ) { local.init.push( deindent` ${local.name}.${propertyName} = ${result}; ` ); @@ -61,12 +65,6 @@ export default function addElementAttributes ( generator, node, local ) { ${local.name}.setAttribute( '${attribute.name}', ${result} ); ` ); } - - // special case - // TODO this attribute must be static – enforce at compile time - if ( attribute.name === 'xmlns' ) { - local.namespace = value; - } } else { diff --git a/compiler/parse/state/tag.js b/compiler/parse/state/tag.js index d8ac4fd776..322972abf3 100644 --- a/compiler/parse/state/tag.js +++ b/compiler/parse/state/tag.js @@ -88,7 +88,7 @@ export default function tag ( parser ) { if ( name in specials ) { const special = specials[ name ]; - if ( parser[ special.id ] ) { + if ( parser[ special.property ] ) { parser.index = start; parser.error( `You can only have one <${name}> tag per component` ); } diff --git a/test/compiler/svg-no-whitespace/_config.js b/test/compiler/svg-no-whitespace/_config.js new file mode 100644 index 0000000000..f2a670abd2 --- /dev/null +++ b/test/compiler/svg-no-whitespace/_config.js @@ -0,0 +1,9 @@ +export default { + test ( assert, component, target ) { + const svg = target.querySelector( 'svg' ); + + assert.equal( svg.childNodes.length, 2 ); + assert.equal( svg.childNodes[0].nodeName, 'rect' ); + assert.equal( svg.childNodes[1].nodeName, 'rect' ); + } +}; diff --git a/test/compiler/svg-no-whitespace/main.html b/test/compiler/svg-no-whitespace/main.html new file mode 100644 index 0000000000..1a937b3188 --- /dev/null +++ b/test/compiler/svg-no-whitespace/main.html @@ -0,0 +1,5 @@ + + + + + diff --git a/test/compiler/svg-xmlns/_config.js b/test/compiler/svg-xmlns/_config.js new file mode 100644 index 0000000000..37d94a1609 --- /dev/null +++ b/test/compiler/svg-xmlns/_config.js @@ -0,0 +1,21 @@ +export default { + data: { + x: 0, + y: 0, + width: 100, + height: 100 + }, + + html: ``, + + test ( assert, component, target ) { + const svg = target.querySelector( 'svg' ); + const rect = target.querySelector( 'rect' ); + + assert.equal( svg.namespaceURI, 'http://www.w3.org/2000/svg' ); + assert.equal( rect.namespaceURI, 'http://www.w3.org/2000/svg' ); + + component.set({ width: 150, height: 50 }); + assert.equal( target.innerHTML, `` ); + } +}; diff --git a/test/compiler/svg-xmlns/main.html b/test/compiler/svg-xmlns/main.html new file mode 100644 index 0000000000..29e96293a5 --- /dev/null +++ b/test/compiler/svg-xmlns/main.html @@ -0,0 +1,3 @@ + + + diff --git a/test/parser/error-multiple-styles/error.json b/test/parser/error-multiple-styles/error.json new file mode 100644 index 0000000000..6a8b184ed6 --- /dev/null +++ b/test/parser/error-multiple-styles/error.json @@ -0,0 +1,8 @@ +{ + "message": "You can only have one + +