@idlizer/core 2.1.10-arktscgen-4 → 2.1.10-arktscgen-6

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 (122) hide show
  1. package/build/lib/src/Language.d.ts +0 -1
  2. package/build/lib/src/Language.js +1 -3
  3. package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +18 -7
  4. package/build/lib/src/LanguageWriters/ArgConvertors.js +95 -103
  5. package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +13 -7
  6. package/build/lib/src/LanguageWriters/LanguageWriter.js +10 -2
  7. package/build/lib/src/LanguageWriters/common.d.ts +1 -0
  8. package/build/lib/src/LanguageWriters/common.js +2 -1
  9. package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +0 -1
  10. package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +1 -3
  11. package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +14 -8
  12. package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +88 -36
  13. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +1 -0
  14. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +10 -8
  15. package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +1 -1
  16. package/build/lib/src/LanguageWriters/convertors/KotlinConvertors.js +9 -5
  17. package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +4 -4
  18. package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +98 -44
  19. package/build/lib/src/LanguageWriters/index.d.ts +5 -4
  20. package/build/lib/src/LanguageWriters/index.js +8 -15
  21. package/build/lib/src/LanguageWriters/nameConvertor.d.ts +2 -0
  22. package/build/lib/src/LanguageWriters/nameConvertor.js +11 -0
  23. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +2 -0
  24. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +13 -1
  25. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +2 -0
  26. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +8 -2
  27. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +2 -10
  28. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +52 -92
  29. package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.d.ts +8 -0
  30. package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.js +75 -27
  31. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +5 -0
  32. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +58 -18
  33. package/build/lib/src/LibraryInterface.d.ts +0 -1
  34. package/build/lib/src/config.d.ts +2 -1461
  35. package/build/lib/src/config.js +16 -32
  36. package/build/lib/src/configMerge.d.ts +3 -0
  37. package/build/lib/src/configMerge.js +63 -0
  38. package/build/lib/src/diagnostictypes.d.ts +1 -5
  39. package/build/lib/src/diagnostictypes.js +1 -27
  40. package/build/lib/src/from-idl/DtsPrinter.js +13 -6
  41. package/build/lib/src/from-idl/IDLLinter.d.ts +3 -4
  42. package/build/lib/src/from-idl/IDLLinter.js +30 -32
  43. package/build/lib/src/from-idl/deserialize.d.ts +3 -4
  44. package/build/lib/src/from-idl/deserialize.js +30 -642
  45. package/build/lib/src/from-idl/parser.d.ts +20 -2
  46. package/build/lib/src/from-idl/parser.js +97 -29
  47. package/build/lib/src/idl/builders.d.ts +43 -0
  48. package/build/lib/src/idl/builders.js +135 -0
  49. package/build/lib/src/idl/discriminators.d.ts +53 -0
  50. package/build/lib/src/idl/discriminators.js +232 -0
  51. package/build/lib/src/idl/dump.d.ts +48 -0
  52. package/build/lib/src/idl/dump.js +327 -0
  53. package/build/lib/src/idl/index.d.ts +9 -0
  54. package/build/lib/src/idl/index.js +23 -0
  55. package/build/lib/src/idl/keywords.d.ts +2 -0
  56. package/build/lib/src/{options.js → idl/keywords.js} +7 -3
  57. package/build/lib/src/idl/node.d.ts +233 -0
  58. package/build/lib/src/idl/node.js +103 -0
  59. package/build/lib/src/idl/stdlib.d.ts +34 -0
  60. package/build/lib/src/idl/stdlib.js +54 -0
  61. package/build/lib/src/idl/utils.d.ts +44 -0
  62. package/build/lib/src/idl/utils.js +215 -0
  63. package/build/lib/src/idl/visitors.d.ts +15 -0
  64. package/build/lib/src/idl/visitors.js +593 -0
  65. package/build/lib/src/index.d.ts +5 -6
  66. package/build/lib/src/index.js +6 -7
  67. package/build/lib/src/inheritance.d.ts +0 -2
  68. package/build/lib/src/inheritance.js +0 -17
  69. package/build/lib/src/inputPaths.d.ts +11 -0
  70. package/build/lib/src/inputPaths.js +81 -0
  71. package/build/lib/src/languageSpecificKeywords.d.ts +0 -1
  72. package/build/lib/src/languageSpecificKeywords.js +0 -5
  73. package/build/lib/src/peer-generation/ConflictingDeclarations.d.ts +6 -0
  74. package/build/lib/src/peer-generation/ConflictingDeclarations.js +43 -0
  75. package/build/lib/src/peer-generation/LayoutManager.d.ts +3 -1
  76. package/build/lib/src/peer-generation/LayoutManager.js +15 -0
  77. package/build/lib/src/peer-generation/Materialized.d.ts +8 -0
  78. package/build/lib/src/peer-generation/Materialized.js +26 -1
  79. package/build/lib/src/peer-generation/PeerLibrary.d.ts +10 -18
  80. package/build/lib/src/peer-generation/PeerLibrary.js +63 -227
  81. package/build/lib/src/peer-generation/ReferenceResolver.d.ts +6 -1
  82. package/build/lib/src/peer-generation/ReferenceResolver.js +93 -2
  83. package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +6 -0
  84. package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +15 -3
  85. package/build/lib/src/peer-generation/idl/common.d.ts +6 -2
  86. package/build/lib/src/peer-generation/idl/common.js +7 -7
  87. package/build/lib/src/peer-generation/isMaterialized.js +2 -3
  88. package/build/lib/src/peer-generation/modules.js +2 -0
  89. package/build/lib/src/peer-generation/toDeclaration.d.ts +4 -0
  90. package/build/lib/src/peer-generation/toDeclaration.js +53 -0
  91. package/build/lib/src/peer-generation/unions.d.ts +1 -1
  92. package/build/lib/src/peer-generation/unions.js +15 -7
  93. package/build/lib/src/resolveNamedNode.d.ts +1 -0
  94. package/build/lib/src/resolveNamedNode.js +7 -0
  95. package/build/lib/src/transformers/FqnTransformer.d.ts +1 -1
  96. package/build/lib/src/transformers/FqnTransformer.js +20 -12
  97. package/build/lib/src/transformers/GenericTransformer.d.ts +4 -3
  98. package/build/lib/src/transformers/GenericTransformer.js +252 -158
  99. package/build/lib/src/transformers/IdlTransformer.d.ts +6 -0
  100. package/build/lib/src/transformers/IdlTransformer.js +7 -0
  101. package/build/lib/src/transformers/NullTransformer.d.ts +1 -1
  102. package/build/lib/src/transformers/NullTransformer.js +27 -21
  103. package/build/lib/src/transformers/OnSerializeTransformer.d.ts +1 -1
  104. package/build/lib/src/transformers/OnSerializeTransformer.js +28 -13
  105. package/build/lib/src/util.d.ts +9 -39
  106. package/build/lib/src/util.js +65 -369
  107. package/package.json +44 -49
  108. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.d.ts +0 -37
  109. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +0 -210
  110. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +0 -83
  111. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +0 -295
  112. package/build/lib/src/from-idl/webidl2-utils.d.ts +0 -21
  113. package/build/lib/src/from-idl/webidl2-utils.js +0 -87
  114. package/build/lib/src/idl.d.ts +0 -439
  115. package/build/lib/src/idl.js +0 -1367
  116. package/build/lib/src/idlize.d.ts +0 -25
  117. package/build/lib/src/idlize.js +0 -198
  118. package/build/lib/src/options.d.ts +0 -13
  119. package/build/lib/src/peer-generation/BuilderClass.d.ts +0 -20
  120. package/build/lib/src/peer-generation/BuilderClass.js +0 -68
  121. package/webidl2.js/dist/webidl2.js +0 -4622
  122. package/webidl2.js/package.json +0 -55
