mirror of https://github.com/sveltejs/svelte
parent
e12a30ae50
commit
9e1bc908d3
@ -1,19 +1,43 @@
|
|||||||
import { snip } from './snip';
|
|
||||||
import { stringify_attribute } from './stringify_attribute';
|
|
||||||
import Attribute from '../nodes/Attribute';
|
import Attribute from '../nodes/Attribute';
|
||||||
|
import { p, x } from 'code-red';
|
||||||
|
import { string_literal } from './stringify';
|
||||||
|
|
||||||
export default function get_slot_data(values: Map<string, Attribute>, is_ssr: boolean) {
|
export default function get_slot_data(values: Map<string, Attribute>, is_ssr: boolean) {
|
||||||
return Array.from(values.values())
|
return {
|
||||||
|
type: 'ObjectExpression',
|
||||||
|
properties: Array.from(values.values())
|
||||||
.filter(attribute => attribute.name !== 'name')
|
.filter(attribute => attribute.name !== 'name')
|
||||||
.map(attribute => {
|
.map(attribute => {
|
||||||
const value = attribute.is_true
|
if (is_ssr) {
|
||||||
? 'true'
|
throw new Error(`TODO SSR`);
|
||||||
: attribute.chunks.length === 0
|
}
|
||||||
? '""'
|
|
||||||
: attribute.chunks.length === 1 && attribute.chunks[0].type !== 'Text'
|
const value = get_value(attribute);
|
||||||
? snip(attribute.chunks[0])
|
|
||||||
: '`' + stringify_attribute(attribute, is_ssr) + '`';
|
// const value = attribute.is_true
|
||||||
|
// ? x`true`
|
||||||
return `${attribute.name}: ${value}`;
|
// : 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}`;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_value(attribute: Attribute) {
|
||||||
|
if (attribute.is_true) return x`true`;
|
||||||
|
if (attribute.chunks.length === 0) return x`""`;
|
||||||
|
|
||||||
|
let value = attribute.chunks
|
||||||
|
.map(chunk => chunk.type === 'Text' ? string_literal(chunk.data) : chunk.node)
|
||||||
|
.reduce((lhs, rhs) => x`${lhs} + ${rhs}`);
|
||||||
|
|
||||||
|
if (attribute.chunks.length > 1 && attribute.chunks[0].type !== 'Text') {
|
||||||
|
value = x`"" + ${value}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
}
|
}
|
Loading…
Reference in new issue