@idlizer/core 2.0.15

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 (78) hide show
  1. package/build/lib/src/IndentedPrinter.d.ts +28 -0
  2. package/build/lib/src/IndentedPrinter.js +81 -0
  3. package/build/lib/src/Language.d.ts +15 -0
  4. package/build/lib/src/Language.js +42 -0
  5. package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +318 -0
  6. package/build/lib/src/LanguageWriters/ArgConvertors.js +1015 -0
  7. package/build/lib/src/LanguageWriters/InteropConvertor.d.ts +36 -0
  8. package/build/lib/src/LanguageWriters/InteropConvertor.js +174 -0
  9. package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +386 -0
  10. package/build/lib/src/LanguageWriters/LanguageWriter.js +746 -0
  11. package/build/lib/src/LanguageWriters/common.d.ts +17 -0
  12. package/build/lib/src/LanguageWriters/common.js +33 -0
  13. package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +8 -0
  14. package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +35 -0
  15. package/build/lib/src/LanguageWriters/index.d.ts +3 -0
  16. package/build/lib/src/LanguageWriters/index.js +3 -0
  17. package/build/lib/src/LanguageWriters/nameConvertor.d.ts +28 -0
  18. package/build/lib/src/LanguageWriters/nameConvertor.js +61 -0
  19. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +147 -0
  20. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +578 -0
  21. package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.d.ts +46 -0
  22. package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.js +121 -0
  23. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +116 -0
  24. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +472 -0
  25. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +72 -0
  26. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +329 -0
  27. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +83 -0
  28. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +275 -0
  29. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +93 -0
  30. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +390 -0
  31. package/build/lib/src/LibraryInterface.d.ts +21 -0
  32. package/build/lib/src/LibraryInterface.js +2 -0
  33. package/build/lib/src/config.d.ts +8 -0
  34. package/build/lib/src/config.js +20 -0
  35. package/build/lib/src/from-idl/DtsPrinter.d.ts +35 -0
  36. package/build/lib/src/from-idl/DtsPrinter.js +375 -0
  37. package/build/lib/src/from-idl/common.d.ts +5 -0
  38. package/build/lib/src/from-idl/common.js +83 -0
  39. package/build/lib/src/from-idl/deserialize.d.ts +9 -0
  40. package/build/lib/src/from-idl/deserialize.js +384 -0
  41. package/build/lib/src/from-idl/toString.d.ts +2 -0
  42. package/build/lib/src/from-idl/toString.js +18 -0
  43. package/build/lib/src/from-idl/webidl2-utils.d.ts +20 -0
  44. package/build/lib/src/from-idl/webidl2-utils.js +84 -0
  45. package/build/lib/src/idl.d.ts +404 -0
  46. package/build/lib/src/idl.js +1015 -0
  47. package/build/lib/src/idlize.d.ts +4 -0
  48. package/build/lib/src/idlize.js +52 -0
  49. package/build/lib/src/index.d.ts +34 -0
  50. package/build/lib/src/index.js +48 -0
  51. package/build/lib/src/inheritance.d.ts +16 -0
  52. package/build/lib/src/inheritance.js +76 -0
  53. package/build/lib/src/languageSpecificKeywords.d.ts +5 -0
  54. package/build/lib/src/languageSpecificKeywords.js +51 -0
  55. package/build/lib/src/library.d.ts +67 -0
  56. package/build/lib/src/library.js +190 -0
  57. package/build/lib/src/options.d.ts +11 -0
  58. package/build/lib/src/options.js +16 -0
  59. package/build/lib/src/peer-generation/PrimitiveType.d.ts +24 -0
  60. package/build/lib/src/peer-generation/PrimitiveType.js +52 -0
  61. package/build/lib/src/peer-generation/ReferenceResolver.d.ts +9 -0
  62. package/build/lib/src/peer-generation/ReferenceResolver.js +37 -0
  63. package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +28 -0
  64. package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +82 -0
  65. package/build/lib/src/peer-generation/idl/common.d.ts +9 -0
  66. package/build/lib/src/peer-generation/idl/common.js +70 -0
  67. package/build/lib/src/peer-generation/unions.d.ts +29 -0
  68. package/build/lib/src/peer-generation/unions.js +111 -0
  69. package/build/lib/src/rand_utils.d.ts +6 -0
  70. package/build/lib/src/rand_utils.js +100 -0
  71. package/build/lib/src/util.d.ts +75 -0
  72. package/build/lib/src/util.js +622 -0
  73. package/package.json +49 -0
  74. package/webidl2.js/LICENSE +21 -0
  75. package/webidl2.js/README.md +827 -0
  76. package/webidl2.js/dist/package.json +3 -0
  77. package/webidl2.js/dist/webidl2.js +4547 -0
  78. package/webidl2.js/package.json +55 -0
