@idlizer/core 2.1.5 → 2.1.9-arktscgen-4
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/IndentedPrinter.js +2 -0
- package/build/lib/src/Language.d.ts +1 -0
- package/build/lib/src/Language.js +3 -0
- package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +18 -4
- package/build/lib/src/LanguageWriters/ArgConvertors.js +162 -26
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +38 -8
- package/build/lib/src/LanguageWriters/LanguageWriter.js +46 -4
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +1 -0
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +37 -14
- 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/KotlinConvertor.d.ts +24 -0
- package/build/lib/src/LanguageWriters/convertors/KotlinConvertor.js +69 -0
- package/build/lib/src/LanguageWriters/convertors/KotlinConvertors.d.ts +25 -0
- package/build/lib/src/LanguageWriters/convertors/KotlinConvertors.js +128 -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/index.js +4 -0
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +12 -7
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +43 -27
- package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.d.ts +1 -1
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +11 -2
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +43 -10
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +5 -2
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +45 -11
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +2 -2
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +3 -3
- package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.d.ts +149 -0
- package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.js +495 -0
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +8 -5
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +17 -13
- package/build/lib/src/LibraryInterface.d.ts +2 -0
- package/build/lib/src/config.d.ts +673 -44
- package/build/lib/src/config.js +20 -0
- package/build/lib/src/configDescriber.d.ts +2 -2
- package/build/lib/src/configDescriber.js +3 -3
- package/build/lib/src/from-idl/DtsPrinter.js +12 -8
- package/build/lib/src/from-idl/IDLLinter.d.ts +0 -1
- package/build/lib/src/from-idl/IDLLinter.js +1 -7
- package/build/lib/src/from-idl/deserialize.d.ts +7 -1
- package/build/lib/src/from-idl/deserialize.js +72 -40
- package/build/lib/src/idl.d.ts +8 -15
- package/build/lib/src/idl.js +69 -72
- package/build/lib/src/idlize.js +2 -0
- package/build/lib/src/index.d.ts +2 -0
- package/build/lib/src/index.js +2 -0
- package/build/lib/src/peer-generation/LayoutManager.d.ts +4 -1
- package/build/lib/src/peer-generation/LayoutManager.js +5 -1
- package/build/lib/src/peer-generation/Materialized.d.ts +7 -3
- package/build/lib/src/peer-generation/Materialized.js +18 -4
- package/build/lib/src/peer-generation/PeerLibrary.d.ts +5 -2
- package/build/lib/src/peer-generation/PeerLibrary.js +30 -10
- package/build/lib/src/peer-generation/PeerMethod.d.ts +1 -1
- package/build/lib/src/peer-generation/getSuperType.d.ts +5 -0
- package/build/lib/src/peer-generation/getSuperType.js +55 -0
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +4 -0
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +7 -0
- package/build/lib/src/peer-generation/idl/common.d.ts +1 -0
- package/build/lib/src/peer-generation/idl/common.js +9 -3
- package/build/lib/src/peer-generation/isExternalType.d.ts +4 -0
- package/build/lib/src/peer-generation/isExternalType.js +15 -0
- package/build/lib/src/peer-generation/isMaterialized.js +18 -6
- package/build/lib/src/peer-generation/unions.js +1 -1
- package/build/lib/src/util.d.ts +4 -1
- package/build/lib/src/util.js +25 -10
- package/build/lib/src/visitor.d.ts +2 -0
- package/build/lib/src/visitor.js +108 -1
- package/package.json +2 -2
- package/webidl2.js/dist/webidl2.js +62 -16
- package/webidl2.js/LICENSE +0 -21
- package/webidl2.js/README.md +0 -827
- package/webidl2.js/dist/package.json +0 -3
|
@@ -17,7 +17,7 @@ import * as idl from '../idl';
|
|
|
17
17
|
import { resolveNamedNode } from '../resolveNamedNode';
|
|
18
18
|
import { Language } from '../Language';
|
|
19
19
|
import { createLanguageWriter } from '../LanguageWriters';
|
|
20
|
-
import { BufferConvertor, CallbackConvertor, DateConvertor, MapConvertor, PointerConvertor, TupleConvertor, TypeAliasConvertor, AggregateConvertor, StringConvertor, ClassConvertor, ArrayConvertor, FunctionConvertor, OptionConvertor, NumberConvertor, NumericConvertor, CustomTypeConvertor, UnionConvertor, MaterializedClassConvertor, BooleanConvertor, EnumConvertor, UndefinedConvertor, VoidConvertor, ImportTypeConvertor, InterfaceConvertor, BigIntToU64Convertor, ObjectConvertor, } from "../LanguageWriters/ArgConvertors";
|
|
20
|
+
import { BufferConvertor, CallbackConvertor, DateConvertor, MapConvertor, PointerConvertor, TupleConvertor, TypeAliasConvertor, AggregateConvertor, StringConvertor, ClassConvertor, ArrayConvertor, FunctionConvertor, OptionConvertor, NumberConvertor, NumericConvertor, CustomTypeConvertor, UnionConvertor, MaterializedClassConvertor, BooleanConvertor, EnumConvertor, UndefinedConvertor, VoidConvertor, ImportTypeConvertor, InterfaceConvertor, BigIntToU64Convertor, ObjectConvertor, ExternalTypeConvertor, } from "../LanguageWriters/ArgConvertors";
|
|
21
21
|
import { CppNameConvertor } from '../LanguageWriters/convertors/CppConvertors';
|
|
22
22
|
import { CJTypeNameConvertor } from '../LanguageWriters/convertors/CJConvertors';
|
|
23
23
|
import { CppConvertor } from '../LanguageWriters/convertors/CppConvertors';
|
|
@@ -32,6 +32,8 @@ import { isMaterialized } from './isMaterialized';
|
|
|
32
32
|
import { isInIdlizeInternal } from '../idlize';
|
|
33
33
|
import { isInCurrentModule } from './modules';
|
|
34
34
|
import { generatorConfiguration } from '../config';
|
|
35
|
+
import { isExternalType } from './isExternalType';
|
|
36
|
+
import { KotlinTypeNameConvertor } from '../LanguageWriters/convertors/KotlinConvertors';
|
|
35
37
|
export const lenses = {
|
|
36
38
|
globals: lib.lens(lib.select.files())
|
|
37
39
|
.pipe(lib.select.nodes())
|
|
@@ -86,11 +88,16 @@ export class PeerLibrary {
|
|
|
86
88
|
get buildersToGenerate() {
|
|
87
89
|
return Array.from(this.builderClasses.values()).filter(it => it.needBeGenerated);
|
|
88
90
|
}
|
|
89
|
-
get
|
|
90
|
-
|
|
91
|
+
get orderedMaterialized() {
|
|
92
|
+
function accessorName(decl) {
|
|
93
|
+
return idl.getQualifiedName(decl, "namespace.name");
|
|
94
|
+
}
|
|
95
|
+
return Array.from(this.materializedClasses.values()).filter(it => it.needBeGenerated)
|
|
96
|
+
.sort((a, b) => accessorName(a.decl).localeCompare(accessorName(b.decl)));
|
|
91
97
|
}
|
|
92
|
-
constructor(language, useMemoM3 = false) {
|
|
98
|
+
constructor(language, interopNativeModule, useMemoM3 = false) {
|
|
93
99
|
this.language = language;
|
|
100
|
+
this.interopNativeModule = interopNativeModule;
|
|
94
101
|
this.useMemoM3 = useMemoM3;
|
|
95
102
|
this.layout = LayoutManager.Empty();
|
|
96
103
|
this._syntheticFile = idl.createFile([]);
|
|
@@ -114,6 +121,7 @@ export class PeerLibrary {
|
|
|
114
121
|
case Language.JAVA: return new JavaTypeNameConvertor(this);
|
|
115
122
|
case Language.CJ: return new CJTypeNameConvertor(this);
|
|
116
123
|
case Language.CPP: return new CppConvertor(this);
|
|
124
|
+
case Language.KOTLIN: return new KotlinTypeNameConvertor(this);
|
|
117
125
|
}
|
|
118
126
|
throw new Error(`IdlNameConvertor for ${language} is not implemented`);
|
|
119
127
|
}
|
|
@@ -156,6 +164,15 @@ export class PeerLibrary {
|
|
|
156
164
|
this.referenceCache = new Map();
|
|
157
165
|
}
|
|
158
166
|
resolveTypeReference(type, singleStep) {
|
|
167
|
+
var _a, _b;
|
|
168
|
+
const key = type.parent ? type : type.name; // does entry have resolve context or just FQN
|
|
169
|
+
let result = ((_a = this.referenceCache) === null || _a === void 0 ? void 0 : _a.has(key))
|
|
170
|
+
? this.referenceCache.get(key)
|
|
171
|
+
: this.resolveTypeReferenceUncached(type, singleStep);
|
|
172
|
+
(_b = this.referenceCache) === null || _b === void 0 ? void 0 : _b.set(key, result);
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
resolveTypeReferenceUncached(type, singleStep) {
|
|
159
176
|
var _a, _b;
|
|
160
177
|
if ((_a = this.referenceCache) === null || _a === void 0 ? void 0 : _a.has(type))
|
|
161
178
|
return this.referenceCache.get(type);
|
|
@@ -182,8 +199,7 @@ export class PeerLibrary {
|
|
|
182
199
|
}
|
|
183
200
|
if (result && (idl.isImport(result) || idl.isNamespace(result)))
|
|
184
201
|
result = undefined;
|
|
185
|
-
|
|
186
|
-
(_b = this.referenceCache) === null || _b === void 0 ? void 0 : _b.set(type, result);
|
|
202
|
+
(_b = this.referenceCache) === null || _b === void 0 ? void 0 : _b.set(type, result);
|
|
187
203
|
return result;
|
|
188
204
|
}
|
|
189
205
|
disableFallback() {
|
|
@@ -293,6 +309,7 @@ export class PeerLibrary {
|
|
|
293
309
|
case idl.IDLUndefinedType: return new UndefinedConvertor(param);
|
|
294
310
|
case idl.IDLVoidType: return new VoidConvertor(param);
|
|
295
311
|
case idl.IDLUnknownType:
|
|
312
|
+
case idl.IDLObjectType:
|
|
296
313
|
case idl.IDLAnyType: return new ObjectConvertor(param, idl.IDLAnyType);
|
|
297
314
|
case idl.IDLDate: return new DateConvertor(param);
|
|
298
315
|
case idl.IDLFunctionType: return new FunctionConvertor(this, param);
|
|
@@ -365,7 +382,7 @@ export class PeerLibrary {
|
|
|
365
382
|
return new EnumConvertor(param, declaration.parent);
|
|
366
383
|
}
|
|
367
384
|
if (idl.isCallback(declaration)) {
|
|
368
|
-
return new CallbackConvertor(this, param, declaration);
|
|
385
|
+
return new CallbackConvertor(this, param, declaration, this.interopNativeModule);
|
|
369
386
|
}
|
|
370
387
|
if (idl.isTypedef(declaration)) {
|
|
371
388
|
if (isCyclicTypeDef(declaration)) {
|
|
@@ -375,8 +392,11 @@ export class PeerLibrary {
|
|
|
375
392
|
return new TypeAliasConvertor(this, param, declaration);
|
|
376
393
|
}
|
|
377
394
|
if (idl.isInterface(declaration)) {
|
|
395
|
+
if (isExternalType(declaration, this)) {
|
|
396
|
+
return new ExternalTypeConvertor(this, param, declaration);
|
|
397
|
+
}
|
|
378
398
|
if (isMaterialized(declaration, this)) {
|
|
379
|
-
return new MaterializedClassConvertor(param, declaration);
|
|
399
|
+
return new MaterializedClassConvertor(this, param, declaration);
|
|
380
400
|
}
|
|
381
401
|
if (isBuilderClass(declaration)) {
|
|
382
402
|
return new ClassConvertor(this, declarationName, param, declaration);
|
|
@@ -417,12 +437,12 @@ export class PeerLibrary {
|
|
|
417
437
|
case idl.IDLVoidType: return idl.IDLVoidType;
|
|
418
438
|
case idl.IDLUndefinedType: return idl.IDLUndefinedType;
|
|
419
439
|
case idl.IDLUnknownType: return ArkCustomObject;
|
|
420
|
-
case idl.IDLObjectType: return ArkCustomObject
|
|
440
|
+
// case idl.IDLObjectType: return ArkCustomObject
|
|
421
441
|
}
|
|
422
442
|
const typeName = idl.isNamedNode(type) ? type.name : undefined;
|
|
423
443
|
switch (typeName) {
|
|
424
444
|
case "object":
|
|
425
|
-
case "Object": return
|
|
445
|
+
case "Object": return idl.IDLObjectType;
|
|
426
446
|
}
|
|
427
447
|
if (idl.isReferenceType(type)) {
|
|
428
448
|
// TODO: remove all this!
|
|
@@ -10,7 +10,7 @@ export declare class PeerMethod {
|
|
|
10
10
|
isCallSignature: boolean;
|
|
11
11
|
method: Method;
|
|
12
12
|
outArgConvertor?: ArgConvertor | undefined;
|
|
13
|
-
|
|
13
|
+
protected overloadIndex?: number;
|
|
14
14
|
constructor(originalParentName: string, argConvertors: ArgConvertor[], returnType: IDLType, isCallSignature: boolean, method: Method, outArgConvertor?: ArgConvertor | undefined);
|
|
15
15
|
get overloadedName(): string;
|
|
16
16
|
get fullMethodName(): string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as idl from '../idl';
|
|
2
|
+
import { ReferenceResolver } from './ReferenceResolver';
|
|
3
|
+
export declare function getSuper(declaration: idl.IDLInterface, resolver: ReferenceResolver): idl.IDLInterface | undefined;
|
|
4
|
+
export declare function getSuperType(declaration: idl.IDLInterface, resolver: ReferenceResolver): idl.IDLReferenceType | undefined;
|
|
5
|
+
//# sourceMappingURL=getSuperType.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
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 * as idl from '../idl';
|
|
16
|
+
function getSuperCandidates(declaration, resolver) {
|
|
17
|
+
return declaration.inheritance
|
|
18
|
+
.map(it => [resolver.resolveTypeReference(it), it])
|
|
19
|
+
.filter(([it,]) => it && idl.isInterface(it) && idl.isClassSubkind(it))
|
|
20
|
+
.map(it => it);
|
|
21
|
+
}
|
|
22
|
+
function getSuperTuple(declaration, resolver) {
|
|
23
|
+
if (idl.isClassSubkind(declaration)) {
|
|
24
|
+
const found = declaration.inheritance.find(it => idl.hasExtAttribute(it, idl.IDLExtendedAttributes.Extends));
|
|
25
|
+
if (found) {
|
|
26
|
+
const resolved = resolver.resolveTypeReference(found);
|
|
27
|
+
if (resolved && idl.isInterface(resolved)) {
|
|
28
|
+
return [resolved, found];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const candidates = getSuperCandidates(declaration, resolver);
|
|
32
|
+
if (candidates.length > 0) {
|
|
33
|
+
return candidates[0];
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
const fst = declaration.inheritance[0];
|
|
38
|
+
if (!fst) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
const resolved = resolver.resolveTypeReference(fst);
|
|
42
|
+
if (!resolved || !idl.isInterface(resolved)) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
return [resolved, fst];
|
|
46
|
+
}
|
|
47
|
+
export function getSuper(declaration, resolver) {
|
|
48
|
+
var _a;
|
|
49
|
+
return (_a = getSuperTuple(declaration, resolver)) === null || _a === void 0 ? void 0 : _a[0];
|
|
50
|
+
}
|
|
51
|
+
export function getSuperType(declaration, resolver) {
|
|
52
|
+
var _a;
|
|
53
|
+
return (_a = getSuperTuple(declaration, resolver)) === null || _a === void 0 ? void 0 : _a[1];
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=getSuperType.js.map
|
|
@@ -34,6 +34,10 @@ export declare class CJFeatureNameConvertor extends DeclarationNameConvertor {
|
|
|
34
34
|
convertEnum(decl: idl.IDLEnum): string;
|
|
35
35
|
static readonly I: CJFeatureNameConvertor;
|
|
36
36
|
}
|
|
37
|
+
export declare class KotlinFeatureNameConvertor extends DeclarationNameConvertor {
|
|
38
|
+
convertEnum(decl: idl.IDLEnum): string;
|
|
39
|
+
static readonly I: KotlinFeatureNameConvertor;
|
|
40
|
+
}
|
|
37
41
|
export declare function createDeclarationNameConvertor(language: Language): DeclarationNameConvertor;
|
|
38
42
|
export declare function createFeatureNameConvertor(language: Language): DeclarationNameConvertor;
|
|
39
43
|
//# sourceMappingURL=IdlNameConvertor.d.ts.map
|
|
@@ -85,6 +85,12 @@ export class CJFeatureNameConvertor extends DeclarationNameConvertor {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
CJFeatureNameConvertor.I = new CJFeatureNameConvertor();
|
|
88
|
+
export class KotlinFeatureNameConvertor extends DeclarationNameConvertor {
|
|
89
|
+
convertEnum(decl) {
|
|
90
|
+
return decl.name;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
KotlinFeatureNameConvertor.I = new KotlinFeatureNameConvertor();
|
|
88
94
|
export function createDeclarationNameConvertor(language) {
|
|
89
95
|
switch (language) {
|
|
90
96
|
case Language.ARKTS: return ETSDeclarationNameConvertor.I;
|
|
@@ -102,6 +108,7 @@ export function createFeatureNameConvertor(language) {
|
|
|
102
108
|
case Language.CPP:
|
|
103
109
|
case Language.TS: return TSFeatureNameConvertor.I;
|
|
104
110
|
case Language.CJ: return CJFeatureNameConvertor.I;
|
|
111
|
+
case Language.KOTLIN: return KotlinFeatureNameConvertor.I;
|
|
105
112
|
default: throw new Error(`Language ${language.toString()} is not supported`);
|
|
106
113
|
}
|
|
107
114
|
}
|
|
@@ -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]}`;
|
|
@@ -58,7 +58,7 @@ export function generifiedTypeName(refType, refName) {
|
|
|
58
58
|
var _a;
|
|
59
59
|
if (!refType)
|
|
60
60
|
return undefined;
|
|
61
|
-
const typeArgs = (_a = refType.typeArguments) === null || _a === void 0 ? void 0 : _a.map(it => idl.printType(it)).join(",");
|
|
61
|
+
const typeArgs = (_a = refType.typeArguments) === null || _a === void 0 ? void 0 : _a.map(it => idl.printType(it) /* FIXME: BUG! */).join(",");
|
|
62
62
|
return `${refName ? refName : refType.name}${typeArgs ? `<${typeArgs}>` : ``}`;
|
|
63
63
|
}
|
|
64
64
|
export function sanitizeGenerics(genericDeclarationString) {
|
|
@@ -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) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as idl from '../idl';
|
|
2
|
+
import { generatorConfiguration } from '../config';
|
|
3
|
+
export function isExternalType(declaration, resolver) {
|
|
4
|
+
// declarations outside of the generator input dirs
|
|
5
|
+
if (generatorConfiguration().externalTypes.get(declaration.name) != undefined)
|
|
6
|
+
return true;
|
|
7
|
+
// treat as external types only declarations with methods
|
|
8
|
+
if (declaration.methods.length == 0)
|
|
9
|
+
return false;
|
|
10
|
+
const pack = idl.getPackageName(declaration);
|
|
11
|
+
if (generatorConfiguration().externalPackages.includes(pack))
|
|
12
|
+
return true;
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=isExternalType.js.map
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
import { generatorConfiguration } from '../config';
|
|
16
16
|
import * as idl from '../idl';
|
|
17
17
|
import { isBuilderClass } from './BuilderClass';
|
|
18
|
+
import { isExternalType } from './isExternalType';
|
|
19
|
+
import { getSuper } from './getSuperType';
|
|
18
20
|
export function isMaterialized(declaration, resolver) {
|
|
19
21
|
var _a;
|
|
20
22
|
if (!idl.isInterfaceSubkind(declaration) && !idl.isClassSubkind(declaration))
|
|
@@ -27,6 +29,11 @@ export function isMaterialized(declaration, resolver) {
|
|
|
27
29
|
if (generatorConfiguration().forceMaterialized.includes(declaration.name)) {
|
|
28
30
|
return true;
|
|
29
31
|
}
|
|
32
|
+
// TODO: rework this
|
|
33
|
+
// TODO: CustomComponent from components.custom config file
|
|
34
|
+
if (["BaseSpan", "CustomComponent"].includes(declaration.name)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
30
37
|
for (const ignore of ["Attribute", "Method", "Interface"]) {
|
|
31
38
|
if (declaration.name.endsWith(ignore)) {
|
|
32
39
|
return false;
|
|
@@ -38,15 +45,19 @@ export function isMaterialized(declaration, resolver) {
|
|
|
38
45
|
if (generatorConfiguration().ignoreMaterialized.includes(declaration.name)) {
|
|
39
46
|
return false;
|
|
40
47
|
}
|
|
48
|
+
if (isExternalType(declaration, resolver)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
41
51
|
// A materialized class is a class or an interface with methods
|
|
42
52
|
// excluding components and related classes
|
|
43
53
|
if (declaration.methods.length > 0 || declaration.constructors.length > 0)
|
|
44
54
|
return true;
|
|
45
55
|
// Or a class or an interface derived from materialized class
|
|
46
|
-
|
|
47
|
-
|
|
56
|
+
const superClass = getSuper(declaration, resolver);
|
|
57
|
+
if (superClass) {
|
|
58
|
+
const superType = superClass;
|
|
48
59
|
if (!superType || !idl.isInterface(superType)) {
|
|
49
|
-
console.log(`Unable to resolve ${
|
|
60
|
+
console.log(`Unable to resolve ${superClass.name} type, consider ${declaration.name} to be not materialized`);
|
|
50
61
|
return false;
|
|
51
62
|
}
|
|
52
63
|
return isMaterialized(superType, resolver);
|
|
@@ -69,10 +80,11 @@ export function isStaticMaterialized(declaration, resolver) {
|
|
|
69
80
|
return false;
|
|
70
81
|
if (!declaration.methods.every(it => it.isStatic && !isSelfReturnMethod(it, declaration, resolver)))
|
|
71
82
|
return false;
|
|
72
|
-
|
|
73
|
-
|
|
83
|
+
const superClass = getSuper(declaration, resolver);
|
|
84
|
+
if (superClass) {
|
|
85
|
+
const superType = superClass;
|
|
74
86
|
if (!superType || !idl.isInterface(superType)) {
|
|
75
|
-
console.log(`Unable to resolve ${
|
|
87
|
+
console.log(`Unable to resolve ${superClass.name} type, consider ${declaration.name} to be not materialized`);
|
|
76
88
|
return false;
|
|
77
89
|
}
|
|
78
90
|
return isStaticMaterialized(superType, resolver);
|
|
@@ -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;
|
|
@@ -89,5 +90,7 @@ type StringProperties<T> = {
|
|
|
89
90
|
[Property in keyof T as (T[Property] extends string ? Property : never)]: T[Property];
|
|
90
91
|
};
|
|
91
92
|
export declare function sorted<T, N extends keyof StringProperties<T>>(array: T[], key: ((value: T) => string) | N): T[];
|
|
93
|
+
export declare function getExtractorName(target: idl.IDLInterface, language: Language, toPtr?: boolean): string;
|
|
94
|
+
export declare function getExternalTypePackage(node: idl.IDLEntry): string | undefined;
|
|
92
95
|
export {};
|
|
93
96
|
//# sourceMappingURL=util.d.ts.map
|
package/build/lib/src/util.js
CHANGED
|
@@ -17,6 +17,7 @@ import * as fs from "fs";
|
|
|
17
17
|
import * as ts from "typescript";
|
|
18
18
|
import * as idl from "./idl";
|
|
19
19
|
import { Language } from './Language';
|
|
20
|
+
import { generatorConfiguration } from './config';
|
|
20
21
|
/** True if this is visible outside this file, false otherwise */
|
|
21
22
|
export function isNodePublic(node) {
|
|
22
23
|
return (ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Public) !== 0;
|
|
@@ -269,6 +270,13 @@ export function zip(left, right) {
|
|
|
269
270
|
throw new Error("Arrays of different length");
|
|
270
271
|
return left.map((_, i) => [left[i], right[i]]);
|
|
271
272
|
}
|
|
273
|
+
export function zipStrip(left, right) {
|
|
274
|
+
const result = [];
|
|
275
|
+
for (let i = 0; i < left.length && i < right.length; ++i) {
|
|
276
|
+
result.push([left[i], right[i]]);
|
|
277
|
+
}
|
|
278
|
+
return result;
|
|
279
|
+
}
|
|
272
280
|
export function identNameWithNamespace(node, language) {
|
|
273
281
|
let parent = node.parent;
|
|
274
282
|
while (parent && !ts.isModuleDeclaration(parent))
|
|
@@ -558,9 +566,7 @@ export function className(node) {
|
|
|
558
566
|
export function nameEnumValues(enumTarget) {
|
|
559
567
|
const prefix = "LEGACY";
|
|
560
568
|
const nameToIndex = new Map();
|
|
561
|
-
enumTarget.
|
|
562
|
-
.map(it => identName(it.name))
|
|
563
|
-
.forEach((name, index) => {
|
|
569
|
+
enumTarget.forEach((name, index) => {
|
|
564
570
|
let upperCaseName;
|
|
565
571
|
if (isUpperCase(name)) {
|
|
566
572
|
upperCaseName = name;
|
|
@@ -612,13 +618,10 @@ export function hashCodeFromString(value) {
|
|
|
612
618
|
return hash;
|
|
613
619
|
}
|
|
614
620
|
export function forceWriteFile(filePath, content) {
|
|
615
|
-
path.dirname(filePath)
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
}
|
|
620
|
-
return dirPath;
|
|
621
|
-
}, ".");
|
|
621
|
+
const dirPath = path.dirname(filePath);
|
|
622
|
+
if (!fs.existsSync(dirPath)) {
|
|
623
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
624
|
+
}
|
|
622
625
|
fs.writeFileSync(filePath, content);
|
|
623
626
|
}
|
|
624
627
|
export function findVersion() {
|
|
@@ -687,4 +690,16 @@ export function sorted(array, key) {
|
|
|
687
690
|
return array.map(it => it)
|
|
688
691
|
.sort((a, b) => comparator.compare(a[key], b[key]));
|
|
689
692
|
}
|
|
693
|
+
export function getExtractorName(target, language, toPtr = true) {
|
|
694
|
+
// TODO: Update for CJ
|
|
695
|
+
return toPtr ? `to${target.name}Ptr` : `from${target.name}Ptr`;
|
|
696
|
+
}
|
|
697
|
+
export function getExternalTypePackage(node) {
|
|
698
|
+
if (!idl.isInterface(node))
|
|
699
|
+
return undefined;
|
|
700
|
+
const pack = idl.getPackageName(node);
|
|
701
|
+
if (generatorConfiguration().externalPackages.includes(pack))
|
|
702
|
+
return `@${pack}`;
|
|
703
|
+
return generatorConfiguration().externalTypes.get(node.name);
|
|
704
|
+
}
|
|
690
705
|
//# sourceMappingURL=util.js.map
|
|
@@ -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
|
@@ -89,7 +89,6 @@ export class IDLDependencyCollector {
|
|
|
89
89
|
visitInterface(decl) {
|
|
90
90
|
return [
|
|
91
91
|
...decl.inheritance
|
|
92
|
-
.filter(it => it !== idl.IDLTopType)
|
|
93
92
|
.flatMap(it => this.walk(it)),
|
|
94
93
|
...decl.properties
|
|
95
94
|
.filter(it => !it.isStatic)
|
|
@@ -134,4 +133,112 @@ export class IDLDependencyCollector {
|
|
|
134
133
|
export function collectDependencies(resolver, node) {
|
|
135
134
|
return walkIDL(new IDLDependencyCollector(resolver), node);
|
|
136
135
|
}
|
|
136
|
+
function isFirstTypeSubsetOfSecond(first, second) {
|
|
137
|
+
if (idl.isOptionalType(second)) {
|
|
138
|
+
return isFirstTypeSubsetOfSecond(idl.maybeUnwrapOptionalType(first), idl.maybeUnwrapOptionalType(second));
|
|
139
|
+
}
|
|
140
|
+
if (idl.isUnionType(second)) {
|
|
141
|
+
const firstTypes = idl.isUnionType(first) ? first.types : [first];
|
|
142
|
+
const secondTypes = second.types;
|
|
143
|
+
return firstTypes.every(firstType => secondTypes.some(secondType => isFirstTypeSubsetOfSecond(firstType, secondType)));
|
|
144
|
+
}
|
|
145
|
+
return idl.printType(first) === idl.printType(second);
|
|
146
|
+
}
|
|
147
|
+
function isFirstParameterSubsetOfSecond(first, second) {
|
|
148
|
+
if (first === undefined)
|
|
149
|
+
return second.isOptional;
|
|
150
|
+
if (first.isOptional && !second.isOptional)
|
|
151
|
+
return false;
|
|
152
|
+
if (second.isOptional)
|
|
153
|
+
return isFirstTypeSubsetOfSecond(idl.maybeUnwrapOptionalType(first.type), idl.maybeUnwrapOptionalType(second.type));
|
|
154
|
+
return isFirstTypeSubsetOfSecond(first.type, second.type);
|
|
155
|
+
}
|
|
156
|
+
function isFirstMethodSubsetOfSecond(first, second) {
|
|
157
|
+
if (first.parameters.length > second.parameters.length)
|
|
158
|
+
return false;
|
|
159
|
+
if (first.isAsync !== second.isAsync)
|
|
160
|
+
return false;
|
|
161
|
+
if (first.isStatic !== second.isStatic)
|
|
162
|
+
return false;
|
|
163
|
+
if (second.parameters.some((secondParameter, idx) => !isFirstParameterSubsetOfSecond(first.parameters.at(idx), secondParameter)))
|
|
164
|
+
return false;
|
|
165
|
+
if (!isFirstTypeSubsetOfSecond(first.returnType, second.returnType))
|
|
166
|
+
return false;
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
function isFirstPropertySubsetOfSecond(first, second) {
|
|
170
|
+
if (idl.getExtAttribute(first, idl.IDLExtendedAttributes.Accessor) !==
|
|
171
|
+
idl.getExtAttribute(second, idl.IDLExtendedAttributes.Accessor))
|
|
172
|
+
return false;
|
|
173
|
+
if (first.isStatic !== second.isStatic)
|
|
174
|
+
return false;
|
|
175
|
+
if (first.isOptional && !second.isOptional)
|
|
176
|
+
return false;
|
|
177
|
+
if (second.isOptional)
|
|
178
|
+
return isFirstTypeSubsetOfSecond(idl.maybeUnwrapOptionalType(first.type), idl.maybeUnwrapOptionalType(second.type));
|
|
179
|
+
return isFirstTypeSubsetOfSecond(first.type, second.type);
|
|
180
|
+
}
|
|
181
|
+
function filterRedundantOverloadsSameNamed(entries) {
|
|
182
|
+
const entryToSupersets = new Map();
|
|
183
|
+
for (const entry of entries) {
|
|
184
|
+
entryToSupersets.set(entry, []);
|
|
185
|
+
for (const other of entries) {
|
|
186
|
+
if (entry === other)
|
|
187
|
+
continue;
|
|
188
|
+
if (idl.isMethod(entry) && idl.isMethod(other)) {
|
|
189
|
+
if (isFirstMethodSubsetOfSecond(entry, other))
|
|
190
|
+
entryToSupersets.get(entry).push(other);
|
|
191
|
+
}
|
|
192
|
+
else if (idl.isProperty(entry) && idl.isProperty(other)) {
|
|
193
|
+
if (isFirstPropertySubsetOfSecond(entry, other))
|
|
194
|
+
entryToSupersets.get(entry).push(other);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
throw new Error("Not implemented");
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const visited = [];
|
|
202
|
+
const roots = [];
|
|
203
|
+
const visit = (method) => {
|
|
204
|
+
if (visited.includes(method))
|
|
205
|
+
return;
|
|
206
|
+
visited.push(method);
|
|
207
|
+
for (const superset of entryToSupersets.get(method)) {
|
|
208
|
+
visit(superset);
|
|
209
|
+
}
|
|
210
|
+
if (!entryToSupersets.get(method).some(it => roots.includes(it)))
|
|
211
|
+
roots.push(method);
|
|
212
|
+
};
|
|
213
|
+
entries.forEach(visit);
|
|
214
|
+
return roots;
|
|
215
|
+
}
|
|
216
|
+
export function filterRedundantMethodsOverloads(methods) {
|
|
217
|
+
const sameNamedGroups = new Map();
|
|
218
|
+
for (const method of methods) {
|
|
219
|
+
if (!sameNamedGroups.has(method.name))
|
|
220
|
+
sameNamedGroups.set(method.name, []);
|
|
221
|
+
sameNamedGroups.get(method.name).push(method);
|
|
222
|
+
}
|
|
223
|
+
const filtered = [];
|
|
224
|
+
for (const sameNamed of sameNamedGroups.values()) {
|
|
225
|
+
filtered.push(...filterRedundantOverloadsSameNamed(sameNamed));
|
|
226
|
+
}
|
|
227
|
+
// stabilizing order
|
|
228
|
+
return methods.filter(it => filtered.includes(it));
|
|
229
|
+
}
|
|
230
|
+
export function filterRedundantAttributesOverloads(properties) {
|
|
231
|
+
const sameNamedGroups = new Map();
|
|
232
|
+
for (const property of properties) {
|
|
233
|
+
if (!sameNamedGroups.has(property.name))
|
|
234
|
+
sameNamedGroups.set(property.name, []);
|
|
235
|
+
sameNamedGroups.get(property.name).push(property);
|
|
236
|
+
}
|
|
237
|
+
const filtered = [];
|
|
238
|
+
for (const sameNamed of sameNamedGroups.values()) {
|
|
239
|
+
filtered.push(...filterRedundantOverloadsSameNamed(sameNamed));
|
|
240
|
+
}
|
|
241
|
+
// stabilizing order
|
|
242
|
+
return properties.filter(it => filtered.includes(it));
|
|
243
|
+
}
|
|
137
244
|
//# 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.9-arktscgen-4",
|
|
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.5
|
|
37
|
+
"@koalaui/interop": "1.7.5",
|
|
38
38
|
"typescript": "4.9.5",
|
|
39
39
|
"@types/node": "^18.0.0"
|
|
40
40
|
},
|