@idlizer/core 2.1.10-arktscgen-9 → 2.1.10-arktscgen-10

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 (75) hide show
  1. package/build/lib/src/IndentedPrinter.js +2 -2
  2. package/build/lib/src/Language.d.ts +1 -0
  3. package/build/lib/src/Language.js +8 -0
  4. package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +47 -3
  5. package/build/lib/src/LanguageWriters/ArgConvertors.js +194 -20
  6. package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +5 -1
  7. package/build/lib/src/LanguageWriters/LanguageWriter.js +15 -0
  8. package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +6 -2
  9. package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +7 -1
  10. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +3 -0
  11. package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +4 -0
  12. package/build/lib/src/LanguageWriters/convertors/KotlinConvertors.d.ts +10 -5
  13. package/build/lib/src/LanguageWriters/convertors/KotlinConvertors.js +138 -51
  14. package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +5 -1
  15. package/build/lib/src/LanguageWriters/index.d.ts +1 -2
  16. package/build/lib/src/LanguageWriters/index.js +17 -3
  17. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +1 -1
  18. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +5 -3
  19. package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.d.ts +1 -1
  20. package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.js +5 -3
  21. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +2 -1
  22. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +8 -3
  23. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +3 -9
  24. package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.d.ts +5 -3
  25. package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.js +52 -31
  26. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +1 -1
  27. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +5 -3
  28. package/build/lib/src/LibraryInterface.d.ts +6 -0
  29. package/build/lib/src/LibraryInterface.js +22 -1
  30. package/build/lib/src/from-idl/DtsPrinter.d.ts +3 -2
  31. package/build/lib/src/from-idl/DtsPrinter.js +9 -6
  32. package/build/lib/src/idl/builders.d.ts +36 -1
  33. package/build/lib/src/idl/builders.js +62 -2
  34. package/build/lib/src/idl/dump.d.ts +3 -0
  35. package/build/lib/src/idl/dump.js +20 -3
  36. package/build/lib/src/idl/index.d.ts +0 -1
  37. package/build/lib/src/idl/index.js +0 -1
  38. package/build/lib/src/idl/node.d.ts +1 -0
  39. package/build/lib/src/idl/node.js +1 -0
  40. package/build/lib/src/idl/stdlib.d.ts +1 -0
  41. package/build/lib/src/idl/stdlib.js +1 -0
  42. package/build/lib/src/idl/utils.d.ts +4 -3
  43. package/build/lib/src/idl/utils.js +26 -13
  44. package/build/lib/src/idl/visitors.js +24 -104
  45. package/build/lib/src/index.d.ts +4 -1
  46. package/build/lib/src/index.js +4 -1
  47. package/build/lib/src/peer-generation/Extractors.d.ts +7 -0
  48. package/build/lib/src/peer-generation/Extractors.js +40 -0
  49. package/build/lib/src/peer-generation/Initializers.d.ts +5 -0
  50. package/build/lib/src/peer-generation/Initializers.js +28 -0
  51. package/build/lib/src/peer-generation/Materialized.d.ts +0 -4
  52. package/build/lib/src/peer-generation/Materialized.js +13 -24
  53. package/build/lib/src/peer-generation/PeerLibrary.d.ts +2 -2
  54. package/build/lib/src/peer-generation/PeerLibrary.js +55 -5
  55. package/build/lib/src/peer-generation/PeerMethod.d.ts +1 -0
  56. package/build/lib/src/peer-generation/PeerMethod.js +1 -0
  57. package/build/lib/src/peer-generation/idl/common.d.ts +0 -2
  58. package/build/lib/src/peer-generation/idl/common.js +3 -25
  59. package/build/lib/src/peer-generation/isMaterialized.d.ts +4 -0
  60. package/build/lib/src/peer-generation/isMaterialized.js +12 -0
  61. package/build/lib/src/peer-generation/unions.d.ts +1 -27
  62. package/build/lib/src/peer-generation/unions.js +1 -99
  63. package/build/lib/src/transformers/FqnTransformer.js +14 -0
  64. package/build/lib/src/transformers/GenericTransformer.d.ts +0 -2
  65. package/build/lib/src/transformers/GenericTransformer.js +19 -19
  66. package/build/lib/src/transformers/IdlTransformer.js +14 -0
  67. package/build/lib/src/transformers/NullTransformer.js +16 -3
  68. package/build/lib/src/transformers/OnSerializeTransformer.js +14 -0
  69. package/build/lib/src/transformers/ThrowsTransformer.d.ts +3 -0
  70. package/build/lib/src/transformers/ThrowsTransformer.js +51 -0
  71. package/build/lib/src/transformers/transformUtils.d.ts +7 -0
  72. package/build/lib/src/transformers/transformUtils.js +55 -0
  73. package/build/lib/src/util.d.ts +0 -16
  74. package/build/lib/src/util.js +2 -76
  75. package/package.json +10 -4