@@ -0,0 +1,384 @@
1
+ /*
2
+ * Copyright (c) 2024 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 * as webidl2 from "webidl2";
16
+ import * as fs from "fs";
17
+ import { isAttribute, isCallback, isClass, isConstructor, isDictionary, isEnum, isInterface, isOperation, isOptional, isPromiseTypeDescription, isRecordTypeDescription, isSequenceTypeDescription, isSingleTypeDescription, isTypedef, isUnionTypeDescription, isUnspecifiedGenericTypeDescription } from "./webidl2-utils";
18
+ import { toString } from "./toString";
19
+ import * as idl from "../idl";
20
+ import { isDefined, warn } from "../util";
21
+ import { generateSyntheticUnionName } from "../peer-generation/idl/common";
22
+ const syntheticTypes = new Map();
23
+ export function addSyntheticType(name, type) {
24
+ if (syntheticTypes.has(name))
25
+ warn(`duplicate synthetic type name "${name}"`); ///throw?
26
+ syntheticTypes.set(name, type);
27
+ } // check
28
+ export function resolveSyntheticType(type) {
29
+ return syntheticTypes.get(type.name);
30
+ }
31
+ export function toIDLNode(file, node) {
32
+ const result = toIDLNodeForward(file, node);
33
+ idl.linkNamespacesBack(result);
34
+ return result;
35
+ }
36
+ function toIDLNodeForward(file, node) {
37
+ if (isEnum(node)) {
38
+ return toIDLEnum(file, node);
39
+ }
40
+ if (isPackage(node)) {
41
+ return toIDLPackage(node);
42
+ }
43
+ if (isImport(node)) {
44
+ return toIDLImport(node);
45
+ }
46
+ if (isClass(node)) {
47
+ return toIDLInterface(file, node);
48
+ }
49
+ if (isInterface(node)) {
50
+ return toIDLInterface(file, node);
51
+ }
52
+ if (isCallback(node)) {
53
+ return toIDLCallback(file, node);
54
+ }
55
+ if (isTypedef(node)) {
56
+ return toIDLTypedef(file, node);
57
+ }
58
+ if (isDictionary(node)) {
59
+ return toIDLDictionary(file, node);
60
+ }
61
+ if (isNamespace(node)) {
62
+ return toIDLNamespace(file, node);
63
+ }
64
+ if (isVersion(node)) {
65
+ return toIDLVersion(file, node);
66
+ }
67
+ if (isAttribute(node)) {
68
+ return toIDLProperty(file, node);
69
+ }
70
+ if (isOperation(node)) {
71
+ return toIDLMethod(file, node);
72
+ }
73
+ throw new Error(`unexpected node type: ${toString(node)}`);
74
+ }
75
+ function isNamespace(node) {
76
+ return node.type === 'namespace';
77
+ }
78
+ function isVersion(node) {
79
+ return node.type === 'version';
80
+ }
81
+ function isPackage(node) {
82
+ return node.type === 'package';
83
+ }
84
+ function isImport(node) {
85
+ return node.type === 'import';
86
+ }
87
+ function isCallable(node) {
88
+ return node.extAttrs.some(it => it.name == "Invoke");
89
+ }
90
+ function toIDLPackage(node) {
91
+ return idl.createPackage(node.nameValue);
92
+ }
93
+ function toIDLImport(node) {
94
+ // console.log(node)
95
+ return idl.createImport(node.nameValue);
96
+ }
97
+ function toIDLInterface(file, node) {
98
+ var _a;
99
+ const result = idl.createInterface(node.name, isClass(node) ? idl.IDLInterfaceSubkind.Class : idl.IDLInterfaceSubkind.Interface, (() => {
100
+ var _a, _b;
101
+ if (!node.inheritance)
102
+ return [];
103
+ const parentTypeArgs = extractTypeArguments(file, (_a = node.inheritanceExtAttrs) !== null && _a !== void 0 ? _a : [], idl.IDLExtendedAttributes.TypeArguments);
104
+ const parentType = idl.createReferenceType(node.inheritance, parentTypeArgs);
105
+ parentType.fileName = file;
106
+ if (node.inheritanceExtAttrs)
107
+ parentType.extendedAttributes = (_b = toExtendedAttributes(node.inheritanceExtAttrs)) === null || _b === void 0 ? void 0 : _b.filter(it => it.name !== idl.IDLExtendedAttributes.TypeArguments);
108
+ return [parentType];
109
+ })(), node.members
110
+ .filter(isConstructor)
111
+ .map(it => toIDLConstructor(file, it)), [], node.members
112
+ .filter(isAttribute)
113
+ .map(it => toIDLProperty(file, it)), node.members
114
+ .filter(isOperation)
115
+ .filter(it => !isCallable(it))
116
+ .map(it => toIDLMethod(file, it)), node.members
117
+ .filter(isOperation)
118
+ .filter(it => isCallable(it))
119
+ .map(it => toIDLCallable(file, it)), (_a = findExtendedAttribute(node.extAttrs, idl.IDLExtendedAttributes.TypeParameters)) === null || _a === void 0 ? void 0 : _a.split(","), {
120
+ fileName: file,
121
+ documentation: makeDocs(node),
122
+ extendedAttributes: toExtendedAttributes(node.extAttrs),
123
+ });
124
+ if (result.inheritance.length && idl.isReferenceType(result.inheritance[0]))
125
+ result.inheritance[0].typeArguments = extractTypeArguments(file, node.extAttrs, idl.IDLExtendedAttributes.TypeArguments);
126
+ if (node.extAttrs.find(it => it.name === "Synthetic"))
127
+ addSyntheticType(node.name, result);
128
+ return result;
129
+ }
130
+ function extractTypeArguments(file, extAttrs, attribute) {
131
+ var _a;
132
+ const attr = extAttrs === null || extAttrs === void 0 ? void 0 : extAttrs.find(it => it.name === attribute);
133
+ if (!attr)
134
+ return undefined;
135
+ let value = toExtendedAttributeValue(attr);
136
+ return (_a = value === null || value === void 0 ? void 0 : value.split(",") // TODO need real parsing here. What about "<T, Map<K, Callback<K,R>>, U>"
137
+ ) === null || _a === void 0 ? void 0 : _a.map(it => toIDLType(file, it));
138
+ }
139
+ function toIDLType(file, type, extAttrs) {
140
+ var _a;
141
+ if (typeof type === "string") {
142
+ // is it IDLStringType?
143
+ const refType = idl.createReferenceType(type);
144
+ refType.fileName = file;
145
+ refType.typeArguments = extractTypeArguments(file, extAttrs, idl.IDLExtendedAttributes.TypeArguments);
146
+ return refType;
147
+ }
148
+ if (type.nullable) {
149
+ return idl.createOptionalType(toIDLType(file, Object.assign(Object.assign({}, type), { nullable: false }), extAttrs));
150
+ }
151
+ if (isUnionTypeDescription(type)) {
152
+ const types = type.idlType
153
+ .map(it => toIDLType(file, it))
154
+ .filter(isDefined);
155
+ const name = generateSyntheticUnionName(types);
156
+ return idl.createUnionType(types, name);
157
+ }
158
+ if (isSingleTypeDescription(type)) {
159
+ switch (type.idlType) {
160
+ case idl.IDLUnknownType.name: return idl.IDLUnknownType;
161
+ case idl.IDLObjectType.name: return idl.IDLObjectType;
162
+ case idl.IDLAnyType.name: return idl.IDLAnyType;
163
+ case idl.IDLBooleanType.name: return idl.IDLBooleanType;
164
+ case idl.IDLNumberType.name: return idl.IDLNumberType;
165
+ case idl.IDLStringType.name: return idl.IDLStringType;
166
+ case idl.IDLUndefinedType.name: return idl.IDLUndefinedType;
167
+ case idl.IDLVoidType.name: return idl.IDLVoidType;
168
+ case idl.IDLI8Type.name: return idl.IDLI8Type;
169
+ case idl.IDLU8Type.name: return idl.IDLU8Type;
170
+ case idl.IDLI16Type.name: return idl.IDLI16Type;
171
+ case idl.IDLU16Type.name: return idl.IDLU16Type;
172
+ case idl.IDLI32Type.name: return idl.IDLI32Type;
173
+ case idl.IDLU32Type.name: return idl.IDLU32Type;
174
+ case idl.IDLI64Type.name: return idl.IDLI64Type;
175
+ case idl.IDLU64Type.name: return idl.IDLU64Type;
176
+ case idl.IDLF32Type.name: return idl.IDLF32Type;
177
+ case idl.IDLF64Type.name: return idl.IDLF64Type;
178
+ case idl.IDLPointerType.name: return idl.IDLPointerType;
179
+ case idl.IDLBufferType.name: return idl.IDLBufferType;
180
+ }
181
+ const combinedExtAttrs = ((_a = type.extAttrs) !== null && _a !== void 0 ? _a : []).concat(extAttrs !== null && extAttrs !== void 0 ? extAttrs : []);
182
+ const idlRefType = idl.createReferenceType(type.idlType);
183
+ idlRefType.fileName = file;
184
+ idlRefType.typeArguments = extractTypeArguments(file, combinedExtAttrs, idl.IDLExtendedAttributes.TypeArguments);
185
+ idlRefType.extendedAttributes = toExtendedAttributes(combinedExtAttrs);
186
+ return idlRefType;
187
+ }
188
+ if (isSequenceTypeDescription(type) || isPromiseTypeDescription(type) || isRecordTypeDescription(type)) {
189
+ return idl.createContainerType(type.generic, type.idlType.map(it => toIDLType(file, it)));
190
+ }
191
+ if (isUnspecifiedGenericTypeDescription(type)) {
192
+ return idl.createUnspecifiedGenericType(type.generic, type.idlType.map(it => toIDLType(file, it)));
193
+ }
194
+ throw new Error(`unexpected type: ${toString(type)}`);
195
+ }
196
+ function toIDLCallable(file, node) {
197
+ var _a, _b;
198
+ if (!node.idlType) {
199
+ throw new Error(`method with no type ${toString(node)}`);
200
+ }
201
+ const returnType = toIDLType(file, node.idlType, node.extAttrs);
202
+ if (idl.isReferenceType(returnType)) {
203
+ const returnTypeArgs = extractTypeArguments(file, node.extAttrs, idl.IDLExtendedAttributes.TypeArguments);
204
+ returnType.typeArguments = returnTypeArgs;
205
+ }
206
+ return idl.createCallable((_a = node.name) !== null && _a !== void 0 ? _a : "", node.arguments.map(it => toIDLParameter(file, it)), returnType, {
207
+ isStatic: node.special === "static",
208
+ isAsync: node.async,
209
+ }, {
210
+ documentation: makeDocs(node),
211
+ extendedAttributes: toExtendedAttributes(node.extAttrs),
212
+ }, (_b = findExtendedAttribute(node.extAttrs, idl.IDLExtendedAttributes.TypeParameters)) === null || _b === void 0 ? void 0 : _b.split(","));
213
+ }
214
+ function toIDLMethod(file, node) {
215
+ var _a, _b;
216
+ if (!node.idlType) {
217
+ throw new Error(`method with no type ${toString(node)}`);
218
+ }
219
+ const returnType = toIDLType(file, node.idlType, node.extAttrs);
220
+ if (idl.isReferenceType(returnType))
221
+ returnType.typeArguments = extractTypeArguments(file, node.extAttrs, idl.IDLExtendedAttributes.TypeArguments);
222
+ return idl.createMethod((_a = node.name) !== null && _a !== void 0 ? _a : "", node.arguments.map(it => toIDLParameter(file, it)), returnType, {
223
+ isStatic: node.special === "static",
224
+ isAsync: node.async,
225
+ isOptional: isOptional(node),
226
+ isFree: false, // TODO: namespace-related-to-rework
227
+ }, {
228
+ documentation: makeDocs(node),
229
+ extendedAttributes: toExtendedAttributes(node.extAttrs),
230
+ }, (_b = findExtendedAttribute(node.extAttrs, idl.IDLExtendedAttributes.TypeParameters)) === null || _b === void 0 ? void 0 : _b.split(","));
231
+ }
232
+ function toIDLConstructor(file, node) {
233
+ return idl.createConstructor(node.arguments.map(it => toIDLParameter(file, it)), undefined, {
234
+ documentation: makeDocs(node),
235
+ });
236
+ }
237
+ function toIDLParameter(file, node) {
238
+ return idl.createParameter(node.name, toIDLType(file, node.idlType, node.extAttrs), node.optional, node.variadic, {
239
+ fileName: file,
240
+ });
241
+ }
242
+ function toIDLCallback(file, node) {
243
+ const result = idl.createCallback(node.name, node.arguments.map(it => toIDLParameter(file, it)), toIDLType(file, node.idlType), {
244
+ fileName: file,
245
+ extendedAttributes: toExtendedAttributes(node.extAttrs),
246
+ documentation: makeDocs(node),
247
+ });
248
+ if (node.extAttrs.find(it => it.name === "Synthetic"))
249
+ addSyntheticType(node.name, result);
250
+ return result;
251
+ }
252
+ function toIDLTypedef(file, node) {
253
+ var _a;
254
+ return idl.createTypedef(node.name, toIDLType(file, node.idlType), (_a = findExtendedAttribute(node.extAttrs, idl.IDLExtendedAttributes.TypeParameters)) === null || _a === void 0 ? void 0 : _a.split(","), {
255
+ extendedAttributes: toExtendedAttributes(node.extAttrs),
256
+ documentation: makeDocs(node),
257
+ fileName: file,
258
+ });
259
+ }
260
+ function toIDLDictionary(file, node) {
261
+ const result = idl.createEnum(node.name, [], {
262
+ documentation: makeDocs(node),
263
+ extendedAttributes: toExtendedAttributes(node.extAttrs),
264
+ fileName: file,
265
+ });
266
+ result.elements = node.members.map(it => toIDLEnumMember(file, it, result));
267
+ return result;
268
+ }
269
+ function toIDLNamespace(file, node) {
270
+ const namespace = idl.createNamespace(node.name, toExtendedAttributes(node.extAttrs), file);
271
+ namespace.members = node.members.map(it => toIDLNodeForward(file, it));
272
+ return namespace;
273
+ }
274
+ function toIDLVersion(file, node) {
275
+ return idl.createVersion(node.value, toExtendedAttributes(node.extAttrs), file);
276
+ }
277
+ function toIDLProperty(file, node) {
278
+ return idl.createProperty(node.name, toIDLType(file, node.idlType), node.readonly, node.special === "static", isOptional(node), {
279
+ documentation: makeDocs(node),
280
+ fileName: file,
281
+ extendedAttributes: toExtendedAttributes(node.extAttrs)
282
+ });
283
+ }
284
+ function unescapeString(value) {
285
+ if (!value.length || value[0] !== '"')
286
+ return value;
287
+ value = value.slice(1, -1);
288
+ value = value.replace(/\\((['"\\bfnrtv])|([0-7]{1-3})|x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/g, (_, all, c, oct, h2, u4) => {
289
+ if (c !== undefined) {
290
+ switch (c) {
291
+ case "'": return "'";
292
+ case '"': return '"';
293
+ case "\\": return "\\";
294
+ case "b": return "\b";
295
+ case "f": return "\f";
296
+ case "n": return "\n";
297
+ case "r": return "\r";
298
+ case "t": return "\t";
299
+ case "v": return "\v";
300
+ }
301
+ }
302
+ else if (oct !== undefined) {
303
+ return String.fromCharCode(parseInt(oct, 8));
304
+ }
305
+ else if (h2 !== undefined) {
306
+ return String.fromCharCode(parseInt(h2, 16));
307
+ }
308
+ else if (u4 !== undefined) {
309
+ return String.fromCharCode(parseInt(u4, 16));
310
+ }
311
+ throw new Error(`unknown escape sequence: ${_}`);
312
+ });
313
+ return value;
314
+ }
315
+ function toIDLEnumMember(file, node, parent) {
316
+ var _a, _b, _c;
317
+ let initializer = undefined;
318
+ if (((_a = node.default) === null || _a === void 0 ? void 0 : _a.type) == "string") {
319
+ initializer = unescapeString(node.default.value);
320
+ }
321
+ else if (((_b = node.default) === null || _b === void 0 ? void 0 : _b.type) == "number") {
322
+ initializer = +((_c = node.default) === null || _c === void 0 ? void 0 : _c.value);
323
+ }
324
+ else if (node.default == null) {
325
+ initializer = undefined;
326
+ }
327
+ else {
328
+ throw new Error(`Not representable enum initializer: ${node.default}`);
329
+ }
330
+ return idl.createEnumMember(node.name, parent, toIDLType(file, node.idlType), initializer, {
331
+ extendedAttributes: toExtendedAttributes(node.extAttrs),
332
+ });
333
+ }
334
+ function toExtendedAttributes(extAttrs) {
335
+ return extAttrs.map(it => {
336
+ return { name: it.name, value: toExtendedAttributeValue(it) };
337
+ });
338
+ }
339
+ function toExtendedAttributeValue(attr) {
340
+ var _a, _b;
341
+ // TODO: be smarter about RHS.
342
+ if (((_a = attr.rhs) === null || _a === void 0 ? void 0 : _a.value) instanceof Array)
343
+ return attr.rhs.value.map(v => v.value).join(",");
344
+ if (typeof ((_b = attr.rhs) === null || _b === void 0 ? void 0 : _b.value) === 'string')
345
+ return unescapeString(attr.rhs.value);
346
+ return;
347
+ }
348
+ function makeDocs(node) {
349
+ let docs = undefined;
350
+ node.extAttrs.forEach(it => {
351
+ var _a;
352
+ if (it.name == "Documentation")
353
+ docs = (_a = it.rhs) === null || _a === void 0 ? void 0 : _a.value;
354
+ });
355
+ return docs;
356
+ }
357
+ function toIDLEnum(file, node) {
358
+ const result = idl.createEnum(node.name, [], {
359
+ fileName: file,
360
+ documentation: makeDocs(node),
361
+ extendedAttributes: toExtendedAttributes(node.extAttrs),
362
+ });
363
+ result.elements = node.values.map((it) => idl.createEnumMember(it.value, result, idl.IDLNumberType, undefined));
364
+ return result;
365
+ }
366
+ function findExtendedAttribute(extAttrs, name) {
367
+ const attr = extAttrs.find(it => it.name === name);
368
+ return attr ? toExtendedAttributeValue(attr) : undefined;
369
+ }
370
+ export function toIDL(file) {
371
+ const content = fs.readFileSync(file).toString();
372
+ return webidl2.parse(content).map(it => toIDLNode(file, it));
373
+ }
374
+ export function toIDLFile(fileName) {
375
+ const content = fs.readFileSync(fileName).toString();
376
+ const entities = webidl2.parse(content).map(it => toIDLNode(fileName, it));
377
+ const pack = entities.find(idl.isPackage);
378
+ return {
379
+ fileName,
380
+ entities,
381
+ package: pack,
382
+ };
383
+ }
384
+ //# sourceMappingURL=deserialize.js.map
@@ -0,0 +1,2 @@
1
+ export declare function toString(node: Object): string;
2
+ //# sourceMappingURL=toString.d.ts.map
@@ -0,0 +1,18 @@
1
+ /*
2
+ * Copyright (c) 2024 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
+ export function toString(node) {
16
+ return JSON.stringify(node, undefined, 4);
17
+ }
18
+ //# sourceMappingURL=toString.js.map
@@ -0,0 +1,20 @@
1
+ import * as webidl2 from "webidl2";
2
+ export declare function isEnum(node: webidl2.IDLRootType): node is webidl2.EnumType;
3
+ export declare function isInterface(node: webidl2.IDLRootType): node is webidl2.InterfaceType;
4
+ export declare function isImport(node: webidl2.IDLRootType): node is webidl2.ImportType;
5
+ export declare function isPackage(node: webidl2.IDLRootType): node is webidl2.PackageType;
6
+ export declare function isClass(node: webidl2.IDLRootType): node is webidl2.InterfaceType;
7
+ export declare function isCallback(node: webidl2.IDLRootType): node is webidl2.CallbackType;
8
+ export declare function isTypedef(node: webidl2.IDLRootType): node is webidl2.TypedefType;
9
+ export declare function isDictionary(node: webidl2.IDLRootType): node is webidl2.DictionaryType;
10
+ export declare function isAttribute(node: webidl2.IDLInterfaceMemberType | webidl2.IDLNamespaceMemberType): node is webidl2.AttributeMemberType;
11
+ export declare function isOperation(node: webidl2.IDLInterfaceMemberType | webidl2.IDLNamespaceMemberType): node is webidl2.OperationMemberType;
12
+ export declare function isConstructor(node: webidl2.IDLInterfaceMemberType): node is webidl2.ConstructorMemberType;
13
+ export declare function isUnionTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.UnionTypeDescription;
14
+ export declare function isSingleTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.SingleTypeDescription;
15
+ export declare function isSequenceTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.SequenceTypeDescription;
16
+ export declare function isPromiseTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.PromiseTypeDescription;
17
+ export declare function isRecordTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.RecordTypeDescription;
18
+ export declare function isUnspecifiedGenericTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.UnspecifiedGenericTypeDescription;
19
+ export declare function isOptional(node: webidl2.AttributeMemberType | webidl2.OperationMemberType): boolean;
20
+ //# sourceMappingURL=webidl2-utils.d.ts.map
@@ -0,0 +1,84 @@
1
+ /*
2
+ * Copyright (c) 2024 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 { IDLEntity } from "../idl";
16
+ export function isEnum(node) {
17
+ return node.type === "enum";
18
+ }
19
+ export function isInterface(node) {
20
+ return node.type === "interface";
21
+ }
22
+ export function isImport(node) {
23
+ return node.type === "import";
24
+ }
25
+ export function isPackage(node) {
26
+ return node.type === "package";
27
+ }
28
+ export function isClass(node) {
29
+ var _a, _b;
30
+ return isInterface(node)
31
+ && ((_b = (_a = node.extAttrs.find(it => it.name === "Entity")) === null || _a === void 0 ? void 0 : _a.rhs) === null || _b === void 0 ? void 0 : _b.value) === IDLEntity.Class;
32
+ }
33
+ export function isCallback(node) {
34
+ return node.type === "callback";
35
+ }
36
+ export function isTypedef(node) {
37
+ return node.type === "typedef";
38
+ }
39
+ export function isDictionary(node) {
40
+ return node.type === "dictionary";
41
+ }
42
+ export function isAttribute(node) {
43
+ return node.type === "attribute";
44
+ }
45
+ export function isOperation(node) {
46
+ return node.type === "operation";
47
+ }
48
+ export function isConstructor(node) {
49
+ return node.type === "constructor";
50
+ }
51
+ export function isUnionTypeDescription(node) {
52
+ return node.union;
53
+ }
54
+ export function isSingleTypeDescription(node) {
55
+ return (typeof node.idlType === "string");
56
+ }
57
+ export function isSequenceTypeDescription(node) {
58
+ return node.generic === "sequence";
59
+ }
60
+ export function isPromiseTypeDescription(node) {
61
+ return node.generic === "Promise";
62
+ }
63
+ export function isRecordTypeDescription(node) {
64
+ return node.generic === "record";
65
+ }
66
+ export function isUnspecifiedGenericTypeDescription(node) {
67
+ switch (node.generic) {
68
+ case "FrozenArray":
69
+ case "ObservableArray":
70
+ case "Promise":
71
+ case "record":
72
+ case "sequence":
73
+ case "":
74
+ return false;
75
+ }
76
+ return true;
77
+ }
78
+ export function isOptional(node) {
79
+ return node.extAttrs
80
+ .map((it) => it.name)
81
+ .map((it) => it.toLowerCase())
82
+ .includes("optional");
83
+ }
84
+ //# sourceMappingURL=webidl2-utils.js.map