@idlizer/core 2.1.9-arktscgen-8 → 2.1.10-arktscgen-2

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.
Files changed (51) hide show
  1. package/build/lib/src/IndentedPrinter.d.ts +2 -1
  2. package/build/lib/src/IndentedPrinter.js +9 -2
  3. package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +35 -26
  4. package/build/lib/src/LanguageWriters/ArgConvertors.js +152 -117
  5. package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +5 -4
  6. package/build/lib/src/LanguageWriters/LanguageWriter.js +16 -15
  7. package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +1 -1
  8. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +1 -1
  9. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +6 -6
  10. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +1 -1
  11. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +6 -6
  12. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +8 -1
  13. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +28 -8
  14. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +1 -1
  15. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +8 -8
  16. package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.d.ts +1 -1
  17. package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.js +6 -6
  18. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +1 -1
  19. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +7 -7
  20. package/build/lib/src/config.d.ts +132 -132
  21. package/build/lib/src/config.js +4 -4
  22. package/build/lib/src/configDescriber.js +1 -1
  23. package/build/lib/src/diagnosticmessages.d.ts +18 -12
  24. package/build/lib/src/diagnosticmessages.js +22 -14
  25. package/build/lib/src/diagnostictypes.d.ts +3 -9
  26. package/build/lib/src/formatter.d.ts +2 -1
  27. package/build/lib/src/formatter.js +3 -3
  28. package/build/lib/src/from-idl/deserialize.js +138 -6
  29. package/build/lib/src/from-idl/parser.d.ts +99 -0
  30. package/build/lib/src/from-idl/parser.js +939 -0
  31. package/build/lib/src/idl.d.ts +13 -1
  32. package/build/lib/src/idl.js +6 -0
  33. package/build/lib/src/index.d.ts +1 -0
  34. package/build/lib/src/index.js +1 -0
  35. package/build/lib/src/peer-generation/LayoutManager.d.ts +1 -1
  36. package/build/lib/src/peer-generation/Materialized.d.ts +1 -1
  37. package/build/lib/src/peer-generation/Materialized.js +4 -4
  38. package/build/lib/src/peer-generation/PeerClass.d.ts +5 -0
  39. package/build/lib/src/peer-generation/PeerClass.js +2 -1
  40. package/build/lib/src/peer-generation/PeerLibrary.d.ts +1 -0
  41. package/build/lib/src/peer-generation/PeerLibrary.js +8 -2
  42. package/build/lib/src/peer-generation/PeerMethod.d.ts +8 -2
  43. package/build/lib/src/peer-generation/PeerMethod.js +22 -4
  44. package/build/lib/src/peer-generation/modules.js +21 -6
  45. package/build/lib/src/util.d.ts +1 -0
  46. package/build/lib/src/util.js +5 -0
  47. package/package.json +10 -3
  48. package/build/lib/src/LanguageWriters/convertors/KotlinConvertor.d.ts +0 -24
  49. package/build/lib/src/LanguageWriters/convertors/KotlinConvertor.js +0 -69
  50. package/build/lib/src/peer-generation/isExternalType.d.ts +0 -4
  51. package/build/lib/src/peer-generation/isExternalType.js +0 -15
@@ -13,7 +13,6 @@
13
13
  * limitations under the License.
14
14
  */
15
15
  import * as idl from "../idl";
16
- import { indentedBy } from "../util";
17
16
  import * as fs from "fs";
18
17
  import { RuntimeType } from "./common";
19
18
  export class TernaryExpression {
@@ -143,13 +142,14 @@ export class ExpressionStatement {
143
142
  }
144
143
  }
