fix boolean attributes along with spreads (DOM mode)

pull/3775/head
Conduitry 6 years ago
parent b1c2ced6f3
commit 2ffdfcb197

@ -9,7 +9,7 @@ import TemplateScope from './shared/TemplateScope';
import { x } from 'code-red'; import { x } from 'code-red';
export default class Attribute extends Node { export default class Attribute extends Node {
type: 'Attribute'; type: 'Attribute' | 'Spread';
start: number; start: number;
end: number; end: number;
scope: TemplateScope; scope: TemplateScope;

@ -44,9 +44,7 @@ export default class AttributeWrapper {
const element = this.parent; const element = this.parent;
const name = fix_attribute_casing(this.node.name); const name = fix_attribute_casing(this.node.name);
let metadata = element.node.namespace ? null : attribute_lookup[name]; const metadata = this.get_metadata();
if (metadata && metadata.applies_to && !~metadata.applies_to.indexOf(element.node.name))
metadata = null;
const is_indirectly_bound_value = const is_indirectly_bound_value =
name === 'value' && name === 'value' &&
@ -193,6 +191,13 @@ export default class AttributeWrapper {
} }
} }
get_metadata() {
if (this.parent.node.namespace) return null;
const metadata = attribute_lookup[fix_attribute_casing(this.node.name)];
if (metadata && metadata.applies_to && !metadata.applies_to.includes(this.parent.node.name)) return null;
return metadata;
}
get_class_name_text() { get_class_name_text() {
const scoped_css = this.node.chunks.some((chunk: Text) => chunk.synthetic); const scoped_css = this.node.chunks.some((chunk: Text) => chunk.synthetic);
const rendered = this.render_chunks(); const rendered = this.render_chunks();

@ -573,8 +573,7 @@ export default class ElementWrapper extends Wrapper {
} }
}); });
// @ts-ignore todo: if (this.node.attributes.some(attr => attr.is_spread)) {
if (this.node.attributes.find(attr => attr.type === 'Spread')) {
this.add_spread_attributes(block); this.add_spread_attributes(block);
return; return;
} }
@ -591,21 +590,24 @@ export default class ElementWrapper extends Wrapper {
const initial_props = []; const initial_props = [];
const updates = []; const updates = [];
this.node.attributes this.attributes
.filter(attr => attr.type === 'Attribute' || attr.type === 'Spread')
.forEach(attr => { .forEach(attr => {
const condition = attr.dependencies.size > 0 const condition = attr.node.dependencies.size > 0
? changed(Array.from(attr.dependencies)) ? changed(Array.from(attr.node.dependencies))
: null; : null;
if (attr.is_spread) { if (attr.node.is_spread) {
const snippet = attr.expression.manipulate(block); const snippet = attr.node.expression.manipulate(block);
initial_props.push(snippet); initial_props.push(snippet);
updates.push(condition ? x`${condition} && ${snippet}` : snippet); updates.push(condition ? x`${condition} && ${snippet}` : snippet);
} else { } else {
const snippet = x`{ ${attr.name}: ${attr.get_value(block)} }`; const metadata = attr.get_metadata();
const snippet = x`{ ${
(metadata && metadata.property_name) ||
fix_attribute_casing(attr.node.name)
}: ${attr.node.get_value(block)} }`;
initial_props.push(snippet); initial_props.push(snippet);
updates.push(condition ? x`${condition} && ${snippet}` : snippet); updates.push(condition ? x`${condition} && ${snippet}` : snippet);

Loading…
Cancel
Save