@@ -1,5 +1,19 @@
1
1
  import * as idl from "../idl";
2
2
  import { DiagnosticMessage, Location } from "../diagnostictypes";
3
+ interface ParseResultOk<T> {
4
+ ok: true;
5
+ result: T;
6
+ }
7
+ interface ParseResultFail {
8
+ ok: false;
9
+ message: DiagnosticMessage;
10
+ }
11
+ type ParseResult<T> = ParseResultOk<T> | ParseResultFail;
12
+ declare const ParseResult: {
13
+ ok: <T>(result: T) => ParseResult<T>;
14
+ fail: <T_1>(message: DiagnosticMessage) => ParseResult<T_1>;
15
+ unwrap: <T_2>(result: ParseResult<T_2>) => T_2;
16
+ };
3
17
  export declare class FatalParserException extends Error {
4
18
  diagnosticMessages?: DiagnosticMessage[];
5
19
  constructor(diagnosticMessages?: DiagnosticMessage[]);
@@ -27,7 +41,10 @@ export declare class Parser {
27
41
  lines: string[];
28
42
  offsets: number[];
29
43
  constructor(fileName: string, content?: string);
30
- parseIDL(): idl.IDLFile;
44
+ parseIDL<T>(parser: () => T): T;
45
+ parseIDLFile(): idl.IDLFile;
46
+ parseIDLType(): idl.IDLType;
47
+ parseIDLTypeList(): idl.IDLType[];
31
48
  _curOffset: number;
32
49
  _curLine: number;
33
50
  _curToken: Token;
@@ -63,9 +80,10 @@ export declare class Parser {
63
80
  currentPackage: string | undefined;
64
81
  parseSingleIdentifier(): Token;
65
82
  parseFullIdentifier(): Token;
83
+ parseIdentifierSafe(single?: boolean): ParseResult<Token>;
66
84
  parseFullIdentifierOrLiteral(): Token;
67
85
  parseLiteral(): Token;
68
- parseAndPushGenerics(ext?: idl.IDLExtendedAttribute[]): string[] | undefined;
86
+ parseAndPushGenerics(ext: idl.IDLExtendedAttribute[] | undefined): string[] | undefined;
69
87
  hasGeneric(name: string): boolean;
70
88
  parseFile(): idl.IDLFile;
71
89
  parseDeclaration(scopeKind: idl.IDLKind): idl.IDLEntry | undefined;
@@ -14,8 +14,11 @@
14
14
  */
15
15
  import * as fs from "fs";
16
16
  import * as idl from "../idl";
17
- import { DiagnosticException } from "../diagnostictypes";
17
+ import { DiagnosticException, MessageSeverityList } from "../diagnostictypes";
18
18
  import { DiagnosticMessageGroup, LoadingFatal, InternalFatal } from "../diagnosticmessages";
19
+ const DeprecatedTypeArguments = new DiagnosticMessageGroup("warning", "DeprecatedTypeArguments", "TypeArguments is deprecated", "TypeArguments extended attribute is deprecated");
20
+ const DeprecatedTypeParameters = new DiagnosticMessageGroup("warning", "DeprecatedTypeParameters", "TypeParameters is deprecated", "TypeParameters extended attribute is deprecated");
21
+ const DeprecatedTypedefSyntax = new DiagnosticMessageGroup("warning", "DeprecatedTypedefSyntax", "C-Style typedef syntax is deprecated", "C-Style typedef syntax is deprecated");
19
22
  const DuplicateModifier = new DiagnosticMessageGroup("error", "DuplicateModifier", "Duplicate modifier", "Duplicate of");
20
23
  const NotApplicableModifier = new DiagnosticMessageGroup("error", "NotApplicableModifier", "Not applicable modifier");
21
24
  const DuplicatePackageDeclaration = new DiagnosticMessageGroup("error", "DuplicatePackageDeclaration", "Duplicate package declaration", "Duplicate of");
@@ -33,6 +36,17 @@ const ExpectedReferenceType = new DiagnosticMessageGroup("error", "ExpectedRefer
33
36
  const ExpectedGenericArguments = new DiagnosticMessageGroup("error", "ExpectedGenericArguments", "Expected generic arguments");
34
37
  const UnexpectedGenericArguments = new DiagnosticMessageGroup("error", "UnexpectedGenericArguments", "Unexpected generic arguments");
35
38
  const InlineParsingDepthExceeded = new DiagnosticMessageGroup("fatal", "InlineParsingDepthExceeded", "Inline parsing depth exceeded");
39
+ const ParseResult = {
40
+ ok: (result) => ({ ok: true, result }),
41
+ fail: (message) => ({ ok: false, message }),
42
+ unwrap: (result) => {
43
+ if (result.ok) {
44
+ return result.result;
45
+ }
46
+ DiagnosticMessageGroup.collectedResults.push(result.message);
47
+ throw new DiagnosticException(result.message);
48
+ }
49
+ };
36
50
  export class FatalParserException extends Error {
37
51
  constructor(diagnosticMessages) {
38
52
  super();
@@ -97,20 +111,20 @@ export class Parser {
97
111
  this.offsets = prepareOffsets(lines);
98
112
  this.lines = lines.map((s) => s.replace(/(\n|\r\n)$/, ""));
99
113
  }
100
- parseIDL() {
114
+ parseIDL(parser) {
101
115
  var _a;
102
- trac("parseIDL");
103
116
  const previousDiagnosticsCount = DiagnosticMessageGroup.allGroupsEntries.length;
104
117
  try {
105
118
  this._lexerNext();
106
119
  this._prevToken = this._curToken;
107
- let file = this.parseFile();
108
- file.text = this.content;
120
+ let result = parser();
109
121
  if (DiagnosticMessageGroup.allGroupsEntries.length != previousDiagnosticsCount) {
110
- // Empty for now, messages will be added in following `catch`.
111
- throw new FatalParserException();
122
+ if (DiagnosticMessageGroup.allGroupsEntries.slice(previousDiagnosticsCount).some(msg => MessageSeverityList.indexOf(msg.severity) <= MessageSeverityList.indexOf('error'))) {
123
+ // Empty for now, messages will be added in following `catch`.
124
+ throw new FatalParserException();
125
+ }
112
126
  }
113
- return file;
127
+ return result;
114
128
  }
115
129
  catch (e) {
116
130
  if (!(e instanceof DiagnosticException) && !(e instanceof FatalParserException)) {
@@ -119,6 +133,22 @@ export class Parser {
119
133
  throw new FatalParserException(DiagnosticMessageGroup.allGroupsEntries.slice(previousDiagnosticsCount));
120
134
  }
121
135
  }
136
+ parseIDLFile() {
137
+ trac("parseIDLFile");
138
+ return this.parseIDL(() => {
139
+ const file = this.parseFile();
140
+ file.text = this.content;
141
+ return file;
142
+ });
143
+ }
144
+ parseIDLType() {
145
+ trac("parseIDLType");
146
+ return this.parseIDL(() => this.parseType());
147
+ }
148
+ parseIDLTypeList() {
149
+ trac("parseIDLTypeList");
150
+ return this.parseIDL(() => this.parseTypeList());
151
+ }
122
152
  _match(re, kind) {
123
153
  re.lastIndex = this._curOffset;
124
154
  const res = re.exec(this.content);
@@ -246,24 +276,27 @@ export class Parser {
246
276
  }
247
277
  parseSingleIdentifier() {
248
278
  trac("parseSingleIdentifier");
249
- const token = this.parseFullIdentifier();
250
- if (token.value.includes(".")) {
251
- IncorrectIdentifier.throwDiagnosticMessage([this.curLocation]);
252
- }
253
- return token;
279
+ return ParseResult.unwrap(this.parseIdentifierSafe(true));
254
280
  }
255
281
  parseFullIdentifier() {
256
282
  trac("parseFullIdentifier");
283
+ return ParseResult.unwrap(this.parseIdentifierSafe(false));
284
+ }
285
+ parseIdentifierSafe(single = false) {
286
+ trac("parseIdentifierSafe");
257
287
  if (this.curKind != TokenKind.Words || literalTypes.has(this.curValue) && this.curValue != "undefined") {
258
- UnexpectedToken.throwDiagnosticMessage([this.curLocation], "Unexpected token, expected identifier");
288
+ return ParseResult.fail(UnexpectedToken.generateDiagnosticMessage([this.curLocation], "Unexpected token, expected identifier"));
289
+ }
290
+ if (single && this.curValue.includes(".")) {
291
+ return ParseResult.fail(IncorrectIdentifier.generateDiagnosticMessage([this.curLocation]));
259
292
  }
260
293
  if (this.curValue.startsWith("-")) {
261
294
  // Valid for identifiers in WebIDL, but not in Idlize
262
- IncorrectIdentifier.throwDiagnosticMessage([this.curLocation]);
295
+ return ParseResult.fail(IncorrectIdentifier.generateDiagnosticMessage([this.curLocation]));
263
296
  }
264
297
  const token = this.curToken;
265
298
  this._lexerNext();
266
- return token;
299
+ return ParseResult.ok(token);
267
300
  }
268
301
  parseFullIdentifierOrLiteral() {
269
302
  trac("parseFullIdentifierOrLiteral");
@@ -286,6 +319,11 @@ export class Parser {
286
319
  parseAndPushGenerics(ext) {
287
320
  var _a;
288
321
  const gen = (_a = extractTypeParameters(ext)) !== null && _a !== void 0 ? _a : [];
322
+ const found = ext === null || ext === void 0 ? void 0 : ext.find(e => e.name === LEGACY_TYPE_PARAMETERS_ATTRIBUTE);
323
+ if (found && found.nameLocation) {
324
+ DeprecatedTypeParameters.reportDiagnosticMessage([found.nameLocation], 'TypeParameters attribute is deprecated, use "<..>" syntax');
325
+ ext === null || ext === void 0 ? void 0 : ext.splice(ext.indexOf(found), 1);
326
+ }
289
327
  if (this.seeAndSkip("<")) {
290
328
  let next = false;
291
329
  while (!this.seeAndSkip(">")) {
@@ -298,7 +336,7 @@ export class Parser {
298
336
  }
299
337
  // To be restored in parseDeclaration
300
338
  this._generics.push(gen);
301
- return gen;
339
+ return gen.length === 0 ? undefined : gen;
302
340
  }
303
341
  hasGeneric(name) {
304
342
  return this._generics.some(x => x.includes(name));
@@ -475,7 +513,7 @@ export class Parser {
475
513
  duplicates.add(name.value);
476
514
  }
477
515
  names.add(name.value);
478
- if (name.value == idl.IDLExtendedAttributes.TypeArguments || name.value == idl.IDLExtendedAttributes.TypeParametersDefaults) {
516
+ if (name.value === LEGACY_TYPE_ARGUMENTS_ATTRIBUTE || name.value === idl.IDLExtendedAttributes.TypeParametersDefaults) {
479
517
  // TypeArguments parsing support
480
518
  try {
481
519
  this._inLiteralParsingLevel += 1;
@@ -553,6 +591,11 @@ export class Parser {
553
591
  }
554
592
  const name = this.parseFullIdentifier();
555
593
  const genArgs = (_a = extractTypeArguments(ext)) !== null && _a !== void 0 ? _a : [];
594
+ const foundArgAttr = ext === null || ext === void 0 ? void 0 : ext.find(it => it.name === LEGACY_TYPE_ARGUMENTS_ATTRIBUTE);
595
+ if (foundArgAttr && foundArgAttr.nameLocation) {
596
+ DeprecatedTypeArguments.reportDiagnosticMessage([foundArgAttr.nameLocation], 'TypeArgument is deprecated extended attribute, use "<..>" syntax');
597
+ ext === null || ext === void 0 ? void 0 : ext.splice(ext.indexOf(foundArgAttr), 1);
598
+ }
556
599
  if (this.seeAndSkip("<")) {
557
600
  let next = false;
558
601
  while (!this.seeAndSkip(">")) {
@@ -680,11 +723,13 @@ export class Parser {
680
723
  this.skip("const");
681
724
  const type = this.parseType();
682
725
  const name = this.parseSingleIdentifier();
683
- this.skip("=");
684
- const value = this.parseLiteral();
726
+ let value;
727
+ if (this.seeAndSkip("=")) {
728
+ value = this.parseLiteral();
729
+ }
685
730
  this.skip(";");
686
731
  // Note that raw value (with quoted strings) is used here, that provides compatibility with older code (while being different from `dictionary` processing)
687
- return idl.createConstant(name.value, type, value.value, { extendedAttributes: ext, nodeLocation: sloc(), nameLocation: name.location, valueLocation: value.location });
732
+ return idl.createConstant(name.value, type, value === null || value === void 0 ? void 0 : value.value, { extendedAttributes: ext, nodeLocation: sloc(), nameLocation: name.location, valueLocation: value === null || value === void 0 ? void 0 : value.location });
688
733
  }
689
734
  parseAttribute() {
690
735
  trac("parseAttribute");
@@ -700,17 +745,38 @@ export class Parser {
700
745
  return idl.createProperty(name.value, type, isReadonly, isStatic, isOptional, { extendedAttributes: ext, documentation: extractDocumentation(ext), nodeLocation: sloc(), nameLocation: name.location });
701
746
  }
702
747
  parseTypedef() {
748
+ var _a;
703
749
  trac("parseTypedef");
704
750
  const sloc = this.trackLocation();
705
751
  const ext = this.consumeCurrentExtended();
706
752
  this.skip("typedef");
707
753
  const typeParameters = this.parseAndPushGenerics(ext);
708
- const type = this.parseType();
709
- const name = this.parseSingleIdentifier();
754
+ const maybeName = this.parseIdentifierSafe(true);
755
+ let name;
756
+ let type;
757
+ let deprecatedSyntax = false;
758
+ if (!maybeName.ok) {
759
+ type = this.parseType();
760
+ name = this.parseSingleIdentifier();
761
+ deprecatedSyntax = true;
762
+ }
763
+ else if (this.seeAndSkip("=")) {
764
+ type = this.parseType();
765
+ name = maybeName.result;
766
+ }
767
+ else {
768
+ type = (_a = builtinTypes.get(maybeName.result.value)) !== null && _a !== void 0 ? _a : idl.createReferenceType(maybeName.result.value, undefined, { extendedAttributes: [], nodeLocation: maybeName.result.location });
769
+ name = this.parseSingleIdentifier();
770
+ deprecatedSyntax = true;
771
+ }
772
+ this.skip(";");
710
773
  if (idl.isUnionType(type)) {
711
774
  type.name = name.value;
775
+ type.extendedAttributes = ext;
776
+ }
777
+ if (deprecatedSyntax) {
778
+ DeprecatedTypedefSyntax.reportDiagnosticMessage([sloc()], "C-Style typedef syntax is deprecated");
712
779
  }
713
- this.skip(";");
714
780
  return idl.createTypedef(name.value, type, typeParameters, { extendedAttributes: ext, documentation: extractDocumentation(ext), nodeLocation: sloc(), nameLocation: name.location });
715
781
  }
716
782
  parseCallback() {
@@ -931,13 +997,15 @@ function sanitizeTypeParameter(param) {
931
997
  }
932
998
  return param;
933
999
  }
934
- function extractTypeParameters(ext) {
935
- var _a, _b, _c;
936
- return (_c = (_b = (_a = ext === null || ext === void 0 ? void 0 : ext.find(x => x.name == idl.IDLExtendedAttributes.TypeParameters)) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.split(",")) === null || _c === void 0 ? void 0 : _c.map(sanitizeTypeParameter);
937
- }
1000
+ const LEGACY_TYPE_PARAMETERS_ATTRIBUTE = "TypeParameters";
1001
+ const LEGACY_TYPE_ARGUMENTS_ATTRIBUTE = "TypeArguments";
938
1002
  function extractTypeArguments(ext) {
939
1003
  var _a;
940
- return (_a = ext === null || ext === void 0 ? void 0 : ext.find(x => x.name == idl.IDLExtendedAttributes.TypeArguments)) === null || _a === void 0 ? void 0 : _a.typesValue;
1004
+ return (_a = ext === null || ext === void 0 ? void 0 : ext.find(x => x.name === LEGACY_TYPE_ARGUMENTS_ATTRIBUTE)) === null || _a === void 0 ? void 0 : _a.typesValue;
1005
+ }
1006
+ function extractTypeParameters(ext) {
1007
+ var _a, _b, _c;
1008
+ return (_c = (_b = (_a = ext === null || ext === void 0 ? void 0 : ext.find(x => x.name === LEGACY_TYPE_PARAMETERS_ATTRIBUTE)) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.split(",")) === null || _c === void 0 ? void 0 : _c.map(sanitizeTypeParameter);
941
1009
  }
942
1010
  const builtinTypesList = [idl.IDLPointerType, idl.IDLVoidType, idl.IDLBooleanType,
943
1011
  idl.IDLObjectType, idl.IDLI8Type, idl.IDLU8Type, idl.IDLI16Type, idl.IDLU16Type,
@@ -0,0 +1,43 @@
1
+ import { Location } from "../diagnostictypes";
2
+ import { IDLCallable, IDLCallback, IDLConstant, IDLConstructor, IDLContainerKind, IDLContainerType, IDLEntry, IDLEnum, IDLEnumMember, IDLExtendedAttribute, IDLFile, IDLImport, IDLInterface, IDLInterfaceSubkind, IDLMethod, IDLNamespace, IDLOptionalType, IDLParameter, IDLPrimitiveType, IDLProperty, IDLReferenceType, IDLType, IDLTypedef, IDLTypeParameterType, IDLUnionType, IDLVersion } from "./node";
3
+ export type IDLNodeInitializer = {
4
+ extendedAttributes?: IDLExtendedAttribute[];
5
+ fileName?: string;
6
+ documentation?: string;
7
+ nodeLocation?: Location;
8
+ nameLocation?: Location;
9
+ valueLocation?: Location;
10
+ };
11
+ export declare function createPrimitiveType(name: string): IDLPrimitiveType;
12
+ export declare function createOptionalType(element: IDLType, nodeInitializer?: IDLNodeInitializer): IDLOptionalType;
13
+ export declare function createNamespace(name: string, members?: IDLEntry[], nodeInitializer?: IDLNodeInitializer): IDLNamespace;
14
+ export declare function createVersion(value: string[], nodeInitializer?: IDLNodeInitializer): IDLVersion;
15
+ export declare function createReferenceType(name: string, typeArguments?: IDLType[], nodeInitializer?: IDLNodeInitializer): IDLReferenceType;
16
+ export declare function createReferenceType(source: IDLEntry, typeArguments?: IDLType[], nodeInitializer?: IDLNodeInitializer): IDLReferenceType;
17
+ export declare function createContainerType(container: IDLContainerKind, element: IDLType[], nodeInitializer?: IDLNodeInitializer): IDLContainerType;
18
+ export declare function createUnionType(types: IDLType[], name?: string, nodeInitializer?: IDLNodeInitializer): IDLUnionType;
19
+ export declare function createFile(entries: IDLEntry[], fileName?: string, packageClause?: string[], nodeInitializer?: IDLNodeInitializer): IDLFile;
20
+ export declare function createImport(clause: string[], name?: string, nodeInitializer?: IDLNodeInitializer): IDLImport;
21
+ export declare function createEnum(name: string, elements: IDLEnumMember[], nodeInitializer: IDLNodeInitializer): IDLEnum;
22
+ export declare function createEnumMember(name: string, parent: IDLEnum, type: IDLPrimitiveType, initializer: number | string | undefined, nodeInitializer?: IDLNodeInitializer): IDLEnumMember;
23
+ export declare function createInterface(name: string, subkind: IDLInterfaceSubkind, inheritance?: IDLReferenceType[], constructors?: IDLConstructor[], constants?: IDLConstant[], properties?: IDLProperty[], methods?: IDLMethod[], callables?: IDLCallable[], typeParameters?: string[], nodeInitializer?: IDLNodeInitializer): IDLInterface;
24
+ export declare function createProperty(name: string, type: IDLType, isReadonly?: boolean, isStatic?: boolean, isOptional?: boolean, nodeInitializer?: IDLNodeInitializer): IDLProperty;
25
+ export declare function createParameter(name: string, type: IDLType, isOptional?: boolean, isVariadic?: boolean, nodeInitializer?: IDLNodeInitializer): IDLParameter;
26
+ export type IDLMethodInitializer = {
27
+ isAsync: boolean;
28
+ isStatic: boolean;
29
+ isOptional: boolean;
30
+ isFree: boolean;
31
+ };
32
+ export declare function createMethod(name: string, parameters: IDLParameter[], returnType: IDLType, methodInitializer?: IDLMethodInitializer, nodeInitializer?: IDLNodeInitializer, typeParameters?: string[]): IDLMethod;
33
+ export type IDLCallableInitializer = {
34
+ isAsync: boolean;
35
+ isStatic: boolean;
36
+ };
37
+ export declare function createCallable(name: string, parameters: IDLParameter[], returnType: IDLType, callableInitializer: IDLCallableInitializer, nodeInitializer?: IDLNodeInitializer, typeParameters?: string[]): IDLCallable;
38
+ export declare function createConstructor(parameters: IDLParameter[], returnType: IDLType | undefined, nodeInitializer?: IDLNodeInitializer): IDLConstructor;
39
+ export declare function createCallback(name: string, parameters: IDLParameter[], returnType: IDLType, nodeInitializer?: IDLNodeInitializer, typeParameters?: string[]): IDLCallback;
40
+ export declare function createTypeParameterReference(name: string, nodeInitializer?: IDLNodeInitializer): IDLTypeParameterType;
41
+ export declare function createTypedef(name: string, type: IDLType, typeParameters?: string[], nodeInitializer?: IDLNodeInitializer): IDLTypedef;
42
+ export declare function createConstant(name: string, type: IDLType, value?: string, nodeInitializer?: IDLNodeInitializer): IDLConstant;
43
+ //# sourceMappingURL=builders.d.ts.map
@@ -0,0 +1,135 @@
1
+ /*
2
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import { generateSyntheticIdlNodeName } from "../peer-generation/idl/common";
16
+ import { isOptionalType, getFQName } from "./discriminators";
17
+ import { IDLKind } from "./node";
18
+ const innerIdlSymbol = Symbol("innerIdlSymbol");
19
+ export function createPrimitiveType(name) {
20
+ return {
21
+ kind: IDLKind.PrimitiveType,
22
+ name: name,
23
+ _idlNodeBrand: innerIdlSymbol,
24
+ _idlTypeBrand: innerIdlSymbol,
25
+ _idlNamedNodeBrand: innerIdlSymbol,
26
+ };
27
+ }
28
+ export function createOptionalType(element, nodeInitializer) {
29
+ if (isOptionalType(element) && !nodeInitializer) {
30
+ return element;
31
+ }
32
+ if (isOptionalType(element)) {
33
+ return Object.assign(Object.assign({ kind: IDLKind.OptionalType, type: element.type }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol });
34
+ }
35
+ return Object.assign(Object.assign({ kind: IDLKind.OptionalType, type: element }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol });
36
+ }
37
+ export function createNamespace(name, members, nodeInitializer) {
38
+ return Object.assign(Object.assign({ kind: IDLKind.Namespace, members: members !== null && members !== void 0 ? members : [], name: name }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
39
+ }
40
+ export function createVersion(value, nodeInitializer) {
41
+ return Object.assign(Object.assign({ kind: IDLKind.Version, value, name: "version" }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
42
+ }
43
+ export function createReferenceType(nameOrSource, typeArguments, nodeInitializer) {
44
+ let name;
45
+ if (typeof nameOrSource === 'string') {
46
+ name = nameOrSource;
47
+ }
48
+ else {
49
+ name = getFQName(nameOrSource);
50
+ }
51
+ return Object.assign(Object.assign({ kind: IDLKind.ReferenceType, name,
52
+ typeArguments }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
53
+ }
54
+ export function createContainerType(container, element, nodeInitializer) {
55
+ return Object.assign(Object.assign({ kind: IDLKind.ContainerType, containerKind: container, elementType: element }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol });
56
+ }
57
+ export function createUnionType(types, name, nodeInitializer) {
58
+ if (types.length < 2)
59
+ throw new Error("IDLUnionType should contain at least 2 types");
60
+ 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 });
61
+ }
62
+ export function createFile(entries, fileName, packageClause = [], nodeInitializer) {
63
+ return Object.assign(Object.assign({ kind: IDLKind.File, packageClause, entries: entries, fileName }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol });
64
+ }
65
+ export function createImport(clause, name, nodeInitializer) {
66
+ return Object.assign(Object.assign({ kind: IDLKind.Import, name: name !== null && name !== void 0 ? name : "", clause }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
67
+ }
68
+ export function createEnum(name, elements, nodeInitializer) {
69
+ const result = Object.assign(Object.assign({ kind: IDLKind.Enum, name: name, elements: elements }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
70
+ elements.forEach(it => it.parent = result);
71
+ return result;
72
+ }
73
+ export function createEnumMember(name, parent, type, initializer, nodeInitializer = {}) {
74
+ return Object.assign(Object.assign({ kind: IDLKind.EnumMember, name: name, parent,
75
+ type,
76
+ initializer }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
77
+ }
78
+ export function createInterface(name, subkind, inheritance = [], constructors = [], constants = [], properties = [], methods = [], callables = [], typeParameters = [], nodeInitializer = {}) {
79
+ return Object.assign(Object.assign({ kind: IDLKind.Interface, name,
80
+ subkind,
81
+ typeParameters,
82
+ inheritance,
83
+ constructors,
84
+ constants,
85
+ properties,
86
+ methods,
87
+ callables }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
88
+ }
89
+ export function createProperty(name, type, isReadonly = false, isStatic = false, isOptional = false, nodeInitializer = {}) {
90
+ return Object.assign(Object.assign({ name, kind: IDLKind.Property, type,
91
+ isReadonly,
92
+ isStatic,
93
+ isOptional }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
94
+ }
95
+ export function createParameter(name, type, isOptional = false, isVariadic = false, nodeInitializer = {}) {
96
+ return Object.assign(Object.assign({ kind: IDLKind.Parameter, name: name, type: type, isOptional,
97
+ isVariadic }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
98
+ }
99
+ export function createMethod(name, parameters, returnType, methodInitializer = {
100
+ isAsync: false,
101
+ isStatic: false,
102
+ isOptional: false,
103
+ isFree: false,
104
+ }, nodeInitializer = {}, typeParameters = []) {
105
+ return Object.assign(Object.assign(Object.assign({ kind: IDLKind.Method, name,
106
+ parameters,
107
+ returnType,
108
+ typeParameters }, methodInitializer), nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
109
+ }
110
+ export function createCallable(
111
+ // TODO name here seems useless
112
+ name, parameters, returnType, callableInitializer, nodeInitializer, typeParameters = []) {
113
+ return Object.assign(Object.assign(Object.assign({ kind: IDLKind.Callable, name,
114
+ parameters,
115
+ returnType }, callableInitializer), nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
116
+ }
117
+ export function createConstructor(parameters, returnType, nodeInitializer = {}) {
118
+ return Object.assign(Object.assign({ kind: IDLKind.Constructor, name: "$CONSTRUCTOR%", parameters,
119
+ returnType }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
120
+ }
121
+ export function createCallback(name, parameters, returnType, nodeInitializer = {}, typeParameters = []) {
122
+ return Object.assign(Object.assign({ kind: IDLKind.Callback, name, parameters, returnType, typeParameters }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
123
+ }
124
+ export function createTypeParameterReference(name, nodeInitializer) {
125
+ return Object.assign(Object.assign({ kind: IDLKind.TypeParameterType, name: name }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
126
+ }
127
+ export function createTypedef(name, type, typeParameters = [], nodeInitializer = {}) {
128
+ return Object.assign(Object.assign({ name, type, typeParameters, kind: IDLKind.Typedef }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
129
+ }
130
+ export function createConstant(name, type, value, nodeInitializer = {}) {
131
+ return Object.assign(Object.assign({ kind: IDLKind.Const, name,
132
+ type,
133
+ value }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
134
+ }
135
+ //# sourceMappingURL=builders.js.map
@@ -0,0 +1,53 @@
1
+ import { stringOrNone } from "../util";
2
+ import { IDLNode, IDLFile, IDLPrimitiveType, IDLContainerType, IDLReferenceType, IDLEnum, IDLEnumMember, IDLUnionType, IDLTypeParameterType, IDLInterface, IDLImport, IDLCallable, IDLMethod, IDLParameter, IDLConstructor, IDLProperty, IDLCallback, IDLConstant, IDLTypedef, IDLType, IDLEntry, IDLNamespace, IDLExtendedAttributes, IDLOptionalType, IDLVersion, IDLNamedNode } from "./node";
3
+ export declare function isFile(node: IDLNode): node is IDLFile;
4
+ export declare function isPrimitiveType(type: IDLNode): type is IDLPrimitiveType;
5
+ export declare function isContainerType(type: IDLNode): type is IDLContainerType;
6
+ export declare function isReferenceType(type: IDLNode): type is IDLReferenceType;
7
+ export declare function isEnum(type: IDLNode): type is IDLEnum;
8
+ export declare function isEnumMember(type: IDLNode): type is IDLEnumMember;
9
+ export declare function isUnionType(type: IDLNode): type is IDLUnionType;
10
+ export declare function isTypeParameterType(type: IDLNode): type is IDLTypeParameterType;
11
+ export declare function isInterface(node: IDLNode): node is IDLInterface;
12
+ export declare function isImport(type: IDLNode): type is IDLImport;
13
+ export declare function isCallable(node: IDLNode): node is IDLCallable;
14
+ export declare function isMethod(node: IDLNode): node is IDLMethod;
15
+ export declare function isParameter(node: IDLNode): node is IDLParameter;
16
+ export declare function isConstructor(node: IDLNode): node is IDLConstructor;
17
+ export declare function isProperty(node: IDLNode): node is IDLProperty;
18
+ export declare function isCallback(node: IDLNode): node is IDLCallback;
19
+ export declare function isInterfaceSubkind(idl: IDLInterface): boolean;
20
+ export declare function isClassSubkind(idl: IDLInterface): boolean;
21
+ export declare function isConstant(node: IDLNode): node is IDLConstant;
22
+ export declare function isTypedef(node: IDLNode): node is IDLTypedef;
23
+ export declare function isType(node: IDLNode): node is IDLType;
24
+ export declare function isEntry(node: IDLNode): node is IDLEntry;
25
+ export declare function isNamespace(node: IDLNode): node is IDLNamespace;
26
+ export declare function isSyntheticEntry(node: IDLNode): boolean;
27
+ export declare function isOptionalType(type: IDLNode): type is IDLOptionalType;
28
+ export declare function isVersion(node: IDLNode): node is IDLVersion;
29
+ export declare function isNamedNode(type: IDLNode): type is IDLNamedNode;
30
+ export declare const IDLContainerUtils: {
31
+ isRecord: (x: IDLNode) => boolean;
32
+ isSequence: (x: IDLNode) => boolean;
33
+ isPromise: (x: IDLNode) => boolean;
34
+ };
35
+ export declare function hasExtAttribute(node: IDLNode, attribute: IDLExtendedAttributes): boolean;
36
+ export declare function getExtAttribute(node: IDLNode, name: IDLExtendedAttributes): stringOrNone;
37
+ export declare function removeExtAttribute(node: IDLNode, name: IDLExtendedAttributes): void;
38
+ export declare function getExtAttributeTypesValue(node: IDLNode, name: IDLExtendedAttributes): IDLType[] | undefined;
39
+ export declare function updateExtAttribute(node: IDLNode, name: IDLExtendedAttributes, value: string | undefined): void;
40
+ export declare function getNamespacesPathFor(node: IDLNode): IDLNamespace[];
41
+ export declare function getFileFor(node: IDLNode): IDLFile | undefined;
42
+ export declare function getPackageClause(node: IDLNode): string[];
43
+ export declare function getPackageName(node: IDLNode): string;
44
+ export declare function getPackageNameSafe(node: IDLNode): string | undefined;
45
+ export declare function isInPackage(entry: IDLEntry | IDLFile, packageName: string, exactMatch?: boolean): boolean;
46
+ export declare function getNamespaceName(a: IDLEntry): string;
47
+ export type QNPattern = "package.namespace.name" | "namespace.name" | "name";
48
+ export declare function deriveQualifiedNameFrom(name: string, from: IDLNode): string;
49
+ export declare function getQualifiedName(a: IDLNode, pattern: QNPattern): string;
50
+ export declare function getFQName(a: IDLNode): string;
51
+ export declare function getFQNameSafe(a: IDLNode): string | undefined;
52
+ export declare function fetchNamespaceFrom(pointOfView?: IDLNode): IDLNamespace | undefined;
53
+ //# sourceMappingURL=discriminators.d.ts.map