@nstudio/nativescript-compiler 9.2.0-alpha.16 → 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.
- package/dist/kit/kit-index.js +9 -0
- package/dist/kotlin/access.js +7 -9
- package/dist/kotlin/arguments.js +2 -2
- package/dist/kotlin/class-declaration.js +20 -0
- package/dist/kotlin/components.js +2 -7
- package/dist/kotlin/core-api.js +2 -21
- package/dist/kotlin/declarations.js +86 -9
- package/dist/kotlin/functions.js +1 -4
- package/dist/kotlin/global-calls.js +1 -4
- package/dist/kotlin/literals.js +3 -6
- package/dist/kotlin/names.js +2 -0
- package/dist/kotlin/native/classfiles.js +2 -13
- package/dist/kotlin/operators.js +12 -6
- package/dist/kotlin/optional-chains.js +2 -9
- package/dist/kotlin/overrides.js +3 -15
- package/dist/kotlin/placement.js +1 -12
- package/dist/kotlin/statements.js +1 -13
- package/dist/kotlin/translator.js +2 -10
- package/dist/kotlin/type-tests.js +1 -1
- package/dist/kotlin/types.js +2 -19
- package/dist/program/core-facts.js +9 -0
- package/dist/semantics/facts.js +37 -1
- package/dist/semantics/lang.js +19 -0
- package/dist/semantics/lower.js +90 -0
- package/dist/semantics/lowering-methods.js +115 -3
- package/dist/semantics/marks.js +30 -0
- package/dist/semantics/refusals.js +12 -11
- package/dist/semantics/tdz.js +103 -8
- package/dist/swift/access.js +6 -8
- package/dist/swift/assignment.js +10 -2
- package/dist/swift/calls.js +7 -2
- package/dist/swift/classes.js +23 -9
- package/dist/swift/components.js +0 -4
- package/dist/swift/core-api.js +9 -29
- package/dist/swift/declarations.js +0 -5
- package/dist/swift/expression-statements.js +7 -0
- package/dist/swift/global-calls.js +0 -4
- package/dist/swift/lenient.js +3 -5
- package/dist/swift/method-values.js +1 -19
- package/dist/swift/modules.js +2 -0
- package/dist/swift/names.js +0 -9
- package/dist/swift/native/api.js +3 -1
- package/dist/swift/native/dispatch.js +2 -8
- package/dist/swift/operators.js +7 -6
- package/dist/swift/optional-chains.js +1 -8
- package/dist/swift/parameters.js +0 -4
- package/dist/swift/placement.js +1 -12
- package/dist/swift/results.js +0 -4
- package/dist/swift/statements.js +1 -13
- package/dist/swift/translator.js +0 -10
- package/dist/types/adapter-api.d.ts +3 -3
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Array.kt +53 -12
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/JSON.kt +30 -4
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Language.kt +33 -0
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Prototypes.kt +9 -1
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Values.kt +137 -28
- package/kit-apple/Sources/NativeScriptKit/Core/js-libs.easysax.easysax.swift +24 -6
- package/kit-apple/Sources/NativeScriptKit/Runtime/JSON.swift +151 -82
- package/kit-apple/Sources/NativeScriptKit/Runtime/Prototypes.swift +13 -1
- package/package.json +1 -1
package/dist/swift/calls.js
CHANGED
|
@@ -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
|
-
|
|
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. */
|
package/dist/swift/classes.js
CHANGED
|
@@ -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
|
package/dist/swift/components.js
CHANGED
|
@@ -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);
|
package/dist/swift/core-api.js
CHANGED
|
@@ -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) ??
|
|
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) ??
|
|
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) ??
|
|
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) ??
|
|
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) ??
|
|
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) ??
|
|
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) ??
|
|
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) ??
|
|
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);
|
package/dist/swift/lenient.js
CHANGED
|
@@ -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
|
|
300
|
-
|
|
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 {
|
|
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
|
};
|
package/dist/swift/modules.js
CHANGED
|
@@ -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.
|
package/dist/swift/names.js
CHANGED
|
@@ -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);
|
package/dist/swift/native/api.js
CHANGED
|
@@ -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;
|
|
@@ -3,6 +3,7 @@ import { CF_CLASSES, functionParts, RT } from "../syntax.js";
|
|
|
3
3
|
import { posted } from "./bridging.js";
|
|
4
4
|
import { lookupClass, lookupInit, nativeTable } from "./sdk.js";
|
|
5
5
|
import { compareText } from "../../program/order.js";
|
|
6
|
+
import { newerVersion } from "../../semantics/lang.js";
|
|
6
7
|
/** The member names script reads, writes and calls on `any` values in these files. */
|
|
7
8
|
export function untypedMembers(checker, files) {
|
|
8
9
|
const uses = new Map();
|
|
@@ -58,7 +59,7 @@ export function nativeDispatch(modules, uses, deploymentTarget, defined = {}, de
|
|
|
58
59
|
const hidden = new Map(candidates.filter(({ cls }) => named.get(cls.swift) === 1 && qualified(cls)).map(({ cls }) => [cls.swift, typeName(cls)]));
|
|
59
60
|
const typed = (type) => (hidden.size ? type.replace(/(?<![\w.])[A-Z]\w*/g, (n) => hidden.get(n) ?? n) : type);
|
|
60
61
|
const gets = [], sets = [], calls = [];
|
|
61
|
-
const guarded = (introduced, code) => (introduced &&
|
|
62
|
+
const guarded = (introduced, code) => (introduced && newerVersion(introduced, deploymentTarget) ? `if #available(iOS ${introduced}, *) { ${code} }` : code);
|
|
62
63
|
for (const [name, u] of [...uses].sort(([a], [b]) => compareText(a, b))) {
|
|
63
64
|
const get = [], set = [], call = [];
|
|
64
65
|
for (const { js, cls } of candidates) {
|
|
@@ -209,10 +210,3 @@ function fromNative(code, type) {
|
|
|
209
210
|
return `${code} as Any?`;
|
|
210
211
|
return `${RT.jsNativeResult}(${code})`;
|
|
211
212
|
}
|
|
212
|
-
function newer(version, than) {
|
|
213
|
-
const a = version.split('.').map(Number), b = than.split('.').map(Number);
|
|
214
|
-
for (let i = 0; i < Math.max(a.length, b.length); i++)
|
|
215
|
-
if ((a[i] ?? 0) !== (b[i] ?? 0))
|
|
216
|
-
return (a[i] ?? 0) > (b[i] ?? 0);
|
|
217
|
-
return false;
|
|
218
|
-
}
|
package/dist/swift/operators.js
CHANGED
|
@@ -12,6 +12,7 @@ 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";
|
|
15
|
+
import { 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: '&', or: '|', xor: '^' };
|
|
17
18
|
export const operatorsMethods = {
|
|
@@ -157,15 +158,15 @@ export const operatorsMethods = {
|
|
|
157
158
|
case K.GreaterThanToken:
|
|
158
159
|
case K.LessThanEqualsToken:
|
|
159
160
|
case K.GreaterThanEqualsToken: {
|
|
160
|
-
const
|
|
161
|
-
if (
|
|
162
|
-
return `${RT.jsCompare}(${l()}, ${r()}) ${
|
|
161
|
+
const plan = planRelational(op, this.isString(e.left), this.isString(e.right), this.isAny(e.left) || this.isAny(e.right));
|
|
162
|
+
if (plan.kind === 'string')
|
|
163
|
+
return `${RT.jsCompare}(${l()}, ${r()}) ${plan.op} 0`;
|
|
163
164
|
// An untyped side may hold a string, and two strings compare as strings.
|
|
164
|
-
if (
|
|
165
|
+
if (plan.kind === 'dynamic') {
|
|
165
166
|
const [a, b] = [this.coerce(e.left, 'Any?'), this.coerce(e.right, 'Any?')];
|
|
166
|
-
return op ===
|
|
167
|
+
return plan.op === '<' ? `(${RT.jsLessThan}(${a}, ${b}) == true)` : plan.op === '>' ? `(${RT.jsGreaterThan}(${a}, ${b}) == true)` : plan.op === '<=' ? `(${RT.jsGreaterThan}(${a}, ${b}) == false)` : `(${RT.jsLessThan}(${a}, ${b}) == false)`;
|
|
167
168
|
}
|
|
168
|
-
return this.marks.infix(this.toNumber(e.left),
|
|
169
|
+
return this.marks.infix(this.toNumber(e.left), plan.op, this.toNumber(e.right));
|
|
169
170
|
}
|
|
170
171
|
case K.QuestionQuestionToken: {
|
|
171
172
|
const t = this.typeOf(e);
|
|
@@ -379,14 +379,7 @@ export const optionalChainsMethods = {
|
|
|
379
379
|
* A string, number or boolean read `e` of type `t` as the optional it holds, where it converts undefined (a read, or
|
|
380
380
|
* a choice one of whose branches does); null where it converts nothing.
|
|
381
381
|
*/
|
|
382
|
-
convertedOptional
|
|
383
|
-
if (this.library)
|
|
384
|
-
return null;
|
|
385
|
-
const inner = ts.skipOuterExpressions(e);
|
|
386
|
-
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))))
|
|
387
|
-
return this.coerce(inner, optionalType(t));
|
|
388
|
-
return this.undefinedConverted(this.expr(ts.skipOuterExpressions(e, ts.OuterExpressionKinds.Parentheses)));
|
|
389
|
-
},
|
|
382
|
+
/* convertedOptional is installed from semantics/lowering-methods.ts */
|
|
390
383
|
/**
|
|
391
384
|
* App and plugin code's string, number or boolean read that converts undefined (`(x ?? "undefined")`): the optional it
|
|
392
385
|
* converts, for a use that takes undefined as it is (a comparison). Null for any other code.
|
package/dist/swift/parameters.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import ts from 'typescript';
|
|
3
3
|
import { assignsTo, ident, isFunctionType, isOptional, nullishType, optionalType, swiftString, RT } from "./syntax.js";
|
|
4
4
|
import { boundNames, hasModifier } from "../semantics/ast.js";
|
|
5
|
-
import { isConstant } from "../semantics/lang.js";
|
|
6
5
|
import { isUntyped, spelledType } from "../semantics/types.js";
|
|
7
6
|
export const parametersMethods = {
|
|
8
7
|
/** A parameter's Swift type as `params` declares it (an unwrapped optional written as optional, as a function type has it). */
|
|
@@ -131,9 +130,6 @@ export const parametersMethods = {
|
|
|
131
130
|
* A parameter Swift gives its default value itself: a constant, unless the method it overrides takes the parameter as optional.
|
|
132
131
|
* An untyped one is given its default in the body, where an explicit undefined (nil) takes it too and null does not.
|
|
133
132
|
*/
|
|
134
|
-
constantDefault(p) {
|
|
135
|
-
return !!p.initializer && isConstant(p.initializer) && !this.optionalDefaults.has(p) && !this.familyDefaultsDiffer(p) && !this.isAny(p.name) && !this.states.defaultTakesUndefined(p);
|
|
136
|
-
},
|
|
137
133
|
/** An app parameter whose default its body applies (`paramPrelude`): an argument is given as the optional it may be. */
|
|
138
134
|
filledDefault(d) {
|
|
139
135
|
return !this.library && !!d && ts.isParameter(d) && !!d.initializer && !d.dotDotDotToken && !this.templateParams && !d.getSourceFile().isDeclarationFile && !this.constantDefault(d);
|
package/dist/swift/placement.js
CHANGED
|
@@ -109,18 +109,7 @@ export const placementMethods = {
|
|
|
109
109
|
const t = contextual ? this.type(contextual, e) : ts.isFunctionLike(slot) ? this.returnTypeOf(slot) : ts.isIdentifier(slot.name ?? slot) ? this.typeOf(slot.name) : 'Any?';
|
|
110
110
|
return !/[?!]$/.test(t);
|
|
111
111
|
},
|
|
112
|
-
|
|
113
|
-
nullishCode(e) {
|
|
114
|
-
if (!ts.isCallExpression(e) && !ts.isPropertyAccessExpression(e))
|
|
115
|
-
return this.refName(e);
|
|
116
|
-
this.nullishCalls.add(e);
|
|
117
|
-
try {
|
|
118
|
-
return this.expr(e);
|
|
119
|
-
}
|
|
120
|
-
finally {
|
|
121
|
-
this.nullishCalls.delete(e);
|
|
122
|
-
}
|
|
123
|
-
},
|
|
112
|
+
/* nullishCode is installed from semantics/lowering-methods.ts */
|
|
124
113
|
/** An app generic class's instance where the same class with an `any` type argument is wanted: Swift's generic classes are invariant. */
|
|
125
114
|
checkAnyArgument(e, target) {
|
|
126
115
|
const want = /^(\w+)<(.+)>[?!]?$/.exec(target);
|
package/dist/swift/results.js
CHANGED
|
@@ -129,10 +129,6 @@ export const resultsMethods = {
|
|
|
129
129
|
}
|
|
130
130
|
return this.undefinedAs(slot.raw, t, slot.target);
|
|
131
131
|
},
|
|
132
|
-
/** The slot of the await `e` is, where its continuation holds the value optional. */
|
|
133
|
-
awaited(e) {
|
|
134
|
-
return this.awaitSlots.get(ts.skipOuterExpressions(e, ts.OuterExpressionKinds.Parentheses));
|
|
135
|
-
},
|
|
136
132
|
/** A local Swift holds optional though its type says a value (`const x = f()` of a call that may give nothing). */
|
|
137
133
|
heldOptionalLocal(e, type) {
|
|
138
134
|
e = ts.skipOuterExpressions(e, ts.OuterExpressionKinds.Parentheses);
|
package/dist/swift/statements.js
CHANGED
|
@@ -182,19 +182,7 @@ export const statementsMethods = {
|
|
|
182
182
|
});
|
|
183
183
|
return forward;
|
|
184
184
|
},
|
|
185
|
-
block
|
|
186
|
-
if (base === undefined)
|
|
187
|
-
base = this.indent;
|
|
188
|
-
const saved = this.indent;
|
|
189
|
-
this.indent = base + ' ';
|
|
190
|
-
try {
|
|
191
|
-
const body = this.statements(ts.isBlock(b) ? [...b.statements] : [b]);
|
|
192
|
-
return `{\n${body.join('\n')}\n${base}}`;
|
|
193
|
-
}
|
|
194
|
-
finally {
|
|
195
|
-
this.indent = saved;
|
|
196
|
-
}
|
|
197
|
-
},
|
|
185
|
+
/* block is installed from semantics/lowering-methods.ts */
|
|
198
186
|
stmt(s) {
|
|
199
187
|
try {
|
|
200
188
|
return HELD_LOSS ? atLossSite('swift', this, s, () => this.stmtChecked(s)) : this.stmtChecked(s);
|
package/dist/swift/translator.js
CHANGED
|
@@ -305,16 +305,6 @@ export class Translator {
|
|
|
305
305
|
}
|
|
306
306
|
freshCounts = null;
|
|
307
307
|
programFreshCounts = new Map();
|
|
308
|
-
nested(body) {
|
|
309
|
-
const saved = this.indent;
|
|
310
|
-
this.indent += ' ';
|
|
311
|
-
try {
|
|
312
|
-
return body();
|
|
313
|
-
}
|
|
314
|
-
finally {
|
|
315
|
-
this.indent = saved;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
308
|
/** Translates a function's body: no async region or loop of the enclosing function reaches into it. */
|
|
319
309
|
inFunction(returnType, body) {
|
|
320
310
|
const refined = this.refinedVersion;
|
|
@@ -622,8 +622,8 @@ export interface KotlinTranslatorView extends TranslatorView {
|
|
|
622
622
|
statics: string[];
|
|
623
623
|
};
|
|
624
624
|
}
|
|
625
|
-
/** A refusal's class:
|
|
626
|
-
export type RefusalClass = 'limit' | 'gap';
|
|
625
|
+
/** A refusal's class: fundamentally incompatible with an engine-free release (`limit`), technically possible but intentionally excluded by design (`excluded`), or not translated yet (`gap`). */
|
|
626
|
+
export type RefusalClass = 'limit' | 'excluded' | 'gap';
|
|
627
627
|
/** A kind of refusal: its title, suggestion and example, as a build's refusal report shows them. */
|
|
628
628
|
export interface RefusalKind {
|
|
629
629
|
class: RefusalClass;
|
|
@@ -636,7 +636,7 @@ export interface RefusalKind {
|
|
|
636
636
|
why?: string;
|
|
637
637
|
}
|
|
638
638
|
/** The ids of the compiler's own refusals, which a hook may refuse with too. */
|
|
639
|
-
export type CompilerRefusalId = 'proxy' | 'reflect' | 'eval' | 'function-constructor' | 'finalization-registry' | 'shared-array-buffer' | 'atomics' | 'with' | 'computed-import' | 'computed-require' | 'arguments-callee' | 'proto' | 'process-env' | 'undefined-constant' | 'shared-typed-copy' | 'shared-copy' | 'lone-surrogate' | 'generic-any-argument' | 'generic-field-overload' | 'generic-field-erased' | 'array-hole' | 'function-arguments' | 'builtin-prototype' | 'object-call' | 'library-member' | 'function-value' | 'other-receiver' | 'builtin-receiver' | 'function-new' | 'wrapper-object' | 'class-prototype' | 'function-this' | 'element-accessor' | 'private-receiver' | 'finally-jump' | 'class-expression' | 'named-function-expression' | 'unsupported-base' | '
|
|
639
|
+
export type CompilerRefusalId = 'proxy' | 'reflect' | 'eval' | 'function-constructor' | 'finalization-registry' | 'shared-array-buffer' | 'atomics' | 'with' | 'computed-import' | 'computed-require' | 'arguments-callee' | 'proto' | 'process-env' | 'undefined-constant' | 'shared-typed-copy' | 'shared-copy' | 'lone-surrogate' | 'generic-any-argument' | 'generic-field-overload' | 'generic-field-erased' | 'array-hole' | 'function-arguments' | 'builtin-prototype' | 'object-call' | 'library-member' | 'function-value' | 'other-receiver' | 'builtin-receiver' | 'function-new' | 'wrapper-object' | 'class-prototype' | 'function-this' | 'element-accessor' | 'private-receiver' | 'finally-jump' | 'class-expression' | 'named-function-expression' | 'unsupported-base' | 'delete-member' | 'index-type' | 'native' | 'internal' | 'unhandled';
|
|
640
640
|
/** The id of a refusal a build reports: the compiler's own, or its framework adapter's (`AdapterRefusalIds`). */
|
|
641
641
|
export type RefusalId = CompilerRefusalId | keyof AdapterRefusalIds;
|
|
642
642
|
/**
|