pull/4095/head
Tan Li Hau 6 years ago
parent cd135f934c
commit daf80e3a82

@ -2,7 +2,6 @@ import Let from '../../../nodes/Let';
import { x, p } from 'code-red';
import Block from '../../Block';
import TemplateScope from '../../../nodes/shared/TemplateScope';
import { BinaryExpression } from 'estree';
export function get_slot_definition(block: Block, scope: TemplateScope, lets: Let[]) {
if (lets.length === 0) return { block, scope };
@ -36,39 +35,30 @@ export function get_slot_definition(block: Block, scope: TemplateScope, lets: Le
const changes = {
type: 'ParenthesizedExpression',
get expression() {
if (block.renderer.context_overflow) {
const grouped = [];
const grouped = [];
Array.from(names).forEach(name => {
const i = context_lookup.get(name).index.value as number;
const g = Math.floor(i / 31);
Array.from(names).forEach(name => {
const i = context_lookup.get(name).index.value as number;
const g = Math.floor(i / 31);
if (!grouped[g]) grouped[g] = [];
grouped[g].push({ name, n: i % 31 });
});
if (!grouped[g]) grouped[g] = [];
grouped[g].push({ name, n: i % 31 });
});
const elements = [];
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`;
}
return {
type: 'ArrayExpression',
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`;
}
return Array.from(names)
.map(name => {
const i = context_lookup.get(name).index.value as number;
return x`${name} ? ${1 << i} : 0`;
})
.reduce((lhs, rhs) => x`${lhs} | ${rhs}`) as BinaryExpression;
return {
type: 'ArrayExpression',
elements
};
}
};

@ -80,17 +80,16 @@ export function get_slot_changes(definition, $$scope, dirty, fn) {
if (definition[2] && fn) {
const lets = definition[2](fn(dirty));
if (typeof $$scope.dirty === 'object') {
if ($$scope.dirty) {
const merged = [];
const len = Math.max($$scope.dirty.length, lets.length);
for (let i = 0; i < len; i += 1) {
merged[i] = $$scope.dirty[i] | lets[i];
}
return merged;
}
return $$scope.dirty | lets;
return lets;
}
return $$scope.dirty;

Loading…
Cancel
Save