parseProperty method
Implementation
Property parseProperty() {
int start = token?.startOffset?? 0;
Token? nameTok = next();
if (token?.type == Token.COLON) {
int line = token?.line?? 0;
next(); // skip colon
Node name = makePropertyName(nameTok);
Expression value = parseAssignment();
return new 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??0;
List<Name> params = parseParameters();
BlockStatement body = parseFunctionBody();
Node value = new FunctionNode(null, params, body)
..start = lparen
..end = endOffset
..line = name.line
..endLine = body.endLine;
return new Property(name, value, kind)
..start = start
..end = endOffset
..line = kindTok?.line??0;
} else if( nameTok?.type == Token.NAME && token?.type==Token.LPAREN ) {
int line = nameTok?.line??0;
Node name = makePropertyName(nameTok);
FunctionNode func = parseFunction(inObject: true, nameTok: nameTok);
final value = FunctionExpression(func);
return new Property(name, value)
..start = start
..end = endOffset
..line = line;
} else if( nameTok?.type==Token.DOT && token?.type==Token.DOT ) {
nameTok = next();
if( token?.type==Token.DOT ) {
consume(Token.DOT);
return SpreadElement(makeName(token));
}
}
throw fail(expected: 'property', tok: nameTok);
}