bio-dts 0.9.0 → 0.11.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.
@@ -531,12 +531,24 @@ declare function p${
531
531
  // remove entirely, if empty
532
532
  if (!newDoc.replace(/[/*\s]/g, '')) {
533
533
  return null;
534
- } else {
535
- return b.commentBlock.from({
536
- leading: true,
537
- value: newDoc
538
- });
539
534
  }
535
+
536
+ // leave comment unchanged
537
+ if (newDoc === comment.value) {
538
+ return comment;
539
+ }
540
+
541
+ const commentBuilder = {
542
+ 'CommentLine': b.commentLine,
543
+ 'CommentBlock': b.commentBlock
544
+ };
545
+
546
+ return commentBuilder[comment.type].from({
547
+ leading: comment.leading,
548
+ trailing: comment.trailing,
549
+ loc: comment.loc,
550
+ value: newDoc
551
+ });
540
552
  }
541
553
 
542
554
  /**
@@ -551,29 +563,31 @@ declare function p${
551
563
  const comment = comments.get(key);
552
564
 
553
565
  const newComment = cleanComment(comment.value);
554
- if (newComment) {
566
+
567
+ if (newComment && newComment !== comment.value) {
555
568
  replace(comment, newComment);
556
- } else {
569
+ }
570
+
571
+ if (!newComment) {
557
572
  replace(comment);
558
573
  }
559
574
  }
560
575
  }
561
576
 
562
- traverse(body, function(path) {
563
-
564
- const {
565
- value
566
- } = path;
577
+ function transformPath(path) {
567
578
 
568
579
  // filter private members
569
- if (!isPublic(value)) {
580
+ if (!isPublic(path.value)) {
570
581
  return replace(path);
571
582
  }
572
583
 
584
+ // generate overloads based on @overlord annotation
573
585
  if (generateOverloads(path)) {
574
586
  return false;
575
587
  }
576
588
 
589
+ // fix optional before required args
590
+ // (just fine in JavaScript)
577
591
  if (fixOptionalArgsMethods(path)) {
578
592
  return false;
579
593
  }
@@ -582,15 +596,27 @@ declare function p${
582
596
  cleanComments(path);
583
597
 
584
598
  fixTypeExport(path);
585
- });
599
+ }
600
+
601
+ const nodes = [ body ];
586
602
 
587
- for (const [ path, args ] of replacements) {
588
- try {
589
- path.replace(...args);
590
- } catch (err) {
591
- console.error('Failed to replace path', path, ...args, err);
603
+ while (nodes.length) {
604
+ const node = nodes.shift();
592
605
 
593
- throw error(path.value, 'failed to replace path: ' + err.message);
606
+ traverse(node, transformPath);
607
+
608
+ while (replacements.length) {
609
+ const [ path, args ] = replacements.shift();
610
+
611
+ try {
612
+ const replacedPaths = path.replace(...args);
613
+
614
+ nodes.push(...replacedPaths);
615
+ } catch (err) {
616
+ console.error('Failed to replace path', path, ...args, err);
617
+
618
+ throw error(path.value, 'failed to replace path: ' + err.message);
619
+ }
594
620
  }
595
621
  }
596
622
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bio-dts",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "description": "Generate sane and clean types from JavaScript sources",
5
5
  "type": "module",
6
6
  "bin": "bin/cmd.js",