Lint and format src/compiler/compile/utils/get_slot_data.js

pull/8569/head
Simon Holthausen 3 years ago
parent f847c4d4c8
commit a2e2bacb3a

@ -6,22 +6,22 @@ import { string_literal } from './stringify.js';
* @param {Block} block * @param {Block} block
*/ */
export default function get_slot_data(values, block = null) { export default function get_slot_data(values, block = null) {
return { return {
type: 'ObjectExpression', type: 'ObjectExpression',
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 (attribute.is_spread) { if (attribute.is_spread) {
const argument = get_spread_value(block, attribute); const argument = get_spread_value(block, attribute);
return { return {
type: 'SpreadElement', type: 'SpreadElement',
argument argument
}; };
} }
const value = get_value(block, attribute); const value = get_value(block, attribute);
return p `${attribute.name}: ${value}`; return p`${attribute.name}: ${value}`;
}) })
}; };
} }
/** /**
@ -29,21 +29,21 @@ export default function get_slot_data(values, block = null) {
* @param {Attribute} attribute * @param {Attribute} attribute
*/ */
function get_value(block, attribute) { function get_value(block, attribute) {
if (attribute.is_true) if (attribute.is_true) return x`true`;
return x `true`; if (attribute.chunks.length === 0) return x`""`;
if (attribute.chunks.length === 0) let value = attribute.chunks
return x `""`; .map((chunk) =>
let value = attribute.chunks chunk.type === 'Text'
.map((chunk) => chunk.type === 'Text' ? string_literal(chunk.data)
? string_literal(chunk.data) : block
: block ? chunk.manipulate(block)
? chunk.manipulate(block) : chunk.node
: chunk.node) )
.reduce((lhs, rhs) => x `${lhs} + ${rhs}`); .reduce((lhs, rhs) => x`${lhs} + ${rhs}`);
if (attribute.chunks.length > 1 && attribute.chunks[0].type !== 'Text') { if (attribute.chunks.length > 1 && attribute.chunks[0].type !== 'Text') {
value = x `"" + ${value}`; value = x`"" + ${value}`;
} }
return value; return value;
} }
/** /**
@ -51,9 +51,5 @@ function get_value(block, attribute) {
* @param {Attribute} attribute * @param {Attribute} attribute
*/ */
function get_spread_value(block, attribute) { function get_spread_value(block, attribute) {
return block ? attribute.expression.manipulate(block) : attribute.expression.node; return block ? attribute.expression.manipulate(block) : attribute.expression.node;
} }

Loading…
Cancel
Save