bio-dts 0.5.0 → 0.6.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.
@@ -96,10 +96,27 @@ export default function transform(src) {
96
96
  value: node
97
97
  } = nodePath;
98
98
 
99
- if (node.type !== 'TSDeclareMethod' && node.type !== 'TSDeclareFunction') {
99
+ const fnDeclaration = (
100
+ node.type === 'TSDeclareMethod' ||
101
+ node.type === 'TSDeclareFunction'
102
+ );
103
+
104
+ const fnDefinition = (
105
+ node?.typeAnnotation?.typeAnnotation?.type === 'TSFunctionType'
106
+ );
107
+
108
+ if (!fnDeclaration && !fnDefinition) {
100
109
  return;
101
110
  }
102
111
 
112
+ const params = fnDeclaration
113
+ ? node.params
114
+ : node?.typeAnnotation?.typeAnnotation?.parameters;
115
+
116
+ const returnType = fnDeclaration
117
+ ? node.returnType
118
+ : node?.typeAnnotation?.typeAnnotation?.typeAnnotation;
119
+
103
120
  const hostPath = (
104
121
  [ 'ExportDefaultDeclaration', 'ExportNamedDeclaration' ].includes(nodePath.parentPath.value.type)
105
122
  ? nodePath.parentPath
@@ -108,7 +125,7 @@ export default function transform(src) {
108
125
 
109
126
  const {
110
127
  variations
111
- } = node.params.slice().reverse().reduce((res, param) => {
128
+ } = params.slice().reverse().reduce((res, param) => {
112
129
 
113
130
  let {
114
131
  required,
@@ -170,6 +187,7 @@ export default function transform(src) {
170
187
  const replacements = variations.slice().reverse().map(variation => {
171
188
 
172
189
  const builder = {
190
+ 'ClassProperty': b.tsDeclareMethod,
173
191
  'TSDeclareFunction': b.tsDeclareFunction,
174
192
  'TSDeclareMethod': b.tsDeclareMethod
175
193
  }[node.type];
@@ -182,8 +200,13 @@ export default function transform(src) {
182
200
  const variationComments = commentPath.value ? [ keepCommentParams(commentPath, variation) ] : [ ];
183
201
 
184
202
  const newNode = builder.from({
185
- ...node,
203
+ key: node.key,
186
204
  params: variation.slice().reverse(),
205
+ id: node.id,
206
+ declare: node.declare || false,
207
+ returnType: b.tsTypeAnnotation.from({
208
+ ...returnType
209
+ }),
187
210
  comments: hostPath === nodePath ? variationComments : []
188
211
  });
189
212
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bio-dts",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Generate sane and clean types from JavaScript sources",
5
5
  "type": "module",
6
6
  "main": "index.js",