@nstudio/nativescript-compiler-svelte 0.0.0-stage → 9.2.0-alpha.10

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/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright OpenJS Foundation and other contributors, https://openjsf.org
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,28 @@
1
- # Temporary Holding Version
1
+ # @nstudio/nativescript-compiler-svelte
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Svelte adapter for [`@nstudio/nativescript-compiler`](https://www.npmjs.com/package/@nstudio/nativescript-compiler), enabling NativeScript Svelte apps (`@nativescript-community/svelte-native`, Svelte 4 or 5) to compile directly to Swift (iOS) and Kotlin (Android) with no JavaScript runtime.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ ns extension install @nstudio/nativescript-compiler
9
+ npm install --save-dev @nstudio/nativescript-compiler-svelte
10
+ ```
11
+
12
+ Install the adapter at the same version as `@nstudio/nativescript-compiler`.
13
+
14
+ ## Usage
15
+
16
+ ```bash
17
+ ns compile ios
18
+ ns compile android
19
+ ```
20
+
21
+ ## Supported Versions
22
+
23
+ - `@nativescript-community/svelte-native`: `>=1.0.0 <2.0.0` or `>=5.0.0-alpha.0 <6.0.0`
24
+ - `svelte`: `>=4.2.0 <5.0.0` or `>=5.50.0 <6.0.0`
25
+
26
+ ## License
27
+
28
+ MIT
@@ -0,0 +1,8 @@
1
+ /** The compiler's own functions and state, from the compiler that loaded the adapter: set by its entry before any front end runs. */
2
+ export let core;
3
+ /** The compiler's TypeScript (`core.ts`), set with `core`: the adapter reads and makes the compiler's syntax trees with it, never with a TypeScript of its own. */
4
+ export let ts;
5
+ export function useCore(api) {
6
+ core = api;
7
+ ts = api.ts;
8
+ }
package/dist/hooks.js ADDED
@@ -0,0 +1,22 @@
1
+ // What the translators do for Svelte: its stores, `get(store)`, `tick()`, and svelte-native's `navigate({ page })`.
2
+ import { ts } from "./core-api.js";
3
+ const model = {
4
+ signalTypes: { Writable: 'store' },
5
+ signalConstructors: { writable: 'always-changed' },
6
+ pure: ['writable'],
7
+ throwsModel: { rethrowing: ['Writable.update'] },
8
+ };
9
+ function globalCall(t, name, e, _decl, lib) {
10
+ const first = e.arguments[0];
11
+ if (name === 'get' && e.arguments.length === 1 && t.symbolName(first) === 'Writable')
12
+ return `${t.expr(first)}.value`;
13
+ if (name === 'navigate' && first && ts.isObjectLiteralExpression(first)) {
14
+ const page = first.properties.find((p) => p.name && p.name.text === 'page');
15
+ return t.navigate(e, page.initializer.text, first);
16
+ }
17
+ if (name === 'tick' && !e.arguments.length && lib)
18
+ return 'Reactivity.tick()';
19
+ return undefined;
20
+ }
21
+ export const swiftHooks = { ...model, globalCall };
22
+ export const kotlinHooks = { ...model, globalCall };
package/dist/index.js ADDED
@@ -0,0 +1,81 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ import { existsSync, readFileSync } from 'node:fs';
10
+ import { createRequire } from 'node:module';
11
+ import { basename, dirname, join, resolve } from 'node:path';
12
+ import { pathToFileURL } from 'node:url';
13
+ import { useCore } from "./core-api.js";
14
+ import { kotlinHooks, swiftHooks } from "./hooks.js";
15
+ import { modules } from "./modules.js";
16
+ import { svelteComponent } from "./svelte.js";
17
+ import { svelte5Component, svelteModule } from "./svelte5.js";
18
+ /**
19
+ * Svelte 4 sets an element's props after its children's, and mounts a block's views top-down once they are all made;
20
+ * Svelte 5 sets a template's static attributes as it makes its views and the rest in one effect after its blocks and
21
+ * components, adds its listeners after that, and updates in effect-tree order: creation order, nested.
22
+ */
23
+ const SVELTE4 = { schedule: 'microtask', eventScope: 'none', propsOrder: 'post', deferBindings: false, insertion: 'mounted', listenersAfterBindings: false, effectScope: 'component', checkEveryBinding: 'off', slots: false, rowSignals: 'off', fragments: false, kit: { scope: { template: 'EffectOrder.component' } } };
24
+ const SVELTE5 = { schedule: 'microtask', eventScope: 'none', propsOrder: 'pre', deferBindings: true, insertion: 'built', listenersAfterBindings: true, effectScope: null, checkEveryBinding: 'off', slots: false, rowSignals: 'off', fragments: false };
25
+ export default function adapter(core) {
26
+ useCore(core);
27
+ return {
28
+ apiVersion: 1,
29
+ name: 'svelte',
30
+ packages: ['@nativescript-community/svelte-native', 'svelte'],
31
+ behaviour: SVELTE4,
32
+ reach: 'project',
33
+ swift: swiftHooks,
34
+ kotlin: kotlinHooks,
35
+ modules,
36
+ frontEnd: async (app) => (Number(JSON.parse(readFileSync(join(app.nodeModules, 'svelte', 'package.json'), 'utf8')).version.split('.')[0]) >= 5 ? svelte5(app) : svelte4(app)),
37
+ };
38
+ }
39
+ /** Svelte 5: parsed by the app's own compiler; `.svelte.ts` modules' runes as Svelte compiles them. */
40
+ async function svelte5(app) {
41
+ const { parse, compile } = createRequire(join(app.root, 'package.json'))('svelte/compiler');
42
+ const styled = (await svelteCss(app.root, 'external')) === 'injected';
43
+ const components = app.files.filter((f) => f.endsWith('.svelte')).map((f) => svelte5Component(f, readFileSync(f, 'utf8'), parse, app.platform, styled ? compile : undefined));
44
+ const overrides = new Map();
45
+ for (const f of app.sources) {
46
+ const module = f.endsWith('.svelte.ts') ? svelteModule(f, readFileSync(f, 'utf8')) : null;
47
+ if (module)
48
+ overrides.set(f, module);
49
+ }
50
+ return { components, modules: app.sources, overrides, root: rootComponent(app), behaviour: SVELTE5 };
51
+ }
52
+ async function svelte4(app) {
53
+ const isStoreFile = (f) => /from\s+['"]svelte\/store['"]/.test(readFileSync(f, 'utf8'));
54
+ const styled = (await svelteCss(app.root, 'injected')) === 'injected';
55
+ const components = app.files.filter((f) => f.endsWith('.svelte')).map((f) => svelteComponent(f, readFileSync(f, 'utf8'), (spec) => {
56
+ const target = resolve(dirname(f), spec);
57
+ return [target + '.ts', target + '/index.ts'].some((t) => existsSync(t) && isStoreFile(t));
58
+ }, styled ? createRequire(join(app.root, 'package.json'))('svelte/compiler').compile : undefined));
59
+ return { components, modules: app.sources, root: rootComponent(app) };
60
+ }
61
+ /** The component the entry starts the app with: `svelteNative(App)`. */
62
+ function rootComponent(app) {
63
+ const rootImport = /svelteNative(?:NoFrame)?\(\s*(\w+)/.exec(app.entryText)?.[1];
64
+ const rootFile = rootImport && new RegExp(`import\\s+${rootImport}\\s+from\\s+['"]([^'"]+)['"]`).exec(app.entryText)?.[1];
65
+ if (!rootFile)
66
+ throw new Error(`${app.entry}: no svelteNative(Component)`);
67
+ return basename(rootFile, '.svelte');
68
+ }
69
+ /**
70
+ * Where the app's Svelte puts a component's `<style>` (`compilerOptions.css` of svelte.config.js, else the version's
71
+ * default): `injected` styles svelte-native adds when the component mounts; `external` ones svelte-loader drops unless
72
+ * the app emits them itself, as NativeScript's webpack configuration does not.
73
+ */
74
+ async function svelteCss(app, fallback) {
75
+ const file = ['svelte.config.js', 'svelte.config.mjs', 'svelte.config.cjs'].map((f) => join(app, f)).find((f) => existsSync(f));
76
+ if (!file)
77
+ return fallback;
78
+ const config = await import(__rewriteRelativeImportExtension(pathToFileURL(file).href, true));
79
+ const css = (config.default ?? config)?.compilerOptions?.css;
80
+ return css === true ? 'injected' : css === false ? 'external' : typeof css === 'string' ? css : fallback;
81
+ }
@@ -0,0 +1,18 @@
1
+ export const modules = {
2
+ shims: {
3
+ 'svelte': `
4
+ export declare function tick(): Promise<void>;
5
+ `,
6
+ 'svelte/store': `
7
+ import type { Sig } from '@nativescript/release';
8
+ export interface Writable<T> extends Sig<T> { set(value: T): void; update(fn: (value: T) => T): void }
9
+ export declare function writable<T>(value: T): Writable<T>;
10
+ export declare function get<T>(store: Writable<T>): T;
11
+ `,
12
+ '@nativescript-community/svelte-native': `
13
+ export declare function navigate(options: { page: any; props?: Record<string, any> }): void;
14
+ export declare function svelteNativeNoFrame(component: any, props: any): void;
15
+ `,
16
+ },
17
+ componentExtensions: ['.svelte'],
18
+ };
package/dist/styles.js ADDED
@@ -0,0 +1,25 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { createRequire } from 'node:module';
3
+ import { dirname } from 'node:path';
4
+ /**
5
+ * A Svelte component's `<style>` as the app's Svelte compiles it (`css: 'external'`, scoped by its own analysis),
6
+ * with the scoping class (`.svelte-<hash>`) read as an attribute the component's elements carry: Svelte puts the class
7
+ * only on elements its selectors can match, so the attribute on every element selects the same ones.
8
+ */
9
+ export function svelteStyles(path, text, compile, generate) {
10
+ const style = /<style([^>]*)>([\s\S]*?)<\/style>/.exec(text);
11
+ if (!style)
12
+ return { styles: [], scope: null };
13
+ const lang = /\blang=["']?(\w+)/.exec(style[1])?.[1];
14
+ let css = style[2];
15
+ if (lang === 'scss' || lang === 'sass')
16
+ css = createRequire(path)('sass').compileString(css, { loadPaths: [dirname(path)], syntax: lang === 'sass' ? 'indented' : 'scss' }).css;
17
+ else if (lang && lang !== 'css')
18
+ throw new Error(`${path}: <style lang="${lang}"> is not supported in a compiled release yet`);
19
+ const scope = `svelte-${createHash('sha256').update(path).digest('hex').slice(0, 8)}`;
20
+ // Only the markup decides what the selectors match: the scripts are left out, and the style is plain CSS.
21
+ const source = text.replace(/(<script[^>]*>)[\s\S]*?(<\/script>)/g, '$1$2').replace(style[0], `<style>${css}</style>`);
22
+ const result = compile(source, { filename: path, generate, css: 'external', cssHash: () => scope });
23
+ const code = (result.css?.code ?? '').split(`.${scope}`).join(`[${scope}]`);
24
+ return { styles: code.trim() ? [{ file: `${path}.style0.css`, css: code }] : [], scope };
25
+ }
package/dist/svelte.js ADDED
@@ -0,0 +1,276 @@
1
+ import { parse } from 'svelte/compiler';
2
+ import { basename } from 'node:path';
3
+ import { core, ts } from "./core-api.js";
4
+ import { svelteStyles } from "./styles.js";
5
+ /**
6
+ * A Svelte Native component (Svelte 4: `export let` props, reactive `let`s,
7
+ * `$:` declarations, `$store` reads, `{#if}`/`{#each}`) as a virtual class.
8
+ */
9
+ export function svelteComponent(path, text, isStoreModule, compile) {
10
+ const name = basename(path, '.svelte');
11
+ // Svelte 4 parses scripts as JavaScript; the TypeScript is read separately, and blanked
12
+ // to spaces in the markup so the template's offsets stay those of the file.
13
+ let script = '';
14
+ const markup = text.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/, (_, open, body, close) => {
15
+ script = body;
16
+ return open + body.replace(/[^\n]/g, ' ') + close;
17
+ });
18
+ const ast = parse(markup);
19
+ const src = (n) => markup.slice(n.start, n.end);
20
+ const sf = ts.createSourceFile(path + '.ts', script, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
21
+ const imports = [];
22
+ const fields = [];
23
+ const props = [];
24
+ const components = new Set();
25
+ // svelte-native's `<Template>`, under the name the component imports it as.
26
+ let templateTag = '';
27
+ const stores = new Set();
28
+ const scope = { names: new Map() };
29
+ const arity = new Map();
30
+ const later = [];
31
+ const derived = [];
32
+ for (const st of sf.statements) {
33
+ if (ts.isImportDeclaration(st)) {
34
+ const from = st.moduleSpecifier.text;
35
+ if (from.endsWith('.svelte')) {
36
+ const local = st.importClause.name.text;
37
+ components.add(local);
38
+ imports.push(`import ${local} from '${from}';`);
39
+ continue;
40
+ }
41
+ if (from === '@nativescript-community/svelte-native') {
42
+ imports.push(st.getText());
43
+ continue;
44
+ }
45
+ if (from === '@nativescript-community/svelte-native/components') {
46
+ const named = st.importClause?.namedBindings;
47
+ if (named && ts.isNamedImports(named))
48
+ for (const e of named.elements)
49
+ if ((e.propertyName ?? e.name).text === 'Template')
50
+ templateTag = e.name.text;
51
+ continue;
52
+ }
53
+ imports.push(st.getText());
54
+ // A module that exports stores: `$name` in this component reads one.
55
+ const named = st.importClause?.namedBindings;
56
+ if (named && ts.isNamedImports(named) && isStoreModule(from))
57
+ for (const e of named.elements)
58
+ stores.add(e.name.text);
59
+ continue;
60
+ }
61
+ const exported = ts.canHaveModifiers(st) && ts.getModifiers(st)?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword);
62
+ if (ts.isVariableStatement(st)) {
63
+ for (const d of st.declarationList.declarations) {
64
+ const id = d.name.text;
65
+ if (exported) {
66
+ props.push(id);
67
+ fields.push(` ${id}!: ${d.type ? d.type.getText() : 'any'};`);
68
+ scope.names.set(id, `this.${id}`);
69
+ }
70
+ else {
71
+ // Every top-level `let` is state: assigning it re-renders what reads it.
72
+ scope.names.set(id, `this.${id}.value`);
73
+ later.push(() => fields.push(` ${id} = $signal${d.type ? `<${d.type.getText()}>` : ''}(${d.initializer ? core.rewrite(d.initializer.getText(), withStores(scope, stores)) : 'undefined'});`));
74
+ }
75
+ }
76
+ continue;
77
+ }
78
+ if (ts.isFunctionDeclaration(st) && st.name) {
79
+ const fn = st.name.text;
80
+ arity.set(fn, st.parameters.length);
81
+ scope.names.set(fn, `this.${fn}`);
82
+ later.push(() => {
83
+ const ret = st.type ? `: ${st.type.getText()}` : '';
84
+ fields.push(` ${(ts.getModifiers(st)?.some((m) => m.kind === ts.SyntaxKind.AsyncKeyword) ? 'async ' : '')}${fn}(${st.parameters.map((p) => p.getText()).join(', ')})${ret} ${core.rewrite(st.body.getText(), withStores(scope, stores), 'statements')}`);
85
+ });
86
+ continue;
87
+ }
88
+ if (ts.isLabeledStatement(st) && st.label.text === '$' && ts.isExpressionStatement(st.statement) && ts.isBinaryExpression(st.statement.expression)) {
89
+ // `$: id = expr` is state that `$$.update()` recomputes in the update after its sources
90
+ // change; `render()` gives it its first value.
91
+ const assign = st.statement.expression;
92
+ const id = assign.left.text;
93
+ scope.names.set(id, `this.${id}.value!`);
94
+ const method = `$d${derived.length}`;
95
+ derived.push({ name: id, method });
96
+ later.push(() => fields.push(` ${id} = $signal<ReturnType<${name}['${method}']> | undefined>(undefined);`, ` ${method}() { return ${core.rewrite(assign.right.getText(), withStores(scope, stores))}; }`));
97
+ continue;
98
+ }
99
+ throw new Error(`${path}: unsupported top-level statement in <script>: ${st.getText().slice(0, 60)}`);
100
+ }
101
+ for (const f of later)
102
+ f();
103
+ const full = withStores(scope, stores);
104
+ const methods = [];
105
+ let next = 0;
106
+ const params = (loops) => loops.map((l) => l.param).join(', ');
107
+ const args = (loops) => loops.flatMap((l) => [l.item, l.index]).join(', ');
108
+ const local = (loops, extra = {}) => {
109
+ const names = new Map(full.names);
110
+ for (const l of loops) {
111
+ names.delete(l.item);
112
+ names.delete(l.index);
113
+ }
114
+ for (const [k, v] of Object.entries(extra))
115
+ names.set(k, v);
116
+ return { names };
117
+ };
118
+ const expr = (code, loops) => {
119
+ const m = `$b${next++}`;
120
+ methods.push(` ${m}(${params(loops)}) { return ${core.rewrite(code, local(loops))}; }`);
121
+ return m;
122
+ };
123
+ const handler = (node, loops) => {
124
+ const m = `$e${next++}`;
125
+ const e = node.expression;
126
+ let body;
127
+ if (e.type === 'ArrowFunctionExpression' || e.type === 'FunctionExpression') {
128
+ // `(e) => (query = e.value)`: the parameter is the event.
129
+ const param = e.params[0]?.name;
130
+ const extra = param ? { [param]: '$event' } : {};
131
+ body = e.body.type === 'BlockStatement' ? core.rewrite(src(e.body), local(loops, extra), 'statements') : `${core.rewrite(src(e.body), local(loops, extra)).slice(1, -1)};`;
132
+ }
133
+ else {
134
+ const code = src(e);
135
+ body = `${core.rewrite(code, local(loops)).slice(1, -1)}(${arity.get(code) === 0 ? '' : '$event'});`;
136
+ }
137
+ methods.push(` ${m}(${[params(loops), '$event: $EventData'].filter(Boolean).join(', ')}) { ${body} }`);
138
+ return m;
139
+ };
140
+ const value = (a, loops) => {
141
+ if (a.value === true)
142
+ return { name: a.name, value: 'true' };
143
+ if (a.value.length === 1 && a.value[0].type === 'Text')
144
+ return { name: a.name, value: a.value[0].data };
145
+ if (a.value.length === 1 && (a.value[0].type === 'MustacheTag' || a.value[0].type === 'AttributeShorthand'))
146
+ return { name: a.name, method: expr(src(a.value[0].expression), loops) };
147
+ // `class="row {extra}"`: text and expressions join as a template literal.
148
+ const parts = a.value.map((v) => (v.type === 'Text' ? v.data.replace(/[`$\\]/g, '\\$&') : '${' + src(v.expression) + '}')).join('');
149
+ return { name: a.name, method: expr('`' + parts + '`', loops) };
150
+ };
151
+ const nodes = (list, loops) => {
152
+ const out = [];
153
+ for (const n of list) {
154
+ if (n.type === 'Text' || n.type === 'Comment')
155
+ continue;
156
+ if (n.type === 'Element' || n.type === 'InlineComponent') {
157
+ const attrs = [];
158
+ const events = [];
159
+ const isList = n.type === 'Element' && core.canonical(n.name) === 'ListView';
160
+ for (const a of n.attributes) {
161
+ if (isList && a.type === 'Attribute' && a.name === 'itemTemplateSelector')
162
+ continue;
163
+ if (a.type === 'Attribute')
164
+ attrs.push(value(a, loops));
165
+ else if (a.type === 'EventHandler') {
166
+ if (a.expression)
167
+ events.push({ name: a.name, method: handler(a, loops) });
168
+ }
169
+ else
170
+ throw new Error(`${path}: ${a.type} ${a.name} is not supported in a release build yet`);
171
+ }
172
+ if (n.type === 'InlineComponent') {
173
+ if (!components.has(n.name))
174
+ throw new Error(`${path}: <${n.name}> is not an imported component`);
175
+ out.push({ kind: 'component', name: n.name, props: attrs, events });
176
+ continue;
177
+ }
178
+ const tag = core.canonical(n.name);
179
+ if (!tag)
180
+ throw new Error(`${path}: <${n.name}> is not a @nativescript/core element the release build knows`);
181
+ out.push({ kind: 'element', tag, attrs, events, children: isList ? listTemplates(n, attrs, loops) : nodes(n.children, loops) });
182
+ continue;
183
+ }
184
+ if (n.type === 'IfBlock') {
185
+ const branches = [];
186
+ let block = n;
187
+ while (block) {
188
+ branches.push({ cond: expr(src(block.expression), loops), body: nodes(block.children, loops) });
189
+ const otherwise = block.else;
190
+ if (!otherwise)
191
+ break;
192
+ const elseif = otherwise.children.find((c) => c.type === 'IfBlock' && c.elseif);
193
+ if (elseif) {
194
+ block = elseif;
195
+ continue;
196
+ }
197
+ branches.push({ cond: null, body: nodes(otherwise.children, loops) });
198
+ break;
199
+ }
200
+ out.push({ kind: 'if', branches });
201
+ continue;
202
+ }
203
+ if (n.type === 'EachBlock') {
204
+ const item = n.context.name;
205
+ const index = n.index ?? `$i${loops.length}`;
206
+ const items = expr(src(n.expression), loops);
207
+ const inner = [...loops, { item, index, param: `${item} = this.${items}(${args(loops)})[0], ${index} = 0` }];
208
+ out.push({ kind: 'for', items, key: n.key ? expr(src(n.key), inner) : null, item, index, body: nodes(n.children, inner) });
209
+ continue;
210
+ }
211
+ throw new Error(`${path}: ${n.type} in a template is not supported in a release build yet`);
212
+ }
213
+ return out;
214
+ };
215
+ /**
216
+ * `<listView items>` with `<Template let:item key="…">` children, as svelte-native renders them: a template
217
+ * sees its item only, the unkeyed one is the default, and `itemTemplateSelector` is core's `(item, index, items)`.
218
+ */
219
+ const listTemplates = (n, attrs, loops) => {
220
+ const items = attrs.find((a) => a.name === 'items');
221
+ if (!items || !('method' in items))
222
+ throw new Error(`${path}: <listView> needs items={…}`);
223
+ const list = `this.${items.method}(${args(loops)})`;
224
+ const selector = n.attributes.find((a) => a.type === 'Attribute' && a.name === 'itemTemplateSelector');
225
+ if (selector) {
226
+ const v = selector.value;
227
+ if (v === true || v.length !== 1 || v[0].type !== 'MustacheTag')
228
+ throw new Error(`${path}: itemTemplateSelector={…} needs a function`);
229
+ const m = `$b${next++}`;
230
+ const p = [params(loops), `$item = ${list}[0]`, '$index = 0'].filter(Boolean).join(', ');
231
+ methods.push(` ${m}(${p}): string { return ${core.rewrite(src(v[0].expression), local(loops))}($item, $index, ${list}); }`);
232
+ attrs.push({ name: 'itemTemplateSelector', method: m });
233
+ }
234
+ const out = [];
235
+ for (const t of n.children) {
236
+ if (t.type === 'Text' || t.type === 'Comment')
237
+ continue;
238
+ if (t.type !== 'InlineComponent' || !templateTag || t.name !== templateTag)
239
+ throw new Error(`${path}: a listView's children are <Template let:item> item templates`);
240
+ let key = 'default';
241
+ let item = `$item${loops.length}`;
242
+ for (const a of t.attributes) {
243
+ if (a.type === 'Let' && a.name === 'item')
244
+ item = a.expression ? src(a.expression) : 'item';
245
+ else if (a.type === 'Attribute' && a.name === 'key' && a.value !== true && a.value.length === 1 && a.value[0].type === 'Text')
246
+ key = a.value[0].data;
247
+ else
248
+ throw new Error(`${path}: <${templateTag} ${a.type === 'Let' ? 'let:' : ''}${a.name}> is not supported in a release build yet`);
249
+ }
250
+ const index = `$i${loops.length}`;
251
+ const loop = { item, index, param: `${item} = ${list}[0], ${index} = 0` };
252
+ out.push({ kind: 'template', key, item, index, body: nodes(t.children, [...loops, loop]) });
253
+ }
254
+ return out;
255
+ };
256
+ const template = nodes(ast.html.children, []);
257
+ const source = [
258
+ `import { $signal, type EventData as $EventData } from '@nativescript/release';`,
259
+ ...imports,
260
+ '',
261
+ `export default class ${name} {`,
262
+ ...fields,
263
+ ...methods,
264
+ '}',
265
+ '',
266
+ ].join('\n');
267
+ const { styles, scope: styleScope } = compile ? svelteStyles(path, text, compile, 'dom') : { styles: [], scope: null };
268
+ return { name, file: path + '.ts', source, props, template: styleScope ? core.scopeTemplate(template, styleScope) : template, styles, derived };
269
+ }
270
+ /** `$favoriteIds` reads the store `favoriteIds`. */
271
+ function withStores(scope, stores) {
272
+ const names = new Map(scope.names);
273
+ for (const s of stores)
274
+ names.set('$' + s, `${s}.value`);
275
+ return { names };
276
+ }
@@ -0,0 +1,376 @@
1
+ import { basename } from 'node:path';
2
+ import { core, ts } from "./core-api.js";
3
+ import { svelteStyles } from "./styles.js";
4
+ /**
5
+ * A Svelte Native component in Svelte 5's runes mode (`$state`, `$derived`,
6
+ * `$effect`, `$props`, snippets, event attributes, keyed `{#each}`) as a
7
+ * virtual class: state is a ref (deep, compared with `Object.is`, as a `$state`
8
+ * proxy is), derived values are getters, and `$effect`s are watchers.
9
+ */
10
+ export function svelte5Component(path, text, parse, platform = 'ios', compile) {
11
+ const name = basename(path, '.svelte');
12
+ const ast = parse(text, { modern: true });
13
+ if (ast.module)
14
+ throw new Error(`${path}: <script module> is not supported in a release build yet`);
15
+ const src = (n) => text.slice(n.start, n.end);
16
+ const script = ast.instance ? src(ast.instance.content) : '';
17
+ const sf = ts.createSourceFile(path + '.ts', script, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
18
+ const imports = [];
19
+ const fields = [];
20
+ const props = [];
21
+ const components = new Set();
22
+ const scope = { names: new Map() };
23
+ const arity = new Map();
24
+ const later = [];
25
+ const watchers = [];
26
+ const types = new Map();
27
+ const rune = (e) => {
28
+ if (!e || !ts.isCallExpression(e))
29
+ return '';
30
+ const callee = e.expression.getText();
31
+ return /^\$(state|derived|effect|props|inspect|host|bindable)(\.\w+)?$/.test(callee) ? callee : '';
32
+ };
33
+ for (const st of sf.statements) {
34
+ if ((ts.isInterfaceDeclaration(st) || ts.isTypeAliasDeclaration(st)) && !ts.getModifiers(st)?.length) {
35
+ const literal = ts.isInterfaceDeclaration(st) ? ts.factory.createTypeLiteralNode(st.members) : st.type;
36
+ if (!ts.isTypeLiteralNode(literal))
37
+ throw new Error(`${path}: type ${st.name.text} is not supported in a component's script in a release build yet`);
38
+ types.set(st.name.text, literal);
39
+ }
40
+ }
41
+ for (const st of sf.statements) {
42
+ if (ts.isImportDeclaration(st)) {
43
+ const from = st.moduleSpecifier.text;
44
+ // `./Row.svelte` is a component; `./store.svelte` (a `.svelte.ts` module) is imported by name.
45
+ if (from.endsWith('.svelte') && st.importClause?.name && !st.importClause.namedBindings) {
46
+ const local = st.importClause.name.text;
47
+ components.add(local);
48
+ imports.push(`import ${local} from '${from}';`);
49
+ continue;
50
+ }
51
+ if (from === '@nativescript-community/svelte-native/components')
52
+ throw new Error(`${path}: svelte-native's components (Template) are not supported with Svelte 5 in a release build yet`);
53
+ imports.push(st.getText());
54
+ continue;
55
+ }
56
+ if (ts.isInterfaceDeclaration(st) || ts.isTypeAliasDeclaration(st))
57
+ continue;
58
+ if (ts.isFunctionDeclaration(st) && st.name) {
59
+ const fn = st.name.text;
60
+ arity.set(fn, st.parameters.length);
61
+ scope.names.set(fn, `this.${fn}`);
62
+ later.push(() => {
63
+ const ret = st.type ? `: ${st.type.getText()}` : '';
64
+ const async = ts.getModifiers(st)?.some((m) => m.kind === ts.SyntaxKind.AsyncKeyword) ? 'async ' : '';
65
+ fields.push(` ${async}${fn}(${st.parameters.map((p) => p.getText()).join(', ')})${ret} ${core.rewrite(st.body.getText(), scope, 'statements')}`);
66
+ });
67
+ continue;
68
+ }
69
+ if (ts.isExpressionStatement(st) && rune(st.expression)) {
70
+ const call = st.expression;
71
+ if (rune(call) !== '$effect')
72
+ throw new Error(`${path}: ${rune(call)} is not supported in a release build yet`);
73
+ const fn = call.arguments[0];
74
+ if (!fn || !(ts.isArrowFunction(fn) || ts.isFunctionExpression(fn)) || fn.parameters.length)
75
+ throw new Error(`${path}: $effect needs a function`);
76
+ if (!ts.isBlock(fn.body) || hasReturnValue(fn.body))
77
+ throw new Error(`${path}: an $effect's teardown is not supported in a release build yet`);
78
+ const m = `$fx${watchers.length}`;
79
+ watchers.push({ source: null, handler: m, arity: 0, immediate: false });
80
+ later.push(() => fields.push(` ${m}() ${core.rewrite(fn.body.getText(), scope, 'statements')}`));
81
+ continue;
82
+ }
83
+ if (ts.isVariableStatement(st)) {
84
+ for (const d of st.declarationList.declarations) {
85
+ const kind = rune(d.initializer);
86
+ if (kind === '$props') {
87
+ if (!ts.isObjectBindingPattern(d.name))
88
+ throw new Error(`${path}: $props() needs destructuring (let { a, b }: Props = $props())`);
89
+ const declared = d.type && ts.isTypeReferenceNode(d.type) ? types.get(d.type.typeName.getText()) : d.type;
90
+ if (!declared || !ts.isTypeLiteralNode(declared))
91
+ throw new Error(`${path}: $props() needs a type (an object type, or an interface the script declares)`);
92
+ for (const e of d.name.elements) {
93
+ const prop = (e.propertyName ?? e.name).getText();
94
+ if (e.initializer || e.dotDotDotToken || e.propertyName)
95
+ throw new Error(`${path}: prop ${e.getText()} (defaults, renames, rest) is not supported in a release build yet`);
96
+ const member = declared.members.find((m) => ts.isPropertySignature(m) && m.name.getText() === prop);
97
+ if (!member?.type)
98
+ throw new Error(`${path}: prop "${prop}" needs a type`);
99
+ if (member.questionToken)
100
+ throw new Error(`${path}: optional prop "${prop}" is not supported in a release build yet`);
101
+ if (ts.isFunctionTypeNode(member.type))
102
+ arity.set(prop, member.type.parameters.length);
103
+ props.push(prop);
104
+ fields.push(` ${prop}!: ${member.type.getText()};`);
105
+ scope.names.set(prop, `this.${prop}`);
106
+ }
107
+ continue;
108
+ }
109
+ if (!ts.isIdentifier(d.name))
110
+ throw new Error(`${path}: ${d.getText().slice(0, 40)}: destructuring is not supported in a release build yet`);
111
+ const id = d.name.text;
112
+ const init = d.initializer;
113
+ if (kind === '$state') {
114
+ scope.names.set(id, `this.${id}.value`);
115
+ const typeArg = init.typeArguments?.[0]?.getText() ?? d.type?.getText();
116
+ later.push(() => fields.push(` ${id} = $ref${typeArg ? `<${typeArg}>` : ''}(${init.arguments[0] ? core.rewrite(init.arguments[0].getText(), scope) : 'undefined'});`));
117
+ continue;
118
+ }
119
+ if (kind === '$derived' || kind === '$derived.by') {
120
+ scope.names.set(id, `this.${id}`);
121
+ later.push(() => fields.push(` get ${id}()${d.type ? `: ${d.type.getText()}` : ''} ${derivedBody(init, kind, scope, path)}`));
122
+ continue;
123
+ }
124
+ if (kind)
125
+ throw new Error(`${path}: ${kind} is not supported in a release build yet`);
126
+ // A plain declaration: not reactive in runes mode.
127
+ scope.names.set(id, `this.${id}`);
128
+ const mutable = !!(st.declarationList.flags & ts.NodeFlags.Let);
129
+ later.push(() => fields.push(` ${mutable ? '' : 'readonly '}${id}${d.type ? `: ${d.type.getText()}` : ''} = ${d.initializer ? core.rewrite(d.initializer.getText(), scope) : 'undefined'};`));
130
+ }
131
+ continue;
132
+ }
133
+ throw new Error(`${path}: unsupported top-level statement in <script>: ${st.getText().slice(0, 60)}`);
134
+ }
135
+ for (const f of later)
136
+ f();
137
+ const methods = [];
138
+ let next = 0;
139
+ const params = (c) => c.loops.map((l) => l.param).join(', ');
140
+ const args = (c) => c.loops.flatMap((l) => [l.item, l.index]).join(', ');
141
+ const local = (c, extra = {}) => {
142
+ const names = new Map(scope.names);
143
+ for (const l of c.loops) {
144
+ names.delete(l.item);
145
+ names.delete(l.index);
146
+ }
147
+ for (const [k, v] of c.names)
148
+ names.set(k, v);
149
+ for (const [k, v] of Object.entries(extra))
150
+ names.set(k, v);
151
+ return { names };
152
+ };
153
+ const expr = (code, c) => {
154
+ const m = `$b${next++}`;
155
+ methods.push(` ${m}(${params(c)}) { return ${core.rewrite(code, local(c))}; }`);
156
+ return m;
157
+ };
158
+ const handler = (e, c) => {
159
+ const m = `$e${next++}`;
160
+ let body;
161
+ if (e.type === 'ArrowFunctionExpression' || e.type === 'FunctionExpression') {
162
+ // `(e) => (query = e.value)`: the parameter is the event.
163
+ const param = e.params[0]?.name;
164
+ const extra = param ? { [param]: '$event' } : {};
165
+ body = e.body.type === 'BlockStatement' ? core.rewrite(src(e.body), local(c, extra), 'statements') : `${core.rewrite(src(e.body), local(c, extra)).slice(1, -1)};`;
166
+ }
167
+ else {
168
+ const code = src(e);
169
+ body = `${core.rewrite(code, local(c)).slice(1, -1)}(${arity.get(code) === 0 ? '' : '$event'});`;
170
+ }
171
+ methods.push(` ${m}(${[params(c), '$event: $EventData'].filter(Boolean).join(', ')}) { ${body} }`);
172
+ return m;
173
+ };
174
+ const value = (a, c) => {
175
+ if (a.value === true)
176
+ return { name: a.name, value: 'true' };
177
+ if (!Array.isArray(a.value))
178
+ return { name: a.name, method: expr(src(a.value.expression), c) };
179
+ if (a.value.length === 1 && a.value[0].type === 'Text')
180
+ return { name: a.name, value: a.value[0].data };
181
+ // `class="row {extra}"`: text and expressions join as a template literal.
182
+ const parts = a.value.map((v) => (v.type === 'Text' ? v.data.replace(/[`$\\]/g, '\\$&') : '${' + src(v.expression) + '}')).join('');
183
+ return { name: a.name, method: expr('`' + parts + '`', c) };
184
+ };
185
+ const snippets = new Map();
186
+ const collect = (n) => {
187
+ if (!n || typeof n !== 'object')
188
+ return;
189
+ if (n.type === 'SnippetBlock') {
190
+ if (snippets.has(n.expression.name))
191
+ throw new Error(`${path}: two snippets named ${n.expression.name}`);
192
+ snippets.set(n.expression.name, n);
193
+ }
194
+ for (const v of Object.values(n))
195
+ if (Array.isArray(v))
196
+ v.forEach(collect);
197
+ else if (v && typeof v === 'object')
198
+ collect(v);
199
+ };
200
+ collect(ast.fragment);
201
+ const nodes = (list, c) => {
202
+ const out = [];
203
+ for (const n of list) {
204
+ if (n.type === 'Text' || n.type === 'Comment' || n.type === 'SnippetBlock')
205
+ continue;
206
+ if (n.type === 'RegularElement' || n.type === 'Component') {
207
+ const attrs = [];
208
+ const events = [];
209
+ for (let a of n.attributes) {
210
+ if (a.type !== 'Attribute')
211
+ throw new Error(`${path}: ${a.type} ${a.name ?? ''} is not supported in a release build yet`);
212
+ // svelte-native sets `ios:x` on iOS and `android:x` on Android only.
213
+ const prefix = /^(ios|android):/.exec(a.name)?.[1];
214
+ if (prefix && prefix !== platform)
215
+ continue;
216
+ if (prefix)
217
+ a = { ...a, name: a.name.slice(prefix.length + 1) };
218
+ else if (n.type === 'RegularElement' && a.name === 'checked' && a.value !== true && !Array.isArray(a.value)) {
219
+ // Svelte 5's renderer API sets `checked` as an HTML boolean attribute: '' when true, removed (null) when
220
+ // false. NativeScript's Switch rejects '' (core's booleanConverter throws), so the binding stops updating.
221
+ throw new Error(`${path}: checked={…} under Svelte 5's custom renderer sets checked to '' or null, which a NativeScript Switch rejects; bind ios:checked and android:checked`);
222
+ }
223
+ // `ontap={…}` on an element listens to `tap`; on a component it is a callback prop.
224
+ if (n.type === 'RegularElement' && /^on/.test(a.name)) {
225
+ if (a.value === true || Array.isArray(a.value))
226
+ throw new Error(`${path}: ${a.name} needs a function`);
227
+ events.push({ name: a.name.slice(2), method: handler(a.value.expression, c) });
228
+ }
229
+ else
230
+ attrs.push(value(a, c));
231
+ }
232
+ if (n.type === 'Component') {
233
+ if (!components.has(n.name))
234
+ throw new Error(`${path}: <${n.name}> is not an imported component`);
235
+ if (n.fragment.nodes.some((x) => x.type !== 'Text' && x.type !== 'Comment'))
236
+ throw new Error(`${path}: children of <${n.name}> are not supported in a release build yet`);
237
+ out.push({ kind: 'component', name: n.name, props: attrs, events });
238
+ continue;
239
+ }
240
+ const tag = core.canonical(n.name);
241
+ if (!tag)
242
+ throw new Error(`${path}: <${n.name}> is not a @nativescript/core element the release build knows`);
243
+ if (tag === 'ListView')
244
+ throw new Error(`${path}: <listView> with Svelte 5 is not supported in a release build yet`);
245
+ out.push({ kind: 'element', tag, attrs, events, children: nodes(n.fragment.nodes, c) });
246
+ continue;
247
+ }
248
+ if (n.type === 'IfBlock') {
249
+ const branches = [];
250
+ let block = n;
251
+ while (block) {
252
+ branches.push({ cond: expr(src(block.test), c), body: nodes(block.consequent.nodes, c) });
253
+ const otherwise = block.alternate;
254
+ if (!otherwise)
255
+ break;
256
+ const elseif = otherwise.nodes.find((x) => x.type === 'IfBlock' && x.elseif);
257
+ if (elseif) {
258
+ block = elseif;
259
+ continue;
260
+ }
261
+ branches.push({ cond: null, body: nodes(otherwise.nodes, c) });
262
+ break;
263
+ }
264
+ out.push({ kind: 'if', branches });
265
+ continue;
266
+ }
267
+ if (n.type === 'EachBlock') {
268
+ if (n.fallback)
269
+ throw new Error(`${path}: {:else} in {#each} is not supported in a release build yet`);
270
+ if (n.context?.type !== 'Identifier')
271
+ throw new Error(`${path}: {#each} needs an item name (destructuring is not supported in a release build yet)`);
272
+ const item = n.context.name;
273
+ const index = n.index ?? `$i${c.loops.length}`;
274
+ const items = expr(src(n.expression), c);
275
+ const inner = { loops: [...c.loops, { item, index, param: `${item} = this.${items}(${args(c)})[0], ${index} = 0` }], names: withoutNames(c.names, [item, index]) };
276
+ out.push({ kind: 'for', items, key: n.key ? expr(src(n.key), inner) : null, item, index, body: nodes(n.body.nodes, inner) });
277
+ continue;
278
+ }
279
+ if (n.type === 'RenderTag') {
280
+ // A snippet renders in place: its parameters read the expressions it was rendered with.
281
+ const call = n.expression;
282
+ const snippet = call.type === 'CallExpression' && call.callee.type === 'Identifier' ? snippets.get(call.callee.name) : undefined;
283
+ if (!snippet)
284
+ throw new Error(`${path}: {@render ${src(call)}} renders a snippet this component does not declare`);
285
+ const names = new Map(c.names);
286
+ snippet.parameters.forEach((p, i) => {
287
+ if (p.type !== 'Identifier')
288
+ throw new Error(`${path}: snippet ${call.callee.name}'s parameters need names`);
289
+ const arg = call.arguments[i];
290
+ names.set(p.name, arg ? core.rewrite(src(arg), local(c)) : 'undefined');
291
+ });
292
+ out.push(...nodes(snippet.body.nodes, { loops: c.loops, names }));
293
+ continue;
294
+ }
295
+ throw new Error(`${path}: ${n.type} in a template is not supported in a release build yet`);
296
+ }
297
+ return out;
298
+ };
299
+ const template = nodes(ast.fragment.nodes, { loops: [], names: new Map() });
300
+ const source = [
301
+ `import { $ref, type EventData as $EventData } from '@nativescript/release';`,
302
+ ...imports,
303
+ '',
304
+ `export default class ${name} {`,
305
+ ...fields,
306
+ ...methods,
307
+ '}',
308
+ '',
309
+ ].join('\n');
310
+ const { styles, scope: styleScope } = compile ? svelteStyles(path, text, compile, 'client') : { styles: [], scope: null };
311
+ return { name, file: path + '.ts', source, props, template: styleScope ? core.scopeTemplate(template, styleScope) : template, styles, watchers: watchers.length ? watchers : undefined };
312
+ }
313
+ function derivedBody(init, kind, scope, path) {
314
+ const arg = init.arguments[0];
315
+ if (kind === '$derived')
316
+ return `{ return ${core.rewrite(arg.getText(), scope)}; }`;
317
+ if (!arg || !(ts.isArrowFunction(arg) || ts.isFunctionExpression(arg)))
318
+ throw new Error(`${path}: $derived.by needs a function`);
319
+ return ts.isBlock(arg.body) ? core.rewrite(arg.body.getText(), scope, 'statements') : `{ return ${core.rewrite(arg.body.getText(), scope)}; }`;
320
+ }
321
+ function withoutNames(names, shadowed) {
322
+ const out = new Map(names);
323
+ for (const s of shadowed)
324
+ out.delete(s);
325
+ return out;
326
+ }
327
+ function hasReturnValue(body) {
328
+ let found = false;
329
+ const visit = (n) => {
330
+ if (found || ts.isFunctionLike(n))
331
+ return;
332
+ if (ts.isReturnStatement(n) && n.expression)
333
+ found = true;
334
+ ts.forEachChild(n, visit);
335
+ };
336
+ ts.forEachChild(body, visit);
337
+ return found;
338
+ }
339
+ /**
340
+ * A `.svelte.ts` module's runes, as Svelte compiles them: a class's `$state`
341
+ * field is a ref behind an accessor pair and a `$derived` field a getter.
342
+ */
343
+ export function svelteModule(path, text) {
344
+ const sf = ts.createSourceFile(path, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
345
+ const edits = [];
346
+ const runeOf = (e) => (e && ts.isCallExpression(e) && /^\$(state|derived)(\.\w+)?$/.test(e.expression.getText()) ? e.expression.getText() : '');
347
+ const visit = (n) => {
348
+ if (ts.isPropertyDeclaration(n) && ts.isClassLike(n.parent) && runeOf(n.initializer)) {
349
+ const id = n.name.getText();
350
+ const init = n.initializer;
351
+ const kind = runeOf(init);
352
+ const type = init.typeArguments?.[0]?.getText() ?? n.type?.getText();
353
+ let code;
354
+ if (kind === '$state') {
355
+ code = `$${id} = $ref${type ? `<${type}>` : ''}(${init.arguments[0]?.getText() ?? 'undefined'});\n get ${id}()${type ? `: ${type}` : ''} { return this.$${id}.value; }\n set ${id}(value${type ? `: ${type}` : ''}) { this.$${id}.value = value; }`;
356
+ }
357
+ else if (kind === '$derived')
358
+ code = `get ${id}()${n.type ? `: ${n.type.getText()}` : ''} { return ${init.arguments[0].getText()}; }`;
359
+ else
360
+ throw new Error(`${path}: ${kind} is not supported in a release build yet`);
361
+ edits.push({ start: n.getStart(), end: n.getEnd(), text: code });
362
+ return;
363
+ }
364
+ if (ts.isCallExpression(n) && /^\$(state|derived|effect)\b/.test(n.expression.getText())) {
365
+ throw new Error(`${path}: ${n.expression.getText()} outside a class field is not supported in a .svelte.ts module in a release build yet`);
366
+ }
367
+ ts.forEachChild(n, visit);
368
+ };
369
+ visit(sf);
370
+ if (!edits.length)
371
+ return null;
372
+ let out = text;
373
+ for (const e of edits.sort((a, b) => b.start - a.start))
374
+ out = out.slice(0, e.start) + e.text + out.slice(e.end);
375
+ return `import { $ref } from '@nativescript/release';\n` + out;
376
+ }
package/package.json CHANGED
@@ -1,6 +1,57 @@
1
1
  {
2
2
  "name": "@nstudio/nativescript-compiler-svelte",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "9.2.0-alpha.10",
4
+ "description": "The Svelte adapter of @nstudio/nativescript-compiler: compiles a NativeScript app written with Svelte into a native iOS or Android app with no JavaScript runtime.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "source": "./index.ts",
9
+ "default": "./dist/index.js"
10
+ },
11
+ "./package.json": "./package.json"
12
+ },
13
+ "files": [
14
+ "dist/"
15
+ ],
16
+ "scripts": {
17
+ "build": "ns-compiled-adapter build .",
18
+ "prepack": "npm run build"
19
+ },
20
+ "license": "MIT",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/nstudio/nativescript-compiler.git",
24
+ "directory": "packages/svelte"
25
+ },
26
+ "dependencies": {
27
+ "svelte": "^4.2.20"
28
+ },
29
+ "peerDependencies": {
30
+ "@nstudio/nativescript-compiler": "9.2.0-alpha.10"
31
+ },
32
+ "nativescript": {
33
+ "compilerAdapter": {
34
+ "apiVersion": 1,
35
+ "detect": {
36
+ "priority": 40,
37
+ "dependencies": [
38
+ "@nativescript-community/svelte-native",
39
+ "svelte"
40
+ ],
41
+ "entryMentions": [
42
+ "svelte-native"
43
+ ],
44
+ "entryImports": [
45
+ "svelte"
46
+ ]
47
+ },
48
+ "testedVersions": {
49
+ "@nativescript-community/svelte-native": ">=1.0.0 <2.0.0 || >=5.0.0-alpha.0 <6.0.0",
50
+ "svelte": ">=4.2.0 <5.0.0 || >=5.50.0 <6.0.0"
51
+ }
52
+ }
53
+ },
54
+ "publishConfig": {
55
+ "access": "public"
56
+ }
57
+ }