@runtime-type-inspector/transpiler 5.0.2 → 5.0.4
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/index.cjs +28 -10
- package/index.mjs +28 -10
- 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
|
-
*
|
|
2695
|
-
*
|
|
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
|
|
|
@@ -4933,6 +4938,10 @@
|
|
|
4933
4938
|
* @property {string} [filename] - The name of a file to which the instance pertains.
|
|
4934
4939
|
* @property {boolean} [addHeader] - Whether to add import declarations headers. Defaults to true.
|
|
4935
4940
|
* @property {string[]} [ignoreLocations] - Ignore these locations because they are known false-positives.
|
|
4941
|
+
* @property {string} [projectVersion] - Host project version funneled into
|
|
4942
|
+
* the emitted header via `setProjectVersion(...)`, so `Download log` meta
|
|
4943
|
+
* identifies the app build. Bundler plugins resolve it from their own
|
|
4944
|
+
* option or the host package.json.
|
|
4936
4945
|
*/
|
|
4937
4946
|
var Asserter = /*#__PURE__*/function (_Stringifier) {
|
|
4938
4947
|
_inherits(Asserter, _Stringifier);
|
|
@@ -4955,7 +4964,8 @@
|
|
|
4955
4964
|
_ref$addHeader = _ref.addHeader,
|
|
4956
4965
|
addHeader = _ref$addHeader === void 0 ? true : _ref$addHeader,
|
|
4957
4966
|
_ref$ignoreLocations = _ref.ignoreLocations,
|
|
4958
|
-
ignoreLocations = _ref$ignoreLocations === void 0 ? [] : _ref$ignoreLocations
|
|
4967
|
+
ignoreLocations = _ref$ignoreLocations === void 0 ? [] : _ref$ignoreLocations,
|
|
4968
|
+
projectVersion = _ref.projectVersion;
|
|
4959
4969
|
_classCallCheck(this, Asserter);
|
|
4960
4970
|
_this = _super.call(this);
|
|
4961
4971
|
/** @type {Record<string, Stat>} */
|
|
@@ -5020,6 +5030,7 @@
|
|
|
5020
5030
|
_this.filename = filename;
|
|
5021
5031
|
_this.addHeader = addHeader;
|
|
5022
5032
|
_this.ignoreLocations = ignoreLocations;
|
|
5033
|
+
_this.projectVersion = projectVersion;
|
|
5023
5034
|
return _this;
|
|
5024
5035
|
}
|
|
5025
5036
|
_createClass(Asserter, [{
|
|
@@ -5128,9 +5139,16 @@
|
|
|
5128
5139
|
if (this.validateDivision) {
|
|
5129
5140
|
header += ", validateDivision";
|
|
5130
5141
|
}
|
|
5131
|
-
header += ", registerTypedef, registerClass, registerImportNamespaceSpecifier
|
|
5142
|
+
header += ", registerTypedef, registerClass, registerImportNamespaceSpecifier";
|
|
5143
|
+
if (this.projectVersion !== undefined && this.projectVersion !== null) {
|
|
5144
|
+
header += ", setProjectVersion";
|
|
5145
|
+
}
|
|
5146
|
+
header += "} from '@runtime-type-inspector/runtime';\n";
|
|
5132
5147
|
// Prevent tree-shaking in UMD build so we can always "add a breakpoint here".
|
|
5133
5148
|
header += "export * from '@runtime-type-inspector/runtime';\n";
|
|
5149
|
+
if (this.projectVersion !== undefined && this.projectVersion !== null) {
|
|
5150
|
+
header += "setProjectVersion(".concat(JSON.stringify(this.projectVersion), ");\n");
|
|
5151
|
+
}
|
|
5134
5152
|
return header;
|
|
5135
5153
|
}
|
|
5136
5154
|
/**
|
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
|
-
*
|
|
2346
|
-
*
|
|
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
|
|
|
@@ -4510,6 +4515,10 @@ class Stringifier {
|
|
|
4510
4515
|
* @property {string} [filename] - The name of a file to which the instance pertains.
|
|
4511
4516
|
* @property {boolean} [addHeader] - Whether to add import declarations headers. Defaults to true.
|
|
4512
4517
|
* @property {string[]} [ignoreLocations] - Ignore these locations because they are known false-positives.
|
|
4518
|
+
* @property {string} [projectVersion] - Host project version funneled into
|
|
4519
|
+
* the emitted header via `setProjectVersion(...)`, so `Download log` meta
|
|
4520
|
+
* identifies the app build. Bundler plugins resolve it from their own
|
|
4521
|
+
* option or the host package.json.
|
|
4513
4522
|
*/
|
|
4514
4523
|
class Asserter extends Stringifier {
|
|
4515
4524
|
/**
|
|
@@ -4522,7 +4531,8 @@ class Asserter extends Stringifier {
|
|
|
4522
4531
|
expandType = expandTypeDepFree,
|
|
4523
4532
|
filename,
|
|
4524
4533
|
addHeader = true,
|
|
4525
|
-
ignoreLocations = []
|
|
4534
|
+
ignoreLocations = [],
|
|
4535
|
+
projectVersion
|
|
4526
4536
|
} = {}) {
|
|
4527
4537
|
super();
|
|
4528
4538
|
/** @type {Record<string, Stat>} */
|
|
@@ -4587,6 +4597,7 @@ class Asserter extends Stringifier {
|
|
|
4587
4597
|
this.filename = filename;
|
|
4588
4598
|
this.addHeader = addHeader;
|
|
4589
4599
|
this.ignoreLocations = ignoreLocations;
|
|
4600
|
+
this.projectVersion = projectVersion;
|
|
4590
4601
|
}
|
|
4591
4602
|
/**
|
|
4592
4603
|
* We expand type-asserted ArrowFunctionExpressions in order to add type assertions.
|
|
@@ -4689,9 +4700,16 @@ class Asserter extends Stringifier {
|
|
|
4689
4700
|
if (this.validateDivision) {
|
|
4690
4701
|
header += ", validateDivision";
|
|
4691
4702
|
}
|
|
4692
|
-
header += ", registerTypedef, registerClass, registerImportNamespaceSpecifier
|
|
4703
|
+
header += ", registerTypedef, registerClass, registerImportNamespaceSpecifier";
|
|
4704
|
+
if (this.projectVersion !== undefined && this.projectVersion !== null) {
|
|
4705
|
+
header += ", setProjectVersion";
|
|
4706
|
+
}
|
|
4707
|
+
header += "} from '@runtime-type-inspector/runtime';\n";
|
|
4693
4708
|
// Prevent tree-shaking in UMD build so we can always "add a breakpoint here".
|
|
4694
4709
|
header += "export * from '@runtime-type-inspector/runtime';\n";
|
|
4710
|
+
if (this.projectVersion !== undefined && this.projectVersion !== null) {
|
|
4711
|
+
header += `setProjectVersion(${JSON.stringify(this.projectVersion)});\n`;
|
|
4712
|
+
}
|
|
4695
4713
|
return header;
|
|
4696
4714
|
}
|
|
4697
4715
|
/**
|
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.
|
|
7
|
+
"version": "5.0.4",
|
|
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.
|
|
25
|
+
"@runtime-type-inspector/runtime": "^5.0.4",
|
|
26
26
|
"typescript": "^5.1.6"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|