@nstudio/nativescript-compiler 9.2.0-alpha.15 → 9.2.0-alpha.17

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 (71) hide show
  1. package/dist/kit/kit-index.js +9 -0
  2. package/dist/kotlin/access.js +7 -9
  3. package/dist/kotlin/arguments.js +2 -2
  4. package/dist/kotlin/class-accessors.js +1 -1
  5. package/dist/kotlin/class-declaration.js +23 -2
  6. package/dist/kotlin/class-methods.js +21 -11
  7. package/dist/kotlin/components.js +2 -7
  8. package/dist/kotlin/core-api.js +2 -21
  9. package/dist/kotlin/declarations.js +86 -9
  10. package/dist/kotlin/functions.js +1 -4
  11. package/dist/kotlin/global-calls.js +1 -4
  12. package/dist/kotlin/literals.js +3 -6
  13. package/dist/kotlin/names.js +2 -0
  14. package/dist/kotlin/native/classfiles.js +2 -13
  15. package/dist/kotlin/operators.js +12 -6
  16. package/dist/kotlin/optional-chains.js +2 -9
  17. package/dist/kotlin/overrides.js +3 -15
  18. package/dist/kotlin/placement.js +1 -12
  19. package/dist/kotlin/statements.js +1 -13
  20. package/dist/kotlin/translator.js +2 -10
  21. package/dist/kotlin/type-tests.js +1 -1
  22. package/dist/kotlin/types.js +2 -19
  23. package/dist/program/core-facts.js +9 -0
  24. package/dist/semantics/facts.js +37 -1
  25. package/dist/semantics/forms/by-name.js +18 -4
  26. package/dist/semantics/lang.js +36 -1
  27. package/dist/semantics/lower.js +90 -0
  28. package/dist/semantics/lowering-methods.js +115 -3
  29. package/dist/semantics/marks.js +30 -0
  30. package/dist/semantics/refusals.js +12 -11
  31. package/dist/semantics/tdz.js +103 -8
  32. package/dist/swift/access.js +6 -8
  33. package/dist/swift/assignment.js +10 -2
  34. package/dist/swift/calls.js +7 -2
  35. package/dist/swift/class-accessors.js +1 -1
  36. package/dist/swift/class-declaration.js +3 -2
  37. package/dist/swift/class-methods.js +16 -1
  38. package/dist/swift/classes.js +23 -9
  39. package/dist/swift/components.js +0 -4
  40. package/dist/swift/core-api.js +9 -29
  41. package/dist/swift/declarations.js +0 -5
  42. package/dist/swift/expression-statements.js +7 -0
  43. package/dist/swift/global-calls.js +0 -4
  44. package/dist/swift/lenient.js +3 -5
  45. package/dist/swift/method-values.js +1 -19
  46. package/dist/swift/modules.js +2 -0
  47. package/dist/swift/names.js +0 -9
  48. package/dist/swift/native/api.js +3 -1
  49. package/dist/swift/native/dispatch.js +2 -8
  50. package/dist/swift/operators.js +7 -6
  51. package/dist/swift/optional-chains.js +1 -8
  52. package/dist/swift/parameters.js +0 -4
  53. package/dist/swift/placement.js +7 -12
  54. package/dist/swift/protocols.js +25 -4
  55. package/dist/swift/results.js +0 -4
  56. package/dist/swift/statements.js +1 -13
  57. package/dist/swift/translator.js +0 -10
  58. package/dist/types/adapter-api.d.ts +3 -3
  59. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Array.kt +53 -12
  60. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/JSON.kt +30 -4
  61. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Language.kt +33 -0
  62. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Prototypes.kt +9 -1
  63. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Values.kt +137 -28
  64. package/kit-apple/Sources/NativeScriptKit/Core/color.color-common.swift +17 -0
  65. package/kit-apple/Sources/NativeScriptKit/Core/color.index.ios.swift +60 -0
  66. package/kit-apple/Sources/NativeScriptKit/Core/js-libs.easysax.easysax.swift +24 -6
  67. package/kit-apple/Sources/NativeScriptKit/Core/kit-index.json +3 -3
  68. package/kit-apple/Sources/NativeScriptKit/Core/ui.gestures.gestures-common.swift +2 -0
  69. package/kit-apple/Sources/NativeScriptKit/Runtime/JSON.swift +151 -82
  70. package/kit-apple/Sources/NativeScriptKit/Runtime/Prototypes.swift +13 -1
  71. package/package.json +1 -1
