mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-20 02:11:31 +00:00
Implement object literal parsing; Instantiate classes from object literals
Essentially, if the contextual type is a class with a constructor that takes zero arguments or doesn't have a constructor at all, an object literal can be used to initialize a new instance of that class with preset values.
This commit is contained in:
22
src/ast.ts
22
src/ast.ts
@ -432,6 +432,18 @@ export abstract class Node {
|
||||
return expr;
|
||||
}
|
||||
|
||||
static createObjectLiteralExpression(
|
||||
names: IdentifierExpression[],
|
||||
values: Expression[],
|
||||
range: Range
|
||||
): ObjectLiteralExpression {
|
||||
var expr = new ObjectLiteralExpression();
|
||||
expr.range = range;
|
||||
expr.names = names;
|
||||
expr.values = values;
|
||||
return expr;
|
||||
}
|
||||
|
||||
static createParenthesizedExpression(
|
||||
expression: Expression,
|
||||
range: Range
|
||||
@ -1363,6 +1375,16 @@ export class NullExpression extends IdentifierExpression {
|
||||
text = "null";
|
||||
}
|
||||
|
||||
/** Represents an object literal expression. */
|
||||
export class ObjectLiteralExpression extends LiteralExpression {
|
||||
literalKind = LiteralKind.OBJECT;
|
||||
|
||||
/** Field names. */
|
||||
names: IdentifierExpression[];
|
||||
/** Field values. */
|
||||
values: Expression[];
|
||||
}
|
||||
|
||||
/** Represents a parenthesized expression. */
|
||||
export class ParenthesizedExpression extends Expression {
|
||||
kind = NodeKind.PARENTHESIZED;
|
||||
|
Reference in New Issue
Block a user