|
|
|
|
@ -1,9 +1,11 @@
|
|
|
|
|
import Attribute from '../nodes/Attribute';
|
|
|
|
|
import { p, x } from 'code-red';
|
|
|
|
|
import { string_literal } from './stringify';
|
|
|
|
|
import Block from '../render_dom/Block';
|
|
|
|
|
import { string_literal } from './stringify.js';
|
|
|
|
|
|
|
|
|
|
export default function get_slot_data(values: Map<string, Attribute>, block: Block = null) {
|
|
|
|
|
/**
|
|
|
|
|
* @param {Map<string, Attribute>} values
|
|
|
|
|
* @param {Block} block
|
|
|
|
|
*/
|
|
|
|
|
export default function get_slot_data(values, block = null) {
|
|
|
|
|
return {
|
|
|
|
|
type: 'ObjectExpression',
|
|
|
|
|
properties: Array.from(values.values())
|
|
|
|
|
@ -16,34 +18,42 @@ export default function get_slot_data(values: Map<string, Attribute>, block: Blo
|
|
|
|
|
argument
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const value = get_value(block, attribute);
|
|
|
|
|
return p `${attribute.name}: ${value}`;
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function get_value(block: Block, attribute: Attribute) {
|
|
|
|
|
if (attribute.is_true) return x`true`;
|
|
|
|
|
if (attribute.chunks.length === 0) return x`""`;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {Block} block
|
|
|
|
|
* @param {Attribute} attribute
|
|
|
|
|
*/
|
|
|
|
|
function get_value(block, attribute) {
|
|
|
|
|
if (attribute.is_true)
|
|
|
|
|
return x `true`;
|
|
|
|
|
if (attribute.chunks.length === 0)
|
|
|
|
|
return x `""`;
|
|
|
|
|
let value = attribute.chunks
|
|
|
|
|
.map((chunk) =>
|
|
|
|
|
chunk.type === 'Text'
|
|
|
|
|
.map((chunk) => chunk.type === 'Text'
|
|
|
|
|
? string_literal(chunk.data)
|
|
|
|
|
: block
|
|
|
|
|
? chunk.manipulate(block)
|
|
|
|
|
: chunk.node
|
|
|
|
|
)
|
|
|
|
|
: chunk.node)
|
|
|
|
|
.reduce((lhs, rhs) => x `${lhs} + ${rhs}`);
|
|
|
|
|
|
|
|
|
|
if (attribute.chunks.length > 1 && attribute.chunks[0].type !== 'Text') {
|
|
|
|
|
value = x `"" + ${value}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function get_spread_value(block: Block, attribute: Attribute) {
|
|
|
|
|
/**
|
|
|
|
|
* @param {Block} block
|
|
|
|
|
* @param {Attribute} attribute
|
|
|
|
|
*/
|
|
|
|
|
function get_spread_value(block, attribute) {
|
|
|
|
|
return block ? attribute.expression.manipulate(block) : attribute.expression.node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|