forked from dsherret/ts-morph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBindingElement.ts
39 lines (35 loc) · 1.47 KB
/
BindingElement.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 { ts } from "../../../typescript";
import * as errors from "../../../errors";
import { BindingNamedNode, InitializerExpressionableNode } from "../base";
import { Node } from "../common";
export const BindingElementBase = InitializerExpressionableNode(BindingNamedNode(Node));
export class BindingElement extends BindingElementBase<ts.BindingElement> {
/**
* Gets the binding element's dot dot dot token (...) if it exists or throws if not.
*/
getDotDotDotTokenOrThrow() {
return errors.throwIfNullOrUndefined(this.getDotDotDotToken(), "Expected to find a dot dot dot token (...).");
}
/**
* Gets the binding element's dot dot dot token (...) if it exists or returns undefined.
*/
getDotDotDotToken() {
return this._getNodeFromCompilerNodeIfExists(this.compilerNode.dotDotDotToken);
}
/**
* Gets binding element's property name node or throws if not found.
*
* For example in `const { a: b } = { a: 5 }`, `a` would be the property name.
*/
getPropertyNameNodeOrThrow() {
return errors.throwIfNullOrUndefined(this.getPropertyNameNode(), "Expected to find a property name node.");
}
/**
* Gets binding element's property name node or returns undefined if not found.
*
* For example in `const { a: b } = { a: 5 }`, `a` would be the property name.
*/
getPropertyNameNode() {
return this._getNodeFromCompilerNodeIfExists(this.compilerNode.propertyName);
}
}