forked from dsherret/ts-morph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BooleanLiteral.ts
29 lines (26 loc) · 974 Bytes
/
BooleanLiteral.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { SyntaxKind, ts } from "../../../typescript";
import { PrimaryExpression } from "../expression";
export const BooleanLiteralBase = PrimaryExpression;
export class BooleanLiteral extends BooleanLiteralBase<ts.BooleanLiteral> {
/**
* Gets the literal value.
*/
getLiteralValue(): boolean {
return this.getKind() === SyntaxKind.TrueKeyword;
}
/**
* Sets the literal value.
*
* Note: For the time being, this forgets the current node and returns the new node.
* @param value - Value to set.
*/
setLiteralValue(value: boolean) {
if (this.getLiteralValue() === value)
return this;
// todo: make this not forget the current node
const parent = this.getParentSyntaxList() || this.getParentOrThrow();
const index = this.getChildIndex();
this.replaceWithText(value ? "true" : "false");
return parent.getChildAtIndex(index) as BooleanLiteral;
}
}