|
|
|
|
@ -6,8 +6,7 @@ import { x, p } from 'code-red';
|
|
|
|
|
* @param {import('../../../nodes/Let.js').default[]} lets
|
|
|
|
|
*/
|
|
|
|
|
export function get_slot_definition(block, scope, lets) {
|
|
|
|
|
if (lets.length === 0)
|
|
|
|
|
return { block, scope };
|
|
|
|
|
if (lets.length === 0) return { block, scope };
|
|
|
|
|
const context_input = {
|
|
|
|
|
type: 'ObjectPattern',
|
|
|
|
|
properties: lets.map((l) => ({
|
|
|
|
|
@ -20,7 +19,6 @@ export function get_slot_definition(block, scope, lets) {
|
|
|
|
|
const properties = [];
|
|
|
|
|
const value_map = new Map();
|
|
|
|
|
lets.forEach((l) => {
|
|
|
|
|
|
|
|
|
|
/** @type {import('estree').Identifier} */
|
|
|
|
|
let value;
|
|
|
|
|
if (l.names.length > 1) {
|
|
|
|
|
@ -28,8 +26,7 @@ export function get_slot_definition(block, scope, lets) {
|
|
|
|
|
const unique_name = block.get_unique_name(l.names.join('_')).name;
|
|
|
|
|
value_map.set(l.value, unique_name);
|
|
|
|
|
value = { type: 'Identifier', name: unique_name };
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
value = l.value || l.name;
|
|
|
|
|
}
|
|
|
|
|
properties.push({
|
|
|
|
|
@ -59,7 +56,9 @@ export function get_slot_definition(block, scope, lets) {
|
|
|
|
|
});
|
|
|
|
|
const context = {
|
|
|
|
|
type: 'ObjectExpression',
|
|
|
|
|
properties: Array.from(names).map((name) => p `${block.renderer.context_lookup.get(name).index}: ${name}`)
|
|
|
|
|
properties: Array.from(names).map(
|
|
|
|
|
(name) => p`${block.renderer.context_lookup.get(name).index}: ${name}`
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|
const { context_lookup } = block.renderer;
|
|
|
|
|
// i am well aware that this code is gross
|
|
|
|
|
@ -73,40 +72,37 @@ export function get_slot_definition(block, scope, lets) {
|
|
|
|
|
const i = /** @type {number} */ (context_lookup.get(name).index.value);
|
|
|
|
|
const g = Math.floor(i / 31);
|
|
|
|
|
const lookup_name = names_lookup.has(name) ? names_lookup.get(name) : name;
|
|
|
|
|
if (!grouped[g])
|
|
|
|
|
grouped[g] = [];
|
|
|
|
|
if (!grouped[g]) grouped[g] = [];
|
|
|
|
|
grouped[g].push({ name: lookup_name, n: i % 31 });
|
|
|
|
|
});
|
|
|
|
|
const elements = [];
|
|
|
|
|
for (let g = 0; g < grouped.length; g += 1) {
|
|
|
|
|
elements[g] = grouped[g]
|
|
|
|
|
? grouped[g]
|
|
|
|
|
.map(({ name, n }) => x `${name} ? ${1 << n} : 0`)
|
|
|
|
|
.reduce((lhs, rhs) => x `${lhs} | ${rhs}`)
|
|
|
|
|
: x `0`;
|
|
|
|
|
.map(({ name, n }) => x`${name} ? ${1 << n} : 0`)
|
|
|
|
|
.reduce((lhs, rhs) => x`${lhs} | ${rhs}`)
|
|
|
|
|
: x`0`;
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
type: 'ArrayExpression',
|
|
|
|
|
elements
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return /** @type {import('estree').BinaryExpression} */ (Array.from(names)
|
|
|
|
|
return /** @type {import('estree').BinaryExpression} */ (
|
|
|
|
|
Array.from(names)
|
|
|
|
|
.map((name) => {
|
|
|
|
|
const lookup_name = names_lookup.has(name) ? names_lookup.get(name) : name;
|
|
|
|
|
const i = /** @type {number} */ (context_lookup.get(name).index.value);
|
|
|
|
|
return x `${lookup_name} ? ${1 << i} : 0`;
|
|
|
|
|
return x`${lookup_name} ? ${1 << i} : 0`;
|
|
|
|
|
})
|
|
|
|
|
.reduce((lhs, rhs) => x `${lhs} | ${rhs}`));
|
|
|
|
|
.reduce((lhs, rhs) => x`${lhs} | ${rhs}`)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return {
|
|
|
|
|
block,
|
|
|
|
|
scope,
|
|
|
|
|
get_context: x `${context_input} => ${context}`,
|
|
|
|
|
get_changes: x `${changes_input} => ${changes}`
|
|
|
|
|
get_context: x`${context_input} => ${context}`,
|
|
|
|
|
get_changes: x`${changes_input} => ${changes}`
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|