@nstudio/nativescript-compiler 9.2.0-alpha.13 → 9.2.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/css/worker.js +2 -2
- package/dist/driver/compile.js +4 -3
- package/dist/kotlin/arguments.js +7 -3
- package/dist/kotlin/assignment.js +3 -0
- package/dist/kotlin/builtins.js +15 -4
- package/dist/kotlin/class-constructor.js +3 -1
- package/dist/kotlin/class-methods.js +9 -2
- package/dist/kotlin/components.js +39 -14
- package/dist/kotlin/construction.js +4 -5
- package/dist/kotlin/conversion.js +19 -3
- package/dist/kotlin/core-api.js +31 -7
- package/dist/kotlin/declarations.js +8 -3
- package/dist/kotlin/expressions.js +10 -5
- package/dist/kotlin/library.js +2 -2
- package/dist/kotlin/modules.js +9 -4
- package/dist/kotlin/names.js +5 -2
- package/dist/kotlin/narrowing.js +2 -1
- package/dist/kotlin/optional-chains.js +24 -5
- package/dist/kotlin/overrides.js +7 -2
- package/dist/kotlin/placement.js +5 -4
- package/dist/kotlin/static-calls.js +17 -5
- package/dist/kotlin/translator.js +15 -39
- package/dist/kotlin/type-facts.js +3 -2
- package/dist/kotlin/types.js +6 -5
- package/dist/kotlin/untyped-values.js +7 -1
- package/dist/program/program.js +3 -3
- package/dist/semantics/apis/array.js +11 -0
- package/dist/semantics/classes.js +24 -0
- package/dist/semantics/config.js +2 -0
- package/dist/semantics/forms/by-name.js +30 -18
- package/dist/semantics/globals.js +8 -2
- package/dist/semantics/lang.js +4 -0
- package/dist/semantics/ledger.js +0 -24
- package/dist/semantics/platform-globals.js +0 -16
- package/dist/semantics/refusals.js +1 -1
- package/dist/semantics/runtime.js +2 -0
- package/dist/semantics/throws.js +7 -0
- package/dist/semantics/worker-state.js +41 -1
- package/dist/swift/assignment.js +3 -0
- package/dist/swift/builtins.js +20 -12
- package/dist/swift/class-methods.js +3 -1
- package/dist/swift/construction.js +5 -1
- package/dist/swift/conversion.js +1 -1
- package/dist/swift/expressions.js +2 -4
- package/dist/swift/from-any.js +5 -0
- package/dist/swift/global-calls.js +8 -1
- package/dist/swift/library.js +1 -1
- package/dist/swift/modules.js +2 -1
- package/dist/swift/object-classes.js +2 -1
- package/dist/swift/protocols.js +5 -16
- package/dist/swift/type-facts.js +2 -0
- package/dist/swift/types.js +7 -6
- package/dist/targets/android/build.js +9 -7
- package/dist/targets/ios/build.js +23 -8
- package/docs/cli/compile-ios.md +1 -1
- package/kit-android/generated/kotlin/org/nativescript/kit/file_system_file_system_access.kt +1 -1
- package/kit-android/generated/kotlin/org/nativescript/kit/http_http_request_internal_index.kt +1 -1
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_properties_index.kt +6 -6
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_view_view_common.kt +1 -1
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_text_base_formatted_string.kt +2 -2
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_text_base_text_base_common.kt +2 -2
- package/kit-android/gradlew.bat +2 -2
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Collections.kt +15 -6
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Iterators.kt +1 -0
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Promise.kt +5 -4
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Workers.kt +39 -11
- package/kit-apple/Overlays/xml-free/Core/ui.core.bindable.index.swift +13 -2
- package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity1.swift +0 -12
- package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity2.swift +0 -39
- package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity3Plus.swift +0 -44
- package/kit-apple/Sources/NativeScriptKit/Core/application.application-common.swift +19 -2
- package/kit-apple/Sources/NativeScriptKit/Core/kit-index.json +87 -22
- package/kit-apple/Sources/NativeScriptKit/Core/text.text-common.swift +9 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.bindable.index.swift +13 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view-base.index.swift +26 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.liquid-glass-container.index.ios.swift +12 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.root-layout.root-layout-common.swift +46 -6
- package/kit-apple/Sources/NativeScriptKit/Core/ui.list-view.index.ios.swift +37 -3
- package/kit-apple/Sources/NativeScriptKit/Core/ui.split-view.split-view-common.swift +12 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.css-selector.swift +50 -6
- package/kit-apple/Sources/NativeScriptKit/Core/ui.text-base.text-base-common.swift +13 -1
- package/kit-apple/Sources/NativeScriptKit/Runtime/Collections.swift +5 -1
- package/kit-apple/Sources/NativeScriptKit/Runtime/Dynamic.swift +13 -2
- package/kit-apple/Sources/NativeScriptKit/Runtime/Errors.swift +10 -2
- package/kit-apple/Sources/NativeScriptKit/Runtime/Functions.swift +57 -12
- package/kit-apple/Sources/NativeScriptKit/Runtime/Lowering.swift +12 -3
- package/kit-apple/Sources/NativeScriptKit/Runtime/Promise.swift +56 -29
- package/kit-apple/Sources/NativeScriptKit/Runtime/Realm.swift +92 -0
- package/kit-apple/Sources/NativeScriptKit/Runtime/Record.swift +25 -5
- package/kit-apple/Sources/NativeScriptKit/Runtime/RegExp.swift +13 -4
- package/kit-apple/Sources/NativeScriptKit/Runtime/RegExpEngine.swift +14 -5
- package/kit-apple/Sources/NativeScriptKit/Runtime/Symbol.swift +28 -6
- package/kit-apple/Sources/NativeScriptKit/Runtime/Threads.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Runtime/Timers.swift +93 -47
- package/kit-apple/Sources/NativeScriptKit/Runtime/TypedArrays.swift +37 -9
- package/kit-apple/Sources/NativeScriptKit/Runtime/Values.swift +6 -4
- package/kit-apple/Sources/NativeScriptKit/Runtime/Views.swift +11 -2
- package/kit-apple/Sources/NativeScriptKit/Runtime/Workers.swift +680 -0
- package/package.json +1 -1
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import { relative } from 'node:path';
|
|
2
|
+
import { dirname, relative, resolve } from 'node:path';
|
|
3
3
|
import { evaluatedImports } from "../program/module-order.js";
|
|
4
|
+
/**
|
|
5
|
+
* `new Worker('~/x')`, `new Worker('./x')`, or `new Worker(new URL('./x', import.meta.url))`:
|
|
6
|
+
* resolves the worker script path against the build's `workerScripts` map for `platform`.
|
|
7
|
+
*/
|
|
8
|
+
export function resolveWorkerScript(name, args, workerScripts, resolveAlias, platform) {
|
|
9
|
+
if (name !== 'Worker' || !workerScripts?.size || !args.length)
|
|
10
|
+
return null;
|
|
11
|
+
const e = args[0];
|
|
12
|
+
let spec = null;
|
|
13
|
+
if (ts.isStringLiteralLike(e)) {
|
|
14
|
+
spec = e.text;
|
|
15
|
+
}
|
|
16
|
+
else if (ts.isNewExpression(e) && ts.isIdentifier(e.expression) && e.expression.text === 'URL') {
|
|
17
|
+
const [s, base] = e.arguments ?? [];
|
|
18
|
+
if (s && ts.isStringLiteralLike(s) && base && base.getText() === 'import.meta.url')
|
|
19
|
+
spec = s.text;
|
|
20
|
+
}
|
|
21
|
+
if (!spec || !workerScripts?.size)
|
|
22
|
+
return null;
|
|
23
|
+
const file = e.getSourceFile().fileName;
|
|
24
|
+
const ext = platform === 'android' ? '.android.ts' : '.ios.ts';
|
|
25
|
+
const target = spec.startsWith('.') ? resolve(dirname(file), spec) : resolveAlias?.(spec, file);
|
|
26
|
+
if (target) {
|
|
27
|
+
const stem = target.replace(/\\/g, '/').replace(/\.(tsx?|m?js)$/, '');
|
|
28
|
+
for (const f of [stem + '.ts', stem + ext, stem + '.tsx', stem + '/index.ts', stem + `/index${ext}`]) {
|
|
29
|
+
const script = workerScripts.get(f);
|
|
30
|
+
if (script)
|
|
31
|
+
return script;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (spec.startsWith('~/') || spec.startsWith('@/')) {
|
|
35
|
+
const rel = spec.slice(2).replace(/\\/g, '/').replace(/\.(tsx?|m?js)$/, '');
|
|
36
|
+
for (const [key, script] of workerScripts) {
|
|
37
|
+
const norm = key.replace(/\\/g, '/');
|
|
38
|
+
if ([`/${rel}.ts`, `/${rel}${ext}`, `/${rel}.tsx`, `/${rel}/index.ts`, `/${rel}/index${ext}`].some((s) => norm.endsWith(s)))
|
|
39
|
+
return script;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
4
44
|
/** Methods that change the array, map, set or typed array they are called on. */
|
|
5
45
|
const MUTATORS = new Set(['push', 'pop', 'shift', 'unshift', 'splice', 'set', 'fill', 'sort', 'reverse', 'copyWithin', 'delete', 'clear', 'add']);
|
|
6
46
|
/** `Object.assign(X, …)` and the like: functions that change their first argument. */
|
package/dist/swift/assignment.js
CHANGED
|
@@ -243,6 +243,9 @@ export const assignmentMethods = {
|
|
|
243
243
|
if (left.expression.kind !== ts.SyntaxKind.SuperKeyword && this.isInstanceMethod(left.name))
|
|
244
244
|
return `${RT.jsExpandoSet}(${this.expr(left.expression)}, ${swiftString(left.name.text)}, ${this.stored(right, left, 'Any?', checks)})`;
|
|
245
245
|
}
|
|
246
|
+
if (ts.isPropertyAccessExpression(left) && !this.library && this.typeOf(left.expression).replace(/[?!]$/, '') === 'JSWorker' && (left.name.text === 'onmessage' || left.name.text === 'onerror')) {
|
|
247
|
+
return `${RT.jsSet}(${this.expr(left.expression)}, ${swiftString(left.name.text)}, ${this.stored(right, left, 'Any?', checks)})`;
|
|
248
|
+
}
|
|
246
249
|
if (ts.isPropertyAccessExpression(left) && this.isAny(left.expression))
|
|
247
250
|
return `${RT.jsSet}(${this.expr(left.expression)}, ${swiftString(left.name.text)}, ${this.stored(right, left, 'Any?', checks)})`;
|
|
248
251
|
// An array written at a key that may be no index (`frames[time]`, time untyped): as script writes it.
|
package/dist/swift/builtins.js
CHANGED
|
@@ -3,7 +3,7 @@ import { heldLoss } from "../semantics/losses.js";
|
|
|
3
3
|
import ts from 'typescript';
|
|
4
4
|
import { MATH, MATH_OF_SPREAD, isTypedArrayType } from "./library.js";
|
|
5
5
|
import { mathFunction } from "../semantics/apis/math.js";
|
|
6
|
-
import { arrayMember } from "../semantics/apis/array.js";
|
|
6
|
+
import { arrayMember, typedFlatPlan } from "../semantics/apis/array.js";
|
|
7
7
|
import { collectionMember } from "../semantics/apis/mapset.js";
|
|
8
8
|
import { argumentRunsConversion, numberMember } from "../semantics/apis/number.js";
|
|
9
9
|
import { promiseMember } from "../semantics/apis/promise.js";
|
|
@@ -235,18 +235,16 @@ export const builtinMethods = {
|
|
|
235
235
|
case 'values':
|
|
236
236
|
return `${t}.${name}()`;
|
|
237
237
|
case 'flat': {
|
|
238
|
-
const
|
|
239
|
-
if (
|
|
238
|
+
const plan = typedFlatPlan(e, el, isUntyped(spelledType(el)));
|
|
239
|
+
if (plan.kind === 'default')
|
|
240
240
|
return `${t}.flat()`;
|
|
241
|
-
if (
|
|
242
|
-
return
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
if (levels >= 1)
|
|
246
|
-
return t + '.flat()'.repeat(levels);
|
|
241
|
+
if (plan.kind === 'chain')
|
|
242
|
+
return t + plan.suffix;
|
|
243
|
+
if (plan.untyped)
|
|
244
|
+
return `${t}.flat(${this.coerce(plan.arg, 'Double')})`;
|
|
247
245
|
if (q)
|
|
248
246
|
throw this.error(e, 'flat with a depth on an optional array');
|
|
249
|
-
return this.convert(`JSArray<Any?>(${t}.jsAnyElements).flat(${this.coerce(
|
|
247
|
+
return this.convert(`JSArray<Any?>(${t}.jsAnyElements).flat(${this.coerce(plan.arg, 'Double')})`, 'JSArray<Any?>', this.typeOf(e));
|
|
250
248
|
}
|
|
251
249
|
case 'toLocaleString':
|
|
252
250
|
if (!e.arguments.length)
|
|
@@ -653,6 +651,12 @@ export const builtinMethods = {
|
|
|
653
651
|
const call = this.marks.tryCode(`${RT.jsCall}(${this.expr(e)}, __reason)`);
|
|
654
652
|
return `{ (__reason: Any?) throws -> ${result} in ${result === 'Void' ? `_ = ${call}` : `return ${this.fromAnyCode(call, result, true)}`} }`;
|
|
655
653
|
}
|
|
654
|
+
// A 0-arg function value (`run: () => Promise<T>`): wrap to ignore the rejection reason.
|
|
655
|
+
const parts = functionParts(this.typeOf(e).replace(/^\((.*)\)!$/, '$1'));
|
|
656
|
+
if (parts && !parts.params.length) {
|
|
657
|
+
const call = this.marks.tryCode(`(${this.fn(e)})()`);
|
|
658
|
+
return `{ (_: Any?) throws -> ${parts.result} in ${parts.result === 'Void' ? call : `return ${call}`} }`;
|
|
659
|
+
}
|
|
656
660
|
return this.fn(e);
|
|
657
661
|
}
|
|
658
662
|
// A handler that only rethrows (`(error) => { …; throw error; }`) is typed as the promise's other handler.
|
|
@@ -688,8 +692,12 @@ export const builtinMethods = {
|
|
|
688
692
|
let onFulfilled = nullFulfilled ? `{ (__v: ${value}) -> ${value} in ${value === 'Never' ? 'switch __v {}' : '__v'} }` : ignores ? this.closure(f, [`_ __unused: ${value}`]) : f && this.fn(f);
|
|
689
693
|
// A function value taking its arguments as a rest (`then(log)` of a `log(...values)`), or any value where the promise's is
|
|
690
694
|
// undefined (`then($DONE)`, which Swift would pass `()`): called with the one value, as it holds it.
|
|
691
|
-
const own = f && !
|
|
692
|
-
if (own &&
|
|
695
|
+
const own = f && !nullFulfilled && !ts.isArrowFunction(f) && !ts.isFunctionExpression(f) ? functionParts(this.typeOf(f).replace(/^\((.*)\)!$/, '$1')) : null;
|
|
696
|
+
if (own && !own.params.length && value !== 'Void') {
|
|
697
|
+
const call = this.marks.tryCode(`(${this.fn(f)})()`);
|
|
698
|
+
onFulfilled = `{ (_: ${value}) throws -> ${own.result} in ${own.result === 'Void' ? call : `return ${call}`} }`;
|
|
699
|
+
}
|
|
700
|
+
else if (own && !adopt && (own.rest >= 0 || (value === 'Void' && own.params.length && own.params[0] !== 'Void')))
|
|
693
701
|
onFulfilled = this.coerce(f, `(${value}) throws -> ${own.result}`);
|
|
694
702
|
// A handler declaring the type of what an untyped promise settles with (`.then((r: Item) => …)` of a `Promise<any>`): it takes the value untyped, read as that type.
|
|
695
703
|
const declared = f && !ignores && isUntyped(spelledType(value)) && (ts.isArrowFunction(f) || ts.isFunctionExpression(f)) && f.parameters.length ? this.closureParamType(f.parameters[0]) : undefined;
|
|
@@ -228,7 +228,9 @@ export const classMethodsMethods = {
|
|
|
228
228
|
const plain = (t) => t.replace(/^\((any .*)\)!$/, '$1?').replace(/!$/, '?');
|
|
229
229
|
// A method reading `arguments` takes the call's arguments as one list; a rest parameter (`fill(...args)`) the arguments from its place.
|
|
230
230
|
const params = this.readsArguments(m) ? ['JSRest<Any?>'] : sig.params.map((p, k) => (k === restAt ? `JSRest<${/^JSArray<(.*)>$/.exec(plain(p.type))?.[1] ?? 'Any?'}>` : isFunctionType(p.type) ? `@escaping ${p.type}` : plain(p.type)));
|
|
231
|
-
|
|
231
|
+
const defFrom = !overridden && !this.readsArguments(m) && restAt < 0 ? m.parameters.findIndex((p) => p.initializer) : -1;
|
|
232
|
+
const trailingFrom = defFrom >= 0 && !m.typeParameters?.length && m.parameters.slice(defFrom).every((p) => p.initializer && !p.dotDotDotToken) && splitTopLevel(this.params(m, false)).every((p) => p.trim().startsWith('_ ')) ? defFrom : undefined;
|
|
233
|
+
k.dynMethods.push({ name: n, type: `(${params.join(', ')}) throws -> ${plain(sig.ret)}`, available: this.gatedFunctions.get(m), length: scriptLength(m), trailingFrom });
|
|
232
234
|
}
|
|
233
235
|
},
|
|
234
236
|
abstractMethod(k, m) {
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
import ts from 'typescript';
|
|
3
3
|
import { isTypedArrayType } from "./library.js";
|
|
4
4
|
import { ERRORS, TYPED_ARRAYS, errorArguments, isWebClass, isLibGlobal } from "../semantics/globals.js";
|
|
5
|
-
import { ident, isOptional, splitTopLevel, RT } from "./syntax.js";
|
|
5
|
+
import { ident, isOptional, splitTopLevel, swiftString, RT } from "./syntax.js";
|
|
6
6
|
import { intlConstructor } from "../semantics/lang.js";
|
|
7
7
|
import { isArrayLengthLiteral, isAsync } from "../semantics/throws.js";
|
|
8
8
|
import { isLibDeclaration } from "../semantics/ast.js";
|
|
9
9
|
import { isKit, isUntyped, spelledType } from "../semantics/types.js";
|
|
10
10
|
import { constClassExpr, constructorOf } from "../semantics/classes.js";
|
|
11
|
+
import { resolveWorkerScript } from "../semantics/worker-state.js";
|
|
11
12
|
export const constructionMethods = {
|
|
12
13
|
/** The library error a class is under whose constructors, its own and its program bases', are none; null for another class. */
|
|
13
14
|
libErrorConstructed(cls) {
|
|
@@ -250,6 +251,9 @@ export const constructionMethods = {
|
|
|
250
251
|
if (this.native.isStructType(t) && !args.length)
|
|
251
252
|
return `${t}()`;
|
|
252
253
|
// A web class the runtime has (`new TextEncoder()`), declared by the DOM's library for core's own code: the runtime's class.
|
|
254
|
+
const workerScript = resolveWorkerScript(name, args, this.workerScripts, this.resolveAlias, 'ios');
|
|
255
|
+
if (workerScript)
|
|
256
|
+
return `JSWorker(${this.coerce(args[0], 'Any?')}, ${swiftString(workerScript)})`;
|
|
253
257
|
if (ts.isIdentifier(callee) && isWebClass(this.ledger, name) && t === `JS${name}` && !!this.resolve(callee)?.declarations?.[0]?.getSourceFile().isDeclarationFile)
|
|
254
258
|
return `${t}(${this.args(e).join(', ')})`;
|
|
255
259
|
this.refuseFunctionNew(e);
|
package/dist/swift/conversion.js
CHANGED
|
@@ -359,7 +359,7 @@ export const conversionMethods = {
|
|
|
359
359
|
// An untyped promise is read as the same promise, its reactions in the ticks they would have in JavaScript.
|
|
360
360
|
if (isUntyped(spelledType(pf)) && !this.lenient && !isOptional(from))
|
|
361
361
|
return `${RT.jsPromiseOf}(${code}) { ${pt === 'Void' ? '_ in ()' : this.presentFromAny('$0', pt)} }`;
|
|
362
|
-
const value = pt === 'Void' ? '' : `return ${isUntyped(spelledType(pf)) ? this.presentFromAny('__v', pt) : this.convert('__v', pf, pt)}`;
|
|
362
|
+
const value = pt === 'Void' ? '' : `return ${pf === 'Void' ? 'nil' : isUntyped(spelledType(pf)) ? this.presentFromAny('__v', pt) : this.convert('__v', pf, pt)}`;
|
|
363
363
|
// Lenient code's promise (or a plugin's, held optional) may be missing: then nothing is chained.
|
|
364
364
|
return `${this.lenient || isOptional(from) ? `(${code} as JSPromise<${pf}>?)?` : code}.then({ (__v: ${pf}) throws -> ${pt} in ${value} })`;
|
|
365
365
|
}
|
|
@@ -9,7 +9,6 @@ import { notedField } from "../semantics/shapes.js";
|
|
|
9
9
|
import { isWriteTarget } from "../semantics/ast.js";
|
|
10
10
|
import { convertedRead } from "../semantics/states/predicates.js";
|
|
11
11
|
import { isStatic } from "../semantics/throws.js";
|
|
12
|
-
import { iosRefusedGlobal } from "../semantics/platform-globals.js";
|
|
13
12
|
import { optionalContext } from "../semantics/spelled.js";
|
|
14
13
|
import { isKit, isUntyped, spelledType } from "../semantics/types.js";
|
|
15
14
|
import { atLossSite, HELD_LOSS } from "../semantics/losses.js";
|
|
@@ -91,9 +90,6 @@ export const expressionsMethods = {
|
|
|
91
90
|
return this.subst.get(e);
|
|
92
91
|
if (globalProxyUse(e, this.checker))
|
|
93
92
|
throw this.limit(e, 'proxy', '`Proxy`');
|
|
94
|
-
const refused = iosRefusedGlobal(e, this.checker);
|
|
95
|
-
if (refused)
|
|
96
|
-
throw this.error(e, `\`${refused.name}\` in an iOS build`, refused.id);
|
|
97
93
|
const narrowed = this.narrowedHeld(e);
|
|
98
94
|
if (narrowed) {
|
|
99
95
|
this.rawHeld.add(e);
|
|
@@ -307,6 +303,8 @@ export const expressionsMethods = {
|
|
|
307
303
|
const made = this.madeClass(e.expression);
|
|
308
304
|
if (made && sameClass(made, to))
|
|
309
305
|
return this.expr(e.expression);
|
|
306
|
+
if (isOptional(to))
|
|
307
|
+
return this.marks.castCode(this.expr(e.expression), to.slice(0, -1), 'as?');
|
|
310
308
|
return this.castThrows(e) ? this.marks.ownTried(`${RT.jsChecked}(${this.expr(e.expression)}, ${metatype(to)})`) : this.marks.castCode(this.expr(e.expression), to, 'as!');
|
|
311
309
|
}
|
|
312
310
|
// A non-strict app's assertion of a value that may be missing (`<UITableViewCell>table.cellForRow(…)`): unwrapped where used.
|
package/dist/swift/from-any.js
CHANGED
|
@@ -197,6 +197,11 @@ export const fromAnyMethods = {
|
|
|
197
197
|
// An Error held untyped (a caught or rejected value): the error, or a view of what was thrown instead.
|
|
198
198
|
if (type === 'JSError' && !this.lenient)
|
|
199
199
|
return `${RT.jsErrorOf}(${code})`;
|
|
200
|
+
// `globalThis as unknown as Worker`: wraps a worker realm's global object as a JSWorker.
|
|
201
|
+
if (type === 'JSWorker')
|
|
202
|
+
return this.marks.ownTried(`JSWorker.fromAny(${code})`);
|
|
203
|
+
if (type === 'JSWorker?' || type === 'JSWorker!')
|
|
204
|
+
return `JSWorker.fromAnyOrNil(${code})`;
|
|
200
205
|
// An implicitly unwrapped class (`tabView: TabView!`): the value as it, missing where it is none.
|
|
201
206
|
if (/^[A-Z][\w.]*!$/.test(type) && !this.native.isStructType(type.slice(0, -1)) && !['Double', 'String', 'Bool'].includes(type.slice(0, -1)))
|
|
202
207
|
return this.libraryClassCast(input, type.slice(0, -1), false, checked || throwing, placed) ?? this.marks.castCode(code, type.slice(0, -1), 'as?');
|
|
@@ -33,10 +33,17 @@ export const globalCallsMethods = {
|
|
|
33
33
|
const mixed = this.patterns.isMixinCall(e);
|
|
34
34
|
if (mixed)
|
|
35
35
|
return mixed.map((c) => `__install_${c.name.text}()`).join('; ');
|
|
36
|
+
const decl = this.resolve(callee)?.declarations?.[0];
|
|
37
|
+
// Worker globals (`postMessage`, `close`): checked before `native.call` so Darwin's C `close(_:)` does not shadow `close()`.
|
|
38
|
+
if ((callee.text === 'postMessage' || callee.text === 'close') && decl && (decl.getSourceFile().fileName === '/__shims__/globals.d.ts' || isLibDeclaration(decl))) {
|
|
39
|
+
if (callee.text === 'close')
|
|
40
|
+
return `${RT.jsClose}()`;
|
|
41
|
+
const args = e.arguments;
|
|
42
|
+
return `${RT.jsPostMessage}(${args[0] ? this.coerce(args[0], 'Any?') : 'nil'}${args[1] ? `, ${this.coerce(args[1], 'Any?')}` : ''})`;
|
|
43
|
+
}
|
|
36
44
|
const native = this.native.call(e);
|
|
37
45
|
if (native)
|
|
38
46
|
return native;
|
|
39
|
-
const decl = this.resolve(callee)?.declarations?.[0];
|
|
40
47
|
// A core function imported under another name (`timer.setTimeout`, read as `__timer_setTimeout`): by its own.
|
|
41
48
|
const name = decl && isCoreDeclaration(decl) && ts.isFunctionDeclaration(decl) && decl.name ? decl.name.text : callee.text;
|
|
42
49
|
const arg = (k) => e.arguments[k];
|
package/dist/swift/library.js
CHANGED
|
@@ -14,7 +14,7 @@ export const DESCRIPTORS = new Set(['PropertyDescriptor', 'TypedPropertyDescript
|
|
|
14
14
|
export const ARRAY_CALLBACK_METHODS = new Set(['forEach', 'map', 'filter', 'some', 'every', 'find', 'findIndex', 'findLast', 'findLastIndex', 'flatMap']);
|
|
15
15
|
export const isTypedArrayType = (t) => /^JS(Int8|Uint8|Uint8Clamped|Int16|Uint16|Int32|Uint32|Float32|Float64|BigInt64|BigUint64)Array$/.test(t);
|
|
16
16
|
// No prototype: a name like `toString` is no error class.
|
|
17
|
-
export const BUILTIN_CLASSES = Object.assign(Object.create(null), { Promise: 'JSThenable', Array: 'JSArrayProtocol', Map: 'JSMapProtocol', Set: 'JSSetProtocol', Date: 'JSDate' }, Object.fromEntries([...BUFFER_TYPES].map((n) => [n, `JS${n}`])));
|
|
17
|
+
export const BUILTIN_CLASSES = Object.assign(Object.create(null), { Promise: 'JSThenable', Array: 'JSArrayProtocol', Map: 'JSMapProtocol', Set: 'JSSetProtocol', Date: 'JSDate', RegExp: 'JSRegExp' }, Object.fromEntries([...BUFFER_TYPES].map((n) => [n, `JS${n}`])));
|
|
18
18
|
/** Library functions read as values, with their Swift function types. */
|
|
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' },
|
package/dist/swift/modules.js
CHANGED
|
@@ -709,11 +709,12 @@ export const modulesMethods = {
|
|
|
709
709
|
interfacesOf(file) {
|
|
710
710
|
let out = '';
|
|
711
711
|
const emitted = new Set();
|
|
712
|
+
const norm = file.replace(/\\/g, '/');
|
|
712
713
|
// An interface's own fields can use another one.
|
|
713
714
|
for (let more = true; more;) {
|
|
714
715
|
more = false;
|
|
715
716
|
for (const [name, decl] of this.interfaces) {
|
|
716
|
-
if (decl.file !==
|
|
717
|
+
if (decl.file.replace(/\\/g, '/') !== norm || emitted.has(name) || !this.used.has(name))
|
|
717
718
|
continue;
|
|
718
719
|
out = decl.code() + '\n\n' + out;
|
|
719
720
|
emitted.add(name);
|
|
@@ -319,7 +319,8 @@ export const objectClassesMethods = {
|
|
|
319
319
|
.filter((m) => !fields.some((f) => f.name === m.name))
|
|
320
320
|
.map((m) => {
|
|
321
321
|
// An app class's method sees the object it is called on as `this` when that is one of the class's (`obj[k].call(other)`).
|
|
322
|
-
const
|
|
322
|
+
const trailing = m.trailingFrom !== undefined ? { ref: `${byName ? '__s' : 'self'}.${ident(m.name)}`, from: m.trailingFrom } : undefined;
|
|
323
|
+
const value = byName ? `${RT.jsMethodValue}(self) { (__s: ${byName.receiver}) in ${this.boxFunction(`__s.${ident(m.name)}`, m.type, -1, m.name, m.length, trailing, false)} }` : this.boxFunction(`self.${ident(m.name)}`, m.type, -1, m.name, m.length, trailing, false);
|
|
323
324
|
// A value the instance holds in the method's place (`obj.step = …`) is what reading it gives.
|
|
324
325
|
const own = byName && ownNames.has(m.name) ? `if let __own = ${RT.jsOwnProperty}(self, ${swiftString(m.name)}) { return __own }; ` : '';
|
|
325
326
|
return { name: m.name, code: m.available ? `${own}if #available(iOS ${m.available}, *) { return ${value} } else { return nil }` : `${own}return ${value}` };
|
package/dist/swift/protocols.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// Protocol conformance as Swift: the protocols a class implements and their witnesses.
|
|
2
2
|
import ts from 'typescript';
|
|
3
3
|
import { ident, isOptional, metatype, optionalType, RT } from "./syntax.js";
|
|
4
|
-
import { implementedInterfaces } from "../semantics/lang.js";
|
|
4
|
+
import { implementedInterfaces, isEmittedInterface } from "../semantics/lang.js";
|
|
5
5
|
import { UNKEYED } from "../semantics/shapes.js";
|
|
6
6
|
import { hasModifier, isLibDeclaration } from "../semantics/ast.js";
|
|
7
7
|
import { isCoreDeclaration } from "../program/core-facts.js";
|
|
8
8
|
import { isNamed, isUntyped, spelledType } from "../semantics/types.js";
|
|
9
|
-
import { programBase } from "../semantics/classes.js";
|
|
9
|
+
import { ownClassMember, programBase, redeclaredMember } from "../semantics/classes.js";
|
|
10
10
|
export const protocolsMethods = {
|
|
11
11
|
/** Whether a class's source base class (or one above it) implements an interface. */
|
|
12
12
|
baseImplements(cls, iface) {
|
|
@@ -35,7 +35,7 @@ export const protocolsMethods = {
|
|
|
35
35
|
const named = implementedInterfaces(this.checker, cls).map((i) => ({ name: this.heritageName(i), type: this.checker.getTypeAtLocation(i) }));
|
|
36
36
|
const met = [...(this.structural.get(cls) ?? [])].map((d) => ({ name: this.topName(d, d.name.text), type: this.checker.getTypeAtLocation(d.name) }));
|
|
37
37
|
const implemented = [...named, ...met.filter((m) => !named.some((n) => n.name === m.name))]
|
|
38
|
-
.filter((i) => !isLibDeclaration(i.type.getSymbol()?.declarations?.[0]) && !this.uncompiledType(i.type))
|
|
38
|
+
.filter((i) => isEmittedInterface(i.type) && !isLibDeclaration(i.type.getSymbol()?.declarations?.[0]) && !this.uncompiledType(i.type))
|
|
39
39
|
// An interface only a declaration file has is no Swift protocol (a plugin's `IHttpsResponseLegacy` in its `.d.ts`), unless core's
|
|
40
40
|
// that the kit has; nor is one the program has no declaration of (a plugin's `import { IOptions } from '.'`, which the platform
|
|
41
41
|
// suffix resolves to the importing file itself).
|
|
@@ -100,17 +100,6 @@ export const protocolsMethods = {
|
|
|
100
100
|
const decl = type.getSymbol()?.declarations?.find(ts.isInterfaceDeclaration);
|
|
101
101
|
if (!decl || !this.protocols.has(name))
|
|
102
102
|
return true;
|
|
103
|
-
const own = (name) => {
|
|
104
|
-
for (let c = cls; c; c = this.sourceBase(c)) {
|
|
105
|
-
const m = c.members.find((x) => x.name?.getText() === name);
|
|
106
|
-
if (m)
|
|
107
|
-
return m;
|
|
108
|
-
const param = c.members.find(ts.isConstructorDeclaration)?.parameters.find((p) => ts.isIdentifier(p.name) && p.name.text === name && ts.canHaveModifiers(p) && !!ts.getModifiers(p)?.length);
|
|
109
|
-
if (param)
|
|
110
|
-
return param;
|
|
111
|
-
}
|
|
112
|
-
return undefined;
|
|
113
|
-
};
|
|
114
103
|
const added = [];
|
|
115
104
|
// The protocol refines its interface's bases: their members are required too.
|
|
116
105
|
const inherited = type
|
|
@@ -123,13 +112,13 @@ export const protocolsMethods = {
|
|
|
123
112
|
continue;
|
|
124
113
|
if (this.fieldByOwnParameter(cls, req))
|
|
125
114
|
return false;
|
|
126
|
-
const m =
|
|
115
|
+
const m = ownClassMember(cls, name, this.checker);
|
|
127
116
|
// A parameter property or an inherited member the class does not declare: Swift checks it.
|
|
128
117
|
if (!m)
|
|
129
118
|
continue;
|
|
130
119
|
if (ts.isPropertySignature(req)) {
|
|
131
120
|
const want = req.questionToken ? optionalType(this.typeOf(req)) : this.typeOf(req);
|
|
132
|
-
const root =
|
|
121
|
+
const root = redeclaredMember(m, this.checker);
|
|
133
122
|
const fieldType = ts.isPropertyDeclaration(m) ? this.typeOf(m.name) : ts.isParameter(m) ? (!!m.questionToken && !isOptional(this.typeOf(m.name)) && !isUntyped(spelledType(this.typeOf(m.name))) ? optionalType(this.typeOf(m.name)) : this.typeOf(m.name)) : null;
|
|
134
123
|
const have = ts.isGetAccessorDeclaration(m) ? (this.narrowedFrom(m) ?? this.returnTypeOf(m)) : root ? this.redeclaredType(root) : fieldType;
|
|
135
124
|
if (have !== want)
|
package/dist/swift/type-facts.js
CHANGED
|
@@ -326,6 +326,8 @@ export const typeFactsMethods = {
|
|
|
326
326
|
return `${t}?`;
|
|
327
327
|
if (isFunctionType(t) && this.widenedFunctionField(decl))
|
|
328
328
|
return optionalType(t);
|
|
329
|
+
if (ts.isParameter(decl) && this.states.nullishHeld(decl))
|
|
330
|
+
return optionalType(t);
|
|
329
331
|
return isWriteTarget(e) && (this.looseObjectDeclaration(decl, t) || (ts.isParameter(decl) && this.states.mayBeNull(decl))) ? optionalType(t) : t;
|
|
330
332
|
},
|
|
331
333
|
/**
|
package/dist/swift/types.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// TypeScript types as Swift types: representations, held and optional forms, shapes.
|
|
2
2
|
import ts from 'typescript';
|
|
3
3
|
import { DESCRIPTORS } from "./library.js";
|
|
4
|
-
import { WEB_DICTIONARIES,
|
|
4
|
+
import { WEB_DICTIONARIES, webClassName } from "../semantics/globals.js";
|
|
5
5
|
import { SPELLING, spell, functionParts, heldType, isFunctionLiteral, isFunctionType, isMethodValue, isOptional, nullishType, optionalElementsType, optionalType, returningAny, swiftString, RT } from "./syntax.js";
|
|
6
6
|
import { literalOverArray, membersOverTypeParameter, readByKey, definedField, untypedResultBinding, untypedResultField } from "../semantics/shapes.js";
|
|
7
7
|
import { ambientAddedMemberOf, ambientBase, augmentedPropertyRead, evolvingArrayRead, evolvingArrayType, isAmbientClass, isRegExpProtocol, mergedInterfaceMemberOf, statementLevel, tokenClassBase, undeclaredMemberOf, isArguments, nullableTypeNode } from "../semantics/lang.js";
|
|
@@ -174,11 +174,12 @@ export const typesMethods = {
|
|
|
174
174
|
const a = args()[k];
|
|
175
175
|
return a ? this.type(a, where) : 'Any?';
|
|
176
176
|
};
|
|
177
|
-
// Core's own code
|
|
178
|
-
if (name &&
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
177
|
+
// Core's own code and apps using DOM/core global typings: web classes declared in .d.ts map to the runtime's.
|
|
178
|
+
if (name && sym?.declarations?.length && sym.declarations.every((d) => d.getSourceFile().isDeclarationFile)) {
|
|
179
|
+
const web = webClassName(this.ledger, name);
|
|
180
|
+
if (web)
|
|
181
|
+
return web;
|
|
182
|
+
if (WEB_DICTIONARIES.includes(name) && (sym.declarations[0].getSourceFile().fileName === '/__shims__/globals.d.ts' || isLibDeclaration(sym.declarations[0])))
|
|
182
183
|
return 'Any?';
|
|
183
184
|
}
|
|
184
185
|
const kind = name === undefined ? undefined : this.framework.signalKind(name);
|
|
@@ -53,15 +53,17 @@ export async function writeAndroid(b) {
|
|
|
53
53
|
bindingDefines.push(...prepared.defines);
|
|
54
54
|
}
|
|
55
55
|
const classPath = androidClassPath(widgets, native);
|
|
56
|
+
const slash = (p) => p.replace(/\\/g, '/');
|
|
56
57
|
// The app's own typings of Java APIs no package types (`declare module androidx { … }` in a script .d.ts).
|
|
57
|
-
const appDir = resolve(b.app) + '/';
|
|
58
|
-
const appTypings = b.program.getSourceFiles().filter((sf) => sf.isDeclarationFile && sf.fileName.startsWith(appDir) && !sf.fileName.includes('/node_modules/') && !/^(import|export)\b/m.test(sf.text) && /^declare\s+(module|namespace)\s+(android|androidx|java|javax|com|org|kotlin|io)\b/m.test(sf.text));
|
|
58
|
+
const appDir = slash(resolve(b.app)) + '/';
|
|
59
|
+
const appTypings = b.program.getSourceFiles().filter((sf) => sf.isDeclarationFile && slash(sf.fileName).startsWith(appDir) && !slash(sf.fileName).includes('/node_modules/') && !/^(import|export)\b/m.test(sf.text) && /^declare\s+(module|namespace)\s+(android|androidx|java|javax|com|org|kotlin|io)\b/m.test(sf.text));
|
|
60
|
+
const allModuleFiles = [...b.modules, ...b.components.map((c) => c.file), ...(b.compiledPlugins ?? [])].map(slash);
|
|
59
61
|
if (b.workers?.length) {
|
|
60
|
-
const writes = sharedWorkerState(b.program, b.workers
|
|
62
|
+
const writes = sharedWorkerState(b.program, b.workers.map(slash), new Set(allModuleFiles), b.resolved);
|
|
61
63
|
if (writes.length)
|
|
62
64
|
throw sharedWorkerStateError(writes, b.app);
|
|
63
65
|
}
|
|
64
|
-
const moduleFiles = [...new Set(
|
|
66
|
+
const moduleFiles = [...new Set(allModuleFiles)];
|
|
65
67
|
// Which modules run on the main thread only; a worker's script reaching one stops the build with the import chain.
|
|
66
68
|
const threads = moduleThreads({ program: b.program, modules: moduleFiles, workers: b.workers, resolved: b.resolved, coreModuleOf: (f) => /[\\/]@nativescript[\\/]core[\\/](.+)$/.exec(f)?.[1] ?? null });
|
|
67
69
|
// A module only `await import(…)` reaches (and what only it imports) runs when it is imported, as the bundle evaluates
|
|
@@ -92,7 +94,7 @@ export async function writeAndroid(b) {
|
|
|
92
94
|
errors: b.allErrors ? [] : null,
|
|
93
95
|
plainFields: !!b.translatorHooks?.plainFields,
|
|
94
96
|
appMembersByName: !!b.xml && !b.xmlMemberKeys,
|
|
95
|
-
pluginRoots: (b.plugins ?? []).map((p) => p.root + '/'),
|
|
97
|
+
pluginRoots: (b.plugins ?? []).map((p) => slash(p.root) + '/'),
|
|
96
98
|
workerScripts: new Map((b.workers ?? []).map((f) => [f.replace(/\\/g, '/'), relative(b.app, f).replace(/\\/g, '/')])),
|
|
97
99
|
resolveAlias: b.aliased ?? null,
|
|
98
100
|
moduleThread: (file) => threads.get(file),
|
|
@@ -354,8 +356,8 @@ project(":kit").projectDir = file(${kotlinString(kitProjectDir(b.out))})
|
|
|
354
356
|
const adapterSources = [adapterKotlin, androidGenerated].filter((d) => !!d && existsSync(d));
|
|
355
357
|
writeFileSync(join(b.out, 'gradle.properties'), `org.gradle.jvmargs=-Xmx4g -Dfile.encoding=UTF-8
|
|
356
358
|
android.useAndroidX=true
|
|
357
|
-
nativescriptWidgetsAar=${widgets}
|
|
358
|
-
${overlay ? `kitOverlay=${join(KIT_ANDROID, 'overlays', XML_FREE_OVERLAY)}\nkitOverlayReplaces=${overlay.replaces.join(',')}\n` : ''}${adapterSources.length ? `kitAdapterSources=${adapterSources.join(',')}\n` : ''}`);
|
|
359
|
+
nativescriptWidgetsAar=${slash(widgets)}
|
|
360
|
+
${overlay ? `kitOverlay=${slash(join(KIT_ANDROID, 'overlays', XML_FREE_OVERLAY))}\nkitOverlayReplaces=${overlay.replaces.join(',')}\n` : ''}${adapterSources.length ? `kitAdapterSources=${adapterSources.map(slash).join(',')}\n` : ''}`);
|
|
359
361
|
writeFileSync(join(b.out, 'build.gradle.kts'), `plugins {
|
|
360
362
|
id("com.android.application") version "8.12.1"
|
|
361
363
|
id("com.android.library") version "8.12.1" apply false
|
|
@@ -28,6 +28,7 @@ import { mirror, writeIfChanged } from "../../driver/mirror.js";
|
|
|
28
28
|
import { KIT_APPLE, PACKAGE } from "../../driver/paths.js";
|
|
29
29
|
import { compiledEnv } from "../../program/env.js";
|
|
30
30
|
import { programClassName } from "../../semantics/top-names.js";
|
|
31
|
+
import { sharedWorkerState, sharedWorkerStateError } from "../../semantics/worker-state.js";
|
|
31
32
|
/** The app as an Xcode project in `b.out`, built where `b.build` says. */
|
|
32
33
|
export async function writeIos(b) {
|
|
33
34
|
const { context, app, appDir, out, name, framework, adapter, behaviour, components, modules, program, checker, files: sourceFiles, infos, elementClasses, root, mounted, xml, pageSheets, sheets, xmlRunTimeFree, xmlMemberKeys, lines: sourceLines, shownSource, plugins, bindings: pluginBindings, pluginFiles, compiledPlugins, reach, properties, resolved, lenient: lenientApp, assignFields: assignsFields, allowUnapplied, unapplied, say, started } = b;
|
|
@@ -74,10 +75,16 @@ export async function writeIos(b) {
|
|
|
74
75
|
for (const [js, c] of Object.entries(nativeTable(m).classes))
|
|
75
76
|
if (c.kind === 'class' && !c.extension && c.module === m)
|
|
76
77
|
pluginNativeClasses.set(js, c.swift);
|
|
78
|
+
const allModuleFiles = [...new Set([...modules, ...components.map((c) => c.file), ...compiledPlugins])];
|
|
79
|
+
if (b.workers?.length) {
|
|
80
|
+
const writes = sharedWorkerState(program, b.workers.map((f) => f.replace(/\\/g, '/')), new Set(allModuleFiles.map((f) => f.replace(/\\/g, '/'))), resolved);
|
|
81
|
+
if (writes.length)
|
|
82
|
+
throw sharedWorkerStateError(writes, app);
|
|
83
|
+
}
|
|
77
84
|
const translator = new Translator(checker, infos, sourceFiles, {
|
|
78
85
|
...context.translation(),
|
|
79
86
|
pluginFiles,
|
|
80
|
-
pluginRoots: plugins.all().map((p) => p.root + '/'),
|
|
87
|
+
pluginRoots: plugins.all().map((p) => p.root.replace(/\\/g, '/') + '/'),
|
|
81
88
|
lenientFiles,
|
|
82
89
|
reach,
|
|
83
90
|
properties,
|
|
@@ -95,6 +102,8 @@ export async function writeIos(b) {
|
|
|
95
102
|
appNativeClasses: Object.keys(appNative).filter((c) => !appNative[c].extension && appNative[c].kind === 'class'),
|
|
96
103
|
pluginNativeClasses,
|
|
97
104
|
pluginModules: native.modules,
|
|
105
|
+
workerScripts: new Map((b.workers ?? []).map((f) => [f.replace(/\\/g, '/'), relative(app, f).replace(/\\/g, '/')])),
|
|
106
|
+
resolveAlias: b.aliased ?? null,
|
|
98
107
|
allowUnapplied,
|
|
99
108
|
errors: b.allErrors ? (allowUnapplied ? [] : [...unapplied]) : null,
|
|
100
109
|
});
|
|
@@ -164,9 +173,14 @@ export async function writeIos(b) {
|
|
|
164
173
|
const shapes = SourceLines.strip((translator.interfacesOutside(new Set(translated.map((m) => m.file))) + translator.shapesCode()).trim());
|
|
165
174
|
if (shapes)
|
|
166
175
|
writeFileSync(join(sourcesDir, '__Objects.swift'), `// Compiled by ns-compiled: the app's object literals without a declared type.\nimport Foundation\nimport NativeScriptKit\n${native.modules.length || /\bUI[A-Z]/.test(shapes) ? `import UIKit\n${native.modules.map((m) => `import ${m}\n`).join('')}` : ''}${SDK_IMPORTS}\n${shapes}\n`);
|
|
167
|
-
const
|
|
176
|
+
const isWorker = (file) => !!translator.workerScripts?.has(file.replace(/\\/g, '/'));
|
|
177
|
+
const workerRegs = translated
|
|
178
|
+
.filter((m) => isWorker(m.file))
|
|
179
|
+
.map((m) => ` JSWorker.register(${swiftString(translator.workerScripts.get(m.file.replace(/\\/g, '/')))}) { ${m.init ? `${m.initThrows ? 'try ' : ''}${m.init}()` : ''} }\n`)
|
|
180
|
+
.join('');
|
|
181
|
+
const activeInits = translated.filter((m) => m.init && !isWorker(m.file));
|
|
168
182
|
const anyInitThrows = activeInits.some((m) => m.initThrows);
|
|
169
|
-
const inits = activeInits.length ? (anyInitThrows ? ` ${RT.jsReport} {\n${activeInits.map((m) => ` ${m.initThrows ? 'try ' : ''}${m.init}()\n`).join('')} }\n` : activeInits.map((m) => ` ${m.init}()\n`).join('')) : '';
|
|
183
|
+
const inits = workerRegs + (activeInits.length ? (anyInitThrows ? ` ${RT.jsReport} {\n${activeInits.map((m) => ` ${m.initThrows ? 'try ' : ''}${m.init}()\n`).join('')} }\n` : activeInits.map((m) => ` ${m.init}()\n`).join('')) : '');
|
|
170
184
|
// The app's CSS as its NativeScript build ships it: the AST core applies.
|
|
171
185
|
const css = kitAst(sheets);
|
|
172
186
|
const corePatchRefusal = corePatchRefused(app, nodeModules(app), 'ios');
|
|
@@ -325,11 +339,12 @@ export async function writeIos(b) {
|
|
|
325
339
|
removePods(out, name);
|
|
326
340
|
const resources = iosProjectResources({ app, appDir, out, name, pods: !!pods, say, stubbed: context.stubbedPlugins });
|
|
327
341
|
const extensions = iosExtensions({ app, out, bundle, packages, signing, team: resources.team, say });
|
|
328
|
-
// Script is single-threaded
|
|
329
|
-
//
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
342
|
+
// Script is single-threaded unless the app starts workers (each in its own isolated JSRealm on a worker thread).
|
|
343
|
+
// When workers are present, disable dynamic MainActor assertions in Debug too so worker threads can run realm-isolated code.
|
|
344
|
+
const hasWorkers = !!(b.workers && b.workers.length);
|
|
345
|
+
const swiftMode = { SWIFT_VERSION: '"6"', SWIFT_DEFAULT_ACTOR_ISOLATION: 'MainActor', ...(hasWorkers ? { OTHER_SWIFT_FLAGS: '"$(inherited) -Xfrontend -disable-dynamic-actor-isolation"' } : {}) };
|
|
346
|
+
// Release only: Debug keeps Swift 6's run-time isolation checks when no workers are present.
|
|
347
|
+
const swiftModeRelease = (...flags) => ` configs:\n Release:\n OTHER_SWIFT_FLAGS: "${['$(inherited)', ...(hasWorkers ? [] : ['-Xfrontend', '-disable-dynamic-actor-isolation']), ...flags].join(' ')}"\n`;
|
|
333
348
|
// The app's own Swift (App_Resources/iOS/src), compiled in the app's target, was written for Swift 5: the target keeps that mode,
|
|
334
349
|
// with the Swift 6 features the generated code relies on (a default argument evaluated in its function's isolation).
|
|
335
350
|
const appMode = native.appSwift ? { ...swiftMode, SWIFT_VERSION: '"5"', SWIFT_UPCOMING_FEATURE_ISOLATED_DEFAULT_VALUES: 'YES', SWIFT_UPCOMING_FEATURE_REGION_BASED_ISOLATION: 'YES', SWIFT_UPCOMING_FEATURE_INFER_SENDABLE_FROM_CAPTURES: 'YES', SWIFT_UPCOMING_FEATURE_GLOBAL_ACTOR_ISOLATED_TYPES_USABILITY: 'YES' } : swiftMode;
|
package/docs/cli/compile-ios.md
CHANGED
|
@@ -31,4 +31,4 @@ General | `$ ns compile ios [--for-device] [--team-id <Team>] [--provision <Prof
|
|
|
31
31
|
|
|
32
32
|
### Platform Notes
|
|
33
33
|
|
|
34
|
-
* `new Worker(...)` background threads are
|
|
34
|
+
* `new Worker(...)` background threads are supported in compiled iOS builds (`ns compile ios`) with per-worker realms, structured cloning, `ArrayBuffer` transfer, timers, and microtasks, matching Android (`ns compile android`).
|
|
@@ -2342,7 +2342,7 @@ open class FileSystemAccess : JSExpando {
|
|
|
2342
2342
|
|
|
2343
2343
|
companion object {
|
|
2344
2344
|
fun getBuffer(buffer: Any?): Any? {
|
|
2345
|
-
if ((buffer is
|
|
2345
|
+
if ((buffer is JSArrayBuffer)) {
|
|
2346
2346
|
return jsOr(
|
|
2347
2347
|
jsGet((jsCastCarried(buffer, JSArrayBuffer::class.java)), "nativeObject")
|
|
2348
2348
|
) {
|
package/kit-android/generated/kotlin/org/nativescript/kit/http_http_request_internal_index.kt
CHANGED
|
@@ -161,7 +161,7 @@ object Core_http_http_request_internal_index {
|
|
|
161
161
|
?: jsObjectRequired())
|
|
162
162
|
)
|
|
163
163
|
javaOptions.content = nativeBuffer
|
|
164
|
-
} else if ((jsGet(options, "content") is
|
|
164
|
+
} else if ((jsGet(options, "content") is JSArrayBuffer)) {
|
|
165
165
|
val typedArray: JSUint8Array =
|
|
166
166
|
JSUint8Array(jsCastCarried(jsGet(options, "content"), JSArrayBuffer::class.java))
|
|
167
167
|
val nativeBuffer: ByteBuffer? =
|
|
@@ -1403,15 +1403,15 @@ open class CssProperty : JSExpando, JSKeysMade {
|
|
|
1403
1403
|
jsObjectOf(
|
|
1404
1404
|
"enumerable" to true,
|
|
1405
1405
|
"configurable" to true,
|
|
1406
|
-
"get" to JSMethod { __self, _ -> get(__self) },
|
|
1407
|
-
"set" to JSMethod { __self, __a -> setCssValue(__self, __a.getOrNull(0)) },
|
|
1406
|
+
"get" to JSMethod(0) { __self, _ -> get(__self) },
|
|
1407
|
+
"set" to JSMethod(1) { __self, __a -> setCssValue(__self, __a.getOrNull(0)) },
|
|
1408
1408
|
)
|
|
1409
1409
|
this.localValueDescriptor =
|
|
1410
1410
|
jsObjectOf(
|
|
1411
1411
|
"enumerable" to true,
|
|
1412
1412
|
"configurable" to true,
|
|
1413
|
-
"get" to JSMethod { __self, _ -> get(__self) },
|
|
1414
|
-
"set" to JSMethod { __self, __a -> setLocalValue(__self, __a.getOrNull(0)) },
|
|
1413
|
+
"get" to JSMethod(0) { __self, _ -> get(__self) },
|
|
1414
|
+
"set" to JSMethod(1) { __self, __a -> setLocalValue(__self, __a.getOrNull(0)) },
|
|
1415
1415
|
)
|
|
1416
1416
|
jsSet(Core_ui_core_properties_index.cssSymbolPropertyMap, key.key, this)
|
|
1417
1417
|
}
|
|
@@ -2592,7 +2592,7 @@ open class ShorthandProperty : JSExpando, JSKeysMade {
|
|
|
2592
2592
|
"configurable" to true,
|
|
2593
2593
|
"get" to jsGet(options, "getter"),
|
|
2594
2594
|
"set" to
|
|
2595
|
-
JSMethod { __self, __a ->
|
|
2595
|
+
JSMethod(1) { __self, __a ->
|
|
2596
2596
|
setCssValue(__self, jsConvertedStringOrNull(__a.getOrNull(0)))
|
|
2597
2597
|
},
|
|
2598
2598
|
)
|
|
@@ -2601,7 +2601,7 @@ open class ShorthandProperty : JSExpando, JSKeysMade {
|
|
|
2601
2601
|
"enumerable" to true,
|
|
2602
2602
|
"configurable" to true,
|
|
2603
2603
|
"get" to jsGet(options, "getter"),
|
|
2604
|
-
"set" to JSMethod { __self, __a -> setLocalValue(__self, __a.getOrNull(0)) },
|
|
2604
|
+
"set" to JSMethod(1) { __self, __a -> setLocalValue(__self, __a.getOrNull(0)) },
|
|
2605
2605
|
)
|
|
2606
2606
|
jsSet(Core_ui_core_properties_index.cssSymbolPropertyMap, key.key, this)
|
|
2607
2607
|
}
|
|
@@ -142,7 +142,7 @@ open class FormattedString : ViewBase {
|
|
|
142
142
|
open fun _addArrayFromBuilder(name: String?, value: JSArray<Any?>?) {
|
|
143
143
|
if (name == "spans") {
|
|
144
144
|
(this.spans ?: jsCannotRead("push")).push(
|
|
145
|
-
JSArray<
|
|
145
|
+
JSArray<Any?>(((value ?: jsObjectRequired())).toList())
|
|
146
146
|
)
|
|
147
147
|
}
|
|
148
148
|
}
|
|
@@ -150,7 +150,7 @@ open class FormattedString : ViewBase {
|
|
|
150
150
|
open fun _addChildFromBuilder(name: String?, value: Any?) {
|
|
151
151
|
if ((value is Span)) {
|
|
152
152
|
(this.spans ?: jsCannotRead("push")).push(
|
|
153
|
-
JSArray<
|
|
153
|
+
JSArray<Any?>(listOf<Any?>(jsCastCarried(value, Span::class.java)))
|
|
154
154
|
)
|
|
155
155
|
}
|
|
156
156
|
}
|
|
@@ -219,13 +219,13 @@ abstract class TextBaseCommon : View {
|
|
|
219
219
|
if (!jsTruthy(this.formattedText)) {
|
|
220
220
|
val formattedText: FormattedString = FormattedString()
|
|
221
221
|
(formattedText.spans ?: jsCannotRead("push")).push(
|
|
222
|
-
JSArray<
|
|
222
|
+
JSArray<Any?>(listOf<Any?>(value))
|
|
223
223
|
)
|
|
224
224
|
this.formattedText = formattedText
|
|
225
225
|
} else {
|
|
226
226
|
((this.formattedText ?: jsCannotRead("spans")).spans
|
|
227
227
|
?: jsCannotRead("push"))
|
|
228
|
-
.push(JSArray<
|
|
228
|
+
.push(JSArray<Any?>(listOf<Any?>(value)))
|
|
229
229
|
}
|
|
230
230
|
} else if (
|
|
231
231
|
name == Core_ui_text_base_text_base_common.CHILD_FORMATTED_TEXT ||
|