@nstudio/nativescript-compiler 9.2.0-alpha.17 → 9.2.0-alpha.19
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/config.js +1 -0
- package/dist/kotlin/access.js +8 -7
- package/dist/kotlin/arguments.js +6 -0
- 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 +3 -3
- 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/conversion.js +9 -1
- 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/runtime.js +1 -0
- 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 +2 -2
- package/dist/semantics/translator-methods.js +1 -1
- package/dist/swift/access.js +7 -9
- package/dist/swift/arguments.js +14 -9
- package/dist/swift/assignment.js +26 -15
- package/dist/swift/calls.js +13 -5
- package/dist/swift/class-methods.js +2 -1
- 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/library.js +2 -2
- package/dist/swift/literals.js +8 -3
- package/dist/swift/method-values.js +2 -1
- package/dist/swift/modules.js +3 -3
- package/dist/swift/names.js +7 -7
- package/dist/swift/native/calls.js +10 -4
- package/dist/swift/object-classes.js +84 -1
- package/dist/swift/operators.js +31 -29
- package/dist/swift/placement.js +22 -6
- package/dist/swift/state-backend.js +3 -2
- package/dist/swift/static-calls.js +3 -4
- package/dist/swift/syntax.js +10 -6
- package/dist/swift/translator.js +1 -1
- package/dist/swift/type-facts.js +3 -3
- package/dist/swift/types.js +5 -5
- 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/fromcore/kotlin/org/nativescript/kit/NativeScriptApplication.kt +9 -0
- 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 +7 -3
- 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 +3 -3
- package/kit-apple/Sources/NativeScriptKit/Core/file-system.file-system-access.ios.swift +58 -49
- package/kit-apple/Sources/NativeScriptKit/Core/file-system.index.swift +10 -10
- 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 +67 -52
- package/kit-apple/Sources/NativeScriptKit/Core/http.index.swift +3 -3
- package/kit-apple/Sources/NativeScriptKit/Core/image-source.index.ios.swift +69 -53
- package/kit-apple/Sources/NativeScriptKit/Core/js-libs.easysax.easysax.swift +4 -22
- package/kit-apple/Sources/NativeScriptKit/Core/kit-index.json +144 -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.action-bar.index.ios.swift +33 -21
- package/kit-apple/Sources/NativeScriptKit/Core/ui.activity-indicator.index.ios.swift +12 -6
- package/kit-apple/Sources/NativeScriptKit/Core/ui.animation.index.ios.swift +77 -65
- package/kit-apple/Sources/NativeScriptKit/Core/ui.animation.keyframe-animation.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.builder.index.swift +10 -6
- package/kit-apple/Sources/NativeScriptKit/Core/ui.button.index.ios.swift +14 -13
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.properties.index.swift +1273 -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 +87 -67
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.view-common.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.date-picker.index.ios.swift +17 -16
- package/kit-apple/Sources/NativeScriptKit/Core/ui.dialogs.index.ios.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.editable-text-base.index.ios.swift +27 -18
- 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.html-view.index.ios.swift +9 -9
- package/kit-apple/Sources/NativeScriptKit/Core/ui.image.index.ios.swift +6 -6
- package/kit-apple/Sources/NativeScriptKit/Core/ui.label.index.ios.swift +8 -8
- package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.flexbox-layout.index.ios.swift +22 -21
- package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.layout-base.ios.swift +4 -3
- package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.liquid-glass-container.index.ios.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.liquid-glass.index.ios.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.root-layout.index.ios.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.root-layout.root-layout-common.swift +9 -9
- package/kit-apple/Sources/NativeScriptKit/Core/ui.list-picker.index.ios.swift +9 -6
- package/kit-apple/Sources/NativeScriptKit/Core/ui.list-view.index.ios.swift +38 -20
- package/kit-apple/Sources/NativeScriptKit/Core/ui.page.index.ios.swift +204 -190
- package/kit-apple/Sources/NativeScriptKit/Core/ui.progress.index.ios.swift +12 -10
- package/kit-apple/Sources/NativeScriptKit/Core/ui.repeater.index.swift +2 -6
- package/kit-apple/Sources/NativeScriptKit/Core/ui.scroll-view.index.ios.swift +18 -9
- package/kit-apple/Sources/NativeScriptKit/Core/ui.search-bar.index.ios.swift +28 -18
- package/kit-apple/Sources/NativeScriptKit/Core/ui.segmented-bar.index.ios.swift +19 -12
- package/kit-apple/Sources/NativeScriptKit/Core/ui.slider.index.ios.swift +14 -12
- package/kit-apple/Sources/NativeScriptKit/Core/ui.split-view.index.ios.swift +17 -12
- 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.switch.index.ios.swift +12 -10
- package/kit-apple/Sources/NativeScriptKit/Core/ui.tab-view.index.ios.swift +36 -20
- package/kit-apple/Sources/NativeScriptKit/Core/ui.text-base.formatted-string.swift +3 -4
- package/kit-apple/Sources/NativeScriptKit/Core/ui.text-base.index.ios.swift +25 -22
- package/kit-apple/Sources/NativeScriptKit/Core/ui.text-base.text-base-common.swift +2 -3
- package/kit-apple/Sources/NativeScriptKit/Core/ui.text-field.index.ios.swift +21 -14
- package/kit-apple/Sources/NativeScriptKit/Core/ui.text-view.index.ios.swift +33 -21
- package/kit-apple/Sources/NativeScriptKit/Core/ui.text-view.text-view-common.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.time-picker.index.ios.swift +22 -18
- 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 +32 -32
- package/kit-apple/Sources/NativeScriptKit/Core/ui.web-view.index.ios.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.web-view.web-view-common.swift +2 -2
- 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/utils.index.ios.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/Native.swift +2 -1
- 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 +6 -4
package/dist/kotlin/types.js
CHANGED
|
@@ -4,7 +4,7 @@ import { KIT_NAMES_ANDROID } from "./library.js";
|
|
|
4
4
|
import { BUFFER_TYPES, WEB_DICTIONARIES, webClassName } from "../semantics/globals.js";
|
|
5
5
|
import { SPELLING, spell, destructuringSource, functionTypeParts, kotlinString, nullishType, optionalElementsType, optionalType, presentConst, RT } from "./syntax.js";
|
|
6
6
|
import { ambientBase, evolvingArrayRead, evolvingArrayType, isAmbientClass, isRegExpProtocol, memberOwner, namesOwnTypeParameter, tokenClassBase, isArguments } from "../semantics/lang.js";
|
|
7
|
-
import { nullishSignalType } from "../semantics/signals.js";
|
|
7
|
+
import { isGivenNullSignalValue, nullishSignalType } from "../semantics/signals.js";
|
|
8
8
|
import { hasModifier, isLibDeclaration, isWriteTarget, implementationOf, takesOwnThis } from "../semantics/ast.js";
|
|
9
9
|
import { isCoreDeclaration } from "../program/core-facts.js";
|
|
10
10
|
import { coreTypeKind, eventDataTypeLiteral, hasMappedIntersection, isJsDocConstructorFunction, isKit, isLibObjectType, isNamed, isUntyped, libraryNativeType, libraryType, mappedOrErasedType, nonNullableInner, nonOptionalSpelling, parseNativeType, spelledType, valueModuleKind } from "../semantics/types.js";
|
|
@@ -194,7 +194,7 @@ export const typesMethods = {
|
|
|
194
194
|
if (javaClass)
|
|
195
195
|
return javaClass;
|
|
196
196
|
// A program type renamed for a name Kotlin has already (`Iterator`, `Pair`) is not the library's type of that name.
|
|
197
|
-
const clashing = !this.library && sym?.valueDeclaration && this.
|
|
197
|
+
const clashing = !this.library && sym?.valueDeclaration && this.kotlinTypeClash(sym.name) ? this.topNames().get(sym.valueDeclaration) : undefined;
|
|
198
198
|
if (clashing)
|
|
199
199
|
return `${clashing}${this.declaredTypeArguments(t, sym.valueDeclaration, where)}`;
|
|
200
200
|
const kind = name === undefined ? undefined : this.framework.signalKind(name);
|
|
@@ -204,7 +204,7 @@ export const typesMethods = {
|
|
|
204
204
|
return `Signal<${arg(0)}>`;
|
|
205
205
|
}
|
|
206
206
|
if (kind === 'computed')
|
|
207
|
-
return where && this.
|
|
207
|
+
return where && this.isKotlinComputedProperty(where) ? arg(0) : `Signal<${arg(0)}>`;
|
|
208
208
|
if (kind)
|
|
209
209
|
return `Signal<${arg(0)}>`;
|
|
210
210
|
const mapped = name === undefined ? undefined : this.framework.typeMapping(name);
|
|
@@ -506,7 +506,7 @@ export const typesMethods = {
|
|
|
506
506
|
const t = this.isLenientDecl(own) ? this.lenientRef(declared) : this.states.looseDeclaration(own) ? optionalType(declared) : declared;
|
|
507
507
|
if (this.holdingNull(t, n))
|
|
508
508
|
return t.replace(/>$/, '?>');
|
|
509
|
-
if (['String', 'Double', 'Boolean'].includes(t) && this.
|
|
509
|
+
if (['String', 'Double', 'Boolean'].includes(t) && isGivenNullSignalValue(n, (id) => this.resolve(id), (read) => ts.isCallExpression(read) && !read.arguments.length && /^Signal<.*\?>$/.test(this.typeOf(read.expression))))
|
|
510
510
|
return `${t}?`;
|
|
511
511
|
if (/^JSArray<String>\??$/.test(t) && this.unsetGroups(n))
|
|
512
512
|
return t.replace('JSArray<String>', 'JSArray<String?>');
|
|
@@ -619,3 +619,18 @@ export function spellInstantiatedCollection(type, checker, render) {
|
|
|
619
619
|
const args = info.typeArgs.map(render);
|
|
620
620
|
return info.kind === 'Map' ? `JSMap<${args[0] ?? 'Any?'}, ${args[1] ?? 'Any?'}>` : `JS${info.kind}<${args[0] ?? 'Any?'}>`;
|
|
621
621
|
}
|
|
622
|
+
/** Own instance methods of `cls` eligible for non-enumerable registration on `JSPrototypes.of(...)`. */
|
|
623
|
+
export function prototypeMethodList(cls, options) {
|
|
624
|
+
const seen = new Set();
|
|
625
|
+
const out = [];
|
|
626
|
+
for (const m of cls.members) {
|
|
627
|
+
if (!ts.isMethodDeclaration(m) || !m.body || isStatic(m) || ts.isPrivateIdentifier(m.name) || ts.isComputedPropertyName(m.name) || m.typeParameters?.length || m.asteriskToken)
|
|
628
|
+
continue;
|
|
629
|
+
const key = m.name.getText().replace(/^['"]|['"]$/g, '');
|
|
630
|
+
if (seen.has(key) || options.skip(m, key))
|
|
631
|
+
continue;
|
|
632
|
+
seen.add(key);
|
|
633
|
+
out.push({ method: m, key });
|
|
634
|
+
}
|
|
635
|
+
return out;
|
|
636
|
+
}
|
|
@@ -2,6 +2,7 @@ import ts from 'typescript';
|
|
|
2
2
|
import { isUntyped, parseNativeType } from "./types.js";
|
|
3
3
|
import { TRACING, traced } from "./decision-trace.js";
|
|
4
4
|
import { lossOf } from "./losses.js";
|
|
5
|
+
import { declaresThis } from "./ast.js";
|
|
5
6
|
/**
|
|
6
7
|
* The rule a placement of a value the backend holds as `from` into `to` follows, the first
|
|
7
8
|
* that matches; `claimed` is the type the checker gives the value. Pure: the backends spell each rule.
|
|
@@ -241,7 +242,14 @@ export function erasesTypeParameter(p, ledger) {
|
|
|
241
242
|
if (structural && p.constraint && (ts.isTypeLiteralNode(p.constraint) || (ts.isIntersectionTypeNode(p.constraint) && p.constraint.types.some(ts.isTypeLiteralNode))))
|
|
242
243
|
return true;
|
|
243
244
|
const named = new RegExp(`\\b${p.name.text}\\b`);
|
|
244
|
-
return !fn.parameters.some((q) =>
|
|
245
|
+
return !fn.parameters.some((q) => {
|
|
246
|
+
if (!q.type || !named.test(q.type.getText()))
|
|
247
|
+
return false;
|
|
248
|
+
if (!structural || !functionShaped(q.type))
|
|
249
|
+
return true;
|
|
250
|
+
const ftn = functionTypeNode(q.type);
|
|
251
|
+
return !!ftn && !declaresThis(ftn) && !keepsIdentity('function', q);
|
|
252
|
+
});
|
|
245
253
|
}
|
|
246
254
|
/** A function type, with null or undefined. */
|
|
247
255
|
function functionTypeNode(t) {
|
package/dist/semantics/facts.js
CHANGED
|
@@ -47,7 +47,7 @@ export class ProgramFacts {
|
|
|
47
47
|
return this.ifaceDecls;
|
|
48
48
|
const out = [];
|
|
49
49
|
const visit = (n) => {
|
|
50
|
-
if (isShapeInterfaceDecl(n))
|
|
50
|
+
if (isShapeInterfaceDecl(n) && !(this.checker.getSymbolAtLocation(n.name)?.flags & ts.SymbolFlags.Class))
|
|
51
51
|
out.push(n);
|
|
52
52
|
ts.forEachChild(n, visit);
|
|
53
53
|
};
|
package/dist/semantics/lang.js
CHANGED
|
@@ -281,3 +281,13 @@ export function untypedVariableInitializer(n, resolve) {
|
|
|
281
281
|
const d = ts.isVariableDeclaration(n) ? n : ts.isIdentifier(n) ? (ts.isVariableDeclaration(n.parent) && n.parent.name === n ? n.parent : resolve(n)?.valueDeclaration) : undefined;
|
|
282
282
|
return d && ts.isVariableDeclaration(d) && !d.type && d.initializer ? ts.skipOuterExpressions(d.initializer, ts.OuterExpressionKinds.Parentheses) : null;
|
|
283
283
|
}
|
|
284
|
+
/** Whether a built-in primitive constructor value (`Number`, `String`, `Boolean`) is a singleton constructor reference (`jsNumberConstructor`) or a typed converter slot. */
|
|
285
|
+
export function builtinConstructorSlot(e, checker, isUntypedContext) {
|
|
286
|
+
const context = checker.getContextualType(e);
|
|
287
|
+
const slot = context && checker.getNonNullableType(context).getCallSignatures()[0];
|
|
288
|
+
if (slot)
|
|
289
|
+
return { slot };
|
|
290
|
+
const p = e.parent;
|
|
291
|
+
const untyped = (!!context && isUntypedContext(context)) || (ts.isBinaryExpression(p) && [ts.SyntaxKind.EqualsEqualsToken, ts.SyntaxKind.ExclamationEqualsToken, ts.SyntaxKind.EqualsEqualsEqualsToken, ts.SyntaxKind.ExclamationEqualsEqualsToken].includes(p.operatorToken.kind));
|
|
292
|
+
return untyped ? { singleton: `js${e.text}Constructor` } : {};
|
|
293
|
+
}
|
package/dist/semantics/lower.js
CHANGED
|
@@ -88,3 +88,57 @@ export function flattenStringConcat(expr, isString) {
|
|
|
88
88
|
visit(expr);
|
|
89
89
|
return out;
|
|
90
90
|
}
|
|
91
|
+
/** Classifies `===`, `!==`, `==`, `!=` into nullish comparison, dynamic runtime helper, or direct backend comparison. */
|
|
92
|
+
export function planEquality(op, leftAny, rightAny, leftNullish, rightNullish) {
|
|
93
|
+
let kind;
|
|
94
|
+
let negated;
|
|
95
|
+
switch (op) {
|
|
96
|
+
case K.EqualsEqualsEqualsToken:
|
|
97
|
+
kind = 'strict';
|
|
98
|
+
negated = false;
|
|
99
|
+
break;
|
|
100
|
+
case K.ExclamationEqualsEqualsToken:
|
|
101
|
+
kind = 'strict';
|
|
102
|
+
negated = true;
|
|
103
|
+
break;
|
|
104
|
+
case K.EqualsEqualsToken:
|
|
105
|
+
kind = 'loose';
|
|
106
|
+
negated = false;
|
|
107
|
+
break;
|
|
108
|
+
case K.ExclamationEqualsToken:
|
|
109
|
+
kind = 'loose';
|
|
110
|
+
negated = true;
|
|
111
|
+
break;
|
|
112
|
+
default:
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
if (leftNullish || rightNullish)
|
|
116
|
+
return { kind, negated, mode: 'nullish' };
|
|
117
|
+
if (leftAny || rightAny || kind === 'loose')
|
|
118
|
+
return { kind, negated, mode: 'dynamic' };
|
|
119
|
+
return { kind, negated, mode: 'direct' };
|
|
120
|
+
}
|
|
121
|
+
/** Classifies `a ?? b` based on whether the left operand is untyped, optional, or statically present. */
|
|
122
|
+
export function planNullishCoalesce(leftAny, leftOptional) {
|
|
123
|
+
if (leftAny)
|
|
124
|
+
return { kind: 'dynamic' };
|
|
125
|
+
if (leftOptional)
|
|
126
|
+
return { kind: 'optional' };
|
|
127
|
+
return { kind: 'identity' };
|
|
128
|
+
}
|
|
129
|
+
/** Extracts `typeof x === 'tag'` (or `!==`, `==`, `!=`, in either operand order) into a backend-neutral descriptor. */
|
|
130
|
+
export function typeofComparison(e) {
|
|
131
|
+
const op = e.operatorToken.kind;
|
|
132
|
+
const strict = op === K.EqualsEqualsEqualsToken || op === K.ExclamationEqualsEqualsToken;
|
|
133
|
+
const loose = op === K.EqualsEqualsToken || op === K.ExclamationEqualsToken;
|
|
134
|
+
if (!strict && !loose)
|
|
135
|
+
return null;
|
|
136
|
+
const negated = op === K.ExclamationEqualsEqualsToken || op === K.ExclamationEqualsToken;
|
|
137
|
+
const left = ts.skipParentheses(e.left);
|
|
138
|
+
const right = ts.skipParentheses(e.right);
|
|
139
|
+
if (ts.isTypeOfExpression(left) && ts.isStringLiteralLike(right))
|
|
140
|
+
return { operand: left.expression, tag: right.text, negated, strict };
|
|
141
|
+
if (ts.isTypeOfExpression(right) && ts.isStringLiteralLike(left))
|
|
142
|
+
return { operand: right.expression, tag: left.text, negated, strict };
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
@@ -207,4 +207,9 @@ export const loweringMethods = {
|
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
},
|
|
210
|
+
/** Refuses a self-referencing named generator expression (`function* f() { yield f; }`). */
|
|
211
|
+
refuseNamedGenerator(fn) {
|
|
212
|
+
if (fn.asteriskToken)
|
|
213
|
+
throw this.error(fn, 'a named function expression', 'named-function-expression');
|
|
214
|
+
},
|
|
210
215
|
};
|
|
@@ -107,7 +107,7 @@ function placed(b, e, target, slot) {
|
|
|
107
107
|
throw b.error(e, rule.refuse);
|
|
108
108
|
// `readHeld` derives the carrier of a name or member read only; any other read's code converts itself.
|
|
109
109
|
const read = ts.skipOuterExpressions(e, ts.OuterExpressionKinds.Parentheses);
|
|
110
|
-
const code = rule.rule === 'untyped' && (ts.isIdentifier(read) || ts.isPropertyAccessExpression(read)) ? b.untypedRead(b.expr(e), target) : b.coerceTyped(e, target);
|
|
110
|
+
const code = rule.rule === 'untyped' && (ts.isIdentifier(read) || ts.isPropertyAccessExpression(read)) ? b.untypedRead(b.expr(e), target, e) : b.coerceTyped(e, target);
|
|
111
111
|
// A slot taking a string, number or boolean's undefined, or any value, takes it as it is, not converted.
|
|
112
112
|
if (takesUndefined(to)) {
|
|
113
113
|
const held = b.undefinedConverted(code) ?? (choice !== e && !b.library ? b.undefinedConverted(b.coerceTyped(choice, target)) : null);
|
|
@@ -564,9 +564,15 @@ export function assertedReceiverCell(b, target, key) {
|
|
|
564
564
|
return { cell: 'asIs' };
|
|
565
565
|
return receiverCell(b, receiverSlot(target, key));
|
|
566
566
|
}
|
|
567
|
-
/** An element read's receiver cell (`assertedReceiverCell`). */
|
|
567
|
+
/** An element read's receiver cell (`assertedReceiverCell` or `unsafeReceiver`). */
|
|
568
568
|
export function elementReceiverCell(b, e) {
|
|
569
|
-
|
|
569
|
+
if (ts.isOptionalChain(e))
|
|
570
|
+
return { cell: 'asIs' };
|
|
571
|
+
const key = keyName(e.argumentExpression);
|
|
572
|
+
const asserted = assertedReceiverCell(b, e.expression, key);
|
|
573
|
+
if (asserted.cell !== 'asIs')
|
|
574
|
+
return asserted;
|
|
575
|
+
return unsafeReceiver(e.expression, b.checker) ? receiverCell(b, receiverSlot(e.expression, key)) : { cell: 'asIs' };
|
|
570
576
|
}
|
|
571
577
|
/** The name a TypeError reading by `key` gives: a literal key's text, else the key's source. */
|
|
572
578
|
export function keyName(key) {
|
|
@@ -164,3 +164,14 @@ export function propSignal(e, checker, framework) {
|
|
|
164
164
|
const kind = name === undefined ? undefined : framework.signalKind(name);
|
|
165
165
|
return kind === 'input' || kind === 'model';
|
|
166
166
|
}
|
|
167
|
+
/** Whether `n` declares or references an untyped variable initialized from a read of a signal holding null (`const card = this.morning()`). */
|
|
168
|
+
export function isGivenNullSignalValue(n, resolve, isNullSignalRead) {
|
|
169
|
+
const d = (n.parent && ts.isVariableDeclaration(n.parent) && n.parent.name === n ? n.parent : ts.isIdentifier(n) ? resolve(n)?.valueDeclaration : undefined);
|
|
170
|
+
if (!d || !ts.isVariableDeclaration(d) || d.type || !d.initializer)
|
|
171
|
+
return false;
|
|
172
|
+
return isNullSignalRead(d.initializer);
|
|
173
|
+
}
|
|
174
|
+
/** Whether a class property declaration initializes a read-only signal via memoization or `.asReadonly()`. */
|
|
175
|
+
export function isReadonlySignalProperty(decl, checker, framework, callee) {
|
|
176
|
+
return !!framework.memoized(decl, checker) || /\.asReadonly$/.test(callee);
|
|
177
|
+
}
|
|
@@ -239,6 +239,13 @@ export const missingMethods = {
|
|
|
239
239
|
*/
|
|
240
240
|
widenedObject(x) {
|
|
241
241
|
const results = (e) => {
|
|
242
|
+
if (ts.isAwaitExpression(e)) {
|
|
243
|
+
const inner = ts.skipOuterExpressions(e.expression, ts.OuterExpressionKinds.Parentheses);
|
|
244
|
+
if (!ts.isCallExpression(inner))
|
|
245
|
+
return [];
|
|
246
|
+
const d = this.checker.getResolvedSignature(inner)?.getDeclaration();
|
|
247
|
+
return d && !ts.isJSDocSignature(d) && (this.lenientAsync(d) || !this.appCode(d)) ? [d] : [];
|
|
248
|
+
}
|
|
242
249
|
if (!ts.isCallExpression(e))
|
|
243
250
|
return [];
|
|
244
251
|
const d = this.checker.getResolvedSignature(e)?.getDeclaration();
|
package/dist/semantics/tdz.js
CHANGED
|
@@ -51,13 +51,14 @@ function addSameModuleTdz(checker, sf, out) {
|
|
|
51
51
|
}
|
|
52
52
|
if (!decls.size)
|
|
53
53
|
return;
|
|
54
|
-
// Track which
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
// Track which hoisted function declarations are reachable from executable statements before each statement index.
|
|
55
|
+
const hoistedFns = new Map();
|
|
56
|
+
for (const st of sf.statements) {
|
|
57
|
+
if (ts.isFunctionDeclaration(st) && st.name && st.body) {
|
|
58
|
+
const sym = checker.getSymbolAtLocation(st.name);
|
|
59
|
+
if (sym)
|
|
60
|
+
hoistedFns.set(sym, st);
|
|
61
|
+
}
|
|
61
62
|
}
|
|
62
63
|
const isRef = (n) => {
|
|
63
64
|
const p = n.parent;
|
|
@@ -71,28 +72,66 @@ function addSameModuleTdz(checker, sf, out) {
|
|
|
71
72
|
return false;
|
|
72
73
|
return true;
|
|
73
74
|
};
|
|
74
|
-
const
|
|
75
|
+
const referencedFnsIn = (root) => {
|
|
76
|
+
const refs = new Set();
|
|
77
|
+
const visit = (n) => {
|
|
78
|
+
if (ts.isIdentifier(n) && isRef(n)) {
|
|
79
|
+
const sym = resolveSymbol(n, checker);
|
|
80
|
+
if (sym && hoistedFns.has(sym))
|
|
81
|
+
refs.add(sym);
|
|
82
|
+
}
|
|
83
|
+
ts.forEachChild(n, visit);
|
|
84
|
+
};
|
|
85
|
+
ts.forEachChild(root, visit);
|
|
86
|
+
return refs;
|
|
87
|
+
};
|
|
88
|
+
const fnCalls = new Map();
|
|
89
|
+
for (const [sym, fn] of hoistedFns)
|
|
90
|
+
fnCalls.set(sym, referencedFnsIn(fn.body));
|
|
91
|
+
const closeReach = (seeds) => {
|
|
92
|
+
const reached = new Set(seeds);
|
|
93
|
+
const queue = [...seeds];
|
|
94
|
+
while (queue.length) {
|
|
95
|
+
const cur = queue.pop();
|
|
96
|
+
for (const next of fnCalls.get(cur) ?? []) {
|
|
97
|
+
if (!reached.has(next)) {
|
|
98
|
+
reached.add(next);
|
|
99
|
+
queue.push(next);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return reached;
|
|
104
|
+
};
|
|
105
|
+
const reachableFnsBefore = new Array(sf.statements.length);
|
|
106
|
+
const seenBefore = new Set();
|
|
107
|
+
for (let i = 0; i < sf.statements.length; i++) {
|
|
108
|
+
reachableFnsBefore[i] = closeReach(seenBefore);
|
|
109
|
+
const st = sf.statements[i];
|
|
110
|
+
if (!ts.isFunctionDeclaration(st) && canRunCode(st)) {
|
|
111
|
+
for (const s of referencedFnsIn(st))
|
|
112
|
+
seenBefore.add(s);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const walk = (node, stmtIndex, hoistedSym, inDeferredScope) => {
|
|
75
116
|
if (ts.isIdentifier(node) && isRef(node)) {
|
|
76
117
|
const sym = resolveSymbol(node, checker);
|
|
77
118
|
const entry = sym ? decls.get(sym) : undefined;
|
|
78
119
|
if (entry) {
|
|
79
|
-
const priorExecutable = runnableBefore[entry.stmtIndex] ||
|
|
80
|
-
(stmtIndex === entry.stmtIndex &&
|
|
81
|
-
ts.isVariableStatement(sf.statements[stmtIndex]) &&
|
|
82
|
-
sf.statements[stmtIndex].declarationList.declarations.slice(0, entry.declIndex).some((prev) => !!prev.initializer && exprCanRunCode(prev.initializer)));
|
|
83
120
|
const beforeDecl = stmtIndex < entry.stmtIndex;
|
|
84
121
|
const inOwnInit = !inDeferredScope && stmtIndex === entry.stmtIndex && node.pos >= entry.decl.initializer.pos && node.end <= entry.decl.initializer.end;
|
|
85
|
-
|
|
122
|
+
const fnReachableEarly = !!hoistedSym && reachableFnsBefore[entry.stmtIndex].has(hoistedSym);
|
|
123
|
+
if ((beforeDecl && !inDeferredScope) || fnReachableEarly || inOwnInit) {
|
|
86
124
|
out.add(entry.decl);
|
|
87
125
|
}
|
|
88
126
|
}
|
|
89
127
|
}
|
|
90
128
|
const entersDeferred = ts.isFunctionLike(node) || ts.isClassStaticBlockDeclaration(node);
|
|
91
|
-
ts.forEachChild(node, (child) => walk(child, stmtIndex,
|
|
129
|
+
ts.forEachChild(node, (child) => walk(child, stmtIndex, hoistedSym, inDeferredScope || entersDeferred));
|
|
92
130
|
};
|
|
93
131
|
for (let i = 0; i < sf.statements.length; i++) {
|
|
94
132
|
const st = sf.statements[i];
|
|
95
|
-
|
|
133
|
+
const hoistedSym = ts.isFunctionDeclaration(st) && st.name ? (checker.getSymbolAtLocation(st.name) ?? null) : null;
|
|
134
|
+
walk(st, i, hoistedSym, false);
|
|
96
135
|
}
|
|
97
136
|
}
|
|
98
137
|
/**
|
package/dist/semantics/throws.js
CHANGED
|
@@ -460,7 +460,7 @@ export class Throws {
|
|
|
460
460
|
return true;
|
|
461
461
|
if (ts.isPropertyAccessExpression(n) && !n.questionDotToken && unsafeReceiver(n.expression, c))
|
|
462
462
|
return true;
|
|
463
|
-
if (ts.isElementAccessExpression(n) && !n.questionDotToken &&
|
|
463
|
+
if (ts.isElementAccessExpression(n) && !n.questionDotToken && unsafeReceiver(n.expression, c))
|
|
464
464
|
return true;
|
|
465
465
|
if ((ts.isPropertyAccessExpression(n) || ts.isElementAccessExpression(n)) && !n.questionDotToken && uncheckedMatch(n.expression, c))
|
|
466
466
|
return true;
|
|
@@ -534,7 +534,7 @@ export class Throws {
|
|
|
534
534
|
// A library function held (`export const parse = parseFloat`, `const { isArray } = Array`): Swift holds it as a function value, which throws.
|
|
535
535
|
if (ts.isCallExpression(call) && holder && !holder.getSourceFile().isDeclarationFile && ((init && (ts.isIdentifier(init) || ts.isPropertyAccessExpression(init)) && (['parseInt', 'parseFloat'].includes(init.getText()) || !!signature?.getSourceFile().isDeclarationFile)) || (ts.isBindingElement(holder) && !!signature?.getSourceFile().isDeclarationFile)))
|
|
536
536
|
return true;
|
|
537
|
-
if ((ts.isCallExpression(call) || ts.isNewExpression(call)) && holder && !holder.getSourceFile().isDeclarationFile && !signature?.getSourceFile().isDeclarationFile && (ts.isVariableDeclaration(holder) || ts.isBindingElement(holder) || ts.isParameter(holder) || ts.isPropertyDeclaration(holder) || ts.isPropertySignature(holder) || ts.isPropertyAssignment(holder) || ts.isGetAccessorDeclaration(holder) || ts.isShorthandPropertyAssignment(holder)))
|
|
537
|
+
if ((ts.isCallExpression(call) || ts.isNewExpression(call)) && holder && !holder.getSourceFile().isDeclarationFile && (!signature?.getSourceFile().isDeclarationFile || ts.isFunctionTypeNode(signature) || (ts.isCallSignatureDeclaration(signature) && isLibFile(signature.getSourceFile()))) && (ts.isVariableDeclaration(holder) || ts.isBindingElement(holder) || ts.isParameter(holder) || ts.isPropertyDeclaration(holder) || ts.isPropertySignature(holder) || ts.isPropertyAssignment(holder) || ts.isGetAccessorDeclaration(holder) || ts.isShorthandPropertyAssignment(holder)))
|
|
538
538
|
return true;
|
|
539
539
|
// A local holding a library function (`const dip = Utils.layout.toDeviceIndependentPixels`), or one a call made (`view.dispose.bind(view)`): a Swift function value, which throws.
|
|
540
540
|
if (ts.isCallExpression(call) && holder && ts.isVariableDeclaration(holder) && !holder.getSourceFile().isDeclarationFile && holder.initializer && (ts.isPropertyAccessExpression(skipParens(holder.initializer)) || ts.isCallExpression(skipParens(holder.initializer))))
|
|
@@ -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,7 +6,7 @@ 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 {
|
|
9
|
+
import { escapingFunction, functionParts, hasTopLevelArrow, ident, identPath, isFunctionType, isOptional, openSwiftChain, optionalType, splitTopLevel, swiftString, RT, lenientReader } from "./syntax.js";
|
|
10
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";
|
|
@@ -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. */
|
|
@@ -612,10 +614,6 @@ export const accessMethods = {
|
|
|
612
614
|
}
|
|
613
615
|
return this.returnTypeOf(decl);
|
|
614
616
|
},
|
|
615
|
-
/** `assertedUntyped`'s cast: strict code's, to a class or shape whose checked conversion can fail. */
|
|
616
|
-
untypedCastChecks(e, t) {
|
|
617
|
-
return !this.lenient && this.isObjectRef(e) && this.castChecks(spell(t));
|
|
618
|
-
},
|
|
619
617
|
/** An `assertedUntyped` assertion read as the optional it may be: missing where the value is undefined or null. */
|
|
620
618
|
/** `x as Iterable<T>` of a value not held as one: whatever x holds iterated, as GetIterator does where it is iterated. */
|
|
621
619
|
assertedIterable(e) {
|
package/dist/swift/arguments.js
CHANGED
|
@@ -7,17 +7,20 @@ import { isStatic } from "../semantics/throws.js";
|
|
|
7
7
|
import { isUntyped, spelledType } from "../semantics/types.js";
|
|
8
8
|
import { untypedGeneric } from "../semantics/spelled.js";
|
|
9
9
|
import { baseMethod } from "../semantics/classes.js";
|
|
10
|
+
import { isCoreDeclaration } from "../program/core-facts.js";
|
|
10
11
|
export const argumentsMethods = {
|
|
12
|
+
/** Whether `decl` is a parameter whose declared type names a type parameter Swift erased. */
|
|
13
|
+
erasedParam(decl) {
|
|
14
|
+
return ((!!decl && ts.isParameter(decl) && ts.isClassLike(decl.parent.parent) && !!decl.parent.parent.typeParameters?.length && this.erasesGenerics(decl.parent.parent)) ||
|
|
15
|
+
(!!decl && ts.isParameter(decl) && ts.isMethodSignature(decl.parent) && this.erasingProtocol(decl.parent)) ||
|
|
16
|
+
(!!decl && ts.isParameter(decl) && !!decl.type && !decl.getSourceFile().isDeclarationFile && !!decl.parent.typeParameters?.some((tp) => (this.erasesTypeParameter(tp) || (!this.library && this.erasesGenerics(decl.parent))) && new RegExp(`\\b${tp.name.text}\\b`).test(decl.type.getText()))));
|
|
17
|
+
},
|
|
11
18
|
/** The slot the parameter `p`, the `k`th, is at call `e` given `a`: Swift's type of it there, and how it takes a missing value. */
|
|
12
19
|
paramSlot(e, p, k, a) {
|
|
13
20
|
const decl = p.valueDeclaration;
|
|
14
21
|
const slot = (target, facts) => argumentSlot(this.placement, target, decl, { call: e, k, a }, facts);
|
|
15
22
|
// A method or constructor of a generic class Swift has erased: the parameter's type as the method declares it.
|
|
16
|
-
const erased =
|
|
17
|
-
// A method of an app's generic interface, whose protocol erases the interface's type parameters.
|
|
18
|
-
(!!decl && ts.isParameter(decl) && ts.isMethodSignature(decl.parent) && this.erasingProtocol(decl.parent)) ||
|
|
19
|
-
// A program function's type parameter Swift erases (`U extends { root: View }`, any of a plugin's): the parameter as declared, the argument's type erased with it.
|
|
20
|
-
(!!decl && ts.isParameter(decl) && !!decl.type && !decl.getSourceFile().isDeclarationFile && !!decl.parent.typeParameters?.some((tp) => (this.erasesTypeParameter(tp) || (!this.library && this.erasesGenerics(decl.parent))) && new RegExp(`\\b${tp.name.text}\\b`).test(decl.type.getText())));
|
|
23
|
+
const erased = this.erasedParam(decl);
|
|
21
24
|
// An array of the class or a subclass where the function takes `JSArray<some C>`: the array itself.
|
|
22
25
|
if (decl && ts.isParameter(decl) && this.opaqueArrayParam(decl))
|
|
23
26
|
return slot(this.typeOf(a));
|
|
@@ -108,14 +111,14 @@ export const argumentsMethods = {
|
|
|
108
111
|
const out = [];
|
|
109
112
|
const restAt = params.findIndex((p) => p.valueDeclaration && ts.isParameter(p.valueDeclaration) && p.valueDeclaration.dotDotDotToken);
|
|
110
113
|
// A function type's rest parameter too (`mainThreadify(fn)` gives `(...args) => void`, or `String.fromCharCode.bind(String)`): Swift's function type takes it as `JSRest`.
|
|
111
|
-
const calleeRest = !this.library && ts.isCallExpression(e) && restAt >= 0 && functionParts(this.typeOf(e.expression).replace(/^\((.*)\)[?!]$/, '$1'))?.rest === restAt;
|
|
114
|
+
const calleeRest = !this.library && ts.isCallExpression(e) && restAt >= 0 && !isCoreDeclaration(sig?.getDeclaration()) && functionParts(this.typeOf(e.expression).replace(/^\((.*)\)[?!]$/, '$1'))?.rest === restAt;
|
|
112
115
|
const appDeclared = (!!sig?.getDeclaration() && (!sig.getDeclaration().getSourceFile().isDeclarationFile || (!this.library && ts.isFunctionTypeNode(sig.getDeclaration())))) || calleeRest;
|
|
113
116
|
let covered = list.length;
|
|
114
117
|
for (let k = 0; k < list.length; k++) {
|
|
115
118
|
const a = list[k];
|
|
116
119
|
if (restAt >= 0 && k >= restAt && appDeclared) {
|
|
117
120
|
// An app function's rest parameter is one array: the arguments packed, spreads included.
|
|
118
|
-
const calleeParam = ts.isCallExpression(e) ? functionParts(this.typeOf(e.expression).replace(/^\((.*)\)[?!]$/, '$1'))?.params[restAt]?.replace(/^JSRest<(.*)>$/, 'JSArray<$1>') : undefined;
|
|
121
|
+
const calleeParam = !this.erasedParam(params[restAt].valueDeclaration) && ts.isCallExpression(e) ? functionParts(this.typeOf(e.expression).replace(/^\((.*)\)[?!]$/, '$1'))?.params[restAt]?.replace(/^JSRest<(.*)>$/, 'JSArray<$1>') : undefined;
|
|
119
122
|
const rest = calleeParam && /^JSArray<.*>$/.test(calleeParam) ? calleeParam : this.restType(params[restAt]);
|
|
120
123
|
out.push(this.packed(list.slice(k), rest, this.restSlot(e, rest.replace(/^JSArray<(.*)>$/, '$1'), params[restAt].valueDeclaration)));
|
|
121
124
|
break;
|
|
@@ -143,8 +146,10 @@ export const argumentsMethods = {
|
|
|
143
146
|
throw this.error(a, 'a spread argument');
|
|
144
147
|
const held = this.typeOf(a.expression);
|
|
145
148
|
const code = this.expr(a.expression);
|
|
149
|
+
const calleeParams = !appDeclared && ts.isCallExpression(e) ? functionParts(this.typeOf(e.expression).replace(/^\((.*)\)[?!]$/, '$1'))?.params : undefined;
|
|
146
150
|
tuple.forEach((el, i) => {
|
|
147
|
-
const
|
|
151
|
+
const cp = calleeParams?.[k + i];
|
|
152
|
+
const given = cp && !cp.startsWith('JSRest<') ? cp.replace(/^@escaping /, '') : this.type(this.checker.getTypeOfSymbolAtLocation(params[k + i], e), e);
|
|
148
153
|
const slot = this.spreadSlot(e, params[k + i], k + i, this.filledDefault(params[k + i].valueDeclaration) ? optionalType(given) : given);
|
|
149
154
|
out.push(held.startsWith('(') && !functionParts(held) ? this.convert(`${code}.${i}`, this.type(el, e), slot.target) : this.presentFromAny(`${RT.jsArg}(${this.coerce(a.expression, 'JSArray<Any?>')}.storage, ${i})`, slot.target, true));
|
|
150
155
|
});
|
|
@@ -188,7 +193,7 @@ export const argumentsMethods = {
|
|
|
188
193
|
// A rest of a type parameter (`bind`'s `(...args: A) => R`): Swift's function type takes it as one untyped array.
|
|
189
194
|
if (d.type && this.isBareTypeParameter(d.type))
|
|
190
195
|
return 'JSArray<Any?>';
|
|
191
|
-
const t = this.typeOf(d.name);
|
|
196
|
+
const t = this.inFile(d.getSourceFile().fileName, () => this.typeOf(d.name));
|
|
192
197
|
return isUntyped(spelledType(t)) ? 'JSArray<Any?>' : t;
|
|
193
198
|
},
|
|
194
199
|
/** The arguments of a call on an untyped value from its `from`th: each, or with spreads, all as one list. */
|
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);
|
|
@@ -238,8 +244,13 @@ export const assignmentMethods = {
|
|
|
238
244
|
if (d && ts.isVariableDeclaration(d) && !d.initializer && !ts.isSourceFile(d.parent.parent.parent))
|
|
239
245
|
return this.marks.assignedCode(this.expr(left), 'nil');
|
|
240
246
|
}
|
|
241
|
-
if (ts.isPropertyAccessExpression(left) && this.isAddedMember(left))
|
|
247
|
+
if (ts.isPropertyAccessExpression(left) && this.isAddedMember(left)) {
|
|
248
|
+
const target = this.checker.getNonNullableType(this.checker.getTypeAtLocation(left.expression));
|
|
249
|
+
if (target.isIntersection() && target.types.some((t) => this.native.type(t))) {
|
|
250
|
+
return `${RT.jsNativeSet}(${this.expr(left.expression)}, ${swiftString(left.name.text)}, ${this.stored(right, left, 'Any?', checks)})`;
|
|
251
|
+
}
|
|
242
252
|
return `(${this.expr(left.expression)} as JSDynamic)[jsKey: ${swiftString(left.name.text)}] = ${this.stored(right, left, 'Any?', checks)}`;
|
|
253
|
+
}
|
|
243
254
|
if (ts.isPropertyAccessExpression(left) && this.isNativeExpando(left))
|
|
244
255
|
return `${RT.jsSetNativeExpando}(${this.expr(left.expression)}, ${swiftString(left.name.text)}, ${this.stored(right, left, 'Any?', checks)})`;
|
|
245
256
|
if (ts.isPropertyAccessExpression(left) && this.isExpando(left))
|
package/dist/swift/calls.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Calls as Swift: functions, methods, prototype calls, JavaScript globals and statics, native dispatch.
|
|
2
2
|
import ts from 'typescript';
|
|
3
|
-
import { LIST_APPLIED, isTypedArrayType } from "./library.js";
|
|
3
|
+
import { LIB_FUNCTION_VALUES, LIST_APPLIED, isTypedArrayType } from "./library.js";
|
|
4
4
|
import { isLibGlobal } from "../semantics/globals.js";
|
|
5
5
|
import { comparedToNullish, functionParts, hasTopLevelArrow, ident, isFunctionType, isOptional, isSymbolAsyncIterator, openSwiftChain, optionalType, swiftString, RT } from "./syntax.js";
|
|
6
6
|
import { assertedReceiverCell, nullishField } from "../semantics/placement.js";
|
|
@@ -33,6 +33,8 @@ export const callsMethods = {
|
|
|
33
33
|
isDomGlobal(e) {
|
|
34
34
|
if (this.library || !ts.isIdentifier(e) || (ts.isPropertyAccessExpression(e.parent) && e.parent.name === e) || ts.isTypeNode(e.parent))
|
|
35
35
|
return false;
|
|
36
|
+
if (Object.hasOwn(LIB_FUNCTION_VALUES, e.text))
|
|
37
|
+
return false;
|
|
36
38
|
const decls = this.resolve(e)?.declarations ?? [];
|
|
37
39
|
// A plugin's name nothing declares here (`window` where its own build had the DOM's typings): the global object's, undefined.
|
|
38
40
|
if (!decls.length)
|
|
@@ -54,7 +56,7 @@ export const callsMethods = {
|
|
|
54
56
|
return this.marks.ownTried(`${own !== undefined && this.props.has(own) ? `self.${ident(own)}` : this.expr(callee)}.requiredValue()`);
|
|
55
57
|
if (own !== undefined && (this.props.has(own) || this.signalFields.has(own)))
|
|
56
58
|
return `self.${ident(own)}.value`;
|
|
57
|
-
if (this.framework.signalKind(this.symbolName(callee)) === 'computed' && this.
|
|
59
|
+
if (this.framework.signalKind(this.symbolName(callee)) === 'computed' && this.isSwiftComputedProperty(callee))
|
|
58
60
|
return this.expr(callee);
|
|
59
61
|
return plain(`${this.expr(callee)}.value`);
|
|
60
62
|
},
|
|
@@ -226,7 +228,7 @@ export const callsMethods = {
|
|
|
226
228
|
const builtin = method === 'call' || method === 'apply' ? this.builtinPrototypeCall(method, target, e) : null;
|
|
227
229
|
if (builtin)
|
|
228
230
|
return builtin;
|
|
229
|
-
if (['call', 'apply', 'bind'].includes(method) && isLibDeclaration(this.checker.getResolvedSignature(e)?.getDeclaration()) && functionParts(this.typeOf(target).replace(/^\((.*)\)[?!]$/, '$1')))
|
|
231
|
+
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
232
|
return this.functionMethod(method, target, e);
|
|
231
233
|
if ((method === 'call' || method === 'apply') && this.programPrototypeMethod(target) && isLibDeclaration(this.checker.getResolvedSignature(e)?.getDeclaration()))
|
|
232
234
|
return this.functionMethod(method, target, e);
|
|
@@ -260,7 +262,7 @@ export const callsMethods = {
|
|
|
260
262
|
}
|
|
261
263
|
// A field holding a function untyped (`private _resolve;`): called with the object as `this`.
|
|
262
264
|
const field = this.resolve(callee.name)?.valueDeclaration;
|
|
263
|
-
if (this.isAny(callee) && field && (ts.isPropertyDeclaration(field) || ts.isPropertySignature(field) || ts.isParameter(field))) {
|
|
265
|
+
if (this.isAny(callee) && field && (ts.isPropertyDeclaration(field) || ts.isPropertySignature(field) || (ts.isMethodSignature(field) && !isLibDeclaration(field)) || ts.isParameter(field))) {
|
|
264
266
|
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
267
|
const code = `${RT.jsCallValue}(${this.expr(callee)}, this: ${this.coerce(target, 'Any?')}, optional: ${!!e.questionDotToken}, ${args})`;
|
|
266
268
|
const t = this.typeOf(e);
|
|
@@ -296,6 +298,9 @@ export const callsMethods = {
|
|
|
296
298
|
return this.ignoringThisArg(e, target, () => this.call(typedThisArg));
|
|
297
299
|
if (isKit(spelledType(t), 'JSArray')) {
|
|
298
300
|
// `observers?.find(…)` on an array TypeScript types as present, which lenient code may hold as undefined: cast to optional, valid either way.
|
|
301
|
+
const checked = !callee.questionDotToken && !ts.isOptionalChain(callee) ? this.receiver(target, method) : null;
|
|
302
|
+
if (checked)
|
|
303
|
+
return this.arrayMethod(method, target, e, '', this.marks.ownTried(checked));
|
|
299
304
|
const asserted = callee.questionDotToken ? null : assertedReceiverCell(this.receivers, target, method);
|
|
300
305
|
if (asserted?.cell === 'present')
|
|
301
306
|
return this.arrayMethod(method, target, e, q, this.marks.ownTried(this.receiverCode(asserted, method)));
|
|
@@ -481,9 +486,12 @@ export const callsMethods = {
|
|
|
481
486
|
if (ts.isNonNullExpression(callee)) {
|
|
482
487
|
if (!/[?!]$/.test(this.typeOf(callee.expression)))
|
|
483
488
|
return this.call(ts.factory.updateCallExpression(e, callee.expression, e.typeArguments, e.arguments));
|
|
489
|
+
const fn = this.expr(callee.expression);
|
|
490
|
+
if (/^(?:try\s+)?FunctionCell_\w+\.present\(/.test(fn))
|
|
491
|
+
return `(${fn})(${this.args(e).join(', ')})`;
|
|
484
492
|
const label = ts.isPropertyAccessExpression(callee.expression) || ts.isIdentifier(callee.expression) ? callee.expression.getText() : null;
|
|
485
493
|
const fnType = this.typeOf(callee.expression).replace(/^\((.*)\)[?!]$/, '$1').replace(/[?!]$/, '');
|
|
486
|
-
return label ? `({ () throws -> ${fnType} in guard let __fn = ${this.tryPrefix(callee.expression)}${
|
|
494
|
+
return label ? `({ () throws -> ${fnType} in guard let __fn = ${this.tryPrefix(callee.expression)}${fn} else { throw JSException(JSTypeError(${swiftString(`${label} is not a function`)})) }; return __fn }())(${this.args(e).join(', ')})` : `${RT.jsCallee}(${fn})(${this.args(e).join(', ')})`;
|
|
487
495
|
}
|
|
488
496
|
throw this.error(e, 'call');
|
|
489
497
|
},
|