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

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 (135) hide show
  1. package/dist/api/ir.js +7 -1
  2. package/dist/driver/cli.js +2 -0
  3. package/dist/driver/compile.js +22 -10
  4. package/dist/driver/unimplemented.js +15 -0
  5. package/dist/kotlin/access.js +22 -4
  6. package/dist/kotlin/arguments.js +5 -0
  7. package/dist/kotlin/builtins.js +0 -4
  8. package/dist/kotlin/calls.js +6 -2
  9. package/dist/kotlin/class-methods.js +9 -3
  10. package/dist/kotlin/components.js +13 -8
  11. package/dist/kotlin/core-api.js +2 -13
  12. package/dist/kotlin/declarations.js +2 -0
  13. package/dist/kotlin/expression-statements.js +5 -4
  14. package/dist/kotlin/functions.js +13 -4
  15. package/dist/kotlin/global-calls.js +11 -0
  16. package/dist/kotlin/literals.js +51 -5
  17. package/dist/kotlin/names.js +2 -2
  18. package/dist/kotlin/native/api.js +9 -1
  19. package/dist/kotlin/native/subclasses.js +4 -3
  20. package/dist/kotlin/native/types.js +8 -5
  21. package/dist/kotlin/operators.js +4 -1
  22. package/dist/kotlin/prototype-calls.js +5 -0
  23. package/dist/kotlin/render.js +62 -0
  24. package/dist/kotlin/statements.js +9 -0
  25. package/dist/kotlin/static-calls.js +4 -3
  26. package/dist/kotlin/types.js +6 -6
  27. package/dist/plugins/native-android.js +7 -3
  28. package/dist/plugins/native-ios.js +2 -0
  29. package/dist/plugins/source.js +73 -23
  30. package/dist/program/app-modules.js +91 -16
  31. package/dist/program/app-paths.js +80 -12
  32. package/dist/program/class-mixins.js +463 -0
  33. package/dist/program/core-facts.js +7 -0
  34. package/dist/program/glob.js +274 -0
  35. package/dist/program/platform.js +32 -4
  36. package/dist/program/program.js +212 -20
  37. package/dist/program/source-lines.js +4 -1
  38. package/dist/program/vite-plugins.js +144 -0
  39. package/dist/semantics/apis/globals.js +2 -2
  40. package/dist/semantics/apis/object.js +1 -0
  41. package/dist/semantics/apis/statics.js +6 -0
  42. package/dist/semantics/ast.js +20 -2
  43. package/dist/semantics/classes.js +36 -1
  44. package/dist/semantics/globals.js +3 -0
  45. package/dist/semantics/lang.js +13 -1
  46. package/dist/semantics/nullish.js +29 -11
  47. package/dist/semantics/refuse-receivers.js +3 -3
  48. package/dist/semantics/refuse-scope.js +2 -7
  49. package/dist/semantics/runtime.js +1 -0
  50. package/dist/semantics/states/value-states.js +1 -1
  51. package/dist/semantics/throws.js +1 -0
  52. package/dist/semantics/translator-methods.js +1 -1
  53. package/dist/semantics/types.js +21 -1
  54. package/dist/swift/access.js +25 -10
  55. package/dist/swift/arguments.js +10 -2
  56. package/dist/swift/assignment.js +12 -1
  57. package/dist/swift/builtins.js +0 -4
  58. package/dist/swift/calls.js +6 -2
  59. package/dist/swift/class-methods.js +3 -3
  60. package/dist/swift/components.js +28 -8
  61. package/dist/swift/construction.js +4 -0
  62. package/dist/swift/core-api.js +9 -12
  63. package/dist/swift/functions.js +13 -2
  64. package/dist/swift/generics.js +5 -1
  65. package/dist/swift/global-calls.js +2 -0
  66. package/dist/swift/literals.js +53 -6
  67. package/dist/swift/names.js +1 -1
  68. package/dist/swift/native/sdk-tables.js +52 -4
  69. package/dist/swift/native/sdk.js +9 -1
  70. package/dist/swift/operators.js +4 -1
  71. package/dist/swift/parameters.js +5 -2
  72. package/dist/swift/placement.js +42 -1
  73. package/dist/swift/prototype-calls.js +17 -2
  74. package/dist/swift/render.js +64 -0
  75. package/dist/swift/results.js +1 -1
  76. package/dist/swift/statements.js +9 -0
  77. package/dist/swift/static-calls.js +8 -3
  78. package/dist/swift/types.js +9 -9
  79. package/dist/targets/android/build.js +13 -9
  80. package/dist/targets/ios/build.js +11 -10
  81. package/dist/targets/ios/dependencies.js +12 -0
  82. package/dist/targets/resources.js +15 -1
  83. package/dist/template/plan.js +105 -8
  84. package/dist/types/adapter-api.d.ts +13 -0
  85. package/dist/types/ir.d.ts +47 -0
  86. package/kit-android/generated/kotlin/org/nativescript/kit/__Objects.kt +102 -7485
  87. package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_view_view_common.kt +1 -3
  88. package/kit-android/generated/source-lines.json +1 -1
  89. package/kit-android/src/fromcore/kotlin/org/nativescript/kit/CoreBridge.kt +67 -1
  90. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Prototypes.kt +26 -0
  91. package/kit-apple/Overlays/xml-free/Core/ui.core.bindable.index.swift +4 -4
  92. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity1.swift +24 -146
  93. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity2.swift +0 -281
  94. 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
  95. package/kit-apple/Sources/NativeScriptKit/Core/__Namespace.Utils.swift +17 -15
  96. package/kit-apple/Sources/NativeScriptKit/Core/application-settings.index.ios.swift +8 -8
  97. package/kit-apple/Sources/NativeScriptKit/Core/application.application-common.swift +4 -4
  98. package/kit-apple/Sources/NativeScriptKit/Core/color.color-common.swift +7 -7
  99. package/kit-apple/Sources/NativeScriptKit/Core/http.http-request-internal.index.ios.swift +2 -1
  100. package/kit-apple/Sources/NativeScriptKit/Core/image-source.index.ios.swift +1 -1
  101. package/kit-apple/Sources/NativeScriptKit/Core/kit-index.json +34 -244
  102. package/kit-apple/Sources/NativeScriptKit/Core/manifest.json +1 -2
  103. package/kit-apple/Sources/NativeScriptKit/Core/ui.action-bar.index.ios.swift +3 -3
  104. package/kit-apple/Sources/NativeScriptKit/Core/ui.button.index.ios.swift +4 -4
  105. package/kit-apple/Sources/NativeScriptKit/Core/ui.content-view.index.swift +8 -8
  106. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.bindable.index.swift +4 -4
  107. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.index.ios.swift +8 -8
  108. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.view-common.swift +1 -3
  109. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.view-helper.view-helper-common.swift +7 -7
  110. package/kit-apple/Sources/NativeScriptKit/Core/ui.frame.index.ios.swift +4 -4
  111. package/kit-apple/Sources/NativeScriptKit/Core/ui.html-view.index.ios.swift +4 -4
  112. package/kit-apple/Sources/NativeScriptKit/Core/ui.image.image-common.swift +2 -2
  113. package/kit-apple/Sources/NativeScriptKit/Core/ui.image.index.ios.swift +4 -4
  114. package/kit-apple/Sources/NativeScriptKit/Core/ui.label.index.ios.swift +4 -4
  115. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.absolute-layout.index.ios.swift +4 -4
  116. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.dock-layout.index.ios.swift +4 -4
  117. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.flexbox-layout.index.ios.swift +3 -3
  118. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.grid-layout.index.ios.swift +4 -4
  119. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.stack-layout.index.ios.swift +4 -4
  120. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.wrap-layout.index.ios.swift +4 -4
  121. package/kit-apple/Sources/NativeScriptKit/Core/ui.list-view.index.ios.swift +3 -3
  122. package/kit-apple/Sources/NativeScriptKit/Core/ui.page.index.ios.swift +4 -4
  123. package/kit-apple/Sources/NativeScriptKit/Core/ui.repeater.index.swift +4 -4
  124. package/kit-apple/Sources/NativeScriptKit/Core/ui.scroll-view.index.ios.swift +4 -4
  125. package/kit-apple/Sources/NativeScriptKit/Core/ui.split-view.index.ios.swift +4 -4
  126. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.background.ios.swift +1 -1
  127. package/kit-apple/Sources/NativeScriptKit/Core/ui.tab-view.index.ios.swift +4 -4
  128. package/kit-apple/Sources/NativeScriptKit/Core/utils.common.swift +9 -9
  129. package/kit-apple/Sources/NativeScriptKit/Core/utils.layout-helper.index.ios.swift +10 -10
  130. package/kit-apple/Sources/NativeScriptKit/CoreBridge.swift +67 -1
  131. package/kit-apple/Sources/NativeScriptKit/Runtime/Lowering.swift +4 -0
  132. package/kit-apple/Sources/NativeScriptKit/Runtime/Prototypes.swift +25 -0
  133. package/kit-apple/Sources/NativeScriptKit/Runtime/RegExp.swift +6 -0
  134. package/package.json +1 -1
  135. package/kit-apple/Sources/NativeScriptKit/Core/Object_toString_charAt_charCodeAt_concat_indexOf_lastIndexOf_and_44_more_fc25df.swift +0 -481
