How to use the edge-parser.expressions.ConditionalExpression 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 / Include.ts View on Github external
compile (parser, buffer, token) {
    const parsed = parser.generateEdgeExpression(token.properties.jsArg, token.loc)
    allowExpressions(
      parsed,
      [
        expressions.Identifier,
        expressions.Literal,
        expressions.LogicalExpression,
        expressions.MemberExpression,
        expressions.ConditionalExpression,
        expressions.CallExpression,
        expressions.TemplateLiteral,
      ],
      parser.options.filename,
      `{${token.properties.jsArg}} is not a valid argument type for the @include tag`,
    )

    /**
     * Include template. Since the partials can be a runtime value, we cannot inline
     * the content right now and have to defer to runtime to get the value of
     * the partial and then process it
     */
    buffer.writeLine(`template.renderInline(${parser.stringifyExpression(parsed)})(template, ctx)`)
  },
}
github edge-js / edge / src / Tags / Component.ts View on Github external
import { EdgeError } from 'edge-error'
import { EdgeBuffer, expressions, Parser } from 'edge-parser'

import { TagContract } from '../Contracts'
import { StringifiedObject } from '../StringifiedObject'
import { expressionsToStringifyObject, isBlockToken, allowExpressions } from '../utils'

/**
 * A list of allowed expressions for the component name
 */
const componentNameAllowedExpressions: (keyof typeof expressions)[] = [
  expressions.Identifier,
  expressions.Literal,
  expressions.LogicalExpression,
  expressions.MemberExpression,
  expressions.ConditionalExpression,
  expressions.CallExpression,
  expressions.TemplateLiteral,
]

/**
 * Returns the component name and props by parsing the component jsArg expression
 */
function getComponentNameAndProps (expression: any, parser: Parser): [string, string] {
  let name

  /**
   * Use the first expression inside the sequence expression as the name
   * of the component
   */
  if (expression.type === expressions.SequenceExpression) {
    name = expression.expressions.shift()