How to use the edge-parser.expressions.BinaryExpression function in edge-parser

To help you get started, we’ve selected a few edge-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github edge-js / edge / src / Tags / Each.ts View on Github external
compile (parser, buffer, token) {
    /**
     * Instead of using `parser.generateEdgeExpression`, we make use of
     * `generateAcornExpression`, since we do not want to process
     * `Indentifer` expressions as per the normal parsing logic
     * and just want to extract it's name.
     */
    const parsed = parser.generateAcornExpression(token.properties.jsArg, token.loc).expression
    allowExpressions(
      parsed,
      [expressions.BinaryExpression],
      parser.options.filename,
      `{${token.properties.jsArg}} is not a valid binary expression for the @each tag`,
    )

    /**
     * Finding if an else child exists inside the each tag
     */
    const elseIndex = token.children.findIndex((child) => isBlockToken(child, 'else'))
    const elseChild = elseIndex > -1 ? token.children.splice(elseIndex) : []

    /**
     * Fetching the item,index and list for the each loop
     */
    const [item, index] = getLoopItemAndIndex(parsed.left, parser.options.filename)
    const list = getLoopList(parsed.right, parser)