forked from dsherret/ts-morph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CaseBlock.ts
39 lines (34 loc) · 1.3 KB
/
CaseBlock.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
30
31
32
33
34
35
36
37
38
39
import * as errors from "../../../errors";
import { removeClausedNodeChildren, verifyAndGetIndex } from "../../../manipulation";
import { ts } from "../../../typescript";
import { CaseOrDefaultClause } from "../aliases";
import { TextInsertableNode } from "../base";
import { Node } from "../common";
export const CaseBlockBase = TextInsertableNode(Node);
export class CaseBlock extends CaseBlockBase<ts.CaseBlock> {
/**
* Gets the clauses.
*/
getClauses(): CaseOrDefaultClause[] {
const clauses: ts.NodeArray<ts.CaseOrDefaultClause> = this.compilerNode.clauses || [];
return clauses.map(s => this._getNodeFromCompilerNode(s));
}
/**
* Removes the clause at the specified index.
* @param index - Index.
*/
removeClause(index: number) {
index = verifyAndGetIndex(index, this.getClauses().length - 1);
return this.removeClauses([index, index]);
}
/**
* Removes the clauses in the specified range.
* @param indexRange - Index range.
*/
removeClauses(indexRange: [number, number]) {
const clauses = this.getClauses();
errors.throwIfRangeOutOfRange(indexRange, [0, clauses.length], nameof(indexRange));
removeClausedNodeChildren(clauses.slice(indexRange[0], indexRange[1] + 1));
return this;
}
}