forked from dsherret/ts-morph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TryStatement.ts
47 lines (40 loc) · 1.5 KB
/
TryStatement.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
40
41
42
43
44
45
46
47
import * as errors from "../../../errors";
import { ts } from "../../../typescript";
import { Block } from "./Block";
import { CatchClause } from "./CatchClause";
import { Statement } from "./Statement";
export const TryStatementBase = Statement;
export class TryStatement extends TryStatementBase<ts.TryStatement> {
/**
* Gets this try statement's try block.
*/
getTryBlock(): Block {
return this._getNodeFromCompilerNode(this.compilerNode.tryBlock);
}
/**
* Gets this try statement's catch clause or undefined if none exists.
*/
getCatchClause(): CatchClause | undefined {
return this._getNodeFromCompilerNodeIfExists(this.compilerNode.catchClause);
}
/**
* Gets this try statement's catch clause or throws if none exists.
*/
getCatchClauseOrThrow() {
return errors.throwIfNullOrUndefined(this.getCatchClause(), "Expected to find a catch clause.");
}
/**
* Gets this try statement's finally block or undefined if none exists.
*/
getFinallyBlock(): Block | undefined {
if (this.compilerNode.finallyBlock == null || this.compilerNode.finallyBlock.getFullWidth() === 0)
return undefined;
return this._getNodeFromCompilerNode(this.compilerNode.finallyBlock);
}
/**
* Gets this try statement's finally block or throws if none exists.
*/
getFinallyBlockOrThrow() {
return errors.throwIfNullOrUndefined(this.getFinallyBlock(), "Expected to find a finally block.");
}
}