@idlizer/core 2.0.15
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.d.ts +28 -0
- package/build/lib/src/IndentedPrinter.js +81 -0
- package/build/lib/src/Language.d.ts +15 -0
- package/build/lib/src/Language.js +42 -0
- package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +318 -0
- package/build/lib/src/LanguageWriters/ArgConvertors.js +1015 -0
- package/build/lib/src/LanguageWriters/InteropConvertor.d.ts +36 -0
- package/build/lib/src/LanguageWriters/InteropConvertor.js +174 -0
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +386 -0
- package/build/lib/src/LanguageWriters/LanguageWriter.js +746 -0
- package/build/lib/src/LanguageWriters/common.d.ts +17 -0
- package/build/lib/src/LanguageWriters/common.js +33 -0
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +8 -0
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +35 -0
- package/build/lib/src/LanguageWriters/index.d.ts +3 -0
- package/build/lib/src/LanguageWriters/index.js +3 -0
- package/build/lib/src/LanguageWriters/nameConvertor.d.ts +28 -0
- package/build/lib/src/LanguageWriters/nameConvertor.js +61 -0
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +147 -0
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +578 -0
- package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.d.ts +46 -0
- package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.js +121 -0
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +116 -0
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +472 -0
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +72 -0
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +329 -0
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +83 -0
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +275 -0
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +93 -0
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +390 -0
- package/build/lib/src/LibraryInterface.d.ts +21 -0
- package/build/lib/src/LibraryInterface.js +2 -0
- package/build/lib/src/config.d.ts +8 -0
- package/build/lib/src/config.js +20 -0
- package/build/lib/src/from-idl/DtsPrinter.d.ts +35 -0
- package/build/lib/src/from-idl/DtsPrinter.js +375 -0
- package/build/lib/src/from-idl/common.d.ts +5 -0
- package/build/lib/src/from-idl/common.js +83 -0
- package/build/lib/src/from-idl/deserialize.d.ts +9 -0
- package/build/lib/src/from-idl/deserialize.js +384 -0
- package/build/lib/src/from-idl/toString.d.ts +2 -0
- package/build/lib/src/from-idl/toString.js +18 -0
- package/build/lib/src/from-idl/webidl2-utils.d.ts +20 -0
- package/build/lib/src/from-idl/webidl2-utils.js +84 -0
- package/build/lib/src/idl.d.ts +404 -0
- package/build/lib/src/idl.js +1015 -0
- package/build/lib/src/idlize.d.ts +4 -0
- package/build/lib/src/idlize.js +52 -0
- package/build/lib/src/index.d.ts +34 -0
- package/build/lib/src/index.js +48 -0
- package/build/lib/src/inheritance.d.ts +16 -0
- package/build/lib/src/inheritance.js +76 -0
- package/build/lib/src/languageSpecificKeywords.d.ts +5 -0
- package/build/lib/src/languageSpecificKeywords.js +51 -0
- package/build/lib/src/library.d.ts +67 -0
- package/build/lib/src/library.js +190 -0
- package/build/lib/src/options.d.ts +11 -0
- package/build/lib/src/options.js +16 -0
- package/build/lib/src/peer-generation/PrimitiveType.d.ts +24 -0
- package/build/lib/src/peer-generation/PrimitiveType.js +52 -0
- package/build/lib/src/peer-generation/ReferenceResolver.d.ts +9 -0
- package/build/lib/src/peer-generation/ReferenceResolver.js +37 -0
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +28 -0
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +82 -0
- package/build/lib/src/peer-generation/idl/common.d.ts +9 -0
- package/build/lib/src/peer-generation/idl/common.js +70 -0
- package/build/lib/src/peer-generation/unions.d.ts +29 -0
- package/build/lib/src/peer-generation/unions.js +111 -0
- package/build/lib/src/rand_utils.d.ts +6 -0
- package/build/lib/src/rand_utils.js +100 -0
- package/build/lib/src/util.d.ts +75 -0
- package/build/lib/src/util.js +622 -0
- package/package.json +49 -0
- 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 +4547 -0
- package/webidl2.js/package.json +55 -0
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
export function createEmptyReferenceResolver() {
|
|
16
|
+
return {
|
|
17
|
+
resolveTypeReference() {
|
|
18
|
+
return undefined;
|
|
19
|
+
},
|
|
20
|
+
toDeclaration(type) {
|
|
21
|
+
return type;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** Please do not store any global instances */
|
|
26
|
+
export function createAlternativeReferenceResolver(mainResolver, alternatives) {
|
|
27
|
+
return {
|
|
28
|
+
resolveTypeReference(type, pointOfView, rootEntries) {
|
|
29
|
+
var _a;
|
|
30
|
+
return (_a = mainResolver.resolveTypeReference(type, pointOfView, rootEntries)) !== null && _a !== void 0 ? _a : alternatives.get(type.name);
|
|
31
|
+
},
|
|
32
|
+
toDeclaration(type) {
|
|
33
|
+
return mainResolver.toDeclaration(type);
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=ReferenceResolver.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as idl from "../../idl";
|
|
2
|
+
import { DeclarationConvertor } from "../../LanguageWriters/nameConvertor";
|
|
3
|
+
import { Language } from "../../Language";
|
|
4
|
+
export declare class DeclarationNameConvertor implements DeclarationConvertor<string> {
|
|
5
|
+
convertInterface(decl: idl.IDLInterface): string;
|
|
6
|
+
convertEnum(decl: idl.IDLEnum): string;
|
|
7
|
+
convertTypedef(decl: idl.IDLTypedef): string;
|
|
8
|
+
convertCallback(decl: idl.IDLCallback): string;
|
|
9
|
+
convertNamespace(node: idl.IDLNamespace): string;
|
|
10
|
+
convertMethod(node: idl.IDLMethod): string;
|
|
11
|
+
convertConstant(node: idl.IDLConstant): string;
|
|
12
|
+
static readonly I: DeclarationNameConvertor;
|
|
13
|
+
}
|
|
14
|
+
export declare class TSFeatureNameConvertor extends DeclarationNameConvertor {
|
|
15
|
+
convertEnum(decl: idl.IDLEnum): string;
|
|
16
|
+
static readonly I: TSFeatureNameConvertor;
|
|
17
|
+
}
|
|
18
|
+
export declare class ETSDeclarationNameConvertor extends DeclarationNameConvertor {
|
|
19
|
+
convertEnum(decl: idl.IDLEnum): string;
|
|
20
|
+
static readonly I: ETSDeclarationNameConvertor;
|
|
21
|
+
}
|
|
22
|
+
export declare class ETSFeatureNameConvertor extends DeclarationNameConvertor {
|
|
23
|
+
convertEnum(decl: idl.IDLEnum): string;
|
|
24
|
+
static readonly I: ETSFeatureNameConvertor;
|
|
25
|
+
}
|
|
26
|
+
export declare function createDeclarationNameConvertor(language: Language): DeclarationNameConvertor;
|
|
27
|
+
export declare function createFeatureNameConvertor(language: Language): DeclarationNameConvertor;
|
|
28
|
+
//# sourceMappingURL=IdlNameConvertor.d.ts.map
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
import { Language } from "../../Language";
|
|
17
|
+
export class DeclarationNameConvertor {
|
|
18
|
+
convertInterface(decl) {
|
|
19
|
+
return decl.name;
|
|
20
|
+
}
|
|
21
|
+
convertEnum(decl) {
|
|
22
|
+
return `${idl.getNamespacesPathFor(decl).join('')}${decl.name}`;
|
|
23
|
+
}
|
|
24
|
+
convertTypedef(decl) {
|
|
25
|
+
return decl.name;
|
|
26
|
+
}
|
|
27
|
+
convertCallback(decl) {
|
|
28
|
+
var _a;
|
|
29
|
+
return (_a = decl.name) !== null && _a !== void 0 ? _a : "MISSING CALLBACK NAME";
|
|
30
|
+
}
|
|
31
|
+
convertNamespace(node) {
|
|
32
|
+
return node.name;
|
|
33
|
+
}
|
|
34
|
+
convertMethod(node) {
|
|
35
|
+
return node.name;
|
|
36
|
+
}
|
|
37
|
+
convertConstant(node) {
|
|
38
|
+
return node.name;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
DeclarationNameConvertor.I = new DeclarationNameConvertor();
|
|
42
|
+
export class TSFeatureNameConvertor extends DeclarationNameConvertor {
|
|
43
|
+
convertEnum(decl) {
|
|
44
|
+
return `${idl.getNamespacesPathFor(decl).join('')}${decl.name}`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
TSFeatureNameConvertor.I = new TSFeatureNameConvertor();
|
|
48
|
+
export class ETSDeclarationNameConvertor extends DeclarationNameConvertor {
|
|
49
|
+
convertEnum(decl) {
|
|
50
|
+
const namespace = idl.getNamespacesPathFor(decl).map(it => it.name).join('_');
|
|
51
|
+
return `${namespace ? `${namespace}_` : ``}${decl.name}`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
ETSDeclarationNameConvertor.I = new ETSDeclarationNameConvertor();
|
|
55
|
+
export class ETSFeatureNameConvertor extends DeclarationNameConvertor {
|
|
56
|
+
convertEnum(decl) {
|
|
57
|
+
const namespace = idl.getNamespacesPathFor(decl).join('');
|
|
58
|
+
return `${namespace ? `${namespace}_` : ``}${decl.name}`;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
ETSFeatureNameConvertor.I = new ETSFeatureNameConvertor();
|
|
62
|
+
export function createDeclarationNameConvertor(language) {
|
|
63
|
+
switch (language) {
|
|
64
|
+
case Language.ARKTS: return ETSDeclarationNameConvertor.I;
|
|
65
|
+
case Language.JAVA:
|
|
66
|
+
case Language.CPP:
|
|
67
|
+
case Language.CJ:
|
|
68
|
+
case Language.TS: return DeclarationNameConvertor.I;
|
|
69
|
+
default: throw new Error(`Language ${language.toString()} is not supported`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export function createFeatureNameConvertor(language) {
|
|
73
|
+
switch (language) {
|
|
74
|
+
case Language.ARKTS: return ETSFeatureNameConvertor.I;
|
|
75
|
+
case Language.JAVA:
|
|
76
|
+
case Language.CPP:
|
|
77
|
+
case Language.CJ:
|
|
78
|
+
case Language.TS: return TSFeatureNameConvertor.I;
|
|
79
|
+
default: throw new Error(`Language ${language.toString()} is not supported`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=IdlNameConvertor.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as idl from "../../idl";
|
|
2
|
+
import { Language } from "../../Language";
|
|
3
|
+
export declare function generateSyntheticIdlNodeName(type: idl.IDLType): string;
|
|
4
|
+
export declare function qualifiedName(decl: idl.IDLNode, languageOrDelimiter: Language | string): string;
|
|
5
|
+
export declare function typeOrUnion(types: idl.IDLType[], name?: string): idl.IDLType;
|
|
6
|
+
export declare function generifiedTypeName(refType: idl.IDLReferenceType | undefined, refName?: string): string | undefined;
|
|
7
|
+
export declare function generateSyntheticUnionName(types: idl.IDLType[]): string;
|
|
8
|
+
export declare function isImportAttr(decl: idl.IDLNode): boolean;
|
|
9
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
import { Language } from "../../Language";
|
|
17
|
+
import { capitalize } from "../../util";
|
|
18
|
+
export function generateSyntheticIdlNodeName(type) {
|
|
19
|
+
if (idl.isPrimitiveType(type))
|
|
20
|
+
return capitalize(type.name);
|
|
21
|
+
if (idl.isContainerType(type)) {
|
|
22
|
+
const typeArgs = type.elementType.map(it => generateSyntheticIdlNodeName(it)).join("_");
|
|
23
|
+
switch (type.containerKind) {
|
|
24
|
+
case "sequence": return "Array_" + typeArgs;
|
|
25
|
+
case "record": return "Map_" + typeArgs;
|
|
26
|
+
case "Promise": return "Promise_" + typeArgs;
|
|
27
|
+
default: throw new Error(`Unknown container type ${idl.DebugUtils.debugPrintType(type)}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (idl.isNamedNode(type))
|
|
31
|
+
return type.name;
|
|
32
|
+
if (idl.isOptionalType(type))
|
|
33
|
+
return `Opt_${generateSyntheticIdlNodeName(type.type)}`;
|
|
34
|
+
throw `Can not compute type name of ${idl.IDLKind[type.kind]}`;
|
|
35
|
+
}
|
|
36
|
+
export function qualifiedName(decl, languageOrDelimiter) {
|
|
37
|
+
if (!idl.isNamedNode(decl))
|
|
38
|
+
throw new Error("internal error, name required for no-named node");
|
|
39
|
+
const delimiter = typeof languageOrDelimiter === "string"
|
|
40
|
+
? languageOrDelimiter
|
|
41
|
+
: (languageOrDelimiter === Language.CPP ? '_' : '.');
|
|
42
|
+
if (idl.isEntry(decl) && decl.namespace)
|
|
43
|
+
return qualifiedName(decl.namespace, delimiter) + delimiter + idl.forceAsNamedNode(decl).name;
|
|
44
|
+
return idl.forceAsNamedNode(decl).name;
|
|
45
|
+
}
|
|
46
|
+
export function typeOrUnion(types, name) {
|
|
47
|
+
const seenNames = new Set();
|
|
48
|
+
const uniqueTypes = types.filter(it => {
|
|
49
|
+
const typeName = idl.printType(it);
|
|
50
|
+
if (seenNames.has(typeName))
|
|
51
|
+
return false;
|
|
52
|
+
seenNames.add(typeName);
|
|
53
|
+
return true;
|
|
54
|
+
});
|
|
55
|
+
return uniqueTypes.length === 1 ? uniqueTypes[0] : idl.createUnionType(uniqueTypes, name);
|
|
56
|
+
}
|
|
57
|
+
export function generifiedTypeName(refType, refName) {
|
|
58
|
+
var _a;
|
|
59
|
+
if (!refType)
|
|
60
|
+
return undefined;
|
|
61
|
+
const typeArgs = (_a = refType.typeArguments) === null || _a === void 0 ? void 0 : _a.map(it => idl.printType(it)).join(",");
|
|
62
|
+
return `${refName ? refName : refType.name}${typeArgs ? `<${typeArgs}>` : ``}`;
|
|
63
|
+
}
|
|
64
|
+
export function generateSyntheticUnionName(types) {
|
|
65
|
+
return `Union_${types.map(it => generateSyntheticIdlNodeName(it)).join("_")}`;
|
|
66
|
+
}
|
|
67
|
+
export function isImportAttr(decl) {
|
|
68
|
+
return idl.hasExtAttribute(decl, idl.IDLExtendedAttributes.Import);
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { TypeConvertor } from "../LanguageWriters";
|
|
2
|
+
import { IDLContainerType, IDLOptionalType, IDLPrimitiveType, IDLReferenceType, IDLType, IDLTypeParameterType, IDLUnionType } from '../idl';
|
|
3
|
+
import { LanguageExpression, LanguageWriter } from "../LanguageWriters/LanguageWriter";
|
|
4
|
+
import { ArgConvertor } from "../LanguageWriters/ArgConvertors";
|
|
5
|
+
import { LibraryInterface } from "../LibraryInterface";
|
|
6
|
+
import { ReferenceResolver } from "./ReferenceResolver";
|
|
7
|
+
export declare class UnionFlattener implements TypeConvertor<IDLType[]> {
|
|
8
|
+
private resolver;
|
|
9
|
+
constructor(resolver: ReferenceResolver);
|
|
10
|
+
convertUnion(type: IDLUnionType): IDLType[];
|
|
11
|
+
convertTypeReference(type: IDLReferenceType): IDLType[];
|
|
12
|
+
convertOptional(type: IDLOptionalType): IDLType[];
|
|
13
|
+
convertContainer(type: IDLContainerType): IDLType[];
|
|
14
|
+
convertImport(type: IDLReferenceType, importClause: string): IDLType[];
|
|
15
|
+
convertPrimitiveType(type: IDLPrimitiveType): IDLType[];
|
|
16
|
+
convertTypeParameter(type: IDLTypeParameterType): IDLType[];
|
|
17
|
+
}
|
|
18
|
+
export declare class UnionRuntimeTypeChecker {
|
|
19
|
+
private convertors;
|
|
20
|
+
private conflictingConvertors;
|
|
21
|
+
private duplicateMembers;
|
|
22
|
+
private discriminators;
|
|
23
|
+
constructor(convertors: ArgConvertor[]);
|
|
24
|
+
private checkConflicts;
|
|
25
|
+
makeDiscriminator(value: string, convertorIndex: number, writer: LanguageWriter): LanguageExpression;
|
|
26
|
+
reportConflicts(context: string | undefined): void;
|
|
27
|
+
}
|
|
28
|
+
export declare function flattenUnionType(library: LibraryInterface, type: IDLType): IDLType;
|
|
29
|
+
//# sourceMappingURL=unions.d.ts.map
|
|
@@ -0,0 +1,111 @@
|
|
|
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 { convertType } from "../LanguageWriters";
|
|
16
|
+
import { IDLCustomObjectType, IDLUndefinedType, isType, isUnionType } from '../idl';
|
|
17
|
+
import { typeOrUnion } from "./idl/common";
|
|
18
|
+
import { RuntimeType } from "../LanguageWriters/common";
|
|
19
|
+
export class UnionFlattener {
|
|
20
|
+
constructor(resolver) {
|
|
21
|
+
this.resolver = resolver;
|
|
22
|
+
}
|
|
23
|
+
convertUnion(type) {
|
|
24
|
+
return type.types.flatMap(it => convertType(this, it));
|
|
25
|
+
}
|
|
26
|
+
convertTypeReference(type) {
|
|
27
|
+
const decl = this.resolver.toDeclaration(type);
|
|
28
|
+
return isType(decl) && decl !== IDLCustomObjectType ? convertType(this, decl) : [type];
|
|
29
|
+
}
|
|
30
|
+
convertOptional(type) {
|
|
31
|
+
return [type.type, IDLUndefinedType];
|
|
32
|
+
}
|
|
33
|
+
convertContainer(type) {
|
|
34
|
+
return [type];
|
|
35
|
+
}
|
|
36
|
+
convertImport(type, importClause) {
|
|
37
|
+
return [type];
|
|
38
|
+
}
|
|
39
|
+
convertPrimitiveType(type) {
|
|
40
|
+
return [type];
|
|
41
|
+
}
|
|
42
|
+
convertTypeParameter(type) {
|
|
43
|
+
return [type];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export class UnionRuntimeTypeChecker {
|
|
47
|
+
constructor(convertors) {
|
|
48
|
+
this.convertors = convertors;
|
|
49
|
+
this.conflictingConvertors = new Set();
|
|
50
|
+
this.duplicateMembers = new Set();
|
|
51
|
+
this.discriminators = [];
|
|
52
|
+
this.checkConflicts();
|
|
53
|
+
}
|
|
54
|
+
checkConflicts() {
|
|
55
|
+
const runtimeTypeConflicts = new Map();
|
|
56
|
+
this.convertors.forEach(conv => {
|
|
57
|
+
conv.runtimeTypes.forEach(rtType => {
|
|
58
|
+
const convertors = runtimeTypeConflicts.get(rtType);
|
|
59
|
+
if (convertors)
|
|
60
|
+
convertors.push(conv);
|
|
61
|
+
else
|
|
62
|
+
runtimeTypeConflicts.set(rtType, [conv]);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
runtimeTypeConflicts.forEach((convertors, rtType) => {
|
|
66
|
+
if (convertors.length > 1) {
|
|
67
|
+
const allMembers = new Set();
|
|
68
|
+
if (rtType === RuntimeType.OBJECT) {
|
|
69
|
+
convertors.forEach(convertor => {
|
|
70
|
+
convertor.getMembers().forEach(member => {
|
|
71
|
+
if (allMembers.has(member))
|
|
72
|
+
this.duplicateMembers.add(member);
|
|
73
|
+
allMembers.add(member);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
convertors.forEach(convertor => {
|
|
78
|
+
this.conflictingConvertors.add(convertor);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
makeDiscriminator(value, convertorIndex, writer) {
|
|
84
|
+
const convertor = this.convertors[convertorIndex];
|
|
85
|
+
if (this.conflictingConvertors.has(convertor) && writer.language.needsUnionDiscrimination) {
|
|
86
|
+
const discriminator = convertor.unionDiscriminator(value, convertorIndex, writer, this.duplicateMembers);
|
|
87
|
+
this.discriminators.push([discriminator, convertor, convertorIndex]);
|
|
88
|
+
if (discriminator)
|
|
89
|
+
return discriminator;
|
|
90
|
+
}
|
|
91
|
+
return writer.makeNaryOp("||", convertor.runtimeTypes.map((it, runtimeTypeIndex) => writer.makeNaryOp("==", [
|
|
92
|
+
writer.makeUnionVariantCondition(convertor, value, `${value}_type`, RuntimeType[it], convertorIndex, runtimeTypeIndex)
|
|
93
|
+
])));
|
|
94
|
+
}
|
|
95
|
+
reportConflicts(context) {
|
|
96
|
+
if (this.discriminators.filter(([discriminator, _, __]) => discriminator === undefined).length > 1) {
|
|
97
|
+
this.discriminators.forEach(([discr, conv, n]) => console.log(` ${n} : ${conv.constructor.name} : ${discr ? discr.asString() : "<undefined>"}`));
|
|
98
|
+
throw new Error(`runtime type conflict in \`${context}\``);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export function flattenUnionType(library, type) {
|
|
103
|
+
const unionFlattener = new UnionFlattener(library);
|
|
104
|
+
if (isUnionType(type)) {
|
|
105
|
+
const allTypes = type.types.flatMap(it => convertType(unionFlattener, it));
|
|
106
|
+
const uniqueTypes = new Set(allTypes);
|
|
107
|
+
return uniqueTypes.size === allTypes.length ? type : typeOrUnion(Array.from(uniqueTypes));
|
|
108
|
+
}
|
|
109
|
+
return type;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=unions.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function initRNG(): void;
|
|
2
|
+
export declare function randInt(max: number, min?: number): number;
|
|
3
|
+
export declare function randString(max: number): string;
|
|
4
|
+
export declare function pick<K, V>(keys: K[], gen: (key: K) => string[], pickedNumbers?: number): string[];
|
|
5
|
+
export declare function pickArray<T>(values: T[], maxLen?: number, pickedNumbers?: number): string[];
|
|
6
|
+
//# sourceMappingURL=rand_utils.d.ts.map
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
let rand = undefined;
|
|
16
|
+
const MASK = 0x7FFFFFFF;
|
|
17
|
+
export function initRNG() {
|
|
18
|
+
let seed;
|
|
19
|
+
console.log(`Use IDLIZE_SEED env variable to set a seed value.`);
|
|
20
|
+
console.log(`Set IDLIZE_SEED env variable to RANDOM to use a random seed value.`);
|
|
21
|
+
console.log(`IDLIZE_SEED=${process.env.IDLIZE_SEED}`);
|
|
22
|
+
if (process.env.IDLIZE_SEED === undefined) {
|
|
23
|
+
seed = 29;
|
|
24
|
+
console.log(`Env IDLIZE_SEED variable is not.`);
|
|
25
|
+
console.log(`Use predefined seed: ${seed}.`);
|
|
26
|
+
}
|
|
27
|
+
else if (process.env.IDLIZE_SEED == "RANDOM") {
|
|
28
|
+
seed = Math.floor(Math.random() * 4096);
|
|
29
|
+
console.log(`Use random seed: ${seed}`);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
seed = Number(process.env.IDLIZE_SEED);
|
|
33
|
+
console.log(`Use seed: ${seed}`);
|
|
34
|
+
}
|
|
35
|
+
rand = new XorRand(seed);
|
|
36
|
+
}
|
|
37
|
+
class XorRand {
|
|
38
|
+
constructor(seed) {
|
|
39
|
+
this.seed = seed;
|
|
40
|
+
}
|
|
41
|
+
random() {
|
|
42
|
+
let x = this.seed;
|
|
43
|
+
x ^= (x << 13) & MASK;
|
|
44
|
+
x ^= (x >> 17) & MASK;
|
|
45
|
+
x ^= (x << 5) & MASK;
|
|
46
|
+
this.seed = x;
|
|
47
|
+
return x / MASK;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export function randInt(max, min = 0) {
|
|
51
|
+
return Math.floor(rand.random() * (max - min)) + min;
|
|
52
|
+
}
|
|
53
|
+
function randChar(minChar, range) {
|
|
54
|
+
return String.fromCharCode(minChar.charCodeAt(0) + randInt(range));
|
|
55
|
+
}
|
|
56
|
+
export function randString(max) {
|
|
57
|
+
let array = [];
|
|
58
|
+
for (let i = 0; i < max; i++) {
|
|
59
|
+
const range = randInt(3);
|
|
60
|
+
let c = (range == 0)
|
|
61
|
+
? randChar('0', 10)
|
|
62
|
+
: (range == 1)
|
|
63
|
+
? randChar('a', 26)
|
|
64
|
+
: randChar('A', 26);
|
|
65
|
+
array.push(c);
|
|
66
|
+
}
|
|
67
|
+
return array.join('');
|
|
68
|
+
}
|
|
69
|
+
export function pick(keys, gen, pickedNumbers = 3) {
|
|
70
|
+
let values = keys.map(it => gen(it));
|
|
71
|
+
let picked = [];
|
|
72
|
+
if (values.map(it => it.length).some(it => it == 0)) {
|
|
73
|
+
console.log("Empty arguments!");
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
for (let _ = 0; _ < pickedNumbers; _++) {
|
|
77
|
+
let v = [];
|
|
78
|
+
for (let i = 0; i < values.length; i++) {
|
|
79
|
+
let len = values[i].length;
|
|
80
|
+
let index = randInt(len);
|
|
81
|
+
let elem = values[i][index];
|
|
82
|
+
v.push(elem);
|
|
83
|
+
}
|
|
84
|
+
picked.push(v.join(", "));
|
|
85
|
+
}
|
|
86
|
+
return [...new Set(picked)];
|
|
87
|
+
}
|
|
88
|
+
export function pickArray(values, maxLen = 7, pickedNumbers = 3) {
|
|
89
|
+
let picked = ["[]"];
|
|
90
|
+
for (let _ = 0; _ < pickedNumbers; _++) {
|
|
91
|
+
let len = randInt(maxLen);
|
|
92
|
+
let p = [];
|
|
93
|
+
for (let i = 0; i < len; i++) {
|
|
94
|
+
p.push(values[randInt(values.length)]);
|
|
95
|
+
}
|
|
96
|
+
picked.push(`[${p.join(", ")}]`);
|
|
97
|
+
}
|
|
98
|
+
return [...new Set(picked)];
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=rand_utils.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as ts from "typescript";
|
|
2
|
+
import { Language } from './Language';
|
|
3
|
+
export interface NameWithType {
|
|
4
|
+
name?: ts.DeclarationName;
|
|
5
|
+
type?: ts.TypeNode;
|
|
6
|
+
}
|
|
7
|
+
/** True if this is visible outside this file, false otherwise */
|
|
8
|
+
export declare function isNodePublic(node: ts.Node): boolean;
|
|
9
|
+
export declare function nameOrNull(name: ts.EntityName | ts.DeclarationName | undefined): string | undefined;
|
|
10
|
+
export declare function isNamedDeclaration(node: ts.Node): node is ts.NamedDeclaration;
|
|
11
|
+
export declare function asString(node: ts.Node | undefined): string;
|
|
12
|
+
export declare function arrayAt<T>(array: T[] | undefined, index: number): T | undefined;
|
|
13
|
+
export declare function getComment(sourceFile: ts.SourceFile, node: ts.Node): string;
|
|
14
|
+
export declare function getSymbolByNode(typechecker: ts.TypeChecker, node: ts.Node): ts.Symbol | undefined;
|
|
15
|
+
export declare function getDeclarationsByNode(typechecker: ts.TypeChecker, node: ts.Node): ts.Declaration[];
|
|
16
|
+
export declare function findRealDeclarations(typechecker: ts.TypeChecker, node: ts.Node): ts.Declaration[];
|
|
17
|
+
export declare function getExportedDeclarationNameByDecl(declaration: ts.NamedDeclaration): string | undefined;
|
|
18
|
+
export declare function getExportedDeclarationNameByNode(typechecker: ts.TypeChecker, node: ts.Node): string | undefined;
|
|
19
|
+
export declare function isReadonly(modifierLikes: ts.NodeArray<ts.ModifierLike> | undefined): boolean;
|
|
20
|
+
export declare function isExport(modifierLikes: ts.NodeArray<ts.ModifierLike> | undefined): boolean;
|
|
21
|
+
export declare function isAbstract(modifierLikes: ts.NodeArray<ts.ModifierLike> | undefined): boolean;
|
|
22
|
+
export declare function isStatic(modifierLikes: ts.NodeArray<ts.ModifierLike> | undefined): boolean;
|
|
23
|
+
export declare function isAsync(modifierLikes: ts.NodeArray<ts.ModifierLike> | readonly ts.Modifier[] | undefined): boolean;
|
|
24
|
+
export declare function isPrivate(modifierLikes: ts.NodeArray<ts.ModifierLike> | undefined): boolean;
|
|
25
|
+
export declare function isProtected(modifierLikes: ts.NodeArray<ts.ModifierLike> | undefined): boolean;
|
|
26
|
+
export declare function getLineNumberString(sourceFile: ts.SourceFile, position: number): string;
|
|
27
|
+
export declare function isDefined<T>(value: T | null | undefined): value is T;
|
|
28
|
+
export declare function capitalize(string: string): string;
|
|
29
|
+
export declare function capitalizeConstantName(string: string): string;
|
|
30
|
+
export declare function dropLast(text: string, chars: number): string;
|
|
31
|
+
export declare function dropSuffix(text: string, suffix: string): string;
|
|
32
|
+
export type stringOrNone = string | undefined;
|
|
33
|
+
export declare function toSet(option: string | undefined): Set<string>;
|
|
34
|
+
export declare function getOrPut<K, V>(map: Map<K, V>, key: K, create: (key: K) => V): V;
|
|
35
|
+
export declare function indentedBy(input: string, indentedBy: number): string;
|
|
36
|
+
export declare function typeOrUndefined(type: ts.TypeNode): ts.TypeNode;
|
|
37
|
+
export declare function forEachExpanding<T>(array: T[], action: (element: T) => void): void;
|
|
38
|
+
export declare function isTypeParamSuitableType(type: ts.TypeNode): boolean;
|
|
39
|
+
export declare function heritageTypes(typechecker: ts.TypeChecker, clause: ts.HeritageClause): ts.TypeReferenceNode[];
|
|
40
|
+
export declare function heritageDeclarations(typechecker: ts.TypeChecker, clause: ts.HeritageClause): ts.NamedDeclaration[];
|
|
41
|
+
export declare function typeName(type: ts.TypeReferenceNode | ts.TypeQueryNode | ts.ImportTypeNode): string | undefined;
|
|
42
|
+
export declare function typeEntityName(type: ts.TypeReferenceNode | ts.TypeQueryNode | ts.ImportTypeNode): ts.EntityName | undefined;
|
|
43
|
+
export declare function zip<A, B>(left: readonly A[], right: readonly B[]): [A, B][];
|
|
44
|
+
export declare function identNameWithNamespace(node: ts.Node, language: Language): string;
|
|
45
|
+
export declare function identName(node: ts.Node | undefined): string | undefined;
|
|
46
|
+
export declare function identString(node: ts.Identifier | ts.PrivateIdentifier | ts.StringLiteral | ts.QualifiedName | ts.NumericLiteral | ts.ComputedPropertyName | ts.BindingName | undefined): string | undefined;
|
|
47
|
+
export declare const defaultCompilerOptions: ts.CompilerOptions;
|
|
48
|
+
export declare function serializerBaseMethods(): string[];
|
|
49
|
+
export declare function getNameWithoutQualifiersRight(node: ts.EntityName | undefined): string | undefined;
|
|
50
|
+
export declare function getNameWithoutQualifiersLeft(node: ts.EntityName | undefined): string | undefined;
|
|
51
|
+
export declare function snakeCaseToCamelCase(input: string, tailToLowerCase?: boolean): string;
|
|
52
|
+
export declare function toCamelCase(input: string): string;
|
|
53
|
+
export declare function isUpperCase(s: string): boolean;
|
|
54
|
+
export declare function camelCaseToUpperSnakeCase(input: string): string;
|
|
55
|
+
export declare function renameDtsToPeer(fileName: string, language: Language, withFileExtension?: boolean): string;
|
|
56
|
+
export declare function renameDtsToComponent(fileName: string, language: Language, withFileExtension?: boolean): string;
|
|
57
|
+
export declare function renameDtsToInterfaces(fileName: string, language: Language, withFileExtension?: boolean): string;
|
|
58
|
+
export declare function renameClassToBuilderClass(className: string, language: Language, withFileExtension?: boolean): string;
|
|
59
|
+
export declare function renameClassToMaterialized(className: string, language: Language, withFileExtension?: boolean): string;
|
|
60
|
+
export declare function importTypeName(type: ts.ImportTypeNode, asType?: boolean): string;
|
|
61
|
+
export declare function throwException(message: string): never;
|
|
62
|
+
export declare function className(node: ts.ClassDeclaration | ts.InterfaceDeclaration): string;
|
|
63
|
+
/**
|
|
64
|
+
* Add a prefix to an enum value which camel case name coincidence
|
|
65
|
+
* with the the same upper case name for an another enum value
|
|
66
|
+
*/
|
|
67
|
+
export declare function nameEnumValues(enumTarget: ts.EnumDeclaration): string[];
|
|
68
|
+
export declare function groupBy<K, V>(values: V[], selector: (value: V) => K): Map<K, V[]>;
|
|
69
|
+
export declare function removeExt(filename: string): string;
|
|
70
|
+
export declare function warn(message: string): void;
|
|
71
|
+
export declare function hashCodeFromString(value: string): number;
|
|
72
|
+
export declare function forceWriteFile(filePath: string, content: string): void;
|
|
73
|
+
export declare function findVersion(): any;
|
|
74
|
+
export declare function zipMany<T>(...xs: T[][]): Array<Array<T | undefined>>;
|
|
75
|
+
//# sourceMappingURL=util.d.ts.map
|