@@ -86,6 +86,15 @@ export class KitTypes {
86
86
  isKitView(name) {
87
87
  return kitExtends(this.index, name, 'View');
88
88
  }
89
+ /** Whether the kit applies `name` by name on this view class (a property in its setProperty). */
90
+ isViewProperty(owner, name) {
91
+ if (owner === 'Style')
92
+ return [...this.index.values()].some((t) => kitExtends(this.index, t.name, 'View') && t.props.has(name));
93
+ for (let t = this.index.get(owner); t; t = t.base ? this.index.get(t.base.replace(/\(.*$/, '')) : undefined)
94
+ if (t.props.has(name))
95
+ return true;
96
+ return false;
97
+ }
89
98
  /** A view, or a view's `style`: properties by name. */
90
99
  isView(owner) {
91
100
  return owner === 'Style' || kitExtends(this.index, owner, 'View');
@@ -10,7 +10,7 @@ import { CONSOLE } from "../semantics/apis/console.js";
10
10
  import { libFunctionValueKind } from "../semantics/apis/statics.js";
11
11
  import { ERRORS, isLibGlobal } from "../semantics/globals.js";
12
12
  import { spell, ident, isCompared, isNullable, isThisParameter, kotlinString, numberLiteral, optionalType, testsMissing, scriptPrimitive, RT, assertedReader } from "./syntax.js";
13
- import { observerSlot, place, receiverCell, receiverSlot, isEnumObject, nullishField } from "../semantics/placement.js";
13
+ import { receiverCell, receiverSlot, isEnumObject, nullishField } from "../semantics/placement.js";
14
14
  import { accessedDeclaration, augmentedPropertyRead, functionProperty, wellKnownMember, isSelf, literalMethod, uncheckedMatch } from "../semantics/lang.js";
15
15
  import { convertedRead, onlyNull } from "../semantics/states/predicates.js";
16
16
  import { isLibDeclaration, isWriteTarget, notIterable } from "../semantics/ast.js";
@@ -247,6 +247,8 @@ export const accessMethods = {
247
247
  return ((base.endsWith('?') || held) && !proven && !e.questionDotToken && !inChain && !isSelf(target, this.subst)) || this.isAsserted(code) ? this.present(code, name, target, isWriteTarget(e)) : code;
248
248
  };
249
249
  if (name === 'length' && this.isString(target)) {
250
+ if (!e.questionDotToken && !inChain && ts.isIdentifier(target) && this.stringBuilders.has(this.resolve(target)))
251
+ return `${ident(target.text)}.length.toDouble()`;
250
252
  return e.questionDotToken || inChain ? `${this.expr(target)}?.length?.toDouble()` : `${recv()}.length.toDouble()`;
251
253
  }
252
254
  if (name === 'length' && (base.startsWith('Pair<') || base.startsWith('Triple<')))
@@ -321,7 +323,7 @@ export const accessMethods = {
321
323
  const describedClass = this.library && symbol?.valueDeclaration?.getSourceFile().isDeclarationFile && !isLibDeclaration(symbol.valueDeclaration) && !this.native?.isNativeDeclaration(symbol.valueDeclaration) ? this.compiledClasses().get(this.checker.getNonNullableType(this.checker.getTypeAtLocation(target)).getSymbol()?.name ?? '') : undefined;
322
324
  // Library mode: a member TypeScript does not find on the type (lenient code reading what the type omits): read by name.
323
325
  const unknown = this.library && !symbol && !e.name.text.startsWith('#') && this.isObjectRef(target);
324
- if (((describedClass && !this.compiledMember(describedClass, name)) || unknown) && !(ts.isCallExpression(e.parent) && e.parent.expression === e && !e.parent.questionDotToken)) {
326
+ if (((describedClass && !this.declaresCompiledMember(describedClass, name)) || unknown) && !(ts.isCallExpression(e.parent) && e.parent.expression === e && !e.parent.questionDotToken)) {
325
327
  const t = this.typeOf(e);
326
328
  const code = `${e.questionDotToken || inChain ? RT.jsGetIfPresent : RT.jsGet}(${this.expr(target)}, ${kotlinString(name)})`;
327
329
  // Called (`x.callback?.(…)`): the function as script holds it, which the call reads.
@@ -350,7 +352,7 @@ export const accessMethods = {
350
352
  const plain = `${receiver}${dot}${ident(name)}`;
351
353
  const read = dot === '.' ? this.marks.marked(plain, { op: 'member', of: this.marks.valueOf(receiver), name }) : plain;
352
354
  // A non-strict app's optional member is held optional though its type says present: a value read reads its undefined.
353
- if ((this.optionalMember(e) || (!e.questionDotToken && !(e.flags & ts.NodeFlags.OptionalChain) && !!symbol && this.states.shapeFieldOptional(symbol))) && !isWriteTarget(e) && !this.nullOk.has(e) && ['String', 'Double', 'Boolean'].includes(this.typeOf(e)))
355
+ if ((this.isLenientOptionalMember(e) || (!e.questionDotToken && !(e.flags & ts.NodeFlags.OptionalChain) && !!symbol && this.states.shapeFieldOptional(symbol))) && !isWriteTarget(e) && !this.nullOk.has(e) && ['String', 'Double', 'Boolean'].includes(this.typeOf(e)))
354
356
  return this.undefinedAs(read, this.typeOf(e));
355
357
  return this.narrowed(e, read);
356
358
  },
@@ -425,7 +427,7 @@ export const accessMethods = {
425
427
  if (ts.isPropertyAccessExpression(x) && this.library && this.resolve(x.name)?.declarations?.some((d) => ts.isPropertySignature(d) && !isLibDeclaration(d)))
426
428
  return null;
427
429
  if (ts.isPropertyAccessExpression(x)) {
428
- if (!(this.optionalMember(x) || (!this.typeOf(x).endsWith('?') && !!this.declaredTypeOf(x)?.endsWith('?'))))
430
+ if (!(this.isLenientOptionalMember(x) || (!this.typeOf(x).endsWith('?') && !!this.declaredTypeOf(x)?.endsWith('?'))))
429
431
  return null;
430
432
  return this.isExpando(x) ? this.fromAny(`${RT.jsGet}(${this.expr(x.expression)}, ${kotlinString(x.name.text)})`, optionalType(this.typeOf(x))) : `${this.expr(x.expression)}.${ident(x.name.text)}`;
431
433
  }
@@ -464,7 +466,7 @@ export const accessMethods = {
464
466
  return ['String', 'Double', 'Boolean'].includes(t) ? this.fromAny(`${RT.jsGet}(${this.expr(x.expression)}, ${kotlinString(x.name.text)})`, optionalType(t)) : null;
465
467
  },
466
468
  /** A non-strict app's read of an object type's optional member (`o.a`, `a?: string`), which Kotlin holds optional. */
467
- optionalMember(x) {
469
+ isLenientOptionalMember(x) {
468
470
  if (!this.lenientApp || this.library || x.questionDotToken || x.flags & ts.NodeFlags.OptionalChain || this.typeOf(x).endsWith('?'))
469
471
  return false;
470
472
  const d = this.resolve(x.name)?.valueDeclaration;
@@ -630,10 +632,6 @@ export const accessMethods = {
630
632
  const holder = ts.findAncestor(e.parent, (p) => !ts.isParenthesizedExpression(p));
631
633
  return holder && ts.isVariableDeclaration(holder) ? this.widerAsserted(holder) : null;
632
634
  },
633
- /** `x` read by an equality or `typeof` (`ObserverSlot`). */
634
- observe(x, read = 'untyped') {
635
- return place(this.placement, x, observerSlot(this.placement, read));
636
- },
637
635
  /**
638
636
  * A read `observedAsIs` (an identity operand, `instanceof`'s left): the nullable it may be, never asserted present.
639
637
  * Library mode reads an untyped value as it is held: `maybeUndefined` would cast it to the declared type.
@@ -91,7 +91,7 @@ export const argumentsMethods = {
91
91
  return (isUntyped(spelledType(pt)) && this.untypedArrow(a)) || null;
92
92
  },
93
93
  /** A function held in a variable, parameter or field (an overloaded method's implementation bound): a Kotlin function type, which has no defaults. */
94
- heldFunction(callee) {
94
+ isHeldFunctionValue(callee) {
95
95
  const name = ts.isPropertyAccessExpression(callee) ? callee.name : ts.isIdentifier(callee) ? callee : null;
96
96
  const d = name && this.checker.getSymbolAtLocation(name)?.valueDeclaration;
97
97
  return !!d && !d.getSourceFile().isDeclarationFile && (ts.isVariableDeclaration(d) || ts.isParameter(d) || ts.isPropertyDeclaration(d));
@@ -157,7 +157,7 @@ export const argumentsMethods = {
157
157
  out.push(`${this.restType(params[restAt])}()`);
158
158
  const decl = sig?.getDeclaration();
159
159
  // A function value takes every parameter; a plugin's call (its code unchecked) may leave out one the callee requires.
160
- const missing = count !== undefined || restAt >= 0 || !decl || ts.isJSDocSignature(decl) ? undefined : ts.isFunctionTypeNode(decl) || ts.isCallSignatureDeclaration(decl) || ts.isArrowFunction(decl) || ts.isFunctionExpression(decl) || (ts.isCallExpression(e) && this.heldFunction(e.expression)) ? 'empty' : !this.library && this.inPluginFile(e) ? 'undefined' : undefined;
160
+ const missing = count !== undefined || restAt >= 0 || !decl || ts.isJSDocSignature(decl) ? undefined : ts.isFunctionTypeNode(decl) || ts.isCallSignatureDeclaration(decl) || ts.isArrowFunction(decl) || ts.isFunctionExpression(decl) || (ts.isCallExpression(e) && this.isHeldFunctionValue(e.expression)) ? 'empty' : !this.library && this.inPluginFile(e) ? 'undefined' : undefined;
161
161
  for (let k = covered; missing && k < params.length; k++) {
162
162
  const s = this.missingSlot(e, params[k], k, missing);
163
163
  if (!s)
@@ -93,7 +93,7 @@ export const classAccessorsMethods = {
93
93
  target.push(`${pad}${this.accessorJvmNames(cls, n, !!a.set || getterOnly, mod)}${mod}${a.set || getterOnly ? 'var' : 'val'} ${ident(n)}: ${t}`, ...parts);
94
94
  // Library mode: read and set by name as well (`node.cssType` of an untyped node), as the prototype's accessor is.
95
95
  const own = (a.get ?? a.set);
96
- if ((this.library || byName || this.membersByName(cls) || this.states.downcastClass(cls) || this.states.byNameClass(cls)) && !isStatic(own) && !ts.isPrivateIdentifier(own.name) && !this.symbolMember(own.name) && (this.memberByName(cls, n) || this.states.byNameMember(cls, n))) {
96
+ if ((this.library || byName || k.droppedProtocolMembers.has(n) || this.membersByName(cls) || this.states.downcastClass(cls) || this.states.byNameClass(cls)) && !isStatic(own) && !ts.isPrivateIdentifier(own.name) && !this.symbolMember(own.name) && (k.droppedProtocolMembers.has(n) || this.memberByName(cls, n) || this.states.byNameMember(cls, n))) {
97
97
  // A write by name gives the setter what script gave (`style="color: red"` and `color="red"` from the Builder); one
98
98
  // passing it to another object's member (`this.style.color = value`) passes it on by name, as that member converts it.
99
99
  const forwarded = a.set && !takes ? forwardedSetter(a.set) : null;
@@ -5,7 +5,7 @@ import ts from 'typescript';
5
5
  import { ERRORS } from "../semantics/globals.js";
6
6
  import { OBJECT_TO_STRING, ident, kotlinString, lambda, optionalType, RT } from "./syntax.js";
7
7
  import { UNKEYED, isPropertyField, memberPlanOf, notesNull, nullNames, definedNamesOf } from "../semantics/shapes.js";
8
- import { implementedInterfaces, initializedNull } from "../semantics/lang.js";
8
+ import { droppedProtocolMemberNames, implementedInterfaces, initializedNull } from "../semantics/lang.js";
9
9
  import { hasModifier } from "../semantics/ast.js";
10
10
  import { isStatic } from "../semantics/throws.js";
11
11
  import { isCoreDeclaration, isShimDeclaration } from "../program/core-facts.js";
@@ -68,6 +68,7 @@ export const classDeclMethods = {
68
68
  this.cssTypeMemberCode(k);
69
69
  this.classDecoratorsCode(k);
70
70
  this.staticsByNameCode(k);
71
+ this.prototypeMethodsCode(k);
71
72
  this.computedMethodsCode(k);
72
73
  this.methodMembersCode(k);
73
74
  this.ownPropertiesCode(k);
@@ -122,6 +123,7 @@ export const classDeclMethods = {
122
123
  const witnesses = [];
123
124
  const notOverrides = new Set();
124
125
  const implemented = this.implementedProtocols(cls, witnesses, notOverrides);
126
+ const droppedProtocolMembers = droppedProtocolMemberNames(c, cls, this.protocols, implemented, (i) => this.implementedName(i), (i, t, n) => this.untranslatedInterface(i) || this.declaredOnlyInterface(i) || (!!this.library && (t.getSymbol()?.declarations ?? []).every((d) => d.getSourceFile().isDeclarationFile)) || this.declaresInterface(c.getTypeAtLocation(cls.name ?? cls), n));
125
127
  for (const i of implemented)
126
128
  this.used.add(i);
127
129
  const ownToString = layout.toString;
@@ -160,7 +162,7 @@ export const classDeclMethods = {
160
162
  // An app class extending the generated kit's (a page's view model, a custom view): read by name as core reads it (bindings, the Builder).
161
163
  const byName = !this.library && ((this.generatedKit && !!kitRoot) || this.appMembersByName);
162
164
  const literalMade = ts.isClassDeclaration(cls) && this.literalMade(cls);
163
- return { cls, name, layout, plugin, appBase, base, kitRoot, collection, isError, isView, abstract, open, memberOpen, expando, witnesses, overridden, interfaceFields, byName, literalMade, supertypes, lines: [], statics: [], fields: [], narrowedParams: new Map(), initsAfterParamProps: [], symbolFields: [], symbolKeyInits: [], symKeyCount: 0, fieldStarts: [], dynAccessors: [], dynMethods: [] };
165
+ return { cls, name, layout, plugin, appBase, base, kitRoot, collection, isError, isView, abstract, open, memberOpen, expando, witnesses, overridden, interfaceFields, droppedProtocolMembers, byName, literalMade, supertypes, lines: [], statics: [], fields: [], narrowedParams: new Map(), initsAfterParamProps: [], symbolFields: [], symbolKeyInits: [], symKeyCount: 0, fieldStarts: [], dynAccessors: [], dynMethods: [] };
164
166
  },
165
167
  /** Evaluates a non-fixed computed symbol key once at class definition time into a companion property. */
166
168
  capturedSymbolKey(k, keyCode) {
@@ -238,6 +240,25 @@ export const classDeclMethods = {
238
240
  this.staticInits.push(` JSPrototypes.declareStatics(${owner}::class.java, listOf(${entries.join(', ')}))`);
239
241
  }
240
242
  },
243
+ prototypeMethodsCode(k) {
244
+ const { cls, name } = k;
245
+ if (this.library || !this.staticInits || !ts.isClassDeclaration(cls) || !this.facts.prototypeClasses().has(cls) || cls.typeParameters?.length)
246
+ return;
247
+ const owner = name.replace(/<.*$/, '');
248
+ const seen = new Set();
249
+ for (const m of cls.members) {
250
+ if (!ts.isMethodDeclaration(m) || !m.body || isStatic(m) || ts.isPrivateIdentifier(m.name) || ts.isComputedPropertyName(m.name) || m.typeParameters?.length || m.asteriskToken || m.parameters.some((p) => p.dotDotDotToken || (ts.isIdentifier(p.name) && p.name.text === 'this')) || this.readsArguments(m))
251
+ continue;
252
+ const key = m.name.getText().replace(/^['"]|['"]$/g, '');
253
+ if (seen.has(key))
254
+ continue;
255
+ seen.add(key);
256
+ const args = m.parameters.map((p, idx) => this.fromAnyCode(this.marks.pureCode(`__a.getOrNull(${idx})`), this.paramType(p), true));
257
+ const call = `__o.${this.methodIdent(key)}(${args.join(', ')})`;
258
+ const body = this.returnTypeOf(m) === 'Unit' ? `${call}; null` : call;
259
+ this.staticInits.push(` JSPrototypes.of(${owner}::class.java).defineProperty(${kotlinString(key)}, JSPropertyDescriptor(value = JSMethod(${m.parameters.length}) { __this, __a -> val __o = ${RT.jsBox}(__this) as? ${owner} ?: throw JSException(JSTypeError("Illegal invocation")); ${body} }, hasValue = true, enumerable = false, writable = true, configurable = true))`);
260
+ }
261
+ },
241
262
  ownPropertiesCode(k) {
242
263
  if (k.isView && !this.generatedKit) {
243
264
  const own = k.fields.filter(isPropertyField).map((f) => f.name);
@@ -197,29 +197,39 @@ export const classMethodsMethods = {
197
197
  return false;
198
198
  },
199
199
  methodsByNameCode(k) {
200
- const { cls, plugin, kitRoot, byName, dynMethods } = k;
200
+ const { cls, plugin, kitRoot, byName, droppedProtocolMembers, dynMethods } = k;
201
201
  const { inherited } = k.layout;
202
202
  // Library mode: every method of the class is read by name as well (`font.getAndroidTypeface()` on an untyped font), overrides included.
203
- if (this.library || byName || this.membersByName(cls) || this.states.downcastClass(cls) || this.states.byNameClass(cls)) {
204
- for (const m of cls.members) {
205
- if (!ts.isMethodDeclaration(m) || !m.body || isStatic(m) || ts.isComputedPropertyName(m.name) || ts.isPrivateIdentifier(m.name) || m.parameters.some((p) => p.dotDotDotToken) || this.readsArguments(m))
206
- continue;
203
+ if (this.library || byName || droppedProtocolMembers.size > 0 || this.membersByName(cls) || this.states.downcastClass(cls) || this.states.byNameClass(cls)) {
204
+ const addMethod = (m) => {
205
+ if (!m.body || isStatic(m) || ts.isComputedPropertyName(m.name) || ts.isPrivateIdentifier(m.name) || m.parameters.some((p) => p.dotDotDotToken) || this.readsArguments(m))
206
+ return;
207
207
  const n = m.name.getText();
208
208
  if (dynMethods.some((d) => d.name === n && !d.key) || n === 'toString' || n === 'equals')
209
- continue;
210
- if (!this.memberByName(cls, n) && !this.states.byNameMember(cls, n))
211
- continue;
209
+ return;
210
+ if (!droppedProtocolMembers.has(n) && !this.memberByName(cls, n) && !this.states.byNameMember(cls, n))
211
+ return;
212
212
  // A plugin's method nothing names is not compiled; one overriding the kit's is read through the kit's own table.
213
213
  if (plugin && !this.library && !inherited.has(n) && !(kitRoot && this.core?.kitMember(kitRoot, n)) && !this.facts.isNamed(n))
214
- continue;
214
+ return;
215
215
  if (!this.library && kitRoot && this.core?.kitMember(kitRoot, n))
216
- continue;
216
+ return;
217
217
  let root = m;
218
218
  for (let up = this.inheritedMethod(cls, n); up; up = this.inheritedMethod(up.parent, n))
219
219
  root = up;
220
220
  if (root.parameters.length !== m.parameters.length)
221
- continue;
221
+ return;
222
222
  dynMethods.push({ name: n, params: root.parameters.map((p) => this.paramType(p)), defaults: root.parameters.map((p) => (this.constantDefault(p) ? this.stored(p.initializer, p, this.paramType(p)) : undefined)), ret: this.returnTypeOf(root) });
223
+ };
224
+ for (const m of cls.members)
225
+ if (ts.isMethodDeclaration(m))
226
+ addMethod(m);
227
+ for (const n of droppedProtocolMembers) {
228
+ if (dynMethods.some((d) => d.name === n && !d.key))
229
+ continue;
230
+ const inh = this.inheritedMethod(cls, n);
231
+ if (inh)
232
+ addMethod(inh);
223
233
  }
224
234
  }
225
235
  },
@@ -229,10 +229,7 @@ export const componentMethods = {
229
229
  statics.push(...(this.framework.hooks.componentStatics?.(this, cls) ?? []));
230
230
  return { params, lines, statics };
231
231
  },
232
- /** A component created as a root view (bootstrap, route, dialog): made and rendered as the framework makes it. */
233
- rootView(cls, type, make) {
234
- return this.framework.hooks.wrapRootView ? this.framework.hooks.wrapRootView(this, cls, type, make) : make;
235
- },
232
+ /* rootView is installed from semantics/lowering-methods.ts */
236
233
  /**
237
234
  * `Object.defineProperty` on an app class's instance that makes one of its declared fields an accessor, read-only,
238
235
  * hidden or fixed: the class's Kotlin field keeps none of these.
@@ -260,9 +257,7 @@ export const componentMethods = {
260
257
  const iface = m.parent;
261
258
  return ts.isInterfaceDeclaration(iface) && !!iface.typeParameters?.length && !iface.getSourceFile().isDeclarationFile && this.protocols.has(this.topName(iface, iface.name.text));
262
259
  },
263
- calleeName(e) {
264
- return ts.isCallExpression(e) ? e.expression.getText() : '';
265
- },
260
+ /* calleeName is installed from semantics/lowering-methods.ts */
266
261
  /** The names an app class's members override: its app base classes' and its interfaces'. */
267
262
  overridden(cls, implemented) {
268
263
  const out = new Set();
@@ -1,7 +1,7 @@
1
1
  import ts from 'typescript';
2
2
  import { heldLoss } from "../semantics/losses.js";
3
3
  import { join } from 'node:path';
4
- import { addedDeclarations, augmentedProperty, isCoreDeclaration, ownPropertyOnly } from "../program/core-facts.js";
4
+ import { addedDeclarations, augmentedProperty, inheritedCoreOwner, isCoreDeclaration, ownPropertyOnly } from "../program/core-facts.js";
5
5
  import { KitTypes, coreClass, kitExtends, kitMember } from "../kit/kit-index.js";
6
6
  import { KIT_NAMES_ANDROID } from "./library.js";
7
7
  import { functionTypeParts, kotlinString, numberLiteral, safeCast, splitTopLevel, RT } from "./syntax.js";
@@ -248,7 +248,7 @@ export class CoreKotlin extends KitTypes {
248
248
  * (`Utils.android` of utils/index is utils/native-helper's): that module's object.
249
249
  */
250
250
  ownerOf(target, name) {
251
- let owner = isMixinOwnMember(name, this.t.checker, (s) => this.t.mixinOf(s)) ? null : (this.owner(target) ?? this.inheritedOwner(target, name));
251
+ let owner = isMixinOwnMember(name, this.t.checker, (s) => this.t.mixinOf(s)) ? null : (this.owner(target) ?? inheritedCoreOwner(target, name, this.t.checker, (c) => this.t.kitRootOf(c)));
252
252
  if (owner && !kitMember(this.index, owner.name, name.text))
253
253
  owner = this.renamedOwner(owner, name.text) ?? owner;
254
254
  if (!owner || !owner.isStatic || !owner.name.startsWith('Core_') || kitMember(this.index, owner.name, name.text))
@@ -267,16 +267,6 @@ export class CoreKotlin extends KitTypes {
267
267
  const module = decl && isCoreDeclaration(decl) ? this.moduleObject(decl) : null;
268
268
  return module && kitMember(this.index, module, name.text) ? { name: module, isStatic: true } : owner;
269
269
  }
270
- /** A core member read through a class of the app or a plugin that extends a core class (`this.isPassThroughParentEnabled` in a GridLayout subclass). */
271
- inheritedOwner(target, name) {
272
- const c = this.t.checker;
273
- const decl = c.getSymbolAtLocation(name)?.valueDeclaration;
274
- if (!decl || !isCoreDeclaration(decl))
275
- return null;
276
- const cls = c.getNonNullableType(c.getTypeAtLocation(target)).getSymbol()?.valueDeclaration;
277
- const root = cls && ts.isClassLike(cls) && !cls.getSourceFile().isDeclarationFile ? this.t.kitRootOf(cls) : null;
278
- return root ? { name: root, isStatic: false } : null;
279
- }
280
270
  /**
281
271
  * `on`/`off`/`once` with a named function: a function value made once per
282
272
  * evaluation has no identity across them, so the kit matches a listener by
@@ -312,15 +302,6 @@ export class CoreKotlin extends KitTypes {
312
302
  throw this.t.error(e, `${owner}.${name} (kit-android has no such member)`);
313
303
  return m;
314
304
  }
315
- isViewProperty(owner, name) {
316
- // A style property applies to any view; the kit's classes each apply their own.
317
- if (owner === 'Style')
318
- return [...this.index.values()].some((t) => kitExtends(this.index, t.name, 'View') && t.props.has(name));
319
- for (let t = this.index.get(owner); t; t = t.base ? this.index.get(t.base.replace(/\(.*$/, '')) : undefined)
320
- if (t.props.has(name))
321
- return true;
322
- return false;
323
- }
324
305
  /** `object.name` of an `augmentedProperty` on a core-typed object, outside a chain: the read of its own property (`Any?`), or null. */
325
306
  augmentedRead(e) {
326
307
  if (ts.isOptionalChain(e) || this.constant(e) !== null)
@@ -10,6 +10,86 @@ import { programBase } from "../semantics/classes.js";
10
10
  import { definedField } from "../semantics/shapes.js";
11
11
  import { isKit, isNamed, isUntyped, spelledType } from "../semantics/types.js";
12
12
  export const declarationsMethods = {
13
+ /**
14
+ * Whether a function-local `let s = ...` of type `String` is only ever mutated via statement-level `s += ...`
15
+ * (at least once inside a loop) and never captured by a closure: safe to back with a `StringBuilder` to avoid O(N^2) copies.
16
+ */
17
+ isStringBuilderLocal(d) {
18
+ if (!ts.isIdentifier(d.name) || !d.initializer)
19
+ return false;
20
+ const ownerFn = ts.findAncestor(d, (n) => ts.isFunctionLike(n) && 'body' in n && !!n.body);
21
+ if (!ownerFn || !ownerFn.body || ts.isSourceFile(d.parent.parent.parent))
22
+ return false;
23
+ const sym = this.checker.getSymbolAtLocation(d.name);
24
+ if (!sym || (sym.declarations?.length ?? 0) !== 1)
25
+ return false;
26
+ let appendedInLoop = false;
27
+ let disqualified = false;
28
+ const visit = (n, inNestedFn, inLoop) => {
29
+ if (disqualified)
30
+ return;
31
+ if (n !== ownerFn && (ts.isFunctionLike(n) || ts.isClassLike(n))) {
32
+ ts.forEachChild(n, (c) => visit(c, true, inLoop));
33
+ return;
34
+ }
35
+ if (ts.isIdentifier(n) && n !== d.name) {
36
+ const p = n.parent;
37
+ if ((ts.isPropertyAccessExpression(p) && p.name === n) || ((ts.isPropertyAssignment(p) || ts.isMethodDeclaration(p) || ts.isPropertyDeclaration(p)) && p.name === n))
38
+ return;
39
+ if (this.checker.getSymbolAtLocation(n) === sym) {
40
+ if (inNestedFn || (ts.isShorthandPropertyAssignment(p) && p.name === n)) {
41
+ disqualified = true;
42
+ return;
43
+ }
44
+ if (ts.isBinaryExpression(p) && p.left === n && p.operatorToken.kind >= ts.SyntaxKind.FirstAssignment && p.operatorToken.kind <= ts.SyntaxKind.LastAssignment) {
45
+ if (p.operatorToken.kind !== ts.SyntaxKind.PlusEqualsToken || !ts.isExpressionStatement(p.parent)) {
46
+ disqualified = true;
47
+ return;
48
+ }
49
+ // Reject `s += ...s...` self-append edge case.
50
+ let readsSelf = false;
51
+ const checkRhs = (x) => {
52
+ if (ts.isIdentifier(x) && this.checker.getSymbolAtLocation(x) === sym)
53
+ readsSelf = true;
54
+ if (!readsSelf)
55
+ ts.forEachChild(x, checkRhs);
56
+ };
57
+ checkRhs(p.right);
58
+ if (readsSelf) {
59
+ disqualified = true;
60
+ return;
61
+ }
62
+ if (inLoop)
63
+ appendedInLoop = true;
64
+ return;
65
+ }
66
+ if (ts.isPrefixUnaryExpression(p) || ts.isPostfixUnaryExpression(p)) {
67
+ if (p.operator === ts.SyntaxKind.PlusPlusToken || p.operator === ts.SyntaxKind.MinusMinusToken) {
68
+ disqualified = true;
69
+ return;
70
+ }
71
+ }
72
+ if ((ts.isForInStatement(p) || ts.isForOfStatement(p)) && p.initializer === n) {
73
+ disqualified = true;
74
+ return;
75
+ }
76
+ if (ts.isArrayLiteralExpression(p) || ts.isObjectLiteralExpression(p) || ts.isSpreadAssignment(p) || ts.isSpreadElement(p)) {
77
+ let up = p;
78
+ while (ts.isArrayLiteralExpression(up) || ts.isObjectLiteralExpression(up) || ts.isPropertyAssignment(up) || ts.isSpreadAssignment(up) || ts.isSpreadElement(up))
79
+ up = up.parent;
80
+ if (ts.isBinaryExpression(up) && up.operatorToken.kind === ts.SyntaxKind.EqualsToken && up.left.pos <= n.pos && n.end <= up.left.end) {
81
+ disqualified = true;
82
+ return;
83
+ }
84
+ }
85
+ }
86
+ }
87
+ const nextLoop = inLoop || ts.isIterationStatement(n, false);
88
+ ts.forEachChild(n, (c) => visit(c, inNestedFn, nextLoop));
89
+ };
90
+ visit(ownerFn.body, false, false);
91
+ return appendedInLoop && !disqualified;
92
+ },
13
93
  declarationList(list, lowered) {
14
94
  const constant = !!(list.flags & ts.NodeFlags.Const);
15
95
  // A `let` or `var` set once, where it is declared, is a constant too.
@@ -21,11 +101,6 @@ export const declarationsMethods = {
21
101
  !assignsTo(ts.findAncestor(d, (n) => ts.isFunctionLike(n) || ts.isSourceFile(n)), this.checker.getSymbolAtLocation(d.name), this.checker);
22
102
  return list.declarations.map((d) => this.declaration(d, constant || once(d), lowered)).join('\n');
23
103
  },
24
- /** An `optionalVariable`'s initializer stored as the optional `type`: a read converting undefined gives that undefined. */
25
- heldStore(d, type) {
26
- const code = this.stored(d.initializer, d, type);
27
- return this.undefinedConverted(code) ?? code;
28
- },
29
104
  declaration(d, constant, lowered) {
30
105
  const i = this.indent;
31
106
  const extension = this.native?.extensionClass(d);
@@ -175,6 +250,12 @@ export const declarationsMethods = {
175
250
  const read = (this.isAny(d.initializer) || this.untypedElement(d.initializer)) && !isUntyped(spelledType(t)) ? (this.checkedPlacement(d.initializer, optionalType(t), maybe, this.storeSlot(d.initializer, optionalType(t), d)) ?? this.fromAny(maybe, optionalType(t))) : this.nullableArrayAs(maybe, this.typeOf(d.initializer), t);
176
251
  return `${i}${constant ? 'val' : 'var'} ${name}: ${optionalType(t)} = ${read}`;
177
252
  }
253
+ if (!this.library && !constant && !lowered && !this.asyncCtx && t === 'String' && this.isStringBuilderLocal(d)) {
254
+ const sym = this.checker.getSymbolAtLocation(d.name);
255
+ this.stringBuilders.add(sym);
256
+ const init = this.stored(d.initializer, d, 'String');
257
+ return `${i}val ${name} = StringBuilder(${init === '""' ? '' : init})`;
258
+ }
178
259
  // An untyped value asserted a Java class its uses need only a superclass of: held as that class, unchecked as script's assertion is.
179
260
  const wider = !this.library && ts.isIdentifier(d.name) ? this.widerAsserted(d) : null;
180
261
  if (wider) {
@@ -423,10 +504,6 @@ export const declarationsMethods = {
423
504
  return this.undefinedAs(slot.raw, t);
424
505
  return `(${slot.raw} ?: ${t === 'Double' ? '0.0' : t === 'String' ? '"null"' : 'false'})`;
425
506
  },
426
- /** The slot of the await `e` is, where its continuation holds the value nullable. */
427
- awaited(e) {
428
- return this.awaitSlots.get(ts.skipOuterExpressions(e, ts.OuterExpressionKinds.Parentheses));
429
- },
430
507
  noteNullVar(d) {
431
508
  const init = d.initializer && ts.skipOuterExpressions(d.initializer, ts.OuterExpressionKinds.Parentheses);
432
509
  const sym = ts.isIdentifier(d.name) ? this.resolve(d.name) : undefined;
@@ -4,7 +4,7 @@ import { resultSlot, returnCell } from "../semantics/placement.js";
4
4
  import { assignsTo, branch, functionTypeParts, ident, isFunctionType, isNullable, isThisParameter, jsObjectCode, kotlinString, mentions, nullishType, numberLiteral, optionalElementsType, optionalType, refersTo, returnsNull, splitTopLevel, RT } from "./syntax.js";
5
5
  import { boundNames, thisNodes, takesOwnThis } from "../semantics/ast.js";
6
6
  import { isAsync } from "../semantics/throws.js";
7
- import { isConstant, methodValues, thisArgBound } from "../semantics/lang.js";
7
+ import { methodValues, thisArgBound } from "../semantics/lang.js";
8
8
  import { isUntyped, spelledType } from "../semantics/types.js";
9
9
  import { literalCallback } from "../semantics/conversion.js";
10
10
  export const functionsMethods = {
@@ -91,9 +91,6 @@ export const functionsMethods = {
91
91
  * A parameter Kotlin gives its constant default itself. Not where another method of its override family declares the
92
92
  * parameter otherwise: Kotlin overrides take the root's default, where JavaScript applies the default of the method that runs.
93
93
  */
94
- constantDefault(p) {
95
- return !!p.initializer && isConstant(p.initializer) && !this.familyDefaultsDiffer(p) && !this.states.defaultTakesUndefined(p);
96
- },
97
94
  /** Statements a function body starts with: computed defaults, destructured parameters. */
98
95
  paramPrelude(fn) {
99
96
  const i = this.indent;
@@ -259,10 +259,7 @@ export const globalCallsMethods = {
259
259
  const decl = this.resolve(e.expression)?.declarations?.[0];
260
260
  return !decl || decl.getSourceFile().isDeclarationFile;
261
261
  },
262
- symbolName(e) {
263
- const t = this.checker.getTypeAtLocation(e);
264
- return (t.aliasSymbol ?? t.getSymbol())?.getName() ?? '';
265
- },
262
+ /* symbolName is installed from semantics/lowering-methods.ts */
266
263
  /** A navigation (`$navigateTo(Page, { props })`) to a component, with the props its options give. */
267
264
  navigate(e, component, options) {
268
265
  const info = this.components.get(component);
@@ -1,7 +1,7 @@
1
1
  // Literals as Kotlin: arrays, objects and class expressions, structural copies and dynamic objects.
2
2
  import ts from 'typescript';
3
3
  import { cast, destructuringSource, ident, isNullable, jsObjectCode, kotlinString, optionalType, splitTopLevel, spell, RT } from "./syntax.js";
4
- import { assertedOperand, evolvingElementContext, intersectionAliasMembers, isTypeParameterType, literalKey, openSpreadType, spreadOperand, unquoted, wellKnownMember } from "../semantics/lang.js";
4
+ import { assertedOperand, evolvingElementContext, intersectionAliasMembers, isTypeParameterType, literalKey, openSpreadType, spreadOperand, unquoted, untypedVariableInitializer, wellKnownMember } from "../semantics/lang.js";
5
5
  import { holdsNil, literalNotes, signatureField, shapePlanOfLiteral, spelledOptional, spreadElementNeedsMap, resultShapeNamed } from "../semantics/shapes.js";
6
6
  import { structural } from "../semantics/conversion.js";
7
7
  import { heldOf, isKit, isUntyped, parseNativeType, spelledType } from "../semantics/types.js";
@@ -628,10 +628,7 @@ export const literalsMethods = {
628
628
  },
629
629
  /** A variable declared without a type whose value is a read of a signal holding null (`const card = this.morning()`). */
630
630
  givenNullSignalValue(n) {
631
- const d = ts.isVariableDeclaration(n) ? n : ts.isIdentifier(n) ? (ts.isVariableDeclaration(n.parent) && n.parent.name === n ? n.parent : this.resolve(n)?.valueDeclaration) : undefined;
632
- if (!d || !ts.isVariableDeclaration(d) || d.type || !d.initializer)
633
- return false;
634
- const read = ts.skipOuterExpressions(d.initializer, ts.OuterExpressionKinds.Parentheses);
635
- return ts.isCallExpression(read) && !read.arguments.length && /^Signal<.*\?>$/.test(this.typeOf(read.expression));
631
+ const read = untypedVariableInitializer(n, (id) => this.resolve(id));
632
+ return !!read && ts.isCallExpression(read) && !read.arguments.length && /^Signal<.*\?>$/.test(this.typeOf(read.expression));
636
633
  },
637
634
  };
@@ -236,6 +236,8 @@ export const namesMethods = {
236
236
  return `${kit ?? this.declaredName(e).split('.').map(ident).join('.')}::class.java`;
237
237
  }
238
238
  const ref = this.globalAlias(e) ?? this.refName(e);
239
+ if (sym && this.stringBuilders.has(sym))
240
+ return `${ref}.toString()`;
239
241
  // Library mode: a class named where a member of that name is in scope (ApplicationCommon's `AndroidApplication` getter) by its package.
240
242
  if (this.library && this.appModule && sym && sym.flags & (ts.SymbolFlags.Class | ts.SymbolFlags.Enum) && !ref.includes('.') && this.memberInScope(e, name))
241
243
  return `${this.appModule}.${ref}`;
@@ -2,6 +2,7 @@ import { existsSync, readdirSync, readFileSync } from 'node:fs';
2
2
  import { homedir } from 'node:os';
3
3
  import { join } from 'node:path';
4
4
  import { inflateRawSync } from 'node:zlib';
5
+ import { newerVersion } from "../../semantics/lang.js";
5
6
  /**
6
7
  * Java signatures for Android APIs, read from the class files themselves: the
7
8
  * SDK's android.jar, NativeScript's widgets AAR and, for androidx types, the
@@ -252,19 +253,7 @@ export function parseClass(b) {
252
253
  return result;
253
254
  }
254
255
  // ---- The classpath -----------------------------------------------------------------------------
255
- function versionKey(v) {
256
- return v.split(/[.-]/).map((x) => (/^\d+$/.test(x) ? Number(x) : -1));
257
- }
258
- export function newer(a, b) {
259
- const stable = (v) => !/-/.test(v);
260
- if (stable(a) !== stable(b))
261
- return stable(a);
262
- const ka = versionKey(a), kb = versionKey(b);
263
- for (let i = 0; i < Math.max(ka.length, kb.length); i++)
264
- if ((ka[i] ?? 0) !== (kb[i] ?? 0))
265
- return (ka[i] ?? 0) > (kb[i] ?? 0);
266
- return false;
267
- }
256
+ export const newer = (a, b) => newerVersion(a, b, true);
268
257
  /** The SDK platform's android.jar: the compile SDK's when installed, else the newest. */
269
258
  export function androidJar(compileSdk) {
270
259
  const sdk = process.env.ANDROID_HOME ?? process.env.ANDROID_SDK_ROOT ?? join(homedir(), 'Library', 'Android', 'sdk');
@@ -12,6 +12,7 @@ import { isLibDeclaration } from "../semantics/ast.js";
12
12
  import { nullAs } from "./expressions.js";
13
13
  import { bigIntArithmetic, bigIntCompare, bigIntPlan } from "../semantics/apis/bigint.js";
14
14
  import { BIT_ASSIGNMENTS, addCall, bitOperation, concatOperand, numericThrowing, untypedBinary, untypedConversion } from "../semantics/apis/operators.js";
15
+ import { flattenStringConcat, planRelational } from "../semantics/lower.js";
15
16
  /** BigInt's operations the backend spells as an operator. */
16
17
  const BIGINT_INFIX = { add: '+', subtract: '-', multiply: '*', and: 'and', or: 'or', xor: 'xor' };
17
18
  export const operatorsMethods = {
@@ -74,6 +75,11 @@ export const operatorsMethods = {
74
75
  // A string that may be missing converts first: Kotlin's `+` on a null string writes "null" for undefined too.
75
76
  if (this.isString(e.left) && isNullable(this.declaredTypeOf(e.left) ?? this.typeOf(e.left)))
76
77
  return `${target()} = ${this.str(e.left)} + ${added()}`;
78
+ if (ts.isIdentifier(e.left) && this.stringBuilders.has(this.resolve(e.left))) {
79
+ const parts = flattenStringConcat(e.right, (x) => this.isString(x));
80
+ const appends = parts.map((p) => `.append(${untyped?.kind === 'concat' ? concatOperand(this, p, untyped) : this.str(p)})`).join('');
81
+ return `${ident(e.left.text)}${appends}`;
82
+ }
77
83
  return this.isString(e.left) ? `${target()} += ${added()}` : `${target()} += ${untyped ? untypedConversion(this, untyped, e.right) : this.toNumber(e.right)}`;
78
84
  }
79
85
  case K.MinusEqualsToken:
@@ -133,19 +139,19 @@ export const operatorsMethods = {
133
139
  case K.GreaterThanToken:
134
140
  case K.LessThanEqualsToken:
135
141
  case K.GreaterThanEqualsToken: {
136
- const sym = ts.tokenToString(op);
137
- if (this.isString(e.left) && this.isString(e.right))
138
- return `${l()} ${sym} ${r()}`;
139
142
  // An untyped or object operand: compared as strings or as numbers by what it holds when the program runs.
140
143
  const dynamic = (x) => {
141
144
  const t = this.typeOf(x);
142
145
  return isUntyped(spelledType(t)) || t === 'Any' || t === 'String?' || /^[A-Z]\??$/.test(t) || (this.isObjectType(t) && !/^JSDate\??$/.test(t));
143
146
  };
144
- if (dynamic(e.left) || dynamic(e.right)) {
145
- const fn = { [K.LessThanToken]: RT.jsLess, [K.GreaterThanToken]: RT.jsGreater, [K.LessThanEqualsToken]: RT.jsLessOrEqual, [K.GreaterThanEqualsToken]: RT.jsGreaterOrEqual }[op];
147
+ const plan = planRelational(op, this.isString(e.left), this.isString(e.right), dynamic(e.left) || dynamic(e.right));
148
+ if (plan.kind === 'string')
149
+ return `${l()} ${plan.op} ${r()}`;
150
+ if (plan.kind === 'dynamic') {
151
+ const fn = { '<': RT.jsLess, '>': RT.jsGreater, '<=': RT.jsLessOrEqual, '>=': RT.jsGreaterOrEqual }[plan.op];
146
152
  return `${fn}(${this.coerce(e.left, 'Any?')}, ${this.coerce(e.right, 'Any?')})`;
147
153
  }
148
- return `${this.toNumber(e.left)} ${sym} ${this.toNumber(e.right)}`;
154
+ return `${this.toNumber(e.left)} ${plan.op} ${this.toNumber(e.right)}`;
149
155
  }
150
156
  case K.QuestionQuestionToken: {
151
157
  const t = this.typeOf(e);
@@ -42,7 +42,7 @@ export const optionalChainsMethods = {
42
42
  // A non-strict app's optional member, as its shape holds it.
43
43
  const shapeOptSym = ts.isPropertyAccessExpression(e) && !e.questionDotToken && !(e.flags & ts.NodeFlags.OptionalChain) ? this.checker.getSymbolAtLocation(e.name) : undefined;
44
44
  const shapeOpt = !!shapeOptSym && this.states.shapeFieldOptional(shapeOptSym) && (['String', 'Double', 'Boolean'].includes(this.typeOf(e)) || this.states.unsetMember(shapeOptSym.valueDeclaration ?? shapeOptSym.declarations?.[0]));
45
- if (ts.isPropertyAccessExpression(e) && ((this.optionalMember(e) && ['String', 'Double', 'Boolean'].includes(this.typeOf(e))) || shapeOpt)) {
45
+ if (ts.isPropertyAccessExpression(e) && ((this.isLenientOptionalMember(e) && ['String', 'Double', 'Boolean'].includes(this.typeOf(e))) || shapeOpt)) {
46
46
  const untyped = this.untypedMemberRead(e);
47
47
  if (untyped)
48
48
  return untyped;
@@ -270,14 +270,7 @@ export const optionalChainsMethods = {
270
270
  * A string, number or boolean read `e` of type `t` as the optional it holds, where it converts undefined (a read, or
271
271
  * a choice one of whose branches does); null where it converts nothing.
272
272
  */
273
- convertedOptional(e, t) {
274
- if (this.library)
275
- return null;
276
- const inner = ts.skipOuterExpressions(e);
277
- if (ts.isConditionalExpression(inner) && this.typeOf(inner) === t && [inner.whenTrue, inner.whenFalse].some((x) => this.undefinedConverted(this.coerce(ts.skipOuterExpressions(x, ts.OuterExpressionKinds.Parentheses), t))))
278
- return this.coerce(inner, optionalType(t));
279
- return this.undefinedConverted(this.expr(ts.skipOuterExpressions(e, ts.OuterExpressionKinds.Parentheses)));
280
- },
273
+ /* convertedOptional is installed from semantics/lowering-methods.ts */
281
274
  /**
282
275
  * App and plugin code's string, number or boolean read that converts undefined (`(x ?: "undefined")`): the nullable it
283
276
  * converts, for a use that takes undefined as it is (a comparison, a receiver's TypeError). Null for any other code.