Skip to content

Commit

Permalink
fix(literal-template): only throw on invalid function when mustEvalua…
Browse files Browse the repository at this point in the history
…te is truthy
  • Loading branch information
fkleuver committed Jun 6, 2018
1 parent 8528baa commit 766571d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,18 +646,21 @@ export class LiteralTemplate extends Expression {
return this.tag.object.evaluate(scope, lookupFunctions);
}

evaluate(scope, lookupFunctions) {
evaluate(scope, lookupFunctions, mustEvaluate) {
const results = new Array(this.length);
for (let i = 0; i < this.length; i++) {
results[i] = this.expressions[i].evaluate(scope, lookupFunctions);
}
if (this.tagged) {
const func = this.tag.evaluate(scope, lookupFunctions);
if (typeof func !== 'function') {
throw new Error(`${this.tag} is not a function`);
if (typeof func === 'function') {
const context = this[`get${this.contextType}Context`](scope, lookupFunctions);
return func.call(context, this.cooked, ...results);
}
if (!mustEvaluate) {
return null;
}
const context = this[`get${this.contextType}Context`](scope, lookupFunctions);
return func.call(context, this.cooked, ...results);
throw new Error(`${this.tag} is not a function`);
}
let result = this.cooked[0];
for (let i = 0; i < this.length; i++) {
Expand Down

0 comments on commit 766571d

Please sign in to comment.