@nstudio/nativescript-compiler 9.2.0-alpha.16 → 9.2.0-alpha.17
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/kit/kit-index.js +9 -0
- package/dist/kotlin/access.js +7 -9
- package/dist/kotlin/arguments.js +2 -2
- package/dist/kotlin/class-declaration.js +20 -0
- package/dist/kotlin/components.js +2 -7
- package/dist/kotlin/core-api.js +2 -21
- package/dist/kotlin/declarations.js +86 -9
- package/dist/kotlin/functions.js +1 -4
- package/dist/kotlin/global-calls.js +1 -4
- package/dist/kotlin/literals.js +3 -6
- package/dist/kotlin/names.js +2 -0
- package/dist/kotlin/native/classfiles.js +2 -13
- package/dist/kotlin/operators.js +12 -6
- package/dist/kotlin/optional-chains.js +2 -9
- package/dist/kotlin/overrides.js +3 -15
- package/dist/kotlin/placement.js +1 -12
- package/dist/kotlin/statements.js +1 -13
- package/dist/kotlin/translator.js +2 -10
- package/dist/kotlin/type-tests.js +1 -1
- package/dist/kotlin/types.js +2 -19
- package/dist/program/core-facts.js +9 -0
- package/dist/semantics/facts.js +37 -1
- package/dist/semantics/lang.js +19 -0
- package/dist/semantics/lower.js +90 -0
- package/dist/semantics/lowering-methods.js +115 -3
- package/dist/semantics/marks.js +30 -0
- package/dist/semantics/refusals.js +12 -11
- package/dist/semantics/tdz.js +103 -8
- package/dist/swift/access.js +6 -8
- package/dist/swift/assignment.js +10 -2
- package/dist/swift/calls.js +7 -2
- package/dist/swift/classes.js +23 -9
- package/dist/swift/components.js +0 -4
- package/dist/swift/core-api.js +9 -29
- package/dist/swift/declarations.js +0 -5
- package/dist/swift/expression-statements.js +7 -0
- package/dist/swift/global-calls.js +0 -4
- package/dist/swift/lenient.js +3 -5
- package/dist/swift/method-values.js +1 -19
- package/dist/swift/modules.js +2 -0
- package/dist/swift/names.js +0 -9
- package/dist/swift/native/api.js +3 -1
- package/dist/swift/native/dispatch.js +2 -8
- package/dist/swift/operators.js +7 -6
- package/dist/swift/optional-chains.js +1 -8
- package/dist/swift/parameters.js +0 -4
- package/dist/swift/placement.js +1 -12
- package/dist/swift/results.js +0 -4
- package/dist/swift/statements.js +1 -13
- package/dist/swift/translator.js +0 -10
- package/dist/types/adapter-api.d.ts +3 -3
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Array.kt +53 -12
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/JSON.kt +30 -4
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Language.kt +33 -0
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Prototypes.kt +9 -1
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Values.kt +137 -28
- package/kit-apple/Sources/NativeScriptKit/Core/js-libs.easysax.easysax.swift +24 -6
- package/kit-apple/Sources/NativeScriptKit/Runtime/JSON.swift +151 -82
- package/kit-apple/Sources/NativeScriptKit/Runtime/Prototypes.swift +13 -1
- package/package.json +1 -1
package/dist/kit/kit-index.js
CHANGED
|
@@ -86,6 +86,15 @@ export class KitTypes {
|
|
|
86
86
|
isKitView(name) {
|
|
87
87
|
return kitExtends(this.index, name, 'View');
|
|
88
88
|
}
|
|
89
|
+
/** Whether the kit applies `name` by name on this view class (a property in its setProperty). */
|
|
90
|
+
isViewProperty(owner, name) {
|
|
91
|
+
if (owner === 'Style')
|
|
92
|
+
return [...this.index.values()].some((t) => kitExtends(this.index, t.name, 'View') && t.props.has(name));
|
|
93
|
+
for (let t = this.index.get(owner); t; t = t.base ? this.index.get(t.base.replace(/\(.*$/, '')) : undefined)
|
|
94
|
+
if (t.props.has(name))
|
|
95
|
+
return true;
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
89
98
|
/** A view, or a view's `style`: properties by name. */
|
|
90
99
|
isView(owner) {
|
|
91
100
|
return owner === 'Style' || kitExtends(this.index, owner, 'View');
|
package/dist/kotlin/access.js
CHANGED
|
@@ -10,7 +10,7 @@ import { CONSOLE } from "../semantics/apis/console.js";
|
|
|
10
10
|
import { libFunctionValueKind } from "../semantics/apis/statics.js";
|
|
11
11
|
import { ERRORS, isLibGlobal } from "../semantics/globals.js";
|
|
12
12
|
import { spell, ident, isCompared, isNullable, isThisParameter, kotlinString, numberLiteral, optionalType, testsMissing, scriptPrimitive, RT, assertedReader } from "./syntax.js";
|
|
13
|
-
import {
|
|
13
|
+
import { receiverCell, receiverSlot, isEnumObject, nullishField } from "../semantics/placement.js";
|
|
14
14
|
import { accessedDeclaration, augmentedPropertyRead, functionProperty, wellKnownMember, isSelf, literalMethod, uncheckedMatch } from "../semantics/lang.js";
|
|
15
15
|
import { convertedRead, onlyNull } from "../semantics/states/predicates.js";
|
|
16
16
|
import { isLibDeclaration, isWriteTarget, notIterable } from "../semantics/ast.js";
|
|
@@ -247,6 +247,8 @@ export const accessMethods = {
|
|
|
247
247
|
return ((base.endsWith('?') || held) && !proven && !e.questionDotToken && !inChain && !isSelf(target, this.subst)) || this.isAsserted(code) ? this.present(code, name, target, isWriteTarget(e)) : code;
|
|
248
248
|
};
|
|
249
249
|
if (name === 'length' && this.isString(target)) {
|
|
250
|
+
if (!e.questionDotToken && !inChain && ts.isIdentifier(target) && this.stringBuilders.has(this.resolve(target)))
|
|
251
|
+
return `${ident(target.text)}.length.toDouble()`;
|
|
250
252
|
return e.questionDotToken || inChain ? `${this.expr(target)}?.length?.toDouble()` : `${recv()}.length.toDouble()`;
|
|
251
253
|
}
|
|
252
254
|
if (name === 'length' && (base.startsWith('Pair<') || base.startsWith('Triple<')))
|
|
@@ -321,7 +323,7 @@ export const accessMethods = {
|
|
|
321
323
|
const describedClass = this.library && symbol?.valueDeclaration?.getSourceFile().isDeclarationFile && !isLibDeclaration(symbol.valueDeclaration) && !this.native?.isNativeDeclaration(symbol.valueDeclaration) ? this.compiledClasses().get(this.checker.getNonNullableType(this.checker.getTypeAtLocation(target)).getSymbol()?.name ?? '') : undefined;
|
|
322
324
|
// Library mode: a member TypeScript does not find on the type (lenient code reading what the type omits): read by name.
|
|
323
325
|
const unknown = this.library && !symbol && !e.name.text.startsWith('#') && this.isObjectRef(target);
|
|
324
|
-
if (((describedClass && !this.
|
|
326
|
+
if (((describedClass && !this.declaresCompiledMember(describedClass, name)) || unknown) && !(ts.isCallExpression(e.parent) && e.parent.expression === e && !e.parent.questionDotToken)) {
|
|
325
327
|
const t = this.typeOf(e);
|
|
326
328
|
const code = `${e.questionDotToken || inChain ? RT.jsGetIfPresent : RT.jsGet}(${this.expr(target)}, ${kotlinString(name)})`;
|
|
327
329
|
// Called (`x.callback?.(…)`): the function as script holds it, which the call reads.
|
|
@@ -350,7 +352,7 @@ export const accessMethods = {
|
|
|
350
352
|
const plain = `${receiver}${dot}${ident(name)}`;
|
|
351
353
|
const read = dot === '.' ? this.marks.marked(plain, { op: 'member', of: this.marks.valueOf(receiver), name }) : plain;
|
|
352
354
|
// A non-strict app's optional member is held optional though its type says present: a value read reads its undefined.
|
|
353
|
-
if ((this.
|
|
355
|
+
if ((this.isLenientOptionalMember(e) || (!e.questionDotToken && !(e.flags & ts.NodeFlags.OptionalChain) && !!symbol && this.states.shapeFieldOptional(symbol))) && !isWriteTarget(e) && !this.nullOk.has(e) && ['String', 'Double', 'Boolean'].includes(this.typeOf(e)))
|
|
354
356
|
return this.undefinedAs(read, this.typeOf(e));
|
|
355
357
|
return this.narrowed(e, read);
|
|
356
358
|
},
|
|
@@ -425,7 +427,7 @@ export const accessMethods = {
|
|
|
425
427
|
if (ts.isPropertyAccessExpression(x) && this.library && this.resolve(x.name)?.declarations?.some((d) => ts.isPropertySignature(d) && !isLibDeclaration(d)))
|
|
426
428
|
return null;
|
|
427
429
|
if (ts.isPropertyAccessExpression(x)) {
|
|
428
|
-
if (!(this.
|
|
430
|
+
if (!(this.isLenientOptionalMember(x) || (!this.typeOf(x).endsWith('?') && !!this.declaredTypeOf(x)?.endsWith('?'))))
|
|
429
431
|
return null;
|
|
430
432
|
return this.isExpando(x) ? this.fromAny(`${RT.jsGet}(${this.expr(x.expression)}, ${kotlinString(x.name.text)})`, optionalType(this.typeOf(x))) : `${this.expr(x.expression)}.${ident(x.name.text)}`;
|
|
431
433
|
}
|
|
@@ -464,7 +466,7 @@ export const accessMethods = {
|
|
|
464
466
|
return ['String', 'Double', 'Boolean'].includes(t) ? this.fromAny(`${RT.jsGet}(${this.expr(x.expression)}, ${kotlinString(x.name.text)})`, optionalType(t)) : null;
|
|
465
467
|
},
|
|
466
468
|
/** A non-strict app's read of an object type's optional member (`o.a`, `a?: string`), which Kotlin holds optional. */
|
|
467
|
-
|
|
469
|
+
isLenientOptionalMember(x) {
|
|
468
470
|
if (!this.lenientApp || this.library || x.questionDotToken || x.flags & ts.NodeFlags.OptionalChain || this.typeOf(x).endsWith('?'))
|
|
469
471
|
return false;
|
|
470
472
|
const d = this.resolve(x.name)?.valueDeclaration;
|
|
@@ -630,10 +632,6 @@ export const accessMethods = {
|
|
|
630
632
|
const holder = ts.findAncestor(e.parent, (p) => !ts.isParenthesizedExpression(p));
|
|
631
633
|
return holder && ts.isVariableDeclaration(holder) ? this.widerAsserted(holder) : null;
|
|
632
634
|
},
|
|
633
|
-
/** `x` read by an equality or `typeof` (`ObserverSlot`). */
|
|
634
|
-
observe(x, read = 'untyped') {
|
|
635
|
-
return place(this.placement, x, observerSlot(this.placement, read));
|
|
636
|
-
},
|
|
637
635
|
/**
|
|
638
636
|
* A read `observedAsIs` (an identity operand, `instanceof`'s left): the nullable it may be, never asserted present.
|
|
639
637
|
* Library mode reads an untyped value as it is held: `maybeUndefined` would cast it to the declared type.
|
package/dist/kotlin/arguments.js
CHANGED
|
@@ -91,7 +91,7 @@ export const argumentsMethods = {
|
|
|
91
91
|
return (isUntyped(spelledType(pt)) && this.untypedArrow(a)) || null;
|
|
92
92
|
},
|
|
93
93
|
/** A function held in a variable, parameter or field (an overloaded method's implementation bound): a Kotlin function type, which has no defaults. */
|
|
94
|
-
|
|
94
|
+
isHeldFunctionValue(callee) {
|
|
95
95
|
const name = ts.isPropertyAccessExpression(callee) ? callee.name : ts.isIdentifier(callee) ? callee : null;
|
|
96
96
|
const d = name && this.checker.getSymbolAtLocation(name)?.valueDeclaration;
|
|
97
97
|
return !!d && !d.getSourceFile().isDeclarationFile && (ts.isVariableDeclaration(d) || ts.isParameter(d) || ts.isPropertyDeclaration(d));
|
|
@@ -157,7 +157,7 @@ export const argumentsMethods = {
|
|
|
157
157
|
out.push(`${this.restType(params[restAt])}()`);
|
|
158
158
|
const decl = sig?.getDeclaration();
|
|
159
159
|
// A function value takes every parameter; a plugin's call (its code unchecked) may leave out one the callee requires.
|
|
160
|
-
const missing = count !== undefined || restAt >= 0 || !decl || ts.isJSDocSignature(decl) ? undefined : ts.isFunctionTypeNode(decl) || ts.isCallSignatureDeclaration(decl) || ts.isArrowFunction(decl) || ts.isFunctionExpression(decl) || (ts.isCallExpression(e) && this.
|
|
160
|
+
const missing = count !== undefined || restAt >= 0 || !decl || ts.isJSDocSignature(decl) ? undefined : ts.isFunctionTypeNode(decl) || ts.isCallSignatureDeclaration(decl) || ts.isArrowFunction(decl) || ts.isFunctionExpression(decl) || (ts.isCallExpression(e) && this.isHeldFunctionValue(e.expression)) ? 'empty' : !this.library && this.inPluginFile(e) ? 'undefined' : undefined;
|
|
161
161
|
for (let k = covered; missing && k < params.length; k++) {
|
|
162
162
|
const s = this.missingSlot(e, params[k], k, missing);
|
|
163
163
|
if (!s)
|
|
@@ -68,6 +68,7 @@ export const classDeclMethods = {
|
|
|
68
68
|
this.cssTypeMemberCode(k);
|
|
69
69
|
this.classDecoratorsCode(k);
|
|
70
70
|
this.staticsByNameCode(k);
|
|
71
|
+
this.prototypeMethodsCode(k);
|
|
71
72
|
this.computedMethodsCode(k);
|
|
72
73
|
this.methodMembersCode(k);
|
|
73
74
|
this.ownPropertiesCode(k);
|
|
@@ -239,6 +240,25 @@ export const classDeclMethods = {
|
|
|
239
240
|
this.staticInits.push(` JSPrototypes.declareStatics(${owner}::class.java, listOf(${entries.join(', ')}))`);
|
|
240
241
|
}
|
|
241
242
|
},
|
|
243
|
+
prototypeMethodsCode(k) {
|
|
244
|
+
const { cls, name } = k;
|
|
245
|
+
if (this.library || !this.staticInits || !ts.isClassDeclaration(cls) || !this.facts.prototypeClasses().has(cls) || cls.typeParameters?.length)
|
|
246
|
+
return;
|
|
247
|
+
const owner = name.replace(/<.*$/, '');
|
|
248
|
+
const seen = new Set();
|
|
249
|
+
for (const m of cls.members) {
|
|
250
|
+
if (!ts.isMethodDeclaration(m) || !m.body || isStatic(m) || ts.isPrivateIdentifier(m.name) || ts.isComputedPropertyName(m.name) || m.typeParameters?.length || m.asteriskToken || m.parameters.some((p) => p.dotDotDotToken || (ts.isIdentifier(p.name) && p.name.text === 'this')) || this.readsArguments(m))
|
|
251
|
+
continue;
|
|
252
|
+
const key = m.name.getText().replace(/^['"]|['"]$/g, '');
|
|
253
|
+
if (seen.has(key))
|
|
254
|
+
continue;
|
|
255
|
+
seen.add(key);
|
|
256
|
+
const args = m.parameters.map((p, idx) => this.fromAnyCode(this.marks.pureCode(`__a.getOrNull(${idx})`), this.paramType(p), true));
|
|
257
|
+
const call = `__o.${this.methodIdent(key)}(${args.join(', ')})`;
|
|
258
|
+
const body = this.returnTypeOf(m) === 'Unit' ? `${call}; null` : call;
|
|
259
|
+
this.staticInits.push(` JSPrototypes.of(${owner}::class.java).defineProperty(${kotlinString(key)}, JSPropertyDescriptor(value = JSMethod(${m.parameters.length}) { __this, __a -> val __o = ${RT.jsBox}(__this) as? ${owner} ?: throw JSException(JSTypeError("Illegal invocation")); ${body} }, hasValue = true, enumerable = false, writable = true, configurable = true))`);
|
|
260
|
+
}
|
|
261
|
+
},
|
|
242
262
|
ownPropertiesCode(k) {
|
|
243
263
|
if (k.isView && !this.generatedKit) {
|
|
244
264
|
const own = k.fields.filter(isPropertyField).map((f) => f.name);
|
|
@@ -229,10 +229,7 @@ export const componentMethods = {
|
|
|
229
229
|
statics.push(...(this.framework.hooks.componentStatics?.(this, cls) ?? []));
|
|
230
230
|
return { params, lines, statics };
|
|
231
231
|
},
|
|
232
|
-
|
|
233
|
-
rootView(cls, type, make) {
|
|
234
|
-
return this.framework.hooks.wrapRootView ? this.framework.hooks.wrapRootView(this, cls, type, make) : make;
|
|
235
|
-
},
|
|
232
|
+
/* rootView is installed from semantics/lowering-methods.ts */
|
|
236
233
|
/**
|
|
237
234
|
* `Object.defineProperty` on an app class's instance that makes one of its declared fields an accessor, read-only,
|
|
238
235
|
* hidden or fixed: the class's Kotlin field keeps none of these.
|
|
@@ -260,9 +257,7 @@ export const componentMethods = {
|
|
|
260
257
|
const iface = m.parent;
|
|
261
258
|
return ts.isInterfaceDeclaration(iface) && !!iface.typeParameters?.length && !iface.getSourceFile().isDeclarationFile && this.protocols.has(this.topName(iface, iface.name.text));
|
|
262
259
|
},
|
|
263
|
-
calleeName
|
|
264
|
-
return ts.isCallExpression(e) ? e.expression.getText() : '';
|
|
265
|
-
},
|
|
260
|
+
/* calleeName is installed from semantics/lowering-methods.ts */
|
|
266
261
|
/** The names an app class's members override: its app base classes' and its interfaces'. */
|
|
267
262
|
overridden(cls, implemented) {
|
|
268
263
|
const out = new Set();
|
package/dist/kotlin/core-api.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import { heldLoss } from "../semantics/losses.js";
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
-
import { addedDeclarations, augmentedProperty, isCoreDeclaration, ownPropertyOnly } from "../program/core-facts.js";
|
|
4
|
+
import { addedDeclarations, augmentedProperty, inheritedCoreOwner, isCoreDeclaration, ownPropertyOnly } from "../program/core-facts.js";
|
|
5
5
|
import { KitTypes, coreClass, kitExtends, kitMember } from "../kit/kit-index.js";
|
|
6
6
|
import { KIT_NAMES_ANDROID } from "./library.js";
|
|
7
7
|
import { functionTypeParts, kotlinString, numberLiteral, safeCast, splitTopLevel, RT } from "./syntax.js";
|
|
@@ -248,7 +248,7 @@ export class CoreKotlin extends KitTypes {
|
|
|
248
248
|
* (`Utils.android` of utils/index is utils/native-helper's): that module's object.
|
|
249
249
|
*/
|
|
250
250
|
ownerOf(target, name) {
|
|
251
|
-
let owner = isMixinOwnMember(name, this.t.checker, (s) => this.t.mixinOf(s)) ? null : (this.owner(target) ??
|
|
251
|
+
let owner = isMixinOwnMember(name, this.t.checker, (s) => this.t.mixinOf(s)) ? null : (this.owner(target) ?? inheritedCoreOwner(target, name, this.t.checker, (c) => this.t.kitRootOf(c)));
|
|
252
252
|
if (owner && !kitMember(this.index, owner.name, name.text))
|
|
253
253
|
owner = this.renamedOwner(owner, name.text) ?? owner;
|
|
254
254
|
if (!owner || !owner.isStatic || !owner.name.startsWith('Core_') || kitMember(this.index, owner.name, name.text))
|
|
@@ -267,16 +267,6 @@ export class CoreKotlin extends KitTypes {
|
|
|
267
267
|
const module = decl && isCoreDeclaration(decl) ? this.moduleObject(decl) : null;
|
|
268
268
|
return module && kitMember(this.index, module, name.text) ? { name: module, isStatic: true } : owner;
|
|
269
269
|
}
|
|
270
|
-
/** A core member read through a class of the app or a plugin that extends a core class (`this.isPassThroughParentEnabled` in a GridLayout subclass). */
|
|
271
|
-
inheritedOwner(target, name) {
|
|
272
|
-
const c = this.t.checker;
|
|
273
|
-
const decl = c.getSymbolAtLocation(name)?.valueDeclaration;
|
|
274
|
-
if (!decl || !isCoreDeclaration(decl))
|
|
275
|
-
return null;
|
|
276
|
-
const cls = c.getNonNullableType(c.getTypeAtLocation(target)).getSymbol()?.valueDeclaration;
|
|
277
|
-
const root = cls && ts.isClassLike(cls) && !cls.getSourceFile().isDeclarationFile ? this.t.kitRootOf(cls) : null;
|
|
278
|
-
return root ? { name: root, isStatic: false } : null;
|
|
279
|
-
}
|
|
280
270
|
/**
|
|
281
271
|
* `on`/`off`/`once` with a named function: a function value made once per
|
|
282
272
|
* evaluation has no identity across them, so the kit matches a listener by
|
|
@@ -312,15 +302,6 @@ export class CoreKotlin extends KitTypes {
|
|
|
312
302
|
throw this.t.error(e, `${owner}.${name} (kit-android has no such member)`);
|
|
313
303
|
return m;
|
|
314
304
|
}
|
|
315
|
-
isViewProperty(owner, name) {
|
|
316
|
-
// A style property applies to any view; the kit's classes each apply their own.
|
|
317
|
-
if (owner === 'Style')
|
|
318
|
-
return [...this.index.values()].some((t) => kitExtends(this.index, t.name, 'View') && t.props.has(name));
|
|
319
|
-
for (let t = this.index.get(owner); t; t = t.base ? this.index.get(t.base.replace(/\(.*$/, '')) : undefined)
|
|
320
|
-
if (t.props.has(name))
|
|
321
|
-
return true;
|
|
322
|
-
return false;
|
|
323
|
-
}
|
|
324
305
|
/** `object.name` of an `augmentedProperty` on a core-typed object, outside a chain: the read of its own property (`Any?`), or null. */
|
|
325
306
|
augmentedRead(e) {
|
|
326
307
|
if (ts.isOptionalChain(e) || this.constant(e) !== null)
|
|
@@ -10,6 +10,86 @@ import { programBase } from "../semantics/classes.js";
|
|
|
10
10
|
import { definedField } from "../semantics/shapes.js";
|
|
11
11
|
import { isKit, isNamed, isUntyped, spelledType } from "../semantics/types.js";
|
|
12
12
|
export const declarationsMethods = {
|
|
13
|
+
/**
|
|
14
|
+
* Whether a function-local `let s = ...` of type `String` is only ever mutated via statement-level `s += ...`
|
|
15
|
+
* (at least once inside a loop) and never captured by a closure: safe to back with a `StringBuilder` to avoid O(N^2) copies.
|
|
16
|
+
*/
|
|
17
|
+
isStringBuilderLocal(d) {
|
|
18
|
+
if (!ts.isIdentifier(d.name) || !d.initializer)
|
|
19
|
+
return false;
|
|
20
|
+
const ownerFn = ts.findAncestor(d, (n) => ts.isFunctionLike(n) && 'body' in n && !!n.body);
|
|
21
|
+
if (!ownerFn || !ownerFn.body || ts.isSourceFile(d.parent.parent.parent))
|
|
22
|
+
return false;
|
|
23
|
+
const sym = this.checker.getSymbolAtLocation(d.name);
|
|
24
|
+
if (!sym || (sym.declarations?.length ?? 0) !== 1)
|
|
25
|
+
return false;
|
|
26
|
+
let appendedInLoop = false;
|
|
27
|
+
let disqualified = false;
|
|
28
|
+
const visit = (n, inNestedFn, inLoop) => {
|
|
29
|
+
if (disqualified)
|
|
30
|
+
return;
|
|
31
|
+
if (n !== ownerFn && (ts.isFunctionLike(n) || ts.isClassLike(n))) {
|
|
32
|
+
ts.forEachChild(n, (c) => visit(c, true, inLoop));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (ts.isIdentifier(n) && n !== d.name) {
|
|
36
|
+
const p = n.parent;
|
|
37
|
+
if ((ts.isPropertyAccessExpression(p) && p.name === n) || ((ts.isPropertyAssignment(p) || ts.isMethodDeclaration(p) || ts.isPropertyDeclaration(p)) && p.name === n))
|
|
38
|
+
return;
|
|
39
|
+
if (this.checker.getSymbolAtLocation(n) === sym) {
|
|
40
|
+
if (inNestedFn || (ts.isShorthandPropertyAssignment(p) && p.name === n)) {
|
|
41
|
+
disqualified = true;
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (ts.isBinaryExpression(p) && p.left === n && p.operatorToken.kind >= ts.SyntaxKind.FirstAssignment && p.operatorToken.kind <= ts.SyntaxKind.LastAssignment) {
|
|
45
|
+
if (p.operatorToken.kind !== ts.SyntaxKind.PlusEqualsToken || !ts.isExpressionStatement(p.parent)) {
|
|
46
|
+
disqualified = true;
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
// Reject `s += ...s...` self-append edge case.
|
|
50
|
+
let readsSelf = false;
|
|
51
|
+
const checkRhs = (x) => {
|
|
52
|
+
if (ts.isIdentifier(x) && this.checker.getSymbolAtLocation(x) === sym)
|
|
53
|
+
readsSelf = true;
|
|
54
|
+
if (!readsSelf)
|
|
55
|
+
ts.forEachChild(x, checkRhs);
|
|
56
|
+
};
|
|
57
|
+
checkRhs(p.right);
|
|
58
|
+
if (readsSelf) {
|
|
59
|
+
disqualified = true;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (inLoop)
|
|
63
|
+
appendedInLoop = true;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (ts.isPrefixUnaryExpression(p) || ts.isPostfixUnaryExpression(p)) {
|
|
67
|
+
if (p.operator === ts.SyntaxKind.PlusPlusToken || p.operator === ts.SyntaxKind.MinusMinusToken) {
|
|
68
|
+
disqualified = true;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if ((ts.isForInStatement(p) || ts.isForOfStatement(p)) && p.initializer === n) {
|
|
73
|
+
disqualified = true;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (ts.isArrayLiteralExpression(p) || ts.isObjectLiteralExpression(p) || ts.isSpreadAssignment(p) || ts.isSpreadElement(p)) {
|
|
77
|
+
let up = p;
|
|
78
|
+
while (ts.isArrayLiteralExpression(up) || ts.isObjectLiteralExpression(up) || ts.isPropertyAssignment(up) || ts.isSpreadAssignment(up) || ts.isSpreadElement(up))
|
|
79
|
+
up = up.parent;
|
|
80
|
+
if (ts.isBinaryExpression(up) && up.operatorToken.kind === ts.SyntaxKind.EqualsToken && up.left.pos <= n.pos && n.end <= up.left.end) {
|
|
81
|
+
disqualified = true;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const nextLoop = inLoop || ts.isIterationStatement(n, false);
|
|
88
|
+
ts.forEachChild(n, (c) => visit(c, inNestedFn, nextLoop));
|
|
89
|
+
};
|
|
90
|
+
visit(ownerFn.body, false, false);
|
|
91
|
+
return appendedInLoop && !disqualified;
|
|
92
|
+
},
|
|
13
93
|
declarationList(list, lowered) {
|
|
14
94
|
const constant = !!(list.flags & ts.NodeFlags.Const);
|
|
15
95
|
// A `let` or `var` set once, where it is declared, is a constant too.
|
|
@@ -21,11 +101,6 @@ export const declarationsMethods = {
|
|
|
21
101
|
!assignsTo(ts.findAncestor(d, (n) => ts.isFunctionLike(n) || ts.isSourceFile(n)), this.checker.getSymbolAtLocation(d.name), this.checker);
|
|
22
102
|
return list.declarations.map((d) => this.declaration(d, constant || once(d), lowered)).join('\n');
|
|
23
103
|
},
|
|
24
|
-
/** An `optionalVariable`'s initializer stored as the optional `type`: a read converting undefined gives that undefined. */
|
|
25
|
-
heldStore(d, type) {
|
|
26
|
-
const code = this.stored(d.initializer, d, type);
|
|
27
|
-
return this.undefinedConverted(code) ?? code;
|
|
28
|
-
},
|
|
29
104
|
declaration(d, constant, lowered) {
|
|
30
105
|
const i = this.indent;
|
|
31
106
|
const extension = this.native?.extensionClass(d);
|
|
@@ -175,6 +250,12 @@ export const declarationsMethods = {
|
|
|
175
250
|
const read = (this.isAny(d.initializer) || this.untypedElement(d.initializer)) && !isUntyped(spelledType(t)) ? (this.checkedPlacement(d.initializer, optionalType(t), maybe, this.storeSlot(d.initializer, optionalType(t), d)) ?? this.fromAny(maybe, optionalType(t))) : this.nullableArrayAs(maybe, this.typeOf(d.initializer), t);
|
|
176
251
|
return `${i}${constant ? 'val' : 'var'} ${name}: ${optionalType(t)} = ${read}`;
|
|
177
252
|
}
|
|
253
|
+
if (!this.library && !constant && !lowered && !this.asyncCtx && t === 'String' && this.isStringBuilderLocal(d)) {
|
|
254
|
+
const sym = this.checker.getSymbolAtLocation(d.name);
|
|
255
|
+
this.stringBuilders.add(sym);
|
|
256
|
+
const init = this.stored(d.initializer, d, 'String');
|
|
257
|
+
return `${i}val ${name} = StringBuilder(${init === '""' ? '' : init})`;
|
|
258
|
+
}
|
|
178
259
|
// An untyped value asserted a Java class its uses need only a superclass of: held as that class, unchecked as script's assertion is.
|
|
179
260
|
const wider = !this.library && ts.isIdentifier(d.name) ? this.widerAsserted(d) : null;
|
|
180
261
|
if (wider) {
|
|
@@ -423,10 +504,6 @@ export const declarationsMethods = {
|
|
|
423
504
|
return this.undefinedAs(slot.raw, t);
|
|
424
505
|
return `(${slot.raw} ?: ${t === 'Double' ? '0.0' : t === 'String' ? '"null"' : 'false'})`;
|
|
425
506
|
},
|
|
426
|
-
/** The slot of the await `e` is, where its continuation holds the value nullable. */
|
|
427
|
-
awaited(e) {
|
|
428
|
-
return this.awaitSlots.get(ts.skipOuterExpressions(e, ts.OuterExpressionKinds.Parentheses));
|
|
429
|
-
},
|
|
430
507
|
noteNullVar(d) {
|
|
431
508
|
const init = d.initializer && ts.skipOuterExpressions(d.initializer, ts.OuterExpressionKinds.Parentheses);
|
|
432
509
|
const sym = ts.isIdentifier(d.name) ? this.resolve(d.name) : undefined;
|
package/dist/kotlin/functions.js
CHANGED
|
@@ -4,7 +4,7 @@ import { resultSlot, returnCell } from "../semantics/placement.js";
|
|
|
4
4
|
import { assignsTo, branch, functionTypeParts, ident, isFunctionType, isNullable, isThisParameter, jsObjectCode, kotlinString, mentions, nullishType, numberLiteral, optionalElementsType, optionalType, refersTo, returnsNull, splitTopLevel, RT } from "./syntax.js";
|
|
5
5
|
import { boundNames, thisNodes, takesOwnThis } from "../semantics/ast.js";
|
|
6
6
|
import { isAsync } from "../semantics/throws.js";
|
|
7
|
-
import {
|
|
7
|
+
import { methodValues, thisArgBound } from "../semantics/lang.js";
|
|
8
8
|
import { isUntyped, spelledType } from "../semantics/types.js";
|
|
9
9
|
import { literalCallback } from "../semantics/conversion.js";
|
|
10
10
|
export const functionsMethods = {
|
|
@@ -91,9 +91,6 @@ export const functionsMethods = {
|
|
|
91
91
|
* A parameter Kotlin gives its constant default itself. Not where another method of its override family declares the
|
|
92
92
|
* parameter otherwise: Kotlin overrides take the root's default, where JavaScript applies the default of the method that runs.
|
|
93
93
|
*/
|
|
94
|
-
constantDefault(p) {
|
|
95
|
-
return !!p.initializer && isConstant(p.initializer) && !this.familyDefaultsDiffer(p) && !this.states.defaultTakesUndefined(p);
|
|
96
|
-
},
|
|
97
94
|
/** Statements a function body starts with: computed defaults, destructured parameters. */
|
|
98
95
|
paramPrelude(fn) {
|
|
99
96
|
const i = this.indent;
|
|
@@ -259,10 +259,7 @@ export const globalCallsMethods = {
|
|
|
259
259
|
const decl = this.resolve(e.expression)?.declarations?.[0];
|
|
260
260
|
return !decl || decl.getSourceFile().isDeclarationFile;
|
|
261
261
|
},
|
|
262
|
-
symbolName
|
|
263
|
-
const t = this.checker.getTypeAtLocation(e);
|
|
264
|
-
return (t.aliasSymbol ?? t.getSymbol())?.getName() ?? '';
|
|
265
|
-
},
|
|
262
|
+
/* symbolName is installed from semantics/lowering-methods.ts */
|
|
266
263
|
/** A navigation (`$navigateTo(Page, { props })`) to a component, with the props its options give. */
|
|
267
264
|
navigate(e, component, options) {
|
|
268
265
|
const info = this.components.get(component);
|
package/dist/kotlin/literals.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Literals as Kotlin: arrays, objects and class expressions, structural copies and dynamic objects.
|
|
2
2
|
import ts from 'typescript';
|
|
3
3
|
import { cast, destructuringSource, ident, isNullable, jsObjectCode, kotlinString, optionalType, splitTopLevel, spell, RT } from "./syntax.js";
|
|
4
|
-
import { assertedOperand, evolvingElementContext, intersectionAliasMembers, isTypeParameterType, literalKey, openSpreadType, spreadOperand, unquoted, wellKnownMember } from "../semantics/lang.js";
|
|
4
|
+
import { assertedOperand, evolvingElementContext, intersectionAliasMembers, isTypeParameterType, literalKey, openSpreadType, spreadOperand, unquoted, untypedVariableInitializer, wellKnownMember } from "../semantics/lang.js";
|
|
5
5
|
import { holdsNil, literalNotes, signatureField, shapePlanOfLiteral, spelledOptional, spreadElementNeedsMap, resultShapeNamed } from "../semantics/shapes.js";
|
|
6
6
|
import { structural } from "../semantics/conversion.js";
|
|
7
7
|
import { heldOf, isKit, isUntyped, parseNativeType, spelledType } from "../semantics/types.js";
|
|
@@ -628,10 +628,7 @@ export const literalsMethods = {
|
|
|
628
628
|
},
|
|
629
629
|
/** A variable declared without a type whose value is a read of a signal holding null (`const card = this.morning()`). */
|
|
630
630
|
givenNullSignalValue(n) {
|
|
631
|
-
const
|
|
632
|
-
|
|
633
|
-
return false;
|
|
634
|
-
const read = ts.skipOuterExpressions(d.initializer, ts.OuterExpressionKinds.Parentheses);
|
|
635
|
-
return ts.isCallExpression(read) && !read.arguments.length && /^Signal<.*\?>$/.test(this.typeOf(read.expression));
|
|
631
|
+
const read = untypedVariableInitializer(n, (id) => this.resolve(id));
|
|
632
|
+
return !!read && ts.isCallExpression(read) && !read.arguments.length && /^Signal<.*\?>$/.test(this.typeOf(read.expression));
|
|
636
633
|
},
|
|
637
634
|
};
|
package/dist/kotlin/names.js
CHANGED
|
@@ -236,6 +236,8 @@ export const namesMethods = {
|
|
|
236
236
|
return `${kit ?? this.declaredName(e).split('.').map(ident).join('.')}::class.java`;
|
|
237
237
|
}
|
|
238
238
|
const ref = this.globalAlias(e) ?? this.refName(e);
|
|
239
|
+
if (sym && this.stringBuilders.has(sym))
|
|
240
|
+
return `${ref}.toString()`;
|
|
239
241
|
// Library mode: a class named where a member of that name is in scope (ApplicationCommon's `AndroidApplication` getter) by its package.
|
|
240
242
|
if (this.library && this.appModule && sym && sym.flags & (ts.SymbolFlags.Class | ts.SymbolFlags.Enum) && !ref.includes('.') && this.memberInScope(e, name))
|
|
241
243
|
return `${this.appModule}.${ref}`;
|
|
@@ -2,6 +2,7 @@ import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { inflateRawSync } from 'node:zlib';
|
|
5
|
+
import { newerVersion } from "../../semantics/lang.js";
|
|
5
6
|
/**
|
|
6
7
|
* Java signatures for Android APIs, read from the class files themselves: the
|
|
7
8
|
* SDK's android.jar, NativeScript's widgets AAR and, for androidx types, the
|
|
@@ -252,19 +253,7 @@ export function parseClass(b) {
|
|
|
252
253
|
return result;
|
|
253
254
|
}
|
|
254
255
|
// ---- The classpath -----------------------------------------------------------------------------
|
|
255
|
-
|
|
256
|
-
return v.split(/[.-]/).map((x) => (/^\d+$/.test(x) ? Number(x) : -1));
|
|
257
|
-
}
|
|
258
|
-
export function newer(a, b) {
|
|
259
|
-
const stable = (v) => !/-/.test(v);
|
|
260
|
-
if (stable(a) !== stable(b))
|
|
261
|
-
return stable(a);
|
|
262
|
-
const ka = versionKey(a), kb = versionKey(b);
|
|
263
|
-
for (let i = 0; i < Math.max(ka.length, kb.length); i++)
|
|
264
|
-
if ((ka[i] ?? 0) !== (kb[i] ?? 0))
|
|
265
|
-
return (ka[i] ?? 0) > (kb[i] ?? 0);
|
|
266
|
-
return false;
|
|
267
|
-
}
|
|
256
|
+
export const newer = (a, b) => newerVersion(a, b, true);
|
|
268
257
|
/** The SDK platform's android.jar: the compile SDK's when installed, else the newest. */
|
|
269
258
|
export function androidJar(compileSdk) {
|
|
270
259
|
const sdk = process.env.ANDROID_HOME ?? process.env.ANDROID_SDK_ROOT ?? join(homedir(), 'Library', 'Android', 'sdk');
|
package/dist/kotlin/operators.js
CHANGED
|
@@ -12,6 +12,7 @@ import { isLibDeclaration } from "../semantics/ast.js";
|
|
|
12
12
|
import { nullAs } from "./expressions.js";
|
|
13
13
|
import { bigIntArithmetic, bigIntCompare, bigIntPlan } from "../semantics/apis/bigint.js";
|
|
14
14
|
import { BIT_ASSIGNMENTS, addCall, bitOperation, concatOperand, numericThrowing, untypedBinary, untypedConversion } from "../semantics/apis/operators.js";
|
|
15
|
+
import { flattenStringConcat, planRelational } from "../semantics/lower.js";
|
|
15
16
|
/** BigInt's operations the backend spells as an operator. */
|
|
16
17
|
const BIGINT_INFIX = { add: '+', subtract: '-', multiply: '*', and: 'and', or: 'or', xor: 'xor' };
|
|
17
18
|
export const operatorsMethods = {
|
|
@@ -74,6 +75,11 @@ export const operatorsMethods = {
|
|
|
74
75
|
// A string that may be missing converts first: Kotlin's `+` on a null string writes "null" for undefined too.
|
|
75
76
|
if (this.isString(e.left) && isNullable(this.declaredTypeOf(e.left) ?? this.typeOf(e.left)))
|
|
76
77
|
return `${target()} = ${this.str(e.left)} + ${added()}`;
|
|
78
|
+
if (ts.isIdentifier(e.left) && this.stringBuilders.has(this.resolve(e.left))) {
|
|
79
|
+
const parts = flattenStringConcat(e.right, (x) => this.isString(x));
|
|
80
|
+
const appends = parts.map((p) => `.append(${untyped?.kind === 'concat' ? concatOperand(this, p, untyped) : this.str(p)})`).join('');
|
|
81
|
+
return `${ident(e.left.text)}${appends}`;
|
|
82
|
+
}
|
|
77
83
|
return this.isString(e.left) ? `${target()} += ${added()}` : `${target()} += ${untyped ? untypedConversion(this, untyped, e.right) : this.toNumber(e.right)}`;
|
|
78
84
|
}
|
|
79
85
|
case K.MinusEqualsToken:
|
|
@@ -133,19 +139,19 @@ export const operatorsMethods = {
|
|
|
133
139
|
case K.GreaterThanToken:
|
|
134
140
|
case K.LessThanEqualsToken:
|
|
135
141
|
case K.GreaterThanEqualsToken: {
|
|
136
|
-
const sym = ts.tokenToString(op);
|
|
137
|
-
if (this.isString(e.left) && this.isString(e.right))
|
|
138
|
-
return `${l()} ${sym} ${r()}`;
|
|
139
142
|
// An untyped or object operand: compared as strings or as numbers by what it holds when the program runs.
|
|
140
143
|
const dynamic = (x) => {
|
|
141
144
|
const t = this.typeOf(x);
|
|
142
145
|
return isUntyped(spelledType(t)) || t === 'Any' || t === 'String?' || /^[A-Z]\??$/.test(t) || (this.isObjectType(t) && !/^JSDate\??$/.test(t));
|
|
143
146
|
};
|
|
144
|
-
|
|
145
|
-
|
|
147
|
+
const plan = planRelational(op, this.isString(e.left), this.isString(e.right), dynamic(e.left) || dynamic(e.right));
|
|
148
|
+
if (plan.kind === 'string')
|
|
149
|
+
return `${l()} ${plan.op} ${r()}`;
|
|
150
|
+
if (plan.kind === 'dynamic') {
|
|
151
|
+
const fn = { '<': RT.jsLess, '>': RT.jsGreater, '<=': RT.jsLessOrEqual, '>=': RT.jsGreaterOrEqual }[plan.op];
|
|
146
152
|
return `${fn}(${this.coerce(e.left, 'Any?')}, ${this.coerce(e.right, 'Any?')})`;
|
|
147
153
|
}
|
|
148
|
-
return `${this.toNumber(e.left)} ${
|
|
154
|
+
return `${this.toNumber(e.left)} ${plan.op} ${this.toNumber(e.right)}`;
|
|
149
155
|
}
|
|
150
156
|
case K.QuestionQuestionToken: {
|
|
151
157
|
const t = this.typeOf(e);
|
|
@@ -42,7 +42,7 @@ export const optionalChainsMethods = {
|
|
|
42
42
|
// A non-strict app's optional member, as its shape holds it.
|
|
43
43
|
const shapeOptSym = ts.isPropertyAccessExpression(e) && !e.questionDotToken && !(e.flags & ts.NodeFlags.OptionalChain) ? this.checker.getSymbolAtLocation(e.name) : undefined;
|
|
44
44
|
const shapeOpt = !!shapeOptSym && this.states.shapeFieldOptional(shapeOptSym) && (['String', 'Double', 'Boolean'].includes(this.typeOf(e)) || this.states.unsetMember(shapeOptSym.valueDeclaration ?? shapeOptSym.declarations?.[0]));
|
|
45
|
-
if (ts.isPropertyAccessExpression(e) && ((this.
|
|
45
|
+
if (ts.isPropertyAccessExpression(e) && ((this.isLenientOptionalMember(e) && ['String', 'Double', 'Boolean'].includes(this.typeOf(e))) || shapeOpt)) {
|
|
46
46
|
const untyped = this.untypedMemberRead(e);
|
|
47
47
|
if (untyped)
|
|
48
48
|
return untyped;
|
|
@@ -270,14 +270,7 @@ export const optionalChainsMethods = {
|
|
|
270
270
|
* A string, number or boolean read `e` of type `t` as the optional it holds, where it converts undefined (a read, or
|
|
271
271
|
* a choice one of whose branches does); null where it converts nothing.
|
|
272
272
|
*/
|
|
273
|
-
convertedOptional
|
|
274
|
-
if (this.library)
|
|
275
|
-
return null;
|
|
276
|
-
const inner = ts.skipOuterExpressions(e);
|
|
277
|
-
if (ts.isConditionalExpression(inner) && this.typeOf(inner) === t && [inner.whenTrue, inner.whenFalse].some((x) => this.undefinedConverted(this.coerce(ts.skipOuterExpressions(x, ts.OuterExpressionKinds.Parentheses), t))))
|
|
278
|
-
return this.coerce(inner, optionalType(t));
|
|
279
|
-
return this.undefinedConverted(this.expr(ts.skipOuterExpressions(e, ts.OuterExpressionKinds.Parentheses)));
|
|
280
|
-
},
|
|
273
|
+
/* convertedOptional is installed from semantics/lowering-methods.ts */
|
|
281
274
|
/**
|
|
282
275
|
* App and plugin code's string, number or boolean read that converts undefined (`(x ?: "undefined")`): the nullable it
|
|
283
276
|
* converts, for a use that takes undefined as it is (a comparison, a receiver's TypeError). Null for any other code.
|
package/dist/kotlin/overrides.js
CHANGED
|
@@ -96,17 +96,7 @@ export const overridesMethods = {
|
|
|
96
96
|
e = e.expression;
|
|
97
97
|
return ts.isIdentifier(e) && (e.text === 'global' || e.text === 'globalThis') && (this.resolve(e)?.declarations ?? []).every((d) => d.getSourceFile().isDeclarationFile);
|
|
98
98
|
},
|
|
99
|
-
|
|
100
|
-
setNativeOf(e) {
|
|
101
|
-
if (!ts.isPropertyAccessExpression(e) || e.name.text !== 'setNative')
|
|
102
|
-
return null;
|
|
103
|
-
return this.properties?.name(this.resolve(e.expression)) ?? null;
|
|
104
|
-
},
|
|
105
|
-
/** The kit class a mixin class (`applyMixins(View, [Extended])`) is applied to. */
|
|
106
|
-
mixinOf(sym) {
|
|
107
|
-
const d = sym?.valueDeclaration;
|
|
108
|
-
return d && ts.isClassDeclaration(d) ? this.patterns.mixinTarget(d) : null;
|
|
109
|
-
},
|
|
99
|
+
/* setNativeOf and mixinOf are installed from semantics/lowering-methods.ts */
|
|
110
100
|
/**
|
|
111
101
|
* A method overriding kit-android's: the kit's Kotlin signature, the
|
|
112
102
|
* TypeScript body seeing its own types; what it throws is reported, as an
|
|
@@ -227,7 +217,7 @@ export const overridesMethods = {
|
|
|
227
217
|
return this.library.counterpart(file, name) ?? 'null';
|
|
228
218
|
},
|
|
229
219
|
/** Whether a compiled class or one it extends declares a member of this name. */
|
|
230
|
-
|
|
220
|
+
declaresCompiledMember(cls, name) {
|
|
231
221
|
for (let b = cls; b; b = programBase(b, this.checker))
|
|
232
222
|
if (b.members.some((m) => m.name?.getText() === name) || this.facts.prototypeKeys().data.has(name) || this.facts.prototypeKeys().accessors.has(name))
|
|
233
223
|
return true;
|
|
@@ -595,9 +585,7 @@ export const overridesMethods = {
|
|
|
595
585
|
return target.name;
|
|
596
586
|
},
|
|
597
587
|
/** A module-level function, class or variable's Kotlin name. */
|
|
598
|
-
topName
|
|
599
|
-
return this.topNames().get(decl) ?? name;
|
|
600
|
-
},
|
|
588
|
+
/* topName is installed from semantics/lowering-methods.ts */
|
|
601
589
|
/**
|
|
602
590
|
* App mode: a type name Kotlin code already has unqualified (a default import's, the runtime's, a thread annotation's,
|
|
603
591
|
* whose import outranks the app's package). Java classes are spelled qualified, so their names hide nothing.
|
package/dist/kotlin/placement.js
CHANGED
|
@@ -43,18 +43,7 @@ export const placementMethods = {
|
|
|
43
43
|
return this.typeOf(d.name);
|
|
44
44
|
return ts.isParameter(d) ? this.paramType(d) : this.returnTypeOf(d);
|
|
45
45
|
},
|
|
46
|
-
|
|
47
|
-
nullishCode(e) {
|
|
48
|
-
if (!ts.isCallExpression(e) && !ts.isPropertyAccessExpression(e))
|
|
49
|
-
return this.refName(e);
|
|
50
|
-
this.nullishCalls.add(e);
|
|
51
|
-
try {
|
|
52
|
-
return this.expr(e);
|
|
53
|
-
}
|
|
54
|
-
finally {
|
|
55
|
-
this.nullishCalls.delete(e);
|
|
56
|
-
}
|
|
57
|
-
},
|
|
46
|
+
/* nullishCode is installed from semantics/lowering-methods.ts */
|
|
58
47
|
/** `nullableEntry`'s read: `jsNulledEntry` of the Map value `code` reads, `jsNulledElement` of the element, the field by its key, or a static by its written flag. */
|
|
59
48
|
nulledEntry(read, code) {
|
|
60
49
|
if (read.kind === 'static') {
|
|
@@ -128,19 +128,7 @@ export const statementsMethods = {
|
|
|
128
128
|
});
|
|
129
129
|
return forward;
|
|
130
130
|
},
|
|
131
|
-
block
|
|
132
|
-
if (base === undefined)
|
|
133
|
-
base = this.indent;
|
|
134
|
-
const saved = this.indent;
|
|
135
|
-
this.indent = base + ' ';
|
|
136
|
-
try {
|
|
137
|
-
const body = this.statements(ts.isBlock(b) ? [...b.statements] : [b]);
|
|
138
|
-
return `{\n${body.join('\n')}\n${base}}`;
|
|
139
|
-
}
|
|
140
|
-
finally {
|
|
141
|
-
this.indent = saved;
|
|
142
|
-
}
|
|
143
|
-
},
|
|
131
|
+
/* block is installed from semantics/lowering-methods.ts */
|
|
144
132
|
stmt(s) {
|
|
145
133
|
let code;
|
|
146
134
|
const at = this.translating;
|
|
@@ -40,6 +40,8 @@ export class Translator {
|
|
|
40
40
|
spelling = [];
|
|
41
41
|
/** Variables initialized from an element read (`const r = xs[i]`): nullable, unwrapped where they are used. */
|
|
42
42
|
undefinedVars = new Map();
|
|
43
|
+
/** Function-local `let s: string` variables only mutated via `+=` in a loop: lowered to `StringBuilder`. */
|
|
44
|
+
stringBuilders = new Set();
|
|
43
45
|
/** A binding Kotlin holds as nullable though TypeScript types it present: reads take it as the undefined it may be. */
|
|
44
46
|
bindsOptional(name, type) {
|
|
45
47
|
const sym = this.checker.getSymbolAtLocation(name);
|
|
@@ -311,16 +313,6 @@ export class Translator {
|
|
|
311
313
|
taken.set(prefix, n);
|
|
312
314
|
return this.marks.pureCode(/^__[a-z]$/.test(prefix) ? `${prefix}_${n}` : `${prefix}${n}`);
|
|
313
315
|
}
|
|
314
|
-
nested(body) {
|
|
315
|
-
const saved = this.indent;
|
|
316
|
-
this.indent += ' ';
|
|
317
|
-
try {
|
|
318
|
-
return body();
|
|
319
|
-
}
|
|
320
|
-
finally {
|
|
321
|
-
this.indent = saved;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
316
|
/** A constructor's `return`, inside the labeled block its `init` runs: Kotlin's `init` takes no `return`. */
|
|
325
317
|
returnLabel = null;
|
|
326
318
|
/** `return`, or in a lambda `return@` its label. */
|
|
@@ -98,7 +98,7 @@ export const typeTestsMethods = {
|
|
|
98
98
|
const x = ts.skipOuterExpressions(e, ts.OuterExpressionKinds.Parentheses);
|
|
99
99
|
if (this.lenientApp && ts.isIdentifier(x) && this.declaredTypeOf(x) === optionalType(t))
|
|
100
100
|
return true;
|
|
101
|
-
if (ts.isPropertyAccessExpression(x) && this.
|
|
101
|
+
if (ts.isPropertyAccessExpression(x) && this.isLenientOptionalMember(x))
|
|
102
102
|
return true;
|
|
103
103
|
if (this.lenientMissingMember(x))
|
|
104
104
|
return true;
|