parseProperty method

Property parseProperty()

Implementation

Property parseProperty() {
  int? start = token!.startOffset;
  Token nameTok = next();
  if (token!.type == Token.COLON) {
    int? line = token!.line;
    next(); // skip colon
    Node name = makePropertyName(nameTok);
    Expression value = parseAssignment();
    return Property(name, value)
      ..start = start
      ..end = endOffset
      ..line = line;
  }
  if (nameTok.type == Token.NAME &&
      (nameTok.text == 'get' || nameTok.text == 'set')) {
    Token kindTok = nameTok;
    String kind =
        kindTok.text == 'get' ? 'get' : 'set'; // internalize the string
    nameTok = next();
    Node name = makePropertyName(nameTok);
    int? lparen = token!.startOffset;
    List<Name> params = parseParameters();
    BlockStatement body = parseFunctionBody();
    Node value = FunctionNode(null, params, body)
      ..start = lparen
      ..end = endOffset
      ..line = name.line;
    return Property(name, value, kind)
      ..start = start
      ..end = endOffset
      ..line = kindTok.line;
  }
  throw fail(expected: 'property', tok: nameTok);
}