@idlizer/core 2.1.2 → 2.1.7

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 (80) hide show
  1. package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +3 -4
  2. package/build/lib/src/LanguageWriters/ArgConvertors.js +43 -32
  3. package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +35 -17
  4. package/build/lib/src/LanguageWriters/LanguageWriter.js +30 -56
  5. package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +3 -1
  6. package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +32 -11
  7. package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +5 -2
  8. package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +71 -62
  9. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +1 -1
  10. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +9 -19
  11. package/build/lib/src/LanguageWriters/convertors/InteropConvertors.d.ts +4 -2
  12. package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +10 -3
  13. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.d.ts +2 -1
  14. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +24 -4
  15. package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +8 -4
  16. package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +87 -33
  17. package/build/lib/src/LanguageWriters/nameConvertor.d.ts +3 -1
  18. package/build/lib/src/LanguageWriters/nameConvertor.js +5 -1
  19. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +19 -11
  20. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +34 -47
  21. package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.d.ts +4 -1
  22. package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.js +1 -1
  23. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +9 -9
  24. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +15 -24
  25. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +17 -8
  26. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +48 -23
  27. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +4 -6
  28. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +15 -14
  29. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +13 -8
  30. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +33 -52
  31. package/build/lib/src/LibraryInterface.d.ts +1 -4
  32. package/build/lib/src/config.d.ts +813 -110
  33. package/build/lib/src/config.js +25 -3
  34. package/build/lib/src/configDescriber.d.ts +31 -4
  35. package/build/lib/src/configDescriber.js +101 -3
  36. package/build/lib/src/from-idl/DtsPrinter.js +31 -18
  37. package/build/lib/src/from-idl/IDLLinter.d.ts +40 -7
  38. package/build/lib/src/from-idl/IDLLinter.js +211 -25
  39. package/build/lib/src/from-idl/common.js +1 -1
  40. package/build/lib/src/from-idl/deserialize.d.ts +10 -1
  41. package/build/lib/src/from-idl/deserialize.js +486 -352
  42. package/build/lib/src/idl.d.ts +29 -19
  43. package/build/lib/src/idl.js +404 -119
  44. package/build/lib/src/idlize.d.ts +2 -1
  45. package/build/lib/src/idlize.js +82 -26
  46. package/build/lib/src/index.d.ts +4 -3
  47. package/build/lib/src/index.js +3 -2
  48. package/build/lib/src/options.d.ts +1 -1
  49. package/build/lib/src/peer-generation/BuilderClass.d.ts +0 -2
  50. package/build/lib/src/peer-generation/BuilderClass.js +0 -8
  51. package/build/lib/src/peer-generation/LayoutManager.d.ts +10 -3
  52. package/build/lib/src/peer-generation/LayoutManager.js +3 -2
  53. package/build/lib/src/peer-generation/Materialized.d.ts +1 -1
  54. package/build/lib/src/peer-generation/Materialized.js +3 -3
  55. package/build/lib/src/peer-generation/PeerClass.d.ts +3 -8
  56. package/build/lib/src/peer-generation/PeerClass.js +0 -1
  57. package/build/lib/src/peer-generation/PeerFile.d.ts +1 -2
  58. package/build/lib/src/peer-generation/PeerFile.js +1 -1
  59. package/build/lib/src/peer-generation/PeerLibrary.d.ts +12 -7
  60. package/build/lib/src/peer-generation/PeerLibrary.js +131 -67
  61. package/build/lib/src/peer-generation/ReferenceResolver.d.ts +1 -1
  62. package/build/lib/src/peer-generation/ReferenceResolver.js +2 -2
  63. package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +1 -0
  64. package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +6 -2
  65. package/build/lib/src/peer-generation/idl/common.d.ts +3 -1
  66. package/build/lib/src/peer-generation/idl/common.js +21 -4
  67. package/build/lib/src/peer-generation/isMaterialized.js +28 -7
  68. package/build/lib/src/peer-generation/unions.d.ts +3 -2
  69. package/build/lib/src/peer-generation/unions.js +7 -3
  70. package/build/lib/src/resolveNamedNode.d.ts +3 -0
  71. package/build/lib/src/resolveNamedNode.js +105 -0
  72. package/build/lib/src/util.d.ts +8 -1
  73. package/build/lib/src/util.js +41 -3
  74. package/build/lib/src/visitor.d.ts +2 -1
  75. package/build/lib/src/visitor.js +109 -7
  76. package/package.json +2 -2
  77. package/webidl2.js/LICENSE +21 -0
  78. package/webidl2.js/README.md +827 -0
  79. package/webidl2.js/dist/package.json +3 -0
  80. package/webidl2.js/dist/webidl2.js +93 -19
