@runtime-type-inspector/transpiler 3.0.2 → 3.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.
Files changed (3) hide show
  1. package/index.cjs +21 -4
  2. package/index.mjs +22 -4
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -1938,9 +1938,6 @@
1938
1938
  loc = node.loc;
1939
1939
  var out = this.spaces;
1940
1940
  if (specifiers.length) {
1941
- if (!source) {
1942
- console.warn("ExportNamedDeclaration> no source given");
1943
- }
1944
1941
  if (specifiers.length === 1 && specifiers[0].type === 'ExportNamespaceSpecifier') {
1945
1942
  out += 'export ';
1946
1943
  out += this.toSource(specifiers[0]);
@@ -3507,7 +3504,9 @@
3507
3504
  TypeOperator = _ts$SyntaxKind.TypeOperator,
3508
3505
  KeyOfKeyword = _ts$SyntaxKind.KeyOfKeyword,
3509
3506
  ConstructorType = _ts$SyntaxKind.ConstructorType,
3510
- NamedTupleMember = _ts$SyntaxKind.NamedTupleMember;
3507
+ NamedTupleMember = _ts$SyntaxKind.NamedTupleMember,
3508
+ MappedType = _ts$SyntaxKind.MappedType,
3509
+ TypeParameter = _ts$SyntaxKind.TypeParameter;
3511
3510
  // console.log({typeArguments, typeName, kind_, node});
3512
3511
  switch (node.kind) {
3513
3512
  case BigIntKeyword:
@@ -3571,6 +3570,24 @@
3571
3570
  type: 'union',
3572
3571
  members: [t, 'null']
3573
3572
  };
3573
+ case MappedType:
3574
+ {
3575
+ var result = toSourceTS(node.type);
3576
+ var parameter = node.typeParameter;
3577
+ if (parameter.kind === TypeParameter) {
3578
+ // For example: {[K in TaskType]: InstanceType etc.
3579
+ var iterable = toSourceTS(parameter.constraint); // TaskType
3580
+ var element = toSourceTS(parameter.name); // K
3581
+ return {
3582
+ type: 'mapping',
3583
+ iterable: iterable,
3584
+ element: element,
3585
+ result: result
3586
+ };
3587
+ }
3588
+ console.warn("MappedType: expected TypeParameter");
3589
+ return 'transpiler-error';
3590
+ }
3574
3591
  // todo work out more: const jsdoc = `(...a: ...number) => 123
3575
3592
  // TS even thinks it's two parameters... just go for array/[]
3576
3593
  case Parameter:
package/index.mjs CHANGED
@@ -1619,9 +1619,6 @@ class Stringifier {
1619
1619
  } = node;
1620
1620
  let out = this.spaces;
1621
1621
  if (specifiers.length) {
1622
- if (!source) {
1623
- console.warn("ExportNamedDeclaration> no source given");
1624
- }
1625
1622
  if (specifiers.length === 1 && specifiers[0].type === 'ExportNamespaceSpecifier') {
1626
1623
  out += 'export ';
1627
1624
  out += this.toSource(specifiers[0]);
@@ -3131,7 +3128,10 @@ function toSourceTS(node) {
3131
3128
  // "operator" key in TypeOperator node
3132
3129
  ConstructorType,
3133
3130
  // parseType('new (...args: any[]) => any');
3134
- NamedTupleMember
3131
+ NamedTupleMember,
3132
+ MappedType,
3133
+ // parseType('{[K in TaskType]: InstanceType<typeof SUPPORTED_TASKS[K]["pipeline"]>}')
3134
+ TypeParameter // Basically K and TaskType of MappedType
3135
3135
  } = ts.SyntaxKind;
3136
3136
  // console.log({typeArguments, typeName, kind_, node});
3137
3137
  switch (node.kind) {
@@ -3196,6 +3196,24 @@ function toSourceTS(node) {
3196
3196
  type: 'union',
3197
3197
  members: [t, 'null']
3198
3198
  };
3199
+ case MappedType:
3200
+ {
3201
+ const result = toSourceTS(node.type);
3202
+ const parameter = node.typeParameter;
3203
+ if (parameter.kind === TypeParameter) {
3204
+ // For example: {[K in TaskType]: InstanceType etc.
3205
+ const iterable = toSourceTS(parameter.constraint); // TaskType
3206
+ const element = toSourceTS(parameter.name); // K
3207
+ return {
3208
+ type: 'mapping',
3209
+ iterable,
3210
+ element,
3211
+ result
3212
+ };
3213
+ }
3214
+ console.warn("MappedType: expected TypeParameter");
3215
+ return 'transpiler-error';
3216
+ }
3199
3217
  // todo work out more: const jsdoc = `(...a: ...number) => 123
3200
3218
  // TS even thinks it's two parameters... just go for array/[]
3201
3219
  case Parameter:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runtime-type-inspector/transpiler",
3
- "version": "3.0.2",
3
+ "version": "3.0.4",
4
4
  "description": "Validating JSDoc types at runtime for high-quality types - Trust is good, control is better.",
5
5
  "main": "index.cjs",
6
6
  "module": "index.mjs",
@@ -18,7 +18,7 @@
18
18
  "homepage": "https://github.com/kungfooman/RuntimeTypeInspector.js#readme",
19
19
  "dependencies": {
20
20
  "@babel/parser": "^7.23.0",
21
- "@runtime-type-inspector/runtime": "~3.0.1",
21
+ "@runtime-type-inspector/runtime": "~3.0.2",
22
22
  "typescript": "^5.1.6"
23
23
  },
24
24
  "files": [