@nstudio/nativescript-compiler 9.2.0-alpha.16 → 9.2.0-alpha.18

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 (186) hide show
  1. package/README.md +3 -0
  2. package/dist/kit/kit-index.js +9 -0
  3. package/dist/kotlin/access.js +14 -15
  4. package/dist/kotlin/arguments.js +2 -2
  5. package/dist/kotlin/assignment.js +22 -13
  6. package/dist/kotlin/builtins.js +67 -0
  7. package/dist/kotlin/calls.js +3 -2
  8. package/dist/kotlin/class-declaration.js +16 -1
  9. package/dist/kotlin/class-methods.js +2 -2
  10. package/dist/kotlin/components.js +2 -7
  11. package/dist/kotlin/core-api.js +3 -22
  12. package/dist/kotlin/declarations.js +86 -9
  13. package/dist/kotlin/expression-statements.js +13 -1
  14. package/dist/kotlin/functions.js +2 -4
  15. package/dist/kotlin/global-calls.js +1 -4
  16. package/dist/kotlin/literals.js +3 -10
  17. package/dist/kotlin/names.js +6 -4
  18. package/dist/kotlin/native/api.js +1 -1
  19. package/dist/kotlin/native/classfiles.js +2 -13
  20. package/dist/kotlin/operators.js +36 -30
  21. package/dist/kotlin/optional-chains.js +3 -10
  22. package/dist/kotlin/overrides.js +5 -17
  23. package/dist/kotlin/placement.js +1 -12
  24. package/dist/kotlin/state-backend.js +6 -2
  25. package/dist/kotlin/statements.js +1 -13
  26. package/dist/kotlin/translator.js +3 -11
  27. package/dist/kotlin/type-tests.js +1 -1
  28. package/dist/kotlin/types.js +6 -23
  29. package/dist/program/core-facts.js +9 -0
  30. package/dist/semantics/classes.js +15 -0
  31. package/dist/semantics/facts.js +38 -2
  32. package/dist/semantics/lang.js +29 -0
  33. package/dist/semantics/lower.js +144 -0
  34. package/dist/semantics/lowering-methods.js +120 -3
  35. package/dist/semantics/marks.js +30 -0
  36. package/dist/semantics/placement.js +9 -3
  37. package/dist/semantics/refusals.js +12 -11
  38. package/dist/semantics/signals.js +11 -0
  39. package/dist/semantics/states/missing.js +7 -0
  40. package/dist/semantics/tdz.js +142 -8
  41. package/dist/semantics/throws.js +1 -1
  42. package/dist/semantics/translator-methods.js +1 -1
  43. package/dist/swift/access.js +13 -17
  44. package/dist/swift/assignment.js +30 -16
  45. package/dist/swift/calls.js +13 -5
  46. package/dist/swift/classes.js +22 -10
  47. package/dist/swift/components.js +3 -7
  48. package/dist/swift/control-flow.js +1 -1
  49. package/dist/swift/conversion.js +5 -2
  50. package/dist/swift/core-api.js +11 -31
  51. package/dist/swift/declarations.js +1 -6
  52. package/dist/swift/expression-statements.js +7 -0
  53. package/dist/swift/expressions.js +6 -2
  54. package/dist/swift/from-any.js +1 -1
  55. package/dist/swift/functions.js +5 -6
  56. package/dist/swift/global-calls.js +1 -5
  57. package/dist/swift/lenient.js +0 -7
  58. package/dist/swift/literals.js +8 -3
  59. package/dist/swift/method-values.js +1 -19
  60. package/dist/swift/modules.js +5 -3
  61. package/dist/swift/names.js +3 -12
  62. package/dist/swift/native/api.js +3 -1
  63. package/dist/swift/native/calls.js +1 -1
  64. package/dist/swift/native/dispatch.js +2 -8
  65. package/dist/swift/object-classes.js +84 -1
  66. package/dist/swift/operators.js +37 -34
  67. package/dist/swift/optional-chains.js +1 -8
  68. package/dist/swift/parameters.js +0 -4
  69. package/dist/swift/placement.js +5 -15
  70. package/dist/swift/results.js +0 -4
  71. package/dist/swift/state-backend.js +3 -2
  72. package/dist/swift/statements.js +1 -13
  73. package/dist/swift/static-calls.js +2 -3
  74. package/dist/swift/syntax.js +9 -5
  75. package/dist/swift/translator.js +1 -11
  76. package/dist/swift/type-facts.js +3 -3
  77. package/dist/swift/types.js +3 -3
  78. package/dist/targets/ios/build.js +1 -1
  79. package/dist/types/adapter-api.d.ts +3 -3
  80. package/kit-android/generated/kotlin/org/nativescript/kit/__Modules.kt +1 -0
  81. package/kit-android/generated/kotlin/org/nativescript/kit/__Objects.kt +525 -99
  82. package/kit-android/generated/kotlin/org/nativescript/kit/accessibility_accessibility_common.kt +2 -2
  83. package/kit-android/generated/kotlin/org/nativescript/kit/application_application_common.kt +29 -6
  84. package/kit-android/generated/kotlin/org/nativescript/kit/application_helpers_common.kt +14 -0
  85. package/kit-android/generated/kotlin/org/nativescript/kit/color_color_utils.kt +3 -3
  86. package/kit-android/generated/kotlin/org/nativescript/kit/css_mediaquery_index.kt +49 -1
  87. package/kit-android/generated/kotlin/org/nativescript/kit/data_observable_array_index.kt +0 -8
  88. package/kit-android/generated/kotlin/org/nativescript/kit/data_observable_index.kt +0 -16
  89. package/kit-android/generated/kotlin/org/nativescript/kit/data_virtual_array_index.kt +6 -4
  90. package/kit-android/generated/kotlin/org/nativescript/kit/http_http_request_index.kt +19 -7
  91. package/kit-android/generated/kotlin/org/nativescript/kit/http_http_request_internal_http_request_internal_common.kt +14 -0
  92. package/kit-android/generated/kotlin/org/nativescript/kit/http_http_request_internal_index.kt +19 -10
  93. package/kit-android/generated/kotlin/org/nativescript/kit/matrix_index.kt +17 -29
  94. package/kit-android/generated/kotlin/org/nativescript/kit/media_query_list_index.kt +144 -22
  95. package/kit-android/generated/kotlin/org/nativescript/kit/npm_css_what_src_parse.kt +8 -3
  96. package/kit-android/generated/kotlin/org/nativescript/kit/org.nativescript.NativeScriptLifecycleCallbacks.kt +2 -10
  97. package/kit-android/generated/kotlin/org/nativescript/kit/ui_builder_index.kt +0 -2
  98. package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_bindable_expression_parser.kt +6 -10
  99. package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_properties_index.kt +531 -8
  100. package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_view_base_index.kt +0 -9
  101. package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_weak_event_listener_index.kt +3 -3
  102. package/kit-android/generated/kotlin/org/nativescript/kit/ui_styling_style_index.kt +19 -0
  103. package/kit-android/generated/kotlin/org/nativescript/kit/ui_styling_style_properties.kt +5 -2
  104. package/kit-android/generated/kotlin/org/nativescript/kit/ui_styling_style_scope.kt +232 -174
  105. package/kit-android/generated/kotlin/org/nativescript/kit/ui_text_view_text_view_common.kt +1 -1
  106. package/kit-android/generated/kotlin/org/nativescript/kit/utils_android_runtime_version.kt +75 -0
  107. package/kit-android/generated/manifest.json +21 -18
  108. package/kit-android/generated/source-lines.json +1 -1
  109. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Array.kt +547 -51
  110. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Intl.kt +1 -1
  111. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/JSON.kt +52 -6
  112. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Language.kt +33 -0
  113. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Prototypes.kt +9 -1
  114. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Strings.kt +32 -18
  115. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Values.kt +137 -28
  116. package/kit-apple/Overlays/xml-free/Core/ui.builder.index.swift +1 -1
  117. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity1.swift +14 -10
  118. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity2.swift +3 -9
  119. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity3Plus.swift +20 -21
  120. package/kit-apple/Sources/NativeScriptKit/Core/Object_eventName_object_index_section_view_ios_android.swift +5 -7
  121. package/kit-apple/Sources/NativeScriptKit/Core/Object_eventName_object_ios_android_.swift +130 -0
  122. package/kit-apple/Sources/NativeScriptKit/Core/Object_eventName_object_oldIndex_newIndex.swift +2 -4
  123. package/kit-apple/Sources/NativeScriptKit/Core/Object_specified_substituted_reads.swift +115 -0
  124. package/kit-apple/Sources/NativeScriptKit/Core/Object_substituted_values_reads.swift +113 -0
  125. package/kit-apple/Sources/NativeScriptKit/Core/Object_substituted_values_reads_.swift +113 -0
  126. package/kit-apple/Sources/NativeScriptKit/Core/application.application-common.swift +348 -330
  127. package/kit-apple/Sources/NativeScriptKit/Core/application.application.ios.swift +358 -359
  128. package/kit-apple/Sources/NativeScriptKit/Core/application.helpers-common.swift +47 -29
  129. package/kit-apple/Sources/NativeScriptKit/Core/connectivity.index.ios.swift +3 -1
  130. package/kit-apple/Sources/NativeScriptKit/Core/css-mediaquery.index.swift +95 -53
  131. package/kit-apple/Sources/NativeScriptKit/Core/css.CSS3Parser.swift +1 -1
  132. package/kit-apple/Sources/NativeScriptKit/Core/css.parser.swift +1 -1
  133. package/kit-apple/Sources/NativeScriptKit/Core/data.observable-array.index.swift +2 -2
  134. package/kit-apple/Sources/NativeScriptKit/Core/file-system.file-system-access.ios.swift +52 -43
  135. package/kit-apple/Sources/NativeScriptKit/Core/http.http-request-internal.http-request-internal-common.swift +18 -0
  136. package/kit-apple/Sources/NativeScriptKit/Core/http.http-request-internal.index.ios.swift +66 -51
  137. package/kit-apple/Sources/NativeScriptKit/Core/image-source.index.ios.swift +67 -51
  138. package/kit-apple/Sources/NativeScriptKit/Core/js-libs.easysax.easysax.swift +24 -6
  139. package/kit-apple/Sources/NativeScriptKit/Core/kit-index.json +143 -32
  140. package/kit-apple/Sources/NativeScriptKit/Core/manifest.json +30 -19
  141. package/kit-apple/Sources/NativeScriptKit/Core/media-query-list.index.swift +190 -78
  142. package/kit-apple/Sources/NativeScriptKit/Core/native-window.native-window.ios.swift +1 -1
  143. package/kit-apple/Sources/NativeScriptKit/Core/npm.css-what.src.parse.swift +205 -201
  144. package/kit-apple/Sources/NativeScriptKit/Core/npm.css-what.src.stringify.swift +41 -42
  145. package/kit-apple/Sources/NativeScriptKit/Core/npm.css-what.src.types.swift +1 -1
  146. package/kit-apple/Sources/NativeScriptKit/Core/trace.index.swift +2 -2
  147. package/kit-apple/Sources/NativeScriptKit/Core/ui.animation.index.ios.swift +77 -65
  148. package/kit-apple/Sources/NativeScriptKit/Core/ui.builder.index.swift +4 -4
  149. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.properties.index.swift +1272 -824
  150. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view-base.index.swift +2 -2
  151. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.index.ios.swift +8 -8
  152. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.view-common.swift +1 -1
  153. package/kit-apple/Sources/NativeScriptKit/Core/ui.frame.frame-common.swift +2 -1
  154. package/kit-apple/Sources/NativeScriptKit/Core/ui.frame.index.ios.swift +6 -6
  155. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.flexbox-layout.index.ios.swift +22 -21
  156. package/kit-apple/Sources/NativeScriptKit/Core/ui.page.index.ios.swift +202 -188
  157. package/kit-apple/Sources/NativeScriptKit/Core/ui.repeater.index.swift +2 -6
  158. package/kit-apple/Sources/NativeScriptKit/Core/ui.split-view.index.ios.swift +3 -3
  159. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.background.ios.swift +2 -2
  160. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.clip-path-function.swift +1 -1
  161. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.css-animation-parser.swift +1 -1
  162. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.css-selector.swift +2 -2
  163. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.font-common.swift +2 -2
  164. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.style-scope.swift +869 -838
  165. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.style.index.swift +46 -31
  166. package/kit-apple/Sources/NativeScriptKit/Core/ui.text-base.formatted-string.swift +1 -2
  167. package/kit-apple/Sources/NativeScriptKit/Core/ui.text-view.text-view-common.swift +1 -1
  168. package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.index.ios.swift +2 -2
  169. package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.modal-transition.ios.swift +4 -4
  170. package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.page-transition.ios.swift +2 -2
  171. package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.shared-transition-helper.ios.swift +17 -17
  172. package/kit-apple/Sources/NativeScriptKit/Core/utils.android-runtime-version.swift +77 -0
  173. package/kit-apple/Sources/NativeScriptKit/Core/utils.debug-source.swift +2 -2
  174. package/kit-apple/Sources/NativeScriptKit/Core/xhr.index.swift +62 -61
  175. package/kit-apple/Sources/NativeScriptKit/Runtime/Array.swift +4 -0
  176. package/kit-apple/Sources/NativeScriptKit/Runtime/Dynamic.swift +2 -0
  177. package/kit-apple/Sources/NativeScriptKit/Runtime/Interop.swift +1 -1
  178. package/kit-apple/Sources/NativeScriptKit/Runtime/Intl.swift +1 -1
  179. package/kit-apple/Sources/NativeScriptKit/Runtime/Iterators.swift +1 -1
  180. package/kit-apple/Sources/NativeScriptKit/Runtime/JSON.swift +413 -73
  181. package/kit-apple/Sources/NativeScriptKit/Runtime/Lowering.swift +3 -2
  182. package/kit-apple/Sources/NativeScriptKit/Runtime/Prototypes.swift +14 -1
  183. package/kit-apple/Sources/NativeScriptKit/Runtime/Symbol.swift +1 -0
  184. package/kit-apple/Sources/NativeScriptKit/Runtime/Values.swift +1 -0
  185. package/kit-apple/Sources/NativeScriptKit/Runtime/Views.swift +2 -0
  186. package/package.json +2 -2
