@tsonic/emitter 0.0.72 → 0.0.74

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 (207) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/adapter-generator.d.ts.map +1 -1
  3. package/dist/adapter-generator.js +2 -1
  4. package/dist/adapter-generator.js.map +1 -1
  5. package/dist/constants.d.ts +3 -2
  6. package/dist/constants.d.ts.map +1 -1
  7. package/dist/constants.js +15 -6
  8. package/dist/constants.js.map +1 -1
  9. package/dist/core/format/attributes.d.ts.map +1 -1
  10. package/dist/core/format/attributes.js +5 -56
  11. package/dist/core/format/attributes.js.map +1 -1
  12. package/dist/core/format/attributes.test.js +1 -1
  13. package/dist/core/format/attributes.test.js.map +1 -1
  14. package/dist/core/format/backend-ast/builders.d.ts +13 -0
  15. package/dist/core/format/backend-ast/builders.d.ts.map +1 -0
  16. package/dist/core/format/backend-ast/builders.js +169 -0
  17. package/dist/core/format/backend-ast/builders.js.map +1 -0
  18. package/dist/core/format/backend-ast/builders.test.d.ts +2 -0
  19. package/dist/core/format/backend-ast/builders.test.d.ts.map +1 -0
  20. package/dist/core/format/backend-ast/builders.test.js +258 -0
  21. package/dist/core/format/backend-ast/builders.test.js.map +1 -0
  22. package/dist/core/format/backend-ast/index.d.ts +3 -2
  23. package/dist/core/format/backend-ast/index.d.ts.map +1 -1
  24. package/dist/core/format/backend-ast/index.js +2 -1
  25. package/dist/core/format/backend-ast/index.js.map +1 -1
  26. package/dist/core/format/backend-ast/invariants.test.d.ts +2 -0
  27. package/dist/core/format/backend-ast/invariants.test.d.ts.map +1 -0
  28. package/dist/core/format/backend-ast/invariants.test.js +72 -0
  29. package/dist/core/format/backend-ast/invariants.test.js.map +1 -0
  30. package/dist/core/format/backend-ast/printer.d.ts +1 -1
  31. package/dist/core/format/backend-ast/printer.d.ts.map +1 -1
  32. package/dist/core/format/backend-ast/printer.js +362 -119
  33. package/dist/core/format/backend-ast/printer.js.map +1 -1
  34. package/dist/core/format/backend-ast/printer.test.d.ts +2 -0
  35. package/dist/core/format/backend-ast/printer.test.d.ts.map +1 -0
  36. package/dist/core/format/backend-ast/printer.test.js +796 -0
  37. package/dist/core/format/backend-ast/printer.test.js.map +1 -0
  38. package/dist/core/format/backend-ast/types.d.ts +66 -14
  39. package/dist/core/format/backend-ast/types.d.ts.map +1 -1
  40. package/dist/core/format/backend-ast/utils.d.ts +12 -8
  41. package/dist/core/format/backend-ast/utils.d.ts.map +1 -1
  42. package/dist/core/format/backend-ast/utils.js +222 -19
  43. package/dist/core/format/backend-ast/utils.js.map +1 -1
  44. package/dist/core/format/backend-ast/utils.test.d.ts +2 -0
  45. package/dist/core/format/backend-ast/utils.test.d.ts.map +1 -0
  46. package/dist/core/format/backend-ast/utils.test.js +142 -0
  47. package/dist/core/format/backend-ast/utils.test.js.map +1 -0
  48. package/dist/core/format/module-emitter/assembly.d.ts +2 -2
  49. package/dist/core/format/module-emitter/assembly.d.ts.map +1 -1
  50. package/dist/core/format/module-emitter/assembly.js +7 -3
  51. package/dist/core/format/module-emitter/assembly.js.map +1 -1
  52. package/dist/core/format/module-emitter/header.d.ts +2 -1
  53. package/dist/core/format/module-emitter/header.d.ts.map +1 -1
  54. package/dist/core/format/module-emitter/header.js +2 -2
  55. package/dist/core/format/module-emitter/header.js.map +1 -1
  56. package/dist/core/format/module-emitter/orchestrator.js +1 -1
  57. package/dist/core/format/module-emitter/orchestrator.js.map +1 -1
  58. package/dist/core/format/module-emitter/static-container.d.ts.map +1 -1
  59. package/dist/core/format/module-emitter/static-container.js +3 -5
  60. package/dist/core/format/module-emitter/static-container.js.map +1 -1
  61. package/dist/core/module-emitter.test.js +1 -0
  62. package/dist/core/module-emitter.test.js.map +1 -1
  63. package/dist/core/semantic/boolean-context.d.ts.map +1 -1
  64. package/dist/core/semantic/boolean-context.js +45 -49
  65. package/dist/core/semantic/boolean-context.js.map +1 -1
  66. package/dist/core/semantic/imports.d.ts.map +1 -1
  67. package/dist/core/semantic/imports.js +25 -15
  68. package/dist/core/semantic/imports.js.map +1 -1
  69. package/dist/core/semantic/imports.test.js +43 -0
  70. package/dist/core/semantic/imports.test.js.map +1 -1
  71. package/dist/core/semantic/type-resolution.d.ts +1 -0
  72. package/dist/core/semantic/type-resolution.d.ts.map +1 -1
  73. package/dist/core/semantic/type-resolution.js +166 -5
  74. package/dist/core/semantic/type-resolution.js.map +1 -1
  75. package/dist/core/semantic/type-resolution.test.js +35 -0
  76. package/dist/core/semantic/type-resolution.test.js.map +1 -1
  77. package/dist/emitter-types/core.d.ts +24 -10
  78. package/dist/emitter-types/core.d.ts.map +1 -1
  79. package/dist/emitter.d.ts.map +1 -1
  80. package/dist/emitter.js +124 -44
  81. package/dist/emitter.js.map +1 -1
  82. package/dist/expression-emitter.d.ts.map +1 -1
  83. package/dist/expression-emitter.js +797 -17
  84. package/dist/expression-emitter.js.map +1 -1
  85. package/dist/expressions/access.d.ts.map +1 -1
  86. package/dist/expressions/access.js +65 -25
  87. package/dist/expressions/access.js.map +1 -1
  88. package/dist/expressions/calls/call-analysis.d.ts +0 -10
  89. package/dist/expressions/calls/call-analysis.d.ts.map +1 -1
  90. package/dist/expressions/calls/call-analysis.js +3 -62
  91. package/dist/expressions/calls/call-analysis.js.map +1 -1
  92. package/dist/expressions/calls/call-emitter.d.ts.map +1 -1
  93. package/dist/expressions/calls/call-emitter.js +97 -196
  94. package/dist/expressions/calls/call-emitter.js.map +1 -1
  95. package/dist/expressions/calls/new-emitter.d.ts.map +1 -1
  96. package/dist/expressions/calls/new-emitter.js +36 -69
  97. package/dist/expressions/calls/new-emitter.js.map +1 -1
  98. package/dist/expressions/collections.d.ts +3 -0
  99. package/dist/expressions/collections.d.ts.map +1 -1
  100. package/dist/expressions/collections.js +238 -57
  101. package/dist/expressions/collections.js.map +1 -1
  102. package/dist/expressions/functions.d.ts.map +1 -1
  103. package/dist/expressions/functions.js +1 -7
  104. package/dist/expressions/functions.js.map +1 -1
  105. package/dist/expressions/identifiers.d.ts.map +1 -1
  106. package/dist/expressions/identifiers.js +24 -38
  107. package/dist/expressions/identifiers.js.map +1 -1
  108. package/dist/expressions/index.test.js +245 -0
  109. package/dist/expressions/index.test.js.map +1 -1
  110. package/dist/expressions/literals.d.ts.map +1 -1
  111. package/dist/expressions/literals.js +9 -41
  112. package/dist/expressions/literals.js.map +1 -1
  113. package/dist/expressions/operators/assignment-emitter.d.ts.map +1 -1
  114. package/dist/expressions/operators/assignment-emitter.js +2 -6
  115. package/dist/expressions/operators/assignment-emitter.js.map +1 -1
  116. package/dist/expressions/operators/binary-emitter.d.ts.map +1 -1
  117. package/dist/expressions/operators/binary-emitter.js +102 -77
  118. package/dist/expressions/operators/binary-emitter.js.map +1 -1
  119. package/dist/expressions/operators/logical-emitter.d.ts.map +1 -1
  120. package/dist/expressions/operators/logical-emitter.js +1 -3
  121. package/dist/expressions/operators/logical-emitter.js.map +1 -1
  122. package/dist/expressions/operators/unary-emitter.d.ts.map +1 -1
  123. package/dist/expressions/operators/unary-emitter.js +9 -20
  124. package/dist/expressions/operators/unary-emitter.js.map +1 -1
  125. package/dist/expressions/other.d.ts.map +1 -1
  126. package/dist/expressions/other.js +57 -4
  127. package/dist/expressions/other.js.map +1 -1
  128. package/dist/generator-exchange.d.ts.map +1 -1
  129. package/dist/generator-exchange.js +3 -2
  130. package/dist/generator-exchange.js.map +1 -1
  131. package/dist/generator-wrapper.d.ts.map +1 -1
  132. package/dist/generator-wrapper.js +27 -56
  133. package/dist/generator-wrapper.js.map +1 -1
  134. package/dist/integration.test.js +393 -5
  135. package/dist/integration.test.js.map +1 -1
  136. package/dist/json-aot-generic.test.js +3 -0
  137. package/dist/json-aot-generic.test.js.map +1 -1
  138. package/dist/patterns.d.ts.map +1 -1
  139. package/dist/patterns.js +19 -40
  140. package/dist/patterns.js.map +1 -1
  141. package/dist/specialization/type-aliases.test.js +8 -0
  142. package/dist/specialization/type-aliases.test.js.map +1 -1
  143. package/dist/statements/classes/members/methods.d.ts.map +1 -1
  144. package/dist/statements/classes/members/methods.js +5 -22
  145. package/dist/statements/classes/members/methods.js.map +1 -1
  146. package/dist/statements/classes/parameters.d.ts.map +1 -1
  147. package/dist/statements/classes/parameters.js +2 -1
  148. package/dist/statements/classes/parameters.js.map +1 -1
  149. package/dist/statements/classes/properties.d.ts.map +1 -1
  150. package/dist/statements/classes/properties.js +5 -16
  151. package/dist/statements/classes/properties.js.map +1 -1
  152. package/dist/statements/control/conditionals/guard-analysis.d.ts +44 -1
  153. package/dist/statements/control/conditionals/guard-analysis.d.ts.map +1 -1
  154. package/dist/statements/control/conditionals/guard-analysis.js +301 -125
  155. package/dist/statements/control/conditionals/guard-analysis.js.map +1 -1
  156. package/dist/statements/control/conditionals/if-emitter.d.ts.map +1 -1
  157. package/dist/statements/control/conditionals/if-emitter.js +182 -53
  158. package/dist/statements/control/conditionals/if-emitter.js.map +1 -1
  159. package/dist/statements/control/exceptions.d.ts.map +1 -1
  160. package/dist/statements/control/exceptions.js +2 -4
  161. package/dist/statements/control/exceptions.js.map +1 -1
  162. package/dist/statements/control/loops.d.ts.map +1 -1
  163. package/dist/statements/control/loops.js +3 -5
  164. package/dist/statements/control/loops.js.map +1 -1
  165. package/dist/statements/declarations/classes.d.ts.map +1 -1
  166. package/dist/statements/declarations/classes.js +2 -4
  167. package/dist/statements/declarations/classes.js.map +1 -1
  168. package/dist/statements/declarations/functions.d.ts.map +1 -1
  169. package/dist/statements/declarations/functions.js +38 -79
  170. package/dist/statements/declarations/functions.js.map +1 -1
  171. package/dist/statements/declarations/interfaces-mutable-storage.test.js +10 -2
  172. package/dist/statements/declarations/interfaces-mutable-storage.test.js.map +1 -1
  173. package/dist/statements/declarations/interfaces.d.ts.map +1 -1
  174. package/dist/statements/declarations/interfaces.js +4 -12
  175. package/dist/statements/declarations/interfaces.js.map +1 -1
  176. package/dist/statements/declarations/type-aliases.d.ts.map +1 -1
  177. package/dist/statements/declarations/type-aliases.js +5 -9
  178. package/dist/statements/declarations/type-aliases.js.map +1 -1
  179. package/dist/statements/declarations/variables.d.ts.map +1 -1
  180. package/dist/statements/declarations/variables.js +55 -51
  181. package/dist/statements/declarations/variables.js.map +1 -1
  182. package/dist/statements/index.test.js +1026 -0
  183. package/dist/statements/index.test.js.map +1 -1
  184. package/dist/types/dictionaries.d.ts.map +1 -1
  185. package/dist/types/dictionaries.js +5 -5
  186. package/dist/types/dictionaries.js.map +1 -1
  187. package/dist/types/functions.d.ts.map +1 -1
  188. package/dist/types/functions.js +5 -25
  189. package/dist/types/functions.js.map +1 -1
  190. package/dist/types/primitives.d.ts.map +1 -1
  191. package/dist/types/primitives.js.map +1 -1
  192. package/dist/types/references.d.ts.map +1 -1
  193. package/dist/types/references.js +65 -128
  194. package/dist/types/references.js.map +1 -1
  195. package/dist/types/references.test.js +170 -46
  196. package/dist/types/references.test.js.map +1 -1
  197. package/dist/types/tuples.d.ts.map +1 -1
  198. package/dist/types/tuples.js +7 -17
  199. package/dist/types/tuples.js.map +1 -1
  200. package/dist/types/unions.d.ts.map +1 -1
  201. package/dist/types/unions.js +2 -5
  202. package/dist/types/unions.js.map +1 -1
  203. package/package.json +2 -2
  204. package/dist/expressions/parentheses.d.ts +0 -4
  205. package/dist/expressions/parentheses.d.ts.map +0 -1
  206. package/dist/expressions/parentheses.js +0 -91
  207. package/dist/expressions/parentheses.js.map +0 -1
