Skip to content

Switch to initializer property #1220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ export abstract class Node {

static createEnumValueDeclaration(
name: IdentifierExpression,
value: Expression | null,
initializer: Expression | null,
flags: CommonFlags,
range: Range
): EnumValueDeclaration {
Expand All @@ -694,7 +694,7 @@ export abstract class Node {
node.range = range;
node.flags = flags;
node.name = name;
node.value = value;
node.initializer = initializer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

return node;
}

Expand Down Expand Up @@ -1848,8 +1848,6 @@ export class EnumDeclaration extends DeclarationStatement {

/** Represents a value of an `enum` declaration. */
export class EnumValueDeclaration extends VariableLikeDeclarationStatement {
/** Value expression. */
value: Expression | null;
}

/** Represents an `export import` statement of an interface. */
Expand Down
4 changes: 2 additions & 2 deletions src/extra/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1000,9 +1000,9 @@ export class ASTBuilder {

visitEnumValueDeclaration(node: EnumValueDeclaration): void {
this.visitIdentifierExpression(node.name);
if (node.value) {
if (node.initializer) {
this.sb.push(" = ");
this.visitNode(node.value);
this.visitNode(node.initializer);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2789,7 +2789,7 @@ export class EnumValue extends VariableLikeElement {

/** Gets the associated value node. */
get valueNode(): Expression | null {
return (<EnumValueDeclaration>this.declaration).value;
return (<EnumValueDeclaration>this.declaration).initializer;
}

/* @override */
Expand Down