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';
interface StateData {
namespace?: string;
parentNode?: string;
parentNodes?: string;
allUsedContexts?: string[];
@ -9,7 +8,6 @@ interface StateData {
}
export default class State {
namespace?: string;
parentNode?: string;
parentNodes?: 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))
metadata = null;
@ -252,12 +252,6 @@ export default class Attribute {
if (this.value === true && name === 'autofocus') {
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) {

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

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

Loading…
Cancel
Save