@eliasku/ts-transformers 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.ts +34 -12
- package/src/types.ts +5 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -51,17 +51,27 @@ function createTransformerFactory(
|
|
|
51
51
|
if (inlined) return inlined;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
|
|
54
|
+
// don't remove any imports
|
|
55
|
+
if (fullOptions.keepConstEnumEmptyDeclaration !== true) {
|
|
56
|
+
if (ts.isImportSpecifier(node)) {
|
|
57
|
+
const removed = tryRemoveConstEnumImport(node);
|
|
58
|
+
if (removed === undefined || node.isTypeOnly) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
58
61
|
}
|
|
59
|
-
}
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
if (ts.isExportSpecifier(node)) {
|
|
64
|
+
const removed = tryRemoveConstEnumExport(node);
|
|
65
|
+
if (removed === undefined || node.isTypeOnly) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (ts.isImportClause(node)) {
|
|
71
|
+
const removed = tryRemoveConstEnumImportClause(node);
|
|
72
|
+
if (removed === undefined) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
65
75
|
}
|
|
66
76
|
}
|
|
67
77
|
}
|
|
@@ -672,6 +682,14 @@ function createTransformerFactory(
|
|
|
672
682
|
return node;
|
|
673
683
|
}
|
|
674
684
|
|
|
685
|
+
function tryRemoveConstEnumExport(node: ts.ExportSpecifier): ts.ExportSpecifier | undefined {
|
|
686
|
+
const importedType = typeChecker.getTypeAtLocation(node);
|
|
687
|
+
if (isConstEnumType(importedType)) {
|
|
688
|
+
return undefined;
|
|
689
|
+
}
|
|
690
|
+
return node;
|
|
691
|
+
}
|
|
692
|
+
|
|
675
693
|
function tryRemoveConstEnumImportClause(node: ts.ImportClause): ts.ImportClause | undefined {
|
|
676
694
|
if (!node.name) return node;
|
|
677
695
|
const type = typeChecker.getTypeAtLocation(node.name);
|
|
@@ -694,16 +712,20 @@ function createTransformerFactory(
|
|
|
694
712
|
node.members,
|
|
695
713
|
);
|
|
696
714
|
}
|
|
715
|
+
|
|
716
|
+
if (fullOptions.keepConstEnumEmptyDeclaration === true) {
|
|
717
|
+
return ts.factory.updateEnumDeclaration(node, node.modifiers, node.name, []);
|
|
718
|
+
}
|
|
697
719
|
return undefined;
|
|
698
720
|
}
|
|
699
721
|
|
|
700
722
|
function wrapTransformNode(node: ts.Node): ts.Node | undefined {
|
|
701
723
|
if (ts.isEnumDeclaration(node)) {
|
|
702
724
|
const result = handleEnumDeclaration(node);
|
|
703
|
-
if (result === undefined) {
|
|
704
|
-
return undefined;
|
|
705
|
-
}
|
|
706
725
|
if (result !== node) {
|
|
726
|
+
if (result) {
|
|
727
|
+
return transformNode(result);
|
|
728
|
+
}
|
|
707
729
|
return result;
|
|
708
730
|
}
|
|
709
731
|
}
|
package/src/types.ts
CHANGED
|
@@ -32,6 +32,11 @@ export interface OptimizerOptions {
|
|
|
32
32
|
* Whether to inline const enum values.
|
|
33
33
|
*/
|
|
34
34
|
inlineConstEnums?: boolean;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Keep empty const enum declarations, keep imports / exports
|
|
38
|
+
*/
|
|
39
|
+
keepConstEnumEmptyDeclaration?: boolean;
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
export const enum VisibilityType {
|