@runtime-type-inspector/transpiler 4.0.1 → 4.0.3

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/index.cjs +21 -9
  2. package/index.mjs +21 -9
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -1555,7 +1555,7 @@
1555
1555
  out += this.toSource(node);
1556
1556
  if (needCurly) {
1557
1557
  out += '\n';
1558
- out += spaces;
1558
+ out += spaces.slice(0, -2);
1559
1559
  out += '}';
1560
1560
  }
1561
1561
  return out;
@@ -1986,7 +1986,10 @@
1986
1986
  directives = node.directives;
1987
1987
  var spaces = this.spaces;
1988
1988
  var out = '';
1989
- out += ' {';
1989
+ if (this.parentType !== 'Program') {
1990
+ out += ' ';
1991
+ }
1992
+ out += '{';
1990
1993
  this.numSpaces++;
1991
1994
  // Handle Directive/DirectiveLiteral like 'use strict';
1992
1995
  if (directives && directives.length) {
@@ -1995,8 +1998,7 @@
1995
1998
  }
1996
1999
  out += this.generateTypeChecks(node);
1997
2000
  if (body.length) {
1998
- if (out.length === 2) {
1999
- // 2 is ' {'
2001
+ if (out[out.length - 1] === '{') {
2000
2002
  out += '\n';
2001
2003
  }
2002
2004
  // out += '/*'+out.length+'*/';
@@ -2066,16 +2068,26 @@
2066
2068
  var alternate = node.alternate,
2067
2069
  consequent = node.consequent,
2068
2070
  test = node.test;
2069
- var spaces = this.spaces;
2070
2071
  var out = '';
2071
- //if (this.parentType !== "IfStatement")
2072
- //{
2073
- out += spaces;
2074
- //}
2072
+ if (this.forceCurly) {
2073
+ out += this.spaces;
2074
+ } else {
2075
+ if (this.parentType === 'BlockStatement') {
2076
+ out += this.spaces;
2077
+ } else if (this.parentType === 'IfStatement') {
2078
+ out += ' ';
2079
+ }
2080
+ }
2075
2081
  out += "if (".concat(this.toSource(test), ")");
2076
2082
  out += this.toSourceCurly(consequent);
2077
2083
  if (alternate) {
2084
+ if (this.forceCurly) {
2085
+ this.numSpaces++;
2086
+ }
2078
2087
  out += " else".concat(this.toSourceCurly(alternate));
2088
+ if (this.forceCurly) {
2089
+ this.numSpaces--;
2090
+ }
2079
2091
  }
2080
2092
  return out;
2081
2093
  }
package/index.mjs CHANGED
@@ -1296,7 +1296,7 @@ class Stringifier {
1296
1296
  out += this.toSource(node);
1297
1297
  if (needCurly) {
1298
1298
  out += '\n';
1299
- out += spaces;
1299
+ out += spaces.slice(0, -2);
1300
1300
  out += '}';
1301
1301
  }
1302
1302
  return out;
@@ -1702,7 +1702,10 @@ class Stringifier {
1702
1702
  } = node;
1703
1703
  const spaces = this.spaces;
1704
1704
  let out = '';
1705
- out += ' {';
1705
+ if (this.parentType !== 'Program') {
1706
+ out += ' ';
1707
+ }
1708
+ out += '{';
1706
1709
  this.numSpaces++;
1707
1710
  // Handle Directive/DirectiveLiteral like 'use strict';
1708
1711
  if (directives && directives.length) {
@@ -1711,8 +1714,7 @@ class Stringifier {
1711
1714
  }
1712
1715
  out += this.generateTypeChecks(node);
1713
1716
  if (body.length) {
1714
- if (out.length === 2) {
1715
- // 2 is ' {'
1717
+ if (out[out.length - 1] === '{') {
1716
1718
  out += '\n';
1717
1719
  }
1718
1720
  // out += '/*'+out.length+'*/';
@@ -1784,16 +1786,26 @@ class Stringifier {
1784
1786
  consequent,
1785
1787
  test
1786
1788
  } = node;
1787
- const spaces = this.spaces;
1788
1789
  let out = '';
1789
- //if (this.parentType !== "IfStatement")
1790
- //{
1791
- out += spaces;
1792
- //}
1790
+ if (this.forceCurly) {
1791
+ out += this.spaces;
1792
+ } else {
1793
+ if (this.parentType === 'BlockStatement') {
1794
+ out += this.spaces;
1795
+ } else if (this.parentType === 'IfStatement') {
1796
+ out += ' ';
1797
+ }
1798
+ }
1793
1799
  out += `if (${this.toSource(test)})`;
1794
1800
  out += this.toSourceCurly(consequent);
1795
1801
  if (alternate) {
1802
+ if (this.forceCurly) {
1803
+ this.numSpaces++;
1804
+ }
1796
1805
  out += ` else${this.toSourceCurly(alternate)}`;
1806
+ if (this.forceCurly) {
1807
+ this.numSpaces--;
1808
+ }
1797
1809
  }
1798
1810
  return out;
1799
1811
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "bin": "bin.js",
3
3
  "name": "@runtime-type-inspector/transpiler",
4
- "version": "4.0.1",
4
+ "version": "4.0.3",
5
5
  "description": "Validating JSDoc types at runtime for high-quality types - Trust is good, control is better.",
6
6
  "main": "index.cjs",
7
7
  "module": "index.mjs",
@@ -19,7 +19,7 @@
19
19
  "homepage": "https://github.com/kungfooman/RuntimeTypeInspector.js#readme",
20
20
  "dependencies": {
21
21
  "@babel/parser": "^7.23.0",
22
- "@runtime-type-inspector/runtime": "^4.0.1",
22
+ "@runtime-type-inspector/runtime": "^4.0.3",
23
23
  "typescript": "^5.1.6"
24
24
  },
25
25
  "files": [