@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
@@ -4,12 +4,13 @@ import { LIST_APPLIED, isTypedArrayType } from "./library.js";
4
4
  import { isLibGlobal } from "../semantics/globals.js";
5
5
  import { comparedToNullish, functionParts, hasTopLevelArrow, ident, isFunctionType, isOptional, isSymbolAsyncIterator, openSwiftChain, optionalType, swiftString, RT } from "./syntax.js";
6
6
  import { assertedReceiverCell, nullishField } from "../semantics/placement.js";
7
- import { intlConstructor, isDomGlobalDeclaration, isObjectToStringCall, mergedInterfaceMemberOf, statementLevel, isArguments, isSelf } from "../semantics/lang.js";
7
+ import { hookedDynamicImport, intlConstructor, isDomGlobalDeclaration, isObjectToStringCall, mergedInterfaceMemberOf, statementLevel, isArguments, isSelf } from "../semantics/lang.js";
8
8
  import { isLibDeclaration, isSymbolIterator } from "../semantics/ast.js";
9
9
  import { isStatic } from "../semantics/throws.js";
10
10
  import { callableSignal, mayBeUnset } from "../semantics/signals.js";
11
11
  import { baseMethod } from "../semantics/classes.js";
12
12
  import { isKit, isUntyped, spelledType } from "../semantics/types.js";
