MCPcopy Create free account
hub / github.com/ampproject/amphtml / constructor

Method constructor

extensions/amp-bind/0.1/bind-expression.js:207–233  ·  view source on GitHub ↗

* @param {string} expressionString * @param {!{[key: string]: !./bind-macro.BindMacro}} macros * @param {number=} opt_maxAstSize * @throws {Error} On malformed expressions.

(expressionString, macros, opt_maxAstSize)

Source from the content-addressed store, hash-verified

205 * @throws {Error} On malformed expressions.
206 */
207 constructor(expressionString, macros, opt_maxAstSize) {
208 if (!FUNCTION_ALLOWLIST) {
209 FUNCTION_ALLOWLIST = generateFunctionAllowlist();
210 }
211
212 /** @const {string} */
213 this.expressionString = expressionString;
214
215 /** @private @const {!{[key: string]: !./bind-macro.BindMacro}} */
216 this.macros_ = macros;
217
218 /** @const @private {!./bind-expr-defines.AstNode} */
219 this.ast_ = parser.parse(this.expressionString);
220
221 /** @const {number} */
222 this.expressionSize = this.numberOfNodesInAst_(this.ast_);
223
224 // Check if this expression string is too large (for performance).
225 const maxSize = opt_maxAstSize || MAX_AST_SIZE;
226 const skipConstraint = getMode().localDev && !getMode().test;
227 if (this.expressionSize > maxSize && !skipConstraint) {
228 throw new Error(
229 `Expression size (${this.expressionSize}) exceeds max ` +
230 `(${maxSize}). Please reduce number of operands.`
231 );
232 }
233 }
234
235 /**
236 * Evaluates the expression given a scope.

Callers

nothing calls this directly

Calls 4

numberOfNodesInAst_Method · 0.95
getModeFunction · 0.90
parseMethod · 0.45

Tested by

no test coverage detected