@idlizer/core 2.1.5 → 2.1.9-arktscgen-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 (75) hide show
  1. package/build/lib/src/IndentedPrinter.js +2 -0
  2. package/build/lib/src/Language.d.ts +1 -0
  3. package/build/lib/src/Language.js +3 -0
  4. package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +18 -4
  5. package/build/lib/src/LanguageWriters/ArgConvertors.js +162 -26
  6. package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +38 -8
  7. package/build/lib/src/LanguageWriters/LanguageWriter.js +46 -4
  8. package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +1 -0
  9. package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +37 -14
  10. package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +1 -0
  11. package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +55 -54
  12. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +1 -1
  13. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +2 -2
  14. package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +1 -0
  15. package/build/lib/src/LanguageWriters/convertors/KotlinConvertor.d.ts +24 -0
  16. package/build/lib/src/LanguageWriters/convertors/KotlinConvertor.js +69 -0
  17. package/build/lib/src/LanguageWriters/convertors/KotlinConvertors.d.ts +25 -0
  18. package/build/lib/src/LanguageWriters/convertors/KotlinConvertors.js +128 -0
  19. package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +4 -2
  20. package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +44 -9
  21. package/build/lib/src/LanguageWriters/index.js +4 -0
  22. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +12 -7
  23. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +43 -27
  24. package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.d.ts +1 -1
  25. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +11 -2
  26. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +43 -10
  27. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +5 -2
  28. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +45 -11
  29. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +2 -2
  30. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +3 -3
  31. package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.d.ts +149 -0
  32. package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.js +495 -0
  33. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +8 -5
  34. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +17 -13
  35. package/build/lib/src/LibraryInterface.d.ts +2 -0
  36. package/build/lib/src/config.d.ts +673 -44
  37. package/build/lib/src/config.js +20 -0
  38. package/build/lib/src/configDescriber.d.ts +2 -2
  39. package/build/lib/src/configDescriber.js +3 -3
  40. package/build/lib/src/from-idl/DtsPrinter.js +12 -8
  41. package/build/lib/src/from-idl/IDLLinter.d.ts +0 -1
  42. package/build/lib/src/from-idl/IDLLinter.js +1 -7
  43. package/build/lib/src/from-idl/deserialize.d.ts +7 -1
  44. package/build/lib/src/from-idl/deserialize.js +72 -40
  45. package/build/lib/src/idl.d.ts +8 -15
  46. package/build/lib/src/idl.js +69 -72
  47. package/build/lib/src/idlize.js +2 -0
  48. package/build/lib/src/index.d.ts +2 -0
  49. package/build/lib/src/index.js +2 -0
  50. package/build/lib/src/peer-generation/LayoutManager.d.ts +4 -1
  51. package/build/lib/src/peer-generation/LayoutManager.js +5 -1
  52. package/build/lib/src/peer-generation/Materialized.d.ts +7 -3
  53. package/build/lib/src/peer-generation/Materialized.js +18 -4
  54. package/build/lib/src/peer-generation/PeerLibrary.d.ts +5 -2
  55. package/build/lib/src/peer-generation/PeerLibrary.js +30 -10
  56. package/build/lib/src/peer-generation/PeerMethod.d.ts +1 -1
  57. package/build/lib/src/peer-generation/getSuperType.d.ts +5 -0
  58. package/build/lib/src/peer-generation/getSuperType.js +55 -0
  59. package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +4 -0
  60. package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +7 -0
  61. package/build/lib/src/peer-generation/idl/common.d.ts +1 -0
  62. package/build/lib/src/peer-generation/idl/common.js +9 -3
  63. package/build/lib/src/peer-generation/isExternalType.d.ts +4 -0
  64. package/build/lib/src/peer-generation/isExternalType.js +15 -0
  65. package/build/lib/src/peer-generation/isMaterialized.js +18 -6
  66. package/build/lib/src/peer-generation/unions.js +1 -1
  67. package/build/lib/src/util.d.ts +4 -1
  68. package/build/lib/src/util.js +25 -10
  69. package/build/lib/src/visitor.d.ts +2 -0
  70. package/build/lib/src/visitor.js +108 -1
  71. package/package.json +2 -2
  72. package/webidl2.js/dist/webidl2.js +62 -16
  73. package/webidl2.js/LICENSE +0 -21
  74. package/webidl2.js/README.md +0 -827
  75. package/webidl2.js/dist/package.json +0 -3
@@ -13,6 +13,7 @@
13
13
  * limitations under the License.
14
14
  */
15
15
  import { D } from "./configDescriber";
16
+ import { capitalize } from "./util";
16
17
  const T = {
17
18
  stringArray: () => D.array(D.string())
18
19
  };
@@ -21,6 +22,9 @@ export const ModuleConfigurationSchema = D.object({
21
22
  packages: T.stringArray(),
22
23
  useFoldersLayout: D.maybe(D.boolean()),
23
24
  });