@@ -4,7 +4,7 @@ import { resultSlot, returnCell } from "../semantics/placement.js";
4
4
  import { assignsTo, branch, functionTypeParts, ident, isFunctionType, isNullable, isThisParameter, jsObjectCode, kotlinString, mentions, nullishType, numberLiteral, optionalElementsType, optionalType, refersTo, returnsNull, splitTopLevel, RT } from "./syntax.js";
5
5
  import { boundNames, thisNodes, takesOwnThis } from "../semantics/ast.js";
6
6
  import { isAsync } from "../semantics/throws.js";
7
- import { isConstant, methodValues, thisArgBound } from "../semantics/lang.js";
7
+ import { methodValues, thisArgBound } from "../semantics/lang.js";
8
8
  import { isUntyped, spelledType } from "../semantics/types.js";
9
9
  import { literalCallback } from "../semantics/conversion.js";
10
10
  export const functionsMethods = {
@@ -91,9 +91,6 @@ export const functionsMethods = {
91
91
  * A parameter Kotlin gives its constant default itself. Not where another method of its override family declares the
92
92
  * parameter otherwise: Kotlin overrides take the root's default, where JavaScript applies the default of the method that runs.
93
93
  */
94
- constantDefault(p) {
95
- return !!p.initializer && isConstant(p.initializer) && !this.familyDefaultsDiffer(p) && !this.states.defaultTakesUndefined(p);
96
- },
97
94
  /** Statements a function body starts with: computed defaults, destructured parameters. */
98
95
  paramPrelude(fn) {
99
96
  const i = this.indent;
@@ -394,6 +391,7 @@ export const functionsMethods = {
394
391
  for (let k = given; k < slotParams.length; k++)
395
392
  params += `${params ? ', ' : ''}__u${k}: ${slotParams[k]}`;
396
393
  if (!ts.isMethodDeclaration(fn) && fn.name && fn.body && refersTo(fn.body, this.checker.getSymbolAtLocation(fn.name), this.checker)) {
394
+ this.refuseNamedGenerator(fn);
397
395
  const fnName = ident(fn.name.text);
398
396
  const pTypes = splitTopLevel(params)
399
397
  .map((p) => p.trim())
@@ -259,10 +259,7 @@ export const globalCallsMethods = {
259
259
  const decl = this.resolve(e.expression)?.declarations?.[0];
260
260
  return !decl || decl.getSourceFile().isDeclarationFile;
261
261
  },
262
- symbolName(e) {
263
- const t = this.checker.getTypeAtLocation(e);
264
- return (t.aliasSymbol ?? t.getSymbol())?.getName() ?? '';
265
- },
262
+ /* symbolName is installed from semantics/lowering-methods.ts */
266
263
  /** A navigation (`$navigateTo(Page, { props })`) to a component, with the props its options give. */
267
264
  navigate(e, component, options) {
268
265
  const info = this.components.get(component);
@@ -84,7 +84,7 @@ export const literalsMethods = {
84
84
  }
85
85
  const el = t.replace(/^JSArray<(.*)>$/, '$1');
86
86
  if (!e.elements.length)
87
- return /^JSArray</.test(t) ? this.construction(`${t}()`, t) : `${t}()`;
87
+ return t === 'JSArray<Double>' ? this.construction('JSArray.doubles()', t) : /^JSArray</.test(t) ? this.construction(`${t}()`, t) : `${t}()`;
88
88
  // An array of objects holds a Kotlin null, which reads as undefined.
89
89
  const nulled = !isNullable(el) && e.elements.find((x) => !ts.isSpreadElement(x) && this.states.nullResult(ts.skipOuterExpressions(x, ts.OuterExpressionKinds.Parentheses)));
90
90
  if (nulled)
@@ -93,7 +93,8 @@ export const literalsMethods = {
93
93
  if (e.elements.some(ts.isOmittedExpression))
94
94
  throw this.error(e, 'an array hole', 'array-hole');
95
95
  const slot = this.elementSlot(e, el);
96
- return this.marks.marked(`${RT.jsArrayOf}<${el}>(${e.elements.map((x) => place(this.placement, x, slot(x))).join(', ')})`, { op: 'array', element: el });
96
+ const ctor = el === 'Double' ? 'JSArray.doublesOf' : `${RT.jsArrayOf}<${el}>`;
97
+ return this.marks.marked(`${ctor}(${e.elements.map((x) => place(this.placement, x, slot(x))).join(', ')})`, { op: 'array', element: el });
97
98
  }
98
99
  const parts = [];
99
100
  let run = [];
@@ -626,12 +627,4 @@ export const literalsMethods = {
626
627
  const value = made.arguments[0];
627
628
  return !!value && (value.kind === ts.SyntaxKind.NullKeyword || (ts.isIdentifier(value) && value.text === 'undefined'));
628
629
  },
629
- /** A variable declared without a type whose value is a read of a signal holding null (`const card = this.morning()`). */
630
- givenNullSignalValue(n) {
631
- const d = ts.isVariableDeclaration(n) ? n : ts.isIdentifier(n) ? (ts.isVariableDeclaration(n.parent) && n.parent.name === n ? n.parent : this.resolve(n)?.valueDeclaration) : undefined;
632
- if (!d || !ts.isVariableDeclaration(d) || d.type || !d.initializer)
633
- return false;
634
- const read = ts.skipOuterExpressions(d.initializer, ts.OuterExpressionKinds.Parentheses);
635
- return ts.isCallExpression(read) && !read.arguments.length && /^Signal<.*\?>$/.test(this.typeOf(read.expression));
636
- },
637
630
  };
@@ -3,7 +3,7 @@ import ts from 'typescript';
3
3
  import { KIT_NAMES_ANDROID } from "./library.js";
4
4
  import { ERRORS } from "../semantics/globals.js";
5
5
  import { IOS_TYPINGS, ident, isThisParameter, kotlinString, lambda, optionalType, RT } from "./syntax.js";
6
- import { accessedDeclaration, canReadArguments, isArguments, objectMethod } from "../semantics/lang.js";
6
+ import { accessedDeclaration, builtinConstructorSlot, canReadArguments, isArguments, objectMethod } from "../semantics/lang.js";
7
7
  import { hasModifier, isAppDeclarationFile, isLibDeclaration, isWriteTarget } from "../semantics/ast.js";
8
8
  import { isCoreDeclaration } from "../program/core-facts.js";
9
9
  import { isStatic } from "../semantics/throws.js";
@@ -20,9 +20,9 @@ export const namesMethods = {
20
20
  if (ERRORS[e.text])
21
21
  return `${ERRORS[e.text]}::class.java`;
22
22
  // Placed untyped or compared (`const f: any = Number`, `s.constructor === String`): singleton builtin constructor.
23
- const context = this.checker.getContextualType(e);
24
- if (!context || !this.checker.getNonNullableType(context).getCallSignatures()[0])
25
- return `js${e.text}Constructor`;
23
+ const { singleton } = builtinConstructorSlot(e, this.checker, (c) => isUntyped(spelledType(this.type(c, e))));
24
+ if (singleton)
25
+ return singleton;
26
26
  return `{ value: Any? -> ${e.text === 'Number' ? RT.jsToNumber : e.text === 'String' ? RT.jsToString : RT.jsTruthy}(value) }`;
27
27
  }
28
28
  // `Promise`, `Date`, `Array`, `Object` as values (`const { isArray } = Array`, a `PromiseConstructorLike` default): the runtime's.
@@ -236,6 +236,8 @@ export const namesMethods = {
236
236
  return `${kit ?? this.declaredName(e).split('.').map(ident).join('.')}::class.java`;
237
237
  }
238
238
  const ref = this.globalAlias(e) ?? this.refName(e);
239
+ if (sym && this.stringBuilders.has(sym))
240
+ return `${ref}.toString()`;
239
241
  // Library mode: a class named where a member of that name is in scope (ApplicationCommon's `AndroidApplication` getter) by its package.
240
242
  if (this.library && this.appModule && sym && sym.flags & (ts.SymbolFlags.Class | ts.SymbolFlags.Enum) && !ref.includes('.') && this.memberInScope(e, name))
241
243
  return `${this.appModule}.${ref}`;
@@ -37,7 +37,7 @@ export class AndroidNativeAPI {
37
37
  * Whether a typings declaration's Java binding holds null: a field's value, a method's result, a parameter's argument.
38
38
  * Java's reference types are platform types, null unless annotated `@NonNull`; its primitives never are.
39
39
  */
40
- holdsNil(d) {
40
+ jvmHoldsNil(d) {
41
41
  const param = ts.isParameter(d) ? d : null;
42
42
  const member = param ? param.parent : d;
43
43
  const k = param ? member.parameters.indexOf(param) : -1;
@@ -2,6 +2,7 @@ import { existsSync, readdirSync, readFileSync } from 'node:fs';
2
2
  import { homedir } from 'node:os';
3
3
  import { join } from 'node:path';
4
4
  import { inflateRawSync } from 'node:zlib';
5
+ import { newerVersion } from "../../semantics/lang.js";
5
6
  /**
6
7
  * Java signatures for Android APIs, read from the class files themselves: the
7
8
  * SDK's android.jar, NativeScript's widgets AAR and, for androidx types, the
@@ -252,19 +253,7 @@ export function parseClass(b) {
252
253
  return result;
253
254
  }
254
255
  // ---- The classpath -----------------------------------------------------------------------------
255
- function versionKey(v) {
256
- return v.split(/[.-]/).map((x) => (/^\d+$/.test(x) ? Number(x) : -1));
257
- }
258
- export function newer(a, b) {
259
- const stable = (v) => !/-/.test(v);
260
- if (stable(a) !== stable(b))
261
- return stable(a);
262
- const ka = versionKey(a), kb = versionKey(b);
263
- for (let i = 0; i < Math.max(ka.length, kb.length); i++)
264
- if ((ka[i] ?? 0) !== (kb[i] ?? 0))
265
- return (ka[i] ?? 0) > (kb[i] ?? 0);
266
- return false;
267
- }
256
+ export const newer = (a, b) => newerVersion(a, b, true);
268
257
  /** The SDK platform's android.jar: the compile SDK's when installed, else the newest. */
269
258
  export function androidJar(compileSdk) {
270
259
  const sdk = process.env.ANDROID_HOME ?? process.env.ANDROID_SDK_ROOT ?? join(homedir(), 'Library', 'Android', 'sdk');
@@ -12,6 +12,8 @@ import { isLibDeclaration } from "../semantics/ast.js";
12
12
  import { nullAs } from "./expressions.js";
13
13
  import { bigIntArithmetic, bigIntCompare, bigIntPlan } from "../semantics/apis/bigint.js";
14
14
  import { BIT_ASSIGNMENTS, addCall, bitOperation, concatOperand, numericThrowing, untypedBinary, untypedConversion } from "../semantics/apis/operators.js";
15
+ import { flattenStringConcat, planArithmetic, planEquality, planLogicalAssign, planRelational } from "../semantics/lower.js";
16
+ import { isReadonlySignalProperty } from "../semantics/signals.js";
15
17
  /** BigInt's operations the backend spells as an operator. */
16
18
  const BIGINT_INFIX = { add: '+', subtract: '-', multiply: '*', and: 'and', or: 'or', xor: 'xor' };
17
19
  export const operatorsMethods = {
@@ -74,6 +76,11 @@ export const operatorsMethods = {
74
76
  // A string that may be missing converts first: Kotlin's `+` on a null string writes "null" for undefined too.
75
77
  if (this.isString(e.left) && isNullable(this.declaredTypeOf(e.left) ?? this.typeOf(e.left)))
76
78
  return `${target()} = ${this.str(e.left)} + ${added()}`;
79
+ if (ts.isIdentifier(e.left) && this.stringBuilders.has(this.resolve(e.left))) {
80
+ const parts = flattenStringConcat(e.right, (x) => this.isString(x));
81
+ const appends = parts.map((p) => `.append(${untyped?.kind === 'concat' ? concatOperand(this, p, untyped) : this.str(p)})`).join('');
82
+ return `${ident(e.left.text)}${appends}`;
83
+ }
77
84
  return this.isString(e.left) ? `${target()} += ${added()}` : `${target()} += ${untyped ? untypedConversion(this, untyped, e.right) : this.toNumber(e.right)}`;
78
85
  }
79
86
  case K.MinusEqualsToken:
@@ -99,31 +106,30 @@ export const operatorsMethods = {
99
106
  case K.AsteriskAsteriskEqualsToken:
100
107
  return `${target()} = ${RT.jsPow}(${this.heldOptionalNumber(e.left) ? this.undefinedAs(this.expr(e.left), 'Double') : this.isAny(e.left) ? this.toNumber(e.left) : l()}, ${this.toNumber(e.right)})`;
101
108
  case K.QuestionQuestionEqualsToken:
102
- return `if (${RT.jsIsNullish}(${l()})) ${this.assignment(e.left, e.right)}`;
103
109
  case K.BarBarEqualsToken:
104
- return `if (!${RT.jsTruthy}(${l()})) ${this.assignment(e.left, e.right)}`;
105
- case K.AmpersandAmpersandEqualsToken:
106
- return `if (${RT.jsTruthy}(${l()})) ${this.assignment(e.left, e.right)}`;
107
- case K.PlusToken: {
108
- if (this.isString(e.left) || this.isString(e.right))
110
+ case K.AmpersandAmpersandEqualsToken: {
111
+ const plan = planLogicalAssign(op);
112
+ const guard = plan.op === '??=' ? `${RT.jsIsNullish}(${l()})` : plan.op === '||=' ? `!${RT.jsTruthy}(${l()})` : `${RT.jsTruthy}(${l()})`;
113
+ return `if (${guard}) ${this.assignment(e.left, e.right)}`;
114
+ }
115
+ case K.PlusToken:
116
+ case K.MinusToken:
117
+ case K.AsteriskToken:
118
+ case K.SlashToken:
119
+ case K.PercentToken:
120
+ case K.AsteriskAsteriskToken: {
121
+ const plan = planArithmetic(op, this.isString(e.left), this.isString(e.right), this.isAny(e.left), this.isAny(e.right));
122
+ if (plan.kind === 'concat')
109
123
  return `${concatOperand(this, e.left, untyped)} + ${concatOperand(this, e.right, untyped)}`;
110
- if (this.isAny(e.left) || this.isAny(e.right)) {
124
+ if (plan.kind === 'dynamicAdd') {
111
125
  const sum = addCall(this, e, untyped), t = this.typeOf(e);
112
126
  // An operand held untyped though TypeScript types it, and so the sum, a number or string.
113
127
  return isUntyped(spelledType(t)) ? sum : this.fromAnyCode(sum, t);
114
128
  }
115
- return `${this.toNumber(e.left)} + ${this.toNumber(e.right)}`;
129
+ if (plan.op === '**')
130
+ return `${RT.jsPow}(${this.toNumber(e.left)}, ${this.toNumber(e.right)})`;
131
+ return `${this.toNumber(e.left)} ${plan.op} ${this.toNumber(e.right)}`;
116
132
  }
117
- case K.MinusToken:
118
- return `${this.toNumber(e.left)} - ${this.toNumber(e.right)}`;
119
- case K.AsteriskToken:
120
- return `${this.toNumber(e.left)} * ${this.toNumber(e.right)}`;
121
- case K.SlashToken:
122
- return `${this.toNumber(e.left)} / ${this.toNumber(e.right)}`;
123
- case K.PercentToken:
124
- return `${this.toNumber(e.left)} % ${this.toNumber(e.right)}`;
125
- case K.AsteriskAsteriskToken:
126
- return `${RT.jsPow}(${this.toNumber(e.left)}, ${this.toNumber(e.right)})`;
127
133
  case K.EqualsEqualsEqualsToken:
128
134
  case K.ExclamationEqualsEqualsToken:
129
135
  case K.EqualsEqualsToken:
@@ -133,19 +139,19 @@ export const operatorsMethods = {
133
139
  case K.GreaterThanToken:
134
140
  case K.LessThanEqualsToken:
135
141
  case K.GreaterThanEqualsToken: {
136
- const sym = ts.tokenToString(op);
137
- if (this.isString(e.left) && this.isString(e.right))
138
- return `${l()} ${sym} ${r()}`;
139
142
  // An untyped or object operand: compared as strings or as numbers by what it holds when the program runs.
140
143
  const dynamic = (x) => {
141
144
  const t = this.typeOf(x);
142
145
  return isUntyped(spelledType(t)) || t === 'Any' || t === 'String?' || /^[A-Z]\??$/.test(t) || (this.isObjectType(t) && !/^JSDate\??$/.test(t));
143
146
  };
144
- if (dynamic(e.left) || dynamic(e.right)) {
145
- const fn = { [K.LessThanToken]: RT.jsLess, [K.GreaterThanToken]: RT.jsGreater, [K.LessThanEqualsToken]: RT.jsLessOrEqual, [K.GreaterThanEqualsToken]: RT.jsGreaterOrEqual }[op];
147
+ const plan = planRelational(op, this.isString(e.left), this.isString(e.right), dynamic(e.left) || dynamic(e.right));
148
+ if (plan.kind === 'string')
149
+ return `${l()} ${plan.op} ${r()}`;
150
+ if (plan.kind === 'dynamic') {
151
+ const fn = { '<': RT.jsLess, '>': RT.jsGreater, '<=': RT.jsLessOrEqual, '>=': RT.jsGreaterOrEqual }[plan.op];
146
152
  return `${fn}(${this.coerce(e.left, 'Any?')}, ${this.coerce(e.right, 'Any?')})`;
147
153
  }
148
- return `${this.toNumber(e.left)} ${sym} ${this.toNumber(e.right)}`;
154
+ return `${this.toNumber(e.left)} ${plan.op} ${this.toNumber(e.right)}`;
149
155
  }
150
156
  case K.QuestionQuestionToken: {
151
157
  const t = this.typeOf(e);
@@ -332,9 +338,9 @@ export const operatorsMethods = {
332
338
  },
333
339
  equality(e) {
334
340
  const K = ts.SyntaxKind;
335
- const op = e.operatorToken.kind;
336
- const negate = op === K.ExclamationEqualsEqualsToken || op === K.ExclamationEqualsToken;
337
- const strict = op === K.EqualsEqualsEqualsToken || op === K.ExclamationEqualsEqualsToken;
341
+ const eq = planEquality(e.operatorToken.kind, false, false, false, false);
342
+ const negate = eq.negated;
343
+ const strict = eq.kind === 'strict';
338
344
  const isNullish = (x) => x.kind === K.NullKeyword || (ts.isIdentifier(x) && x.text === 'undefined');
339
345
  const [a, b] = [e.left, e.right];
340
346
  const lt = this.typeOf(a);
@@ -414,7 +420,7 @@ export const operatorsMethods = {
414
420
  }
415
421
  },
416
422
  /** Whether a `Signal<T>` node is lowered as a Kotlin property reading its value (`val x: T get() = …`) rather than a `Signal<T>`. */
417
- isComputedProperty(n) {
423
+ isKotlinComputedProperty(n) {
418
424
  if (this.library)
419
425
  return false;
420
426
  const decl = ts.isIdentifier(n) || ts.isPropertyAccessExpression(n) || ts.isPrivateIdentifier(n) ? this.resolve(n)?.valueDeclaration : n;
@@ -425,13 +431,13 @@ export const operatorsMethods = {
425
431
  if (!ts.isPropertyDeclaration(decl) || !ts.isClassLike(decl.parent) || !decl.initializer)
426
432
  return false;
427
433
  const init = decl.initializer, callee = this.calleeName(init);
428
- if (this.framework.heldSignal(callee) || /\.asReadonly$/.test(callee))
434
+ if (this.framework.heldSignal(callee) || isReadonlySignalProperty(decl, this.checker, this.framework, callee))
429
435
  return true;
430
436
  return this.signalAlias(decl);
431
437
  },
432
438
  /** A read-only signal's current value. */
433
439
  signalValue(e) {
434
- return this.isComputedProperty(e) ? this.expr(e) : `${this.expr(e)}.value`;
440
+ return this.isKotlinComputedProperty(e) ? this.expr(e) : `${this.expr(e)}.value`;
435
441
  },
436
442
  /** A field initialized with another read-only signal (`dayColor = ink`, a module's memo): a property reading through it. */
437
443
  signalAlias(m) {
@@ -23,7 +23,7 @@ export const optionalChainsMethods = {
23
23
  return `(${this.coerce(e.left, optionalType(this.typeOf(e)))} ?: ${rightMaybe})`;
24
24
  }
25
25
  // A kit method whose Kotlin signature returns nullable (`ViewBase.getViewById`: `ViewBase?`) though core's typings say present.
26
- if (ts.isCallExpression(e) && !this.library && !this.nullOk.has(e) && !isNullable(this.typeOf(e)) && this.isObjectRef(e) && !isFunctionType(this.typeOf(e)) && this.core?.kitNil?.(e)) {
26
+ if (ts.isCallExpression(e) && !this.library && !this.nullOk.has(e) && !isNullable(this.typeOf(e)) && this.isObjectRef(e) && !isFunctionType(this.typeOf(e)) && this.core?.kotlinKitNil?.(e)) {
27
27
  this.nullOk.add(e);
28
28
  try {
29
29
  return this.expr(e);
@@ -42,7 +42,7 @@ export const optionalChainsMethods = {
42
42
  // A non-strict app's optional member, as its shape holds it.
43
43
  const shapeOptSym = ts.isPropertyAccessExpression(e) && !e.questionDotToken && !(e.flags & ts.NodeFlags.OptionalChain) ? this.checker.getSymbolAtLocation(e.name) : undefined;
44
44
  const shapeOpt = !!shapeOptSym && this.states.shapeFieldOptional(shapeOptSym) && (['String', 'Double', 'Boolean'].includes(this.typeOf(e)) || this.states.unsetMember(shapeOptSym.valueDeclaration ?? shapeOptSym.declarations?.[0]));
45
- if (ts.isPropertyAccessExpression(e) && ((this.optionalMember(e) && ['String', 'Double', 'Boolean'].includes(this.typeOf(e))) || shapeOpt)) {
45
+ if (ts.isPropertyAccessExpression(e) && ((this.isLenientOptionalMember(e) && ['String', 'Double', 'Boolean'].includes(this.typeOf(e))) || shapeOpt)) {
46
46
  const untyped = this.untypedMemberRead(e);
47
47
  if (untyped)
48
48
  return untyped;
@@ -270,14 +270,7 @@ export const optionalChainsMethods = {
270
270
  * A string, number or boolean read `e` of type `t` as the optional it holds, where it converts undefined (a read, or
271
271
  * a choice one of whose branches does); null where it converts nothing.
272
272
  */
273
- convertedOptional(e, t) {
274
- if (this.library)
275
- return null;
276
- const inner = ts.skipOuterExpressions(e);
277
- if (ts.isConditionalExpression(inner) && this.typeOf(inner) === t && [inner.whenTrue, inner.whenFalse].some((x) => this.undefinedConverted(this.coerce(ts.skipOuterExpressions(x, ts.OuterExpressionKinds.Parentheses), t))))
278
- return this.coerce(inner, optionalType(t));
279
- return this.undefinedConverted(this.expr(ts.skipOuterExpressions(e, ts.OuterExpressionKinds.Parentheses)));
280
- },
273
+ /* convertedOptional is installed from semantics/lowering-methods.ts */
281
274
  /**
282
275
  * App and plugin code's string, number or boolean read that converts undefined (`(x ?: "undefined")`): the nullable it
283
276
  * converts, for a use that takes undefined as it is (a comparison, a receiver's TypeError). Null for any other code.
@@ -96,17 +96,7 @@ export const overridesMethods = {
96
96
  e = e.expression;
97
97
  return ts.isIdentifier(e) && (e.text === 'global' || e.text === 'globalThis') && (this.resolve(e)?.declarations ?? []).every((d) => d.getSourceFile().isDeclarationFile);
98
98
  },
99
- /** `fooProperty.setNative`: the registered name of the property it belongs to. */
100
- setNativeOf(e) {
101
- if (!ts.isPropertyAccessExpression(e) || e.name.text !== 'setNative')
102
- return null;
103
- return this.properties?.name(this.resolve(e.expression)) ?? null;
104
- },
105
- /** The kit class a mixin class (`applyMixins(View, [Extended])`) is applied to. */
106
- mixinOf(sym) {
107
- const d = sym?.valueDeclaration;
108
- return d && ts.isClassDeclaration(d) ? this.patterns.mixinTarget(d) : null;
109
- },
99
+ /* setNativeOf and mixinOf are installed from semantics/lowering-methods.ts */
110
100
  /**
111
101
  * A method overriding kit-android's: the kit's Kotlin signature, the
112
102
  * TypeScript body seeing its own types; what it throws is reported, as an
@@ -227,7 +217,7 @@ export const overridesMethods = {
227
217
  return this.library.counterpart(file, name) ?? 'null';
228
218
  },
229
219
  /** Whether a compiled class or one it extends declares a member of this name. */
230
- compiledMember(cls, name) {
220
+ declaresCompiledMember(cls, name) {
231
221
  for (let b = cls; b; b = programBase(b, this.checker))
232
222
  if (b.members.some((m) => m.name?.getText() === name) || this.facts.prototypeKeys().data.has(name) || this.facts.prototypeKeys().accessors.has(name))
233
223
  return true;
@@ -595,14 +585,12 @@ export const overridesMethods = {
595
585
  return target.name;
596
586
  },
597
587
  /** A module-level function, class or variable's Kotlin name. */
598
- topName(decl, name) {
599
- return this.topNames().get(decl) ?? name;
600
- },
588
+ /* topName is installed from semantics/lowering-methods.ts */
601
589
  /**
602
590
  * App mode: a type name Kotlin code already has unqualified (a default import's, the runtime's, a thread annotation's,
603
591
  * whose import outranks the app's package). Java classes are spelled qualified, so their names hide nothing.
604
592
  */
605
- nativeClash(name) {
593
+ kotlinTypeClash(name) {
606
594
  return !this.library && (KOTLIN_NATIVE_TYPES.has(name) || runtimeTypeName(name) || THREAD_ANNOTATIONS.includes(name));
607
595
  },
608
596
  /**
@@ -704,7 +692,7 @@ export const overridesMethods = {
704
692
  const kitClash = (list.some((x) => typeLike(x.decl)) && !!this.core?.has(name) && !this.core.nested?.(name)) || (coreFunctions.has(name) && list.some((x) => ts.isFunctionDeclaration(x.decl) || ts.isVariableDeclaration(x.decl)));
705
693
  // A type the hand-written kit declares for itself, or an app's type named as one Kotlin has already (`Pair`): the
706
694
  // generated one takes its module's name.
707
- const internalClash = !!this.library?.internalTypes?.has(name) || (list.some((x) => typeLike(x.decl) || ts.isInterfaceDeclaration(x.decl)) && this.nativeClash(name));
695
+ const internalClash = !!this.library?.internalTypes?.has(name) || (list.some((x) => typeLike(x.decl) || ts.isInterfaceDeclaration(x.decl)) && this.kotlinTypeClash(name));
708
696
  if (list.length < 2 && !kitClash && !internalClash)
709
697
  continue;
710
698
  // The app's declaration keeps its name (the first app module's, of several); the others take their module's.
@@ -43,18 +43,7 @@ export const placementMethods = {
43
43
  return this.typeOf(d.name);
44
44
  return ts.isParameter(d) ? this.paramType(d) : this.returnTypeOf(d);
45
45
  },
46
- /** A `nullishRead` value as its `JSNullish<T>`. */
47
- nullishCode(e) {
48
- if (!ts.isCallExpression(e) && !ts.isPropertyAccessExpression(e))
49
- return this.refName(e);
50
- this.nullishCalls.add(e);
51
- try {
52
- return this.expr(e);
53
- }
54
- finally {
55
- this.nullishCalls.delete(e);
56
- }
57
- },
46
+ /* nullishCode is installed from semantics/lowering-methods.ts */
58
47
  /** `nullableEntry`'s read: `jsNulledEntry` of the Map value `code` reads, `jsNulledElement` of the element, the field by its key, or a static by its written flag. */
59
48
  nulledEntry(read, code) {
60
49
  if (read.kind === 'static') {
@@ -43,7 +43,7 @@ export const stateBackendMethods = {
43
43
  return t.library;
44
44
  },
45
45
  get native() {
46
- return t.native;
46
+ return t.native ? { holdsNil: (d) => !!t.native.jvmHoldsNil?.(d) } : null;
47
47
  },
48
48
  get framework() {
49
49
  return t.framework;
@@ -67,7 +67,11 @@ export const stateBackendMethods = {
67
67
  const t = this.heldSpelling(x);
68
68
  return heldAs(t, isNullable(t));
69
69
  },
70
- kitNil: (x) => !this.library && !!this.core?.kitNil?.(x),
70
+ kitNil: (x) => !this.library && !!this.core?.kotlinKitNil?.(x),
71
+ untypedCastChecks: (_e, t) => {
72
+ const type = spell(t);
73
+ return this.isObjectType(type) && !/^JS(Array|Record|Promise|Date|Error)\b/.test(type);
74
+ },
71
75
  declaredOptional: (x) => {
72
76
  const sym = this.resolve(x);
73
77
  return !!sym && (!!this.undefinedVars.get(sym)?.endsWith('?') || !!this.declaredTypeOf(x)?.endsWith('?'));
@@ -128,19 +128,7 @@ export const statementsMethods = {
128
128
  });
129
129
  return forward;
130
130
  },
131
- block(b, base) {
132
- if (base === undefined)
133
- base = this.indent;
134
- const saved = this.indent;
135
- this.indent = base + ' ';
136
- try {
137
- const body = this.statements(ts.isBlock(b) ? [...b.statements] : [b]);
138
- return `{\n${body.join('\n')}\n${base}}`;
139
- }
140
- finally {
141
- this.indent = saved;
142
- }
143
- },
131
+ /* block is installed from semantics/lowering-methods.ts */
144
132
  stmt(s) {
145
133
  let code;
146
134
  const at = this.translating;
@@ -40,6 +40,8 @@ export class Translator {
40
40
  spelling = [];
41
41
  /** Variables initialized from an element read (`const r = xs[i]`): nullable, unwrapped where they are used. */
42
42
  undefinedVars = new Map();
43
+ /** Function-local `let s: string` variables only mutated via `+=` in a loop: lowered to `StringBuilder`. */
44
+ stringBuilders = new Set();
43
45
  /** A binding Kotlin holds as nullable though TypeScript types it present: reads take it as the undefined it may be. */
44
46
  bindsOptional(name, type) {
45
47
  const sym = this.checker.getSymbolAtLocation(name);
@@ -311,16 +313,6 @@ export class Translator {
311
313
  taken.set(prefix, n);
312
314
  return this.marks.pureCode(/^__[a-z]$/.test(prefix) ? `${prefix}_${n}` : `${prefix}${n}`);
313
315
  }
314
- nested(body) {
315
- const saved = this.indent;
316
- this.indent += ' ';
317
- try {
318
- return body();
319
- }
320
- finally {
321
- this.indent = saved;
322
- }
323
- }
324
316
  /** A constructor's `return`, inside the labeled block its `init` runs: Kotlin's `init` takes no `return`. */
325
317
  returnLabel = null;
326
318
  /** `return`, or in a lambda `return@` its label. */
@@ -511,7 +503,7 @@ export class Translator {
511
503
  if (sub)
512
504
  return this.convert(sub.code, this.typeOf(sub.bare), target);
513
505
  const inner = /^Signal<(.*)>\??$/.exec(target)?.[1];
514
- return inner && this.isComputedProperty(e) ? `Signal.computing { ${this.coerce(e, inner)} }` : null;
506
+ return inner && this.isKotlinComputedProperty(e) ? `Signal.computing { ${this.coerce(e, inner)} }` : null;
515
507
  },
516
508
  readHeld: (e) => this.readHeld(e),
517
509
  untypedRead: (code, target) => this.fromAnyCode(code, target, this.lenient),
@@ -98,7 +98,7 @@ export const typeTestsMethods = {
98
98
  const x = ts.skipOuterExpressions(e, ts.OuterExpressionKinds.Parentheses);
99
99
  if (this.lenientApp && ts.isIdentifier(x) && this.declaredTypeOf(x) === optionalType(t))
100
100
  return true;
101
- if (ts.isPropertyAccessExpression(x) && this.optionalMember(x))
101
+ if (ts.isPropertyAccessExpression(x) && this.isLenientOptionalMember(x))
102
102
  return true;
103
103
  if (this.lenientMissingMember(x))
104
104
  return true;
@@ -4,8 +4,8 @@ import { KIT_NAMES_ANDROID } from "./library.js";
4
4
  import { BUFFER_TYPES, WEB_DICTIONARIES, webClassName } from "../semantics/globals.js";
5
5
  import { SPELLING, spell, destructuringSource, functionTypeParts, kotlinString, nullishType, optionalElementsType, optionalType, presentConst, RT } from "./syntax.js";
6
6
  import { ambientBase, evolvingArrayRead, evolvingArrayType, isAmbientClass, isRegExpProtocol, memberOwner, namesOwnTypeParameter, tokenClassBase, isArguments } from "../semantics/lang.js";
7
- import { nullishSignalType } from "../semantics/signals.js";
8
- import { hasModifier, isLibDeclaration, thisNodes, isWriteTarget, implementationOf, takesOwnThis } from "../semantics/ast.js";
7
+ import { isGivenNullSignalValue, nullishSignalType } from "../semantics/signals.js";
8
+ import { hasModifier, isLibDeclaration, isWriteTarget, implementationOf, takesOwnThis } from "../semantics/ast.js";
9
9
  import { isCoreDeclaration } from "../program/core-facts.js";
10
10
  import { coreTypeKind, eventDataTypeLiteral, hasMappedIntersection, isJsDocConstructorFunction, isKit, isLibObjectType, isNamed, isUntyped, libraryNativeType, libraryType, mappedOrErasedType, nonNullableInner, nonOptionalSpelling, parseNativeType, spelledType, valueModuleKind } from "../semantics/types.js";
11
11
  import { isStatic } from "../semantics/throws.js";
@@ -194,7 +194,7 @@ export const typesMethods = {
194
194
  if (javaClass)
195
195
  return javaClass;
196
196
  // A program type renamed for a name Kotlin has already (`Iterator`, `Pair`) is not the library's type of that name.
197
- const clashing = !this.library && sym?.valueDeclaration && this.nativeClash(sym.name) ? this.topNames().get(sym.valueDeclaration) : undefined;
197
+ const clashing = !this.library && sym?.valueDeclaration && this.kotlinTypeClash(sym.name) ? this.topNames().get(sym.valueDeclaration) : undefined;
198
198
  if (clashing)
199
199
  return `${clashing}${this.declaredTypeArguments(t, sym.valueDeclaration, where)}`;
200
200
  const kind = name === undefined ? undefined : this.framework.signalKind(name);
@@ -204,7 +204,7 @@ export const typesMethods = {
204
204
  return `Signal<${arg(0)}>`;
205
205
  }
206
206
  if (kind === 'computed')
207
- return where && this.isComputedProperty(where) ? arg(0) : `Signal<${arg(0)}>`;
207
+ return where && this.isKotlinComputedProperty(where) ? arg(0) : `Signal<${arg(0)}>`;
208
208
  if (kind)
209
209
  return `Signal<${arg(0)}>`;
210
210
  const mapped = name === undefined ? undefined : this.framework.typeMapping(name);
@@ -506,7 +506,7 @@ export const typesMethods = {
506
506
  const t = this.isLenientDecl(own) ? this.lenientRef(declared) : this.states.looseDeclaration(own) ? optionalType(declared) : declared;
507
507
  if (this.holdingNull(t, n))
508
508
  return t.replace(/>$/, '?>');
509
- if (['String', 'Double', 'Boolean'].includes(t) && this.givenNullSignalValue(n))
509
+ if (['String', 'Double', 'Boolean'].includes(t) && isGivenNullSignalValue(n, (id) => this.resolve(id), (read) => ts.isCallExpression(read) && !read.arguments.length && /^Signal<.*\?>$/.test(this.typeOf(read.expression))))
510
510
  return `${t}?`;
511
511
  if (/^JSArray<String>\??$/.test(t) && this.unsetGroups(n))
512
512
  return t.replace('JSArray<String>', 'JSArray<String?>');
@@ -642,22 +642,5 @@ export const typesMethods = {
642
642
  const site = this.typeOf(e);
643
643
  return this.returnTypeOf(decl) === optionalType(site) && site !== optionalType(site) && !this.nullTolerant(e);
644
644
  },
645
- /** Runs `body` with `this` in `fn` (and in the arrow functions inside it) read as `name`. */
646
- withThis(fn, name, untyped, body) {
647
- const nodes = thisNodes(fn);
648
- for (const n of nodes) {
649
- this.subst.set(n, name);
650
- if (untyped)
651
- this.untypedThis.add(n);
652
- }
653
- try {
654
- return body();
655
- }
656
- finally {
657
- for (const n of nodes) {
658
- this.subst.delete(n);
659
- this.untypedThis.delete(n);
660
- }
661
- }
662
- },
645
+ /* withThis is installed from semantics/lowering-methods.ts */
663
646
  };
@@ -156,3 +156,12 @@ export function nativeViewOf(checker, type, table = NATIVE_VIEWS) {
156
156
  };
157
157
  return visit(checker.getNonNullableType(type));
158
158
  }
159
+ /** A core member read through a class of the app or a plugin that extends a core class (`this.isPassThroughParentEnabled` in a GridLayout subclass). */
160
+ export function inheritedCoreOwner(target, name, checker, kitRootOf) {
161
+ const decl = checker.getSymbolAtLocation(name)?.valueDeclaration;
162
+ if (!decl || !isCoreDeclaration(decl))
163
+ return null;
164
+ const cls = checker.getNonNullableType(checker.getTypeAtLocation(target)).getSymbol()?.valueDeclaration;
165
+ const root = cls && ts.isClassLike(cls) && !cls.getSourceFile().isDeclarationFile ? kitRootOf(cls) : null;
166
+ return root ? { name: root, isStatic: false } : null;
167
+ }
@@ -619,3 +619,18 @@ export function spellInstantiatedCollection(type, checker, render) {
619
619
  const args = info.typeArgs.map(render);
620
620
  return info.kind === 'Map' ? `JSMap<${args[0] ?? 'Any?'}, ${args[1] ?? 'Any?'}>` : `JS${info.kind}<${args[0] ?? 'Any?'}>`;
621
621
  }
622
+ /** Own instance methods of `cls` eligible for non-enumerable registration on `JSPrototypes.of(...)`. */
623
+ export function prototypeMethodList(cls, options) {
624
+ const seen = new Set();
625
+ const out = [];
626
+ for (const m of cls.members) {
627
+ if (!ts.isMethodDeclaration(m) || !m.body || isStatic(m) || ts.isPrivateIdentifier(m.name) || ts.isComputedPropertyName(m.name) || m.typeParameters?.length || m.asteriskToken)
628
+ continue;
629
+ const key = m.name.getText().replace(/^['"]|['"]$/g, '');
630
+ if (seen.has(key) || options.skip(m, key))
631
+ continue;
632
+ seen.add(key);
633
+ out.push({ method: m, key });
634
+ }
635
+ return out;
636
+ }
@@ -37,6 +37,7 @@ export class ProgramFacts {
37
37
  overrideMap = null;
38
38
  familyMap = null;
39
39
  protoKeys = null;
40
+ protoClasses = null;
40
41
  tdzSet = null;
41
42
  ifaceDecls = null;
42
43
  ifaceNamesByTop = new WeakMap();
@@ -46,7 +47,7 @@ export class ProgramFacts {
46
47
  return this.ifaceDecls;
47
48
  const out = [];
48
49
  const visit = (n) => {
49
- if (isShapeInterfaceDecl(n))
50
+ if (isShapeInterfaceDecl(n) && !(this.checker.getSymbolAtLocation(n.name)?.flags & ts.SymbolFlags.Class))
50
51
  out.push(n);
51
52
  ts.forEachChild(n, visit);
52
53
  };
@@ -452,7 +453,42 @@ export class ProgramFacts {
452
453
  }
453
454
  return (this.protoKeys = { data, accessors });
454
455
  }
455
- /** App-mode module `let`/`const` bindings in an import cycle that may be read before their module initializes. */
456
+ /** Program classes whose `.prototype` object is read or observed via `Object.getPrototypeOf` in app mode. */
457
+ prototypeClasses() {
458
+ if (this.protoClasses)
459
+ return this.protoClasses;
460
+ const out = new Set();
461
+ if (this.scope.library)
462
+ return (this.protoClasses = out);
463
+ let anyGetProto = false;
464
+ const addChain = (cls) => {
465
+ for (let c = cls; c; c = programBase(c, this.checker)) {
466
+ if (ts.isClassDeclaration(c) && !c.getSourceFile().isDeclarationFile)
467
+ out.add(c);
468
+ }
469
+ };
470
+ const visit = (n) => {
471
+ if (ts.isPropertyAccessExpression(n) && n.name.text === 'prototype') {
472
+ const sym = resolveSymbol(n.expression, this.checker);
473
+ if (sym && sym.flags & ts.SymbolFlags.Class && sym.valueDeclaration && ts.isClassLike(sym.valueDeclaration))
474
+ addChain(sym.valueDeclaration);
475
+ }
476
+ else if (ts.isCallExpression(n) && ts.isPropertyAccessExpression(n.expression) && ts.isIdentifier(n.expression.expression) && n.expression.expression.text === 'Object' && n.expression.name.text === 'getPrototypeOf') {
477
+ anyGetProto = true;
478
+ }
479
+ ts.forEachChild(n, visit);
480
+ };
481
+ for (const sf of this.files)
482
+ if (!sf.isDeclarationFile)
483
+ visit(sf);
484
+ if (anyGetProto) {
485
+ for (const c of this.classes())
486
+ if (ts.isClassDeclaration(c))
487
+ out.add(c);
488
+ }
489
+ return (this.protoClasses = out);
490
+ }
491
+ /** App-mode module `let`/`const` bindings that may be read before their initializer runs. */
456
492
  tdzBindings() {
457
493
  return (this.tdzSet ??= this.scope.library ? new Set() : cyclicModuleBindings(this.checker, this.files));
458
494
  }