@idlizer/core 2.1.0 → 2.1.5

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 (82) hide show
  1. package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +15 -2
  2. package/build/lib/src/LanguageWriters/ArgConvertors.js +93 -33
  3. package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +34 -14
  4. package/build/lib/src/LanguageWriters/LanguageWriter.js +29 -52
  5. package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +2 -1
  6. package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +16 -5
  7. package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +4 -2
  8. package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +25 -15
  9. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +7 -18
  10. package/build/lib/src/LanguageWriters/convertors/InteropConvertors.d.ts +4 -2
  11. package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +13 -3
  12. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.d.ts +2 -1
  13. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +24 -4
  14. package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +4 -2
  15. package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +49 -29
  16. package/build/lib/src/LanguageWriters/nameConvertor.d.ts +3 -1
  17. package/build/lib/src/LanguageWriters/nameConvertor.js +5 -1
  18. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +21 -10
  19. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +56 -65
  20. package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.d.ts +4 -1
  21. package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.js +1 -1
  22. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +16 -10
  23. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +18 -27
  24. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +14 -9
  25. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +18 -21
  26. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +11 -7
  27. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +42 -18
  28. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +14 -6
  29. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +49 -44
  30. package/build/lib/src/LibraryInterface.d.ts +1 -5
  31. package/build/lib/src/config.d.ts +1029 -66
  32. package/build/lib/src/config.js +15 -2
  33. package/build/lib/src/configDescriber.d.ts +30 -3
  34. package/build/lib/src/configDescriber.js +99 -1
  35. package/build/lib/src/from-idl/DtsPrinter.js +32 -20
  36. package/build/lib/src/from-idl/IDLLinter.d.ts +40 -7
  37. package/build/lib/src/from-idl/IDLLinter.js +211 -25
  38. package/build/lib/src/from-idl/common.js +1 -1
  39. package/build/lib/src/from-idl/deserialize.d.ts +4 -1
  40. package/build/lib/src/from-idl/deserialize.js +434 -346
  41. package/build/lib/src/idl.d.ts +28 -18
  42. package/build/lib/src/idl.js +376 -111
  43. package/build/lib/src/idlize.d.ts +3 -1
  44. package/build/lib/src/idlize.js +85 -28
  45. package/build/lib/src/index.d.ts +6 -3
  46. package/build/lib/src/index.js +5 -2
  47. package/build/lib/src/options.d.ts +1 -1
  48. package/build/lib/src/peer-generation/BuilderClass.d.ts +0 -2
  49. package/build/lib/src/peer-generation/BuilderClass.js +0 -8
  50. package/build/lib/src/peer-generation/LayoutManager.d.ts +10 -3
  51. package/build/lib/src/peer-generation/LayoutManager.js +3 -2
  52. package/build/lib/src/peer-generation/Materialized.d.ts +1 -1
  53. package/build/lib/src/peer-generation/Materialized.js +2 -2
  54. package/build/lib/src/peer-generation/PeerClass.d.ts +3 -8
  55. package/build/lib/src/peer-generation/PeerClass.js +0 -1
  56. package/build/lib/src/peer-generation/PeerFile.d.ts +1 -2
  57. package/build/lib/src/peer-generation/PeerFile.js +1 -1
  58. package/build/lib/src/peer-generation/PeerLibrary.d.ts +12 -9
  59. package/build/lib/src/peer-generation/PeerLibrary.js +136 -71
  60. package/build/lib/src/peer-generation/ReferenceResolver.d.ts +1 -1
  61. package/build/lib/src/peer-generation/ReferenceResolver.js +2 -2
  62. package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +1 -0
  63. package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +6 -2
  64. package/build/lib/src/peer-generation/idl/common.d.ts +2 -1
  65. package/build/lib/src/peer-generation/idl/common.js +13 -2
  66. package/build/lib/src/peer-generation/isEnumType.d.ts +5 -0
  67. package/build/lib/src/peer-generation/isEnumType.js +29 -0
  68. package/build/lib/src/peer-generation/isMaterialized.js +25 -8
  69. package/build/lib/src/peer-generation/modules.d.ts +10 -0
  70. package/build/lib/src/peer-generation/modules.js +38 -0
  71. package/build/lib/src/peer-generation/unions.d.ts +3 -2
  72. package/build/lib/src/peer-generation/unions.js +6 -2
  73. package/build/lib/src/resolveNamedNode.d.ts +3 -0
  74. package/build/lib/src/resolveNamedNode.js +105 -0
  75. package/build/lib/src/util.d.ts +7 -0
  76. package/build/lib/src/util.js +39 -0
  77. package/build/lib/src/visitor.d.ts +0 -1
  78. package/build/lib/src/visitor.js +1 -7
  79. package/package.json +2 -2
  80. package/webidl2.js/dist/webidl2.js +35 -7
  81. package/build/lib/src/configMerge.d.ts +0 -2
  82. package/build/lib/src/configMerge.js +0 -42