@@ -87,18 +87,18 @@ export class KotlinEnumWithGetter {
87
87
  const enumType = idl.createReferenceType(this.enumEntity);
88
88
  writer.writeStaticEntitiesBlock(() => {
89
89
  members.forEach(it => {
90
- writer.writeFieldDeclaration(it.name, enumType, [FieldModifier.PUBLIC, FieldModifier.STATIC, FieldModifier.FINAL], false, writer.makeString(`${mangledName}(${it.stringId ? `\"${it.stringId}\"` : it.numberId})`));
90
+ writer.writeFieldDeclaration(it.name, enumType, [FieldModifier.PUBLIC, FieldModifier.STATIC, FieldModifier.READONLY], false, writer.makeString(`${mangledName}(${it.stringId ? `\"${it.stringId}\"` : it.numberId})`));
91
91
  });
92
92
  });
93
93
  const value = 'value';
94
- writer.writeFieldDeclaration(value, idl.IDLI32Type, [FieldModifier.PUBLIC], true, writer.makeNull());
94
+ writer.writeFieldDeclaration(value, idl.IDLI32Type, [FieldModifier.PUBLIC, FieldModifier.READONLY], true);
95
95
  const signature = new MethodSignature(idl.IDLVoidType, [idl.IDLI32Type]);
96
96
  writer.writeConstructorImplementation('constructor', signature, () => {
97
97
  writer.writeStatement(writer.makeAssign(`this.${value}`, undefined, writer.makeString(signature.argName(0)), false));
98
98
  });
99
99
  if (isStringEnum) {
100
100
  const stringValue = 'stringValue';
101
- writer.writeFieldDeclaration(stringValue, idl.IDLStringType, [FieldModifier.PUBLIC], true, writer.makeNull());
101
+ writer.writeFieldDeclaration(stringValue, idl.IDLStringType, [FieldModifier.PUBLIC, FieldModifier.READONLY], true);
102
102
  const signature = new MethodSignature(idl.IDLVoidType, [idl.IDLStringType]);
103
103
  writer.writeConstructorImplementation('constructor', signature, () => {
104
104
  writer.writeStatement(writer.makeAssign(`this.${stringValue}`, undefined, writer.makeString(signature.argName(0)), false));
@@ -123,11 +123,11 @@ class KotlinMapForEachStatement {
123
123
  }
124
124
  }
125
125
  export class KotlinThrowErrorStatement {
126
- constructor(message) {
127
- this.message = message;
126
+ constructor(exception) {
127
+ this.exception = exception;
128
128
  }
129
129
  write(writer) {
130
- writer.print(`throw Error("${this.message}")`);
130
+ writer.print(`throw ${this.exception.asString()}`);
131
131
  }
132
132
  }
133
133
  class KotlinArrayResizeStatement {
@@ -286,7 +286,11 @@ export class KotlinLanguageWriter extends LanguageWriter {
286
286
  prefix = prefix ? prefix.trim() + " " : "";
287
287
  const typeParams = (generics === null || generics === void 0 ? void 0 : generics.length) ? `<${generics.join(", ")}>` : "";
288
288
  const normalizedArgs = signature.args.map((it, i) => idl.isOptionalType(it) && signature.isArgOptional(i) ? idl.maybeUnwrapOptionalType(it) : it);
289
- this.printer.print(`${prefix}fun ${name}${typeParams}(${normalizedArgs.map((it, index) => `${signature.argName(index)}: ${this.getNodeName(it)}${signature.isArgOptional(index) ? "?" : ``}${signature.argDefault(index) ? ' = ' + signature.argDefault(index) : ""}`).join(", ")})${needReturn ? ": " + this.getNodeName(signature.returnType) : ""}${needBracket ? " {" : ""}`);
289
+ if (signature.returnType === idl.IDLThisType) {
290
+ throw new Error(`Return type 'this' must be substituted when generating for Kotlin`);
291
+ }
292
+ const returnTypePart = needReturn ? ": " + this.getNodeName(signature.returnType) : "";
293
+ this.printer.print(`${prefix}fun ${name}${typeParams}(${normalizedArgs.map((it, index) => `${signature.argName(index)}: ${this.getNodeName(it)}${signature.isArgOptional(index) ? "?" : ``}${signature.argDefault(index) ? ' = ' + signature.argDefault(index) : ""}`).join(", ")})${returnTypePart}${needBracket ? " {" : ""}`);
290
294
  }
291
295
  writeFieldDeclaration(name, type, modifiers, optional, initExpr) {
292
296
  const init = initExpr != undefined ? ` = ${initExpr.asString()}` : ``;
@@ -348,30 +352,32 @@ export class KotlinLanguageWriter extends LanguageWriter {
348
352
  const realInteropType = this.getNodeName(type);
349
353
  let expr;
350
354
  switch (realInteropType) {
351
- case "UByteArray":
352
- case "IntArray":
353
- case "FloatArray":
355
+ case "KUint8ArrayPtr":
356
+ case "KInt32ArrayPtr":
357
+ case "KFloat32ArrayPtr":
354
358
  expr = `${varName}Pinned.addressOf(0)`;
355
359
  break;
356
- case "KPointer":
357
360
  case "KNativePointer":
358
361
  case "KSerializerBuffer":
359
362
  expr = `${varName}.toCPointer<CPointed>()!!`;
360
363
  break;
361
- case "BigInteger":
364
+ case "KByte":
365
+ case "KShort":
366
+ case "KUShort":
362
367
  case "KInt":
368
+ case "KUInt":
363
369
  case "KLong":
370
+ case "KULong":
364
371
  case "KFloat":
365
372
  case "KDouble":
366
- case "String":
367
373
  case "KStringPtr":
368
- case "KBoolean":
369
- case "Float":
370
- case "Double":
371
- case "UInt":
372
- case "Int":
373
374
  expr = varName;
374
375
  break;
376
+ case "Boolean": {
377
+ // small trick to hide all casts Boolean <=> KBoolean in a NativeModule
378
+ expr = `${varName}.toByte()`;
379
+ break;
380
+ }
375
381
  default: throw new Error(`Unexpected type ${realInteropType} in interop with Kotlin`);
376
382
  }
377
383
  return this.makeString(expr);
@@ -381,26 +387,32 @@ export class KotlinLanguageWriter extends LanguageWriter {
381
387
  let expr;
382
388
  switch (realInteropType) {
383
389
  case "KNativePointer":
384
- case "KPointer":
385
390
  expr = `${varName}.toLong()`;
386
391
  break;
392
+ case "KByte":
393
+ case "KShort":
394
+ case "KUShort":
387
395
  case "KInt":
396
+ case "KUInt":
388
397
  case "KLong":
389
- case "BigInteger":
390
- case "Float":
391
- case "Double":
392
- case "Long":
393
- case "Int":
398
+ case "KULong":
399
+ case "KFloat":
400
+ case "KDouble":
394
401
  expr = varName;
395
402
  break;
396
- case "String":
397
403
  case "KStringPtr":
398
404
  expr = `${varName}?.toKString() ?: ""`;
399
405
  break;
400
- case "Boolean":
401
- case "KBoolean":
406
+ case "Boolean": {
407
+ // small trick to hide all casts Boolean <=> KBoolean in a NativeModule
402
408
  expr = `${varName} != 0.toByte()`;
403
409
  break;
410
+ }
411
+ case "Any": {
412
+ // unsupported case for now, implementation returns Unit (analogue of void) instead of a real object
413
+ expr = varName;
414
+ break;
415
+ }
404
416
  case "KInteropReturnBuffer":
405
417
  expr = `${varName}.useContents { KInteropReturnBuffer(length, data.toLong()) }`;
406
418
  break;
@@ -409,19 +421,20 @@ export class KotlinLanguageWriter extends LanguageWriter {
409
421
  return this.makeString(expr);
410
422
  }
411
423
  writeMethodDeclaration(name, signature, modifiers) {
412
- this.writeDeclaration(name, signature, true, false, modifiers);
424
+ this.writeDeclaration(name, signature, true, false, modifiers, []);
413
425
  }
414
426
  writeConstructorImplementation(className, signature, op, delegationCall, modifiers) {
415
427
  const delegationType = ((delegationCall === null || delegationCall === void 0 ? void 0 : delegationCall.delegationType) == DelegationType.THIS) ? "this" : "super";
416
428
  const superInvocation = delegationCall
417
429
  ? ` : ${delegationType}(${delegationCall.delegationArgs.map(it => it.asString()).join(", ")})`
418
- : "";
430
+ : ``;
419
431
  const argList = signature.args.map((it, index) => {
420
432
  var _a;
421
433
  const maybeDefault = ((_a = signature.defaults) === null || _a === void 0 ? void 0 : _a[index]) ? ` = ${signature.defaults[index]}` : "";
422
434
  return `${signature.argName(index)}: ${this.getNodeName(it)}${maybeDefault}`;
423
435
  }).join(", ");
424
- this.print(`constructor(${argList})${superInvocation} {`);
436
+ const modifierList = modifiers ? modifiers.map((it) => MethodModifier[it].toLowerCase()).join(" ") + " " : "";
437
+ this.print(`${modifierList}constructor(${argList})${superInvocation} {`);
425
438
  this.pushIndent();
426
439
  op(this);
427
440
  this.popIndent();
@@ -494,6 +507,8 @@ export class KotlinLanguageWriter extends LanguageWriter {
494
507
  return new KotlinLambdaExpression(this, signature, this.resolver, body);
495
508
  }
496
509
  makeThrowError(message) {
510
+ if (typeof message === 'string')
511
+ message = this.makeString(`Error("${message}")`);
497
512
  return new KotlinThrowErrorStatement(message);
498
513
  }
499
514
  makeReturn(expr) {
@@ -605,7 +620,7 @@ export class KotlinLanguageWriter extends LanguageWriter {
605
620
  return new KotlinEnumWithGetter(enumEntity, options.isExport);
606
621
  }
607
622
  castToBoolean(value) {
608
- return `if (${value}) { 1 } else { 0 }`;
623
+ return value;
609
624
  }
610
625
  castToInt(value, bitness) {
611
626
  return `${this.escapeKeyword(value)}.${bitness == 8 ? 'toByte()' : 'toInt()'}`;
@@ -616,6 +631,12 @@ export class KotlinLanguageWriter extends LanguageWriter {
616
631
  makeNewObject(objectName, params = []) {
617
632
  return new KotlinNewObjectExpression(objectName, params);
618
633
  }
634
+ makeFunctionReference(name) {
635
+ return this.makeString(`::${name}`);
636
+ }
637
+ makeMethodReference(receiver, method) {
638
+ return this.makeString(`${receiver}::${method}`);
639
+ }
619
640
  escapeKeyword(keyword) {
620
641
  return keyword;
621
642
  }
@@ -71,7 +71,7 @@ export declare class TSLanguageWriter extends LanguageWriter {
71
71
  makeNull(type?: idl.IDLOptionalType): LanguageExpression;
72
72
  makeAssign(variableName: string, type: idl.IDLType | undefined, expr: LanguageExpression | undefined, isDeclared?: boolean, isConst?: boolean, options?: MakeAssignOptions): LanguageStatement;
73
73
  makeLambda(signature: MethodSignature, body?: LanguageStatement[]): LanguageExpression;
74
- makeThrowError(message: string): LanguageStatement;
74
+ makeThrowError(message: string | LanguageExpression): LanguageStatement;
75
75
  makeReturn(expr: LanguageExpression): LanguageStatement;
76
76
  makeStatement(expr: LanguageExpression): LanguageStatement;
77
77
  makeLoop(counter: string, limit: string, statement?: LanguageStatement): LanguageStatement;
@@ -63,11 +63,11 @@ class TSUnwrapOptionalExpression {
63
63
  // STATEMENTS //
64
64
  ////////////////////////////////////////////////////////////////
65
65
  class TSThrowErrorStatement {
66
- constructor(message) {
67
- this.message = message;
66
+ constructor(exception) {
67
+ this.exception = exception;
68
68
  }
69
69
  write(writer) {
70
- writer.print(`throw new Error('${this.message}')`);
70
+ writer.print(`throw ${this.exception.asString()}`);
71
71
  }
72
72
  }
73
73
  export class TSReturnStatement extends ReturnStatement {
@@ -339,6 +339,8 @@ export class TSLanguageWriter extends LanguageWriter {
339
339
  return new TSLambdaExpression(this, this.typeConvertor, signature, this.resolver, body);
340
340
  }
341
341
  makeThrowError(message) {
342
+ if (typeof message === 'string')
343
+ message = this.makeString(`new Error('${message}')`);
342
344
  return new TSThrowErrorStatement(message);
343
345
  }
344
346
  makeReturn(expr) {
@@ -18,4 +18,10 @@ export interface LibraryInterface extends ReferenceResolver {
18
18
  */
19
19
  libraryPrefix: string;
20
20
  }
21
+ export declare function getTransformer(library: LibraryInterface, from: idl.IDLNode, to: idl.IDLNode): {
22
+ module: string;
23
+ ns?: string;
24
+ method: string;
25
+ };
26
+ export declare function mapLibraryName(node: idl.IDLEntry, lang: Language, mapping?: Map<string, Map<string, string>>, prefix?: string): string;
21
27
  //# sourceMappingURL=LibraryInterface.d.ts.map
@@ -1,2 +1,23 @@
1
- export {};
1
+ import * as idl from "./idl";
2
+ import { Language } from "./Language";
3
+ import { getModuleFor } from "./peer-generation/modules";
4
+ export function getTransformer(library, from, to) {
5
+ const convertor = library.createTypeNameConvertor(Language.CPP);
6
+ const withNS = Language.supportNS(library.language);
7
+ const handwritten = library.layout.handwrittenPackage();
8
+ return {
9
+ module: withNS ? handwritten : `${handwritten}.extractors`,
10
+ ns: withNS ? "extractors" : undefined,
11
+ method: `transform_${convertor.convert(from)}_to_${convertor.convert(to)}`
12
+ };
13
+ }
14
+ export function mapLibraryName(node, lang, mapping, prefix = "@") {
15
+ var _a, _b;
16
+ const module = getModuleFor(node);
17
+ if (module.tsLikePackage !== undefined) {
18
+ return `^` + module.tsLikePackage;
19
+ }
20
+ const packageName = idl.getPackageName(node);
21
+ return `^` + ((_b = (_a = mapping === null || mapping === void 0 ? void 0 : mapping.get(packageName)) === null || _a === void 0 ? void 0 : _a.get(lang.name)) !== null && _b !== void 0 ? _b : `${prefix}${packageName}`);
22
+ }
2
23
  //# sourceMappingURL=LibraryInterface.js.map
@@ -1,11 +1,12 @@
1
1
  import { stringOrNone } from "../util";
2
- import { IDLCallback, IDLConstructor, IDLEntry, IDLEnum, IDLInterface, IDLMethod, IDLParameter, IDLProperty, IDLTypedef, IDLNamespace, IDLFile, IDLImport, IDLReferenceType, IDLCallable, IDLConstant, SignatureTag, IDLVersion } from "../idl";
2
+ import { IDLCallback, IDLConstructor, IDLEntry, IDLEnum, IDLInterface, IDLMethod, IDLParameter, IDLProperty, IDLTypedef, IDLNamespace, IDLFile, IDLImport, IDLCallable, IDLConstant, SignatureTag, IDLVersion } from "../idl";
3
3
  import { Language } from "../Language";
4
+ import { ReferenceResolver } from "../peer-generation/ReferenceResolver";
4
5
  export declare class CustomPrintVisitor {
5
6
  private resolver;
6
7
  private language;
7
8
  output: string[];
8
- constructor(resolver: (type: IDLReferenceType) => IDLEntry | undefined, language: Language);
9
+ constructor(resolver: ReferenceResolver, language: Language);
9
10
  currentInterface?: IDLInterface;
10
11
  visit(node: IDLEntry, wrapNamespaces?: boolean): void;
11
12
  printMetadata(node: IDLEnum): void;
@@ -12,12 +12,13 @@
12
12
  * See the License for the specific language governing permissions and
13
13
  * limitations under the License.
14
14
  */
15
- import { indentedBy, isInNamespace } from "../util";
16
- import { IDLEntity, IDLKind, getExtAttribute, getVerbatimDts, hasExtAttribute, isCallback, isConstructor, isContainerType, isEnum, isInterface, isMethod, isPrimitiveType, isProperty, isReferenceType, isSyntheticEntry, isTypeParameterType, isTypedef, isUnionType, isImport, isVersion, isNamespace, IDLExtendedAttributes, IDLAccessorAttribute, IDLVoidType, IDLStringType, IDLUndefinedType, isCallable, IDLAnyType, IDLContainerUtils, DebugUtils, mixMethodParametersAndTags, createReferenceType, transformMethodsAsync2ReturnPromise, linearizeNamespaceMembers, isNamedNode, IDLThisType, isOptionalType, IDLI8Type, IDLU8Type, IDLI16Type, IDLU16Type, IDLI32Type, IDLU32Type, IDLI64Type, IDLU64Type, IDLF16Type, IDLF32Type, IDLF64Type, IDLBufferType, IDLUnknownType, IDLBooleanType, IDLNumberType, IDLPointerType, IDLInterfaceSubkind, escapeIDLKeyword, getNamespacesPathFor, IDLBigintType, IDLDate, IDLFunctionType, getQualifiedName, IDLObjectType, isConstant, } from "../idl";
17
- import { resolveSyntheticType, parseIDLFile } from "./deserialize";
15
+ import { indentedBy } from "../util";
16
+ import { IDLEntity, IDLKind, getExtAttribute, getVerbatimDts, hasExtAttribute, isCallback, isConstructor, isContainerType, isEnum, isInterface, isMethod, isPrimitiveType, isProperty, isReferenceType, isSyntheticEntry, isTypeParameterType, isTypedef, isUnionType, isImport, isVersion, isNamespace, IDLExtendedAttributes, IDLAccessorAttribute, IDLVoidType, IDLStringType, IDLUndefinedType, isCallable, IDLAnyType, IDLContainerUtils, DebugUtils, mixMethodParametersAndTags, createReferenceType, transformMethodsAsync2ReturnPromise, linearizeNamespaceMembers, isNamedNode, IDLThisType, isOptionalType, IDLI8Type, IDLU8Type, IDLI16Type, IDLU16Type, IDLI32Type, IDLU32Type, IDLI64Type, IDLU64Type, IDLF16Type, IDLF32Type, IDLF64Type, IDLBufferType, IDLUnknownType, IDLBooleanType, IDLNumberType, IDLPointerType, IDLInterfaceSubkind, escapeIDLKeyword, getNamespacesPathFor, IDLBigintType, IDLDate, IDLFunctionType, getQualifiedName, IDLObjectType, isConstant, isInNamespace, } from "../idl";
17
+ import { parseIDLFile } from "./deserialize";
18
18
  import { Language } from "../Language";
19
19
  import { warn } from "../util";
20
20
  import { isInIdlize } from "../idl";
21
+ import { maybeRestoreThrows } from "../transformers/transformUtils";
21
22
  export class CustomPrintVisitor {
22
23
  constructor(resolver, language) {
23
24
  this.resolver = resolver;
@@ -208,7 +209,7 @@ export class CustomPrintVisitor {
208
209
  // Let's skip imported declarations
209
210
  if (isTypedef(node) &&
210
211
  hasExtAttribute(node, IDLExtendedAttributes.Import)) {
211
- let definition = this.resolver(createReferenceType(node));
212
+ let definition = this.resolver.resolveTypeReference(createReferenceType(node));
212
213
  // TODO: handle namespace case better!
213
214
  // TODO: namespace-related-to-rework
214
215
  //throw new Error("not implemented yet")
@@ -269,8 +270,10 @@ export class CustomPrintVisitor {
269
270
  this.output.push(this.indented(value));
270
271
  }
271
272
  printTypeForTS(type, undefinedToVoid, sequenceToArrayInterface = false, isCommonMethod = false) {
273
+ var _a;
272
274
  if (!type)
273
275
  throw new Error("Missing type");
276
+ type = (_a = maybeRestoreThrows(type, this.resolver)) !== null && _a !== void 0 ? _a : type;
274
277
  if (isOptionalType(type))
275
278
  return `${this.printTypeForTS(type.type, undefinedToVoid, sequenceToArrayInterface)} | undefined`;
276
279
  if (isPrimitiveType(type)) {
@@ -320,7 +323,7 @@ export class CustomPrintVisitor {
320
323
  toTypeName(node) {
321
324
  var _a, _b;
322
325
  if (isReferenceType(node)) {
323
- const decl = this.resolver(node);
326
+ const decl = this.resolver.resolveTypeReference(node);
324
327
  if (decl) {
325
328
  if (isSyntheticEntry(decl)) {
326
329
  if (isInterface(decl)) {
@@ -365,7 +368,7 @@ export class CustomPrintVisitor {
365
368
  }
366
369
  }
367
370
  export function idlToDtsString(name, content) {
368
- let printer = new CustomPrintVisitor(resolveSyntheticType, Language.TS);
371
+ let printer = new CustomPrintVisitor({ resolveTypeReference: () => undefined, toDeclaration: () => IDLVoidType }, Language.TS);
369
372
  const idlFile = parseIDLFile(name, content);
370
373
  printer.printPackage(idlFile);
371
374
  linearizeNamespaceMembers(idlFile.entries).forEach(it => {
@@ -1,5 +1,5 @@
1
1
  import { Location } from "../diagnostictypes";
2
- import { IDLCallable, IDLCallback, IDLConstant, IDLConstructor, IDLContainerKind, IDLContainerType, IDLEntry, IDLEnum, IDLEnumMember, IDLExtendedAttribute, IDLFile, IDLImport, IDLInterface, IDLInterfaceSubkind, IDLMethod, IDLNamespace, IDLOptionalType, IDLParameter, IDLPrimitiveType, IDLProperty, IDLReferenceType, IDLType, IDLTypedef, IDLTypeParameterType, IDLUnionType, IDLVersion } from "./node";
2
+ import { IDLCallable, IDLCallback, IDLConstant, IDLConstructor, IDLContainerKind, IDLContainerType, IDLEntry, IDLEnum, IDLEnumMember, IDLExtendedAttribute, IDLFile, IDLImport, IDLInterface, IDLInterfaceSubkind, IDLMethod, IDLNamespace, IDLNode, IDLOptionalType, IDLParameter, IDLPrimitiveType, IDLProperty, IDLReferenceType, IDLType, IDLTypedef, IDLTypeParameterType, IDLUnionType, IDLVersion } from "./node";
3
3
  export type IDLNodeInitializer = {
4
4
  extendedAttributes?: IDLExtendedAttribute[];
5
5
  fileName?: string;
@@ -40,4 +40,39 @@ export declare function createCallback(name: string, parameters: IDLParameter[],
40
40
  export declare function createTypeParameterReference(name: string, nodeInitializer?: IDLNodeInitializer): IDLTypeParameterType;
41
41
  export declare function createTypedef(name: string, type: IDLType, typeParameters?: string[], nodeInitializer?: IDLNodeInitializer): IDLTypedef;
42
42
  export declare function createConstant(name: string, type: IDLType, value?: string, nodeInitializer?: IDLNodeInitializer): IDLConstant;
43
+ export declare function generateSyntheticIdlNodeName(type: IDLType): string;
44
+ export declare function generateSyntheticUnionName(types: IDLType[]): string;
45
+ export declare const IDLPointerType: IDLPrimitiveType;
46
+ export declare const IDLVoidType: IDLPrimitiveType;
47
+ export declare const IDLBooleanType: IDLPrimitiveType;
48
+ export declare const IDLI8Type: IDLPrimitiveType;
49
+ export declare const IDLU8Type: IDLPrimitiveType;
50
+ export declare const IDLI16Type: IDLPrimitiveType;
51
+ export declare const IDLU16Type: IDLPrimitiveType;
52
+ export declare const IDLI32Type: IDLPrimitiveType;
53
+ export declare const IDLU32Type: IDLPrimitiveType;
54
+ export declare const IDLI64Type: IDLPrimitiveType;
55
+ export declare const IDLU64Type: IDLPrimitiveType;
56
+ export declare const IDLF16Type: IDLPrimitiveType;
57
+ export declare const IDLF32Type: IDLPrimitiveType;
58
+ export declare const IDLF64Type: IDLPrimitiveType;
59
+ export declare const IDLBigintType: IDLPrimitiveType;
60
+ export declare const IDLNumberType: IDLPrimitiveType;
61
+ export declare const IDLStringType: IDLPrimitiveType;
62
+ export declare const IDLAnyType: IDLPrimitiveType;
63
+ export declare const IDLUndefinedType: IDLPrimitiveType;
64
+ export declare const IDLUnknownType: IDLPrimitiveType;
65
+ export declare const IDLObjectType: IDLPrimitiveType;
66
+ export declare const IDLThisType: IDLPrimitiveType;
67
+ export declare const IDLDate: IDLPrimitiveType;
68
+ export declare const IDLBufferType: IDLPrimitiveType;
69
+ export declare const IDLUint8ArrayType: IDLContainerType;
70
+ export declare const IDLSerializerBuffer: IDLPrimitiveType;
71
+ export declare const IDLFunctionType: IDLPrimitiveType;
72
+ export declare const IDLCustomObjectType: IDLPrimitiveType;
73
+ export declare const IDLInteropReturnBufferType: IDLPrimitiveType;
74
+ export declare const IDLNullTypeName = "idlize.stdlib.Null";
75
+ export declare const IDLThrowsTypeName = "idlize.stdlib.Throws";
76
+ export declare function isUndefinedType(type: IDLNode): type is IDLPrimitiveType;
77
+ export declare function isVoidType(type: IDLNode): type is IDLPrimitiveType;
43
78
  //# sourceMappingURL=builders.d.ts.map
@@ -12,8 +12,8 @@
12
12
  * See the License for the specific language governing permissions and
13
13
  * limitations under the License.
14
14
  */
15
- import { generateSyntheticIdlNodeName } from "../peer-generation/idl/common";
16
- import { isOptionalType, getFQName } from "./discriminators";
15
+ import { capitalize } from "../util";
16
+ import { isOptionalType, getFQName, isContainerType, isNamedNode, isPrimitiveType } from "./discriminators";
17
17
  import { IDLKind } from "./node";
18
18
  const innerIdlSymbol = Symbol("innerIdlSymbol");
19
19
  export function createPrimitiveType(name) {
@@ -132,4 +132,64 @@ export function createConstant(name, type, value, nodeInitializer = {}) {
132
132
  type,
133
133
  value }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
134
134
  }
135
+ export function generateSyntheticIdlNodeName(type) {
136
+ if (isPrimitiveType(type))
137
+ return capitalize(type.name);
138
+ if (isContainerType(type)) {
139
+ const typeArgs = type.elementType.map(it => generateSyntheticIdlNodeName(it)).join("_").replaceAll(".", "_");
140
+ switch (type.containerKind) {
141
+ case "sequence": return "Array_" + typeArgs;
142
+ case "record": return "Map_" + typeArgs;
143
+ case "Promise": return "Promise_" + typeArgs;
144
+ default: throw new Error(`Unknown container type ${type.containerKind}`);
145
+ }
146
+ }
147
+ if (isNamedNode(type))
148
+ return type.name.split('.').map(capitalize).join('_');
149
+ if (isOptionalType(type))
150
+ return `Opt_${generateSyntheticIdlNodeName(type.type)}`;
151
+ throw `Can not compute type name of ${IDLKind[type.kind]}`;
152
+ }
153
+ export function generateSyntheticUnionName(types) {
154
+ return `Union_${types.map(it => generateSyntheticIdlNodeName(it)).join("_").replaceAll(".", "_")}`;
155
+ }
156
+ /// STANDARD LIBRARY
157
+ export const IDLPointerType = createPrimitiveType('pointer');
158
+ export const IDLVoidType = createPrimitiveType('void');
159
+ export const IDLBooleanType = createPrimitiveType('boolean');
160
+ export const IDLI8Type = createPrimitiveType('i8');
161
+ export const IDLU8Type = createPrimitiveType('u8');
162
+ export const IDLI16Type = createPrimitiveType('i16');
163
+ export const IDLU16Type = createPrimitiveType('u16');
164
+ export const IDLI32Type = createPrimitiveType('i32');
165
+ export const IDLU32Type = createPrimitiveType('u32');
166
+ export const IDLI64Type = createPrimitiveType('i64');
167
+ export const IDLU64Type = createPrimitiveType('u64');
168
+ export const IDLF16Type = createPrimitiveType('f16');
169
+ export const IDLF32Type = createPrimitiveType('f32');
170
+ export const IDLF64Type = createPrimitiveType('f64');
171
+ export const IDLBigintType = createPrimitiveType("bigint");
172
+ export const IDLNumberType = createPrimitiveType('number');
173
+ export const IDLStringType = createPrimitiveType('String');
174
+ export const IDLAnyType = createPrimitiveType('any');
175
+ export const IDLUndefinedType = createPrimitiveType('undefined');
176
+ export const IDLUnknownType = createPrimitiveType('unknown');
177
+ export const IDLObjectType = createPrimitiveType('Object');
178
+ export const IDLThisType = createPrimitiveType('this');
179
+ export const IDLDate = createPrimitiveType('date');
180
+ export const IDLBufferType = createPrimitiveType('buffer');
181
+ export const IDLUint8ArrayType = createContainerType('sequence', [IDLU8Type]);
182
+ export const IDLSerializerBuffer = createPrimitiveType('SerializerBuffer');
183
+ // Stub for IdlPeerLibrary
184
+ export const IDLFunctionType = createPrimitiveType('Function');
185
+ export const IDLCustomObjectType = createPrimitiveType('CustomObject');
186
+ export const IDLInteropReturnBufferType = createPrimitiveType('InteropReturnBuffer');
187
+ export const IDLNullTypeName = "idlize.stdlib.Null";
188
+ export const IDLThrowsTypeName = "idlize.stdlib.Throws";
189
+ export function isUndefinedType(type) {
190
+ return isPrimitiveType(type) && type.name === IDLUndefinedType.name;
191
+ }
192
+ export function isVoidType(type) {
193
+ return isPrimitiveType(type) && type.name === IDLVoidType.name;
194
+ }
135
195
  //# sourceMappingURL=builders.js.map
@@ -44,5 +44,8 @@ export interface IDLPrintOptions {
44
44
  allowUnknownKinds: boolean;
45
45
  }
46
46
  export declare function toIDLString(file: IDLFile, options: Partial<IDLPrintOptions>): string;
47
+ export declare const DebugUtils: {
48
+ debugPrintType: (type: IDLType) => string;
49
+ };
47
50
  export {};
48
51
  //# sourceMappingURL=dump.d.ts.map
@@ -13,10 +13,10 @@
13
13
  * limitations under the License.
14
14
  */
15
15
  import { IndentedPrinter } from "../IndentedPrinter";
16
+ import { IDLNullTypeName, IDLStringType, IDLUndefinedType } from "./builders";
16
17
  import { isInterface, isOptionalType, isPrimitiveType, isContainerType, isReferenceType, isUnionType, isTypeParameterType, hasExtAttribute } from "./discriminators";
17
18
  import { IDLKeywords } from "./keywords";
18
19
  import { IDLExtendedAttributes, IDLKind } from "./node";
19
- import { IDLNullTypeName, IDLUndefinedType, IDLStringType } from "./stdlib";
20
20
  export function escapeIDLKeyword(name) {
21
21
  return name + (IDLKeywords.has(name) ? "_" : "");
22
22
  }
@@ -43,8 +43,16 @@ export function printType(type, options) {
43
43
  }
44
44
  if (isPrimitiveType(type))
45
45
  return type.name;
46
- if (isContainerType(type))
47
- return `${type.containerKind}<${type.elementType.map(it => printType(it)).join(", ")}>`;
46
+ if (isContainerType(type)) {
47
+ const maybeExtendedAttributes = type.extendedAttributes && type.extendedAttributes.length
48
+ ? `[${quoteAttributeValues(type.extendedAttributes)}] `
49
+ : '';
50
+ const res = `${maybeExtendedAttributes}${type.containerKind}<${type.elementType.map(it => printType(it)).join(", ")}>`;
51
+ if (maybeExtendedAttributes.length) {
52
+ return `(${res})`;
53
+ }
54
+ return res;
55
+ }
48
56
  if (isReferenceType(type)) {
49
57
  const maybeExtendedAttributes = type.extendedAttributes && type.extendedAttributes.length
50
58
  ? `[${quoteAttributeValues(type.extendedAttributes)}] `
@@ -325,4 +333,13 @@ export function toIDLString(file, options) {
325
333
  file.entries.forEach(it => writer.printIDL(it, options));
326
334
  return writer.getOutput().join("\n");
327
335
  }
336
+ export const DebugUtils = {
337
+ debugPrintType: (type) => {
338
+ const filename = type.fileName ? `, fileName: '${type.fileName}'` : "";
339
+ if (isContainerType(type)) {
340
+ return `[IDLType, name: '${printType(type)}', kind: '${IDLKind[type.kind]}', elements: [${type.elementType.map(DebugUtils.debugPrintType).join(', ')}]${filename}]`;
341
+ }
342
+ return `[IDLType, name: '${printType(type)}', kind: '${IDLKind[type.kind]}'${filename}]`;
343
+ },
344
+ };
328
345
  //# sourceMappingURL=dump.js.map
@@ -3,7 +3,6 @@ export * from './discriminators';
3
3
  export * from './dump';
4
4
  export * from './keywords';
5
5
  export * from './node';
6
- export * from './stdlib';
7
6
  export * from './utils';
8
7
  export * from './visitors';
9
8
  //# sourceMappingURL=index.d.ts.map
@@ -17,7 +17,6 @@ export * from './discriminators';
17
17
  export * from './dump';
18
18
  export * from './keywords';
19
19
  export * from './node';
20
- export * from './stdlib';
21
20
  export * from './utils';
22
21
  export * from './visitors';
23
22
  //# sourceMappingURL=index.js.map
@@ -35,6 +35,7 @@ export declare enum IDLExtendedAttributes {
35
35
  Accessor = "Accessor",
36
36
  Annotations = "Annotations",
37
37
  Async = "Async",
38
+ AsRecord = "AsRecord",
38
39
  CallSignature = "CallSignature",
39
40
  CommonMethod = "CommonMethod",
40
41
  Component = "Component",
@@ -51,6 +51,7 @@ export var IDLExtendedAttributes;
51
51
  IDLExtendedAttributes["Accessor"] = "Accessor";
52
52
  IDLExtendedAttributes["Annotations"] = "Annotations";
53
53
  IDLExtendedAttributes["Async"] = "Async";
54
+ IDLExtendedAttributes["AsRecord"] = "AsRecord";
54
55
  IDLExtendedAttributes["CallSignature"] = "CallSignature";
55
56
  IDLExtendedAttributes["CommonMethod"] = "CommonMethod";
56
57
  IDLExtendedAttributes["Component"] = "Component";
@@ -29,6 +29,7 @@ export declare const IDLFunctionType: IDLPrimitiveType;
29
29
  export declare const IDLCustomObjectType: IDLPrimitiveType;
30
30
  export declare const IDLInteropReturnBufferType: IDLPrimitiveType;
31
31
  export declare const IDLNullTypeName = "idlize.stdlib.Null";
32
+ export declare const IDLThrowsTypeName = "idlize.stdlib.Throws";
32
33
  export declare function isUndefinedType(type: IDLNode): type is IDLPrimitiveType;
33
34
  export declare function isVoidType(type: IDLNode): type is IDLPrimitiveType;
34
35
  //# sourceMappingURL=stdlib.d.ts.map
@@ -45,6 +45,7 @@ export const IDLFunctionType = createPrimitiveType('Function');
45
45
  export const IDLCustomObjectType = createPrimitiveType('CustomObject');
46
46
  export const IDLInteropReturnBufferType = createPrimitiveType('InteropReturnBuffer');
47
47
  export const IDLNullTypeName = "idlize.stdlib.Null";
48
+ export const IDLThrowsTypeName = "idlize.stdlib.Throws";
48
49
  export function isUndefinedType(type) {
49
50
  return isPrimitiveType(type) && type.name === IDLUndefinedType.name;
50
51
  }
@@ -1,6 +1,7 @@
1
1
  import { stringOrNone } from "../util";
2
2
  import { QNPattern } from "./discriminators";
3
3
  import { IDLNode, IDLNamedNode, IDLType, IDLEntry, IDLReferenceType, IDLContainerType, IDLSignature, IDLParameter, IDLEnum, IDLFile } from "./node";
4
+ import { Language } from "../Language";
4
5
  export declare function entityToType(entity: IDLNode): IDLType;
5
6
  export declare function forceAsNamedNode(type: IDLNode): IDLNamedNode;
6
7
  export declare function isEqualByQualifedName(a?: IDLNamedNode, b?: IDLNamedNode, pattern?: QNPattern): boolean;
@@ -12,9 +13,6 @@ export declare function decomposeQualifiedName(type: IDLReferenceType): [string
12
13
  export declare function qualifiedNameStartsWith(node: IDLNode | string[], template: string[]): boolean;
13
14
  export declare function maybeUnwrapOptionalType(type: IDLType): IDLType;
14
15
  export declare function maybeOptional(type: IDLType, optional?: boolean): IDLType;
15
- export declare const DebugUtils: {
16
- debugPrintType: (type: IDLType) => string;
17
- };
18
16
  export declare function asPromise(type?: IDLType): IDLContainerType | undefined;
19
17
  export declare function transformMethodsAsync2ReturnPromise(entry: IDLEntry): void;
20
18
  export declare function transformMethodsReturnPromise2Async(entry: IDLEntry): void;
@@ -41,4 +39,7 @@ export declare function hasTypeParameters(entry: IDLEntry): boolean;
41
39
  export declare function isGeneric(entry: IDLEntry): entry is IDLEntry & {
42
40
  typeParameters?: string[];
43
41
  };
42
+ export declare function snakeToLowCamelNode(node: IDLEntry): string;
43
+ export declare function entryToFunctionName(_language: Language, declaration: IDLEntry, prefix: string, postfix: string): string;
44
+ export declare function isInNamespace(node: IDLEntry): boolean;
44
45
  //# sourceMappingURL=utils.d.ts.map