@@ -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(),
@@ -31,10 +35,14 @@ export const CoreConfigurationSchema = D.object({
31
35
  ignoreMaterialized: T.stringArray(),
32
36
  builderClasses: T.stringArray(),
33
37
  forceMaterialized: T.stringArray(),
34
- forceCallback: T.stringArray(),
38
+ forceCallback: D.map(D.string(), T.stringArray()).onMerge('replace'),
39
+ forceResource: T.stringArray(),
35
40
  forceContext: T.stringArray(),
41
+ hooks: D.map(D.string(), D.map(D.string(), HookMethodSchema)).onMerge('replace'),
42
+ externalModuleTypes: D.map(D.string(), D.string()).onMerge('replace'),
36
43
  moduleName: D.string(),
37
- modules: D.map(D.string(), ModuleConfigurationSchema)
44
+ modules: D.map(D.string(), ModuleConfigurationSchema).onMerge('replace'),
45
+ globalPackages: T.stringArray()
38
46
  });
39
47
  export const defaultCoreConfiguration = {
40
48
  TypePrefix: "",
@@ -46,10 +54,14 @@ export const defaultCoreConfiguration = {
46
54
  ignoreMaterialized: [],
47
55
  builderClasses: [],
48
56
  forceMaterialized: [],
49
- forceCallback: [],
57
+ forceCallback: new Map(),
58
+ forceResource: [],
50
59
  forceContext: [],
60
+ hooks: new Map(),
61
+ externalModuleTypes: new Map(),
51
62
  moduleName: "",
52
63
  modules: new Map(),
64
+ globalPackages: []
53
65
  };
54
66
  let currentConfig = defaultCoreConfiguration;
55
67
  export function setDefaultConfiguration(config) {
@@ -65,4 +77,14 @@ export function generatorTypePrefix() {
65
77
  const conf = generatorConfiguration();
66
78
  return `${conf.TypePrefix}${conf.LibraryPrefix}`;
67
79
  }
80
+ export function generatorHookName(className, methodName) {
81
+ var _a;
82
+ const hookMethods = generatorConfiguration().hooks.get(className);
83
+ if (!hookMethods)
84
+ return undefined;
85
+ const hook = hookMethods.get(methodName);
86
+ if (!hook)
87
+ return undefined;
88
+ return (_a = hook.hookName) !== null && _a !== void 0 ? _a : `hook${className}${capitalize(methodName)}`;
89
+ }
68
90
  //# sourceMappingURL=config.js.map
@@ -8,6 +8,12 @@ export interface JsonSchemaArray extends JsonSchemaLeaf {
8
8
  export interface JsonSchemaTuple extends JsonSchemaLeaf {
9
9
  items: JsonSchemaNode[];
10
10
  }
11
+ export interface JsonSchemaUnion extends JsonSchemaLeaf {
12
+ oneOf: JsonSchemaNode[];
13
+ }
14
+ export interface JsonSchemaLiteral extends JsonSchemaLeaf {
15
+ 'const': string | number | boolean | null;
16
+ }
11
17
  export interface JsonSchemaMap extends JsonSchemaLeaf {
12
18
  additionalProperties: JsonSchemaNode;
13
19
  }
@@ -16,7 +22,7 @@ export interface JsonSchemaObject extends JsonSchemaLeaf {
16
22
  required: string[];
17
23
  additionalProperties: boolean;
18
24
  }
19
- export type JsonSchemaNode = JsonSchemaLeaf | JsonSchemaArray | JsonSchemaTuple | JsonSchemaMap | JsonSchemaObject;
25
+ export type JsonSchemaNode = JsonSchemaLeaf | JsonSchemaArray | JsonSchemaTuple | JsonSchemaMap | JsonSchemaObject | JsonSchemaUnion | JsonSchemaLiteral;
20
26
  export interface JsonSchema {
21
27
  $ref: string;
22
28
  $schema: string;
@@ -27,6 +33,7 @@ type ObjectDescriptionToType<T extends {}> = {
27
33
  readonly [x in keyof T]: UnwrapConfigDescriberLeaf<T[x]>;
28
34
  };
29
35
  type TraverseTuple<Ts extends any[]> = Ts extends [] ? [] : Ts extends [infer Head, ...infer Rest] ? [UnwrapConfigDescriberLeaf<Head>, ...TraverseTuple<Rest>] : never;
36
+ type TraverseUnion<Ts extends any[]> = Ts extends [] ? never : Ts extends [infer Head, ...infer Rest] ? UnwrapConfigDescriberLeaf<Head> | TraverseUnion<Rest> : never;
30
37
  export interface ValidationSuccess<T> {
31
38
  success: true;
32
39
  value: T;
@@ -42,12 +49,19 @@ declare class ValidationBox<T> {
42
49
  static fail<T>(errorMessage: string): ValidationBox<T>;
43
50
  static ok<T>(value: T): ValidationBox<T>;
44
51
  success(): boolean;
45
- unwrap(): T;
52
+ unwrap(message?: string): T;
46
53
  error(): string;
47
54
  get(): ValidationResult<T>;
48
55
  or<U>(x: U): ValidationBox<U | T>;
49
56
  }
50
- declare class ConfigDescriberLeaf<T> {
57
+ export interface ConfigDescriberBaseConfig {
58
+ mergeStrategy: 'replace' | 'merge';
59
+ }
60
+ declare class ConfigDescriberBase {
61
+ $: ConfigDescriberBaseConfig;
62
+ onMerge(strategy: ConfigDescriberBaseConfig['mergeStrategy']): this;
63
+ }
64
+ declare class ConfigDescriberLeaf<T> extends ConfigDescriberBase {
51
65
  validate: (x: unknown) => ValidationBox<T>;
52
66
  printSchema: () => JsonSchemaNode;
53
67
  constructor(validate: (x: unknown) => ValidationBox<T>, printSchema: () => JsonSchemaNode);
@@ -60,6 +74,12 @@ declare class ConfigDescriberObjectLeaf<T> extends ConfigDescriberLeaf<T> {
60
74
  constructor(validate: (x: unknown) => ValidationBox<T>, printSchema: () => JsonSchemaNode, schema: Record<string, ConfigDescriberLeaf<T>>);
61
75
  }
62
76
  export type ConfigSchema<T> = ConfigDescriberLeaf<T>;
77
+ export interface ConfigDescriberFieldInfo {
78
+ mergeStrategy: ConfigDescriberBaseConfig['mergeStrategy'];
79
+ }
80
+ export declare function inspectSchema(schema: ConfigDescriberLeaf<any>): {
81
+ inspectPath(name: string): ConfigDescriberFieldInfo | undefined;
82
+ };
63
83
  export interface CommonBuilderConfig<T> {
64
84
  default?: T;
65
85
  description?: string;
@@ -77,8 +97,15 @@ export declare const D: {
77
97
  array<T_2>(type: ConfigDescriberLeaf<T_2>, initAsEmpty?: boolean): ConfigDescriberLeaf<T_2[]>;
78
98
  map<K_1, V>(keySchema: ConfigDescriberLeaf<K_1>, valSchema: ConfigDescriberLeaf<V>): ConfigDescriberLeaf<Map<K_1, V>>;
79
99
  tuple<Ts extends ConfigDescriberLeaf<any>[]>(...items: Ts): ConfigDescriberLeaf<TraverseTuple<Ts>>;
100
+ union<Ts_1 extends ConfigDescriberLeaf<any>[]>(...items: Ts_1): ConfigDescriberLeaf<TraverseUnion<Ts_1>>;
101
+ literal: {
102
+ string<T_3 extends string>(x: T_3): ConfigDescriberLeaf<T_3>;
103
+ number<T_4 extends number>(x: T_4): ConfigDescriberLeaf<T_4>;
104
+ boolean<T_5 extends boolean>(x: T_5): ConfigDescriberLeaf<T_5>;
105
+ null(x: null): ConfigDescriberLeaf<null>;
106
+ };
80
107
  combine<A, B>(a: ConfigDescriberObjectLeaf<A>, b: ConfigDescriberObjectLeaf<B>): ConfigDescriberObjectLeaf<A & B>;
81
- printJSONSchema<T_3>(schema: ConfigDescriberLeaf<T_3>): string;
108
+ printJSONSchema<T_6>(schema: ConfigDescriberLeaf<T_6>): string;
82
109
  };
83
110
  export type ConfigTypeInfer<T> = UnwrapConfigDescriberLeaf<T>;
84
111
  export {};
@@ -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) {
@@ -51,8 +51,20 @@ class ValidationBox {
51
51
  });
52
52
  }
53
53
  }
54
- class ConfigDescriberLeaf {
54
+ class ConfigDescriberBase {
55
+ constructor() {
56
+ this.$ = {
57
+ mergeStrategy: 'merge'
58
+ };
59
+ }
60
+ onMerge(strategy) {
61
+ this.$.mergeStrategy = strategy;
62
+ return this;
63
+ }
64
+ }
65
+ class ConfigDescriberLeaf extends ConfigDescriberBase {
55
66
  constructor(validate, printSchema) {
67
+ super();
56
68
  this.validate = validate;
57
69
  this.printSchema = printSchema;
58
70
  }
@@ -66,6 +78,27 @@ class ConfigDescriberObjectLeaf extends ConfigDescriberLeaf {
66
78
  this.schema = schema;
67
79
  }
68
80
  }
81
+ export function inspectSchema(schema) {
82
+ return {
83
+ inspectPath(name) {
84
+ if (name === '') {
85
+ return {
86
+ mergeStrategy: schema.$.mergeStrategy
87
+ };
88
+ }
89
+ const path = name.split('.');
90
+ let leaf = schema;
91
+ while (leaf instanceof ConfigDescriberObjectLeaf && path.length > 0) {
92
+ const key = path.shift();
93
+ leaf = leaf.schema[key];
94
+ if (!leaf) {
95
+ return undefined;
96
+ }
97
+ }
98
+ return { mergeStrategy: leaf.$.mergeStrategy };
99
+ }
100
+ };
101
+ }
69
102
  function mk(typeName, check, config) {
70
103
  return new ConfigDescriberLeaf(x => {
71
104
  if (check(x)) {
@@ -262,6 +295,71 @@ export const D = {
262
295
  };
263
296
  });
264
297
  },
298
+ union(...items) {
299
+ return new ConfigDescriberLeaf(xs => {
300
+ for (const item of items) {
301
+ const r = item.validate(xs);
302
+ if (r.success()) {
303
+ return r;
304
+ }
305
+ }
306
+ return ValidationBox.fail('Not matched');
307
+ }, () => {
308
+ return {
309
+ oneOf: items.map(it => it.printSchema())
310
+ };
311
+ });
312
+ },
313
+ literal: {
314
+ string(x) {
315
+ return new ConfigDescriberLeaf(xs => {
316
+ if (typeof xs === 'string' && x === xs) {
317
+ return ValidationBox.ok(xs);
318
+ }
319
+ return ValidationBox.fail('Not matched');
320
+ }, () => {
321
+ return {
322
+ 'const': x
323
+ };
324
+ });
325
+ },
326
+ number(x) {
327
+ return new ConfigDescriberLeaf(xs => {
328
+ if (typeof xs === 'number' && x === xs) {
329
+ return ValidationBox.ok(xs);
330
+ }
331
+ return ValidationBox.fail('Not matched');
332
+ }, () => {
333
+ return {
334
+ 'const': x
335
+ };
336
+ });
337
+ },
338
+ boolean(x) {
339
+ return new ConfigDescriberLeaf(xs => {
340
+ if (typeof xs === 'boolean' && x === xs) {
341
+ return ValidationBox.ok(xs);
342
+ }
343
+ return ValidationBox.fail('Not matched');
344
+ }, () => {
345
+ return {
346
+ 'const': x
347
+ };
348
+ });
349
+ },
350
+ null(x) {
351
+ return new ConfigDescriberLeaf(xs => {
352
+ if (typeof xs === 'object' && xs === null) {
353
+ return ValidationBox.ok(null);
354
+ }
355
+ return ValidationBox.fail('Expected null');
356
+ }, () => {
357
+ return {
358
+ 'const': null
359
+ };
360
+ });
361
+ }
362
+ },
265
363
  ////////////////////////////////////////
266
364
  // Utils
267
365
  combine(a, b) {
@@ -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, 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 } 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, 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, IDLObjectType } from "../idl";
17
17
  import { resolveSyntheticType, toIDLFile } from "./deserialize";
18
18
  import { Language } from "../Language";
19
19
  import { warn } from "../util";
@@ -64,7 +64,7 @@ export class CustomPrintVisitor {
64
64
  else {
65
65
  throw new Error(`Unexpected node kind: ${IDLKind[node.kind]}`);
66
66
  }
67
- for (const namespace of namespacesPath) {
67
+ for (const _ of namespacesPath) {
68
68
  this.popIndent();
69
69
  this.print("}");
70
70
  }
@@ -86,9 +86,6 @@ export class CustomPrintVisitor {
86
86
  printInterface(node) {
87
87
  var _a;
88
88
  let typeSpec = this.toTypeName(node);
89
- // Workaround for an SDK declaration clash between `WrappedBuilder` and `ContentModifier`
90
- if (node.name === "WrappedBuilder")
91
- typeSpec = "WrappedBuilder<Args extends any[]>";
92
89
  const entity = (_a = getExtAttribute(node, IDLExtendedAttributes.Entity)) !== null && _a !== void 0 ? _a : IDLEntity.Interface;
93
90
  if (entity === IDLEntity.Literal) {
94
91
  this.print(`${isInNamespace(node) ? "" : "declare "}type ${typeSpec} = ${this.literal(node, false, true)}`);
@@ -99,6 +96,9 @@ export class CustomPrintVisitor {
99
96
  else if (entity === IDLEntity.NamedTuple) {
100
97
  this.print(`${isInNamespace(node) ? "" : "declare "}type ${typeSpec} = ${this.literal(node, true, true)}`);
101
98
  }
99
+ else if (entity === IDLEntity.Intersection) {
100
+ this.print(`${isInNamespace(node) ? "" : "declare "}type ${typeSpec} = ${node.inheritance.map(it => this.printTypeForTS(it)).join(' & ')}`);
101
+ }
102
102
  else {
103
103
  let interfaces = node.inheritance;
104
104
  let keyword = "extends";
@@ -152,8 +152,11 @@ export class CustomPrintVisitor {
152
152
  }
153
153
  paramText(paramOrTag) {
154
154
  const param = paramOrTag;
155
- if (param.kind === IDLKind.Parameter)
156
- return `${param.isVariadic ? "..." : ""}${getName(param)}${param.isOptional ? "?" : ""}: ${this.printTypeForTS(param.type)}`;
155
+ if (param.kind === IDLKind.Parameter) {
156
+ const dots = param.isVariadic ? "..." : "";
157
+ const brackets = param.isVariadic ? "[]" : "";
158
+ return `${dots}${getName(param)}${param.isOptional ? "?" : ""}: ${this.printTypeForTS(param.type)}${brackets}`;
159
+ }
157
160
  const tag = paramOrTag;
158
161
  return `${tag.name}: ${tag.value}`;
159
162
  }
@@ -280,6 +283,7 @@ export class CustomPrintVisitor {
280
283
  case IDLNumberType:
281
284
  return "number";
282
285
  case IDLAnyType: return "any";
286
+ case IDLObjectType: return "Object";
283
287
  case IDLUnknownType: return "unknown";
284
288
  case IDLBufferType: return "ArrayBuffer";
285
289
  case IDLBooleanType: return "boolean";
@@ -290,6 +294,7 @@ export class CustomPrintVisitor {
290
294
  case IDLBigintType:
291
295
  case IDLPointerType: return "number|bigint";
292
296
  case IDLDate: return "Date";
297
+ case IDLFunctionType: return "Function";
293
298
  default: throw new Error(`Unknown primitive type ${DebugUtils.debugPrintType(type)}`);
294
299
  }
295
300
  }
@@ -311,15 +316,21 @@ export class CustomPrintVisitor {
311
316
  toTypeName(node) {
312
317
  var _a, _b;
313
318
  if (isReferenceType(node)) {
314
- const synthDecl = this.resolver(node);
315
- if (synthDecl && isSyntheticEntry(synthDecl)) {
316
- if (isInterface(synthDecl)) {
317
- const isTuple = getExtAttribute(synthDecl, IDLExtendedAttributes.Entity) === IDLEntity.Tuple;
318
- return this.literal(synthDecl, isTuple, !isTuple);
319
- }
320
- if (isCallback(synthDecl)) {
321
- return this.callback(synthDecl);
319
+ const decl = this.resolver(node);
320
+ if (decl) {
321
+ if (isSyntheticEntry(decl)) {
322
+ if (isInterface(decl)) {
323
+ const isTuple = getExtAttribute(decl, IDLExtendedAttributes.Entity) === IDLEntity.Tuple;
324
+ return this.literal(decl, isTuple, !isTuple);
325
+ }
326
+ if (isCallback(decl)) {
327
+ return this.callback(decl);
328
+ }
322
329
  }
330
+ let typeSpec = getQualifiedName(decl, "namespace.name");
331
+ if (node.typeArguments)
332
+ typeSpec = `${typeSpec}<${node.typeArguments.map(it => this.printTypeForTS(it))}>`;
333
+ return typeSpec;
323
334
  }
324
335
  }
325
336
  if (hasExtAttribute(node, IDLExtendedAttributes.Import)) {
@@ -329,7 +340,7 @@ export class CustomPrintVisitor {
329
340
  if ((isInterface(node) || isCallback(node) || isTypedef(node)) && ((_a = node.typeParameters) === null || _a === void 0 ? void 0 : _a.length))
330
341
  typeSpec = `${typeSpec}<${(_b = node.typeParameters) === null || _b === void 0 ? void 0 : _b.join(",")}>`;
331
342
  if (isReferenceType(node) && node.typeArguments)
332
- typeSpec = `${typeSpec}<${node.typeArguments.map(it => this.toTypeName(it))}>`;
343
+ typeSpec = `${typeSpec}<${node.typeArguments.map(it => this.printTypeForTS(it))}>`;
333
344
  return typeSpec;
334
345
  }
335
346
  callback(node) {
@@ -345,10 +356,12 @@ export class CustomPrintVisitor {
345
356
  }
346
357
  export function idlToDtsString(name, content) {
347
358
  let printer = new CustomPrintVisitor(resolveSyntheticType, Language.TS);
348
- const idlFile = toIDLFile(name, content);
359
+ const [idlFile] = toIDLFile(name, { content });
349
360
  printer.printPackage(idlFile);
350
- idlFile.entries.forEach(it => {
361
+ linearizeNamespaceMembers(idlFile.entries).forEach(it => {
351
362
  transformMethodsAsync2ReturnPromise(it);
363
+ });
364
+ idlFile.entries.forEach(it => {
352
365
  printer.visit(it);
353
366
  });
354
367
  return printer.output.join("\n");
@@ -1,24 +1,57 @@
1
1
  import * as idl from "../idl";
2
2
  import { ReferenceResolver } from "../peer-generation/ReferenceResolver";
3
+ import { IDLTokenInfoMap } from "./deserialize";
4
+ export declare enum IDLValidationDiagnosticsCode {
5
+ INVALID_EXTENDED_ATTRIBUTE = 1000,
6
+ ENUM_IS_NOT_CONSISTENT = 1001,
7
+ REFERENCE_IS_NOT_RESOLVED = 1002
8
+ }
9
+ type IDLValidationErrorDescriptionBox = Record<IDLValidationDiagnosticsCode, string>;
10
+ export declare const IDLValidationErrorDescription: {
11
+ en_EN: IDLValidationErrorDescriptionBox;
12
+ };
3
13
  export interface IDLLinterOptions {
4
14
  validEntryAttributes: Map<idl.IDLKind, string[]>;
5
15
  checkEnumsConsistency: boolean;
6
16
  checkReferencesResolved: boolean;
7
17
  }
18
+ interface IDLLinterContextRecord {
19
+ typeParameters: Set<string>;
20
+ }
21
+ declare class IDLLinterContext {
22
+ private stack;
23
+ constructor();
24
+ enter(rec: IDLLinterContextRecord): void;
25
+ leave(): void;
26
+ get current(): IDLLinterContextRecord;
27
+ hasTypeParameter(name: string): boolean;
28
+ }
8
29
  export declare class IDLLinter {
9
- protected node: idl.IDLNode;
30
+ protected file: idl.IDLFile;
10
31
  protected resolver: ReferenceResolver;
11
32
  protected options: IDLLinterOptions;
12
- constructor(node: idl.IDLNode, resolver: ReferenceResolver, options: IDLLinterOptions);
13
- private entryErrors;
14
- private pushError;
15
- result: string;
16
- visit(): string;
33
+ protected info?: IDLTokenInfoMap | undefined;
34
+ protected context: IDLLinterContext;
35
+ diagnostics: IDLLinterDiagnosticsSummary[];
36
+ constructor(file: idl.IDLFile, resolver: ReferenceResolver, options: IDLLinterOptions, info?: IDLTokenInfoMap | undefined);
37
+ visit(): IDLLinterDiagnosticsSummary[];
38
+ protected enter(node: idl.IDLNode): (() => void) | undefined;
17
39
  protected check(node: idl.IDLNode): void;
18
40
  protected checkValidAttributes(entry: idl.IDLEntry, validAttributes: string[]): void;
19
41
  protected checkEnumConsistency(entry: idl.IDLEnum): void;
20
42
  private static builtinReferences;
21
43
  protected checkReferenceResolved(reference: idl.IDLReferenceType): void;
22
44
  }
23
- export declare function verifyIDLLinter(node: idl.IDLNode, resolver: ReferenceResolver, options: IDLLinterOptions): true;
45
+ interface IDLLinterDiagnosticsSummary {
46
+ code: IDLValidationDiagnosticsCode;
47
+ message: string;
48
+ file: string;
49
+ position: [number, number];
50
+ }
51
+ export declare class IDLLinterError extends Error {
52
+ size: number;
53
+ constructor(message: string, size: number);
54
+ }
55
+ export declare function verifyIDLLinter(file: idl.IDLFile, resolver: ReferenceResolver, options: IDLLinterOptions, info?: IDLTokenInfoMap): true;
56
+ export {};
24
57
  //# sourceMappingURL=IDLLinter.d.ts.map