@nstudio/nativescript-compiler 9.2.0-alpha.18 → 9.2.0-alpha.20
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/config.js +1 -0
- package/dist/kotlin/arguments.js +6 -0
- package/dist/kotlin/class-methods.js +4 -4
- package/dist/kotlin/overrides.js +1 -1
- package/dist/kotlin/placement.js +23 -2
- package/dist/kotlin/untyped-values.js +5 -0
- package/dist/semantics/conversion.js +9 -1
- package/dist/semantics/runtime.js +1 -0
- package/dist/semantics/signals.js +1 -1
- package/dist/semantics/throws.js +1 -1
- package/dist/swift/arguments.js +14 -9
- package/dist/swift/assignment.js +6 -1
- package/dist/swift/calls.js +7 -2
- package/dist/swift/class-methods.js +2 -1
- package/dist/swift/library.js +2 -2
- package/dist/swift/method-values.js +2 -1
- package/dist/swift/names.js +4 -4
- package/dist/swift/native/calls.js +9 -3
- package/dist/swift/placement.js +18 -3
- package/dist/swift/static-calls.js +1 -1
- package/dist/swift/syntax.js +1 -1
- package/dist/swift/types.js +2 -2
- package/kit-android/generated/kotlin/org/nativescript/kit/data_observable_array_index.kt +8 -0
- package/kit-android/generated/kotlin/org/nativescript/kit/data_observable_index.kt +16 -0
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_builder_index.kt +2 -0
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_properties_index.kt +38 -37
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_view_base_index.kt +9 -0
- 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/Dynamic.kt +28 -13
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Language.kt +10 -2
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Values.kt +11 -10
- package/kit-apple/Overlays/xml-free/Core/ui.builder.index.swift +6 -2
- package/kit-apple/Sources/NativeScriptKit/Core/data.observable-array.index.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/file-system.file-system-access.ios.swift +7 -7
- package/kit-apple/Sources/NativeScriptKit/Core/file-system.index.swift +10 -10
- package/kit-apple/Sources/NativeScriptKit/Core/http.http-request-internal.index.ios.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/http.index.swift +3 -3
- package/kit-apple/Sources/NativeScriptKit/Core/image-source.index.ios.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/js-libs.easysax.easysax.swift +4 -22
- package/kit-apple/Sources/NativeScriptKit/Core/kit-index.json +2 -1
- 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.keyframe-animation.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.builder.index.swift +6 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.button.index.ios.swift +14 -13
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.properties.index.swift +8 -7
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.index.ios.swift +79 -59
- 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.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.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 +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.progress.index.ios.swift +12 -10
- 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 +14 -9
- 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 +2 -2
- 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.time-picker.index.ios.swift +22 -18
- package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.shared-transition-helper.ios.swift +15 -15
- 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.index.ios.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Runtime/Dynamic.swift +6 -2
- package/kit-apple/Sources/NativeScriptKit/Runtime/Functions.swift +3 -1
- package/kit-apple/Sources/NativeScriptKit/Runtime/Native.swift +2 -1
- package/kit-apple/Sources/NativeScriptKit/Runtime/Values.swift +5 -2
- package/package.json +5 -3
package/config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/kotlin/arguments.js
CHANGED
|
@@ -17,6 +17,10 @@ export const argumentsMethods = {
|
|
|
17
17
|
if (decl && this.states.nullishHeld(decl))
|
|
18
18
|
return argumentSlot(this.placement, nullishType(this.type(this.checker.getTypeOfSymbolAtLocation(p, e), e)), decl, at, { nullish: true });
|
|
19
19
|
let pt = decl && this.states.nullish().held.has(decl) ? 'Any?' : this.heldElements(decl && ts.isParameter(decl) ? decl : e, this.type(this.checker.getTypeOfSymbolAtLocation(p, e), e));
|
|
20
|
+
// An overloaded declared function held as a Kotlin function value (`cancelAnimationFrame`) takes its Kotlin type's parameter.
|
|
21
|
+
const calleeParam = !appDeclared && ts.isCallExpression(e) ? functionTypeParts(this.typeOf(e.expression).replace(/^\((.*)\)\?$/, '$1'))?.params[k] : undefined;
|
|
22
|
+
if (calleeParam && !calleeParam.startsWith('JSArray<'))
|
|
23
|
+
pt = calleeParam;
|
|
20
24
|
// A generic implementation's parameter is not instantiated by an overload's call: the overload's, as this call instantiates it.
|
|
21
25
|
const implTypes = impl && impl !== sig?.getDeclaration() ? (impl.typeParameters?.map((t) => t.name.text) ?? []) : [];
|
|
22
26
|
const resolved = sig?.getParameters()[k];
|
|
@@ -332,6 +336,8 @@ export const argumentsMethods = {
|
|
|
332
336
|
const decl = params[k + i].valueDeclaration;
|
|
333
337
|
if (s.constantDefault && isNullable(el.type))
|
|
334
338
|
out.push(`(${this.convert(el.code, el.type, optionalType(s.target))} ?: ${this.coerce(decl.initializer, s.target)})`);
|
|
339
|
+
else if (el.type === optionalType(s.target) && ['Double', 'String', 'Boolean'].includes(s.target))
|
|
340
|
+
out.push(`(${el.code} ?: ${s.target === 'Double' ? 'Double.NaN' : s.target === 'String' ? '"undefined"' : 'false'})`);
|
|
335
341
|
else if (isNullable(el.type) && !isNullable(s.target) && !isUntyped(spelledType(s.target)) && !isUntyped(spelledType(el.type)))
|
|
336
342
|
return null;
|
|
337
343
|
else
|
|
@@ -142,7 +142,7 @@ export const classMethodsMethods = {
|
|
|
142
142
|
const own = !overridden.has(n) && /^\$[be]\d+$/.test(n) ? 'internal ' : '';
|
|
143
143
|
lines.push(' ' + this.func(m, this.methodIdent(n), (this.erasedSignatureMethods.has(m) ? `@JvmName("${n}__typed") ` : '') + own + (kotlinEquals ? 'override ' : this.memberMods(k, n))));
|
|
144
144
|
// A plugin's objects are read untyped too (`handler.attachToView(view)` on an `any`): their methods by name.
|
|
145
|
-
if (plugin && !m
|
|
145
|
+
if (plugin && !this.generics(m) && !m.parameters.some((p) => p.dotDotDotToken))
|
|
146
146
|
k.dynMethods.push({ name: n, params: m.parameters.map((p) => this.paramType(p)), ret: this.returnTypeOf(m) });
|
|
147
147
|
},
|
|
148
148
|
abstractMethodCode(k, m) {
|
|
@@ -188,7 +188,7 @@ export const classMethodsMethods = {
|
|
|
188
188
|
}
|
|
189
189
|
// Called by its symbol with the Kotlin signature it has: the overridden one's.
|
|
190
190
|
const sig = root && root !== m ? root : m;
|
|
191
|
-
if (!isStatic(m) && !sig.parameters.some((p) => p.dotDotDotToken) && !sig
|
|
191
|
+
if (!isStatic(m) && !sig.parameters.some((p) => p.dotDotDotToken) && !this.generics(sig) && !this.readsArguments(sig)) {
|
|
192
192
|
const key = keyed.fixed ? keyed.key : this.capturedSymbolKey(k, keyed.key);
|
|
193
193
|
k.dynMethods.push({ name: keyed.member, key, fixed: keyed.fixed, either: keyed.either, maybeUndefined: keyed.key.includes('?: "undefined"'), params: sig.parameters.map((p) => this.paramType(p)), unread: m.parameters.map((p) => this.unreadParameter(m, p)), ret: this.returnTypeOf(sig) });
|
|
194
194
|
}
|
|
@@ -202,7 +202,7 @@ export const classMethodsMethods = {
|
|
|
202
202
|
// Library mode: every method of the class is read by name as well (`font.getAndroidTypeface()` on an untyped font), overrides included.
|
|
203
203
|
if (this.library || byName || droppedProtocolMembers.size > 0 || this.membersByName(cls) || this.states.downcastClass(cls) || this.states.byNameClass(cls)) {
|
|
204
204
|
const addMethod = (m) => {
|
|
205
|
-
if (!m.body || isStatic(m) || ts.isComputedPropertyName(m.name) || ts.isPrivateIdentifier(m.name) || m
|
|
205
|
+
if (!m.body || isStatic(m) || ts.isComputedPropertyName(m.name) || ts.isPrivateIdentifier(m.name) || this.generics(m) || m.parameters.some((p) => p.dotDotDotToken) || this.readsArguments(m))
|
|
206
206
|
return;
|
|
207
207
|
const n = m.name.getText();
|
|
208
208
|
if (dynMethods.some((d) => d.name === n && !d.key) || n === 'toString' || n === 'equals')
|
|
@@ -217,7 +217,7 @@ export const classMethodsMethods = {
|
|
|
217
217
|
let root = m;
|
|
218
218
|
for (let up = this.inheritedMethod(cls, n); up; up = this.inheritedMethod(up.parent, n))
|
|
219
219
|
root = up;
|
|
220
|
-
if (root.parameters.length !== m.parameters.length)
|
|
220
|
+
if (root.parameters.length !== m.parameters.length || this.generics(root))
|
|
221
221
|
return;
|
|
222
222
|
dynMethods.push({ name: n, params: root.parameters.map((p) => this.paramType(p)), defaults: root.parameters.map((p) => (this.constantDefault(p) ? this.stored(p.initializer, p, this.paramType(p)) : undefined)), ret: this.returnTypeOf(root) });
|
|
223
223
|
};
|
package/dist/kotlin/overrides.js
CHANGED
|
@@ -472,7 +472,7 @@ export const overridesMethods = {
|
|
|
472
472
|
if (!decls.length)
|
|
473
473
|
return this.pluginFiles.has(e.getSourceFile().fileName) && !isArguments(e, this.checker) && !['undefined', 'NaN', 'Infinity'].includes(e.text);
|
|
474
474
|
// The animation-frame functions held as values: kit-android's runtime has none.
|
|
475
|
-
if (['requestAnimationFrame', 'cancelAnimationFrame'].includes(e.text) && decls.every((d) => d.getSourceFile().
|
|
475
|
+
if (['requestAnimationFrame', 'cancelAnimationFrame'].includes(e.text) && decls.every((d) => d.getSourceFile().isDeclarationFile) && !(ts.isCallExpression(e.parent) && e.parent.expression === e))
|
|
476
476
|
return true;
|
|
477
477
|
return isDomGlobalDeclaration(e.text, decls);
|
|
478
478
|
},
|
package/dist/kotlin/placement.js
CHANGED
|
@@ -394,10 +394,14 @@ export const placementMethods = {
|
|
|
394
394
|
const thisTaking = parts &&
|
|
395
395
|
parts.params.length >= 1 &&
|
|
396
396
|
parts.params.length <= 5 &&
|
|
397
|
-
this.checker
|
|
397
|
+
(this.checker
|
|
398
398
|
.getTypeAtLocation(e)
|
|
399
399
|
.getCallSignatures()
|
|
400
|
-
.some((sig) => !!sig.thisParameter)
|
|
400
|
+
.some((sig) => !!sig.thisParameter) ||
|
|
401
|
+
!!this.checker
|
|
402
|
+
.getContextualType(e)
|
|
403
|
+
?.getCallSignatures()
|
|
404
|
+
.some((sig) => !!sig.thisParameter));
|
|
401
405
|
if (thisTaking) {
|
|
402
406
|
const code = cast(`${RT.jsThisFunction}(__f, ${parts.params.length})`, target.replace(/^\((.*)\)\?$/, '$1'));
|
|
403
407
|
return `run { val __f = ${this.expr(e)}; ${/\)\?$/.test(target) ? `if (${RT.jsIsNullish}(__f)) null else ${code}` : code} }`;
|
|
@@ -459,6 +463,23 @@ export const placementMethods = {
|
|
|
459
463
|
const call = `${this.library ? this.refName(e) : ident(e.text)}(${names.map((n, k) => this.convert(n, g.params[k], f.params[k])).join(', ')})`;
|
|
460
464
|
return `{ ${g.params.map((p, k) => `${names[k]}: ${p}`).join(', ')} -> ${call} }`;
|
|
461
465
|
}
|
|
466
|
+
// A function value typed without `this` (`stylePropertyDescriptor.set`: `(v: any) => void`) placed where a `this`-taking function is wanted (`(this: T, value) => void`): preserve any underlying `JSMethod`'s receiver instead of dropping `value`.
|
|
467
|
+
if (f &&
|
|
468
|
+
g &&
|
|
469
|
+
f.params.length < g.params.length &&
|
|
470
|
+
g.params.length <= 5 &&
|
|
471
|
+
!this.checker
|
|
472
|
+
.getTypeAtLocation(e)
|
|
473
|
+
.getCallSignatures()
|
|
474
|
+
.some((sig) => !!sig.thisParameter) &&
|
|
475
|
+
this.checker
|
|
476
|
+
.getContextualType(e)
|
|
477
|
+
?.getCallSignatures()
|
|
478
|
+
.some((sig) => !!sig.thisParameter)) {
|
|
479
|
+
const raw = ts.isPropertyAccessExpression(e) && !e.questionDotToken && this.isAny(e.expression) ? `${RT.jsGet}(${this.expr(e.expression)}, ${kotlinString(e.name.text)})` : this.expr(e);
|
|
480
|
+
const code = cast(`${RT.jsThisFunction}(__f, ${g.params.length}, false)`, target.replace(/^\((.*)\)\?$/, '$1'));
|
|
481
|
+
return `run { val __f = ${raw}; ${/\)\?$/.test(target) ? `if (${RT.jsIsNullish}(__f)) null else ${code}` : code} }`;
|
|
482
|
+
}
|
|
462
483
|
const voidPromiseRet = !this.library && !!f && !!g && f.ret === 'JSPromise<Unit>' && /^JSPromise<.+>$/.test(g.ret) && g.ret !== f.ret;
|
|
463
484
|
if (f && g && f.params.length <= g.params.length && (f.params.length < g.params.length || voidPromiseRet || f.params.some((p, k) => p !== g.params[k] && this.convert('x', g.params[k], p) !== 'x')) && (g.ret === 'Unit' || g.ret === f.ret || voidPromiseRet || (isUntyped(spelledType(g.ret)) && (this.library || f.ret !== 'Unit')) || (!this.library && isUntyped(spelledType(f.ret))))) {
|
|
464
485
|
const names = g.params.map((_, k) => this.marks.pureCode(`__a${k}`));
|
|
@@ -175,6 +175,11 @@ export const untypedValuesMethods = {
|
|
|
175
175
|
// A prototype's method given as a value (`View.prototype[prop.setNative] = makeNativeSetter(…)`), called with the instance as `this`.
|
|
176
176
|
if (ts.isBinaryExpression(n) && n.operatorToken.kind === ts.SyntaxKind.EqualsToken && (ts.isElementAccessExpression(n.left) || ts.isPropertyAccessExpression(n.left)) && ts.isPropertyAccessExpression(n.left.expression) && n.left.expression.name.text === 'prototype')
|
|
177
177
|
prototypeValues.push(n.right);
|
|
178
|
+
// A property descriptor's accessor (`{ get: …, set: … }` or `desc.set = …`), called with the target object as `this`.
|
|
179
|
+
if (ts.isPropertyAssignment(n) && (ts.isIdentifier(n.name) || ts.isStringLiteral(n.name)) && (n.name.text === 'get' || n.name.text === 'set'))
|
|
180
|
+
prototypeValues.push(n.initializer);
|
|
181
|
+
if (ts.isBinaryExpression(n) && n.operatorToken.kind === ts.SyntaxKind.EqualsToken && ts.isPropertyAccessExpression(n.left) && (n.left.name.text === 'get' || n.left.name.text === 'set'))
|
|
182
|
+
prototypeValues.push(n.right);
|
|
178
183
|
if (ts.isVariableDeclaration(n) && n.initializer && ts.isIdentifier(n.name))
|
|
179
184
|
add(n, n.initializer);
|
|
180
185
|
if (ts.isPropertyDeclaration(n) && !isStatic(n) && ts.isClassLike(n.parent) && c.getTypeAtLocation(n.name).getCallSignatures().length)
|
|
@@ -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) {
|
|
@@ -166,7 +166,7 @@ export function propSignal(e, checker, framework) {
|
|
|
166
166
|
}
|
|
167
167
|
/** Whether `n` declares or references an untyped variable initialized from a read of a signal holding null (`const card = this.morning()`). */
|
|
168
168
|
export function isGivenNullSignalValue(n, resolve, isNullSignalRead) {
|
|
169
|
-
const d = (ts.isVariableDeclaration(n.parent) && n.parent.name === n ? n.parent : ts.isIdentifier(n) ? resolve(n)?.valueDeclaration : undefined);
|
|
169
|
+
const d = (n.parent && ts.isVariableDeclaration(n.parent) && n.parent.name === n ? n.parent : ts.isIdentifier(n) ? resolve(n)?.valueDeclaration : undefined);
|
|
170
170
|
if (!d || !ts.isVariableDeclaration(d) || d.type || !d.initializer)
|
|
171
171
|
return false;
|
|
172
172
|
return isNullSignalRead(d.initializer);
|
package/dist/semantics/throws.js
CHANGED
|
@@ -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))))
|
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
|
@@ -244,8 +244,13 @@ export const assignmentMethods = {
|
|
|
244
244
|
if (d && ts.isVariableDeclaration(d) && !d.initializer && !ts.isSourceFile(d.parent.parent.parent))
|
|
245
245
|
return this.marks.assignedCode(this.expr(left), 'nil');
|
|
246
246
|
}
|
|
247
|
-
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
|
+
}
|
|
248
252
|
return `(${this.expr(left.expression)} as JSDynamic)[jsKey: ${swiftString(left.name.text)}] = ${this.stored(right, left, 'Any?', checks)}`;
|
|
253
|
+
}
|
|
249
254
|
if (ts.isPropertyAccessExpression(left) && this.isNativeExpando(left))
|
|
250
255
|
return `${RT.jsSetNativeExpando}(${this.expr(left.expression)}, ${swiftString(left.name.text)}, ${this.stored(right, left, 'Any?', checks)})`;
|
|
251
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)
|
|
@@ -484,9 +486,12 @@ export const callsMethods = {
|
|
|
484
486
|
if (ts.isNonNullExpression(callee)) {
|
|
485
487
|
if (!/[?!]$/.test(this.typeOf(callee.expression)))
|
|
486
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(', ')})`;
|
|
487
492
|
const label = ts.isPropertyAccessExpression(callee.expression) || ts.isIdentifier(callee.expression) ? callee.expression.getText() : null;
|
|
488
493
|
const fnType = this.typeOf(callee.expression).replace(/^\((.*)\)[?!]$/, '$1').replace(/[?!]$/, '');
|
|
489
|
-
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(', ')})`;
|
|
490
495
|
}
|
|
491
496
|
throw this.error(e, 'call');
|
|
492
497
|
},
|
|
@@ -145,7 +145,8 @@ export const classMethodsMethods = {
|
|
|
145
145
|
this.chainingLoose = true;
|
|
146
146
|
const rawKey = this.propertyKey(m.name.expression);
|
|
147
147
|
this.chainingLoose = saved;
|
|
148
|
-
const
|
|
148
|
+
const keyThrows = this.throwsInfo.expr(m.name.expression);
|
|
149
|
+
const key = fixedKey(m.name.expression, this.checker) ? (keyThrows ? `(try? ${rawKey})` : rawKey) : this.storedSymbolKey(k, m.name.expression, rawKey);
|
|
149
150
|
symbolMethods.push({ key, method, owner: ident(k.name), params: m.parameters.map((p) => this.paramType(p)), unread: m.parameters.map((p) => this.unreadParameter(m, p)), ret: this.returnTypeOf(m), throws: this.throwsInfo.fn(m) });
|
|
150
151
|
lines.push(' ' + this.memberFunc(m, method));
|
|
151
152
|
return;
|
package/dist/swift/library.js
CHANGED
|
@@ -19,8 +19,8 @@ export const BUILTIN_CLASSES = Object.assign(Object.create(null), { Promise: 'JS
|
|
|
19
19
|
export const LIB_FUNCTION_VALUES = {
|
|
20
20
|
clearTimeout: { code: `{ (__id: Any?) -> Void in ${RT.jsClearTimeout}(${RT.jsIsNullish}(__id) ? nil : ${RT.jsToNumber}(__id)) }`, type: '(Any?) throws -> Void' },
|
|
21
21
|
clearInterval: { code: `{ (__id: Any?) -> Void in ${RT.jsClearInterval}(${RT.jsIsNullish}(__id) ? nil : ${RT.jsToNumber}(__id)) }`, type: '(Any?) throws -> Void' },
|
|
22
|
-
queueMicrotask: { code: `{ (__f: @escaping () throws -> Void) -> Void in ${RT.jsQueueMicrotask} { ${RT.jsReport} { try __f() } } }`, type: '(() throws -> Void) throws -> Void' },
|
|
23
|
-
requestAnimationFrame: { code: `{ (__f: @escaping (Double) throws -> Void) -> Double in ${RT.jsRequestAnimationFrame} { __t in ${RT.jsReport} { try __f(__t) } } }`, type: '((Double) throws -> Void) throws -> Double' },
|
|
22
|
+
queueMicrotask: { code: `{ (__f: @escaping () throws -> Void) -> Void in ${RT.jsQueueMicrotask} { ${RT.jsReport} { try __f() } } }`, type: '(@escaping () throws -> Void) throws -> Void' },
|
|
23
|
+
requestAnimationFrame: { code: `{ (__f: @escaping (Double) throws -> Void) -> Double in ${RT.jsRequestAnimationFrame} { __t in ${RT.jsReport} { try __f(__t) } } }`, type: '(@escaping (Double) throws -> Void) throws -> Double' },
|
|
24
24
|
cancelAnimationFrame: { code: `{ (__id: Double?) -> Void in ${RT.jsCancelAnimationFrame}(__id) }`, type: '(Double?) throws -> Void' },
|
|
25
25
|
};
|
|
26
26
|
/** `Math`'s functions, by the Swift function each is. */
|
|
@@ -136,7 +136,8 @@ export const methodValuesMethods = {
|
|
|
136
136
|
const params = fn.parameters.filter((p) => !(ts.isIdentifier(p.name) && p.name.text === 'this'));
|
|
137
137
|
const ret = this.returnTypeOf(fn);
|
|
138
138
|
const localType = (p) => (p.questionToken || (p.initializer && !this.templateParams) ? this.paramType(p) : this.states.mayBeNull(p) ? (this.lenient ? optionalType(this.typeOf(p.name)) : `${this.typeOf(p.name)}!`) : this.paramType(p));
|
|
139
|
-
const
|
|
139
|
+
const rawSelf = declaresThis(fn) ? localType(fn.parameters[0]) : 'Any?';
|
|
140
|
+
const selfType = !isUntyped(spelledType(rawSelf)) && !this.declaredNullable(fn.parameters[0]) ? rawSelf.replace(/\?$/, '!') : rawSelf;
|
|
140
141
|
const selfBind = !isUntyped(spelledType(selfType)) ? [`let __self: ${selfType} = ${this.presentFromAny('__this', selfType.replace(/!$/, '?'), true, true)}`] : [];
|
|
141
142
|
// A function reading `arguments` binds its parameters from them itself.
|
|
142
143
|
const binds = [
|
package/dist/swift/names.js
CHANGED
|
@@ -56,6 +56,10 @@ export const namesMethods = {
|
|
|
56
56
|
// A name nothing declares for iOS (`android`, `java`, Node's `__dirname`) is a value whose use throws.
|
|
57
57
|
if (name === 'global' && (this.library ? !libDecl || libDecl.getSourceFile().isDeclarationFile : !!libDecl && libDecl.getSourceFile().isDeclarationFile))
|
|
58
58
|
return 'jsGlobalThis';
|
|
59
|
+
// A timer or microtask function held as a value (`const clear = clearTimeout`, `requestAnimationFrame`, `queueMicrotask`), core's declaration of it too.
|
|
60
|
+
const held = !!libDecl && libDecl.getSourceFile().isDeclarationFile && Object.hasOwn(LIB_FUNCTION_VALUES, name) && !(ts.isCallExpression(e.parent) && e.parent.expression === e) ? LIB_FUNCTION_VALUES[name] : undefined;
|
|
61
|
+
if (held)
|
|
62
|
+
return this.convert(held.code, held.type, this.typeOf(e));
|
|
59
63
|
if (this.isDomGlobal(e))
|
|
60
64
|
return `jsGlobalThis[jsKey: ${swiftString(name)}]`;
|
|
61
65
|
// The runtime gives the bundled app's module its folder in the app bundle.
|
|
@@ -81,10 +85,6 @@ export const namesMethods = {
|
|
|
81
85
|
return sdk;
|
|
82
86
|
return this.fromAnyCode(`jsGlobalThis[jsKey: ${swiftString(name)}]`, this.typeOf(e));
|
|
83
87
|
}
|
|
84
|
-
// A timer or microtask function held as a value (`const clear = clearTimeout`), core's declaration of it too.
|
|
85
|
-
const held = !!libDecl && libDecl.getSourceFile().isDeclarationFile && Object.hasOwn(LIB_FUNCTION_VALUES, name) && !(ts.isCallExpression(e.parent) && e.parent.expression === e) ? LIB_FUNCTION_VALUES[name] : undefined;
|
|
86
|
-
if (held)
|
|
87
|
-
return this.convert(held.code, held.type, this.typeOf(e));
|
|
88
88
|
// A global function core or the app only declares (`zonedCallback`, which core's globals set), as a value: the global object's.
|
|
89
89
|
if (!this.library && libDecl && ts.isFunctionDeclaration(libDecl) && !libDecl.body && (appAmbient || isCoreDeclaration(libDecl)) && ts.isSourceFile(libDecl.parent) && !hasModifier(libDecl, ts.SyntaxKind.ExportKeyword))
|
|
90
90
|
return 'jsGlobalThis[jsKey: ' + swiftString(name) + ']';
|
|
@@ -531,7 +531,7 @@ export const nativeCallsMethods = {
|
|
|
531
531
|
const k = lookupConstant(native.module, native.name);
|
|
532
532
|
if (!k)
|
|
533
533
|
throw this.t.error(e, `${native.name} (${this.noCounterpart(native.module, native.name)})`, 'native');
|
|
534
|
-
this.usesEnumOf(k, native.module, native.name);
|
|
534
|
+
this.usesEnumOf(k, native.module, native.name, e);
|
|
535
535
|
return this.fromSwift(k.swift, k.type, e);
|
|
536
536
|
},
|
|
537
537
|
/**
|
|
@@ -544,16 +544,22 @@ export const nativeCallsMethods = {
|
|
|
544
544
|
if (!k)
|
|
545
545
|
continue;
|
|
546
546
|
this.uses(module);
|
|
547
|
-
this.usesEnumOf(k, module, e.text);
|
|
547
|
+
this.usesEnumOf(k, module, e.text, e);
|
|
548
548
|
return this.fromSwift(k.swift, k.type, e);
|
|
549
549
|
}
|
|
550
550
|
return null;
|
|
551
551
|
},
|
|
552
552
|
/** A typed constant's enum is looked up among the modules in use, and may live in another table than the typings' module. */
|
|
553
|
-
usesEnumOf(k, module, jsName) {
|
|
553
|
+
usesEnumOf(k, module, jsName, e) {
|
|
554
|
+
this.checkAvailable(k, e, jsName);
|
|
554
555
|
const home = k.enumType ? constantModule(module, jsName) : null;
|
|
555
556
|
if (home)
|
|
556
557
|
this.uses(home);
|
|
558
|
+
if (k.enumType) {
|
|
559
|
+
const en = lookupEnum(home ?? module, k.enumType);
|
|
560
|
+
if (en)
|
|
561
|
+
this.checkAvailable(en, e, k.enumType);
|
|
562
|
+
}
|
|
557
563
|
},
|
|
558
564
|
/** A native function of no arguments as a value (`isRunning = UIAccessibilityIsVoiceOverRunning`): a closure calling it, as Swift may have it as a property. */
|
|
559
565
|
functionValue(e, native) {
|
package/dist/swift/placement.js
CHANGED
|
@@ -3,7 +3,7 @@ import { heldLoss } from "../semantics/losses.js";
|
|
|
3
3
|
import ts from 'typescript';
|
|
4
4
|
import { convertedRead } from "../semantics/states/predicates.js";
|
|
5
5
|
import { place } from "../semantics/placement.js";
|
|
6
|
-
import { THROWING_CODE, escapingFunction, escapingParam, functionParts, hasTopLevelArrow, ident, isFunctionType, isNullish, isOptional, nullishType, numberLiteralBranch, numericLiteralOnly, optionalType, postfixChain, splitTopLevel, swiftString, unwrapFunction, RT, lenientReader } from "./syntax.js";
|
|
6
|
+
import { THROWING_CODE, escapingFunction, escapingParam, functionParts, hasTopLevelArrow, ident, isFunctionType, isNullish, isOptional, nullishType, numberLiteralBranch, numericLiteralOnly, optionalElementsType, optionalType, postfixChain, splitTopLevel, swiftString, unwrapFunction, RT, lenientReader } from "./syntax.js";
|
|
7
7
|
import { structural } from "../semantics/conversion.js";
|
|
8
8
|
import { heldOf, isKit, isNamed, isUntyped, parseNativeType, spelledType } from "../semantics/types.js";
|
|
9
9
|
import { isLibDeclaration, isWriteTarget, notIterable } from "../semantics/ast.js";
|
|
@@ -19,8 +19,10 @@ export const placementMethods = {
|
|
|
19
19
|
loweredReturn(e, slot) {
|
|
20
20
|
const own = this.typeOf(e).replace(/[?!]$/, ''), promise = `JSPromise<${slot.target}>`;
|
|
21
21
|
// The `try` marks the value: a return through a finally holds it in a block, which a `try` cannot mark.
|
|
22
|
-
if (!isKit(spelledType(own), 'JSPromise'))
|
|
23
|
-
|
|
22
|
+
if (!isKit(spelledType(own), 'JSPromise')) {
|
|
23
|
+
const placed = place(this.placement, e, slot);
|
|
24
|
+
return [this.marks.tryBefore(this.tryPrefix(e) || (THROWING_CODE.test(placed) ? 'try ' : ''), placed), false];
|
|
25
|
+
}
|
|
24
26
|
// A promise of another type than the function's (`Promise<[Status, boolean]>` returned where `Promise<any>` is): its value converted.
|
|
25
27
|
const adopt = (code) => (own !== promise ? this.convert(code, own, promise) : code);
|
|
26
28
|
const read = this.typeOf(e);
|
|
@@ -617,6 +619,19 @@ export const placementMethods = {
|
|
|
617
619
|
return this.array(bare, 'JSArray<Any?>');
|
|
618
620
|
return this.convert(this.expr(e), source, target);
|
|
619
621
|
}
|
|
622
|
+
// An array of typed promises where an array of untyped promises is wanted (`Promise<void>[]` as `Promise<unknown>[]`).
|
|
623
|
+
if (!this.library && /^JSArray<JSPromise<.+>>[?!]?$/.test(source) && /^JSArray<JSPromise<Any\?>>[?!]?$/.test(target) && !/^JSArray<JSPromise<Any\?>>[?!]?$/.test(source)) {
|
|
624
|
+
const fromPromise = source.replace(/^JSArray<(.*)>[?!]?$/, '$1');
|
|
625
|
+
return `(${this.expr(e)} as ${source.replace(/[?!]$/, '')}).map { ${this.convert('$0', fromPromise, 'JSPromise<Any?>')} }`;
|
|
626
|
+
}
|
|
627
|
+
// A Set or Array whose elements Swift held optional (`optionalElements`), placed where non-optional elements are declared.
|
|
628
|
+
if (!this.library && source !== target && source === optionalElementsType(target) && /^JS(Set|Array)<.+>\??$/.test(target)) {
|
|
629
|
+
const el = target.replace(/^JS(?:Set|Array)<(.*)>\??$/, '$1');
|
|
630
|
+
if (!isUntyped(spelledType(el))) {
|
|
631
|
+
const kind = target.startsWith('JSSet<') ? 'JSSet' : 'JSArray';
|
|
632
|
+
return `${kind}<${el}>(${this.expr(e)}.map { ${this.undefinedAs('$0', el, optionalType(el))} })`;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
620
635
|
if (/^JSPromise<(Any\?|JSArray<Any\?>)>$/.test(source) && /^JSPromise<.*>[?!]?$/.test(target) && source !== target.replace(/[?!]$/, '')) {
|
|
621
636
|
const all = ts.isCallExpression(bare) && ts.isPropertyAccessExpression(bare.expression) && bare.expression.name.text === 'all' && ts.isIdentifier(bare.expression.expression) && bare.expression.expression.text === 'Promise' && isLibGlobal(this, bare.expression.expression) && bare.arguments.length === 1 && !ts.isArrayLiteralExpression(bare.arguments[0]) ? bare : null;
|
|
622
637
|
return all ? this.untypedAll(all.arguments[0], target) : this.convert(this.expr(e), source, target);
|
|
@@ -112,7 +112,7 @@ export const staticCallsMethods = {
|
|
|
112
112
|
case 'Array':
|
|
113
113
|
if (method === 'isArray') {
|
|
114
114
|
const g = !this.library ? shapeArrayGuardAccess(arg(0), (t) => this.isObjectShape(t), (x) => this.typeOf(x)) : null;
|
|
115
|
-
return `JSArray<Any?>.isArray(${g ? `${this.expr(g.prop.expression)}${g.optional ? '?' : ''}[jsKey: ${swiftString(g.prop.name.text)}]` : this.restArgument(e, arg(0), 'Any?')})`;
|
|
115
|
+
return `JSArray<Any?>.isArray(${g ? `${this.expr(g.prop.expression)}${g.optional && this.typeOf(g.prop.expression).endsWith('?') ? '?' : ''}[jsKey: ${swiftString(g.prop.name.text)}]` : this.restArgument(e, arg(0), 'Any?')})`;
|
|
116
116
|
}
|
|
117
117
|
if (method === 'from' && e.arguments.length === 1)
|
|
118
118
|
return `${T()}.from(${this.iterable(arg(0))})`;
|
package/dist/swift/syntax.js
CHANGED
|
@@ -385,7 +385,7 @@ export const SWIFT_SYNTAX = {
|
|
|
385
385
|
asyncBody: (cap) => [`${cap}.body {`, '}'],
|
|
386
386
|
// Undefined where the result has no undefined (a tuple, after branches that each return): reached only where the types are wrong.
|
|
387
387
|
asyncReturn: (cap, value, isPromise, result) => (value === null ? `${cap}.returnValue(${result === 'Void' ? '()' : /^\(.*\)$/.test(result) && !/->/.test(result) ? `{ fatalError("undefined for ${result}") }()` : 'nil'})` : `${cap}.${isPromise ? 'returnPromise' : 'returnValue'}(${value})`),
|
|
388
|
-
asyncError: (cap) =>
|
|
388
|
+
asyncError: (cap) => `${cap}.throwValue`,
|
|
389
389
|
loopRun: (iteration) => `JSAsyncLoop().run ${iteration}`,
|
|
390
390
|
undefinedValue: 'nil',
|
|
391
391
|
generatorBody: (cap, element, isAsync) => [`return ${isAsync ? 'JSAsyncGenerator' : 'JSGenerator'}<${element}> { (${cap}: ${isAsync ? 'JSAsyncGeneratorContext' : 'JSGeneratorContext'}) throws -> Void in`, '}'],
|
package/dist/swift/types.js
CHANGED
|
@@ -338,8 +338,8 @@ export const typesMethods = {
|
|
|
338
338
|
return `${this.appModule}.${this.topNames().get(sym.valueDeclaration ?? sym.declarations[0]) ?? name}`;
|
|
339
339
|
}
|
|
340
340
|
if (name && name !== '__type' && name !== '__object') {
|
|
341
|
-
//
|
|
342
|
-
if (
|
|
341
|
+
// An interface only a declaration file has (the DOM's `MediaQueryListEvent`, `AddEventListenerOptions`, `Document`, core's `AddChildFromBuilder` in library mode) has no Swift type.
|
|
342
|
+
if (sym && sym.flags & ts.SymbolFlags.Interface && !(sym.flags & ts.SymbolFlags.Class) && sym.declarations?.every((d) => d.getSourceFile().isDeclarationFile && ((isLibDeclaration(d) && (/lib\.dom/.test(d.getSourceFile().fileName) || (this.library && DESCRIPTORS.has(name)))) || (this.library && isCoreDeclaration(d)))))
|
|
343
343
|
return 'Any?';
|
|
344
344
|
if (sym?.declarations?.some((d) => !d.getSourceFile().isDeclarationFile))
|
|
345
345
|
this.used.add(name);
|
|
@@ -717,6 +717,13 @@ open class ObservableArray : Observable, JSStringConvertible, JSToJSON, JSIterab
|
|
|
717
717
|
)
|
|
718
718
|
null
|
|
719
719
|
}
|
|
720
|
+
"map" ->
|
|
721
|
+
jsFunction { __a ->
|
|
722
|
+
this.map(
|
|
723
|
+
jsFunction3<Any?, Double, ObservableArray, Any?>(__a.getOrNull(0)),
|
|
724
|
+
__a.getOrNull(1),
|
|
725
|
+
)
|
|
726
|
+
}
|
|
720
727
|
"filter" ->
|
|
721
728
|
jsFunction { __a ->
|
|
722
729
|
this.filter(
|
|
@@ -773,6 +780,7 @@ open class ObservableArray : Observable, JSStringConvertible, JSToJSON, JSIterab
|
|
|
773
780
|
"every",
|
|
774
781
|
"some",
|
|
775
782
|
"forEach",
|
|
783
|
+
"map",
|
|
776
784
|
"filter",
|
|
777
785
|
"reduce",
|
|
778
786
|
"reduceRight" -> true
|
|
@@ -661,6 +661,20 @@ open class Observable : JSExpando, JSKeysMade {
|
|
|
661
661
|
this._clearEventListeners()
|
|
662
662
|
null
|
|
663
663
|
}
|
|
664
|
+
"_globalNotify" ->
|
|
665
|
+
jsFunction { __a ->
|
|
666
|
+
this._globalNotify(
|
|
667
|
+
jsConvertedStringOrNull(__a.getOrNull(0)),
|
|
668
|
+
jsConvertedStringOrNull(__a.getOrNull(1)),
|
|
669
|
+
__a.getOrNull(2),
|
|
670
|
+
)
|
|
671
|
+
null
|
|
672
|
+
}
|
|
673
|
+
"notify" ->
|
|
674
|
+
jsFunction { __a ->
|
|
675
|
+
this.notify(__a.getOrNull(0))
|
|
676
|
+
null
|
|
677
|
+
}
|
|
664
678
|
"notifyPropertyChange" ->
|
|
665
679
|
jsFunction { __a ->
|
|
666
680
|
this.notifyPropertyChange(
|
|
@@ -714,6 +728,8 @@ open class Observable : JSExpando, JSKeysMade {
|
|
|
714
728
|
"addEventListener",
|
|
715
729
|
"removeEventListener",
|
|
716
730
|
"_clearEventListeners",
|
|
731
|
+
"_globalNotify",
|
|
732
|
+
"notify",
|
|
717
733
|
"notifyPropertyChange",
|
|
718
734
|
"hasListeners",
|
|
719
735
|
"_createPropertyChangeData",
|
|
@@ -310,6 +310,7 @@ object xml2ui {
|
|
|
310
310
|
override fun jsGet(key: String): Any? =
|
|
311
311
|
when (key) {
|
|
312
312
|
"_next" -> if ((jsMadeBits0 and (1L shl 0)) != 0L) this._next else null
|
|
313
|
+
"pipe" -> jsFunction { __a -> this.pipe(__a.getOrNull(0)) }
|
|
313
314
|
"next" ->
|
|
314
315
|
jsFunction { __a ->
|
|
315
316
|
this.next(jsCast(__a.getOrNull(0), ParserEvent::class.java))
|
|
@@ -327,6 +328,7 @@ object xml2ui {
|
|
|
327
328
|
|
|
328
329
|
override fun jsHasMember(key: String): Boolean =
|
|
329
330
|
when (key) {
|
|
331
|
+
"pipe",
|
|
330
332
|
"next" -> true
|
|
331
333
|
else -> false
|
|
332
334
|
}
|