@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
@@ -1,16 +1,112 @@
1
- // Module-level `let`/`const` bindings belonging to an import cycle, which may be read or written before their
2
- // initializer runs (JavaScript's TDZ ReferenceError). Only cyclic app modules carry TDZ guards so acyclic modules
3
- // and library kits emit zero extra overhead.
1
+ // Module-level `let`/`const` bindings that may be read or written before their initializer runs (JavaScript's TDZ
2
+ // ReferenceError): either belonging to an import cycle or read by a function / earlier statement in the same module
3
+ // when executable code runs before the declaration. Other module bindings and library kits emit zero extra overhead.
4
4
  import ts from 'typescript';
5
- import { hasModifier } from "./ast.js";
5
+ import { hasModifier, resolveSymbol } from "./ast.js";
6
+ /** Whether a top-level statement before a declaration can run user code (and thus invoke a hoisted function or closure). */
7
+ function canRunCode(st) {
8
+ if (ts.isImportDeclaration(st) || ts.isExportDeclaration(st) || ts.isFunctionDeclaration(st) || ts.isInterfaceDeclaration(st) || ts.isTypeAliasDeclaration(st) || ts.isEmptyStatement(st))
9
+ return false;
10
+ if (hasModifier(st, ts.SyntaxKind.DeclareKeyword))
11
+ return false;
12
+ if (ts.isVariableStatement(st))
13
+ return st.declarationList.declarations.some((d) => !!d.initializer && exprCanRunCode(d.initializer));
14
+ if (ts.isClassDeclaration(st))
15
+ return st.members.some((m) => ts.isClassStaticBlockDeclaration(m) || (ts.isPropertyDeclaration(m) && !!(ts.getCombinedModifierFlags(m) & ts.ModifierFlags.Static) && !!m.initializer && exprCanRunCode(m.initializer)));
16
+ return true;
17
+ }
18
+ /** Whether an expression may invoke a function, getter, constructor, or other non-literal code at evaluation time. */
19
+ function exprCanRunCode(e) {
20
+ if (ts.isLiteralExpression(e) || e.kind === ts.SyntaxKind.TrueKeyword || e.kind === ts.SyntaxKind.FalseKeyword || e.kind === ts.SyntaxKind.NullKeyword || ts.isArrowFunction(e) || ts.isFunctionExpression(e) || ts.isIdentifier(e))
21
+ return false;
22
+ if (ts.isParenthesizedExpression(e) || ts.isAsExpression(e) || ts.isTypeAssertionExpression(e) || ts.isSatisfiesExpression(e) || ts.isNonNullExpression(e))
23
+ return exprCanRunCode(e.expression);
24
+ if (ts.isPrefixUnaryExpression(e))
25
+ return exprCanRunCode(e.operand);
26
+ if (ts.isBinaryExpression(e))
27
+ return exprCanRunCode(e.left) || exprCanRunCode(e.right);
28
+ if (ts.isArrayLiteralExpression(e))
29
+ return e.elements.some((x) => !ts.isOmittedExpression(x) && exprCanRunCode(ts.isSpreadElement(x) ? x.expression : x));
30
+ if (ts.isObjectLiteralExpression(e))
31
+ return e.properties.some((p) => (ts.isPropertyAssignment(p) && exprCanRunCode(p.initializer)) || (ts.isSpreadAssignment(p) && exprCanRunCode(p.expression)));
32
+ return true;
33
+ }
34
+ /** Collects same-module `let`/`const` declarations that may be observed before their initializer executes. */
35
+ function addSameModuleTdz(checker, sf, out) {
36
+ const decls = new Map();
37
+ for (let i = 0; i < sf.statements.length; i++) {
38
+ const st = sf.statements[i];
39
+ if (!ts.isVariableStatement(st) || hasModifier(st, ts.SyntaxKind.DeclareKeyword))
40
+ continue;
41
+ if (!(st.declarationList.flags & ts.NodeFlags.BlockScoped))
42
+ continue;
43
+ for (let j = 0; j < st.declarationList.declarations.length; j++) {
44
+ const d = st.declarationList.declarations[j];
45
+ if (!ts.isIdentifier(d.name) || !d.initializer || out.has(d))
46
+ continue;
47
+ const sym = checker.getSymbolAtLocation(d.name);
48
+ if (sym)
49
+ decls.set(sym, { decl: d, stmtIndex: i, declIndex: j });
50
+ }
51
+ }
52
+ if (!decls.size)
53
+ return;
54
+ // Track which statement indices have executable code before them.
55
+ const runnableBefore = new Array(sf.statements.length).fill(false);
56
+ let ran = false;
57
+ for (let i = 0; i < sf.statements.length; i++) {
58
+ runnableBefore[i] = ran;
59
+ if (canRunCode(sf.statements[i]))
60
+ ran = true;
61
+ }
62
+ const isRef = (n) => {
63
+ const p = n.parent;
64
+ if (ts.isImportSpecifier(p) || ts.isExportSpecifier(p) || ts.isImportClause(p) || ts.isTypeReferenceNode(p))
65
+ return false;
66
+ if (ts.isVariableDeclaration(p) && p.name === n)
67
+ return false;
68
+ if (ts.isPropertyAccessExpression(p) && p.name === n)
69
+ return false;
70
+ if ((ts.isPropertyAssignment(p) || ts.isMethodDeclaration(p) || ts.isPropertyDeclaration(p)) && p.name === n)
71
+ return false;
72
+ return true;
73
+ };
74
+ const walk = (node, stmtIndex, inHoistedFn, inDeferredScope) => {
75
+ if (ts.isIdentifier(node) && isRef(node)) {
76
+ const sym = resolveSymbol(node, checker);
77
+ const entry = sym ? decls.get(sym) : undefined;
78
+ if (entry) {
79
+ const priorExecutable = runnableBefore[entry.stmtIndex] ||
80
+ (stmtIndex === entry.stmtIndex &&
81
+ ts.isVariableStatement(sf.statements[stmtIndex]) &&
82
+ sf.statements[stmtIndex].declarationList.declarations.slice(0, entry.declIndex).some((prev) => !!prev.initializer && exprCanRunCode(prev.initializer)));
83
+ const beforeDecl = stmtIndex < entry.stmtIndex;
84
+ const inOwnInit = !inDeferredScope && stmtIndex === entry.stmtIndex && node.pos >= entry.decl.initializer.pos && node.end <= entry.decl.initializer.end;
85
+ if ((beforeDecl && (!inDeferredScope || priorExecutable)) || (inHoistedFn && priorExecutable) || inOwnInit) {
86
+ out.add(entry.decl);
87
+ }
88
+ }
89
+ }
90
+ const entersDeferred = ts.isFunctionLike(node) || ts.isClassStaticBlockDeclaration(node);
91
+ ts.forEachChild(node, (child) => walk(child, stmtIndex, inHoistedFn, inDeferredScope || entersDeferred));
92
+ };
93
+ for (let i = 0; i < sf.statements.length; i++) {
94
+ const st = sf.statements[i];
95
+ walk(st, i, ts.isFunctionDeclaration(st), false);
96
+ }
97
+ }
6
98
  /**
7
- * The module-level `let` and `const` declarations (with initializers) in `files` that belong to an import cycle
8
- * (SCC of size > 1 or self-import in the value-import graph).
99
+ * The module-level `let` and `const` declarations (with initializers) in `files` that may be read or written before
100
+ * their initializer runs: either in an import cycle (SCC of size > 1 or self-import) or reachable before initialization
101
+ * within the same module.
9
102
  */
