How to use the @glimmer/syntax.SyntaxError function in @glimmer/syntax

To help you get started, we’ve selected a few @glimmer/syntax 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 glimmerjs / glimmer-vm / packages / @glimmer / compiler / lib / template-compiler.ts View on Github external
function assertValidPartial(statement: AST.MustacheStatement) /* : expr */ {
  let { params, hash, escaped, loc } = statement;

  if (params && params.length !== 1) {
    throw new SyntaxError(
      `Partial found with no arguments. You must specify a template name. (on line ${loc.start.line})`,
      statement.loc
    );
  } else if (hash && hash.pairs.length > 0) {
    throw new SyntaxError(
      `partial does not take any named arguments (on line ${loc.start.line})`,
      statement.loc
    );
  } else if (!escaped) {
    throw new SyntaxError(
      `{{{partial ...}}} is not supported, please use {{partial ...}} instead (on line ${loc.start.line})`,
      statement.loc
    );
  }

  return params;
github glimmerjs / glimmer-vm / packages / @glimmer / compiler / lib / strict-template-compiler.ts View on Github external
function assertValidPartial(statement: AST.MustacheStatement) /* : expr */ {
  let { params, hash, escaped, loc } = statement;

  if (params && params.length !== 1) {
    throw new SyntaxError(
      `Partial found with no arguments. You must specify a template name. (on line ${
        loc.start.line
      })`,
      statement.loc
    );
  } else if (hash && hash.pairs.length > 0) {
    throw new SyntaxError(
      `partial does not take any named arguments (on line ${loc.start.line})`,
      statement.loc
    );
  } else if (!escaped) {
    throw new SyntaxError(
      `{{{partial ...}}} is not supported, please use {{partial ...}} instead (on line ${
        loc.start.line
      })`,
      statement.loc
    );
  }

  return params;
}
github glimmerjs / glimmer-vm / packages / @glimmer / compiler / lib / template-compiler.ts View on Github external
private expression(path: AST.Expression, context: ExpressionContext, expr: AST.Node) {
    if (isLiteral(path)) {
      this.opcode(['literal', path.value], expr);
    } else if (path.type !== 'PathExpression') {
      throw new SyntaxError(`Expected PathExpression, got ${path.type}`, path.loc);
    } else if (isKeyword(expr)) {
      this.keyword(expr as AST.Call);
    } else {
      this.path(path, context);
    }
  }
github glimmerjs / glimmer-vm / packages / @glimmer / compiler / lib / template-compiler.ts View on Github external
function assertValidDebuggerUsage(statement: AST.MustacheStatement) {
  let { params, hash } = statement;

  if (hash && hash.pairs.length > 0) {
    throw new SyntaxError(`debugger does not take any named arguments`, statement.loc);
  }

  if (params.length === 0) {
    return 'default';
  } else {
    throw new SyntaxError(`debugger does not take any positional arguments`, statement.loc);
  }
}
github glimmerjs / glimmer-vm / packages / @glimmer / compiler / lib / template-compiler.ts View on Github external
function assertIsSimplePath(path: AST.Expression, loc: AST.SourceLocation, context: string) {
  if (path.type !== 'PathExpression') {
    throw new SyntaxError(
      `\`${path.type}\` is not a valid ${context} on line ${loc.start.line}.`,
      path.loc
    );
  }

  if (!isSimplePath(path)) {
    throw new SyntaxError(
      `\`${path.original}\` is not a valid name for a ${context} on line ${loc.start.line}.`,
      path.loc
    );
  }
}
github glimmerjs / glimmer-vm / packages / @glimmer / compiler / lib / strict-template-compiler.ts View on Github external
function assertValidYield(statement: AST.MustacheStatement): string {
  let { pairs } = statement.hash;

  if ((pairs.length === 1 && pairs[0].key !== 'to') || pairs.length > 1) {
    throw new SyntaxError(`yield only takes a single named argument: 'to'`, statement.loc);
  } else if (pairs.length === 1 && pairs[0].value.type !== 'StringLiteral') {
    throw new SyntaxError(`you can only yield to a literal value`, statement.loc);
  } else if (pairs.length === 0) {
    return 'default';
  } else {
    return (pairs[0].value as AST.StringLiteral).value;
  }
}
github glimmerjs / glimmer-vm / packages / @glimmer / compiler / lib / strict-template-compiler.ts View on Github external
function assertIsSimplePath(path: AST.PathExpression, loc: AST.SourceLocation, context: string) {
  if (!isSimplePath(path)) {
    throw new SyntaxError(
      `\`${path.original}\` is not a valid name for a ${context} on line ${loc.start.line}.`,
      path.loc
    );
  }
}
github glimmerjs / glimmer-vm / packages / @glimmer / compiler / lib / template-compiler.ts View on Github external
function assertValidHasBlockUsage(type: string, call: AST.Call): string {
  let { params, hash, loc } = call;

  if (hash && hash.pairs.length > 0) {
    throw new SyntaxError(`${type} does not take any named arguments`, call.loc);
  }

  if (params.length === 0) {
    return 'default';
  } else if (params.length === 1) {
    let param = params[0];
    if (param.type === 'StringLiteral') {
      return param.value;
    } else {
      throw new SyntaxError(
        `you can only yield to a literal value (on line ${loc.start.line})`,
        call.loc
      );
    }
  } else {
    throw new SyntaxError(
      `${type} only takes a single positional argument (on line ${loc.start.line})`,
      call.loc
    );
  }
}