bio-dts 0.6.1 → 0.7.0
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/README.md +3 -1
- package/lib/post-transform.js +46 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,9 @@ Utilities to generate sane and clean type definitions from JavaScript files.
|
|
|
6
6
|
|
|
7
7
|
## About
|
|
8
8
|
|
|
9
|
-
This module provides `pre` and `post` processing helpers to a type definition pipeline
|
|
9
|
+
This module provides `pre` and `post` processing helpers to a type definition pipeline.
|
|
10
|
+
|
|
11
|
+
You can use it [via API](#api) or through a simple [generator cli](#usage).
|
|
10
12
|
|
|
11
13
|
|
|
12
14
|
## Usage
|
package/lib/post-transform.js
CHANGED
|
@@ -113,6 +113,10 @@ export default function transform(src) {
|
|
|
113
113
|
? node.params
|
|
114
114
|
: node?.typeAnnotation?.typeAnnotation?.parameters;
|
|
115
115
|
|
|
116
|
+
const typeParameters = fnDeclaration
|
|
117
|
+
? node.typeParameters
|
|
118
|
+
: node?.typeAnnotation?.typeAnnotation?.typeParameters;
|
|
119
|
+
|
|
116
120
|
const returnType = fnDeclaration
|
|
117
121
|
? node.returnType
|
|
118
122
|
: node?.typeAnnotation?.typeAnnotation?.typeAnnotation;
|
|
@@ -207,7 +211,10 @@ export default function transform(src) {
|
|
|
207
211
|
returnType: returnType ? b.tsTypeAnnotation.from({
|
|
208
212
|
...returnType
|
|
209
213
|
}) : null,
|
|
210
|
-
comments: hostPath === nodePath ? variationComments : []
|
|
214
|
+
comments: hostPath === nodePath ? variationComments : [],
|
|
215
|
+
typeParameters: typeParameters ? b.tsTypeParameterDeclaration.from({
|
|
216
|
+
...typeParameters
|
|
217
|
+
}) : null
|
|
211
218
|
});
|
|
212
219
|
|
|
213
220
|
return (
|
|
@@ -227,6 +234,40 @@ export default function transform(src) {
|
|
|
227
234
|
}
|
|
228
235
|
|
|
229
236
|
|
|
237
|
+
/**
|
|
238
|
+
* Ensures we don't re-export external declarations
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
*
|
|
242
|
+
* ```javascript
|
|
243
|
+
* export type Woop = import('./Woop').default;
|
|
244
|
+
*
|
|
245
|
+
* // ===>
|
|
246
|
+
*
|
|
247
|
+
* type Woop = import('./Woop').default;
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* @param {import('./util.js').Path} nodePath
|
|
251
|
+
*
|
|
252
|
+
* @return {any[]} replacements
|
|
253
|
+
*/
|
|
254
|
+
function fixTypeExport(nodePath) {
|
|
255
|
+
|
|
256
|
+
const {
|
|
257
|
+
value: node
|
|
258
|
+
} = nodePath;
|
|
259
|
+
|
|
260
|
+
if (
|
|
261
|
+
node.type !== 'ExportNamedDeclaration' ||
|
|
262
|
+
node.declaration?.typeAnnotation?.type !== 'TSImportType'
|
|
263
|
+
) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
replace(nodePath, nodePath.get('declaration').value);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
|
|
230
271
|
function cleanComment(comment) {
|
|
231
272
|
|
|
232
273
|
const replacements = [];
|
|
@@ -308,6 +349,10 @@ export default function transform(src) {
|
|
|
308
349
|
return false;
|
|
309
350
|
}
|
|
310
351
|
|
|
352
|
+
if (fixTypeExport(path)) {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
|
|
311
356
|
cleanComments(path);
|
|
312
357
|
});
|
|
313
358
|
|