25
+ export const HookMethodSchema = D.object({
26
+ hookName: D.string(),
27
+ });
24
28
  export const CoreConfigurationSchema = D.object({
25
29
  TypePrefix: D.string(),
26
30
  LibraryPrefix: D.string(),
@@ -34,6 +38,9 @@ export const CoreConfigurationSchema = D.object({
34
38
  forceCallback: D.map(D.string(), T.stringArray()).onMerge('replace'),
35
39
  forceResource: T.stringArray(),
36
40
  forceContext: T.stringArray(),
41
+ hooks: D.map(D.string(), D.map(D.string(), HookMethodSchema)).onMerge('replace'),
42
+ externalTypes: D.map(D.string(), D.string()).onMerge('replace'),
43
+ externalPackages: T.stringArray(),
37
44
  moduleName: D.string(),
38
45
  modules: D.map(D.string(), ModuleConfigurationSchema).onMerge('replace'),
39
46
  globalPackages: T.stringArray()
@@ -51,6 +58,9 @@ export const defaultCoreConfiguration = {
51
58
  forceCallback: new Map(),
52
59
  forceResource: [],
53
60
  forceContext: [],
61
+ hooks: new Map(),
62
+ externalTypes: new Map(),
63
+ externalPackages: [],
54
64
  moduleName: "",
55
65
  modules: new Map(),
56
66
  globalPackages: []
@@ -69,4 +79,14 @@ export function generatorTypePrefix() {
69
79
  const conf = generatorConfiguration();
70
80
  return `${conf.TypePrefix}${conf.LibraryPrefix}`;
71
81
  }
82
+ export function generatorHookName(className, methodName) {
83
+ var _a;
84
+ const hookMethods = generatorConfiguration().hooks.get(className);
85
+ if (!hookMethods)
86
+ return undefined;
87
+ const hook = hookMethods.get(methodName);
88
+ if (!hook)
89
+ return undefined;
90
+ return (_a = hook.hookName) !== null && _a !== void 0 ? _a : `hook${className}${capitalize(methodName)}`;
91
+ }
72
92
  //# sourceMappingURL=config.js.map
@@ -49,7 +49,7 @@ declare class ValidationBox<T> {
49
49
  static fail<T>(errorMessage: string): ValidationBox<T>;
50
50
  static ok<T>(value: T): ValidationBox<T>;
51
51
  success(): boolean;
52
- unwrap(): T;
52
+ unwrap(message?: string): T;
53
53
  error(): string;
54
54
  get(): ValidationResult<T>;
55
55
  or<U>(x: U): ValidationBox<U | T>;
@@ -102,7 +102,7 @@ export declare const D: {
102
102
  string<T_3 extends string>(x: T_3): ConfigDescriberLeaf<T_3>;
103
103
  number<T_4 extends number>(x: T_4): ConfigDescriberLeaf<T_4>;
104
104
  boolean<T_5 extends boolean>(x: T_5): ConfigDescriberLeaf<T_5>;
105
- null(x: null): ConfigDescriberLeaf<null>;
105
+ null(): ConfigDescriberLeaf<null>;
106
106
  };
107
107
  combine<A, B>(a: ConfigDescriberObjectLeaf<A>, b: ConfigDescriberObjectLeaf<B>): ConfigDescriberObjectLeaf<A & B>;
108
108
  printJSONSchema<T_6>(schema: ConfigDescriberLeaf<T_6>): string;
@@ -26,11 +26,11 @@ class ValidationBox {
26
26
  success() {
27
27
  return this.box.success;
28
28
  }
29
- unwrap() {
29
+ unwrap(message) {
30
30
  if (this.box.success) {
31
31
  return this.box.value;
32
32
  }
33
- throw new Error("");
33
+ throw new Error(message !== null && message !== void 0 ? message : 'panic');
34
34
  }
35
35
  error() {
36
36
  if (!this.box.success) {
@@ -347,7 +347,7 @@ export const D = {
347
347
  };
348
348
  });
349
349
  },
350
- null(x) {
350
+ null() {
351
351
  return new ConfigDescriberLeaf(xs => {
352
352
  if (typeof xs === 'object' && xs === null) {
353
353
  return ValidationBox.ok(null);
@@ -13,7 +13,7 @@
13
13
  * limitations under the License.
14
14
  */
15
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, getSuperType, IDLAnyType, IDLContainerUtils, DebugUtils, mixMethodParametersAndTags, createReferenceType, transformMethodsAsync2ReturnPromise, linearizeNamespaceMembers, isNamedNode, IDLThisType, isOptionalType, IDLI8Type, IDLU8Type, IDLI16Type, IDLU16Type, IDLI32Type, IDLU32Type, IDLI64Type, IDLU64Type, IDLF16Type, IDLF32Type, IDLF64Type, IDLBufferType, isUnspecifiedGenericType, IDLUnknownType, IDLBooleanType, IDLNumberType, IDLPointerType, IDLInterfaceSubkind, escapeIDLKeyword, getNamespacesPathFor, IDLBigintType, IDLDate, IDLFunctionType, getQualifiedName } from "../idl";
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, isUnspecifiedGenericType, IDLUnknownType, IDLBooleanType, IDLNumberType, IDLPointerType, IDLInterfaceSubkind, escapeIDLKeyword, getNamespacesPathFor, IDLBigintType, IDLDate, IDLFunctionType, getQualifiedName, IDLObjectType } from "../idl";
17
17
  import { resolveSyntheticType, toIDLFile } from "./deserialize";
18
18
  import { Language } from "../Language";
19
19
  import { warn } from "../util";
@@ -103,7 +103,7 @@ export class CustomPrintVisitor {
103
103
  let interfaces = node.inheritance;
104
104
  let keyword = "extends";
105
105
  if (node.subkind === IDLInterfaceSubkind.Class) {
106
- const superType = getSuperType(node);
106
+ const superType = node.inheritance.find(it => hasExtAttribute(it, IDLExtendedAttributes.Extends));
107
107
  if (superType)
108
108
  typeSpec += ` extends ${this.printTypeForTS(superType)}`;
109
109
  interfaces = interfaces.slice(1);
@@ -129,8 +129,11 @@ export class CustomPrintVisitor {
129
129
  }
130
130
  }
131
131
  printMethod(node, forceAsFree = false) {
132
- const returnType = node.returnType && !(isConstructor(node) && this.currentInterface.subkind === IDLInterfaceSubkind.Class)
132
+ let returnType = node.returnType && !(isConstructor(node) && this.currentInterface.subkind === IDLInterfaceSubkind.Class)
133
133
  ? `: ${this.printTypeForTS(node.returnType, true)}` : "";
134
+ if (hasExtAttribute(node, IDLExtendedAttributes.CommonMethod)) {
135
+ returnType = `: ${this.currentInterface.name}`;
136
+ }
134
137
  const name = isConstructor(node)
135
138
  ? this.currentInterface.subkind === IDLInterfaceSubkind.Class ? "constructor" : "new"
136
139
  : getName(node);
@@ -188,11 +191,11 @@ export class CustomPrintVisitor {
188
191
  this.print(`${isInNamespace(node) ? "" : "declare "}enum ${node.name} {`);
189
192
  this.pushIndent();
190
193
  node.elements.forEach(it => {
191
- const initializer = (it.type === IDLStringType ? `"${it.initializer}"` : `${it.initializer}`);
192
- this.print(`${getName(it)} = ${initializer},`);
194
+ const initializer = it.initializer ? (it.type === IDLStringType ? ` = "${it.initializer}"` : ` = ${it.initializer}`) : "";
195
+ this.print(`${getName(it)}${initializer},`);
193
196
  let originalName = getExtAttribute(it, IDLExtendedAttributes.OriginalEnumMemberName);
194
197
  if (originalName && originalName != getName(it)) {
195
- this.print(`${originalName} = ${initializer},`);
198
+ this.print(`${originalName}${initializer},`);
196
199
  }
197
200
  });
198
201
  this.popIndent();
@@ -283,13 +286,14 @@ export class CustomPrintVisitor {
283
286
  case IDLNumberType:
284
287
  return "number";
285
288
  case IDLAnyType: return "any";
289
+ case IDLObjectType: return "Object";
286
290
  case IDLUnknownType: return "unknown";
287
291
  case IDLBufferType: return "ArrayBuffer";
288
292
  case IDLBooleanType: return "boolean";
289
293
  case IDLUndefinedType: return undefinedToVoid ? "void" : "undefined";
290
294
  case IDLStringType: return "string";
291
295
  case IDLVoidType: return "void";
292
- case IDLThisType: return "T";
296
+ case IDLThisType: return this.currentInterface.name;
293
297
  case IDLBigintType:
294
298
  case IDLPointerType: return "number|bigint";
295
299
  case IDLDate: return "Date";
@@ -355,7 +359,7 @@ export class CustomPrintVisitor {
355
359
  }
356
360
  export function idlToDtsString(name, content) {
357
361
  let printer = new CustomPrintVisitor(resolveSyntheticType, Language.TS);
358
- const [idlFile] = toIDLFile(name, content);
362
+ const [idlFile] = toIDLFile(name, { content });
359
363
  printer.printPackage(idlFile);
360
364
  linearizeNamespaceMembers(idlFile.entries).forEach(it => {
361
365
  transformMethodsAsync2ReturnPromise(it);
@@ -39,7 +39,6 @@ export declare class IDLLinter {
39
39
  protected check(node: idl.IDLNode): void;
40
40
  protected checkValidAttributes(entry: idl.IDLEntry, validAttributes: string[]): void;
41
41
  protected checkEnumConsistency(entry: idl.IDLEnum): void;
42
- private static builtinReferences;
43
42
  protected checkReferenceResolved(reference: idl.IDLReferenceType): void;
44
43
  }
45
44
  interface IDLLinterDiagnosticsSummary {
@@ -67,7 +67,7 @@ export class IDLLinter {
67
67
  }
68
68
  enter(node) {
69
69
  var _a, _b;
70
- if (idl.isInterface(node) || idl.isTypedef(node) || idl.isMethod(node) || idl.isCallable(node)) {
70
+ if (idl.isInterface(node) || idl.isTypedef(node) || idl.isMethod(node) || idl.isCallable(node) || idl.isCallback(node)) {
71
71
  this.context.enter({ typeParameters: new Set((_b = (_a = node.typeParameters) === null || _a === void 0 ? void 0 : _a.map(parseTypeParameter)) !== null && _b !== void 0 ? _b : []) });
72
72
  return () => this.context.leave();
73
73
  }
@@ -129,8 +129,6 @@ export class IDLLinter {
129
129
  }
130
130
  checkReferenceResolved(reference) {
131
131
  var _a, _b, _c, _d, _e, _f;
132
- if (IDLLinter.builtinReferences.includes(reference.name))
133
- return;
134
132
  if (this.context.hasTypeParameter(reference.name)) {
135
133
  return;
136
134
  }
@@ -156,10 +154,6 @@ export class IDLLinter {
156
154
  }
157
155
  }
158
156
  }
159
- IDLLinter.builtinReferences = [
160
- idl.IDLTopType.name,
161
- idl.IDLObjectType.name,
162
- ];
163
157
  export class IDLLinterError extends Error {
164
158
  constructor(message, size) {
165
159
  super(message);
@@ -4,5 +4,11 @@ export type WebIDLTokenCollection = Record<string, webidl2.Token | null | undefi
4
4
  export type IDLTokenInfoMap = Map<unknown, WebIDLTokenCollection>;
5
5
  export declare function addSyntheticType(name: string, type: idl.IDLEntry): void;
6
6
  export declare function resolveSyntheticType(type: idl.IDLReferenceType): idl.IDLEntry | undefined;
7
- export declare function toIDLFile(fileName: string, content?: string): [idl.IDLFile, IDLTokenInfoMap];
7
+ type IDLInheritanceMode = 'single' | 'multiple';
8
+ interface ToIDLFileProps {
9
+ inheritanceMode?: IDLInheritanceMode;
10
+ content?: string;
11
+ }
12
+ export declare function toIDLFile(fileName: string, { content, inheritanceMode }?: ToIDLFileProps): [idl.IDLFile, IDLTokenInfoMap];
13
+ export {};
8
14
  //# sourceMappingURL=deserialize.d.ts.map
@@ -33,8 +33,12 @@ export function resolveSyntheticType(type) {
33
33
  return syntheticTypes.get(type.name);
34
34
  }
35
35
  class IDLDeserializer {
36
- constructor(info) {
36
+ enterGenericScope(generics) {
37
+ this.genericsScopes.push(new Set(generics !== null && generics !== void 0 ? generics : []));
38
+ }
39
+ constructor(info, inheritanceMode = 'multiple') {
37
40
  this.info = info;
41
+ this.inheritanceMode = inheritanceMode;
38
42
  this.namespacePathNames = [];
39
43
  this.currentPackage = [];
40
44
  this.genericsScopes = [];
@@ -61,7 +65,7 @@ class IDLDeserializer {
61
65
  }
62
66
  extractGenerics(extAttrs) {
63
67
  var _a, _b;
64
- return new Set((_b = (_a = this.findExtendedAttribute(extAttrs, idl.IDLExtendedAttributes.TypeParameters)) === null || _a === void 0 ? void 0 : _a.split(",")) === null || _b === void 0 ? void 0 : _b.map(it => this.sanitizeTypeParameter(it)));
68
+ return (_b = (_a = this.findExtendedAttribute(extAttrs, idl.IDLExtendedAttributes.TypeParameters)) === null || _a === void 0 ? void 0 : _a.split(",")) === null || _b === void 0 ? void 0 : _b.map(it => this.sanitizeTypeParameter(it));
65
69
  }
66
70
  ///
67
71
  toIDLNode(file, node) {
@@ -107,34 +111,38 @@ class IDLDeserializer {
107
111
  throw new Error(`unexpected node type: ${toString(node)}`);
108
112
  }
109
113
  toIDLImport(node) {
110
- // console.log(node)
111
114
  return this.withInfo(node, idl.createImport(node.clause.split("."), node.alias || undefined));
112
115
  }
113
116
  interfaceSubkind(node) {
114
117
  var _a, _b;
115
118
  const nodeIDLEntity = (_b = (_a = node.extAttrs.find(it => it.name === "Entity")) === null || _a === void 0 ? void 0 : _a.rhs) === null || _b === void 0 ? void 0 : _b.value;
116
- if (nodeIDLEntity == idl.IDLEntity.Class)
117
- return idl.IDLInterfaceSubkind.Class;
118
- if (nodeIDLEntity == idl.IDLEntity.Interface)
119
- return idl.IDLInterfaceSubkind.Interface;
120
- if (nodeIDLEntity == idl.IDLEntity.Tuple)
121
- return idl.IDLInterfaceSubkind.Tuple;
122
- return idl.IDLInterfaceSubkind.Interface;
119
+ switch (nodeIDLEntity) {
120
+ case idl.IDLEntity.Class: return idl.IDLInterfaceSubkind.Class;
121
+ case idl.IDLEntity.Literal: return idl.IDLInterfaceSubkind.AnonymousInterface;
122
+ case idl.IDLEntity.Tuple: return idl.IDLInterfaceSubkind.Tuple;
123
+ default: return idl.IDLInterfaceSubkind.Interface;
124
+ }
123
125
  }
124
126
  toIDLInterface(file, node) {
125
- var _a;
126
127
  const generics = this.extractGenerics(node.extAttrs);
127
- this.genericsScopes.push(generics);
128
- const result = idl.createInterface(node.name, this.interfaceSubkind(node), (() => {
129
- var _a, _b;
130
- if (!node.inheritance)
128
+ this.enterGenericScope(generics);
129
+ const subkind = this.interfaceSubkind(node);
130
+ const result = idl.createInterface(node.name, subkind, (() => {
131
+ if (!node.inheritance) {
131
132
  return [];
132
- const parentTypeArgs = this.extractTypeArguments(file, (_a = node.inheritanceExtAttrs) !== null && _a !== void 0 ? _a : [], idl.IDLExtendedAttributes.TypeArguments);
133
- const parentType = idl.createReferenceType(node.inheritance, parentTypeArgs);
134
- parentType.fileName = file;
135
- if (node.inheritanceExtAttrs)
136
- parentType.extendedAttributes = (_b = this.toExtendedAttributes(node.inheritanceExtAttrs)) === null || _b === void 0 ? void 0 : _b.filter(it => it.name !== idl.IDLExtendedAttributes.TypeArguments);
137
- return [parentType];
133
+ }
134
+ const implementations = [];
135
+ node.inheritance.forEach(it => {
136
+ var _a;
137
+ const attributes = it.extAttrs;
138
+ const parentTypeArgs = this.extractTypeArguments(file, attributes !== null && attributes !== void 0 ? attributes : [], idl.IDLExtendedAttributes.TypeArguments);
139
+ const attrs = (_a = this.toExtendedAttributes(attributes !== null && attributes !== void 0 ? attributes : [])) === null || _a === void 0 ? void 0 : _a.filter(it => it.name !== idl.IDLExtendedAttributes.TypeArguments);
140
+ const ref = idl.createReferenceType(it.inheritance, parentTypeArgs, {
141
+ extendedAttributes: attrs
142
+ });
143
+ implementations.push(ref);
144
+ });
145
+ return implementations;
138
146
  })(), node.members
139
147
  .filter(isConstructor)
140
148
  .map(it => this.toIDLConstructor(file, it)), [], node.members
@@ -145,7 +153,7 @@ class IDLDeserializer {
145
153
  .map(it => this.toIDLMethod(file, it, false)), node.members
146
154
  .filter(isOperation)
147
155
  .filter(it => this.isCallable(it))
148
- .map(it => this.toIDLCallable(file, it)), (_a = this.findExtendedAttribute(node.extAttrs, idl.IDLExtendedAttributes.TypeParameters)) === null || _a === void 0 ? void 0 : _a.split(","), {
156
+ .map(it => this.toIDLCallable(file, it)), generics, {
149
157
  fileName: file,
150
158
  documentation: this.makeDocs(node),
151
159
  extendedAttributes: this.toExtendedAttributes(node.extAttrs),
@@ -158,7 +166,7 @@ class IDLDeserializer {
158
166
  }
159
167
  return result;
160
168
  }
161
- toIDLType(file, type, extAttrs) {
169
+ toIDLType(file, type, extAttrs, suggestedName) {
162
170
  var _a;
163
171
  if (typeof type === "string") {
164
172
  // is it IDLStringType?
@@ -178,7 +186,7 @@ class IDLDeserializer {
178
186
  types = types.filter(it => it !== idl.IDLUndefinedType);
179
187
  return this.withInfo(type, idl.createOptionalType(collapseTypes(types)));
180
188
  }
181
- const name = generateSyntheticUnionName(types);
189
+ const name = suggestedName !== null && suggestedName !== void 0 ? suggestedName : generateSyntheticUnionName(types);
182
190
  return this.withInfo(type, idl.createUnionType(types, name));
183
191
  }
184
192
  if (isSingleTypeDescription(type)) {
@@ -233,12 +241,12 @@ class IDLDeserializer {
233
241
  throw new Error(`unexpected type: ${toString(type)}`);
234
242
  }
235
243
  toIDLCallable(file, node) {
236
- var _a, _b;
244
+ var _a;
237
245
  if (!node.idlType) {
238
246
  throw new Error(`method with no type ${toString(node)}`);
239
247
  }
240
248
  const generics = this.extractGenerics(node.extAttrs);
241
- this.genericsScopes.push(generics);
249
+ this.enterGenericScope(generics);
242
250
  const returnType = this.toIDLType(file, node.idlType, node.extAttrs);
243
251
  if (idl.isReferenceType(returnType)) {
244
252
  const returnTypeArgs = this.extractTypeArguments(file, node.extAttrs, idl.IDLExtendedAttributes.TypeArguments);
@@ -250,17 +258,17 @@ class IDLDeserializer {
250
258
  }, {
251
259
  documentation: this.makeDocs(node),
252
260
  extendedAttributes: this.toExtendedAttributes(node.extAttrs),
253
- }, (_b = this.findExtendedAttribute(node.extAttrs, idl.IDLExtendedAttributes.TypeParameters)) === null || _b === void 0 ? void 0 : _b.split(",")));
261
+ }, generics));
254
262
  this.genericsScopes.pop();
255
263
  return result;
256
264
  }
257
265
  toIDLMethod(file, node, isFree = false) {
258
- var _a, _b;
266
+ var _a;
259
267
  if (!node.idlType) {
260
268
  throw new Error(`method with no type ${toString(node)}`);
261
269
  }
262
270
  const generics = this.extractGenerics(node.extAttrs);
263
- this.genericsScopes.push(generics);
271
+ this.enterGenericScope(generics);
264
272
  const returnType = this.toIDLType(file, node.idlType, node.extAttrs);
265
273
  if (idl.isReferenceType(returnType))
266
274
  returnType.typeArguments = this.extractTypeArguments(file, node.extAttrs, idl.IDLExtendedAttributes.TypeArguments);
@@ -272,7 +280,7 @@ class IDLDeserializer {
272
280
  }, {
273
281
  documentation: this.makeDocs(node),
274
282
  extendedAttributes: this.toExtendedAttributes(node.extAttrs),
275
- }, (_b = this.findExtendedAttribute(node.extAttrs, idl.IDLExtendedAttributes.TypeParameters)) === null || _b === void 0 ? void 0 : _b.split(",")));
283
+ }, generics));
276
284
  this.genericsScopes.pop();
277
285
  return result;
278
286
  }
@@ -287,22 +295,24 @@ class IDLDeserializer {
287
295
  }));
288
296
  }
289
297
  toIDLCallback(file, node) {
298
+ const generics = this.extractGenerics(node.extAttrs);
299
+ this.enterGenericScope(generics);
290
300
  const result = idl.createCallback(node.name, node.arguments.map(it => this.toIDLParameter(file, it)), this.toIDLType(file, node.idlType, undefined), {
291
301
  fileName: file,
292
302
  extendedAttributes: this.toExtendedAttributes(node.extAttrs),
293
303
  documentation: this.makeDocs(node),
294
- });
304
+ }, generics);
295
305
  if (node.extAttrs.find(it => it.name === "Synthetic")) {
296
306
  const fqName = this.currentPackage.concat(this.namespacePathNames).concat([node.name]).join('.');
297
307
  addSyntheticType(fqName, result);
298
308
  }
309
+ this.genericsScopes.pop();
299
310
  return this.withInfo(node, result);
300
311
  }
301
312
  toIDLTypedef(file, node) {
302
- var _a;
303
313
  const generics = this.extractGenerics(node.extAttrs);
304
- this.genericsScopes.push(generics);
305
- const result = this.withInfo(node, idl.createTypedef(node.name, this.toIDLType(file, node.idlType, undefined), (_a = this.findExtendedAttribute(node.extAttrs, idl.IDLExtendedAttributes.TypeParameters)) === null || _a === void 0 ? void 0 : _a.split(","), {
314
+ this.enterGenericScope(generics);
315
+ const result = this.withInfo(node, idl.createTypedef(node.name, this.toIDLType(file, node.idlType, undefined, node.name), generics, {
306
316
  extendedAttributes: this.toExtendedAttributes(node.extAttrs),
307
317
  documentation: this.makeDocs(node),
308
318
  fileName: file,
@@ -358,7 +368,7 @@ class IDLDeserializer {
358
368
  initializer = undefined;
359
369
  }
360
370
  else {
361
- throw new Error(`Not representable enum initializer: ${node.default}`);
371
+ throw new Error(`Not representable enum initializer: ${JSON.stringify(node.default)}. Found in ${file}`);
362
372
  }
363
373
  return this.withInfo(node, idl.createEnumMember(node.name, parent, this.toIDLType(file, node.idlType, undefined), initializer, {
364
374
  extendedAttributes: this.toExtendedAttributes(node.extAttrs),
@@ -401,17 +411,39 @@ class IDLDeserializer {
401
411
  return node.type === 'import';
402
412
  }
403
413
  isCallable(node) {
404
- return node.extAttrs.some(it => it.name == "Invoke");
414
+ return node.extAttrs.some(it => it.name == idl.IDLExtendedAttributes.CallSignature);
405
415
  }
406
416
  ///
417
+ splitTypeArguments(line) {
418
+ let buffer = "";
419
+ let brackets = 0;
420
+ const result = [];
421
+ for (const letter of line) {
422
+ if (letter === ',' && brackets === 0) {
423
+ result.push(buffer);
424
+ buffer = '';
425
+ continue;
426
+ }
427
+ if (letter === '<') {
428
+ brackets += 1;
429
+ }
430
+ if (letter === '>') {
431
+ brackets -= 1;
432
+ }
433
+ buffer += letter;
434
+ }
435
+ if (buffer.length) {
436
+ result.push(buffer);
437
+ }
438
+ return result;
439
+ }
407
440
  extractTypeArguments(file, extAttrs, attribute) {
408
441
  var _a;
409
442
  const attr = extAttrs === null || extAttrs === void 0 ? void 0 : extAttrs.find(it => it.name === attribute);
410
443
  if (!attr)
411
444
  return undefined;
412
445
  let value = this.toExtendedAttributeValue(attr);
413
- return (_a = value === null || value === void 0 ? void 0 : value.split(",") // TODO need real parsing here. What about "<T, Map<K, Callback<K,R>>, U>"
414
- ) === null || _a === void 0 ? void 0 : _a.map(it => { var _a; return this.toIDLType(file, (_a = webidl2.parseType(it, file)) !== null && _a !== void 0 ? _a : it); });
446
+ return (_a = this.splitTypeArguments(value)) === null || _a === void 0 ? void 0 : _a.map(it => { var _a; return this.toIDLType(file, (_a = webidl2.parseType(it.replaceAll('\'', '"'), file)) !== null && _a !== void 0 ? _a : it); });
415
447
  }
416
448
  constantValue(node) {
417
449
  switch (node.value.type) {
@@ -480,9 +512,9 @@ class IDLDeserializer {
480
512
  return attr ? this.toExtendedAttributeValue(attr) : undefined;
481
513
  }
482
514
  }
483
- export function toIDLFile(fileName, content) {
515
+ export function toIDLFile(fileName, { content, inheritanceMode = 'multiple' } = {}) {
484
516
  const lexicalInfo = new Map();
485
- const deserializer = new IDLDeserializer(lexicalInfo);
517
+ const deserializer = new IDLDeserializer(lexicalInfo, inheritanceMode);
486
518
  if (undefined === content)
487
519
  content = fs.readFileSync(fileName).toString();
488
520
  let packageClause = [];
@@ -44,6 +44,7 @@ export declare enum IDLExtendedAttributes {
44
44
  DtsName = "DtsName",
45
45
  DtsTag = "DtsTag",
46
46
  Entity = "Entity",
47
+ Extends = "Extends",
47
48
  Import = "Import",
48
49
  DefaultExport = "DefaultExport",
49
50
  IndexSignature = "IndexSignature",
@@ -55,10 +56,12 @@ export declare enum IDLExtendedAttributes {
55
56
  Protected = "Protected",
56
57
  Synthetic = "Synthetic",
57
58
  Throws = "Throws",
59
+ TraceKey = "TraceKey",
58
60
  TypeArguments = "TypeArguments",
59
61
  TypeParameters = "TypeParameters",
60
62
  VerbatimDts = "VerbatimDts",
61
- HandWrittenImplementation = "HandWrittenImplementation"
63
+ HandWrittenImplementation = "HandWrittenImplementation",
64
+ ExtraMethod = "ExtraMethod"
62
65
  }
63
66
  export declare enum IDLAccessorAttribute {
64
67
  Getter = "Getter",
@@ -252,15 +255,6 @@ export declare function isSyntheticEntry(node: IDLNode): boolean;
252
255
  export declare function isOptionalType(type: IDLNode): type is IDLOptionalType;
253
256
  export declare function isVersion(node: IDLNode): node is IDLVersion;
254
257
  export declare function createOptionalType(element: IDLType, nodeInitializer?: IDLNodeInitializer): IDLOptionalType;
255
- /**
256
- * This placeholder is used when a class has no superclass.
257
- * Examples:
258
- * class definition: inheritance:
259
- * `C extends T` : [T]
260
- * `C implements T` : [Top, T]
261
- * `C extends T implements I, J` : [T, I, J]
262
- */
263
- export declare const IDLTopType: IDLReferenceType;
264
258
  export declare const IDLPointerType: IDLPrimitiveType;
265
259
  export declare const IDLVoidType: IDLPrimitiveType;
266
260
  export declare const IDLBooleanType: IDLPrimitiveType;
@@ -281,7 +275,7 @@ export declare const IDLStringType: IDLPrimitiveType;
281
275
  export declare const IDLAnyType: IDLPrimitiveType;
282
276
  export declare const IDLUndefinedType: IDLPrimitiveType;
283
277
  export declare const IDLUnknownType: IDLPrimitiveType;
284
- export declare const IDLObjectType: IDLReferenceType;
278
+ export declare const IDLObjectType: IDLPrimitiveType;
285
279
  export declare const IDLThisType: IDLPrimitiveType;
286
280
  export declare const IDLDate: IDLPrimitiveType;
287
281
  export declare const IDLBufferType: IDLPrimitiveType;
@@ -305,6 +299,7 @@ export declare function getPackageName(node: IDLNode): string;
305
299
  export declare function isInPackage(entry: IDLEntry | IDLFile, packageName: string, exactMatch?: boolean): boolean;
306
300
  export declare function getNamespaceName(a: IDLEntry): string;
307
301
  export type QNPattern = "package.namespace.name" | "namespace.name" | "name";
302
+ export declare function deriveQualifiedNameFrom(name: string, from: IDLNode): string;
308
303
  export declare function getQualifiedName(a: IDLNode, pattern: QNPattern): string;
309
304
  export declare function getFQName(a: IDLNode): string;
310
305
  export declare function createVersion(value: string[], nodeInitializer?: IDLNodeInitializer): IDLVersion;
@@ -333,13 +328,14 @@ export type IDLCallableInitializer = {
333
328
  isAsync: boolean;
334
329
  isStatic: boolean;
335
330
  };
336
- export declare function createCallable(name: string, parameters: IDLParameter[], returnType: IDLType, callableInitializer: IDLCallableInitializer, nodeInitializer: IDLNodeInitializer, typeParameters?: string[]): IDLCallable;
331
+ export declare function createCallable(name: string, parameters: IDLParameter[], returnType: IDLType, callableInitializer: IDLCallableInitializer, nodeInitializer?: IDLNodeInitializer, typeParameters?: string[]): IDLCallable;
337
332
  export declare function createConstructor(parameters: IDLParameter[], returnType: IDLType | undefined, nodeInitializer?: IDLNodeInitializer): IDLConstructor;
338
333
  export declare function createCallback(name: string, parameters: IDLParameter[], returnType: IDLType, nodeInitializer?: IDLNodeInitializer, typeParameters?: string[]): IDLCallback;
339
334
  export declare function createTypeParameterReference(name: string, nodeInitializer?: IDLNodeInitializer): IDLTypeParameterType;
340
335
  export declare function createTypedef(name: string, type: IDLType, typeParameters?: string[], nodeInitializer?: IDLNodeInitializer): IDLTypedef;
341
336
  export declare function createConstant(name: string, type: IDLType, value: string, nodeInitializer?: IDLNodeInitializer): IDLConstant;
342
337
  export declare function clone<T extends IDLNode>(node: T): T;
338
+ export declare function hasTypeParameters(entry: IDLEntry): boolean;
343
339
  export declare function escapeIDLKeyword(name: string): string;
344
340
  export declare function unescapeKeyword(name: string): string;
345
341
  type PrintedIndentInc = "[[indent-inc]]";
@@ -365,9 +361,6 @@ export declare function printNamespace(idl: IDLNamespace): PrintedLine[];
365
361
  export declare function printCallback(idl: IDLCallback): PrintedLine[];
366
362
  export declare function printScoped(idl: IDLEntry): PrintedLine[];
367
363
  export declare function printInterface(idl: IDLInterface): PrintedLine[];
368
- export declare function getSuperType(idl: IDLInterface): IDLReferenceType | undefined;
369
- export declare function getSuperTypes(idl: IDLInterface): IDLReferenceType[] | undefined;
370
- export declare function hasSuperType(idl: IDLInterface): boolean;
371
364
  export declare function printEnumMember(idl: IDLEnumMember): PrintedLine[];
372
365
  export declare function printEnum(idl: IDLEnum, skipInitializers: boolean): PrintedLine[];
373
366
  export declare function printTypedef(idl: IDLTypedef): PrintedLine[];