@@ -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))
@@ -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
6
  import { holdsNil, literalNotes, signatureField, shapePlanOfLiteral, spelledOptional, 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))
@@ -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`,
@@ -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,
@@ -11,7 +11,7 @@ import { holdsNil, notedField, resultShapeNamed } from "../semantics/shapes.js";
11
11
  import { implementedInterfaces, literalKey, takesReceiver } from "../semantics/lang.js";
12
12
  import { slotOf } from "../semantics/trust.js";
13
13
  import { isCoreDeclaration } from "../program/core-facts.js";
14
- import { isStatic } from "../semantics/throws.js";
14
+ import { isAsync, isStatic } from "../semantics/throws.js";
15
15
  import { typedCollection } from "./native/bridging.js";
16
16
  import { isLibGlobal } from "../semantics/globals.js";
17
17
  import { literalClassOf } from "../semantics/classes.js";
@@ -897,4 +897,45 @@ export const placementMethods = {
897
897
  });
898
898
  return `{ () ${this.throwsInfo.expr(e) ? 'throws ' : ''}-> ${name} in ${[`let ${o} = ${name}(jsLiteral: ())`, ...steps, `return ${o}`].join('; ')} }()`;
899
899
  },
900
+ /** An object literal typed as an abstract/plugin class (`HlmPickerPanelRef`, `IconInfo`): a local subclass overriding its methods and fields. */
901
+ abstractClassLiteral(e, cls, name) {
902
+ const clsName = this.className(cls);
903
+ const implName = this.fresh('__Lit');
904
+ const clsType = this.checker.getDeclaredTypeOfSymbol(this.checker.getSymbolAtLocation(cls.name));
905
+ const ctorLines = [];
906
+ const methodLines = [];
907
+ const args = [];
908
+ const ctorParams = [];
909
+ for (const p of e.properties) {
910
+ if (!(ts.isPropertyAssignment(p) || ts.isShorthandPropertyAssignment(p) || ts.isMethodDeclaration(p))) {
911
+ throw this.error(p, `this member of an object literal of type ${name}`);
912
+ }
913
+ const key = literalKey(p.name, this.checker) ?? p.name.getText();
914
+ const m = cls.members.find((x) => ts.isMethodDeclaration(x) && x.name.getText() === key);
915
+ if (m) {
916
+ const sig = this.emittedSignature(m);
917
+ const throws = !isAsync(m) && this.throwsInfo.fn(m);
918
+ const fnType = `(${sig.params.map((x) => x.type).join(', ')}) ${throws ? 'throws ' : ''}-> ${sig.ret}`;
919
+ const fField = `__fn_${ident(key)}`;
920
+ const val = ts.isMethodDeclaration(p) ? `{ (${this.params(p, true)}) ${throws ? 'throws ' : ''}-> ${sig.ret} in${this.functionBody(p, sig.ret, this.indent).slice(1)}` : this.coerce(ts.isPropertyAssignment(p) ? p.initializer : p.name, fnType);
921
+ ctorParams.push(`_ ${fField}: @escaping ${fnType}`);
922
+ args.push(val);
923
+ const pDecls = sig.params.map((x, k) => `_ __a${k}: ${x.type}`).join(', ');
924
+ const pArgs = sig.params.map((_, k) => `__a${k}`).join(', ');
925
+ methodLines.push(`private let ${fField}: ${fnType}`);
926
+ methodLines.push(`override func ${ident(key)}(${pDecls})${throws ? ' throws' : ''}${sig.ret === 'Void' ? '' : ` -> ${sig.ret}`} { ${sig.ret === 'Void' ? '' : 'return '}${throws ? 'try ' : ''}${fField}(${pArgs}) }`);
927
+ ctorLines.push(`self.${fField} = ${fField}`);
928
+ continue;
929
+ }
930
+ const prop = clsType.getProperty(key)?.valueDeclaration;
931
+ const pt = prop && ts.isPropertyDeclaration(prop) ? this.typeOf(prop.name) : 'Any?';
932
+ const pVal = ts.isPropertyAssignment(p) ? p.initializer : p.name;
933
+ const param = `__p_${ident(key)}`;
934
+ ctorParams.push(`_ ${param}: ${pt}`);
935
+ args.push(this.coerce(pVal, pt));
936
+ ctorLines.push(`self.${ident(key)} = ${param}`);
937
+ }
938
+ const throws = this.throwsInfo.expr(e);
939
+ return `{ () ${throws ? 'throws ' : ''}-> ${clsName} in final class ${implName}: ${clsName} { nonisolated deinit {}; ${methodLines.join('; ')}; init(${ctorParams.join(', ')}) { ${ctorLines.join('; ')}; super.init() } }; return ${implName}(${args.join(', ')}) }()`;
940
+ },
900
941
  };
@@ -150,8 +150,21 @@ export const prototypeCallsMethods = {
150
150
  return this.convert(this.marks.tryCode(`${RT.jsCallMethod}(${[this.coerce(thisArg, 'Any?'), JSON.stringify(source.name.text), ...rest.map((x) => this.coerce(x, 'Any?'))].join(', ')})`), 'Any?', this.typeOf(e));
151
151
  }
152
152
  // A method taken from its object (`const f = obj.method`) stays bound to it in Swift: called with that object, it is the same call.
153
- if (source && ts.isPropertyAccessExpression(source) && !(thisArg && source.expression.getText() === thisArg.getText()))
154
- throw this.error(e, `${method} of a method taken from its object, with another receiver`);
153
+ const sourceExpr = source && ts.isPropertyAccessExpression(source) ? ts.skipOuterExpressions(source.expression) : undefined;
154
+ const dynamicReceiverCall = () => {
155
+ const call = this.marks.tryCode(`${RT.jsCallValue}(${this.coerce(target, 'Any?')}, this: ${thisArg ? this.coerce(thisArg, 'Any?') : 'nil'}, optional: ${!!e.questionDotToken || (ts.isPropertyAccessExpression(e.expression) && !!e.expression.questionDotToken)}, [${rest.map((x) => this.coerce(x, 'Any?')).join(', ')}])`);
156
+ const rt = this.typeOf(e);
157
+ return rt === 'Void' || isUntyped(spelledType(rt)) ? call : this.fromAnyCode(call, rt, true);
158
+ };
159
+ const isDescriptorMember = (d) => !!d && ts.isInterfaceDeclaration(d.parent) && d.parent.name.text === 'PropertyDescriptor';
160
+ if (source && ts.isPropertyAccessExpression(source)) {
161
+ const srcDecl = this.resolve(source.name)?.declarations?.[0];
162
+ const fromPrototype = !!sourceExpr && ts.isPropertyAccessExpression(sourceExpr) && sourceExpr.name.text === 'prototype';
163
+ if (method === 'call' && (isDescriptorMember(srcDecl) || fromPrototype))
164
+ return dynamicReceiverCall();
165
+ if (!(thisArg && sourceExpr.getText() === thisArg.getText()))
166
+ throw this.error(e, `${method} of a method taken from its object, with another receiver`);
167
+ }
155
168
  const plain = (x) => x.kind === ts.SyntaxKind.ThisKeyword || ts.isIdentifier(x) || (ts.isPropertyAccessExpression(x) ? plain(x.expression) : this.pure(x));
156
169
  let held = target;
157
170
  // `(ctx.fillText as (text: string, x: number, y: number) => void).call(ctx, …)`: the method itself, with its own signature.
@@ -159,6 +172,8 @@ export const prototypeCallsMethods = {
159
172
  held = held.expression;
160
173
  const sym = ts.isPropertyAccessExpression(held) || ts.isIdentifier(held) ? this.resolve(ts.isPropertyAccessExpression(held) ? held.name : held) : undefined;
161
174
  const decl = sym?.declarations?.find((d) => (ts.isMethodDeclaration(d) || ts.isFunctionDeclaration(d)) && !!d.body) ?? sym?.valueDeclaration;
175
+ if (method === 'call' && isDescriptorMember(decl))
176
+ return dynamicReceiverCall();
162
177
  const bound = !!decl && (ts.isMethodDeclaration(decl) || ts.isMethodSignature(decl) || (ts.isFunctionDeclaration(decl) && thisNodes(decl).length > 0));
163
178
  const kitCall = this.kitPrototypeCall(held, e, method);
164
179
  if (kitCall)
@@ -183,6 +183,68 @@ export function render(c, components, throws = () => false, behaviour = DEFAULT_
183
183
  return say(depth, s.detached ? `let ${s.name} = Region(host: nil)` : `let ${s.name} = ${s.parent}.kitAddRegion()`);
184
184
  case 'addRegion':
185
185
  return say(depth, `${s.parent}.kitAddRegion(${s.region})`);
186
+ case 'setSlot': {
187
+ say(depth, `${s.component}.__slots[${swiftString(s.name)}] = { (__sr: Region) throws -> Void in`);
188
+ const wrap = s.scope ? scope(s.scope, 'Void') : null;
189
+ const d = wrap ? depth + 2 : depth + 1;
190
+ if (wrap)
191
+ say(depth + 1, wrap);
192
+ if (s.viewMark)
193
+ say(d, 'let __view = EffectOrder.current');
194
+ say(d, `let ${s.body.fragment} = RegionFragment(__sr)`);
195
+ steps(s.body.steps, d);
196
+ say(d, `__sr.set(parts: ${s.body.fragment}.parts)`);
197
+ if (wrap)
198
+ say(depth + 1, '}');
199
+ return say(depth, '}');
200
+ }
201
+ case 'slot': {
202
+ const host = regionHost(s.host);
203
+ if (s.fallback) {
204
+ say(depth, `if let __slot = self.__slots[${swiftString(s.name)}] {`);
205
+ say(depth + 1, `try __slot(${host})`);
206
+ say(depth, '} else {');
207
+ say(depth + 1, `let ${s.fallback.fragment} = RegionFragment(${host})`);
208
+ steps(s.fallback.steps, depth + 1);
209
+ say(depth + 1, `${host}.set(parts: ${s.fallback.fragment}.parts)`);
210
+ return say(depth, '}');
211
+ }
212
+ return say(depth, `if let __slot = self.__slots[${swiftString(s.name)}] { try __slot(${host}) }`);
213
+ }
214
+ case 'componentOutlet': {
215
+ const host = regionHost(s.host);
216
+ const inj = s.injector ? `, injector: { ${call(s.injector)} }` : '';
217
+ const inp = s.inputs ? `, inputs: { ${call(s.inputs)} }` : '';
218
+ return say(depth, `${s.call}(${host}, component: { ${call(s.component)} }${inj}${inp})`);
219
+ }
220
+ case 'templateOutlet': {
221
+ const host = regionHost(s.host);
222
+ const ctx = s.context ? `, context: { ${call(s.context)} }` : '';
223
+ return say(depth, `${s.call}(${host}, template: { ${call(s.template)} }${ctx})`);
224
+ }
225
+ case 'bindTemplate':
226
+ case 'structural': {
227
+ const open = s.kind === 'bindTemplate' ? `TemplateOutlet.bind(self.${ident(s.field)})` : `let ${s.tplName} = TemplateOutlet.make`;
228
+ say(depth, `${open} { (__sr: Region, ${s.ctxParam}: Any?) throws -> Void in`);
229
+ const wrap = s.scope ? scope(s.scope, 'Void') : null;
230
+ const d = wrap ? depth + 2 : depth + 1;
231
+ if (wrap)
232
+ say(depth + 1, wrap);
233
+ if (s.viewMark)
234
+ say(d, 'let __view = EffectOrder.current');
235
+ say(d, `let ${s.body.fragment} = RegionFragment(__sr)`);
236
+ steps(s.body.steps, d);
237
+ say(d, `__sr.set(parts: ${s.body.fragment}.parts)`);
238
+ if (wrap)
239
+ say(depth + 1, '}');
240
+ say(depth, '}');
241
+ if (s.kind === 'structural') {
242
+ say(depth, `try ${s.call}(${s.region}, ${s.tplName}) {`);
243
+ steps(s.steps, depth + 1);
244
+ say(depth, '}');
245
+ }
246
+ return;
247
+ }
186
248
  case 'choose': {
187
249
  const host = regionHost(s.host);
188
250
  const which = s.conds.map((k, i) => (k ? `${cond(k, s.caught)} ? ${i} : ` : `${i}`)).join('') + (s.conds.at(-1) ? `${s.conds.length}` : '');
@@ -286,6 +348,8 @@ export function render(c, components, throws = () => false, behaviour = DEFAULT_
286
348
  };
287
349
  const passes = plan.passes;
288
350
  const m = plan.members;
351
+ if (plan.hasSlots)
352
+ say(1, 'var __slots: [String: (Region) throws -> Void] = [:]');
289
353
  if (passes) {
290
354
  // Both passes, with the hooks a parent runs for its child between and after them.
291
355
  const hooks = (list) => list.map((h) => (h.flush ? `${h.flush}(for: self)` : h.every ? `${h.every} { self.${h.member}() }` : `self.${h.member}()`)).join('; ');
@@ -39,7 +39,7 @@ export const resultsMethods = {
39
39
  const cls = fn.parent;
40
40
  if (!cls || !ts.isClassLike(cls))
41
41
  return false;
42
- for (let t = this.checker.getTypeAtLocation(cls); t;) {
42
+ for (let t = this.checker.getTypeAtLocation(cls); t?.isClassOrInterface();) {
43
43
  const base = this.checker.getBaseTypes(t)[0];
44
44
  if (!base)
45
45
  return false;
@@ -361,6 +361,15 @@ export const statementsMethods = {
361
361
  });
362
362
  }
363
363
  if (ts.isForInStatement(s)) {
364
+ if (!ts.isVariableDeclarationList(s.initializer)) {
365
+ const k = this.fresh('__key');
366
+ const lines = this.assignIterated(s.initializer, k, this.checker.getStringType(), s.expression);
367
+ return this.loopBody(() => {
368
+ const label = this.takeLabel();
369
+ const body = this.block(s.statement);
370
+ return `${i}${label}for ${k} in ${this.tryPrefix(s.expression)}${RT.jsKeysOf}(${this.expr(s.expression)}) {\n${lines.map((l) => `${i} ${l}`).join('\n')}\n${body.slice(2)}`;
371
+ });
372
+ }
364
373
  const list = s.initializer;
365
374
  const name = ident(list.declarations[0].name.text);
366
375
  const mutable = assignsTo(s.statement, this.checker.getSymbolAtLocation(list.declarations[0].name), this.checker) ? 'var ' : '';
@@ -3,6 +3,7 @@ import ts from 'typescript';
3
3
  import { TYPED_ARRAYS } from "../semantics/globals.js";
4
4
  import { ident, isFunctionType, optionalType, swiftString, RT } from "./syntax.js";
5
5
  import { literalKey, statementLevel, undefinedLiteral } from "../semantics/lang.js";
6
+ import { arrayFromLengthInit } from "../semantics/ast.js";
6
7
  import { assignsArrayIntoObject, definesDuringConstruction, restrictsField, definedField } from "../semantics/shapes.js";
7
8
  import { CONSOLE } from "../semantics/apis/console.js";
8
9
  import { staticFunction } from "../semantics/apis/statics.js";
@@ -115,9 +116,9 @@ export const staticCallsMethods = {
115
116
  if (method === 'from' && e.arguments.length === 1)
116
117
  return `${T()}.from(${this.iterable(arg(0))})`;
117
118
  if (method === 'from' && (e.arguments.length === 2 || e.arguments.length === 3) && ts.isObjectLiteralExpression(arg(0))) {
118
- const length = arg(0).properties.find((p) => p.name?.getText() === 'length');
119
+ const lenInit = arrayFromLengthInit(arg(0));
119
120
  const fn = arg(1);
120
- if (!length || !ts.isPropertyAssignment(length) || !(ts.isArrowFunction(fn) || ts.isFunctionExpression(fn)))
121
+ if (!lenInit || !(ts.isArrowFunction(fn) || ts.isFunctionExpression(fn)))
121
122
  throw this.error(e, 'Array.from of this object');
122
123
  const el = T().replace(/^JSArray<(.*)>$/, '$1');
123
124
  const params = fn.parameters.filter((p) => !(ts.isIdentifier(p.name) && p.name.text === 'this'));
@@ -125,7 +126,7 @@ export const staticCallsMethods = {
125
126
  const value = params[0] && ts.isIdentifier(params[0].name) && params[0].name.text !== '_' ? `let ${ident(params[0].name.text)}: Any? = nil; ` : '';
126
127
  return this.ignoringThisArg(e, arg(0), () => {
127
128
  const body = ts.isBlock(fn.body) ? this.functionBody(fn, el, this.indent).slice(1, -1) : ` return ${this.marks.tryBefore(this.tryPrefix(fn.body), this.coerce(fn.body, el))} `;
128
- return `${T()}.from(length: ${this.expr(length.initializer)}) { (${index}: Double) ${this.throwsInfo.fn(fn) ? 'throws ' : ''}-> ${el} in ${value}${body}}`;
129
+ return `${T()}.from(length: ${this.expr(lenInit)}) { (${index}: Double) ${this.throwsInfo.fn(fn) ? 'throws ' : ''}-> ${el} in ${value}${body}}`;
129
130
  });
130
131
  }
131
132
  if (method === 'from' && (e.arguments.length === 2 || e.arguments.length === 3))
@@ -165,6 +166,10 @@ export const staticCallsMethods = {
165
166
  return `${RT.jsFromCharCode}(codes: ${this.packed(e.arguments, 'JSArray<Double>')}.storage)`;
166
167
  if (method === 'fromCharCode')
167
168
  return `${RT.jsFromCharCode}(${a().join(', ')})`;
169
+ if (method === 'fromCodePoint' && e.arguments.some(ts.isSpreadElement))
170
+ return `${RT.jsFromCodePoint}(codes: ${this.packed(e.arguments, 'JSArray<Double>')}.storage)`;
171
+ if (method === 'fromCodePoint')
172
+ return `${RT.jsFromCodePoint}(${e.arguments.map((x) => this.restArgument(e, x, 'Double')).join(', ')})`;
168
173
  break;
169
174
  case 'BigInt':
170
175
  if (method === 'asIntN' || method === 'asUintN')