This commit is contained in:
zdenko
2018-01-16 01:54:55 +01:00
committed by Geoffrey Booth
parent a70f1a082e
commit 7ea3ea92f3
2 changed files with 4 additions and 56 deletions

View File

@@ -5291,7 +5291,7 @@
// comprehensions. Some of the generated code can be shared in common, and
// some cannot.
compileNode(o) {
var body, bodyFragments, compare, compareDown, declare, declareDown, defPart, defPartFragments, down, forPartFragments, fragments, guardPart, idt1, increment, index, ivar, kvar, kvarAssign, last, lvar, name, namePart, ref, ref1, resultPart, returnResult, rvar, scope, source, step, stepNum, stepVar, svar, varPart;
var body, bodyFragments, compare, compareDown, declare, declareDown, defPart, down, forPartFragments, fragments, guardPart, idt1, increment, index, ivar, kvar, kvarAssign, last, lvar, name, namePart, ref, ref1, resultPart, returnResult, rvar, scope, source, step, stepNum, stepVar, svar, varPart;
body = Block.wrap([this.body]);
ref1 = body.expressions, last = ref1[ref1.length - 1];
if ((last != null ? last.jumps() : void 0) instanceof Return) {
@@ -5400,7 +5400,6 @@
if (this.pattern) {
body.expressions.unshift(new Assign(this.name, this.from ? new IdentifierLiteral(kvar) : new Literal(`${svar}[${kvar}]`)));
}
defPartFragments = [].concat(this.makeCode(defPart), this.pluckDirectCall(o, body));
if (namePart) {
varPart = `\n${idt1}${namePart};`;
}
@@ -5418,10 +5417,7 @@
if (bodyFragments && bodyFragments.length > 0) {
bodyFragments = [].concat(this.makeCode('\n'), bodyFragments, this.makeCode('\n'));
}
fragments = [];
if ((defPartFragments != null) && fragmentsToText(defPartFragments) !== '') {
fragments = fragments.concat(defPartFragments);
}
fragments = [this.makeCode(defPart)];
if (resultPart) {
fragments.push(this.makeCode(resultPart));
}
@@ -5432,32 +5428,6 @@
return fragments;
}
pluckDirectCall(o, body) {
var base, defs, expr, fn, idx, j, len1, ref, ref1, ref2, ref3, ref4, ref5, ref6, val;
defs = [];
ref1 = body.expressions;
for (idx = j = 0, len1 = ref1.length; j < len1; idx = ++j) {
expr = ref1[idx];
expr = expr.unwrapAll();
if (!(expr instanceof Call)) {
continue;
}
val = (ref2 = expr.variable) != null ? ref2.unwrapAll() : void 0;
if (!((val instanceof Code) || (val instanceof Value && ((ref3 = val.base) != null ? ref3.unwrapAll() : void 0) instanceof Code && val.properties.length === 1 && ((ref4 = (ref5 = val.properties[0].name) != null ? ref5.value : void 0) === 'call' || ref4 === 'apply')))) {
continue;
}
fn = ((ref6 = val.base) != null ? ref6.unwrapAll() : void 0) || val;
ref = new IdentifierLiteral(o.scope.freeVariable('fn'));
base = new Value(ref);
if (val.base) {
[val.base, base] = [base, val];
}
body.expressions[idx] = new Call(base, expr.args);
defs = defs.concat(this.makeCode(this.tab), new Assign(ref, fn).compileToFragments(o, LEVEL_TOP), this.makeCode(';\n'));
}
return defs;
}
};
For.prototype.children = ['body', 'source', 'guard', 'step'];