@@ -1,15 +1,17 @@
1
1
  /**
2
2
  * Call expression emitter
3
3
  */
4
+ import { getAwaitedIrType, isAwaitableIrType, } from "@tsonic/frontend";
4
5
  import { emitExpressionAst } from "../../expression-emitter.js";
5
6
  import { emitTypeArgumentsAst, generateSpecializedName, } from "../identifiers.js";
6
7
  import { emitTypeAst } from "../../type-emitter.js";
7
8
  import { emitMemberAccess } from "../access.js";
8
9
  import { isLValue, getPassingModifierFromCast, isJsonSerializerCall, isGlobalJsonCall, isInstanceMemberAccess, shouldEmitFluentExtensionCall, getTypeNamespace, registerJsonAotExpressionTypes, registerJsonAotType, needsIntCast, isPromiseChainMethod, isAsyncWrapperType, } from "./call-analysis.js";
9
- import { extractCalleeNameFromAst } from "../../core/format/backend-ast/utils.js";
10
+ import { extractCalleeNameFromAst, getIdentifierTypeLeafName, } from "../../core/format/backend-ast/utils.js";
10
11
  import { resolveImportPath } from "../../core/semantic/index.js";
11
12
  import { containsTypeParameter } from "../../core/semantic/type-resolution.js";
