How to use the edge-parser.expressions.Identifier 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 / Component.ts View on Github external
/**
   * Make sure the sequence expression has only 2 arguments in it. Though it doesn't hurt
   * the rendering of component, we must not run code with false expectations.
   */
  if (parsed.expressions.length > 2) {
    throw new EdgeError('maximum of 2 arguments are allowed for @slot tag', 'E_MAX_ARGUMENTS', {
      line: parsed.loc.start.line,
      col: parsed.loc.start.column,
      filename: parser.options.filename,
    })
  }

  allowExpressions(
    parsed.expressions[1],
    [expressions.Identifier],
    parser.options.filename,
    `{${parser.stringifyExpression(parsed.expressions[1])}} is not valid prop identifier for @slot tag`,
  )

  /**
   * Returning the slot name and slot props name
   */
  return [name.raw, parsed.expressions[1].name]
}
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
     */
github edge-js / edge / src / Tags / Each.ts View on Github external
function getLoopItemAndIndex (expression: any, filename: string): [string, string] {
  allowExpressions(
    expression,
    [expressions.SequenceExpression, expressions.Identifier],
    filename,
    `invalid left hand side expression for the @each tag`,
  )

  /**
   * Return list index from the sequence expression
   */
  if (expression.type === 'SequenceExpression') {
    allowExpressions(
      expression.expressions[0],
      [expressions.Identifier],
      filename,
      `invalid expression for {value} identifier for the @each tag`,
    )

    allowExpressions(
      expression.expressions[1],
      [expressions.SequenceExpression, expressions.Identifier],
      filename,
      `invalid expression for {key} identifier for the @each tag`,
    )
    return [expression.expressions[0].name, expression.expressions[1].name]
  }

  return [expression.name, 'key']
}