put namespace on Element nodes

pull/992/head
Rich Harris 8 years ago
parent f6ac3a44e5
commit e30dc8e3fa

@ -1,7 +1,6 @@
import { assign } from '../../shared/index.js'; import { assign } from '../../shared/index.js';
interface StateData { interface StateData {
namespace?: string;
parentNode?: string; parentNode?: string;
parentNodes?: string; parentNodes?: string;
allUsedContexts?: string[]; allUsedContexts?: string[];
@ -9,7 +8,6 @@ interface StateData {
} }
export default class State { export default class State {
namespace?: string;
parentNode?: string; parentNode?: string;
parentNodes?: string; parentNodes?: string;
allUsedContexts?: string[]; allUsedContexts?: string[];

@ -57,7 +57,7 @@ export default class Attribute {
} }
} }
let metadata = state.namespace ? null : attributeLookup[name]; let metadata = node.namespace ? null : attributeLookup[name];
if (metadata && metadata.appliesTo && !~metadata.appliesTo.indexOf(node.name)) if (metadata && metadata.appliesTo && !~metadata.appliesTo.indexOf(node.name))
metadata = null; metadata = null;
@ -252,12 +252,6 @@ export default class Attribute {
if (this.value === true && name === 'autofocus') { if (this.value === true && name === 'autofocus') {
block.autofocus = state.parentNode; block.autofocus = state.parentNode;
} }
// special case — xmlns
if (name === 'xmlns') {
// TODO this attribute must be static enforce at compile time
state.namespace = this.value[0].data;
}
} }
if (isIndirectlyBoundValue) { if (isIndirectlyBoundValue) {

@ -33,10 +33,10 @@ export default class Element extends Node {
this.cannotUseInnerHTML(); this.cannotUseInnerHTML();
} }
const parentElement = this.findNearest('Element'); const parentElement = this.parent && this.parent.findNearest('Element');
this.namespace = this.name === 'svg' ? this.namespace = this.name === 'svg' ?
namespaces.svg : namespaces.svg :
parentElement.namespace; parentElement ? parentElement.namespace : this.generator.namespace;
this.attributes.forEach(attribute => { this.attributes.forEach(attribute => {
if (attribute.type === 'Attribute' && attribute.value !== true) { if (attribute.type === 'Attribute' && attribute.value !== true) {
@ -179,9 +179,6 @@ export default class Element extends Node {
const childState = state.child({ const childState = state.child({
parentNode: this.var, parentNode: this.var,
parentNodes: block.getUniqueName(`${this.var}_nodes`), parentNodes: block.getUniqueName(`${this.var}_nodes`),
namespace: this.name === 'svg'
? 'http://www.w3.org/2000/svg'
: state.namespace,
allUsedContexts: [], allUsedContexts: [],
}); });
@ -196,14 +193,14 @@ export default class Element extends Node {
block.builders.create.addLine( block.builders.create.addLine(
`${name} = ${getRenderStatement( `${name} = ${getRenderStatement(
this.generator, this.generator,
childState.namespace, this.namespace,
this.name this.name
)};` )};`
); );
if (this.generator.hydratable) { if (this.generator.hydratable) {
block.builders.claim.addBlock(deindent` block.builders.claim.addBlock(deindent`
${name} = ${getClaimStatement(generator, childState.namespace, state.parentNodes, this)}; ${name} = ${getClaimStatement(generator, this.namespace, state.parentNodes, this)};
var ${childState.parentNodes} = @children(${name}); var ${childState.parentNodes} = @children(${name});
`); `);
} }
@ -235,7 +232,7 @@ export default class Element extends Node {
} }
// insert static children with textContent or innerHTML // insert static children with textContent or innerHTML
if (!childState.namespace && this.canUseInnerHTML && this.children.length > 0) { if (!this.namespace && this.canUseInnerHTML && this.children.length > 0) {
if (this.children.length === 1 && this.children[0].type === 'Text') { if (this.children.length === 1 && this.children[0].type === 'Text') {
block.builders.create.addLine( block.builders.create.addLine(
`${name}.textContent = ${stringify(this.children[0].data)};` `${name}.textContent = ${stringify(this.children[0].data)};`

@ -35,7 +35,6 @@ export default class Fragment extends Node {
this.init(); this.init();
const state = new State({ const state = new State({
namespace: this.generator.namespace,
parentNode: null, parentNode: null,
parentNodes: 'nodes' parentNodes: 'nodes'
}); });

Loading…
Cancel
Save