@nstudio/nativescript-compiler 9.2.0-alpha.15 → 9.2.0-alpha.16
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/kotlin/class-accessors.js +1 -1
- package/dist/kotlin/class-declaration.js +3 -2
- package/dist/kotlin/class-methods.js +21 -11
- package/dist/semantics/forms/by-name.js +18 -4
- package/dist/semantics/lang.js +17 -1
- package/dist/swift/class-accessors.js +1 -1
- package/dist/swift/class-declaration.js +3 -2
- package/dist/swift/class-methods.js +16 -1
- package/dist/swift/placement.js +6 -0
- package/dist/swift/protocols.js +25 -4
- package/kit-apple/Sources/NativeScriptKit/Core/color.color-common.swift +17 -0
- package/kit-apple/Sources/NativeScriptKit/Core/color.index.ios.swift +60 -0
- package/kit-apple/Sources/NativeScriptKit/Core/kit-index.json +3 -3
- package/kit-apple/Sources/NativeScriptKit/Core/ui.gestures.gestures-common.swift +2 -0
- package/package.json +1 -1
|
@@ -93,7 +93,7 @@ export const classAccessorsMethods = {
|
|
|
93
93
|
target.push(`${pad}${this.accessorJvmNames(cls, n, !!a.set || getterOnly, mod)}${mod}${a.set || getterOnly ? 'var' : 'val'} ${ident(n)}: ${t}`, ...parts);
|
|
94
94
|
// Library mode: read and set by name as well (`node.cssType` of an untyped node), as the prototype's accessor is.
|
|
95
95
|
const own = (a.get ?? a.set);
|
|
96
|
-
if ((this.library || byName || this.membersByName(cls) || this.states.downcastClass(cls) || this.states.byNameClass(cls)) && !isStatic(own) && !ts.isPrivateIdentifier(own.name) && !this.symbolMember(own.name) && (this.memberByName(cls, n) || this.states.byNameMember(cls, n))) {
|
|
96
|
+
if ((this.library || byName || k.droppedProtocolMembers.has(n) || this.membersByName(cls) || this.states.downcastClass(cls) || this.states.byNameClass(cls)) && !isStatic(own) && !ts.isPrivateIdentifier(own.name) && !this.symbolMember(own.name) && (k.droppedProtocolMembers.has(n) || this.memberByName(cls, n) || this.states.byNameMember(cls, n))) {
|
|
97
97
|
// A write by name gives the setter what script gave (`style="color: red"` and `color="red"` from the Builder); one
|
|
98
98
|
// passing it to another object's member (`this.style.color = value`) passes it on by name, as that member converts it.
|
|
99
99
|
const forwarded = a.set && !takes ? forwardedSetter(a.set) : null;
|
|
@@ -5,7 +5,7 @@ import ts from 'typescript';
|
|
|
5
5
|
import { ERRORS } from "../semantics/globals.js";
|
|
6
6
|
import { OBJECT_TO_STRING, ident, kotlinString, lambda, optionalType, RT } from "./syntax.js";
|
|
7
7
|
import { UNKEYED, isPropertyField, memberPlanOf, notesNull, nullNames, definedNamesOf } from "../semantics/shapes.js";
|
|
8
|
-
import { implementedInterfaces, initializedNull } from "../semantics/lang.js";
|
|
8
|
+
import { droppedProtocolMemberNames, implementedInterfaces, initializedNull } from "../semantics/lang.js";
|
|
9
9
|
import { hasModifier } from "../semantics/ast.js";
|
|
10
10
|
import { isStatic } from "../semantics/throws.js";
|
|
11
11
|
import { isCoreDeclaration, isShimDeclaration } from "../program/core-facts.js";
|
|
@@ -122,6 +122,7 @@ export const classDeclMethods = {
|
|
|
122
122
|
const witnesses = [];
|
|
123
123
|
const notOverrides = new Set();
|
|
124
124
|
const implemented = this.implementedProtocols(cls, witnesses, notOverrides);
|
|
125
|
+
const droppedProtocolMembers = droppedProtocolMemberNames(c, cls, this.protocols, implemented, (i) => this.implementedName(i), (i, t, n) => this.untranslatedInterface(i) || this.declaredOnlyInterface(i) || (!!this.library && (t.getSymbol()?.declarations ?? []).every((d) => d.getSourceFile().isDeclarationFile)) || this.declaresInterface(c.getTypeAtLocation(cls.name ?? cls), n));
|
|
125
126
|
for (const i of implemented)
|
|
126
127
|
this.used.add(i);
|
|
127
128
|
const ownToString = layout.toString;
|
|
@@ -160,7 +161,7 @@ export const classDeclMethods = {
|
|
|
160
161
|
// An app class extending the generated kit's (a page's view model, a custom view): read by name as core reads it (bindings, the Builder).
|
|
161
162
|
const byName = !this.library && ((this.generatedKit && !!kitRoot) || this.appMembersByName);
|
|
162
163
|
const literalMade = ts.isClassDeclaration(cls) && this.literalMade(cls);
|
|
163
|
-
return { cls, name, layout, plugin, appBase, base, kitRoot, collection, isError, isView, abstract, open, memberOpen, expando, witnesses, overridden, interfaceFields, byName, literalMade, supertypes, lines: [], statics: [], fields: [], narrowedParams: new Map(), initsAfterParamProps: [], symbolFields: [], symbolKeyInits: [], symKeyCount: 0, fieldStarts: [], dynAccessors: [], dynMethods: [] };
|
|
164
|
+
return { cls, name, layout, plugin, appBase, base, kitRoot, collection, isError, isView, abstract, open, memberOpen, expando, witnesses, overridden, interfaceFields, droppedProtocolMembers, byName, literalMade, supertypes, lines: [], statics: [], fields: [], narrowedParams: new Map(), initsAfterParamProps: [], symbolFields: [], symbolKeyInits: [], symKeyCount: 0, fieldStarts: [], dynAccessors: [], dynMethods: [] };
|
|
164
165
|
},
|
|
165
166
|
/** Evaluates a non-fixed computed symbol key once at class definition time into a companion property. */
|
|
166
167
|
capturedSymbolKey(k, keyCode) {
|
|
@@ -197,29 +197,39 @@ export const classMethodsMethods = {
|
|
|
197
197
|
return false;
|
|
198
198
|
},
|
|
199
199
|
methodsByNameCode(k) {
|
|
200
|
-
const { cls, plugin, kitRoot, byName, dynMethods } = k;
|
|
200
|
+
const { cls, plugin, kitRoot, byName, droppedProtocolMembers, dynMethods } = k;
|
|
201
201
|
const { inherited } = k.layout;
|
|
202
202
|
// Library mode: every method of the class is read by name as well (`font.getAndroidTypeface()` on an untyped font), overrides included.
|
|
203
|
-
if (this.library || byName || this.membersByName(cls) || this.states.downcastClass(cls) || this.states.byNameClass(cls)) {
|
|
204
|
-
|
|
205
|
-
if (!
|
|
206
|
-
|
|
203
|
+
if (this.library || byName || droppedProtocolMembers.size > 0 || this.membersByName(cls) || this.states.downcastClass(cls) || this.states.byNameClass(cls)) {
|
|
204
|
+
const addMethod = (m) => {
|
|
205
|
+
if (!m.body || isStatic(m) || ts.isComputedPropertyName(m.name) || ts.isPrivateIdentifier(m.name) || m.parameters.some((p) => p.dotDotDotToken) || this.readsArguments(m))
|
|
206
|
+
return;
|
|
207
207
|
const n = m.name.getText();
|
|
208
208
|
if (dynMethods.some((d) => d.name === n && !d.key) || n === 'toString' || n === 'equals')
|
|
209
|
-
|
|
210
|
-
if (!this.memberByName(cls, n) && !this.states.byNameMember(cls, n))
|
|
211
|
-
|
|
209
|
+
return;
|
|
210
|
+
if (!droppedProtocolMembers.has(n) && !this.memberByName(cls, n) && !this.states.byNameMember(cls, n))
|
|
211
|
+
return;
|
|
212
212
|
// A plugin's method nothing names is not compiled; one overriding the kit's is read through the kit's own table.
|
|
213
213
|
if (plugin && !this.library && !inherited.has(n) && !(kitRoot && this.core?.kitMember(kitRoot, n)) && !this.facts.isNamed(n))
|
|
214
|
-
|
|
214
|
+
return;
|
|
215
215
|
if (!this.library && kitRoot && this.core?.kitMember(kitRoot, n))
|
|
216
|
-
|
|
216
|
+
return;
|
|
217
217
|
let root = m;
|
|
218
218
|
for (let up = this.inheritedMethod(cls, n); up; up = this.inheritedMethod(up.parent, n))
|
|
219
219
|
root = up;
|
|
220
220
|
if (root.parameters.length !== m.parameters.length)
|
|
221
|
-
|
|
221
|
+
return;
|
|
222
222
|
dynMethods.push({ name: n, params: root.parameters.map((p) => this.paramType(p)), defaults: root.parameters.map((p) => (this.constantDefault(p) ? this.stored(p.initializer, p, this.paramType(p)) : undefined)), ret: this.returnTypeOf(root) });
|
|
223
|
+
};
|
|
224
|
+
for (const m of cls.members)
|
|
225
|
+
if (ts.isMethodDeclaration(m))
|
|
226
|
+
addMethod(m);
|
|
227
|
+
for (const n of droppedProtocolMembers) {
|
|
228
|
+
if (dynMethods.some((d) => d.name === n && !d.key))
|
|
229
|
+
continue;
|
|
230
|
+
const inh = this.inheritedMethod(cls, n);
|
|
231
|
+
if (inh)
|
|
232
|
+
addMethod(inh);
|
|
223
233
|
}
|
|
224
234
|
}
|
|
225
235
|
},
|
|
@@ -4,6 +4,7 @@ import { O, U, declarationFile, hasStatic, unionOfObjects, untyped } from "./flo
|
|
|
4
4
|
import { LIB_FILE, isTemplateMethod } from "../trust.js";
|
|
5
5
|
import { implementedInterfaces, literalKey, mergedInterfaceMemberOf } from "../lang.js";
|
|
6
6
|
import { programBase } from "../classes.js";
|
|
7
|
+
import { hasMappedIntersection } from "../types.js";
|
|
7
8
|
export const byNameCallsMethods = {
|
|
8
9
|
/**
|
|
9
10
|
* Members the framework may call where the program can't see (`FrameworkModel.calledByFramework`), but the template
|
|
@@ -119,11 +120,21 @@ export const byNameCallsMethods = {
|
|
|
119
120
|
}
|
|
120
121
|
}
|
|
121
122
|
};
|
|
123
|
+
const erasedUntyped = (t) => {
|
|
124
|
+
if (untyped(t))
|
|
125
|
+
return true;
|
|
126
|
+
const n = c.getNonNullableType(t);
|
|
127
|
+
return untyped(n) || (n.isIntersection() && hasMappedIntersection(n));
|
|
128
|
+
};
|
|
122
129
|
const open = (slots) => slots.filter((s) => {
|
|
123
130
|
const r = this.find(s);
|
|
124
131
|
// A part's type is the value's own (an array literal's elements), not the type its holder declares.
|
|
125
|
-
return !!r.type && (
|
|
132
|
+
return !!r.type && (erasedUntyped(r.type) || (!!r.decl && unionOfObjects(r.type))) && !(r.decl && LIB_FILE.test(r.decl.getSourceFile().fileName));
|
|
126
133
|
});
|
|
134
|
+
// A class implementing a mapped-type intersection erased to Any? (`implements Ds3ControllerAsync`) is called dynamically by name.
|
|
135
|
+
for (const cls of this.classes)
|
|
136
|
+
if (implementedInterfaces(c, cls).some((i) => erasedUntyped(c.getTypeAtLocation(i))))
|
|
137
|
+
found.add(cls);
|
|
127
138
|
// Placed by generated code, or only into `bindingContext`s and the generated code's own slots.
|
|
128
139
|
const byKeys = (x, slots) => !!keyedFile && (keyedFile(x.getSourceFile()) || (!this.heldUntyped.has(x) && slots.every((s) => keyedSlot(s.decl))));
|
|
129
140
|
for (const [x, slots] of this.placed) {
|
|
@@ -134,7 +145,7 @@ export const byNameCallsMethods = {
|
|
|
134
145
|
for (const x of this.placedUntyped)
|
|
135
146
|
classOf(x, byKeys(x, open(this.placed.get(x) ?? [])));
|
|
136
147
|
const visit = (n) => {
|
|
137
|
-
if ((ts.isAsExpression(n) || ts.isTypeAssertionExpression(n)) &&
|
|
148
|
+
if ((ts.isAsExpression(n) || ts.isTypeAssertionExpression(n)) && erasedUntyped(c.getTypeAtLocation(n)))
|
|
138
149
|
classOf(n.expression);
|
|
139
150
|
if (ts.isElementAccessExpression(n)) {
|
|
140
151
|
const key = ts.skipOuterExpressions(n.argumentExpression);
|
|
@@ -325,7 +336,10 @@ export const byNameCallsMethods = {
|
|
|
325
336
|
for (const raw of rawTypes) {
|
|
326
337
|
const wt = c.getNonNullableType(raw);
|
|
327
338
|
const wanted = wt.getSymbol();
|
|
328
|
-
|
|
339
|
+
const intersection = wt.isIntersection() && !wt.types.some((u) => (u.getSymbol()?.flags ?? 0) & ts.SymbolFlags.Class);
|
|
340
|
+
if (!intersection && (!wanted || !(wanted.flags & (ts.SymbolFlags.TypeLiteral | ts.SymbolFlags.Interface)) || wanted.flags & ts.SymbolFlags.Class))
|
|
341
|
+
continue;
|
|
342
|
+
if (wt.getCallSignatures().length || wt.getConstructSignatures().length || !wt.getProperties().length)
|
|
329
343
|
continue;
|
|
330
344
|
for (const part of t.isUnion() ? t.types : [t]) {
|
|
331
345
|
const cls = part.getSymbol()?.declarations?.find((d) => ts.isClassLike(d) && !declarationFile(d));
|
|
@@ -334,7 +348,7 @@ export const byNameCallsMethods = {
|
|
|
334
348
|
this.viewedStatic.add(b);
|
|
335
349
|
continue;
|
|
336
350
|
}
|
|
337
|
-
if (!cls || names(cls, wanted))
|
|
351
|
+
if (!cls || (wanted && names(cls, wanted)))
|
|
338
352
|
continue;
|
|
339
353
|
const keys = wt.getProperties().map((p) => p.name);
|
|
340
354
|
for (let b = cls; b; b = programBase(b, c)) {
|
package/dist/semantics/lang.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import { isSymbolAsyncIterator, isSymbolIterator } from "./ast.js";
|
|
2
|
+
import { isLibDeclaration, isSymbolAsyncIterator, isSymbolIterator } from "./ast.js";
|
|
3
3
|
import { SHIM_GLOBAL_OBJECT_VARS } from "./globals.js";
|
|
4
|
+
import { implementedInterfaces } from "./lang/members.js";
|
|
4
5
|
export { evolvingArrayRead, evolvingArrayType, evolvingElementContext, spreadOperand, openSpreadType, intersectionAliasMembers, iterationThrows, iteratedType, iteratesCheckedResult } from "./lang/arrays.js";
|
|
5
6
|
export { unsafeReceiver, uncheckedMatch, leadingNeverRead, redeclaredBeside, thisArgCall, withoutThisArg, thisArgBound, takesReceiver, ignoresThisArg } from "./lang/this-args.js";
|
|
6
7
|
export { isAmbientClass, ambientBase, ambientAddedMemberOf, implementedInterfaces, runtimeTypeName, mergedInterfaceMemberOf, augmentedPropertyRead, optionalBodilessMethod, undeclaredMemberOf, classesHeldUntyped, hasStatic, admitsUndefined, assertedOperand, undefinedLiteral, onlyUndefined, resultsAreUndefinedElements, implementedInterfaceDeclarations, accessedDeclaration, memberOwner, namesOwnTypeParameter } from "./lang/members.js";
|
|
@@ -246,3 +247,18 @@ export function substitutedExpr(subst, e, branchingOnly = false) {
|
|
|
246
247
|
return null;
|
|
247
248
|
return { bare, code };
|
|
248
249
|
}
|
|
250
|
+
/** Member names of declared TypeScript interfaces left out of a class's native conformances, so dynamic views (`fromJS` / `init(jsObject:)`) can read them by name. */
|
|
251
|
+
export function droppedProtocolMemberNames(checker, cls, protocols, implemented, ifaceName, skipped) {
|
|
252
|
+
const out = new Set();
|
|
253
|
+
for (const i of implementedInterfaces(checker, cls)) {
|
|
254
|
+
const t = checker.getTypeAtLocation(i);
|
|
255
|
+
if (!isEmittedInterface(t) || isLibDeclaration(t.getSymbol()?.declarations?.[0]))
|
|
256
|
+
continue;
|
|
257
|
+
const name = ifaceName(i);
|
|
258
|
+
if (!protocols.has(name) || implemented.includes(name) || skipped(i, t, name))
|
|
259
|
+
continue;
|
|
260
|
+
for (const p of t.getProperties())
|
|
261
|
+
out.add(p.name);
|
|
262
|
+
}
|
|
263
|
+
return out;
|
|
264
|
+
}
|
|
@@ -80,7 +80,7 @@ export const classAccessorsMethods = {
|
|
|
80
80
|
this.declare(n, { kind: 'var', mods, type: declared, throws: !!a.get && !reported && this.throwsInfo.fn(a.get) });
|
|
81
81
|
// A plugin's objects are read untyped too (`navigator.gpu.native`): their accessors by name.
|
|
82
82
|
const own = (a.get ?? a.set);
|
|
83
|
-
if (this.byNameAccessor(cls, own) && !ts.isPrivateIdentifier(own.name)) {
|
|
83
|
+
if ((this.byNameAccessor(cls, own) || k.droppedProtocolMembers.has(n)) && !ts.isPrivateIdentifier(own.name)) {
|
|
84
84
|
const getThrows = !!a.get && this.throwsInfo.fn(a.get) && !reported;
|
|
85
85
|
const read = getThrows ? this.marks.orNil(`${RT.jsReported} { try self.${ident(n)} }`) : `self.${ident(n)}`;
|
|
86
86
|
const stored = () => (declared.endsWith('!') ? this.fromAny('newValue', declared.replace(/!$/, '?')) : isKit(spelledType(declared), 'JSNullish') ? `(${RT.jsConverted}(newValue, to: ${declared}.self) ?? nil)` : this.fromAnyCode('newValue', declared, true));
|
|
@@ -5,7 +5,7 @@ import { atLossSite, HELD_LOSS } from "../semantics/losses.js";
|
|
|
5
5
|
import { ERRORS } from "../semantics/globals.js";
|
|
6
6
|
import { NONISOLATED_DEINIT, ident, swiftString, RT } from "./syntax.js";
|
|
7
7
|
import { UNKEYED, memberPlanOf, notesNull, nullNames, definedNamesOf } from "../semantics/shapes.js";
|
|
8
|
-
import { initializedNull } from "../semantics/lang.js";
|
|
8
|
+
import { droppedProtocolMemberNames, initializedNull } from "../semantics/lang.js";
|
|
9
9
|
import { isStatic } from "../semantics/throws.js";
|
|
10
10
|
import { isCoreDeclaration, isShimDeclaration } from "../program/core-facts.js";
|
|
11
11
|
import { classExprCaptures, classExprScriptName, programBase } from "../semantics/classes.js";
|
|
@@ -111,6 +111,7 @@ export const classDeclMethods = {
|
|
|
111
111
|
// The library's interfaces (`Iterable<T>`, `Iterator<T>`) are protocols of the kit's, conformed to below.
|
|
112
112
|
const witnesses = [];
|
|
113
113
|
const { named, met, implemented } = this.implementedProtocols(cls, kitRoot, witnesses);
|
|
114
|
+
const droppedProtocolMembers = droppedProtocolMemberNames(c, cls, this.protocols, implemented, (i) => this.heritageName(i), (_, t, n) => this.uncompiledType(t) || (t.getSymbol()?.declarations ?? []).every((d) => d.getSourceFile().isDeclarationFile && (this.library || !isCoreDeclaration(d) || !this.core.has(n))) || this.conformsToProtocol(cls, n));
|
|
114
115
|
// What a protocol requires the class reads without throwing: a getter that throws reports instead.
|
|
115
116
|
const required = new Set([...named, ...met].filter((i) => implemented.includes(i.name)).flatMap((i) => i.type.getProperties().map((p) => p.name)));
|
|
116
117
|
const conformances = [...(base ? [base] : []), ...(collection && !appBase && !implemented.length ? ['JSDynamic'] : []), ...implemented];
|
|
@@ -130,7 +131,7 @@ export const classDeclMethods = {
|
|
|
130
131
|
conformances.push('JSToJSONConvertible');
|
|
131
132
|
implicitlyCalled.add('toJSON');
|
|
132
133
|
}
|
|
133
|
-
return { cls, name, layout, heritage, appBase, base, kitRoot, collection, isError, expando, isView, implemented, witnesses, required, conformances, implicitlyCalled, lines: [''], fieldInits: [], fields: [], paramPropValues: new Map(), symbolFields: [], symbolMethods: [], keyInits: [], symKeyCount: 0, dynAccessors: [], dynMethods: [] };
|
|
134
|
+
return { cls, name, layout, heritage, appBase, base, kitRoot, collection, isError, expando, isView, implemented, droppedProtocolMembers, witnesses, required, conformances, implicitlyCalled, lines: [''], fieldInits: [], fields: [], paramPropValues: new Map(), symbolFields: [], symbolMethods: [], keyInits: [], symKeyCount: 0, dynAccessors: [], dynMethods: [] };
|
|
134
135
|
},
|
|
135
136
|
conversionMembers(k) {
|
|
136
137
|
const { cls, layout, lines } = k;
|
|
@@ -160,6 +160,21 @@ export const classMethodsMethods = {
|
|
|
160
160
|
methodMembers(k) {
|
|
161
161
|
for (const m of k.cls.members)
|
|
162
162
|
this.methodMember(k, m);
|
|
163
|
+
for (const n of k.droppedProtocolMembers) {
|
|
164
|
+
if (k.dynMethods.some((d) => d.name === n))
|
|
165
|
+
continue;
|
|
166
|
+
const inh = this.inheritedMethod(k.cls, n);
|
|
167
|
+
if (!inh || !inh.body || isStatic(inh) || ts.isPrivateIdentifier(inh.name))
|
|
168
|
+
continue;
|
|
169
|
+
const restAt = inh.parameters.findIndex((p) => p.dotDotDotToken);
|
|
170
|
+
const generic = !this.library && !this.erasesGenerics(inh) && !!inh.typeParameters?.some((p) => !this.erasesTypeParameter(p));
|
|
171
|
+
if ((restAt >= 0 && restAt !== inh.parameters.length - 1) || generic)
|
|
172
|
+
continue;
|
|
173
|
+
const sig = this.emittedSignature(inh);
|
|
174
|
+
const plain = (t) => t.replace(/^\((any .*)\)!$/, '$1?').replace(/!$/, '?');
|
|
175
|
+
const params = this.readsArguments(inh) ? ['JSRest<Any?>'] : sig.params.map((p, idx) => (idx === restAt ? `JSRest<${/^JSArray<(.*)>$/.exec(plain(p.type))?.[1] ?? 'Any?'}>` : isFunctionType(p.type) ? `@escaping ${p.type}` : plain(p.type)));
|
|
176
|
+
k.dynMethods.push({ name: n, type: `(${params.join(', ')}) throws -> ${plain(sig.ret)}`, available: this.gatedFunctions.get(inh), length: scriptLength(inh) });
|
|
177
|
+
}
|
|
163
178
|
},
|
|
164
179
|
methodMember(k, m) {
|
|
165
180
|
const { cls, kitRoot, lines } = k;
|
|
@@ -222,7 +237,7 @@ export const classMethodsMethods = {
|
|
|
222
237
|
lines.push(' ' + this.memberFunc(m, ident(nonVirtualName(n, cls.name?.text ?? k.name)), 'final '));
|
|
223
238
|
// A plugin's objects are read untyped too (`handler.attachToView(view)` on an `any`): their methods by name.
|
|
224
239
|
const restAt = m.parameters.findIndex((p) => p.dotDotDotToken);
|
|
225
|
-
if ((((this.pluginFiles.has(cls.getSourceFile().fileName) || this.appMembersByName || this.states.downcastClass(cls) || this.states.byNameClass(cls)) && this.states.byNameMember(cls, n)) || this.states.viewedMember(cls, n)) && !isStatic(m) && !ts.isPrivateIdentifier(m.name) && (restAt < 0 || restAt === m.parameters.length - 1) && !extra.length && !generic) {
|
|
240
|
+
if ((((this.pluginFiles.has(cls.getSourceFile().fileName) || this.appMembersByName || this.states.downcastClass(cls) || this.states.byNameClass(cls)) && this.states.byNameMember(cls, n)) || this.states.viewedMember(cls, n) || k.droppedProtocolMembers.has(n)) && !isStatic(m) && !ts.isPrivateIdentifier(m.name) && (restAt < 0 || restAt === m.parameters.length - 1) && !extra.length && !generic) {
|
|
226
241
|
// The signature Swift has for the method: an override's is its root's.
|
|
227
242
|
const sig = this.emittedSignature(m);
|
|
228
243
|
const plain = (t) => t.replace(/^\((any .*)\)!$/, '$1?').replace(/!$/, '?');
|
package/dist/swift/placement.js
CHANGED
|
@@ -694,6 +694,12 @@ export const placementMethods = {
|
|
|
694
694
|
const viewedFrom = this.classNamed(source.replace(/[?!]$/, ''));
|
|
695
695
|
if (viewedFrom && this.states.viewedClass(viewedFrom) && source.replace(/[?!]$/, '') !== target.replace(/[?!]$/, '') && this.isObjectShape(target.replace(/[?!]$/, '')))
|
|
696
696
|
return this.convert(this.expr(e), source, target);
|
|
697
|
+
// A class whose declared protocol was dropped by `protocolWitnesses`: wrap through `IFaceObject(jsObject:)`.
|
|
698
|
+
const targetProto = target.replace(/[?!]$/, '');
|
|
699
|
+
if (!this.library && viewedFrom && source.replace(/[?!]$/, '') !== targetProto && this.protocols.has(targetProto) && this.facts.hasInterface(this, this.interfaces, (d, s) => this.topName(d, s), targetProto) && !this.conformsToProtocol(viewedFrom, targetProto)) {
|
|
700
|
+
const wrapped = `${targetProto}Object(jsObject: ${this.expr(e)})`;
|
|
701
|
+
return isOptional(source) || source.endsWith('!') ? this.marks.unwrappedIf(`(${this.expr(e)}).map { ${targetProto}Object(jsObject: $0) }`, !(isOptional(target) || target.endsWith('!'))) : wrapped;
|
|
702
|
+
}
|
|
697
703
|
const viewedStatics = /^(\w+)\.Type$/.exec(source)?.[1];
|
|
698
704
|
if (viewedStatics && this.classNamed(viewedStatics) && this.states.viewedStatics(this.classNamed(viewedStatics)) && /^\w+$/.test(target) && this.isObjectShape(target))
|
|
699
705
|
return this.viewOf(target, this.expr(e));
|
package/dist/swift/protocols.js
CHANGED
|
@@ -49,6 +49,24 @@ export const protocolsMethods = {
|
|
|
49
49
|
this.used.add(i);
|
|
50
50
|
return { named, met, implemented };
|
|
51
51
|
},
|
|
52
|
+
/** Whether `cls` (or an app base class) conforms natively to protocol `name` in Swift. */
|
|
53
|
+
conformsToProtocol(cls, name) {
|
|
54
|
+
for (let c = cls; c; c = this.sourceBase(c)) {
|
|
55
|
+
const kitRoot = this.kitRootOf(c);
|
|
56
|
+
const named = implementedInterfaces(this.checker, c).map((i) => ({ name: this.heritageName(i), type: this.checker.getTypeAtLocation(i) }));
|
|
57
|
+
const met = [...(this.structural.get(c) ?? [])].map((d) => ({ name: this.topName(d, d.name.text), type: this.checker.getTypeAtLocation(d.name) }));
|
|
58
|
+
const hit = [...named, ...met].find((i) => i.name === name);
|
|
59
|
+
if (!hit || !isEmittedInterface(hit.type) || isLibDeclaration(hit.type.getSymbol()?.declarations?.[0]) || this.uncompiledType(hit.type))
|
|
60
|
+
continue;
|
|
61
|
+
if ((hit.type.getSymbol()?.declarations ?? []).every((d) => d.getSourceFile().isDeclarationFile && (this.library || !isCoreDeclaration(d) || !this.core.has(hit.name))))
|
|
62
|
+
continue;
|
|
63
|
+
if (kitRoot && hit.type.getProperties().some((p) => !!this.core.kitMember(kitRoot, p.name)))
|
|
64
|
+
continue;
|
|
65
|
+
if (this.protocolWitnesses(c, hit.name, hit.type, [], false))
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
},
|
|
52
70
|
/**
|
|
53
71
|
* A component class's conformance to the app interfaces it implements, as an extension of it. Every app protocol
|
|
54
72
|
* refines JSDynamic, which here reads and writes the interfaces' fields only.
|
|
@@ -96,7 +114,7 @@ export const protocolsMethods = {
|
|
|
96
114
|
* `handlerError(error: Error)`) conforms through a witness of the protocol's
|
|
97
115
|
* signature that calls it; any other difference leaves the protocol out.
|
|
98
116
|
*/
|
|
99
|
-
protocolWitnesses(cls, name, type, out) {
|
|
117
|
+
protocolWitnesses(cls, name, type, out, record = true) {
|
|
100
118
|
const decl = type.getSymbol()?.declarations?.find(ts.isInterfaceDeclaration);
|
|
101
119
|
if (!decl || !this.protocols.has(name))
|
|
102
120
|
return true;
|
|
@@ -144,10 +162,13 @@ export const protocolsMethods = {
|
|
|
144
162
|
const args = want.map((_, k) => `__p${k}`);
|
|
145
163
|
const call = this.marks.tryCode(`self.${ident(name)}(${args.map((a, k) => (have[k] === want[k] ? a : erased(have[k], k) ? this.marks.ownTried(`${RT.jsChecked}(${a}, ${metatype(have[k])})`) : `${a} as Any?`)).join(', ')})`);
|
|
146
164
|
const body = ret === 'Void' ? call : ownRet === 'Void' ? `${call}; return nil` : byResult ? `let __r: ${ownRet} = ${call}; return __r` : `return ${call}`;
|
|
147
|
-
|
|
148
|
-
|
|
165
|
+
if (record) {
|
|
166
|
+
added.push(` func ${ident(name)}(${want.map((t, k) => `_ ${args[k]}: ${t}`).join(', ')}) throws${ret === 'Void' ? '' : ` -> ${ret}`} { ${body} }`);
|
|
167
|
+
this.declare(name, { kind: 'func', params: want.map((t, k) => `_ ${args[k]}: ${t}`).join(', '), throws: true, type: ret });
|
|
168
|
+
}
|
|
149
169
|
}
|
|
150
|
-
|
|
170
|
+
if (record)
|
|
171
|
+
out.push(...added);
|
|
151
172
|
return true;
|
|
152
173
|
},
|
|
153
174
|
};
|
|
@@ -599,8 +599,24 @@ open class ColorBase: JSDynamic, JSStringConvertible, JSExpando, JSKeysMade, JSS
|
|
|
599
599
|
open subscript(jsKey key: String) -> Any? {
|
|
600
600
|
get {
|
|
601
601
|
switch key.utf8.count {
|
|
602
|
+
case 1:
|
|
603
|
+
switch key {
|
|
604
|
+
case "a": return self.a
|
|
605
|
+
case "r": return self.r
|
|
606
|
+
case "g": return self.g
|
|
607
|
+
case "b": return self.b
|
|
608
|
+
default: break
|
|
609
|
+
}
|
|
610
|
+
case 3:
|
|
611
|
+
switch key {
|
|
612
|
+
case "hex": return self.hex
|
|
613
|
+
case "ios": return self.ios
|
|
614
|
+
default: break
|
|
615
|
+
}
|
|
602
616
|
case 4:
|
|
603
617
|
switch key {
|
|
618
|
+
case "argb": return self.argb
|
|
619
|
+
case "name": return self.name
|
|
604
620
|
case "spin": return FunctionCell_Double_to_ColorBaseOpt.script("spin", 1, self.spin)
|
|
605
621
|
default: break
|
|
606
622
|
}
|
|
@@ -625,6 +641,7 @@ open class ColorBase: JSDynamic, JSStringConvertible, JSExpando, JSKeysMade, JSS
|
|
|
625
641
|
}
|
|
626
642
|
case 7:
|
|
627
643
|
switch key {
|
|
644
|
+
case "android": return self.android
|
|
628
645
|
case "isLight": return FunctionCell_none_to_Bool.script("isLight", 0, self.isLight)
|
|
629
646
|
case "lighten": return FunctionCell_Double_to_ColorBaseOpt.script("lighten", 1, self.lighten)
|
|
630
647
|
default: break
|
|
@@ -59,11 +59,71 @@ open class Color: ColorBase {
|
|
|
59
59
|
open override subscript(jsKey key: String) -> Any? {
|
|
60
60
|
get {
|
|
61
61
|
switch key.utf8.count {
|
|
62
|
+
case 3:
|
|
63
|
+
switch key {
|
|
64
|
+
case "ios": return self.ios
|
|
65
|
+
default: break
|
|
66
|
+
}
|
|
62
67
|
case 4:
|
|
63
68
|
switch key {
|
|
64
69
|
case "_ios":
|
|
65
70
|
if !(jsMadeBits0 & (1 << 2) != 0) { return nil }
|
|
66
71
|
return self._ios
|
|
72
|
+
case "spin": return FunctionCell_Double_to_ColorBaseOpt.script("spin", 1, self.spin)
|
|
73
|
+
default: break
|
|
74
|
+
}
|
|
75
|
+
case 5:
|
|
76
|
+
switch key {
|
|
77
|
+
case "toHsl": return FunctionCell_none_to_Object_a_h_s_lOpt.script("toHsl", 0, self.toHsl)
|
|
78
|
+
case "toHsv": return FunctionCell_none_to_Object_a_h_s_vOpt.script("toHsv", 0, self.toHsv)
|
|
79
|
+
default: break
|
|
80
|
+
}
|
|
81
|
+
case 6:
|
|
82
|
+
switch key {
|
|
83
|
+
case "equals": return FunctionCell_AnyOpt_to_Bool.script("equals", 1, self.equals)
|
|
84
|
+
case "isDark": return FunctionCell_none_to_Bool.script("isDark", 0, self.isDark)
|
|
85
|
+
case "darken": return FunctionCell_Double_to_ColorBaseOpt.script("darken", 1, self.darken)
|
|
86
|
+
default: break
|
|
87
|
+
}
|
|
88
|
+
case 7:
|
|
89
|
+
switch key {
|
|
90
|
+
case "isLight": return FunctionCell_none_to_Bool.script("isLight", 0, self.isLight)
|
|
91
|
+
case "lighten": return FunctionCell_Double_to_ColorBaseOpt.script("lighten", 1, self.lighten)
|
|
92
|
+
default: break
|
|
93
|
+
}
|
|
94
|
+
case 8:
|
|
95
|
+
switch key {
|
|
96
|
+
case "setAlpha": return FunctionCell_Double_to_ColorBaseOpt.script("setAlpha", 1, self.setAlpha)
|
|
97
|
+
case "saturate": return FunctionCell_Double_to_ColorBaseOpt.script("saturate", 1, self.saturate)
|
|
98
|
+
case "brighten": return FunctionCell_Double_to_ColorBaseOpt.script("brighten", 1, self.brighten)
|
|
99
|
+
default: break
|
|
100
|
+
}
|
|
101
|
+
case 9:
|
|
102
|
+
switch key {
|
|
103
|
+
case "greyscale": return FunctionCell_none_to_ColorBaseOpt.script("greyscale", 0, self.greyscale)
|
|
104
|
+
default: break
|
|
105
|
+
}
|
|
106
|
+
case 10:
|
|
107
|
+
switch key {
|
|
108
|
+
case "desaturate": return FunctionCell_Double_to_ColorBaseOpt.script("desaturate", 1, self.desaturate)
|
|
109
|
+
case "complement": return FunctionCell_none_to_ColorBaseOpt.script("complement", 0, self.complement)
|
|
110
|
+
default: break
|
|
111
|
+
}
|
|
112
|
+
case 11:
|
|
113
|
+
switch key {
|
|
114
|
+
case "toHslString": return FunctionCell_none_to_String.script("toHslString", 0, self.toHslString)
|
|
115
|
+
case "toHsvString": return FunctionCell_none_to_String.script("toHsvString", 0, self.toHsvString)
|
|
116
|
+
case "toRgbString": return FunctionCell_none_to_String.script("toRgbString", 0, self.toRgbString)
|
|
117
|
+
default: break
|
|
118
|
+
}
|
|
119
|
+
case 12:
|
|
120
|
+
switch key {
|
|
121
|
+
case "getLuminance": return FunctionCell_none_to_Double.script("getLuminance", 0, self.getLuminance)
|
|
122
|
+
default: break
|
|
123
|
+
}
|
|
124
|
+
case 13:
|
|
125
|
+
switch key {
|
|
126
|
+
case "getBrightness": return FunctionCell_none_to_Double.script("getBrightness", 0, self.getBrightness)
|
|
67
127
|
default: break
|
|
68
128
|
}
|
|
69
129
|
default: break
|
|
@@ -1683,7 +1683,7 @@
|
|
|
1683
1683
|
"jsStaticKeys": [{"kind":"var","static":true,"type":"[String]"}],
|
|
1684
1684
|
"subscript": [{"kind":"subscript","type":"Any?","params":[{"label":"jsKey","name":"key","type":"String"}]}]
|
|
1685
1685
|
},
|
|
1686
|
-
"names": ["_ios"],
|
|
1686
|
+
"names": ["_ios","brighten","complement","darken","desaturate","equals","getBrightness","getLuminance","greyscale","ios","isDark","isLight","lighten","saturate","setAlpha","spin","toHsl","toHslString","toHsv","toHsvString","toRgbString"],
|
|
1687
1687
|
"base": "ColorBase"
|
|
1688
1688
|
},
|
|
1689
1689
|
"ColorBase": {
|
|
@@ -1741,7 +1741,7 @@
|
|
|
1741
1741
|
"toRgbString": [{"kind":"func","type":"String","params":[]}],
|
|
1742
1742
|
"toString": [{"kind":"func","type":"String","params":[]}]
|
|
1743
1743
|
},
|
|
1744
|
-
"names": ["_argb","_argbFromString","_name","brighten","complement","darken","desaturate","equals","getBrightness","getLuminance","greyscale","isDark","isLight","lighten","saturate","setAlpha","spin","toHsl","toHslString","toHsv","toHsvString","toRgbString","toString"]
|
|
1744
|
+
"names": ["_argb","_argbFromString","_name","a","android","argb","b","brighten","complement","darken","desaturate","equals","g","getBrightness","getLuminance","greyscale","hex","ios","isDark","isLight","lighten","name","r","saturate","setAlpha","spin","toHsl","toHslString","toHsv","toHsvString","toRgbString","toString"]
|
|
1745
1745
|
},
|
|
1746
1746
|
"Combinator": {
|
|
1747
1747
|
"kind": "enum",
|
|
@@ -13809,7 +13809,7 @@
|
|
|
13809
13809
|
"target": [{"kind":"var","type":"View?"}],
|
|
13810
13810
|
"type": [{"kind":"var","type":"Double"}]
|
|
13811
13811
|
},
|
|
13812
|
-
"names": ["_callback","_context","_target","disconnect","type"]
|
|
13812
|
+
"names": ["_callback","_context","_target","callback","context","disconnect","type"]
|
|
13813
13813
|
},
|
|
13814
13814
|
"GridLayout": {
|
|
13815
13815
|
"kind": "class",
|
|
@@ -99,11 +99,13 @@ open class GesturesObserverBase: JSDynamic, JSExpando, JSKeysMade, JSStaticKeyed
|
|
|
99
99
|
case 7:
|
|
100
100
|
switch key {
|
|
101
101
|
case "_target": return self._target
|
|
102
|
+
case "context": return self.context
|
|
102
103
|
default: break
|
|
103
104
|
}
|
|
104
105
|
case 8:
|
|
105
106
|
switch key {
|
|
106
107
|
case "_context": return self._context
|
|
108
|
+
case "callback": return FunctionCell_AnyOpt_to_Void.scriptOrNil("", 1, self.callback)
|
|
107
109
|
default: break
|
|
108
110
|
}
|
|
109
111
|
case 9:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nstudio/nativescript-compiler",
|
|
3
|
-
"version": "9.2.0-alpha.
|
|
3
|
+
"version": "9.2.0-alpha.16",
|
|
4
4
|
"description": "NativeScript CLI plugin (`ns compile`) and compiler turning a NativeScript app into native Swift (iOS) or Kotlin (Android) with no JavaScript runtime; framework adapters (`@nstudio/nativescript-compiler-<framework>`) compile each framework.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|