@@ -65,6 +65,7 @@ export var IDLExtendedAttributes;
65
65
  IDLExtendedAttributes["DtsTag"] = "DtsTag";
66
66
  IDLExtendedAttributes["Entity"] = "Entity";
67
67
  IDLExtendedAttributes["Import"] = "Import";
68
+ IDLExtendedAttributes["DefaultExport"] = "DefaultExport";
68
69
  IDLExtendedAttributes["IndexSignature"] = "IndexSignature";
69
70
  IDLExtendedAttributes["Interfaces"] = "Interfaces";
70
71
  IDLExtendedAttributes["NativeModule"] = "NativeModule";
@@ -94,7 +95,7 @@ export var IDLInterfaceSubkind;
94
95
  })(IDLInterfaceSubkind || (IDLInterfaceSubkind = {}));
95
96
  export function forEachChild(node, cbEnter, cbLeave) {
96
97
  var _a, _b;
97
- cbEnter(node);
98
+ const cleanup = cbEnter(node);
98
99
  switch (node.kind) {
99
100
  case IDLKind.File:
100
101
  node.entries.forEach((value) => forEachChild(value, cbEnter, cbLeave));
@@ -172,8 +173,108 @@ export function forEachChild(node, cbEnter, cbLeave) {
172
173
  throw new Error(`Unhandled ${node.kind}`);
173
174
  }
174
175
  }
175
- if (cbLeave)
176
- cbLeave(node);
176
+ cbLeave === null || cbLeave === void 0 ? void 0 : cbLeave(node);
177
+ cleanup === null || cleanup === void 0 ? void 0 : cleanup();
178
+ }
179
+ /** Updates tree in place! */
180
+ function updateEachChild(node, op, cbLeave) {
181
+ const old = node;
182
+ node = op(old);
183
+ if (node.kind !== old.kind) {
184
+ throw new Error("Kinds must be the same!");
185
+ }
186
+ switch (node.kind) {
187
+ case IDLKind.File: {
188
+ const concrete = node;
189
+ concrete.entries = concrete.entries.map(it => updateEachChild(it, op, cbLeave));
190
+ break;
191
+ }
192
+ case IDLKind.Namespace: {
193
+ const concrete = node;
194
+ concrete.members = concrete.members.map((it) => updateEachChild(it, op, cbLeave));
195
+ break;
196
+ }
197
+ case IDLKind.Interface: {
198
+ const concrete = node;
199
+ concrete.inheritance = concrete.inheritance.map((it) => updateEachChild(it, op, cbLeave));
200
+ concrete.constructors = concrete.constructors.map((it) => updateEachChild(it, op, cbLeave));
201
+ concrete.properties = concrete.properties.map((it) => updateEachChild(it, op, cbLeave));
202
+ concrete.methods = concrete.methods.map((it) => updateEachChild(it, op, cbLeave));
203
+ concrete.callables = concrete.callables.map((it) => updateEachChild(it, op, cbLeave));
204
+ break;
205
+ }
206
+ case IDLKind.Method:
207
+ case IDLKind.Callable:
208
+ case IDLKind.Callback:
209
+ case IDLKind.Constructor: {
210
+ const concrete = node;
211
+ concrete.parameters = concrete.parameters.map((it) => updateEachChild(it, op, cbLeave));
212
+ if (concrete.returnType) {
213
+ concrete.returnType = updateEachChild(concrete.returnType, op, cbLeave);
214
+ }
215
+ break;
216
+ }
217
+ case IDLKind.UnionType: {
218
+ const concrete = node;
219
+ concrete.types = concrete.types.map((it) => updateEachChild(it, op, cbLeave));
220
+ break;
221
+ }
222
+ case IDLKind.OptionalType: {
223
+ const concrete = node;
224
+ concrete.type = updateEachChild(concrete.type, op, cbLeave);
225
+ break;
226
+ }
227
+ case IDLKind.Const: {
228
+ const concrete = node;
229
+ concrete.type = updateEachChild(concrete.type, op, cbLeave);
230
+ break;
231
+ }
232
+ case IDLKind.Enum: {
233
+ const concrete = node;
234
+ concrete.elements = concrete.elements.map((it) => updateEachChild(it, op, cbLeave));
235
+ break;
236
+ }
237
+ case IDLKind.Property: {
238
+ const concrete = node;
239
+ concrete.type = updateEachChild(concrete.type, op, cbLeave);
240
+ break;
241
+ }
242
+ case IDLKind.Parameter: {
243
+ const concrete = node;
244
+ if (concrete.type)
245
+ concrete.type = updateEachChild(concrete.type, op, cbLeave);
246
+ break;
247
+ }
248
+ case IDLKind.Typedef: {
249
+ const concrete = node;
250
+ concrete.type = updateEachChild(concrete.type, op, cbLeave);
251
+ break;
252
+ }
253
+ case IDLKind.ContainerType: {
254
+ const concrete = node;
255
+ concrete.elementType = concrete.elementType.map(it => updateEachChild(it, op, cbLeave));
256
+ break;
257
+ }
258
+ case IDLKind.UnspecifiedGenericType: {
259
+ const concrete = node;
260
+ concrete.typeArguments = concrete.typeArguments.map(it => updateEachChild(it, op, cbLeave));
261
+ break;
262
+ }
263
+ case IDLKind.ReferenceType:
264
+ case IDLKind.TypeParameterType:
265
+ case IDLKind.EnumMember:
266
+ case IDLKind.Import:
267
+ case IDLKind.PrimitiveType:
268
+ case IDLKind.Version:
269
+ break;
270
+ default: {
271
+ throw new Error(`Unhandled ${node.kind}`);
272
+ }
273
+ }
274
+ if (cbLeave) {
275
+ cbLeave === null || cbLeave === void 0 ? void 0 : cbLeave(node);
276
+ }
277
+ return node;
177
278
  }
