@eliasku/ts-transformers 0.0.4 → 0.0.5

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.
Files changed (3) hide show
  1. package/README.md +31 -13
  2. package/package.json +1 -1
  3. package/src/index.ts +1 -1
package/README.md CHANGED
@@ -1,3 +1,6 @@
1
+ [![NPM Version](https://img.shields.io/npm/v/%40eliasku%2Fts-transformers)](https://www.npmjs.com/package/@eliasku/ts-transformers)
2
+ ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/eliasku/ts-transformers/ci.yml)
3
+
1
4
  # @eliasku/ts-transformers
2
5
 
3
6
  TypeScript transformer for aggressive code minification through type-aware property renaming and const enum inlining.
@@ -25,6 +28,7 @@ Based on type analysis, properties are categorized as:
25
28
  - **Private**: Everything else → prefixed with `$_` (mangled by minifier)
26
29
 
27
30
  **Example:**
31
+
28
32
  ```typescript
29
33
  // Before
30
34
  class MyClass {
@@ -52,7 +56,10 @@ Replaces const enum accesses with literal values and removes declarations.
52
56
 
53
57
  ```typescript
54
58
  // Before
55
- const enum Status { Active = 1, Inactive = 0 }
59
+ const enum Status {
60
+ Active = 1,
61
+ Inactive = 0,
62
+ }
56
63
  const status = Status.Active;
57
64
 
58
65
  // After transformer + minifier
@@ -94,7 +101,7 @@ await build({
94
101
  entryPoints: ["./dist/bundle.js"],
95
102
  outfile: "./dist/bundle.min.js",
96
103
  minify: true,
97
- mangleProps: /^\$_/, // Match your privatePrefix
104
+ mangleProps: /^\$_/, // Match your privatePrefix
98
105
  mangleQuoted: false,
99
106
  keepNames: false,
100
107
  });
@@ -107,15 +114,15 @@ await build({
107
114
  Entry points defining your public API surface.
108
115
 
109
116
  ```typescript
110
- entrySourceFiles: ["./src/index.ts"]
117
+ entrySourceFiles: ["./src/index.ts"];
111
118
  ```
112
119
 
113
- ### privatePrefix (optional, default: "$_")
120
+ ### privatePrefix (optional, default: "$\_")
114
121
 
115
122
  Prefix for private properties that will be mangled by esbuild.
116
123
 
117
124
  ```typescript
118
- privatePrefix: "$_" // myFunction → $_myFunction
125
+ privatePrefix: "$_"; // myFunction → $_myFunction
119
126
  ```
120
127
 
121
128
  ### publicJSDocTag (optional, default: "public")
@@ -123,13 +130,13 @@ privatePrefix: "$_" // myFunction → $_myFunction
123
130
  JSDoc tag marking types/properties as public. Set to empty string to disable.
124
131
 
125
132
  ```typescript
126
- publicJSDocTag: "public"
133
+ publicJSDocTag: "public";
127
134
 
128
135
  class MyClass {
129
136
  /** @public */
130
- apiMethod() {} // Public, no prefix
137
+ apiMethod() {} // Public, no prefix
131
138
 
132
- internalHelper() {} // Private, gets $_ prefix
139
+ internalHelper() {} // Private, gets $_ prefix
133
140
  }
134
141
  ```
135
142
 
@@ -138,12 +145,12 @@ class MyClass {
138
145
  Skip renaming decorated fields.
139
146
 
140
147
  ```typescript
141
- ignoreDecorated: true
148
+ ignoreDecorated: true;
142
149
 
143
150
  @Component({ selector: "app-root" })
144
151
  class AppComponent {
145
- @Input() data: any; // Not renamed
146
- private internal = 1; // Renamed to $_internal
152
+ @Input() data: any; // Not renamed
153
+ private internal = 1; // Renamed to $_internal
147
154
  }
148
155
  ```
149
156
 
@@ -157,7 +164,7 @@ Inline const enum values and remove declarations.
157
164
  // src/index.ts (before)
158
165
  class API {
159
166
  private baseUrl = "https://api.example.com";
160
-
167
+
161
168
  /** @public */
162
169
  async get(path: string): Promise<Response> {
163
170
  const url = `${this.baseUrl}${path}`;
@@ -187,5 +194,16 @@ class API {
187
194
  }
188
195
 
189
196
  // After esbuild minifier
190
- class A{a="https://api.example.com";async get(t){const n=`${this.a}${t}`;return await fetch(n)}b(t){return t}}const s=new A;export{s};
197
+ class A {
198
+ a = "https://api.example.com";
199
+ async get(t) {
200
+ const n = `${this.a}${t}`;
201
+ return await fetch(n);
202
+ }
203
+ b(t) {
204
+ return t;
205
+ }
206
+ }
207
+ const s = new A();
208
+ export { s };
191
209
  ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@eliasku/ts-transformers",
3
3
  "description": "TypeScript transformer for code optimization",
4
- "version": "0.0.4",
4
+ "version": "0.0.5",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "scripts": {
package/src/index.ts CHANGED
@@ -53,7 +53,7 @@ function createTransformerFactory(
53
53
 
54
54
  if (ts.isImportSpecifier(node)) {
55
55
  const removed = tryRemoveConstEnumImport(node);
56
- if (removed === undefined) {
56
+ if (removed === undefined || node.isTypeOnly) {
57
57
  return undefined;
58
58
  }
59
59
  }