@idlizer/core 2.1.5 → 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 +0 -1
- package/build/lib/src/LanguageWriters/ArgConvertors.js +8 -3
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +9 -4
- package/build/lib/src/LanguageWriters/LanguageWriter.js +4 -4
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +1 -0
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +16 -6
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +1 -0
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +55 -54
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +1 -1
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +2 -2
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +1 -0
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +4 -2
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +44 -9
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +7 -2
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +24 -10
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +3 -0
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +32 -7
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +6 -3
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +11 -9
- package/build/lib/src/config.d.ts +607 -44
- package/build/lib/src/config.js +18 -0
- package/build/lib/src/configDescriber.d.ts +1 -1
- package/build/lib/src/configDescriber.js +2 -2
- package/build/lib/src/from-idl/DtsPrinter.js +3 -2
- package/build/lib/src/from-idl/IDLLinter.js +1 -1
- package/build/lib/src/from-idl/deserialize.d.ts +7 -1
- package/build/lib/src/from-idl/deserialize.js +79 -33
- package/build/lib/src/idl.d.ts +4 -2
- package/build/lib/src/idl.js +64 -33
- package/build/lib/src/peer-generation/Materialized.js +1 -1
- package/build/lib/src/peer-generation/PeerLibrary.js +4 -4
- package/build/lib/src/peer-generation/idl/common.d.ts +1 -0
- package/build/lib/src/peer-generation/idl/common.js +8 -2
- package/build/lib/src/peer-generation/isMaterialized.js +4 -0
- package/build/lib/src/peer-generation/unions.js +1 -1
- package/build/lib/src/util.d.ts +2 -1
- package/build/lib/src/util.js +8 -3
- package/build/lib/src/visitor.d.ts +2 -0
- package/build/lib/src/visitor.js +108 -0
- package/package.json +2 -2
- package/webidl2.js/dist/webidl2.js +62 -16
package/build/lib/src/idl.js
CHANGED
|
@@ -64,6 +64,7 @@ export var IDLExtendedAttributes;
|
|
|
64
64
|
IDLExtendedAttributes["DtsName"] = "DtsName";
|
|
65
65
|
IDLExtendedAttributes["DtsTag"] = "DtsTag";
|
|
66
66
|
IDLExtendedAttributes["Entity"] = "Entity";
|
|
67
|
+
IDLExtendedAttributes["Extends"] = "Extends";
|
|
67
68
|
IDLExtendedAttributes["Import"] = "Import";
|
|
68
69
|
IDLExtendedAttributes["DefaultExport"] = "DefaultExport";
|
|
69
70
|
IDLExtendedAttributes["IndexSignature"] = "IndexSignature";
|
|
@@ -386,6 +387,9 @@ export function createOptionalType(element, nodeInitializer) {
|
|
|
386
387
|
if (isOptionalType(element) && !nodeInitializer) {
|
|
387
388
|
return element;
|
|
388
389
|
}
|
|
390
|
+
if (isOptionalType(element)) {
|
|
391
|
+
return Object.assign(Object.assign({ kind: IDLKind.OptionalType, type: element.type }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol });
|
|
392
|
+
}
|
|
389
393
|
return Object.assign(Object.assign({ kind: IDLKind.OptionalType, type: element }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlTypeBrand: innerIdlSymbol });
|
|
390
394
|
}
|
|
391
395
|
/**
|
|
@@ -418,7 +422,7 @@ export const IDLStringType = createPrimitiveType('String');
|
|
|
418
422
|
export const IDLAnyType = createPrimitiveType('any');
|
|
419
423
|
export const IDLUndefinedType = createPrimitiveType('undefined');
|
|
420
424
|
export const IDLUnknownType = createPrimitiveType('unknown');
|
|
421
|
-
export const IDLObjectType =
|
|
425
|
+
export const IDLObjectType = createPrimitiveType('Object');
|
|
422
426
|
export const IDLThisType = createPrimitiveType('this');
|
|
423
427
|
export const IDLDate = createPrimitiveType('date');
|
|
424
428
|
export const IDLBufferType = createPrimitiveType('buffer');
|
|
@@ -568,7 +572,7 @@ export function createFile(entries, fileName, packageClause = [], nodeInitialize
|
|
|
568
572
|
return Object.assign(Object.assign({ kind: IDLKind.File, packageClause, entries: entries, fileName }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol });
|
|
569
573
|
}
|
|
570
574
|
export function createImport(clause, name, nodeInitializer) {
|
|
571
|
-
return Object.assign(Object.assign({ kind: IDLKind.Import, name: name
|
|
575
|
+
return Object.assign(Object.assign({ kind: IDLKind.Import, name: name !== null && name !== void 0 ? name : "", clause }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
572
576
|
}
|
|
573
577
|
export function createEnum(name, elements, nodeInitializer) {
|
|
574
578
|
return Object.assign(Object.assign({ kind: IDLKind.Enum, name: name, elements: elements }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
@@ -622,13 +626,6 @@ export function createConstructor(parameters, returnType, nodeInitializer = {})
|
|
|
622
626
|
returnType }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
623
627
|
}
|
|
624
628
|
export function createCallback(name, parameters, returnType, nodeInitializer = {}, typeParameters = []) {
|
|
625
|
-
if (returnType === IDLThisType || isReferenceType(returnType) && returnType.name === "this")
|
|
626
|
-
returnType = IDLAnyType;
|
|
627
|
-
parameters = parameters.map(it => {
|
|
628
|
-
if (it.type && isNamedNode(it.type) && (it.type.name === "T" || it.type.name === "this"))
|
|
629
|
-
return createParameter(it.name, IDLAnyType, it.isOptional, it.isVariadic, { fileName: it.fileName });
|
|
630
|
-
return it;
|
|
631
|
-
});
|
|
632
629
|
return Object.assign(Object.assign({ kind: IDLKind.Callback, name, parameters, returnType, typeParameters }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
633
630
|
}
|
|
634
631
|
export function createTypeParameterReference(name, nodeInitializer) {
|
|
@@ -643,7 +640,7 @@ export function createConstant(name, type, value, nodeInitializer = {}) {
|
|
|
643
640
|
value }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
644
641
|
}
|
|
645
642
|
export function clone(node) {
|
|
646
|
-
var _a, _b, _c, _d;
|
|
643
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
|
|
647
644
|
const make = (node) => node;
|
|
648
645
|
const get = (node) => node;
|
|
649
646
|
switch (node.kind) {
|
|
@@ -651,7 +648,7 @@ export function clone(node) {
|
|
|
651
648
|
const entry = get(node);
|
|
652
649
|
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
650
|
documentation: node.documentation,
|
|
654
|
-
extendedAttributes: node.extendedAttributes,
|
|
651
|
+
extendedAttributes: (_d = node.extendedAttributes) === null || _d === void 0 ? void 0 : _d.slice(),
|
|
655
652
|
fileName: node.fileName
|
|
656
653
|
}));
|
|
657
654
|
}
|
|
@@ -659,7 +656,7 @@ export function clone(node) {
|
|
|
659
656
|
const entry = get(node);
|
|
660
657
|
return make(createImport(entry.clause, entry.name, {
|
|
661
658
|
documentation: entry.documentation,
|
|
662
|
-
extendedAttributes: entry.extendedAttributes,
|
|
659
|
+
extendedAttributes: (_e = entry.extendedAttributes) === null || _e === void 0 ? void 0 : _e.slice(),
|
|
663
660
|
fileName: entry.fileName
|
|
664
661
|
}));
|
|
665
662
|
}
|
|
@@ -667,7 +664,7 @@ export function clone(node) {
|
|
|
667
664
|
const entry = get(node);
|
|
668
665
|
return make(createCallback(entry.name, entry.parameters.map(clone), clone(entry.returnType), {
|
|
669
666
|
documentation: entry.documentation,
|
|
670
|
-
extendedAttributes: entry.extendedAttributes,
|
|
667
|
+
extendedAttributes: (_f = entry.extendedAttributes) === null || _f === void 0 ? void 0 : _f.slice(),
|
|
671
668
|
fileName: entry.fileName
|
|
672
669
|
}, entry.typeParameters));
|
|
673
670
|
}
|
|
@@ -675,7 +672,7 @@ export function clone(node) {
|
|
|
675
672
|
const entry = get(node);
|
|
676
673
|
return make(createConstant(entry.name, clone(entry.type), entry.value, {
|
|
677
674
|
documentation: entry.documentation,
|
|
678
|
-
extendedAttributes: entry.extendedAttributes,
|
|
675
|
+
extendedAttributes: (_g = entry.extendedAttributes) === null || _g === void 0 ? void 0 : _g.slice(),
|
|
679
676
|
fileName: entry.fileName
|
|
680
677
|
}));
|
|
681
678
|
}
|
|
@@ -683,7 +680,7 @@ export function clone(node) {
|
|
|
683
680
|
const entry = get(node);
|
|
684
681
|
return make(createProperty(entry.name, clone(entry.type), entry.isReadonly, entry.isStatic, entry.isOptional, {
|
|
685
682
|
documentation: entry.documentation,
|
|
686
|
-
extendedAttributes: entry.extendedAttributes,
|
|
683
|
+
extendedAttributes: (_h = entry.extendedAttributes) === null || _h === void 0 ? void 0 : _h.slice(),
|
|
687
684
|
fileName: entry.fileName
|
|
688
685
|
}));
|
|
689
686
|
}
|
|
@@ -691,7 +688,7 @@ export function clone(node) {
|
|
|
691
688
|
const entry = get(node);
|
|
692
689
|
return make(createParameter(entry.name, clone(entry.type), entry.isOptional, entry.isVariadic, {
|
|
693
690
|
documentation: entry.documentation,
|
|
694
|
-
extendedAttributes: entry.extendedAttributes,
|
|
691
|
+
extendedAttributes: (_j = entry.extendedAttributes) === null || _j === void 0 ? void 0 : _j.slice(),
|
|
695
692
|
fileName: entry.fileName
|
|
696
693
|
}));
|
|
697
694
|
}
|
|
@@ -704,7 +701,7 @@ export function clone(node) {
|
|
|
704
701
|
isStatic: entry.isStatic
|
|
705
702
|
}, {
|
|
706
703
|
documentation: entry.documentation,
|
|
707
|
-
extendedAttributes: entry.extendedAttributes,
|
|
704
|
+
extendedAttributes: (_k = entry.extendedAttributes) === null || _k === void 0 ? void 0 : _k.slice(),
|
|
708
705
|
fileName: entry.fileName
|
|
709
706
|
}, entry.typeParameters));
|
|
710
707
|
}
|
|
@@ -715,7 +712,7 @@ export function clone(node) {
|
|
|
715
712
|
isStatic: entry.isStatic
|
|
716
713
|
}, {
|
|
717
714
|
documentation: entry.documentation,
|
|
718
|
-
extendedAttributes: entry.extendedAttributes,
|
|
715
|
+
extendedAttributes: (_l = entry.extendedAttributes) === null || _l === void 0 ? void 0 : _l.slice(),
|
|
719
716
|
fileName: entry.documentation
|
|
720
717
|
}, entry.typeParameters));
|
|
721
718
|
}
|
|
@@ -723,7 +720,7 @@ export function clone(node) {
|
|
|
723
720
|
const entry = get(node);
|
|
724
721
|
return make(createConstructor(entry.parameters.map(clone), entry.returnType ? clone(entry.returnType) : undefined, {
|
|
725
722
|
documentation: entry.documentation,
|
|
726
|
-
extendedAttributes: entry.extendedAttributes,
|
|
723
|
+
extendedAttributes: (_m = entry.extendedAttributes) === null || _m === void 0 ? void 0 : _m.slice(),
|
|
727
724
|
fileName: entry.fileName
|
|
728
725
|
}));
|
|
729
726
|
}
|
|
@@ -731,7 +728,7 @@ export function clone(node) {
|
|
|
731
728
|
const entry = get(node);
|
|
732
729
|
const cloned = createEnum(entry.name, entry.elements.map(clone), {
|
|
733
730
|
documentation: entry.documentation,
|
|
734
|
-
extendedAttributes: entry.extendedAttributes,
|
|
731
|
+
extendedAttributes: (_o = entry.extendedAttributes) === null || _o === void 0 ? void 0 : _o.slice(),
|
|
735
732
|
fileName: entry.fileName
|
|
736
733
|
});
|
|
737
734
|
cloned.elements.forEach(it => {
|
|
@@ -743,7 +740,7 @@ export function clone(node) {
|
|
|
743
740
|
const entry = get(node);
|
|
744
741
|
return make(createEnumMember(entry.name, entry.parent, clone(entry.type), entry.initializer, {
|
|
745
742
|
documentation: entry.documentation,
|
|
746
|
-
extendedAttributes: entry.extendedAttributes,
|
|
743
|
+
extendedAttributes: (_p = entry.extendedAttributes) === null || _p === void 0 ? void 0 : _p.slice(),
|
|
747
744
|
fileName: entry.fileName
|
|
748
745
|
}));
|
|
749
746
|
}
|
|
@@ -751,7 +748,7 @@ export function clone(node) {
|
|
|
751
748
|
const entry = get(node);
|
|
752
749
|
return make(createTypedef(entry.name, clone(entry.type), entry.typeParameters, {
|
|
753
750
|
documentation: entry.documentation,
|
|
754
|
-
extendedAttributes: entry.extendedAttributes,
|
|
751
|
+
extendedAttributes: (_q = entry.extendedAttributes) === null || _q === void 0 ? void 0 : _q.slice(),
|
|
755
752
|
fileName: entry.fileName
|
|
756
753
|
}));
|
|
757
754
|
}
|
|
@@ -762,7 +759,7 @@ export function clone(node) {
|
|
|
762
759
|
const type = get(node);
|
|
763
760
|
return make(createContainerType(type.containerKind, type.elementType.map(clone), {
|
|
764
761
|
documentation: type.documentation,
|
|
765
|
-
extendedAttributes: type.extendedAttributes,
|
|
762
|
+
extendedAttributes: (_r = type.extendedAttributes) === null || _r === void 0 ? void 0 : _r.slice(),
|
|
766
763
|
fileName: type.fileName
|
|
767
764
|
}));
|
|
768
765
|
}
|
|
@@ -770,15 +767,15 @@ export function clone(node) {
|
|
|
770
767
|
const type = get(node);
|
|
771
768
|
return make(createUnspecifiedGenericType(type.name, type.typeArguments.map(clone), {
|
|
772
769
|
documentation: type.documentation,
|
|
773
|
-
extendedAttributes: type.extendedAttributes,
|
|
770
|
+
extendedAttributes: (_s = type.extendedAttributes) === null || _s === void 0 ? void 0 : _s.slice(),
|
|
774
771
|
fileName: type.fileName
|
|
775
772
|
}));
|
|
776
773
|
}
|
|
777
774
|
case IDLKind.ReferenceType: {
|
|
778
775
|
const type = get(node);
|
|
779
|
-
return make(createReferenceType(type.name, (
|
|
776
|
+
return make(createReferenceType(type.name, (_t = type.typeArguments) === null || _t === void 0 ? void 0 : _t.map(clone), {
|
|
780
777
|
documentation: type.documentation,
|
|
781
|
-
extendedAttributes: type.extendedAttributes,
|
|
778
|
+
extendedAttributes: (_u = type.extendedAttributes) === null || _u === void 0 ? void 0 : _u.slice(),
|
|
782
779
|
fileName: type.fileName
|
|
783
780
|
}));
|
|
784
781
|
}
|
|
@@ -786,7 +783,7 @@ export function clone(node) {
|
|
|
786
783
|
const type = get(node);
|
|
787
784
|
return make(createUnionType(type.types.map(clone), type.name, {
|
|
788
785
|
documentation: type.documentation,
|
|
789
|
-
extendedAttributes: type.extendedAttributes,
|
|
786
|
+
extendedAttributes: (_v = type.extendedAttributes) === null || _v === void 0 ? void 0 : _v.slice(),
|
|
790
787
|
fileName: type.fileName
|
|
791
788
|
}));
|
|
792
789
|
}
|
|
@@ -794,7 +791,7 @@ export function clone(node) {
|
|
|
794
791
|
const type = get(node);
|
|
795
792
|
return make(createTypeParameterReference(type.name, {
|
|
796
793
|
documentation: type.documentation,
|
|
797
|
-
extendedAttributes: type.extendedAttributes,
|
|
794
|
+
extendedAttributes: (_w = type.extendedAttributes) === null || _w === void 0 ? void 0 : _w.slice(),
|
|
798
795
|
fileName: type.fileName
|
|
799
796
|
}));
|
|
800
797
|
}
|
|
@@ -802,7 +799,7 @@ export function clone(node) {
|
|
|
802
799
|
const type = get(node);
|
|
803
800
|
return make(createOptionalType(clone(type.type), {
|
|
804
801
|
documentation: type.documentation,
|
|
805
|
-
extendedAttributes: type.extendedAttributes,
|
|
802
|
+
extendedAttributes: (_x = type.extendedAttributes) === null || _x === void 0 ? void 0 : _x.slice(),
|
|
806
803
|
fileName: type.fileName
|
|
807
804
|
}));
|
|
808
805
|
}
|
|
@@ -810,7 +807,7 @@ export function clone(node) {
|
|
|
810
807
|
const entry = get(node);
|
|
811
808
|
return make(createVersion(entry.value, {
|
|
812
809
|
documentation: entry.documentation,
|
|
813
|
-
extendedAttributes: entry.extendedAttributes,
|
|
810
|
+
extendedAttributes: (_y = entry.extendedAttributes) === null || _y === void 0 ? void 0 : _y.slice(),
|
|
814
811
|
fileName: entry.fileName
|
|
815
812
|
}));
|
|
816
813
|
}
|
|
@@ -818,7 +815,7 @@ export function clone(node) {
|
|
|
818
815
|
const ns = get(node);
|
|
819
816
|
return make(createNamespace(ns.name, ns.members.map(clone), {
|
|
820
817
|
documentation: ns.documentation,
|
|
821
|
-
extendedAttributes: ns.extendedAttributes,
|
|
818
|
+
extendedAttributes: (_z = ns.extendedAttributes) === null || _z === void 0 ? void 0 : _z.slice(),
|
|
822
819
|
fileName: ns.fileName
|
|
823
820
|
}));
|
|
824
821
|
}
|
|
@@ -826,12 +823,21 @@ export function clone(node) {
|
|
|
826
823
|
const file = get(node);
|
|
827
824
|
return make(createFile(file.entries.map(clone), file.fileName, file.packageClause, {
|
|
828
825
|
documentation: file.documentation,
|
|
829
|
-
extendedAttributes: file.extendedAttributes,
|
|
826
|
+
extendedAttributes: (_0 = file.extendedAttributes) === null || _0 === void 0 ? void 0 : _0.slice(),
|
|
830
827
|
fileName: file.fileName
|
|
831
828
|
}));
|
|
832
829
|
}
|
|
833
830
|
}
|
|
834
831
|
}
|
|
832
|
+
export function hasTypeParameters(entry) {
|
|
833
|
+
let foundTypeParameter = false;
|
|
834
|
+
forEachChild(entry, n => {
|
|
835
|
+
if (isTypeParameterType(n)) {
|
|
836
|
+
foundTypeParameter = true;
|
|
837
|
+
}
|
|
838
|
+
});
|
|
839
|
+
return foundTypeParameter;
|
|
840
|
+
}
|
|
835
841
|
export function escapeIDLKeyword(name) {
|
|
836
842
|
return name + (IDLKeywords.has(name) ? "_" : "");
|
|
837
843
|
}
|
|
@@ -1024,10 +1030,35 @@ export function printScoped(idl) {
|
|
|
1024
1030
|
return printInterface(idl);
|
|
1025
1031
|
throw new Error(`Unexpected scoped: ${idl.kind} ${idl.name}`);
|
|
1026
1032
|
}
|
|
1033
|
+
function printInterfaceInherit(idl) {
|
|
1034
|
+
var _a;
|
|
1035
|
+
if (idl.inheritance.length === 0) {
|
|
1036
|
+
return "";
|
|
1037
|
+
}
|
|
1038
|
+
const inheritance = [...idl.inheritance];
|
|
1039
|
+
const types = [];
|
|
1040
|
+
if (idl.subkind === IDLInterfaceSubkind.Class) {
|
|
1041
|
+
if (inheritance[0] !== IDLTopType) {
|
|
1042
|
+
const ref = clone(inheritance[0]);
|
|
1043
|
+
(_a = ref.extendedAttributes) !== null && _a !== void 0 ? _a : (ref.extendedAttributes = []);
|
|
1044
|
+
if (!hasExtAttribute(ref, IDLExtendedAttributes.Extends)) {
|
|
1045
|
+
ref.extendedAttributes = ref.extendedAttributes.concat([
|
|
1046
|
+
{ name: IDLExtendedAttributes.Extends }
|
|
1047
|
+
]);
|
|
1048
|
+
}
|
|
1049
|
+
types.push(`${printType(ref)}`);
|
|
1050
|
+
inheritance.shift();
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
inheritance.forEach(type => {
|
|
1054
|
+
types.push(printType(type));
|
|
1055
|
+
});
|
|
1056
|
+
return ": " + types.join(', ');
|
|
1057
|
+
}
|
|
1027
1058
|
export function printInterface(idl) {
|
|
1028
1059
|
return [
|
|
1029
1060
|
...printExtendedAttributes(idl, 0),
|
|
1030
|
-
`interface ${idl.name}${
|
|
1061
|
+
`interface ${idl.name}${printInterfaceInherit(idl)} {`,
|
|
1031
1062
|
// TODO: type system hack!
|
|
1032
1063
|
]
|
|
1033
1064
|
.concat(printedIndentInc)
|
|
@@ -135,7 +135,7 @@ export function createDestroyPeerMethod(clazz) {
|
|
|
135
135
|
if (clazz.isGlobalScope() || clazz.isStaticMaterialized) {
|
|
136
136
|
return undefined;
|
|
137
137
|
}
|
|
138
|
-
return new MaterializedMethod(clazz.
|
|
138
|
+
return new MaterializedMethod(idl.getQualifiedName(clazz.decl, "namespace.name").split('.').join('_'), clazz.getImplementationName(), [], idl.IDLVoidType, false, new Method('destroyPeer', new NamedMethodSignature(idl.IDLVoidType, [idl.createReferenceType(clazz.decl)], ['peer'])));
|
|
139
139
|
}
|
|
140
140
|
export function getInternalClassName(name) {
|
|
141
141
|
return `${name}Internal`;
|
|
@@ -182,8 +182,7 @@ export class PeerLibrary {
|
|
|
182
182
|
}
|
|
183
183
|
if (result && (idl.isImport(result) || idl.isNamespace(result)))
|
|
184
184
|
result = undefined;
|
|
185
|
-
|
|
186
|
-
(_b = this.referenceCache) === null || _b === void 0 ? void 0 : _b.set(type, result);
|
|
185
|
+
(_b = this.referenceCache) === null || _b === void 0 ? void 0 : _b.set(type, result);
|
|
187
186
|
return result;
|
|
188
187
|
}
|
|
189
188
|
disableFallback() {
|
|
@@ -293,6 +292,7 @@ export class PeerLibrary {
|
|
|
293
292
|
case idl.IDLUndefinedType: return new UndefinedConvertor(param);
|
|
294
293
|
case idl.IDLVoidType: return new VoidConvertor(param);
|
|
295
294
|
case idl.IDLUnknownType:
|
|
295
|
+
case idl.IDLObjectType:
|
|
296
296
|
case idl.IDLAnyType: return new ObjectConvertor(param, idl.IDLAnyType);
|
|
297
297
|
case idl.IDLDate: return new DateConvertor(param);
|
|
298
298
|
case idl.IDLFunctionType: return new FunctionConvertor(this, param);
|
|
@@ -417,12 +417,12 @@ export class PeerLibrary {
|
|
|
417
417
|
case idl.IDLVoidType: return idl.IDLVoidType;
|
|
418
418
|
case idl.IDLUndefinedType: return idl.IDLUndefinedType;
|
|
419
419
|
case idl.IDLUnknownType: return ArkCustomObject;
|
|
420
|
-
case idl.IDLObjectType: return ArkCustomObject
|
|
420
|
+
// case idl.IDLObjectType: return ArkCustomObject
|
|
421
421
|
}
|
|
422
422
|
const typeName = idl.isNamedNode(type) ? type.name : undefined;
|
|
423
423
|
switch (typeName) {
|
|
424
424
|
case "object":
|
|
425
|
-
case "Object": return
|
|
425
|
+
case "Object": return idl.IDLObjectType;
|
|
426
426
|
}
|
|
427
427
|
if (idl.isReferenceType(type)) {
|
|
428
428
|
// TODO: remove all this!
|
|
@@ -6,6 +6,7 @@ export declare function collapseTypes(types: idl.IDLType[], name?: string): idl.
|
|
|
6
6
|
export declare function generifiedTypeName(refType: idl.IDLReferenceType | undefined, refName?: string): string | undefined;
|
|
7
7
|
export declare function sanitizeGenerics(genericDeclarationString: string): string;
|
|
8
8
|
export declare function generateSyntheticUnionName(types: idl.IDLType[]): string;
|
|
9
|
+
export declare function generateSyntheticFunctionParameterName(parameter: idl.IDLParameter): string;
|
|
9
10
|
export declare function generateSyntheticFunctionName(parameters: idl.IDLParameter[], returnType: idl.IDLType, isAsync?: boolean): string;
|
|
10
11
|
export declare function isImportAttr(decl: idl.IDLNode): boolean;
|
|
11
12
|
//# sourceMappingURL=common.d.ts.map
|
|
@@ -28,7 +28,7 @@ export function generateSyntheticIdlNodeName(type) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
if (idl.isNamedNode(type))
|
|
31
|
-
return type.name;
|
|
31
|
+
return type.name.split('.').map(capitalize).join('_');
|
|
32
32
|
if (idl.isOptionalType(type))
|
|
33
33
|
return `Opt_${generateSyntheticIdlNodeName(type.type)}`;
|
|
34
34
|
throw `Can not compute type name of ${idl.IDLKind[type.kind]}`;
|
|
@@ -75,9 +75,15 @@ export function sanitizeGenerics(genericDeclarationString) {
|
|
|
75
75
|
export function generateSyntheticUnionName(types) {
|
|
76
76
|
return `Union_${types.map(it => generateSyntheticIdlNodeName(it)).join("_").replaceAll(".", "_")}`;
|
|
77
77
|
}
|
|
78
|
+
export function generateSyntheticFunctionParameterName(parameter) {
|
|
79
|
+
if (parameter.isOptional) {
|
|
80
|
+
return generateSyntheticIdlNodeName(idl.createOptionalType(parameter.type));
|
|
81
|
+
}
|
|
82
|
+
return generateSyntheticIdlNodeName(parameter.type);
|
|
83
|
+
}
|
|
78
84
|
export function generateSyntheticFunctionName(parameters, returnType, isAsync = false) {
|
|
79
85
|
let prefix = isAsync ? "AsyncCallback" : "Callback";
|
|
80
|
-
const names = parameters.map(
|
|
86
|
+
const names = parameters.map(generateSyntheticFunctionParameterName).concat(generateSyntheticIdlNodeName(returnType));
|
|
81
87
|
return `${prefix}_${names.join("_").replaceAll(".", "_")}`;
|
|
82
88
|
}
|
|
83
89
|
export function isImportAttr(decl) {
|
|
@@ -27,6 +27,10 @@ export function isMaterialized(declaration, resolver) {
|
|
|
27
27
|
if (generatorConfiguration().forceMaterialized.includes(declaration.name)) {
|
|
28
28
|
return true;
|
|
29
29
|
}
|
|
30
|
+
// TODO: rework this
|
|
31
|
+
if (["BaseSpan"].includes(declaration.name)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
30
34
|
for (const ignore of ["Attribute", "Method", "Interface"]) {
|
|
31
35
|
if (declaration.name.endsWith(ignore)) {
|
|
32
36
|
return false;
|
|
@@ -110,7 +110,7 @@ export class UnionRuntimeTypeChecker {
|
|
|
110
110
|
const discriminator = discr ? discr.asString() : "<undefined>";
|
|
111
111
|
report += ` ${num}| ${typename}| ${properties}| ${resolved}| ${discriminator}\n`;
|
|
112
112
|
});
|
|
113
|
-
throw new Error(report)
|
|
113
|
+
// throw new Error(report)
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
}
|
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;
|
|
@@ -66,7 +67,7 @@ export declare function className(node: ts.ClassDeclaration | ts.InterfaceDeclar
|
|
|
66
67
|
* Add a prefix to an enum value which camel case name coincidence
|
|
67
68
|
* with the the same upper case name for an another enum value
|
|
68
69
|
*/
|
|
69
|
-
export declare function nameEnumValues(enumTarget:
|
|
70
|
+
export declare function nameEnumValues(enumTarget: string[]): string[];
|
|
70
71
|
export declare function groupBy<K, V>(values: V[], selector: (value: V) => K): Map<K, V[]>;
|
|
71
72
|
export declare function groupByIndexed<K, V>(values: V[], selector: (value: V) => K): Map<K, [V, number][]>;
|
|
72
73
|
export declare function removeExt(filename: string): string;
|
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))
|
|
@@ -558,9 +565,7 @@ export function className(node) {
|
|
|
558
565
|
export function nameEnumValues(enumTarget) {
|
|
559
566
|
const prefix = "LEGACY";
|
|
560
567
|
const nameToIndex = new Map();
|
|
561
|
-
enumTarget.
|
|
562
|
-
.map(it => identName(it.name))
|
|
563
|
-
.forEach((name, index) => {
|
|
568
|
+
enumTarget.forEach((name, index) => {
|
|
564
569
|
let upperCaseName;
|
|
565
570
|
if (isUpperCase(name)) {
|
|
566
571
|
upperCaseName = name;
|
|
@@ -39,4 +39,6 @@ export declare class IDLDependencyCollector implements IDLConverter<idl.IDLNode[
|
|
|
39
39
|
walk(node?: idl.IDLNode): idl.IDLNode[];
|
|
40
40
|
}
|
|
41
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[];
|
|
42
44
|
//# sourceMappingURL=visitor.d.ts.map
|
package/build/lib/src/visitor.js
CHANGED
|
@@ -134,4 +134,112 @@ export class IDLDependencyCollector {
|
|
|
134
134
|
export function collectDependencies(resolver, node) {
|
|
135
135
|
return walkIDL(new IDLDependencyCollector(resolver), node);
|
|
136
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
|
+
}
|
|
137
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
|
},
|