178
279
  export function isNamedNode(type) {
179
280
  return "_idlNamedNodeBrand" in type;
@@ -281,16 +382,11 @@ function createPrimitiveType(name) {
281
382
  _idlNamedNodeBrand: innerIdlSymbol,
282
383
  };
283
384
  }
284
- export function createOptionalType(element) {
285
- if (isOptionalType(element)) {
385
+ export function createOptionalType(element, nodeInitializer) {
386
+ if (isOptionalType(element) && !nodeInitializer) {
286
387
  return element;
287
388
  }
288
- return {
289
- kind: IDLKind.OptionalType,
290
- type: element,
291
- _idlNodeBrand: innerIdlSymbol,
292
- _idlTypeBrand: innerIdlSymbol,
293
- };
389
+ return Object.assign(Object.assign({ kind: IDLKind.OptionalType, type: element }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol });
294
390
  }
295
391
  /**
296
392
  * This placeholder is used when a class has no superclass.
@@ -301,6 +397,7 @@ export function createOptionalType(element) {
301
397
  * `C extends T implements I, J` : [T, I, J]
302
398
  */
303
399
  export const IDLTopType = createReferenceType("__TOP__");
400
+ // must match with toIDLType in deserialize.ts
304
401
  export const IDLPointerType = createPrimitiveType('pointer');
305
402
  export const IDLVoidType = createPrimitiveType('void');
306
403
  export const IDLBooleanType = createPrimitiveType('boolean');
@@ -326,40 +423,44 @@ export const IDLThisType = createPrimitiveType('this');
326
423
  export const IDLDate = createPrimitiveType('date');
327
424
  export const IDLBufferType = createPrimitiveType('buffer');
328
425
  export const IDLUint8ArrayType = createContainerType('sequence', [IDLU8Type]);
426
+ export const IDLSerializerBuffer = createPrimitiveType('SerializerBuffer');
329
427
  // Stub for IdlPeerLibrary
330
428
  export const IDLFunctionType = createPrimitiveType('Function');
331
- export const IDLLengthType = createPrimitiveType('Length');
332
429
  export const IDLCustomObjectType = createPrimitiveType('CustomObject');
333
430
  export const IDLInteropReturnBufferType = createPrimitiveType('InteropReturnBuffer');
334
- export function createNamespace(name, extendedAttributes, fileName) {
335
- return {
336
- kind: IDLKind.Namespace,
337
- members: [],
338
- name: name,
339
- extendedAttributes,
340
- fileName,
341
- _idlNodeBrand: innerIdlSymbol,
342
- _idlEntryBrand: innerIdlSymbol,
343
- _idlNamedNodeBrand: innerIdlSymbol,
344
- };
431
+ export function createNamespace(name, members, nodeInitializer) {
432
+ return Object.assign(Object.assign({ kind: IDLKind.Namespace, members: members !== null && members !== void 0 ? members : [], name: name }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
433
+ }
434
+ function isSpecialNodes(node) {
435
+ return node === IDLTopType
436
+ || node === IDLObjectType
437
+ || isPrimitiveType(node);
345
438
  }
346
439
  export function linkParentBack(node) {
347
440
  const parentStack = [];
348
- forEachChild(node, (node) => {
349
- if (isPrimitiveType(node))
350
- return;
351
- if (parentStack.length)
352
- node.parent = parentStack[parentStack.length - 1];
441
+ updateEachChild(node, (node) => {
442
+ if (isSpecialNodes(node)) {
443
+ return node;
444
+ }
445
+ if (parentStack.length) {
446
+ const top = parentStack[parentStack.length - 1];
447
+ if (node.parent !== undefined && node.parent !== top) {
448
+ node = clone(node);
449
+ }
450
+ node.parent = top;
451
+ }
353
452
  parentStack.push(node);
453
+ return node;
354
454
  }, (node) => {
355
- if (isPrimitiveType(node))
455
+ if (isSpecialNodes(node)) {
356
456
  return;
457
+ }
357
458
  parentStack.pop();
358
459
  });
359
460
  return node;
360
461
  }
361
- export function getNamespacesPathFor(entry) {
362
- let iterator = entry.parent;
462
+ export function getNamespacesPathFor(node) {
463
+ let iterator = node.parent;
363
464
  const result = [];
364
465
  while (iterator) {
365
466
  if (isNamespace(iterator))
@@ -368,31 +469,32 @@ export function getNamespacesPathFor(entry) {
368
469
  }
369
470
  return result;
370
471
  }
371
- export function getFileFor(entry) {
372
- let iterator = entry;
472
+ export function getFileFor(node) {
473
+ let iterator = node;
373
474
  while (iterator) {
374
475
  if (isFile(iterator))
375
476
  return iterator;
376
477
  iterator = iterator.parent;
377
478
  }
378
- console.warn(`Entry ${JSON.stringify(entry)} does not have IDLFile in parents`);
479
+ console.warn(`Node ${getQualifiedName(node, "namespace.name")} does not have IDLFile in parents`);
379
480
  return undefined;
380
481
  }
381
- export function isEqualByQualifedName(a, b) {
482
+ export function isEqualByQualifedName(a, b, pattern = "package.namespace.name") {
382
483
  if (a === b)
383
484
  return true;
384
485
  if (!a || !b)
385
486
  return false;
386
487
  if (a.kind !== b.kind || a.name !== b.name)
387
488
  return false;
388
- return getFQName(a) === getFQName(b);
489
+ return getQualifiedName(a, pattern) === getQualifiedName(b, pattern);
389
490
  }
390
- export function getPackageClause(entry) {
391
- let file = getFileFor(entry);
392
- return (file === null || file === void 0 ? void 0 : file.packageClause) || [];
491
+ export function getPackageClause(node) {
492
+ var _a;
493
+ const file = getFileFor(node);
494
+ return (_a = file === null || file === void 0 ? void 0 : file.packageClause) !== null && _a !== void 0 ? _a : [];
393
495
  }
394
- export function getPackageName(entry) {
395
- return getPackageClause(entry).join(".");
496
+ export function getPackageName(node) {
497
+ return getPackageClause(node).join(".");
396
498
  }
397
499
  export function isInPackage(entry, packageName, exactMatch = false) {
398
500
  const entryPackageName = getPackageName(entry);
@@ -403,22 +505,21 @@ export function isInPackage(entry, packageName, exactMatch = false) {
403
505
  export function getNamespaceName(a) {
404
506
  return getNamespacesPathFor(a).map(it => it.name).join('.');
405
507
  }
508
+ export function getQualifiedName(a, pattern) {
509
+ const result = [];
510
+ if ("package.namespace.name" === pattern)
511
+ result.push(...getPackageClause(a), ...getNamespacesPathFor(a).map(it => it.name));
512
+ else if ("namespace.name" === pattern)
513
+ result.push(...getNamespacesPathFor(a).map(it => it.name));
514
+ if (isNamedNode(a) && a.name)
515
+ result.push(a.name);
516
+ return result.join(".");
517
+ }
406
518
  export function getFQName(a) {
407
- // TODO package name is very dirty now, waiting for Alexander Rekunkov PR
408
- // return [...getPackageClause(a), ...getNamespacesPathFor(a).map(it => it.name), a.name].join('.')
409
- return [...getNamespacesPathFor(a).map(it => it.name), a.name].join('.');
519
+ return getQualifiedName(a, "package.namespace.name");
410
520
  }
411
- export function createVersion(value, extendedAttributes, fileName) {
412
- return {
413
- kind: IDLKind.Version,
414
- value,
415
- name: "version",
416
- extendedAttributes,
417
- fileName,
418
- _idlNodeBrand: innerIdlSymbol,
419
- _idlEntryBrand: innerIdlSymbol,
420
- _idlNamedNodeBrand: innerIdlSymbol,
421
- };
521
+ export function createVersion(value, nodeInitializer) {
522
+ return Object.assign(Object.assign({ kind: IDLKind.Version, value, name: "version" }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
422
523
  }
423
524
  export function fetchNamespaceFrom(pointOfView) {
424
525
  let node = pointOfView;
@@ -429,7 +530,7 @@ export function fetchNamespaceFrom(pointOfView) {
429
530
  }
430
531
  return undefined;
431
532
  }
432
- export function createReferenceType(nameOrSource, typeArguments) {
533
+ export function createReferenceType(nameOrSource, typeArguments, nodeInitializer) {
433
534
  let name;
434
535
  if (typeof nameOrSource === 'string') {
435
536
  name = nameOrSource;
@@ -437,24 +538,12 @@ export function createReferenceType(nameOrSource, typeArguments) {
437
538
  else {
438
539
  name = getFQName(nameOrSource);
439
540
  }
440
- return {
441
- kind: IDLKind.ReferenceType,
442
- name,
443
- typeArguments,
444
- _idlNodeBrand: innerIdlSymbol,
445
- _idlTypeBrand: innerIdlSymbol,
446
- _idlNamedNodeBrand: innerIdlSymbol,
447
- };
541
+ return Object.assign(Object.assign({ kind: IDLKind.ReferenceType, name,
542
+ typeArguments }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
448
543
  }
449
- export function createUnspecifiedGenericType(name, typeArguments) {
450
- return {
451
- kind: IDLKind.UnspecifiedGenericType,
452
- name,
453
- typeArguments,
454
- _idlNodeBrand: innerIdlSymbol,
455
- _idlTypeBrand: innerIdlSymbol,
456
- _idlNamedNodeBrand: innerIdlSymbol,
457
- };
544
+ export function createUnspecifiedGenericType(name, typeArguments, nodeInitializer) {
545
+ return Object.assign(Object.assign({ kind: IDLKind.UnspecifiedGenericType, name,
546
+ typeArguments }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
458
547
  }
459
548
  export function entityToType(entity) {
460
549
  if (isType(entity)) {
@@ -467,35 +556,16 @@ export function entityToType(entity) {
467
556
  throw new Error(`Expected to have IDLType or IDLEntry, got ${entity}`);
468
557
  }
469
558
  }
470
- export function createContainerType(container, element) {
471
- return {
472
- kind: IDLKind.ContainerType,
473
- containerKind: container,
474
- elementType: element,
475
- _idlNodeBrand: innerIdlSymbol,
476
- _idlTypeBrand: innerIdlSymbol,
477
- };
559
+ export function createContainerType(container, element, nodeInitializer) {
560
+ return Object.assign(Object.assign({ kind: IDLKind.ContainerType, containerKind: container, elementType: element }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol });
478
561
  }
479
- export function createUnionType(types, name) {
562
+ export function createUnionType(types, name, nodeInitializer) {
480
563
  if (types.length < 2)
481
564
  throw new Error("IDLUnionType should contain at least 2 types");
482
- return {
483
- kind: IDLKind.UnionType,
484
- name: name !== null && name !== void 0 ? name : "Union_" + types.map(it => generateSyntheticIdlNodeName(it)).join("_"),
485
- types: types,
486
- _idlNodeBrand: innerIdlSymbol,
487
- _idlTypeBrand: innerIdlSymbol,
488
- _idlNamedNodeBrand: innerIdlSymbol,
489
- };
565
+ return Object.assign(Object.assign({ kind: IDLKind.UnionType, name: name !== null && name !== void 0 ? name : "Union_" + types.map(it => generateSyntheticIdlNodeName(it)).join("_"), types: types }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
490
566
  }
491
- export function createFile(entries, fileName, packageClause = []) {
492
- return {
493
- kind: IDLKind.File,
494
- packageClause,
495
- entries: entries,
496
- fileName,
497
- _idlNodeBrand: innerIdlSymbol,
498
- };
567
+ export function createFile(entries, fileName, packageClause = [], nodeInitializer) {
568
+ return Object.assign(Object.assign({ kind: IDLKind.File, packageClause, entries: entries, fileName }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol });
499
569
  }
500
570
  export function createImport(clause, name, nodeInitializer) {
501
571
  return Object.assign(Object.assign({ kind: IDLKind.Import, name: name || "", clause }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
@@ -561,14 +631,8 @@ export function createCallback(name, parameters, returnType, nodeInitializer = {
561
631
  });
562
632
  return Object.assign(Object.assign({ kind: IDLKind.Callback, name, parameters, returnType, typeParameters }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
563
633
  }
564
- export function createTypeParameterReference(name) {
565
- return {
566
- kind: IDLKind.TypeParameterType,
567
- name: name,
568
- _idlNodeBrand: innerIdlSymbol,
569
- _idlTypeBrand: innerIdlSymbol,
570
- _idlNamedNodeBrand: innerIdlSymbol,
571
- };
634
+ export function createTypeParameterReference(name, nodeInitializer) {
635
+ return Object.assign(Object.assign({ kind: IDLKind.TypeParameterType, name: name }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
572
636
  }
573
637
  export function createTypedef(name, type, typeParameters = [], nodeInitializer = {}) {
574
638
  return Object.assign(Object.assign({ name, type, typeParameters, kind: IDLKind.Typedef }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
@@ -578,6 +642,196 @@ export function createConstant(name, type, value, nodeInitializer = {}) {
578
642
  type,
579
643
  value }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
580
644
  }
645
+ export function clone(node) {
646
+ var _a, _b, _c, _d;
647
+ const make = (node) => node;
648
+ const get = (node) => node;
649
+ switch (node.kind) {
650
+ case IDLKind.Interface: {
651
+ const entry = get(node);
652
+ return make(createInterface(entry.name, entry.subkind, (_a = entry.inheritance) === null || _a === void 0 ? void 0 : _a.map(clone), (_b = entry.constructors) === null || _b === void 0 ? void 0 : _b.map(clone), entry.constants.map(clone), entry.properties.map(clone), entry.methods.map(clone), entry.callables.map(clone), (_c = entry.typeParameters) === null || _c === void 0 ? void 0 : _c.map(it => it), {
653
+ documentation: node.documentation,
654
+ extendedAttributes: node.extendedAttributes,
655
+ fileName: node.fileName
656
+ }));
657
+ }
658
+ case IDLKind.Import: {
659
+ const entry = get(node);
660
+ return make(createImport(entry.clause, entry.name, {
661
+ documentation: entry.documentation,
662
+ extendedAttributes: entry.extendedAttributes,
663
+ fileName: entry.fileName
664
+ }));
665
+ }
666
+ case IDLKind.Callback: {
667
+ const entry = get(node);
668
+ return make(createCallback(entry.name, entry.parameters.map(clone), clone(entry.returnType), {
669
+ documentation: entry.documentation,
670
+ extendedAttributes: entry.extendedAttributes,
671
+ fileName: entry.fileName
672
+ }, entry.typeParameters));
673
+ }
674
+ case IDLKind.Const: {
675
+ const entry = get(node);
676
+ return make(createConstant(entry.name, clone(entry.type), entry.value, {
677
+ documentation: entry.documentation,
678
+ extendedAttributes: entry.extendedAttributes,
679
+ fileName: entry.fileName
680
+ }));
681
+ }
682
+ case IDLKind.Property: {
683
+ const entry = get(node);
684
+ return make(createProperty(entry.name, clone(entry.type), entry.isReadonly, entry.isStatic, entry.isOptional, {
685
+ documentation: entry.documentation,
686
+ extendedAttributes: entry.extendedAttributes,
687
+ fileName: entry.fileName
688
+ }));
689
+ }
690
+ case IDLKind.Parameter: {
691
+ const entry = get(node);
692
+ return make(createParameter(entry.name, clone(entry.type), entry.isOptional, entry.isVariadic, {
693
+ documentation: entry.documentation,
694
+ extendedAttributes: entry.extendedAttributes,
695
+ fileName: entry.fileName
696
+ }));
697
+ }
698
+ case IDLKind.Method: {
699
+ const entry = get(node);
700
+ return make(createMethod(entry.name, entry.parameters.map(clone), clone(entry.returnType), {
701
+ isAsync: entry.isAsync,
702
+ isFree: entry.isFree,
703
+ isOptional: entry.isOptional,
704
+ isStatic: entry.isStatic
705
+ }, {
706
+ documentation: entry.documentation,
707
+ extendedAttributes: entry.extendedAttributes,
708
+ fileName: entry.fileName
709
+ }, entry.typeParameters));
710
+ }
711
+ case IDLKind.Callable: {
712
+ const entry = get(node);
713
+ return make(createCallable(entry.name, entry.parameters.map(clone), clone(entry.returnType), {
714
+ isAsync: entry.isAsync,
715
+ isStatic: entry.isStatic
716
+ }, {
717
+ documentation: entry.documentation,
718
+ extendedAttributes: entry.extendedAttributes,
719
+ fileName: entry.documentation
720
+ }, entry.typeParameters));
721
+ }
722
+ case IDLKind.Constructor: {
723
+ const entry = get(node);
724
+ return make(createConstructor(entry.parameters.map(clone), entry.returnType ? clone(entry.returnType) : undefined, {
725
+ documentation: entry.documentation,
726
+ extendedAttributes: entry.extendedAttributes,
727
+ fileName: entry.fileName
728
+ }));
729
+ }
730
+ case IDLKind.Enum: {
731
+ const entry = get(node);
732
+ const cloned = createEnum(entry.name, entry.elements.map(clone), {
733
+ documentation: entry.documentation,
734
+ extendedAttributes: entry.extendedAttributes,
735
+ fileName: entry.fileName
736
+ });
737
+ cloned.elements.forEach(it => {
738
+ it.parent = cloned;
739
+ });
740
+ return make(cloned);
741
+ }
742
+ case IDLKind.EnumMember: {
743
+ const entry = get(node);
744
+ return make(createEnumMember(entry.name, entry.parent, clone(entry.type), entry.initializer, {
745
+ documentation: entry.documentation,
746
+ extendedAttributes: entry.extendedAttributes,
747
+ fileName: entry.fileName
748
+ }));
749
+ }
750
+ case IDLKind.Typedef: {
751
+ const entry = get(node);
752
+ return make(createTypedef(entry.name, clone(entry.type), entry.typeParameters, {
753
+ documentation: entry.documentation,
754
+ extendedAttributes: entry.extendedAttributes,
755
+ fileName: entry.fileName
756
+ }));
757
+ }
758
+ case IDLKind.PrimitiveType: {
759
+ return node;
760
+ }
761
+ case IDLKind.ContainerType: {
762
+ const type = get(node);
763
+ return make(createContainerType(type.containerKind, type.elementType.map(clone), {
764
+ documentation: type.documentation,
765
+ extendedAttributes: type.extendedAttributes,
766
+ fileName: type.fileName
767
+ }));
768
+ }
769
+ case IDLKind.UnspecifiedGenericType: {
770
+ const type = get(node);
771
+ return make(createUnspecifiedGenericType(type.name, type.typeArguments.map(clone), {
772
+ documentation: type.documentation,
773
+ extendedAttributes: type.extendedAttributes,
774
+ fileName: type.fileName
775
+ }));
776
+ }
777
+ case IDLKind.ReferenceType: {
778
+ const type = get(node);
779
+ return make(createReferenceType(type.name, (_d = type.typeArguments) === null || _d === void 0 ? void 0 : _d.map(clone), {
780
+ documentation: type.documentation,
781
+ extendedAttributes: type.extendedAttributes,
782
+ fileName: type.fileName
783
+ }));
784
+ }
785
+ case IDLKind.UnionType: {
786
+ const type = get(node);
787
+ return make(createUnionType(type.types.map(clone), type.name, {
788
+ documentation: type.documentation,
789
+ extendedAttributes: type.extendedAttributes,
790
+ fileName: type.fileName
791
+ }));
792
+ }
793
+ case IDLKind.TypeParameterType: {
794
+ const type = get(node);
795
+ return make(createTypeParameterReference(type.name, {
796
+ documentation: type.documentation,
797
+ extendedAttributes: type.extendedAttributes,
798
+ fileName: type.fileName
799
+ }));
800
+ }
801
+ case IDLKind.OptionalType: {
802
+ const type = get(node);
803
+ return make(createOptionalType(clone(type.type), {
804
+ documentation: type.documentation,
805
+ extendedAttributes: type.extendedAttributes,
806
+ fileName: type.fileName
807
+ }));
808
+ }
809
+ case IDLKind.Version: {
810
+ const entry = get(node);
811
+ return make(createVersion(entry.value, {
812
+ documentation: entry.documentation,
813
+ extendedAttributes: entry.extendedAttributes,
814
+ fileName: entry.fileName
815
+ }));
816
+ }
817
+ case IDLKind.Namespace: {
818
+ const ns = get(node);
819
+ return make(createNamespace(ns.name, ns.members.map(clone), {
820
+ documentation: ns.documentation,
821
+ extendedAttributes: ns.extendedAttributes,
822
+ fileName: ns.fileName
823
+ }));
824
+ }
825
+ case IDLKind.File: {
826
+ const file = get(node);
827
+ return make(createFile(file.entries.map(clone), file.fileName, file.packageClause, {
828
+ documentation: file.documentation,
829
+ extendedAttributes: file.extendedAttributes,
830
+ fileName: file.fileName
831
+ }));
832
+ }
833
+ }
834
+ }
581
835
  export function escapeIDLKeyword(name) {
582
836
  return name + (IDLKeywords.has(name) ? "_" : "");
583
837
  }
@@ -734,15 +988,17 @@ export function printMethod(idl) {
734
988
  ];
735
989
  }
736
990
  export function printPackage(idl) {
737
- if (!idl.packageClause.length)
991
+ const effectiveClause = idl.packageClause.filter(it => !!it);
992
+ if (!effectiveClause.length)
738
993
  return [];
739
994
  return [
740
- `package ${idl.packageClause.join(".")};`
995
+ `package ${effectiveClause.join(".")};`
741
996
  ];
742
997
  }
743
998
  export function printImport(idl) {
999
+ const effectiveClause = idl.clause.filter(it => !!it);
744
1000
  return [
745
- `import ${idl.clause.join(".")}${idl.name ? " as " : ""}${idl.name};`
1001
+ `import ${effectiveClause.join(".") || "NULL_IMPORT"}${idl.name ? " as " : ""}${idl.name};`
746
1002
  ];
747
1003
  }
748
1004
  export function printNamespace(idl) {
@@ -789,6 +1045,16 @@ export function getSuperType(idl) {
789
1045
  const parent = idl.inheritance[0];
790
1046
  return parent && parent !== IDLTopType ? parent : undefined;
791
1047
  }
1048
+ export function getSuperTypes(idl) {
1049
+ if (!idl.inheritance)
1050
+ return undefined;
1051
+ if (idl.inheritance[0] == IDLTopType) {
1052
+ return idl.inheritance.length == 1 ? undefined : idl.inheritance.slice(1);
1053
+ }
1054
+ else {
1055
+ return idl.inheritance.length == 0 ? undefined : idl.inheritance;
1056
+ }
1057
+ }
792
1058
  export function hasSuperType(idl) {
793
1059
  return isDefined(getSuperType(idl));
794
1060
  }
@@ -1015,10 +1281,9 @@ export function isStringEnum(decl) {
1015
1281
  export function linearizeNamespaceMembers(entries) {
1016
1282
  const linearized = [];
1017
1283
  for (const entry of entries) {
1284
+ linearized.push(entry);
1018
1285
  if (isNamespace(entry))
1019
1286
  linearized.push(...linearizeNamespaceMembers(entry.members));
1020
- else
1021
- linearized.push(entry);
1022
1287
  }
1023
1288
  return linearized;
1024
1289
  }
@@ -12,10 +12,12 @@ export interface GenerateVisitor<T> {
12
12
  tsSourceFile: ts.SourceFile;
13
13
  visitor: GenerateVisitor<T>;
14
14
  result: T;
15
+ isAux: boolean;
15
16
  };
16
17
  }): T;
17
18
  }
18
- export declare function generate<T>(inputFiles: string[], outputDir: string, visitorFactory: (sourceFile: ts.SourceFile, program: ts.Program, compilerHost: ts.CompilerHost) => GenerateVisitor<T>, options: GenerateOptions<T>): void;
19
+ export declare function generate<T>(baseDirs: string[], lookupDirs: string[], inputFiles: string[], auxInputFiles: string[], outputDir: string, stdlibFile: string, visitorFactory: (sourceFile: ts.SourceFile, program: ts.Program, compilerHost: ts.CompilerHost) => GenerateVisitor<T>, options: GenerateOptions<T>): void;
20
+ export declare const PACKAGE_IDLIZE_INTERNAL = "idlize.internal";
19
21
  export declare function isInIdlize(entry: idl.IDLEntry | idl.IDLFile): boolean;
20
22
  export declare function isInIdlizeInterop(entry: idl.IDLEntry | idl.IDLFile): boolean;
21
23
  export declare function isInIdlizeInternal(entry: idl.IDLEntry | idl.IDLFile): boolean;