@idlizer/core 2.1.10-arktscgen-5 → 2.1.10-arktscgen-7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/lib/src/Language.js +1 -1
- package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +16 -6
- package/build/lib/src/LanguageWriters/ArgConvertors.js +80 -92
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +8 -7
- package/build/lib/src/LanguageWriters/LanguageWriter.js +35 -22
- 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/CppConvertors.d.ts +7 -1
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +53 -15
- 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/TSConvertors.js +26 -14
- package/build/lib/src/LanguageWriters/index.d.ts +4 -3
- package/build/lib/src/LanguageWriters/index.js +9 -11
- 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/CppLanguageWriter.js +1 -1
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +2 -22
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +34 -113
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +3 -0
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +33 -9
- 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 +12 -5
- 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 +29 -641
- 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 +4 -2
- package/build/lib/src/index.js +5 -3
- 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/LayoutManager.d.ts +1 -1
- package/build/lib/src/peer-generation/Materialized.d.ts +8 -2
- package/build/lib/src/peer-generation/Materialized.js +24 -12
- package/build/lib/src/peer-generation/PeerLibrary.d.ts +10 -15
- package/build/lib/src/peer-generation/PeerLibrary.js +35 -215
- 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/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 +5 -0
- package/build/lib/src/util.js +25 -0
- package/package.json +6 -7
- 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 -85
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +0 -306
- 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 -444
- package/build/lib/src/idl.js +0 -1385
- 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
|
@@ -1,21 +1,248 @@
|
|
|
1
1
|
import { generatorConfiguration } from "../config";
|
|
2
2
|
import { toIdlType } from "../from-idl/deserialize";
|
|
3
3
|
import * as idl from "../idl";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { Language } from "../Language";
|
|
5
|
+
import { StructureNameConvertor } from "../LanguageWriters/convertors/CppConvertors";
|
|
6
6
|
import { isMaterialized } from "../peer-generation/isMaterialized";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
import { LayoutManager } from "../peer-generation/LayoutManager";
|
|
8
|
+
import { createCachedReferenceResolver } from "../peer-generation/ReferenceResolver";
|
|
9
|
+
import { toDeclaration } from "../peer-generation/toDeclaration";
|
|
10
|
+
import { IdlTransformer } from "./IdlTransformer";
|
|
11
|
+
export function genericsTransformer(files, options) {
|
|
12
|
+
const optionsResolver = createCachedReferenceResolver(files);
|
|
13
|
+
options.ignore.push(ignoreConfigRule(options.ignoreGenerics), createIgnoreMaterializedRule(optionsResolver), createIgnoreResourceRule(optionsResolver));
|
|
14
|
+
const defaultsGenericsTransformer = new DefaultGenericsTransformer(createCachedReferenceResolver(files));
|
|
15
|
+
files = files.map(it => defaultsGenericsTransformer.visit(it)).map(idl.linkParentBack);
|
|
16
|
+
const resolver = createCachedReferenceResolver(files);
|
|
17
|
+
const resolverAdditionals = new Map();
|
|
18
|
+
const library = {
|
|
19
|
+
language: Language.CPP,
|
|
20
|
+
files: files,
|
|
21
|
+
typeConvertor: function (param, type, isOptionalParam) {
|
|
22
|
+
throw new Error('Function not implemented.');
|
|
23
|
+
},
|
|
24
|
+
declarationConvertor: function (param, type, declaration) {
|
|
25
|
+
throw new Error('Function not implemented.');
|
|
26
|
+
},
|
|
27
|
+
createTypeNameConvertor: function (language) {
|
|
28
|
+
throw new Error('Function not implemented.');
|
|
29
|
+
},
|
|
30
|
+
createContinuationCallbackReference: function (continuationType) {
|
|
31
|
+
throw new Error('Function not implemented.');
|
|
32
|
+
},
|
|
33
|
+
getCurrentContext: function () {
|
|
34
|
+
throw new Error('Function not implemented.');
|
|
35
|
+
},
|
|
36
|
+
layout: LayoutManager.Empty(),
|
|
37
|
+
libraryPrefix: '',
|
|
38
|
+
resolveTypeReference: function (type, options) {
|
|
39
|
+
if (resolverAdditionals.has(type.name))
|
|
40
|
+
return resolverAdditionals.get(type.name);
|
|
41
|
+
return resolver.resolveTypeReference(type, options);
|
|
42
|
+
},
|
|
43
|
+
toDeclaration: function (type) {
|
|
44
|
+
if (!idl.isType(type) && !idl.isEntry(type))
|
|
45
|
+
throw new Error("toDeclaration can be performed only on types or entries!");
|
|
46
|
+
return toDeclaration(type, this);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const production = new Array();
|
|
50
|
+
const nameConvertor = new StructureNameConvertor(library);
|
|
51
|
+
const monomorphizeReferencesTransformer = new GenericsTransformer(library, produced => {
|
|
52
|
+
const anchorDecl = library.resolveTypeReference(idl.createReferenceType(produced.anchor));
|
|
53
|
+
const producedFqn = produced.anchor.split('.').slice(0, -1).concat(produced.produced.name).join('.');
|
|
54
|
+
if (!resolverAdditionals.has(producedFqn)) {
|
|
55
|
+
resolverAdditionals.set(producedFqn, produced.produced);
|
|
56
|
+
production.push(produced);
|
|
57
|
+
// hack to be able calculate FQN for this declaration
|
|
58
|
+
produced.produced.parent = anchorDecl.parent;
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
nameConvertor: (node) => nameConvertor.convert(node),
|
|
62
|
+
ignore: options.ignore,
|
|
63
|
+
ignoreGenerics: options.ignoreGenerics,
|
|
64
|
+
});
|
|
65
|
+
files = files.map(it => monomorphizeReferencesTransformer.visit(it)).map(idl.linkParentBack);
|
|
66
|
+
const debugInsertedEntries = new Set();
|
|
67
|
+
const insertProductionTransformer = new InsertProductionTransformer(production, {
|
|
68
|
+
debugInserted: (node) => debugInsertedEntries.add(node),
|
|
14
69
|
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
70
|
+
files = files.map(it => insertProductionTransformer.visit(it)).map(idl.linkParentBack);
|
|
71
|
+
const debugMissedEntries = new Set(production.filter(it => !debugInsertedEntries.has(it.anchor)).map(it => it.anchor));
|
|
72
|
+
if (debugMissedEntries.size) {
|
|
73
|
+
throw new Error(`Failed to insert generated generics for entries ${Array.from(debugMissedEntries).join(', ')}`);
|
|
74
|
+
}
|
|
75
|
+
return files;
|
|
76
|
+
}
|
|
77
|
+
class DefaultGenericsTransformer extends IdlTransformer {
|
|
78
|
+
constructor(resolver) {
|
|
79
|
+
super();
|
|
80
|
+
this.resolver = resolver;
|
|
81
|
+
}
|
|
82
|
+
visit(node) {
|
|
83
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
84
|
+
if (idl.isReferenceType(node)) {
|
|
85
|
+
const decl = this.resolver.resolveTypeReference(node);
|
|
86
|
+
if (!decl) {
|
|
87
|
+
console.error(`Can not resolve reference for inplacing default generics ${node.name} in file ${(_a = node.fileName) !== null && _a !== void 0 ? _a : '<unknown>'}`);
|
|
88
|
+
return this.visitEachChild(node);
|
|
89
|
+
}
|
|
90
|
+
if (!idl.isTypedef(decl) && !idl.isInterface(decl) && !idl.isCallback(decl)) {
|
|
91
|
+
return this.visitEachChild(node);
|
|
92
|
+
}
|
|
93
|
+
if (((_c = (_b = decl.typeParameters) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) > ((_e = (_d = node.typeArguments) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0)) {
|
|
94
|
+
const defaults = (_j = (_h = (_g = (_f = decl.extendedAttributes) === null || _f === void 0 ? void 0 : _f.find(it => it.name === idl.IDLExtendedAttributes.TypeParametersDefaults)) === null || _g === void 0 ? void 0 : _g.typesValue) === null || _h === void 0 ? void 0 : _h.slice()) !== null && _j !== void 0 ? _j : [];
|
|
95
|
+
while (defaults.length < decl.typeParameters.length) {
|
|
96
|
+
defaults.unshift(undefined);
|
|
97
|
+
}
|
|
98
|
+
const typeArguments = Array.from((_k = node.typeArguments) !== null && _k !== void 0 ? _k : []);
|
|
99
|
+
while (decl.typeParameters.length > typeArguments.length) {
|
|
100
|
+
if (defaults[typeArguments.length] === undefined) {
|
|
101
|
+
const declarationDetails = `${idl.getFQName(decl)}<${((_l = decl.typeParameters) !== null && _l !== void 0 ? _l : [])
|
|
102
|
+
.map((it, index) => `${it}${defaults[index] ? '=' + defaults[index] : ''}`)
|
|
103
|
+
.join(', ')}>`;
|
|
104
|
+
const referenceDetails = `${node.name}<${typeArguments.map(it => idl.printType(it)).join(", ")}>`;
|
|
105
|
+
throw new Error(`Can not validate reference to ${declarationDetails} declaration: reference ${referenceDetails} has not enough generic arguments or declaration does not have enough default generic values. Reference defined at: ${node.fileName}`);
|
|
106
|
+
}
|
|
107
|
+
typeArguments.push(defaults[typeArguments.length]);
|
|
108
|
+
}
|
|
109
|
+
return idl.createReferenceType(node.name, typeArguments, idl.cloneNodeInitializer(node));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return this.visitEachChild(node);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
class GenericsTransformer extends IdlTransformer {
|
|
116
|
+
constructor(resolver, producer, options) {
|
|
117
|
+
super();
|
|
118
|
+
this.resolver = resolver;
|
|
119
|
+
this.producer = producer;
|
|
120
|
+
this.options = options;
|
|
121
|
+
this.meaninglessFieldsTransformer = new RemoveMeaninglessFieldsTransformer();
|
|
122
|
+
}
|
|
123
|
+
visit(node) {
|
|
124
|
+
var _a;
|
|
125
|
+
if (idl.isReferenceType(node)) {
|
|
126
|
+
const ref = this.visitEachChild(node);
|
|
127
|
+
if (!((_a = ref.typeArguments) === null || _a === void 0 ? void 0 : _a.length) || hasTypeParameterTypeChild(ref)) {
|
|
128
|
+
return ref;
|
|
129
|
+
}
|
|
130
|
+
const resolved = this.resolver.resolveTypeReference(ref);
|
|
131
|
+
if (!resolved) {
|
|
132
|
+
throw new Error(`Can not resolve ${ref.name}`);
|
|
133
|
+
}
|
|
134
|
+
if (this.options.ignore.some(it => it(ref) || it(resolved)) ||
|
|
135
|
+
this.options.ignoreGenerics.includes(idl.getFQName(resolved))) {
|
|
136
|
+
return ref;
|
|
137
|
+
}
|
|
138
|
+
if (!idl.isTypedef(resolved) && !idl.isInterface(resolved) && !idl.isCallback(resolved)) {
|
|
139
|
+
throw new Error(`Unsupported generics target ${resolved.kind}`);
|
|
140
|
+
}
|
|
141
|
+
const inplacedRef = idl.createReferenceType(idl.deriveQualifiedNameFrom(monomorphisedEntryName(resolved, ref.typeArguments, this.options), resolved), undefined, idl.cloneNodeInitializer(ref));
|
|
142
|
+
if (!this.resolver.resolveTypeReference(inplacedRef)) {
|
|
143
|
+
const monomorphizedEntry = this.visit(this.monomorphizeEntry(resolved, ref.typeArguments));
|
|
144
|
+
this.producer({ anchor: idl.getFQName(resolved), produced: monomorphizedEntry });
|
|
145
|
+
}
|
|
146
|
+
return inplacedRef;
|
|
147
|
+
}
|
|
148
|
+
return this.visitEachChild(node);
|
|
149
|
+
}
|
|
150
|
+
monomorphizeEntry(typedEntry, typeArguments) {
|
|
151
|
+
var _a, _b, _c;
|
|
152
|
+
if (!idl.isTypedef(typedEntry) && !idl.isInterface(typedEntry) && !idl.isCallback(typedEntry))
|
|
153
|
+
throw new Error(`Can not monomorphize ${typedEntry.kind}`);
|
|
154
|
+
if (((_a = typedEntry.typeParameters) === null || _a === void 0 ? void 0 : _a.length) != typeArguments.length)
|
|
155
|
+
throw new Error(`Trying to monomorphize entry ${typedEntry.name} that accepts ${(_b = typedEntry.typeParameters) === null || _b === void 0 ? void 0 : _b.length} type parameters with ${typeArguments.length} type arguments`);
|
|
156
|
+
const monomorphizedEntry = idl.clone(typedEntry);
|
|
157
|
+
monomorphizedEntry.name = monomorphisedEntryName(typedEntry, typeArguments, this.options);
|
|
158
|
+
monomorphizedEntry.typeParameters = undefined;
|
|
159
|
+
const nameToType = new Map(typedEntry.typeParameters.map((name, index) => [name, typeArguments[index]]));
|
|
160
|
+
idl.updateEachChild(monomorphizedEntry, (node) => {
|
|
161
|
+
var _a;
|
|
162
|
+
if (idl.isTypeParameterType(node)) {
|
|
163
|
+
if (!nameToType.has(node.name))
|
|
164
|
+
throw new Error(`Can not name ${node.name} in type parameters of ${typedEntry.name}: available are ${(_a = typedEntry.typeParameters) === null || _a === void 0 ? void 0 : _a.join(", ")}`);
|
|
165
|
+
return idl.clone(nameToType.get(node.name));
|
|
166
|
+
}
|
|
167
|
+
return node;
|
|
168
|
+
});
|
|
169
|
+
(_c = monomorphizedEntry.extendedAttributes) !== null && _c !== void 0 ? _c : (monomorphizedEntry.extendedAttributes = []);
|
|
170
|
+
monomorphizedEntry.extendedAttributes.push({
|
|
171
|
+
name: idl.IDLExtendedAttributes.OriginalGenericName,
|
|
172
|
+
value: idl.getFQName(typedEntry),
|
|
173
|
+
typesValue: typeArguments,
|
|
174
|
+
});
|
|
175
|
+
this.correctTransformOnSerialize(monomorphizedEntry.extendedAttributes, typeArguments);
|
|
176
|
+
return this.meaninglessFieldsTransformer.visit(monomorphizedEntry);
|
|
177
|
+
}
|
|
178
|
+
correctTransformOnSerialize(extendedAttributes, typeArguments) {
|
|
179
|
+
const transformOnSerializeAttribute = extendedAttributes.find(it => it.name === idl.IDLExtendedAttributes.TransformOnSerialize);
|
|
180
|
+
if (transformOnSerializeAttribute === undefined)
|
|
181
|
+
return;
|
|
182
|
+
const targetType = toIdlType("", transformOnSerializeAttribute.value);
|
|
183
|
+
if (idl.isReferenceType(targetType)) {
|
|
184
|
+
const monomorphizedReference = this.visit(idl.createReferenceType(targetType.name, typeArguments, idl.cloneNodeInitializer(targetType)));
|
|
185
|
+
transformOnSerializeAttribute.value = monomorphizedReference.name;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
class InsertProductionTransformer extends IdlTransformer {
|
|
190
|
+
constructor(production, options) {
|
|
191
|
+
super();
|
|
192
|
+
this.options = options;
|
|
193
|
+
this.production = new Map();
|
|
194
|
+
for (const result of production) {
|
|
195
|
+
if (!this.production.has(result.anchor))
|
|
196
|
+
this.production.set(result.anchor, []);
|
|
197
|
+
this.production.get(result.anchor).push(result.produced);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
visit(node) {
|
|
201
|
+
if (idl.isFile(node)) {
|
|
202
|
+
if (node.entries.some(it => this.production.has(idl.getFQNameSafe(it)))) {
|
|
203
|
+
return idl.createFile(node.entries.flatMap(it => {
|
|
204
|
+
const fqn = idl.getFQNameSafe(it);
|
|
205
|
+
if (this.production.has(fqn)) {
|
|
206
|
+
this.options.debugInserted(fqn);
|
|
207
|
+
return this.production.get(fqn).concat(this.visit(it));
|
|
208
|
+
}
|
|
209
|
+
return this.visit(it);
|
|
210
|
+
}), node.fileName, node.packageClause, idl.cloneNodeInitializer(node));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (idl.isNamespace(node)) {
|
|
214
|
+
if (node.members.some(it => this.production.has(idl.getFQNameSafe(it)))) {
|
|
215
|
+
return idl.createNamespace(node.name, node.members.flatMap(it => {
|
|
216
|
+
const fqn = idl.getFQNameSafe(it);
|
|
217
|
+
if (this.production.has(fqn)) {
|
|
218
|
+
this.options.debugInserted(fqn);
|
|
219
|
+
return this.production.get(fqn).concat(this.visit(it));
|
|
220
|
+
}
|
|
221
|
+
return this.visit(it);
|
|
222
|
+
}), idl.cloneNodeInitializer(node));
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return this.visitEachChild(node);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
class RemoveMeaninglessFieldsTransformer extends IdlTransformer {
|
|
229
|
+
visit(node) {
|
|
230
|
+
if (idl.isInterface(node) && node.properties.some(it => isMeaninglessFieldType(it.type))) {
|
|
231
|
+
return idl.createInterface(node.name, node.subkind, node.inheritance.map(it => this.visit(it)), node.constructors.map(it => this.visit(it)), node.constants.map(it => this.visit(it)), node.properties.filter(it => !isMeaninglessFieldType(it.type)).map(it => this.visit(it)), node.methods.map(it => this.visit(it)), node.callables.map(it => this.visit(it)), node.typeParameters, idl.cloneNodeInitializer(node));
|
|
232
|
+
}
|
|
233
|
+
if (idl.isMethod(node) && node.parameters.some(it => isMeaninglessFieldType(it.type))) {
|
|
234
|
+
return idl.createMethod(node.name, node.parameters.filter(it => !isMeaninglessFieldType(it.type)).map(it => this.visit(it)), this.visit(node.returnType), {
|
|
235
|
+
isAsync: node.isAsync,
|
|
236
|
+
isFree: node.isFree,
|
|
237
|
+
isOptional: node.isOptional,
|
|
238
|
+
isStatic: node.isStatic,
|
|
239
|
+
}, idl.cloneNodeInitializer(node), node.typeParameters);
|
|
240
|
+
}
|
|
241
|
+
if (idl.isCallback(node) && node.parameters.some(it => isMeaninglessFieldType(it.type))) {
|
|
242
|
+
return idl.createCallback(node.name, node.parameters.filter(it => !isMeaninglessFieldType(it.type)).map(it => this.visit(it)), this.visit(node.returnType), idl.cloneNodeInitializer(node), node.typeParameters);
|
|
243
|
+
}
|
|
244
|
+
return this.visitEachChild(node);
|
|
245
|
+
}
|
|
19
246
|
}
|
|
20
247
|
export function isInplacedGeneric(entry) {
|
|
21
248
|
return idl.hasExtAttribute(entry, idl.IDLExtendedAttributes.OriginalGenericName);
|
|
@@ -27,26 +254,17 @@ export function maybeRestoreGenerics(maybeTransformedGeneric, resolver) {
|
|
|
27
254
|
}
|
|
28
255
|
if (maybeTransformedGeneric && idl.hasExtAttribute(maybeTransformedGeneric, idl.IDLExtendedAttributes.OriginalGenericName)) {
|
|
29
256
|
const originalName = idl.getExtAttribute(maybeTransformedGeneric, idl.IDLExtendedAttributes.OriginalGenericName);
|
|
30
|
-
const
|
|
31
|
-
if (!
|
|
257
|
+
const typeArguments = idl.getExtAttributeTypesValue(maybeTransformedGeneric, idl.IDLExtendedAttributes.OriginalGenericName);
|
|
258
|
+
if (!typeArguments)
|
|
32
259
|
throw new Error(`Can not restore original generic type arguments for ${originalName}: no type arguments`);
|
|
33
|
-
|
|
34
|
-
return idl.createReferenceType(originalName, typeArguments, {
|
|
35
|
-
extendedAttributes: [{
|
|
36
|
-
name: idl.IDLExtendedAttributes.TypeArguments,
|
|
37
|
-
value: typeArgumentsAttribute,
|
|
38
|
-
}]
|
|
39
|
-
});
|
|
260
|
+
return idl.createReferenceType(originalName, typeArguments);
|
|
40
261
|
}
|
|
41
262
|
return undefined;
|
|
42
263
|
}
|
|
43
|
-
function ignoreConfigRule(
|
|
44
|
-
|
|
45
|
-
return
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
function ignoreBuilderClassRule(node) {
|
|
49
|
-
return idl.isInterface(node) && isBuilderClass(node);
|
|
264
|
+
function ignoreConfigRule(ignoreGenerics) {
|
|
265
|
+
return (node) => {
|
|
266
|
+
return idl.isEntry(node) && ignoreGenerics.includes(idl.getFQName(node));
|
|
267
|
+
};
|
|
50
268
|
}
|
|
51
269
|
function createIgnoreMaterializedRule(resolver) {
|
|
52
270
|
return (node) => idl.isInterface(node) && isMaterialized(node, resolver) && !idl.hasExtAttribute(node, idl.IDLExtendedAttributes.TransformOnSerialize);
|
|
@@ -63,40 +281,8 @@ function createIgnoreResourceRule(resolver) {
|
|
|
63
281
|
return generatorConfiguration().forceResource.includes(declaration.name);
|
|
64
282
|
};
|
|
65
283
|
}
|
|
66
|
-
function monomorphisedEntryName(typedEntry, typeArguments) {
|
|
67
|
-
return typedEntry.name + "_" + typeArguments.map(
|
|
68
|
-
}
|
|
69
|
-
function monomorphizeEntry(typedEntry, typeArguments) {
|
|
70
|
-
var _a, _b, _c, _d;
|
|
71
|
-
if (!idl.isTypedef(typedEntry) && !idl.isInterface(typedEntry) && !idl.isCallback(typedEntry))
|
|
72
|
-
throw new Error(`Can not monomorphize ${typedEntry.kind}`);
|
|
73
|
-
if (((_a = typedEntry.typeParameters) === null || _a === void 0 ? void 0 : _a.length) != typeArguments.length)
|
|
74
|
-
throw new Error(`Trying to monomorphize entry ${typedEntry.name} that accepts ${(_b = typedEntry.typeParameters) === null || _b === void 0 ? void 0 : _b.length} type parameters with ${typeArguments.length} type arguments`);
|
|
75
|
-
const monomorphizedEntry = idl.clone(typedEntry);
|
|
76
|
-
monomorphizedEntry.name = monomorphisedEntryName(typedEntry, typeArguments);
|
|
77
|
-
monomorphizedEntry.typeParameters = undefined;
|
|
78
|
-
const nameToType = new Map(typedEntry.typeParameters.map((name, index) => [name, typeArguments[index]]));
|
|
79
|
-
idl.updateEachChild(monomorphizedEntry, (node) => {
|
|
80
|
-
var _a;
|
|
81
|
-
if (idl.isTypeParameterType(node)) {
|
|
82
|
-
if (!nameToType.has(node.name))
|
|
83
|
-
throw new Error(`Can not name ${node.name} in type parameters of ${typedEntry.name}: available are ${(_a = typedEntry.typeParameters) === null || _a === void 0 ? void 0 : _a.join(", ")}`);
|
|
84
|
-
return idl.clone(nameToType.get(node.name));
|
|
85
|
-
}
|
|
86
|
-
return node;
|
|
87
|
-
});
|
|
88
|
-
monomorphizedEntry.extendedAttributes = (_d = (_c = monomorphizedEntry.extendedAttributes) === null || _c === void 0 ? void 0 : _c.filter(it => {
|
|
89
|
-
return it.name != idl.IDLExtendedAttributes.TypeParameters;
|
|
90
|
-
})) !== null && _d !== void 0 ? _d : [];
|
|
91
|
-
monomorphizedEntry.extendedAttributes.push({
|
|
92
|
-
name: idl.IDLExtendedAttributes.OriginalGenericName,
|
|
93
|
-
value: idl.getFQName(typedEntry),
|
|
94
|
-
}, {
|
|
95
|
-
name: idl.IDLExtendedAttributes.TypeArguments,
|
|
96
|
-
value: typeArguments.map(type => idl.printType(type)).join("|"),
|
|
97
|
-
});
|
|
98
|
-
inplaceRemoveMeaninglessFields(monomorphizedEntry);
|
|
99
|
-
return monomorphizedEntry;
|
|
284
|
+
function monomorphisedEntryName(typedEntry, typeArguments, options) {
|
|
285
|
+
return typedEntry.name + "_" + typeArguments.map(options.nameConvertor).join("_");
|
|
100
286
|
}
|
|
101
287
|
function hasTypeParameterTypeChild(node) {
|
|
102
288
|
let result = false;
|
|
@@ -106,101 +292,9 @@ function hasTypeParameterTypeChild(node) {
|
|
|
106
292
|
});
|
|
107
293
|
return result;
|
|
108
294
|
}
|
|
109
|
-
function inplaceReferenceGenerics(ref, resolver, options) {
|
|
110
|
-
var _a, _b;
|
|
111
|
-
inplaceDefaultReferenceGenerics(ref, resolver);
|
|
112
|
-
if (!((_a = ref.typeArguments) === null || _a === void 0 ? void 0 : _a.length) || hasTypeParameterTypeChild(ref)) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
ref.typeArguments.forEach(it => inplaceFQN(it, resolver));
|
|
116
|
-
const resolved = resolver.resolveTypeReference(ref);
|
|
117
|
-
if (!resolved) {
|
|
118
|
-
throw new Error(`Can not resolve ${ref.name}`);
|
|
119
|
-
}
|
|
120
|
-
if (((_b = options === null || options === void 0 ? void 0 : options.ignore) === null || _b === void 0 ? void 0 : _b.some(it => it(ref) || it(resolved))) || generatorConfiguration().ignoreGenerics.includes(idl.getFQName(resolved))) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
if (!idl.isTypedef(resolved) && !idl.isInterface(resolved) && !idl.isCallback(resolved)) {
|
|
124
|
-
throw new Error(`Unsupported generics target ${resolved.kind}`);
|
|
125
|
-
}
|
|
126
|
-
const inplacedRef = idl.createReferenceType(monomorphisedEntryName(resolved, ref.typeArguments));
|
|
127
|
-
if (!resolver.resolveTypeReference(inplacedRef)) {
|
|
128
|
-
const monomorphizedEntry = monomorphizeEntry(resolved, ref.typeArguments);
|
|
129
|
-
insertEntryNearTo(monomorphizedEntry, resolved);
|
|
130
|
-
inplaceGenerics(monomorphizedEntry, resolver);
|
|
131
|
-
correctTransformOnSerialize(resolver, monomorphizedEntry, ref.typeArguments, options);
|
|
132
|
-
}
|
|
133
|
-
ref.name = inplacedRef.name;
|
|
134
|
-
ref.typeArguments = undefined;
|
|
135
|
-
}
|
|
136
|
-
function insertEntryNearTo(entry, anchor) {
|
|
137
|
-
if (!anchor.parent) {
|
|
138
|
-
throw new Error(`Entry used as anchor has not parent`);
|
|
139
|
-
}
|
|
140
|
-
let parentEntries;
|
|
141
|
-
if (idl.isFile(anchor.parent)) {
|
|
142
|
-
parentEntries = anchor.parent.entries;
|
|
143
|
-
}
|
|
144
|
-
else if (idl.isNamespace(anchor.parent)) {
|
|
145
|
-
parentEntries = anchor.parent.members;
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
throw new Error(`Can not insert entry, unknown parent kind ${anchor.parent.kind}`);
|
|
149
|
-
}
|
|
150
|
-
parentEntries.splice(parentEntries.indexOf(anchor), 0, entry);
|
|
151
|
-
idl.linkParentBack(anchor.parent);
|
|
152
|
-
}
|
|
153
|
-
// when generic declaration has TransformOnSerialize attribute, for monomorphized entry we must update that attribute that will look
|
|
154
|
-
// at monomorphized TransformOnSerialize
|
|
155
|
-
function correctTransformOnSerialize(resolver, monomorphizedEntry, typeArguments, options) {
|
|
156
|
-
const targetName = idl.getExtAttribute(monomorphizedEntry, idl.IDLExtendedAttributes.TransformOnSerialize);
|
|
157
|
-
if (targetName === undefined) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
const targetType = toIdlType("", targetName);
|
|
161
|
-
if (idl.isReferenceType(targetType)) {
|
|
162
|
-
targetType.typeArguments = typeArguments;
|
|
163
|
-
inplaceReferenceGenerics(targetType, resolver, options);
|
|
164
|
-
idl.updateExtAttribute(monomorphizedEntry, idl.IDLExtendedAttributes.TransformOnSerialize, targetType.name);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
function inplaceDefaultReferenceGenerics(node, resolver) {
|
|
168
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
169
|
-
const decl = resolver.resolveTypeReference(node);
|
|
170
|
-
if (!decl) {
|
|
171
|
-
console.error(`Can not resolve reference for inplacing default generics ${node.name} in file ${(_a = node.fileName) !== null && _a !== void 0 ? _a : '<unknown>'}`);
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
if (!idl.isTypedef(decl) && !idl.isInterface(decl) && !idl.isCallback(decl)) {
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
if (((_c = (_b = decl.typeParameters) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) > ((_e = (_d = node.typeArguments) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0)) {
|
|
178
|
-
const defaults = (_h = (_g = (_f = decl.extendedAttributes) === null || _f === void 0 ? void 0 : _f.find(it => it.name === idl.IDLExtendedAttributes.TypeParametersDefaults)) === null || _g === void 0 ? void 0 : _g.typesValue) !== null && _h !== void 0 ? _h : [];
|
|
179
|
-
while (defaults.length < decl.typeParameters.length) {
|
|
180
|
-
defaults.unshift(undefined);
|
|
181
|
-
}
|
|
182
|
-
(_j = node.typeArguments) !== null && _j !== void 0 ? _j : (node.typeArguments = []);
|
|
183
|
-
while (decl.typeParameters.length > node.typeArguments.length) {
|
|
184
|
-
if (defaults[node.typeArguments.length] === undefined) {
|
|
185
|
-
throw new Error(`Can not validate reference to ${idl.getFQName(decl)} declaration: reference has not enough generic arguments or declaration does not have enough default generic values`);
|
|
186
|
-
}
|
|
187
|
-
node.typeArguments.push(defaults[node.typeArguments.length]);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
295
|
function isMeaninglessFieldType(type) {
|
|
192
|
-
return type === idl.IDLVoidType || type === idl.IDLUndefinedType
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if (options.recursive) {
|
|
196
|
-
idl.forEachChild(node, child => inplaceRemoveMeaninglessFields(child, { recursive: false }));
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
if (idl.isInterface(node)) {
|
|
200
|
-
node.properties = node.properties.filter(it => !isMeaninglessFieldType(it.type));
|
|
201
|
-
}
|
|
202
|
-
if (idl.isMethod(node)) {
|
|
203
|
-
node.parameters = node.parameters.filter(it => !isMeaninglessFieldType(it.type));
|
|
204
|
-
}
|
|
296
|
+
return type === idl.IDLVoidType || type === idl.IDLUndefinedType ||
|
|
297
|
+
idl.isUnionType(type) && type.types.every(isMeaninglessFieldType) ||
|
|
298
|
+
idl.isOptionalType(type) && isMeaninglessFieldType(type.type);
|
|
205
299
|
}
|
|
206
300
|
//# sourceMappingURL=GenericTransformer.js.map
|
|
@@ -1,31 +1,37 @@
|
|
|
1
1
|
import * as idl from "../idl";
|
|
2
2
|
import { generateSyntheticUnionName } from "../peer-generation/idl/common";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { IdlTransformer } from "./IdlTransformer";
|
|
4
|
+
export function nullsTransformer(files) {
|
|
5
|
+
const transformer = new NullsTransformer();
|
|
6
|
+
return files.map(it => transformer.visit(it)).map(idl.linkParentBack);
|
|
7
|
+
}
|
|
8
|
+
class NullsTransformer extends IdlTransformer {
|
|
9
|
+
visit(node) {
|
|
5
10
|
var _a;
|
|
6
|
-
if (idl.isOptionalType(
|
|
7
|
-
if (idl.isUnionType(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
if (idl.isOptionalType(node)) {
|
|
12
|
+
if (idl.isUnionType(node.type) && node.type.types.some(isNullReference)) {
|
|
13
|
+
const unionTypes = node.type.types.filter(it => !isNullReference(it)).map(it => this.visit(it));
|
|
14
|
+
const unionName = generateSyntheticUnionName(unionTypes);
|
|
15
|
+
const extendedAttributes = ((_a = node.extendedAttributes) !== null && _a !== void 0 ? _a : [])
|
|
16
|
+
.concat({ name: idl.IDLExtendedAttributes.UnionWithNull });
|
|
17
|
+
return idl.createOptionalType(unionTypes.length === 1
|
|
18
|
+
? unionTypes[0]
|
|
19
|
+
: idl.createUnionType(unionTypes, unionName, idl.cloneNodeInitializer(node.type)), {
|
|
20
|
+
documentation: node.documentation,
|
|
21
|
+
extendedAttributes,
|
|
22
|
+
fileName: node.fileName,
|
|
23
|
+
});
|
|
16
24
|
}
|
|
17
25
|
}
|
|
18
|
-
else if (idl.isUnionType(
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return idl.createOptionalType(
|
|
23
|
-
name: idl.IDLExtendedAttributes.UnionOnlyNull
|
|
24
|
-
}] });
|
|
26
|
+
else if (idl.isUnionType(node)) {
|
|
27
|
+
if (node.types.some(isNullReference)) {
|
|
28
|
+
const unionTypes = node.types.filter(it => !isNullReference(it)).map(it => this.visit(it));
|
|
29
|
+
const unionName = generateSyntheticUnionName(unionTypes);
|
|
30
|
+
return idl.createOptionalType(unionTypes.length === 1 ? unionTypes[0] : idl.createUnionType(unionTypes, unionName, idl.cloneNodeInitializer(node)), { extendedAttributes: [{ name: idl.IDLExtendedAttributes.UnionOnlyNull }] });
|
|
25
31
|
}
|
|
26
32
|
}
|
|
27
|
-
return
|
|
28
|
-
}
|
|
33
|
+
return this.visitEachChild(node);
|
|
34
|
+
}
|
|
29
35
|
}
|
|
30
36
|
function isNullReference(node) {
|
|
31
37
|
return idl.isReferenceType(node) && node.name === idl.IDLNullTypeName;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as idl from "../idl";
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function transformOnSerializeTransformer(files: idl.IDLFile[], destinationGetter: (node: idl.IDLNode) => string | undefined): idl.IDLFile[];
|
|
3
3
|
//# sourceMappingURL=OnSerializeTransformer.d.ts.map
|
|
@@ -1,19 +1,34 @@
|
|
|
1
|
-
import { generatorConfiguration } from "../config";
|
|
2
1
|
import * as idl from "../idl";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return child;
|
|
8
|
-
});
|
|
2
|
+
import { IdlTransformer } from "./IdlTransformer";
|
|
3
|
+
export function transformOnSerializeTransformer(files, destinationGetter) {
|
|
4
|
+
const transformer = new TransformOnSerializeTransformer(destinationGetter);
|
|
5
|
+
return files.map(it => transformer.visit(it)).map(idl.linkParentBack);
|
|
9
6
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
class TransformOnSerializeTransformer extends IdlTransformer {
|
|
8
|
+
constructor(destinationGetter) {
|
|
9
|
+
super();
|
|
10
|
+
this.destinationGetter = destinationGetter;
|
|
13
11
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
idl.
|
|
12
|
+
visit(node) {
|
|
13
|
+
var _a;
|
|
14
|
+
if (idl.isInterface(node) || idl.isEnum(node) || idl.isTypedef(node) || idl.isCallback(node)) {
|
|
15
|
+
const destination = this.destinationGetter(node);
|
|
16
|
+
if (!destination)
|
|
17
|
+
return this.visitEachChild(node);
|
|
18
|
+
const nodeInitializer = idl.cloneNodeInitializer(node);
|
|
19
|
+
nodeInitializer.extendedAttributes = ((_a = nodeInitializer.extendedAttributes) !== null && _a !== void 0 ? _a : [])
|
|
20
|
+
.filter(it => it.name !== idl.IDLExtendedAttributes.TransformOnSerialize)
|
|
21
|
+
.concat({ name: idl.IDLExtendedAttributes.TransformOnSerialize, value: destination });
|
|
22
|
+
if (idl.isInterface(node))
|
|
23
|
+
return idl.createInterface(node.name, node.subkind, node.inheritance, node.constructors, node.constants, node.properties, node.methods, node.callables, node.typeParameters, nodeInitializer);
|
|
24
|
+
if (idl.isEnum(node))
|
|
25
|
+
return idl.createEnum(node.name, node.elements, nodeInitializer);
|
|
26
|
+
if (idl.isTypedef(node))
|
|
27
|
+
return idl.createTypedef(node.name, node.type, node.typeParameters, nodeInitializer);
|
|
28
|
+
if (idl.isCallback(node))
|
|
29
|
+
return idl.createCallback(node.name, node.parameters, node.returnType, nodeInitializer, node.typeParameters);
|
|
30
|
+
}
|
|
31
|
+
return this.visitEachChild(node);
|
|
17
32
|
}
|
|
18
33
|
}
|
|
19
34
|
//# sourceMappingURL=OnSerializeTransformer.js.map
|
package/build/lib/src/util.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare function snakeCaseToCamelCase(input: string, tailToLowerCase?: bo
|
|
|
18
18
|
export declare function toCamelCase(input: string): string;
|
|
19
19
|
export declare function isUpperCase(s: string): boolean;
|
|
20
20
|
export declare function camelCaseToUpperSnakeCase(input: string): string;
|
|
21
|
+
export declare function camelCaseToLowerSnakeCase(input: string): string;
|
|
21
22
|
export declare function snakeToLowCamelNode(node: idl.IDLEntry): string;
|
|
22
23
|
export declare function renameDtsToPeer(fileName: string, language: Language, withFileExtension?: boolean): string;
|
|
23
24
|
export declare function renameDtsToComponent(fileName: string, language: Language, withFileExtension?: boolean): string;
|
|
@@ -57,6 +58,9 @@ export declare function getExtractor(target: idl.IDLInterface, lang: Language, t
|
|
|
57
58
|
receiver?: string;
|
|
58
59
|
method: string;
|
|
59
60
|
};
|
|
61
|
+
export declare function getInitializerFeature(lang: Language): string;
|
|
62
|
+
export declare function getInitializerDefaultValue(decl: idl.IDLEntry, lang: Language): string;
|
|
63
|
+
export declare function getSyntheticTypesFileName(): string;
|
|
60
64
|
export declare function getTransformer(library: LibraryInterface, from: idl.IDLNode, to: idl.IDLNode): {
|
|
61
65
|
receiver?: string;
|
|
62
66
|
method: string;
|
|
@@ -66,5 +70,6 @@ export declare function scanDirectory(dir: string, fileFilter: (file: string) =>
|
|
|
66
70
|
export declare function scanInputDirs(inputDirs: string[]): string[];
|
|
67
71
|
export declare function scanInputDirs(inputDirs: string[], fileExtension: string): string[];
|
|
68
72
|
export declare function scanInputDirs(inputDirs: string[], fileFilter: (file: string) => boolean, recursive: boolean): string[];
|
|
73
|
+
export declare function consoleWarn(message: string): void;
|
|
69
74
|
export {};
|
|
70
75
|
//# sourceMappingURL=util.d.ts.map
|
package/build/lib/src/util.js
CHANGED
|
@@ -122,6 +122,9 @@ export function camelCaseToUpperSnakeCase(input) {
|
|
|
122
122
|
.map(s => toUpperSnakeCase(s))
|
|
123
123
|
.join('_');
|
|
124
124
|
}
|
|
125
|
+
export function camelCaseToLowerSnakeCase(input) {
|
|
126
|
+
return camelCaseToUpperSnakeCase(input).toLowerCase();
|
|
127
|
+
}
|
|
125
128
|
export function snakeToLowCamelNode(node) {
|
|
126
129
|
if (!node.fileName) {
|
|
127
130
|
throw new Error("Invalid Convert");
|
|
@@ -351,6 +354,21 @@ export function getExtractor(target, lang, toPtr = true) {
|
|
|
351
354
|
const method = toPtr ? `to${extractorClass}Ptr` : `from${extractorClass}Ptr`;
|
|
352
355
|
return { receiver, method };
|
|
353
356
|
}
|
|
357
|
+
export function getInitializerFeature(lang) {
|
|
358
|
+
// TBD: update code for KT and CJ
|
|
359
|
+
return "initializers";
|
|
360
|
+
}
|
|
361
|
+
export function getInitializerDefaultValue(decl, lang) {
|
|
362
|
+
const parent = decl.parent;
|
|
363
|
+
const fqn = parent && idl.isProperty(decl)
|
|
364
|
+
? `${idl.getFQName(parent)}NS.${decl.name}`
|
|
365
|
+
: idl.getFQName(decl);
|
|
366
|
+
// TBD: update code for KT and CJ
|
|
367
|
+
return `${getInitializerFeature(lang)}.${fqn}`;
|
|
368
|
+
}
|
|
369
|
+
export function getSyntheticTypesFileName() {
|
|
370
|
+
return "synthetic_types";
|
|
371
|
+
}
|
|
354
372
|
export function getTransformer(library, from, to) {
|
|
355
373
|
const convertor = library.createTypeNameConvertor(Language.CPP);
|
|
356
374
|
return {
|
|
@@ -401,4 +419,11 @@ export function scanInputDirs(inputDirs, fileFilter = undefined, recursive = fal
|
|
|
401
419
|
return path.basename(a).localeCompare(path.basename(b));
|
|
402
420
|
});
|
|
403
421
|
}
|
|
422
|
+
const printedWarnMessages = new Set();
|
|
423
|
+
export function consoleWarn(message) {
|
|
424
|
+
if (printedWarnMessages.has(message))
|
|
425
|
+
return;
|
|
426
|
+
printedWarnMessages.add(message);
|
|
427
|
+
console.warn(message);
|
|
428
|
+
}
|
|
404
429
|
//# sourceMappingURL=util.js.map
|