Skip to content

Commit

Permalink
Merge pull request #262 from PaulBGD/svg-set-xmlns
Browse files Browse the repository at this point in the history
xmlns should be added as an attribute for consistency
  • Loading branch information
Rich-Harris authored Jan 25, 2017
2 parents 8eb540d + d47fead commit 6cde8ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,21 @@ export default function addElementAttributes ( generator, node, local ) {
// static attributes
result = JSON.stringify( value.data );

let addAttribute = false;
if ( name === 'xmlns' ) {
// special case
// TODO this attribute must be static – enforce at compile time
local.namespace = value.data;
addAttribute = true;
} else if ( propertyName ) {
local.init.addLine(
`${local.name}.${propertyName} = ${result};`
);
} else {
addAttribute = true;
}

if ( addAttribute ) {
generator.uses[ helper ] = true;
local.init.addLine(
`${helper}( ${local.name}, '${name}', ${result} );`
Expand Down
4 changes: 2 additions & 2 deletions test/generator/svg-xmlns/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
height: 100
},

html: `<svg><rect x="0" y="0" width="100" height="100"></rect></svg>`,
html: `<svg xmlns="http://www.w3.org/2000/svg"><rect x="0" y="0" width="100" height="100"></rect></svg>`,

test ( assert, component, target ) {
const svg = target.querySelector( 'svg' );
Expand All @@ -16,6 +16,6 @@ export default {
assert.equal( rect.namespaceURI, 'http://www.w3.org/2000/svg' );

component.set({ width: 150, height: 50 });
assert.equal( target.innerHTML, `<svg><rect x="0" y="0" width="150" height="50"></rect></svg>` );
assert.equal( target.innerHTML, `<svg xmlns="http://www.w3.org/2000/svg"><rect x="0" y="0" width="150" height="50"></rect></svg>` );
}
};

0 comments on commit 6cde8ff

Please sign in to comment.