pull/3539/head
Richard Harris 6 years ago
parent 1e2f29bf4e
commit 16b4897abf

@ -46,7 +46,7 @@ export default class Renderer {
has_bindings = false; has_bindings = false;
stack: { current: { value: string }, literal: TemplateLiteral }[] = []; stack: { current: { value: string }, literal: TemplateLiteral }[] = [];
current: { value: string }; current: { value: string }; // TODO can it just be `current: string`?
literal: TemplateLiteral; literal: TemplateLiteral;
targets: AppendTarget[] = []; targets: AppendTarget[] = [];

@ -81,11 +81,13 @@ export default function(node: Element, renderer: Renderer, options: RenderOption
// options.slot_scopes.set(slot_name, get_slot_scope(node.lets)); // options.slot_scopes.set(slot_name, get_slot_scope(node.lets));
// } // }
const class_expression = node.classes.map((class_directive: Class) => { const class_expression = node.classes.length > 0 && node.classes
const { expression, name } = class_directive; .map((class_directive: Class) => {
const snippet = expression ? snip(expression) : `#ctx${quote_prop_if_necessary(name)}`; const { expression, name } = class_directive;
return `${snippet} ? "${name}" : ""`; const snippet = expression ? expression.node : x`#ctx.${name}`;
}).join(', '); return x`${snippet} ? "${name}" : ""`;
})
.reduce((lhs, rhs) => x`${lhs} + ${rhs}`);
let add_class_attribute = class_expression ? true : false; let add_class_attribute = class_expression ? true : false;
@ -171,9 +173,9 @@ export default function(node: Element, renderer: Renderer, options: RenderOption
} }
}); });
// if (add_class_attribute) { if (add_class_attribute) {
// opening_tag += `\${@add_classes([${class_expression}].join(' ').trim())}`; renderer.add_expression(x`@add_classes([${class_expression}].join(' ').trim())`);
// } }
renderer.add_string('>'); renderer.add_string('>');

@ -70,7 +70,7 @@ export default function ssr(
: []; : [];
const reactive_declarations = component.reactive_declarations.map(d => { const reactive_declarations = component.reactive_declarations.map(d => {
let snippet = b`${d.node}`; let statement = b`${d.node.body}`;
if (d.declaration) { if (d.declaration) {
const declared = extract_names(d.declaration); const declared = extract_names(d.declaration);
@ -88,16 +88,16 @@ export default function ssr(
declared.length > injected.length declared.length > injected.length
); );
snippet = separate statement = separate
? b` ? b`
${injected.map(name => b`let ${name};`)} ${injected.map(name => b`let ${name};`)}
${snippet}` ${statement}`
: b` : b`
let ${snippet}`; let ${d.node.body.expression.left} = ${d.node.body.expression.right}`;
} }
} }
return snippet; return statement;
}); });
const main = renderer.has_bindings const main = renderer.has_bindings

@ -8,25 +8,13 @@ export default function get_slot_data(values: Map<string, Attribute>, is_ssr: bo
properties: Array.from(values.values()) properties: Array.from(values.values())
.filter(attribute => attribute.name !== 'name') .filter(attribute => attribute.name !== 'name')
.map(attribute => { .map(attribute => {
if (is_ssr) {
throw new Error(`TODO SSR`);
}
const value = get_value(attribute); const value = get_value(attribute);
// const value = attribute.is_true
// ? x`true`
// : attribute.chunks.length === 0
// ? x`""`
// : attribute.chunks.length === 1 && attribute.chunks[0].type !== 'Text'
// ? snip(attribute.chunks[0])
// : '`' + stringify_attribute(attribute, is_ssr) + '`';
return p`${attribute.name}: ${value}`; return p`${attribute.name}: ${value}`;
}) })
} }
} }
// TODO fairly sure this is duplicated at least once
function get_value(attribute: Attribute) { function get_value(attribute: Attribute) {
if (attribute.is_true) return x`true`; if (attribute.is_true) return x`true`;
if (attribute.chunks.length === 0) return x`""`; if (attribute.chunks.length === 0) return x`""`;

Loading…
Cancel
Save