@nstudio/nativescript-compiler-solid 0.0.0-stage → 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/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-solid
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
+ Solid adapter for [`@nstudio/nativescript-compiler`](https://www.npmjs.com/package/@nstudio/nativescript-compiler), enabling NativeScript Solid apps (`@nativescript-community/solid-js`) 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-solid
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/solid-js`: `>=2.0.0-rc.0 <3.0.0`
24
+ - `solid-js`: `>=2.0.0-rc.0 <3.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/index.js ADDED
@@ -0,0 +1,40 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { dirname, join } from 'node:path';
3
+ import { useCore, ts } from "./core-api.js";
4
+ import { solidComponent, solidRoutes, solidStore } from "./solid.js";
5
+ export default function adapter(core) {
6
+ useCore(core);
7
+ return {
8
+ apiVersion: 1,
9
+ name: 'solid',
10
+ packages: ['@nativescript-community/solid-js', 'solid-js'],
11
+ behaviour: { schedule: 'microtask', eventScope: 'none', propsOrder: 'pre', deferBindings: true, insertion: 'built', listenersAfterBindings: false, effectScope: 'depth', checkEveryBinding: 'off', slots: false, rowSignals: 'off', fragments: false, kit: { scope: { template: 'EffectOrder.depth', region: 'EffectOrder.deeper' } } },
12
+ reach: 'project',
13
+ frontEnd(app) {
14
+ const tsx = app.files.filter((f) => f.endsWith('.tsx'));
15
+ const texts = new Map([...app.sources, ...tsx].map((f) => [f, readFileSync(f, 'utf8')]));
16
+ const routerFile = tsx.find((f) => /<StackRouter\b/.test(texts.get(f)));
17
+ const { routes, initial } = routerFile ? solidRoutes(texts.get(routerFile)) : { routes: [], initial: '' };
18
+ const fns = [];
19
+ for (const f of tsx) {
20
+ if (f === routerFile)
21
+ continue;
22
+ const sf = ts.createSourceFile(f, texts.get(f), ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
23
+ for (const st of sf.statements)
24
+ if (ts.isFunctionDeclaration(st) && st.name && /^[A-Z]/.test(st.name.text))
25
+ fns.push({ file: f, fn: st });
26
+ }
27
+ const names = new Set(fns.map(({ fn }) => fn.name.text));
28
+ const components = fns.map(({ file, fn }) => solidComponent(file, fn, routes, names));
29
+ const overrides = new Map();
30
+ for (const f of app.sources) {
31
+ const store = solidStore(texts.get(f));
32
+ if (store)
33
+ overrides.set(f, store);
34
+ }
35
+ const start = routes.find((r) => r.name === initial);
36
+ components.push({ name: 'StackRouter', file: join(dirname(routerFile), 'StackRouter.solid.ts'), source: `import ${start.component} from './components/${start.component}.solid';\nexport default class StackRouter {}\n`, props: [], template: [{ kind: 'element', tag: 'Frame', attrs: [], events: [], children: [{ kind: 'component', name: start.component, props: [], events: [] }] }] });
37
+ return { components, modules: app.sources, overrides, root: 'StackRouter' };
38
+ },
39
+ };
40
+ }
package/dist/solid.js ADDED
@@ -0,0 +1,331 @@
1
+ import { dirname } from 'node:path';
2
+ import { core, ts } from "./core-api.js";
3
+ /**
4
+ * A Solid NativeScript component (dominative elements, `on:` events,
5
+ * `createSignal`/`createMemo`, `<Show>`/`<For>`, solid-navigation) as a
6
+ * virtual class. Solid is already signals: a getter call reads one, a setter
7
+ * call writes one, and a zero-argument arrow is a derived value.
8
+ */
9
+ export function solidComponent(path, fn, routes, components) {
10
+ const name = fn.name.text;
11
+ const sf = fn.getSourceFile();
12
+ const text = sf.getFullText();
13
+ const route = routes.find((r) => r.component === name);
14
+ const scope = { names: new Map() };
15
+ const fields = [];
16
+ const props = [];
17
+ const arity = new Map();
18
+ const imports = [];
19
+ for (const i of sf.statements.filter(ts.isImportDeclaration)) {
20
+ const from = i.moduleSpecifier.text;
21
+ if (from === 'solid-js' || from === 'solid-navigation')
22
+ continue;
23
+ const local = i.importClause?.name?.text;
24
+ if (local && components.has(local)) {
25
+ imports.push(`import ${local} from './${local}.solid';`);
26
+ continue;
27
+ }
28
+ imports.push(i.getText());
29
+ }
30
+ for (const r of routes)
31
+ if (r.component !== name && new RegExp(`navigate\\(\\s*['"]${r.name}['"]`).test(text) && !imports.some((i) => i.startsWith(`import ${r.component} `)))
32
+ imports.push(`import ${r.component} from './${r.component}.solid';`);
33
+ // `props: { recipe: Recipe; ... }`: `props.recipe` is the prop.
34
+ const param = fn.parameters[0];
35
+ const propsName = param && ts.isIdentifier(param.name) ? param.name.text : '';
36
+ if (param?.type && ts.isTypeLiteralNode(param.type)) {
37
+ for (const m of param.type.members) {
38
+ if (!ts.isPropertySignature(m) || !m.type)
39
+ continue;
40
+ const p = m.name.text;
41
+ props.push(p);
42
+ fields.push(` ${p}!: ${m.type.getText()};`);
43
+ if (ts.isFunctionTypeNode(m.type))
44
+ arity.set(p, m.type.parameters.length);
45
+ }
46
+ }
47
+ const body = fn.body.statements;
48
+ const ret = body.find(ts.isReturnStatement);
49
+ let paramsName = '';
50
+ // First pass: names, so every body member can read every other.
51
+ for (const st of body) {
52
+ if (st === ret)
53
+ continue;
54
+ if (ts.isFunctionDeclaration(st) && st.name) {
55
+ arity.set(st.name.text, st.parameters.length);
56
+ scope.names.set(st.name.text, `this.${st.name.text}`);
57
+ continue;
58
+ }
59
+ if (!ts.isVariableStatement(st))
60
+ throw new Error(`${path}: unsupported statement in ${name}: ${st.getText().slice(0, 60)}`);
61
+ for (const d of st.declarationList.declarations) {
62
+ const init = unwrapAs(d.initializer);
63
+ if (ts.isArrayBindingPattern(d.name)) {
64
+ const [value, setter] = d.name.elements.map((e) => (ts.isBindingElement(e) ? e.name.text : ''));
65
+ scope.names.set(value, `this.${value}`);
66
+ if (setter)
67
+ scope.names.set(setter, `this.$set_${value}`);
68
+ continue;
69
+ }
70
+ const id = d.name.text;
71
+ if (ts.isCallExpression(init) && init.expression.getText() === 'useParams') {
72
+ // A screen's params are its props.
73
+ paramsName = id;
74
+ const cast = d.initializer && ts.isAsExpression(d.initializer) ? d.initializer.type : null;
75
+ if (cast && ts.isTypeLiteralNode(cast))
76
+ for (const m of cast.members)
77
+ if (ts.isPropertySignature(m) && m.type) {
78
+ const p = m.name.text;
79
+ props.push(p);
80
+ fields.push(` ${p}!: ${m.type.getText()};`);
81
+ }
82
+ continue;
83
+ }
84
+ if (ts.isCallExpression(init) && init.expression.getText() === 'useRouter') {
85
+ scope.names.set(id, '$router');
86
+ continue;
87
+ }
88
+ if (paramsName && init.getText() === `${paramsName}.${id}`)
89
+ continue; // `const recipe = params.recipe`
90
+ const derived = (ts.isCallExpression(init) && init.expression.getText() === 'createMemo') || (ts.isArrowFunction(init) && !init.parameters.length);
91
+ // A memo or an accessor is read by calling it (`color()`): the call reads the derived method.
92
+ scope.names.set(id, derived ? `this.$get_${id}` : `this.${id}`);
93
+ if ((ts.isArrowFunction(init) || ts.isFunctionExpression(init)) && init.parameters.length)
94
+ arity.set(id, init.parameters.length);
95
+ }
96
+ }
97
+ for (const p of props)
98
+ scope.names.set(p, `this.${p}`);
99
+ const full = { names: scope.names, members: propsName ? { object: propsName, replacement: 'this' } : paramsName ? { object: paramsName, replacement: 'this' } : undefined };
100
+ // Setters: `setX(v)` writes, `setX((prev) => …)` updates.
101
+ const setters = (code) => code.replace(/this\.\$set_(\w+)\(/g, (_, v) => `this.${v}.$write(`);
102
+ for (const st of body) {
103
+ if (st === ret)
104
+ continue;
105
+ if (ts.isFunctionDeclaration(st) && st.name) {
106
+ fields.push(` ${(ts.getModifiers(st)?.some((m) => m.kind === ts.SyntaxKind.AsyncKeyword) ? 'async ' : '')}${st.name.text}(${st.parameters.map((p) => p.getText()).join(', ')})${st.type ? `: ${st.type.getText()}` : ''} ${setters(navigate(core.rewrite(st.body.getText(), full, 'statements'), routes))}`);
107
+ continue;
108
+ }
109
+ for (const d of st.declarationList.declarations) {
110
+ const init = unwrapAs(d.initializer);
111
+ if (ts.isArrayBindingPattern(d.name)) {
112
+ const value = d.name.elements[0].name.text;
113
+ const call = init;
114
+ const typeArgs = call.typeArguments ? `<${call.typeArguments.map((t) => t.getText()).join(', ')}>` : '';
115
+ fields.push(` ${value} = $state($writable${typeArgs}(${call.arguments[0] ? core.rewrite(call.arguments[0].getText(), full) : 'undefined'}));`);
116
+ continue;
117
+ }
118
+ const id = d.name.text;
119
+ if (!scope.names.has(id) || scope.names.get(id) === '$router')
120
+ continue;
121
+ if (paramsName && (init.getText() === `${paramsName}.${id}` || (ts.isCallExpression(init) && init.expression.getText() === 'useParams')))
122
+ continue;
123
+ if (scope.names.get(id) === `this.$get_${id}` && !(ts.isCallExpression(init) || ts.isArrowFunction(init)))
124
+ continue;
125
+ const derive = ts.isCallExpression(init) && init.expression.getText() === 'createMemo' ? init.arguments[0] : (ts.isArrowFunction(init) && !init.parameters.length ? init : null);
126
+ if (derive) {
127
+ // A memo or an accessor: `color()` reads it.
128
+ const b = ts.isBlock(derive.body) ? setters(core.rewrite(derive.body.getText(), full, 'statements')) : `{ return ${setters(core.rewrite(derive.body.getText(), full))}; }`;
129
+ fields.push(` $get_${id}() ${b}`);
130
+ continue;
131
+ }
132
+ if (ts.isArrowFunction(init) || ts.isFunctionExpression(init)) {
133
+ const b = ts.isBlock(init.body) ? init.body.getText() : `{ return ${init.body.getText()}; }`;
134
+ fields.push(` ${(ts.getModifiers(init)?.some((m) => m.kind === ts.SyntaxKind.AsyncKeyword) ? 'async ' : '')}${id}(${init.parameters.map((p) => p.getText()).join(', ')}) ${setters(navigate(core.rewrite(b, full, 'statements'), routes))}`);
135
+ continue;
136
+ }
137
+ fields.push(` get ${id}() { return ${core.rewrite(init.getText(), full)}; }`);
138
+ }
139
+ }
140
+ const methods = [];
141
+ let next = 0;
142
+ const params = (loops) => loops.map((l) => l.param).join(', ');
143
+ const args = (loops) => loops.flatMap((l) => [l.item, l.index]).join(', ');
144
+ const local = (loops, extra = {}) => {
145
+ const names = new Map(scope.names);
146
+ for (const l of loops) {
147
+ names.delete(l.item);
148
+ names.delete(l.index);
149
+ }
150
+ for (const [k, v] of Object.entries(extra))
151
+ names.set(k, v);
152
+ return { names, members: full.members };
153
+ };
154
+ // A keyed `<For>` passes its index as an accessor: `i()` reads the loop's index.
155
+ const indexReads = (code, loops) => loops.reduce((c, l) => c.replace(new RegExp(`(?<![\\w$.])${l.index.replace(/\$/g, '\\$')}\\(\\)`, 'g'), l.index), code);
156
+ const expr = (code, loops) => {
157
+ const m = `$b${next++}`;
158
+ methods.push(` ${m}(${params(loops)}) { return ${setters(core.rewrite(indexReads(code, loops), local(loops)))}; }`);
159
+ return m;
160
+ };
161
+ const handler = (e, loops) => {
162
+ const m = `$e${next++}`;
163
+ let code;
164
+ if (ts.isArrowFunction(e) || ts.isFunctionExpression(e)) {
165
+ const p = e.parameters[0] ? e.parameters[0].name.text : null;
166
+ const extra = p ? { [p]: '$event' } : {};
167
+ const body = indexReads(e.body.getText(), loops);
168
+ code = ts.isBlock(e.body) ? core.rewrite(body, local(loops, extra), 'statements') : `${core.rewrite(body, local(loops, extra)).slice(1, -1)};`;
169
+ }
170
+ else {
171
+ const t = e.getText();
172
+ code = `${core.rewrite(t, local(loops)).slice(1, -1)}(${arity.get(t) === 0 ? '' : '$event'});`;
173
+ }
174
+ methods.push(` ${m}(${[params(loops), '$event: $EventData'].filter(Boolean).join(', ')}) { ${setters(navigate(code, routes))} }`);
175
+ return m;
176
+ };
177
+ const element = (n, loops) => {
178
+ const open = ts.isJsxElement(n) ? n.openingElement : n;
179
+ const tag = open.tagName.getText();
180
+ const attr = (k) => open.attributes.properties.find((a) => ts.isJsxAttribute(a) && a.name.getText() === k)?.initializer;
181
+ if (tag === 'Show') {
182
+ const when = attr('when').expression;
183
+ return [{ kind: 'if', branches: [{ cond: expr(when.getText(), loops), body: ts.isJsxElement(n) ? children(n.children, loops) : [] }] }];
184
+ }
185
+ if (tag === 'For') {
186
+ const { items, item, index, body } = each(n, loops);
187
+ return [{ kind: 'for', items, key: null, item, index, body }];
188
+ }
189
+ const attrs = [];
190
+ const events = [];
191
+ const isComponent = /^[A-Z]/.test(tag);
192
+ for (const a of open.attributes.properties) {
193
+ if (!ts.isJsxAttribute(a))
194
+ throw new Error(`${path}: spread attributes are not supported in a release build yet`);
195
+ const raw = a.name.getText();
196
+ const init = a.initializer;
197
+ if (raw.startsWith('on:') && init && ts.isJsxExpression(init) && init.expression) {
198
+ events.push({ name: raw.slice(3), method: handler(init.expression, loops) });
199
+ continue;
200
+ }
201
+ if (!init)
202
+ attrs.push({ name: raw, value: 'true' });
203
+ else if (ts.isStringLiteral(init))
204
+ attrs.push({ name: raw, value: init.text });
205
+ else if (ts.isJsxExpression(init) && init.expression)
206
+ attrs.push({ name: raw, method: expr(init.expression.getText(), loops) });
207
+ }
208
+ if (isComponent) {
209
+ if (!components.has(tag))
210
+ throw new Error(`${path}: <${tag}> is not a component of the app`);
211
+ return [{ kind: 'component', name: tag, props: attrs, events }];
212
+ }
213
+ const el = core.canonical(tag);
214
+ if (!el)
215
+ throw new Error(`${path}: <${tag}> is not a @nativescript/core element the release build knows`);
216
+ if (el === 'ListView')
217
+ return [{ kind: 'element', tag: el, attrs, events, children: listRows(n, attrs, loops) }];
218
+ return [{ kind: 'element', tag: el, attrs, events, children: ts.isJsxElement(n) ? children(n.children, loops) : [] }];
219
+ };
220
+ /** `<For each={…}>{(item, i) => …}</For>`: the items method, the row's names and its body. */
221
+ const each = (n, loops) => {
222
+ const open = ts.isJsxElement(n) ? n.openingElement : n;
223
+ const init = open.attributes.properties.find((a) => ts.isJsxAttribute(a) && a.name.getText() === 'each')?.initializer;
224
+ const cb = ts.isJsxElement(n) ? n.children.find(ts.isJsxExpression)?.expression : undefined;
225
+ if (!init || !ts.isJsxExpression(init) || !init.expression || !cb || !ts.isArrowFunction(cb))
226
+ throw new Error(`${path}: <For> needs each={…} and a function child`);
227
+ const item = cb.parameters[0].name.text;
228
+ const index = cb.parameters[1] ? cb.parameters[1].name.text : `$i${loops.length}`;
229
+ const items = expr(init.expression.getText(), loops);
230
+ const inner = [...loops, { item, index, param: `${item} = this.${items}(${args(loops)})[0], ${index} = 0` }];
231
+ return { items, item, index, inner, body: jsx(cb.body, inner) };
232
+ };
233
+ /**
234
+ * A dominative `<listview>`'s rows: its views are its items, each shown in a cell of its own, so the
235
+ * one `<For>` that makes them is the list's items and its body the item template. A row that is a
236
+ * conditional becomes a template per branch.
237
+ */
238
+ const listRows = (n, attrs, loops) => {
239
+ const kids = ts.isJsxElement(n) ? n.children.filter((c) => !(ts.isJsxText(c) && c.containsOnlyTriviaWhiteSpaces)) : [];
240
+ const only = kids.length === 1 && ts.isJsxElement(kids[0]) && kids[0].openingElement.tagName.getText() === 'For' ? kids[0] : null;
241
+ if (!only || attrs.some((a) => a.name === 'items' || a.name === 'itemTemplateSelector'))
242
+ throw new Error(`${path}: a <listview>'s rows are one <For each={…}> child in a release build`);
243
+ const row = each(only, loops);
244
+ attrs.push({ name: 'items', method: row.items });
245
+ const { templates, selector } = core.rowTemplates(row.body, row.item, row.index);
246
+ if (selector) {
247
+ const m = `$b${next++}`;
248
+ methods.push(` ${m}(${params(row.inner)}): string { return ${selector((c) => `this.${c}(${args(row.inner)})`)}; }`);
249
+ attrs.push({ name: 'itemTemplateSelector', method: m });
250
+ }
251
+ return templates;
252
+ };
253
+ const jsx = (e, loops) => {
254
+ while (ts.isParenthesizedExpression(e))
255
+ e = e.expression;
256
+ if (ts.isJsxElement(e) || ts.isJsxSelfClosingElement(e))
257
+ return element(e, loops);
258
+ if (ts.isJsxFragment(e))
259
+ return children(e.children, loops);
260
+ if (ts.isConditionalExpression(e))
261
+ return [{ kind: 'if', branches: [{ cond: expr(e.condition.getText(), loops), body: jsx(e.whenTrue, loops) }, { cond: null, body: jsx(e.whenFalse, loops) }] }];
262
+ throw new Error(`${path}: {${e.getText().slice(0, 50)}} in JSX is not supported in a release build yet`);
263
+ };
264
+ const children = (list, loops) => list.flatMap((c) => (ts.isJsxText(c) ? [] : ts.isJsxExpression(c) ? (c.expression ? jsx(c.expression, loops) : []) : jsx(c, loops)));
265
+ const template = jsx(ret.expression, []);
266
+ const source = [`import { $writable, $state, $navigateTo, type EventData as $EventData } from '@nativescript/release';`, ...imports, '', `export default class ${name} {`, ...fields, ...methods, '}', ''].join('\n');
267
+ return { name, file: `${dirname(path)}/${name}.solid.ts`, source, props, template, page: !!route };
268
+ }
269
+ function unwrapAs(e) {
270
+ while (ts.isAsExpression(e) || ts.isParenthesizedExpression(e))
271
+ e = e.expression;
272
+ return e;
273
+ }
274
+ /** `router.navigate('Detail', { params: { recipe } })` → push the Detail route's page with those props. */
275
+ function navigate(code, routes) {
276
+ return code.replace(/\$router\.navigate\(\s*['"](\w+)['"]\s*,\s*\{\s*params\s*:\s*/g, (_, r) => {
277
+ const route = routes.find((x) => x.name === r);
278
+ if (!route)
279
+ throw new Error(`navigate('${r}'): no such route`);
280
+ return `$navigateTo(${route.component}, { props: `;
281
+ });
282
+ }
283
+ /** Routes and the initial one, from `<StackRouter initialRouteName><Route name component/></StackRouter>`. */
284
+ export function solidRoutes(text) {
285
+ const sf = ts.createSourceFile('app.tsx', text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
286
+ const routes = [];
287
+ let initial = '';
288
+ const visit = (n) => {
289
+ if (ts.isJsxOpeningElement(n) || ts.isJsxSelfClosingElement(n)) {
290
+ const attr = (k) => n.attributes.properties.find((a) => ts.isJsxAttribute(a) && a.name.getText() === k)?.initializer;
291
+ const tag = n.tagName.getText();
292
+ if (tag === 'StackRouter') {
293
+ const i = attr('initialRouteName');
294
+ if (i && ts.isStringLiteral(i))
295
+ initial = i.text;
296
+ }
297
+ if (tag === 'Route')
298
+ routes.push({ name: attr('name').text, component: attr('component').expression.getText() });
299
+ }
300
+ ts.forEachChild(n, visit);
301
+ };
302
+ visit(sf);
303
+ return { routes, initial: initial || routes[0]?.name || '' };
304
+ }
305
+ /** A module's `export const [x, setX] = createSignal(v)` as a writable signal `x`, and `setX(…)` as its write. */
306
+ export function solidStore(text) {
307
+ if (!/createSignal/.test(text))
308
+ return null;
309
+ const sf = ts.createSourceFile('store.ts', text, ts.ScriptTarget.Latest, true);
310
+ const setters = new Map();
311
+ let out = `import { $writable, $state } from '@nativescript/release';\n`;
312
+ for (const st of sf.statements) {
313
+ if (ts.isImportDeclaration(st) && st.moduleSpecifier.text === 'solid-js')
314
+ continue;
315
+ if (ts.isVariableStatement(st)) {
316
+ const d = st.declarationList.declarations[0];
317
+ if (ts.isArrayBindingPattern(d.name) && d.initializer && ts.isCallExpression(d.initializer) && d.initializer.expression.getText() === 'createSignal') {
318
+ const [value, setter] = d.name.elements.map((e) => (ts.isBindingElement(e) ? e.name.text : ''));
319
+ if (setter)
320
+ setters.set(setter, value);
321
+ const call = d.initializer;
322
+ out += `export const ${value} = $state($writable${call.typeArguments ? `<${call.typeArguments.map((t) => t.getText()).join(', ')}>` : ''}(${call.arguments[0]?.getText() ?? 'undefined'}));\n`;
323
+ continue;
324
+ }
325
+ }
326
+ out += st.getText() + '\n';
327
+ }
328
+ for (const [setter, value] of setters)
329
+ out = out.replace(new RegExp(`\\b${setter}\\(`, 'g'), `${value}.$write(`);
330
+ return out;
331
+ }
package/package.json CHANGED
@@ -1,6 +1,51 @@
1
1
  {
2
2
  "name": "@nstudio/nativescript-compiler-solid",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "9.2.0-alpha.11",
4
+ "description": "The Solid adapter of @nstudio/nativescript-compiler: compiles a NativeScript app written with Solid 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/solid"
25
+ },
26
+ "peerDependencies": {
27
+ "@nstudio/nativescript-compiler": "9.2.0-alpha.11"
28
+ },
29
+ "nativescript": {
30
+ "compilerAdapter": {
31
+ "apiVersion": 1,
32
+ "detect": {
33
+ "priority": 20,
34
+ "dependencies": [
35
+ "@nativescript-community/solid-js",
36
+ "solid-js"
37
+ ],
38
+ "entryMentions": [
39
+ "solid-js"
40
+ ]
41
+ },
42
+ "testedVersions": {
43
+ "@nativescript-community/solid-js": ">=2.0.0-rc.0 <3.0.0",
44
+ "solid-js": ">=2.0.0-rc.0 <3.0.0"
45
+ }
46
+ }
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ }
51
+ }