@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
|
@@ -4,7 +4,7 @@ import ts from 'typescript';
|
|
|
4
4
|
import { isLibGlobal } from "../semantics/globals.js";
|
|
5
5
|
import { cast, earlyBacking, ident, isFunctionType, isNullable, kotlinString, optionalType, safeCast, RT } from "./syntax.js";
|
|
6
6
|
import { elementReceiverCell, keyName, isEnumObject, receiverCell, receiverSlot } from "../semantics/placement.js";
|
|
7
|
-
import { uncheckedMatch } from "../semantics/lang.js";
|
|
7
|
+
import { nullableTypeNode, uncheckedMatch } from "../semantics/lang.js";
|
|
8
8
|
import { isLibDeclaration, isWriteTarget } from "../semantics/ast.js";
|
|
9
9
|
import { isKit, isNamed, isUntyped, parseNativeType, spelledType } from "../semantics/types.js";
|
|
10
10
|
export const optionalChainsMethods = {
|
|
@@ -12,10 +12,29 @@ export const optionalChainsMethods = {
|
|
|
12
12
|
while (ts.isParenthesizedExpression(e))
|
|
13
13
|
e = e.expression;
|
|
14
14
|
// `a ?? b` of objects where `b` may be missing too: missing then.
|
|
15
|
-
if (ts.isBinaryExpression(e) && e.operatorToken.kind === ts.SyntaxKind.QuestionQuestionToken && !this.library && this.isObjectRef(e) && !isNullable(this.typeOf(e))
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
if (ts.isBinaryExpression(e) && e.operatorToken.kind === ts.SyntaxKind.QuestionQuestionToken && !this.library && this.isObjectRef(e) && !isNullable(this.typeOf(e))) {
|
|
16
|
+
if (this.states.missingObject(e)) {
|
|
17
|
+
const code = this.expr(e);
|
|
18
|
+
if (this.isAsserted(code))
|
|
19
|
+
return this.unasserted(code);
|
|
20
|
+
}
|
|
21
|
+
const rightMaybe = this.maybeUndefined(e.right);
|
|
22
|
+
if (rightMaybe)
|
|
23
|
+
return `(${this.coerce(e.left, optionalType(this.typeOf(e)))} ?: ${rightMaybe})`;
|
|
24
|
+
}
|
|
25
|
+
// A kit method whose Kotlin signature returns nullable (`ViewBase.getViewById`: `ViewBase?`) though core's typings say present.
|
|
26
|
+
if (ts.isCallExpression(e) && !this.library && !this.nullOk.has(e) && !isNullable(this.typeOf(e)) && this.isObjectRef(e) && !isFunctionType(this.typeOf(e)) && this.core?.kitNil?.(e)) {
|
|
27
|
+
this.nullOk.add(e);
|
|
28
|
+
try {
|
|
29
|
+
return this.expr(e);
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
this.nullOk.delete(e);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// `x as T | undefined` / `x as T | null` where non-strictNullChecks stripped the union: safe cast returning nullable.
|
|
36
|
+
if ((ts.isAsExpression(e) || ts.isTypeAssertionExpression(e)) && !this.library && !isNullable(this.typeOf(e)) && this.isObjectRef(e) && this.isObjectRef(e.expression) && nullableTypeNode(e.type)) {
|
|
37
|
+
return safeCast(this.expr(e.expression), this.typeOf(e));
|
|
19
38
|
}
|
|
20
39
|
const assertion = this.assertedUntyped(e);
|
|
21
40
|
if (assertion)
|
package/dist/kotlin/overrides.js
CHANGED
|
@@ -151,6 +151,8 @@ export const overridesMethods = {
|
|
|
151
151
|
}
|
|
152
152
|
if (isUntyped(spelledType(from)))
|
|
153
153
|
return this.fromAny(code, to);
|
|
154
|
+
if (!this.library && from === 'JSPromise<Unit>' && /^JSPromise<(.+)>$/.test(to) && to !== from)
|
|
155
|
+
return this.fromAny(code, to);
|
|
154
156
|
if (to === optionalType(from))
|
|
155
157
|
return code;
|
|
156
158
|
// An array of one element type where another is declared (`string[]` given as `any[]`): convert structural elements, else share the array.
|
|
@@ -367,8 +369,11 @@ export const overridesMethods = {
|
|
|
367
369
|
return true;
|
|
368
370
|
for (const h of decl.heritageClauses ?? []) {
|
|
369
371
|
for (const x of h.types) {
|
|
370
|
-
if (
|
|
371
|
-
|
|
372
|
+
if (h.token === ts.SyntaxKind.ImplementsKeyword && this.implementedName(x) === name) {
|
|
373
|
+
const iface = this.checker.getTypeAtLocation(x).getSymbol()?.declarations?.find(ts.isInterfaceDeclaration);
|
|
374
|
+
if (this.protocolWitnesses(decl, iface, name, [], new Set()))
|
|
375
|
+
return true;
|
|
376
|
+
}
|
|
372
377
|
if (h.token === ts.SyntaxKind.ExtendsKeyword && this.declaresInterface(this.checker.getTypeAtLocation(x), name))
|
|
373
378
|
return true;
|
|
374
379
|
}
|
package/dist/kotlin/placement.js
CHANGED
|
@@ -470,7 +470,8 @@ export const placementMethods = {
|
|
|
470
470
|
const call = `${this.library ? this.refName(e) : ident(e.text)}(${names.map((n, k) => this.convert(n, g.params[k], f.params[k])).join(', ')})`;
|
|
471
471
|
return `{ ${g.params.map((p, k) => `${names[k]}: ${p}`).join(', ')} -> ${call} }`;
|
|
472
472
|
}
|
|
473
|
-
|
|
473
|
+
const voidPromiseRet = !this.library && !!f && !!g && f.ret === 'JSPromise<Unit>' && /^JSPromise<.+>$/.test(g.ret) && g.ret !== f.ret;
|
|
474
|
+
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))))) {
|
|
474
475
|
const names = g.params.map((_, k) => this.marks.pureCode(`__a${k}`));
|
|
475
476
|
const fn = this.functionValue(e);
|
|
476
477
|
// A function field Kotlin declares nullable (one left unset): unwrapped where it is called.
|
|
@@ -479,8 +480,8 @@ export const placementMethods = {
|
|
|
479
480
|
.slice(0, f.params.length)
|
|
480
481
|
.map((n, k) => this.convert(n, g.params[k], f.params[k]))
|
|
481
482
|
.join(', ')})`;
|
|
482
|
-
// An untyped result is read as the slot's.
|
|
483
|
-
const call = isUntyped(spelledType(f.ret)) && g.ret !== 'Unit' && !isUntyped(spelledType(g.ret)) && !this.library ? this.fromAny(called, g.ret) : called;
|
|
483
|
+
// An untyped result (or Promise<void> into Promise<T | void>) is read as the slot's.
|
|
484
|
+
const call = voidPromiseRet || (isUntyped(spelledType(f.ret)) && g.ret !== 'Unit' && !isUntyped(spelledType(g.ret)) && !this.library) ? this.fromAny(called, g.ret) : called;
|
|
484
485
|
const adapter = `{ ${g.params.map((p, k) => `${names[k]}: ${p}`).join(', ')} -> ${call} }`;
|
|
485
486
|
// An optional member (`closeCallback?: …`) given to an optional parameter (`cb?: …`): undefined stays undefined,
|
|
486
487
|
// as the checker without strictNullChecks types neither as optional.
|
|
@@ -567,7 +568,7 @@ export const placementMethods = {
|
|
|
567
568
|
return elements(code);
|
|
568
569
|
}
|
|
569
570
|
}
|
|
570
|
-
if (!this.library && sb === 'JSPromise<Any?>' && /^JSPromise<(.+)>$/.test(tb))
|
|
571
|
+
if (!this.library && (sb === 'JSPromise<Any?>' || sb === 'JSPromise<Unit>') && /^JSPromise<(.+)>$/.test(tb) && tb !== sb)
|
|
571
572
|
return this.fromAny(this.functionValue(e), target);
|
|
572
573
|
if (head(sb) && head(sb) === head(tb) && sb !== tb)
|
|
573
574
|
return cast(this.functionValue(e), target);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { heldLoss } from "../semantics/losses.js";
|
|
3
3
|
import ts from 'typescript';
|
|
4
4
|
import { TYPED_ARRAYS } from "../semantics/globals.js";
|
|
5
|
-
import { ident, isThisParameter, kotlinString, optionalType, RT } from "./syntax.js";
|
|
5
|
+
import { functionTypeParts, ident, isThisParameter, kotlinString, optionalType, RT } from "./syntax.js";
|
|
6
6
|
import { undefinedLiteral } from "../semantics/lang.js";
|
|
7
7
|
import { arrayFromLengthInit } from "../semantics/ast.js";
|
|
8
8
|
import { assignsArrayIntoObject, shapeArrayGuardAccess } from "../semantics/shapes.js";
|
|
@@ -125,8 +125,14 @@ export const staticCallsMethods = {
|
|
|
125
125
|
const guard = !this.library ? shapeArrayGuardAccess(arg(0), (t) => this.isShapeType(t), (x) => this.typeOf(x)) : null;
|
|
126
126
|
return guard ? `JSArray.isArray(${this.expr(guard.prop.expression)}${guard.optional ? '?' : ''}.jsGet(${kotlinString(guard.prop.name.text)}))` : `JSArray.isArray(${this.restArgument(e, arg(0), 'Any?')})`;
|
|
127
127
|
}
|
|
128
|
-
if (method === 'from' && e.arguments.length === 1)
|
|
129
|
-
|
|
128
|
+
if (method === 'from' && e.arguments.length === 1) {
|
|
129
|
+
const seq = this.iterable(arg(0));
|
|
130
|
+
const el = T().replace(/^JSArray<(.*)>$/, '$1');
|
|
131
|
+
if (el !== T() && !isUntyped(spelledType(el)) && (this.isAny(arg(0)) || !!this.jsIteration(arg(0)) || /^(Pair|Triple)</.test(this.typeOf(arg(0)).replace(/\?$/, '')))) {
|
|
132
|
+
return `JSArray<${el}>(${seq}.map { ${this.fromAny('it', el)} })`;
|
|
133
|
+
}
|
|
134
|
+
return `JSArray(${seq}.toList())`;
|
|
135
|
+
}
|
|
130
136
|
if (method === 'from' && (e.arguments.length === 2 || e.arguments.length === 3) && ts.isObjectLiteralExpression(arg(0))) {
|
|
131
137
|
const lenExpr = arrayFromLengthInit(arg(0));
|
|
132
138
|
const fn = arg(1);
|
|
@@ -141,8 +147,14 @@ export const staticCallsMethods = {
|
|
|
141
147
|
return `JSArray.fromLength<${el}>(${this.toNumber(lenExpr)}, fun(${index}: Double): ${el} { ${value}${body.slice(1, -1)} })`;
|
|
142
148
|
});
|
|
143
149
|
}
|
|
144
|
-
if (method === 'from' && (e.arguments.length === 2 || e.arguments.length === 3))
|
|
145
|
-
return this.ignoringThisArg(e, arg(0), () =>
|
|
150
|
+
if (method === 'from' && (e.arguments.length === 2 || e.arguments.length === 3)) {
|
|
151
|
+
return this.ignoringThisArg(e, arg(0), () => {
|
|
152
|
+
const seq = this.iterable(arg(0));
|
|
153
|
+
const p0 = functionTypeParts(this.typeOf(arg(1)).replace(/^\((.*)\)\?$/, '$1'))?.params[0];
|
|
154
|
+
const arr = p0 && !isUntyped(spelledType(p0)) && (this.isAny(arg(0)) || !!this.jsIteration(arg(0))) ? `JSArray<${p0}>(${seq}.map { ${this.fromAny('it', p0)} })` : `JSArray(${seq}.toList())`;
|
|
155
|
+
return `${arr}.map(${this.fn(arg(1))})`;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
146
158
|
if (method === 'of')
|
|
147
159
|
return `${RT.jsArrayOf}<${T().replace(/^JSArray<(.*)>$/, '$1')}>(${a().join(', ')})`;
|
|
148
160
|
// `Array.apply(thisArg, list)`: `Array(...list)`, a length when the list is one number.
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { dirname as pathDirname, resolve as pathResolve } from 'node:path';
|
|
2
1
|
import { heldLoss } from "../semantics/losses.js";
|
|
3
2
|
import ts from 'typescript';
|
|
4
3
|
import { KOTLIN_LEDGER } from "../semantics/ledger.js";
|
|
@@ -87,9 +86,6 @@ export class Translator {
|
|
|
87
86
|
nativeDeclared = (d) => !!this.native?.isNativeDeclaration(d);
|
|
88
87
|
/** The innermost statement or expression being translated: where code made from a type alone is placed. */
|
|
89
88
|
translating;
|
|
90
|
-
/** Android: the worker scripts compiled with the app, by file, and the name the entry registers each under. */
|
|
91
|
-
workerScripts;
|
|
92
|
-
resolveAlias;
|
|
93
89
|
/** The generated kit: a module's name for `AppModules.runImport`, set where modules `await import(…)` reaches run when imported. */
|
|
94
90
|
moduleKey;
|
|
95
91
|
/** The program's whole-program answers, shared with any translator of the same checker and files. */
|
|
@@ -148,8 +144,6 @@ export class Translator {
|
|
|
148
144
|
this.framework = new Framework(c.hooks);
|
|
149
145
|
this.checker = checker;
|
|
150
146
|
this.lenient = c.lenient ?? false;
|
|
151
|
-
this.workerScripts = c.workerScripts ?? null;
|
|
152
|
-
this.resolveAlias = c.resolveAlias ?? null;
|
|
153
147
|
this.moduleThread = c.moduleThread ?? null;
|
|
154
148
|
this.moduleKey = c.moduleKey;
|
|
155
149
|
this.components = components;
|
|
@@ -194,6 +188,21 @@ export class Translator {
|
|
|
194
188
|
};
|
|
195
189
|
visit(f);
|
|
196
190
|
}
|
|
191
|
+
// Mark unviewable interface object classes upfront before any module translates, so cross-file `fromAny` never emits `.jsView(...)` for one.
|
|
192
|
+
for (const f of this.sourceFiles) {
|
|
193
|
+
if (f.isDeclarationFile)
|
|
194
|
+
continue;
|
|
195
|
+
for (const st of f.statements) {
|
|
196
|
+
if (!ts.isInterfaceDeclaration(st))
|
|
197
|
+
continue;
|
|
198
|
+
const name = this.topName(st, st.name.text);
|
|
199
|
+
const all = this.withInherited(st, st.members);
|
|
200
|
+
if (this.protocols.has(name) && all.some(ts.isMethodSignature))
|
|
201
|
+
this.unviewable.add(`${name}Object`);
|
|
202
|
+
else if (!this.protocols.has(name) && all.some((m) => !!m.name && ts.isComputedPropertyName(m.name)))
|
|
203
|
+
this.unviewable.add(name);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
197
206
|
}
|
|
198
207
|
/** A class whose methods and accessors are read by name: a substitution's, which untyped code reads as often as typed code does, or a `ValueStates.viewedClass`. */
|
|
199
208
|
membersByName(cls) {
|
|
@@ -716,39 +725,6 @@ export class Translator {
|
|
|
716
725
|
});
|
|
717
726
|
return `object : ${this.className(base)}() {\n${members.join('\n')}\n}`;
|
|
718
727
|
}
|
|
719
|
-
/** `new Worker('~/x')`, `new Worker('./x')`, or `new Worker(new URL('./x', import.meta.url))`: the worker script it names, when the app compiled it. */
|
|
720
|
-
workerScript(e) {
|
|
721
|
-
let spec = null;
|
|
722
|
-
if (ts.isStringLiteralLike(e)) {
|
|
723
|
-
spec = e.text;
|
|
724
|
-
}
|
|
725
|
-
else if (ts.isNewExpression(e) && ts.isIdentifier(e.expression) && e.expression.text === 'URL') {
|
|
726
|
-
const [s, base] = e.arguments ?? [];
|
|
727
|
-
if (s && ts.isStringLiteralLike(s) && base && base.getText() === 'import.meta.url')
|
|
728
|
-
spec = s.text;
|
|
729
|
-
}
|
|
730
|
-
if (!spec || !this.workerScripts?.size)
|
|
731
|
-
return null;
|
|
732
|
-
const file = e.getSourceFile().fileName;
|
|
733
|
-
const target = spec.startsWith('.') ? pathResolve(pathDirname(file), spec) : this.resolveAlias?.(spec, file);
|
|
734
|
-
if (target) {
|
|
735
|
-
const stem = target.replace(/\\/g, '/').replace(/\.(tsx?|m?js)$/, '');
|
|
736
|
-
for (const f of [stem + '.ts', stem + '.android.ts', stem + '.tsx', stem + '/index.ts', stem + '/index.android.ts']) {
|
|
737
|
-
const script = this.workerScripts.get(f);
|
|
738
|
-
if (script)
|
|
739
|
-
return script;
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
if (spec.startsWith('~/') || spec.startsWith('@/')) {
|
|
743
|
-
const rel = spec.slice(2).replace(/\\/g, '/').replace(/\.(tsx?|m?js)$/, '');
|
|
744
|
-
for (const [key, script] of this.workerScripts) {
|
|
745
|
-
const norm = key.replace(/\\/g, '/');
|
|
746
|
-
if ([`/${rel}.ts`, `/${rel}.android.ts`, `/${rel}.tsx`, `/${rel}/index.ts`, `/${rel}/index.android.ts`].some((s) => norm.endsWith(s)))
|
|
747
|
-
return script;
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
return null;
|
|
751
|
-
}
|
|
752
728
|
/**
|
|
753
729
|
* A function literal stored where untyped code calls it (`global.onmessage = (m: Msg) => …`): jsCall passes
|
|
754
730
|
* JavaScript values, so typed parameters are converted from them inside.
|
|
@@ -54,8 +54,9 @@ export const typeFactsMethods = {
|
|
|
54
54
|
// Lenient code: an optional member's type does not say it may be missing.
|
|
55
55
|
if (this.lenient && (ts.isPropertySignature(decl) || ts.isPropertyDeclaration(decl)) && decl.questionToken)
|
|
56
56
|
t = optionalType(t);
|
|
57
|
-
// A parameter with a default is nullable in its signature only; the body sees it filled in
|
|
58
|
-
|
|
57
|
+
// A parameter with a default is nullable in its signature only; the body sees it filled in,
|
|
58
|
+
// except when held as `JSNullish<T>` (where `.optional` is nullable until narrowed/unwrapped).
|
|
59
|
+
if (ts.isParameter(decl) && (decl.questionToken || this.states.nullishHeld(decl)))
|
|
59
60
|
t = optionalType(t);
|
|
60
61
|
if ((this.nullableDecls.has(sym) || this.states.looseDeclaration(decl) || this.states.lenientNullField(decl) || (ts.isPropertyAccessExpression(e) && (['String', 'Double', 'Boolean'].includes(t) || this.states.unsetMember(decl)) && this.states.shapeFieldOptional(sym))) && !isUntyped(spelledType(t)))
|
|
61
62
|
t = optionalType(t);
|
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";
|
|
@@ -182,10 +182,11 @@ export const typesMethods = {
|
|
|
182
182
|
const a = args()[k];
|
|
183
183
|
return a ? this.type(a, where) : 'Any?';
|
|
184
184
|
};
|
|
185
|
-
if (name && sym?.declarations?.
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
185
|
+
if (name && sym?.declarations?.length && sym.declarations.every((d) => d.getSourceFile().isDeclarationFile)) {
|
|
186
|
+
const web = webClassName(this.ledger, name);
|
|
187
|
+
if (web)
|
|
188
|
+
return web;
|
|
189
|
+
if (WEB_DICTIONARIES.includes(name) && (sym.declarations[0].getSourceFile().fileName === '/__shims__/globals.d.ts' || isLibDeclaration(sym.declarations[0])))
|
|
189
190
|
return 'Any?';
|
|
190
191
|
}
|
|
191
192
|
// Library mode: a Java class named as a library type (`java.util.Map`, `java.util.Iterator`) is the Java class.
|
|
@@ -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;
|