@runtime-type-inspector/transpiler 3.2.5 → 3.2.6

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 +36 -39
  2. package/index.mjs +19 -31
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -876,46 +876,43 @@
876
876
  // Strip the rest (either leftover of optional value or description)
877
877
  name = name.split(' ')[0].split('=')[0].trim();
878
878
  var simplifiedType = simplifyType(type, optional);
879
- var parts = name.split(".");
880
- if (parts.length === 3) {
881
- // Something like: @param {number[]} settings.render.skyboxRotation - Rotation of skybox.
882
- var parts0 = parts[0]; // settings
883
- var parts1 = parts[1]; // render
884
- var parts2 = parts[2]; // skyboxRotation
885
- var toptype = params[parts0];
886
- toptype.properties[parts1].properties = toptype.properties[parts1].properties || {};
887
- toptype.properties[parts1].properties[parts2] = simplifiedType;
888
- } else if (parts.length === 2) {
889
- // Something like: @param {number} description[].components
890
- var _parts = parts[0]; // description[]
891
- var _parts2 = parts[1]; // components
892
- if (_parts.endsWith('[]')) {
893
- _parts = _parts.slice(0, -2); // description[] -> description
894
- }
895
-
896
- var _toptype = params[_parts];
897
- if ((_toptype === null || _toptype === void 0 ? void 0 : _toptype.type) === "union") {
898
- var typeObject = _toptype.members.find(function (_) {
899
- return (_ === null || _ === void 0 ? void 0 : _.type) === 'object';
900
- });
901
- typeObject.properties[_parts2] = simplifiedType;
902
- //typeObject.properties = simplifiedType; // todo add test case
903
- } else if ((_toptype === null || _toptype === void 0 ? void 0 : _toptype.type) === "array") {
904
- _toptype.elementType.properties[_parts2] = simplifiedType;
905
- } else if ((_toptype === null || _toptype === void 0 ? void 0 : _toptype.type) === "object") {
906
- _toptype.properties = _toptype.properties || {};
907
- _toptype.properties[_parts2] = simplifiedType;
908
- } else {
909
- console.warn("parseJSDoc> skipping @param, unseen syntax detected, please check if your JSDoc is valid or open an issue about this", {
910
- src: src,
911
- toptype: _toptype,
912
- parts0: _parts,
913
- parts1: _parts2,
914
- simplifiedType: simplifiedType
915
- });
879
+ // Turn "options.stats[].unitsName" into ['options', 'stats', 'unitsName'].
880
+ var parts = name.split(/[\[\]]*\./);
881
+ var properties = params;
882
+ var _iterator = _createForOfIteratorHelper(parts),
883
+ _step;
884
+ try {
885
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
886
+ var part = _step.value;
887
+ /** @type {object} */
888
+ var toptype = properties[part];
889
+ if (!toptype) {
890
+ // No toptype means we resolved as far as possible, now we can add `simplifiedType`.
891
+ console.assert(part === parts.at(-1), 'Current part and last part should be the same.');
892
+ properties[part] = simplifiedType;
893
+ } else if (toptype.type === "union") {
894
+ var typeObject = toptype.members.find(function (_) {
895
+ return (_ === null || _ === void 0 ? void 0 : _.type) === 'object';
896
+ });
897
+ properties = typeObject.properties;
898
+ } else if (toptype.type === "array") {
899
+ properties = toptype.elementType.properties;
900
+ } else if (toptype.type === "object") {
901
+ toptype.properties = toptype.properties || Object.create(null);
902
+ properties = toptype.properties;
903
+ } else {
904
+ console.warn("parseJSDoc> Skipping @param, unseen syntax detected. Please check if your JSDoc is valid or open an issue about this!", {
905
+ src: src,
906
+ toptype: toptype,
907
+ parts: parts,
908
+ simplifiedType: simplifiedType
909
+ });
910
+ }
916
911
  }
917
- } else {
918
- params[name] = simplifiedType;
912
+ } catch (err) {
913
+ _iterator.e(err);
914
+ } finally {
915
+ _iterator.f();
919
916
  }
920
917
  });