10
103
  export function cyclicModuleBindings(checker, files) {
11
104
  const sources = files.filter((f) => !f.isDeclarationFile);
105
+ const out = new Set();
106
+ for (const sf of sources)
107
+ addSameModuleTdz(checker, sf, out);
12
108
  if (sources.length < 2)
13
- return new Set();
109
+ return out;
14
110
  const fileSet = new Set(sources);
15
111
  const edges = new Map();
16
112
  const resolveTargets = (sf, seen) => {
@@ -89,7 +185,6 @@ export function cyclicModuleBindings(checker, files) {
89
185
  for (const sf of sources)
90
186
  if (!index.has(sf))
91
187
  strongConnect(sf);
92
- const out = new Set();
93
188
  for (const sf of cyclic) {
94
189
  for (const st of sf.statements) {
95
190
  if (!ts.isVariableStatement(st) || hasModifier(st, ts.SyntaxKind.DeclareKeyword))
@@ -7,7 +7,7 @@ import { CONSOLE } from "../semantics/apis/console.js";
7
7
  import { libFunctionValueKind } from "../semantics/apis/statics.js";
8
8
  import { ERRORS, isLibGlobal } from "../semantics/globals.js";
9
9
  import { spell, escapingFunction, functionParts, hasTopLevelArrow, ident, identPath, isFunctionType, isOptional, openSwiftChain, optionalType, splitTopLevel, swiftString, RT, lenientReader } from "./syntax.js";
10
- import { elementReceiverCell, keyName, observerSlot, place, receiverCell, receiverSlot, isEnumObject, nullishField } from "../semantics/placement.js";
10
+ import { elementReceiverCell, keyName, receiverCell, receiverSlot, isEnumObject, nullishField } from "../semantics/placement.js";
11
11
  import { ambientAddedMemberOf, augmentedPropertyRead, functionProperty, uncheckedMatch, wellKnownMember, isSelf } from "../semantics/lang.js";
12
12
  import { convertedRead, onlyNull } from "../semantics/states/predicates.js";
13
13
  import { isLibDeclaration, isWriteTarget, notIterable } from "../semantics/ast.js";
@@ -438,10 +438,12 @@ export const accessMethods = {
438
438
  const x = ts.skipOuterExpressions(target, ts.OuterExpressionKinds.Parentheses);
439
439
  if (nullishField(this, x) && !this.subst.has(x) && !receiverSlot(target, key).chained)
440
440
  return this.marks.ownTried(`${this.nullishCode(x)}.present(${this.states.nullishMemberKey(x).set ? 'setting: ' : ''}${swiftString(key)})`);
441
- return this.receiverCode(receiverCell(this.receivers, receiverSlot(target, key)), key);
441
+ const p = target.parent;
442
+ const set = ts.isPropertyAccessExpression(p) && ts.isBinaryExpression(p.parent) && p.parent.operatorToken.kind === ts.SyntaxKind.EqualsToken && p.parent.left === p;
443
+ return this.receiverCode(receiverCell(this.receivers, receiverSlot(target, key)), key, set);
442
444
  },
443
445
  /** A receiver cell as Swift writes it: null where the access reads it as it is. */
444
- receiverCode(c, key) {
446
+ receiverCode(c, key, set = false) {
445
447
  if (c.cell === 'chained') {
446
448
  // Swift's `?.` carries the chain on through the receiver's own check.
447
449
  const code = this.maybeUndefined(c.receiver) ?? this.expr(c.receiver);
@@ -451,7 +453,7 @@ export const accessMethods = {
451
453
  throw this.error(c.receiver, `an optional chain's link read past it as \`${open}\``);
452
454
  return `${open}.${RT.jsUnwrap}(${swiftString(key)}${c.isNull ? ', null: true' : ''})`;
453
455
  }
454
- return c.cell === 'asIs' ? null : `${RT.jsUnwrap}(${c.code}, ${swiftString(key)}${c.isNull ? ', null: true' : ''})`;
456
+ return c.cell === 'asIs' ? null : set && !c.isNull ? `${RT.jsUnwrap}(${c.code}, setting: ${swiftString(key)})` : `${RT.jsUnwrap}(${c.code}, ${swiftString(key)}${c.isNull ? ', null: true' : ''})`;
455
457
  },
456
458
  elementAccess(e) {
457
459
  this.refuseProto(e);
@@ -650,10 +652,6 @@ export const accessMethods = {
650
652
  heldMissing(e) {
651
653
  return this.marks.isUnwrap(this.expr(e)) || this.looseObjectRead(e) || this.widenedParameterRead(e) || /[?!]$/.test(this.declaredTypeOf(e) ?? '') ? this.observe(e, 'asIs') : null;
652
654
  },
653
- /** `x` read by an equality or `typeof` (`ObserverSlot`). */
654
- observe(x, read = 'untyped') {
655
- return place(this.placement, x, observerSlot(this.placement, read));
656
- },
657
655
  /** A read `observedAsIs` (`instanceof`'s left): the optional it may be, never unwrapped. */
658
656
  observed(e) {
659
657
  if (this.library || this.lenient)
@@ -168,11 +168,19 @@ export const assignmentMethods = {
168
168
  return `${fnObject}[jsKey: ${swiftString(left.name.text)}] = ${this.stored(right, left, 'Any?', checks)}`;
169
169
  if (fnObject)
170
170
  throw this.error(e, `${ts.tokenToString(e.operatorToken.kind)} on a function's property`);
171
- if (e.operatorToken.kind === ts.SyntaxKind.EqualsToken && ts.isIdentifier(left)) {
171
+ if (ts.isIdentifier(left)) {
172
172
  const decl = this.resolve(left)?.valueDeclaration;
173
173
  if (decl && ts.isVariableDeclaration(decl) && this.facts.tdzBindings().has(decl) && !(decl.parent.flags & ts.NodeFlags.Const)) {
174
174
  const raw = this.refName(left).replace(/`/g, '');
175
- return `__tdz_set_${raw}(${this.stored(right, left, this.declaredTypeOf(left) ?? this.typeOf(left), checks)})`;
175
+ const lt = this.declaredTypeOf(left) ?? this.typeOf(left);
176
+ if (e.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
177
+ return `__tdz_set_${raw}(${this.stored(right, left, lt, checks)})`;
178
+ }
179
+ const op = { [ts.SyntaxKind.PlusEqualsToken]: '+', [ts.SyntaxKind.MinusEqualsToken]: '-', [ts.SyntaxKind.AsteriskEqualsToken]: '*', [ts.SyntaxKind.SlashEqualsToken]: '/' }[e.operatorToken.kind];
180
+ if (op) {
181
+ const rhs = op === '+' && lt === 'String' ? this.str(right) : this.coerce(right, lt);
182
+ return this.marks.ownTried(`{ () throws -> ${lt} in let __v = try __tdz_get_${raw}() ${op} ${this.tryPrefix(right)}${rhs}; try __tdz_set_${raw}(__v); return __v }()`);
183
+ }
176
184
  }
177
185
  }
178
186
  const nullish = e.operatorToken.kind === ts.SyntaxKind.EqualsToken && ts.isIdentifier(left) ? this.states.nullishRead(left) : null;
@@ -478,8 +478,13 @@ export const callsMethods = {
478
478
  return `${maybe ? `${RT.jsCallee}(${maybe})` : this.expr(callee)}(${this.args(e).join(', ')})`;
479
479
  }
480
480
  // `handler!(…)`: the function, where undefined is not a function.
481
- if (ts.isNonNullExpression(callee))
482
- return /[?!]$/.test(this.typeOf(callee.expression)) ? `${RT.jsCallee}(${this.expr(callee.expression)})(${this.args(e).join(', ')})` : this.call(ts.factory.updateCallExpression(e, callee.expression, e.typeArguments, e.arguments));
481
+ if (ts.isNonNullExpression(callee)) {
482
+ if (!/[?!]$/.test(this.typeOf(callee.expression)))
483
+ return this.call(ts.factory.updateCallExpression(e, callee.expression, e.typeArguments, e.arguments));
484
+ const label = ts.isPropertyAccessExpression(callee.expression) || ts.isIdentifier(callee.expression) ? callee.expression.getText() : null;
485
+ const fnType = this.typeOf(callee.expression).replace(/^\((.*)\)[?!]$/, '$1').replace(/[?!]$/, '');
486
+ return label ? `({ () throws -> ${fnType} in guard let __fn = ${this.tryPrefix(callee.expression)}${this.expr(callee.expression)} else { throw JSException(JSTypeError(${swiftString(`${label} is not a function`)})) }; return __fn }())(${this.args(e).join(', ')})` : `${RT.jsCallee}(${this.expr(callee.expression)})(${this.args(e).join(', ')})`;
487
+ }
483
488
  throw this.error(e, 'call');
484
489
  },
485
490
  /** An Error (or a subclass the program declares without its own toString), which Swift holds as a JSError. */
@@ -80,7 +80,7 @@ export const classAccessorsMethods = {
80
80
  this.declare(n, { kind: 'var', mods, type: declared, throws: !!a.get && !reported && this.throwsInfo.fn(a.get) });
81
81
  // A plugin's objects are read untyped too (`navigator.gpu.native`): their accessors by name.
82
82
  const own = (a.get ?? a.set);
83
- if (this.byNameAccessor(cls, own) && !ts.isPrivateIdentifier(own.name)) {
83
+ if ((this.byNameAccessor(cls, own) || k.droppedProtocolMembers.has(n)) && !ts.isPrivateIdentifier(own.name)) {
84
84
  const getThrows = !!a.get && this.throwsInfo.fn(a.get) && !reported;
85
85
  const read = getThrows ? this.marks.orNil(`${RT.jsReported} { try self.${ident(n)} }`) : `self.${ident(n)}`;
86
86
  const stored = () => (declared.endsWith('!') ? this.fromAny('newValue', declared.replace(/!$/, '?')) : isKit(spelledType(declared), 'JSNullish') ? `(${RT.jsConverted}(newValue, to: ${declared}.self) ?? nil)` : this.fromAnyCode('newValue', declared, true));
@@ -5,7 +5,7 @@ import { atLossSite, HELD_LOSS } from "../semantics/losses.js";
5
5
  import { ERRORS } from "../semantics/globals.js";
6
6
  import { NONISOLATED_DEINIT, ident, swiftString, RT } from "./syntax.js";
7
7
  import { UNKEYED, memberPlanOf, notesNull, nullNames, definedNamesOf } from "../semantics/shapes.js";
8
- import { initializedNull } from "../semantics/lang.js";
8
+ import { droppedProtocolMemberNames, initializedNull } from "../semantics/lang.js";
9
9
  import { isStatic } from "../semantics/throws.js";
10
10
  import { isCoreDeclaration, isShimDeclaration } from "../program/core-facts.js";
11
11
  import { classExprCaptures, classExprScriptName, programBase } from "../semantics/classes.js";
@@ -111,6 +111,7 @@ export const classDeclMethods = {
111
111
  // The library's interfaces (`Iterable<T>`, `Iterator<T>`) are protocols of the kit's, conformed to below.
112
112
  const witnesses = [];
113
113
  const { named, met, implemented } = this.implementedProtocols(cls, kitRoot, witnesses);
114
+ const droppedProtocolMembers = droppedProtocolMemberNames(c, cls, this.protocols, implemented, (i) => this.heritageName(i), (_, t, n) => this.uncompiledType(t) || (t.getSymbol()?.declarations ?? []).every((d) => d.getSourceFile().isDeclarationFile && (this.library || !isCoreDeclaration(d) || !this.core.has(n))) || this.conformsToProtocol(cls, n));
114
115
  // What a protocol requires the class reads without throwing: a getter that throws reports instead.
115
116
  const required = new Set([...named, ...met].filter((i) => implemented.includes(i.name)).flatMap((i) => i.type.getProperties().map((p) => p.name)));
116
117
  const conformances = [...(base ? [base] : []), ...(collection && !appBase && !implemented.length ? ['JSDynamic'] : []), ...implemented];
@@ -130,7 +131,7 @@ export const classDeclMethods = {
130
131
  conformances.push('JSToJSONConvertible');
131
132
  implicitlyCalled.add('toJSON');
132
133
  }
133
- return { cls, name, layout, heritage, appBase, base, kitRoot, collection, isError, expando, isView, implemented, witnesses, required, conformances, implicitlyCalled, lines: [''], fieldInits: [], fields: [], paramPropValues: new Map(), symbolFields: [], symbolMethods: [], keyInits: [], symKeyCount: 0, dynAccessors: [], dynMethods: [] };
134
+ return { cls, name, layout, heritage, appBase, base, kitRoot, collection, isError, expando, isView, implemented, droppedProtocolMembers, witnesses, required, conformances, implicitlyCalled, lines: [''], fieldInits: [], fields: [], paramPropValues: new Map(), symbolFields: [], symbolMethods: [], keyInits: [], symKeyCount: 0, dynAccessors: [], dynMethods: [] };
134
135
  },
135
136
  conversionMembers(k) {
136
137
  const { cls, layout, lines } = k;
@@ -160,6 +160,21 @@ export const classMethodsMethods = {
160
160
  methodMembers(k) {
161
161
  for (const m of k.cls.members)
162
162
  this.methodMember(k, m);
163
+ for (const n of k.droppedProtocolMembers) {
164
+ if (k.dynMethods.some((d) => d.name === n))
165
+ continue;
166
+ const inh = this.inheritedMethod(k.cls, n);
167
+ if (!inh || !inh.body || isStatic(inh) || ts.isPrivateIdentifier(inh.name))
168
+ continue;
169
+ const restAt = inh.parameters.findIndex((p) => p.dotDotDotToken);
170
+ const generic = !this.library && !this.erasesGenerics(inh) && !!inh.typeParameters?.some((p) => !this.erasesTypeParameter(p));
171
+ if ((restAt >= 0 && restAt !== inh.parameters.length - 1) || generic)
172
+ continue;
173
+ const sig = this.emittedSignature(inh);
174
+ const plain = (t) => t.replace(/^\((any .*)\)!$/, '$1?').replace(/!$/, '?');
175
+ const params = this.readsArguments(inh) ? ['JSRest<Any?>'] : sig.params.map((p, idx) => (idx === restAt ? `JSRest<${/^JSArray<(.*)>$/.exec(plain(p.type))?.[1] ?? 'Any?'}>` : isFunctionType(p.type) ? `@escaping ${p.type}` : plain(p.type)));
176
+ k.dynMethods.push({ name: n, type: `(${params.join(', ')}) throws -> ${plain(sig.ret)}`, available: this.gatedFunctions.get(inh), length: scriptLength(inh) });
177
+ }
163
178
  },
164
179
  methodMember(k, m) {
165
180
  const { cls, kitRoot, lines } = k;
@@ -222,7 +237,7 @@ export const classMethodsMethods = {
222
237
  lines.push(' ' + this.memberFunc(m, ident(nonVirtualName(n, cls.name?.text ?? k.name)), 'final '));
223
238
  // A plugin's objects are read untyped too (`handler.attachToView(view)` on an `any`): their methods by name.
224
239
  const restAt = m.parameters.findIndex((p) => p.dotDotDotToken);
225
- if ((((this.pluginFiles.has(cls.getSourceFile().fileName) || this.appMembersByName || this.states.downcastClass(cls) || this.states.byNameClass(cls)) && this.states.byNameMember(cls, n)) || this.states.viewedMember(cls, n)) && !isStatic(m) && !ts.isPrivateIdentifier(m.name) && (restAt < 0 || restAt === m.parameters.length - 1) && !extra.length && !generic) {
240
+ if ((((this.pluginFiles.has(cls.getSourceFile().fileName) || this.appMembersByName || this.states.downcastClass(cls) || this.states.byNameClass(cls)) && this.states.byNameMember(cls, n)) || this.states.viewedMember(cls, n) || k.droppedProtocolMembers.has(n)) && !isStatic(m) && !ts.isPrivateIdentifier(m.name) && (restAt < 0 || restAt === m.parameters.length - 1) && !extra.length && !generic) {
226
241
  // The signature Swift has for the method: an override's is its root's.
227
242
  const sig = this.emittedSignature(m);
228
243
  const plain = (t) => t.replace(/^\((any .*)\)!$/, '$1?').replace(/!$/, '?');
@@ -20,9 +20,6 @@ export const classesMethods = {
20
20
  this.declare(name, { kind: 'var', type: t });
21
21
  return [` lazy var ${memo} = ${this.memo(fn, t, throws, true)}`, ` var ${ident(name)}: ${t} ${throws ? `{\n get throws { try ${memo}.read() }\n }` : `{ ${memo}.value }`}`];
22
22
  },
23
- calleeName(e) {
24
- return ts.isCallExpression(e) ? e.expression.getText() : '';
25
- },
26
23
  /** A class decorator the class's translation neither refuses nor runs: core's (`@CSSType`, `@NativeClass`) and the framework's. */
27
24
  keptDecorator(d) {
28
25
  return new RegExp(`^(${['CSSType', 'NativeClass', 'ObjCClass', ...this.framework.readDecorators()].join('|')})\\b`).test(d.expression.getText());
@@ -343,6 +340,29 @@ export const classesMethods = {
343
340
  })
344
341
  .join('\n');
345
342
  },
343
+ /** A class's instance methods registered non-enumerably on `JSPrototypes.of(Cls.self)` when its prototype is observed. */
344
+ prototypeMethods(cls) {
345
+ if (this.library || this.native.classDecl(cls) || cls.typeParameters?.some((p) => !this.erasesTypeParameter(p)))
346
+ return '';
347
+ const i = this.indent;
348
+ const name = this.className(cls);
349
+ const seen = new Set();
350
+ const entries = [];
351
+ for (const m of cls.members) {
352
+ if (!ts.isMethodDeclaration(m) || !m.body || isStatic(m) || ts.isPrivateIdentifier(m.name) || ts.isComputedPropertyName(m.name) || m.typeParameters?.length || m.asteriskToken || isAsync(m) || m.parameters.some((p) => p.dotDotDotToken) || this.readsArguments(m))
353
+ continue;
354
+ const key = m.name.getText().replace(/^['"]|['"]$/g, '');
355
+ if (seen.has(key))
356
+ continue;
357
+ seen.add(key);
358
+ const sig = this.emittedSignature(m);
359
+ const args = sig.params.map((p, k) => this.throwingConverts(() => this.presentFromAny(`${RT.jsArg}(__a, ${k})`, p.type, true, true)));
360
+ const call = this.marks.tryIf(this.throwsInfo.fn(m), `__o.${ident(key)}(${args.join(', ')})`);
361
+ const body = sig.ret === 'Void' ? `${call}; return nil` : `return ${this.convert(call, sig.ret, 'Any?')}`;
362
+ entries.push(`${i}try? JSPrototypes.of(${name}.self).defineProperty(${swiftString(key)}, JSPropertyDescriptor(value: { (__this: Any?, __a: [Any?]) throws -> Any? in guard let __o = __this as? ${name} else { throw JSException(JSTypeError("Illegal invocation")) }; ${body} } as JSMethod, enumerable: false, writable: true, configurable: true))`);
363
+ }
364
+ return entries.join('\n');
365
+ },
346
366
  /** What defining a class does after its static initializers (library mode): its statics when held as a value, then its decorators, the last first. */
347
367
  classDefinition(cls) {
348
368
  const i = this.indent;
@@ -452,12 +472,6 @@ export const classesMethods = {
452
472
  const cls = (t.isTypeParameter() ? (t.getConstraint() ?? t) : t).getSymbol()?.valueDeclaration;
453
473
  return !!cls && ts.isClassLike(cls) && !!this.kitRootOf(cls);
454
474
  },
455
- /** `fooProperty.setNative`: the registered name of the property it belongs to. */
456
- setNativeOf(e) {
457
- if (!ts.isPropertyAccessExpression(e) || e.name.text !== 'setNative')
458
- return null;
459
- return this.properties?.name(this.resolve(e.expression)) ?? null;
460
- },
461
475
  /**
462
476
  * A method overriding NativeScriptKit's: the kit's Swift signature, the
463
477
  * TypeScript body seeing its own types; what it throws is reported, as an
@@ -307,10 +307,6 @@ export const componentMethods = {
307
307
  componentStatics(cls) {
308
308
  return this.framework.hooks.componentStatics?.(this, cls) ?? [];
309
309
  },
310
- /** A component created as a root view (bootstrap, route, dialog): made and rendered as the framework makes it. */
311
- rootView(cls, type, make) {
312
- return this.framework.hooks.wrapRootView ? this.framework.hooks.wrapRootView(this, cls, type, make) : make;
313
- },
314
310
  /** What a component's method returning an array (a loop's items) holds, as Swift spells it. */
315
311
  memberElementType(cls, name) {
316
312
  const m = cls.members.find((x) => ts.isMethodDeclaration(x) && ts.isIdentifier(x.name) && x.name.text === name);
@@ -2,7 +2,7 @@ import ts from 'typescript';
2
2
  import { heldLoss } from "../semantics/losses.js";
3
3
  import { KIT_APPLE_SOURCES } from "../driver/paths.js";
4
4
  import { KIT_GLOBALS, KitTypes, coreClass, kitExtends, kitIndex, kitMember } from "../kit/kit-index.js";
5
- import { NATIVE_MEMBERS, SCRIPT_OBJECTS, addedDeclarations, augmentedProperty, coreBarrels, coreSymbolName, isCoreDeclaration, ownPropertyOnly, packageOf, unappliedProperty } from "../program/core-facts.js";
5
+ import { NATIVE_MEMBERS, SCRIPT_OBJECTS, addedDeclarations, augmentedProperty, coreBarrels, coreSymbolName, inheritedCoreOwner, 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
8
  import { isMixinOwnMember } from "../semantics/classes.js";
@@ -303,21 +303,11 @@ export class CoreAPI extends KitTypes {
303
303
  throw this.t.error(e, `${owner}.${name} (NativeScriptKit has no such member)`);
304
304
  return m;
305
305
  }
306
- /** Whether the kit applies `name` by name on this view class (a property in its setProperty). */
307
- isViewProperty(owner, name) {
308
- // A style property applies to any view; the kit's classes each apply their own.
309
- if (owner === 'Style')
310
- return [...this.index.values()].some((t) => kitExtends(this.index, t.name, 'View') && t.props.has(name));
311
- for (let t = this.index.get(owner); t; t = t.base ? this.index.get(t.base) : undefined)
312
- if (t.props.has(name))
313
- return true;
314
- return false;
315
- }
316
306
  /** `object.name` of an `augmentedProperty` on a core-typed object, outside a chain: the read of its own property (`Any?`), or null. */
317
307
  augmentedRead(e) {
318
308
  if (ts.isOptionalChain(e) || this.constant(e) !== null || this.mixinOwn(e.name))
319
309
  return null;
320
- const owner = this.owner(e.expression) ?? this.inheritedOwner(e.expression, e.name);
310
+ const owner = this.owner(e.expression) ?? inheritedCoreOwner(e.expression, e.name, this.t.checker, (c) => this.t.kitRootOf(c));
321
311
  if (!owner || owner.isStatic || (this.isView(owner.name) && this.isViewProperty(owner.name, e.name.text)))
322
312
  return null;
323
313
  if (!augmentedProperty(this.index, owner.name, e.name, this.t.resolve(e.name)))
@@ -331,7 +321,7 @@ export class CoreAPI extends KitTypes {
331
321
  return constant;
332
322
  if (this.heldFunction(e.expression, e.name.text))
333
323
  return null;
334
- const owner = this.mixinOwn(e.name) ? null : (this.owner(e.expression) ?? this.inheritedOwner(e.expression, e.name));
324
+ const owner = this.mixinOwn(e.name) ? null : (this.owner(e.expression) ?? inheritedCoreOwner(e.expression, e.name, this.t.checker, (c) => this.t.kitRootOf(c)));
335
325
  if (!owner)
336
326
  return null;
337
327
  const t = this.t;
@@ -425,7 +415,7 @@ export class CoreAPI extends KitTypes {
425
415
  assign(left, value) {
426
416
  if (this.heldFunction(left.expression, left.name.text))
427
417
  return null;
428
- const owner = this.mixinOwn(left.name) ? null : (this.owner(left.expression) ?? this.inheritedOwner(left.expression, left.name));
418
+ const owner = this.mixinOwn(left.name) ? null : (this.owner(left.expression) ?? inheritedCoreOwner(left.expression, left.name, this.t.checker, (c) => this.t.kitRootOf(c)));
429
419
  if (!owner)
430
420
  return null;
431
421
  const t = this.t;
@@ -458,16 +448,6 @@ export class CoreAPI extends KitTypes {
458
448
  return assigned('nil');
459
449
  return assigned(this.toKit(t.coerce(value, t.typeOf(left)), m.type));
460
450
  }
461
- /** A core member read through a class of the app or a plugin that extends a core class (`this.isPassThroughParentEnabled` in a GridLayout subclass). */
462
- inheritedOwner(target, name) {
463
- const c = this.t.checker;
464
- const decl = c.getSymbolAtLocation(name)?.valueDeclaration;
465
- if (!decl || !isCoreDeclaration(decl))
466
- return null;
467
- const cls = c.getNonNullableType(c.getTypeAtLocation(target)).getSymbol()?.valueDeclaration;
468
- const root = cls && ts.isClassLike(cls) && !cls.getSourceFile().isDeclarationFile ? this.t.kitRootOf(cls) : null;
469
- return root ? { name: root, isStatic: false } : null;
470
- }
471
451
  /** A member a mixin class declares: the extension it becomes has it by name. */
472
452
  mixinOwn(name) {
473
453
  return isMixinOwnMember(name, this.t.checker, (s) => this.t.mixinOf(s));
@@ -523,7 +503,7 @@ export class CoreAPI extends KitTypes {
523
503
  throwingAccess(e) {
524
504
  if (this.mixinOwn(e.name))
525
505
  return false;
526
- const owner = (this.owner(e.expression) ?? this.inheritedOwner(e.expression, e.name))?.name;
506
+ const owner = (this.owner(e.expression) ?? inheritedCoreOwner(e.expression, e.name, this.t.checker, (c) => this.t.kitRootOf(c)))?.name;
527
507
  const m = owner ? kitMember(this.index, owner, e.name.text) : null;
528
508
  if (m && !e.questionDotToken && this.optionalKitValue(e.expression))
529
509
  return true;
@@ -549,7 +529,7 @@ export class CoreAPI extends KitTypes {
549
529
  const access = ts.isCallExpression(x) ? x.expression : x;
550
530
  if (ts.isOptionalChain(x) || !ts.isPropertyAccessExpression(access) || this.mixinOwn(access.name))
551
531
  return false;
552
- const owner = this.owner(access.expression) ?? this.inheritedOwner(access.expression, access.name);
532
+ const owner = this.owner(access.expression) ?? inheritedCoreOwner(access.expression, access.name, this.t.checker, (c) => this.t.kitRootOf(c));
553
533
  const m = !owner ? null : ts.isCallExpression(x) ? this.callMember(owner.name, access.name.text, x.arguments.length) : kitMember(this.index, owner.name, access.name.text);
554
534
  if (!m || m.kind !== (ts.isCallExpression(x) ? 'func' : 'var'))
555
535
  return false;
@@ -580,7 +560,7 @@ export class CoreAPI extends KitTypes {
580
560
  // A kit method's optional result (`SplitView.getInstance()`, `SplitViewBase | null`), which a non-strict app's typings give present.
581
561
  if (ts.isCallExpression(x) && ts.isPropertyAccessExpression(x.expression) && !x.expression.questionDotToken && !ts.isOptionalChain(x)) {
582
562
  const c = x.expression;
583
- const owner = this.mixinOwn(c.name) ? null : (this.owner(c.expression) ?? this.inheritedOwner(c.expression, c.name));
563
+ const owner = this.mixinOwn(c.name) ? null : (this.owner(c.expression) ?? inheritedCoreOwner(c.expression, c.name, this.t.checker, (k) => this.t.kitRootOf(k)));
584
564
  const m = owner ? this.callMember(owner.name, c.name.text, x.arguments.length) : null;
585
565
  if (m?.kind !== 'func' ||
586
566
  !/\?$/.test(m.type.trim()) ||
@@ -594,7 +574,7 @@ export class CoreAPI extends KitTypes {
594
574
  }
595
575
  if (!ts.isPropertyAccessExpression(x) || x.questionDotToken || ts.isOptionalChain(x))
596
576
  return false;
597
- const owner = this.mixinOwn(x.name) ? null : (this.owner(x.expression) ?? this.inheritedOwner(x.expression, x.name));
577
+ const owner = this.mixinOwn(x.name) ? null : (this.owner(x.expression) ?? inheritedCoreOwner(x.expression, x.name, this.t.checker, (k) => this.t.kitRootOf(k)));
598
578
  const m = owner ? kitMember(this.index, owner.name, x.name.text) : null;
599
579
  if (m?.kind !== 'var' ||
600
580
  !/\?$/.test(m.type.trim()) ||
@@ -663,7 +643,7 @@ export class CoreAPI extends KitTypes {
663
643
  if (e.expression.getText() === 'CoreTypes.AnimationCurve.cubicBezier' && isCoreDeclaration(this.t.resolve(e.expression.name)?.declarations?.[0])) {
664
644
  return `CubicBezierAnimationCurve(${e.arguments.map((a) => this.t.coerce(a, 'Double')).join(', ')})`;
665
645
  }
666
- const owner = this.mixinOwn(e.expression.name) ? null : (this.owner(e.expression.expression) ?? this.inheritedOwner(e.expression.expression, e.expression.name));
646
+ const owner = this.mixinOwn(e.expression.name) ? null : (this.owner(e.expression.expression) ?? inheritedCoreOwner(e.expression.expression, e.expression.name, this.t.checker, (k) => this.t.kitRootOf(k)));
667
647
  if (!owner)
668
648
  return null;
669
649
  const t = this.t;
@@ -242,11 +242,6 @@ export const declarationsMethods = {
242
242
  const read = ts.skipOuterExpressions(init, ts.OuterExpressionKinds.Parentheses);
243
243
  return (ts.isElementAccessExpression(read) || ts.isPropertyAccessExpression(read)) && isNamed(spelledType(this.typeOf(read.expression)), 'JSRecord<Any?>') ? 'Any?' : optionalType(t);
244
244
  },
245
- /** An `optionalVariable`'s initializer stored as the optional `type`: a read converting undefined gives that undefined. */
246
- heldStore(d, type) {
247
- const code = this.stored(d.initializer, d, type);
248
- return this.undefinedConverted(code) ?? code;
249
- },
250
245
  /** Whether a pattern steps its value's iterator (`patternIteration`). */
251
246
  patternIterated(name, init) {
252
247
  // A match reads its values as an array does.
@@ -250,6 +250,13 @@ export const exprStatementsMethods = {
250
250
  const call = `({ () ${tp ? 'throws ' : ''}-> ${v.type} in ${v.code} }())`;
251
251
  return this.marks.assignedCode('_', tp ? this.marks.tryCode(call) : call);
252
252
  }
253
+ if (step && ts.isIdentifier(e.operand)) {
254
+ const top = this.resolve(e.operand)?.valueDeclaration;
255
+ if (top && ts.isVariableDeclaration(top) && this.facts.tdzBindings().has(top) && !(top.parent.flags & ts.NodeFlags.Const)) {
256
+ const raw = (this.globalAlias(e.operand) ?? this.refName(e.operand)).replace(/`/g, '');
257
+ return this.marks.tryCode(`__tdz_set_${raw}(try __tdz_get_${raw}() ${step} 1)`);
258
+ }
259
+ }
253
260
  if (step && (this.isAny(e.operand) || isUntyped(spelledType(this.declaredTypeOf(e.operand)))))
254
261
  return `${this.lvalue(e.operand)} = ${RT.jsToNumber}(${this.expr(e.operand)}) ${step} 1`;
255
262
  const held = step ? this.optionalNumberOperand(e.operand) : null;
@@ -173,10 +173,6 @@ export const globalCallsMethods = {
173
173
  const call = `${this.loose(callee) ? `${RT.jsCallable}(${value}, ${swiftString(callee.text)})` : value}(${(!this.library && decl ? this.core.exportArgs(e, decl, args) : args).join(', ')})`;
174
174
  return !this.library && decl ? this.core.moduleCall(decl, call, this.typeOf(e), e) : call;
175
175
  },
176
- symbolName(e) {
177
- const t = this.checker.getTypeAtLocation(e);
178
- return (t.aliasSymbol ?? t.getSymbol())?.getName() ?? '';
179
- },
180
176
  /** A navigation (`$navigateTo(Page, { props })`) to a component, with the props its options give. */
181
177
  navigate(e, component, options) {
182
178
  const info = this.components.get(component);
@@ -1,7 +1,7 @@
1
1
  // Loose, lenient and tolerated reads as Swift: values non-strict code reads where its types say otherwise.
2
2
  import ts from 'typescript';
3
3
  import { balanced, functionParts, hasTopLevelArrow, isFunctionType, isOptional, splitTopLevel, swiftString, RT } from "./syntax.js";
4
- import { accessedDeclaration, evolvingElementContext, isSelf } from "../semantics/lang.js";
4
+ import { accessedDeclaration, evolvingElementContext, isSelf, untypedVariableInitializer } from "../semantics/lang.js";
5
5
  import { hasModifier, isWriteTarget, notIterable } from "../semantics/ast.js";
6
6
  import { rethrowUnlessRefused } from "../semantics/refusals.js";
7
7
  import { isUntyped, spelledType } from "../semantics/types.js";
@@ -296,10 +296,8 @@ export const lenientMethods = {
296
296
  },
297
297
  /** A variable declared without a type whose value is a read of a signal holding null (`const card = this.morning()`). */
298
298
  givenNullSignalValue(n) {
299
- const d = ts.isVariableDeclaration(n) ? n : ts.isIdentifier(n) ? (ts.isVariableDeclaration(n.parent) && n.parent.name === n ? n.parent : this.resolve(n)?.valueDeclaration) : undefined;
300
- if (!d || !ts.isVariableDeclaration(d) || d.type || !d.initializer)
301
- return false;
302
- return this.nullSignalRead(ts.skipOuterExpressions(d.initializer, ts.OuterExpressionKinds.Parentheses));
299
+ const init = untypedVariableInitializer(n, (id) => this.resolve(id));
300
+ return !!init && this.nullSignalRead(init);
303
301
  },
304
302
  nullSignalRead(e) {
305
303
  if (!ts.isCallExpression(e) || e.arguments.length || !['writable', 'input', 'computed'].includes(this.framework.signalKind(this.symbolName(e.expression)) ?? ''))
@@ -2,7 +2,7 @@
2
2
  import ts from 'typescript';
3
3
  import { ident, isMethodValue, optionalType, scriptLength, swiftString, RT } from "./syntax.js";
4
4
  import { forwardedSetter, inferredFunctionName, methodValues } from "../semantics/lang.js";
5
- import { thisNodes, declaresThis } from "../semantics/ast.js";
5
+ import { declaresThis } from "../semantics/ast.js";
6
6
  import { isUntyped, spelledType } from "../semantics/types.js";
7
7
  import { isStatic } from "../semantics/throws.js";
8
8
  export const methodValuesMethods = {
@@ -158,22 +158,4 @@ export const methodValuesMethods = {
158
158
  const fnName = !this.library ? inferredFunctionName(fn) : '';
159
159
  return fnName ? `${RT.jsMethodFunction}(${swiftString(fnName)}, ${scriptLength(fn)}, ${method})` : `(${method} as JSMethod)`;
160
160
  },
161
- /** Runs `body` with `this` in `fn` (and in the arrow functions inside it) read as `name`. */
162
- withThis(fn, name, untyped, body) {
163
- const nodes = thisNodes(fn);
164
- for (const n of nodes) {
165
- this.subst.set(n, name);
166
- if (untyped)
167
- this.untypedThis.add(n);
168
- }
169
- try {
170
- return body();
171
- }
172
- finally {
173
- for (const n of nodes) {
174
- this.subst.delete(n);
175
- this.untypedThis.delete(n);
176
- }
177
- }
178
- },
179
161
  };
@@ -150,6 +150,8 @@ export const modulesMethods = {
150
150
  }
151
151
  if ((library || this.appMembersByName) && st.members.some((m) => ts.isAccessor(m) && !isStatic(m)))
152
152
  later(() => this.prototypeAccessors(st));
153
+ if (!library && this.facts.prototypeClasses().has(st))
154
+ later(() => this.prototypeMethods(st));
153
155
  for (const line of inits)
154
156
  later(() => line);
155
157
  // Library mode: its statics and decorators run once it is defined.
@@ -159,11 +159,6 @@ export const namesMethods = {
159
159
  const d = sym?.valueDeclaration;
160
160
  return !!d && ts.isModuleDeclaration(d) && !d.getSourceFile().isDeclarationFile;
161
161
  },
162
- /** The kit class a mixin class (`applyMixins(View, [Extended])`) is applied to. */
163
- mixinOf(sym) {
164
- const d = sym?.valueDeclaration;
165
- return d && ts.isClassDeclaration(d) ? this.patterns.mixinTarget(d) : null;
166
- },
167
162
  /**
168
163
  * The name a translated declaration has: an import renamed (`install as
169
164
  * installGestureHandler`) names its export, and a module-level name that
@@ -183,10 +178,6 @@ export const namesMethods = {
183
178
  return e.text;
184
179
  return target.name;
185
180
  },
186
- /** A module-level function or variable's Swift name. */
187
- topName(decl, name) {
188
- return this.topNames().get(decl) ?? name;
189
- },
190
181
  /** `name` in `file`'s module: the shortest end of its path no other name has taken (`label__index`, else `label__two_index`). */
191
182
  uniqueTopName(name, file) {
192
183
  return moduleSuffixedName(name, file, this.topTaken);
@@ -29,7 +29,9 @@ export class NativeAPI {
29
29
  if (known)
30
30
  return /[\\/]objc![^\\/]*\.d\.ts$/.test(decl.getSourceFile().fileName) || tableDeclares(known, decl) ? known : null;
31
31
  // An app's own declaration of an SDK type newer than the published typings (`declare class UIArrangementViewController`
32
- // in a .d.ts of its own): the SDK module whose table has a type of that name.
32
+ // in a .d.ts of its own): the SDK module whose table has a type of that name (only when the Apple SDK is present).
33
+ if (process.platform !== 'darwin')
34
+ return null;
33
35
  const file = decl.getSourceFile();
34
36
  if (!file.isDeclarationFile || /[\\/]node_modules[\\/]/.test(file.fileName))
35
37
  return null;