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