@nstudio/nativescript-compiler 9.2.0-alpha.10 → 9.2.0-alpha.11
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/driver/cli.js +2 -0
- package/dist/driver/compile.js +22 -10
- package/dist/driver/unimplemented.js +15 -0
- package/dist/kotlin/access.js +22 -4
- 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/core-api.js +2 -13
- package/dist/kotlin/declarations.js +2 -0
- package/dist/kotlin/expression-statements.js +5 -4
- package/dist/kotlin/functions.js +13 -4
- package/dist/kotlin/global-calls.js +11 -0
- package/dist/kotlin/literals.js +51 -5
- package/dist/kotlin/names.js +2 -2
- package/dist/kotlin/native/api.js +9 -1
- 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/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 +4 -3
- package/dist/kotlin/types.js +6 -6
- package/dist/plugins/native-android.js +7 -3
- 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 +212 -20
- 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/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/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/core-api.js +9 -12
- 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 +53 -6
- 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 +42 -1
- 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 +8 -3
- package/dist/swift/types.js +9 -9
- package/dist/targets/android/build.js +13 -9
- 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/ui_core_view_view_common.kt +1 -3
- package/kit-android/generated/source-lines.json +1 -1
- package/kit-android/src/fromcore/kotlin/org/nativescript/kit/CoreBridge.kt +67 -1
- 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 +24 -146
- package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity2.swift +0 -281
- 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/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 +34 -244
- 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.frame.index.ios.swift +4 -4
- 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 +4 -4
- 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/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/package.json +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/Object_toString_charAt_charCodeAt_concat_indexOf_lastIndexOf_and_44_more_fc25df.swift +0 -481
package/dist/api/ir.js
CHANGED
|
@@ -17,7 +17,13 @@ export function scopeTemplate(nodes, attribute) {
|
|
|
17
17
|
case 'template':
|
|
18
18
|
case 'local':
|
|
19
19
|
case 'let':
|
|
20
|
+
case 'structural':
|
|
21
|
+
case 'bindTemplate':
|
|
20
22
|
return { ...n, body: scopeTemplate(n.body, attribute) };
|
|
23
|
+
case 'component':
|
|
24
|
+
return n.slots ? { ...n, slots: Object.fromEntries(Object.entries(n.slots).map(([k, v]) => [k, scopeTemplate(v, attribute)])) } : n;
|
|
25
|
+
case 'slot':
|
|
26
|
+
return n.fallback ? { ...n, fallback: scopeTemplate(n.fallback, attribute) } : n;
|
|
21
27
|
default:
|
|
22
28
|
return n;
|
|
23
29
|
}
|
|
@@ -25,5 +31,5 @@ export function scopeTemplate(nodes, attribute) {
|
|
|
25
31
|
}
|
|
26
32
|
/** The nodes with each `local` and `let` replaced by its body: what renders where the local is. */
|
|
27
33
|
export function withoutLocals(nodes) {
|
|
28
|
-
return nodes.flatMap((n) => (n.kind === 'local' || n.kind === 'let' ? withoutLocals(n.body) : [n]));
|
|
34
|
+
return nodes.flatMap((n) => (n.kind === 'local' || n.kind === 'let' ? withoutLocals(n.body) : n.kind === 'bindTemplate' ? [] : [n]));
|
|
29
35
|
}
|
package/dist/driver/cli.js
CHANGED
|
@@ -26,6 +26,7 @@ const FLAGS = {
|
|
|
26
26
|
'keep-going': { type: 'boolean', help: "write the project anyway: the platform compiler's errors show what is incomplete" },
|
|
27
27
|
'allow-unimplemented-properties': { type: 'boolean', help: 'warn, not stop, for properties core declares that the kit does not apply (release.allowUnimplementedProperties)' },
|
|
28
28
|
'allow-core-mismatch': { type: 'boolean', help: 'build with an installed core the kit was not generated from (release.allowCoreMismatch)' },
|
|
29
|
+
'allow-plugin-mismatch': { type: 'boolean', help: 'warn, not stop, when an installed plugin differs from its repository source (release.allowPluginMismatch)' },
|
|
29
30
|
'allow-untested-frameworks': { type: 'boolean', help: 'build with framework versions the adapter is not tested with (release.allowUntestedFrameworks)' },
|
|
30
31
|
'skip-toolchain-check': { type: 'boolean', help: 'do not check Xcode, the JDK or the Android SDK first' },
|
|
31
32
|
'no-source-lines': { type: 'boolean', help: 'generated code names no TypeScript source lines' },
|
|
@@ -81,6 +82,7 @@ try {
|
|
|
81
82
|
keepGoing: v['keep-going'],
|
|
82
83
|
allowUnimplementedProperties: v['allow-unimplemented-properties'],
|
|
83
84
|
allowCoreMismatch: v['allow-core-mismatch'],
|
|
85
|
+
allowPluginMismatch: v['allow-plugin-mismatch'],
|
|
84
86
|
allowUntestedFrameworks: v['allow-untested-frameworks'],
|
|
85
87
|
skipToolchainCheck: v['skip-toolchain-check'],
|
|
86
88
|
sourceLines: !v['no-source-lines'],
|
package/dist/driver/compile.js
CHANGED
|
@@ -11,6 +11,7 @@ import { BuildContext } from "../program/build-context.js";
|
|
|
11
11
|
import { clearBuildCaches } from "../program/build-caches.js";
|
|
12
12
|
import { pathAliases } from "../program/app-paths.js";
|
|
13
13
|
import { appImports, reachedFrom, tsconfigIncluded } from "../program/app-modules.js";
|
|
14
|
+
import { loadViteAppPlugins } from "../program/vite-plugins.js";
|
|
14
15
|
import { appDeclarations, createProgram, nodeModules } from "../program/program.js";
|
|
15
16
|
import { corePatchRefusal } from "../program/core-patches.js";
|
|
16
17
|
import { reachability } from "../program/reach.js";
|
|
@@ -99,10 +100,17 @@ export async function compile(o, build = new BuildContext()) {
|
|
|
99
100
|
// `x.ts` beside `x.ios.ts` is the other platforms' module: the platform's own file is the one `./x` resolves to.
|
|
100
101
|
const thisPlatform = platform === 'android' ? '.android.ts' : '.ios.ts';
|
|
101
102
|
const platformSources = files.filter((f) => f.endsWith('.ts') && !f.endsWith('.d.ts') && f !== entry && !/polyfills\.ts$/.test(f) && !otherPlatform.test(f) && !(!/\.(ios|android)\.ts$/.test(f) && files.includes(f.replace(/\.ts$/, thisPlatform))));
|
|
102
|
-
// The app's own specifiers: relative ones and its tsconfig's path aliases (`~/app/x`).
|
|
103
|
-
const
|
|
103
|
+
// The app's own specifiers: relative ones, Vite app-plugin `resolveId` hooks, and its tsconfig's path aliases (`~/app/x`).
|
|
104
|
+
const vitePlugins = await loadViteAppPlugins(app);
|
|
105
|
+
const baseAliased = pathAliases(app);
|
|
106
|
+
const aliased = (spec, importer) => vitePlugins.resolveId(spec, importer) ?? baseAliased(spec);
|
|
104
107
|
const appSpecifier = (spec) => spec.startsWith('.') || aliased(spec) !== undefined;
|
|
105
|
-
const
|
|
108
|
+
const readTransformed = (f) => vitePlugins.transform(readFileSync(f, 'utf8'), f);
|
|
109
|
+
const { importsOf, usedBy, workerScripts, discovered } = appImports(files, aliased, thisPlatform, app, readTransformed);
|
|
110
|
+
if (discovered.length) {
|
|
111
|
+
files.push(...discovered);
|
|
112
|
+
platformSources.push(...discovered.filter((f) => f.endsWith('.ts') && !f.endsWith('.d.ts') && f !== entry && !/polyfills\.ts$/.test(f) && !otherPlatform.test(f)));
|
|
113
|
+
}
|
|
106
114
|
// The modules of the build: what the bundler reaches. Some frameworks' bundle is what the entry imports, lazy routes
|
|
107
115
|
// included; another's, every file its tsconfig.json does not exclude (specs, mocks), and what those import.
|
|
108
116
|
const included = adapter?.reach === 'entry' ? null : tsconfigIncluded(app, appDir);
|
|
@@ -234,7 +242,7 @@ export async function compile(o, build = new BuildContext()) {
|
|
|
234
242
|
];
|
|
235
243
|
const replacements = { ...bindingReplacements, ...pluginReplacements(app, platform) };
|
|
236
244
|
modules.push(...Object.values(replacements).filter((f) => !modules.includes(f)));
|
|
237
|
-
let { checker, program, files: sourceFiles, pluginFiles, resolved, lenient: lenientApp, assignsFields } = createProgram(modules, virtual, platform, undefined, plugins, declarations, replacements, {}, aliased, undefined, build);
|
|
245
|
+
let { checker, program, files: sourceFiles, pluginFiles, resolved, lenient: lenientApp, assignsFields } = createProgram(modules, virtual, platform, undefined, plugins, declarations, replacements, {}, aliased, undefined, build, vitePlugins);
|
|
238
246
|
// The binding contexts the program proves: closures read a proved class's members directly. The page factories build
|
|
239
247
|
// each XML file's tree. The program is made again to type both.
|
|
240
248
|
if (xml && xmlBindings) {
|
|
@@ -296,7 +304,7 @@ export async function compile(o, build = new BuildContext()) {
|
|
|
296
304
|
}
|
|
297
305
|
}
|
|
298
306
|
if (changed)
|
|
299
|
-
({ checker, program, files: sourceFiles, pluginFiles, resolved, lenient: lenientApp, assignsFields } = createProgram(modules, virtual, platform, undefined, plugins, declarations, replacements, {}, aliased, undefined, build));
|
|
307
|
+
({ checker, program, files: sourceFiles, pluginFiles, resolved, lenient: lenientApp, assignsFields } = createProgram(modules, virtual, platform, undefined, plugins, declarations, replacements, {}, aliased, undefined, build, vitePlugins));
|
|
300
308
|
// Nothing parses XML or evaluates an expression at run time: core reads app objects by the keys the XML and app code name.
|
|
301
309
|
if (xmlRunTimeFree) {
|
|
302
310
|
const { planKeys, scriptKeys } = await import("../xml/keys.js");
|
|
@@ -313,8 +321,9 @@ export async function compile(o, build = new BuildContext()) {
|
|
|
313
321
|
writeFileSync(process.env.NS_XML_PLAN, JSON.stringify(xmlPlan(await loadCoreXml(), appDir, xml.xml, program, platform, xml.pageStyles.map((f) => relative(appDir, f).split('\\').join('/'))), null, 1) + '\n');
|
|
314
322
|
}
|
|
315
323
|
const infos = new Map(components.map((c) => {
|
|
316
|
-
const
|
|
317
|
-
|
|
324
|
+
const sf = program.getSourceFile(c.file);
|
|
325
|
+
const cls = sf?.statements.find((s) => ts.isClassDeclaration(s) && s.name?.text === c.name) ?? sf?.statements.find(ts.isClassDeclaration);
|
|
326
|
+
return [c.name, { name: c.name, props: c.props, members: cls ? componentMembersOf(cls, checker) : COMPONENT_MEMBERS, outputs: c.outputs, outputFields: c.outputFields, optional: c.optional, passed: c.passed, fragment: behaviour.fragments && !c.page && isFragment(c.template), setters: c.setters, propAliases: c.propAliases, changes: c.changes, ...(c.doCheck ? { doCheck: true } : {}), ...(c.afterContentInit ? { afterContentInit: true } : {}), ...(c.afterContentChecked ? { afterContentChecked: true } : {}), ...(c.afterViewChecked ? { afterViewChecked: true } : {}), ...(c.slots?.length ? { slots: c.slots } : {}), onPush: c.onPush }];
|
|
318
327
|
}));
|
|
319
328
|
// A component whose template is one fragment component is a fragment too, however deep the chain.
|
|
320
329
|
if (behaviour.fragments) {
|
|
@@ -330,9 +339,10 @@ export async function compile(o, build = new BuildContext()) {
|
|
|
330
339
|
}
|
|
331
340
|
}
|
|
332
341
|
// A closed world: the plugin code the app reaches, checked against what npm installed before it is compiled.
|
|
333
|
-
const appFiles = [...modules, ...components.map((c) => c.file)];
|
|
342
|
+
const appFiles = [...new Set([...modules, ...components.map((c) => c.file)])];
|
|
334
343
|
const { reach, compiled: compiledPlugins } = closedWorld(program, resolved, appFiles, pluginFiles, platform, build);
|
|
335
|
-
|
|
344
|
+
const allowPluginMismatch = !!o.allowPluginMismatch || releaseOptions(app, platform).allowPluginMismatch === true;
|
|
345
|
+
plugins.verify(compiledPlugins, allowPluginMismatch ? (msg) => console.warn(`warning: ${msg} (building anyway: release.allowPluginMismatch)`) : undefined);
|
|
336
346
|
const properties = collectProperties(checker, sourceFiles);
|
|
337
347
|
// The files the translated code says it came from: a component's source for its virtual class, a module's own file for a replacement of it.
|
|
338
348
|
const sourceLines = o.sourceLines === false ? null : new SourceLines(new Map([...components.map((c) => [c.file, componentSource(c)]), ...[...overrides.keys()].map((f) => [f, f])]));
|
|
@@ -342,7 +352,9 @@ export async function compile(o, build = new BuildContext()) {
|
|
|
342
352
|
if (sourceLines)
|
|
343
353
|
sourceLines.name = (file) => sourceName(file);
|
|
344
354
|
// Constructs no compiled release runs, all of them with their TypeScript lines, before anything is translated.
|
|
345
|
-
const
|
|
355
|
+
const pluginSet = new Set(pluginFiles);
|
|
356
|
+
const appSourceFiles = sourceFiles.filter((f) => !pluginSet.has(f.fileName));
|
|
357
|
+
const unsupported = preflight(checker, [...appSourceFiles, ...compiledPlugins.map((f) => program.getSourceFile(f))], sourceLines ? (n) => sourceLines.locate(n) : undefined, (st) => !pluginSet.has(st.getSourceFile().fileName) || reach.keeps(st), (f) => pluginSet.has(f) && !writtenStrict(f, build.adapter));
|
|
346
358
|
if (unsupported.length) {
|
|
347
359
|
console.error(formatPreflight(unsupported));
|
|
348
360
|
for (const f of unsupported)
|
|
@@ -110,6 +110,19 @@ export class PropertyGuard {
|
|
|
110
110
|
for (const a of n.props)
|
|
111
111
|
if (!props.get(n.name)?.includes(a.name))
|
|
112
112
|
check(tag, a.name);
|
|
113
|
+
if (n.slots)
|
|
114
|
+
for (const slotNodes of Object.values(n.slots))
|
|
115
|
+
walk(slotNodes);
|
|
116
|
+
}
|
|
117
|
+
else if (n.kind === 'slot') {
|
|
118
|
+
if (n.fallback)
|
|
119
|
+
walk(n.fallback);
|
|
120
|
+
}
|
|
121
|
+
else if (n.kind === 'componentOutlet' || n.kind === 'templateOutlet') {
|
|
122
|
+
// Dynamic outlets have no static template children.
|
|
123
|
+
}
|
|
124
|
+
else if (n.kind === 'structural' || n.kind === 'bindTemplate') {
|
|
125
|
+
walk(n.body);
|
|
113
126
|
}
|
|
114
127
|
else if (n.kind === 'if')
|
|
115
128
|
for (const b of n.branches)
|
|
@@ -119,6 +132,8 @@ export class PropertyGuard {
|
|
|
119
132
|
}
|
|
120
133
|
};
|
|
121
134
|
walk(c.template);
|
|
135
|
+
for (const t of c.templates ?? [])
|
|
136
|
+
walk(t.body);
|
|
122
137
|
}
|
|
123
138
|
return dedupe(out);
|
|
124
139
|
}
|
package/dist/kotlin/access.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import { heldLoss } from "../semantics/losses.js";
|
|
3
3
|
import ts from 'typescript';
|
|
4
4
|
import { propSignal } from "../semantics/signals.js";
|
|
5
|
-
import { LIB_CONSTANTS, MATH } from "./library.js";
|
|
5
|
+
import { KIT_NAMES_ANDROID, LIB_CONSTANTS, MATH } from "./library.js";
|
|
6
|
+
import { prototypeClassSymbol } from "../semantics/classes.js";
|
|
7
|
+
import { isCoreDeclaration } from "../program/core-facts.js";
|
|
6
8
|
import { mathFunctionValue } from "../semantics/apis/math.js";
|
|
7
9
|
import { CONSOLE } from "../semantics/apis/console.js";
|
|
8
10
|
import { libFunctionValueKind } from "../semantics/apis/statics.js";
|
|
@@ -83,9 +85,14 @@ export const accessMethods = {
|
|
|
83
85
|
// `Function.prototype`: a function doing nothing.
|
|
84
86
|
if (name === 'prototype' && ts.isIdentifier(target) && target.text === 'Function' && this.resolve(target)?.declarations?.every((d) => d.getSourceFile().isDeclarationFile))
|
|
85
87
|
return 'JSFunction { null }';
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
// A class's prototype, the registry's object for it.
|
|
89
|
+
const protoSym = prototypeClassSymbol(target, name, this);
|
|
90
|
+
if (protoSym) {
|
|
91
|
+
const declOnly = protoSym.declarations?.every((d) => d.getSourceFile().isDeclarationFile);
|
|
92
|
+
const clsName = declOnly ? (isCoreDeclaration(protoSym.declarations?.[0]) ? (KIT_NAMES_ANDROID[protoSym.name] ?? protoSym.name) : null) : this.expr(target);
|
|
93
|
+
if (clsName)
|
|
94
|
+
return `JSPrototypes.of(${clsName}::class.java)`;
|
|
95
|
+
}
|
|
89
96
|
if (ts.isIdentifier(target) && isLibGlobal(this, target)) {
|
|
90
97
|
const constant = LIB_CONSTANTS[`${target.text}.${name}`];
|
|
91
98
|
if (constant)
|
|
@@ -103,6 +110,12 @@ export const accessMethods = {
|
|
|
103
110
|
}
|
|
104
111
|
if (libFn === 'fromCharCode')
|
|
105
112
|
return this.convert(`{ __args: JSArray<Double> -> ${RT.jsFromCharCode}(*__args.storage.toDoubleArray()) }`, '(JSArray<Double>) -> String', this.typeOf(e));
|
|
113
|
+
if (libFn === 'fromCodePoint')
|
|
114
|
+
return this.convert(`{ __args: JSArray<Double> -> ${RT.jsFromCodePoint}(*__args.storage.toDoubleArray()) }`, '(JSArray<Double>) -> String', this.typeOf(e));
|
|
115
|
+
if (libFn === 'mathRandom')
|
|
116
|
+
return this.convert('{ Math.random() }', '() -> Double', this.typeOf(e));
|
|
117
|
+
if (libFn === 'mathVariadic')
|
|
118
|
+
return this.convert(`{ __args: JSArray<Double> -> ${name === 'min' ? RT.jsMathMin : RT.jsMathMax}(*__args.storage.toDoubleArray()) }`, '(JSArray<Double>) -> Double', this.typeOf(e));
|
|
106
119
|
if (libFn === 'typedArrayFrom')
|
|
107
120
|
return this.convert(`{ __v: Any? -> JS${target.text}.from(__v) }`, `(Any?) -> JS${target.text}`, this.typeOf(e));
|
|
108
121
|
if (libFn === 'isArray')
|
|
@@ -573,6 +586,11 @@ export const accessMethods = {
|
|
|
573
586
|
const rt = this.typeOf(e);
|
|
574
587
|
return isUntyped(spelledType(rt)) || isWriteTarget(e) ? code : this.fromAnyCode(code, rt, true);
|
|
575
588
|
}
|
|
589
|
+
if (this.typeOf(e.expression) === 'Nothing') {
|
|
590
|
+
const code = `${RT.jsGet}(${this.coerce(e.expression, 'Any?')}, ${this.propertyKey(key)})`;
|
|
591
|
+
const rt = this.typeOf(e);
|
|
592
|
+
return isUntyped(spelledType(rt)) || isWriteTarget(e) ? code : this.fromAnyCode(code, rt, true);
|
|
593
|
+
}
|
|
576
594
|
throw this.error(e, 'indexing this type', 'index-type');
|
|
577
595
|
},
|
|
578
596
|
/** `assertedUntyped`'s cast: to an object type other than the kit's own containers, promises, dates and errors. */
|
package/dist/kotlin/arguments.js
CHANGED
|
@@ -129,6 +129,11 @@ export const argumentsMethods = {
|
|
|
129
129
|
break;
|
|
130
130
|
}
|
|
131
131
|
if (ts.isSpreadElement(a)) {
|
|
132
|
+
if (restAt >= 0 && k >= restAt && !appDeclared) {
|
|
133
|
+
out.push(`*${this.packed(list.slice(k), 'JSArray<Any?>', this.restSlot(e, 'Any?'))}.storage.toTypedArray()`);
|
|
134
|
+
covered = list.length;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
132
137
|
const spread = k === list.length - 1 ? this.spreadArgs(a, k, params, restAt, appDeclared, slot) : null;
|
|
133
138
|
if (!spread)
|
|
134
139
|
throw this.error(a, 'a spread argument');
|
package/dist/kotlin/builtins.js
CHANGED
|
@@ -379,8 +379,6 @@ export const builtinMethods = {
|
|
|
379
379
|
const fn = name === 'replace' ? RT.jsReplace : RT.jsReplaceAll;
|
|
380
380
|
// A function value: called with the match, each group (undefined where it took no part), the match's index and the string.
|
|
381
381
|
if (!(ts.isArrowFunction(second) || ts.isFunctionExpression(second)) && this.checker.getTypeAtLocation(second).getCallSignatures().length) {
|
|
382
|
-
if (name === 'replaceAll')
|
|
383
|
-
throw this.error(e, 'replaceAll with a function');
|
|
384
382
|
// A rest parameter takes the arguments from its position on, which a call by script cannot give it.
|
|
385
383
|
const decl = this.checker.getTypeAtLocation(second).getCallSignatures()[0]?.getDeclaration();
|
|
386
384
|
const restAt = decl && !ts.isJSDocSignature(decl) ? decl.parameters.findIndex((p) => p.dotDotDotToken) : -1;
|
|
@@ -399,8 +397,6 @@ export const builtinMethods = {
|
|
|
399
397
|
}
|
|
400
398
|
if (!(ts.isArrowFunction(second) || ts.isFunctionExpression(second)))
|
|
401
399
|
return `${fn}(${s}, ${r}, ${this.str(second)})`;
|
|
402
|
-
if (name === 'replaceAll')
|
|
403
|
-
throw this.error(e, 'replaceAll with a function');
|
|
404
400
|
// The replacer gets the match, then each group, then the offset.
|
|
405
401
|
const m = this.fresh('__match');
|
|
406
402
|
// The match, each group (undefined where it took no part), the index, the input, then the groups object.
|
package/dist/kotlin/calls.js
CHANGED
|
@@ -3,12 +3,13 @@ import ts from 'typescript';
|
|
|
3
3
|
import { TYPED_ARRAYS, isLibGlobal } from "../semantics/globals.js";
|
|
4
4
|
import { cast, functionTypeParts, ident, isFunctionType, kotlinString, optionalType, splitTopLevel, RT } from "./syntax.js";
|
|
5
5
|
import { assertedReceiverCell, nullishField } from "../semantics/placement.js";
|
|
6
|
-
import { intlConstructor, isObjectToStringCall, literalKey, mergedInterfaceMemberOf, isSelf } from "../semantics/lang.js";
|
|
6
|
+
import { hookedDynamicImport, intlConstructor, isObjectToStringCall, literalKey, mergedInterfaceMemberOf, isSelf } from "../semantics/lang.js";
|
|
7
7
|
import { callableSignal } from "../semantics/signals.js";
|
|
8
8
|
import { isLibDeclaration, isSymbolIterator, implementationOf } from "../semantics/ast.js";
|
|
9
9
|
import { isStatic } from "../semantics/throws.js";
|
|
10
10
|
import { constClassExpr, programBase } from "../semantics/classes.js";
|
|
11
11
|
import { isKit, isNamed, isUntyped, spelledType } from "../semantics/types.js";
|
|
12
|
+
import { isKitInstanceMethod } from "../program/core-facts.js";
|
|
12
13
|
import { globalOp } from "../semantics/apis/globals.js";
|
|
13
14
|
export const callsMethods = {
|
|
14
15
|
arity(e) {
|
|
@@ -95,6 +96,9 @@ export const callsMethods = {
|
|
|
95
96
|
}
|
|
96
97
|
if (callee.kind === ts.SyntaxKind.SuperKeyword)
|
|
97
98
|
throw this.error(e, 'super() outside the start of a constructor');
|
|
99
|
+
const dynImport = hookedDynamicImport(e, this.framework.hooks);
|
|
100
|
+
if (dynImport)
|
|
101
|
+
return dynImport;
|
|
98
102
|
// `getWindow<UIWindow>?.()`: the type arguments are only TypeScript's, and a function declaration is always there.
|
|
99
103
|
const declaredFunction = (x) => ts.isIdentifier(x) && !!this.resolve(x)?.declarations?.some(ts.isFunctionDeclaration);
|
|
100
104
|
if (ts.isExpressionWithTypeArguments(callee) && (!e.questionDotToken || declaredFunction(callee.expression)))
|
|
@@ -105,7 +109,7 @@ export const callsMethods = {
|
|
|
105
109
|
const declaredMethod = ts.isPropertyAccessExpression(callee) && !!this.resolve(callee.name)?.declarations?.some((d) => ts.isMethodDeclaration(d) && !!d.body);
|
|
106
110
|
// `iterator.next?.()`: a method the library declares on a typed value is always there too.
|
|
107
111
|
const libMethod = !this.library && ts.isPropertyAccessExpression(callee) && !this.isAny(callee.expression) && !!this.resolve(callee.name)?.declarations?.length && this.resolve(callee.name).declarations.every((d) => isLibDeclaration(d) && (ts.isMethodSignature(d) || ts.isMethodDeclaration(d)));
|
|
108
|
-
if (e.questionDotToken && !declaredMethod && !libMethod && !this.core
|
|
112
|
+
if (e.questionDotToken && !declaredMethod && !libMethod && !isKitInstanceMethod(this.core, callee) && !declaredFunction(callee) && !(ts.isPropertyAccessExpression(callee) && mergedInterfaceMemberOf(callee, this.checker))) {
|
|
109
113
|
const fn = this.expr(callee);
|
|
110
114
|
// A Java method read untyped (`window.getInsetsController?.()`): called as script calls it.
|
|
111
115
|
if (/^js(Java)?Get(Optional)?\(/.test(fn))
|
|
@@ -7,7 +7,7 @@ import { kitMember } from "../kit/kit-index.js";
|
|
|
7
7
|
import { runtimeKitIndex } from "./core-index.js";
|
|
8
8
|
import { inheritsToString, toStringGivesNonString, uncheckedIteratorResult } from "../semantics/classes.js";
|
|
9
9
|
import { isUntyped, spelledType } from "../semantics/types.js";
|
|
10
|
-
import {
|
|
10
|
+
import { isDirectSymbolMethod } from "../semantics/lang.js";
|
|
11
11
|
export const classMethodsMethods = {
|
|
12
12
|
/**
|
|
13
13
|
* `[fooProperty.setNative](value)`: the class's native setter for that registered property. The generated kit
|
|
@@ -67,8 +67,14 @@ export const classMethodsMethods = {
|
|
|
67
67
|
const keyed = this.symbolMember(m.name);
|
|
68
68
|
if (this.symbolMethodCode(k, m, keyed))
|
|
69
69
|
return;
|
|
70
|
-
if (keyed &&
|
|
71
|
-
|
|
70
|
+
if (keyed && isDirectSymbolMethod(keyed.member)) {
|
|
71
|
+
if (isStatic(m)) {
|
|
72
|
+
this.indent = ' ';
|
|
73
|
+
k.statics.push(' ' + this.func(m, keyed.member));
|
|
74
|
+
this.indent = ' ';
|
|
75
|
+
}
|
|
76
|
+
else
|
|
77
|
+
lines.push(' ' + this.func(m, keyed.member, memberOpen));
|
|
72
78
|
return;
|
|
73
79
|
}
|
|
74
80
|
if (keyed)
|
|
@@ -3,7 +3,7 @@ import ts from 'typescript';
|
|
|
3
3
|
import { atLossSite, HELD_LOSS } from "../semantics/losses.js";
|
|
4
4
|
import { ident, isFunctionType, isNullable, kotlinString, nullishType, optionalType, ownReturns, RT } from "./syntax.js";
|
|
5
5
|
import { UNKEYED, definesDuringConstruction, implementedOptionalMembers, restrictsField, definedField } from "../semantics/shapes.js";
|
|
6
|
-
import { hasModifier, isLibDeclaration } from "../semantics/ast.js";
|
|
6
|
+
import { extendsHeritage, hasModifier, isLibDeclaration, nonSuperStatements } from "../semantics/ast.js";
|
|
7
7
|
import { implementedInterfaces } from "../semantics/lang.js";
|
|
8
8
|
import { isCoreDeclaration } from "../program/core-facts.js";
|
|
9
9
|
import { isStatic } from "../semantics/throws.js";
|
|
@@ -210,18 +210,21 @@ export const componentMethods = {
|
|
|
210
210
|
for (const m of implementedOptionalMembers(cls, this.checker))
|
|
211
211
|
lines.push(` var ${ident(m.name.text)}: ${optionalType(this.typeOf(m))} = null`);
|
|
212
212
|
// The constructor's body runs once every field has its value, as TypeScript's class fields come first.
|
|
213
|
-
|
|
213
|
+
const ctorStmts = nonSuperStatements(ctor);
|
|
214
|
+
if (ctorStmts.length && ctor?.body && ownReturns(ctor.body)) {
|
|
214
215
|
this.returnLabel = '__ctor';
|
|
215
|
-
this.indent = '
|
|
216
|
+
this.indent = ' ';
|
|
216
217
|
try {
|
|
217
|
-
lines.push(` init {\n run __ctor
|
|
218
|
+
lines.push(` init {\n run __ctor@{\n${this.statements(ctorStmts).join('\n')}\n }\n }`);
|
|
218
219
|
}
|
|
219
220
|
finally {
|
|
220
221
|
this.returnLabel = null;
|
|
221
222
|
}
|
|
222
223
|
}
|
|
223
|
-
else if (
|
|
224
|
-
|
|
224
|
+
else if (ctorStmts.length) {
|
|
225
|
+
this.indent = ' ';
|
|
226
|
+
lines.push(` init {\n${this.statements(ctorStmts).join('\n')}\n }`);
|
|
227
|
+
}
|
|
225
228
|
this.indent = '';
|
|
226
229
|
statics.push(...(this.framework.hooks.componentStatics?.(this, cls) ?? []));
|
|
227
230
|
return { params, lines, statics };
|
|
@@ -351,9 +354,11 @@ export const componentMethods = {
|
|
|
351
354
|
const witnesses = [];
|
|
352
355
|
const notOverrides = new Set();
|
|
353
356
|
const appInterface = (n) => this.protocols.has(n) && [...implementedInterfaces(this.checker, cls).map((i) => this.checker.getTypeAtLocation(i).getSymbol()?.declarations?.find(ts.isInterfaceDeclaration)), ...(this.structural.get(cls) ?? [])].some((d) => !!d && this.topName(d, d.name.text) === n && !d.getSourceFile().isDeclarationFile);
|
|
357
|
+
const heritage = extendsHeritage(cls);
|
|
358
|
+
const baseSuper = heritage && this.classPlan(cls).base ? [`${this.type(this.checker.getTypeAtLocation(heritage), heritage)}()`] : [];
|
|
354
359
|
const supertypes = this.implementedProtocols(cls, witnesses, notOverrides).filter(appInterface);
|
|
355
360
|
if (!supertypes.length)
|
|
356
|
-
return { supertypes, overrides: new Set(), lines: [] };
|
|
361
|
+
return { supertypes: baseSuper, overrides: new Set(), lines: [] };
|
|
357
362
|
for (const i of supertypes)
|
|
358
363
|
this.used.add(i);
|
|
359
364
|
const overrides = this.overridden(cls, supertypes);
|
|
@@ -379,7 +384,7 @@ export const componentMethods = {
|
|
|
379
384
|
fields.push({ name: m.name.text, type });
|
|
380
385
|
}
|
|
381
386
|
}
|
|
382
|
-
return { supertypes, overrides, lines: [...witnesses, ...this.dynamicMembers(UNKEYED, { fields, className: cls.name?.text ?? null, accessors })] };
|
|
387
|
+
return { supertypes: [...baseSuper, ...supertypes], overrides, lines: [...witnesses, ...this.dynamicMembers(UNKEYED, { fields, className: cls.name?.text ?? null, accessors })] };
|
|
383
388
|
},
|
|
384
389
|
/**
|
|
385
390
|
* Whether a class can implement an interface. A method whose untyped
|
package/dist/kotlin/core-api.js
CHANGED
|
@@ -7,6 +7,7 @@ import { KIT_NAMES_ANDROID } from "./library.js";
|
|
|
7
7
|
import { functionTypeParts, kotlinString, numberLiteral, splitTopLevel, RT } from "./syntax.js";
|
|
8
8
|
import { KIT_ANDROID } from "../driver/paths.js";
|
|
9
9
|
import { rethrowUnlessRefused } from "../semantics/refusals.js";
|
|
10
|
+
import { isMixinOwnMember } from "../semantics/classes.js";
|
|
10
11
|
import { isUntyped, spelledType } from "../semantics/types.js";
|
|
11
12
|
import { kotlinKitIndex, TOP_LEVEL, NATIVE_MEMBERS, SCRIPT_OBJECTS, KIT } from "./core-index.js";
|
|
12
13
|
/** The native class a core view's `android` is. */
|
|
@@ -138,13 +139,6 @@ export class CoreKotlin extends KitTypes {
|
|
|
138
139
|
}
|
|
139
140
|
return null;
|
|
140
141
|
}
|
|
141
|
-
/** Whether `target.method` is a method the kit declares on target's class (an optional call of it is a plain call). */
|
|
142
|
-
isKitMethod(callee) {
|
|
143
|
-
if (!ts.isPropertyAccessExpression(callee))
|
|
144
|
-
return false;
|
|
145
|
-
const owner = this.owner(callee.expression);
|
|
146
|
-
return !!owner && !owner.isStatic && kitMember(this.index, owner.name, callee.name.text)?.kind === 'func';
|
|
147
|
-
}
|
|
148
142
|
owner(e) {
|
|
149
143
|
const found = this.declaredOwner(e);
|
|
150
144
|
if (!found)
|
|
@@ -253,7 +247,7 @@ export class CoreKotlin extends KitTypes {
|
|
|
253
247
|
* (`Utils.android` of utils/index is utils/native-helper's): that module's object.
|
|
254
248
|
*/
|
|
255
249
|
ownerOf(target, name) {
|
|
256
|
-
let owner = this.
|
|
250
|
+
let owner = isMixinOwnMember(name, this.t.checker, (s) => this.t.mixinOf(s)) ? null : (this.owner(target) ?? this.inheritedOwner(target, name));
|
|
257
251
|
if (owner && !kitMember(this.index, owner.name, name.text))
|
|
258
252
|
owner = this.renamedOwner(owner, name.text) ?? owner;
|
|
259
253
|
if (!owner || !owner.isStatic || !owner.name.startsWith('Core_') || kitMember(this.index, owner.name, name.text))
|
|
@@ -282,11 +276,6 @@ export class CoreKotlin extends KitTypes {
|
|
|
282
276
|
const root = cls && ts.isClassLike(cls) && !cls.getSourceFile().isDeclarationFile ? this.t.kitRootOf(cls) : null;
|
|
283
277
|
return root ? { name: root, isStatic: false } : null;
|
|
284
278
|
}
|
|
285
|
-
/** A member a mixin class declares: the extension it becomes has it by name. */
|
|
286
|
-
mixinOwn(name) {
|
|
287
|
-
const decl = this.t.checker.getSymbolAtLocation(name)?.valueDeclaration;
|
|
288
|
-
return !!decl && ts.isClassDeclaration(decl.parent) && !!this.t.mixinOf(this.t.checker.getSymbolAtLocation(decl.parent.name));
|
|
289
|
-
}
|
|
290
279
|
/**
|
|
291
280
|
* `on`/`off`/`once` with a named function: a function value made once per
|
|
292
281
|
* evaluation has no identity across them, so the kit matches a listener by
|
|
@@ -276,6 +276,8 @@ export const declarationsMethods = {
|
|
|
276
276
|
.filter((x) => x !== el)
|
|
277
277
|
.map((x) => {
|
|
278
278
|
const key = x.propertyName ?? x.name;
|
|
279
|
+
if (ts.isComputedPropertyName(key))
|
|
280
|
+
return this.propertyKey(key.expression);
|
|
279
281
|
if (!ts.isIdentifier(key) && !ts.isStringLiteral(key))
|
|
280
282
|
throw this.error(x, 'a computed key beside an object rest pattern');
|
|
281
283
|
return kotlinString(key.text);
|
|
@@ -37,10 +37,11 @@ export const exprStatementsMethods = {
|
|
|
37
37
|
const replaced = this.patterns.prototypeMethod(e);
|
|
38
38
|
if (replaced) {
|
|
39
39
|
// A Page's native view made by a plugin (gesturehandler's PageLayout): the kit's factory hook, `this` the page.
|
|
40
|
-
if (replaced.target
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
if (replaced.target === 'Page' && replaced.method === 'createNativeView') {
|
|
41
|
+
const ret = this.returnTypeOf(replaced.fn);
|
|
42
|
+
return `Page.nativeViewFactory = fun Page.(): ${ret} ${this.functionBody(replaced.fn, ret, this.indent)}`;
|
|
43
|
+
}
|
|
44
|
+
return `JSPrototypes.of(${replaced.target}::class.java)[${kotlinString(replaced.method)}] = ${this.coerce(replaced.fn, 'Any?')}`;
|
|
44
45
|
}
|
|
45
46
|
// Assigning a class alias its class (`PageLayout = com.….PageLayout`): its uses already name the class.
|
|
46
47
|
if (ts.isBinaryExpression(e) && e.operatorToken.kind === ts.SyntaxKind.EqualsToken && ts.isIdentifier(e.left)) {
|
package/dist/kotlin/functions.js
CHANGED
|
@@ -33,9 +33,12 @@ export const functionsMethods = {
|
|
|
33
33
|
// ---- Functions -----------------------------------------------------------------------------
|
|
34
34
|
/** `override`: an override's, which takes a constant default from the method it overrides. */
|
|
35
35
|
params(fn, closure, override = false) {
|
|
36
|
-
if (this.readsArguments(fn))
|
|
37
|
-
return '__arguments: JSArray<Any?>';
|
|
38
36
|
const implicit = this.implicitThis(fn) ? ['__this: Any?'] : [];
|
|
37
|
+
if (this.readsArguments(fn)) {
|
|
38
|
+
const explicitThis = fn.parameters.find((p) => isThisParameter(p) && !this.voidThis(p));
|
|
39
|
+
const selfParam = implicit.length ? implicit : explicitThis ? [`__this: ${this.type(this.checker.getTypeAtLocation(explicitThis.name), explicitThis)}`] : [];
|
|
40
|
+
return [...selfParam, '__arguments: JSArray<Any?>'].join(', ');
|
|
41
|
+
}
|
|
39
42
|
return [
|
|
40
43
|
...implicit,
|
|
41
44
|
...fn.parameters.map((p, k) => {
|
|
@@ -384,14 +387,20 @@ export const functionsMethods = {
|
|
|
384
387
|
}
|
|
385
388
|
}
|
|
386
389
|
const ret = this.closureResult(fn, slotRet).target;
|
|
387
|
-
if (!ts.isMethodDeclaration(fn) && fn.name && fn.body && refersTo(fn.body, this.checker.getSymbolAtLocation(fn.name), this.checker))
|
|
388
|
-
throw this.error(fn, 'a named function expression', 'named-function-expression');
|
|
389
390
|
let params = this.params(fn, true);
|
|
390
391
|
// A slot's function type may take more parameters than the literal declares (JavaScript ignores extras).
|
|
391
392
|
const slotParams = slotParts?.params ?? [];
|
|
392
393
|
const given = ts.isFunctionExpression(fn) && thisArgBound(fn, this.checker) ? fn.parameters.filter((q) => !isThisParameter(q)).length : fn.parameters.length;
|
|
393
394
|
for (let k = given; k < slotParams.length; k++)
|
|
394
395
|
params += `${params ? ', ' : ''}__u${k}: ${slotParams[k]}`;
|
|
396
|
+
if (!ts.isMethodDeclaration(fn) && fn.name && fn.body && refersTo(fn.body, this.checker.getSymbolAtLocation(fn.name), this.checker)) {
|
|
397
|
+
const fnName = ident(fn.name.text);
|
|
398
|
+
const pTypes = splitTopLevel(params)
|
|
399
|
+
.map((p) => p.trim())
|
|
400
|
+
.filter(Boolean)
|
|
401
|
+
.map((p) => p.slice(p.indexOf(':') + 1).trim());
|
|
402
|
+
return `run { lateinit var ${fnName}: (${pTypes.join(', ')}) -> ${ret}; ${fnName} = fun(${params})${ret === 'Unit' ? '' : `: ${ret}`} ${this.functionBody(fn, ret, this.indent)}; ${fnName} }`;
|
|
403
|
+
}
|
|
395
404
|
return this.asLambda(fn, params, ret) ?? `fun(${params})${ret === 'Unit' ? '' : `: ${ret}`} ${this.functionBody(fn, ret, this.indent)}`;
|
|
396
405
|
},
|
|
397
406
|
/** A function literal's result slot, where `slotRet` is the result of the function type it is given as: nothing where that returns void, else its own type. */
|
|
@@ -120,6 +120,15 @@ export const globalCallsMethods = {
|
|
|
120
120
|
case 'clearTimeout':
|
|
121
121
|
case 'clearInterval':
|
|
122
122
|
return `${RT[globalOp(op)]}(${arg(0) ? this.restArgument(e, arg(0), 'Double?') : 'null'})`;
|
|
123
|
+
case 'requestAnimationFrame': {
|
|
124
|
+
const takesTime = this.checker
|
|
125
|
+
.getTypeAtLocation(arg(0))
|
|
126
|
+
.getCallSignatures()
|
|
127
|
+
.some((sig) => sig.parameters.length > 0);
|
|
128
|
+
return `org.nativescript.kit.requestAnimationFrame { __t -> (${this.fn(arg(0))})(${takesTime ? '__t' : ''}); Unit }`;
|
|
129
|
+
}
|
|
130
|
+
case 'cancelAnimationFrame':
|
|
131
|
+
return `org.nativescript.kit.cancelAnimationFrame(${arg(0) ? this.restArgument(e, arg(0), 'Double?') : 'null'})`;
|
|
123
132
|
case 'Symbol':
|
|
124
133
|
return `${RT.jsSymbol}(${arg(0) ? this.str(arg(0)) : 'null'})`;
|
|
125
134
|
case 'BigInt':
|
|
@@ -130,6 +139,8 @@ export const globalCallsMethods = {
|
|
|
130
139
|
// `Error('x')` constructs as `new Error('x')` does; so does `Array(n)`.
|
|
131
140
|
if (ERRORS[name])
|
|
132
141
|
return this.errorValue(name, e.arguments);
|
|
142
|
+
if (name === 'getComputedStyle')
|
|
143
|
+
return `run { ${arg(0) ? `${this.coerce(arg(0), 'Any?')}; ` : ''}JSObject("getPropertyValue" to JSFunction { "" }) }`;
|
|
133
144
|
if (name === 'Array' && isLibGlobal(this, callee))
|
|
134
145
|
return this.arrayConstruct(e, this.typeOf(e), e.arguments);
|
|
135
146
|
// `RegExp(re)` without flags is `re` itself; otherwise it constructs as `new RegExp` does.
|
package/dist/kotlin/literals.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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, literalKey, openSpreadType, spreadOperand, unquoted, wellKnownMember } from "../semantics/lang.js";
|
|
4
|
+
import { assertedOperand, evolvingElementContext, intersectionAliasMembers, isTypeParameterType, literalKey, openSpreadType, spreadOperand, unquoted, wellKnownMember } from "../semantics/lang.js";
|
|
5
5
|
import { holdsNil, literalNotes, signatureField, shapePlanOfLiteral, spelledOptional, 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";
|
|
8
8
|
import { boxStep, unboxStep } from "../semantics/type-step.js";
|
|
9
9
|
import { place } from "../semantics/placement.js";
|
|
10
|
-
import { isLibDeclaration, thisNodes } from "../semantics/ast.js";
|
|
10
|
+
import { hasModifier, isLibDeclaration, thisNodes, tupleSpreadTypes } from "../semantics/ast.js";
|
|
11
11
|
import { isCoreDeclaration } from "../program/core-facts.js";
|
|
12
12
|
import { isStatic } from "../semantics/throws.js";
|
|
13
13
|
import { programSymbolKey } from "../program/stable-names.js";
|
|
@@ -42,6 +42,39 @@ export const literalsMethods = {
|
|
|
42
42
|
return 'JSMatch.empty()';
|
|
43
43
|
if (t.startsWith('Pair<') || t.startsWith('Triple<')) {
|
|
44
44
|
const types = splitTopLevel(t.replace(/^(Pair|Triple)<(.*)>$/, '$2'));
|
|
45
|
+
if (e.elements.some(ts.isSpreadElement)) {
|
|
46
|
+
const binds = [];
|
|
47
|
+
const items = [];
|
|
48
|
+
for (const x of e.elements) {
|
|
49
|
+
if (ts.isSpreadElement(x)) {
|
|
50
|
+
const tArgs = tupleSpreadTypes(x, this.checker);
|
|
51
|
+
if (tArgs) {
|
|
52
|
+
const spreadCode = this.expr(x.expression);
|
|
53
|
+
const ref = ts.isIdentifier(x.expression) ? spreadCode : this.fresh('__tup');
|
|
54
|
+
if (ref !== spreadCode)
|
|
55
|
+
binds.push(`val ${ref} = ${spreadCode}`);
|
|
56
|
+
const spreadType = this.typeOf(x.expression);
|
|
57
|
+
const pairOrTriple = spreadType.startsWith('Pair<') || spreadType.startsWith('Triple<');
|
|
58
|
+
for (let k = 0; k < tArgs.length; k++) {
|
|
59
|
+
const elem = pairOrTriple ? `${ref}.${['first', 'second', 'third'][k]}` : `${ref}[${k}]`;
|
|
60
|
+
const from = this.type(tArgs[k], x);
|
|
61
|
+
const targetType = types[items.length];
|
|
62
|
+
items.push(targetType && targetType !== from ? this.convert(elem, from, targetType) : elem);
|
|
63
|
+
}
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
throw this.error(x, `a non-tuple spread in ${t}`);
|
|
67
|
+
}
|
|
68
|
+
const to = types[items.length];
|
|
69
|
+
items.push(to ? this.coerce(x, to) : this.expr(x));
|
|
70
|
+
}
|
|
71
|
+
const missing = types
|
|
72
|
+
.slice(items.length)
|
|
73
|
+
.filter(isNullable)
|
|
74
|
+
.map(() => 'null');
|
|
75
|
+
const made = `${t.replace(/<.*/, '')}(${[...items, ...missing].join(', ')})`;
|
|
76
|
+
return binds.length ? `run { ${binds.join('; ')}; ${made} }` : made;
|
|
77
|
+
}
|
|
45
78
|
// A literal shorter than its tuple type leaves an optional element out: undefined there.
|
|
46
79
|
const missing = types
|
|
47
80
|
.slice(e.elements.length)
|
|
@@ -119,6 +152,8 @@ export const literalsMethods = {
|
|
|
119
152
|
return `${r}.obj[${ts.isComputedPropertyName(p.name) ? this.propertyKey(p.name.expression) : kotlinString(literalKey(p.name, this.checker) ?? p.name.getText())}] = ${this.stored(p.initializer, p, v)}`;
|
|
120
153
|
if (ts.isShorthandPropertyAssignment(p))
|
|
121
154
|
return `${r}.obj[${kotlinString(p.name.text)}] = ${this.shorthandValue(p.name)}`;
|
|
155
|
+
if (ts.isMethodDeclaration(p))
|
|
156
|
+
return `${r}.obj[${ts.isComputedPropertyName(p.name) ? this.propertyKey(p.name.expression) : kotlinString(literalKey(p.name, this.checker) ?? p.name.getText())}] = ${this.untypedMethod(p)}`;
|
|
122
157
|
throw this.error(p, 'this member in a dictionary literal');
|
|
123
158
|
});
|
|
124
159
|
return `run { val ${r} = ${name}(); ${steps.join('; ')}; ${r} }`;
|
|
@@ -128,6 +163,8 @@ export const literalsMethods = {
|
|
|
128
163
|
return `Pair(${ts.isComputedPropertyName(p.name) ? this.propertyKey(p.name.expression) : kotlinString(literalKey(p.name, this.checker) ?? p.name.getText())}, ${this.stored(p.initializer, p, v)})`;
|
|
129
164
|
if (ts.isShorthandPropertyAssignment(p))
|
|
130
165
|
return `Pair(${kotlinString(p.name.text)}, ${this.shorthandValue(p.name)})`;
|
|
166
|
+
if (ts.isMethodDeclaration(p))
|
|
167
|
+
return `Pair(${ts.isComputedPropertyName(p.name) ? this.propertyKey(p.name.expression) : kotlinString(literalKey(p.name, this.checker) ?? p.name.getText())}, ${this.untypedMethod(p)})`;
|
|
131
168
|
throw this.error(p, 'this member in a dictionary literal');
|
|
132
169
|
});
|
|
133
170
|
return this.construction(entries.length ? `${name}(listOf(${entries.join(', ')}))` : `${name}()`, name);
|
|
@@ -137,6 +174,8 @@ export const literalsMethods = {
|
|
|
137
174
|
return `EventData.fromJS(${this.dynamicObject(e)})`;
|
|
138
175
|
if (isUntyped(spelledType(name)) || name === 'Any' || name === 'Nothing' || name === 'JSObject' || name === 'EventData')
|
|
139
176
|
return this.dynamicObject(e);
|
|
177
|
+
if (isTypeParameterType(type, this.checker))
|
|
178
|
+
return this.fromAnyCode(this.dynamicObject(e), name);
|
|
140
179
|
// The generated kit: an object of an interface core declares (`TraceErrorHandler`), which core holds untyped and calls by name.
|
|
141
180
|
if (this.generatedKit && this.core?.has(`${name}Object`) && isCoreDeclaration(this.checker.getNonNullableType(type).getSymbol()?.declarations?.[0]))
|
|
142
181
|
return this.dynamicObject(e);
|
|
@@ -177,8 +216,15 @@ export const literalsMethods = {
|
|
|
177
216
|
else if (joined) {
|
|
178
217
|
order = joined.map((m) => this.interfaceField(m));
|
|
179
218
|
}
|
|
180
|
-
else if (
|
|
181
|
-
|
|
219
|
+
else if (classOfType(type, this.checker) ?? literalClassOf(this, e)) {
|
|
220
|
+
const cls = (classOfType(type, this.checker) ?? literalClassOf(this, e));
|
|
221
|
+
if (this.library || this.inPluginFile(e) || hasModifier(cls, ts.SyntaxKind.AbstractKeyword))
|
|
222
|
+
return this.classLiteral(e, cls, name);
|
|
223
|
+
throw this.error(e, `an object literal of type ${name}`);
|
|
224
|
+
}
|
|
225
|
+
else if (decl && ts.isModuleDeclaration(decl)) {
|
|
226
|
+
return this.dynamicObject(e);
|
|
227
|
+
}
|
|
182
228
|
else
|
|
183
229
|
throw this.error(e, `an object literal of type ${name}`);
|
|
184
230
|
const given = new Map();
|
|
@@ -385,7 +431,7 @@ export const literalsMethods = {
|
|
|
385
431
|
// A literal no type of the class's is at (one held as the class) has fields of its own types, which the class's fields take.
|
|
386
432
|
const own = this.checker.getTypeAtLocation(e);
|
|
387
433
|
const fields = classOfType(this.checker.getContextualType(e) ?? own, this.checker) ? own : this.checker.getDeclaredTypeOfSymbol(this.checker.getSymbolAtLocation(cls.name));
|
|
388
|
-
const method = (n) => cls.members.find((m) => ts.isMethodDeclaration(m) && !!m.body && m.name.getText() === n) ?? this.inheritedMethod(cls, n);
|
|
434
|
+
const method = (n) => cls.members.find((m) => ts.isMethodDeclaration(m) && (!!m.body || hasModifier(m, ts.SyntaxKind.AbstractKeyword)) && m.name.getText() === n) ?? this.inheritedMethod(cls, n);
|
|
389
435
|
for (const p of e.properties) {
|
|
390
436
|
if (!ts.isPropertyAssignment(p) && !ts.isShorthandPropertyAssignment(p) && !ts.isMethodDeclaration(p))
|
|
391
437
|
throw this.error(p, `this member of an object literal of type ${name}`);
|