How to use edge-error - 6 common examples

To help you get started, we’ve selected a few edge-error 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
)

  /**
   * Return the slot name with empty props, when the expression is a literal
   * value.
   */
  if (parsed.type === expressions.Literal) {
    return [name.raw, null]
  }

  /**
   * 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
   */
github edge-js / edge / src / utils / index.ts View on Github external
export function disAllowExpressions (
  expression: any,
  expressions: (keyof typeof expressionsList)[],
  filename: string,
  message: string,
) {
  if (expressions.includes(expression.type)) {
    throw new EdgeError(message, 'E_UNALLOWED_EXPRESSION', {
      line: expression.loc.start.line,
      col: expression.loc.start.column,
      filename: filename,
    })
  }
}
github edge-js / edge / src / Tags / Slot.ts View on Github external
compile (parser, _buffer, token) {
    throw new EdgeError(
      `@slot tag must appear as top level tag inside the @component tag`,
      'E_ORPHAN_SLOT_TAG',
      {
        line: token.loc.start.line,
        col: token.loc.start.col,
        filename: parser.options.filename,
      },
    )
  },
}
github edge-js / edge / src / Compiler / index.ts View on Github external
return
        }

        /**
         * Collect set calls inside parent templates
         */
        if (isBlockToken(node, 'set')) {
          extendedSetCalls.push(node)
          return
        }

        /**
         * Everything else if not allowed as top level nodes
         */
        const [line, col] = getLineAndColumnForToken(node)
        throw new EdgeError(
          `Template extending the layout can only define @sections as top level nodes`,
          'E_UNALLOWED_EXPRESSION',
          { line, col, filename },
        )
      })
github edge-js / edge / src / Tags / Set.ts View on Github external
/**
     * The set tag only accepts a sequence expression.
     */
    allowExpressions(
      parsed,
      [expressions.SequenceExpression],
      parser.options.filename,
      `{${token.properties.jsArg}} is not a valid key-value pair for the @slot tag`,
    )

    /**
     * Disallow more than 2 values for the sequence expression
     */
    if (parsed.expressions.length > 2) {
      throw new EdgeError(`maximum of 2 arguments are allowed for the @set tag`, 'E_MAX_ARGUMENTS', {
        line: parsed.loc.start.line,
        col: parsed.loc.start.column,
        filename: parser.options.filename,
      })
    }

    const [key, value] = parsed.expressions

    /**
     * The key has to be a literal value
     */
    allowExpressions(
      key,
      [expressions.Literal],
      parser.options.filename,
      'The first argument for @set tag must be a string literal',
github edge-js / edge / src / utils / index.ts View on Github external
export function allowExpressions (
  expression: any,
  expressions: (keyof typeof expressionsList)[],
  filename: string,
  message: string,
) {
  if (!expressions.includes(expression.type)) {
    throw new EdgeError(message, 'E_UNALLOWED_EXPRESSION', {
      line: expression.loc.start.line,
      col: expression.loc.start.column,
      filename: filename,
    })
  }
}

edge-error

Create errors with custom stack trace pointing to the .edge template file

MIT
Latest version published 4 months ago

Package Health Score

71 / 100
Full package analysis

Popular edge-error functions