921
918
  if (Object.keys(params).length === 0) {
package/index.mjs CHANGED
@@ -619,44 +619,32 @@ function parseJSDoc(src, expandType = expandTypeDepFree) {
619
619
  // Strip the rest (either leftover of optional value or description)
620
620
  name = name.split(' ')[0].split('=')[0].trim();
621
621
  const simplifiedType = simplifyType(type, optional);
622
- const parts = name.split(".");
623
- if (parts.length === 3) {
624
- // Something like: @param {number[]} settings.render.skyboxRotation - Rotation of skybox.
625
- const parts0 = parts[0]; // settings
626
- const parts1 = parts[1]; // render
627
- const parts2 = parts[2]; // skyboxRotation
628
- const toptype = params[parts0];
629
- toptype.properties[parts1].properties = toptype.properties[parts1].properties || {};
630
- toptype.properties[parts1].properties[parts2] = simplifiedType;
631
- } else if (parts.length === 2) {
632
- // Something like: @param {number} description[].components
633
- let parts0 = parts[0]; // description[]
634
- const parts1 = parts[1]; // components
635
- if (parts0.endsWith('[]')) {
636
- parts0 = parts0.slice(0, -2); // description[] -> description
637
- }
638
-
639
- const toptype = params[parts0];
640
- if ((toptype == null ? void 0 : toptype.type) === "union") {
622
+ // Turn "options.stats[].unitsName" into ['options', 'stats', 'unitsName'].
623
+ const parts = name.split(/[\[\]]*\./);
624
+ let properties = params;
625
+ for (const part of parts) {
626
+ /** @type {object} */
627
+ const toptype = properties[part];
628
+ if (!toptype) {
629
+ // No toptype means we resolved as far as possible, now we can add `simplifiedType`.
630
+ console.assert(part === parts.at(-1), 'Current part and last part should be the same.');
631
+ properties[part] = simplifiedType;
632
+ } else if (toptype.type === "union") {
641
633
  const typeObject = toptype.members.find(_ => (_ == null ? void 0 : _.type) === 'object');
642
- typeObject.properties[parts1] = simplifiedType;
643
- //typeObject.properties = simplifiedType; // todo add test case
644
- } else if ((toptype == null ? void 0 : toptype.type) === "array") {
645
- toptype.elementType.properties[parts1] = simplifiedType;
646
- } else if ((toptype == null ? void 0 : toptype.type) === "object") {
647
- toptype.properties = toptype.properties || {};
648
- toptype.properties[parts1] = simplifiedType;
634
+ properties = typeObject.properties;
635
+ } else if (toptype.type === "array") {
636
+ properties = toptype.elementType.properties;
637
+ } else if (toptype.type === "object") {
638
+ toptype.properties = toptype.properties || Object.create(null);
639
+ properties = toptype.properties;
649
640
  } else {
650
- console.warn("parseJSDoc> skipping @param, unseen syntax detected, please check if your JSDoc is valid or open an issue about this", {
641
+ console.warn("parseJSDoc> Skipping @param, unseen syntax detected. Please check if your JSDoc is valid or open an issue about this!", {
651
642
  src,
652
643
  toptype,
653
- parts0,
654
- parts1,
644
+ parts,
655
645
  simplifiedType
656
646
  });
657
647
  }
658
- } else {
659
- params[name] = simplifiedType;
660
648
  }
661
649
  });
662
650
  if (Object.keys(params).length === 0) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "bin": "bin.js",
3
3
  "name": "@runtime-type-inspector/transpiler",
4
- "version": "3.2.5",
4
+ "version": "3.2.6",
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": "^3.2.5",
22
+ "@runtime-type-inspector/runtime": "^3.2.6",
23
23
  "typescript": "^5.1.6"
24
24
  },
25
25
  "files": [