@idlizer/core 2.0.32 → 2.0.35

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 (43) hide show
  1. package/build/lib/src/LanguageWriters/ArgConvertors.js +12 -4
  2. package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +11 -8
  3. package/build/lib/src/LanguageWriters/LanguageWriter.js +11 -8
  4. package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +2 -1
  5. package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +0 -2
  6. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +0 -1
  7. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +1 -7
  8. package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +10 -8
  9. package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +2 -2
  10. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +1 -0
  11. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +3 -0
  12. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +2 -1
  13. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +3 -0
  14. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +12 -2
  15. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +1 -0
  16. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +3 -0
  17. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +1 -0
  18. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +17 -3
  19. package/build/lib/src/from-idl/DtsPrinter.d.ts +3 -3
  20. package/build/lib/src/from-idl/DtsPrinter.js +18 -26
  21. package/build/lib/src/from-idl/common.d.ts +2 -2
  22. package/build/lib/src/from-idl/common.js +2 -8
  23. package/build/lib/src/from-idl/deserialize.d.ts +1 -4
  24. package/build/lib/src/from-idl/deserialize.js +17 -19
  25. package/build/lib/src/idl.d.ts +26 -33
  26. package/build/lib/src/idl.js +38 -56
  27. package/build/lib/src/index.d.ts +1 -1
  28. package/build/lib/src/index.js +1 -1
  29. package/build/lib/src/library.d.ts +1 -2
  30. package/build/lib/src/library.js +1 -4
  31. package/build/lib/src/peer-generation/Materialized.d.ts +3 -1
  32. package/build/lib/src/peer-generation/Materialized.js +8 -1
  33. package/build/lib/src/peer-generation/PeerFile.d.ts +1 -1
  34. package/build/lib/src/peer-generation/PeerFile.js +3 -11
  35. package/build/lib/src/peer-generation/PeerLibrary.d.ts +10 -5
  36. package/build/lib/src/peer-generation/PeerLibrary.js +31 -4
  37. package/build/lib/src/peer-generation/PeerMethod.js +5 -1
  38. package/build/lib/src/peer-generation/PrimitiveType.d.ts +2 -0
  39. package/build/lib/src/peer-generation/PrimitiveType.js +4 -0
  40. package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +5 -4
  41. package/build/lib/src/peer-generation/isMaterialized.d.ts +1 -0
  42. package/build/lib/src/peer-generation/isMaterialized.js +8 -0
  43. package/package.json +2 -2
