@nstudio/nativescript-compiler 9.2.0-alpha.10 → 9.2.0-alpha.12

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 (181) hide show
  1. package/dist/api/ir.js +7 -1
  2. package/dist/cli/runtime.cjs +7 -1
  3. package/dist/css/css.js +30 -6
  4. package/dist/driver/cli.js +2 -0
  5. package/dist/driver/compile.js +23 -10
  6. package/dist/driver/paths.js +7 -0
  7. package/dist/driver/unimplemented.js +15 -0
  8. package/dist/kotlin/access.js +23 -5
  9. package/dist/kotlin/arguments.js +5 -0
  10. package/dist/kotlin/builtins.js +0 -4
  11. package/dist/kotlin/calls.js +6 -2
  12. package/dist/kotlin/class-methods.js +9 -3
  13. package/dist/kotlin/components.js +13 -8
  14. package/dist/kotlin/conversion.js +17 -5
  15. package/dist/kotlin/core-api.js +2 -13
  16. package/dist/kotlin/declarations.js +2 -0
  17. package/dist/kotlin/expression-statements.js +5 -4
  18. package/dist/kotlin/expressions.js +8 -3
  19. package/dist/kotlin/functions.js +13 -4
  20. package/dist/kotlin/global-calls.js +11 -0
  21. package/dist/kotlin/literals.js +58 -14
  22. package/dist/kotlin/names.js +2 -2
  23. package/dist/kotlin/native/api.js +9 -1
  24. package/dist/kotlin/native/calls.js +84 -3
  25. package/dist/kotlin/native/subclasses.js +4 -3
  26. package/dist/kotlin/native/types.js +8 -5
  27. package/dist/kotlin/operators.js +4 -1
  28. package/dist/kotlin/overrides.js +7 -5
  29. package/dist/kotlin/placement.js +3 -1
  30. package/dist/kotlin/prototype-calls.js +5 -0
  31. package/dist/kotlin/render.js +62 -0
  32. package/dist/kotlin/statements.js +9 -0
  33. package/dist/kotlin/static-calls.js +10 -7
  34. package/dist/kotlin/translator.js +31 -11
  35. package/dist/kotlin/type-facts.js +10 -2
  36. package/dist/kotlin/types.js +6 -6
  37. package/dist/plugins/native-android.js +37 -5
  38. package/dist/plugins/native-ios.js +2 -0
  39. package/dist/plugins/source.js +73 -23
  40. package/dist/program/app-modules.js +91 -16
  41. package/dist/program/app-paths.js +80 -12
  42. package/dist/program/class-mixins.js +463 -0
  43. package/dist/program/core-facts.js +7 -0
  44. package/dist/program/glob.js +274 -0
  45. package/dist/program/platform.js +32 -4
  46. package/dist/program/program.js +239 -38
  47. package/dist/program/source-lines.js +4 -1
  48. package/dist/program/vite-plugins.js +144 -0
  49. package/dist/semantics/apis/globals.js +2 -2
  50. package/dist/semantics/apis/object.js +1 -0
  51. package/dist/semantics/apis/statics.js +6 -0
  52. package/dist/semantics/ast.js +20 -2
  53. package/dist/semantics/classes.js +36 -1
  54. package/dist/semantics/facts.js +28 -1
  55. package/dist/semantics/globals.js +3 -0
  56. package/dist/semantics/lang.js +13 -1
  57. package/dist/semantics/nullish.js +29 -11
  58. package/dist/semantics/refuse-receivers.js +3 -3
  59. package/dist/semantics/refuse-scope.js +2 -7
  60. package/dist/semantics/runtime.js +1 -0
  61. package/dist/semantics/shapes.js +21 -1
  62. package/dist/semantics/states/value-states.js +1 -1
  63. package/dist/semantics/throws.js +1 -0
  64. package/dist/semantics/translator-methods.js +1 -1
  65. package/dist/semantics/types.js +21 -1
  66. package/dist/swift/access.js +25 -10
  67. package/dist/swift/arguments.js +10 -2
  68. package/dist/swift/assignment.js +12 -1
  69. package/dist/swift/builtins.js +0 -4
  70. package/dist/swift/calls.js +6 -2
  71. package/dist/swift/class-methods.js +3 -3
  72. package/dist/swift/components.js +28 -8
  73. package/dist/swift/construction.js +4 -0
  74. package/dist/swift/conversion.js +1 -1
  75. package/dist/swift/core-api.js +9 -12
  76. package/dist/swift/from-any.js +2 -2
  77. package/dist/swift/functions.js +13 -2
  78. package/dist/swift/generics.js +5 -1
  79. package/dist/swift/global-calls.js +2 -0
  80. package/dist/swift/literals.js +57 -10
  81. package/dist/swift/modules.js +1 -1
  82. package/dist/swift/names.js +1 -1
  83. package/dist/swift/native/sdk-tables.js +52 -4
  84. package/dist/swift/native/sdk.js +9 -1
  85. package/dist/swift/operators.js +4 -1
  86. package/dist/swift/parameters.js +5 -2
  87. package/dist/swift/placement.js +44 -4
  88. package/dist/swift/prototype-calls.js +17 -2
  89. package/dist/swift/render.js +64 -0
  90. package/dist/swift/results.js +1 -1
  91. package/dist/swift/statements.js +9 -0
  92. package/dist/swift/static-calls.js +13 -6
  93. package/dist/swift/types.js +9 -9
  94. package/dist/targets/android/build.js +18 -12
  95. package/dist/targets/ios/build.js +11 -10
  96. package/dist/targets/ios/dependencies.js +12 -0
  97. package/dist/targets/resources.js +15 -1
  98. package/dist/template/plan.js +105 -8
  99. package/dist/types/adapter-api.d.ts +13 -0
  100. package/dist/types/ir.d.ts +47 -0
  101. package/kit-android/generated/kotlin/org/nativescript/kit/__Objects.kt +102 -7485
  102. package/kit-android/generated/kotlin/org/nativescript/kit/application_application.kt +4 -4
  103. package/kit-android/generated/kotlin/org/nativescript/kit/image_source_index.kt +1 -1
  104. package/kit-android/generated/kotlin/org/nativescript/kit/ui_animation_animation_common.kt +7 -3
  105. package/kit-android/generated/kotlin/org/nativescript/kit/ui_animation_index.kt +3 -1
  106. package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_view_base_index.kt +2 -4
  107. package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_view_index.kt +5 -6
  108. package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_view_view_common.kt +1 -3
  109. package/kit-android/generated/kotlin/org/nativescript/kit/ui_dialogs_index.kt +11 -6
  110. package/kit-android/generated/kotlin/org/nativescript/kit/ui_frame_fragment_transitions.kt +1 -1
  111. package/kit-android/generated/kotlin/org/nativescript/kit/ui_frame_frame_common.kt +1 -1
  112. package/kit-android/generated/kotlin/org/nativescript/kit/ui_frame_frame_helper_for_android.kt +7 -5
  113. package/kit-android/generated/kotlin/org/nativescript/kit/ui_frame_index.kt +6 -3
  114. package/kit-android/generated/kotlin/org/nativescript/kit/ui_gestures_touch_manager.kt +1 -1
  115. package/kit-android/generated/kotlin/org/nativescript/kit/ui_layouts_flexbox_layout_index.kt +1 -1
  116. package/kit-android/generated/kotlin/org/nativescript/kit/ui_search_bar_index.kt +4 -3
  117. package/kit-android/generated/kotlin/org/nativescript/kit/ui_segmented_bar_index.kt +2 -2
  118. package/kit-android/generated/kotlin/org/nativescript/kit/ui_text_base_formatted_string.kt +1 -3
  119. package/kit-android/generated/kotlin/org/nativescript/kit/ui_text_base_index.kt +1 -1
  120. package/kit-android/generated/kotlin/org/nativescript/kit/ui_transition_fade_transition.kt +1 -1
  121. package/kit-android/generated/kotlin/org/nativescript/kit/ui_transition_flip_transition.kt +8 -8
  122. package/kit-android/generated/kotlin/org/nativescript/kit/utils_index.kt +1 -1
  123. package/kit-android/generated/source-lines.json +1 -1
  124. package/kit-android/gradlew.bat +94 -0
  125. package/kit-android/src/fromcore/kotlin/org/nativescript/kit/CoreBridge.kt +67 -1
  126. package/kit-android/src/main/kotlin/org/nativescript/kit/Signals.kt +15 -2
  127. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Prototypes.kt +26 -0
  128. package/kit-apple/Overlays/xml-free/Core/ui.core.bindable.index.swift +4 -4
  129. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity1.swift +26 -161
  130. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity2.swift +9 -284
  131. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity3Plus.swift +11 -7
  132. package/kit-apple/Sources/NativeScriptKit/Core/Object_callback_thisArg_once.swift +1 -1
  133. package/kit-apple/Sources/NativeScriptKit/Core/Object_eventName_object_index_section_view_ios_android.swift +7 -5
  134. package/kit-apple/Sources/NativeScriptKit/Core/Object_eventName_object_oldIndex_newIndex.swift +4 -2
  135. package/kit-apple/Sources/NativeScriptKit/Core/{Object_iterator_prototype_for_keyFor_hasInstance_isConcatSpreadable_and_19_more_91b5f3.swift → Object_iterator_prototype_for_keyFor_hasInstance_isConcatSpreadable_and_19_more_fa18e1.swift} +28 -103
  136. package/kit-apple/Sources/NativeScriptKit/Core/__Namespace.Utils.swift +17 -15
  137. package/kit-apple/Sources/NativeScriptKit/Core/application-settings.index.ios.swift +8 -8
  138. package/kit-apple/Sources/NativeScriptKit/Core/application.application-common.swift +4 -4
  139. package/kit-apple/Sources/NativeScriptKit/Core/color.color-common.swift +7 -7
  140. package/kit-apple/Sources/NativeScriptKit/Core/data.observable.index.swift +3 -3
  141. package/kit-apple/Sources/NativeScriptKit/Core/http.http-request-internal.index.ios.swift +2 -1
  142. package/kit-apple/Sources/NativeScriptKit/Core/image-source.index.ios.swift +1 -1
  143. package/kit-apple/Sources/NativeScriptKit/Core/kit-index.json +40 -246
  144. package/kit-apple/Sources/NativeScriptKit/Core/manifest.json +1 -2
  145. package/kit-apple/Sources/NativeScriptKit/Core/ui.action-bar.index.ios.swift +3 -3
  146. package/kit-apple/Sources/NativeScriptKit/Core/ui.button.index.ios.swift +4 -4
  147. package/kit-apple/Sources/NativeScriptKit/Core/ui.content-view.index.swift +8 -8
  148. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.bindable.index.swift +4 -4
  149. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.index.ios.swift +8 -8
  150. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.view-common.swift +1 -3
  151. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.view-helper.view-helper-common.swift +7 -7
  152. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.weak-event-listener.index.swift +3 -3
  153. package/kit-apple/Sources/NativeScriptKit/Core/ui.frame.index.ios.swift +4 -4
  154. package/kit-apple/Sources/NativeScriptKit/Core/ui.gestures.index.ios.swift +2 -2
  155. package/kit-apple/Sources/NativeScriptKit/Core/ui.html-view.index.ios.swift +4 -4
  156. package/kit-apple/Sources/NativeScriptKit/Core/ui.image.image-common.swift +2 -2
  157. package/kit-apple/Sources/NativeScriptKit/Core/ui.image.index.ios.swift +4 -4
  158. package/kit-apple/Sources/NativeScriptKit/Core/ui.label.index.ios.swift +4 -4
  159. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.absolute-layout.index.ios.swift +4 -4
  160. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.dock-layout.index.ios.swift +4 -4
  161. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.flexbox-layout.index.ios.swift +3 -3
  162. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.grid-layout.index.ios.swift +4 -4
  163. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.stack-layout.index.ios.swift +4 -4
  164. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.wrap-layout.index.ios.swift +4 -4
  165. package/kit-apple/Sources/NativeScriptKit/Core/ui.list-view.index.ios.swift +3 -3
  166. package/kit-apple/Sources/NativeScriptKit/Core/ui.page.index.ios.swift +4 -4
  167. package/kit-apple/Sources/NativeScriptKit/Core/ui.repeater.index.swift +10 -6
  168. package/kit-apple/Sources/NativeScriptKit/Core/ui.scroll-view.index.ios.swift +4 -4
  169. package/kit-apple/Sources/NativeScriptKit/Core/ui.split-view.index.ios.swift +4 -4
  170. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.background.ios.swift +1 -1
  171. package/kit-apple/Sources/NativeScriptKit/Core/ui.tab-view.index.ios.swift +4 -4
  172. package/kit-apple/Sources/NativeScriptKit/Core/ui.text-base.formatted-string.swift +2 -1
  173. package/kit-apple/Sources/NativeScriptKit/Core/utils.common.swift +9 -9
  174. package/kit-apple/Sources/NativeScriptKit/Core/utils.layout-helper.index.ios.swift +10 -10
  175. package/kit-apple/Sources/NativeScriptKit/CoreBridge.swift +67 -1
  176. package/kit-apple/Sources/NativeScriptKit/Runtime/Lowering.swift +4 -0
  177. package/kit-apple/Sources/NativeScriptKit/Runtime/Prototypes.swift +25 -0
  178. package/kit-apple/Sources/NativeScriptKit/Runtime/RegExp.swift +6 -0
  179. package/kit-apple/Sources/NativeScriptKit/Signals.swift +20 -2
  180. package/package.json +2 -1
  181. package/kit-apple/Sources/NativeScriptKit/Core/Object_toString_charAt_charCodeAt_concat_indexOf_lastIndexOf_and_44_more_fc25df.swift +0 -481
