extensions/amp-bind/0.1/bind-evaluator.js
/**
   * Evaluates all expressions with the given `scope` data returns two maps:
   * expression strings to results and expression strings to errors.
   * @param {!Object} scope
   * @return {{
   *   results: !Object<string, ./bind-expression.BindExpressionResultDef>,
   *   errors: !Object<string, !EvaluatorErrorDef>,
   * }}
   */
Evaluates all expressions with the given `scope` data returns two maps:
expression strings to results and expression strings to errors.
Evaluates all expressions with the given ` scope ` data returns two maps : expression strings to results and expression strings to errors .
evaluateBindings(scope) {
    const cache = Object.create(null);
    const errors = Object.create(null);
    this.bindings_.forEach(binding => {
      const expressionString = binding.expressionString;
      if (cache[expressionString] !== undefined || errors[expressionString]) {
        return;
      }
      const expression = this.expressions_[expressionString];
      if (!expression) {
        const error =
            new Error(`Expression "${expressionString}"" is not cached.`);
        errors[expressionString] = {message: error.message, stack: error.stack};
        return;
      }
      const {result, error} = this.evaluate_(expression, scope);
      if (error) {
        errors[expressionString] = error;
        return;
      }
      cache[expressionString] = result;
    });
    this.bindings_.forEach(binding => {
      const {tagName, property, expressionString} = binding;
      const result = cache[expressionString];
      if (result === undefined) {
        return;
      }
      const resultString = this.stringValueOf_(property, result);
      if (!this.validator_.isResultValid(tagName, property, resultString)) {
        delete cache[expressionString];
        const error =
            new Error(`"${result}" is not a valid result for [${property}].`);
        errors[expressionString] = {message: error.message, stack: error.stack};
      }
    });
    return {results: cache, errors};
  }
evaluateBindings ( scope ) { const cache = Object . create ( null ) ; const errors = Object . create ( null ) ; this . bindings_ . forEach ( binding => { const expressionString = binding . expressionString ; if ( cache [ expressionString ] !== undefined || errors [ expressionString ] ) { return ; } const expression = this . expressions_ [ expressionString ] ; if ( ! expression ) { const error = new Error ( ` ${ expressionString } ` ) ; errors [ expressionString ] = { message : error . message , stack : error . stack } ; return ; } const { result , error } = this . evaluate_ ( expression , scope ) ; if ( error ) { errors [ expressionString ] = error ; return ; } cache [ expressionString ] = result ; } ) ; this . bindings_ . forEach ( binding => { const { tagName , property , expressionString } = binding ; const result = cache [ expressionString ] ; if ( result === undefined ) { return ; } const resultString = this . stringValueOf_ ( property , result ) ; if ( ! this . validator_ . isResultValid ( tagName , property , resultString ) ) { delete cache [ expressionString ] ; const error = new Error ( ` ${ result } ${ property } ` ) ; errors [ expressionString ] = { message : error . message , stack : error . stack } ; } } ) ; return { results : cache , errors } ; }
Evaluates all expressions with the given `scope` data returns two maps:
 expression strings to results and expression strings to errors.
Evaluates all expressions with the given ` scope ` data returns two maps : expression strings to results and expression strings to errors .
/** @type {!Object<string, ./bind-expression.BindExpressionResultDef>} */ /** @type {!Object<string, !EvaluatorErrorDef>} */ // First, evaluate all of the expression strings in the bindings. // Skip if we've already evaluated this expression string. // Then, validate each binding and delete invalid expression results. // IMPORTANT: We need to validate expression results on each binding // since validity depends on the `tagName` and `property` rather than // just the `result`. // TODO(choumx): If this expression string is used in another // tagName/property which is valid, we ought to allow it.