@nstudio/nativescript-compiler 9.2.0-alpha.16 → 9.2.0-alpha.18
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/README.md +3 -0
- package/dist/kit/kit-index.js +9 -0
- package/dist/kotlin/access.js +14 -15
- package/dist/kotlin/arguments.js +2 -2
- package/dist/kotlin/assignment.js +22 -13
- package/dist/kotlin/builtins.js +67 -0
- package/dist/kotlin/calls.js +3 -2
- package/dist/kotlin/class-declaration.js +16 -1
- package/dist/kotlin/class-methods.js +2 -2
- package/dist/kotlin/components.js +2 -7
- package/dist/kotlin/core-api.js +3 -22
- package/dist/kotlin/declarations.js +86 -9
- package/dist/kotlin/expression-statements.js +13 -1
- package/dist/kotlin/functions.js +2 -4
- package/dist/kotlin/global-calls.js +1 -4
- package/dist/kotlin/literals.js +3 -10
- package/dist/kotlin/names.js +6 -4
- package/dist/kotlin/native/api.js +1 -1
- package/dist/kotlin/native/classfiles.js +2 -13
- package/dist/kotlin/operators.js +36 -30
- package/dist/kotlin/optional-chains.js +3 -10
- package/dist/kotlin/overrides.js +5 -17
- package/dist/kotlin/placement.js +1 -12
- package/dist/kotlin/state-backend.js +6 -2
- package/dist/kotlin/statements.js +1 -13
- package/dist/kotlin/translator.js +3 -11
- package/dist/kotlin/type-tests.js +1 -1
- package/dist/kotlin/types.js +6 -23
- package/dist/program/core-facts.js +9 -0
- package/dist/semantics/classes.js +15 -0
- package/dist/semantics/facts.js +38 -2
- package/dist/semantics/lang.js +29 -0
- package/dist/semantics/lower.js +144 -0
- package/dist/semantics/lowering-methods.js +120 -3
- package/dist/semantics/marks.js +30 -0
- package/dist/semantics/placement.js +9 -3
- package/dist/semantics/refusals.js +12 -11
- package/dist/semantics/signals.js +11 -0
- package/dist/semantics/states/missing.js +7 -0
- package/dist/semantics/tdz.js +142 -8
- package/dist/semantics/throws.js +1 -1
- package/dist/semantics/translator-methods.js +1 -1
- package/dist/swift/access.js +13 -17
- package/dist/swift/assignment.js +30 -16
- package/dist/swift/calls.js +13 -5
- package/dist/swift/classes.js +22 -10
- package/dist/swift/components.js +3 -7
- package/dist/swift/control-flow.js +1 -1
- package/dist/swift/conversion.js +5 -2
- package/dist/swift/core-api.js +11 -31
- package/dist/swift/declarations.js +1 -6
- package/dist/swift/expression-statements.js +7 -0
- package/dist/swift/expressions.js +6 -2
- package/dist/swift/from-any.js +1 -1
- package/dist/swift/functions.js +5 -6
- package/dist/swift/global-calls.js +1 -5
- package/dist/swift/lenient.js +0 -7
- package/dist/swift/literals.js +8 -3
- package/dist/swift/method-values.js +1 -19
- package/dist/swift/modules.js +5 -3
- package/dist/swift/names.js +3 -12
- package/dist/swift/native/api.js +3 -1
- package/dist/swift/native/calls.js +1 -1
- package/dist/swift/native/dispatch.js +2 -8
- package/dist/swift/object-classes.js +84 -1
- package/dist/swift/operators.js +37 -34
- package/dist/swift/optional-chains.js +1 -8
- package/dist/swift/parameters.js +0 -4
- package/dist/swift/placement.js +5 -15
- package/dist/swift/results.js +0 -4
- package/dist/swift/state-backend.js +3 -2
- package/dist/swift/statements.js +1 -13
- package/dist/swift/static-calls.js +2 -3
- package/dist/swift/syntax.js +9 -5
- package/dist/swift/translator.js +1 -11
- package/dist/swift/type-facts.js +3 -3
- package/dist/swift/types.js +3 -3
- package/dist/targets/ios/build.js +1 -1
- package/dist/types/adapter-api.d.ts +3 -3
- package/kit-android/generated/kotlin/org/nativescript/kit/__Modules.kt +1 -0
- package/kit-android/generated/kotlin/org/nativescript/kit/__Objects.kt +525 -99
- package/kit-android/generated/kotlin/org/nativescript/kit/accessibility_accessibility_common.kt +2 -2
- package/kit-android/generated/kotlin/org/nativescript/kit/application_application_common.kt +29 -6
- package/kit-android/generated/kotlin/org/nativescript/kit/application_helpers_common.kt +14 -0
- package/kit-android/generated/kotlin/org/nativescript/kit/color_color_utils.kt +3 -3
- package/kit-android/generated/kotlin/org/nativescript/kit/css_mediaquery_index.kt +49 -1
- package/kit-android/generated/kotlin/org/nativescript/kit/data_observable_array_index.kt +0 -8
- package/kit-android/generated/kotlin/org/nativescript/kit/data_observable_index.kt +0 -16
- package/kit-android/generated/kotlin/org/nativescript/kit/data_virtual_array_index.kt +6 -4
- package/kit-android/generated/kotlin/org/nativescript/kit/http_http_request_index.kt +19 -7
- package/kit-android/generated/kotlin/org/nativescript/kit/http_http_request_internal_http_request_internal_common.kt +14 -0
- package/kit-android/generated/kotlin/org/nativescript/kit/http_http_request_internal_index.kt +19 -10
- package/kit-android/generated/kotlin/org/nativescript/kit/matrix_index.kt +17 -29
- package/kit-android/generated/kotlin/org/nativescript/kit/media_query_list_index.kt +144 -22
- package/kit-android/generated/kotlin/org/nativescript/kit/npm_css_what_src_parse.kt +8 -3
- package/kit-android/generated/kotlin/org/nativescript/kit/org.nativescript.NativeScriptLifecycleCallbacks.kt +2 -10
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_builder_index.kt +0 -2
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_bindable_expression_parser.kt +6 -10
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_properties_index.kt +531 -8
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_view_base_index.kt +0 -9
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_weak_event_listener_index.kt +3 -3
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_styling_style_index.kt +19 -0
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_styling_style_properties.kt +5 -2
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_styling_style_scope.kt +232 -174
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_text_view_text_view_common.kt +1 -1
- package/kit-android/generated/kotlin/org/nativescript/kit/utils_android_runtime_version.kt +75 -0
- package/kit-android/generated/manifest.json +21 -18
- package/kit-android/generated/source-lines.json +1 -1
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Array.kt +547 -51
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Intl.kt +1 -1
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/JSON.kt +52 -6
- 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/Strings.kt +32 -18
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Values.kt +137 -28
- package/kit-apple/Overlays/xml-free/Core/ui.builder.index.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity1.swift +14 -10
- package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity2.swift +3 -9
- package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity3Plus.swift +20 -21
- package/kit-apple/Sources/NativeScriptKit/Core/Object_eventName_object_index_section_view_ios_android.swift +5 -7
- package/kit-apple/Sources/NativeScriptKit/Core/Object_eventName_object_ios_android_.swift +130 -0
- package/kit-apple/Sources/NativeScriptKit/Core/Object_eventName_object_oldIndex_newIndex.swift +2 -4
- package/kit-apple/Sources/NativeScriptKit/Core/Object_specified_substituted_reads.swift +115 -0
- package/kit-apple/Sources/NativeScriptKit/Core/Object_substituted_values_reads.swift +113 -0
- package/kit-apple/Sources/NativeScriptKit/Core/Object_substituted_values_reads_.swift +113 -0
- package/kit-apple/Sources/NativeScriptKit/Core/application.application-common.swift +348 -330
- package/kit-apple/Sources/NativeScriptKit/Core/application.application.ios.swift +358 -359
- package/kit-apple/Sources/NativeScriptKit/Core/application.helpers-common.swift +47 -29
- package/kit-apple/Sources/NativeScriptKit/Core/connectivity.index.ios.swift +3 -1
- package/kit-apple/Sources/NativeScriptKit/Core/css-mediaquery.index.swift +95 -53
- package/kit-apple/Sources/NativeScriptKit/Core/css.CSS3Parser.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/css.parser.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/data.observable-array.index.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/file-system.file-system-access.ios.swift +52 -43
- package/kit-apple/Sources/NativeScriptKit/Core/http.http-request-internal.http-request-internal-common.swift +18 -0
- package/kit-apple/Sources/NativeScriptKit/Core/http.http-request-internal.index.ios.swift +66 -51
- package/kit-apple/Sources/NativeScriptKit/Core/image-source.index.ios.swift +67 -51
- package/kit-apple/Sources/NativeScriptKit/Core/js-libs.easysax.easysax.swift +24 -6
- package/kit-apple/Sources/NativeScriptKit/Core/kit-index.json +143 -32
- package/kit-apple/Sources/NativeScriptKit/Core/manifest.json +30 -19
- package/kit-apple/Sources/NativeScriptKit/Core/media-query-list.index.swift +190 -78
- package/kit-apple/Sources/NativeScriptKit/Core/native-window.native-window.ios.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/npm.css-what.src.parse.swift +205 -201
- package/kit-apple/Sources/NativeScriptKit/Core/npm.css-what.src.stringify.swift +41 -42
- package/kit-apple/Sources/NativeScriptKit/Core/npm.css-what.src.types.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/trace.index.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.animation.index.ios.swift +77 -65
- package/kit-apple/Sources/NativeScriptKit/Core/ui.builder.index.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.properties.index.swift +1272 -824
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view-base.index.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.index.ios.swift +8 -8
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.view-common.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.frame.frame-common.swift +2 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.frame.index.ios.swift +6 -6
- package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.flexbox-layout.index.ios.swift +22 -21
- package/kit-apple/Sources/NativeScriptKit/Core/ui.page.index.ios.swift +202 -188
- package/kit-apple/Sources/NativeScriptKit/Core/ui.repeater.index.swift +2 -6
- package/kit-apple/Sources/NativeScriptKit/Core/ui.split-view.index.ios.swift +3 -3
- package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.background.ios.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.clip-path-function.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.css-animation-parser.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.css-selector.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.font-common.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.style-scope.swift +869 -838
- package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.style.index.swift +46 -31
- package/kit-apple/Sources/NativeScriptKit/Core/ui.text-base.formatted-string.swift +1 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.text-view.text-view-common.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.index.ios.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.modal-transition.ios.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.page-transition.ios.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.shared-transition-helper.ios.swift +17 -17
- package/kit-apple/Sources/NativeScriptKit/Core/utils.android-runtime-version.swift +77 -0
- package/kit-apple/Sources/NativeScriptKit/Core/utils.debug-source.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/xhr.index.swift +62 -61
- package/kit-apple/Sources/NativeScriptKit/Runtime/Array.swift +4 -0
- package/kit-apple/Sources/NativeScriptKit/Runtime/Dynamic.swift +2 -0
- package/kit-apple/Sources/NativeScriptKit/Runtime/Interop.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Runtime/Intl.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Runtime/Iterators.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Runtime/JSON.swift +413 -73
- package/kit-apple/Sources/NativeScriptKit/Runtime/Lowering.swift +3 -2
- package/kit-apple/Sources/NativeScriptKit/Runtime/Prototypes.swift +14 -1
- package/kit-apple/Sources/NativeScriptKit/Runtime/Symbol.swift +1 -0
- package/kit-apple/Sources/NativeScriptKit/Runtime/Values.swift +1 -0
- package/kit-apple/Sources/NativeScriptKit/Runtime/Views.swift +2 -0
- package/package.json +2 -2
|
@@ -548,7 +548,7 @@ export const frontMethods = traceMethods('front', {
|
|
|
548
548
|
// JavaScript's assertion converts nothing: an empty value asserted to an array is still empty where it is read.
|
|
549
549
|
if (isPrimitive(t) || t.kind === 'array')
|
|
550
550
|
return isUntyped(from) ? e : null;
|
|
551
|
-
return isUntyped(from) && this.untypedCastChecks(e, t) ? e : null;
|
|
551
|
+
return isUntyped(from) && this.states.backend.untypedCastChecks(e, t) ? e : null;
|
|
552
552
|
}
|
|
553
553
|
catch (err) {
|
|
554
554
|
rethrowUnlessRefused(err);
|
package/dist/swift/access.js
CHANGED
|
@@ -6,8 +6,8 @@ import { mathFunctionValue } from "../semantics/apis/math.js";
|
|
|
6
6
|
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
|
-
import {
|
|
10
|
-
import { elementReceiverCell, keyName,
|
|
9
|
+
import { escapingFunction, functionParts, hasTopLevelArrow, ident, identPath, isFunctionType, isOptional, openSwiftChain, optionalType, splitTopLevel, swiftString, RT, lenientReader } from "./syntax.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";
|
|
@@ -420,17 +420,19 @@ export const accessMethods = {
|
|
|
420
420
|
},
|
|
421
421
|
/** App code's indexed receiver Swift holds optional, outside an optional chain: JavaScript's TypeError where it is missing. */
|
|
422
422
|
elementReceiver(e, target) {
|
|
423
|
-
if (this.library || e.questionDotToken || ts.isOptionalChain(e)
|
|
423
|
+
if (this.library || e.questionDotToken || ts.isOptionalChain(e))
|
|
424
424
|
return target;
|
|
425
|
+
// A compound assignment or update reads the element first.
|
|
426
|
+
const set = ts.isBinaryExpression(e.parent) && e.parent.operatorToken.kind === ts.SyntaxKind.EqualsToken && e.parent.left === e;
|
|
425
427
|
const cell = elementReceiverCell(this.receivers, e);
|
|
426
428
|
if (cell.cell === 'present')
|
|
427
|
-
return this.marks.ownTried(this.receiverCode(cell, keyName(e.argumentExpression)));
|
|
429
|
+
return this.marks.ownTried(this.receiverCode(cell, keyName(e.argumentExpression), set));
|
|
430
|
+
if (this.marks.isUnwrap(target))
|
|
431
|
+
return target;
|
|
428
432
|
if (!this.typeOf(e.expression).endsWith('?') && (isWriteTarget(e) || !this.widenedParameterRead(ts.skipOuterExpressions(e.expression, ts.OuterExpressionKinds.Parentheses))))
|
|
429
433
|
return target;
|
|
430
434
|
const k = e.argumentExpression;
|
|
431
435
|
const key = swiftString(ts.isStringLiteralLike(k) || ts.isNumericLiteral(k) ? k.text : k.getText());
|
|
432
|
-
// A compound assignment or update reads the element first.
|
|
433
|
-
const set = ts.isBinaryExpression(e.parent) && e.parent.operatorToken.kind === ts.SyntaxKind.EqualsToken && e.parent.left === e;
|
|
434
436
|
return this.marks.ownTried(this.marks.helper('jsUnwrap', target, set ? `, setting: ${key}` : `, ${key}${onlyNull(this.checker.getTypeAtLocation(e.expression)) ? ', null: true' : ''}`));
|
|
435
437
|
},
|
|
436
438
|
/** A receiver that can be missing though its type says not (`x!`, `items[i]`): JavaScript's TypeError when it is. */
|
|
@@ -438,10 +440,12 @@ export const accessMethods = {
|
|
|
438
440
|
const x = ts.skipOuterExpressions(target, ts.OuterExpressionKinds.Parentheses);
|
|
439
441
|
if (nullishField(this, x) && !this.subst.has(x) && !receiverSlot(target, key).chained)
|
|
440
442
|
return this.marks.ownTried(`${this.nullishCode(x)}.present(${this.states.nullishMemberKey(x).set ? 'setting: ' : ''}${swiftString(key)})`);
|
|
441
|
-
|
|
443
|
+
const p = target.parent;
|
|
444
|
+
const set = ts.isPropertyAccessExpression(p) && ts.isBinaryExpression(p.parent) && p.parent.operatorToken.kind === ts.SyntaxKind.EqualsToken && p.parent.left === p;
|
|
445
|
+
return this.receiverCode(receiverCell(this.receivers, receiverSlot(target, key)), key, set);
|
|
442
446
|
},
|
|
443
447
|
/** A receiver cell as Swift writes it: null where the access reads it as it is. */
|
|
444
|
-
receiverCode(c, key) {
|
|
448
|
+
receiverCode(c, key, set = false) {
|
|
445
449
|
if (c.cell === 'chained') {
|
|
446
450
|
// Swift's `?.` carries the chain on through the receiver's own check.
|
|
447
451
|
const code = this.maybeUndefined(c.receiver) ?? this.expr(c.receiver);
|
|
@@ -451,7 +455,7 @@ export const accessMethods = {
|
|
|
451
455
|
throw this.error(c.receiver, `an optional chain's link read past it as \`${open}\``);
|
|
452
456
|
return `${open}.${RT.jsUnwrap}(${swiftString(key)}${c.isNull ? ', null: true' : ''})`;
|
|
453
457
|
}
|
|
454
|
-
return c.cell === 'asIs' ? null : `${RT.jsUnwrap}(${c.code}, ${swiftString(key)}${c.isNull ? ', null: true' : ''})`;
|
|
458
|
+
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
459
|
},
|
|
456
460
|
elementAccess(e) {
|
|
457
461
|
this.refuseProto(e);
|
|
@@ -610,10 +614,6 @@ export const accessMethods = {
|
|
|
610
614
|
}
|
|
611
615
|
return this.returnTypeOf(decl);
|
|
612
616
|
},
|
|
613
|
-
/** `assertedUntyped`'s cast: strict code's, to a class or shape whose checked conversion can fail. */
|
|
614
|
-
untypedCastChecks(e, t) {
|
|
615
|
-
return !this.lenient && this.isObjectRef(e) && this.castChecks(spell(t));
|
|
616
|
-
},
|
|
617
617
|
/** An `assertedUntyped` assertion read as the optional it may be: missing where the value is undefined or null. */
|
|
618
618
|
/** `x as Iterable<T>` of a value not held as one: whatever x holds iterated, as GetIterator does where it is iterated. */
|
|
619
619
|
assertedIterable(e) {
|
|
@@ -650,10 +650,6 @@ export const accessMethods = {
|
|
|
650
650
|
heldMissing(e) {
|
|
651
651
|
return this.marks.isUnwrap(this.expr(e)) || this.looseObjectRead(e) || this.widenedParameterRead(e) || /[?!]$/.test(this.declaredTypeOf(e) ?? '') ? this.observe(e, 'asIs') : null;
|
|
652
652
|
},
|
|
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
653
|
/** A read `observedAsIs` (`instanceof`'s left): the optional it may be, never unwrapped. */
|
|
658
654
|
observed(e) {
|
|
659
655
|
if (this.library || this.lenient)
|
package/dist/swift/assignment.js
CHANGED
|
@@ -8,27 +8,33 @@ import { isArrayLengthWrite } from "../semantics/throws.js";
|
|
|
8
8
|
import { byKey } from "../semantics/spelled.js";
|
|
9
9
|
import { isKit, isUntyped, spelledType } from "../semantics/types.js";
|
|
10
10
|
import { untypedUnary } from "../semantics/apis/operators.js";
|
|
11
|
+
import { planUnary } from "../semantics/lower.js";
|
|
11
12
|
export const assignmentMethods = {
|
|
12
13
|
prefix(e) {
|
|
13
14
|
const K = ts.SyntaxKind;
|
|
14
15
|
const thrown = untypedUnary(this, e);
|
|
15
16
|
if (thrown)
|
|
16
17
|
return thrown;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
const unary = planUnary(e.operator, this.typeOf(e.operand) === 'JSBigInt');
|
|
19
|
+
if (unary) {
|
|
20
|
+
switch (unary.kind) {
|
|
21
|
+
case 'not': {
|
|
22
|
+
const cell = negatedCell(this.conditions, e.operand);
|
|
23
|
+
const operand = cell.step === 'bool' ? this.expr(cell.e) : this.cond(e.operand, cell);
|
|
24
|
+
return negation(operand);
|
|
25
|
+
}
|
|
26
|
+
// `-0` is negative zero; Swift reads the literal `-0` as an integer zero.
|
|
27
|
+
case 'negate':
|
|
28
|
+
if (unary.bigInt)
|
|
29
|
+
return `(-${this.expr(e.operand)})`;
|
|
30
|
+
return ts.isNumericLiteral(e.operand) ? (Number(e.operand.text) === 0 ? '-0.0' : `-${this.expr(e.operand)}`) : `-${this.toNumber(e.operand)}`;
|
|
31
|
+
case 'plus':
|
|
32
|
+
return this.toNumber(e.operand);
|
|
33
|
+
case 'bitNot':
|
|
34
|
+
return unary.bigInt ? `(~${this.expr(e.operand)})` : `${RT.jsBitNot}(${this.toNumber(e.operand)})`;
|
|
22
35
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (this.typeOf(e.operand) === 'JSBigInt')
|
|
26
|
-
return `(-${this.expr(e.operand)})`;
|
|
27
|
-
return ts.isNumericLiteral(e.operand) ? (Number(e.operand.text) === 0 ? '-0.0' : `-${this.expr(e.operand)}`) : `-${this.toNumber(e.operand)}`;
|
|
28
|
-
case K.PlusToken:
|
|
29
|
-
return this.toNumber(e.operand);
|
|
30
|
-
case K.TildeToken:
|
|
31
|
-
return this.typeOf(e.operand) === 'JSBigInt' ? `(~${this.expr(e.operand)})` : `${RT.jsBitNot}(${this.toNumber(e.operand)})`;
|
|
36
|
+
}
|
|
37
|
+
switch (e.operator) {
|
|
32
38
|
case K.PlusPlusToken:
|
|
33
39
|
case K.MinusMinusToken: {
|
|
34
40
|
const member = this.untypedMember(e.operand);
|
|
@@ -168,11 +174,19 @@ export const assignmentMethods = {
|
|
|
168
174
|
return `${fnObject}[jsKey: ${swiftString(left.name.text)}] = ${this.stored(right, left, 'Any?', checks)}`;
|
|
169
175
|
if (fnObject)
|
|
170
176
|
throw this.error(e, `${ts.tokenToString(e.operatorToken.kind)} on a function's property`);
|
|
171
|
-
if (
|
|
177
|
+
if (ts.isIdentifier(left)) {
|
|
172
178
|
const decl = this.resolve(left)?.valueDeclaration;
|
|
173
179
|
if (decl && ts.isVariableDeclaration(decl) && this.facts.tdzBindings().has(decl) && !(decl.parent.flags & ts.NodeFlags.Const)) {
|
|
174
180
|
const raw = this.refName(left).replace(/`/g, '');
|
|
175
|
-
|
|
181
|
+
const lt = this.declaredTypeOf(left) ?? this.typeOf(left);
|
|
182
|
+
if (e.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
|
|
183
|
+
return `__tdz_set_${raw}(${this.stored(right, left, lt, checks)})`;
|
|
184
|
+
}
|
|
185
|
+
const op = { [ts.SyntaxKind.PlusEqualsToken]: '+', [ts.SyntaxKind.MinusEqualsToken]: '-', [ts.SyntaxKind.AsteriskEqualsToken]: '*', [ts.SyntaxKind.SlashEqualsToken]: '/' }[e.operatorToken.kind];
|
|
186
|
+
if (op) {
|
|
187
|
+
const rhs = op === '+' && lt === 'String' ? this.str(right) : this.coerce(right, lt);
|
|
188
|
+
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 }()`);
|
|
189
|
+
}
|
|
176
190
|
}
|
|
177
191
|
}
|
|
178
192
|
const nullish = e.operatorToken.kind === ts.SyntaxKind.EqualsToken && ts.isIdentifier(left) ? this.states.nullishRead(left) : null;
|
package/dist/swift/calls.js
CHANGED
|
@@ -54,7 +54,7 @@ export const callsMethods = {
|
|
|
54
54
|
return this.marks.ownTried(`${own !== undefined && this.props.has(own) ? `self.${ident(own)}` : this.expr(callee)}.requiredValue()`);
|
|
55
55
|
if (own !== undefined && (this.props.has(own) || this.signalFields.has(own)))
|
|
56
56
|
return `self.${ident(own)}.value`;
|
|
57
|
-
if (this.framework.signalKind(this.symbolName(callee)) === 'computed' && this.
|
|
57
|
+
if (this.framework.signalKind(this.symbolName(callee)) === 'computed' && this.isSwiftComputedProperty(callee))
|
|
58
58
|
return this.expr(callee);
|
|
59
59
|
return plain(`${this.expr(callee)}.value`);
|
|
60
60
|
},
|
|
@@ -226,7 +226,7 @@ export const callsMethods = {
|
|
|
226
226
|
const builtin = method === 'call' || method === 'apply' ? this.builtinPrototypeCall(method, target, e) : null;
|
|
227
227
|
if (builtin)
|
|
228
228
|
return builtin;
|
|
229
|
-
if (['call', 'apply', 'bind'].includes(method) && isLibDeclaration(this.checker.getResolvedSignature(e)?.getDeclaration()) && functionParts(this.typeOf(target).replace(/^\((.*)\)[?!]$/, '$1')))
|
|
229
|
+
if (['call', 'apply', 'bind'].includes(method) && isLibDeclaration(this.checker.getResolvedSignature(e)?.getDeclaration()) && (functionParts(this.typeOf(target).replace(/^\((.*)\)[?!]$/, '$1')) || (ts.isPropertyAccessExpression(target) && target.expression.getText() === 'Function.prototype' && ['call', 'apply', 'bind'].includes(target.name.text))))
|
|
230
230
|
return this.functionMethod(method, target, e);
|
|
231
231
|
if ((method === 'call' || method === 'apply') && this.programPrototypeMethod(target) && isLibDeclaration(this.checker.getResolvedSignature(e)?.getDeclaration()))
|
|
232
232
|
return this.functionMethod(method, target, e);
|
|
@@ -260,7 +260,7 @@ export const callsMethods = {
|
|
|
260
260
|
}
|
|
261
261
|
// A field holding a function untyped (`private _resolve;`): called with the object as `this`.
|
|
262
262
|
const field = this.resolve(callee.name)?.valueDeclaration;
|
|
263
|
-
if (this.isAny(callee) && field && (ts.isPropertyDeclaration(field) || ts.isPropertySignature(field) || ts.isParameter(field))) {
|
|
263
|
+
if (this.isAny(callee) && field && (ts.isPropertyDeclaration(field) || ts.isPropertySignature(field) || (ts.isMethodSignature(field) && !isLibDeclaration(field)) || ts.isParameter(field))) {
|
|
264
264
|
const args = e.arguments.some(ts.isSpreadElement) ? `${this.packed(e.arguments, 'JSArray<Any?>', this.restSlot(e, 'Any?'))}.storage` : `[${e.arguments.map((a) => this.restArgument(e, a, 'Any?')).join(', ')}]`;
|
|
265
265
|
const code = `${RT.jsCallValue}(${this.expr(callee)}, this: ${this.coerce(target, 'Any?')}, optional: ${!!e.questionDotToken}, ${args})`;
|
|
266
266
|
const t = this.typeOf(e);
|
|
@@ -296,6 +296,9 @@ export const callsMethods = {
|
|
|
296
296
|
return this.ignoringThisArg(e, target, () => this.call(typedThisArg));
|
|
297
297
|
if (isKit(spelledType(t), 'JSArray')) {
|
|
298
298
|
// `observers?.find(…)` on an array TypeScript types as present, which lenient code may hold as undefined: cast to optional, valid either way.
|
|
299
|
+
const checked = !callee.questionDotToken && !ts.isOptionalChain(callee) ? this.receiver(target, method) : null;
|
|
300
|
+
if (checked)
|
|
301
|
+
return this.arrayMethod(method, target, e, '', this.marks.ownTried(checked));
|
|
299
302
|
const asserted = callee.questionDotToken ? null : assertedReceiverCell(this.receivers, target, method);
|
|
300
303
|
if (asserted?.cell === 'present')
|
|
301
304
|
return this.arrayMethod(method, target, e, q, this.marks.ownTried(this.receiverCode(asserted, method)));
|
|
@@ -478,8 +481,13 @@ export const callsMethods = {
|
|
|
478
481
|
return `${maybe ? `${RT.jsCallee}(${maybe})` : this.expr(callee)}(${this.args(e).join(', ')})`;
|
|
479
482
|
}
|
|
480
483
|
// `handler!(…)`: the function, where undefined is not a function.
|
|
481
|
-
if (ts.isNonNullExpression(callee))
|
|
482
|
-
|
|
484
|
+
if (ts.isNonNullExpression(callee)) {
|
|
485
|
+
if (!/[?!]$/.test(this.typeOf(callee.expression)))
|
|
486
|
+
return this.call(ts.factory.updateCallExpression(e, callee.expression, e.typeArguments, e.arguments));
|
|
487
|
+
const label = ts.isPropertyAccessExpression(callee.expression) || ts.isIdentifier(callee.expression) ? callee.expression.getText() : null;
|
|
488
|
+
const fnType = this.typeOf(callee.expression).replace(/^\((.*)\)[?!]$/, '$1').replace(/[?!]$/, '');
|
|
489
|
+
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(', ')})`;
|
|
490
|
+
}
|
|
483
491
|
throw this.error(e, 'call');
|
|
484
492
|
},
|
|
485
493
|
/** An Error (or a subclass the program declares without its own toString), which Swift holds as a JSError. */
|
package/dist/swift/classes.js
CHANGED
|
@@ -8,7 +8,7 @@ import { isLibDeclaration, withoutDefault, isWriteTarget } from "../semantics/as
|
|
|
8
8
|
import { isAsync, isStatic } from "../semantics/throws.js";
|
|
9
9
|
import { isCoreDeclaration, isShimDeclaration } from "../program/core-facts.js";
|
|
10
10
|
import { isNativePropertyDecorator } from "../program/patterns.js";
|
|
11
|
-
import { prototypeDecorated } from "../semantics/classes.js";
|
|
11
|
+
import { prototypeDecorated, prototypeMethodList } from "../semantics/classes.js";
|
|
12
12
|
import { isKit, isUntyped, spelledType } from "../semantics/types.js";
|
|
13
13
|
export const classesMethods = {
|
|
14
14
|
/** A class's memo field (`computed(fn)`): the memo the instance makes when it is first read, and the field reading its value (a throw rethrown to each reader). */
|
|
@@ -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,27 @@ 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 plugin = this.pluginFiles.has(cls.getSourceFile().fileName);
|
|
350
|
+
const inherited = plugin ? this.classPlan(cls).inherited : null;
|
|
351
|
+
const kitRoot = plugin ? this.kitRootOf(cls) : null;
|
|
352
|
+
const entries = [];
|
|
353
|
+
for (const { method: m, key } of prototypeMethodList(cls, {
|
|
354
|
+
skip: (m, key) => isAsync(m) || m.parameters.some((p) => p.dotDotDotToken) || this.readsArguments(m) || (plugin && !inherited.has(key) && !(kitRoot && this.core.kitMember(kitRoot, key)) && !this.facts.isNamed(key)),
|
|
355
|
+
})) {
|
|
356
|
+
const sig = this.emittedSignature(m);
|
|
357
|
+
const args = sig.params.map((p, k) => this.throwingConverts(() => this.presentFromAny(`${RT.jsArg}(__a, ${k})`, p.type, true, true)));
|
|
358
|
+
const call = this.marks.tryIf(this.throwsInfo.fn(m), `__o.${ident(key)}(${args.join(', ')})`);
|
|
359
|
+
const body = sig.ret === 'Void' ? `${call}; return nil` : `return ${this.convert(call, sig.ret, 'Any?')}`;
|
|
360
|
+
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))`);
|
|
361
|
+
}
|
|
362
|
+
return entries.join('\n');
|
|
363
|
+
},
|
|
346
364
|
/** 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
365
|
classDefinition(cls) {
|
|
348
366
|
const i = this.indent;
|
|
@@ -452,12 +470,6 @@ export const classesMethods = {
|
|
|
452
470
|
const cls = (t.isTypeParameter() ? (t.getConstraint() ?? t) : t).getSymbol()?.valueDeclaration;
|
|
453
471
|
return !!cls && ts.isClassLike(cls) && !!this.kitRootOf(cls);
|
|
454
472
|
},
|
|
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
473
|
/**
|
|
462
474
|
* A method overriding NativeScriptKit's: the kit's Swift signature, the
|
|
463
475
|
* TypeScript body seeing its own types; what it throws is reported, as an
|
package/dist/swift/components.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import ts from 'typescript';
|
|
3
3
|
import { resultSlot } from "../semantics/placement.js";
|
|
4
4
|
import { capturesThis, escapingParam, ident, isFunctionType, isMethodValue, isOptional, metatype, nullishType, optionalType, swiftString, withoutThenables, RT } from "./syntax.js";
|
|
5
|
-
import { equalOption } from "../semantics/signals.js";
|
|
5
|
+
import { equalOption, isReadonlySignalProperty } from "../semantics/signals.js";
|
|
6
6
|
import { isTemplateMethod } from "../semantics/trust.js";
|
|
7
7
|
import { extendsHeritage, hasModifier, nonSuperStatements } from "../semantics/ast.js";
|
|
8
8
|
import { nullableTypeNode, resultsAreUndefinedElements } from "../semantics/lang.js";
|
|
@@ -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);
|
|
@@ -360,7 +356,7 @@ export const componentMethods = {
|
|
|
360
356
|
return this.throwsInfo.fn(held.arguments[0]) ? ` var ${name}: ${t} {\n get throws { try ${read} }\n }` : ` var ${name}: ${t} { ${read} }`;
|
|
361
357
|
},
|
|
362
358
|
/** Whether a `Signal<T>` node is lowered as a Swift computed property (`var x: T`) rather than a `Signal<T>` instance. */
|
|
363
|
-
|
|
359
|
+
isSwiftComputedProperty(n) {
|
|
364
360
|
if (ts.isIdentifier(n) && this.moduleComputed(n))
|
|
365
361
|
return true;
|
|
366
362
|
const decl = ts.isIdentifier(n) || ts.isPropertyAccessExpression(n) ? this.resolve(n)?.valueDeclaration : n;
|
|
@@ -372,7 +368,7 @@ export const componentMethods = {
|
|
|
372
368
|
}
|
|
373
369
|
if (ts.isPropertyDeclaration(decl) && ts.isClassDeclaration(decl.parent) && !this.pluginFiles.has(decl.getSourceFile().fileName) && decl.initializer) {
|
|
374
370
|
const callee = this.calleeName(decl.initializer);
|
|
375
|
-
if (
|
|
371
|
+
if (isReadonlySignalProperty(decl, this.checker, this.framework, callee) || (ts.isIdentifier(decl.initializer) && !!this.moduleComputed(decl.initializer)))
|
|
376
372
|
return true;
|
|
377
373
|
}
|
|
378
374
|
return false;
|
|
@@ -160,7 +160,7 @@ export const controlFlowMethods = {
|
|
|
160
160
|
let code;
|
|
161
161
|
const block = s.catchClause ? this.block(s.tryBlock) : '';
|
|
162
162
|
// A catch whose try block cannot throw never runs: the block alone.
|
|
163
|
-
if (s.catchClause && !this.throwsInfo.statements([s.tryBlock])) {
|
|
163
|
+
if (s.catchClause && !this.throwsInfo.statements([s.tryBlock]) && !/\btry\s/.test(block)) {
|
|
164
164
|
this.catchless.add(s.tryBlock);
|
|
165
165
|
code = this.scope(s.tryBlock);
|
|
166
166
|
}
|
package/dist/swift/conversion.js
CHANGED
|
@@ -146,8 +146,11 @@ export const conversionMethods = {
|
|
|
146
146
|
return null;
|
|
147
147
|
// Given to the language's or a platform's API (`list.map(f)`, which rethrows what `f` may throw), which never compares it: as it is.
|
|
148
148
|
if ((ts.isCallExpression(p) || ts.isNewExpression(p)) && p.arguments?.includes(e)) {
|
|
149
|
-
const
|
|
150
|
-
|
|
149
|
+
const sig = this.checker.getResolvedSignature(p);
|
|
150
|
+
const callee = sig?.getDeclaration();
|
|
151
|
+
const paramDecl = sig?.getParameters()[p.arguments.indexOf(e)]?.valueDeclaration;
|
|
152
|
+
const paramType = paramDecl ? this.checker.getTypeAtLocation(paramDecl) : undefined;
|
|
153
|
+
if (callee && callee.getSourceFile().isDeclarationFile && !isCoreDeclaration(callee) && paramType && this.checker.getNonNullableType(paramType).getCallSignatures().length > 0)
|
|
151
154
|
return null;
|
|
152
155
|
}
|
|
153
156
|
return decl;
|
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;
|
|
@@ -533,7 +513,7 @@ export class CoreAPI extends KitTypes {
|
|
|
533
513
|
return m?.kind === 'var' && !!m.throws;
|
|
534
514
|
}
|
|
535
515
|
/** A kit property's value or method's result the kit holds optional, read where core's typings say present. */
|
|
536
|
-
|
|
516
|
+
swiftKitNil(x) {
|
|
537
517
|
try {
|
|
538
518
|
x = ts.skipOuterExpressions(x, ts.OuterExpressionKinds.Parentheses);
|
|
539
519
|
if (ts.isCallExpression(x) && ts.isIdentifier(x.expression)) {
|
|
@@ -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;
|
|
@@ -568,7 +548,7 @@ export class CoreAPI extends KitTypes {
|
|
|
568
548
|
optionalKitValue(x) {
|
|
569
549
|
while (ts.isParenthesizedExpression(x))
|
|
570
550
|
x = x.expression;
|
|
571
|
-
if (!this.t.lenient && !this.t.library && this.
|
|
551
|
+
if (!this.t.lenient && !this.t.library && this.swiftKitNil(x))
|
|
572
552
|
return true;
|
|
573
553
|
if (ts.isIdentifier(x)) {
|
|
574
554
|
const sym = this.t.resolve(x);
|
|
@@ -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.
|
|
@@ -263,7 +258,7 @@ export const declarationsMethods = {
|
|
|
263
258
|
if (!js) {
|
|
264
259
|
const value = this.coerce(init, this.typeOf(init));
|
|
265
260
|
// What the kit holds optional though the declarations say present (`getActualSize()`): JavaScript's TypeError destructuring undefined.
|
|
266
|
-
if (ts.isObjectBindingPattern(name) && this.marks.isUnwrap(value) && !this.lenient && this.core.
|
|
261
|
+
if (ts.isObjectBindingPattern(name) && this.marks.isUnwrap(value) && !this.lenient && this.core.swiftKitNil(init))
|
|
267
262
|
return `: ${this.typeOf(init)} = try ${this.required(init, this.marks.unwrapInner(value))}`;
|
|
268
263
|
return `: ${this.typeOf(init)} = ${this.marks.tryBefore(this.tryPrefix(init), value)}`;
|
|
269
264
|
}
|
|
@@ -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;
|
|
@@ -43,7 +43,7 @@ export const expressionsMethods = {
|
|
|
43
43
|
cond(e, cell) {
|
|
44
44
|
const sub = substitutedExpr(this.subst, e);
|
|
45
45
|
if (sub)
|
|
46
|
-
return this.typeOf(sub.bare) === 'Bool' ? sub.code : `${RT.jsTruthy}(${sub.code})`;
|
|
46
|
+
return this.typeOf(sub.bare) === 'Bool' ? sub.code : `${RT.jsTruthy}(${this.marks.isUnwrap(sub.code) ? this.marks.unwrapInner(sub.code) : sub.code})`;
|
|
47
47
|
if (cell === undefined)
|
|
48
48
|
cell = conditionCell(this.conditions, e);
|
|
49
49
|
const code = this.truthy(cell);
|
|
@@ -148,10 +148,11 @@ export const expressionsMethods = {
|
|
|
148
148
|
const t = this.lenientRef(declared) !== declared ? optionalType(declared) : declared;
|
|
149
149
|
const exprType = this.typeOf(a);
|
|
150
150
|
const rt = isUntyped(spelledType(t)) && !isUntyped(spelledType(exprType)) && exprType !== 'Void' ? exprType : t;
|
|
151
|
+
const retType = this.lenientRef(rt) !== rt ? optionalType(rt) : rt;
|
|
151
152
|
const tp = this.tryPrefix(a);
|
|
152
153
|
const retVal = rt !== t ? this.fromAnyCode(this.expr(a.left), rt, true) : this.expr(a.left);
|
|
153
154
|
const retThrows = tp || /\btry\b/.test(retVal);
|
|
154
|
-
return `({ () ${retThrows ? 'throws ' : ''}-> ${
|
|
155
|
+
return `({ () ${retThrows ? 'throws ' : ''}-> ${retType} in ${tp}${this.binary(a)}; return ${retVal} }())`;
|
|
155
156
|
}
|
|
156
157
|
if (ts.isParenthesizedExpression(e)) {
|
|
157
158
|
const inner = this.expr(e.expression);
|
|
@@ -271,6 +272,9 @@ export const expressionsMethods = {
|
|
|
271
272
|
const raw = this.untypedMemberValue(e.expression);
|
|
272
273
|
if (raw)
|
|
273
274
|
return raw;
|
|
275
|
+
const maybe = this.maybeUndefined(e.expression);
|
|
276
|
+
if (maybe)
|
|
277
|
+
return this.marks.leading(`(${maybe} as Any?)`, maybe);
|
|
274
278
|
}
|
|
275
279
|
// `<Array<View>>views` of a ViewBase[]: Swift's arrays of the two are distinct types, so the elements are read as the asserted one, in a copy unless the array already is one.
|
|
276
280
|
const fromArray = /^JSArray<(.+)>[?!]?$/.exec(from), toArray = /^JSArray<(.+)>[?!]?$/.exec(to);
|
package/dist/swift/from-any.js
CHANGED
|
@@ -263,7 +263,7 @@ export const fromAnyMethods = {
|
|
|
263
263
|
// An interface classes implement: an object conforming to it as it is, any other read by its keys.
|
|
264
264
|
return type.endsWith('?') ? `${RT.jsUnlessNullish}(${code}, { (${RT.jsFlat}($0) as? ${base}) ?? ${base}Object(jsObject: $0) })` : `{ (__o: Any?) -> ${base} in (${RT.jsFlat}(__o) as? ${base}) ?? ${base}Object(jsObject: __o) }(${code})`;
|
|
265
265
|
}
|
|
266
|
-
if (this.facts.hasInterface(this, this.interfaces, (d, s) => this.topName(d, s), base) || !!this.shapes.named(base) || (!this.library && this.core.viewable(base))) {
|
|
266
|
+
if ((!this.classNamed(base) && (this.facts.hasInterface(this, this.interfaces, (d, s) => this.topName(d, s), base) || !!this.shapes.named(base))) || (!this.library && this.core.viewable(base))) {
|
|
267
267
|
this.used.add(base);
|
|
268
268
|
// An object of the interface's class already is the object read (a receiver `call` passes); any other is read by its keys.
|
|
269
269
|
return type.endsWith('?') ? `${RT.jsUnlessNullish}(${code}, { (${RT.jsFlat}($0) as? ${base}) ?? ${this.viewOf(base, '$0')} })` : `{ (__o: Any?) -> ${base} in (${RT.jsFlat}(__o) as? ${base}) ?? ${this.viewOf(base, '__o')} }(${code})`;
|
package/dist/swift/functions.js
CHANGED
|
@@ -8,7 +8,7 @@ import { returnCell } from "../semantics/placement.js";
|
|
|
8
8
|
import { hasModifier, isLibDeclaration, withoutDefault, implementationOf, declaresThis } from "../semantics/ast.js";
|
|
9
9
|
import { isAsync, isStatic } from "../semantics/throws.js";
|
|
10
10
|
import { isCoreDeclaration } from "../program/core-facts.js";
|
|
11
|
-
import { methodValues } from "../semantics/lang.js";
|
|
11
|
+
import { builtinConstructorSlot, methodValues } from "../semantics/lang.js";
|
|
12
12
|
import { baseMethod } from "../semantics/classes.js";
|
|
13
13
|
import { isUntyped, spelledType } from "../semantics/types.js";
|
|
14
14
|
export const functionsMethods = {
|
|
@@ -261,11 +261,9 @@ export const functionsMethods = {
|
|
|
261
261
|
const conversion = { Number: [RT.jsToNumber, 'Double'], String: [RT.jsToString, 'String'], Boolean: [RT.jsTruthy, 'Bool'] }[e.text];
|
|
262
262
|
if (!conversion)
|
|
263
263
|
return null;
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if (!slot)
|
|
268
|
-
return `js${e.text}Constructor`;
|
|
264
|
+
const { singleton, slot } = builtinConstructorSlot(e, this.checker, (c) => isUntyped(spelledType(this.type(c, e))));
|
|
265
|
+
if (singleton)
|
|
266
|
+
return singleton;
|
|
269
267
|
const param = slot?.getParameters()[0];
|
|
270
268
|
const t = param ? this.type(this.checker.getTypeOfSymbolAtLocation(param, e), e) : 'Any?';
|
|
271
269
|
const call = p && ts.isCallExpression(p) && p.arguments[0] === e && ts.isPropertyAccessExpression(p.expression) ? p.expression.expression : null;
|
|
@@ -390,6 +388,7 @@ export const functionsMethods = {
|
|
|
390
388
|
const throws = !isAsync(fn) && this.throwsInfo.fn(fn) ? 'throws ' : '';
|
|
391
389
|
// A function expression's name is only for itself: one that never refers to itself is an anonymous function.
|
|
392
390
|
if (fn.name && refersTo(fn.body, this.checker.getSymbolAtLocation(fn.name), this.checker)) {
|
|
391
|
+
this.refuseNamedGenerator(fn);
|
|
393
392
|
const fnName = ident(fn.name.text);
|
|
394
393
|
const extra = this.unusedParameters(fn).map((t, k) => `_ __unused${k}: ${t}`);
|
|
395
394
|
const fnParams = [this.params(fn, false), ...extra, ...pad.map((p) => (p.startsWith('_ ') ? p : `_ ${p}`))].filter(Boolean).join(', ');
|
|
@@ -161,7 +161,7 @@ export const globalCallsMethods = {
|
|
|
161
161
|
const declared = this.checker.getResolvedSignature(e)?.getDeclaration();
|
|
162
162
|
const isFunctionValue = !declared || ts.isJSDocSignature(declared) || !('body' in declared && declared.body) || ts.isArrowFunction(declared) || ts.isFunctionExpression(declared);
|
|
163
163
|
// A function held untyped (one of several function types): called as script calls it.
|
|
164
|
-
if (this.isAny(callee)) {
|
|
164
|
+
if (this.isAny(callee) && !(declared && ts.isFunctionDeclaration(declared) && declared.body)) {
|
|
165
165
|
const code = `${RT.jsCall}(${this.expr(callee)}${this.untypedArgs(e)})`;
|
|
166
166
|
const t = this.typeOf(e);
|
|
167
167
|
return isUntyped(spelledType(t)) || t === 'Void' ? code : this.fromAnyCode(code, t, true);
|
|
@@ -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
|
@@ -294,13 +294,6 @@ export const lenientMethods = {
|
|
|
294
294
|
const t = this.typeOf(x);
|
|
295
295
|
return !isFunctionType(t) && this.nullableRef(t) !== t;
|
|
296
296
|
},
|
|
297
|
-
/** A variable declared without a type whose value is a read of a signal holding null (`const card = this.morning()`). */
|
|
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));
|
|
303
|
-
},
|
|
304
297
|
nullSignalRead(e) {
|
|
305
298
|
if (!ts.isCallExpression(e) || e.arguments.length || !['writable', 'input', 'computed'].includes(this.framework.signalKind(this.symbolName(e.expression)) ?? ''))
|
|
306
299
|
return false;
|