@idlizer/core 2.0.31 → 2.0.33
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 -2
- package/build/lib/src/LanguageWriters/ArgConvertors.js +19 -19
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +9 -7
- package/build/lib/src/LanguageWriters/LanguageWriter.js +10 -7
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +3 -5
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +0 -1
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +1 -8
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +2 -2
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +1 -1
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +1 -1
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +7 -3
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +14 -3
- package/build/lib/src/from-idl/DtsPrinter.d.ts +1 -1
- package/build/lib/src/from-idl/DtsPrinter.js +28 -22
- package/build/lib/src/from-idl/deserialize.d.ts +1 -2
- package/build/lib/src/from-idl/deserialize.js +10 -12
- package/build/lib/src/idl.d.ts +19 -8
- package/build/lib/src/idl.js +82 -39
- package/build/lib/src/idlize.d.ts +12 -2
- package/build/lib/src/idlize.js +24 -9
- package/build/lib/src/library.d.ts +5 -10
- package/build/lib/src/library.js +2 -2
- package/build/lib/src/peer-generation/PeerFile.d.ts +4 -3
- package/build/lib/src/peer-generation/PeerFile.js +10 -3
- package/build/lib/src/peer-generation/PeerLibrary.d.ts +4 -6
- package/build/lib/src/peer-generation/PeerLibrary.js +18 -36
- package/build/lib/src/peer-generation/PeerMethod.js +5 -1
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +5 -4
- package/build/lib/src/peer-generation/idl/common.js +3 -3
- package/build/lib/src/util.d.ts +2 -0
- package/build/lib/src/util.js +4 -0
- package/build/lib/src/visitor.js +1 -1
- package/package.json +1 -1
- package/webidl2.js/dist/webidl2.js +20 -19
package/build/lib/src/idl.d.ts
CHANGED
|
@@ -21,7 +21,8 @@ export declare enum IDLKind {
|
|
|
21
21
|
TypeParameterType = 18,
|
|
22
22
|
OptionalType = 19,
|
|
23
23
|
Version = 20,
|
|
24
|
-
Namespace = 21
|
|
24
|
+
Namespace = 21,
|
|
25
|
+
File = 22
|
|
25
26
|
}
|
|
26
27
|
export declare enum IDLEntity {
|
|
27
28
|
Class = "Class",
|
|
@@ -58,6 +59,7 @@ export declare enum IDLExtendedAttributes {
|
|
|
58
59
|
Predefined = "Predefined",
|
|
59
60
|
Protected = "Protected",
|
|
60
61
|
Synthetic = "Synthetic",
|
|
62
|
+
Throws = "Throws",
|
|
61
63
|
TSType = "TSType",
|
|
62
64
|
TypeArguments = "TypeArguments",
|
|
63
65
|
TypeParameters = "TypeParameters",
|
|
@@ -75,10 +77,15 @@ export interface IDLExtendedAttribute {
|
|
|
75
77
|
export interface IDLNode {
|
|
76
78
|
_idlNodeBrand: any;
|
|
77
79
|
kind: IDLKind;
|
|
80
|
+
parent?: IDLNode;
|
|
78
81
|
fileName?: string;
|
|
79
82
|
extendedAttributes?: IDLExtendedAttribute[];
|
|
80
83
|
documentation?: string;
|
|
81
84
|
}
|
|
85
|
+
export interface IDLFile extends IDLNode {
|
|
86
|
+
entries: IDLEntry[];
|
|
87
|
+
fileName?: string;
|
|
88
|
+
}
|
|
82
89
|
export interface IDLNamedNode extends IDLNode {
|
|
83
90
|
_idlNamedNodeBrand: any;
|
|
84
91
|
name: string;
|
|
@@ -86,7 +93,6 @@ export interface IDLNamedNode extends IDLNode {
|
|
|
86
93
|
export interface IDLEntry extends IDLNode, IDLNamedNode {
|
|
87
94
|
_idlEntryBrand: any;
|
|
88
95
|
comment?: string;
|
|
89
|
-
namespace?: IDLNamespace;
|
|
90
96
|
}
|
|
91
97
|
export interface IDLType extends IDLNode {
|
|
92
98
|
_idlTypeBrand: any;
|
|
@@ -112,7 +118,6 @@ export interface IDLContainerType extends IDLType {
|
|
|
112
118
|
export interface IDLReferenceType extends IDLType, IDLNamedNode {
|
|
113
119
|
kind: IDLKind.ReferenceType;
|
|
114
120
|
typeArguments?: IDLType[];
|
|
115
|
-
namespace?: IDLNamespace;
|
|
116
121
|
}
|
|
117
122
|
export interface IDLUnspecifiedGenericType extends IDLType, IDLNamedNode {
|
|
118
123
|
kind: IDLKind.UnspecifiedGenericType;
|
|
@@ -204,10 +209,11 @@ export interface IDLInterface extends IDLEntry {
|
|
|
204
209
|
}
|
|
205
210
|
export interface IDLPackage extends IDLEntry {
|
|
206
211
|
kind: IDLKind.Package;
|
|
212
|
+
clause: string[];
|
|
207
213
|
}
|
|
208
214
|
export interface IDLImport extends IDLEntry {
|
|
209
215
|
kind: IDLKind.Import;
|
|
210
|
-
|
|
216
|
+
clause: string[];
|
|
211
217
|
}
|
|
212
218
|
export interface IDLNamespace extends IDLEntry {
|
|
213
219
|
kind: IDLKind.Namespace;
|
|
@@ -220,6 +226,7 @@ export interface IDLCallback extends IDLEntry, IDLSignature {
|
|
|
220
226
|
export declare function forEachChild(node: IDLNode, cbEnter: (entry: IDLNode) => void, cbLeave?: (entry: IDLNode) => void): void;
|
|
221
227
|
export declare function isNamedNode(type: IDLNode): type is IDLNamedNode;
|
|
222
228
|
export declare function forceAsNamedNode(type: IDLNode): IDLNamedNode;
|
|
229
|
+
export declare function isFile(node: IDLNode): node is IDLFile;
|
|
223
230
|
export declare function isUndefinedType(type: IDLNode): type is IDLPrimitiveType;
|
|
224
231
|
export declare function isVoidType(type: IDLNode): type is IDLPrimitiveType;
|
|
225
232
|
export declare function isPrimitiveType(type: IDLNode): type is IDLPrimitiveType;
|
|
@@ -294,21 +301,25 @@ export type IDLNodeInitializer = {
|
|
|
294
301
|
documentation?: string;
|
|
295
302
|
};
|
|
296
303
|
export declare function createNamespace(name: string, extendedAttributes?: IDLExtendedAttribute[], fileName?: string): IDLNamespace;
|
|
297
|
-
export declare function
|
|
304
|
+
export declare function linkParentBack<T extends IDLNode>(node: T): T;
|
|
298
305
|
export declare function getNamespacesPathFor(entry: IDLEntry): IDLNamespace[];
|
|
306
|
+
export declare function getFileFor(entry: IDLNode): IDLFile | undefined;
|
|
299
307
|
export declare function isEqualByQualifedName(a?: IDLEntry, b?: IDLEntry): boolean;
|
|
308
|
+
export declare function getPackageClause(entry: IDLFile | IDLEntry): string[];
|
|
309
|
+
export declare function getPackageName(entry: IDLFile | IDLEntry): string;
|
|
300
310
|
export declare function getNamespaceName(a: IDLEntry): string;
|
|
301
311
|
export declare function getFQName(a: IDLEntry): string;
|
|
302
312
|
export declare function createVersion(value: string[], extendedAttributes?: IDLExtendedAttribute[], fileName?: string): IDLVersion;
|
|
303
313
|
export declare function fetchNamespaceFrom(pointOfView?: IDLNode): IDLNamespace | undefined;
|
|
304
|
-
export declare function createReferenceType(name: string, typeArguments?: IDLType[]
|
|
314
|
+
export declare function createReferenceType(name: string, typeArguments?: IDLType[]): IDLReferenceType;
|
|
305
315
|
export declare function createReferenceType(source: IDLEntry, typeArguments?: IDLType[]): IDLReferenceType;
|
|
306
316
|
export declare function createUnspecifiedGenericType(name: string, typeArguments: IDLType[]): IDLUnspecifiedGenericType;
|
|
307
317
|
export declare function entityToType(entity: IDLNode): IDLType;
|
|
308
318
|
export declare function createContainerType(container: IDLContainerKind, element: IDLType[]): IDLContainerType;
|
|
309
319
|
export declare function createUnionType(types: IDLType[], name?: string): IDLUnionType;
|
|
310
|
-
export declare function
|
|
311
|
-
export declare function
|
|
320
|
+
export declare function createFile(entries: IDLEntry[], fileName?: string): IDLFile;
|
|
321
|
+
export declare function createPackage(clause: string[]): IDLPackage;
|
|
322
|
+
export declare function createImport(clause: string[], name?: string, nodeInitializer?: IDLNodeInitializer): IDLImport;
|
|
312
323
|
export declare function createEnum(name: string, elements: IDLEnumMember[], nodeInitializer: IDLNodeInitializer): IDLEnum;
|
|
313
324
|
export declare function createEnumMember(name: string, parent: IDLEnum, type: IDLPrimitiveType, initializer: number | string | undefined, nodeInitializer?: IDLNodeInitializer): IDLEnumMember;
|
|
314
325
|
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;
|
package/build/lib/src/idl.js
CHANGED
|
@@ -40,6 +40,7 @@ export var IDLKind;
|
|
|
40
40
|
IDLKind[IDLKind["OptionalType"] = 19] = "OptionalType";
|
|
41
41
|
IDLKind[IDLKind["Version"] = 20] = "Version";
|
|
42
42
|
IDLKind[IDLKind["Namespace"] = 21] = "Namespace";
|
|
43
|
+
IDLKind[IDLKind["File"] = 22] = "File";
|
|
43
44
|
})(IDLKind || (IDLKind = {}));
|
|
44
45
|
export var IDLEntity;
|
|
45
46
|
(function (IDLEntity) {
|
|
@@ -78,6 +79,7 @@ export var IDLExtendedAttributes;
|
|
|
78
79
|
IDLExtendedAttributes["Predefined"] = "Predefined";
|
|
79
80
|
IDLExtendedAttributes["Protected"] = "Protected";
|
|
80
81
|
IDLExtendedAttributes["Synthetic"] = "Synthetic";
|
|
82
|
+
IDLExtendedAttributes["Throws"] = "Throws";
|
|
81
83
|
IDLExtendedAttributes["TSType"] = "TSType";
|
|
82
84
|
IDLExtendedAttributes["TypeArguments"] = "TypeArguments";
|
|
83
85
|
IDLExtendedAttributes["TypeParameters"] = "TypeParameters";
|
|
@@ -101,6 +103,9 @@ export function forEachChild(node, cbEnter, cbLeave) {
|
|
|
101
103
|
var _a, _b;
|
|
102
104
|
cbEnter(node);
|
|
103
105
|
switch (node.kind) {
|
|
106
|
+
case IDLKind.File:
|
|
107
|
+
node.entries.forEach((value) => forEachChild(value, cbEnter, cbLeave));
|
|
108
|
+
break;
|
|
104
109
|
case IDLKind.Namespace:
|
|
105
110
|
node.members.forEach((value) => forEachChild(value, cbEnter, cbLeave));
|
|
106
111
|
break;
|
|
@@ -187,6 +192,9 @@ export function forceAsNamedNode(type) {
|
|
|
187
192
|
}
|
|
188
193
|
return type;
|
|
189
194
|
}
|
|
195
|
+
export function isFile(node) {
|
|
196
|
+
return node.kind === IDLKind.File;
|
|
197
|
+
}
|
|
190
198
|
export function isUndefinedType(type) {
|
|
191
199
|
return isPrimitiveType(type) && type.name === IDLUndefinedType.name;
|
|
192
200
|
}
|
|
@@ -346,29 +354,41 @@ export function createNamespace(name, extendedAttributes, fileName) {
|
|
|
346
354
|
_idlNamedNodeBrand: innerIdlSymbol,
|
|
347
355
|
};
|
|
348
356
|
}
|
|
349
|
-
export function
|
|
350
|
-
|
|
351
|
-
forEachChild(node,
|
|
352
|
-
if (
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
357
|
+
export function linkParentBack(node) {
|
|
358
|
+
const parentStack = [];
|
|
359
|
+
forEachChild(node, (node) => {
|
|
360
|
+
if (isPrimitiveType(node))
|
|
361
|
+
return;
|
|
362
|
+
if (parentStack.length)
|
|
363
|
+
node.parent = parentStack[parentStack.length - 1];
|
|
364
|
+
parentStack.push(node);
|
|
365
|
+
}, (node) => {
|
|
366
|
+
if (isPrimitiveType(node))
|
|
367
|
+
return;
|
|
368
|
+
parentStack.pop();
|
|
361
369
|
});
|
|
370
|
+
return node;
|
|
362
371
|
}
|
|
363
372
|
export function getNamespacesPathFor(entry) {
|
|
364
|
-
let iterator = entry.
|
|
373
|
+
let iterator = entry.parent;
|
|
365
374
|
const result = [];
|
|
366
375
|
while (iterator) {
|
|
367
|
-
|
|
368
|
-
|
|
376
|
+
if (isNamespace(iterator))
|
|
377
|
+
result.unshift(iterator);
|
|
378
|
+
iterator = iterator.parent;
|
|
369
379
|
}
|
|
370
380
|
return result;
|
|
371
381
|
}
|
|
382
|
+
export function getFileFor(entry) {
|
|
383
|
+
let iterator = entry;
|
|
384
|
+
while (iterator) {
|
|
385
|
+
if (isFile(iterator))
|
|
386
|
+
return iterator;
|
|
387
|
+
iterator = iterator.parent;
|
|
388
|
+
}
|
|
389
|
+
console.warn(`Entry ${JSON.stringify(entry)} does not have IDLFile in parents`);
|
|
390
|
+
return undefined;
|
|
391
|
+
}
|
|
372
392
|
export function isEqualByQualifedName(a, b) {
|
|
373
393
|
if (a === b)
|
|
374
394
|
return true;
|
|
@@ -376,17 +396,28 @@ export function isEqualByQualifedName(a, b) {
|
|
|
376
396
|
return false;
|
|
377
397
|
if (a.kind !== b.kind || a.name !== b.name)
|
|
378
398
|
return false;
|
|
379
|
-
return
|
|
399
|
+
return getFQName(a) === getFQName(b);
|
|
400
|
+
}
|
|
401
|
+
export function getPackageClause(entry) {
|
|
402
|
+
let file = getFileFor(entry);
|
|
403
|
+
if (!file)
|
|
404
|
+
return [];
|
|
405
|
+
for (const child of file.entries)
|
|
406
|
+
if (isPackage(child))
|
|
407
|
+
return child.clause;
|
|
408
|
+
// console.warn("Expected to have one IDLPackage inside IDLFile. Using empty package name")
|
|
409
|
+
return [];
|
|
410
|
+
}
|
|
411
|
+
export function getPackageName(entry) {
|
|
412
|
+
return getPackageClause(entry).join(".");
|
|
380
413
|
}
|
|
381
414
|
export function getNamespaceName(a) {
|
|
382
415
|
return getNamespacesPathFor(a).map(it => it.name).join('.');
|
|
383
416
|
}
|
|
384
417
|
export function getFQName(a) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
return ns + a.name;
|
|
418
|
+
// TODO package name is very dirty now, waiting for Alexander Rekunkov PR
|
|
419
|
+
// return [...getPackageClause(a), ...getNamespacesPathFor(a).map(it => it.name), a.name].join('.')
|
|
420
|
+
return [...getNamespacesPathFor(a).map(it => it.name), a.name].join('.');
|
|
390
421
|
}
|
|
391
422
|
export function createVersion(value, extendedAttributes, fileName) {
|
|
392
423
|
return {
|
|
@@ -401,30 +432,26 @@ export function createVersion(value, extendedAttributes, fileName) {
|
|
|
401
432
|
};
|
|
402
433
|
}
|
|
403
434
|
export function fetchNamespaceFrom(pointOfView) {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
435
|
+
let node = pointOfView;
|
|
436
|
+
while (node) {
|
|
437
|
+
if (isNamespace(node))
|
|
438
|
+
return node;
|
|
439
|
+
node = node.parent;
|
|
409
440
|
}
|
|
410
441
|
return undefined;
|
|
411
442
|
}
|
|
412
|
-
export function createReferenceType(nameOrSource, typeArguments
|
|
443
|
+
export function createReferenceType(nameOrSource, typeArguments) {
|
|
413
444
|
let name;
|
|
414
|
-
let namespace;
|
|
415
445
|
if (typeof nameOrSource === 'string') {
|
|
416
446
|
name = nameOrSource;
|
|
417
|
-
namespace = fetchNamespaceFrom(pointOfView);
|
|
418
447
|
}
|
|
419
448
|
else {
|
|
420
|
-
name = nameOrSource
|
|
421
|
-
namespace = fetchNamespaceFrom(nameOrSource);
|
|
449
|
+
name = getFQName(nameOrSource);
|
|
422
450
|
}
|
|
423
451
|
return {
|
|
424
452
|
kind: IDLKind.ReferenceType,
|
|
425
453
|
name,
|
|
426
454
|
typeArguments,
|
|
427
|
-
namespace: namespace,
|
|
428
455
|
_idlNodeBrand: innerIdlSymbol,
|
|
429
456
|
_idlTypeBrand: innerIdlSymbol,
|
|
430
457
|
_idlNamedNodeBrand: innerIdlSymbol,
|
|
@@ -444,7 +471,12 @@ export function entityToType(entity) {
|
|
|
444
471
|
if (isType(entity)) {
|
|
445
472
|
return entity;
|
|
446
473
|
}
|
|
447
|
-
|
|
474
|
+
else if (isEntry(entity)) {
|
|
475
|
+
return createReferenceType(entity);
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
throw new Error(`Expected to have IDLType or IDLEntry, got ${entity}`);
|
|
479
|
+
}
|
|
448
480
|
}
|
|
449
481
|
export function createContainerType(container, element) {
|
|
450
482
|
return {
|
|
@@ -467,17 +499,26 @@ export function createUnionType(types, name) {
|
|
|
467
499
|
_idlNamedNodeBrand: innerIdlSymbol,
|
|
468
500
|
};
|
|
469
501
|
}
|
|
470
|
-
export function
|
|
502
|
+
export function createFile(entries, fileName) {
|
|
503
|
+
return {
|
|
504
|
+
kind: IDLKind.File,
|
|
505
|
+
entries: entries,
|
|
506
|
+
fileName,
|
|
507
|
+
_idlNodeBrand: innerIdlSymbol,
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
export function createPackage(clause) {
|
|
471
511
|
return {
|
|
472
512
|
kind: IDLKind.Package,
|
|
473
|
-
name,
|
|
513
|
+
name: "",
|
|
514
|
+
clause,
|
|
474
515
|
_idlNodeBrand: innerIdlSymbol,
|
|
475
516
|
_idlEntryBrand: innerIdlSymbol,
|
|
476
517
|
_idlNamedNodeBrand: innerIdlSymbol,
|
|
477
518
|
};
|
|
478
519
|
}
|
|
479
|
-
export function createImport(
|
|
480
|
-
return Object.assign(Object.assign({ kind: IDLKind.Import, name,
|
|
520
|
+
export function createImport(clause, name, nodeInitializer) {
|
|
521
|
+
return Object.assign(Object.assign({ kind: IDLKind.Import, name: name || "", clause }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
481
522
|
}
|
|
482
523
|
export function createEnum(name, elements, nodeInitializer) {
|
|
483
524
|
return Object.assign(Object.assign({ kind: IDLKind.Enum, name: name, elements: elements }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
@@ -713,13 +754,15 @@ export function printMethod(idl) {
|
|
|
713
754
|
];
|
|
714
755
|
}
|
|
715
756
|
export function printPackage(idl) {
|
|
757
|
+
if (!idl.clause.length)
|
|
758
|
+
return [];
|
|
716
759
|
return [
|
|
717
|
-
`package
|
|
760
|
+
`package ${idl.clause.join(".")};`
|
|
718
761
|
];
|
|
719
762
|
}
|
|
720
763
|
export function printImport(idl) {
|
|
721
764
|
return [
|
|
722
|
-
`import "${idl.name}
|
|
765
|
+
`import ${idl.clause.join(".")}${idl.name ? " as " : ""}${idl.name};`
|
|
723
766
|
];
|
|
724
767
|
}
|
|
725
768
|
export function printNamespace(idl) {
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
|
-
import { GenerateOptions
|
|
3
|
-
export
|
|
2
|
+
import { GenerateOptions } from "./options";
|
|
3
|
+
export interface GenerateVisitor<T> {
|
|
4
|
+
visitPhase1(): T;
|
|
5
|
+
visitPhase2?(siblings: {
|
|
6
|
+
[key in string]: {
|
|
7
|
+
tsSourceFile: ts.SourceFile;
|
|
8
|
+
visitor: GenerateVisitor<T>;
|
|
9
|
+
result: T;
|
|
10
|
+
};
|
|
11
|
+
}): T;
|
|
12
|
+
}
|
|
13
|
+
export declare function generate<T>(inputDirs: string[], inputFiles: string[], outputDir: string, visitorFactory: (sourceFile: ts.SourceFile, program: ts.Program, compilerHost: ts.CompilerHost) => GenerateVisitor<T>, options: GenerateOptions<T>): void;
|
|
4
14
|
//# sourceMappingURL=idlize.d.ts.map
|
package/build/lib/src/idlize.js
CHANGED
|
@@ -62,7 +62,8 @@ export function generate(inputDirs, inputFiles, outputDir, visitorFactory, optio
|
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
input = Array.from(new Set(input.map(p => path.resolve(p)))).sort();
|
|
65
|
-
let
|
|
65
|
+
let compilerHost = ts.createCompilerHost(options.compilerOptions);
|
|
66
|
+
let program = ts.createProgram(input.concat([path.join(__dirname, "../stdlib.d.ts")]), options.compilerOptions, compilerHost);
|
|
66
67
|
if (options.enableLog) {
|
|
67
68
|
console.log("Initialized TypeScript program with input files:", input);
|
|
68
69
|
}
|
|
@@ -70,23 +71,37 @@ export function generate(inputDirs, inputFiles, outputDir, visitorFactory, optio
|
|
|
70
71
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
71
72
|
const typeChecker = program.getTypeChecker();
|
|
72
73
|
(_a = options.onBegin) === null || _a === void 0 ? void 0 : _a.call(options, outputDir, typeChecker);
|
|
74
|
+
const dtsFileName2Visitor = {};
|
|
73
75
|
for (const sourceFile of program.getSourceFiles()) {
|
|
74
|
-
const
|
|
75
|
-
const isInDir = resolvedInputDirs.some(dir =>
|
|
76
|
-
const isExplicitFile = input.some(f => path.resolve(f) ===
|
|
76
|
+
const resolvedSourceFileName = path.resolve(sourceFile.fileName);
|
|
77
|
+
const isInDir = resolvedInputDirs.some(dir => resolvedSourceFileName.startsWith(dir));
|
|
78
|
+
const isExplicitFile = input.some(f => path.resolve(f) === resolvedSourceFileName);
|
|
77
79
|
if (!isInDir && !isExplicitFile) {
|
|
78
80
|
if (options.enableLog) {
|
|
79
|
-
console.log(`Skipping file: ${
|
|
81
|
+
console.log(`Skipping file: ${resolvedSourceFileName}`);
|
|
80
82
|
}
|
|
81
83
|
continue;
|
|
82
84
|
}
|
|
83
85
|
if (options.enableLog) {
|
|
84
|
-
console.log(`Processing file: ${
|
|
86
|
+
console.log(`Processing file: ${resolvedSourceFileName}`);
|
|
85
87
|
}
|
|
86
88
|
// Walk the tree to search for classes
|
|
87
|
-
const visitor = visitorFactory(sourceFile,
|
|
88
|
-
const
|
|
89
|
-
|
|
89
|
+
const visitor = visitorFactory(sourceFile, program, compilerHost);
|
|
90
|
+
const result = visitor.visitPhase1();
|
|
91
|
+
dtsFileName2Visitor[sourceFile.fileName] = {
|
|
92
|
+
tsSourceFile: sourceFile,
|
|
93
|
+
visitor,
|
|
94
|
+
result
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
for (const resolvedSourceFileName in dtsFileName2Visitor) {
|
|
98
|
+
const visitorStaff = dtsFileName2Visitor[resolvedSourceFileName];
|
|
99
|
+
if (visitorStaff.visitor.visitPhase2)
|
|
100
|
+
visitorStaff.result = visitorStaff.visitor.visitPhase2(dtsFileName2Visitor);
|
|
101
|
+
}
|
|
102
|
+
for (const resolvedSourceFileName in dtsFileName2Visitor) {
|
|
103
|
+
const visitorStaff = dtsFileName2Visitor[resolvedSourceFileName];
|
|
104
|
+
(_b = options.onSingleFile) === null || _b === void 0 ? void 0 : _b.call(options, visitorStaff.result, outputDir, visitorStaff.tsSourceFile);
|
|
90
105
|
}
|
|
91
106
|
(_c = options.onEnd) === null || _c === void 0 ? void 0 : _c.call(options, outputDir);
|
|
92
107
|
if (options.enableLog) {
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import * as idl from './idl';
|
|
2
2
|
export interface IDLLibrary {
|
|
3
|
-
readonly files: readonly IDLFile[];
|
|
3
|
+
readonly files: readonly idl.IDLFile[];
|
|
4
4
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
package?: idl.IDLPackage;
|
|
8
|
-
entities: idl.IDLNode[];
|
|
9
|
-
}
|
|
10
|
-
declare function createLibrary(files: IDLFile[]): IDLLibrary;
|
|
11
|
-
declare function toLibrary(ii: Iterable<IDLFile>): IDLLibrary;
|
|
5
|
+
declare function createLibrary(files: idl.IDLFile[]): IDLLibrary;
|
|
6
|
+
declare function toLibrary(ii: Iterable<idl.IDLFile>): IDLLibrary;
|
|
12
7
|
declare function serializeParam(params: unknown): string;
|
|
13
8
|
export interface LibraryQuery<A, R> {
|
|
14
9
|
fn: (x: A) => R;
|
|
@@ -44,8 +39,8 @@ export declare const lib: {
|
|
|
44
39
|
lens: typeof lens;
|
|
45
40
|
query: typeof query;
|
|
46
41
|
select: {
|
|
47
|
-
files(): LibraryReducer<readonly IDLFile[]>;
|
|
48
|
-
nodes(params: EntitiesParams): LibraryQuery<readonly IDLFile[], idl.IDLNode[]>;
|
|
42
|
+
files(): LibraryReducer<readonly idl.IDLFile[]>;
|
|
43
|
+
nodes(params: EntitiesParams): LibraryQuery<readonly idl.IDLFile[], idl.IDLNode[]>;
|
|
49
44
|
entries(): LibraryQuery<idl.IDLNode[], idl.IDLEntry[]>;
|
|
50
45
|
interfaces(): LibraryQuery<idl.IDLNode[], idl.IDLInterface[]>;
|
|
51
46
|
hasExt<T extends idl.IDLNode>(attr: idl.IDLExtendedAttributes): LibraryQuery<T[], T[]>;
|
package/build/lib/src/library.js
CHANGED
|
@@ -148,7 +148,7 @@ const select = {
|
|
|
148
148
|
return [node];
|
|
149
149
|
}
|
|
150
150
|
return req(key, xs => {
|
|
151
|
-
return xs.flatMap(x => x.
|
|
151
|
+
return xs.flatMap(x => x.entries).flatMap(go);
|
|
152
152
|
});
|
|
153
153
|
},
|
|
154
154
|
entries() {
|
|
@@ -166,7 +166,7 @@ const select = {
|
|
|
166
166
|
name(name) {
|
|
167
167
|
return reduce(`select.by.name.${name}`, lib => {
|
|
168
168
|
return lib.files.flatMap(it => {
|
|
169
|
-
return it.
|
|
169
|
+
return it.entries.flatMap(it => {
|
|
170
170
|
if (idl.isNamedNode(it) && it.name === name) {
|
|
171
171
|
return [it];
|
|
172
172
|
}
|
|
@@ -2,13 +2,14 @@ import * as idl from '../idl';
|
|
|
2
2
|
import { PeerClass } from "./PeerClass";
|
|
3
3
|
import { LibraryFileInterface } from '../LibraryInterface';
|
|
4
4
|
export declare class PeerFile implements LibraryFileInterface {
|
|
5
|
-
readonly
|
|
6
|
-
readonly entries: idl.IDLEntry[];
|
|
5
|
+
readonly file: idl.IDLFile;
|
|
7
6
|
readonly isPredefined: boolean;
|
|
8
7
|
readonly peers: Map<string, PeerClass>;
|
|
9
|
-
constructor(
|
|
8
|
+
constructor(file: idl.IDLFile, isPredefined?: boolean);
|
|
10
9
|
packageName(): string;
|
|
11
10
|
package(): idl.IDLPackage | undefined;
|
|
12
11
|
get peersToGenerate(): PeerClass[];
|
|
12
|
+
get entries(): idl.IDLEntry[];
|
|
13
|
+
get originalFilename(): string;
|
|
13
14
|
}
|
|
14
15
|
//# sourceMappingURL=PeerFile.d.ts.map
|
|
@@ -14,9 +14,8 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import * as idl from '../idl';
|
|
16
16
|
export class PeerFile {
|
|
17
|
-
constructor(
|
|
18
|
-
this.
|
|
19
|
-
this.entries = entries;
|
|
17
|
+
constructor(file, isPredefined = false) {
|
|
18
|
+
this.file = file;
|
|
20
19
|
this.isPredefined = isPredefined;
|
|
21
20
|
this.peers = new Map();
|
|
22
21
|
}
|
|
@@ -37,5 +36,13 @@ export class PeerFile {
|
|
|
37
36
|
const peers = Array.from(this.peers.values());
|
|
38
37
|
return peers;
|
|
39
38
|
}
|
|
39
|
+
// TODO just to not refactor too much in one PR
|
|
40
|
+
get entries() {
|
|
41
|
+
return this.file.entries;
|
|
42
|
+
}
|
|
43
|
+
// TODO just to not refactor too much in one PR
|
|
44
|
+
get originalFilename() {
|
|
45
|
+
return this.file.fileName;
|
|
46
|
+
}
|
|
40
47
|
}
|
|
41
48
|
//# sourceMappingURL=PeerFile.js.map
|
|
@@ -10254,10 +10254,8 @@ export declare class PeerLibrary implements LibraryInterface {
|
|
|
10254
10254
|
asIDLLibrary(): IDLLibrary;
|
|
10255
10255
|
get globalScopeInterfaces(): idl.IDLInterface[];
|
|
10256
10256
|
layout: LayoutManager;
|
|
10257
|
-
private
|
|
10258
|
-
|
|
10259
|
-
get syntheticEntries(): idl.IDLEntry[];
|
|
10260
|
-
initSyntheticEntries(entries: idl.IDLEntry[]): void;
|
|
10257
|
+
private _syntheticFile;
|
|
10258
|
+
initSyntheticEntries(file: idl.IDLFile): void;
|
|
10261
10259
|
readonly files: PeerFile[];
|
|
10262
10260
|
readonly builderClasses: Map<string, BuilderClass>;
|
|
10263
10261
|
get buildersToGenerate(): BuilderClass[];
|
|
@@ -10279,8 +10277,8 @@ export declare class PeerLibrary implements LibraryInterface {
|
|
|
10279
10277
|
setCurrentContext(context: string | undefined): void;
|
|
10280
10278
|
findFileByOriginalFilename(filename: string): PeerFile | undefined;
|
|
10281
10279
|
mapType(type: idl.IDLType): string;
|
|
10282
|
-
resolveTypeReference(type: idl.IDLReferenceType
|
|
10283
|
-
|
|
10280
|
+
resolveTypeReference(type: idl.IDLReferenceType): idl.IDLEntry | undefined;
|
|
10281
|
+
private resolveTypeReferenceScoped;
|
|
10284
10282
|
hasInLibrary(entry: idl.IDLEntry): boolean;
|
|
10285
10283
|
typeConvertor(param: string, type: idl.IDLType, isOptionalParam?: boolean): ArgConvertor;
|
|
10286
10284
|
declarationConvertor(param: string, type: idl.IDLReferenceType, declaration: idl.IDLEntry | undefined): ArgConvertor;
|
|
@@ -40,21 +40,13 @@ export class PeerLibrary {
|
|
|
40
40
|
return this._cachedIdlLibrary;
|
|
41
41
|
}
|
|
42
42
|
this._cachedIdlLibrary = {
|
|
43
|
-
files: this.files.map(file =>
|
|
44
|
-
fileName: file.originalFilename,
|
|
45
|
-
entities: file.entries,
|
|
46
|
-
package: file.package()
|
|
47
|
-
}))
|
|
43
|
+
files: this.files.map(file => file.file)
|
|
48
44
|
};
|
|
49
45
|
return this._cachedIdlLibrary;
|
|
50
46
|
}
|
|
51
47
|
get globalScopeInterfaces() { return query(this.asIDLLibrary(), lenses.globals); }
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return this._syntheticEntries;
|
|
55
|
-
}
|
|
56
|
-
initSyntheticEntries(entries) {
|
|
57
|
-
this._syntheticEntries = entries;
|
|
48
|
+
initSyntheticEntries(file) {
|
|
49
|
+
this._syntheticFile = file;
|
|
58
50
|
}
|
|
59
51
|
get buildersToGenerate() {
|
|
60
52
|
return Array.from(this.builderClasses.values()).filter(it => it.needBeGenerated);
|
|
@@ -66,7 +58,7 @@ export class PeerLibrary {
|
|
|
66
58
|
this.language = language;
|
|
67
59
|
this.libraryPackages = libraryPackages;
|
|
68
60
|
this.layout = LayoutManager.Empty();
|
|
69
|
-
this.
|
|
61
|
+
this._syntheticFile = idl.createFile([]);
|
|
70
62
|
this.files = [];
|
|
71
63
|
this.builderClasses = new Map();
|
|
72
64
|
this.materializedClasses = new Map();
|
|
@@ -110,7 +102,7 @@ export class PeerLibrary {
|
|
|
110
102
|
createContinuationCallbackReference(continuationType) {
|
|
111
103
|
const continuationParameters = this.createContinuationParameters(continuationType);
|
|
112
104
|
const syntheticName = generateSyntheticFunctionName(continuationParameters, idl.IDLVoidType);
|
|
113
|
-
return idl.createReferenceType(syntheticName
|
|
105
|
+
return idl.createReferenceType(syntheticName);
|
|
114
106
|
}
|
|
115
107
|
getCurrentContext() {
|
|
116
108
|
return this.context;
|
|
@@ -124,15 +116,15 @@ export class PeerLibrary {
|
|
|
124
116
|
mapType(type) {
|
|
125
117
|
return this.targetNameConvertorInstance.convert(type);
|
|
126
118
|
}
|
|
127
|
-
resolveTypeReference(type
|
|
128
|
-
|
|
119
|
+
resolveTypeReference(type) {
|
|
120
|
+
return this.resolveTypeReferenceScoped(type);
|
|
121
|
+
}
|
|
122
|
+
resolveTypeReferenceScoped(type, pointOfView, rootEntries) {
|
|
123
|
+
const entry = this._syntheticFile.entries.find(it => it.name === type.name);
|
|
129
124
|
if (entry)
|
|
130
125
|
return entry;
|
|
131
126
|
const qualifiedName = type.name.split(".");
|
|
132
|
-
|
|
133
|
-
let pointOfViewNamespace = !pointOfView || idl.isNamespace(pointOfView)
|
|
134
|
-
? pointOfView
|
|
135
|
-
: pointOfView.namespace;
|
|
127
|
+
let pointOfViewNamespace = idl.fetchNamespaceFrom(type.parent);
|
|
136
128
|
rootEntries !== null && rootEntries !== void 0 ? rootEntries : (rootEntries = this.files.flatMap(it => it.entries));
|
|
137
129
|
if (1 === qualifiedName.length) {
|
|
138
130
|
const predefined = rootEntries.filter(it => idl.hasExtAttribute(it, idl.IDLExtendedAttributes.Predefined));
|
|
@@ -152,9 +144,12 @@ export class PeerLibrary {
|
|
|
152
144
|
if (!candidates.length)
|
|
153
145
|
break;
|
|
154
146
|
if (qualifiedNamePart === qualifiedName.length - 1) {
|
|
155
|
-
|
|
147
|
+
const target = candidates.length == 1
|
|
156
148
|
? candidates[0]
|
|
157
149
|
: candidates.find(it => !idl.hasExtAttribute(it, idl.IDLExtendedAttributes.Import)); // probably the wrong logic here
|
|
150
|
+
if (target && idl.isImport(target)) // Temporary disable Import declarations
|
|
151
|
+
return undefined;
|
|
152
|
+
return target;
|
|
158
153
|
}
|
|
159
154
|
entries = [];
|
|
160
155
|
for (const candidate of candidates) {
|
|
@@ -166,7 +161,7 @@ export class PeerLibrary {
|
|
|
166
161
|
entries.push(...candidate.constants, ...candidate.properties, ...candidate.methods);
|
|
167
162
|
}
|
|
168
163
|
}
|
|
169
|
-
pointOfViewNamespace = pointOfViewNamespace === null || pointOfViewNamespace === void 0 ? void 0 : pointOfViewNamespace.
|
|
164
|
+
pointOfViewNamespace = idl.fetchNamespaceFrom(pointOfViewNamespace === null || pointOfViewNamespace === void 0 ? void 0 : pointOfViewNamespace.parent);
|
|
170
165
|
}
|
|
171
166
|
// TODO: remove the next block after namespaces out of quarantine
|
|
172
167
|
if (!pointOfView) {
|
|
@@ -174,7 +169,7 @@ export class PeerLibrary {
|
|
|
174
169
|
const traverseNamespaces = (entry) => {
|
|
175
170
|
if (entry && idl.isNamespace(entry) && entry.members.length) {
|
|
176
171
|
//console.log(`Try alien namespace '${idl.getNamespacesPathFor(entry.members[0]).map(obj => obj.name).join(".")}' to resolve name '${type.name}'`)
|
|
177
|
-
const resolved = this.
|
|
172
|
+
const resolved = this.resolveTypeReferenceScoped(type, entry, rootEntries);
|
|
178
173
|
if (resolved)
|
|
179
174
|
resolveds.push(resolved);
|
|
180
175
|
entry.members.forEach(traverseNamespaces);
|
|
@@ -186,22 +181,9 @@ export class PeerLibrary {
|
|
|
186
181
|
} // end of block to remove
|
|
187
182
|
return undefined; // empty result
|
|
188
183
|
}
|
|
189
|
-
resolvePackageName(entry) {
|
|
190
|
-
var _a;
|
|
191
|
-
if (this._syntheticEntries.includes(entry))
|
|
192
|
-
return ((_a = this.libraryPackages) === null || _a === void 0 ? void 0 : _a.length) ? this.libraryPackages[0] : this.files[0].packageName();
|
|
193
|
-
while (entry.namespace) {
|
|
194
|
-
entry = entry.namespace;
|
|
195
|
-
}
|
|
196
|
-
for (const file of this.files) {
|
|
197
|
-
if (file.entries.includes(entry))
|
|
198
|
-
return file.packageName();
|
|
199
|
-
}
|
|
200
|
-
throw new Error(`Package name for entry ${entry.name} was not found`);
|
|
201
|
-
}
|
|
202
184
|
hasInLibrary(entry) {
|
|
203
185
|
var _a, _b;
|
|
204
|
-
return !((_a = this.libraryPackages) === null || _a === void 0 ? void 0 : _a.length) || ((_b = this.libraryPackages) === null || _b === void 0 ? void 0 : _b.includes(
|
|
186
|
+
return !((_a = this.libraryPackages) === null || _a === void 0 ? void 0 : _a.length) || ((_b = this.libraryPackages) === null || _b === void 0 ? void 0 : _b.includes(idl.getPackageName(entry)));
|
|
205
187
|
}
|
|
206
188
|
typeConvertor(param, type, isOptionalParam = false) {
|
|
207
189
|
if (isOptionalParam) {
|