@@ -33,9 +33,12 @@ export const functionsMethods = {
33
33
  // ---- Functions -----------------------------------------------------------------------------
34
34
  /** `override`: an override's, which takes a constant default from the method it overrides. */
35
35
  params(fn, closure, override = false) {
36
- if (this.readsArguments(fn))
37
- return '__arguments: JSArray<Any?>';
38
36
  const implicit = this.implicitThis(fn) ? ['__this: Any?'] : [];
37
+ if (this.readsArguments(fn)) {
38
+ const explicitThis = fn.parameters.find((p) => isThisParameter(p) && !this.voidThis(p));
39
+ const selfParam = implicit.length ? implicit : explicitThis ? [`__this: ${this.type(this.checker.getTypeAtLocation(explicitThis.name), explicitThis)}`] : [];
40
+ return [...selfParam, '__arguments: JSArray<Any?>'].join(', ');
41
+ }
39
42
  return [
40
43
  ...implicit,
41
44
  ...fn.parameters.map((p, k) => {
@@ -384,14 +387,20 @@ export const functionsMethods = {
384
387
  }
385
388
  }
386
389
  const ret = this.closureResult(fn, slotRet).target;
387
- if (!ts.isMethodDeclaration(fn) && fn.name && fn.body && refersTo(fn.body, this.checker.getSymbolAtLocation(fn.name), this.checker))
388
- throw this.error(fn, 'a named function expression', 'named-function-expression');
389
390
  let params = this.params(fn, true);
390
391
  // A slot's function type may take more parameters than the literal declares (JavaScript ignores extras).
391
392
  const slotParams = slotParts?.params ?? [];
392
393
  const given = ts.isFunctionExpression(fn) && thisArgBound(fn, this.checker) ? fn.parameters.filter((q) => !isThisParameter(q)).length : fn.parameters.length;
393
394
  for (let k = given; k < slotParams.length; k++)
394
395
  params += `${params ? ', ' : ''}__u${k}: ${slotParams[k]}`;
396
+ if (!ts.isMethodDeclaration(fn) && fn.name && fn.body && refersTo(fn.body, this.checker.getSymbolAtLocation(fn.name), this.checker)) {
397
+ const fnName = ident(fn.name.text);
398
+ const pTypes = splitTopLevel(params)
399
+ .map((p) => p.trim())
400
+ .filter(Boolean)
401
+ .map((p) => p.slice(p.indexOf(':') + 1).trim());
402
+ return `run { lateinit var ${fnName}: (${pTypes.join(', ')}) -> ${ret}; ${fnName} = fun(${params})${ret === 'Unit' ? '' : `: ${ret}`} ${this.functionBody(fn, ret, this.indent)}; ${fnName} }`;
403
+ }
395
404
  return this.asLambda(fn, params, ret) ?? `fun(${params})${ret === 'Unit' ? '' : `: ${ret}`} ${this.functionBody(fn, ret, this.indent)}`;
396
405
  },
397
406
  /** A function literal's result slot, where `slotRet` is the result of the function type it is given as: nothing where that returns void, else its own type. */
@@ -120,6 +120,15 @@ export const globalCallsMethods = {
120
120
  case 'clearTimeout':
121
121
  case 'clearInterval':
122
122
  return `${RT[globalOp(op)]}(${arg(0) ? this.restArgument(e, arg(0), 'Double?') : 'null'})`;
123
+ case 'requestAnimationFrame': {
124
+ const takesTime = this.checker
125
+ .getTypeAtLocation(arg(0))
126
+ .getCallSignatures()
127
+ .some((sig) => sig.parameters.length > 0);
128
+ return `org.nativescript.kit.requestAnimationFrame { __t -> (${this.fn(arg(0))})(${takesTime ? '__t' : ''}); Unit }`;
129
+ }
130
+ case 'cancelAnimationFrame':
131
+ return `org.nativescript.kit.cancelAnimationFrame(${arg(0) ? this.restArgument(e, arg(0), 'Double?') : 'null'})`;
123
132
  case 'Symbol':
124
133
  return `${RT.jsSymbol}(${arg(0) ? this.str(arg(0)) : 'null'})`;
125
134
  case 'BigInt':
@@ -130,6 +139,8 @@ export const globalCallsMethods = {
130
139
  // `Error('x')` constructs as `new Error('x')` does; so does `Array(n)`.
131
140
  if (ERRORS[name])
132
141
  return this.errorValue(name, e.arguments);
142
+ if (name === 'getComputedStyle')
143
+ return `run { ${arg(0) ? `${this.coerce(arg(0), 'Any?')}; ` : ''}JSObject("getPropertyValue" to JSFunction { "" }) }`;
133
144
  if (name === 'Array' && isLibGlobal(this, callee))
134
145
  return this.arrayConstruct(e, this.typeOf(e), e.arguments);
135
146
  // `RegExp(re)` without flags is `re` itself; otherwise it constructs as `new RegExp` does.
@@ -1,13 +1,13 @@
1
1
  // Literals as Kotlin: arrays, objects and class expressions, structural copies and dynamic objects.
2
2
  import ts from 'typescript';
3
3
  import { cast, destructuringSource, ident, isNullable, jsObjectCode, kotlinString, optionalType, splitTopLevel, spell, RT } from "./syntax.js";
4
- import { assertedOperand, evolvingElementContext, intersectionAliasMembers, literalKey, openSpreadType, spreadOperand, unquoted, wellKnownMember } from "../semantics/lang.js";
5
- import { holdsNil, literalNotes, signatureField, shapePlanOfLiteral, spelledOptional, resultShapeNamed } from "../semantics/shapes.js";
4
+ import { assertedOperand, evolvingElementContext, intersectionAliasMembers, isTypeParameterType, literalKey, openSpreadType, spreadOperand, unquoted, wellKnownMember } from "../semantics/lang.js";
5
+ import { holdsNil, literalNotes, signatureField, shapePlanOfLiteral, spelledOptional, spreadElementNeedsMap, resultShapeNamed } from "../semantics/shapes.js";
6
6
  import { structural } from "../semantics/conversion.js";
7
7
  import { heldOf, isKit, isUntyped, parseNativeType, spelledType } from "../semantics/types.js";
8
8
  import { boxStep, unboxStep } from "../semantics/type-step.js";
9
9
  import { place } from "../semantics/placement.js";
10
- import { isLibDeclaration, thisNodes } from "../semantics/ast.js";
10
+ import { hasModifier, isLibDeclaration, thisNodes, tupleSpreadTypes } from "../semantics/ast.js";
11
11
  import { isCoreDeclaration } from "../program/core-facts.js";
12
12
  import { isStatic } from "../semantics/throws.js";
13
13
  import { programSymbolKey } from "../program/stable-names.js";
@@ -42,6 +42,39 @@ export const literalsMethods = {
42
42
  return 'JSMatch.empty()';
43
43
  if (t.startsWith('Pair<') || t.startsWith('Triple<')) {
44
44
  const types = splitTopLevel(t.replace(/^(Pair|Triple)<(.*)>$/, '$2'));
45
+ if (e.elements.some(ts.isSpreadElement)) {
46
+ const binds = [];
47
+ const items = [];
48
+ for (const x of e.elements) {
49
+ if (ts.isSpreadElement(x)) {
50
+ const tArgs = tupleSpreadTypes(x, this.checker);
51
+ if (tArgs) {
52
+ const spreadCode = this.expr(x.expression);
53
+ const ref = ts.isIdentifier(x.expression) ? spreadCode : this.fresh('__tup');
54
+ if (ref !== spreadCode)
55
+ binds.push(`val ${ref} = ${spreadCode}`);
56
+ const spreadType = this.typeOf(x.expression);
57
+ const pairOrTriple = spreadType.startsWith('Pair<') || spreadType.startsWith('Triple<');
58
+ for (let k = 0; k < tArgs.length; k++) {
59
+ const elem = pairOrTriple ? `${ref}.${['first', 'second', 'third'][k]}` : `${ref}[${k}]`;
60
+ const from = this.type(tArgs[k], x);
61
+ const targetType = types[items.length];
62
+ items.push(targetType && targetType !== from ? this.convert(elem, from, targetType) : elem);
63
+ }
64
+ continue;
65
+ }
66
+ throw this.error(x, `a non-tuple spread in ${t}`);
67
+ }
68
+ const to = types[items.length];
69
+ items.push(to ? this.coerce(x, to) : this.expr(x));
70
+ }
71
+ const missing = types
72
+ .slice(items.length)
73
+ .filter(isNullable)
74
+ .map(() => 'null');
75
+ const made = `${t.replace(/<.*/, '')}(${[...items, ...missing].join(', ')})`;
76
+ return binds.length ? `run { ${binds.join('; ')}; ${made} }` : made;
77
+ }
45
78
  // A literal shorter than its tuple type leaves an optional element out: undefined there.
46
79
  const missing = types
47
80
  .slice(e.elements.length)
@@ -71,8 +104,7 @@ export const literalsMethods = {
71
104
  run = [];
72
105
  }
73
106
  const items = `(${this.iterable(x.expression)}).toList()`;
74
- // Library mode: an array of untyped values (`const cssClasses = []`) spread where the literal's elements are typed.
75
- parts.push(this.library && !isUntyped(spelledType(el)) && isUntyped(spelledType(this.elementTypeOf(x.expression))) ? `${items}.map { ${this.fromAny('it', el)} }` : items);
107
+ parts.push(spreadElementNeedsMap(this.elementTypeOf(x.expression), el, (n) => this.isShapeType(n), !!this.library) ? `${items}.map { ${this.fromAny('it', el)} }` : items);
76
108
  }
77
109
  else if (ts.isOmittedExpression(x))
78
110
  throw this.error(x, 'an array hole', 'array-hole');
@@ -119,6 +151,8 @@ export const literalsMethods = {
119
151
  return `${r}.obj[${ts.isComputedPropertyName(p.name) ? this.propertyKey(p.name.expression) : kotlinString(literalKey(p.name, this.checker) ?? p.name.getText())}] = ${this.stored(p.initializer, p, v)}`;
120
152
  if (ts.isShorthandPropertyAssignment(p))
121
153
  return `${r}.obj[${kotlinString(p.name.text)}] = ${this.shorthandValue(p.name)}`;
154
+ if (ts.isMethodDeclaration(p))
155
+ return `${r}.obj[${ts.isComputedPropertyName(p.name) ? this.propertyKey(p.name.expression) : kotlinString(literalKey(p.name, this.checker) ?? p.name.getText())}] = ${this.untypedMethod(p)}`;
122
156
  throw this.error(p, 'this member in a dictionary literal');
123
157
  });
124
158
  return `run { val ${r} = ${name}(); ${steps.join('; ')}; ${r} }`;
@@ -128,6 +162,8 @@ export const literalsMethods = {
128
162
  return `Pair(${ts.isComputedPropertyName(p.name) ? this.propertyKey(p.name.expression) : kotlinString(literalKey(p.name, this.checker) ?? p.name.getText())}, ${this.stored(p.initializer, p, v)})`;
129
163
  if (ts.isShorthandPropertyAssignment(p))
130
164
  return `Pair(${kotlinString(p.name.text)}, ${this.shorthandValue(p.name)})`;
165
+ if (ts.isMethodDeclaration(p))
166
+ return `Pair(${ts.isComputedPropertyName(p.name) ? this.propertyKey(p.name.expression) : kotlinString(literalKey(p.name, this.checker) ?? p.name.getText())}, ${this.untypedMethod(p)})`;
131
167
  throw this.error(p, 'this member in a dictionary literal');
132
168
  });
133
169
  return this.construction(entries.length ? `${name}(listOf(${entries.join(', ')}))` : `${name}()`, name);
@@ -137,6 +173,8 @@ export const literalsMethods = {
137
173
  return `EventData.fromJS(${this.dynamicObject(e)})`;
138
174
  if (isUntyped(spelledType(name)) || name === 'Any' || name === 'Nothing' || name === 'JSObject' || name === 'EventData')
139
175
  return this.dynamicObject(e);
176
+ if (isTypeParameterType(type, this.checker))
177
+ return this.fromAnyCode(this.dynamicObject(e), name);
140
178
  // The generated kit: an object of an interface core declares (`TraceErrorHandler`), which core holds untyped and calls by name.
141
179
  if (this.generatedKit && this.core?.has(`${name}Object`) && isCoreDeclaration(this.checker.getNonNullableType(type).getSymbol()?.declarations?.[0]))
142
180
  return this.dynamicObject(e);
@@ -177,8 +215,15 @@ export const literalsMethods = {
177
215
  else if (joined) {
178
216
  order = joined.map((m) => this.interfaceField(m));
179
217
  }
180
- else if (this.library && (classOfType(type, this.checker) ?? literalClassOf(this, e)))
181
- return this.classLiteral(e, classOfType(type, this.checker) ?? literalClassOf(this, e), name);
218
+ else if (classOfType(type, this.checker) ?? literalClassOf(this, e)) {
219
+ const cls = (classOfType(type, this.checker) ?? literalClassOf(this, e));
220
+ if (this.library || this.inPluginFile(e) || hasModifier(cls, ts.SyntaxKind.AbstractKeyword))
221
+ return this.classLiteral(e, cls, name);
222
+ throw this.error(e, `an object literal of type ${name}`);
223
+ }
224
+ else if (decl && ts.isModuleDeclaration(decl)) {
225
+ return this.dynamicObject(e);
226
+ }
182
227
  else
183
228
  throw this.error(e, `an object literal of type ${name}`);
184
229
  const given = new Map();
@@ -385,7 +430,7 @@ export const literalsMethods = {
385
430
  // A literal no type of the class's is at (one held as the class) has fields of its own types, which the class's fields take.
386
431
  const own = this.checker.getTypeAtLocation(e);
387
432
  const fields = classOfType(this.checker.getContextualType(e) ?? own, this.checker) ? own : this.checker.getDeclaredTypeOfSymbol(this.checker.getSymbolAtLocation(cls.name));
388
- const method = (n) => cls.members.find((m) => ts.isMethodDeclaration(m) && !!m.body && m.name.getText() === n) ?? this.inheritedMethod(cls, n);
433
+ const method = (n) => cls.members.find((m) => ts.isMethodDeclaration(m) && (!!m.body || hasModifier(m, ts.SyntaxKind.AbstractKeyword)) && m.name.getText() === n) ?? this.inheritedMethod(cls, n);
389
434
  for (const p of e.properties) {
390
435
  if (!ts.isPropertyAssignment(p) && !ts.isShorthandPropertyAssignment(p) && !ts.isMethodDeclaration(p))
391
436
  throw this.error(p, `this member of an object literal of type ${name}`);
@@ -461,7 +506,7 @@ export const literalsMethods = {
461
506
  },
462
507
  /** An interface's or object shape's Kotlin class. */
463
508
  isShapeType(name) {
464
- return this.interfaces.has(name) || !!this.shapes.named(name) || (!this.library && !!this.core?.viewable?.(name));
509
+ return this.facts.hasInterface(this, this.interfaces, (d, s) => this.topName(d, s), name) || !!this.shapes.named(name) || (!this.library && !!this.core?.viewable?.(name));
465
510
  },
466
511
  /**
467
512
  * A value of one of the app's object types where another goes (`DuoFold` passed as a `StageFold`): TypeScript's
@@ -475,16 +520,15 @@ export const literalsMethods = {
475
520
  return null;
476
521
  const contextual = this.checker.getContextualType(e);
477
522
  const props = contextual ? this.checker.getNonNullableType(contextual).getProperties() : [];
478
- if (!props.length)
479
- return null;
480
523
  // A literal is made as its contextual type already; a copy would lose the keys it notes.
481
- if (ts.isObjectLiteralExpression(ts.skipOuterExpressions(e)) && this.shapes.question(() => this.type(this.checker.getNonNullableType(contextual)).replace(/\?$/, '') === to))
524
+ if (props.length && ts.isObjectLiteralExpression(ts.skipOuterExpressions(e)) && this.shapes.question(() => this.type(this.checker.getNonNullableType(contextual)).replace(/\?$/, '') === to))
482
525
  return this.expr(e);
483
526
  const code = this.expr(e);
484
527
  if (this.constructs(code, to))
485
528
  return code;
486
- const view = this.viewOf(to, '__s');
487
- if (view === `${to}.jsView(__s)`)
529
+ const reader = this.protocols.has(to) ? `${to}Object` : to;
530
+ const view = this.viewOf(reader, '__s');
531
+ if (!props.length || view === `${reader}.jsView(__s)`)
488
532
  return `(${code})${holdsNil(heldOf(spelledType(source))) ? '?' : ''}.let { __s -> ${view} }`;
489
533
  const fields = props
490
534
  .map((p) => programSymbolKey(p, this.checker)?.member ?? wellKnownMember(p.name) ?? p.name)
@@ -199,9 +199,9 @@ export const namesMethods = {
199
199
  const ref = this.refName(e);
200
200
  const self = fnDecl.parameters.find((q) => isThisParameter(q) && !this.voidThis(q));
201
201
  // A function taking `this` as a value (a property descriptor's `set`): the receiver is the caller's.
202
- if ((self || this.implicitThis(fnDecl)) && !this.readsArguments(fnDecl)) {
202
+ if (self || this.implicitThis(fnDecl)) {
203
203
  const thisType = self ? this.type(this.checker.getTypeAtLocation(self.name), self) : 'Any?';
204
- const args = fnDecl.parameters.filter((q) => !isThisParameter(q)).map((q, k) => (q.dotDotDotToken ? `JSArray(__a.drop(${k}).map { ${this.fromAnyCode('it', this.typeOf(q.name).replace(/^JSArray<(.*)>$/, '$1'), true)} }.toMutableList())` : this.fromAnyCode(this.marks.pureCode(`__a.getOrNull(${k})`), this.paramType(q), true)));
204
+ const args = this.readsArguments(fnDecl) ? ['JSArray(__a.toMutableList())'] : fnDecl.parameters.filter((q) => !isThisParameter(q)).map((q, k) => (q.dotDotDotToken ? `JSArray(__a.drop(${k}).map { ${this.fromAnyCode('it', this.typeOf(q.name).replace(/^JSArray<(.*)>$/, '$1'), true)} }.toMutableList())` : this.fromAnyCode(this.marks.pureCode(`__a.getOrNull(${k})`), this.paramType(q), true)));
205
205
  return `JSMethod ${lambda(['__self', '__a'], `${ref}(${[isUntyped(spelledType(thisType)) ? '__self' : this.fromAnyCode('__self', thisType, true), ...args].join(', ')})`)}`;
206
206
  }
207
207
  // Library mode: a function of an optional string, number or boolean held as a value (a shorthand's converter) may be given
@@ -1,5 +1,5 @@
1
1
  import ts from 'typescript';
2
- import { ACC_FINAL, ACC_STATIC, methodTypes } from "./classfiles.js";
2
+ import { ACC_BRIDGE, ACC_FINAL, ACC_STATIC, ACC_SYNTHETIC, methodTypes } from "./classfiles.js";
3
3
  import { ANDROID_TYPINGS } from "./bridging.js";
4
4
  import { nativeTypesMethods } from "./types.js";
5
5
  import { nativeMembersMethods } from "./members.js";
@@ -106,6 +106,14 @@ export class AndroidNativeAPI {
106
106
  const fits = pool.filter((c) => kinds.every((k, i) => k.kind === 'any' || this.score(k, c.params[i]) !== null));
107
107
  if (fits.length === 1 || (every && fits.length))
108
108
  return fits;
109
+ if (fits.length > 1) {
110
+ const nonBridge = fits.filter((c) => !(c.m.access & (ACC_BRIDGE | ACC_SYNTHETIC)));
111
+ if (nonBridge.length === 1)
112
+ return nonBridge;
113
+ const concrete = (nonBridge.length ? nonBridge : fits).filter((c) => !c.params.some((p) => p === 'Ljava/lang/Object;'));
114
+ if (concrete.length === 1)
115
+ return concrete;
116
+ }
109
117
  throw this.t.error(fn, `${name} (matches ${pool.map((c) => this.display(c.m.owner, name, c)).join(' and ')}; declare its parameter types)`, 'native');
110
118
  }
111
119
  /** What `Base.extend({ … })` calls make (extend.ts), by call and by the variable holding one, and the files scanned for them. */
@@ -94,8 +94,8 @@ export const nativeCallsMethods = {
94
94
  // An optional chain (`?.`) TypeScript types as present: the value, as the code reads it.
95
95
  if (raw.optional && !ts.isPropertyAccessExpression(e.parent) && !ts.isCallExpression(e.parent) && !ts.isElementAccessExpression(e.parent))
96
96
  return this.t.asserted(raw.code);
97
- // Tested or passed on as it is (`intent.getAction() && …`): null is the test's to see.
98
- if (raw.nullable && this.t.library && raw.desc.startsWith('L') && raw.desc !== 'Ljava/lang/CharSequence;' && this.t.nullTolerant(e))
97
+ // Discarded results (`context.registerReceiver(...)`) or null-tolerant uses (`intent.getParcelableExtra(...) as UsbDevice | null`) never dereference null.
98
+ if (raw.nullable && raw.desc.startsWith('L') && raw.desc !== 'Ljava/lang/CharSequence;' && this.t.nullTolerant(e))
99
99
  return raw.code;
100
100
  // `@RecentlyNullable` (android.jar): null passes on as Kotlin's platform types let it, except into a member read or an array's elements.
101
101
  if (raw.recentlyNullable && !raw.optional && ((ts.isPropertyAccessExpression(e.parent) && e.parent.expression === e) || raw.desc.startsWith('[')))
@@ -263,10 +263,91 @@ export const nativeCallsMethods = {
263
263
  if (property)
264
264
  return { code: e.arguments.length ? `run { ${target}.${ident(property)} = ${args} }` : `${target}.${ident(property)}`, desc: e.arguments.length ? 'V' : chosen.ret, optional: target.endsWith('?'), nullable: chosen.m.nullable, recentlyNullable: chosen.m.recentlyNullable };
265
265
  const mapped = r.isStatic ? null : this.mapped(classes, name, chosen.m.descriptor);
266
+ // A generic Java method whose return type parameter is unconstrained by its arguments (e.g. `Intent.getParcelableExtra`,
267
+ // `View.findViewById`) would otherwise infer `Nothing` (`java.lang.Void`) under an unsafe `as` cast.
268
+ const typeArgs = mapped ? '' : this.unconstrainedMethodTypeArgs(chosen.m, e);
266
269
  // Kotlin's own member keeps a function's call parentheses (`toInt()`, `get(i)`) and drops a property's.
267
- const call = mapped ? (/^\.(get|to\w+)$/.test(mapped) ? `${mapped}(${args})` : mapped) : `.${ident(name)}(${args})`;
270
+ const call = mapped ? (/^\.(get|to\w+)$/.test(mapped) ? `${mapped}(${args})` : mapped) : `.${ident(name)}${typeArgs}(${args})`;
268
271
  return { code: `${target}${call}`, desc: chosen.ret, optional: target.endsWith('?'), nullable: chosen.m.nullable, recentlyNullable: chosen.m.recentlyNullable };
269
272
  },
273
+ /**
274
+ * Explicit Kotlin type arguments for a generic Java method when any of its type parameters is not referenced in its
275
+ * parameter list (e.g. `<T::Landroid/os/Parcelable;>(Ljava/lang/String;)TT;`), preventing Kotlin from inferring `Nothing` (`Void`).
276
+ */
277
+ unconstrainedMethodTypeArgs(m, e) {
278
+ const sig = m.signature;
279
+ if (!sig || !sig.startsWith('<'))
280
+ return '';
281
+ // Parse `<Name:ClassBound:InterfaceBound...>` respecting nested generic arguments.
282
+ let depth = 0;
283
+ let headerEnd = -1;
284
+ for (let i = 0; i < sig.length; i++) {
285
+ if (sig[i] === '<')
286
+ depth++;
287
+ else if (sig[i] === '>' && --depth === 0) {
288
+ headerEnd = i;
289
+ break;
290
+ }
291
+ }
292
+ if (headerEnd < 0 || sig[headerEnd + 1] !== '(')
293
+ return '';
294
+ const paramsEnd = sig.indexOf(')', headerEnd + 2);
295
+ if (paramsEnd < 0)
296
+ return '';
297
+ const paramsSig = sig.slice(headerEnd + 2, paramsEnd);
298
+ const header = sig.slice(1, headerEnd);
299
+ const typeParams = [];
300
+ let i = 0;
301
+ while (i < header.length) {
302
+ const colon = header.indexOf(':', i);
303
+ if (colon < 0)
304
+ break;
305
+ const name = header.slice(i, colon);
306
+ i = colon;
307
+ let bound = null;
308
+ while (i < header.length && header[i] === ':') {
309
+ i++;
310
+ if (i >= header.length || header[i] === ':')
311
+ continue;
312
+ const start = i;
313
+ let d = 0;
314
+ while (i < header.length) {
315
+ const ch = header[i];
316
+ if (ch === '<')
317
+ d++;
318
+ else if (ch === '>')
319
+ d--;
320
+ else if (ch === ';' && d === 0) {
321
+ i++;
322
+ break;
323
+ }
324
+ i++;
325
+ }
326
+ const raw = header.slice(start, i);
327
+ if (!bound && raw.startsWith('L')) {
328
+ const internal = raw.slice(1, -1).replace(/<.*$/, '');
329
+ if (internal !== 'java/lang/Object')
330
+ bound = internal;
331
+ }
332
+ }
333
+ typeParams.push({ name, bound });
334
+ }
335
+ if (!typeParams.length || typeParams.every((tp) => paramsSig.includes(`T${tp.name};`)))
336
+ return '';
337
+ const resolved = typeParams.map((tp, k) => {
338
+ const tsArg = e.typeArguments?.[k];
339
+ if (tsArg) {
340
+ const kt = this.t.type(this.t.checker.getTypeFromTypeNode(tsArg), e).replace(/\?$/, '');
341
+ if (kt && kt !== 'Any' && kt !== 'Nothing' && kt !== 'Unit' && !this.t.isTypeParameterName(kt) && (!tp.bound || this.classpath.distance(kt.replace(/\./g, '/'), tp.bound) !== null))
342
+ return kt;
343
+ }
344
+ if (!tp.bound)
345
+ return 'Any?';
346
+ const cls = this.classpath.get(tp.bound);
347
+ return cls && this.typeParamCount(cls) ? this.classRef(cls, undefined, '*', e) : this.kotlinTypeName(tp.bound);
348
+ });
349
+ return `<${resolved.join(', ')}>`;
350
+ },
270
351
  /** `const AccessibilityDelegate = android.view.View['AccessibilityDelegate']`: the nested Java class the alias names. */
271
352
  nestedAlias(e) {
272
353
  const d = ts.isIdentifier(e) ? this.t.resolve(e)?.valueDeclaration : undefined;
@@ -210,8 +210,9 @@ ${indent}}`;
210
210
  for (const p of literal.properties) {
211
211
  const name = p.name?.getText().replace(/^['"]|['"]$/g, '') ?? '';
212
212
  const fn = ts.isMethodDeclaration(p) ? p : ts.isPropertyAssignment(p) && (ts.isArrowFunction(p.initializer) || ts.isFunctionExpression(p.initializer)) ? p.initializer : null;
213
- // A function value (`this.onTouch.bind(this)`): the override calls it.
214
- const value = !fn && ts.isPropertyAssignment(p) ? t.checker.getTypeAtLocation(p.initializer).getCallSignatures()[0] : undefined;
213
+ // A function value (`this.onTouch.bind(this)`, `{ onDismiss }`): the override calls it.
214
+ const valueExpr = !fn && ts.isPropertyAssignment(p) ? p.initializer : !fn && ts.isShorthandPropertyAssignment(p) ? p.name : undefined;
215
+ const value = valueExpr ? t.checker.getTypeAtLocation(valueExpr).getCallSignatures()[0] : undefined;
215
216
  const declared = value?.getDeclaration();
216
217
  if (!fn && !(declared && !ts.isJSDocSignature(declared)))
217
218
  throw t.error(p, `${name} in an implementation of ${javaTypeName(`L${cls.name};`)} (only methods and functions)`, 'native');
@@ -219,7 +220,7 @@ ${indent}}`;
219
220
  if (!target)
220
221
  throw t.error(p, `${name} (${javaTypeName(`L${cls.name};`)} has no method of that name to implement)`, 'native');
221
222
  provided.add(name);
222
- members.push(fn ? this.overrideMethod(fn, name, target, base + ' ', ownerVar(target.m.owner)) : this.overrideWithValue(p.initializer, declared, name, target, base + ' ', ownerVar(target.m.owner)));
223
+ members.push(fn ? this.overrideMethod(fn, name, target, base + ' ', ownerVar(target.m.owner)) : this.overrideWithValue(valueExpr, declared, name, target, base + ' ', ownerVar(target.m.owner)));
223
224
  }
224
225
  if (isInterface) {
225
226
  const objectMethods = new Set((this.classpath.get('java/lang/Object')?.methods ?? []).map((m) => m.name + m.descriptor));
@@ -23,8 +23,8 @@ export const nativeTypesMethods = {
23
23
  for (let k = segs.length - 1; k >= 1 && !found; k--)
24
24
  found = this.classpath.get(`${segs.slice(0, k).join('/')}/${segs.slice(k).join('$')}`);
25
25
  this.symbols.set(sym, found);
26
- // Library mode: a type core's code names that no Android version has (`View.androidviewViewAccessibilityDelegate`), untyped.
27
- if (!found && this.t.library)
26
+ // Library mode or plugin code naming another platform's class (`NativeScript.Mason.TextNode`, `MasonTextWrap`), untyped.
27
+ if (!found && (this.t.library || this.t.pluginFiles.has(where?.getSourceFile().fileName ?? this.t.currentFile ?? '')))
28
28
  return null;
29
29
  if (!found)
30
30
  throw this.t.error(where, `${segs.join('.')} (no class file on the classpath: android.jar, the widgets AAR, androidx in the Gradle cache)`, 'native');
@@ -403,15 +403,18 @@ export const nativeTypesMethods = {
403
403
  if (!base)
404
404
  return null;
405
405
  const interfaces = [];
406
- const add = (e) => {
407
- const i = this.classOf(this.t.resolve(e), e);
406
+ const add = (e, skipNonNative = false) => {
407
+ const sym = this.t.resolve(e);
408
+ if (skipNonNative && !this.isNativeSymbol(sym))
409
+ return;
410
+ const i = this.classOf(sym, e);
408
411
  if (!i || !(i.access & ACC_INTERFACE))
409
412
  throw this.t.error(e, `${e.getText()} (not a Java interface)`, 'native');
410
413
  if (!interfaces.includes(i))
411
414
  interfaces.push(i);
412
415
  };
413
416
  for (const i of cls.heritageClauses?.find((h) => h.token === ts.SyntaxKind.ImplementsKeyword)?.types ?? [])
414
- add(i.expression);
417
+ add(i.expression, true);
415
418
  const listed = cls.members.find((m) => ts.isPropertyDeclaration(m) && m.name.getText() === 'interfaces' && hasStatic(m));
416
419
  if (listed?.initializer && ts.isArrayLiteralExpression(listed.initializer))
417
420
  for (const e of listed.initializer.elements)
@@ -8,7 +8,7 @@ import { located } from "../semantics/refusals.js";
8
8
  import { notedField } from "../semantics/shapes.js";
9
9
  import { isKit, isUntyped, spelledType } from "../semantics/types.js";
10
10
  import { assertedFrom, emptyComparison, scriptComparison } from "../semantics/placement.js";
11
- import { constClassExpr } from "../semantics/classes.js";
11
+ import { constClassExpr, hasInstanceClass } from "../semantics/classes.js";
12
12
  import { isLibDeclaration } from "../semantics/ast.js";
13
13
  import { nullAs } from "./expressions.js";
14
14
  import { bigIntArithmetic, bigIntCompare, bigIntPlan } from "../semantics/apis/bigint.js";
@@ -250,6 +250,9 @@ export const operatorsMethods = {
250
250
  return heldRight ? this.undefinedAs(chosen, t) : chosen;
251
251
  }
252
252
  case K.InstanceOfKeyword: {
253
+ const hi = hasInstanceClass(e.right, this.checker);
254
+ if (hi)
255
+ return `${this.className(hi)}.jsHasInstance(${this.coerce(e.left, 'Any?')})`;
253
256
  const rhsExpr = constClassExpr(e.right, this.checker);
254
257
  if (rhsExpr)
255
258
  return `(${this.observed(e.left)} is ${this.emitClassExprCode(rhsExpr)})`;
@@ -153,9 +153,11 @@ export const overridesMethods = {
153
153
  return this.fromAny(code, to);
154
154
  if (to === optionalType(from))
155
155
  return code;
156
- // An array of one element type where another is declared (`string[]` given as `any[]`): the same array, as script shares it.
157
- if (/^JSArray<.*>$/.test(from.replace(/\?$/, '')) && /^JSArray<.*>$/.test(to.replace(/\?$/, '')) && from.replace(/\?$/, '') !== to.replace(/\?$/, ''))
158
- return this.unchecked(to, code);
156
+ // An array of one element type where another is declared (`string[]` given as `any[]`): convert structural elements, else share the array.
157
+ if (/^JSArray<.*>$/.test(from.replace(/\?$/, '')) && /^JSArray<.*>$/.test(to.replace(/\?$/, '')) && from.replace(/\?$/, '') !== to.replace(/\?$/, '')) {
158
+ const el = !this.library ? this.elementwise(from, to) : null;
159
+ return el ? el(code) : this.unchecked(to, code);
160
+ }
159
161
  // A tuple where an array is declared: its elements.
160
162
  const tuple = /^(Pair|Triple)<.*>$/.exec(from), array = /^JSArray<(.*)>\??$/.exec(to);
161
163
  if (tuple && array)
@@ -168,13 +170,13 @@ export const overridesMethods = {
168
170
  // An object of a known shape where a dictionary is wanted: a dictionary of its entries.
169
171
  const record = /^JSRecord<(.+)>$/.exec(to.replace(/\?$/, ''));
170
172
  const fromShape = from.replace(/\?$/, '');
171
- if (record && (this.interfaces.has(fromShape) || !!this.shapes.named(fromShape))) {
173
+ if (record && this.isShapeType(fromShape)) {
172
174
  const entries = `JSRecord<${record[1]}>(__s.jsKeys.map { __k -> Pair(__k, ${this.fromAny('__s.jsGet(__k)', record[1])}) })`;
173
175
  return from.endsWith('?') ? `${code}?.let { __s -> ${entries} }` : `${code}.let { __s -> ${entries} }`;
174
176
  }
175
177
  // One object shape where another is declared (a wider shape an override returns): not a subclass, read by its keys.
176
178
  const shape = to.replace(/\?$/, '');
177
- if (from.replace(/\?$/, '') !== shape && (this.interfaces.has(shape) || !!this.shapes.named(shape)))
179
+ if (from.replace(/\?$/, '') !== shape && this.isShapeType(shape))
178
180
  return this.fromAny(code, to);
179
181
  if (this.isObjectType(from) && this.isObjectType(to) && from.replace(/\?$/, '') !== to.replace(/\?$/, ''))
180
182
  return this.classCast(code, from, to);
@@ -567,6 +567,8 @@ export const placementMethods = {
567
567
  return elements(code);
568
568
  }
569
569
  }
570
+ if (!this.library && sb === 'JSPromise<Any?>' && /^JSPromise<(.+)>$/.test(tb))
571
+ return this.fromAny(this.functionValue(e), target);
570
572
  if (head(sb) && head(sb) === head(tb) && sb !== tb)
571
573
  return cast(this.functionValue(e), target);
572
574
  if (sb !== tb && anyArguments(sb, tb))
@@ -574,7 +576,7 @@ export const placementMethods = {
574
576
  // An object given where an object type of the program's is declared, which it meets without naming it (`btn` as a `MeasuredView`): read through it by name.
575
577
  const wanted = this.checker.getContextualType(e)?.getSymbol();
576
578
  const programInterface = !!wanted && !!(wanted.flags & ts.SymbolFlags.Interface) && !(wanted.flags & ts.SymbolFlags.Class) && !!wanted.declarations?.every((d) => !d.getSourceFile().isDeclarationFile) && wanted.name === tb;
577
- if (!this.library && sb !== tb && this.isObjectType(sb) && (programInterface || this.interfaces.has(tb) || !!this.shapes.named(tb)) && !this.declaresInterface(this.checker.getTypeAtLocation(e), tb)) {
579
+ if (!this.library && sb !== tb && this.isObjectType(sb) && (programInterface || this.facts.hasInterface(this, this.interfaces, (d, s) => this.topName(d, s), tb) || !!this.shapes.named(tb)) && !this.declaresInterface(this.checker.getTypeAtLocation(e), tb)) {
578
580
  const reader = this.protocols.has(tb) ? `${tb}Object` : tb;
579
581
  return isNullable(target) ? `${this.expr(e)}?.let { ${this.viewOf(reader, 'it')} }` : this.viewOf(reader, this.expr(e));
580
582
  }
@@ -125,6 +125,11 @@ export const prototypeCallsMethods = {
125
125
  .map((n, k) => `${n}: ${parts.params[given.length + k]}`)
126
126
  .join(', ')} -> ${fn}(${[...fixed, ...names.slice(given.length)].join(', ')}) }`;
127
127
  }
128
+ const targetDecl = ts.isIdentifier(target) ? this.resolve(target)?.valueDeclaration : undefined;
129
+ if (method === 'call' && targetDecl && !ts.isJSDocSignature(targetDecl) && ts.isFunctionLike(targetDecl) && this.readsArguments(targetDecl)) {
130
+ const selfArg = takesThis ? [thisArg ? this.coerce(thisArg, parts.params[0]) : 'null'] : [];
131
+ return `${fn}(${[...selfArg, this.packed(rest, 'JSArray<Any?>', this.restSlot(e, 'Any?'))].join(', ')})`;
132
+ }
128
133
  const args = parts.params.map((t, k) => (given[k] ? this.coerce(given[k], t) : t.endsWith('?') ? 'null' : (this.zero(t) ?? 'null')));
129
134
  return `${fn}(${args.join(', ')})`;
130
135
  },
@@ -173,6 +173,66 @@ export function render(c, components, options = {}) {
173
173
  return say(depth, s.detached ? `val ${s.name} = Region(null)` : `val ${s.name} = ${s.parent}.kitAddRegion()`);
174
174
  case 'addRegion':
175
175
  return say(depth, `${s.parent}.kitAddRegion(${s.region})`);
176
+ case 'setSlot': {
177
+ say(depth, `${s.component}.__slots[${kotlinString(s.name)}] = { __sr: Region ->`);
178
+ const wrap = s.scope ? scope(s.scope) : null;
179
+ const d = wrap ? depth + 2 : depth + 1;
180
+ if (wrap)
181
+ say(depth + 1, wrap);
182
+ if (s.viewMark)
183
+ say(d, 'val __view = EffectOrder.current');
184
+ say(d, `val ${s.body.fragment} = RegionFragment(__sr)`);
185
+ steps(s.body.steps, d);
186
+ say(d, `${s.body.fragment}.fill()`);
187
+ if (wrap)
188
+ say(depth + 1, '}');
189
+ return say(depth, '}');
190
+ }
191
+ case 'slot': {
192
+ const host = regionHost(s.host);
193
+ if (s.fallback) {
194
+ say(depth, `this.__slots[${kotlinString(s.name)}]?.invoke(${host}) ?: run {`);
195
+ say(depth + 1, `val ${s.fallback.fragment} = RegionFragment(${host})`);
196
+ steps(s.fallback.steps, depth + 1);
197
+ say(depth + 1, `${s.fallback.fragment}.fill()`);
198
+ return say(depth, '}');
199
+ }
200
+ return say(depth, `this.__slots[${kotlinString(s.name)}]?.invoke(${host})`);
201
+ }
202
+ case 'componentOutlet': {
203
+ const host = regionHost(s.host);
204
+ const inj = s.injector ? `, injector = { ${call(s.injector)} }` : '';
205
+ const inp = s.inputs ? `, inputs = { ${call(s.inputs)} }` : '';
206
+ return say(depth, `${s.call}(${host}, { ${call(s.component)} }${inj}${inp})`);
207
+ }
208
+ case 'templateOutlet': {
209
+ const host = regionHost(s.host);
210
+ const ctx = s.context ? `, context = { ${call(s.context)} }` : '';
211
+ return say(depth, `${s.call}(${host}, { ${call(s.template)} }${ctx})`);
212
+ }
213
+ case 'bindTemplate':
214
+ case 'structural': {
215
+ const open = s.kind === 'bindTemplate' ? `TemplateOutlet.bind(this.${ident(s.field)})` : `val ${s.tplName} = TemplateOutlet.make`;
216
+ say(depth, `${open} { __sr: Region, ${s.ctxParam}: Any? ->`);
217
+ const wrap = s.scope ? scope(s.scope) : null;
218
+ const d = wrap ? depth + 2 : depth + 1;
219
+ if (wrap)
220
+ say(depth + 1, wrap);
221
+ if (s.viewMark)
222
+ say(d, 'val __view = EffectOrder.current');
223
+ say(d, `val ${s.body.fragment} = RegionFragment(__sr)`);
224
+ steps(s.body.steps, d);
225
+ say(d, `${s.body.fragment}.fill()`);
226
+ if (wrap)
227
+ say(depth + 1, '}');
228
+ say(depth, '}');
229
+ if (s.kind === 'structural') {
230
+ say(depth, `${s.call}(${s.region}, ${s.tplName}) {`);
231
+ steps(s.steps, depth + 1);
232
+ say(depth, '}');
233
+ }
234
+ return;
235
+ }
176
236
  case 'choose': {
177
237
  const host = regionHost(s.host);
178
238
  const which = s.conds.map((k, i) => (k ? `if (${cond(k, s.caught)}) ${i} else ` : `${i}`)).join('') + (s.conds.at(-1) ? `${s.conds.length}` : '');
@@ -262,6 +322,8 @@ export function render(c, components, options = {}) {
262
322
  };
263
323
  const passes = plan.passes;
264
324
  const m = plan.members;
325
+ if (plan.hasSlots)
326
+ say(1, 'var __slots: MutableMap<String, (Region) -> Unit> = mutableMapOf()');
265
327
  if (passes) {
266
328
  // Both passes, with the hooks a parent runs for its child between and after them.
267
329
  const hooks = (list) => list.map((h) => (h.flush ? `${h.flush}(this)` : h.every ? `${h.every} { this.${h.member}() }` : `this.${h.member}()`)).join('; ');
@@ -255,6 +255,15 @@ export const statementsMethods = {
255
255
  });
256
256
  }
257
257
  if (ts.isForInStatement(s)) {
258
+ if (!ts.isVariableDeclarationList(s.initializer)) {
259
+ const k = this.fresh('__key');
260
+ const assigns = this.assignIterated(s.initializer, k, this.checker.getStringType(), s.expression);
261
+ return this.loopBody(() => {
262
+ const label = this.takeLabel();
263
+ const body = this.block(s.statement);
264
+ return `${i}${label}for (${k} in ${RT.jsKeysOf}(${this.expr(s.expression)})) {\n${assigns.map((a) => `${i} ${a}`).join('\n')}\n${body.slice(2)}`;
265
+ });
266
+ }
258
267
  const list = s.initializer;
259
268
  const name = ident(list.declarations[0].name.text);
260
269
  if (!assignsTo(s.statement, this.checker.getSymbolAtLocation(list.declarations[0].name), this.checker))