From 1d941abddcde97a3497cbed8bbcb859f86ab0292 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 6 Dec 2016 10:14:14 -0500 Subject: [PATCH] allow multiple SVGs - fixes #130 --- compiler/generate/visitors/Element.js | 2 +- test/compiler/svg-multiple/_config.js | 29 +++++++++++++++++++++++++++ test/compiler/svg-multiple/main.html | 7 +++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/compiler/svg-multiple/_config.js create mode 100644 test/compiler/svg-multiple/main.html diff --git a/compiler/generate/visitors/Element.js b/compiler/generate/visitors/Element.js index 69614e721f..6ffad9635d 100644 --- a/compiler/generate/visitors/Element.js +++ b/compiler/generate/visitors/Element.js @@ -13,7 +13,7 @@ export default { const local = { name, - namespace: name === 'svg' ? 'http://www.w3.org/2000/svg' : generator.current.namespace, + namespace: node.name === 'svg' ? 'http://www.w3.org/2000/svg' : generator.current.namespace, isComponent: false, allUsedContexts: new Set(), diff --git a/test/compiler/svg-multiple/_config.js b/test/compiler/svg-multiple/_config.js new file mode 100644 index 0000000000..9fd938e47a --- /dev/null +++ b/test/compiler/svg-multiple/_config.js @@ -0,0 +1,29 @@ +export default { + data: { + x: 0, + y: 0, + width: 100, + height: 100 + }, + + html: ` + + + `, + + test ( assert, component, target ) { + const svgs = target.querySelectorAll( 'svg' ); + const rects = target.querySelectorAll( 'rect' ); + + assert.equal( svgs[0].namespaceURI, 'http://www.w3.org/2000/svg' ); + assert.equal( svgs[0].namespaceURI, 'http://www.w3.org/2000/svg' ); + assert.equal( rects[1].namespaceURI, 'http://www.w3.org/2000/svg' ); + assert.equal( rects[1].namespaceURI, 'http://www.w3.org/2000/svg' ); + + component.set({ width: 150, height: 50 }); + assert.htmlEqual( target.innerHTML, ` + + + ` ); + } +}; diff --git a/test/compiler/svg-multiple/main.html b/test/compiler/svg-multiple/main.html new file mode 100644 index 0000000000..2998701d4b --- /dev/null +++ b/test/compiler/svg-multiple/main.html @@ -0,0 +1,7 @@ + + + + + + +