@idlizer/core 2.1.2 → 2.1.7
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 -4
- package/build/lib/src/LanguageWriters/ArgConvertors.js +43 -32
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +35 -17
- package/build/lib/src/LanguageWriters/LanguageWriter.js +30 -56
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +3 -1
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +32 -11
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +5 -2
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +71 -62
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +1 -1
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +9 -19
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.d.ts +4 -2
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +10 -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 +8 -4
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +87 -33
- 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 +19 -11
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +34 -47
- 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 +17 -8
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +48 -23
- 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 +13 -8
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +33 -52
- package/build/lib/src/LibraryInterface.d.ts +1 -4
- package/build/lib/src/config.d.ts +813 -110
- package/build/lib/src/config.js +25 -3
- package/build/lib/src/configDescriber.d.ts +31 -4
- package/build/lib/src/configDescriber.js +101 -3
- package/build/lib/src/from-idl/DtsPrinter.js +31 -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 +10 -1
- package/build/lib/src/from-idl/deserialize.js +486 -352
- package/build/lib/src/idl.d.ts +29 -19
- package/build/lib/src/idl.js +404 -119
- 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 +3 -3
- 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 +131 -67
- 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 +3 -1
- package/build/lib/src/peer-generation/idl/common.js +21 -4
- package/build/lib/src/peer-generation/isMaterialized.js +28 -7
- package/build/lib/src/peer-generation/unions.d.ts +3 -2
- package/build/lib/src/peer-generation/unions.js +7 -3
- package/build/lib/src/resolveNamedNode.d.ts +3 -0
- package/build/lib/src/resolveNamedNode.js +105 -0
- package/build/lib/src/util.d.ts +8 -1
- package/build/lib/src/util.js +41 -3
- package/build/lib/src/visitor.d.ts +2 -1
- package/build/lib/src/visitor.js +109 -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 +93 -19
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
import { isReferenceType, hasExtAttribute, IDLExtendedAttributes } from "./idl";
|
|
16
|
+
import { isFile, isNamedNode, isNamespace, isEnum, isInterface, isImport } from "./idl";
|
|
17
|
+
export function resolveNamedNode(target, pov, corpus) {
|
|
18
|
+
let result;
|
|
19
|
+
let povScope = [];
|
|
20
|
+
while (pov) {
|
|
21
|
+
if (isFile(pov)) {
|
|
22
|
+
if (result = resolveDownFromFile(target, pov, corpus))
|
|
23
|
+
return result;
|
|
24
|
+
const importUsings = pov.entries.filter(it => isImport(it) && !it.name).map(it => it);
|
|
25
|
+
for (const importUsing of importUsings)
|
|
26
|
+
if (result = resolveDownFromRoot([...importUsing.clause, ...target], corpus))
|
|
27
|
+
return result;
|
|
28
|
+
povScope = pov.packageClause.slice();
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
if (result = resolveDownFromNode(target, pov, false, corpus))
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
pov = pov.parent;
|
|
36
|
+
}
|
|
37
|
+
for (;;) {
|
|
38
|
+
if (result = resolveDownFromRoot([...povScope, ...target], corpus))
|
|
39
|
+
return result;
|
|
40
|
+
if (povScope.length)
|
|
41
|
+
povScope.pop();
|
|
42
|
+
else
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
function resolveDownFromNode(target, pov, withSelf, corpus) {
|
|
48
|
+
if (withSelf && isNamedNode(pov)) {
|
|
49
|
+
if (isReferenceType(pov) || !pov.name.length)
|
|
50
|
+
return undefined;
|
|
51
|
+
let nameMatched = target[0] === pov.name;
|
|
52
|
+
if (!nameMatched)
|
|
53
|
+
nameMatched = target[0] === "default" && hasExtAttribute(pov, IDLExtendedAttributes.DefaultExport);
|
|
54
|
+
if (!nameMatched)
|
|
55
|
+
return undefined;
|
|
56
|
+
target = target.slice(1);
|
|
57
|
+
if (isImport(pov)) {
|
|
58
|
+
return resolveDownFromRoot([...pov.clause, ...target], corpus);
|
|
59
|
+
}
|
|
60
|
+
if (!target.length)
|
|
61
|
+
return pov;
|
|
62
|
+
}
|
|
63
|
+
let candidates;
|
|
64
|
+
if (isNamespace(pov))
|
|
65
|
+
candidates = pov.members;
|
|
66
|
+
else if (isEnum(pov))
|
|
67
|
+
candidates = pov.elements;
|
|
68
|
+
else if (isInterface(pov))
|
|
69
|
+
candidates = pov.constants;
|
|
70
|
+
else
|
|
71
|
+
return undefined;
|
|
72
|
+
let result;
|
|
73
|
+
for (const candidate of candidates) {
|
|
74
|
+
if (result = resolveDownFromNode(target, candidate, true, corpus))
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
function resolveDownFromFile(target, pov, corpus) {
|
|
80
|
+
let result;
|
|
81
|
+
for (const candidate of pov.entries) {
|
|
82
|
+
if (result = resolveDownFromNode(target, candidate, true, corpus))
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
function resolveDownFromRoot(target, corpus) {
|
|
88
|
+
let result;
|
|
89
|
+
for (const file of corpus) {
|
|
90
|
+
if (file.packageClause.length >= target.length)
|
|
91
|
+
continue;
|
|
92
|
+
let match = true;
|
|
93
|
+
for (let index = 0; index < file.packageClause.length; ++index)
|
|
94
|
+
if (file.packageClause[index] !== target[index]) {
|
|
95
|
+
match = false;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
if (!match)
|
|
99
|
+
continue;
|
|
100
|
+
if (result = resolveDownFromFile(target.slice(file.packageClause.length), file, corpus))
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=resolveNamedNode.js.map
|
package/build/lib/src/util.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ export declare function heritageDeclarations(typechecker: ts.TypeChecker, clause
|
|
|
42
42
|
export declare function typeName(type: ts.TypeReferenceNode | ts.TypeQueryNode | ts.ImportTypeNode): string | undefined;
|
|
43
43
|
export declare function typeEntityName(type: ts.TypeReferenceNode | ts.TypeQueryNode | ts.ImportTypeNode): ts.EntityName | undefined;
|
|
44
44
|
export declare function zip<A, B>(left: readonly A[], right: readonly B[]): [A, B][];
|
|
45
|
+
export declare function zipStrip<A, B>(left: readonly A[], right: readonly B[]): [A, B][];
|
|
45
46
|
export declare function identNameWithNamespace(node: ts.Node, language: Language): string;
|
|
46
47
|
export declare function identName(node: ts.Node | undefined): string | undefined;
|
|
47
48
|
export declare function identString(node: ts.Identifier | ts.PrivateIdentifier | ts.StringLiteral | ts.QualifiedName | ts.NumericLiteral | ts.ComputedPropertyName | ts.BindingName | undefined): string | undefined;
|
|
@@ -53,6 +54,7 @@ export declare function snakeCaseToCamelCase(input: string, tailToLowerCase?: bo
|
|
|
53
54
|
export declare function toCamelCase(input: string): string;
|
|
54
55
|
export declare function isUpperCase(s: string): boolean;
|
|
55
56
|
export declare function camelCaseToUpperSnakeCase(input: string): string;
|
|
57
|
+
export declare function snakeToLowCamelNode(node: idl.IDLEntry): string;
|
|
56
58
|
export declare function renameDtsToPeer(fileName: string, language: Language, withFileExtension?: boolean): string;
|
|
57
59
|
export declare function renameDtsToComponent(fileName: string, language: Language, withFileExtension?: boolean): string;
|
|
58
60
|
export declare function renameDtsToInterfaces(fileName: string, language: Language, withFileExtension?: boolean): string;
|
|
@@ -65,7 +67,7 @@ export declare function className(node: ts.ClassDeclaration | ts.InterfaceDeclar
|
|
|
65
67
|
* Add a prefix to an enum value which camel case name coincidence
|
|
66
68
|
* with the the same upper case name for an another enum value
|
|
67
69
|
*/
|
|
68
|
-
export declare function nameEnumValues(enumTarget:
|
|
70
|
+
export declare function nameEnumValues(enumTarget: string[]): string[];
|
|
69
71
|
export declare function groupBy<K, V>(values: V[], selector: (value: V) => K): Map<K, V[]>;
|
|
70
72
|
export declare function groupByIndexed<K, V>(values: V[], selector: (value: V) => K): Map<K, [V, number][]>;
|
|
71
73
|
export declare function removeExt(filename: string): string;
|
|
@@ -84,4 +86,9 @@ export declare class Lazy<T> {
|
|
|
84
86
|
export declare function lazy<T>(factory: () => T): Lazy<T>;
|
|
85
87
|
export declare function isInNamespace(node: idl.IDLEntry): boolean;
|
|
86
88
|
export declare function rightmostIndexOf<T>(array: T[], predicate: (value: T) => boolean): number;
|
|
89
|
+
type StringProperties<T> = {
|
|
90
|
+
[Property in keyof T as (T[Property] extends string ? Property : never)]: T[Property];
|
|
91
|
+
};
|
|
92
|
+
export declare function sorted<T, N extends keyof StringProperties<T>>(array: T[], key: ((value: T) => string) | N): T[];
|
|
93
|
+
export {};
|
|
87
94
|
//# sourceMappingURL=util.d.ts.map
|
package/build/lib/src/util.js
CHANGED
|
@@ -269,6 +269,13 @@ export function zip(left, right) {
|
|
|
269
269
|
throw new Error("Arrays of different length");
|
|
270
270
|
return left.map((_, i) => [left[i], right[i]]);
|
|
271
271
|
}
|
|
272
|
+
export function zipStrip(left, right) {
|
|
273
|
+
const result = [];
|
|
274
|
+
for (let i = 0; i < left.length && i < right.length; ++i) {
|
|
275
|
+
result.push([left[i], right[i]]);
|
|
276
|
+
}
|
|
277
|
+
return result;
|
|
278
|
+
}
|
|
272
279
|
export function identNameWithNamespace(node, language) {
|
|
273
280
|
let parent = node.parent;
|
|
274
281
|
while (parent && !ts.isModuleDeclaration(parent))
|
|
@@ -300,6 +307,9 @@ export function identName(node) {
|
|
|
300
307
|
return `void`;
|
|
301
308
|
if (node.kind == ts.SyntaxKind.UndefinedKeyword)
|
|
302
309
|
return `undefined`;
|
|
310
|
+
if (ts.isThisTypeNode(node)) {
|
|
311
|
+
return 'this';
|
|
312
|
+
}
|
|
303
313
|
if (ts.isVariableDeclaration(node)) {
|
|
304
314
|
return identString(node.name);
|
|
305
315
|
}
|
|
@@ -340,6 +350,9 @@ export function identName(node) {
|
|
|
340
350
|
if (ts.isComputedPropertyName(node)) {
|
|
341
351
|
return identString(node);
|
|
342
352
|
}
|
|
353
|
+
if (ts.isExportAssignment(node)) {
|
|
354
|
+
return node.expression.getText();
|
|
355
|
+
}
|
|
343
356
|
if (ts.isUnionTypeNode(node)) {
|
|
344
357
|
return `UnionType`;
|
|
345
358
|
}
|
|
@@ -469,6 +482,22 @@ export function camelCaseToUpperSnakeCase(input) {
|
|
|
469
482
|
.map(s => toUpperSnakeCase(s))
|
|
470
483
|
.join('_');
|
|
471
484
|
}
|
|
485
|
+
export function snakeToLowCamelNode(node) {
|
|
486
|
+
if (!node.fileName) {
|
|
487
|
+
throw new Error("Invalid Convert");
|
|
488
|
+
}
|
|
489
|
+
const classname = path.basename(node.fileName).replace(".idl", "").replace(".d.ts", "");
|
|
490
|
+
return classname
|
|
491
|
+
.split('_')
|
|
492
|
+
.filter(word => word !== '')
|
|
493
|
+
.map((word, index) => {
|
|
494
|
+
if (index === 0) {
|
|
495
|
+
return word.toLowerCase();
|
|
496
|
+
}
|
|
497
|
+
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
498
|
+
})
|
|
499
|
+
.join('');
|
|
500
|
+
}
|
|
472
501
|
export function renameDtsToPeer(fileName, language, withFileExtension = true) {
|
|
473
502
|
const renamed = "Ark"
|
|
474
503
|
.concat(snakeCaseToCamelCase(fileName))
|
|
@@ -536,9 +565,7 @@ export function className(node) {
|
|
|
536
565
|
export function nameEnumValues(enumTarget) {
|
|
537
566
|
const prefix = "LEGACY";
|
|
538
567
|
const nameToIndex = new Map();
|
|
539
|
-
enumTarget.
|
|
540
|
-
.map(it => identName(it.name))
|
|
541
|
-
.forEach((name, index) => {
|
|
568
|
+
enumTarget.forEach((name, index) => {
|
|
542
569
|
let upperCaseName;
|
|
543
570
|
if (isUpperCase(name)) {
|
|
544
571
|
upperCaseName = name;
|
|
@@ -654,4 +681,15 @@ export function rightmostIndexOf(array, predicate) {
|
|
|
654
681
|
});
|
|
655
682
|
return result;
|
|
656
683
|
}
|
|
684
|
+
// sort array using external key function or internal string property
|
|
685
|
+
export function sorted(array, key) {
|
|
686
|
+
const comparator = new Intl.Collator();
|
|
687
|
+
if (typeof key === "function") {
|
|
688
|
+
return array.map(it => { return { sortKey: key(it), value: it }; })
|
|
689
|
+
.sort((a, b) => comparator.compare(a.sortKey, b.sortKey))
|
|
690
|
+
.map(it => it.value);
|
|
691
|
+
}
|
|
692
|
+
return array.map(it => it)
|
|
693
|
+
.sort((a, b) => comparator.compare(a[key], b[key]));
|
|
694
|
+
}
|
|
657
695
|
//# sourceMappingURL=util.js.map
|
|
@@ -30,7 +30,6 @@ export declare class IDLDependencyCollector implements IDLConverter<idl.IDLNode[
|
|
|
30
30
|
visitPrimitiveType(): idl.IDLNode[];
|
|
31
31
|
visitNamespace(decl: idl.IDLNamespace): idl.IDLNode[];
|
|
32
32
|
visitInterface(decl: idl.IDLInterface): idl.IDLNode[];
|
|
33
|
-
protected visitSupertype(type: idl.IDLType | idl.IDLInterface): idl.IDLNode[];
|
|
34
33
|
visitEnum(): idl.IDLNode[];
|
|
35
34
|
visitTypedef(decl: idl.IDLTypedef): idl.IDLNode[];
|
|
36
35
|
visitCallback(decl: idl.IDLCallback): idl.IDLNode[];
|
|
@@ -40,4 +39,6 @@ export declare class IDLDependencyCollector implements IDLConverter<idl.IDLNode[
|
|
|
40
39
|
walk(node?: idl.IDLNode): idl.IDLNode[];
|
|
41
40
|
}
|
|
42
41
|
export declare function collectDependencies(resolver: ReferenceResolver, node: idl.IDLNode): idl.IDLNode[];
|
|
42
|
+
export declare function filterRedundantMethodsOverloads(methods: idl.IDLMethod[]): idl.IDLMethod[];
|
|
43
|
+
export declare function filterRedundantAttributesOverloads(properties: idl.IDLProperty[]): idl.IDLProperty[];
|
|
43
44
|
//# sourceMappingURL=visitor.d.ts.map
|
package/build/lib/src/visitor.js
CHANGED
|
@@ -90,7 +90,7 @@ export class IDLDependencyCollector {
|
|
|
90
90
|
return [
|
|
91
91
|
...decl.inheritance
|
|
92
92
|
.filter(it => it !== idl.IDLTopType)
|
|
93
|
-
.flatMap(it => this.
|
|
93
|
+
.flatMap(it => this.walk(it)),
|
|
94
94
|
...decl.properties
|
|
95
95
|
.filter(it => !it.isStatic)
|
|
96
96
|
.flatMap(it => this.walk(it.type)),
|
|
@@ -101,12 +101,6 @@ export class IDLDependencyCollector {
|
|
|
101
101
|
])
|
|
102
102
|
];
|
|
103
103
|
}
|
|
104
|
-
visitSupertype(type) {
|
|
105
|
-
if (idl.isInterface(type)) {
|
|
106
|
-
return this.walk(idl.createReferenceType(type));
|
|
107
|
-
}
|
|
108
|
-
return this.walk(type);
|
|
109
|
-
}
|
|
110
104
|
visitEnum() {
|
|
111
105
|
return [];
|
|
112
106
|
}
|
|
@@ -140,4 +134,112 @@ export class IDLDependencyCollector {
|
|
|
140
134
|
export function collectDependencies(resolver, node) {
|
|
141
135
|
return walkIDL(new IDLDependencyCollector(resolver), node);
|
|
142
136
|
}
|
|
137
|
+
function isFirstTypeSubsetOfSecond(first, second) {
|
|
138
|
+
if (idl.isOptionalType(second)) {
|
|
139
|
+
return isFirstTypeSubsetOfSecond(idl.maybeUnwrapOptionalType(first), idl.maybeUnwrapOptionalType(second));
|
|
140
|
+
}
|
|
141
|
+
if (idl.isUnionType(second)) {
|
|
142
|
+
const firstTypes = idl.isUnionType(first) ? first.types : [first];
|
|
143
|
+
const secondTypes = second.types;
|
|
144
|
+
return firstTypes.every(firstType => secondTypes.some(secondType => isFirstTypeSubsetOfSecond(firstType, secondType)));
|
|
145
|
+
}
|
|
146
|
+
return idl.printType(first) === idl.printType(second);
|
|
147
|
+
}
|
|
148
|
+
function isFirstParameterSubsetOfSecond(first, second) {
|
|
149
|
+
if (first === undefined)
|
|
150
|
+
return second.isOptional;
|
|
151
|
+
if (first.isOptional && !second.isOptional)
|
|
152
|
+
return false;
|
|
153
|
+
if (second.isOptional)
|
|
154
|
+
return isFirstTypeSubsetOfSecond(idl.maybeUnwrapOptionalType(first.type), idl.maybeUnwrapOptionalType(second.type));
|
|
155
|
+
return isFirstTypeSubsetOfSecond(first.type, second.type);
|
|
156
|
+
}
|
|
157
|
+
function isFirstMethodSubsetOfSecond(first, second) {
|
|
158
|
+
if (first.parameters.length > second.parameters.length)
|
|
159
|
+
return false;
|
|
160
|
+
if (first.isAsync !== second.isAsync)
|
|
161
|
+
return false;
|
|
162
|
+
if (first.isStatic !== second.isStatic)
|
|
163
|
+
return false;
|
|
164
|
+
if (second.parameters.some((secondParameter, idx) => !isFirstParameterSubsetOfSecond(first.parameters.at(idx), secondParameter)))
|
|
165
|
+
return false;
|
|
166
|
+
if (!isFirstTypeSubsetOfSecond(first.returnType, second.returnType))
|
|
167
|
+
return false;
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
function isFirstPropertySubsetOfSecond(first, second) {
|
|
171
|
+
if (idl.getExtAttribute(first, idl.IDLExtendedAttributes.Accessor) !==
|
|
172
|
+
idl.getExtAttribute(second, idl.IDLExtendedAttributes.Accessor))
|
|
173
|
+
return false;
|
|
174
|
+
if (first.isStatic !== second.isStatic)
|
|
175
|
+
return false;
|
|
176
|
+
if (first.isOptional && !second.isOptional)
|
|
177
|
+
return false;
|
|
178
|
+
if (second.isOptional)
|
|
179
|
+
return isFirstTypeSubsetOfSecond(idl.maybeUnwrapOptionalType(first.type), idl.maybeUnwrapOptionalType(second.type));
|
|
180
|
+
return isFirstTypeSubsetOfSecond(first.type, second.type);
|
|
181
|
+
}
|
|
182
|
+
function filterRedundantOverloadsSameNamed(entries) {
|
|
183
|
+
const entryToSupersets = new Map();
|
|
184
|
+
for (const entry of entries) {
|
|
185
|
+
entryToSupersets.set(entry, []);
|
|
186
|
+
for (const other of entries) {
|
|
187
|
+
if (entry === other)
|
|
188
|
+
continue;
|
|
189
|
+
if (idl.isMethod(entry) && idl.isMethod(other)) {
|
|
190
|
+
if (isFirstMethodSubsetOfSecond(entry, other))
|
|
191
|
+
entryToSupersets.get(entry).push(other);
|
|
192
|
+
}
|
|
193
|
+
else if (idl.isProperty(entry) && idl.isProperty(other)) {
|
|
194
|
+
if (isFirstPropertySubsetOfSecond(entry, other))
|
|
195
|
+
entryToSupersets.get(entry).push(other);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
throw new Error("Not implemented");
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const visited = [];
|
|
203
|
+
const roots = [];
|
|
204
|
+
const visit = (method) => {
|
|
205
|
+
if (visited.includes(method))
|
|
206
|
+
return;
|
|
207
|
+
visited.push(method);
|
|
208
|
+
for (const superset of entryToSupersets.get(method)) {
|
|
209
|
+
visit(superset);
|
|
210
|
+
}
|
|
211
|
+
if (!entryToSupersets.get(method).some(it => roots.includes(it)))
|
|
212
|
+
roots.push(method);
|
|
213
|
+
};
|
|
214
|
+
entries.forEach(visit);
|
|
215
|
+
return roots;
|
|
216
|
+
}
|
|
217
|
+
export function filterRedundantMethodsOverloads(methods) {
|
|
218
|
+
const sameNamedGroups = new Map();
|
|
219
|
+
for (const method of methods) {
|
|
220
|
+
if (!sameNamedGroups.has(method.name))
|
|
221
|
+
sameNamedGroups.set(method.name, []);
|
|
222
|
+
sameNamedGroups.get(method.name).push(method);
|
|
223
|
+
}
|
|
224
|
+
const filtered = [];
|
|
225
|
+
for (const sameNamed of sameNamedGroups.values()) {
|
|
226
|
+
filtered.push(...filterRedundantOverloadsSameNamed(sameNamed));
|
|
227
|
+
}
|
|
228
|
+
// stabilizing order
|
|
229
|
+
return methods.filter(it => filtered.includes(it));
|
|
230
|
+
}
|
|
231
|
+
export function filterRedundantAttributesOverloads(properties) {
|
|
232
|
+
const sameNamedGroups = new Map();
|
|
233
|
+
for (const property of properties) {
|
|
234
|
+
if (!sameNamedGroups.has(property.name))
|
|
235
|
+
sameNamedGroups.set(property.name, []);
|
|
236
|
+
sameNamedGroups.get(property.name).push(property);
|
|
237
|
+
}
|
|
238
|
+
const filtered = [];
|
|
239
|
+
for (const sameNamed of sameNamedGroups.values()) {
|
|
240
|
+
filtered.push(...filterRedundantOverloadsSameNamed(sameNamed));
|
|
241
|
+
}
|
|
242
|
+
// stabilizing order
|
|
243
|
+
return properties.filter(it => filtered.includes(it));
|
|
244
|
+
}
|
|
143
245
|
//# sourceMappingURL=visitor.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idlizer/core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"types": "build/lib/src/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"keywords": [],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@koalaui/interop": "1.
|
|
37
|
+
"@koalaui/interop": "1.7.1",
|
|
38
38
|
"typescript": "4.9.5",
|
|
39
39
|
"@types/node": "^18.0.0"
|
|
40
40
|
},
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014 Robin Berjon
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|