@nstudio/nativescript-compiler 9.2.0-alpha.14 → 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/driver/compile.js +4 -3
- package/dist/kotlin/arguments.js +2 -1
- package/dist/kotlin/builtins.js +14 -3
- 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 +16 -3
- package/dist/kotlin/core-api.js +14 -7
- package/dist/kotlin/declarations.js +1 -1
- package/dist/kotlin/expressions.js +10 -5
- package/dist/kotlin/modules.js +7 -3
- package/dist/kotlin/names.js +5 -2
- 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/translator.js +0 -39
- package/dist/kotlin/types.js +4 -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 +8 -10
- 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/object-classes.js +2 -1
- package/dist/swift/protocols.js +5 -16
- package/dist/swift/types.js +4 -3
- package/dist/targets/ios/build.js +22 -7
- package/docs/cli/compile-ios.md +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/src/main/kotlin/org/nativescript/kit/runtime/Collections.kt +15 -6
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Promise.kt +1 -1
- 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
package/dist/kotlin/types.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// TypeScript types as Kotlin types: representations, held and optional forms, shapes.
|
|
2
2
|
import ts from 'typescript';
|
|
3
3
|
import { KIT_NAMES_ANDROID } from "./library.js";
|
|
4
|
-
import { BUFFER_TYPES, WEB_DICTIONARIES,
|
|
4
|
+
import { BUFFER_TYPES, WEB_DICTIONARIES, webClassName } from "../semantics/globals.js";
|
|
5
5
|
import { SPELLING, spell, destructuringSource, functionTypeParts, kotlinString, nullishType, optionalElementsType, optionalType, presentConst, RT } from "./syntax.js";
|
|
6
6
|
import { ambientBase, evolvingArrayRead, evolvingArrayType, isAmbientClass, isRegExpProtocol, memberOwner, namesOwnTypeParameter, tokenClassBase, isArguments } from "../semantics/lang.js";
|
|
7
7
|
import { nullishSignalType } from "../semantics/signals.js";
|
|
@@ -183,10 +183,9 @@ export const typesMethods = {
|
|
|
183
183
|
return a ? this.type(a, where) : 'Any?';
|
|
184
184
|
};
|
|
185
185
|
if (name && sym?.declarations?.length && sym.declarations.every((d) => d.getSourceFile().isDeclarationFile)) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return 'JSWorker';
|
|
186
|
+
const web = webClassName(this.ledger, name);
|
|
187
|
+
if (web)
|
|
188
|
+
return web;
|
|
190
189
|
if (WEB_DICTIONARIES.includes(name) && (sym.declarations[0].getSourceFile().fileName === '/__shims__/globals.d.ts' || isLibDeclaration(sym.declarations[0])))
|
|
191
190
|
return 'Any?';
|
|
192
191
|
}
|
|
@@ -312,7 +312,13 @@ export const untypedValuesMethods = {
|
|
|
312
312
|
const kept = this.pluginFiles.has(decl.getSourceFile().fileName) ? [] : (decl.typeParameters ?? []).filter((p) => !this.erasesTypeParameter(p));
|
|
313
313
|
const generic = kept.length ? `<${kept.map((p) => (!this.library && this.classConstraint(p) ? this.type(this.checker.getTypeFromTypeNode(p.constraint), p).replace(/\?$/, '') : 'Any?')).join(', ')}>` : '';
|
|
314
314
|
// One reading `arguments` takes them all (`__arguments`).
|
|
315
|
-
const
|
|
315
|
+
const argOf = (q, k) => {
|
|
316
|
+
if (q.dotDotDotToken)
|
|
317
|
+
return `JSArray(__a.drop(${k}).map { ${generic ? `${RT.jsUnchecked}(it)` : this.fromAnyCode('it', this.typeOf(q.name).replace(/^JSArray<(.*)>$/, '$1'), true)} }.toMutableList())`;
|
|
318
|
+
const raw = generic ? `${RT.jsUnchecked}(__a.getOrNull(${k}))` : this.fromAnyCode(this.marks.pureCode(`__a.getOrNull(${k})`), this.paramType(q), true);
|
|
319
|
+
return this.constantDefault(q) ? `if (__a.getOrNull(${k}) == null) ${this.stored(q.initializer, q, this.paramType(q))} else ${raw}` : raw;
|
|
320
|
+
};
|
|
321
|
+
const args = this.readsArguments(decl) ? ['JSArray<Any?>(__a.toMutableList())'] : decl.parameters.map(argOf);
|
|
316
322
|
const arity = decl.parameters.findIndex((q) => !!q.questionToken || !!q.initializer || !!q.dotDotDotToken);
|
|
317
323
|
if (this.implicitThis(decl))
|
|
318
324
|
return `JSMethod(${arity < 0 ? decl.parameters.length : arity}) ${lambda(['__self', '__a'], `${name}${generic}(${['__self', ...args].join(', ')})${this.returnTypeOf(decl) === 'Unit' ? '; null' : ''}`)}`;
|
package/dist/program/program.js
CHANGED
|
@@ -434,7 +434,7 @@ export function createProgram(roots, virtual, platform = 'ios', modulesDir, plug
|
|
|
434
434
|
}
|
|
435
435
|
}
|
|
436
436
|
// A package the app replaces for the native build is the app's module.
|
|
437
|
-
const replacement = !m.startsWith('.') && !m
|
|
437
|
+
const replacement = !m.startsWith('.') && !isAbsolute(m) ? replacements[packageOf(m)] : undefined;
|
|
438
438
|
if (replacement)
|
|
439
439
|
return { resolvedModule: { resolvedFileName: replacement, extension: ts.Extension.Ts } };
|
|
440
440
|
// A plugin is compiled from its source: an import that reaches its code resolves to the file it was built from,
|
|
@@ -446,7 +446,7 @@ export function createProgram(roots, virtual, platform = 'ios', modulesDir, plug
|
|
|
446
446
|
const augments = ts.isModuleDeclaration(lit.parent) && lit.parent.name === lit && !!plugins?.all().some((p) => containing.startsWith(p.root + '/'));
|
|
447
447
|
// Every import of `rxjs` (including `import type` and `.d.ts` files like `@angular/cdk`) must resolve to the same compiled `rxjs` source so Observable/OperatorFunction types match across the whole program.
|
|
448
448
|
const sharedRxjs = m === 'rxjs' || m.startsWith('rxjs/');
|
|
449
|
-
if (plugins && (isSource(containing) || pluginFiles.has(containing) || augments || containing.startsWith('/__shims__/') || (containing.endsWith('.d.ts') && sharedRxjs)) && !m.startsWith('.') && !m
|
|
449
|
+
if (plugins && (isSource(containing) || pluginFiles.has(containing) || augments || containing.startsWith('/__shims__/') || (containing.endsWith('.d.ts') && sharedRxjs)) && !m.startsWith('.') && !isAbsolute(m) && !notPlugin(packageOf(m)) && (!typeOnly || sharedRxjs)) {
|
|
450
450
|
const js = runtimeFile(m, modules, platform, localPackages);
|
|
451
451
|
if (js) {
|
|
452
452
|
plugins.get(js.packageDir);
|
|
@@ -470,7 +470,7 @@ export function createProgram(roots, virtual, platform = 'ios', modulesDir, plug
|
|
|
470
470
|
}
|
|
471
471
|
}
|
|
472
472
|
// Type-only imports of local `file:` packages (outside node_modules): resolve to the package's typings.
|
|
473
|
-
if (!m.startsWith('.') && !m
|
|
473
|
+
if (!m.startsWith('.') && !isAbsolute(m)) {
|
|
474
474
|
const localDir = localPackages.get(packageOf(m));
|
|
475
475
|
if (localDir) {
|
|
476
476
|
const deep = m.slice(packageOf(m).length).replace(/^\//, '');
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// `Array`'s functions, and those of the buffer types.
|
|
2
|
+
import ts from 'typescript';
|
|
2
3
|
import { apiEntry, apiTable } from "./api.js";
|
|
3
4
|
export const ARRAY_STATICS = apiTable('static', {
|
|
4
5
|
// Function.prototype's, which `Array(...list)` reads as.
|
|
@@ -67,3 +68,13 @@ export const GENERIC_ARRAY_METHODS = new Set([...Object.keys(ARRAY_METHODS), 'co
|
|
|
67
68
|
export function arrayMember(name) {
|
|
68
69
|
return apiEntry(ARRAY_METHODS, name);
|
|
69
70
|
}
|
|
71
|
+
/** How `array.flat(depth?)` lowers for a receiver whose element type is `element`. */
|
|
72
|
+
export function typedFlatPlan(e, element, untyped) {
|
|
73
|
+
const arg = e.arguments[0];
|
|
74
|
+
if (!arg)
|
|
75
|
+
return { kind: 'default' };
|
|
76
|
+
if (untyped)
|
|
77
|
+
return { kind: 'depth', arg, untyped: true };
|
|
78
|
+
const levels = Math.min(Number(ts.isNumericLiteral(arg) ? arg.text : NaN), /^(JSArray<)*/.exec(element)[0].length / 8);
|
|
79
|
+
return levels >= 1 ? { kind: 'chain', suffix: '.flat()'.repeat(levels) } : { kind: 'depth', arg, untyped: false };
|
|
80
|
+
}
|
|
@@ -75,6 +75,30 @@ export function rootMethod(m, checker) {
|
|
|
75
75
|
root = up;
|
|
76
76
|
return root;
|
|
77
77
|
}
|
|
78
|
+
/** The Error runtime base name (e.g. `'JSError'`) that `cls`'s hierarchy extends through program base classes, or null. */
|
|
79
|
+
export function rootErrorBase(cls, checker) {
|
|
80
|
+
let root = cls;
|
|
81
|
+
for (let b = programBase(root, checker); b; b = programBase(b, checker))
|
|
82
|
+
root = b;
|
|
83
|
+
const h = root.heritageClauses?.find((x) => x.token === ts.SyntaxKind.ExtendsKeyword)?.types[0];
|
|
84
|
+
return h ? (ERRORS[h.expression.getText()] ?? null) : null;
|
|
85
|
+
}
|
|
86
|
+
/** The non-static member or constructor parameter property of `name` declared on `cls` or a program base class. */
|
|
87
|
+
export function ownClassMember(cls, name, checker) {
|
|
88
|
+
for (let c = cls; c; c = programBase(c, checker)) {
|
|
89
|
+
const m = c.members.find((x) => !isStatic(x) && x.name?.getText() === name);
|
|
90
|
+
if (m)
|
|
91
|
+
return m;
|
|
92
|
+
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);
|
|
93
|
+
if (param)
|
|
94
|
+
return param;
|
|
95
|
+
}
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
/** If `m` is a property or parameter property redeclaring a program base class's field/accessor, that base member; else null. */
|
|
99
|
+
export function redeclaredMember(m, checker) {
|
|
100
|
+
return ts.isPropertyDeclaration(m) || ts.isParameter(m) ? redeclaredField(m, checker) : null;
|
|
101
|
+
}
|
|
78
102
|
/** The field, accessor or parameter property a program base class declares under a field's name, which the field redeclares. */
|
|
79
103
|
export function redeclaredField(m, checker) {
|
|
80
104
|
const cls = ts.isParameter(m) ? (ts.isParameterPropertyDeclaration(m, m.parent) ? m.parent.parent : undefined) : m.parent;
|
package/dist/semantics/config.js
CHANGED
|
@@ -19,6 +19,8 @@ export function configFields(config, ledger) {
|
|
|
19
19
|
allowUnapplied: config.allowUnapplied ?? false,
|
|
20
20
|
lines: config.lines ?? null,
|
|
21
21
|
errors: config.errors ?? null,
|
|
22
|
+
workerScripts: config.workerScripts ?? null,
|
|
23
|
+
resolveAlias: config.resolveAlias ?? null,
|
|
22
24
|
};
|
|
23
25
|
}
|
|
24
26
|
/** What a translator reads of its build, from a config that may leave it out: a build of its own, with no framework. */
|
|
@@ -299,6 +299,8 @@ export const byNameCallsMethods = {
|
|
|
299
299
|
const c = this.checker, viewed = new Map();
|
|
300
300
|
const extendsInterface = (t, wanted, depth = 0) => depth < 32 && (t.getSymbol() === wanted || (t.isClassOrInterface() && c.getBaseTypes(t).some((b) => extendsInterface(b, wanted, depth + 1))));
|
|
301
301
|
const names = (cls, wanted) => {
|
|
302
|
+
if (!(wanted.declarations ?? []).some(ts.isInterfaceDeclaration))
|
|
303
|
+
return false;
|
|
302
304
|
// A library base's own interface (`extends Error` where `Error` is wanted) is the class's too.
|
|
303
305
|
if (extendsInterface(c.getTypeAtLocation(cls.name ?? cls), wanted))
|
|
304
306
|
return true;
|
|
@@ -309,27 +311,37 @@ export const byNameCallsMethods = {
|
|
|
309
311
|
}
|
|
310
312
|
return false;
|
|
311
313
|
};
|
|
312
|
-
for (const x of this.placed
|
|
314
|
+
for (const [x, slots] of this.placed) {
|
|
315
|
+
const rawTypes = [];
|
|
313
316
|
const at = c.getContextualType(x);
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
317
|
+
if (at)
|
|
318
|
+
rawTypes.push(at);
|
|
319
|
+
for (const s of slots) {
|
|
320
|
+
const rt = this.find(s).type;
|
|
321
|
+
if (rt)
|
|
322
|
+
rawTypes.push(rt);
|
|
323
|
+
}
|
|
318
324
|
const t = c.getNonNullableType(c.getTypeAtLocation(x));
|
|
319
|
-
for (const
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
this.viewedStatic.add(b);
|
|
325
|
+
for (const raw of rawTypes) {
|
|
326
|
+
const wt = c.getNonNullableType(raw);
|
|
327
|
+
const wanted = wt.getSymbol();
|
|
328
|
+
if (!wanted || !(wanted.flags & (ts.SymbolFlags.TypeLiteral | ts.SymbolFlags.Interface)) || wanted.flags & ts.SymbolFlags.Class || wt.getCallSignatures().length || wt.getConstructSignatures().length || !wt.getProperties().length)
|
|
324
329
|
continue;
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
330
|
+
for (const part of t.isUnion() ? t.types : [t]) {
|
|
331
|
+
const cls = part.getSymbol()?.declarations?.find((d) => ts.isClassLike(d) && !declarationFile(d));
|
|
332
|
+
if (cls && part.getConstructSignatures().length) {
|
|
333
|
+
for (let b = cls; b; b = programBase(b, c))
|
|
334
|
+
this.viewedStatic.add(b);
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
if (!cls || names(cls, wanted))
|
|
338
|
+
continue;
|
|
339
|
+
const keys = wt.getProperties().map((p) => p.name);
|
|
340
|
+
for (let b = cls; b; b = programBase(b, c)) {
|
|
341
|
+
const into = viewed.get(b) ?? viewed.set(b, new Set()).get(b);
|
|
342
|
+
for (const k of keys)
|
|
343
|
+
into.add(k);
|
|
344
|
+
}
|
|
333
345
|
}
|
|
334
346
|
}
|
|
335
347
|
}
|
|
@@ -18,8 +18,14 @@ const WORKER_CLASSES = ['Worker', 'MessageEvent', 'ErrorEvent', 'URL'];
|
|
|
18
18
|
/** Web API classes that have native/kit representations (as opposed to DOM-only element/node interfaces held untyped). */
|
|
19
19
|
export const ALL_WEB_CLASSES = new Set([...WEB_CLASSES, ...WORKER_CLASSES, 'URLSearchParams', 'AbortController', 'AbortSignal', 'Blob', 'File', 'FormData', 'Headers', 'Request', 'Response', 'Event', 'EventTarget', 'CustomEvent', 'CloseEvent', 'WebSocket', 'ReadableStream', 'WritableStream', 'TransformStream']);
|
|
20
20
|
/** `name` is a web class the kit implements. */
|
|
21
|
-
export function isWebClass(
|
|
22
|
-
return WEB_CLASSES.includes(name) ||
|
|
21
|
+
export function isWebClass(_ledger, name) {
|
|
22
|
+
return WEB_CLASSES.includes(name) || WORKER_CLASSES.includes(name);
|
|
23
|
+
}
|
|
24
|
+
/** The kit class name for a web or worker global class (`Worker` → `JSWorker`, `DedicatedWorkerGlobalScope` → `JSWorker`). */
|
|
25
|
+
export function webClassName(ledger, name) {
|
|
26
|
+
if (name === 'DedicatedWorkerGlobalScope')
|
|
27
|
+
return 'JSWorker';
|
|
28
|
+
return isWebClass(ledger, name) ? `JS${name}` : null;
|
|
23
29
|
}
|
|
24
30
|
/** The web's option and algorithm dictionaries, plus global-object web interfaces read by key. */
|
|
25
31
|
export const WEB_DICTIONARIES = ['TextDecoderOptions', 'Algorithm', 'HmacKeyGenParams', 'RsaKeyGenParams', 'RsaHashedKeyGenParams', 'RsaOaepParams', 'Performance', 'Storage'];
|
package/dist/semantics/lang.js
CHANGED
|
@@ -7,6 +7,10 @@ export { isAmbientClass, ambientBase, ambientAddedMemberOf, implementedInterface
|
|
|
7
7
|
export { slotType, nullSetFields, initializedNull, assignedValues, definitelyAssignedFields, containsThis, alwaysThrows, alwaysEnds, statementLevel } from "./lang/fields.js";
|
|
8
8
|
export { readWrite, compoundOperator, asOperation, assignmentOf, globalProxyUse, builtinPrototypeAlias, aliasedPrototypeMember, tokenClassBase, isArguments, escapesArguments, canReadArguments, inferredFunctionName, functionProperty, isConstant, isSelf, objectMethod, literalMethod, prototypeAlias, methodValues } from "./lang/prototypes.js";
|
|
9
9
|
// JavaScript semantics both translators share, decided from the syntax tree and the checker.
|
|
10
|
+
/** Whether `t`'s symbol has an explicit `interface` declaration (not a mapped/`Pick` type alias erased to `Any?`). */
|
|
11
|
+
export function isEmittedInterface(t) {
|
|
12
|
+
return (t.getSymbol()?.declarations ?? []).some(ts.isInterfaceDeclaration);
|
|
13
|
+
}
|
|
10
14
|
/** A type written with `| null` or `| undefined`, which code checked without strictNullChecks types without them. */
|
|
11
15
|
export function nullableTypeNode(t) {
|
|
12
16
|
return !!t && ts.isUnionTypeNode(t) && t.types.some((x) => x.kind === ts.SyntaxKind.UndefinedKeyword || (ts.isLiteralTypeNode(x) && x.literal.kind === ts.SyntaxKind.NullKeyword));
|
package/dist/semantics/ledger.js
CHANGED
|
@@ -10,23 +10,15 @@ export const LEDGER_KINDS = {
|
|
|
10
10
|
looseReads: 'gap',
|
|
11
11
|
checkedParameters: 'platform',
|
|
12
12
|
implicitThisUnconstructed: 'gap',
|
|
13
|
-
workerGlobals: 'gap',
|
|
14
13
|
nativeSdk: 'platform',
|
|
15
14
|
freesOnLastReference: 'platform',
|
|
16
15
|
failedUnwrapThrows: 'gap',
|
|
17
16
|
subclassFieldsBeforeBase: 'platform',
|
|
18
17
|
typedArrays: 'gap',
|
|
19
|
-
typedFlat: 'gap',
|
|
20
|
-
functionObjects: 'gap',
|
|
21
18
|
functionIdentity: 'gap',
|
|
22
19
|
unboundGenerics: 'gap',
|
|
23
20
|
indexConversions: 'gap',
|
|
24
|
-
accessorNameClash: 'gap',
|
|
25
|
-
genericAsyncResult: 'gap',
|
|
26
|
-
orAssignTyped: 'gap',
|
|
27
|
-
errorSubclassConstructor: 'gap',
|
|
28
21
|
errorSubclassKeyOrder: 'gap',
|
|
29
|
-
unmetInterfaceMembers: 'gap',
|
|
30
22
|
pluginsWrittenStrict: 'gap',
|
|
31
23
|
functionElementsUntyped: 'platform',
|
|
32
24
|
errorClassObjects: 'platform',
|
|
@@ -56,23 +48,15 @@ export const SWIFT_LEDGER = {
|
|
|
56
48
|
looseReads: true,
|
|
57
49
|
checkedParameters: false,
|
|
58
50
|
implicitThisUnconstructed: true,
|
|
59
|
-
workerGlobals: false,
|
|
60
51
|
nativeSdk: 'apple',
|
|
61
52
|
freesOnLastReference: true,
|
|
62
53
|
failedUnwrapThrows: false,
|
|
63
54
|
subclassFieldsBeforeBase: true,
|
|
64
55
|
typedArrays: true,
|
|
65
|
-
typedFlat: true,
|
|
66
|
-
functionObjects: true,
|
|
67
56
|
functionIdentity: true,
|
|
68
57
|
unboundGenerics: true,
|
|
69
58
|
indexConversions: true,
|
|
70
|
-
accessorNameClash: true,
|
|
71
|
-
genericAsyncResult: true,
|
|
72
|
-
orAssignTyped: true,
|
|
73
|
-
errorSubclassConstructor: true,
|
|
74
59
|
errorSubclassKeyOrder: false,
|
|
75
|
-
unmetInterfaceMembers: true,
|
|
76
60
|
pluginsWrittenStrict: true,
|
|
77
61
|
functionElementsUntyped: true,
|
|
78
62
|
errorClassObjects: false,
|
|
@@ -102,23 +86,15 @@ export const KOTLIN_LEDGER = {
|
|
|
102
86
|
looseReads: false,
|
|
103
87
|
checkedParameters: true,
|
|
104
88
|
implicitThisUnconstructed: false,
|
|
105
|
-
workerGlobals: true,
|
|
106
89
|
nativeSdk: 'android',
|
|
107
90
|
freesOnLastReference: false,
|
|
108
91
|
failedUnwrapThrows: true,
|
|
109
92
|
subclassFieldsBeforeBase: false,
|
|
110
93
|
typedArrays: false,
|
|
111
|
-
typedFlat: false,
|
|
112
|
-
functionObjects: false,
|
|
113
94
|
functionIdentity: false,
|
|
114
95
|
unboundGenerics: false,
|
|
115
96
|
indexConversions: false,
|
|
116
|
-
accessorNameClash: false,
|
|
117
|
-
genericAsyncResult: false,
|
|
118
|
-
orAssignTyped: false,
|
|
119
|
-
errorSubclassConstructor: false,
|
|
120
97
|
errorSubclassKeyOrder: true,
|
|
121
|
-
unmetInterfaceMembers: false,
|
|
122
98
|
pluginsWrittenStrict: false,
|
|
123
99
|
functionElementsUntyped: false,
|
|
124
100
|
errorClassObjects: true,
|
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
1
|
/** The typings of the platform a build does not bind (`Ledger.nativeSdk`): what they declare only the other platform's code holds. */
|
|
3
2
|
export function otherPlatformTypings(ledger) {
|
|
4
3
|
return ledger.nativeSdk === 'apple' ? /[\\/]@nativescript[\\/]types-android[\\/]/ : /[\\/]@nativescript[\\/]types-ios[\\/]/;
|
|
5
4
|
}
|
|
6
|
-
/**
|
|
7
|
-
* The worker API's globals both platforms type (program.ts `WORKER_GLOBALS`), which only Android's kit runs: an iOS build
|
|
8
|
-
* refuses each, where the platform's own names (Darwin's `close`) would otherwise take their place.
|
|
9
|
-
*/
|
|
10
|
-
const IOS_REFUSED = { Worker: 'worker', postMessage: 'worker', close: 'worker', URL: 'library-member' };
|
|
11
|
-
/** The refusal an iOS build gives `e` where it is, or is read from, one of those globals; null otherwise. */
|
|
12
|
-
export function iosRefusedGlobal(e, checker) {
|
|
13
|
-
let x = e;
|
|
14
|
-
while (ts.isNewExpression(x) || ts.isCallExpression(x) || ts.isPropertyAccessExpression(x) || ts.isElementAccessExpression(x) || ts.isParenthesizedExpression(x) || ts.isAsExpression(x) || ts.isNonNullExpression(x) || ts.isTypeAssertionExpression(x))
|
|
15
|
-
x = x.expression;
|
|
16
|
-
if (!ts.isIdentifier(x) || !Object.hasOwn(IOS_REFUSED, x.text))
|
|
17
|
-
return null;
|
|
18
|
-
const decls = checker.getSymbolAtLocation(x)?.declarations ?? [];
|
|
19
|
-
return decls.length && decls.every((d) => d.getSourceFile().fileName === '/__shims__/globals.d.ts') ? { id: IOS_REFUSED[x.text], name: x.text } : null;
|
|
20
|
-
}
|
|
@@ -70,7 +70,7 @@ export function allRefusals(adapter) {
|
|
|
70
70
|
return { ...REFUSALS, ...adapter?.refusals };
|
|
71
71
|
}
|
|
72
72
|
export const REPORT_HEADER = 'Constructs a compiled release does not run, with a rewrite for each:';
|
|
73
|
-
export const ISSUES_URL = 'https://github.com/
|
|
73
|
+
export const ISSUES_URL = 'https://github.com/nstudio/nativescript-compiler/issues';
|
|
74
74
|
const GAP_NOTE = `This is a compiler gap, not your code: please report it at ${ISSUES_URL}`;
|
|
75
75
|
/**
|
|
76
76
|
* A construct the build refuses: a declared limit of compiled releases or a gap of the compiler, of kind `id`, at `at`
|
|
@@ -285,6 +285,7 @@ const SWIFT_ONLY = [
|
|
|
285
285
|
'jsCancelAnimationFrame',
|
|
286
286
|
'jsCheckStack',
|
|
287
287
|
'jsChecked',
|
|
288
|
+
'jsClose',
|
|
288
289
|
'jsCompare',
|
|
289
290
|
'jsConstructor',
|
|
290
291
|
'jsConverted',
|
|
@@ -351,6 +352,7 @@ const SWIFT_ONLY = [
|
|
|
351
352
|
'jsOffScriptThread',
|
|
352
353
|
'jsPostDecrement',
|
|
353
354
|
'jsPostIncrement',
|
|
355
|
+
'jsPostMessage',
|
|
354
356
|
'jsPostUpdate',
|
|
355
357
|
'jsPreDecrement',
|
|
356
358
|
'jsPreIncrement',
|
package/dist/semantics/throws.js
CHANGED
|
@@ -51,6 +51,10 @@ const THROWING_BUILTINS = new Set([
|
|
|
51
51
|
'btoa',
|
|
52
52
|
'Crypto.getRandomValues',
|
|
53
53
|
'TextDecoder.decode',
|
|
54
|
+
'Worker.postMessage',
|
|
55
|
+
'DedicatedWorkerGlobalScope.postMessage',
|
|
56
|
+
'postMessage',
|
|
57
|
+
'close',
|
|
54
58
|
]);
|
|
55
59
|
/**
|
|
56
60
|
* Which functions throw, worked out across the call graph: a function is
|
|
@@ -566,6 +570,9 @@ export class Throws {
|
|
|
566
570
|
// A buffer or a view of an invalid length is a RangeError.
|
|
567
571
|
if (ts.isNewExpression(call) && ts.isIdentifier(call.expression) && BUFFER_TYPES.has(call.expression.text) && c.getSymbolAtLocation(call.expression)?.declarations?.every((d) => d.getSourceFile().isDeclarationFile))
|
|
568
572
|
return true;
|
|
573
|
+
// `new Worker(...)` and `new URL(...)` throw when the script is absent/already running or the URL is invalid.
|
|
574
|
+
if (ts.isNewExpression(call) && ts.isIdentifier(call.expression) && (call.expression.text === 'Worker' || call.expression.text === 'URL') && c.getSymbolAtLocation(call.expression)?.declarations?.every((d) => d.getSourceFile().isDeclarationFile))
|
|
575
|
+
return true;
|
|
569
576
|
// A weak reference to an untyped value refuses a primitive.
|
|
570
577
|
if (ts.isNewExpression(call) && ts.isIdentifier(call.expression) && call.expression.text === 'WeakRef' && args[0] && this.untyped(args[0]))
|
|
571
578
|
return true;
|
|
@@ -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)
|
|
@@ -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];
|
|
@@ -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}` };
|