1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.elideImportOrExportClause = void 0;
|
4 | function elideImportOrExportClause(context, node) {
|
5 | const { tsInstance, transformationContext, factory } = context;
|
6 | const resolver = transformationContext.getEmitResolver();
|
7 |
|
8 | if (!resolver)
|
9 | return tsInstance.isImportDeclaration(node) ? node.importClause : node.exportClause;
|
10 | const { visitNode, isNamedImportBindings, isImportSpecifier, SyntaxKind, visitNodes, isNamedExportBindings, isExportSpecifier, } = tsInstance;
|
11 | if (tsInstance.isImportDeclaration(node)) {
|
12 | if (node.importClause.isTypeOnly)
|
13 | return undefined;
|
14 | return visitNode(node.importClause, visitImportClause);
|
15 | }
|
16 | else {
|
17 | if (node.isTypeOnly)
|
18 | return undefined;
|
19 | return visitNode(node.exportClause, visitNamedExports, isNamedExportBindings);
|
20 | }
|
21 | |
22 |
|
23 |
|
24 |
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 | function visitImportClause(node) {
|
31 |
|
32 | const name = resolver.isReferencedAliasDeclaration(node) ? node.name : undefined;
|
33 | const namedBindings = visitNode(node.namedBindings, visitNamedImportBindings, isNamedImportBindings);
|
34 | return name || namedBindings
|
35 | ? factory.updateImportClause(node, false, name, namedBindings)
|
36 | : undefined;
|
37 | }
|
38 | |
39 |
|
40 |
|
41 |
|
42 |
|
43 | function visitNamedImportBindings(node) {
|
44 | if (node.kind === SyntaxKind.NamespaceImport) {
|
45 |
|
46 | return resolver.isReferencedAliasDeclaration(node) ? node : undefined;
|
47 | }
|
48 | else {
|
49 |
|
50 | const elements = visitNodes(node.elements, visitImportSpecifier, isImportSpecifier);
|
51 | return tsInstance.some(elements) ? factory.updateNamedImports(node, elements) : undefined;
|
52 | }
|
53 | }
|
54 | |
55 |
|
56 |
|
57 |
|
58 |
|
59 | function visitImportSpecifier(node) {
|
60 |
|
61 | return resolver.isReferencedAliasDeclaration(node) ? node : undefined;
|
62 | }
|
63 | |
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | function visitNamedExports(node) {
|
70 |
|
71 | const elements = visitNodes(node.elements, visitExportSpecifier, isExportSpecifier);
|
72 | return tsInstance.some(elements) ? factory.updateNamedExports(node, elements) : undefined;
|
73 | }
|
74 | |
75 |
|
76 |
|
77 |
|
78 |
|
79 | function visitExportSpecifier(node) {
|
80 |
|
81 | return resolver.isValueAliasDeclaration(node) ? node : undefined;
|
82 | }
|
83 | }
|
84 | exports.elideImportOrExportClause = elideImportOrExportClause;
|
85 |
|
86 |
|
\ | No newline at end of file |