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

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

Loading…
Cancel
Save