forked from dsherret/ts-morph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImportClause.ts
62 lines (55 loc) · 1.94 KB
/
ImportClause.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import * as errors from "../../../errors";
import { Node } from "../common";
import { ts } from "../../../typescript";
import { TypeGuards } from "../../../utils";
export const ImportClauseBase = Node;
export class ImportClause extends ImportClauseBase<ts.ImportClause> {
/**
* Gets the default import or throws if it doesn't exit.
*/
getDefaultImportOrThrow() {
return errors.throwIfNullOrUndefined(this.getDefaultImport(), "Expected to find a default import.");
}
/**
* Gets the default import or returns undefined if it doesn't exist.
*/
getDefaultImport() {
return this.getNodeProperty("name");
}
/**
* Gets the named bindings of the import clause or throws if it doesn't exist.
*/
getNamedBindingsOrThrow() {
return errors.throwIfNullOrUndefined(this.getNamedBindings(), "Expected to find an import declaration's named bindings.");
}
/**
* Gets the named bindings of the import clause or returns undefined if it doesn't exist.
*/
getNamedBindings() {
return this.getNodeProperty("namedBindings");
}
/**
* Gets the namespace import if it exists or throws.
*/
getNamespaceImportOrThrow() {
return errors.throwIfNullOrUndefined(this.getNamespaceImport(), "Expected to find a namespace import.");
}
/**
* Gets the namespace import identifier, if it exists.
*/
getNamespaceImport() {
const namedBindings = this.getNamedBindings();
if (namedBindings == null || !TypeGuards.isNamespaceImport(namedBindings))
return undefined;
return namedBindings.getNameNode();
}
/**
* Gets the namespace import identifier, if it exists.
*/
getNamedImports() {
const namedBindings = this.getNamedBindings();
if (namedBindings == null || !TypeGuards.isNamedImports(namedBindings))
return [];
return namedBindings.getElements();
}
}