bio-dts 0.12.0 → 0.13.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 CHANGED
@@ -34,7 +34,7 @@ Checkout the [test fixtures](./test/fixtures) for full coverage.
34
34
 
35
35
  ## API
36
36
 
37
- ```javascript
37
+ ```js
38
38
  import {
39
39
  preTransform,
40
40
  postTransform,
@@ -64,14 +64,16 @@ export default function generateTypes(fileNames, options, ts) {
64
64
  host.writeFile = (fileName, text, ...args) => {
65
65
  isVerbose(options, fileName) && console.debug('[generate-types] [post]', fileName, text);
66
66
 
67
- try {
68
- text = postTransform(text);
69
- } catch (err) {
70
- console.error(`[generate-types] [post] failed to parse ${fileName} with contents ${text}`, err);
71
- throw err;
72
- }
67
+ if (fileName.toLowerCase().endsWith('.d.ts')) {
68
+ try {
69
+ text = postTransform(text);
70
+ } catch (err) {
71
+ console.error(`[generate-types] [post] failed to parse ${fileName} with contents ${text}`, err);
72
+ throw err;
73
+ }
73
74
 
74
- isVerbose(options, fileName) && console.debug('[generate-types] [post] [generated]', fileName, text);
75
+ isVerbose(options, fileName) && console.debug('[generate-types] [post] [generated]', fileName, text);
76
+ }
75
77
 
76
78
  // @ts-expect-error
77
79
  host._writeFile(fileName, text, ...args);
@@ -127,7 +127,7 @@ export default function transform(src) {
127
127
 
128
128
  const actualName = param.argument?.name || param.name;
129
129
 
130
- if (actualName !== expectedName) {
130
+ if (isNamedParam(param) && actualName !== expectedName) {
131
131
  throw error(node, `documented parameter <${ expectedName }> differs from actual parameter <${ actualName }>`);
132
132
  }
133
133
 
@@ -210,7 +210,8 @@ export default function transform(src) {
210
210
  variations.forEach((variation) => {
211
211
  const builder = {
212
212
  'RestElement': b.restElement,
213
- 'Identifier': b.identifier
213
+ 'Identifier': b.identifier,
214
+ 'ObjectPattern': b.objectPattern
214
215
  }[param.type];
215
216
 
216
217
  variation.push(builder.from(param));
@@ -682,6 +683,10 @@ function getHostPath(nodePath) {
682
683
  : nodePath;
683
684
  }
684
685
 
686
+ function isNamedParam(param) {
687
+ return param.type === 'Identifier' || param.type == 'RestElement';
688
+ }
689
+
685
690
  /**
686
691
  * @param { { loc: { start: { line: number, column: number } } } } node
687
692
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bio-dts",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Generate sane and clean types from JavaScript sources",
5
5
  "type": "module",
6
6
  "bin": "bin/cmd.js",
@@ -10,11 +10,12 @@
10
10
  "./package.json": "./package.json"
11
11
  },
12
12
  "scripts": {
13
- "all": "run-s lint check-types test test:dts",
13
+ "all": "run-s lint check-types test test:dts:*",
14
14
  "lint": "eslint .",
15
15
  "check-types": "tsc --noEmit",
16
16
  "test": "mocha test",
17
- "test:dts": "node bin/cmd.js --outDir test/fixtures/snapshots -r test/fixtures"
17
+ "test:dts:default": "node bin/cmd.js --outDir test/fixtures/snapshots/default -r test/fixtures",
18
+ "test:dts:declaration-map": "node bin/cmd.js --declarationMap --outDir test/fixtures/snapshots/declaration-map -r test/fixtures"
18
19
  },
19
20
  "repository": {
20
21
  "type": "git",