@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,390 @@
|
|
|
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 { IndentedPrinter } from "../../IndentedPrinter";
|
|
18
|
+
import { AssignStatement, CheckOptionalStatement, ExpressionStatement, FieldModifier, LambdaExpression, LanguageWriter, Method, MethodModifier, NamedMethodSignature, ReturnStatement, StringExpression } from "../LanguageWriter";
|
|
19
|
+
import { RuntimeType } from "../common";
|
|
20
|
+
import { throwException } from "../../util";
|
|
21
|
+
import { TSKeywords } from '../../languageSpecificKeywords';
|
|
22
|
+
////////////////////////////////////////////////////////////////
|
|
23
|
+
// EXPRESSIONS //
|
|
24
|
+
////////////////////////////////////////////////////////////////
|
|
25
|
+
export class TSLambdaExpression extends LambdaExpression {
|
|
26
|
+
constructor(writer, convertor, signature, resolver, body) {
|
|
27
|
+
super(writer, signature, resolver, body);
|
|
28
|
+
this.convertor = convertor;
|
|
29
|
+
}
|
|
30
|
+
get statementHasSemicolon() {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
asString() {
|
|
34
|
+
const params = this.signature.args.map((it, i) => {
|
|
35
|
+
const maybeOptional = idl.isOptionalType(it) ? "?" : "";
|
|
36
|
+
return `${this.signature.argName(i)}${maybeOptional}: ${this.convertor.convert(it)}`;
|
|
37
|
+
});
|
|
38
|
+
return `(${params.join(", ")}): ${this.convertor.convert(this.signature.returnType)} => { ${this.bodyAsString()} }`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export class TSCastExpression {
|
|
42
|
+
constructor(value, type, unsafe = false) {
|
|
43
|
+
this.value = value;
|
|
44
|
+
this.type = type;
|
|
45
|
+
this.unsafe = unsafe;
|
|
46
|
+
}
|
|
47
|
+
asString() {
|
|
48
|
+
return this.unsafe
|
|
49
|
+
? `unsafeCast<${this.type}>(${this.value.asString()})`
|
|
50
|
+
: `(${this.value.asString()} as ${this.type})`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
class TSUnwrapOptionalExpression {
|
|
54
|
+
constructor(value) {
|
|
55
|
+
this.value = value;
|
|
56
|
+
}
|
|
57
|
+
asString() {
|
|
58
|
+
return `(${this.value.asString()})!`;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
////////////////////////////////////////////////////////////////
|
|
62
|
+
// STATEMENTS //
|
|
63
|
+
////////////////////////////////////////////////////////////////
|
|
64
|
+
class TSThrowErrorStatement {
|
|
65
|
+
constructor(message) {
|
|
66
|
+
this.message = message;
|
|
67
|
+
}
|
|
68
|
+
write(writer) {
|
|
69
|
+
writer.print(`throw new Error("${this.message}")`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export class TSReturnStatement extends ReturnStatement {
|
|
73
|
+
constructor(expression) {
|
|
74
|
+
super(expression);
|
|
75
|
+
this.expression = expression;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
class TSLoopStatement {
|
|
79
|
+
constructor(counter, limit, statement) {
|
|
80
|
+
this.counter = counter;
|
|
81
|
+
this.limit = limit;
|
|
82
|
+
this.statement = statement;
|
|
83
|
+
}
|
|
84
|
+
write(writer) {
|
|
85
|
+
writer.print(`for (let ${this.counter} = 0; ${this.counter} < ${this.limit}; ${this.counter}++) {`);
|
|
86
|
+
if (this.statement) {
|
|
87
|
+
writer.pushIndent();
|
|
88
|
+
this.statement.write(writer);
|
|
89
|
+
writer.popIndent();
|
|
90
|
+
writer.print("}");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
class TSMapForEachStatement {
|
|
95
|
+
constructor(map, key, value, op) {
|
|
96
|
+
this.map = map;
|
|
97
|
+
this.key = key;
|
|
98
|
+
this.value = value;
|
|
99
|
+
this.op = op;
|
|
100
|
+
}
|
|
101
|
+
write(writer) {
|
|
102
|
+
writer.print(`for (const [${this.key}, ${this.value}] of ${this.map}) {`);
|
|
103
|
+
writer.pushIndent();
|
|
104
|
+
this.op();
|
|
105
|
+
writer.popIndent();
|
|
106
|
+
writer.print(`}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export class TsTupleAllocStatement {
|
|
110
|
+
constructor(tuple) {
|
|
111
|
+
this.tuple = tuple;
|
|
112
|
+
}
|
|
113
|
+
write(writer) {
|
|
114
|
+
writer.writeStatement(writer.makeAssign(this.tuple, undefined, writer.makeString("[]"), false, false));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
////////////////////////////////////////////////////////////////
|
|
118
|
+
// WRITER //
|
|
119
|
+
////////////////////////////////////////////////////////////////
|
|
120
|
+
export class TSLanguageWriter extends LanguageWriter {
|
|
121
|
+
constructor(printer, resolver, typeConvertor, language = Language.TS) {
|
|
122
|
+
super(printer, resolver, language);
|
|
123
|
+
this.typeConvertor = typeConvertor;
|
|
124
|
+
}
|
|
125
|
+
maybeSemicolon() { return ""; }
|
|
126
|
+
pushNamespace(namespace, ident = true) {
|
|
127
|
+
this.print(`export namespace ${namespace} {`);
|
|
128
|
+
if (ident)
|
|
129
|
+
this.pushIndent();
|
|
130
|
+
}
|
|
131
|
+
fork(options) {
|
|
132
|
+
var _a;
|
|
133
|
+
return new TSLanguageWriter(new IndentedPrinter(), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor, this.language);
|
|
134
|
+
}
|
|
135
|
+
getNodeName(type) {
|
|
136
|
+
return this.typeConvertor.convert(type);
|
|
137
|
+
}
|
|
138
|
+
writeClass(name, op, superClass, interfaces, generics, isDeclared) {
|
|
139
|
+
let extendsClause = superClass ? ` extends ${superClass}` : '';
|
|
140
|
+
let implementsClause = interfaces ? ` implements ${interfaces.join(",")}` : '';
|
|
141
|
+
const genericsClause = (generics === null || generics === void 0 ? void 0 : generics.length) ? `<${generics.join(", ")}>` : '';
|
|
142
|
+
this.printer.print(`export${isDeclared ? " declare" : ""} class ${name}${genericsClause}${extendsClause}${implementsClause} {`);
|
|
143
|
+
this.pushIndent();
|
|
144
|
+
op(this);
|
|
145
|
+
this.popIndent();
|
|
146
|
+
this.printer.print(`}`);
|
|
147
|
+
}
|
|
148
|
+
writeInterface(name, op, superInterfaces, isDeclared) {
|
|
149
|
+
let extendsClause = superInterfaces ? ` extends ${superInterfaces.join(",")}` : '';
|
|
150
|
+
this.printer.print(`export ${isDeclared ? "declare " : ""}interface ${name}${extendsClause} {`);
|
|
151
|
+
this.pushIndent();
|
|
152
|
+
op(this);
|
|
153
|
+
this.popIndent();
|
|
154
|
+
this.printer.print(`}`);
|
|
155
|
+
}
|
|
156
|
+
writeFunctionDeclaration(name, signature) {
|
|
157
|
+
this.printer.print(this.generateFunctionDeclaration(name, signature));
|
|
158
|
+
}
|
|
159
|
+
writeFunctionImplementation(name, signature, op) {
|
|
160
|
+
this.printer.print(`${this.generateFunctionDeclaration(name, signature)} {`);
|
|
161
|
+
this.printer.pushIndent();
|
|
162
|
+
op(this);
|
|
163
|
+
this.printer.popIndent();
|
|
164
|
+
this.printer.print('}');
|
|
165
|
+
}
|
|
166
|
+
generateFunctionDeclaration(name, signature) {
|
|
167
|
+
const args = signature.args.map((it, index) => `${signature.argName(index)}${idl.isOptionalType(it) ? '?' : ''}: ${this.getNodeName(it)}`);
|
|
168
|
+
return `export function ${name}(${args.join(", ")})`;
|
|
169
|
+
}
|
|
170
|
+
writeEnum(name, members) {
|
|
171
|
+
this.printer.print(`export enum ${name} {`);
|
|
172
|
+
this.printer.pushIndent();
|
|
173
|
+
for (const [index, member] of members.entries()) {
|
|
174
|
+
let value;
|
|
175
|
+
if (member.alias !== undefined) {
|
|
176
|
+
value = member.alias;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
value = `${member.stringId != undefined ? `"${member.stringId}"` : `${member.numberId}`}`;
|
|
180
|
+
}
|
|
181
|
+
const maybeComma = index < members.length - 1 ? "," : "";
|
|
182
|
+
this.printer.print(`${member.name} = ${value}${maybeComma}`);
|
|
183
|
+
}
|
|
184
|
+
this.printer.popIndent();
|
|
185
|
+
this.printer.print("}");
|
|
186
|
+
}
|
|
187
|
+
writeFieldDeclaration(name, type, modifiers, optional, initExpr) {
|
|
188
|
+
const init = initExpr != undefined ? ` = ${initExpr.asString()}` : ``;
|
|
189
|
+
let prefix = this.makeFieldModifiersList(modifiers);
|
|
190
|
+
if (prefix)
|
|
191
|
+
prefix += " ";
|
|
192
|
+
this.printer.print(`${prefix}${name}${optional ? "?" : ""}: ${this.getNodeName(type)}${init}`);
|
|
193
|
+
}
|
|
194
|
+
writeNativeMethodDeclaration(name, signature, isNative) {
|
|
195
|
+
this.writeMethodImplementation(new Method(name, signature, [MethodModifier.STATIC]), writer => {
|
|
196
|
+
writer.writeStatement(writer.makeThrowError("Not implemented"));
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
writeMethodDeclaration(name, signature, modifiers) {
|
|
200
|
+
this.writeDeclaration(name, signature, true, false, modifiers);
|
|
201
|
+
}
|
|
202
|
+
writeConstructorImplementation(className, signature, op, superCall, modifiers) {
|
|
203
|
+
this.writeDeclaration(`${modifiers ? modifiers.map((it) => MethodModifier[it].toLowerCase()).join(' ') : ''} constructor`, signature, false, true);
|
|
204
|
+
this.pushIndent();
|
|
205
|
+
if (superCall) {
|
|
206
|
+
this.print(`super(${superCall.signature.args.map((_, i) => superCall === null || superCall === void 0 ? void 0 : superCall.signature.argName(i)).join(", ")})`);
|
|
207
|
+
}
|
|
208
|
+
op(this);
|
|
209
|
+
this.popIndent();
|
|
210
|
+
this.printer.print(`}`);
|
|
211
|
+
}
|
|
212
|
+
writeMethodImplementation(method, op) {
|
|
213
|
+
this.writeDeclaration(method.name, method.signature, true, true, method.modifiers, method.generics);
|
|
214
|
+
this.pushIndent();
|
|
215
|
+
op(this);
|
|
216
|
+
this.popIndent();
|
|
217
|
+
this.printer.print(`}`);
|
|
218
|
+
}
|
|
219
|
+
writeProperty(propName, propType) {
|
|
220
|
+
throw new Error("writeProperty for TS is not implemented yet.");
|
|
221
|
+
}
|
|
222
|
+
writeDeclaration(name, signature, needReturn, needBracket, modifiers, generics) {
|
|
223
|
+
var _a;
|
|
224
|
+
let prefix = !modifiers ? undefined : this.supportedModifiers
|
|
225
|
+
.filter(it => modifiers.includes(it))
|
|
226
|
+
.map(it => this.mapMethodModifier(it)).join(" ");
|
|
227
|
+
if (modifiers === null || modifiers === void 0 ? void 0 : modifiers.includes(MethodModifier.GETTER)) {
|
|
228
|
+
prefix = `get ${prefix}`;
|
|
229
|
+
}
|
|
230
|
+
else if (modifiers === null || modifiers === void 0 ? void 0 : modifiers.includes(MethodModifier.SETTER)) {
|
|
231
|
+
prefix = `set ${prefix}`;
|
|
232
|
+
needReturn = false;
|
|
233
|
+
}
|
|
234
|
+
else if (modifiers === null || modifiers === void 0 ? void 0 : modifiers.includes(MethodModifier.FREE)) {
|
|
235
|
+
prefix = `${needBracket ? "" : "declare "}function ${prefix}`;
|
|
236
|
+
}
|
|
237
|
+
prefix = prefix ? prefix.trim() + " " : "";
|
|
238
|
+
const typeParams = (generics === null || generics === void 0 ? void 0 : generics.length) ? `<${generics.join(", ")}>` : "";
|
|
239
|
+
// FIXME:
|
|
240
|
+
const isSetter = modifiers === null || modifiers === void 0 ? void 0 : modifiers.includes(MethodModifier.SETTER);
|
|
241
|
+
const canBeOptional = [];
|
|
242
|
+
for (let i = signature.args.length - 1; i >= 0; --i) {
|
|
243
|
+
const prevCanBeOptional = (_a = canBeOptional.at(-1)) !== null && _a !== void 0 ? _a : true;
|
|
244
|
+
const curr = signature.args[i];
|
|
245
|
+
const result = prevCanBeOptional && (idl.isOptionalType(curr) || signature.argDefault(i) !== undefined);
|
|
246
|
+
canBeOptional.push(result);
|
|
247
|
+
}
|
|
248
|
+
canBeOptional.reverse();
|
|
249
|
+
const isOptional = signature.args.map((it, i) => idl.isOptionalType(it) && canBeOptional[i] && !isSetter);
|
|
250
|
+
const normalizedArgs = signature.args.map((it, i) => idl.isOptionalType(it) && isOptional[i] ? idl.maybeUnwrapOptionalType(it) : it);
|
|
251
|
+
this.printer.print(`${prefix}${name}${typeParams}(${normalizedArgs.map((it, index) => `${this.escapeKeyword(signature.argName(index))}${isOptional[index] ? "?" : ""}: ${this.getNodeName(it)}${signature.argDefault(index) ? ' = ' + signature.argDefault(index) : ""}`).join(", ")})${needReturn ? ": " + this.getNodeName(signature.returnType) : ""} ${needBracket ? "{" : ""}`);
|
|
252
|
+
}
|
|
253
|
+
makeNull() {
|
|
254
|
+
return new StringExpression("undefined");
|
|
255
|
+
}
|
|
256
|
+
makeAssign(variableName, type, expr, isDeclared = true, isConst = true, options) {
|
|
257
|
+
return new AssignStatement(variableName, type, expr, isDeclared, isConst, options);
|
|
258
|
+
}
|
|
259
|
+
makeLambda(signature, body) {
|
|
260
|
+
return new TSLambdaExpression(this, this.typeConvertor, signature, this.resolver, body);
|
|
261
|
+
}
|
|
262
|
+
makeThrowError(message) {
|
|
263
|
+
return new TSThrowErrorStatement(message);
|
|
264
|
+
}
|
|
265
|
+
makeReturn(expr) {
|
|
266
|
+
return new TSReturnStatement(expr);
|
|
267
|
+
}
|
|
268
|
+
makeCheckOptional(optional, doStatement) {
|
|
269
|
+
return new CheckOptionalStatement("undefined", optional, doStatement);
|
|
270
|
+
}
|
|
271
|
+
makeStatement(expr) {
|
|
272
|
+
return new ExpressionStatement(expr);
|
|
273
|
+
}
|
|
274
|
+
makeLoop(counter, limit, statement) {
|
|
275
|
+
return new TSLoopStatement(counter, limit, statement);
|
|
276
|
+
}
|
|
277
|
+
makeMapForEach(map, key, value, op) {
|
|
278
|
+
return new TSMapForEachStatement(map, key, value, op);
|
|
279
|
+
}
|
|
280
|
+
writePrintLog(message) {
|
|
281
|
+
this.print(`console.log("${message}")`);
|
|
282
|
+
}
|
|
283
|
+
makeCast(value, type, options) {
|
|
284
|
+
var _a;
|
|
285
|
+
return new TSCastExpression(value, this.getNodeName(/* FIXME: */ idl.maybeUnwrapOptionalType(type)), (_a = options === null || options === void 0 ? void 0 : options.unsafe) !== null && _a !== void 0 ? _a : false);
|
|
286
|
+
}
|
|
287
|
+
typeInstanceOf(type, value, members) {
|
|
288
|
+
if (idl.isInterface(type)) {
|
|
289
|
+
if (idl.isInterfaceSubkind(type)) {
|
|
290
|
+
if (!members) {
|
|
291
|
+
throw new Error("Members must be defined for interface type recognition!");
|
|
292
|
+
}
|
|
293
|
+
return this.makeString(members.map(it => `${value}.hasOwnProperty("${it}")`).join("&&"));
|
|
294
|
+
}
|
|
295
|
+
if (idl.isClassSubkind(type)) {
|
|
296
|
+
return super.typeInstanceOf(type, value, members);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
throw new Error(`typeInstanceOf fails: not class or interface: ${this.getNodeName(type)}`);
|
|
300
|
+
}
|
|
301
|
+
getObjectAccessor(convertor, value, args) {
|
|
302
|
+
if (convertor.useArray && (args === null || args === void 0 ? void 0 : args.index) != undefined) {
|
|
303
|
+
return `${value}[${args.index}]`;
|
|
304
|
+
}
|
|
305
|
+
return `${value}`;
|
|
306
|
+
}
|
|
307
|
+
makeUndefined() {
|
|
308
|
+
return this.makeString("undefined");
|
|
309
|
+
}
|
|
310
|
+
makeRuntimeType(rt) {
|
|
311
|
+
return this.makeString(`RuntimeType.${RuntimeType[rt]}`);
|
|
312
|
+
}
|
|
313
|
+
makeTupleAlloc(option) {
|
|
314
|
+
return new TsTupleAllocStatement(option);
|
|
315
|
+
}
|
|
316
|
+
makeArrayInit(type, size) {
|
|
317
|
+
var _a;
|
|
318
|
+
return this.makeString(`new Array<${this.getNodeName(type.elementType[0])}>(${(_a = size === null || size === void 0 ? void 0 : size.toString()) !== null && _a !== void 0 ? _a : ''})`);
|
|
319
|
+
}
|
|
320
|
+
makeClassInit(type, paramenters) {
|
|
321
|
+
return this.makeString(`new ${this.getNodeName(type)}(${paramenters.map(it => it.asString()).join(", ")})`);
|
|
322
|
+
}
|
|
323
|
+
makeMapInit(type) {
|
|
324
|
+
return this.makeString(`new ${this.getNodeName(type)}()`);
|
|
325
|
+
}
|
|
326
|
+
makeMapInsert(keyAccessor, key, valueAccessor, value) {
|
|
327
|
+
// keyAccessor and valueAccessor are equal in TS
|
|
328
|
+
return this.makeStatement(this.makeMethodCall(keyAccessor, "set", [this.makeString(key), this.makeString(value)]));
|
|
329
|
+
}
|
|
330
|
+
makeUnwrapOptional(expression) {
|
|
331
|
+
return new TSUnwrapOptionalExpression(expression);
|
|
332
|
+
}
|
|
333
|
+
getTagType() {
|
|
334
|
+
return idl.createReferenceType("Tags");
|
|
335
|
+
}
|
|
336
|
+
getRuntimeType() {
|
|
337
|
+
return idl.IDLI32Type;
|
|
338
|
+
}
|
|
339
|
+
makeTupleAssign(receiver, fields) {
|
|
340
|
+
return this.makeAssign(receiver, undefined, this.makeString(`[${fields.map(it => `${it}!`).join(",")}]`), false);
|
|
341
|
+
}
|
|
342
|
+
get supportedModifiers() {
|
|
343
|
+
return [MethodModifier.PUBLIC, MethodModifier.PRIVATE, MethodModifier.STATIC];
|
|
344
|
+
}
|
|
345
|
+
get supportedFieldModifiers() {
|
|
346
|
+
return [FieldModifier.PUBLIC, FieldModifier.PRIVATE, FieldModifier.PROTECTED, FieldModifier.READONLY, FieldModifier.STATIC];
|
|
347
|
+
}
|
|
348
|
+
enumFromOrdinal(value, enumEntry) {
|
|
349
|
+
return this.makeString(`Object.values(${idl.forceAsNamedNode(enumEntry).name})[${value.asString()}]`);
|
|
350
|
+
}
|
|
351
|
+
ordinalFromEnum(value, enumEntry) {
|
|
352
|
+
const enumName = idl.forceAsNamedNode(enumEntry).name;
|
|
353
|
+
const decl = idl.isReferenceType(enumEntry) ? this.resolver.resolveTypeReference(enumEntry) : undefined;
|
|
354
|
+
if (decl && idl.isEnum(decl) && idl.isStringEnum(decl)) {
|
|
355
|
+
return this.makeString(`Object.values(${enumName}).indexOf(${value.asString()})`);
|
|
356
|
+
}
|
|
357
|
+
return value;
|
|
358
|
+
}
|
|
359
|
+
makeEnumCast(enumName, unsafe, convertor) {
|
|
360
|
+
if (unsafe) {
|
|
361
|
+
return this.makeUnsafeCast(convertor, enumName);
|
|
362
|
+
}
|
|
363
|
+
return enumName;
|
|
364
|
+
}
|
|
365
|
+
castToBoolean(value) { return `+${value}`; }
|
|
366
|
+
makeCallIsObject(value) {
|
|
367
|
+
return this.makeString(`${value} instanceof Object`);
|
|
368
|
+
}
|
|
369
|
+
escapeKeyword(keyword) {
|
|
370
|
+
return TSKeywords.has(keyword) ? keyword + "_" : keyword;
|
|
371
|
+
}
|
|
372
|
+
makeDiscriminatorConvertor(convertor, value, index) {
|
|
373
|
+
const decl = this.resolver.resolveTypeReference(idl.createReferenceType(this.getNodeName(convertor.nativeType()), undefined, convertor.idlType));
|
|
374
|
+
if (decl === undefined || !idl.isEnum(decl)) {
|
|
375
|
+
throwException(`The type reference ${decl === null || decl === void 0 ? void 0 : decl.name} must be Enum`);
|
|
376
|
+
}
|
|
377
|
+
const ordinal = idl.isStringEnum(decl)
|
|
378
|
+
? this.ordinalFromEnum(this.makeCast(this.makeString(this.getObjectAccessor(convertor, value)), convertor.idlType), idl.createReferenceType(this.getNodeName(convertor.nativeType()), undefined, convertor.idlType))
|
|
379
|
+
: this.makeUnionVariantCast(this.getObjectAccessor(convertor, value), this.getNodeName(idl.IDLI32Type), convertor, index);
|
|
380
|
+
const { low, high } = idl.extremumOfOrdinals(decl);
|
|
381
|
+
return this.discriminatorFromExpressions(value, convertor.runtimeTypes[0], [
|
|
382
|
+
this.makeNaryOp(">=", [ordinal, this.makeString(low.toString())]),
|
|
383
|
+
this.makeNaryOp("<=", [ordinal, this.makeString(high.toString())])
|
|
384
|
+
]);
|
|
385
|
+
}
|
|
386
|
+
makeSerializerConstructorSignature() {
|
|
387
|
+
return new NamedMethodSignature(idl.IDLVoidType, [], []);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
//# sourceMappingURL=TsLanguageWriter.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as idl from "./idl";
|
|
2
|
+
import { Language } from "./Language";
|
|
3
|
+
import { ArgConvertor } from "./LanguageWriters/ArgConvertors";
|
|
4
|
+
import { ReferenceResolver } from "./peer-generation/ReferenceResolver";
|
|
5
|
+
export interface LibraryFileInterface {
|
|
6
|
+
get entries(): idl.IDLEntry[];
|
|
7
|
+
}
|
|
8
|
+
export interface LibraryInterface extends ReferenceResolver {
|
|
9
|
+
language: Language;
|
|
10
|
+
get files(): LibraryFileInterface[];
|
|
11
|
+
typeConvertor(param: string, type: idl.IDLType, isOptionalParam?: boolean): ArgConvertor;
|
|
12
|
+
declarationConvertor(param: string, type: idl.IDLReferenceType, declaration: idl.IDLEntry | undefined): ArgConvertor;
|
|
13
|
+
getInteropName(node: idl.IDLNode): string;
|
|
14
|
+
createContinuationCallbackReference(continuationType: idl.IDLType): idl.IDLReferenceType;
|
|
15
|
+
getCurrentContext(): string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* todo: is it really needed?
|
|
18
|
+
*/
|
|
19
|
+
libraryPrefix: string;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=LibraryInterface.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface GeneratorConfiguration {
|
|
2
|
+
param<T>(name: string): T;
|
|
3
|
+
paramArray<T>(name: string): T[];
|
|
4
|
+
}
|
|
5
|
+
export declare function setDefaultConfiguration(config: GeneratorConfiguration): void;
|
|
6
|
+
export declare function generatorConfiguration(): GeneratorConfiguration;
|
|
7
|
+
export declare function generatorTypePrefix(): string;
|
|
8
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class EmptyGeneratorConfiguration {
|
|
2
|
+
param(name) {
|
|
3
|
+
throw new Error(`${name} is unknown`);
|
|
4
|
+
}
|
|
5
|
+
paramArray(name) {
|
|
6
|
+
throw new Error(`array ${name} is unknown`);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
let currentConfig = new EmptyGeneratorConfiguration();
|
|
10
|
+
export function setDefaultConfiguration(config) {
|
|
11
|
+
currentConfig = config;
|
|
12
|
+
}
|
|
13
|
+
export function generatorConfiguration() {
|
|
14
|
+
return currentConfig;
|
|
15
|
+
}
|
|
16
|
+
export function generatorTypePrefix() {
|
|
17
|
+
const conf = generatorConfiguration();
|
|
18
|
+
return `${conf.param("TypePrefix")}${conf.param("LibraryPrefix")}`;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { stringOrNone } from "../util";
|
|
2
|
+
import { IDLCallback, IDLConstructor, IDLEntry, IDLEnum, IDLInterface, IDLMethod, IDLParameter, IDLProperty, IDLTypedef, IDLNamespace, IDLImport, IDLPackage, IDLReferenceType, IDLCallable, IDLConstant, SignatureTag, IDLVersion } from "../idl";
|
|
3
|
+
import { Language } from "../Language";
|
|
4
|
+
export declare class CustomPrintVisitor {
|
|
5
|
+
private resolver;
|
|
6
|
+
private language;
|
|
7
|
+
output: string[];
|
|
8
|
+
constructor(resolver: (type: IDLReferenceType) => IDLEntry | undefined, language: Language);
|
|
9
|
+
currentInterface?: IDLInterface;
|
|
10
|
+
visit(node: IDLEntry, wrapNamespaces?: boolean): void;
|
|
11
|
+
printMetadata(node: IDLEnum): void;
|
|
12
|
+
printConstant(node: IDLConstant): void;
|
|
13
|
+
printInterface(node: IDLInterface): void;
|
|
14
|
+
printMethod(node: IDLMethod | IDLConstructor | IDLCallable, isGlobal?: boolean): void;
|
|
15
|
+
paramText(paramOrTag: IDLParameter | SignatureTag): string;
|
|
16
|
+
printProperty(node: IDLProperty): void;
|
|
17
|
+
printEnum(node: IDLEnum): void;
|
|
18
|
+
printTypedef(node: IDLTypedef | IDLCallback): void;
|
|
19
|
+
printVersion(node: IDLVersion): void;
|
|
20
|
+
printNamespace(node: IDLNamespace): void;
|
|
21
|
+
printImport(node: IDLImport): void;
|
|
22
|
+
printPackage(node: IDLPackage): void;
|
|
23
|
+
checkVerbatim(node: IDLEntry): void;
|
|
24
|
+
private indent;
|
|
25
|
+
indented(input: string): string;
|
|
26
|
+
pushIndent(): void;
|
|
27
|
+
popIndent(): void;
|
|
28
|
+
print(value: stringOrNone): void;
|
|
29
|
+
private printTypeForTS;
|
|
30
|
+
private toTypeName;
|
|
31
|
+
private callback;
|
|
32
|
+
private literal;
|
|
33
|
+
}
|
|
34
|
+
export declare function idlToDtsString(name: string, content: string): string;
|
|
35
|
+
//# sourceMappingURL=DtsPrinter.d.ts.map
|