@nstudio/nativescript-compiler 9.2.0-alpha.17 → 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/kotlin/access.js +8 -7
- 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 +4 -9
- package/dist/kotlin/class-methods.js +2 -2
- package/dist/kotlin/core-api.js +1 -1
- package/dist/kotlin/declarations.js +1 -1
- package/dist/kotlin/expression-statements.js +13 -1
- package/dist/kotlin/functions.js +1 -0
- package/dist/kotlin/literals.js +4 -8
- package/dist/kotlin/names.js +4 -4
- package/dist/kotlin/native/api.js +1 -1
- package/dist/kotlin/operators.js +25 -25
- package/dist/kotlin/optional-chains.js +1 -1
- package/dist/kotlin/overrides.js +2 -2
- package/dist/kotlin/state-backend.js +6 -2
- package/dist/kotlin/translator.js +1 -1
- package/dist/kotlin/types.js +4 -4
- package/dist/semantics/classes.js +15 -0
- package/dist/semantics/facts.js +1 -1
- package/dist/semantics/lang.js +10 -0
- package/dist/semantics/lower.js +54 -0
- package/dist/semantics/lowering-methods.js +5 -0
- package/dist/semantics/placement.js +9 -3
- package/dist/semantics/signals.js +11 -0
- package/dist/semantics/states/missing.js +7 -0
- package/dist/semantics/tdz.js +54 -15
- package/dist/semantics/throws.js +1 -1
- package/dist/semantics/translator-methods.js +1 -1
- package/dist/swift/access.js +7 -9
- package/dist/swift/assignment.js +20 -14
- package/dist/swift/calls.js +6 -3
- package/dist/swift/classes.js +7 -9
- package/dist/swift/components.js +3 -3
- package/dist/swift/control-flow.js +1 -1
- package/dist/swift/conversion.js +5 -2
- package/dist/swift/core-api.js +2 -2
- package/dist/swift/declarations.js +1 -1
- 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 -1
- package/dist/swift/lenient.js +1 -6
- package/dist/swift/literals.js +8 -3
- package/dist/swift/modules.js +3 -3
- package/dist/swift/names.js +3 -3
- package/dist/swift/native/calls.js +1 -1
- package/dist/swift/object-classes.js +84 -1
- package/dist/swift/operators.js +31 -29
- package/dist/swift/placement.js +4 -3
- package/dist/swift/state-backend.js +3 -2
- package/dist/swift/static-calls.js +2 -3
- package/dist/swift/syntax.js +9 -5
- package/dist/swift/translator.js +1 -1
- package/dist/swift/type-facts.js +3 -3
- package/dist/swift/types.js +3 -3
- package/dist/targets/ios/build.js +1 -1
- 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 +497 -42
- 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 +22 -2
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Strings.kt +32 -18
- 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/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 +280 -9
- package/kit-apple/Sources/NativeScriptKit/Runtime/Lowering.swift +3 -2
- package/kit-apple/Sources/NativeScriptKit/Runtime/Prototypes.swift +1 -0
- 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
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
|
|
4
|
+
import { accessedDeclaration, evolvingElementContext, isSelf } 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";
|
|
@@ -294,11 +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 init = untypedVariableInitializer(n, (id) => this.resolve(id));
|
|
300
|
-
return !!init && this.nullSignalRead(init);
|
|
301
|
-
},
|
|
302
297
|
nullSignalRead(e) {
|
|
303
298
|
if (!ts.isCallExpression(e) || e.arguments.length || !['writable', 'input', 'computed'].includes(this.framework.signalKind(this.symbolName(e.expression)) ?? ''))
|
|
304
299
|
return false;
|
package/dist/swift/literals.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Literals as Swift: arrays, objects and dynamic objects.
|
|
2
2
|
import ts from 'typescript';
|
|
3
|
-
import { functionParts, ident, identPath, initOrder, isNullish, isOptional, label, optionalType, splitTopLevel, swiftString, withoutThenables, spell, RT } from "./syntax.js";
|
|
3
|
+
import { functionParts, ident, identPath, implicitType, initOrder, isNullish, isOptional, label, optionalType, splitTopLevel, swiftString, withoutThenables, spell, RT } from "./syntax.js";
|
|
4
4
|
import { assertedOperand, evolvingElementContext, intersectionAliasMembers, isTypeParameterType, literalKey, openSpreadType, spreadOperand, unquoted } from "../semantics/lang.js";
|
|
5
5
|
import { place } from "../semantics/placement.js";
|
|
6
6
|
import { holdsNil, literalNotes, signatureField, shapePlanOfLiteral, spelledOptional, spreadElementNeedsMap, resultShapeNamed } from "../semantics/shapes.js";
|
|
@@ -300,7 +300,7 @@ export const literalsMethods = {
|
|
|
300
300
|
}
|
|
301
301
|
};
|
|
302
302
|
// A field the class holds implicitly unwrapped (`shapeHeld`) takes what the literal gives as optional, undefined included.
|
|
303
|
-
const loose = (want) => !!want && target === name && this.shapeHeld({ type: want }) ===
|
|
303
|
+
const loose = (want) => !!want && target === name && this.shapeHeld({ type: want }) === implicitType(want);
|
|
304
304
|
// Methods that read `this` see the object through a weak reference the literal sets once it exists.
|
|
305
305
|
// A function expression as a member (`onViewLoaded: function () { this.loadedCount++ }`) reads the object as `this` too.
|
|
306
306
|
const thisFunction = (p) => ts.isPropertyAssignment(p) && ts.isFunctionExpression(p.initializer) && thisNodes(p.initializer).length > 0;
|
|
@@ -390,7 +390,12 @@ export const literalsMethods = {
|
|
|
390
390
|
}
|
|
391
391
|
else if (ts.isMethodDeclaration(p)) {
|
|
392
392
|
const key = literalKey(p.name, this.checker) ?? this.symbolMemberName(p.name) ?? p.name.getText();
|
|
393
|
-
const
|
|
393
|
+
const fieldType = order.find((f) => f.name === key)?.type ?? '';
|
|
394
|
+
if (isUntyped(spelledType(fieldType))) {
|
|
395
|
+
given.set(key, this.untypedMethod(p));
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
const want = functionParts(fieldType.replace(/^\((.*)\)[?!]$/, '$1'));
|
|
394
399
|
// An unannotated method returning an object literal makes it against its field's declared result, as TypeScript types the returned literal.
|
|
395
400
|
const sig = !p.type && want && want.result !== 'Void' ? this.checker.getSignatureFromDeclaration(p) : undefined;
|
|
396
401
|
const literalResult = !!sig && !!this.checker.getReturnTypeOfSignature(sig).symbol?.declarations?.some(ts.isObjectLiteralExpression);
|
package/dist/swift/modules.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Module-level declarations as Swift: modules, variables, namespaces, constants, interfaces and protocols.
|
|
2
2
|
import { setLossSite } from "../semantics/losses.js";
|
|
3
3
|
import ts from 'typescript';
|
|
4
|
-
import { NONISOLATED_DEINIT, SWIFT_GLOBAL_FUNCTIONS, escapingFunction, functionParts, ident, identPath, indented, isFunctionType, isNullish, isOptional, nativeResult, nativeZero, optionalType, swiftString, RT } from "./syntax.js";
|
|
4
|
+
import { NONISOLATED_DEINIT, SWIFT_GLOBAL_FUNCTIONS, escapingFunction, functionParts, ident, identPath, implicitType, indented, isFunctionType, isNullish, isOptional, nativeResult, nativeZero, optionalType, swiftString, RT } from "./syntax.js";
|
|
5
5
|
import { lookupClass, lookupMember } from "./native/sdk.js";
|
|
6
6
|
import { boundNames, hasModifier, isLibDeclaration, moduleBlockVars, redeclaredVar } from "../semantics/ast.js";
|
|
7
7
|
import { enteredGuard, onMainThread } from "./native/bridging.js";
|
|
@@ -684,7 +684,7 @@ export const modulesMethods = {
|
|
|
684
684
|
});
|
|
685
685
|
const signature = (m) => `func ${m.name}(${m.params.map((p) => `_ ${p.name}: ${isFunctionType(p.type) ? `@escaping ${p.type}` : p.type}`).join(', ')}) throws${m.ret === 'Void' ? '' : ` -> ${m.ret}`}`;
|
|
686
686
|
const fnType = (m) => `(${m.params.map((p) => p.type).join(', ')}) throws -> ${m.ret.replace(/!$/, '?')}`;
|
|
687
|
-
const lines = [
|
|
687
|
+
const lines = [`@MainActor protocol ${name}: JSDynamic {`];
|
|
688
688
|
const params = (m) => m.params.map((p) => `_ ${p.name}: ${isFunctionType(p.type) ? `@escaping ${p.type}` : p.type}`).join(', ');
|
|
689
689
|
const requirements = (owner) => {
|
|
690
690
|
for (const f of fields)
|
|
@@ -938,7 +938,7 @@ ${members.join('\n')}
|
|
|
938
938
|
return isFunctionType(f.type) ? `(${f.type})?` : this.nullableRef(f.type);
|
|
939
939
|
// An app's object field holds undefined too, as a literal asserted to the type may give it (`{ …, view } as
|
|
940
940
|
// ItemEventData` before the view exists); a read that uses it unwraps it there.
|
|
941
|
-
return !this.library && !isOptional(f.type) && !f.type.endsWith('!') && !isFunctionType(f.type) && this.nullableRef(f.type) !== f.type ?
|
|
941
|
+
return !this.library && !isOptional(f.type) && !f.type.endsWith('!') && !isFunctionType(f.type) && this.nullableRef(f.type) !== f.type ? implicitType(f.type) : f.type;
|
|
942
942
|
},
|
|
943
943
|
membersWritten() {
|
|
944
944
|
return this.facts.assignedMembers();
|
package/dist/swift/names.js
CHANGED
|
@@ -186,7 +186,7 @@ export const namesMethods = {
|
|
|
186
186
|
* App mode: a type name Swift code already has unqualified (the standard library's, the runtime's, the app module's own
|
|
187
187
|
* Swift, or a native module's the app imports), which a program type of that name would hide from the app.
|
|
188
188
|
*/
|
|
189
|
-
|
|
189
|
+
swiftTypeClash(name) {
|
|
190
190
|
return !this.library && (SWIFT_NATIVE_TYPES.has(name) || runtimeTypeName(name) || this.appSwiftNames.has(name) || this.importedTypeNames().has(name));
|
|
191
191
|
},
|
|
192
192
|
/** The Swift type names of `nativeModules` and of the SDK modules whose declarations the program's code names. */
|
|
@@ -276,7 +276,7 @@ export const namesMethods = {
|
|
|
276
276
|
this.kitClashes.push(name);
|
|
277
277
|
// A type the hand-written kit declares for itself (Signals' `Source`), or an app's type named as one Swift has already
|
|
278
278
|
// (`Result`): the generated one takes its module's name.
|
|
279
|
-
const internalClash = !!this.library?.internalTypes?.has(name) || (list.some((x) => typeLike(x.decl) || ts.isInterfaceDeclaration(x.decl)) && this.
|
|
279
|
+
const internalClash = !!this.library?.internalTypes?.has(name) || (list.some((x) => typeLike(x.decl) || ts.isInterfaceDeclaration(x.decl)) && this.swiftTypeClash(name));
|
|
280
280
|
if (list.length < 2 && !kitClash && !internalClash)
|
|
281
281
|
continue;
|
|
282
282
|
// The app's first declaration keeps its name; the others take their module's.
|
|
@@ -326,7 +326,7 @@ export const namesMethods = {
|
|
|
326
326
|
if (ts.isModuleDeclaration(st))
|
|
327
327
|
collect(st);
|
|
328
328
|
for (const [name, list] of hoisted) {
|
|
329
|
-
if (!byName.has(name) && list.length < 2 && !this.core.has(name) && !this.
|
|
329
|
+
if (!byName.has(name) && list.length < 2 && !this.core.has(name) && !this.swiftTypeClash(name))
|
|
330
330
|
continue;
|
|
331
331
|
for (const x of list)
|
|
332
332
|
this.renamedTop.set(x.decl, `${name}__${(this.namespacePath(x.ns) ?? '').replace(/\./g, '_')}`);
|
|
@@ -435,7 +435,7 @@ export const nativeCallsMethods = {
|
|
|
435
435
|
* Whether a typings declaration's Swift binding holds nil (an optional): a property's value, a method's result, a
|
|
436
436
|
* parameter's argument, or a parameter of a block the method takes. False where the tables have no such member.
|
|
437
437
|
*/
|
|
438
|
-
|
|
438
|
+
iosHoldsNil(d) {
|
|
439
439
|
try {
|
|
440
440
|
const block = ts.isParameter(d) && ts.isFunctionTypeNode(d.parent) && ts.isParameter(d.parent.parent) ? d.parent.parent : null;
|
|
441
441
|
const param = block ?? (ts.isParameter(d) ? d : null);
|
|
@@ -16,8 +16,19 @@ export const objectClassesMethods = {
|
|
|
16
16
|
// A view keeps no fields: each reads and writes its root's key, and its own object's fields are `jsOwn`'s. A result
|
|
17
17
|
// interface's class in the kit has one for an app's untyped object of it.
|
|
18
18
|
const view = !symbolic.length && !keyed.length && (this.library ? resultShapeNamed(this, name) : this.viewed.has(name));
|
|
19
|
+
// Fast direct JSON writer for plain shapes (no views, symbols, Any, functions, BigInt, or declared toJSON).
|
|
20
|
+
const fastJSON = !this.library &&
|
|
21
|
+
!view &&
|
|
22
|
+
!symbolic.length &&
|
|
23
|
+
!keyed.length &&
|
|
24
|
+
fields.length > 0 &&
|
|
25
|
+
!fields.some((f) => {
|
|
26
|
+
const h = this.shapeHeld(f);
|
|
27
|
+
const base = h.replace(/[?!]$/, '');
|
|
28
|
+
return f.name === 'toJSON' || base === 'Any' || isFunctionType(base.replace(/^\((.*)\)$/, '$1')) || /^JS(Nullish|BigInt)\b/.test(base);
|
|
29
|
+
});
|
|
19
30
|
this.shapesWritten.add(name);
|
|
20
|
-
const lines = [`final class ${name}: ${['JSDynamic', ...this.shapeProtocols(allFields).map((x) => x.conformance), ...(symbolic.length ? [] : ['JSObjectConvertible']), ...(view ? ['JSViewing'] : []), ...(keyed.length ? ['JSSymbolKeyed'] : [])].join(', ')} {`, NONISOLATED_DEINIT];
|
|
31
|
+
const lines = [`final class ${name}: ${['JSDynamic', ...this.shapeProtocols(allFields).map((x) => x.conformance), ...(symbolic.length ? [] : ['JSObjectConvertible']), ...(fastJSON ? ['JSJSONFastSerializable'] : []), ...(view ? ['JSViewing'] : []), ...(keyed.length ? ['JSSymbolKeyed'] : [])].join(', ')} {`, NONISOLATED_DEINIT];
|
|
21
32
|
const held = (f) => this.shapeHeld(f);
|
|
22
33
|
// A field the object lacks, or holds of another type (JSON without an optional field), reads as JavaScript converts it where used.
|
|
23
34
|
const fieldType = (f) => (this.lenient ? held(f).replace(/^\((.*)\)!$/, '($1)?') : held(f).endsWith('!') ? optionalType(f.type) : f.type);
|
|
@@ -109,6 +120,78 @@ export const objectClassesMethods = {
|
|
|
109
120
|
}
|
|
110
121
|
members[0] = ` var jsKeys: [String] {\n${view ? ' if let __r = jsRoot { return __r.jsKeys }\n' : ''} let order = jsOrder ?? ${declared}\n let keys = order + (jsExtra?.jsKeys ?? []).filter { !order.contains($0) }\n return ${optional.length ? 'keys.filter(jsHas)' : 'keys'}\n }`;
|
|
111
122
|
lines.push(...members);
|
|
123
|
+
if (fastJSON) {
|
|
124
|
+
const canFast = ['jsOrder == nil', 'jsExtra == nil', ...(nullable.length ? ['jsNulls == nil'] : []), ...(optional.length ? ['jsUnset == nil'] : [])].join(' && ');
|
|
125
|
+
const safe = (f) => ['Double', 'String', 'Bool'].includes(this.shapeHeld(f));
|
|
126
|
+
const guaranteedFirst = safe(fields[0]);
|
|
127
|
+
const steps = [];
|
|
128
|
+
if (guaranteedFirst) {
|
|
129
|
+
fields.forEach((f, idx) => {
|
|
130
|
+
const h = this.shapeHeld(f);
|
|
131
|
+
const opt = h.endsWith('?');
|
|
132
|
+
const base = h.replace(/[?!]$/, '');
|
|
133
|
+
const ref = `self.${ident(memberOf(f))}`;
|
|
134
|
+
const keyLit = JSON.stringify(f.name);
|
|
135
|
+
const prefix = idx === 0 ? `{${keyLit}:` : `,${keyLit}:`;
|
|
136
|
+
if (!opt && h === 'Double')
|
|
137
|
+
steps.push(` out.appendJSONLiteral(${swiftString(prefix)}); out.appendJSONNumber(${ref})`);
|
|
138
|
+
else if (!opt && h === 'String')
|
|
139
|
+
steps.push(` out.appendJSONLiteral(${swiftString(prefix)}); out.appendJSONString(${ref})`);
|
|
140
|
+
else if (!opt && h === 'Bool')
|
|
141
|
+
steps.push(` out.appendJSONLiteral(${swiftString(prefix)}); out.appendJSONBool(${ref})`);
|
|
142
|
+
else if (opt && base === 'Double')
|
|
143
|
+
steps.push(` if let __v = ${ref} { out.appendJSONLiteral(${swiftString(prefix)}); out.appendJSONNumber(__v) }`);
|
|
144
|
+
else if (opt && base === 'String')
|
|
145
|
+
steps.push(` if let __v = ${ref} { out.appendJSONLiteral(${swiftString(prefix)}); out.appendJSONString(__v) }`);
|
|
146
|
+
else if (opt && base === 'Bool')
|
|
147
|
+
steps.push(` if let __v = ${ref} { out.appendJSONLiteral(${swiftString(prefix)}); out.appendJSONBool(__v) }`);
|
|
148
|
+
else if (base === 'JSArray<Double>')
|
|
149
|
+
steps.push(` if !out.appendJSONNumbersIfPlain(${swiftString(prefix)}, ${ref}) { try writeField(${swiftString(prefix)}, ${swiftString(f.name)}, ${ref}) }`);
|
|
150
|
+
else if (base === 'JSArray<String>')
|
|
151
|
+
steps.push(` if !out.appendJSONStringsIfPlain(${swiftString(prefix)}, ${ref}) { try writeField(${swiftString(prefix)}, ${swiftString(f.name)}, ${ref}) }`);
|
|
152
|
+
else
|
|
153
|
+
steps.push(` try writeField(${swiftString(prefix)}, ${swiftString(f.name)}, ${ref})`);
|
|
154
|
+
});
|
|
155
|
+
steps.push(' out.appendJSONLiteral("}")');
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
steps.push(' out.appendJSONLiteral("{")');
|
|
159
|
+
steps.push(' var __first = true');
|
|
160
|
+
const needsMark = fields.some((f) => !['Double', 'String', 'Bool'].includes(this.shapeHeld(f).replace(/\?$/, '')));
|
|
161
|
+
if (needsMark)
|
|
162
|
+
steps.push(' var __m = 0');
|
|
163
|
+
for (const f of fields) {
|
|
164
|
+
const h = this.shapeHeld(f);
|
|
165
|
+
const opt = h.endsWith('?');
|
|
166
|
+
const base = h.replace(/[?!]$/, '');
|
|
167
|
+
const ref = `self.${ident(memberOf(f))}`;
|
|
168
|
+
const keyLit = JSON.stringify(f.name);
|
|
169
|
+
const p0 = `${keyLit}:`;
|
|
170
|
+
const p1 = `,${keyLit}:`;
|
|
171
|
+
const pExpr = `__first ? ${swiftString(p0)} : ${swiftString(p1)}`;
|
|
172
|
+
if (!opt && h === 'Double')
|
|
173
|
+
steps.push(` out.appendJSONLiteral(${pExpr}); out.appendJSONNumber(${ref}); __first = false`);
|
|
174
|
+
else if (!opt && h === 'String')
|
|
175
|
+
steps.push(` out.appendJSONLiteral(${pExpr}); out.appendJSONString(${ref}); __first = false`);
|
|
176
|
+
else if (!opt && h === 'Bool')
|
|
177
|
+
steps.push(` out.appendJSONLiteral(${pExpr}); out.appendJSONBool(${ref}); __first = false`);
|
|
178
|
+
else if (opt && base === 'Double')
|
|
179
|
+
steps.push(` if let __v = ${ref} { out.appendJSONLiteral(${pExpr}); out.appendJSONNumber(__v); __first = false }`);
|
|
180
|
+
else if (opt && base === 'String')
|
|
181
|
+
steps.push(` if let __v = ${ref} { out.appendJSONLiteral(${pExpr}); out.appendJSONString(__v); __first = false }`);
|
|
182
|
+
else if (opt && base === 'Bool')
|
|
183
|
+
steps.push(` if let __v = ${ref} { out.appendJSONLiteral(${pExpr}); out.appendJSONBool(__v); __first = false }`);
|
|
184
|
+
else if (base === 'JSArray<Double>')
|
|
185
|
+
steps.push(` __m = out.count; if !out.appendJSONNumbersIfPlain(${pExpr}, ${ref}) { try writeField(${pExpr}, ${swiftString(f.name)}, ${ref}) }; if out.count != __m { __first = false }`);
|
|
186
|
+
else if (base === 'JSArray<String>')
|
|
187
|
+
steps.push(` __m = out.count; if !out.appendJSONStringsIfPlain(${pExpr}, ${ref}) { try writeField(${pExpr}, ${swiftString(f.name)}, ${ref}) }; if out.count != __m { __first = false }`);
|
|
188
|
+
else
|
|
189
|
+
steps.push(` __m = out.count; try writeField(${pExpr}, ${swiftString(f.name)}, ${ref}); if out.count != __m { __first = false }`);
|
|
190
|
+
}
|
|
191
|
+
steps.push(' out.appendJSONLiteral("}")');
|
|
192
|
+
}
|
|
193
|
+
lines.push(` var jsCanFastJSON: Bool { ${canFast} }`, ' func jsWriteJSONFast(to out: JSUTF8Buffer, writeField: (StaticString, String, Any?) throws -> Void) throws -> Bool {', ' if !jsCanFastJSON { return false }', ...steps, ' return true', ' }');
|
|
194
|
+
}
|
|
112
195
|
lines.push('}');
|
|
113
196
|
return lines.join('\n');
|
|
114
197
|
},
|
package/dist/swift/operators.js
CHANGED
|
@@ -12,7 +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
|
+
import { planArithmetic, planEquality, planLogicalAssign, planRelational, typeofComparison } from "../semantics/lower.js";
|
|
16
16
|
/** BigInt's operations the backend spells as an operator. */
|
|
17
17
|
const BIGINT_INFIX = { add: '+', subtract: '-', multiply: '*', and: '&', or: '|', xor: '^' };
|
|
18
18
|
export const operatorsMethods = {
|
|
@@ -126,29 +126,32 @@ export const operatorsMethods = {
|
|
|
126
126
|
return assigned(() => `${l()} ?? ${(isOptional(this.declaredTypeOf(e.left) ?? this.typeOf(e.left)) ? this.maybeUndefined(e.right) : null) ?? this.stored(e.right, e.left, this.typeOf(e.left).replace(/\?$/, ''))}`);
|
|
127
127
|
return this.marks.blockCode(`if ${this.tryPrefix(e.left)}${RT.jsIsNullish}(${l()}) { ${this.tryPrefix(e.right)}${target()} = ${(isOptional(this.declaredTypeOf(e.left) ?? this.typeOf(e.left)) ? this.maybeUndefined(e.right) : null) ?? this.stored(e.right, e.left, this.typeOf(e.left).replace(/\?$/, ''))} }`);
|
|
128
128
|
case K.BarBarEqualsToken:
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return this.marks.blockCode(`if ${RT.jsTruthy}(${this.tryPrefix(e.left)}${l()}) { ${this.tryPrefix(e)}${target()} = ${this.stored(e.right, e.left, this.typeOf(e.left))} }`);
|
|
132
|
-
case K.PlusToken: {
|
|
133
|
-
if (this.isString(e.left) || this.isString(e.right))
|
|
134
|
-
return this.marks.infix(concatOperand(this, e.left, untyped), '+', concatOperand(this, e.right, untyped));
|
|
135
|
-
if (this.isAny(e.left) || this.isAny(e.right)) {
|
|
136
|
-
const sum = addCall(this, e, untyped), t = this.typeOf(e);
|
|
137
|
-
return isUntyped(spelledType(t)) ? sum : this.fromAnyCode(sum, t);
|
|
138
|
-
}
|
|
139
|
-
return this.marks.infix(this.toNumber(e.left), '+', this.toNumber(e.right));
|
|
129
|
+
case K.AmpersandAmpersandEqualsToken: {
|
|
130
|
+
const plan = planLogicalAssign(op);
|
|
131
|
+
return this.marks.blockCode(`if ${plan.op === '||=' ? '!' : ''}${RT.jsTruthy}(${this.tryPrefix(e.left)}${l()}) { ${this.tryPrefix(e)}${target()} = ${this.stored(e.right, e.left, this.typeOf(e.left))} }`);
|
|
140
132
|
}
|
|
133
|
+
case K.PlusToken:
|
|
141
134
|
case K.MinusToken:
|
|
142
|
-
return this.marks.infix(this.toNumber(e.left), '-', this.toNumber(e.right));
|
|
143
135
|
case K.AsteriskToken:
|
|
144
|
-
return this.marks.infix(this.toNumber(e.left), '*', this.toNumber(e.right));
|
|
145
|
-
// Integer literals on both sides would divide as Int where no operand pins Double (`Double(1 / 8)`, `js(16 / 9)`).
|
|
146
136
|
case K.SlashToken:
|
|
147
|
-
return numericLiteralOnly(e.left) && numericLiteralOnly(e.right) ? `(${this.expr(e.left)} as Double) / ${this.expr(e.right)}` : this.marks.infix(this.toNumber(e.left), '/', this.toNumber(e.right));
|
|
148
137
|
case K.PercentToken:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
138
|
+
case K.AsteriskAsteriskToken: {
|
|
139
|
+
const plan = planArithmetic(op, this.isString(e.left), this.isString(e.right), this.isAny(e.left), this.isAny(e.right));
|
|
140
|
+
if (plan.kind === 'concat')
|
|
141
|
+
return this.marks.infix(concatOperand(this, e.left, untyped), '+', concatOperand(this, e.right, untyped));
|
|
142
|
+
if (plan.kind === 'dynamicAdd') {
|
|
143
|
+
const sum = addCall(this, e, untyped), t = this.typeOf(e);
|
|
144
|
+
return isUntyped(spelledType(t)) ? sum : this.fromAnyCode(sum, t);
|
|
145
|
+
}
|
|
146
|
+
// Integer literals on both sides would divide as Int where no operand pins Double (`Double(1 / 8)`, `js(16 / 9)`).
|
|
147
|
+
if (plan.op === '/' && numericLiteralOnly(e.left) && numericLiteralOnly(e.right))
|
|
148
|
+
return `(${this.expr(e.left)} as Double) / ${this.expr(e.right)}`;
|
|
149
|
+
if (plan.op === '%')
|
|
150
|
+
return `${RT.jsMod}(${this.toNumber(e.left)}, ${this.toNumber(e.right)})`;
|
|
151
|
+
if (plan.op === '**')
|
|
152
|
+
return `${RT.jsPow}(${this.toNumber(e.left)}, ${this.toNumber(e.right)})`;
|
|
153
|
+
return this.marks.infix(this.toNumber(e.left), plan.op, this.toNumber(e.right));
|
|
154
|
+
}
|
|
152
155
|
case K.EqualsEqualsEqualsToken:
|
|
153
156
|
case K.ExclamationEqualsEqualsToken:
|
|
154
157
|
case K.EqualsEqualsToken:
|
|
@@ -446,24 +449,23 @@ export const operatorsMethods = {
|
|
|
446
449
|
* there, a nil check. Null where the test is not one of presence.
|
|
447
450
|
*/
|
|
448
451
|
typeofPresence(e) {
|
|
449
|
-
const
|
|
450
|
-
|
|
451
|
-
const [t, lit] = ts.isTypeOfExpression(l) && ts.isStringLiteralLike(r) ? [l, r] : ts.isTypeOfExpression(r) && ts.isStringLiteralLike(l) ? [r, l] : [null, null];
|
|
452
|
-
if (!t || !lit)
|
|
452
|
+
const cmp = typeofComparison(e);
|
|
453
|
+
if (!cmp)
|
|
453
454
|
return null;
|
|
455
|
+
const left = ts.skipOuterExpressions(e.left, ts.OuterExpressionKinds.Parentheses);
|
|
456
|
+
const t = (ts.isTypeOfExpression(left) ? left : ts.skipOuterExpressions(e.right, ts.OuterExpressionKinds.Parentheses));
|
|
454
457
|
const c = this.typeofCell(t);
|
|
455
|
-
if (c.cell !== 'presence' || (
|
|
458
|
+
if (c.cell !== 'presence' || (cmp.tag !== 'undefined' && cmp.tag !== c.type))
|
|
456
459
|
return null;
|
|
457
|
-
|
|
458
|
-
return `${c.tested} ${(lit.text === 'undefined') !== negate ? '==' : '!='} nil`;
|
|
460
|
+
return `${c.tested} ${(cmp.tag === 'undefined') !== cmp.negated ? '==' : '!='} nil`;
|
|
459
461
|
},
|
|
460
462
|
equality(e) {
|
|
461
463
|
this.refuseUnheldIdentity(e.left);
|
|
462
464
|
this.refuseUnheldIdentity(e.right);
|
|
463
465
|
const K = ts.SyntaxKind;
|
|
464
|
-
const
|
|
465
|
-
const negate =
|
|
466
|
-
const strict =
|
|
466
|
+
const eq = planEquality(e.operatorToken.kind, false, false, false, false);
|
|
467
|
+
const negate = eq.negated;
|
|
468
|
+
const strict = eq.kind === 'strict';
|
|
467
469
|
const isNullish = (x) => x.kind === K.NullKeyword || (ts.isIdentifier(x) && x.text === 'undefined');
|
|
468
470
|
const [a, b] = [e.left, e.right];
|
|
469
471
|
const lt = this.typeOf(a);
|
package/dist/swift/placement.js
CHANGED
|
@@ -239,7 +239,7 @@ export const placementMethods = {
|
|
|
239
239
|
if (this.lenient && ts.isIdentifier(e) && !isWriteTarget(e) && !isUntyped(spelledType(target))) {
|
|
240
240
|
const d = this.resolve(e)?.valueDeclaration;
|
|
241
241
|
if (d && ts.isVariableDeclaration(d) && !d.type && !d.initializer && isUntyped(spelledType(this.declaredTypeOf(e))) && this.typeOf(e) !== target) {
|
|
242
|
-
const read = this.fromAny(this.refName(e), target);
|
|
242
|
+
const read = this.throwingConverts(() => this.fromAny(this.refName(e), target), this.libraryThrowsHere(e), e);
|
|
243
243
|
return this.nullableRef(target) !== target && !this.looseTolerated(e) ? this.presentCode(read, target) : read;
|
|
244
244
|
}
|
|
245
245
|
}
|
|
@@ -299,7 +299,7 @@ export const placementMethods = {
|
|
|
299
299
|
return unwrap?.op !== 'unwrap' || !postfixChain(unwrap.of.code) ? code : c?.op === 'try' ? this.marks.tryCode(unwrap.of.code) : unwrap.of.code;
|
|
300
300
|
},
|
|
301
301
|
coerced(e, target) {
|
|
302
|
-
if (this.
|
|
302
|
+
if (this.isSwiftComputedProperty(e) && /^Signal<.*>[?!]?$/.test(target)) {
|
|
303
303
|
const inner = target.replace(/[?!]$/, '').slice(7, -1);
|
|
304
304
|
return `Signal<${inner}>(computing: { ${this.marks.tryBefore(this.tryPrefix(e), this.coerce(e, inner))} })`;
|
|
305
305
|
}
|
|
@@ -384,7 +384,8 @@ export const placementMethods = {
|
|
|
384
384
|
// An array literal where any value may go holds any value: script may store a string in `const list: any = [1, 2]`,
|
|
385
385
|
// or in `{ list: [1] }` of an untyped object.
|
|
386
386
|
const untypedMember = ts.isPropertyAssignment(bare.parent) && this.dynamicLiterals.has(bare.parent.parent);
|
|
387
|
-
|
|
387
|
+
const ctx = this.checker.getContextualType(bare);
|
|
388
|
+
if (ts.isArrayLiteralExpression(bare) && isUntyped(spelledType(target)) && !ts.isAsExpression(e) && ((untypedMember && (!ctx || !!(ctx.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) || !this.checker.isArrayType(ctx))) || !!(ctx?.flags & ts.TypeFlags.Any)))
|
|
388
389
|
return this.array(bare, 'JSArray<Any?>');
|
|
389
390
|
// An array of tuples where the slot's type has them typed (`[[property, color]]` for `[any, any][]` returned as `[CssProperty, Color][]`).
|
|
390
391
|
const tuples = /^(JSArray<)?(\(.*\))>?$/.exec(target.replace(/\?$/, ''));
|
|
@@ -62,7 +62,7 @@ export const stateBackendMethods = {
|
|
|
62
62
|
return t.library;
|
|
63
63
|
},
|
|
64
64
|
get native() {
|
|
65
|
-
return t.native;
|
|
65
|
+
return { holdsNil: (d) => t.native.iosHoldsNil(d) };
|
|
66
66
|
},
|
|
67
67
|
get framework() {
|
|
68
68
|
return t.framework;
|
|
@@ -86,7 +86,8 @@ export const stateBackendMethods = {
|
|
|
86
86
|
return heldAs(t, isOptional(t) || t.endsWith('!'));
|
|
87
87
|
},
|
|
88
88
|
declaredOptional: (x) => this.declaredOptional(x),
|
|
89
|
-
kitNil: (x) => !this.library && this.core.
|
|
89
|
+
kitNil: (x) => !this.library && this.core.swiftKitNil(x),
|
|
90
|
+
untypedCastChecks: (e, t) => !this.lenient && this.isObjectRef(e) && this.castChecks(spell(t)),
|
|
90
91
|
keyedClass: (c) => keyedClass(c, this.states, this.shapeFacts()),
|
|
91
92
|
};
|
|
92
93
|
},
|
|
@@ -16,7 +16,6 @@ export const staticCallsMethods = {
|
|
|
16
16
|
if (!s)
|
|
17
17
|
throw this.error(e, `${owner}.${member}`, 'library-member');
|
|
18
18
|
const method = s.name;
|
|
19
|
-
const a = () => this.args(e);
|
|
20
19
|
const arg = (k) => e.arguments[k];
|
|
21
20
|
const T = () => this.typeOf(e);
|
|
22
21
|
if (TYPED_ARRAYS.includes(owner) && (method === 'of' || method === 'from')) {
|
|
@@ -134,7 +133,7 @@ export const staticCallsMethods = {
|
|
|
134
133
|
if (method === 'from' && (e.arguments.length === 2 || e.arguments.length === 3))
|
|
135
134
|
return this.ignoringThisArg(e, arg(0), () => `JSArray<${this.elementTypeOf(arg(0))}>.from(${this.iterable(arg(0))}).map(${this.expr(arg(1))})`);
|
|
136
135
|
if (method === 'of')
|
|
137
|
-
return `${T()}([${
|
|
136
|
+
return e.arguments.some(ts.isSpreadElement) ? this.packed(e.arguments, T()) : `${T()}([${e.arguments.map((x) => this.restArgument(e, x, T().replace(/^JSArray<(.*)>$/, '$1'))).join(', ')}])`;
|
|
138
137
|
// `Array.apply(thisArg, list)`: `Array(...list)`, a length when the list is one number.
|
|
139
138
|
if (method === 'apply' && e.arguments.length === 2) {
|
|
140
139
|
const made = `${RT.jsArrayConstruct}(${this.restArgument(e, arg(1), 'JSArray<Any?>')}.storage)`;
|
|
@@ -167,7 +166,7 @@ export const staticCallsMethods = {
|
|
|
167
166
|
if (method === 'fromCharCode' && e.arguments.some(ts.isSpreadElement))
|
|
168
167
|
return `${RT.jsFromCharCode}(codes: ${this.packed(e.arguments, 'JSArray<Double>')}.storage)`;
|
|
169
168
|
if (method === 'fromCharCode')
|
|
170
|
-
return `${RT.jsFromCharCode}(${
|
|
169
|
+
return `${RT.jsFromCharCode}(${e.arguments.map((x) => this.restArgument(e, x, 'Double')).join(', ')})`;
|
|
171
170
|
if (method === 'fromCodePoint' && e.arguments.some(ts.isSpreadElement))
|
|
172
171
|
return `${RT.jsFromCodePoint}(codes: ${this.packed(e.arguments, 'JSArray<Double>')}.storage)`;
|
|
173
172
|
if (method === 'fromCodePoint')
|
package/dist/swift/syntax.js
CHANGED
|
@@ -144,21 +144,25 @@ export function balanced(code) {
|
|
|
144
144
|
}
|
|
145
145
|
return depth === 0 && !quoted;
|
|
146
146
|
}
|
|
147
|
-
/** `T?`, keeping an already optional type and parenthesizing a function type. */
|
|
147
|
+
/** `T?`, keeping an already optional type and parenthesizing a function or existential (`any P`) type. */
|
|
148
148
|
export function optionalType(t) {
|
|
149
149
|
if (t.endsWith('!'))
|
|
150
150
|
return t;
|
|
151
|
-
if (hasTopLevelArrow(t))
|
|
151
|
+
if (hasTopLevelArrow(t) || t.startsWith('any '))
|
|
152
152
|
return `(${t})?`;
|
|
153
153
|
return t.endsWith('?') ? t : `${t}?`;
|
|
154
154
|
}
|
|
155
|
+
/** `T!`, parenthesizing a function or existential (`any P`) type. */
|
|
156
|
+
export function implicitType(t) {
|
|
157
|
+
return hasTopLevelArrow(t) || t.startsWith('any ') ? `(${t})!` : `${t}!`;
|
|
158
|
+
}
|
|
155
159
|
const NAMES = { string: 'String', number: 'Double', boolean: 'Bool', void: 'Void', never: 'Never', any: 'Any', symbol: 'JSSymbol', bigint: 'JSBigInt' };
|
|
156
160
|
/** A native type as Swift spells it. */
|
|
157
161
|
export function spell(t) {
|
|
158
162
|
if (t.text !== undefined)
|
|
159
163
|
return t.text;
|
|
160
164
|
if (t.implicit)
|
|
161
|
-
return
|
|
165
|
+
return implicitType(t.name);
|
|
162
166
|
return t.optional ? optionalType(t.name) : t.name;
|
|
163
167
|
}
|
|
164
168
|
/** Swift's names of the types the front builds; a function type the front builds converts and never throws. */
|
|
@@ -359,10 +363,10 @@ export const SWIFT_SYNTAX = {
|
|
|
359
363
|
runtime: RT,
|
|
360
364
|
voidType: 'Void',
|
|
361
365
|
untypedType: 'Any?',
|
|
362
|
-
fnType: (params, ret) => `(${params.map((p) => (p === '() -> Void' ? `@escaping ${p}` : p)).join(', ')}) -> ${ret}
|
|
366
|
+
fnType: (params, ret) => (params.length === 0 && ret === 'Void' ? '@MainActor () -> Void' : `(${params.map((p) => (p === '@MainActor () -> Void' ? `@escaping ${p}` : p)).join(', ')}) -> ${ret}`),
|
|
363
367
|
constant: (name, type, value) => `let ${name}${type ? `: ${type}` : ''} = ${value}`,
|
|
364
368
|
closure: (params, body, onError, i) => {
|
|
365
|
-
const list = `(${params.map(([n, t]) => `${n}: ${t === '() -> Void' ? '@escaping ' : ''}${t}`).join(', ')})`;
|
|
369
|
+
const list = `(${params.map(([n, t]) => `${n}: ${t === '@MainActor () -> Void' ? '@escaping ' : ''}${t}`).join(', ')})`;
|
|
366
370
|
if (!throwsOutside(body.join('\n')))
|
|
367
371
|
return `{ ${list} -> Void in\n${body.join('\n')}\n${i}}`;
|
|
368
372
|
const deeper = body.map((l) => ' ' + l);
|
package/dist/swift/translator.js
CHANGED
|
@@ -584,7 +584,7 @@ export class Translator {
|
|
|
584
584
|
return t.states;
|
|
585
585
|
},
|
|
586
586
|
readHeld: (e) => this.readHeld(e),
|
|
587
|
-
untypedRead: (code, target) => this.convert(code, 'Any?', target),
|
|
587
|
+
untypedRead: (code, target, e) => this.throwingConverts(() => this.convert(code, 'Any?', target), this.libraryThrowsHere(e), e),
|
|
588
588
|
cells: {
|
|
589
589
|
jsAny: (name) => `${name}.jsAny`,
|
|
590
590
|
present: (name, key) => this.marks.ownTried(`${name}.present(${swiftString(key)})`),
|
package/dist/swift/type-facts.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Facts of Swift types: nullish storage, setters and widened parameters, declared types and shapes, and small tests of a type.
|
|
2
2
|
import ts from 'typescript';
|
|
3
|
-
import { isFunctionType, isNullish, isOptional, nullishType, optionalType, shapeName } from "./syntax.js";
|
|
3
|
+
import { implicitType, isFunctionType, isNullish, isOptional, nullishType, optionalType, shapeName } from "./syntax.js";
|
|
4
4
|
import { shapePlanOfLiteral } from "../semantics/shapes.js";
|
|
5
5
|
import { accessedDeclaration, assignedValues, wellKnownMember } from "../semantics/lang.js";
|
|
6
6
|
import { isLibDeclaration, isWriteTarget } from "../semantics/ast.js";
|
|
@@ -519,7 +519,7 @@ export const typeFactsMethods = {
|
|
|
519
519
|
const z = this.zero(t);
|
|
520
520
|
if (z)
|
|
521
521
|
return `${t} = ${z}`;
|
|
522
|
-
return
|
|
522
|
+
return implicitType(t);
|
|
523
523
|
},
|
|
524
524
|
deferred(t) {
|
|
525
525
|
const z = this.zero(t);
|
|
@@ -527,6 +527,6 @@ export const typeFactsMethods = {
|
|
|
527
527
|
return `${t} = ${z}`;
|
|
528
528
|
if (this.lenient && this.nullableRef(t) !== t)
|
|
529
529
|
return this.nullableRef(t);
|
|
530
|
-
return
|
|
530
|
+
return implicitType(t);
|
|
531
531
|
},
|
|
532
532
|
};
|
package/dist/swift/types.js
CHANGED
|
@@ -5,7 +5,7 @@ import { WEB_DICTIONARIES, webClassName } from "../semantics/globals.js";
|
|
|
5
5
|
import { SPELLING, spell, functionParts, heldType, isFunctionLiteral, isFunctionType, isMethodValue, isOptional, nullishType, optionalElementsType, optionalType, returningAny, swiftString, RT } from "./syntax.js";
|
|
6
6
|
import { literalOverArray, membersOverTypeParameter, readByKey, definedField, untypedResultBinding, untypedResultField } from "../semantics/shapes.js";
|
|
7
7
|
import { ambientAddedMemberOf, ambientBase, augmentedPropertyRead, evolvingArrayRead, evolvingArrayType, isAmbientClass, isRegExpProtocol, mergedInterfaceMemberOf, statementLevel, tokenClassBase, undeclaredMemberOf, isArguments, nullableTypeNode } from "../semantics/lang.js";
|
|
8
|
-
import { nullishSignalType } from "../semantics/signals.js";
|
|
8
|
+
import { isGivenNullSignalValue, nullishSignalType } from "../semantics/signals.js";
|
|
9
9
|
import { hasModifier, isLibDeclaration, isSymbolIterator, isWriteTarget, implementationOf, declaresThis } from "../semantics/ast.js";
|
|
10
10
|
import { isCoreDeclaration } from "../program/core-facts.js";
|
|
11
11
|
import { coreTypeKind, eventDataTypeLiteral, hasMappedIntersection, isJsDocConstructorFunction, isKit, isLibObjectType, isUntyped, libraryNativeType, libraryType, mappedOrErasedType, nonNullableInner, nonOptionalSpelling, parseNativeType, spelledType, valueModuleKind } from "../semantics/types.js";
|
|
@@ -189,7 +189,7 @@ export const typesMethods = {
|
|
|
189
189
|
return `Signal<${arg(0)}>`;
|
|
190
190
|
}
|
|
191
191
|
if (kind === 'computed')
|
|
192
|
-
return where && this.
|
|
192
|
+
return where && this.isSwiftComputedProperty(where) ? arg(0) : `Signal<${arg(0)}>`;
|
|
193
193
|
if (kind)
|
|
194
194
|
return `Signal<${arg(0)}>`;
|
|
195
195
|
const mapped = name === undefined ? undefined : this.framework.typeMapping(name);
|
|
@@ -630,7 +630,7 @@ export const typesMethods = {
|
|
|
630
630
|
if (isUntyped(spelledType(this.declaredTypeOf(n))))
|
|
631
631
|
return 'Any?';
|
|
632
632
|
}
|
|
633
|
-
if ((t === 'Bool' || t === 'String' || t === 'Double') && (this.holdsUndefined(n) || this.
|
|
633
|
+
if ((t === 'Bool' || t === 'String' || t === 'Double') && (this.holdsUndefined(n) || isGivenNullSignalValue(n, (id) => this.resolve(id), (init) => this.nullSignalRead(init)) || this.states.lenientNullField(n)))
|
|
634
634
|
return `${t}?`;
|
|
635
635
|
if (t === 'JSArray<String>' && this.unsetGroups(n))
|
|
636
636
|
return 'JSArray<String?>';
|
|
@@ -342,7 +342,7 @@ export async function writeIos(b) {
|
|
|
342
342
|
// Script is single-threaded unless the app starts workers (each in its own isolated JSRealm on a worker thread).
|
|
343
343
|
// When workers are present, disable dynamic MainActor assertions in Debug too so worker threads can run realm-isolated code.
|
|
344
344
|
const hasWorkers = !!(b.workers && b.workers.length);
|
|
345
|
-
const swiftMode = { SWIFT_VERSION: '"6"', SWIFT_DEFAULT_ACTOR_ISOLATION: 'MainActor', ...(hasWorkers ? { OTHER_SWIFT_FLAGS: '"$(inherited) -Xfrontend -disable-dynamic-actor-isolation"' } : {}) };
|
|
345
|
+
const swiftMode = { SWIFT_VERSION: '"6"', SWIFT_DEFAULT_ACTOR_ISOLATION: 'MainActor', SWIFT_UPCOMING_FEATURE_INFER_ISOLATED_CONFORMANCES: 'YES', ...(hasWorkers ? { OTHER_SWIFT_FLAGS: '"$(inherited) -Xfrontend -disable-dynamic-actor-isolation"' } : {}) };
|
|
346
346
|
// Release only: Debug keeps Swift 6's run-time isolation checks when no workers are present.
|
|
347
347
|
const swiftModeRelease = (...flags) => ` configs:\n Release:\n OTHER_SWIFT_FLAGS: "${['$(inherited)', ...(hasWorkers ? [] : ['-Xfrontend', '-disable-dynamic-actor-isolation']), ...flags].join(' ')}"\n`;
|
|
348
348
|
// The app's own Swift (App_Resources/iOS/src), compiled in the app's target, was written for Swift 5: the target keeps that mode,
|
|
@@ -41,6 +41,7 @@ object CoreModules {
|
|
|
41
41
|
Core_data_virtual_array_index.__init()
|
|
42
42
|
Core_text_text_common.__init()
|
|
43
43
|
Core_file_system_index.__init()
|
|
44
|
+
Core_utils_android_runtime_version.__init()
|
|
44
45
|
Core_ui_styling_style_index.__init()
|
|
45
46
|
Core_ui_core_properties_index.__init()
|
|
46
47
|
Core_ui_styling_font_common.__init()
|