@nstudio/nativescript-compiler 9.2.0-alpha.10 → 9.2.0-alpha.12
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/api/ir.js +7 -1
- package/dist/cli/runtime.cjs +7 -1
- package/dist/css/css.js +30 -6
- package/dist/driver/cli.js +2 -0
- package/dist/driver/compile.js +23 -10
- package/dist/driver/paths.js +7 -0
- package/dist/driver/unimplemented.js +15 -0
- package/dist/kotlin/access.js +23 -5
- package/dist/kotlin/arguments.js +5 -0
- package/dist/kotlin/builtins.js +0 -4
- package/dist/kotlin/calls.js +6 -2
- package/dist/kotlin/class-methods.js +9 -3
- package/dist/kotlin/components.js +13 -8
- package/dist/kotlin/conversion.js +17 -5
- package/dist/kotlin/core-api.js +2 -13
- package/dist/kotlin/declarations.js +2 -0
- package/dist/kotlin/expression-statements.js +5 -4
- package/dist/kotlin/expressions.js +8 -3
- package/dist/kotlin/functions.js +13 -4
- package/dist/kotlin/global-calls.js +11 -0
- package/dist/kotlin/literals.js +58 -14
- package/dist/kotlin/names.js +2 -2
- package/dist/kotlin/native/api.js +9 -1
- package/dist/kotlin/native/calls.js +84 -3
- package/dist/kotlin/native/subclasses.js +4 -3
- package/dist/kotlin/native/types.js +8 -5
- package/dist/kotlin/operators.js +4 -1
- package/dist/kotlin/overrides.js +7 -5
- package/dist/kotlin/placement.js +3 -1
- package/dist/kotlin/prototype-calls.js +5 -0
- package/dist/kotlin/render.js +62 -0
- package/dist/kotlin/statements.js +9 -0
- package/dist/kotlin/static-calls.js +10 -7
- package/dist/kotlin/translator.js +31 -11
- package/dist/kotlin/type-facts.js +10 -2
- package/dist/kotlin/types.js +6 -6
- package/dist/plugins/native-android.js +37 -5
- package/dist/plugins/native-ios.js +2 -0
- package/dist/plugins/source.js +73 -23
- package/dist/program/app-modules.js +91 -16
- package/dist/program/app-paths.js +80 -12
- package/dist/program/class-mixins.js +463 -0
- package/dist/program/core-facts.js +7 -0
- package/dist/program/glob.js +274 -0
- package/dist/program/platform.js +32 -4
- package/dist/program/program.js +239 -38
- package/dist/program/source-lines.js +4 -1
- package/dist/program/vite-plugins.js +144 -0
- package/dist/semantics/apis/globals.js +2 -2
- package/dist/semantics/apis/object.js +1 -0
- package/dist/semantics/apis/statics.js +6 -0
- package/dist/semantics/ast.js +20 -2
- package/dist/semantics/classes.js +36 -1
- package/dist/semantics/facts.js +28 -1
- package/dist/semantics/globals.js +3 -0
- package/dist/semantics/lang.js +13 -1
- package/dist/semantics/nullish.js +29 -11
- package/dist/semantics/refuse-receivers.js +3 -3
- package/dist/semantics/refuse-scope.js +2 -7
- package/dist/semantics/runtime.js +1 -0
- package/dist/semantics/shapes.js +21 -1
- package/dist/semantics/states/value-states.js +1 -1
- package/dist/semantics/throws.js +1 -0
- package/dist/semantics/translator-methods.js +1 -1
- package/dist/semantics/types.js +21 -1
- package/dist/swift/access.js +25 -10
- package/dist/swift/arguments.js +10 -2
- package/dist/swift/assignment.js +12 -1
- package/dist/swift/builtins.js +0 -4
- package/dist/swift/calls.js +6 -2
- package/dist/swift/class-methods.js +3 -3
- package/dist/swift/components.js +28 -8
- package/dist/swift/construction.js +4 -0
- package/dist/swift/conversion.js +1 -1
- package/dist/swift/core-api.js +9 -12
- package/dist/swift/from-any.js +2 -2
- package/dist/swift/functions.js +13 -2
- package/dist/swift/generics.js +5 -1
- package/dist/swift/global-calls.js +2 -0
- package/dist/swift/literals.js +57 -10
- package/dist/swift/modules.js +1 -1
- package/dist/swift/names.js +1 -1
- package/dist/swift/native/sdk-tables.js +52 -4
- package/dist/swift/native/sdk.js +9 -1
- package/dist/swift/operators.js +4 -1
- package/dist/swift/parameters.js +5 -2
- package/dist/swift/placement.js +44 -4
- package/dist/swift/prototype-calls.js +17 -2
- package/dist/swift/render.js +64 -0
- package/dist/swift/results.js +1 -1
- package/dist/swift/statements.js +9 -0
- package/dist/swift/static-calls.js +13 -6
- package/dist/swift/types.js +9 -9
- package/dist/targets/android/build.js +18 -12
- package/dist/targets/ios/build.js +11 -10
- package/dist/targets/ios/dependencies.js +12 -0
- package/dist/targets/resources.js +15 -1
- package/dist/template/plan.js +105 -8
- package/dist/types/adapter-api.d.ts +13 -0
- package/dist/types/ir.d.ts +47 -0
- package/kit-android/generated/kotlin/org/nativescript/kit/__Objects.kt +102 -7485
- package/kit-android/generated/kotlin/org/nativescript/kit/application_application.kt +4 -4
- package/kit-android/generated/kotlin/org/nativescript/kit/image_source_index.kt +1 -1
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_animation_animation_common.kt +7 -3
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_animation_index.kt +3 -1
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_view_base_index.kt +2 -4
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_view_index.kt +5 -6
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_view_view_common.kt +1 -3
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_dialogs_index.kt +11 -6
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_frame_fragment_transitions.kt +1 -1
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_frame_frame_common.kt +1 -1
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_frame_frame_helper_for_android.kt +7 -5
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_frame_index.kt +6 -3
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_gestures_touch_manager.kt +1 -1
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_layouts_flexbox_layout_index.kt +1 -1
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_search_bar_index.kt +4 -3
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_segmented_bar_index.kt +2 -2
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_text_base_formatted_string.kt +1 -3
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_text_base_index.kt +1 -1
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_transition_fade_transition.kt +1 -1
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_transition_flip_transition.kt +8 -8
- package/kit-android/generated/kotlin/org/nativescript/kit/utils_index.kt +1 -1
- package/kit-android/generated/source-lines.json +1 -1
- package/kit-android/gradlew.bat +94 -0
- package/kit-android/src/fromcore/kotlin/org/nativescript/kit/CoreBridge.kt +67 -1
- package/kit-android/src/main/kotlin/org/nativescript/kit/Signals.kt +15 -2
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Prototypes.kt +26 -0
- package/kit-apple/Overlays/xml-free/Core/ui.core.bindable.index.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity1.swift +26 -161
- package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity2.swift +9 -284
- package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity3Plus.swift +11 -7
- package/kit-apple/Sources/NativeScriptKit/Core/Object_callback_thisArg_once.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/Object_eventName_object_index_section_view_ios_android.swift +7 -5
- package/kit-apple/Sources/NativeScriptKit/Core/Object_eventName_object_oldIndex_newIndex.swift +4 -2
- package/kit-apple/Sources/NativeScriptKit/Core/{Object_iterator_prototype_for_keyFor_hasInstance_isConcatSpreadable_and_19_more_91b5f3.swift → Object_iterator_prototype_for_keyFor_hasInstance_isConcatSpreadable_and_19_more_fa18e1.swift} +28 -103
- package/kit-apple/Sources/NativeScriptKit/Core/__Namespace.Utils.swift +17 -15
- package/kit-apple/Sources/NativeScriptKit/Core/application-settings.index.ios.swift +8 -8
- package/kit-apple/Sources/NativeScriptKit/Core/application.application-common.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/color.color-common.swift +7 -7
- package/kit-apple/Sources/NativeScriptKit/Core/data.observable.index.swift +3 -3
- package/kit-apple/Sources/NativeScriptKit/Core/http.http-request-internal.index.ios.swift +2 -1
- package/kit-apple/Sources/NativeScriptKit/Core/image-source.index.ios.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/kit-index.json +40 -246
- package/kit-apple/Sources/NativeScriptKit/Core/manifest.json +1 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.action-bar.index.ios.swift +3 -3
- package/kit-apple/Sources/NativeScriptKit/Core/ui.button.index.ios.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/ui.content-view.index.swift +8 -8
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.bindable.index.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.index.ios.swift +8 -8
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.view-common.swift +1 -3
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.view-helper.view-helper-common.swift +7 -7
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.weak-event-listener.index.swift +3 -3
- package/kit-apple/Sources/NativeScriptKit/Core/ui.frame.index.ios.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/ui.gestures.index.ios.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.html-view.index.ios.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/ui.image.image-common.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.image.index.ios.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/ui.label.index.ios.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.absolute-layout.index.ios.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.dock-layout.index.ios.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.flexbox-layout.index.ios.swift +3 -3
- package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.grid-layout.index.ios.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.stack-layout.index.ios.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.wrap-layout.index.ios.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/ui.list-view.index.ios.swift +3 -3
- package/kit-apple/Sources/NativeScriptKit/Core/ui.page.index.ios.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/ui.repeater.index.swift +10 -6
- package/kit-apple/Sources/NativeScriptKit/Core/ui.scroll-view.index.ios.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/ui.split-view.index.ios.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.background.ios.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.tab-view.index.ios.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/ui.text-base.formatted-string.swift +2 -1
- package/kit-apple/Sources/NativeScriptKit/Core/utils.common.swift +9 -9
- package/kit-apple/Sources/NativeScriptKit/Core/utils.layout-helper.index.ios.swift +10 -10
- package/kit-apple/Sources/NativeScriptKit/CoreBridge.swift +67 -1
- package/kit-apple/Sources/NativeScriptKit/Runtime/Lowering.swift +4 -0
- package/kit-apple/Sources/NativeScriptKit/Runtime/Prototypes.swift +25 -0
- package/kit-apple/Sources/NativeScriptKit/Runtime/RegExp.swift +6 -0
- package/kit-apple/Sources/NativeScriptKit/Signals.swift +20 -2
- package/package.json +2 -1
- package/kit-apple/Sources/NativeScriptKit/Core/Object_toString_charAt_charCodeAt_concat_indexOf_lastIndexOf_and_44_more_fc25df.swift +0 -481
package/dist/swift/placement.js
CHANGED
|
@@ -11,7 +11,7 @@ import { holdsNil, notedField, resultShapeNamed } from "../semantics/shapes.js";
|
|
|
11
11
|
import { implementedInterfaces, literalKey, takesReceiver } from "../semantics/lang.js";
|
|
12
12
|
import { slotOf } from "../semantics/trust.js";
|
|
13
13
|
import { isCoreDeclaration } from "../program/core-facts.js";
|
|
14
|
-
import { isStatic } from "../semantics/throws.js";
|
|
14
|
+
import { isAsync, isStatic } from "../semantics/throws.js";
|
|
15
15
|
import { typedCollection } from "./native/bridging.js";
|
|
16
16
|
import { isLibGlobal } from "../semantics/globals.js";
|
|
17
17
|
import { literalClassOf } from "../semantics/classes.js";
|
|
@@ -178,7 +178,7 @@ export const placementMethods = {
|
|
|
178
178
|
if (!shape) {
|
|
179
179
|
// An interface's object class, whose fields are its property signatures.
|
|
180
180
|
const d = this.checker.getSymbolAtLocation(e.name)?.valueDeclaration;
|
|
181
|
-
if (!d || !ts.isPropertySignature(d) || !ts.isInterfaceDeclaration(d.parent) || d.parent.name.text !== held || !this.interfaces.
|
|
181
|
+
if (!d || !ts.isPropertySignature(d) || !ts.isInterfaceDeclaration(d.parent) || d.parent.name.text !== held || !this.facts.hasInterface(this, this.interfaces, (x, s) => this.topName(x, s), held) || this.protocols.has(held))
|
|
182
182
|
return null;
|
|
183
183
|
const t = this.typeOf(d);
|
|
184
184
|
return (d.questionToken || holdsNil(heldOf(spelledType(t)))) && heldOf(spelledType(t)) !== 'any' ? e.name.text : null;
|
|
@@ -703,8 +703,7 @@ export const placementMethods = {
|
|
|
703
703
|
if (/^\(.*\)$/.test(source) && !functionParts(source) && /^JSArray<.*>[?!]?$/.test(target))
|
|
704
704
|
return this.convert(this.expr(e), source, target);
|
|
705
705
|
// An array literal is made of the slot's element type already.
|
|
706
|
-
|
|
707
|
-
if (literal && /^JSArray<.+>[?!]?$/.test(source) && /^JSArray<.+>[?!]?$/.test(target) && ['elements', 'view'].includes(structural(parseNativeType(source), parseNativeType(target), this.structuralFacts())?.step ?? ''))
|
|
706
|
+
if (ts.isArrayLiteralExpression(bare) && /^JSArray<.+>[?!]?$/.test(source) && /^JSArray<.+>[?!]?$/.test(target) && ['elements', 'view'].includes(structural(parseNativeType(source), parseNativeType(target), this.structuralFacts())?.step ?? ''))
|
|
708
707
|
return this.expr(e);
|
|
709
708
|
if (/^JSArray<\w+>[?!]?$/.test(source) && /^JSArray<\w+>[?!]?$/.test(target) && source.replace(/[?!]$/, '') !== target.replace(/[?!]$/, ''))
|
|
710
709
|
return this.convert(this.expr(e), source, target);
|
|
@@ -897,4 +896,45 @@ export const placementMethods = {
|
|
|
897
896
|
});
|
|
898
897
|
return `{ () ${this.throwsInfo.expr(e) ? 'throws ' : ''}-> ${name} in ${[`let ${o} = ${name}(jsLiteral: ())`, ...steps, `return ${o}`].join('; ')} }()`;
|
|
899
898
|
},
|
|
899
|
+
/** An object literal typed as an abstract/plugin class (`HlmPickerPanelRef`, `IconInfo`): a local subclass overriding its methods and fields. */
|
|
900
|
+
abstractClassLiteral(e, cls, name) {
|
|
901
|
+
const clsName = this.className(cls);
|
|
902
|
+
const implName = this.fresh('__Lit');
|
|
903
|
+
const clsType = this.checker.getDeclaredTypeOfSymbol(this.checker.getSymbolAtLocation(cls.name));
|
|
904
|
+
const ctorLines = [];
|
|
905
|
+
const methodLines = [];
|
|
906
|
+
const args = [];
|
|
907
|
+
const ctorParams = [];
|
|
908
|
+
for (const p of e.properties) {
|
|
909
|
+
if (!(ts.isPropertyAssignment(p) || ts.isShorthandPropertyAssignment(p) || ts.isMethodDeclaration(p))) {
|
|
910
|
+
throw this.error(p, `this member of an object literal of type ${name}`);
|
|
911
|
+
}
|
|
912
|
+
const key = literalKey(p.name, this.checker) ?? p.name.getText();
|
|
913
|
+
const m = cls.members.find((x) => ts.isMethodDeclaration(x) && x.name.getText() === key);
|
|
914
|
+
if (m) {
|
|
915
|
+
const sig = this.emittedSignature(m);
|
|
916
|
+
const throws = !isAsync(m) && this.throwsInfo.fn(m);
|
|
917
|
+
const fnType = `(${sig.params.map((x) => x.type).join(', ')}) ${throws ? 'throws ' : ''}-> ${sig.ret}`;
|
|
918
|
+
const fField = `__fn_${ident(key)}`;
|
|
919
|
+
const val = ts.isMethodDeclaration(p) ? `{ (${this.params(p, true)}) ${throws ? 'throws ' : ''}-> ${sig.ret} in${this.functionBody(p, sig.ret, this.indent).slice(1)}` : this.coerce(ts.isPropertyAssignment(p) ? p.initializer : p.name, fnType);
|
|
920
|
+
ctorParams.push(`_ ${fField}: @escaping ${fnType}`);
|
|
921
|
+
args.push(val);
|
|
922
|
+
const pDecls = sig.params.map((x, k) => `_ __a${k}: ${x.type}`).join(', ');
|
|
923
|
+
const pArgs = sig.params.map((_, k) => `__a${k}`).join(', ');
|
|
924
|
+
methodLines.push(`private let ${fField}: ${fnType}`);
|
|
925
|
+
methodLines.push(`override func ${ident(key)}(${pDecls})${throws ? ' throws' : ''}${sig.ret === 'Void' ? '' : ` -> ${sig.ret}`} { ${sig.ret === 'Void' ? '' : 'return '}${throws ? 'try ' : ''}${fField}(${pArgs}) }`);
|
|
926
|
+
ctorLines.push(`self.${fField} = ${fField}`);
|
|
927
|
+
continue;
|
|
928
|
+
}
|
|
929
|
+
const prop = clsType.getProperty(key)?.valueDeclaration;
|
|
930
|
+
const pt = prop && ts.isPropertyDeclaration(prop) ? this.typeOf(prop.name) : 'Any?';
|
|
931
|
+
const pVal = ts.isPropertyAssignment(p) ? p.initializer : p.name;
|
|
932
|
+
const param = `__p_${ident(key)}`;
|
|
933
|
+
ctorParams.push(`_ ${param}: ${pt}`);
|
|
934
|
+
args.push(this.coerce(pVal, pt));
|
|
935
|
+
ctorLines.push(`self.${ident(key)} = ${param}`);
|
|
936
|
+
}
|
|
937
|
+
const throws = this.throwsInfo.expr(e);
|
|
938
|
+
return `{ () ${throws ? 'throws ' : ''}-> ${clsName} in final class ${implName}: ${clsName} { nonisolated deinit {}; ${methodLines.join('; ')}; init(${ctorParams.join(', ')}) { ${ctorLines.join('; ')}; super.init() } }; return ${implName}(${args.join(', ')}) }()`;
|
|
939
|
+
},
|
|
900
940
|
};
|
|
@@ -150,8 +150,21 @@ export const prototypeCallsMethods = {
|
|
|
150
150
|
return this.convert(this.marks.tryCode(`${RT.jsCallMethod}(${[this.coerce(thisArg, 'Any?'), JSON.stringify(source.name.text), ...rest.map((x) => this.coerce(x, 'Any?'))].join(', ')})`), 'Any?', this.typeOf(e));
|
|
151
151
|
}
|
|
152
152
|
// A method taken from its object (`const f = obj.method`) stays bound to it in Swift: called with that object, it is the same call.
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
const sourceExpr = source && ts.isPropertyAccessExpression(source) ? ts.skipOuterExpressions(source.expression) : undefined;
|
|
154
|
+
const dynamicReceiverCall = () => {
|
|
155
|
+
const call = this.marks.tryCode(`${RT.jsCallValue}(${this.coerce(target, 'Any?')}, this: ${thisArg ? this.coerce(thisArg, 'Any?') : 'nil'}, optional: ${!!e.questionDotToken || (ts.isPropertyAccessExpression(e.expression) && !!e.expression.questionDotToken)}, [${rest.map((x) => this.coerce(x, 'Any?')).join(', ')}])`);
|
|
156
|
+
const rt = this.typeOf(e);
|
|
157
|
+
return rt === 'Void' || isUntyped(spelledType(rt)) ? call : this.fromAnyCode(call, rt, true);
|
|
158
|
+
};
|
|
159
|
+
const isDescriptorMember = (d) => !!d && ts.isInterfaceDeclaration(d.parent) && d.parent.name.text === 'PropertyDescriptor';
|
|
160
|
+
if (source && ts.isPropertyAccessExpression(source)) {
|
|
161
|
+
const srcDecl = this.resolve(source.name)?.declarations?.[0];
|
|
162
|
+
const fromPrototype = !!sourceExpr && ts.isPropertyAccessExpression(sourceExpr) && sourceExpr.name.text === 'prototype';
|
|
163
|
+
if (method === 'call' && (isDescriptorMember(srcDecl) || fromPrototype))
|
|
164
|
+
return dynamicReceiverCall();
|
|
165
|
+
if (!(thisArg && sourceExpr.getText() === thisArg.getText()))
|
|
166
|
+
throw this.error(e, `${method} of a method taken from its object, with another receiver`);
|
|
167
|
+
}
|
|
155
168
|
const plain = (x) => x.kind === ts.SyntaxKind.ThisKeyword || ts.isIdentifier(x) || (ts.isPropertyAccessExpression(x) ? plain(x.expression) : this.pure(x));
|
|
156
169
|
let held = target;
|
|
157
170
|
// `(ctx.fillText as (text: string, x: number, y: number) => void).call(ctx, …)`: the method itself, with its own signature.
|
|
@@ -159,6 +172,8 @@ export const prototypeCallsMethods = {
|
|
|
159
172
|
held = held.expression;
|
|
160
173
|
const sym = ts.isPropertyAccessExpression(held) || ts.isIdentifier(held) ? this.resolve(ts.isPropertyAccessExpression(held) ? held.name : held) : undefined;
|
|
161
174
|
const decl = sym?.declarations?.find((d) => (ts.isMethodDeclaration(d) || ts.isFunctionDeclaration(d)) && !!d.body) ?? sym?.valueDeclaration;
|
|
175
|
+
if (method === 'call' && isDescriptorMember(decl))
|
|
176
|
+
return dynamicReceiverCall();
|
|
162
177
|
const bound = !!decl && (ts.isMethodDeclaration(decl) || ts.isMethodSignature(decl) || (ts.isFunctionDeclaration(decl) && thisNodes(decl).length > 0));
|
|
163
178
|
const kitCall = this.kitPrototypeCall(held, e, method);
|
|
164
179
|
if (kitCall)
|
package/dist/swift/render.js
CHANGED
|
@@ -183,6 +183,68 @@ export function render(c, components, throws = () => false, behaviour = DEFAULT_
|
|
|
183
183
|
return say(depth, s.detached ? `let ${s.name} = Region(host: nil)` : `let ${s.name} = ${s.parent}.kitAddRegion()`);
|
|
184
184
|
case 'addRegion':
|
|
185
185
|
return say(depth, `${s.parent}.kitAddRegion(${s.region})`);
|
|
186
|
+
case 'setSlot': {
|
|
187
|
+
say(depth, `${s.component}.__slots[${swiftString(s.name)}] = { (__sr: Region) throws -> Void in`);
|
|
188
|
+
const wrap = s.scope ? scope(s.scope, 'Void') : null;
|
|
189
|
+
const d = wrap ? depth + 2 : depth + 1;
|
|
190
|
+
if (wrap)
|
|
191
|
+
say(depth + 1, wrap);
|
|
192
|
+
if (s.viewMark)
|
|
193
|
+
say(d, 'let __view = EffectOrder.current');
|
|
194
|
+
say(d, `let ${s.body.fragment} = RegionFragment(__sr)`);
|
|
195
|
+
steps(s.body.steps, d);
|
|
196
|
+
say(d, `__sr.set(parts: ${s.body.fragment}.parts)`);
|
|
197
|
+
if (wrap)
|
|
198
|
+
say(depth + 1, '}');
|
|
199
|
+
return say(depth, '}');
|
|
200
|
+
}
|
|
201
|
+
case 'slot': {
|
|
202
|
+
const host = regionHost(s.host);
|
|
203
|
+
if (s.fallback) {
|
|
204
|
+
say(depth, `if let __slot = self.__slots[${swiftString(s.name)}] {`);
|
|
205
|
+
say(depth + 1, `try __slot(${host})`);
|
|
206
|
+
say(depth, '} else {');
|
|
207
|
+
say(depth + 1, `let ${s.fallback.fragment} = RegionFragment(${host})`);
|
|
208
|
+
steps(s.fallback.steps, depth + 1);
|
|
209
|
+
say(depth + 1, `${host}.set(parts: ${s.fallback.fragment}.parts)`);
|
|
210
|
+
return say(depth, '}');
|
|
211
|
+
}
|
|
212
|
+
return say(depth, `if let __slot = self.__slots[${swiftString(s.name)}] { try __slot(${host}) }`);
|
|
213
|
+
}
|
|
214
|
+
case 'componentOutlet': {
|
|
215
|
+
const host = regionHost(s.host);
|
|
216
|
+
const inj = s.injector ? `, injector: { ${call(s.injector)} }` : '';
|
|
217
|
+
const inp = s.inputs ? `, inputs: { ${call(s.inputs)} }` : '';
|
|
218
|
+
return say(depth, `${s.call}(${host}, component: { ${call(s.component)} }${inj}${inp})`);
|
|
219
|
+
}
|
|
220
|
+
case 'templateOutlet': {
|
|
221
|
+
const host = regionHost(s.host);
|
|
222
|
+
const ctx = s.context ? `, context: { ${call(s.context)} }` : '';
|
|
223
|
+
return say(depth, `${s.call}(${host}, template: { ${call(s.template)} }${ctx})`);
|
|
224
|
+
}
|
|
225
|
+
case 'bindTemplate':
|
|
226
|
+
case 'structural': {
|
|
227
|
+
const open = s.kind === 'bindTemplate' ? `TemplateOutlet.bind(self.${ident(s.field)})` : `let ${s.tplName} = TemplateOutlet.make`;
|
|
228
|
+
say(depth, `${open} { (__sr: Region, ${s.ctxParam}: Any?) throws -> Void in`);
|
|
229
|
+
const wrap = s.scope ? scope(s.scope, 'Void') : null;
|
|
230
|
+
const d = wrap ? depth + 2 : depth + 1;
|
|
231
|
+
if (wrap)
|
|
232
|
+
say(depth + 1, wrap);
|
|
233
|
+
if (s.viewMark)
|
|
234
|
+
say(d, 'let __view = EffectOrder.current');
|
|
235
|
+
say(d, `let ${s.body.fragment} = RegionFragment(__sr)`);
|
|
236
|
+
steps(s.body.steps, d);
|
|
237
|
+
say(d, `__sr.set(parts: ${s.body.fragment}.parts)`);
|
|
238
|
+
if (wrap)
|
|
239
|
+
say(depth + 1, '}');
|
|
240
|
+
say(depth, '}');
|
|
241
|
+
if (s.kind === 'structural') {
|
|
242
|
+
say(depth, `try ${s.call}(${s.region}, ${s.tplName}) {`);
|
|
243
|
+
steps(s.steps, depth + 1);
|
|
244
|
+
say(depth, '}');
|
|
245
|
+
}
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
186
248
|
case 'choose': {
|
|
187
249
|
const host = regionHost(s.host);
|
|
188
250
|
const which = s.conds.map((k, i) => (k ? `${cond(k, s.caught)} ? ${i} : ` : `${i}`)).join('') + (s.conds.at(-1) ? `${s.conds.length}` : '');
|
|
@@ -286,6 +348,8 @@ export function render(c, components, throws = () => false, behaviour = DEFAULT_
|
|
|
286
348
|
};
|
|
287
349
|
const passes = plan.passes;
|
|
288
350
|
const m = plan.members;
|
|
351
|
+
if (plan.hasSlots)
|
|
352
|
+
say(1, 'var __slots: [String: (Region) throws -> Void] = [:]');
|
|
289
353
|
if (passes) {
|
|
290
354
|
// Both passes, with the hooks a parent runs for its child between and after them.
|
|
291
355
|
const hooks = (list) => list.map((h) => (h.flush ? `${h.flush}(for: self)` : h.every ? `${h.every} { self.${h.member}() }` : `self.${h.member}()`)).join('; ');
|
package/dist/swift/results.js
CHANGED
|
@@ -39,7 +39,7 @@ export const resultsMethods = {
|
|
|
39
39
|
const cls = fn.parent;
|
|
40
40
|
if (!cls || !ts.isClassLike(cls))
|
|
41
41
|
return false;
|
|
42
|
-
for (let t = this.checker.getTypeAtLocation(cls); t;) {
|
|
42
|
+
for (let t = this.checker.getTypeAtLocation(cls); t?.isClassOrInterface();) {
|
|
43
43
|
const base = this.checker.getBaseTypes(t)[0];
|
|
44
44
|
if (!base)
|
|
45
45
|
return false;
|
package/dist/swift/statements.js
CHANGED
|
@@ -361,6 +361,15 @@ export const statementsMethods = {
|
|
|
361
361
|
});
|
|
362
362
|
}
|
|
363
363
|
if (ts.isForInStatement(s)) {
|
|
364
|
+
if (!ts.isVariableDeclarationList(s.initializer)) {
|
|
365
|
+
const k = this.fresh('__key');
|
|
366
|
+
const lines = this.assignIterated(s.initializer, k, this.checker.getStringType(), s.expression);
|
|
367
|
+
return this.loopBody(() => {
|
|
368
|
+
const label = this.takeLabel();
|
|
369
|
+
const body = this.block(s.statement);
|
|
370
|
+
return `${i}${label}for ${k} in ${this.tryPrefix(s.expression)}${RT.jsKeysOf}(${this.expr(s.expression)}) {\n${lines.map((l) => `${i} ${l}`).join('\n')}\n${body.slice(2)}`;
|
|
371
|
+
});
|
|
372
|
+
}
|
|
364
373
|
const list = s.initializer;
|
|
365
374
|
const name = ident(list.declarations[0].name.text);
|
|
366
375
|
const mutable = assignsTo(s.statement, this.checker.getSymbolAtLocation(list.declarations[0].name), this.checker) ? 'var ' : '';
|
|
@@ -3,7 +3,8 @@ import ts from 'typescript';
|
|
|
3
3
|
import { TYPED_ARRAYS } from "../semantics/globals.js";
|
|
4
4
|
import { ident, isFunctionType, optionalType, swiftString, RT } from "./syntax.js";
|
|
5
5
|
import { literalKey, statementLevel, undefinedLiteral } from "../semantics/lang.js";
|
|
6
|
-
import {
|
|
6
|
+
import { arrayFromLengthInit } from "../semantics/ast.js";
|
|
7
|
+
import { assignsArrayIntoObject, definesDuringConstruction, restrictsField, definedField, shapeArrayGuardAccess } from "../semantics/shapes.js";
|
|
7
8
|
import { CONSOLE } from "../semantics/apis/console.js";
|
|
8
9
|
import { staticFunction } from "../semantics/apis/statics.js";
|
|
9
10
|
import { runtimeCall } from "../semantics/apis/api.js";
|
|
@@ -110,14 +111,16 @@ export const staticCallsMethods = {
|
|
|
110
111
|
break;
|
|
111
112
|
}
|
|
112
113
|
case 'Array':
|
|
113
|
-
if (method === 'isArray')
|
|
114
|
-
|
|
114
|
+
if (method === 'isArray') {
|
|
115
|
+
const g = !this.library ? shapeArrayGuardAccess(arg(0), (t) => this.isObjectShape(t), (x) => this.typeOf(x)) : null;
|
|
116
|
+
return `JSArray<Any?>.isArray(${g ? `${this.expr(g.prop.expression)}${g.optional ? '?' : ''}[jsKey: ${swiftString(g.prop.name.text)}]` : this.restArgument(e, arg(0), 'Any?')})`;
|
|
117
|
+
}
|
|
115
118
|
if (method === 'from' && e.arguments.length === 1)
|
|
116
119
|
return `${T()}.from(${this.iterable(arg(0))})`;
|
|
117
120
|
if (method === 'from' && (e.arguments.length === 2 || e.arguments.length === 3) && ts.isObjectLiteralExpression(arg(0))) {
|
|
118
|
-
const
|
|
121
|
+
const lenInit = arrayFromLengthInit(arg(0));
|
|
119
122
|
const fn = arg(1);
|
|
120
|
-
if (!
|
|
123
|
+
if (!lenInit || !(ts.isArrowFunction(fn) || ts.isFunctionExpression(fn)))
|
|
121
124
|
throw this.error(e, 'Array.from of this object');
|
|
122
125
|
const el = T().replace(/^JSArray<(.*)>$/, '$1');
|
|
123
126
|
const params = fn.parameters.filter((p) => !(ts.isIdentifier(p.name) && p.name.text === 'this'));
|
|
@@ -125,7 +128,7 @@ export const staticCallsMethods = {
|
|
|
125
128
|
const value = params[0] && ts.isIdentifier(params[0].name) && params[0].name.text !== '_' ? `let ${ident(params[0].name.text)}: Any? = nil; ` : '';
|
|
126
129
|
return this.ignoringThisArg(e, arg(0), () => {
|
|
127
130
|
const body = ts.isBlock(fn.body) ? this.functionBody(fn, el, this.indent).slice(1, -1) : ` return ${this.marks.tryBefore(this.tryPrefix(fn.body), this.coerce(fn.body, el))} `;
|
|
128
|
-
return `${T()}.from(length: ${this.expr(
|
|
131
|
+
return `${T()}.from(length: ${this.expr(lenInit)}) { (${index}: Double) ${this.throwsInfo.fn(fn) ? 'throws ' : ''}-> ${el} in ${value}${body}}`;
|
|
129
132
|
});
|
|
130
133
|
}
|
|
131
134
|
if (method === 'from' && (e.arguments.length === 2 || e.arguments.length === 3))
|
|
@@ -165,6 +168,10 @@ export const staticCallsMethods = {
|
|
|
165
168
|
return `${RT.jsFromCharCode}(codes: ${this.packed(e.arguments, 'JSArray<Double>')}.storage)`;
|
|
166
169
|
if (method === 'fromCharCode')
|
|
167
170
|
return `${RT.jsFromCharCode}(${a().join(', ')})`;
|
|
171
|
+
if (method === 'fromCodePoint' && e.arguments.some(ts.isSpreadElement))
|
|
172
|
+
return `${RT.jsFromCodePoint}(codes: ${this.packed(e.arguments, 'JSArray<Double>')}.storage)`;
|
|
173
|
+
if (method === 'fromCodePoint')
|
|
174
|
+
return `${RT.jsFromCodePoint}(${e.arguments.map((x) => this.restArgument(e, x, 'Double')).join(', ')})`;
|
|
168
175
|
break;
|
|
169
176
|
case 'BigInt':
|
|
170
177
|
if (method === 'asIntN' || method === 'asUintN')
|
package/dist/swift/types.js
CHANGED
|
@@ -8,7 +8,7 @@ import { ambientAddedMemberOf, ambientBase, augmentedPropertyRead, evolvingArray
|
|
|
8
8
|
import { nullishSignalType } from "../semantics/signals.js";
|
|
9
9
|
import { hasModifier, isLibDeclaration, isSymbolIterator, isWriteTarget, implementationOf, declaresThis } from "../semantics/ast.js";
|
|
10
10
|
import { isCoreDeclaration } from "../program/core-facts.js";
|
|
11
|
-
import { coreTypeKind, eventDataTypeLiteral, isJsDocConstructorFunction, isKit, isLibObjectType, isUntyped, libraryNativeType, libraryType, mappedOrErasedType, nonNullableInner, nonOptionalSpelling, parseNativeType, spelledType } from "../semantics/types.js";
|
|
11
|
+
import { coreTypeKind, eventDataTypeLiteral, hasMappedIntersection, isJsDocConstructorFunction, isKit, isLibObjectType, isUntyped, libraryNativeType, libraryType, mappedOrErasedType, nonNullableInner, nonOptionalSpelling, parseNativeType, spelledType, valueModuleKind } from "../semantics/types.js";
|
|
12
12
|
import { keepsIdentity } from "../semantics/conversion.js";
|
|
13
13
|
import { extendedClass, isEventData } from "../semantics/classes.js";
|
|
14
14
|
import { otherPlatformTypings } from "../semantics/platform-globals.js";
|
|
@@ -55,10 +55,10 @@ export const typesMethods = {
|
|
|
55
55
|
if (native)
|
|
56
56
|
return optionalType(native);
|
|
57
57
|
}
|
|
58
|
-
// A namespace as a value (`{ Accuracy: CoreTypes.Accuracy }`)
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
61
|
-
return `${this.namespacePath(
|
|
58
|
+
// A namespace as a value (`{ Accuracy: CoreTypes.Accuracy }`) or an ES module namespace (`typeof import('...')`).
|
|
59
|
+
const ns = valueModuleKind(t);
|
|
60
|
+
if (ns)
|
|
61
|
+
return ns === 'module' ? 'Any?' : `${this.namespacePath(ns)}.Type`;
|
|
62
62
|
// An enum as a value (`typeof AccessibilityRole`): the object JavaScript makes of it.
|
|
63
63
|
// Not the enum's own name, through which its members are read (`Status.Denied`).
|
|
64
64
|
const enumObject = t.flags & F.Object && (t.getSymbol()?.flags ?? 0) & ts.SymbolFlags.RegularEnum ? t.getSymbol().valueDeclaration : undefined;
|
|
@@ -78,13 +78,13 @@ export const typesMethods = {
|
|
|
78
78
|
if (constraint)
|
|
79
79
|
return this.type(constraint, where);
|
|
80
80
|
const decl = t.symbol?.declarations?.[0];
|
|
81
|
+
if (decl && ts.isTypeParameterDeclaration(decl) && (this.erasesGenerics(decl.parent) || this.erasesTypeParameter(decl)))
|
|
82
|
+
return 'Any?';
|
|
81
83
|
if (decl && this.pluginFiles.has(decl.getSourceFile().fileName) && !(ts.isTypeParameterDeclaration(decl) && this.keepsGenerics(decl.parent)))
|
|
82
84
|
return 'Any?';
|
|
83
85
|
// A library's generic signature (`ClassDecorator`'s `TFunction`) in library mode: erased as the program's own are.
|
|
84
86
|
if (decl && this.library && decl.getSourceFile().isDeclarationFile)
|
|
85
87
|
return 'Any?';
|
|
86
|
-
if (decl && ts.isTypeParameterDeclaration(decl) && this.erasesTypeParameter(decl))
|
|
87
|
-
return 'Any?';
|
|
88
88
|
// Inside an object shape, a class of its own outside every generic scope: any value.
|
|
89
89
|
if (this.shaping.size)
|
|
90
90
|
return 'Any?';
|
|
@@ -122,7 +122,7 @@ export const typesMethods = {
|
|
|
122
122
|
const inNarrowing = (u) => !!(u.flags & F.Object) && !u.getCallSignatures().length && u.getProperties().every((p) => c.getTypeOfSymbol(p).flags & F.Unknown);
|
|
123
123
|
if (param && (isUntyped(spelledType(this.type(param, where))) || t.types.every((u) => u === param || inNarrowing(u))))
|
|
124
124
|
return this.type(param, where);
|
|
125
|
-
if (membersOverTypeParameter(t, c))
|
|
125
|
+
if (membersOverTypeParameter(t, c) || hasMappedIntersection(t))
|
|
126
126
|
return 'Any?';
|
|
127
127
|
// A function carrying properties (`((p: P) => R) & { type: string }`): an untyped value, called as script calls it.
|
|
128
128
|
if (t.types.some((u) => u.getCallSignatures().length) && t.types.some((u) => !u.getCallSignatures().length && u.getProperties().length) && !t.types.some((u) => isLibDeclaration(u.getSymbol()?.declarations?.[0])))
|
|
@@ -251,7 +251,7 @@ export const typesMethods = {
|
|
|
251
251
|
// A function type reading the receiver it is called with (`(this: Action, state) => void`): a script function, as
|
|
252
252
|
// `call`/`apply` pass that receiver and a Swift closure has none.
|
|
253
253
|
const sd = s.getDeclaration();
|
|
254
|
-
if (sd && (ts.isFunctionTypeNode(sd) || ts.isFunctionExpression(sd) || ts.isFunctionDeclaration(sd)) && declaresThis(sd))
|
|
254
|
+
if (sd && (ts.isFunctionTypeNode(sd) || ts.isFunctionExpression(sd) || ts.isFunctionDeclaration(sd) || ts.isMethodSignature(sd)) && declaresThis(sd))
|
|
255
255
|
return 'Any?';
|
|
256
256
|
if (sd && ts.isFunctionExpression(sd) && this.readsArguments(sd)) {
|
|
257
257
|
const ret = this.widenedResultType(sd, this.type(s.getReturnType(), where));
|
|
@@ -21,7 +21,7 @@ import { formatKotlin } from "../../kotlin/ktfmt.js";
|
|
|
21
21
|
import { moduleThreads, THREAD_ANNOTATIONS } from "../../semantics/threading.js";
|
|
22
22
|
import { androidManifest, copyAndroidAppFiles, copyAndroidFonts, pluginManifests } from "./resources.js";
|
|
23
23
|
import { appResourcesDir, uncaughtErrorSwitches } from "../resources.js";
|
|
24
|
-
import { KIT_ANDROID, PACKAGE } from "../../driver/paths.js";
|
|
24
|
+
import { gradleWrapper, KIT_ANDROID, PACKAGE } from "../../driver/paths.js";
|
|
25
25
|
import { OVERLAY_FILE, XML_FREE_OVERLAY } from "../../kit/overlay.js";
|
|
26
26
|
import { byName } from "../../program/order.js";
|
|
27
27
|
import { programClassName } from "../../semantics/top-names.js";
|
|
@@ -61,7 +61,7 @@ export async function writeAndroid(b) {
|
|
|
61
61
|
if (writes.length)
|
|
62
62
|
throw sharedWorkerStateError(writes, b.app);
|
|
63
63
|
}
|
|
64
|
-
const moduleFiles = [...b.modules, ...b.components.map((c) => c.file), ...(b.compiledPlugins ?? [])];
|
|
64
|
+
const moduleFiles = [...new Set([...b.modules, ...b.components.map((c) => c.file), ...(b.compiledPlugins ?? [])])];
|
|
65
65
|
// Which modules run on the main thread only; a worker's script reaching one stops the build with the import chain.
|
|
66
66
|
const threads = moduleThreads({ program: b.program, modules: moduleFiles, workers: b.workers, resolved: b.resolved, coreModuleOf: (f) => /[\\/]@nativescript[\\/]core[\\/](.+)$/.exec(f)?.[1] ?? null });
|
|
67
67
|
// A module only `await import(…)` reaches (and what only it imports) runs when it is imported, as the bundle evaluates
|
|
@@ -93,16 +93,21 @@ export async function writeAndroid(b) {
|
|
|
93
93
|
plainFields: !!b.translatorHooks?.plainFields,
|
|
94
94
|
appMembersByName: !!b.xml && !b.xmlMemberKeys,
|
|
95
95
|
pluginRoots: (b.plugins ?? []).map((p) => p.root + '/'),
|
|
96
|
-
workerScripts: new Map((b.workers ?? []).map((f) => [f, relative(b.app, f)])),
|
|
96
|
+
workerScripts: new Map((b.workers ?? []).map((f) => [f.replace(/\\/g, '/'), relative(b.app, f).replace(/\\/g, '/')])),
|
|
97
|
+
resolveAlias: b.aliased ?? null,
|
|
97
98
|
moduleThread: (file) => threads.get(file),
|
|
98
99
|
moduleKey: lazy.size ? (file) => relative(b.app, file) : undefined,
|
|
99
100
|
});
|
|
100
101
|
// Components whose class could not be written (`--keep-going`): a root view of one is left as it is.
|
|
101
102
|
const unwritten = new Set();
|
|
102
103
|
const kotlinClass = (name) => programClassName(translator, name);
|
|
104
|
+
const componentClass = (name) => {
|
|
105
|
+
const c = b.components.find((x) => x.name === name);
|
|
106
|
+
const sf = c && b.program.getSourceFile(c.file);
|
|
107
|
+
return sf?.statements.find((s) => ts.isClassDeclaration(s) && s.name?.text === name) ?? sf?.statements.find(ts.isClassDeclaration);
|
|
108
|
+
};
|
|
103
109
|
const rootView = (name, make) => {
|
|
104
|
-
const
|
|
105
|
-
const cls = c && b.program.getSourceFile(c.file)?.statements.find(ts.isClassDeclaration);
|
|
110
|
+
const cls = b.translatorHooks?.wrapsRootViews && !unwritten.has(name) ? componentClass(name) : undefined;
|
|
106
111
|
return cls ? translator.rootView(cls, kotlinClass(name), make) : make;
|
|
107
112
|
};
|
|
108
113
|
const table = {};
|
|
@@ -162,13 +167,8 @@ export async function writeAndroid(b) {
|
|
|
162
167
|
const header = (from, template) => `${headerLine(sourceName(b.app, from, b.context.adapter), template && (dirname(template) === dirname(from) ? basename(template) : sourceName(b.app, template, b.context.adapter)))}\npackage ${pkg}\n\nimport org.nativescript.kit.*\n\n`;
|
|
163
168
|
// A component's file is a module too: what it declares beside the component (its constants and helpers).
|
|
164
169
|
const modules = translateKotlinModules(translator, b.program, moduleFiles, b.resolved, b.app);
|
|
165
|
-
const componentClass = (name) => {
|
|
166
|
-
const c = b.components.find((x) => x.name === name);
|
|
167
|
-
return c && b.program.getSourceFile(c.file)?.statements.find(ts.isClassDeclaration);
|
|
168
|
-
};
|
|
169
170
|
for (const c of b.components) {
|
|
170
|
-
const
|
|
171
|
-
const cls = sf.statements.find(ts.isClassDeclaration);
|
|
171
|
+
const cls = componentClass(c.name);
|
|
172
172
|
try {
|
|
173
173
|
const { params, lines, statics } = translator.componentMembers(cls, c.props);
|
|
174
174
|
const conformance = translator.componentConformance(cls);
|
|
@@ -265,6 +265,11 @@ export async function writeAndroid(b) {
|
|
|
265
265
|
if ('branches' in n && Array.isArray(n.branches))
|
|
266
266
|
for (const br of n.branches)
|
|
267
267
|
visit(br.body);
|
|
268
|
+
if ('fallback' in n && Array.isArray(n.fallback))
|
|
269
|
+
visit(n.fallback);
|
|
270
|
+
if ('slots' in n && n.slots)
|
|
271
|
+
for (const slotNodes of Object.values(n.slots))
|
|
272
|
+
visit(slotNodes);
|
|
268
273
|
}
|
|
269
274
|
};
|
|
270
275
|
for (const c of b.components)
|
|
@@ -461,7 +466,8 @@ ${overlays.map((m) => ` variant.sources.manifests.addStaticManifestFile($
|
|
|
461
466
|
const k = b.keyStore;
|
|
462
467
|
const signing = k ? [`-Pandroid.injected.signing.store.file=${resolve(k.path)}`, `-Pandroid.injected.signing.store.password=${k.password}`, `-Pandroid.injected.signing.key.alias=${k.alias}`, `-Pandroid.injected.signing.key.password=${k.aliasPassword}`] : [];
|
|
463
468
|
// Kotlin's errors point into the generated files: printed with the TypeScript lines they came from.
|
|
464
|
-
const
|
|
469
|
+
const gw = gradleWrapper(['-p', b.out, ':assembleRelease', ...(b.bundle ? [':bundleRelease'] : []), ...signing, '--quiet'], kit);
|
|
470
|
+
const gradle = spawnSync(gw.command, gw.args, { stdio: ['inherit', 'pipe', 'pipe'], encoding: 'utf8', maxBuffer: 1 << 30 });
|
|
465
471
|
process.stdout.write(mapKotlinDiagnostics(gradle.stdout ?? '', b.out));
|
|
466
472
|
process.stderr.write(mapKotlinDiagnostics(gradle.stderr ?? '', b.out));
|
|
467
473
|
if (gradle.status !== 0)
|
|
@@ -106,11 +106,16 @@ export async function writeIos(b) {
|
|
|
106
106
|
// A component's file declares more than the component (interfaces, constants): it is a module as well.
|
|
107
107
|
// The SDK frameworks beyond UIKit the program's code names (CoreSpotlight, SafariServices), imported by every file once all are known.
|
|
108
108
|
const SDK_IMPORTS = '// @sdk-imports\n';
|
|
109
|
-
const translated = translateModules(translator, program, [...modules, ...components.map((c) => c.file), ...compiledPlugins], resolved);
|
|
109
|
+
const translated = translateModules(translator, program, [...new Set([...modules, ...components.map((c) => c.file), ...compiledPlugins])], resolved);
|
|
110
|
+
const componentClass = (name) => {
|
|
111
|
+
const c = components.find((x) => x.name === name);
|
|
112
|
+
const sf = c && program.getSourceFile(c.file);
|
|
113
|
+
return sf?.statements.find((s) => ts.isClassDeclaration(s) && s.name?.text === name) ?? sf?.statements.find(ts.isClassDeclaration);
|
|
114
|
+
};
|
|
110
115
|
// Every component's members first: whether a constructor throws is known before any template creates the component.
|
|
111
116
|
const members = new Map();
|
|
112
117
|
for (const c of components) {
|
|
113
|
-
const cls =
|
|
118
|
+
const cls = componentClass(c.name);
|
|
114
119
|
try {
|
|
115
120
|
members.set(c.name, located(translator.componentMembers(cls, c.props).join('\n')));
|
|
116
121
|
}
|
|
@@ -122,17 +127,12 @@ export async function writeIos(b) {
|
|
|
122
127
|
infos.get(c.name).initThrows = translator.initThrows(c.name);
|
|
123
128
|
infos.get(c.name).throwingSetters = (c.setters ?? []).filter((p) => translator.memberThrows(cls, '$set_' + p));
|
|
124
129
|
}
|
|
125
|
-
const componentClass = (name) => {
|
|
126
|
-
const c = components.find((x) => x.name === name);
|
|
127
|
-
return c && program.getSourceFile(c.file)?.statements.find(ts.isClassDeclaration);
|
|
128
|
-
};
|
|
129
130
|
/** Components whose class could not be written (`--keep-going`): a root view of one is left as it is. */
|
|
130
131
|
const unwritten = new Set();
|
|
131
132
|
for (const c of components) {
|
|
132
|
-
const
|
|
133
|
-
const cls = sf.statements.find(ts.isClassDeclaration);
|
|
133
|
+
const cls = componentClass(c.name);
|
|
134
134
|
try {
|
|
135
|
-
const lines = [`final class ${swiftClass(c.name)} {`, NONISOLATED_DEINIT, members.get(c.name) ?? '', ...translator.componentStatics(cls), '', ...render(c, infos, (m) => translator.memberThrows(cls, m), behaviour, { itemType: (m) => translator.memberElementType(cls, m), propValue: (child, p, m) => translator.propValue(cls, componentClass(child), p, m), swiftClass: (name) => (elementClasses.has(name) || infos.has(name) ? swiftClass(name) : name) }), '}', translator.componentConformance(cls, swiftClass(c.name))];
|
|
135
|
+
const lines = [`final class ${swiftClass(c.name)}${translator.componentSuperclass(cls)} {`, NONISOLATED_DEINIT, members.get(c.name) ?? '', ...translator.componentStatics(cls), '', ...render(c, infos, (m) => translator.memberThrows(cls, m), behaviour, { itemType: (m) => translator.memberElementType(cls, m), propValue: (child, p, m) => translator.propValue(cls, componentClass(child), p, m), swiftClass: (name) => (elementClasses.has(name) || infos.has(name) ? swiftClass(name) : name) }), '}', translator.componentConformance(cls, swiftClass(c.name))];
|
|
136
136
|
writeFileSync(join(sourcesDir, c.name + '.swift'), header(c.file) + lines.join('\n') + '\n');
|
|
137
137
|
}
|
|
138
138
|
catch (e) {
|
|
@@ -403,7 +403,8 @@ ${Object.entries(appSettings)
|
|
|
403
403
|
/** The code making a component's root view, wrapped as the framework wraps root views. */
|
|
404
404
|
function rootView(name, make) {
|
|
405
405
|
const c = adapter?.swift?.wrapsRootViews && !unwritten.has(name) ? components.find((x) => x.name === name) : undefined;
|
|
406
|
-
const
|
|
406
|
+
const sf = c && program.getSourceFile(c.file);
|
|
407
|
+
const cls = sf?.statements.find((s) => ts.isClassDeclaration(s) && s.name?.text === name) ?? sf?.statements.find(ts.isClassDeclaration);
|
|
407
408
|
return cls ? translator.rootView(cls, swiftClass(name), make) : make;
|
|
408
409
|
}
|
|
409
410
|
}
|
|
@@ -32,6 +32,18 @@ export function swiftPackages(app, stubbed = new Set()) {
|
|
|
32
32
|
pkg.path = resolve(app, p.path);
|
|
33
33
|
if (plugin && !existsSync(pkg.path) && existsSync(resolve(dir, p.path)))
|
|
34
34
|
pkg.path = resolve(dir, p.path);
|
|
35
|
+
// In a hoisted monorepo, `node_modules/<pkg>/...` may live in an ancestor workspace directory or relative to the plugin's own directory.
|
|
36
|
+
if (!existsSync(pkg.path) && p.path.startsWith('node_modules/')) {
|
|
37
|
+
for (let cur = dirname(app);; cur = dirname(cur)) {
|
|
38
|
+
const probe = resolve(cur, p.path);
|
|
39
|
+
if (existsSync(probe)) {
|
|
40
|
+
pkg.path = probe;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
if (dirname(cur) === cur)
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
35
47
|
if (!existsSync(pkg.path))
|
|
36
48
|
throw new Error(`${relative(app, join(dir, 'nativescript.config.ts')) || 'nativescript.config.ts'}: the Swift package ${name} is not at ${pkg.path}`);
|
|
37
49
|
// The JavaScript engine's headers, which a plugin binding the engine ships: no engine runs a compiled app.
|
|
@@ -10,9 +10,20 @@ export function readConfig(app) {
|
|
|
10
10
|
if (!file)
|
|
11
11
|
return {};
|
|
12
12
|
const sf = ts.createSourceFile(file, readFileSync(file, 'utf8'), ts.ScriptTarget.Latest, true);
|
|
13
|
+
const locals = new Map();
|
|
14
|
+
for (const st of sf.statements) {
|
|
15
|
+
if (ts.isVariableStatement(st)) {
|
|
16
|
+
for (const d of st.declarationList.declarations) {
|
|
17
|
+
if (ts.isIdentifier(d.name) && d.initializer)
|
|
18
|
+
locals.set(d.name.text, d.initializer);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
13
22
|
const value = (e) => {
|
|
14
23
|
if (ts.isAsExpression(e) || ts.isSatisfiesExpression(e) || ts.isParenthesizedExpression(e))
|
|
15
24
|
return value(e.expression);
|
|
25
|
+
if (ts.isIdentifier(e) && locals.has(e.text))
|
|
26
|
+
return value(locals.get(e.text));
|
|
16
27
|
if (ts.isStringLiteralLike(e))
|
|
17
28
|
return e.text;
|
|
18
29
|
if (ts.isNumericLiteral(e))
|
|
@@ -25,9 +36,12 @@ export function readConfig(app) {
|
|
|
25
36
|
return e.elements.map(value);
|
|
26
37
|
if (ts.isObjectLiteralExpression(e)) {
|
|
27
38
|
const out = {};
|
|
28
|
-
for (const p of e.properties)
|
|
39
|
+
for (const p of e.properties) {
|
|
29
40
|
if (ts.isPropertyAssignment(p))
|
|
30
41
|
out[p.name.getText().replace(/^['"]|['"]$/g, '')] = value(p.initializer);
|
|
42
|
+
else if (ts.isShorthandPropertyAssignment(p))
|
|
43
|
+
out[p.name.text] = value(p.name);
|
|
44
|
+
}
|
|
31
45
|
return out;
|
|
32
46
|
}
|
|
33
47
|
return undefined;
|