145
144
  export class BlockStatement {
146
- constructor(statements, inScope = true) {
145
+ constructor(statements, inScope = true, newLine = true) {
147
146
  this.statements = statements;
148
147
  this.inScope = inScope;
148
+ this.newLine = newLine;
149
149
  }
150
150
  write(writer) {
151
151
  if (this.inScope) {
152
- writer.print("{");
152
+ this.newLine ? writer.print("{") : writer.printer.appendLastString(" {");
153
153
  writer.pushIndent();
154
154
  }
155
155
  this.statements.forEach(s => s.write(writer));
@@ -175,7 +175,12 @@ export class IfStatement {
175
175
  }
176
176
  });
177
177
  if (this.elseStatement !== undefined) {
178
- writer.print("else");
178
+ if ((this.thenStatement instanceof BlockStatement) && this.thenStatement.inScope) {
179
+ writer.printer.appendLastString(" else");
180
+ }
181
+ else {
182
+ writer.print("else");
183
+ }
179
184
  this.writeBody(writer, this.elseStatement, () => {
180
185
  if (this.insideElseOp) {
181
186
  this.insideElseOp();
@@ -206,7 +211,7 @@ export class MultiBranchIfStatement {
206
211
  writer.print(`if (${expr.asString()}) {`);
207
212
  }
208
213
  else {
209
- writer.print(`else if (${expr.asString()}) {`);
214
+ writer.printer.appendLastString(` else if (${expr.asString()}) {`);
210
215
  }
211
216
  writer.pushIndent();
212
217
  stmt.write(writer);
@@ -214,7 +219,7 @@ export class MultiBranchIfStatement {
214
219
  writer.print("}");
215
220
  });
216
221
  if (this.statements.length > 0 && this.elseStatement !== undefined) {
217
- writer.print("else {");
222
+ writer.printer.appendLastString(" else {");
218
223
  writer.pushIndent();
219
224
  this.elseStatement.write(writer);
220
225
  writer.popIndent();
@@ -268,21 +273,17 @@ export class LambdaExpression {
268
273
  this.resolver = resolver;
269
274
  this.body = body;
270
275
  }
271
- bodyAsString() {
272
- var _a;
276
+ bodyAsString(isScoped = false) {
273
277
  const writer = this.originalWriter.fork();
274
278
  if (this.body) {
275
- for (const stmt of this.body) {
276
- stmt.write(writer);
277
- }
279
+ writer.writeStatement(new BlockStatement(this.body, isScoped, false));
278
280
  }
279
281
  writer.features.forEach(([feature, module]) => {
280
282
  this.originalWriter.addFeature(feature, module);
281
283
  });
282
- return (this.body ? ((_a = this.body) === null || _a === void 0 ? void 0 : _a.length) > 1 ? '\n' : '' : '').concat(writer.getOutput()
283
- .filter(line => line !== "")
284
- .map(line => indentedBy(line.endsWith('{') || line.endsWith('}') || line.endsWith(';') ? line : `${line};`, 1))
285
- .join("\n"));
284
+ return writer.getOutput()
285
+ .map(line => (line.endsWith('{') || line.endsWith('}') || line.endsWith(';')) ? line : `${line};`)
286
+ .join("\n");
286
287
  }
287
288
  }
288
289
  ////////////////////////////////////////////////////////////////
@@ -166,7 +166,7 @@ export class TSTypeNameConvertor {
166
166
  case idl.IDLDate:
167
167
  return 'Date';
168
168
  case idl.IDLBufferType:
169
- return 'NativeBuffer';
169
+ return 'ArrayBuffer';
170
170
  case idl.IDLInteropReturnBufferType:
171
171
  return `KInteropReturnBuffer`;
172
172
  }
@@ -123,7 +123,7 @@ export declare class CJLanguageWriter extends LanguageWriter {
123
123
  makeReturn(expr: LanguageExpression): LanguageStatement;
124
124
  makeStatement(expr: LanguageExpression): LanguageStatement;
125
125
  makeLoop(counter: string, limit: string, statement?: LanguageStatement): LanguageStatement;
126
- makeMapForEach(map: string, key: string, value: string, op: () => void): LanguageStatement;
126
+ makeMapForEach(map: string, key: string, value: string, body: LanguageStatement[]): LanguageStatement;
127
127
  makeDefinedCheck(value: string): LanguageExpression;
128
128
  makeNewObject(objectName: string, params?: LanguageExpression[]): LanguageExpression;
129
129
  writePrintLog(message: string): void;
@@ -16,7 +16,7 @@ import * as idl from "../../idl";
16
16
  import { IndentedPrinter } from "../../IndentedPrinter";
17
17
  import { CJKeywords } from "../../languageSpecificKeywords";
18
18
  import { RuntimeType } from "../common";
19
- import { AssignStatement, ExpressionStatement, FieldModifier, LambdaExpression, LanguageWriter, MethodModifier, MethodSignature, ReturnStatement, StringExpression } from "../LanguageWriter";
19
+ import { AssignStatement, BlockStatement, ExpressionStatement, FieldModifier, LambdaExpression, LanguageWriter, MethodModifier, MethodSignature, ReturnStatement, StringExpression } from "../LanguageWriter";
20
20
  import { Language } from "../../Language";
21
21
  import { indentedBy, isDefined } from "../../util";
22
22
  ////////////////////////////////////////////////////////////////
@@ -145,16 +145,16 @@ class CJLoopStatement {
145
145
  }
146
146
  }
147
147
  class CJMapForEachStatement {
148
- constructor(map, key, value, op) {
148
+ constructor(map, key, value, body) {
149
149
  this.map = map;
150
150
  this.key = key;
151
151
  this.value = value;
152
- this.op = op;
152
+ this.body = body;
153
153
  }
154
154
  write(writer) {
155
155
  writer.print(`for ((${this.key}, ${this.value}) in ${this.map}) {`);
156
156
  writer.pushIndent();
157
- this.op();
157
+ writer.writeStatement(new BlockStatement(this.body, false));
158
158
  writer.popIndent();
159
159
  writer.print(`}`);
160
160
  }
@@ -483,8 +483,8 @@ export class CJLanguageWriter extends LanguageWriter {
483
483
  makeLoop(counter, limit, statement) {
484
484
  return new CJLoopStatement(counter, limit, statement);
485
485
  }
486
- makeMapForEach(map, key, value, op) {
487
- return new CJMapForEachStatement(map, key, value, op);
486
+ makeMapForEach(map, key, value, body) {
487
+ return new CJMapForEachStatement(map, key, value, body);
488
488
  }
489
489
  makeDefinedCheck(value) {
490
490
  return new CJCheckDefinedExpression(this.escapeKeyword(value));
@@ -92,7 +92,7 @@ export declare class CppLanguageWriter extends CLikeLanguageWriter {
92
92
  makeUnionVariantCast(value: string, type: string, convertor: ArgConvertor, index: number): LanguageExpression;
93
93
  makeStaticMethodCall(receiver: string, method: string, params: LanguageExpression[], nullable?: boolean): LanguageExpression;
94
94
  makeLoop(counter: string, limit: string, statement?: LanguageStatement): LanguageStatement;
95
- makeMapForEach(map: string, key: string, value: string, op: () => void): LanguageStatement;
95
+ makeMapForEach(map: string, key: string, value: string, body: LanguageStatement[]): LanguageStatement;
96
96
  makeArrayInit(type: IDLContainerType): LanguageExpression;
97
97
  makeClassInit(type: IDLType, paramenters: LanguageExpression[]): LanguageExpression;
98
98
  makeMapInit(type: IDLType): LanguageExpression;
@@ -123,18 +123,18 @@ class CppMapResizeStatement {
123
123
  }
124
124
  }
125
125
  class CppMapForEachStatement {
126
- constructor(map, key, value, op) {
126
+ constructor(map, key, value, body) {
127
127
  this.map = map;
128
128
  this.key = key;
129
129
  this.value = value;
130
- this.op = op;
130
+ this.body = body;
131
131
  }
132
132
  write(writer) {
133
133
  writer.print(`for (int32_t i = 0; i < ${this.map}.size; i++) {`);
134
134
  writer.pushIndent();
135
135
  writer.print(`auto ${this.key} = ${this.map}.keys[i];`);
136
136
  writer.print(`auto ${this.value} = ${this.map}.values[i];`);
137
- this.op();
137
+ writer.writeStatement(new BlockStatement(this.body, false));
138
138
  writer.popIndent();
139
139
  writer.print(`}`);
140
140
  }
@@ -179,7 +179,7 @@ export class CppLanguageWriter extends CLikeLanguageWriter {
179
179
  }
180
180
  fork(options) {
181
181
  var _a;
182
- return new CppLanguageWriter(new IndentedPrinter(), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor, this.primitivesTypes);
182
+ return new CppLanguageWriter(new IndentedPrinter([], this.indentDepth()), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor, this.primitivesTypes);
183
183
  }
184
184
  writeDeclaration(name, signature, modifiers, postfix) {
185
185
  const realName = this.classMode === 'normal' ? name : `${this.currentClass.at(0)}::${name}`;
@@ -320,8 +320,8 @@ export class CppLanguageWriter extends CLikeLanguageWriter {
320
320
  makeLoop(counter, limit, statement) {
321
321
  return new CLikeLoopStatement(counter, limit, statement);
322
322
  }
323
- makeMapForEach(map, key, value, op) {
324
- return new CppMapForEachStatement(map, key, value, op);
323
+ makeMapForEach(map, key, value, body) {
324
+ return new CppMapForEachStatement(map, key, value, body);
325
325
  }
326
326
  makeArrayInit(type) {
327
327
  return this.makeString(`{}`);
@@ -7,6 +7,12 @@ import * as idl from '../../idl';
7
7
  import { IdlNameConvertor } from "../nameConvertor";
8
8
  import { RuntimeType } from "../common";
9
9
  import { ReferenceResolver } from "../../peer-generation/ReferenceResolver";
10
+ export declare class ETSStringExpression implements LanguageExpression {
11
+ value: string;
12
+ constructor(value: string);
13
+ private changeQuotes;
14
+ asString(): string;
15
+ }
10
16
  export declare class EtsAssignStatement implements LanguageStatement {
11
17
  variableName: string;
12
18
  type: IDLType | undefined;
@@ -44,7 +50,8 @@ export declare class ETSLanguageWriter extends TSLanguageWriter {
44
50
  }): LanguageWriter;
45
51
  makeAssign(variableName: string, type: IDLType | undefined, expr: LanguageExpression, isDeclared?: boolean, isConst?: boolean, options?: MakeAssignOptions): LanguageStatement;
46
52
  makeLambda(signature: MethodSignature, body?: LanguageStatement[]): LanguageExpression;
47
- makeMapForEach(map: string, key: string, value: string, op: () => void): LanguageStatement;
53
+ makeString(value: string): LanguageExpression;
54
+ makeMapForEach(map: string, key: string, value: string, body: LanguageStatement[]): LanguageStatement;
48
55
  makeMapSize(map: string): LanguageExpression;
49
56
  get supportedModifiers(): MethodModifier[];
50
57
  runtimeType(param: ArgConvertor, valueType: string, value: string): void;
@@ -13,7 +13,7 @@
13
13
  * limitations under the License.
14
14
  */
15
15
  import { IndentedPrinter } from "../../IndentedPrinter";
16
- import { LambdaExpression, MethodModifier } from "../LanguageWriter";
16
+ import { BlockStatement, LambdaExpression, MethodModifier } from "../LanguageWriter";
17
17
  import { TSCastExpression, TSLanguageWriter } from "./TsLanguageWriter";
18
18
  import { getExtAttribute, IDLThisType } from '../../idl';
19
19
  import { AggregateConvertor, CustomTypeConvertor, InterfaceConvertor, MaterializedClassConvertor } from "../ArgConvertors";
@@ -22,6 +22,23 @@ import { convertDeclaration } from "../nameConvertor";
22
22
  import { createDeclarationNameConvertor } from "../../peer-generation/idl/IdlNameConvertor";
23
23
  import { Language } from "../../Language";
24
24
  ////////////////////////////////////////////////////////////////
25
+ // EXPRESSIONS //
26
+ ////////////////////////////////////////////////////////////////
27
+ export class ETSStringExpression {
28
+ constructor(value) {
29
+ this.value = value;
30
+ }
31
+ changeQuotes(value) {
32
+ return `'${value.substring(1, value.length - 1)}'`;
33
+ }
34
+ asString() {
35
+ if (this.value.startsWith('"') && this.value.endsWith('"')) {
36
+ return this.changeQuotes(this.value);
37
+ }
38
+ return this.value;
39
+ }
40
+ }
41
+ ////////////////////////////////////////////////////////////////
25
42
  // STATEMENTS //
26
43
  ////////////////////////////////////////////////////////////////
27
44
  export class EtsAssignStatement {
@@ -49,18 +66,18 @@ export class EtsAssignStatement {
49
66
  }
50
67
  }
51
68
  class ArkTSMapForEachStatement {
52
- constructor(map, key, value, op) {
69
+ constructor(map, key, value, body) {
53
70
  this.map = map;
54
71
  this.key = key;
55
72
  this.value = value;
56
- this.op = op;
73
+ this.body = body;
57
74
  }
58
75
  write(writer) {
59
76
  writer.print(`for (const pair of ${this.map}) {`);
60
77
  writer.pushIndent();
61
78
  writer.print(`const ${this.key} = pair[0]`);
62
79
  writer.print(`const ${this.value} = pair[1]`);
63
- this.op();
80
+ writer.writeStatement(new BlockStatement(this.body, false));
64
81
  writer.popIndent();
65
82
  writer.print(`}`);
66
83
  }
@@ -126,7 +143,7 @@ export class ETSLambdaExpression extends LambdaExpression {
126
143
  isRetTypeCallback = resolved !== undefined && idl.isCallback(resolved);
127
144
  }
128
145
  return `(${params.join(", ")})${isRetTypeCallback
129
- ? "" : `:${this.convertor.convert(this.signature.returnType)}`} => { ${this.bodyAsString()} }`;
146
+ ? "" : `:${this.convertor.convert(this.signature.returnType)}`} =>${this.bodyAsString(true)}`;
130
147
  }
131
148
  }
132
149
  ////////////////////////////////////////////////////////////////
@@ -160,7 +177,7 @@ export class ETSLanguageWriter extends TSLanguageWriter {
160
177
  }
161
178
  fork(options) {
162
179
  var _a;
163
- return new ETSLanguageWriter(new IndentedPrinter(), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor, this.arrayConvertor);
180
+ return new ETSLanguageWriter(new IndentedPrinter([], this.indentDepth()), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor, this.arrayConvertor);
164
181
  }
165
182
  makeAssign(variableName, type, expr, isDeclared = true, isConst = true, options) {
166
183
  return new EtsAssignStatement(variableName, type, expr, isDeclared, isConst, options);
@@ -168,8 +185,11 @@ export class ETSLanguageWriter extends TSLanguageWriter {
168
185
  makeLambda(signature, body) {
169
186
  return new ETSLambdaExpression(this, this.typeConvertor, signature, this.resolver, body);
170
187
  }
171
- makeMapForEach(map, key, value, op) {
172
- return new ArkTSMapForEachStatement(map, key, value, op);
188
+ makeString(value) {
189
+ return new ETSStringExpression(value);
190
+ }
191
+ makeMapForEach(map, key, value, body) {
192
+ return new ArkTSMapForEachStatement(map, key, value, body);
173
193
  }
174
194
  makeMapSize(map) {
175
195
  return this.makeString(`${super.makeMapSize(map).asString()}`); // TODO: cast really needed?
@@ -49,7 +49,7 @@ export declare class JavaLanguageWriter extends CLikeLanguageWriter {
49
49
  makeReturn(expr: LanguageExpression): LanguageStatement;
50
50
  makeDefinedCheck(value: string): LanguageExpression;
51
51
  makeLoop(counter: string, limit: string, statement?: LanguageStatement): LanguageStatement;
52
- makeMapForEach(map: string, key: string, value: string, op: () => void): LanguageStatement;
52
+ makeMapForEach(map: string, key: string, value: string, body: LanguageStatement[]): LanguageStatement;
53
53
  makeMapSize(map: string): LanguageExpression;
54
54
  makeCast(value: LanguageExpression, node: idl.IDLNode, options?: MakeCastOptions): LanguageExpression;
55
55
  makeStatement(expr: LanguageExpression): LanguageStatement;
@@ -14,7 +14,7 @@
14
14
  */
15
15
  import { Language } from '../../Language';
16
16
  import { IndentedPrinter } from "../../IndentedPrinter";
17
- import { AssignStatement, FieldModifier, LambdaExpression, Method, MethodModifier, MethodSignature, NamedMethodSignature, } from "../LanguageWriter";
17
+ import { AssignStatement, BlockStatement, FieldModifier, LambdaExpression, Method, MethodModifier, MethodSignature, NamedMethodSignature, } from "../LanguageWriter";
18
18
  import { CLikeExpressionStatement, CLikeLanguageWriter, CLikeLoopStatement, CLikeReturnStatement } from "./CLikeLanguageWriter";
19
19
  import * as idl from '../../idl';
20
20
  import { RuntimeType } from "../common";
@@ -30,7 +30,7 @@ class JavaLambdaExpression extends LambdaExpression {
30
30
  }
31
31
  asString() {
32
32
  const params = this.signature.args.map((it, i) => `${idl.forceAsNamedNode(it).name} ${this.signature.argName(i)}`);
33
- return `(${params.join(", ")}) -> { ${this.bodyAsString()} }`;
33
+ return `(${params.join(", ")}) ->${this.bodyAsString(true)}`;
34
34
  }
35
35
  }
36
36
  export class JavaCastExpression {
@@ -66,11 +66,11 @@ export class JavaAssignStatement extends AssignStatement {
66
66
  }
67
67
  }
68
68
  class JavaMapForEachStatement {
69
- constructor(map, key, value, op) {
69
+ constructor(map, key, value, body) {
70
70
  this.map = map;
71
71
  this.key = key;
72
72
  this.value = value;
73
- this.op = op;
73
+ this.body = body;
74
74
  }
75
75
  write(writer) {
76
76
  const entryVar = `${this.map}Entry`;
@@ -78,7 +78,7 @@ class JavaMapForEachStatement {
78
78
  writer.pushIndent();
79
79
  writer.print(`var ${this.key} = ${entryVar}.getKey();`);
80
80
  writer.print(`var ${this.value} = ${entryVar}.getValue();`);
81
- this.op();
81
+ writer.writeStatement(new BlockStatement(this.body, false));
82
82
  writer.popIndent();
83
83
  writer.print(`}`);
84
84
  }
@@ -103,7 +103,7 @@ export class JavaLanguageWriter extends CLikeLanguageWriter {
103
103
  }
104
104
  fork(options) {
105
105
  var _a;
106
- return new JavaLanguageWriter(new IndentedPrinter(), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor);
106
+ return new JavaLanguageWriter(new IndentedPrinter([], this.indentDepth()), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor);
107
107
  }
108
108
  writeClass(name, op, superClass, interfaces, generics, isDeclared, isExport = true) {
109
109
  let genericsClause = (generics === null || generics === void 0 ? void 0 : generics.length) ? `<${generics.join(', ')}> ` : ``;
@@ -194,8 +194,8 @@ export class JavaLanguageWriter extends CLikeLanguageWriter {
194
194
  makeLoop(counter, limit, statement) {
195
195
  return new CLikeLoopStatement(counter, limit, statement);
196
196
  }
197
- makeMapForEach(map, key, value, op) {
198
- return new JavaMapForEachStatement(map, key, value, op);
197
+ makeMapForEach(map, key, value, body) {
198
+ return new JavaMapForEachStatement(map, key, value, body);
199
199
  }
200
200
  makeMapSize(map) {
201
201
  return this.makeString(`${map}.size()`);
@@ -102,7 +102,7 @@ export declare class KotlinLanguageWriter extends LanguageWriter {
102
102
  makeLambdaReturn(expr: LanguageExpression): LanguageStatement;
103
103
  makeStatement(expr: LanguageExpression): LanguageStatement;
104
104
  makeLoop(counter: string, limit: string, statement?: LanguageStatement): LanguageStatement;
105
- makeMapForEach(map: string, key: string, value: string, op: () => void): LanguageStatement;
105
+ makeMapForEach(map: string, key: string, value: string, body: LanguageStatement[]): LanguageStatement;
106
106
  writePrintLog(message: string): void;
107
107
  makeCast(value: LanguageExpression, node: idl.IDLNode, options?: MakeCastOptions): LanguageExpression;
108
108
  typeInstanceOf(type: idl.IDLEntry, value: string, members?: string[]): LanguageExpression;
@@ -15,7 +15,7 @@
15
15
  import * as idl from '../../idl';
16
16
  import { Language } from '../../Language';
17
17
  import { IndentedPrinter } from "../../IndentedPrinter";
18
- import { AssignStatement, DelegationType, ExpressionStatement, FieldModifier, LambdaExpression, LanguageWriter, Method, MethodModifier, MethodSignature, ReturnStatement } from "../LanguageWriter";
18
+ import { AssignStatement, BlockStatement, DelegationType, ExpressionStatement, FieldModifier, LambdaExpression, LanguageWriter, Method, MethodModifier, MethodSignature, ReturnStatement } from "../LanguageWriter";
19
19
  import { RuntimeType } from "../common";
20
20
  import { isDefined } from "../../util";
21
21
  import { removePoints } from '../convertors/CJConvertors';
@@ -108,16 +108,16 @@ export class KotlinEnumWithGetter {
108
108
  }
109
109
  }
110
110
  class KotlinMapForEachStatement {
111
- constructor(map, key, value, op) {
111
+ constructor(map, key, value, body) {
112
112
  this.map = map;
113
113
  this.key = key;
114
114
  this.value = value;
115
- this.op = op;
115
+ this.body = body;
116
116
  }
117
117
  write(writer) {
118
118
  writer.print(`for ((${this.key}, ${this.value}) in ${this.map}) {`);
119
119
  writer.pushIndent();
120
- this.op();
120
+ writer.writeStatement(new BlockStatement(this.body, false));
121
121
  writer.popIndent();
122
122
  writer.print(`}`);
123
123
  }
@@ -460,8 +460,8 @@ export class KotlinLanguageWriter extends LanguageWriter {
460
460
  makeLoop(counter, limit, statement) {
461
461
  return new KotlinLoopStatement(counter, limit, statement);
462
462
  }
463
- makeMapForEach(map, key, value, op) {
464
- return new KotlinMapForEachStatement(map, key, value, op);
463
+ makeMapForEach(map, key, value, body) {
464
+ return new KotlinMapForEachStatement(map, key, value, body);
465
465
  }
466
466
  writePrintLog(message) {
467
467
  this.print(`println(\"${message}\")`);
@@ -76,7 +76,7 @@ export declare class TSLanguageWriter extends LanguageWriter {
76
76
  makeReturn(expr: LanguageExpression): LanguageStatement;
77
77
  makeStatement(expr: LanguageExpression): LanguageStatement;
78
78
  makeLoop(counter: string, limit: string, statement?: LanguageStatement): LanguageStatement;
79
- makeMapForEach(map: string, key: string, value: string, op: () => void): LanguageStatement;
79
+ makeMapForEach(map: string, key: string, value: string, body: LanguageStatement[]): LanguageStatement;
80
80
  writePrintLog(message: string): void;
81
81
  makeCast(value: LanguageExpression, node: idl.IDLNode, options?: MakeCastOptions): LanguageExpression;
82
82
  typeInstanceOf(type: idl.IDLEntry, value: string, members?: string[]): LanguageExpression;
@@ -36,7 +36,7 @@ export class TSLambdaExpression extends LambdaExpression {
36
36
  const maybeOptional = idl.isOptionalType(it) ? "?" : "";
37
37
  return `${this.signature.argName(i)}${maybeOptional}: ${this.convertor.convert(it)}`;
38
38
  });
39
- return `(${params.join(", ")}): ${this.convertor.convert(this.signature.returnType)} => { ${this.bodyAsString()} }`;
39
+ return `(${params.join(", ")}): ${this.convertor.convert(this.signature.returnType)} =>${this.bodyAsString(true)}`;
40
40
  }
41
41
  }
42
42
  export class TSCastExpression {
@@ -93,16 +93,16 @@ class TSLoopStatement {
93
93
  }
94
94
  }
95
95
  class TSMapForEachStatement {
96
- constructor(map, key, value, op) {
96
+ constructor(map, key, value, body) {
97
97
  this.map = map;
98
98
  this.key = key;
99
99
  this.value = value;
100
- this.op = op;
100
+ this.body = body;
101
101
  }
102
102
  write(writer) {
103
103
  writer.print(`for (const [${this.key}, ${this.value}] of ${this.map}) {`);
104
104
  writer.pushIndent();
105
- this.op();
105
+ writer.writeStatement(new BlockStatement(this.body, false));
106
106
  writer.popIndent();
107
107
  writer.print(`}`);
108
108
  }
@@ -133,7 +133,7 @@ export class TSLanguageWriter extends LanguageWriter {
133
133
  }
134
134
  fork(options) {
135
135
  var _a;
136
- 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);
136
+ return new TSLanguageWriter(new IndentedPrinter([], this.indentDepth()), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor, this.language);
137
137
  }
138
138
  getNodeName(type) {
139
139
  // another stub. Bad one.
@@ -316,8 +316,8 @@ export class TSLanguageWriter extends LanguageWriter {
316
316
  makeLoop(counter, limit, statement) {
317
317
  return new TSLoopStatement(counter, limit, statement);
318
318
  }
319
- makeMapForEach(map, key, value, op) {
320
- return new TSMapForEachStatement(map, key, value, op);
319
+ makeMapForEach(map, key, value, body) {
320
+ return new TSMapForEachStatement(map, key, value, body);
321
321
  }
322
322
  writePrintLog(message) {
323
323
  this.print(`console.log("${message}")`);