From 16106d113d666941682ed4216a65f5e12d627df0 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 26 Mar 2019 12:10:41 -0400 Subject: [PATCH] handle foreignObject correctly, default to svg namespace for top-level svg elements - fixes #2298 --- src/compile/nodes/Element.ts | 15 +++++---------- .../svg-foreignobject-namespace/_config.js | 14 ++++++++++++++ .../svg-foreignobject-namespace/main.svelte | 5 +++++ .../input.svelte | 8 -------- .../warnings.json | 15 --------------- 5 files changed, 24 insertions(+), 33 deletions(-) create mode 100644 test/runtime/samples/svg-foreignobject-namespace/_config.js create mode 100644 test/runtime/samples/svg-foreignobject-namespace/main.svelte delete mode 100644 test/validator/samples/svg-child-component-undeclared-namespace/input.svelte delete mode 100644 test/validator/samples/svg-child-component-undeclared-namespace/warnings.json diff --git a/src/compile/nodes/Element.ts b/src/compile/nodes/Element.ts index 6d9c8059f5..a76a01e3b4 100644 --- a/src/compile/nodes/Element.ts +++ b/src/compile/nodes/Element.ts @@ -94,16 +94,11 @@ export default class Element extends Node { this.name = info.name; const parent_element = parent.find_nearest(/^Element/); - this.namespace = this.name === 'svg' ? - namespaces.svg : - parent_element ? parent_element.namespace : this.component.namespace; - - if (!this.namespace && svg.test(this.name)) { - this.component.warn(this, { - code: `missing-namespace`, - message: `<${this.name}> is an SVG element – did you forget to add ?` - }); - } + this.namespace = this.name === 'svg' || (!parent_element && svg.test(this.name)) + ? namespaces.svg + : this.name === 'foreignObject' + ? namespaces.html + : parent_element ? parent_element.namespace : this.component.namespace; if (this.name === 'textarea') { if (info.children.length > 0) { diff --git a/test/runtime/samples/svg-foreignobject-namespace/_config.js b/test/runtime/samples/svg-foreignobject-namespace/_config.js new file mode 100644 index 0000000000..a0185bae8e --- /dev/null +++ b/test/runtime/samples/svg-foreignobject-namespace/_config.js @@ -0,0 +1,14 @@ +export default { + html: ` + + +

some text

+
+
+ `, + + test({ assert, target }) { + const p = target.querySelector('p'); + assert.equal(p.namespaceURI, 'http://www.w3.org/1999/xhtml'); + } +}; diff --git a/test/runtime/samples/svg-foreignobject-namespace/main.svelte b/test/runtime/samples/svg-foreignobject-namespace/main.svelte new file mode 100644 index 0000000000..e841e0d417 --- /dev/null +++ b/test/runtime/samples/svg-foreignobject-namespace/main.svelte @@ -0,0 +1,5 @@ + + +

some text

+
+
diff --git a/test/validator/samples/svg-child-component-undeclared-namespace/input.svelte b/test/validator/samples/svg-child-component-undeclared-namespace/input.svelte deleted file mode 100644 index b4b6fc86d7..0000000000 --- a/test/validator/samples/svg-child-component-undeclared-namespace/input.svelte +++ /dev/null @@ -1,8 +0,0 @@ - - - \ No newline at end of file diff --git a/test/validator/samples/svg-child-component-undeclared-namespace/warnings.json b/test/validator/samples/svg-child-component-undeclared-namespace/warnings.json deleted file mode 100644 index 128b8628ed..0000000000 --- a/test/validator/samples/svg-child-component-undeclared-namespace/warnings.json +++ /dev/null @@ -1,15 +0,0 @@ -[{ - "code": "missing-namespace", - "message": " is an SVG element – did you forget to add ?", - "start": { - "line": 8, - "column": 0, - "character": 89 - }, - "end": { - "line": 8, - "column": 49, - "character": 138 - }, - "pos": 89 -}]