@idlizer/core 2.1.10-arktscgen-4 → 2.1.10-arktscgen-6
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/Language.d.ts +0 -1
- package/build/lib/src/Language.js +1 -3
- package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +18 -7
- package/build/lib/src/LanguageWriters/ArgConvertors.js +95 -103
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +13 -7
- package/build/lib/src/LanguageWriters/LanguageWriter.js +10 -2
- package/build/lib/src/LanguageWriters/common.d.ts +1 -0
- package/build/lib/src/LanguageWriters/common.js +2 -1
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +0 -1
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +1 -3
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +14 -8
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +88 -36
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +1 -0
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +10 -8
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +1 -1
- package/build/lib/src/LanguageWriters/convertors/KotlinConvertors.js +9 -5
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +4 -4
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +98 -44
- package/build/lib/src/LanguageWriters/index.d.ts +5 -4
- package/build/lib/src/LanguageWriters/index.js +8 -15
- package/build/lib/src/LanguageWriters/nameConvertor.d.ts +2 -0
- package/build/lib/src/LanguageWriters/nameConvertor.js +11 -0
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +2 -0
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +13 -1
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +2 -0
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +8 -2
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +2 -10
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +52 -92
- package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.d.ts +8 -0
- package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.js +75 -27
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +5 -0
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +58 -18
- package/build/lib/src/LibraryInterface.d.ts +0 -1
- package/build/lib/src/config.d.ts +2 -1461
- package/build/lib/src/config.js +16 -32
- package/build/lib/src/configMerge.d.ts +3 -0
- package/build/lib/src/configMerge.js +63 -0
- package/build/lib/src/diagnostictypes.d.ts +1 -5
- package/build/lib/src/diagnostictypes.js +1 -27
- package/build/lib/src/from-idl/DtsPrinter.js +13 -6
- package/build/lib/src/from-idl/IDLLinter.d.ts +3 -4
- package/build/lib/src/from-idl/IDLLinter.js +30 -32
- package/build/lib/src/from-idl/deserialize.d.ts +3 -4
- package/build/lib/src/from-idl/deserialize.js +30 -642
- package/build/lib/src/from-idl/parser.d.ts +20 -2
- package/build/lib/src/from-idl/parser.js +97 -29
- package/build/lib/src/idl/builders.d.ts +43 -0
- package/build/lib/src/idl/builders.js +135 -0
- package/build/lib/src/idl/discriminators.d.ts +53 -0
- package/build/lib/src/idl/discriminators.js +232 -0
- package/build/lib/src/idl/dump.d.ts +48 -0
- package/build/lib/src/idl/dump.js +327 -0
- package/build/lib/src/idl/index.d.ts +9 -0
- package/build/lib/src/idl/index.js +23 -0
- package/build/lib/src/idl/keywords.d.ts +2 -0
- package/build/lib/src/{options.js → idl/keywords.js} +7 -3
- package/build/lib/src/idl/node.d.ts +233 -0
- package/build/lib/src/idl/node.js +103 -0
- package/build/lib/src/idl/stdlib.d.ts +34 -0
- package/build/lib/src/idl/stdlib.js +54 -0
- package/build/lib/src/idl/utils.d.ts +44 -0
- package/build/lib/src/idl/utils.js +215 -0
- package/build/lib/src/idl/visitors.d.ts +15 -0
- package/build/lib/src/idl/visitors.js +593 -0
- package/build/lib/src/index.d.ts +5 -6
- package/build/lib/src/index.js +6 -7
- package/build/lib/src/inheritance.d.ts +0 -2
- package/build/lib/src/inheritance.js +0 -17
- package/build/lib/src/inputPaths.d.ts +11 -0
- package/build/lib/src/inputPaths.js +81 -0
- package/build/lib/src/languageSpecificKeywords.d.ts +0 -1
- package/build/lib/src/languageSpecificKeywords.js +0 -5
- package/build/lib/src/peer-generation/ConflictingDeclarations.d.ts +6 -0
- package/build/lib/src/peer-generation/ConflictingDeclarations.js +43 -0
- package/build/lib/src/peer-generation/LayoutManager.d.ts +3 -1
- package/build/lib/src/peer-generation/LayoutManager.js +15 -0
- package/build/lib/src/peer-generation/Materialized.d.ts +8 -0
- package/build/lib/src/peer-generation/Materialized.js +26 -1
- package/build/lib/src/peer-generation/PeerLibrary.d.ts +10 -18
- package/build/lib/src/peer-generation/PeerLibrary.js +63 -227
- package/build/lib/src/peer-generation/ReferenceResolver.d.ts +6 -1
- package/build/lib/src/peer-generation/ReferenceResolver.js +93 -2
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +6 -0
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +15 -3
- package/build/lib/src/peer-generation/idl/common.d.ts +6 -2
- package/build/lib/src/peer-generation/idl/common.js +7 -7
- package/build/lib/src/peer-generation/isMaterialized.js +2 -3
- package/build/lib/src/peer-generation/modules.js +2 -0
- package/build/lib/src/peer-generation/toDeclaration.d.ts +4 -0
- package/build/lib/src/peer-generation/toDeclaration.js +53 -0
- package/build/lib/src/peer-generation/unions.d.ts +1 -1
- package/build/lib/src/peer-generation/unions.js +15 -7
- package/build/lib/src/resolveNamedNode.d.ts +1 -0
- package/build/lib/src/resolveNamedNode.js +7 -0
- package/build/lib/src/transformers/FqnTransformer.d.ts +1 -1
- package/build/lib/src/transformers/FqnTransformer.js +20 -12
- package/build/lib/src/transformers/GenericTransformer.d.ts +4 -3
- package/build/lib/src/transformers/GenericTransformer.js +252 -158
- package/build/lib/src/transformers/IdlTransformer.d.ts +6 -0
- package/build/lib/src/transformers/IdlTransformer.js +7 -0
- package/build/lib/src/transformers/NullTransformer.d.ts +1 -1
- package/build/lib/src/transformers/NullTransformer.js +27 -21
- package/build/lib/src/transformers/OnSerializeTransformer.d.ts +1 -1
- package/build/lib/src/transformers/OnSerializeTransformer.js +28 -13
- package/build/lib/src/util.d.ts +9 -39
- package/build/lib/src/util.js +65 -369
- package/package.json +44 -49
- package/build/lib/src/LanguageWriters/convertors/JavaConvertors.d.ts +0 -37
- package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +0 -210
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +0 -83
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +0 -295
- package/build/lib/src/from-idl/webidl2-utils.d.ts +0 -21
- package/build/lib/src/from-idl/webidl2-utils.js +0 -87
- package/build/lib/src/idl.d.ts +0 -439
- package/build/lib/src/idl.js +0 -1367
- package/build/lib/src/idlize.d.ts +0 -25
- package/build/lib/src/idlize.js +0 -198
- package/build/lib/src/options.d.ts +0 -13
- package/build/lib/src/peer-generation/BuilderClass.d.ts +0 -20
- package/build/lib/src/peer-generation/BuilderClass.js +0 -68
- package/webidl2.js/dist/webidl2.js +0 -4622
- package/webidl2.js/package.json +0 -55
package/build/lib/src/util.d.ts
CHANGED
|
@@ -1,31 +1,7 @@
|
|
|
1
|
-
import * as ts from "typescript";
|
|
2
1
|
import * as idl from "./idl";
|
|
3
2
|
import { Language } from './Language';
|
|
4
3
|
import { LibraryInterface } from './LibraryInterface';
|
|
5
|
-
export interface NameWithType {
|
|
6
|
-
name?: ts.DeclarationName;
|
|
7
|
-
type?: ts.TypeNode;
|
|
8
|
-
}
|
|
9
|
-
/** True if this is visible outside this file, false otherwise */
|
|
10
|
-
export declare function isNodePublic(node: ts.Node): boolean;
|
|
11
|
-
export declare function nameOrNull(name: ts.EntityName | ts.DeclarationName | undefined): string | undefined;
|
|
12
|
-
export declare function isNamedDeclaration(node: ts.Node): node is ts.NamedDeclaration;
|
|
13
|
-
export declare function asString(node: ts.Node | undefined): string;
|
|
14
4
|
export declare function arrayAt<T>(array: T[] | undefined, index: number): T | undefined;
|
|
15
|
-
export declare function getComment(sourceFile: ts.SourceFile, node: ts.Node): string;
|
|
16
|
-
export declare function getSymbolByNode(typechecker: ts.TypeChecker, node: ts.Node): ts.Symbol | undefined;
|
|
17
|
-
export declare function getDeclarationsByNode(typechecker: ts.TypeChecker, node: ts.Node): ts.Declaration[];
|
|
18
|
-
export declare function findRealDeclarations(typechecker: ts.TypeChecker, node: ts.Node): ts.Declaration[];
|
|
19
|
-
export declare function getExportedDeclarationNameByDecl(declaration: ts.NamedDeclaration): string | undefined;
|
|
20
|
-
export declare function getExportedDeclarationNameByNode(typechecker: ts.TypeChecker, node: ts.Node): string | undefined;
|
|
21
|
-
export declare function isReadonly(modifierLikes: ts.NodeArray<ts.ModifierLike> | undefined): boolean;
|
|
22
|
-
export declare function isExport(modifierLikes: ts.NodeArray<ts.ModifierLike> | undefined): boolean;
|
|
23
|
-
export declare function isAbstract(modifierLikes: ts.NodeArray<ts.ModifierLike> | undefined): boolean;
|
|
24
|
-
export declare function isStatic(modifierLikes: ts.NodeArray<ts.ModifierLike> | undefined): boolean;
|
|
25
|
-
export declare function isAsync(modifierLikes: ts.NodeArray<ts.ModifierLike> | readonly ts.Modifier[] | undefined): boolean;
|
|
26
|
-
export declare function isPrivate(modifierLikes: ts.NodeArray<ts.ModifierLike> | undefined): boolean;
|
|
27
|
-
export declare function isProtected(modifierLikes: ts.NodeArray<ts.ModifierLike> | undefined): boolean;
|
|
28
|
-
export declare function getLineNumberString(sourceFile: ts.SourceFile, position: number): string;
|
|
29
5
|
export declare function isDefined<T>(value: T | null | undefined): value is T;
|
|
30
6
|
export declare function capitalize(string: string): string;
|
|
31
7
|
export declare function capitalizeConstantName(string: string): string;
|
|
@@ -35,22 +11,9 @@ export type stringOrNone = string | undefined;
|
|
|
35
11
|
export declare function toSet(option: string | undefined): Set<string>;
|
|
36
12
|
export declare function getOrPut<K, V>(map: Map<K, V>, key: K, create: (key: K) => V): V;
|
|
37
13
|
export declare function indentedBy(input: string, indentedBy: number): string;
|
|
38
|
-
export declare function typeOrUndefined(type: ts.TypeNode): ts.TypeNode;
|
|
39
14
|
export declare function forEachExpanding<T>(array: T[], action: (element: T) => void): void;
|
|
40
|
-
export declare function isTypeParamSuitableType(type: ts.TypeNode): boolean;
|
|
41
|
-
export declare function heritageTypes(typechecker: ts.TypeChecker, clause: ts.HeritageClause): ts.TypeReferenceNode[];
|
|
42
|
-
export declare function heritageDeclarations(typechecker: ts.TypeChecker, clause: ts.HeritageClause): ts.NamedDeclaration[];
|
|
43
|
-
export declare function typeName(type: ts.TypeReferenceNode | ts.TypeQueryNode | ts.ImportTypeNode): string | undefined;
|
|
44
|
-
export declare function typeEntityName(type: ts.TypeReferenceNode | ts.TypeQueryNode | ts.ImportTypeNode): ts.EntityName | undefined;
|
|
45
15
|
export declare function zip<A, B>(left: readonly A[], right: readonly B[]): [A, B][];
|
|
46
16
|
export declare function zipStrip<A, B>(left: readonly A[], right: readonly B[]): [A, B][];
|
|
47
|
-
export declare function identNameWithNamespace(node: ts.Node, language: Language): string;
|
|
48
|
-
export declare function identName(node: ts.Node | undefined): string | undefined;
|
|
49
|
-
export declare function identString(node: ts.Identifier | ts.PrivateIdentifier | ts.StringLiteral | ts.QualifiedName | ts.NumericLiteral | ts.ComputedPropertyName | ts.BindingName | undefined): string | undefined;
|
|
50
|
-
export declare const defaultCompilerOptions: ts.CompilerOptions;
|
|
51
|
-
export declare function serializerBaseMethods(): string[];
|
|
52
|
-
export declare function getNameWithoutQualifiersRight(node: ts.EntityName | undefined): string | undefined;
|
|
53
|
-
export declare function getNameWithoutQualifiersLeft(node: ts.EntityName | undefined): string | undefined;
|
|
54
17
|
export declare function snakeCaseToCamelCase(input: string, tailToLowerCase?: boolean): string;
|
|
55
18
|
export declare function toCamelCase(input: string): string;
|
|
56
19
|
export declare function isUpperCase(s: string): boolean;
|
|
@@ -61,9 +24,7 @@ export declare function renameDtsToComponent(fileName: string, language: Languag
|
|
|
61
24
|
export declare function renameDtsToInterfaces(fileName: string, language: Language, withFileExtension?: boolean): string;
|
|
62
25
|
export declare function renameClassToBuilderClass(className: string, language: Language, withFileExtension?: boolean): string;
|
|
63
26
|
export declare function renameClassToMaterialized(className: string, language: Language, withFileExtension?: boolean): string;
|
|
64
|
-
export declare function importTypeName(type: ts.ImportTypeNode, asType?: boolean): string;
|
|
65
27
|
export declare function throwException(message: string): never;
|
|
66
|
-
export declare function className(node: ts.ClassDeclaration | ts.InterfaceDeclaration): string;
|
|
67
28
|
/**
|
|
68
29
|
* Add a prefix to an enum value which camel case name coincidence
|
|
69
30
|
* with the the same upper case name for an another enum value
|
|
@@ -96,9 +57,18 @@ export declare function getExtractor(target: idl.IDLInterface, lang: Language, t
|
|
|
96
57
|
receiver?: string;
|
|
97
58
|
method: string;
|
|
98
59
|
};
|
|
60
|
+
export declare function getInitializerFeature(lang: Language): string;
|
|
61
|
+
export declare function getInitializerDefaultValue(decl: idl.IDLEntry, lang: Language): string;
|
|
62
|
+
export declare function getSyntheticTypesFileName(): string;
|
|
99
63
|
export declare function getTransformer(library: LibraryInterface, from: idl.IDLNode, to: idl.IDLNode): {
|
|
100
64
|
receiver?: string;
|
|
101
65
|
method: string;
|
|
102
66
|
};
|
|
67
|
+
export declare function removePoints(s: string): string;
|
|
68
|
+
export declare function scanDirectory(dir: string, fileFilter: (file: string) => boolean, recursive?: boolean): string[];
|
|
69
|
+
export declare function scanInputDirs(inputDirs: string[]): string[];
|
|
70
|
+
export declare function scanInputDirs(inputDirs: string[], fileExtension: string): string[];
|
|
71
|
+
export declare function scanInputDirs(inputDirs: string[], fileFilter: (file: string) => boolean, recursive: boolean): string[];
|
|
72
|
+
export declare function consoleWarn(message: string): void;
|
|
103
73
|
export {};
|
|
104
74
|
//# sourceMappingURL=util.d.ts.map
|
package/build/lib/src/util.js
CHANGED
|
@@ -14,137 +14,13 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import * as path from 'path';
|
|
16
16
|
import * as fs from "fs";
|
|
17
|
-
import * as ts from "typescript";
|
|
18
17
|
import * as idl from "./idl";
|
|
19
18
|
import { Language } from './Language';
|
|
20
19
|
import { getModuleFor, isInExternalModule } from './peer-generation/modules';
|
|
21
20
|
import { getInternalClassName, getInternalClassQualifiedName } from './peer-generation/Materialized';
|
|
22
|
-
/** True if this is visible outside this file, false otherwise */
|
|
23
|
-
export function isNodePublic(node) {
|
|
24
|
-
return (ts.getCombinedModifierFlags(node) & ts.ModifierFlags.Public) !== 0;
|
|
25
|
-
}
|
|
26
|
-
export function nameOrNull(name) {
|
|
27
|
-
if (name == undefined)
|
|
28
|
-
return undefined;
|
|
29
|
-
if (ts.isIdentifier(name)) {
|
|
30
|
-
return ts.idText(name);
|
|
31
|
-
}
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
export function isNamedDeclaration(node) {
|
|
35
|
-
return ("name" in node);
|
|
36
|
-
}
|
|
37
|
-
export function asString(node) {
|
|
38
|
-
if (node === undefined)
|
|
39
|
-
return "undefined node";
|
|
40
|
-
if (ts.isIdentifier(node))
|
|
41
|
-
return ts.idText(node);
|
|
42
|
-
if (ts.isQualifiedName(node))
|
|
43
|
-
return `${identName(node.left)}.${identName(node.right)}`;
|
|
44
|
-
if (ts.isStringLiteral(node))
|
|
45
|
-
return node.text;
|
|
46
|
-
if (ts.isTypeReferenceNode(node))
|
|
47
|
-
return `${ts.SyntaxKind[node.kind]}(${asString(node.typeName)})`;
|
|
48
|
-
if (ts.isImportTypeNode(node))
|
|
49
|
-
return `${ts.SyntaxKind[node.kind]}(${asString(node.qualifier)})`;
|
|
50
|
-
if (isNamedDeclaration(node)) {
|
|
51
|
-
if (node.name === undefined) {
|
|
52
|
-
return `${ts.SyntaxKind[node.kind]}(undefined name)`;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
return `${ts.SyntaxKind[node.kind]}(${asString(node.name)})`;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
return `${ts.SyntaxKind[node.kind]}`;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
21
|
export function arrayAt(array, index) {
|
|
63
22
|
return array ? array[index >= 0 ? index : array.length + index] : undefined;
|
|
64
23
|
}
|
|
65
|
-
export function getComment(sourceFile, node) {
|
|
66
|
-
const commentRanges = ts.getLeadingCommentRanges(sourceFile.getFullText(), node.getFullStart());
|
|
67
|
-
if (!commentRanges)
|
|
68
|
-
return "";
|
|
69
|
-
return commentRanges
|
|
70
|
-
.map(range => sourceFile.getFullText().slice(range.pos, range.end))
|
|
71
|
-
.join("\n");
|
|
72
|
-
}
|
|
73
|
-
export function getSymbolByNode(typechecker, node) {
|
|
74
|
-
return typechecker.getSymbolAtLocation(node);
|
|
75
|
-
}
|
|
76
|
-
export function getDeclarationsByNode(typechecker, node) {
|
|
77
|
-
var _a, _b;
|
|
78
|
-
return (_b = (_a = getSymbolByNode(typechecker, node)) === null || _a === void 0 ? void 0 : _a.getDeclarations()) !== null && _b !== void 0 ? _b : [];
|
|
79
|
-
}
|
|
80
|
-
export function findRealDeclarations(typechecker, node) {
|
|
81
|
-
const declarations = getDeclarationsByNode(typechecker, node);
|
|
82
|
-
const first = declarations[0];
|
|
83
|
-
if (first && ts.isExportAssignment(first)) {
|
|
84
|
-
return findRealDeclarations(typechecker, first.expression);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
return declarations;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
export function getExportedDeclarationNameByDecl(declaration) {
|
|
91
|
-
let declName = declaration.name ? ts.idText(declaration.name) : undefined;
|
|
92
|
-
let current = declaration;
|
|
93
|
-
while (current != undefined && !ts.isSourceFile(current)) {
|
|
94
|
-
current = current.parent;
|
|
95
|
-
}
|
|
96
|
-
let source = current;
|
|
97
|
-
let exportedName = declName;
|
|
98
|
-
source.forEachChild(it => {
|
|
99
|
-
if (ts.isExportDeclaration(it)) {
|
|
100
|
-
let clause = it.exportClause;
|
|
101
|
-
if (clause && ts.isNamedExportBindings(clause) && ts.isNamedExports(clause)) {
|
|
102
|
-
clause.elements.forEach(it => {
|
|
103
|
-
let propName = it.propertyName ? ts.idText(it.propertyName) : undefined;
|
|
104
|
-
let property = ts.idText(it.name);
|
|
105
|
-
if (propName == declName) {
|
|
106
|
-
exportedName = property;
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
return exportedName;
|
|
113
|
-
}
|
|
114
|
-
export function getExportedDeclarationNameByNode(typechecker, node) {
|
|
115
|
-
let declarations = getDeclarationsByNode(typechecker, node);
|
|
116
|
-
if (declarations.length == 0)
|
|
117
|
-
return undefined;
|
|
118
|
-
return getExportedDeclarationNameByDecl(declarations[0]);
|
|
119
|
-
}
|
|
120
|
-
function hasModifier(modifierLikes, modifier) {
|
|
121
|
-
return (modifierLikes === null || modifierLikes === void 0 ? void 0 : modifierLikes.find(it => it.kind === modifier)) != undefined;
|
|
122
|
-
}
|
|
123
|
-
export function isReadonly(modifierLikes) {
|
|
124
|
-
return hasModifier(modifierLikes, ts.SyntaxKind.ReadonlyKeyword);
|
|
125
|
-
}
|
|
126
|
-
export function isExport(modifierLikes) {
|
|
127
|
-
return hasModifier(modifierLikes, ts.SyntaxKind.ExportKeyword);
|
|
128
|
-
}
|
|
129
|
-
export function isAbstract(modifierLikes) {
|
|
130
|
-
return hasModifier(modifierLikes, ts.SyntaxKind.AbstractKeyword);
|
|
131
|
-
}
|
|
132
|
-
export function isStatic(modifierLikes) {
|
|
133
|
-
return hasModifier(modifierLikes, ts.SyntaxKind.StaticKeyword);
|
|
134
|
-
}
|
|
135
|
-
export function isAsync(modifierLikes) {
|
|
136
|
-
return hasModifier(modifierLikes, ts.SyntaxKind.AsyncKeyword);
|
|
137
|
-
}
|
|
138
|
-
export function isPrivate(modifierLikes) {
|
|
139
|
-
return hasModifier(modifierLikes, ts.SyntaxKind.PrivateKeyword);
|
|
140
|
-
}
|
|
141
|
-
export function isProtected(modifierLikes) {
|
|
142
|
-
return hasModifier(modifierLikes, ts.SyntaxKind.ProtectedKeyword);
|
|
143
|
-
}
|
|
144
|
-
export function getLineNumberString(sourceFile, position) {
|
|
145
|
-
let pos = ts.getLineAndCharacterOfPosition(sourceFile, position);
|
|
146
|
-
return `${pos.line + 1}:${pos.character}`;
|
|
147
|
-
}
|
|
148
24
|
export function isDefined(value) {
|
|
149
25
|
return !!value;
|
|
150
26
|
}
|
|
@@ -191,22 +67,6 @@ export function indentedBy(input, indentedBy) {
|
|
|
191
67
|
return "";
|
|
192
68
|
}
|
|
193
69
|
}
|
|
194
|
-
export function typeOrUndefined(type) {
|
|
195
|
-
var _a;
|
|
196
|
-
let needUndefined = true;
|
|
197
|
-
if (ts.isUnionTypeNode(type)) {
|
|
198
|
-
(_a = type.types) === null || _a === void 0 ? void 0 : _a.forEach(it => {
|
|
199
|
-
if (it.kind == ts.SyntaxKind.UndefinedKeyword)
|
|
200
|
-
needUndefined = false;
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
if (!needUndefined)
|
|
204
|
-
return type;
|
|
205
|
-
return ts.factory.createUnionTypeNode([
|
|
206
|
-
type,
|
|
207
|
-
ts.factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword)
|
|
208
|
-
]);
|
|
209
|
-
}
|
|
210
70
|
export function forEachExpanding(array, action) {
|
|
211
71
|
let i = 0;
|
|
212
72
|
while (true) {
|
|
@@ -216,56 +76,6 @@ export function forEachExpanding(array, action) {
|
|
|
216
76
|
i += 1;
|
|
217
77
|
}
|
|
218
78
|
}
|
|
219
|
-
export function isTypeParamSuitableType(type) {
|
|
220
|
-
if (ts.isTypeReferenceNode(type)) {
|
|
221
|
-
return !['boolean', 'number', 'string', 'undefined', 'any'].includes(type.typeName.getText());
|
|
222
|
-
}
|
|
223
|
-
return false;
|
|
224
|
-
}
|
|
225
|
-
export function heritageTypes(typechecker, clause) {
|
|
226
|
-
return clause
|
|
227
|
-
.types
|
|
228
|
-
.map(it => {
|
|
229
|
-
let type = typechecker.getTypeAtLocation(it.expression);
|
|
230
|
-
let typeNode = typechecker.typeToTypeNode(type, undefined, ts.NodeBuilderFlags.NoTruncation);
|
|
231
|
-
if (typeNode && ts.isTypeReferenceNode(typeNode))
|
|
232
|
-
return typeNode;
|
|
233
|
-
return undefined;
|
|
234
|
-
})
|
|
235
|
-
.filter(it => it != undefined);
|
|
236
|
-
}
|
|
237
|
-
export function heritageDeclarations(typechecker, clause) {
|
|
238
|
-
return clause
|
|
239
|
-
.types
|
|
240
|
-
.map(it => {
|
|
241
|
-
var _a;
|
|
242
|
-
let decls = getDeclarationsByNode(typechecker, it.expression);
|
|
243
|
-
return (_a = decls[0]) !== null && _a !== void 0 ? _a : undefined;
|
|
244
|
-
})
|
|
245
|
-
.filter(isDefined);
|
|
246
|
-
}
|
|
247
|
-
export function typeName(type) {
|
|
248
|
-
const entityName = typeEntityName(type);
|
|
249
|
-
if (!entityName)
|
|
250
|
-
return undefined;
|
|
251
|
-
if (ts.isIdentifier(entityName))
|
|
252
|
-
return ts.idText(entityName);
|
|
253
|
-
if (ts.isQualifiedName(entityName)) {
|
|
254
|
-
// a.b.c is QualifiedName((QualifiedName a, b), c) so the right one is always an Identifier?
|
|
255
|
-
if (!ts.isIdentifier(entityName.right))
|
|
256
|
-
throw new Error(`Unexpected right of QualifiedName ${asString(entityName.right)}`);
|
|
257
|
-
return ts.idText(entityName.right);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
export function typeEntityName(type) {
|
|
261
|
-
if (ts.isTypeReferenceNode(type))
|
|
262
|
-
return type.typeName;
|
|
263
|
-
if (ts.isTypeQueryNode(type))
|
|
264
|
-
return type.exprName;
|
|
265
|
-
if (ts.isImportTypeNode(type))
|
|
266
|
-
return type.qualifier;
|
|
267
|
-
throw new Error("unsupported");
|
|
268
|
-
}
|
|
269
79
|
export function zip(left, right) {
|
|
270
80
|
if (left.length != right.length)
|
|
271
81
|
throw new Error("Arrays of different length");
|
|
@@ -278,178 +88,6 @@ export function zipStrip(left, right) {
|
|
|
278
88
|
}
|
|
279
89
|
return result;
|
|
280
90
|
}
|
|
281
|
-
export function identNameWithNamespace(node, language) {
|
|
282
|
-
let parent = node.parent;
|
|
283
|
-
while (parent && !ts.isModuleDeclaration(parent))
|
|
284
|
-
parent = parent.parent;
|
|
285
|
-
if (parent) {
|
|
286
|
-
const separator = language === Language.CPP ? '_' : '.';
|
|
287
|
-
return `${identName(parent.name)}${separator}${identName(node)}`;
|
|
288
|
-
}
|
|
289
|
-
else {
|
|
290
|
-
return identName(node);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
export function identName(node) {
|
|
294
|
-
if (!node)
|
|
295
|
-
return undefined;
|
|
296
|
-
if (node.kind == ts.SyntaxKind.AnyKeyword)
|
|
297
|
-
return `any`;
|
|
298
|
-
if (node.kind == ts.SyntaxKind.ObjectKeyword)
|
|
299
|
-
return `object`;
|
|
300
|
-
if (node.kind == ts.SyntaxKind.StringKeyword)
|
|
301
|
-
return `string`;
|
|
302
|
-
if (node.kind == ts.SyntaxKind.BooleanKeyword)
|
|
303
|
-
return `boolean`;
|
|
304
|
-
if (node.kind == ts.SyntaxKind.BigIntKeyword)
|
|
305
|
-
return `bigint`;
|
|
306
|
-
if (node.kind == ts.SyntaxKind.NumberKeyword)
|
|
307
|
-
return `number`;
|
|
308
|
-
if (node.kind == ts.SyntaxKind.VoidKeyword)
|
|
309
|
-
return `void`;
|
|
310
|
-
if (node.kind == ts.SyntaxKind.UndefinedKeyword)
|
|
311
|
-
return `undefined`;
|
|
312
|
-
if (ts.isThisTypeNode(node)) {
|
|
313
|
-
return 'this';
|
|
314
|
-
}
|
|
315
|
-
if (ts.isVariableDeclaration(node)) {
|
|
316
|
-
return identString(node.name);
|
|
317
|
-
}
|
|
318
|
-
if (ts.isTypeReferenceNode(node)) {
|
|
319
|
-
return identString(node.typeName);
|
|
320
|
-
}
|
|
321
|
-
if (ts.isArrayTypeNode(node)) {
|
|
322
|
-
return `Array`;
|
|
323
|
-
}
|
|
324
|
-
if (ts.isQualifiedName(node)) {
|
|
325
|
-
return identName(node.right);
|
|
326
|
-
}
|
|
327
|
-
if (ts.isModuleDeclaration(node)) {
|
|
328
|
-
return identString(node.name);
|
|
329
|
-
}
|
|
330
|
-
if (ts.isFunctionDeclaration(node)) {
|
|
331
|
-
return identString(node.name);
|
|
332
|
-
}
|
|
333
|
-
if (ts.isPropertyDeclaration(node)) {
|
|
334
|
-
// TODO: mention parent's name
|
|
335
|
-
return identString(node.name);
|
|
336
|
-
}
|
|
337
|
-
if (ts.isInterfaceDeclaration(node)) {
|
|
338
|
-
return identString(node.name);
|
|
339
|
-
}
|
|
340
|
-
if (ts.isClassDeclaration(node)) {
|
|
341
|
-
return identString(node.name);
|
|
342
|
-
}
|
|
343
|
-
if (ts.isMethodDeclaration(node)) {
|
|
344
|
-
return identString(node.name);
|
|
345
|
-
}
|
|
346
|
-
if (ts.isEnumDeclaration(node)) {
|
|
347
|
-
return identString(node.name);
|
|
348
|
-
}
|
|
349
|
-
if (ts.isEnumMember(node)) {
|
|
350
|
-
return identString(node.name);
|
|
351
|
-
}
|
|
352
|
-
if (ts.isComputedPropertyName(node)) {
|
|
353
|
-
return identString(node);
|
|
354
|
-
}
|
|
355
|
-
if (ts.isExportAssignment(node)) {
|
|
356
|
-
return node.expression.getText();
|
|
357
|
-
}
|
|
358
|
-
if (ts.isUnionTypeNode(node)) {
|
|
359
|
-
return `UnionType`;
|
|
360
|
-
}
|
|
361
|
-
if (ts.isFunctionTypeNode(node)) {
|
|
362
|
-
return `FunctionType`;
|
|
363
|
-
}
|
|
364
|
-
if (ts.isIdentifier(node))
|
|
365
|
-
return identString(node);
|
|
366
|
-
if (ts.isImportTypeNode(node))
|
|
367
|
-
return `imported ${identString(node.qualifier)}`;
|
|
368
|
-
if (ts.isTypeLiteralNode(node))
|
|
369
|
-
return `TypeLiteral`;
|
|
370
|
-
if (ts.isTupleTypeNode(node))
|
|
371
|
-
return `TupleType`;
|
|
372
|
-
if (ts.isIndexSignatureDeclaration(node))
|
|
373
|
-
return `IndexSignature`;
|
|
374
|
-
if (ts.isIndexedAccessTypeNode(node))
|
|
375
|
-
return `IndexedAccess`;
|
|
376
|
-
if (ts.isTemplateLiteralTypeNode(node))
|
|
377
|
-
return `TemplateLiteral`;
|
|
378
|
-
if (ts.isParameter(node))
|
|
379
|
-
return `Parameter`;
|
|
380
|
-
if (ts.isParenthesizedTypeNode(node))
|
|
381
|
-
return identName(node.type);
|
|
382
|
-
if (ts.isIntersectionTypeNode(node))
|
|
383
|
-
return node.types.map(it => identName(it)).join("&");
|
|
384
|
-
if (node.kind === ts.SyntaxKind.UnknownKeyword)
|
|
385
|
-
return `UnknownKeyword`;
|
|
386
|
-
throw new Error(`Unknown: ${ts.SyntaxKind[node.kind]}`);
|
|
387
|
-
}
|
|
388
|
-
export function identString(node) {
|
|
389
|
-
if (!node)
|
|
390
|
-
return undefined;
|
|
391
|
-
if (ts.isStringLiteral(node))
|
|
392
|
-
return node.text;
|
|
393
|
-
if (ts.isNumericLiteral(node))
|
|
394
|
-
return node.text;
|
|
395
|
-
if (ts.isIdentifier(node))
|
|
396
|
-
return ts.idText(node);
|
|
397
|
-
if (ts.isQualifiedName(node))
|
|
398
|
-
return `${identString(node.left)}.${identName(node.right)}`;
|
|
399
|
-
if (ts.isComputedPropertyName(node))
|
|
400
|
-
return "<computed property>";
|
|
401
|
-
throw new Error("Unknown");
|
|
402
|
-
}
|
|
403
|
-
export const defaultCompilerOptions = {
|
|
404
|
-
target: ts.ScriptTarget.ES5,
|
|
405
|
-
module: ts.ModuleKind.CommonJS,
|
|
406
|
-
noLib: true,
|
|
407
|
-
types: []
|
|
408
|
-
};
|
|
409
|
-
export function serializerBaseMethods() {
|
|
410
|
-
const program = ts.createProgram([
|
|
411
|
-
"./utils/ts/SerializerBase.ts",
|
|
412
|
-
"./utils/ts/types.ts",
|
|
413
|
-
], defaultCompilerOptions);
|
|
414
|
-
const serializerDecl = program.getSourceFiles()
|
|
415
|
-
.find(it => it.fileName.includes("SerializerBase"));
|
|
416
|
-
// TODO: pack classes with npm package
|
|
417
|
-
if (serializerDecl === undefined)
|
|
418
|
-
return [];
|
|
419
|
-
const methods = [];
|
|
420
|
-
visit(serializerDecl);
|
|
421
|
-
return methods;
|
|
422
|
-
function visit(node) {
|
|
423
|
-
if (ts.isSourceFile(node))
|
|
424
|
-
node.statements.forEach(visit);
|
|
425
|
-
if (ts.isClassDeclaration(node))
|
|
426
|
-
node.members.filter(ts.isMethodDeclaration).forEach(visit);
|
|
427
|
-
if (ts.isMethodDeclaration(node))
|
|
428
|
-
methods.push(node.name.getText(serializerDecl));
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
export function getNameWithoutQualifiersRight(node) {
|
|
432
|
-
if (!node)
|
|
433
|
-
return undefined;
|
|
434
|
-
if (ts.isQualifiedName(node)) {
|
|
435
|
-
return identName(node.right);
|
|
436
|
-
}
|
|
437
|
-
if (ts.isIdentifier(node)) {
|
|
438
|
-
return identName(node);
|
|
439
|
-
}
|
|
440
|
-
throw new Error("Impossible");
|
|
441
|
-
}
|
|
442
|
-
export function getNameWithoutQualifiersLeft(node) {
|
|
443
|
-
if (!node)
|
|
444
|
-
return undefined;
|
|
445
|
-
if (ts.isQualifiedName(node)) {
|
|
446
|
-
return identName(node.left);
|
|
447
|
-
}
|
|
448
|
-
if (ts.isIdentifier(node)) {
|
|
449
|
-
return identName(node);
|
|
450
|
-
}
|
|
451
|
-
throw new Error("Impossible");
|
|
452
|
-
}
|
|
453
91
|
export function snakeCaseToCamelCase(input, tailToLowerCase = false) {
|
|
454
92
|
return input
|
|
455
93
|
.split("_")
|
|
@@ -550,16 +188,9 @@ export function renameClassToMaterialized(className, language, withFileExtension
|
|
|
550
188
|
}
|
|
551
189
|
return renamed;
|
|
552
190
|
}
|
|
553
|
-
export function importTypeName(type, asType = false) {
|
|
554
|
-
return asType ? "object" : identName(type.qualifier);
|
|
555
|
-
}
|
|
556
191
|
export function throwException(message) {
|
|
557
192
|
throw new Error(message);
|
|
558
193
|
}
|
|
559
|
-
export function className(node) {
|
|
560
|
-
var _a;
|
|
561
|
-
return (_a = nameOrNull(node.name)) !== null && _a !== void 0 ? _a : throwException(`Nameless component ${asString(node)}`);
|
|
562
|
-
}
|
|
563
194
|
/**
|
|
564
195
|
* Add a prefix to an enum value which camel case name coincidence
|
|
565
196
|
* with the the same upper case name for an another enum value
|
|
@@ -720,6 +351,21 @@ export function getExtractor(target, lang, toPtr = true) {
|
|
|
720
351
|
const method = toPtr ? `to${extractorClass}Ptr` : `from${extractorClass}Ptr`;
|
|
721
352
|
return { receiver, method };
|
|
722
353
|
}
|
|
354
|
+
export function getInitializerFeature(lang) {
|
|
355
|
+
// TBD: update code for KT and CJ
|
|
356
|
+
return "initializers";
|
|
357
|
+
}
|
|
358
|
+
export function getInitializerDefaultValue(decl, lang) {
|
|
359
|
+
const parent = decl.parent;
|
|
360
|
+
const fqn = parent && idl.isProperty(decl)
|
|
361
|
+
? `${idl.getFQName(parent)}NS.${decl.name}`
|
|
362
|
+
: idl.getFQName(decl);
|
|
363
|
+
// TBD: update code for KT and CJ
|
|
364
|
+
return `${getInitializerFeature(lang)}.${fqn}`;
|
|
365
|
+
}
|
|
366
|
+
export function getSyntheticTypesFileName() {
|
|
367
|
+
return "synthetic_types";
|
|
368
|
+
}
|
|
723
369
|
export function getTransformer(library, from, to) {
|
|
724
370
|
const convertor = library.createTypeNameConvertor(Language.CPP);
|
|
725
371
|
return {
|
|
@@ -727,4 +373,54 @@ export function getTransformer(library, from, to) {
|
|
|
727
373
|
method: `transform_${convertor.convert(from)}_to_${convertor.convert(to)}`
|
|
728
374
|
};
|
|
729
375
|
}
|
|
376
|
+
export function removePoints(s) {
|
|
377
|
+
return s.split(/[\.\-]/g).join('_');
|
|
378
|
+
}
|
|
379
|
+
export function scanDirectory(dir, fileFilter, recursive = false) {
|
|
380
|
+
const dirsToVisit = [path.resolve(dir)];
|
|
381
|
+
const result = [];
|
|
382
|
+
while (dirsToVisit.length > 0) {
|
|
383
|
+
let dir = dirsToVisit.pop();
|
|
384
|
+
let dirents = fs.readdirSync(dir, { withFileTypes: true });
|
|
385
|
+
for (const entry of dirents) {
|
|
386
|
+
const fullPath = path.join(dir, entry.name);
|
|
387
|
+
if (entry.isFile()) {
|
|
388
|
+
if (fileFilter(fullPath)) {
|
|
389
|
+
result.push(fullPath);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
else if (recursive && entry.isDirectory()) {
|
|
393
|
+
dirsToVisit.push(fullPath);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return result;
|
|
398
|
+
}
|
|
399
|
+
export function scanInputDirs(inputDirs, fileFilter = undefined, recursive = false) {
|
|
400
|
+
if (typeof fileFilter === 'undefined')
|
|
401
|
+
return scanInputDirs(inputDirs, (_) => true, recursive);
|
|
402
|
+
if (typeof fileFilter === 'string')
|
|
403
|
+
return scanInputDirs(inputDirs, (file) => file.endsWith(fileFilter), recursive);
|
|
404
|
+
const resolvedInputDirs = inputDirs.map(dir => path.resolve(dir));
|
|
405
|
+
console.log("Resolved input directories:", resolvedInputDirs);
|
|
406
|
+
return resolvedInputDirs.flatMap(dir => {
|
|
407
|
+
if (fs.existsSync(dir) && fs.statSync(dir).isDirectory()) {
|
|
408
|
+
console.log(`Processing all definitions from directory: ${dir}`);
|
|
409
|
+
return scanDirectory(dir, fileFilter, recursive);
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
console.warn(`Warning: Directory does not exist or is not a directory: ${dir}`);
|
|
413
|
+
return [];
|
|
414
|
+
}
|
|
415
|
+
}).sort((a, b) => {
|
|
416
|
+
return path.basename(a).localeCompare(path.basename(b));
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
const printedWarnMessages = new Set();
|
|
420
|
+
export function consoleWarn(message) {
|
|
421
|
+
if (printedWarnMessages.has(message))
|
|
422
|
+
return;
|
|
423
|
+
printedWarnMessages.add(message);
|
|
424
|
+
console.warn(message);
|
|
425
|
+
}
|
|
730
426
|
//# sourceMappingURL=util.js.map
|
package/package.json
CHANGED
|
@@ -1,53 +1,48 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
"name": "@idlizer/core",
|
|
3
|
+
"version": "2.1.10-arktscgen-6",
|
|
4
|
+
"description": "",
|
|
5
|
+
"types": "build/lib/src/index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": [
|
|
8
|
+
"./build/lib/src/index.js"
|
|
9
|
+
],
|
|
10
|
+
"./idl": [
|
|
11
|
+
"./build/lib/src/idl/index.js"
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
"typesVersions": {
|
|
15
|
+
"*": {
|
|
16
|
+
"idl": [
|
|
17
|
+
"build/lib/src/idl/index.d.ts"
|
|
18
|
+
],
|
|
19
|
+
"*": [
|
|
20
|
+
"build/lib/src/index.d.ts"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"build/lib/**/*.js",
|
|
26
|
+
"build/lib/**/*.d.ts"
|
|
9
27
|
],
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
|
|
28
|
+
"engines": {
|
|
29
|
+
"npm": ">= 8",
|
|
30
|
+
"node": ">= 18"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [],
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@koalaui/harness": "1.7.6+devel",
|
|
35
|
+
"@koalaui/ets-tsc": "4.9.5-r5",
|
|
36
|
+
"mocha": "^9.2.2",
|
|
37
|
+
"ts-node": "^10.9.2",
|
|
38
|
+
"typescript": "4.9.5",
|
|
39
|
+
"@types/node": "^18.0.0",
|
|
40
|
+
"rimraf": "^6.0.1"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"test": "mocha",
|
|
44
|
+
"clean": "rimraf -g build",
|
|
45
|
+
"compile:self": "tsc -b .",
|
|
46
|
+
"compile": "npm run compile:self"
|
|
22
47
|
}
|
|
23
|
-
},
|
|
24
|
-
"files": [
|
|
25
|
-
"build/lib/**/*.js",
|
|
26
|
-
"build/lib/**/*.d.ts",
|
|
27
|
-
"webidl2.js/dist/**/*.js",
|
|
28
|
-
"webidl2.js/package.json"
|
|
29
|
-
],
|
|
30
|
-
"engines": {
|
|
31
|
-
"npm": ">= 8",
|
|
32
|
-
"node": ">= 18"
|
|
33
|
-
},
|
|
34
|
-
"keywords": [],
|
|
35
|
-
"dependencies": {
|
|
36
|
-
"typescript": "4.9.5"
|
|
37
|
-
},
|
|
38
|
-
"devDependencies": {
|
|
39
|
-
"@koalaui/harness": "1.7.6+devel",
|
|
40
|
-
"@koalaui/ets-tsc": "4.9.5-r5",
|
|
41
|
-
"@types/mocha": "^9.1.0",
|
|
42
|
-
"mocha": "^9.2.2",
|
|
43
|
-
"ts-node": "^10.9.2",
|
|
44
|
-
"@koalaui/interop": "1.7.9",
|
|
45
|
-
"@types/node": "^18.0.0"
|
|
46
|
-
},
|
|
47
|
-
"scripts": {
|
|
48
|
-
"test": "mocha",
|
|
49
|
-
"clean": "rimraf -g build",
|
|
50
|
-
"compile:self": "tsc -b .",
|
|
51
|
-
"compile": "npm run compile:self"
|
|
52
|
-
}
|
|
53
48
|
}
|