@@ -28,16 +28,13 @@ export function addSyntheticType(name, type) {
28
28
  export function resolveSyntheticType(type) {
29
29
  return syntheticTypes.get(type.name);
30
30
  }
31
- export function toIDLNode(file, node) {
31
+ function toIDLNode(file, node) {
32
32
  return toIDLNodeForward(file, node);
33
33
  }
34
34
  function toIDLNodeForward(file, node) {
35
35
  if (isEnum(node)) {
36
36
  return toIDLEnum(file, node);
37
37
  }
38
- if (isPackage(node)) {
39
- return toIDLPackage(node);
40
- }
41
38
  if (isImport(node)) {
42
39
  return toIDLImport(node);
43
40
  }
@@ -85,13 +82,6 @@ function isImport(node) {
85
82
  function isCallable(node) {
86
83
  return node.extAttrs.some(it => it.name == "Invoke");
87
84
  }
88
- function toIDLPackage(node) {
89
- if (node.clause.startsWith('"')) { // TODO: remove after new schema formation
90
- //node.clause = node.clause.substring(1, node.clause.length - 1)
91
- throw new Error("Obsolete IDL-source syntax detected");
92
- }
93
- return idl.createPackage(node.clause.split("."));
94
- }
95
85
  function toIDLImport(node) {
96
86
  // console.log(node)
97
87
  return idl.createImport(node.clause.split("."), node.alias || undefined);
@@ -369,14 +359,22 @@ function findExtendedAttribute(extAttrs, name) {
369
359
  const attr = extAttrs.find(it => it.name === name);
370
360
  return attr ? toExtendedAttributeValue(attr) : undefined;
371
361
  }
372
- export function toIDL(file) {
373
- const content = fs.readFileSync(file).toString();
374
- return webidl2.parse(content).map(it => toIDLNode(file, it));
375
- }
376
- export function toIDLFile(fileName) {
377
- const content = fs.readFileSync(fileName).toString();
378
- const entries = webidl2.parse(content).map(it => toIDLNode(fileName, it));
379
- const file = idl.createFile(entries, fileName);
362
+ export function toIDLFile(fileName, content) {
363
+ if (undefined === content)
364
+ content = fs.readFileSync(fileName).toString();
365
+ let packageClause = [];
366
+ const entries = webidl2.parse(content)
367
+ .filter(it => {
368
+ if (!it.type)
369
+ return false;
370
+ if (isPackage(it)) {
371
+ packageClause = it.clause.split(".");
372
+ return false;
373
+ }
374
+ return true;
375
+ })
376
+ .map(it => toIDLNode(fileName, it));
377
+ const file = idl.createFile(entries, fileName, packageClause);
380
378
  return idl.linkParentBack(file);
381
379
  }
382
380
  //# sourceMappingURL=deserialize.js.map
@@ -1,33 +1,31 @@
1
1
  import { stringOrNone } from "./util";
2
2
  export declare enum IDLKind {
3
3
  Interface = 0,
4
- Package = 1,
5
- Import = 2,
6
- Callback = 3,
7
- Const = 4,
8
- Property = 5,
9
- Parameter = 6,
10
- Method = 7,
11
- Callable = 8,
12
- Constructor = 9,
13
- Enum = 10,
14
- EnumMember = 11,
15
- Typedef = 12,
16
- PrimitiveType = 13,
17
- ContainerType = 14,
18
- UnspecifiedGenericType = 15,
19
- ReferenceType = 16,
20
- UnionType = 17,
21
- TypeParameterType = 18,
22
- OptionalType = 19,
23
- Version = 20,
24
- Namespace = 21,
25
- File = 22
4
+ Import = 1,
5
+ Callback = 2,
6
+ Const = 3,
7
+ Property = 4,
8
+ Parameter = 5,
9
+ Method = 6,
10
+ Callable = 7,
11
+ Constructor = 8,
12
+ Enum = 9,
13
+ EnumMember = 10,
14
+ Typedef = 11,
15
+ PrimitiveType = 12,
16
+ ContainerType = 13,
17
+ UnspecifiedGenericType = 14,
18
+ ReferenceType = 15,
19
+ UnionType = 16,
20
+ TypeParameterType = 17,
21
+ OptionalType = 18,
22
+ Version = 19,
23
+ Namespace = 20,
24
+ File = 21
26
25
  }
27
26
  export declare enum IDLEntity {
28
27
  Class = "Class",
29
28
  Interface = "Interface",
30
- Package = "Package",
31
29
  Import = "Import",
32
30
  Intersection = "Intersection",
33
31
  Literal = "Literal",
@@ -49,7 +47,6 @@ export declare enum IDLExtendedAttributes {
49
47
  DtsName = "DtsName",
50
48
  DtsTag = "DtsTag",
51
49
  Entity = "Entity",
52
- GlobalScope = "GlobalScope",
53
50
  Import = "Import",
54
51
  IndexSignature = "IndexSignature",
55
52
  Interfaces = "Interfaces",
@@ -59,6 +56,7 @@ export declare enum IDLExtendedAttributes {
59
56
  Predefined = "Predefined",
60
57
  Protected = "Protected",
61
58
  Synthetic = "Synthetic",
59
+ Throws = "Throws",
62
60
  TSType = "TSType",
63
61
  TypeArguments = "TypeArguments",
64
62
  TypeParameters = "TypeParameters",
@@ -82,6 +80,7 @@ export interface IDLNode {
82
80
  documentation?: string;
83
81
  }
84
82
  export interface IDLFile extends IDLNode {
83
+ packageClause: string[];
85
84
  entries: IDLEntry[];
86
85
  fileName?: string;
87
86
  }
@@ -206,10 +205,6 @@ export interface IDLInterface extends IDLEntry {
206
205
  methods: IDLMethod[];
207
206
  callables: IDLCallable[];
208
207
  }
209
- export interface IDLPackage extends IDLEntry {
210
- kind: IDLKind.Package;
211
- clause: string[];
212
- }
213
208
  export interface IDLImport extends IDLEntry {
214
209
  kind: IDLKind.Import;
215
210
  clause: string[];
@@ -237,7 +232,6 @@ export declare function isEnumMember(type: IDLNode): type is IDLEnumMember;
237
232
  export declare function isUnionType(type: IDLNode): type is IDLUnionType;
238
233
  export declare function isTypeParameterType(type: IDLNode): type is IDLTypeParameterType;
239
234
  export declare function isInterface(node: IDLNode): node is IDLInterface;
240
- export declare function isPackage(type: IDLNode): type is IDLPackage;
241
235
  export declare function isImport(type: IDLNode): type is IDLImport;
242
236
  export declare function isCallable(node: IDLNode): node is IDLCallable;
243
237
  export declare function isMethod(node: IDLNode): node is IDLMethod;
@@ -316,8 +310,7 @@ export declare function createUnspecifiedGenericType(name: string, typeArguments
316
310
  export declare function entityToType(entity: IDLNode): IDLType;
317
311
  export declare function createContainerType(container: IDLContainerKind, element: IDLType[]): IDLContainerType;
318
312
  export declare function createUnionType(types: IDLType[], name?: string): IDLUnionType;
319
- export declare function createFile(entries: IDLEntry[], fileName?: string): IDLFile;
320
- export declare function createPackage(clause: string[]): IDLPackage;
313
+ export declare function createFile(entries: IDLEntry[], fileName?: string, packageClause?: string[]): IDLFile;
321
314
  export declare function createImport(clause: string[], name?: string, nodeInitializer?: IDLNodeInitializer): IDLImport;
322
315
  export declare function createEnum(name: string, elements: IDLEnumMember[], nodeInitializer: IDLNodeInitializer): IDLEnum;
323
316
  export declare function createEnumMember(name: string, parent: IDLEnum, type: IDLPrimitiveType, initializer: number | string | undefined, nodeInitializer?: IDLNodeInitializer): IDLEnumMember;
@@ -360,7 +353,7 @@ export declare function printExtendedAttributes(idl: IDLNode, indentLevel: numbe
360
353
  export declare const attributesToQuote: Set<IDLExtendedAttributes>;
361
354
  export declare function printFunction(idl: IDLFunction): PrintedLine[];
362
355
  export declare function printMethod(idl: IDLMethod): PrintedLine[];
363
- export declare function printPackage(idl: IDLPackage): PrintedLine[];
356
+ export declare function printPackage(idl: IDLFile): PrintedLine[];
364
357
  export declare function printImport(idl: IDLImport): PrintedLine[];
365
358
  export declare function printNamespace(idl: IDLNamespace): PrintedLine[];
366
359
  export declare function printCallback(idl: IDLCallback): PrintedLine[];
@@ -377,7 +370,7 @@ export interface IDLPrintOptions {
377
370
  disableEnumInitializers: boolean;
378
371
  allowUnknownKinds: boolean;
379
372
  }
380
- export declare function toIDLString(entries: IDLEntry[], options: Partial<IDLPrintOptions>): string;
373
+ export declare function toIDLString(file: IDLFile, options: Partial<IDLPrintOptions>): string;
381
374
  export declare function verifyIDLString(source: string): true;
382
375
  export declare function hasExtAttribute(node: IDLNode, attribute: IDLExtendedAttributes): boolean;
383
376
  export declare function getExtAttribute(node: IDLNode, name: IDLExtendedAttributes): stringOrNone;
@@ -19,34 +19,32 @@ import { IDLKeywords } from "./languageSpecificKeywords";
19
19
  export var IDLKind;
20
20
  (function (IDLKind) {
21
21
  IDLKind[IDLKind["Interface"] = 0] = "Interface";
22
- IDLKind[IDLKind["Package"] = 1] = "Package";
23
- IDLKind[IDLKind["Import"] = 2] = "Import";
24
- IDLKind[IDLKind["Callback"] = 3] = "Callback";
25
- IDLKind[IDLKind["Const"] = 4] = "Const";
26
- IDLKind[IDLKind["Property"] = 5] = "Property";
27
- IDLKind[IDLKind["Parameter"] = 6] = "Parameter";
28
- IDLKind[IDLKind["Method"] = 7] = "Method";
29
- IDLKind[IDLKind["Callable"] = 8] = "Callable";
30
- IDLKind[IDLKind["Constructor"] = 9] = "Constructor";
31
- IDLKind[IDLKind["Enum"] = 10] = "Enum";
32
- IDLKind[IDLKind["EnumMember"] = 11] = "EnumMember";
33
- IDLKind[IDLKind["Typedef"] = 12] = "Typedef";
34
- IDLKind[IDLKind["PrimitiveType"] = 13] = "PrimitiveType";
35
- IDLKind[IDLKind["ContainerType"] = 14] = "ContainerType";
36
- IDLKind[IDLKind["UnspecifiedGenericType"] = 15] = "UnspecifiedGenericType";
37
- IDLKind[IDLKind["ReferenceType"] = 16] = "ReferenceType";
38
- IDLKind[IDLKind["UnionType"] = 17] = "UnionType";
39
- IDLKind[IDLKind["TypeParameterType"] = 18] = "TypeParameterType";
40
- IDLKind[IDLKind["OptionalType"] = 19] = "OptionalType";
41
- IDLKind[IDLKind["Version"] = 20] = "Version";
42
- IDLKind[IDLKind["Namespace"] = 21] = "Namespace";
43
- IDLKind[IDLKind["File"] = 22] = "File";
22
+ IDLKind[IDLKind["Import"] = 1] = "Import";
23
+ IDLKind[IDLKind["Callback"] = 2] = "Callback";
24
+ IDLKind[IDLKind["Const"] = 3] = "Const";
25
+ IDLKind[IDLKind["Property"] = 4] = "Property";
26
+ IDLKind[IDLKind["Parameter"] = 5] = "Parameter";
27
+ IDLKind[IDLKind["Method"] = 6] = "Method";
28
+ IDLKind[IDLKind["Callable"] = 7] = "Callable";
29
+ IDLKind[IDLKind["Constructor"] = 8] = "Constructor";
30
+ IDLKind[IDLKind["Enum"] = 9] = "Enum";
31
+ IDLKind[IDLKind["EnumMember"] = 10] = "EnumMember";
32
+ IDLKind[IDLKind["Typedef"] = 11] = "Typedef";
33
+ IDLKind[IDLKind["PrimitiveType"] = 12] = "PrimitiveType";
34
+ IDLKind[IDLKind["ContainerType"] = 13] = "ContainerType";
35
+ IDLKind[IDLKind["UnspecifiedGenericType"] = 14] = "UnspecifiedGenericType";
36
+ IDLKind[IDLKind["ReferenceType"] = 15] = "ReferenceType";
37
+ IDLKind[IDLKind["UnionType"] = 16] = "UnionType";
38
+ IDLKind[IDLKind["TypeParameterType"] = 17] = "TypeParameterType";
39
+ IDLKind[IDLKind["OptionalType"] = 18] = "OptionalType";
40
+ IDLKind[IDLKind["Version"] = 19] = "Version";
41
+ IDLKind[IDLKind["Namespace"] = 20] = "Namespace";
42
+ IDLKind[IDLKind["File"] = 21] = "File";
44
43
  })(IDLKind || (IDLKind = {}));
45
44
  export var IDLEntity;
46
45
  (function (IDLEntity) {
47
46
  IDLEntity["Class"] = "Class";
48
47
  IDLEntity["Interface"] = "Interface";
49
- IDLEntity["Package"] = "Package";
50
48
  IDLEntity["Import"] = "Import";
51
49
  IDLEntity["Intersection"] = "Intersection";
52
50
  IDLEntity["Literal"] = "Literal";
@@ -69,7 +67,6 @@ export var IDLExtendedAttributes;
69
67
  IDLExtendedAttributes["DtsName"] = "DtsName";
70
68
  IDLExtendedAttributes["DtsTag"] = "DtsTag";
71
69
  IDLExtendedAttributes["Entity"] = "Entity";
72
- IDLExtendedAttributes["GlobalScope"] = "GlobalScope";
73
70
  IDLExtendedAttributes["Import"] = "Import";
74
71
  IDLExtendedAttributes["IndexSignature"] = "IndexSignature";
75
72
  IDLExtendedAttributes["Interfaces"] = "Interfaces";
@@ -79,6 +76,7 @@ export var IDLExtendedAttributes;
79
76
  IDLExtendedAttributes["Predefined"] = "Predefined";
80
77
  IDLExtendedAttributes["Protected"] = "Protected";
81
78
  IDLExtendedAttributes["Synthetic"] = "Synthetic";
79
+ IDLExtendedAttributes["Throws"] = "Throws";
82
80
  IDLExtendedAttributes["TSType"] = "TSType";
83
81
  IDLExtendedAttributes["TypeArguments"] = "TypeArguments";
84
82
  IDLExtendedAttributes["TypeParameters"] = "TypeParameters";
@@ -170,7 +168,6 @@ export function forEachChild(node, cbEnter, cbLeave) {
170
168
  case IDLKind.ReferenceType:
171
169
  case IDLKind.TypeParameterType:
172
170
  case IDLKind.EnumMember:
173
- case IDLKind.Package:
174
171
  case IDLKind.Import:
175
172
  case IDLKind.PrimitiveType:
176
173
  case IDLKind.Version:
@@ -227,9 +224,6 @@ export function isTypeParameterType(type) {
227
224
  export function isInterface(node) {
228
225
  return node.kind === IDLKind.Interface;
229
226
  }
230
- export function isPackage(type) {
231
- return type.kind == IDLKind.Package;
232
- }
233
227
  export function isImport(type) {
234
228
  return type.kind == IDLKind.Import;
235
229
  }
@@ -399,13 +393,7 @@ export function isEqualByQualifedName(a, b) {
399
393
  }
400
394
  export function getPackageClause(entry) {
401
395
  let file = getFileFor(entry);
402
- if (!file)
403
- return [];
404
- for (const child of file.entries)
405
- if (isPackage(child))
406
- return child.clause;
407
- // console.warn("Expected to have one IDLPackage inside IDLFile. Using empty package name")
408
- return [];
396
+ return (file === null || file === void 0 ? void 0 : file.packageClause) || [];
409
397
  }
410
398
  export function getPackageName(entry) {
411
399
  return getPackageClause(entry).join(".");
@@ -498,24 +486,15 @@ export function createUnionType(types, name) {
498
486
  _idlNamedNodeBrand: innerIdlSymbol,
499
487
  };
500
488
  }
501
- export function createFile(entries, fileName) {
489
+ export function createFile(entries, fileName, packageClause = []) {
502
490
  return {
503
491
  kind: IDLKind.File,
492
+ packageClause,
504
493
  entries: entries,
505
494
  fileName,
506
495
  _idlNodeBrand: innerIdlSymbol,
507
496
  };
508
497
  }
509
- export function createPackage(clause) {
510
- return {
511
- kind: IDLKind.Package,
512
- name: "",
513
- clause,
514
- _idlNodeBrand: innerIdlSymbol,
515
- _idlEntryBrand: innerIdlSymbol,
516
- _idlNamedNodeBrand: innerIdlSymbol,
517
- };
518
- }
519
498
  export function createImport(clause, name, nodeInitializer) {
520
499
  return Object.assign(Object.assign({ kind: IDLKind.Import, name: name || "", clause }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
521
500
  }
@@ -753,10 +732,10 @@ export function printMethod(idl) {
753
732
  ];
754
733
  }
755
734
  export function printPackage(idl) {
756
- if (!idl.clause.length)
735
+ if (!idl.packageClause.length)
757
736
  return [];
758
737
  return [
759
- `package ${idl.clause.join(".")};`
738
+ `package ${idl.packageClause.join(".")};`
760
739
  ];
761
740
  }
762
741
  export function printImport(idl) {
@@ -855,6 +834,7 @@ export function printTypedef(idl) {
855
834
  `typedef ${printType(idl.type)} ${idl.name};`
856
835
  ];
857
836
  }
837
+ // TODO: use IndentedPrinter instead!
858
838
  export function printIDL(idl, options) {
859
839
  var _a;
860
840
  if (idl.kind == IDLKind.Interface)
@@ -865,8 +845,6 @@ export function printIDL(idl, options) {
865
845
  return printTypedef(idl);
866
846
  if (idl.kind == IDLKind.Callback)
867
847
  return printCallback(idl);
868
- if (idl.kind == IDLKind.Package)
869
- return printPackage(idl);
870
848
  if (idl.kind == IDLKind.Import)
871
849
  return printImport(idl);
872
850
  if (idl.kind == IDLKind.Namespace)
@@ -882,23 +860,27 @@ export function printIDL(idl, options) {
882
860
  throw new Error(`unexpected kind: ${idl.kind}`);
883
861
  }
884
862
  }
885
- export function toIDLString(entries, options) {
863
+ export function toIDLString(file, options) {
886
864
  let indent = 0;
887
- const generatedIdl = entries
865
+ const generated = printPackage(file);
866
+ return generated.concat(file.entries
888
867
  .map(it => printIDL(it, options))
889
868
  .flat()
890
869
  .filter(isDefined)
891
870
  .filter(it => it.length > 0)
892
871
  .map(it => {
893
- if (it === printedIndentInc)
872
+ if (it === printedIndentInc) {
894
873
  ++indent;
895
- else if (it === printedIndentDec)
874
+ return undefined;
875
+ }
876
+ else if (it === printedIndentDec) {
896
877
  --indent;
878
+ return undefined;
879
+ }
897
880
  else
898
881
  return indentedBy(it, indent);
899
882
  })
900
- .join("\n");
901
- return generatedIdl;
883
+ .filter(isDefined)).join("\n");
902
884
  }
903
885
  // throws validation error
904
886
  export function verifyIDLString(source) {
@@ -45,5 +45,5 @@ export * from "./peer-generation/ReferenceResolver";
45
45
  export * from "./peer-generation/idl/common";
46
46
  export { fromIDL } from "./from-idl/common";
47
47
  export { idlToDtsString, CustomPrintVisitor } from "./from-idl/DtsPrinter";
48
- export { toIDL, toIDLFile, addSyntheticType, resolveSyntheticType } from "./from-idl/deserialize";
48
+ export { toIDLFile, addSyntheticType, resolveSyntheticType } from "./from-idl/deserialize";
49
49
  //# sourceMappingURL=index.d.ts.map
@@ -59,5 +59,5 @@ export * from "./peer-generation/ReferenceResolver";
59
59
  export * from "./peer-generation/idl/common";
60
60
  export { fromIDL } from "./from-idl/common";
61
61
  export { idlToDtsString, CustomPrintVisitor } from "./from-idl/DtsPrinter";
62
- export { toIDL, toIDLFile, addSyntheticType, resolveSyntheticType } from "./from-idl/deserialize";
62
+ export { toIDLFile, addSyntheticType, resolveSyntheticType } from "./from-idl/deserialize";
63
63
  //# sourceMappingURL=index.js.map
@@ -31,7 +31,6 @@ export type QueryType<T> = LibraryQuery<IDLLibrary, T> | LensBuilder<T>;
31
31
  export declare function query<T>(lib: IDLLibrary, input: QueryType<T>): T;
32
32
  interface EntitiesParams {
33
33
  expandNamespaces?: boolean;
34
- slipPackage?: boolean;
35
34
  }
36
35
  export declare const lib: {
37
36
  createLibrary: typeof createLibrary;
@@ -40,7 +39,7 @@ export declare const lib: {
40
39
  query: typeof query;
41
40
  select: {
42
41
  files(): LibraryReducer<readonly idl.IDLFile[]>;
43
- nodes(params: EntitiesParams): LibraryQuery<readonly idl.IDLFile[], idl.IDLNode[]>;
42
+ nodes(params?: EntitiesParams): LibraryQuery<readonly idl.IDLFile[], idl.IDLNode[]>;
44
43
  entries(): LibraryQuery<idl.IDLNode[], idl.IDLEntry[]>;
45
44
  interfaces(): LibraryQuery<idl.IDLNode[], idl.IDLInterface[]>;
46
45
  hasExt<T extends idl.IDLNode>(attr: idl.IDLExtendedAttributes): LibraryQuery<T[], T[]>;
@@ -139,12 +139,9 @@ const select = {
139
139
  nodes(params) {
140
140
  const key = 'entities' + serializeParam(params);
141
141
  function go(node) {
142
- if (idl.isNamespace(node) && params.expandNamespaces) {
142
+ if (idl.isNamespace(node) && (params === null || params === void 0 ? void 0 : params.expandNamespaces)) {
143
143
  return node.members.flatMap(go);
144
144
  }
145
- if (idl.isPackage(node) && params.slipPackage) {
146
- return [];
147
- }
148
145
  return [node];
149
146
  }
150
147
  return req(key, xs => {
@@ -52,9 +52,11 @@ export declare class MaterializedClass implements PeerClassBase {
52
52
  getComponentName(): string;
53
53
  getImplementationName(): string;
54
54
  generatedName(isCallSignature: boolean): string;
55
+ private _isGlobal;
56
+ setGlobalScope(): void;
55
57
  isGlobalScope(): boolean;
56
58
  }
57
- export declare function createDestroyPeerMethod(clazz: MaterializedClass): MaterializedMethod;
59
+ export declare function createDestroyPeerMethod(clazz: MaterializedClass): MaterializedMethod | undefined;
58
60
  export declare function getInternalClassName(name: string): string;
59
61
  export declare function getInternalClassQualifiedName(target: idl.IDLEntry): string;
60
62
  export declare function getMaterializedFileName(name: string): string;
@@ -111,6 +111,7 @@ export class MaterializedClass {
111
111
  this.methods = methods;
112
112
  this.needBeGenerated = needBeGenerated;
113
113
  this.taggedMethods = taggedMethods;
114
+ this._isGlobal = false;
114
115
  PeerMethod.markAndGroupOverloads(methods);
115
116
  }
116
117
  getComponentName() {
@@ -122,11 +123,17 @@ export class MaterializedClass {
122
123
  generatedName(isCallSignature) {
123
124
  return this.className;
124
125
  }
126
+ setGlobalScope() {
127
+ this._isGlobal = true;
128
+ }
125
129
  isGlobalScope() {
126
- return idl.hasExtAttribute(this.decl, idl.IDLExtendedAttributes.GlobalScope);
130
+ return this._isGlobal;
127
131
  }
128
132
  }
129
133
  export function createDestroyPeerMethod(clazz) {
134
+ if (clazz.isGlobalScope()) {
135
+ return undefined;
136
+ }
130
137
  return new MaterializedMethod(clazz.className, clazz.getImplementationName(), [], idl.IDLVoidType, false, new Method('destroyPeer', new NamedMethodSignature(idl.IDLVoidType, [idl.createReferenceType(clazz.className)], ['peer'])));
131
138
  }
132
139
  export function getInternalClassName(name) {
@@ -7,7 +7,7 @@ export declare class PeerFile implements LibraryFileInterface {
7
7
  readonly peers: Map<string, PeerClass>;
8
8
  constructor(file: idl.IDLFile, isPredefined?: boolean);
9
9
  packageName(): string;
10
- package(): idl.IDLPackage | undefined;
10
+ packageClause(): string[];
11
11
  get peersToGenerate(): PeerClass[];
12
12
  get entries(): idl.IDLEntry[];
13
13
  get originalFilename(): string;
@@ -12,7 +12,6 @@
12
12
  * See the License for the specific language governing permissions and
13
13
  * limitations under the License.
14
14
  */
15
- import * as idl from '../idl';
16
15
  export class PeerFile {
17
16
  constructor(file, isPredefined = false) {
18
17
  this.file = file;
@@ -20,17 +19,10 @@ export class PeerFile {
20
19
  this.peers = new Map();
21
20
  }
22
21
  packageName() {
23
- const packageTag = this.package();
24
- if (packageTag === undefined) {
25
- return "";
26
- }
27
- if (packageTag.name.startsWith('"') && packageTag.name.endsWith('"')) {
28
- return packageTag.name.slice(1, packageTag.name.length - 1);
29
- }
30
- return packageTag.name;
22
+ return this.packageClause().join(".");
31
23
  }
32
- package() {
33
- return this.entries.find(it => idl.isPackage(it));
24
+ packageClause() {
25
+ return this.file.packageClause;
34
26
  }
35
27
  get peersToGenerate() {
36
28
  const peers = Array.from(this.peers.values());
@@ -9,10 +9,14 @@ import { MaterializedClass } from './Materialized';
9
9
  import { PeerFile } from './PeerFile';
10
10
  import { LayoutManager, LayoutManagerStrategy } from './LayoutManager';
11
11
  import { IDLLibrary } from '../library';
12
+ export interface GlobalScopeDeclarations {
13
+ methods: idl.IDLMethod[];
14
+ constants: idl.IDLConstant[];
15
+ }
12
16
  export declare const lenses: {
13
17
  globals: {
14
- req: import("../library").LibraryReducer<idl.IDLInterface[]>;
15
- pipe<T>(r: import("../library").LibraryQuery<idl.IDLInterface[], T>): {
18
+ req: import("../library").LibraryReducer<GlobalScopeDeclarations[]>;
19
+ pipe<T>(r: import("../library").LibraryQuery<GlobalScopeDeclarations[], T>): {
16
20
  req: import("../library").LibraryReducer<T>;
17
21
  pipe<T_1>(r: import("../library").LibraryQuery<T, T_1>): {
18
22
  req: import("../library").LibraryReducer<T_1>;
@@ -5128,7 +5132,7 @@ export declare const lenses: {
5128
5132
  };
5129
5133
  query(): import("../library").LibraryReducer<T>;
5130
5134
  };
5131
- row<T_2047>(key: string, f: (x: idl.IDLInterface[]) => T_2047): {
5135
+ row<T_2047>(key: string, f: (x: GlobalScopeDeclarations[]) => T_2047): {
5132
5136
  req: import("../library").LibraryReducer<T_2047>;
5133
5137
  pipe<T_2048>(r: import("../library").LibraryQuery<T_2047, T_2048>): {
5134
5138
  req: import("../library").LibraryReducer<T_2048>;
@@ -10244,7 +10248,7 @@ export declare const lenses: {
10244
10248
  };
10245
10249
  query(): import("../library").LibraryReducer<T_2047>;
10246
10250
  };
10247
- query(): import("../library").LibraryReducer<idl.IDLInterface[]>;
10251
+ query(): import("../library").LibraryReducer<GlobalScopeDeclarations[]>;
10248
10252
  };
10249
10253
  };
10250
10254
  export declare class PeerLibrary implements LibraryInterface {
@@ -10252,10 +10256,11 @@ export declare class PeerLibrary implements LibraryInterface {
10252
10256
  libraryPackages: string[] | undefined;
10253
10257
  private _cachedIdlLibrary?;
10254
10258
  asIDLLibrary(): IDLLibrary;
10255
- get globalScopeInterfaces(): idl.IDLInterface[];
10259
+ get globals(): GlobalScopeDeclarations[];
10256
10260
  layout: LayoutManager;
10257
10261
  private _syntheticFile;
10258
10262
  initSyntheticEntries(file: idl.IDLFile): void;
10263
+ getSyntheticData(): idl.IDLInterface[];
10259
10264
  readonly files: PeerFile[];
10260
10265
  readonly builderClasses: Map<string, BuilderClass>;
10261
10266
  get buildersToGenerate(): BuilderClass[];
@@ -30,9 +30,33 @@ import { lib, query } from '../library';
30
30
  import { isMaterialized } from './isMaterialized';
31
31
  export const lenses = {
32
32
  globals: lib.lens(lib.select.files())
33
- .pipe(lib.select.nodes({ expandNamespaces: true }))
34
- .pipe(lib.select.interfaces())
35
- .pipe(lib.select.hasExt(idl.IDLExtendedAttributes.GlobalScope))
33
+ .pipe(lib.select.nodes())
34
+ .pipe(lib.req('globals', (nodes) => {
35
+ const result = [];
36
+ const queue = [nodes];
37
+ while (queue.length) {
38
+ const line = {
39
+ constants: [],
40
+ methods: []
41
+ };
42
+ const next = queue.pop();
43
+ next.forEach(node => {
44
+ if (idl.isNamespace(node)) {
45
+ queue.push(node.members);
46
+ }
47
+ if (idl.isConstant(node)) {
48
+ line.constants.push(node);
49
+ }
50
+ if (idl.isMethod(node)) {
51
+ line.methods.push(node);
52
+ }
53
+ });
54
+ if (line.constants.length || line.methods.length) {
55
+ result.push(line);
56
+ }
57
+ }
58
+ return result;
59
+ }))
36
60
  };
37
61
  export class PeerLibrary {
38
62
  asIDLLibrary() {
@@ -44,10 +68,13 @@ export class PeerLibrary {
44
68
  };
45
69
  return this._cachedIdlLibrary;
46
70
  }
47
- get globalScopeInterfaces() { return query(this.asIDLLibrary(), lenses.globals); }
71
+ get globals() { return query(this.asIDLLibrary(), lenses.globals); }
48
72
  initSyntheticEntries(file) {
49
73
  this._syntheticFile = file;
50
74
  }
75
+ getSyntheticData() {
76
+ return this._syntheticFile.entries.filter(it => idl.isInterface(it));
77
+ }
51
78
  get buildersToGenerate() {
52
79
  return Array.from(this.builderClasses.values()).filter(it => it.needBeGenerated);
53
80
  }
@@ -12,6 +12,7 @@
12
12
  * See the License for the specific language governing permissions and
13
13
  * limitations under the License.
14
14
  */
15
+ import { generatorTypePrefix } from "../config";
15
16
  import { mangleMethodName, MethodModifier } from "../LanguageWriters/LanguageWriter";
16
17
  import { capitalize, isDefined } from "../util";
17
18
  import { PrimitiveTypesInstance } from "./PrimitiveType";
@@ -69,13 +70,16 @@ export class PeerMethod {
69
70
  return !((_a = this.method.modifiers) === null || _a === void 0 ? void 0 : _a.includes(MethodModifier.STATIC));
70
71
  }
71
72
  generateAPIParameters(converter) {
73
+ var _a;
72
74
  const args = this.argAndOutConvertors.map(it => {
73
75
  let isPointer = it.isPointerType();
74
76
  return `${isPointer ? "const " : ""}${converter.convert(it.nativeType())}${isPointer ? "*" : ""} ${it.param}`;
75
77
  });
76
78
  const receiver = this.generateReceiver();
77
79
  if (receiver)
78
- return [`${receiver.argType} ${receiver.argName}`, ...args];
80
+ args.unshift(`${receiver.argType} ${receiver.argName}`);
81
+ if ((_a = this.method.modifiers) === null || _a === void 0 ? void 0 : _a.includes(MethodModifier.THROWS))
82
+ args.unshift(`${generatorTypePrefix()}VMContext vmContext`);
79
83
  return args;
80
84
  }
81
85
  generateReceiver() {
@@ -3,6 +3,7 @@ export declare class PrimitiveType {
3
3
  protected isPointer: boolean;
4
4
  constructor(name: string, isPointer?: boolean);
5
5
  getText(): string;
6
+ getInterop(): string;
6
7
  toString(): string;
7
8
  }
8
9
  export declare class PrimitiveTypeList {
@@ -11,6 +12,7 @@ export declare class PrimitiveTypeList {
11
12
  static get ObjectTag(): string;
12
13
  readonly Int32: PrimitiveType;
13
14
  readonly Int64: PrimitiveType;
15
+ readonly Number: PrimitiveType;
14
16
  readonly Boolean: PrimitiveType;
15
17
  readonly Function: PrimitiveType;
16
18
  readonly Undefined: PrimitiveType;