@runtime-type-inspector/transpiler 5.0.2 → 5.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 +13 -8
  2. package/index.mjs +13 -8
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -1518,11 +1518,18 @@
1518
1518
  }
1519
1519
  properties[propName] = expandTypeDepFree(propTypeRaw);
1520
1520
  }
1521
+ // Bare `{}` carries no `properties` key, matching the TS/Babel parsers
1522
+ // (and distinguishing it from the `object` keyword, which does).
1521
1523
  } catch (err) {
1522
1524
  _iterator.e(err);
1523
1525
  } finally {
1524
1526
  _iterator.f();
1525
1527
  }
1528
+ if (!Object.keys(properties).length) {
1529
+ return {
1530
+ type: 'object'
1531
+ };
1532
+ }
1526
1533
  return {
1527
1534
  type: 'object',
1528
1535
  properties: properties
@@ -2691,8 +2698,12 @@
2691
2698
  */
2692
2699
  /**
2693
2700
  * Recursively clones and simplifies a type for emission into source code.
2694
- * Strips empty `properties` and collapses empty `object` types to the bare
2695
- * string `'object'`. Numbers/booleans (literal types) pass through.
2701
+ * Empty `properties` are preserved (not deleted) and empty `object` types
2702
+ * are kept structured: `{type: 'object'}` without a `properties` key is the
2703
+ * `{}` literal (accepts every non-nullish value like TS), while
2704
+ * `{type: 'object', properties: {}}` is the `object` keyword (rejects
2705
+ * primitives). Collapsing either form would erase that distinction.
2706
+ * Numbers/booleans (literal types) pass through.
2696
2707
  * Non-destructive — the original type tree is never mutated.
2697
2708
  * @param {string | DocType | number | boolean} type - The type.
2698
2709
  * @returns {string | DocType | number | boolean} The simplified type.
@@ -2704,9 +2715,6 @@
2704
2715
  var out = _objectSpread2({}, type);
2705
2716
  if (out.properties) {
2706
2717
  out.properties = mapValues(out.properties, simplifyType);
2707
- if (out.type === 'object' && !Object.keys(out.properties).length) {
2708
- delete out.properties;
2709
- }
2710
2718
  }
2711
2719
  if (out.indexSignatures && Array.isArray(out.indexSignatures)) {
2712
2720
  out.indexSignatures = out.indexSignatures.map(simplifyType);
@@ -2733,9 +2741,6 @@
2733
2741
  if (out.type === 'typeof' && out.argument) {
2734
2742
  out.argument = simplifyType(out.argument);
2735
2743
  }
2736
- if (out.type === 'object' && !out.properties && !out.indexSignatures && !out.optional) {
2737
- return 'object';
2738
- }
2739
2744
  return out;
2740
2745
  }
2741
2746
 
package/index.mjs CHANGED
@@ -1265,6 +1265,13 @@ function expandTypeDepFree(type) {
1265
1265
  }
1266
1266
  properties[propName] = expandTypeDepFree(propTypeRaw);
1267
1267
  }
1268
+ // Bare `{}` carries no `properties` key, matching the TS/Babel parsers
1269
+ // (and distinguishing it from the `object` keyword, which does).
1270
+ if (!Object.keys(properties).length) {
1271
+ return {
1272
+ type: 'object'
1273
+ };
1274
+ }
1268
1275
  return {
1269
1276
  type: 'object',
1270
1277
  properties
@@ -2342,8 +2349,12 @@ function mapValues(obj, fn) {
2342
2349
  */
2343
2350
  /**
2344
2351
  * Recursively clones and simplifies a type for emission into source code.
2345
- * Strips empty `properties` and collapses empty `object` types to the bare
2346
- * string `'object'`. Numbers/booleans (literal types) pass through.
2352
+ * Empty `properties` are preserved (not deleted) and empty `object` types
2353
+ * are kept structured: `{type: 'object'}` without a `properties` key is the
2354
+ * `{}` literal (accepts every non-nullish value like TS), while
2355
+ * `{type: 'object', properties: {}}` is the `object` keyword (rejects
2356
+ * primitives). Collapsing either form would erase that distinction.
2357
+ * Numbers/booleans (literal types) pass through.
2347
2358
  * Non-destructive — the original type tree is never mutated.
2348
2359
  * @param {string | DocType | number | boolean} type - The type.
2349
2360
  * @returns {string | DocType | number | boolean} The simplified type.
@@ -2355,9 +2366,6 @@ function simplifyType(type) {
2355
2366
  const out = _extends({}, type);
2356
2367
  if (out.properties) {
2357
2368
  out.properties = mapValues(out.properties, simplifyType);
2358
- if (out.type === 'object' && !Object.keys(out.properties).length) {
2359
- delete out.properties;
2360
- }
2361
2369
  }
2362
2370
  if (out.indexSignatures && Array.isArray(out.indexSignatures)) {
2363
2371
  out.indexSignatures = out.indexSignatures.map(simplifyType);
@@ -2384,9 +2392,6 @@ function simplifyType(type) {
2384
2392
  if (out.type === 'typeof' && out.argument) {
2385
2393
  out.argument = simplifyType(out.argument);
2386
2394
  }
2387
- if (out.type === 'object' && !out.properties && !out.indexSignatures && !out.optional) {
2388
- return 'object';
2389
- }
2390
2395
  return out;
2391
2396
  }
2392
2397
 
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "ts2js": "ts2js.js"
5
5
  },
6
6
  "name": "@runtime-type-inspector/transpiler",
7
- "version": "5.0.2",
7
+ "version": "5.0.3",
8
8
  "description": "Validating JSDoc types at runtime for high-quality types - Trust is good, control is better.",
9
9
  "main": "index.cjs",
10
10
  "module": "index.mjs",
@@ -22,7 +22,7 @@
22
22
  "homepage": "https://github.com/kungfooman/RuntimeTypeInspector.js#readme",
23
23
  "dependencies": {
24
24
  "@babel/parser": "^7.23.0",
25
- "@runtime-type-inspector/runtime": "^5.0.2",
25
+ "@runtime-type-inspector/runtime": "^5.0.3",
26
26
  "typescript": "^5.1.6"
27
27
  },
28
28
  "files": [