13
+ import { isKitInstanceMethod } from "../program/core-facts.js";
13
14
  export const callsMethods = {
14
15
  /** How many parameters the called function declares (JavaScript ignores extra arguments). */
15
16
  arity(e) {
@@ -84,6 +85,9 @@ export const callsMethods = {
84
85
  return this.signalRead(callee, (code) => (this.nullSignalRead(e) ? this.marks.implicitOf(code) : code));
85
86
  if (callee.kind === ts.SyntaxKind.SuperKeyword)
86
87
  throw this.error(e, 'super() outside the start of a constructor');
88
+ const dynImport = hookedDynamicImport(e, this.framework.hooks);
89
+ if (dynImport)
90
+ return dynImport;
87
91
  // `getWindow<UIWindow>?.()`: the type arguments are only TypeScript's, and a function declaration is always there.
88
92
  const declaredFunction = (x) => ts.isIdentifier(x) && !!this.resolve(x)?.declarations?.some(ts.isFunctionDeclaration);
89
93
  if (ts.isExpressionWithTypeArguments(callee) && (!e.questionDotToken || declaredFunction(callee.expression)))
@@ -138,7 +142,7 @@ export const callsMethods = {
138
142
  // `callback?.(x)` of a parameter declared present: Swift has it as non-optional, and the call is a plain one.
139
143
  const param = ts.isIdentifier(callee) ? this.resolve(callee)?.valueDeclaration : undefined;
140
144
  const presentParam = !!param && ts.isParameter(param) && !param.questionToken && !param.initializer && !this.states.mayBeNull(param) && isFunctionType(this.typeOf(callee));
141
- if (e.questionDotToken && !presentParam && !this.core.isKitMethod(callee) && !declaredMethod && !declaredFunction(callee)) {
145
+ if (e.questionDotToken && !presentParam && !isKitInstanceMethod(this.core, callee) && !declaredMethod && !declaredFunction(callee)) {
142
146
  // A field narrowed to a function already reads unwrapped.
143
147
  const fn = this.expr(callee);
144
148
  return fn.endsWith('!') ? `${fn}(${this.args(e).join(', ')})` : `${fn}?(${this.args(e).join(', ')})`;
@@ -6,7 +6,7 @@ import { isStatic } from "../semantics/throws.js";
6
6
  import { COLLECTION_OVERRIDE_METHODS, collectionBaseInfo, programBase, uncheckedIteratorResult } from "../semantics/classes.js";
7
7
  import { namesMembersBySymbol } from "../semantics/read-sites.js";
8
8
  import { fixedKey } from "../semantics/translator-methods.js";
9
- import { isDisposerMember } from "../semantics/lang.js";
9
+ import { isDirectSymbolMethod } from "../semantics/lang.js";
10
10
  export const classMethodsMethods = {
11
11
  computedMethods(k) {
12
12
  const { cls, name, expando, lines } = k;
@@ -128,8 +128,8 @@ export const classMethodsMethods = {
128
128
  }
129
129
  return;
130
130
  }
131
- if (keyed && isDisposerMember(keyed.member)) {
132
- lines.push(' ' + this.memberFunc(m, keyed.member));
131
+ if (keyed && isDirectSymbolMethod(keyed.member)) {
132
+ lines.push(' ' + this.memberFunc(m, keyed.member, isStatic(m) ? 'class ' : ''));
133
133
  return;
134
134
  }
135
135
  if (keyed)
@@ -4,7 +4,7 @@ import { resultSlot } from "../semantics/placement.js";
4
4
  import { capturesThis, escapingParam, ident, isFunctionType, isMethodValue, isOptional, metatype, nullishType, optionalType, swiftString, withoutThenables, RT } from "./syntax.js";
5
5
  import { equalOption } from "../semantics/signals.js";
6
6
  import { isTemplateMethod } from "../semantics/trust.js";
7
- import { hasModifier } from "../semantics/ast.js";
7
+ import { extendsHeritage, hasModifier, nonSuperStatements } from "../semantics/ast.js";
8
8
  import { nullableTypeNode, resultsAreUndefinedElements } from "../semantics/lang.js";
9
9
  import { implementedOptionalMembers } from "../semantics/shapes.js";
10
10
  import { isAsync, isStatic } from "../semantics/throws.js";
@@ -271,22 +271,38 @@ export const componentMethods = {
271
271
  this.declare(m.name.text, { kind: 'var', type: t });
272
272
  lines.push(` var ${ident(m.name.text)}: ${t}`);
273
273
  }
274
+ // If the component keeps a real superclass (e.g. `@Component extends @Directive`), chain `super.init()` before constructor body.
275
+ const baseCls = this.sourceBase(cls);
276
+ const baseThrows = !!baseCls && this.throwsInfo.initThrows(baseCls);
277
+ if (baseCls) {
278
+ inits.push(` ${baseThrows ? 'try ' : ''}super.init()`);
279
+ }
274
280
  // The constructor's body runs once every field is set; what it throws is reported, as a failed creation is.
275
- if (ctor?.body?.statements.length) {
281
+ const bodyStmts = nonSuperStatements(ctor);
282
+ if (bodyStmts.length) {
276
283
  this.indent = ' ';
277
- const body = this.statements([...ctor.body.statements]);
278
- inits.push(` ${this.throwsInfo.statements(ctor.body.statements) ? RT.jsReport : 'do'} {\n${body.join('\n')}\n }`);
284
+ const body = this.statements([...bodyStmts]);
285
+ inits.push(` ${this.throwsInfo.statements(bodyStmts) ? RT.jsReport : 'do'} {\n${body.join('\n')}\n }`);
279
286
  }
280
287
  this.indent = '';
281
- const throws = convenienceZeroArg || fieldThrows ? ' throws' : '';
288
+ const throws = convenienceZeroArg || fieldThrows || baseThrows ? ' throws' : '';
282
289
  if (throws && cls.name)
283
290
  this.throwingInits.add(cls.name.text);
284
- lines.push(` init(${propParams.join(', ')})${throws} {`, ...inits, ' }');
291
+ const overrideInit = !!baseCls && !propParams.length ? 'override ' : '';
292
+ lines.push(` ${overrideInit}init(${propParams.join(', ')})${throws} {`, ...inits, ' }');
285
293
  if (convenienceZeroArg) {
286
294
  lines.push(` convenience init() throws {\n try self.init(${ctorInjectVals.join(', ')})\n }`);
287
295
  }
288
296
  return lines;
289
297
  },
298
+ /** The Swift superclass clause (`: Base<...>`) for a component that keeps a real superclass, else empty. */
299
+ componentSuperclass(cls) {
300
+ const heritage = extendsHeritage(cls);
301
+ const appBase = this.sourceBase(cls);
302
+ if (!heritage || !appBase)
303
+ return '';
304
+ return `: ${this.className(appBase)}${this.typeArguments(heritage, appBase)}`;
305
+ },
290
306
  /** Static members a component class adds for the framework. */
291
307
  componentStatics(cls) {
292
308
  return this.framework.hooks.componentStatics?.(this, cls) ?? [];
@@ -319,8 +335,12 @@ export const componentMethods = {
319
335
  },
320
336
  /** Whether a component's method or getter throws, so its caller in `render()` reports what it throws. */
321
337
  memberThrows(cls, name) {
322
- const m = cls.members.find((x) => x.name && ts.isIdentifier(x.name) && x.name.text === name);
323
- return !!m && !isAsync(m) && this.throwsInfo.fn(m);
338
+ for (let cur = cls; cur; cur = this.sourceBase(cur)) {
339
+ const m = cur.members.find((x) => x.name && ts.isIdentifier(x.name) && x.name.text === name);
340
+ if (m)
341
+ return !isAsync(m) && this.throwsInfo.fn(m);
342
+ }
343
+ return false;
324
344
  },
325
345
  /** The memo call (`computed(fn)`) a module-level variable an identifier names is initialized with. */
326
346
  moduleComputed(id) {
@@ -271,6 +271,10 @@ export const constructionMethods = {
271
271
  return `${t}()`;
272
272
  return `${t}(${this.args(e).join(', ')})`;
273
273
  }
274
+ if (this.checker.getTypeAtLocation(callee).getConstructSignatures().length) {
275
+ const made = `NativeScriptKit.jsConstruct(${this.expr(callee)}${this.untypedArgs(e)})`;
276
+ return isUntyped(spelledType(t)) ? made : this.fromAny(made, t);
277
+ }
274
278
  throw this.error(e, 'new');
275
279
  },
276
280
  /** One of the library's error classes, constructed. */
@@ -299,7 +299,7 @@ export const conversionMethods = {
299
299
  if (isUntyped(spelledType(from)))
300
300
  return this.fromAny(code, to);
301
301
  // An event's data read as the object type a handler declares (`({ window }: { window: NativeWindow })`).
302
- if (from === 'EventData' && (this.interfaces.has(to.replace(/\?$/, '')) || !!this.shapes.named(to.replace(/\?$/, ''))))
302
+ if (from === 'EventData' && (this.facts.hasInterface(this, this.interfaces, (d, s) => this.topName(d, s), to.replace(/\?$/, '')) || !!this.shapes.named(to.replace(/\?$/, ''))))
303
303
  return this.fromAny(code, to);
304
304
  const f = functionParts(unwrapFunction(from, false));
305
305
  const g = functionParts(unwrapFunction(to, false));
@@ -5,6 +5,7 @@ import { KIT_GLOBALS, KitTypes, coreClass, kitExtends, kitIndex, kitMember } fro
5
5
  import { NATIVE_MEMBERS, SCRIPT_OBJECTS, addedDeclarations, augmentedProperty, coreBarrels, coreSymbolName, isCoreDeclaration, ownPropertyOnly, packageOf, unappliedProperty } from "../program/core-facts.js";
6
6
  import { optionalType, splitTopLevel, RT } from "./syntax.js";
7
7
  import { rethrowUnlessRefused } from "../semantics/refusals.js";
8
+ import { isMixinOwnMember } from "../semantics/classes.js";
8
9
  import { isKit, isUntyped, spelledType } from "../semantics/types.js";
9
10
  export const KIT = KIT_APPLE_SOURCES;
10
11
  /**
@@ -347,7 +348,9 @@ export class CoreAPI extends KitTypes {
347
348
  return `${recv}.nativeView`;
348
349
  if (!owner.isStatic && this.isView(owner.name) && !kitMember(this.index, owner.name, name)) {
349
350
  if (!this.isViewProperty(owner.name, name)) {
350
- if (!augmentedProperty(this.index, owner.name, e.name, t.resolve(e.name)))
351
+ const sym = t.resolve(e.name);
352
+ const extra = !sym || sym.declarations?.every((d) => !isCoreDeclaration(d));
353
+ if (!extra && !augmentedProperty(this.index, owner.name, e.name, sym))
351
354
  unappliedProperty(t, e.name, `${owner.name}.${name}`, 'NativeScriptKit');
352
355
  else if (inChain)
353
356
  throw t.error(e, `${owner.name}.${name} in an optional chain`);
@@ -371,7 +374,8 @@ export class CoreAPI extends KitTypes {
371
374
  }
372
375
  return undefined;
373
376
  })();
374
- if (!own && !owner.isStatic && (this.ownPropertyOnly(owner.name, e.name) || augmentedProperty(this.index, owner.name, e.name, t.resolve(e.name)))) {
377
+ const propSym = t.resolve(e.name);
378
+ if (!own && !owner.isStatic && (this.ownPropertyOnly(owner.name, e.name) || augmentedProperty(this.index, owner.name, e.name, propSym) || ((!propSym || !propSym.declarations?.some(isCoreDeclaration)) && kitMember(this.index, owner.name, 'jsExpando')))) {
375
379
  if (inChain)
376
380
  throw t.error(e, `${owner.name}.${name} in an optional chain`);
377
381
  return t.fromAnyCode(`${recv}[jsKey: ${JSON.stringify(name)}]`, t.typeOf(e), true);
@@ -429,7 +433,8 @@ export class CoreAPI extends KitTypes {
429
433
  const recv = owner.isStatic ? owner.name : this.receiver(left.expression, left.name.text);
430
434
  if (!owner.isStatic && this.isView(owner.name) && (!kitMember(this.index, owner.name, name) || this.isViewProperty(owner.name, name))) {
431
435
  if (!this.isViewProperty(owner.name, name)) {
432
- if (augmentedProperty(this.index, owner.name, left.name, t.resolve(left.name)))
436
+ const sym = t.resolve(left.name);
437
+ if (!sym || sym.declarations?.every((d) => !isCoreDeclaration(d)) || augmentedProperty(this.index, owner.name, left.name, sym))
433
438
  return `${recv}[jsKey: ${JSON.stringify(name)}] = ${t.coerce(value, 'Any?')}`;
434
439
  unappliedProperty(t, left.name, `${owner.name}.${name}`, 'NativeScriptKit');
435
440
  }
@@ -465,8 +470,7 @@ export class CoreAPI extends KitTypes {
465
470
  }
466
471
  /** A member a mixin class declares: the extension it becomes has it by name. */
467
472
  mixinOwn(name) {
468
- const decl = this.t.checker.getSymbolAtLocation(name)?.valueDeclaration;
469
- return !!decl && ts.isClassDeclaration(decl.parent) && !!this.t.mixinOf(this.t.checker.getSymbolAtLocation(decl.parent.name));
473
+ return isMixinOwnMember(name, this.t.checker, (s) => this.t.mixinOf(s));
470
474
  }
471
475
  /**
472
476
  * A member of an event data type (core's, or a framework's such as `ListViewItemTapEvent`)
@@ -651,13 +655,6 @@ export class CoreAPI extends KitTypes {
651
655
  this.matchKitParams(e, params, out);
652
656
  return out;
653
657
  }
654
- /** Whether `target.method` is a method the kit declares on target's class (an optional call of it is a plain call). */
655
- isKitMethod(callee) {
656
- if (!ts.isPropertyAccessExpression(callee))
657
- return false;
658
- const owner = this.owner(callee.expression);
659
- return !!owner && !owner.isStatic && kitMember(this.index, owner.name, callee.name.text)?.kind === 'func';
660
- }
661
658
  /** `target.method(args)` where target is core-typed, or `new CoreClass(args)`. */
662
659
  call(e) {
663
660
  if (!ts.isPropertyAccessExpression(e.expression))
@@ -253,12 +253,12 @@ export const fromAnyMethods = {
253
253
  if (whole)
254
254
  return this.unboxFunction(code, whole);
255
255
  const base = type.replace(/\?$/, '');
256
- if (this.protocols.has(base) && this.interfaces.has(base)) {
256
+ if (this.protocols.has(base) && this.facts.hasInterface(this, this.interfaces, (d, s) => this.topName(d, s), base)) {
257
257
  this.used.add(base);
258
258
  // An interface classes implement: an object conforming to it as it is, any other read by its keys.
259
259
  return type.endsWith('?') ? `${RT.jsUnlessNullish}(${code}, { (${RT.jsFlat}($0) as? ${base}) ?? ${base}Object(jsObject: $0) })` : `{ (__o: Any?) -> ${base} in (${RT.jsFlat}(__o) as? ${base}) ?? ${base}Object(jsObject: __o) }(${code})`;
260
260
  }
261
- if (this.interfaces.has(base) || !!this.shapes.named(base) || (!this.library && this.core.viewable(base))) {
261
+ if (this.facts.hasInterface(this, this.interfaces, (d, s) => this.topName(d, s), base) || !!this.shapes.named(base) || (!this.library && this.core.viewable(base))) {
262
262
  this.used.add(base);
263
263
  // An object of the interface's class already is the object read (a receiver `call` passes); any other is read by its keys.
264
264
  return type.endsWith('?') ? `${RT.jsUnlessNullish}(${code}, { (${RT.jsFlat}($0) as? ${base}) ?? ${this.viewOf(base, '$0')} })` : `{ (__o: Any?) -> ${base} in (${RT.jsFlat}(__o) as? ${base}) ?? ${this.viewOf(base, '__o')} }(${code})`;
@@ -389,8 +389,19 @@ export const functionsMethods = {
389
389
  const ret = this.closureResult(fn).target;
390
390
  const throws = !isAsync(fn) && this.throwsInfo.fn(fn) ? 'throws ' : '';
391
391
  // A function expression's name is only for itself: one that never refers to itself is an anonymous function.
392
- if (fn.name && refersTo(fn.body, this.checker.getSymbolAtLocation(fn.name), this.checker))
393
- throw this.error(fn, 'a named function expression', 'named-function-expression');
392
+ if (fn.name && refersTo(fn.body, this.checker.getSymbolAtLocation(fn.name), this.checker)) {
393
+ const fnName = ident(fn.name.text);
394
+ const extra = this.unusedParameters(fn).map((t, k) => `_ __unused${k}: ${t}`);
395
+ const fnParams = [this.params(fn, false), ...extra, ...pad.map((p) => (p.startsWith('_ ') ? p : `_ ${p}`))].filter(Boolean).join(', ');
396
+ const pTypes = fnParams
397
+ ? splitTopLevel(fnParams).map((d) => withoutDefault(d.slice(d.indexOf(':') + 1))
398
+ .trim()
399
+ .replace(/^@escaping /, ''))
400
+ : [];
401
+ const fnType = `(${pTypes.join(', ')}) ${throws}-> ${ret}`;
402
+ const body = this.functionBody(fn, ret, this.indent + ' ');
403
+ return `{ () -> ${fnType} in\n${this.indent} func ${fnName}(${fnParams}) ${throws}-> ${ret} ${body}\n${this.indent} return ${fnName}\n${this.indent}}()`;
404
+ }
394
405
  if (this.takesRestArray(fn) && !pad.length) {
395
406
  const inner = this.indent + ' ';
396
407
  const binds = fn.parameters.map((p, k) => {
@@ -52,7 +52,11 @@ export const genericsMethods = {
52
52
  * `Plot<Point>` where `Plot<any>` is taken compiles only erased. Each parameter is then any value.
53
53
  */
54
54
  erasesGenerics(decl) {
55
- return !decl.getSourceFile().isDeclarationFile && this.pluginFiles.has(decl.getSourceFile().fileName) && !this.keepsGenerics(decl);
55
+ if (decl.getSourceFile().isDeclarationFile)
56
+ return false;
57
+ if (ts.isClassDeclaration(decl) && this.framework.hooks.erasesGenericClass?.(decl))
58
+ return true;
59
+ return this.pluginFiles.has(decl.getSourceFile().fileName) && !this.keepsGenerics(decl);
56
60
  },
57
61
  /** The Swift type of a member whose declared type names a type parameter of its erased generic class (`data: T` as `Any?`); null for any other. */
58
62
  erasedMemberType(decl) {
@@ -132,6 +132,8 @@ export const globalCallsMethods = {
132
132
  // `Error('x')` constructs as `new Error('x')` does.
133
133
  if (ERRORS[name])
134
134
  return this.errorValue(name, e.arguments);
135
+ if (name === 'getComputedStyle')
136
+ return `({ (_: Any?) -> Any? in JSObject([("getPropertyValue", { (_: [Any?]) -> Any? in "" } as JSFunction)]) }(${arg(0) ? this.coerce(arg(0), 'Any?') : 'nil'}))`;
135
137
  if (decl && /[\\/]lib\.[\w.]*\.d\.ts$/.test(decl.getSourceFile().fileName))
136
138
  throw this.error(e, `${name}()`, name === 'Object' ? 'object-call' : 'library-member');
137
139
  }
@@ -1,13 +1,13 @@
1
1
  // Literals as Swift: arrays, objects and dynamic objects.
2
2
  import ts from 'typescript';
3
3
  import { functionParts, ident, identPath, initOrder, isNullish, isOptional, label, optionalType, splitTopLevel, swiftString, withoutThenables, spell, RT } from "./syntax.js";
4
- import { assertedOperand, evolvingElementContext, intersectionAliasMembers, literalKey, openSpreadType, spreadOperand, unquoted } from "../semantics/lang.js";
4
+ import { assertedOperand, evolvingElementContext, intersectionAliasMembers, isTypeParameterType, literalKey, openSpreadType, spreadOperand, unquoted } from "../semantics/lang.js";
5
5
  import { place } from "../semantics/placement.js";
6
- import { holdsNil, literalNotes, signatureField, shapePlanOfLiteral, spelledOptional, resultShapeNamed } from "../semantics/shapes.js";
6
+ import { holdsNil, literalNotes, signatureField, shapePlanOfLiteral, spelledOptional, spreadElementNeedsMap, resultShapeNamed } from "../semantics/shapes.js";
7
7
  import { isCoreDeclaration } from "../program/core-facts.js";
8
- import { thisNodes, withoutDefault } from "../semantics/ast.js";
8
+ import { hasModifier, thisNodes, tupleSpreadTypes, withoutDefault } from "../semantics/ast.js";
9
9
  import { programSymbolKey } from "../program/stable-names.js";
10
- import { literalClassOf } from "../semantics/classes.js";
10
+ import { classOfType, literalClassOf } from "../semantics/classes.js";
11
11
  import { heldOf, isKit, isUntyped, spelledType } from "../semantics/types.js";
12
12
  export const literalsMethods = {
13
13
  array(e, want) {
@@ -33,9 +33,44 @@ export const literalsMethods = {
33
33
  if (isUntyped(spelledType(t)) || t === 'JSArray<Never>')
34
34
  t = 'JSArray<Any?>';
35
35
  if (t.startsWith('(')) {
36
- const types = want ? splitTopLevel(t.slice(1, -1)) : [];
36
+ const tupleTypes = splitTopLevel(t.slice(1, -1));
37
+ if (e.elements.some(ts.isSpreadElement)) {
38
+ const binds = [];
39
+ const items = [];
40
+ for (const x of e.elements) {
41
+ if (ts.isSpreadElement(x)) {
42
+ const args = tupleSpreadTypes(x, this.checker);
43
+ if (args) {
44
+ const spreadExpr = this.expr(x.expression);
45
+ const ref = ts.isIdentifier(x.expression) ? spreadExpr : this.fresh('__tup');
46
+ if (ref !== spreadExpr)
47
+ binds.push(`let ${ref} = ${this.tryPrefix(x.expression)}${spreadExpr}`);
48
+ const stName = this.typeOf(x.expression);
49
+ for (let k = 0; k < args.length; k++) {
50
+ const elem = stName.startsWith('(') ? `${ref}.${k}` : `${ref}[${k}]`;
51
+ const from = this.type(args[k], x);
52
+ const to = tupleTypes[items.length];
53
+ items.push(to && to !== from ? this.convert(elem, from, to) : elem);
54
+ }
55
+ continue;
56
+ }
57
+ throw this.error(x, `a non-tuple spread in tuple ${t}`);
58
+ }
59
+ const to = tupleTypes[items.length];
60
+ items.push(to ? this.coerce(x, to) : this.expr(x));
61
+ }
62
+ const missing = tupleTypes.slice(items.length).map((x) => (isOptional(x) || isUntyped(spelledType(x)) ? 'nil' : null));
63
+ if (missing.some((x) => x === null))
64
+ throw this.error(e, `an array literal shorter than its tuple type ${t}`);
65
+ const made = `(${[...items, ...missing].join(', ')})`;
66
+ if (!binds.length)
67
+ return made;
68
+ const throws = this.throwsInfo.expr(e) || binds.some((b) => b.includes('try '));
69
+ return `{ () ${throws ? 'throws ' : ''}-> ${t} in ${binds.join('; ')}; return ${made} }()`;
70
+ }
71
+ const types = want ? tupleTypes : [];
37
72
  // An optional element left out (`['a']` for `[string, string?]`) is undefined.
38
- const missing = splitTopLevel(t.slice(1, -1))
73
+ const missing = tupleTypes
39
74
  .slice(e.elements.length)
40
75
  .map((x) => (isOptional(x) || isUntyped(spelledType(x)) ? 'nil' : null));
41
76
  if (missing.some((x) => x === null))
@@ -53,9 +88,9 @@ export const literalsMethods = {
53
88
  parts.push(`[${run.join(', ')}]`);
54
89
  run = [];
55
90
  }
56
- // The spread's elements as this array's (`[name, ...untyped]` into a `string[]`).
57
- const from = this.elementTypeOf(x.expression);
58
- parts.push(from !== el && isUntyped(spelledType(from)) ? `Array(${this.iterable(x.expression)}).map { ${this.fromAny('$0', el)} }` : `Array(${this.iterable(x.expression)})`);
91
+ // The spread's elements as this array's (`[name, ...untyped]` into a `string[]`, or `[...derived]` into a base shape array).
92
+ const needsMap = spreadElementNeedsMap(this.elementTypeOf(x.expression), el, (n) => this.isObjectShape(n), true);
93
+ parts.push(needsMap ? `Array(${this.iterable(x.expression)}).map { ${this.fromAny('$0', el)} }` : `Array(${this.iterable(x.expression)})`);
59
94
  }
60
95
  else if (ts.isOmittedExpression(x))
61
96
  throw this.error(x, 'an array hole', 'array-hole');
@@ -117,6 +152,8 @@ export const literalsMethods = {
117
152
  return `${r}.object[${ts.isComputedPropertyName(p.name) ? `${this.tryPrefix(p.name.expression)}${this.propertyKey(p.name.expression)}` : swiftString(literalKey(p.name, this.checker) ?? p.name.getText())}] = ${this.marks.tryBefore(this.tryPrefix(p.initializer), this.stored(p.initializer, p, v))}`;
118
153
  if (ts.isShorthandPropertyAssignment(p))
119
154
  return `${r}.object[${swiftString(p.name.text)}] = ${this.shorthandEntry(p, v)}`;
155
+ if (ts.isMethodDeclaration(p))
156
+ return `${r}.object[${ts.isComputedPropertyName(p.name) ? `${this.tryPrefix(p.name.expression)}${this.propertyKey(p.name.expression)}` : swiftString(literalKey(p.name, this.checker) ?? p.name.getText())}] = ${this.untypedMethod(p)}`;
120
157
  throw this.error(p, 'this member in a dictionary literal');
121
158
  });
122
159
  const throws = this.throwsInfo.expr(e) || steps.some((x) => x.includes('try '));
@@ -127,6 +164,8 @@ export const literalsMethods = {
127
164
  return `(${ts.isComputedPropertyName(p.name) ? this.propertyKey(p.name.expression) : swiftString(literalKey(p.name, this.checker) ?? p.name.getText())}, ${this.stored(p.initializer, p, v)})`;
128
165
  if (ts.isShorthandPropertyAssignment(p))
129
166
  return `(${swiftString(p.name.text)}, ${this.shorthandEntry(p, v)})`;
167
+ if (ts.isMethodDeclaration(p))
168
+ return `(${ts.isComputedPropertyName(p.name) ? this.propertyKey(p.name.expression) : swiftString(literalKey(p.name, this.checker) ?? p.name.getText())}, ${this.untypedMethod(p)})`;
130
169
  throw this.error(p, 'this member in a dictionary literal');
131
170
  });
132
171
  return entries.length ? `${name}([${entries.join(', ')}])` : `${name}()`;
@@ -136,6 +175,8 @@ export const literalsMethods = {
136
175
  return `EventData(jsObject: ${this.dynamicObject(e)})`;
137
176
  if (isUntyped(spelledType(name)) || name === 'Any' || name === 'Never' || name === 'EventData' || name === 'JSObject')
138
177
  return this.dynamicObject(e);
178
+ if (isTypeParameterType(type, this.checker))
179
+ return this.fromAnyCode(this.dynamicObject(e), name);
139
180
  if (/^JS(Iterator|AsyncIterator)</.test(name))
140
181
  return this.scriptIterator(e, name);
141
182
  // A spread of an open type (`{ ...state, x }` with `state: T`) carries keys no shape declares; the shape keeps them as extras.
@@ -171,8 +212,14 @@ export const literalsMethods = {
171
212
  order = this.interfaceFields(ts.isInterfaceDeclaration(decl) ? this.interfaceMembers(decl) : decl.members);
172
213
  else if (joined)
173
214
  order = this.interfaceFields(joined);
174
- else
215
+ else if (decl && ts.isModuleDeclaration(decl))
216
+ return this.dynamicObject(e);
217
+ else {
218
+ const cls = classOfType(type, this.checker) ?? literalClassOf(this, e);
219
+ if (cls && (this.pluginFiles.has(e.getSourceFile().fileName) || hasModifier(cls, ts.SyntaxKind.AbstractKeyword)))
220
+ return this.abstractClassLiteral(e, cls, name);
175
221
  throw this.error(e, `an object literal of type ${name}`);
222
+ }
176
223
  const given = new Map();
177
224
  const spreadTemps = [];
178
225
  // An optional field given undefined is a key all the same, as one given null is: the shape notes which (`jsUnset`,
@@ -581,7 +581,7 @@ export const modulesMethods = {
581
581
  return { shape: (n) => this.isObjectShape(n), extends: (a, b) => !!this.classNamed(a) && this.sourceExtends(a, b) };
582
582
  },
583
583
  isObjectShape(name) {
584
- return (this.interfaces.has(name) && !this.protocols.has(name)) || !!this.shapes.named(name) || (!this.library && this.core.viewable(name));
584
+ return (this.facts.hasInterface(this, this.interfaces, (d, s) => this.topName(d, s), name) && !this.protocols.has(name)) || !!this.shapes.named(name) || (!this.library && this.core.viewable(name));
585
585
  },
586
586
  /** An interface's members with those of the interfaces it extends (`StageFold extends Rect`), its own first. */
587
587
  interfaceMembers(decl) {
@@ -21,7 +21,7 @@ export const namesMethods = {
21
21
  if (thisFn) {
22
22
  const declared = declaresThis(thisFn);
23
23
  const params = declared ? thisFn.parameters.slice(1) : [...thisFn.parameters];
24
- const args = params.map((p, k) => this.fromAnyCode(`${RT.jsArg}(__a, ${k})`, this.paramType(p), true));
24
+ const args = this.readsArguments(thisFn) ? ['JSArray<Any?>(__a)'] : params.map((p, k) => this.fromAnyCode(`${RT.jsArg}(__a, ${k})`, this.paramType(p), true));
25
25
  const self = declared ? this.paramType(thisFn.parameters[0]) : 'Any?';
26
26
  const call = this.marks.tryIf(this.throwsInfo.fn(thisFn), `${this.refName(e)}(${[isUntyped(spelledType(self)) ? '__this' : this.fromAnyCode('__this', self, true), ...args].join(', ')})`);
27
27
  const ret = this.returnTypeOf(thisFn);
@@ -22,8 +22,8 @@ export function isSubframework(module) {
22
22
  }
23
23
  // By the SDK's build too: a beta and its release candidate share a version and differ in API.
24
24
  export const tableCache = () => join(compiledEnv('TABLE_CACHE') ?? cacheDir('native-tables'), `ios-${sdk().version}-${sdk().build}`);
25
- /** The layout tables are written in: availability of enums, escaping block parameters, optional protocol properties, typedefs of a plugin's headers. */
26
- const TABLE_FORMAT = 8;
25
+ /** The layout tables are written in: availability of enums, escaping block parameters, optional protocol properties, typedefs of a plugin's headers, nested @objc types. */
26
+ const TABLE_FORMAT = 9;
27
27
  export const tables = buildCache(new Map());
28
28
  /** The key each module outside the SDK was loaded under. */
29
29
  export const tableKeys = buildCache(new Map());
@@ -123,7 +123,7 @@ function generate(module, extraArgs, plugin = false, internal = false) {
123
123
  // headers is named with its header (`c:Branch.h@T@BranchStandardEvent`), an SDK one without (`c:@T@…`).
124
124
  const objcUSR = plugin
125
125
  ? (usr) => usr
126
- .replace(/^c:@C?M@\w+@@?(?=objc\()/, 'c:')
126
+ .replace(/^c:@C?M@\w+(?:@[A-Z]+@\w+)*@@?(?=objc\()/, 'c:')
127
127
  .replace(/^c:@M@\w+@(?=E@)/, 'c:@')
128
128
  .replace(/(^|::SYNTHESIZED::)c:[^@:]+@(?=T@)/, '$1c:@')
129
129
  : (usr) => usr;
@@ -168,6 +168,54 @@ function generate(module, extraArgs, plugin = false, internal = false) {
168
168
  swiftTypes[s.pathComponents[0]] = kind;
169
169
  }
170
170
  }
171
+ const swiftObjcMap = new Map();
172
+ if (plugin) {
173
+ for (const s of graph.symbols) {
174
+ if (!s.identifier.precise.startsWith('s:') || (s.kind.identifier !== 'swift.protocol' && s.kind.identifier !== 'swift.class'))
175
+ continue;
176
+ const declText = (s.declarationFragments ?? []).map((x) => x.spelling).join('');
177
+ if (!/@objc\b/.test(declText))
178
+ continue;
179
+ const explicit = /@objc\((\w+)\)/.exec(declText)?.[1];
180
+ const name = explicit ?? s.pathComponents.at(-1);
181
+ if (name)
182
+ swiftObjcMap.set(s.identifier.precise, `c:objc(${s.kind.identifier === 'swift.protocol' ? 'pl' : 'cs'})${name}`);
183
+ }
184
+ if (swiftObjcMap.size) {
185
+ const ownerOf = new Map();
186
+ for (const r of graph.relationships)
187
+ if ((r.kind === 'memberOf' || r.kind === 'requirementOf') && swiftObjcMap.has(r.target))
188
+ ownerOf.set(r.source, swiftObjcMap.get(r.target));
189
+ for (const s of graph.symbols) {
190
+ const mapped = swiftObjcMap.get(s.identifier.precise);
191
+ if (mapped) {
192
+ s.identifier.precise = mapped;
193
+ continue;
194
+ }
195
+ const ownerUsr = ownerOf.get(s.identifier.precise);
196
+ if (!ownerUsr || !s.identifier.precise.startsWith('s:'))
197
+ continue;
198
+ const declText = (s.declarationFragments ?? []).map((x) => x.spelling).join('');
199
+ if (!/@objc\b/.test(declText) && !ownerUsr.includes('objc(pl)'))
200
+ continue;
201
+ const last = s.pathComponents.at(-1) ?? '';
202
+ if (s.kind.identifier === 'swift.method' || s.kind.identifier === 'swift.type.method' || s.kind.identifier === 'swift.init') {
203
+ const part = s.kind.identifier === 'swift.type.method' ? 'cm' : 'im';
204
+ const explicitSel = /@objc\(([^)]+)\)/.exec(declText)?.[1];
205
+ const m = /^(\w+)\(([^)]*)\)$/.exec(last);
206
+ const lbls = m && m[2] ? m[2].split(':').slice(0, -1) : [];
207
+ const sel = explicitSel ?? (m ? `${m[1]}${lbls.length ? (lbls[0] === '_' ? ':' : `With${upperFirst(lbls[0])}:`) + lbls.slice(1).map((l) => (l === '_' ? ':' : `${l}:`)).join('') : ''}` : last);
208
+ swiftObjcMap.set(s.identifier.precise, `${ownerUsr}(${part})${sel}`);
209
+ s.identifier.precise = `${ownerUsr}(${part})${sel}`;
210
+ }
211
+ else if (s.kind.identifier === 'swift.property' || s.kind.identifier === 'swift.type.property') {
212
+ const part = s.kind.identifier === 'swift.type.property' ? 'cpy' : 'py';
213
+ swiftObjcMap.set(s.identifier.precise, `${ownerUsr}(${part})${last}`);
214
+ s.identifier.precise = `${ownerUsr}(${part})${last}`;
215
+ }
216
+ }
217
+ }
218
+ }
171
219
  for (const s of graph.symbols) {
172
220
  const swiftClass = plugin && s.kind.identifier === 'swift.class' && /^c:@M@/.test(s.identifier.precise);
173
221
  s.identifier.precise = objcUSR(s.identifier.precise);
@@ -184,7 +232,7 @@ function generate(module, extraArgs, plugin = false, internal = false) {
184
232
  symbols.set(sym.usr, sym);
185
233
  }
186
234
  for (const r of graph.relationships)
187
- rels.push({ ...r, source: objcUSR(r.source), target: objcUSR(r.target) });
235
+ rels.push({ ...r, source: objcUSR(swiftObjcMap.get(r.source) ?? r.source), target: objcUSR(swiftObjcMap.get(r.target) ?? r.target) });
188
236
  }
189
237
  }
190
238
  finally {
@@ -132,12 +132,20 @@ export function lookupClass(module, jsClass) {
132
132
  }
133
133
  export function lookupMember(module, jsClass, jsMember, isStatic) {
134
134
  const receiver = lookupClass(module, jsClass);
135
+ let readonlyProp = null;
135
136
  for (const [, c] of hierarchy(module, jsClass)) {
136
137
  const members = isStatic ? c.static : c.instance;
137
138
  const m = Object.hasOwn(members, jsMember) ? members[jsMember] : null;
138
- if (m)
139
+ if (m) {
140
+ if (m.kind === 'property' && m.readonly) {
141
+ readonlyProp ??= rehome(m, c, receiver);
142
+ continue;
143
+ }
139
144
  return rehome(m, c, receiver);
145
+ }
140
146
  }
147
+ if (readonlyProp)
148
+ return readonlyProp;
141
149
  if (!isStatic && !jsMember.startsWith('init') && cLong.test(jsMember))
142
150
  return lookupMember(module, jsClass, jsMember.replace(cLong, 'LongLong'), false);
143
151
  if (!isStatic)
@@ -8,7 +8,7 @@ import { asOperation, assignmentOf, readWrite } from "../semantics/lang.js";
8
8
  import { assertedFrom, emptyComparison, scriptComparison } from "../semantics/placement.js";
9
9
  import { notedField } from "../semantics/shapes.js";
10
10
  import { isLibDeclaration } from "../semantics/ast.js";
11
- import { constClassExpr } from "../semantics/classes.js";
11
+ import { constClassExpr, hasInstanceClass } from "../semantics/classes.js";
12
12
  import { isUntyped, spelledType } from "../semantics/types.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";
@@ -334,6 +334,9 @@ export const operatorsMethods = {
334
334
  return op === K.BarBarToken ? `({ () ${throws}-> ${t} in let ${v} = ${this.marks.tryBefore(lt, leftCode)}; return ${RT.jsTruthy}(${v}) ? ${leftValue} : ${rt}${right} }())` : `({ () ${throws}-> ${t} in let ${v} = ${this.marks.tryBefore(lt, leftCode)}; return ${RT.jsTruthy}(${v}) ? ${rt}${right} : ${leftValue} }())`;
335
335
  }
336
336
  case K.InstanceOfKeyword: {
337
+ const hi = hasInstanceClass(e.right, this.checker);
338
+ if (hi)
339
+ return `${this.className(hi)}.jsHasInstance(${this.coerce(e.left, 'Any?')})`;
337
340
  const ce = constClassExpr(e.right, this.checker);
338
341
  if (ce)
339
342
  return `(${this.observed(e.left)} is ${this.emitClassExpr(ce)})`;
@@ -26,9 +26,12 @@ export const parametersMethods = {
26
26
  return !this.lenient && !p.questionToken && ts.isIdentifier(p.name) && this.states.widened(p) && !this.states.nullishHeld(p) && !isOptional(this.typeOf(p.name)) && !this.isAny(p.name);
27
27
  },
28
28
  params(fn, closure) {
29
- if (this.readsArguments(fn))
30
- return `${closure ? '' : '_ '}__arguments: JSArray<Any?>`;
31
29
  const receiver = this.implicitThis(fn) ? [`${closure ? '' : '_ '}${ident('this')}: Any?`] : [];
30
+ if (this.readsArguments(fn)) {
31
+ const explicitThis = !closure ? fn.parameters.find((p) => ts.isIdentifier(p.name) && p.name.text === 'this' && p.type?.kind !== ts.SyntaxKind.VoidKeyword) : undefined;
32
+ const selfParam = receiver.length ? receiver : explicitThis ? [`_ ${ident('this')}: ${this.typeOf(explicitThis.name)}`] : [];
33
+ return [...selfParam, `${closure ? '' : '_ '}__arguments: JSArray<Any?>`].join(', ');
34
+ }
32
35
  // `this: void` only says the function reads no `this`: no parameter.
33
36
  return [
34
37
  ...receiver,