12
13
  import { allocateLocalName } from "../../core/format/local-names.js";
14
+ import { identifierExpression, identifierType, nullLiteral, stringLiteral, } from "../../core/format/backend-ast/builders.js";
13
15
  /**
14
16
  * Wrap an expression AST with an optional argument modifier (ref/out/in).
15
17
  */
@@ -93,6 +95,9 @@ const captureAssignableArrayTarget = (expr, context) => {
93
95
  kind: "identifierExpression",
94
96
  identifier: indexTemp.emittedName,
95
97
  };
98
+ const indexArgument = receiverAst.arguments[0];
99
+ if (!indexArgument)
100
+ return undefined;
96
101
  return {
97
102
  readExpression: {
98
103
  kind: "elementAccessExpression",
@@ -106,7 +111,7 @@ const captureAssignableArrayTarget = (expr, context) => {
106
111
  },
107
112
  setupStatements: [
108
113
  createVarLocal(objectTemp.emittedName, receiverAst.expression),
109
- createVarLocal(indexTemp.emittedName, receiverAst.arguments[0]),
114
+ createVarLocal(indexTemp.emittedName, indexArgument),
110
115
  ],
111
116
  context: indexTemp.context,
112
117
  };
@@ -198,11 +203,9 @@ const emitArrayMutationInteropCall = (expr, context) => {
198
203
  ...captured.setupStatements,
199
204
  createVarLocal(wrapperTemp.emittedName, {
200
205
  kind: "objectCreationExpression",
201
- type: {
202
- kind: "identifierType",
203
- name: "global::Tsonic.JSRuntime.JSArray",
204
- typeArguments: [elementTypeAst],
205
- },
206
+ type: identifierType("global::Tsonic.JSRuntime.JSArray", [
207
+ elementTypeAst,
208
+ ]),
206
209
  arguments: [captured.readExpression],
207
210
  }),
208
211
  createVarLocal(resultTemp.emittedName, mutationCall),
@@ -279,11 +282,7 @@ const emitArrayWrapperInteropCall = (expr, context) => {
279
282
  }
280
283
  const wrapperAst = {
281
284
  kind: "objectCreationExpression",
282
- type: {
283
- kind: "identifierType",
284
- name: `global::${stripClrGenericArity(bindingType)}`,
285
- typeArguments,
286
- },
285
+ type: identifierType(`global::${stripClrGenericArity(bindingType)}`, typeArguments),
287
286
  arguments: [receiverAst],
288
287
  };
289
288
  const [argAsts, argContext] = emitCallArguments(expr.arguments, expr, currentContext);
@@ -313,20 +312,19 @@ const emitArrayWrapperInteropCall = (expr, context) => {
313
312
  currentContext,
314
313
  ];
315
314
  };
316
- const isTaskTypeAst = (typeAst) => {
317
- if (typeAst.kind !== "identifierType")
318
- return false;
319
- const simple = typeAst.name.includes(".")
320
- ? typeAst.name.slice(typeAst.name.lastIndexOf(".") + 1)
321
- : typeAst.name;
322
- return simple === "Task";
323
- };
315
+ const isTaskTypeAst = (typeAst) => getIdentifierTypeLeafName(typeAst) === "Task";
324
316
  const containsVoidTypeAst = (typeAst) => {
325
317
  if (typeAst.kind === "predefinedType" && typeAst.keyword === "void") {
326
318
  return true;
327
319
  }
328
320
  if (typeAst.kind === "identifierType") {
329
- if (typeAst.name === "void" || typeAst.name.endsWith(".void")) {
321
+ if (typeAst.name === "void") {
322
+ return true;
323
+ }
324
+ return (typeAst.typeArguments ?? []).some((t) => containsVoidTypeAst(t));
325
+ }
326
+ if (typeAst.kind === "qualifiedIdentifierType") {
327
+ if (getIdentifierTypeLeafName(typeAst) === "void") {
330
328
  return true;
331
329
  }
332
330
  return (typeAst.typeArguments ?? []).some((t) => containsVoidTypeAst(t));
@@ -345,9 +343,18 @@ const containsVoidTypeAst = (typeAst) => {
345
343
  }
346
344
  return false;
347
345
  };
348
- const getTaskResultType = (typeAst) => isTaskTypeAst(typeAst) && typeAst.typeArguments?.length === 1
349
- ? typeAst.typeArguments[0]
350
- : undefined;
346
+ const getTaskResultType = (typeAst) => {
347
+ if (!isTaskTypeAst(typeAst)) {
348
+ return undefined;
349
+ }
350
+ if (typeAst.kind !== "identifierType" &&
351
+ typeAst.kind !== "qualifiedIdentifierType") {
352
+ return undefined;
353
+ }
354
+ return typeAst.typeArguments?.length === 1
355
+ ? typeAst.typeArguments[0]
356
+ : undefined;
357
+ };
351
358
  const callbackParameterCount = (callbackExpr) => {
352
359
  if (callbackExpr.kind === "arrowFunction" ||
353
360
  callbackExpr.kind === "functionExpression") {
@@ -441,28 +448,15 @@ const buildDelegateType = (parameterTypes, returnType) => {
441
448
  const isVoidReturn = returnType?.kind === "predefinedType" && returnType.keyword === "void";
442
449
  if (returnType === undefined) {
443
450
  return parameterTypes.length === 0
444
- ? { kind: "identifierType", name: "global::System.Action" }
445
- : {
446
- kind: "identifierType",
447
- name: "global::System.Action",
448
- typeArguments: parameterTypes,
449
- };
451
+ ? identifierType("global::System.Action")
452
+ : identifierType("global::System.Action", parameterTypes);
450
453
  }
451
- if (isVoidReturn ||
452
- (returnType.kind === "identifierType" && returnType.name === "void")) {
454
+ if (isVoidReturn || getIdentifierTypeLeafName(returnType) === "void") {
453
455
  return parameterTypes.length === 0
454
- ? { kind: "identifierType", name: "global::System.Action" }
455
- : {
456
- kind: "identifierType",
457
- name: "global::System.Action",
458
- typeArguments: parameterTypes,
459
- };
456
+ ? identifierType("global::System.Action")
457
+ : identifierType("global::System.Action", parameterTypes);
460
458
  }
461
- return {
462
- kind: "identifierType",
463
- name: "global::System.Func",
464
- typeArguments: [...parameterTypes, returnType],
465
- };
459
+ return identifierType("global::System.Func", [...parameterTypes, returnType]);
466
460
  };
467
461
  const isVoidOrUnknownIrType = (type) => type === undefined ||
468
462
  type.kind === "voidType" ||
@@ -570,8 +564,8 @@ const emitFunctionValueCallArguments = (args, signature, expr, context) => {
570
564
  ? parameter.type.elementType
571
565
  : undefined;
572
566
  let elementTypeAst = {
573
- kind: "identifierType",
574
- name: "object",
567
+ kind: "predefinedType",
568
+ keyword: "object",
575
569
  };
576
570
  if (restElementType) {
577
571
  const [emittedType, typeCtx] = emitTypeAst(restElementType, currentContext);
@@ -728,8 +722,7 @@ const emitFlattenedRestArguments = (restArgs, restElementType, context) => {
728
722
  {
729
723
  kind: "invocationExpression",
730
724
  expression: {
731
- kind: "identifierExpression",
732
- identifier: "global::System.Array.Empty",
725
+ ...identifierExpression("global::System.Array.Empty"),
733
726
  },
734
727
  typeArguments: [elementTypeAst],
735
728
  arguments: [],
@@ -738,15 +731,30 @@ const emitFlattenedRestArguments = (restArgs, restElementType, context) => {
738
731
  currentContext,
739
732
  ];
740
733
  }
741
- let concatAst = segments[0];
734
+ const firstSegment = segments[0];
735
+ if (!firstSegment) {
736
+ return [
737
+ [
738
+ {
739
+ kind: "arrayCreationExpression",
740
+ elementType: elementTypeAst,
741
+ initializer: [],
742
+ },
743
+ ],
744
+ currentContext,
745
+ ];
746
+ }
747
+ let concatAst = firstSegment;
742
748
  for (let index = 1; index < segments.length; index++) {
749
+ const segment = segments[index];
750
+ if (!segment)
751
+ continue;
743
752
  concatAst = {
744
753
  kind: "invocationExpression",
745
754
  expression: {
746
- kind: "identifierExpression",
747
- identifier: "global::System.Linq.Enumerable.Concat",
755
+ ...identifierExpression("global::System.Linq.Enumerable.Concat"),
748
756
  },
749
- arguments: [concatAst, segments[index]],
757
+ arguments: [concatAst, segment],
750
758
  };
751
759
  }
752
760
  return [
@@ -754,8 +762,7 @@ const emitFlattenedRestArguments = (restArgs, restElementType, context) => {
754
762
  {
755
763
  kind: "invocationExpression",
756
764
  expression: {
757
- kind: "identifierExpression",
758
- identifier: "global::System.Linq.Enumerable.ToArray",
765
+ ...identifierExpression("global::System.Linq.Enumerable.ToArray"),
759
766
  },
760
767
  arguments: [concatAst],
761
768
  },
@@ -764,45 +771,8 @@ const emitFlattenedRestArguments = (restArgs, restElementType, context) => {
764
771
  ];
765
772
  };
766
773
  const stableIrTypeKey = (type) => JSON.stringify(type);
767
- const unwrapAsyncWrapperIrType = (type) => {
768
- if (type.kind !== "referenceType")
769
- return undefined;
770
- if (!type.typeArguments || type.typeArguments.length !== 1)
771
- return undefined;
772
- const inner = type.typeArguments[0];
773
- if (!inner)
774
- return undefined;
775
- const simpleName = type.name.split(".").pop() ?? type.name;
776
- const clrName = type.resolvedClrType ?? type.name;
777
- const isAsyncWrapper = simpleName === "Promise" ||
778
- simpleName === "PromiseLike" ||
779
- simpleName === "Task_1" ||
780
- simpleName === "Task`1" ||
781
- simpleName === "ValueTask_1" ||
782
- simpleName === "ValueTask`1" ||
783
- clrName === "System.Threading.Tasks.Task" ||
784
- clrName === "System.Threading.Tasks.ValueTask" ||
785
- clrName.startsWith("System.Threading.Tasks.Task`1") ||
786
- clrName.startsWith("System.Threading.Tasks.ValueTask`1");
787
- return isAsyncWrapper ? inner : undefined;
788
- };
789
774
  const isAsyncWrapperIrTypeLike = (type) => {
790
- if (type.kind !== "referenceType")
791
- return false;
792
- const simpleName = type.name.split(".").pop() ?? type.name;
793
- const clrName = type.resolvedClrType ?? type.name;
794
- return (simpleName === "Promise" ||
795
- simpleName === "PromiseLike" ||
796
- simpleName === "Task" ||
797
- simpleName === "Task_1" ||
798
- simpleName === "Task`1" ||
799
- simpleName === "ValueTask" ||
800
- simpleName === "ValueTask_1" ||
801
- simpleName === "ValueTask`1" ||
802
- clrName === "System.Threading.Tasks.Task" ||
803
- clrName === "System.Threading.Tasks.ValueTask" ||
804
- clrName.startsWith("System.Threading.Tasks.Task`1") ||
805
- clrName.startsWith("System.Threading.Tasks.ValueTask`1"));
775
+ return isAwaitableIrType(type);
806
776
  };
807
777
  const containsPromiseChainArtifact = (type) => {
808
778
  if (!type)
@@ -818,9 +788,11 @@ const containsPromiseChainArtifact = (type) => {
818
788
  const normalizePromiseChainResultIrType = (type) => {
819
789
  if (!type)
820
790
  return undefined;
821
- const asyncInner = unwrapAsyncWrapperIrType(type);
822
- if (asyncInner) {
823
- return normalizePromiseChainResultIrType(asyncInner);
791
+ const awaited = getAwaitedIrType(type);
792
+ if (awaited) {
793
+ return awaited.kind === "voidType"
794
+ ? awaited
795
+ : normalizePromiseChainResultIrType(awaited);
824
796
  }
825
797
  if (type.kind === "unionType") {
826
798
  const normalizedTypes = [];
@@ -883,25 +855,15 @@ const mergePromiseChainResultIrTypes = (...types) => {
883
855
  };
884
856
  };
885
857
  const buildTaskTypeAst = (resultType) => resultType
886
- ? {
887
- kind: "identifierType",
888
- name: "global::System.Threading.Tasks.Task",
889
- typeArguments: [resultType],
890
- }
891
- : {
892
- kind: "identifierType",
893
- name: "global::System.Threading.Tasks.Task",
894
- };
858
+ ? identifierType("global::System.Threading.Tasks.Task", [resultType])
859
+ : identifierType("global::System.Threading.Tasks.Task");
895
860
  const buildTaskRunInvocation = (outputTaskType, body, isAsync) => {
896
861
  const resultType = getTaskResultType(outputTaskType);
897
862
  return {
898
863
  kind: "invocationExpression",
899
864
  expression: {
900
865
  kind: "memberAccessExpression",
901
- expression: {
902
- kind: "identifierExpression",
903
- identifier: "global::System.Threading.Tasks.Task",
904
- },
866
+ expression: identifierExpression("global::System.Threading.Tasks.Task"),
905
867
  memberName: "Run",
906
868
  },
907
869
  arguments: [
@@ -917,35 +879,22 @@ const buildTaskRunInvocation = (outputTaskType, body, isAsync) => {
917
879
  };
918
880
  const buildCompletedTaskAst = () => ({
919
881
  kind: "memberAccessExpression",
920
- expression: {
921
- kind: "identifierExpression",
922
- identifier: "global::System.Threading.Tasks.Task",
923
- },
882
+ expression: identifierExpression("global::System.Threading.Tasks.Task"),
924
883
  memberName: "CompletedTask",
925
884
  });
926
885
  const buildPromiseRejectedExceptionAst = (reasonAst) => {
927
- const reasonExpr = reasonAst ??
928
- {
929
- kind: "literalExpression",
930
- text: "null",
931
- };
886
+ const reasonExpr = reasonAst ?? nullLiteral();
932
887
  return {
933
888
  kind: "binaryExpression",
934
889
  operatorToken: "??",
935
890
  left: {
936
891
  kind: "asExpression",
937
892
  expression: reasonExpr,
938
- type: {
939
- kind: "identifierType",
940
- name: "global::System.Exception",
941
- },
893
+ type: identifierType("global::System.Exception"),
942
894
  },
943
895
  right: {
944
896
  kind: "objectCreationExpression",
945
- type: {
946
- kind: "identifierType",
947
- name: "global::System.Exception",
948
- },
897
+ type: identifierType("global::System.Exception"),
949
898
  arguments: [
950
899
  {
951
900
  kind: "binaryExpression",
@@ -960,8 +909,7 @@ const buildPromiseRejectedExceptionAst = (reasonAst) => {
960
909
  arguments: [],
961
910
  },
962
911
  right: {
963
- kind: "literalExpression",
964
- text: '"Promise rejected"',
912
+ ...stringLiteral("Promise rejected"),
965
913
  },
966
914
  },
967
915
  ],
@@ -1038,10 +986,7 @@ const isValueTaskLikeIrType = (type) => {
1038
986
  };
1039
987
  const emitPromiseNormalizedTaskAst = (valueAst, valueType, resultTypeAst, context) => {
1040
988
  let currentContext = context;
1041
- const asyncInner = valueType
1042
- ? unwrapAsyncWrapperIrType(valueType)
1043
- : undefined;
1044
- if (asyncInner) {
989
+ if (valueType && isAwaitableIrType(valueType)) {
1045
990
  if (isValueTaskLikeIrType(valueType)) {
1046
991
  return [
1047
992
  {
@@ -1100,10 +1045,7 @@ const emitPromiseNormalizedTaskAst = (valueAst, valueType, resultTypeAst, contex
1100
1045
  kind: "invocationExpression",
1101
1046
  expression: {
1102
1047
  kind: "memberAccessExpression",
1103
- expression: {
1104
- kind: "identifierExpression",
1105
- identifier: "global::System.Threading.Tasks.Task",
1106
- },
1048
+ expression: identifierExpression("global::System.Threading.Tasks.Task"),
1107
1049
  memberName: "FromResult",
1108
1050
  },
1109
1051
  typeArguments: [resultTypeAst],
@@ -1145,10 +1087,7 @@ const emitPromiseStaticCall = (expr, context) => {
1145
1087
  kind: "invocationExpression",
1146
1088
  expression: {
1147
1089
  kind: "memberAccessExpression",
1148
- expression: {
1149
- kind: "identifierExpression",
1150
- identifier: "global::System.Threading.Tasks.Task",
1151
- },
1090
+ expression: identifierExpression("global::System.Threading.Tasks.Task"),
1152
1091
  memberName: "FromException",
1153
1092
  },
1154
1093
  typeArguments: outputResultType ? [outputResultType] : undefined,
@@ -1177,10 +1116,7 @@ const emitPromiseStaticCall = (expr, context) => {
1177
1116
  currentContext = normalizedTaskContext;
1178
1117
  normalizedValuesAst = {
1179
1118
  kind: "invocationExpression",
1180
- expression: {
1181
- kind: "identifierExpression",
1182
- identifier: "global::System.Linq.Enumerable.Select",
1183
- },
1119
+ expression: identifierExpression("global::System.Linq.Enumerable.Select"),
1184
1120
  arguments: [
1185
1121
  valuesAst,
1186
1122
  {
@@ -1203,10 +1139,7 @@ const emitPromiseStaticCall = (expr, context) => {
1203
1139
  kind: "invocationExpression",
1204
1140
  expression: {
1205
1141
  kind: "memberAccessExpression",
1206
- expression: {
1207
- kind: "identifierExpression",
1208
- identifier: "global::System.Threading.Tasks.Task",
1209
- },
1142
+ expression: identifierExpression("global::System.Threading.Tasks.Task"),
1210
1143
  memberName: "WhenAll",
1211
1144
  },
1212
1145
  arguments: [normalizedValuesAst],
@@ -1218,10 +1151,7 @@ const emitPromiseStaticCall = (expr, context) => {
1218
1151
  kind: "invocationExpression",
1219
1152
  expression: {
1220
1153
  kind: "memberAccessExpression",
1221
- expression: {
1222
- kind: "identifierExpression",
1223
- identifier: "global::System.Threading.Tasks.Task",
1224
- },
1154
+ expression: identifierExpression("global::System.Threading.Tasks.Task"),
1225
1155
  memberName: "WhenAny",
1226
1156
  },
1227
1157
  arguments: [normalizedValuesAst],
@@ -1299,18 +1229,14 @@ const buildDynamicImportContainerType = (targetModule) => {
1299
1229
  const containerName = targetModule.hasTypeCollision
1300
1230
  ? `${targetModule.className}__Module`
1301
1231
  : targetModule.className;
1302
- return {
1303
- kind: "identifierType",
1304
- name: `global::${targetModule.namespace}.${containerName}`,
1305
- };
1232
+ return identifierType(`global::${targetModule.namespace}.${containerName}`);
1306
1233
  };
1307
1234
  const buildRunClassConstructorExpression = (containerType) => ({
1308
1235
  kind: "invocationExpression",
1309
1236
  expression: {
1310
1237
  kind: "memberAccessExpression",
1311
1238
  expression: {
1312
- kind: "identifierExpression",
1313
- identifier: "global::System.Runtime.CompilerServices.RuntimeHelpers",
1239
+ ...identifierExpression("global::System.Runtime.CompilerServices.RuntimeHelpers"),
1314
1240
  },
1315
1241
  memberName: "RunClassConstructor",
1316
1242
  },
@@ -1334,10 +1260,7 @@ const emitDynamicImportCall = (expr, context) => {
1334
1260
  return null;
1335
1261
  const completedTaskExpr = {
1336
1262
  kind: "memberAccessExpression",
1337
- expression: {
1338
- kind: "identifierExpression",
1339
- identifier: "global::System.Threading.Tasks.Task",
1340
- },
1263
+ expression: identifierExpression("global::System.Threading.Tasks.Task"),
1341
1264
  memberName: "CompletedTask",
1342
1265
  };
1343
1266
  const targetModule = resolveDynamicImportTargetModule(specifier, context);
@@ -1352,10 +1275,7 @@ const emitDynamicImportCall = (expr, context) => {
1352
1275
  kind: "invocationExpression",
1353
1276
  expression: {
1354
1277
  kind: "memberAccessExpression",
1355
- expression: {
1356
- kind: "identifierExpression",
1357
- identifier: "global::System.Threading.Tasks.Task",
1358
- },
1278
+ expression: identifierExpression("global::System.Threading.Tasks.Task"),
1359
1279
  memberName: "Run",
1360
1280
  },
1361
1281
  arguments: [
@@ -1384,7 +1304,7 @@ const emitDynamicImportCall = (expr, context) => {
1384
1304
  ? [
1385
1305
  {
1386
1306
  kind: "objectCreationExpression",
1387
- type: { kind: "identifierType", name: "object" },
1307
+ type: { kind: "predefinedType", keyword: "object" },
1388
1308
  arguments: [],
1389
1309
  },
1390
1310
  currentContext,
@@ -1432,10 +1352,9 @@ const emitPromiseThenCatchFinally = (expr, context) => {
1432
1352
  : expr.inferredType;
1433
1353
  const [rawOutputTaskType, outputTaskCtx] = emitTypeAst(outputTypeHint ?? { kind: "referenceType", name: "Task" }, currentContext);
1434
1354
  currentContext = outputTaskCtx;
1435
- const defaultOutputTaskType = isTaskTypeAst(rawOutputTaskType) &&
1436
- rawOutputTaskType.typeArguments?.length === 1 &&
1437
- containsVoidTypeAst(rawOutputTaskType.typeArguments[0])
1438
- ? { kind: "identifierType", name: "global::System.Threading.Tasks.Task" }
1355
+ const rawOutputTaskResultType = getTaskResultType(rawOutputTaskType);
1356
+ const defaultOutputTaskType = rawOutputTaskResultType && containsVoidTypeAst(rawOutputTaskResultType)
1357
+ ? identifierType("global::System.Threading.Tasks.Task")
1439
1358
  : rawOutputTaskType;
1440
1359
  const [sourceTaskType, sourceTaskCtx] = emitTypeAst(expr.callee.object.inferredType ?? { kind: "referenceType", name: "Task" }, currentContext);
1441
1360
  currentContext = sourceTaskCtx;
@@ -1508,7 +1427,7 @@ const emitPromiseThenCatchFinally = (expr, context) => {
1508
1427
  : {
1509
1428
  kind: "localDeclarationStatement",
1510
1429
  modifiers: [],
1511
- type: { kind: "identifierType", name: "var" },
1430
+ type: { kind: "varType" },
1512
1431
  declarators: [
1513
1432
  {
1514
1433
  name: valueIdent,
@@ -1616,7 +1535,7 @@ const emitPromiseThenCatchFinally = (expr, context) => {
1616
1535
  const callbackCallee = rejectedAst.kind === "lambdaExpression"
1617
1536
  ? {
1618
1537
  kind: "castExpression",
1619
- type: buildDelegateType([{ kind: "identifierType", name: "global::System.Exception" }], callbackReturnTypeAst),
1538
+ type: buildDelegateType([identifierType("global::System.Exception")], callbackReturnTypeAst),
1620
1539
  expression: rejectedAst,
1621
1540
  }
1622
1541
  : rejectedAst;
@@ -1681,10 +1600,7 @@ const emitPromiseThenCatchFinally = (expr, context) => {
1681
1600
  body: { kind: "blockStatement", statements: thenStatements },
1682
1601
  catches: [
1683
1602
  {
1684
- type: {
1685
- kind: "identifierType",
1686
- name: "global::System.Exception",
1687
- },
1603
+ type: identifierType("global::System.Exception"),
1688
1604
  identifier: exIdent,
1689
1605
  body: {
1690
1606
  kind: "blockStatement",
@@ -1714,7 +1630,7 @@ const emitPromiseThenCatchFinally = (expr, context) => {
1714
1630
  ];
1715
1631
  const catches = [
1716
1632
  {
1717
- type: { kind: "identifierType", name: "global::System.Exception" },
1633
+ type: identifierType("global::System.Exception"),
1718
1634
  identifier: exIdent,
1719
1635
  body: {
1720
1636
  kind: "blockStatement",
@@ -1854,10 +1770,7 @@ const emitJsRuntimeJsonParseCall = (expr, context, typeArgument) => {
1854
1770
  kind: "invocationExpression",
1855
1771
  expression: {
1856
1772
  kind: "memberAccessExpression",
1857
- expression: {
1858
- kind: "identifierExpression",
1859
- identifier: "global::Tsonic.JSRuntime.JSON",
1860
- },
1773
+ expression: identifierExpression("global::Tsonic.JSRuntime.JSON"),
1861
1774
  memberName: "parse",
1862
1775
  },
1863
1776
  arguments: argAsts,
@@ -1915,19 +1828,13 @@ const emitJsonSerializerCall = (expr, context, method, deserializeTypeOverride)
1915
1828
  // unknown and should emit plain JsonSerializer calls without requiring the
1916
1829
  // generated TsonicJson helper.
1917
1830
  if (context.options.jsonAotRegistry?.needsJsonAot) {
1918
- argAsts.push({
1919
- kind: "identifierExpression",
1920
- identifier: "TsonicJson.Options",
1921
- });
1831
+ argAsts.push(identifierExpression("TsonicJson.Options"));
1922
1832
  }
1923
1833
  const invocation = {
1924
1834
  kind: "invocationExpression",
1925
1835
  expression: {
1926
1836
  kind: "memberAccessExpression",
1927
- expression: {
1928
- kind: "identifierExpression",
1929
- identifier: "global::System.Text.Json.JsonSerializer",
1930
- },
1837
+ expression: identifierExpression("global::System.Text.Json.JsonSerializer"),
1931
1838
  memberName: method,
1932
1839
  },
1933
1840
  arguments: argAsts,
@@ -2092,10 +1999,7 @@ export const emitCall = (expr, context) => {
2092
1999
  ];
2093
2000
  const invocation = {
2094
2001
  kind: "invocationExpression",
2095
- expression: {
2096
- kind: "identifierExpression",
2097
- identifier: finalCalleeName,
2098
- },
2002
+ expression: identifierExpression(finalCalleeName),
2099
2003
  arguments: allArgAsts,
2100
2004
  typeArguments: typeArgAsts.length > 0 ? typeArgAsts : undefined,
2101
2005
  };
@@ -2103,10 +2007,7 @@ export const emitCall = (expr, context) => {
2103
2007
  const callAst = expr.inferredType?.kind === "arrayType"
2104
2008
  ? {
2105
2009
  kind: "invocationExpression",
2106
- expression: {
2107
- kind: "identifierExpression",
2108
- identifier: "global::System.Linq.Enumerable.ToArray",
2109
- },
2010
+ expression: identifierExpression("global::System.Linq.Enumerable.ToArray"),
2110
2011
  arguments: [invocation],
2111
2012
  }
2112
2013
  : invocation;