@idlizer/core 2.0.30 → 2.0.32
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/convertors/CppConvertors.js +3 -5
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +1 -1
- 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 +2 -2
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +1 -1
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +5 -2
- package/build/lib/src/from-idl/DtsPrinter.js +18 -15
- 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 +18 -8
- package/build/lib/src/idl.js +81 -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/idl/common.d.ts +1 -1
- package/build/lib/src/peer-generation/idl/common.js +4 -4
- package/build/lib/src/peer-generation/unions.js +2 -2
- 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.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) {
|
|
@@ -101,6 +102,9 @@ export function forEachChild(node, cbEnter, cbLeave) {
|
|
|
101
102
|
var _a, _b;
|
|
102
103
|
cbEnter(node);
|
|
103
104
|
switch (node.kind) {
|
|
105
|
+
case IDLKind.File:
|
|
106
|
+
node.entries.forEach((value) => forEachChild(value, cbEnter, cbLeave));
|
|
107
|
+
break;
|
|
104
108
|
case IDLKind.Namespace:
|
|
105
109
|
node.members.forEach((value) => forEachChild(value, cbEnter, cbLeave));
|
|
106
110
|
break;
|
|
@@ -187,6 +191,9 @@ export function forceAsNamedNode(type) {
|
|
|
187
191
|
}
|
|
188
192
|
return type;
|
|
189
193
|
}
|
|
194
|
+
export function isFile(node) {
|
|
195
|
+
return node.kind === IDLKind.File;
|
|
196
|
+
}
|
|
190
197
|
export function isUndefinedType(type) {
|
|
191
198
|
return isPrimitiveType(type) && type.name === IDLUndefinedType.name;
|
|
192
199
|
}
|
|
@@ -346,29 +353,41 @@ export function createNamespace(name, extendedAttributes, fileName) {
|
|
|
346
353
|
_idlNamedNodeBrand: innerIdlSymbol,
|
|
347
354
|
};
|
|
348
355
|
}
|
|
349
|
-
export function
|
|
350
|
-
|
|
351
|
-
forEachChild(node,
|
|
352
|
-
if (
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
356
|
+
export function linkParentBack(node) {
|
|
357
|
+
const parentStack = [];
|
|
358
|
+
forEachChild(node, (node) => {
|
|
359
|
+
if (isPrimitiveType(node))
|
|
360
|
+
return;
|
|
361
|
+
if (parentStack.length)
|
|
362
|
+
node.parent = parentStack[parentStack.length - 1];
|
|
363
|
+
parentStack.push(node);
|
|
364
|
+
}, (node) => {
|
|
365
|
+
if (isPrimitiveType(node))
|
|
366
|
+
return;
|
|
367
|
+
parentStack.pop();
|
|
361
368
|
});
|
|
369
|
+
return node;
|
|
362
370
|
}
|
|
363
371
|
export function getNamespacesPathFor(entry) {
|
|
364
|
-
let iterator = entry.
|
|
372
|
+
let iterator = entry.parent;
|
|
365
373
|
const result = [];
|
|
366
374
|
while (iterator) {
|
|
367
|
-
|
|
368
|
-
|
|
375
|
+
if (isNamespace(iterator))
|
|
376
|
+
result.unshift(iterator);
|
|
377
|
+
iterator = iterator.parent;
|
|
369
378
|
}
|
|
370
379
|
return result;
|
|
371
380
|
}
|
|
381
|
+
export function getFileFor(entry) {
|
|
382
|
+
let iterator = entry;
|
|
383
|
+
while (iterator) {
|
|
384
|
+
if (isFile(iterator))
|
|
385
|
+
return iterator;
|
|
386
|
+
iterator = iterator.parent;
|
|
387
|
+
}
|
|
388
|
+
console.warn(`Entry ${JSON.stringify(entry)} does not have IDLFile in parents`);
|
|
389
|
+
return undefined;
|
|
390
|
+
}
|
|
372
391
|
export function isEqualByQualifedName(a, b) {
|
|
373
392
|
if (a === b)
|
|
374
393
|
return true;
|
|
@@ -376,17 +395,28 @@ export function isEqualByQualifedName(a, b) {
|
|
|
376
395
|
return false;
|
|
377
396
|
if (a.kind !== b.kind || a.name !== b.name)
|
|
378
397
|
return false;
|
|
379
|
-
return
|
|
398
|
+
return getFQName(a) === getFQName(b);
|
|
399
|
+
}
|
|
400
|
+
export function getPackageClause(entry) {
|
|
401
|
+
let file = getFileFor(entry);
|
|
402
|
+
if (!file)
|
|
403
|
+
return [];
|
|
404
|
+
for (const child of file.entries)
|
|
405
|
+
if (isPackage(child))
|
|
406
|
+
return child.clause;
|
|
407
|
+
// console.warn("Expected to have one IDLPackage inside IDLFile. Using empty package name")
|
|
408
|
+
return [];
|
|
409
|
+
}
|
|
410
|
+
export function getPackageName(entry) {
|
|
411
|
+
return getPackageClause(entry).join(".");
|
|
380
412
|
}
|
|
381
413
|
export function getNamespaceName(a) {
|
|
382
414
|
return getNamespacesPathFor(a).map(it => it.name).join('.');
|
|
383
415
|
}
|
|
384
416
|
export function getFQName(a) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
return ns + a.name;
|
|
417
|
+
// TODO package name is very dirty now, waiting for Alexander Rekunkov PR
|
|
418
|
+
// return [...getPackageClause(a), ...getNamespacesPathFor(a).map(it => it.name), a.name].join('.')
|
|
419
|
+
return [...getNamespacesPathFor(a).map(it => it.name), a.name].join('.');
|
|
390
420
|
}
|
|
391
421
|
export function createVersion(value, extendedAttributes, fileName) {
|
|
392
422
|
return {
|
|
@@ -401,30 +431,26 @@ export function createVersion(value, extendedAttributes, fileName) {
|
|
|
401
431
|
};
|
|
402
432
|
}
|
|
403
433
|
export function fetchNamespaceFrom(pointOfView) {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
434
|
+
let node = pointOfView;
|
|
435
|
+
while (node) {
|
|
436
|
+
if (isNamespace(node))
|
|
437
|
+
return node;
|
|
438
|
+
node = node.parent;
|
|
409
439
|
}
|
|
410
440
|
return undefined;
|
|
411
441
|
}
|
|
412
|
-
export function createReferenceType(nameOrSource, typeArguments
|
|
442
|
+
export function createReferenceType(nameOrSource, typeArguments) {
|
|
413
443
|
let name;
|
|
414
|
-
let namespace;
|
|
415
444
|
if (typeof nameOrSource === 'string') {
|
|
416
445
|
name = nameOrSource;
|
|
417
|
-
namespace = fetchNamespaceFrom(pointOfView);
|
|
418
446
|
}
|
|
419
447
|
else {
|
|
420
|
-
name = nameOrSource
|
|
421
|
-
namespace = fetchNamespaceFrom(nameOrSource);
|
|
448
|
+
name = getFQName(nameOrSource);
|
|
422
449
|
}
|
|
423
450
|
return {
|
|
424
451
|
kind: IDLKind.ReferenceType,
|
|
425
452
|
name,
|
|
426
453
|
typeArguments,
|
|
427
|
-
namespace: namespace,
|
|
428
454
|
_idlNodeBrand: innerIdlSymbol,
|
|
429
455
|
_idlTypeBrand: innerIdlSymbol,
|
|
430
456
|
_idlNamedNodeBrand: innerIdlSymbol,
|
|
@@ -444,7 +470,12 @@ export function entityToType(entity) {
|
|
|
444
470
|
if (isType(entity)) {
|
|
445
471
|
return entity;
|
|
446
472
|
}
|
|
447
|
-
|
|
473
|
+
else if (isEntry(entity)) {
|
|
474
|
+
return createReferenceType(entity);
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
477
|
+
throw new Error(`Expected to have IDLType or IDLEntry, got ${entity}`);
|
|
478
|
+
}
|
|
448
479
|
}
|
|
449
480
|
export function createContainerType(container, element) {
|
|
450
481
|
return {
|
|
@@ -467,17 +498,26 @@ export function createUnionType(types, name) {
|
|
|
467
498
|
_idlNamedNodeBrand: innerIdlSymbol,
|
|
468
499
|
};
|
|
469
500
|
}
|
|
470
|
-
export function
|
|
501
|
+
export function createFile(entries, fileName) {
|
|
502
|
+
return {
|
|
503
|
+
kind: IDLKind.File,
|
|
504
|
+
entries: entries,
|
|
505
|
+
fileName,
|
|
506
|
+
_idlNodeBrand: innerIdlSymbol,
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
export function createPackage(clause) {
|
|
471
510
|
return {
|
|
472
511
|
kind: IDLKind.Package,
|
|
473
|
-
name,
|
|
512
|
+
name: "",
|
|
513
|
+
clause,
|
|
474
514
|
_idlNodeBrand: innerIdlSymbol,
|
|
475
515
|
_idlEntryBrand: innerIdlSymbol,
|
|
476
516
|
_idlNamedNodeBrand: innerIdlSymbol,
|
|
477
517
|
};
|
|
478
518
|
}
|
|
479
|
-
export function createImport(
|
|
480
|
-
return Object.assign(Object.assign({ kind: IDLKind.Import, name,
|
|
519
|
+
export function createImport(clause, name, nodeInitializer) {
|
|
520
|
+
return Object.assign(Object.assign({ kind: IDLKind.Import, name: name || "", clause }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
481
521
|
}
|
|
482
522
|
export function createEnum(name, elements, nodeInitializer) {
|
|
483
523
|
return Object.assign(Object.assign({ kind: IDLKind.Enum, name: name, elements: elements }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
@@ -713,13 +753,15 @@ export function printMethod(idl) {
|
|
|
713
753
|
];
|
|
714
754
|
}
|
|
715
755
|
export function printPackage(idl) {
|
|
756
|
+
if (!idl.clause.length)
|
|
757
|
+
return [];
|
|
716
758
|
return [
|
|
717
|
-
`package
|
|
759
|
+
`package ${idl.clause.join(".")};`
|
|
718
760
|
];
|
|
719
761
|
}
|
|
720
762
|
export function printImport(idl) {
|
|
721
763
|
return [
|
|
722
|
-
`import "${idl.name}
|
|
764
|
+
`import ${idl.clause.join(".")}${idl.name ? " as " : ""}${idl.name};`
|
|
723
765
|
];
|
|
724
766
|
}
|
|
725
767
|
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) {
|
|
@@ -2,7 +2,7 @@ import * as idl from "../../idl";
|
|
|
2
2
|
import { Language } from "../../Language";
|
|
3
3
|
export declare function generateSyntheticIdlNodeName(type: idl.IDLType): string;
|
|
4
4
|
export declare function qualifiedName(decl: idl.IDLNode, languageOrDelimiter: Language | string): string;
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function collapseTypes(types: idl.IDLType[], name?: string): idl.IDLType;
|
|
6
6
|
export declare function generifiedTypeName(refType: idl.IDLReferenceType | undefined, refName?: string): string | undefined;
|
|
7
7
|
export declare function generateSyntheticUnionName(types: idl.IDLType[]): string;
|
|
8
8
|
export declare function generateSyntheticFunctionName(parameters: idl.IDLParameter[], returnType: idl.IDLType, isAsync?: boolean): string;
|
|
@@ -39,11 +39,11 @@ export function qualifiedName(decl, languageOrDelimiter) {
|
|
|
39
39
|
const delimiter = typeof languageOrDelimiter === "string"
|
|
40
40
|
? languageOrDelimiter
|
|
41
41
|
: (languageOrDelimiter === Language.CPP ? '_' : '.');
|
|
42
|
-
if (idl.isEntry(decl)
|
|
43
|
-
|
|
44
|
-
return idl.
|
|
42
|
+
if (!idl.isEntry(decl))
|
|
43
|
+
throw new Error(`Expected to have an IDLEntry, got ${idl.IDLKind[decl.kind]}`);
|
|
44
|
+
return idl.getFQName(decl).split(".").join(delimiter);
|
|
45
45
|
}
|
|
46
|
-
export function
|
|
46
|
+
export function collapseTypes(types, name) {
|
|
47
47
|
const seenNames = new Set();
|
|
48
48
|
const uniqueTypes = types.filter(it => {
|
|
49
49
|
const typeName = idl.printType(it);
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { convertType } from "../LanguageWriters";
|
|
16
16
|
import { IDLCustomObjectType, IDLUndefinedType, isType, isUnionType } from '../idl';
|
|
17
|
-
import {
|
|
17
|
+
import { collapseTypes } from "./idl/common";
|
|
18
18
|
import { CustomTypeConvertor } from "../LanguageWriters/ArgConvertors";
|
|
19
19
|
import { RuntimeType } from "../LanguageWriters/common";
|
|
20
20
|
export class UnionFlattener {
|
|
@@ -115,7 +115,7 @@ export function flattenUnionType(library, type) {
|
|
|
115
115
|
if (isUnionType(type)) {
|
|
116
116
|
const allTypes = type.types.flatMap(it => convertType(unionFlattener, it));
|
|
117
117
|
const uniqueTypes = new Set(allTypes);
|
|
118
|
-
return uniqueTypes.size === allTypes.length ? type :
|
|
118
|
+
return uniqueTypes.size === allTypes.length ? type : collapseTypes(Array.from(uniqueTypes));
|
|
119
119
|
}
|
|
120
120
|
return type;
|
|
121
121
|
}
|
package/build/lib/src/util.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
|
+
import * as idl from "./idl";
|
|
2
3
|
import { Language } from './Language';
|
|
3
4
|
export interface NameWithType {
|
|
4
5
|
name?: ts.DeclarationName;
|
|
@@ -80,4 +81,5 @@ export declare class Lazy<T> {
|
|
|
80
81
|
get value(): T;
|
|
81
82
|
}
|
|
82
83
|
export declare function lazy<T>(factory: () => T): Lazy<T>;
|
|
84
|
+
export declare function isInNamespace(node: idl.IDLEntry): boolean;
|
|
83
85
|
//# sourceMappingURL=util.d.ts.map
|
package/build/lib/src/util.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import * as path from 'path';
|
|
16
16
|
import * as fs from "fs";
|
|
17
17
|
import * as ts from "typescript";
|
|
18
|
+
import * as idl from "./idl";
|
|
18
19
|
import { Language } from './Language';
|
|
19
20
|
/** True if this is visible outside this file, false otherwise */
|
|
20
21
|
export function isNodePublic(node) {
|
|
@@ -635,4 +636,7 @@ export class Lazy {
|
|
|
635
636
|
export function lazy(factory) {
|
|
636
637
|
return new Lazy(factory);
|
|
637
638
|
}
|
|
639
|
+
export function isInNamespace(node) {
|
|
640
|
+
return idl.getNamespacesPathFor(node).length > 0;
|
|
641
|
+
}
|
|
638
642
|
//# sourceMappingURL=util.js.map
|
package/build/lib/src/visitor.js
CHANGED
|
@@ -103,7 +103,7 @@ export class IDLDependencyCollector {
|
|
|
103
103
|
}
|
|
104
104
|
visitSupertype(type) {
|
|
105
105
|
if (idl.isInterface(type)) {
|
|
106
|
-
return this.walk(idl.createReferenceType(type
|
|
106
|
+
return this.walk(idl.createReferenceType(type));
|
|
107
107
|
}
|
|
108
108
|
return this.walk(type);
|
|
109
109
|
}
|