Skip to content

Commit a9021ae

Browse files
committed
Convert AstKind to be a string enum to facilitate debugging
Fix some more places where AstBaseNode was used instead of AstNode
1 parent 4ed8630 commit a9021ae

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

libraries/rushell/src/AstNode.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
import { Token } from './Tokenizer';
55
import { TextRange } from './TextRange';
66

7-
export enum AstKind {
8-
None,
9-
Script,
10-
AndIf,
11-
Command,
12-
CompoundWord,
13-
VariableExpansion,
14-
Text
7+
export const enum AstKind {
8+
None = 'None',
9+
Script = 'Script',
10+
AndIf = 'AndIf',
11+
Command = 'Command',
12+
CompoundWord = 'CompoundWord',
13+
VariableExpansion = 'VariableExpansion',
14+
Text = 'Text'
1515
}
1616

1717
/**
@@ -27,7 +27,7 @@ export abstract class AstBaseNode {
2727
*/
2828
public getDump(indent: string = ''): string {
2929
const nestedIndent: string = indent + ' ';
30-
let result: string = indent + '- ' + AstKind[this.kind] + ':\n';
30+
let result: string = indent + `- ${this.kind}:\n`;
3131

3232
const dumpText: string | undefined = this.getDumpText();
3333
if (dumpText) {
@@ -39,16 +39,16 @@ export abstract class AstBaseNode {
3939
result += nestedIndent + 'Range=' + JSON.stringify(fullRange.toString()) + '\n';
4040
}
4141

42-
const childNodes: AstBaseNode[] = this.getChildNodes();
42+
const childNodes: AstNode[] = this.getChildNodes();
4343
for (const child of childNodes) {
4444
result += child.getDump(nestedIndent);
4545
}
4646

4747
return result;
4848
}
4949

50-
public getChildNodes(): AstBaseNode[] {
51-
const nodes: AstBaseNode[] = [];
50+
public getChildNodes(): AstNode[] {
51+
const nodes: AstNode[] = [];
5252
this.collectChildNodesInto(nodes);
5353
return nodes;
5454
}
@@ -67,7 +67,7 @@ export abstract class AstBaseNode {
6767
return encompassingRange;
6868
}
6969

70-
protected abstract collectChildNodesInto(nodes: AstBaseNode[]): void;
70+
protected abstract collectChildNodesInto(nodes: AstNode[]): void;
7171

7272
protected getDumpText(): string | undefined {
7373
return undefined;
@@ -83,7 +83,7 @@ export class AstScript extends AstBaseNode {
8383
public body: AstNode | undefined;
8484

8585
/** @override */
86-
protected collectChildNodesInto(nodes: AstBaseNode[]): void {
86+
protected collectChildNodesInto(nodes: AstNode[]): void {
8787
if (this.body) {
8888
nodes.push(this.body);
8989
}
@@ -107,7 +107,7 @@ export class AstAndIf extends AstBaseNode {
107107
public secondCommand: AstCommand | undefined;
108108

109109
/** @override */
110-
protected collectChildNodesInto(nodes: AstBaseNode[]): void {
110+
protected collectChildNodesInto(nodes: AstNode[]): void {
111111
if (this.firstCommand) {
112112
nodes.push(this.firstCommand);
113113
}
@@ -127,7 +127,7 @@ export class AstCommand extends AstBaseNode {
127127
public arguments: AstCompoundWord[] = [];
128128

129129
/** @override */
130-
protected collectChildNodesInto(nodes: AstBaseNode[]): void {
130+
protected collectChildNodesInto(nodes: AstNode[]): void {
131131
if (this.commandPath) {
132132
nodes.push(this.commandPath);
133133
}
@@ -141,10 +141,10 @@ export class AstCommand extends AstBaseNode {
141141
export class AstCompoundWord extends AstBaseNode {
142142
public readonly kind: AstKind.CompoundWord = AstKind.CompoundWord;
143143

144-
public readonly parts: AstBaseNode[] = [];
144+
public readonly parts: AstNode[] = [];
145145

146146
/** @override */
147-
protected collectChildNodesInto(nodes: AstBaseNode[]): void {
147+
protected collectChildNodesInto(nodes: AstNode[]): void {
148148
nodes.push(...this.parts);
149149
}
150150
}
@@ -156,7 +156,7 @@ export class AstVariableExpansion extends AstBaseNode {
156156
public readonly kind: AstKind.VariableExpansion = AstKind.VariableExpansion;
157157

158158
/** @override */
159-
protected collectChildNodesInto(nodes: AstBaseNode[]): void {
159+
protected collectChildNodesInto(nodes: AstNode[]): void {
160160
// no children
161161
}
162162
}
@@ -170,7 +170,7 @@ export class AstText extends AstBaseNode {
170170
public token: Token | undefined;
171171

172172
/** @override */
173-
protected collectChildNodesInto(nodes: AstBaseNode[]): void {
173+
protected collectChildNodesInto(nodes: AstNode[]): void {
174174
// no children
175175
}
176176

0 commit comments

Comments
 (0)