From fa705302616e511860401b98df76426e687be1c0 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 24 Jan 2017 17:03:14 -0500 Subject: [PATCH] handle xlink attributes --- .../attributes/addElementAttributes.js | 51 +++++++++++-------- src/shared/dom.js | 4 ++ test/generator/svg-xlink/_config.js | 19 +++++++ test/generator/svg-xlink/main.html | 7 +++ test/helpers.js | 4 ++ 5 files changed, 64 insertions(+), 21 deletions(-) create mode 100644 test/generator/svg-xlink/_config.js create mode 100644 test/generator/svg-xlink/main.html diff --git a/src/generators/dom/visitors/attributes/addElementAttributes.js b/src/generators/dom/visitors/attributes/addElementAttributes.js index 490d330348..c6009ff2e8 100644 --- a/src/generators/dom/visitors/attributes/addElementAttributes.js +++ b/src/generators/dom/visitors/attributes/addElementAttributes.js @@ -5,15 +5,24 @@ import flattenReference from '../../../../utils/flattenReference.js'; export default function addElementAttributes ( generator, node, local ) { node.attributes.forEach( attribute => { + const name = attribute.name; + if ( attribute.type === 'Attribute' ) { - let metadata = local.namespace ? null : attributeLookup[ attribute.name ]; + let metadata = local.namespace ? null : attributeLookup[ name ]; if ( metadata && metadata.appliesTo && !~metadata.appliesTo.indexOf( node.name ) ) metadata = null; let dynamic = false; - const isBoundOptionValue = node.name === 'option' && attribute.name === 'value'; // TODO check it's actually bound + const isBoundOptionValue = node.name === 'option' && name === 'value'; // TODO check it's actually bound const propertyName = isBoundOptionValue ? '__value' : metadata && metadata.propertyName; + const isXlink = name.slice( 0, 6 ) === 'xlink:'; + + // xlink is a special case... we could maybe extend this to generic + // namespaced attributes but I'm not sure that's applicable in + // HTML5? + const helper = isXlink ? 'setXlinkAttribute' : 'setAttribute'; + if ( attribute.value === true ) { // attributes without values, e.g.