@mmapp/react-compiler 0.1.0-alpha.1 → 0.1.0-alpha.4
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/ATOM-PIPELINE.md +144 -0
- package/README.md +88 -40
- package/dist/auth-3UK75242.mjs +17 -0
- package/dist/babel/index.d.mts +2 -2
- package/dist/babel/index.d.ts +2 -2
- package/dist/babel/index.js +2816 -279
- package/dist/babel/index.mjs +2 -2
- package/dist/chunk-3USIFFE4.mjs +2190 -0
- package/dist/chunk-45YMGEVT.mjs +186 -0
- package/dist/chunk-4FN2AISW.mjs +148 -0
- package/dist/chunk-4OPI5L7G.mjs +2593 -0
- package/dist/chunk-4RYTKOOJ.mjs +186 -0
- package/dist/chunk-52XHYD2V.mjs +214 -0
- package/dist/chunk-5FTDWKHH.mjs +244 -0
- package/dist/chunk-5GUFFFGL.mjs +148 -0
- package/dist/chunk-5RKTOVR5.mjs +244 -0
- package/dist/chunk-5YDMOO4X.mjs +214 -0
- package/dist/chunk-64ZWEMLJ.mjs +148 -0
- package/dist/chunk-6XP4KSWQ.mjs +2190 -0
- package/dist/chunk-72QWL54I.mjs +175 -0
- package/dist/chunk-7B4TRI7C.mjs +4835 -0
- package/dist/chunk-7JRAEFRB.mjs +7510 -0
- package/dist/chunk-7T6Q5KAA.mjs +7506 -0
- package/dist/chunk-7ZKGHTNB.mjs +4952 -0
- package/dist/chunk-ABYPKRSB.mjs +215 -0
- package/dist/chunk-BZEXUPDH.mjs +175 -0
- package/dist/chunk-CIESM3BP.mjs +33 -0
- package/dist/chunk-DE3ZGQAC.mjs +148 -0
- package/dist/chunk-DMCY3BBG.mjs +1933 -0
- package/dist/chunk-DPIK3PJS.mjs +244 -0
- package/dist/chunk-E5IVH4RE.mjs +186 -0
- package/dist/chunk-E6FZNUR5.mjs +4953 -0
- package/dist/chunk-EJRBDQDP.mjs +2607 -0
- package/dist/chunk-ELO4TXJL.mjs +186 -0
- package/dist/chunk-EO6SYNCG.mjs +175 -0
- package/dist/chunk-FKRO52XH.mjs +3446 -0
- package/dist/chunk-FL4YAKU6.mjs +4941 -0
- package/dist/chunk-FYT47UBU.mjs +5076 -0
- package/dist/chunk-GCLGPOJZ.mjs +148 -0
- package/dist/chunk-GXB4JOP7.mjs +5072 -0
- package/dist/chunk-HFXOUMTD.mjs +175 -0
- package/dist/chunk-HRYR54PT.mjs +175 -0
- package/dist/chunk-HWIZ47US.mjs +214 -0
- package/dist/chunk-IB7MNPQL.mjs +4953 -0
- package/dist/chunk-ICSIHQCG.mjs +148 -0
- package/dist/chunk-J3M4GUS7.mjs +161 -0
- package/dist/chunk-J7JUAHS4.mjs +186 -0
- package/dist/chunk-JLA5VNQ3.mjs +186 -0
- package/dist/chunk-JQLWFCTM.mjs +214 -0
- package/dist/chunk-JRGFBWTN.mjs +2918 -0
- package/dist/chunk-KFJJCQAL.mjs +148 -0
- package/dist/chunk-KJUIIEQE.mjs +186 -0
- package/dist/chunk-KNWTHRVQ.mjs +175 -0
- package/dist/chunk-KSG4XSZF.mjs +175 -0
- package/dist/chunk-LF5N6DOU.mjs +175 -0
- package/dist/chunk-LJQCM2IM.mjs +214 -0
- package/dist/chunk-NTB7OEX2.mjs +2918 -0
- package/dist/chunk-NW6555WJ.mjs +186 -0
- package/dist/chunk-O4AUS7EU.mjs +148 -0
- package/dist/chunk-OMZE6VLQ.mjs +214 -0
- package/dist/chunk-OPJKP747.mjs +7506 -0
- package/dist/chunk-P4BR7WVO.mjs +2190 -0
- package/dist/chunk-QQHVYH2X.mjs +244 -0
- package/dist/chunk-R2DD5GTY.mjs +186 -0
- package/dist/chunk-S5QLWLLT.mjs +186 -0
- package/dist/chunk-SCWGT2FY.mjs +2190 -0
- package/dist/chunk-SMKJUSB3.mjs +2190 -0
- package/dist/chunk-THFYE5ZX.mjs +244 -0
- package/dist/chunk-UDDTWG5J.mjs +734 -0
- package/dist/chunk-VCAY2KGM.mjs +175 -0
- package/dist/chunk-VLTKQDJ3.mjs +244 -0
- package/dist/chunk-WBYMW4NQ.mjs +3450 -0
- package/dist/chunk-WECAV6QB.mjs +148 -0
- package/dist/chunk-WMKBXUCE.mjs +3228 -0
- package/dist/chunk-WVYY32LD.mjs +939 -0
- package/dist/chunk-XAJ5BKKL.mjs +4947 -0
- package/dist/chunk-XDVM4YHX.mjs +3450 -0
- package/dist/chunk-XG2X7AEA.mjs +175 -0
- package/dist/chunk-XG7Z23NQ.mjs +148 -0
- package/dist/chunk-XWZAOCQ7.mjs +2607 -0
- package/dist/chunk-Y6MA7ULW.mjs +148 -0
- package/dist/chunk-YMS7Q7LG.mjs +214 -0
- package/dist/chunk-Z2G5RZ4H.mjs +186 -0
- package/dist/chunk-ZA37XTGA.mjs +175 -0
- package/dist/chunk-ZE3KCHBM.mjs +2918 -0
- package/dist/cli/index.js +14720 -7199
- package/dist/cli/index.mjs +224 -183
- package/dist/codemod/cli.js +1 -1
- package/dist/codemod/cli.mjs +2 -2
- package/dist/codemod/index.d.mts +3 -3
- package/dist/codemod/index.d.ts +3 -3
- package/dist/codemod/index.js +1 -1
- package/dist/codemod/index.mjs +2 -2
- package/dist/config-PL24KEWL.mjs +219 -0
- package/dist/deploy-YAJGW6II.mjs +9 -0
- package/dist/dev-server-CrQ041KP.d.mts +79 -0
- package/dist/dev-server-CrQ041KP.d.ts +79 -0
- package/dist/dev-server-RmGHIntF.d.mts +113 -0
- package/dist/dev-server-RmGHIntF.d.ts +113 -0
- package/dist/dev-server.d.mts +2 -2
- package/dist/dev-server.d.ts +2 -2
- package/dist/dev-server.js +6424 -1597
- package/dist/dev-server.mjs +5 -5
- package/dist/envelope-ChEkuHij.d.mts +265 -0
- package/dist/envelope-ChEkuHij.d.ts +265 -0
- package/dist/envelope.d.mts +2 -2
- package/dist/envelope.d.ts +2 -2
- package/dist/envelope.js +2814 -277
- package/dist/envelope.mjs +3 -3
- package/dist/index-CEKyyazf.d.mts +104 -0
- package/dist/index-CEKyyazf.d.ts +104 -0
- package/dist/index.d.mts +168 -9
- package/dist/index.d.ts +168 -9
- package/dist/index.js +5606 -681
- package/dist/index.mjs +217 -9
- package/dist/init-7FJENUDK.mjs +407 -0
- package/{src/cli/init.ts → dist/init-7JQMAAXS.mjs} +70 -95
- package/dist/init-DQDX3QK6.mjs +369 -0
- package/dist/init-EHO4VQ22.mjs +369 -0
- package/dist/init-UC3FWPIW.mjs +367 -0
- package/dist/init-UNSMVKIK.mjs +366 -0
- package/dist/init-UNV5XIDE.mjs +367 -0
- package/dist/project-compiler-2P4N4DR7.mjs +10 -0
- package/dist/project-compiler-D2LCC27O.mjs +10 -0
- package/dist/project-compiler-EJ3GANJE.mjs +10 -0
- package/dist/project-compiler-LOQKVRZJ.mjs +10 -0
- package/dist/project-compiler-NNK32MPG.mjs +10 -0
- package/dist/project-compiler-OP2VVGJQ.mjs +10 -0
- package/dist/project-compiler-RQ6OQKRM.mjs +10 -0
- package/dist/project-compiler-VWNNCHGO.mjs +10 -0
- package/dist/project-compiler-XVAAU4C5.mjs +10 -0
- package/dist/project-compiler-YES5FGMD.mjs +10 -0
- package/dist/project-compiler-ZB4RUYVL.mjs +10 -0
- package/dist/project-compiler-ZKMQDLGU.mjs +10 -0
- package/dist/project-decompiler-FLXCEJHS.mjs +7 -0
- package/dist/project-decompiler-U55HQUHW.mjs +7 -0
- package/dist/project-decompiler-US7GAVIC.mjs +7 -0
- package/dist/project-decompiler-VLPR22QF.mjs +7 -0
- package/dist/pull-FUS5QYZS.mjs +109 -0
- package/dist/pull-KOL2QAYQ.mjs +109 -0
- package/dist/pull-LD5ENLGY.mjs +109 -0
- package/dist/pull-P44LDRWB.mjs +109 -0
- package/dist/seed-KOGEPGOJ.mjs +154 -0
- package/dist/server-VW6UPCHO.mjs +277 -0
- package/dist/testing/index.d.mts +8 -8
- package/dist/testing/index.d.ts +8 -8
- package/dist/testing/index.js +2824 -287
- package/dist/testing/index.mjs +2 -2
- package/dist/verify-BYHUKARQ.mjs +1833 -0
- package/dist/verify-OQDEQYMS.mjs +1833 -0
- package/dist/verify-SEIXUGN4.mjs +1833 -0
- package/dist/vite/index.d.mts +1 -1
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +2817 -280
- package/dist/vite/index.mjs +3 -3
- package/examples/authentication/main.workflow.tsx +1 -1
- package/examples/authentication/mm.config.ts +1 -1
- package/examples/authentication/pages/LoginPage.tsx +2 -2
- package/examples/authentication/pages/SignupPage.tsx +2 -2
- package/examples/counter.workflow.tsx +1 -1
- package/examples/dashboard.workflow.tsx +1 -1
- package/examples/invoice-approval/actions/invoice.server.ts +1 -1
- package/examples/invoice-approval/main.workflow.tsx +1 -1
- package/examples/invoice-approval/mm.config.ts +1 -1
- package/examples/invoice-approval/pages/InvoiceDetailPage.tsx +1 -1
- package/examples/invoice-approval/pages/InvoiceFormPage.tsx +1 -1
- package/examples/invoice-approval/pages/InvoiceListPage.tsx +1 -1
- package/examples/todo-app.workflow.tsx +1 -1
- package/examples/uber-app/actions/matching.server.ts +1 -1
- package/examples/uber-app/actions/notifications.server.ts +1 -1
- package/examples/uber-app/actions/payments.server.ts +1 -1
- package/examples/uber-app/actions/pricing.server.ts +1 -1
- package/examples/uber-app/app/admin/analytics.tsx +2 -2
- package/examples/uber-app/app/admin/fleet.tsx +21 -21
- package/examples/uber-app/app/admin/surge-pricing.tsx +2 -2
- package/examples/uber-app/app/driver/dashboard.tsx +2 -2
- package/examples/uber-app/app/driver/earnings.tsx +2 -2
- package/examples/uber-app/app/driver/navigation.tsx +2 -2
- package/examples/uber-app/app/driver/ride-acceptance.tsx +2 -2
- package/examples/uber-app/app/rider/home.tsx +2 -2
- package/examples/uber-app/app/rider/payment-methods.tsx +2 -2
- package/examples/uber-app/app/rider/ride-history.tsx +2 -2
- package/examples/uber-app/app/rider/ride-tracking.tsx +2 -2
- package/examples/uber-app/components/DriverCard.tsx +1 -1
- package/examples/uber-app/components/MapView.tsx +3 -3
- package/examples/uber-app/components/RatingStars.tsx +2 -2
- package/examples/uber-app/components/RideCard.tsx +1 -1
- package/examples/uber-app/mm.config.ts +1 -1
- package/examples/uber-app/workflows/dispute-resolution.workflow.tsx +2 -2
- package/examples/uber-app/workflows/driver-onboarding.workflow.tsx +2 -2
- package/examples/uber-app/workflows/payment-processing.workflow.tsx +2 -2
- package/examples/uber-app/workflows/ride-request.workflow.tsx +2 -2
- package/package.json +10 -4
- package/compile-blueprint-chat.mjs +0 -99
- package/compile-blueprint-glass-console.mjs +0 -98
- package/compile-chat-defs.mjs +0 -92
- package/examples/uber-app/tests/payment.test.tsx +0 -129
- package/examples/uber-app/tests/ride-flow.test.tsx +0 -123
- package/package.json.backup +0 -86
- package/scripts/decompile.ts +0 -226
- package/scripts/seed-auth.ts +0 -267
- package/scripts/seed-uber.ts +0 -248
- package/scripts/validate-uber.ts +0 -119
- package/seed-blueprint-chat.mjs +0 -444
- package/seed-blueprint-glass-console.mjs +0 -445
- package/seed-compiled.mjs +0 -318
- package/src/RoundTripValidator.ts +0 -400
- package/src/__tests__/atom-rendering-coverage.test.ts +0 -680
- package/src/__tests__/auth-module-compilation.test.ts +0 -247
- package/src/__tests__/auth-template-compilation.test.ts +0 -589
- package/src/__tests__/change-extractor.test.ts +0 -142
- package/src/__tests__/cli-pull.test.ts +0 -73
- package/src/__tests__/cli-test.test.ts +0 -72
- package/src/__tests__/component-extractor.test.ts +0 -331
- package/src/__tests__/context-extractor.test.ts +0 -145
- package/src/__tests__/decompiler.test.ts +0 -718
- package/src/__tests__/define-blueprint.test.ts +0 -133
- package/src/__tests__/definition-validator.test.ts +0 -519
- package/src/__tests__/during-extractor.test.ts +0 -152
- package/src/__tests__/effect-extractor.test.ts +0 -107
- package/src/__tests__/event-emission.test.ts +0 -127
- package/src/__tests__/examples.test.ts +0 -236
- package/src/__tests__/full-blueprint-coverage.test.ts +0 -1221
- package/src/__tests__/golden-suite.test.ts +0 -403
- package/src/__tests__/grammar-island-extractor.test.ts +0 -289
- package/src/__tests__/instance-key.test.ts +0 -82
- package/src/__tests__/ir-migration.test.ts +0 -255
- package/src/__tests__/lock-file.test.ts +0 -117
- package/src/__tests__/model-extractor.test.ts +0 -195
- package/src/__tests__/model-field-acl.test.ts +0 -237
- package/src/__tests__/model-hooks.test.ts +0 -130
- package/src/__tests__/model-ref-resolution.test.ts +0 -268
- package/src/__tests__/model-roundtrip.test.ts +0 -502
- package/src/__tests__/model-runtime.test.ts +0 -112
- package/src/__tests__/model-transitions.test.ts +0 -183
- package/src/__tests__/nrt-action-trace.test.ts +0 -391
- package/src/__tests__/pipeline-hardening.test.ts +0 -413
- package/src/__tests__/project-compiler.test.ts +0 -546
- package/src/__tests__/project-decompiler.test.ts +0 -343
- package/src/__tests__/query-compilation.test.ts +0 -145
- package/src/__tests__/round-trip/PLAN.md +0 -158
- package/src/__tests__/round-trip/README.md +0 -52
- package/src/__tests__/round-trip/RESULTS.md +0 -86
- package/src/__tests__/round-trip/fixtures/data-heavy/main.workflow.tsx +0 -55
- package/src/__tests__/round-trip/fixtures/data-heavy/mm.config.ts +0 -11
- package/src/__tests__/round-trip/fixtures/data-heavy/models/contact.ts +0 -54
- package/src/__tests__/round-trip/fixtures/full-workflow/main.workflow.tsx +0 -79
- package/src/__tests__/round-trip/fixtures/full-workflow/mm.config.ts +0 -12
- package/src/__tests__/round-trip/fixtures/full-workflow/models/order.ts +0 -50
- package/src/__tests__/round-trip/fixtures/simple-crud/main.workflow.tsx +0 -25
- package/src/__tests__/round-trip/fixtures/simple-crud/mm.config.ts +0 -11
- package/src/__tests__/round-trip/fixtures/simple-crud/models/task.ts +0 -32
- package/src/__tests__/round-trip/fixtures/view-heavy/main.workflow.tsx +0 -79
- package/src/__tests__/round-trip/fixtures/view-heavy/mm.config.ts +0 -10
- package/src/__tests__/round-trip/round-trip.test.ts +0 -2598
- package/src/__tests__/round-trip-ir.test.ts +0 -300
- package/src/__tests__/round-trip.test.ts +0 -1212
- package/src/__tests__/route-merging.test.ts +0 -372
- package/src/__tests__/router-composition.test.ts +0 -489
- package/src/__tests__/router-extractor.test.ts +0 -176
- package/src/__tests__/server-action-extractor.test.ts +0 -128
- package/src/__tests__/smart-type-inference.test.ts +0 -365
- package/src/__tests__/source-envelope.test.ts +0 -284
- package/src/__tests__/source-fidelity.test.ts +0 -516
- package/src/__tests__/state-extractor.test.ts +0 -115
- package/src/__tests__/strict-mode.test.ts +0 -227
- package/src/__tests__/transition-effect-extractor.test.ts +0 -119
- package/src/__tests__/transition-extractor.test.ts +0 -68
- package/src/__tests__/ts-to-expression.test.ts +0 -462
- package/src/__tests__/type-generator.test.ts +0 -201
- package/src/__tests__/uber-validation.test.ts +0 -502
- package/src/action-compiler.ts +0 -361
- package/src/babel/emitters/experience-transform.ts +0 -199
- package/src/babel/emitters/ir-to-tsx-emitter.ts +0 -110
- package/src/babel/emitters/pure-form-emitter.ts +0 -1023
- package/src/babel/emitters/runtime-glue-emitter.ts +0 -39
- package/src/babel/extractors/change-extractor.ts +0 -199
- package/src/babel/extractors/component-extractor.ts +0 -907
- package/src/babel/extractors/computed-extractor.ts +0 -262
- package/src/babel/extractors/context-extractor.ts +0 -277
- package/src/babel/extractors/during-extractor.ts +0 -295
- package/src/babel/extractors/effect-extractor.ts +0 -340
- package/src/babel/extractors/event-extractor.ts +0 -235
- package/src/babel/extractors/grammar-island-extractor.ts +0 -302
- package/src/babel/extractors/model-extractor.ts +0 -1018
- package/src/babel/extractors/router-extractor.ts +0 -303
- package/src/babel/extractors/server-action-extractor.ts +0 -173
- package/src/babel/extractors/server-action-hook-extractor.ts +0 -72
- package/src/babel/extractors/server-state-extractor.ts +0 -88
- package/src/babel/extractors/state-extractor.ts +0 -214
- package/src/babel/extractors/transition-effect-extractor.ts +0 -176
- package/src/babel/extractors/transition-extractor.ts +0 -143
- package/src/babel/index.ts +0 -24
- package/src/babel/transpilers/ts-to-expression.ts +0 -674
- package/src/babel/visitor.ts +0 -807
- package/src/cli/auth.ts +0 -255
- package/src/cli/build.ts +0 -288
- package/src/cli/deploy.ts +0 -206
- package/src/cli/index.ts +0 -328
- package/src/cli/installer.ts +0 -261
- package/src/cli/lock-file.ts +0 -94
- package/src/cli/mmrc.ts +0 -22
- package/src/cli/pull.ts +0 -172
- package/src/cli/registry-client.ts +0 -175
- package/src/cli/test.ts +0 -397
- package/src/cli/type-generator.ts +0 -243
- package/src/codemod/__tests__/forward.test.ts +0 -239
- package/src/codemod/__tests__/reverse.test.ts +0 -145
- package/src/codemod/__tests__/round-trip.test.ts +0 -137
- package/src/codemod/annotation.ts +0 -97
- package/src/codemod/classify.ts +0 -197
- package/src/codemod/cli.ts +0 -207
- package/src/codemod/control-flow.ts +0 -409
- package/src/codemod/forward.ts +0 -244
- package/src/codemod/import-manager.ts +0 -171
- package/src/codemod/index.ts +0 -120
- package/src/codemod/reverse.ts +0 -197
- package/src/codemod/rules.ts +0 -174
- package/src/codemod/state-transform.ts +0 -126
- package/src/decompiler/ast-builder.ts +0 -538
- package/src/decompiler/config-generator.ts +0 -151
- package/src/decompiler/index.ts +0 -315
- package/src/decompiler/project-decompiler.ts +0 -1776
- package/src/decompiler/project.ts +0 -862
- package/src/decompiler/split-strategy.ts +0 -140
- package/src/decompiler/state-emitter.ts +0 -1053
- package/src/decompiler/sx-emitter.ts +0 -318
- package/src/decompiler/workspace-hydrator.ts +0 -189
- package/src/dev-server.ts +0 -238
- package/src/envelope/fs-tree.ts +0 -217
- package/src/envelope/source-envelope.ts +0 -264
- package/src/envelope.ts +0 -315
- package/src/incremental-compiler.ts +0 -401
- package/src/index.ts +0 -99
- package/src/model-compiler.ts +0 -277
- package/src/project-compiler.ts +0 -1629
- package/src/route-extractor.ts +0 -333
- package/src/testing/index.ts +0 -32
- package/src/testing/snapshot.ts +0 -252
- package/src/testing/test-utils.ts +0 -226
- package/src/types.ts +0 -68
- package/src/vite/index.ts +0 -288
- package/test-compile.mjs +0 -142
- package/tsconfig.json +0 -25
- package/tsup.config.ts +0 -23
- package/vitest.config.ts +0 -9
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type Generator — converts a WorkflowDefinition into a TypeScript .d.ts file.
|
|
3
|
-
*
|
|
4
|
-
* Generates:
|
|
5
|
-
* - defineModel() call with `as const` assertion
|
|
6
|
-
* - Field types mapped to TypeScript types
|
|
7
|
-
* - State names as union type
|
|
8
|
-
* - Transition names as union type
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type { WorkflowDefinitionResponse } from './registry-client';
|
|
12
|
-
|
|
13
|
-
/** Map workflow field types to TypeScript types */
|
|
14
|
-
const FIELD_TYPE_MAP: Record<string, string> = {
|
|
15
|
-
string: 'string',
|
|
16
|
-
text: 'string',
|
|
17
|
-
email: 'string',
|
|
18
|
-
url: 'string',
|
|
19
|
-
phone: 'string',
|
|
20
|
-
password: 'string',
|
|
21
|
-
slug: 'string',
|
|
22
|
-
color: 'string',
|
|
23
|
-
number: 'number',
|
|
24
|
-
integer: 'number',
|
|
25
|
-
float: 'number',
|
|
26
|
-
decimal: 'number',
|
|
27
|
-
currency: 'number',
|
|
28
|
-
percentage: 'number',
|
|
29
|
-
boolean: 'boolean',
|
|
30
|
-
date: 'string',
|
|
31
|
-
datetime: 'string',
|
|
32
|
-
time: 'string',
|
|
33
|
-
timestamp: 'string',
|
|
34
|
-
json: 'unknown',
|
|
35
|
-
object: 'Record<string, unknown>',
|
|
36
|
-
array: 'unknown[]',
|
|
37
|
-
file: 'string',
|
|
38
|
-
image: 'string',
|
|
39
|
-
reference: 'string',
|
|
40
|
-
enum: 'string',
|
|
41
|
-
select: 'string',
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
function getTsType(fieldType: string): string {
|
|
45
|
-
return FIELD_TYPE_MAP[fieldType] ?? 'unknown';
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function escapeStringLiteral(s: string): string {
|
|
49
|
-
return s.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function serializeDefault(value: unknown): string {
|
|
53
|
-
if (value === undefined || value === null) return "''";
|
|
54
|
-
if (typeof value === 'string') return `'${escapeStringLiteral(value)}'`;
|
|
55
|
-
if (typeof value === 'number' || typeof value === 'boolean') return String(value);
|
|
56
|
-
if (Array.isArray(value)) return JSON.stringify(value);
|
|
57
|
-
return JSON.stringify(value);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Generate a .d.ts file from a workflow definition response.
|
|
62
|
-
*/
|
|
63
|
-
export function generateTypeDeclaration(def: WorkflowDefinitionResponse): string {
|
|
64
|
-
const lines: string[] = [];
|
|
65
|
-
|
|
66
|
-
lines.push("import { defineModel } from '@mindmatrix/react';");
|
|
67
|
-
lines.push('');
|
|
68
|
-
lines.push('declare const _default: ReturnType<typeof defineModel<{');
|
|
69
|
-
lines.push(` readonly slug: '${escapeStringLiteral(def.slug)}';`);
|
|
70
|
-
lines.push(` readonly version: '${escapeStringLiteral(def.version || '1.0.0')}';`);
|
|
71
|
-
|
|
72
|
-
// Fields
|
|
73
|
-
if (def.fields && def.fields.length > 0) {
|
|
74
|
-
lines.push(' readonly fields: {');
|
|
75
|
-
for (const field of def.fields) {
|
|
76
|
-
const props: string[] = [];
|
|
77
|
-
props.push(`readonly type: '${escapeStringLiteral(field.type)}'`);
|
|
78
|
-
|
|
79
|
-
if (field.default_value !== undefined && field.default_value !== null) {
|
|
80
|
-
props.push(`readonly default: ${serializeDefault(field.default_value)}`);
|
|
81
|
-
} else {
|
|
82
|
-
// Provide a sensible default based on type
|
|
83
|
-
const tsType = getTsType(field.type);
|
|
84
|
-
if (tsType === 'string') props.push("readonly default: ''");
|
|
85
|
-
else if (tsType === 'number') props.push('readonly default: 0');
|
|
86
|
-
else if (tsType === 'boolean') props.push('readonly default: false');
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (field.validation?.enum && field.validation.enum.length > 0) {
|
|
90
|
-
const enumValues = field.validation.enum
|
|
91
|
-
.map(v => `'${escapeStringLiteral(v)}'`)
|
|
92
|
-
.join(', ');
|
|
93
|
-
props.push(`readonly enum: readonly [${enumValues}]`);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (field.required) {
|
|
97
|
-
props.push('readonly required: true');
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
lines.push(` readonly ${field.name}: { ${props.join('; ')} };`);
|
|
101
|
-
}
|
|
102
|
-
lines.push(' };');
|
|
103
|
-
} else {
|
|
104
|
-
lines.push(' readonly fields: {};');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// States
|
|
108
|
-
if (def.states && def.states.length > 0) {
|
|
109
|
-
lines.push(' readonly states: {');
|
|
110
|
-
for (const state of def.states) {
|
|
111
|
-
const stateProps: string[] = [];
|
|
112
|
-
if (state.type === 'initial') {
|
|
113
|
-
stateProps.push("readonly type: 'initial'");
|
|
114
|
-
} else if (state.type === 'final') {
|
|
115
|
-
stateProps.push("readonly type: 'final'");
|
|
116
|
-
}
|
|
117
|
-
lines.push(` readonly ${state.name}: { ${stateProps.join('; ')} };`);
|
|
118
|
-
}
|
|
119
|
-
lines.push(' };');
|
|
120
|
-
} else {
|
|
121
|
-
lines.push(' readonly states: {};');
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Transitions
|
|
125
|
-
if (def.transitions && def.transitions.length > 0) {
|
|
126
|
-
lines.push(' readonly transitions: {');
|
|
127
|
-
for (const transition of def.transitions) {
|
|
128
|
-
const tProps: string[] = [];
|
|
129
|
-
|
|
130
|
-
// from — use first element as string literal, or union if multiple
|
|
131
|
-
if (transition.from.length === 1) {
|
|
132
|
-
tProps.push(`readonly from: '${escapeStringLiteral(transition.from[0])}'`);
|
|
133
|
-
} else if (transition.from.length > 1) {
|
|
134
|
-
const fromUnion = transition.from.map(f => `'${escapeStringLiteral(f)}'`).join(' | ');
|
|
135
|
-
tProps.push(`readonly from: ${fromUnion}`);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
tProps.push(`readonly to: '${escapeStringLiteral(transition.to)}'`);
|
|
139
|
-
|
|
140
|
-
lines.push(` readonly ${transition.name}: { ${tProps.join('; ')} };`);
|
|
141
|
-
}
|
|
142
|
-
lines.push(' };');
|
|
143
|
-
} else {
|
|
144
|
-
lines.push(' readonly transitions: {};');
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
lines.push('}>>;');
|
|
148
|
-
lines.push('export default _default;');
|
|
149
|
-
lines.push('');
|
|
150
|
-
|
|
151
|
-
// Also export state and transition union types for convenience
|
|
152
|
-
if (def.states && def.states.length > 0) {
|
|
153
|
-
const stateUnion = def.states.map(s => `'${escapeStringLiteral(s.name)}'`).join(' | ');
|
|
154
|
-
lines.push(`export type States = ${stateUnion};`);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (def.transitions && def.transitions.length > 0) {
|
|
158
|
-
const transitionUnion = def.transitions.map(t => `'${escapeStringLiteral(t.name)}'`).join(' | ');
|
|
159
|
-
lines.push(`export type Transitions = ${transitionUnion};`);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (def.fields && def.fields.length > 0) {
|
|
163
|
-
lines.push('');
|
|
164
|
-
lines.push('export interface Fields {');
|
|
165
|
-
for (const field of def.fields) {
|
|
166
|
-
const tsType = getTsType(field.type);
|
|
167
|
-
lines.push(` ${field.name}: ${tsType};`);
|
|
168
|
-
}
|
|
169
|
-
lines.push('}');
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
lines.push('');
|
|
173
|
-
|
|
174
|
-
return lines.join('\n');
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Generate a full source index.ts for a workflow package (--full mode).
|
|
179
|
-
*/
|
|
180
|
-
export function generateFullSource(def: WorkflowDefinitionResponse): string {
|
|
181
|
-
const lines: string[] = [];
|
|
182
|
-
|
|
183
|
-
lines.push("import { defineModel } from '@mindmatrix/react';");
|
|
184
|
-
lines.push('');
|
|
185
|
-
lines.push('export default defineModel({');
|
|
186
|
-
lines.push(` slug: '${escapeStringLiteral(def.slug)}',`);
|
|
187
|
-
lines.push(` version: '${escapeStringLiteral(def.version || '1.0.0')}',`);
|
|
188
|
-
|
|
189
|
-
if (def.fields && def.fields.length > 0) {
|
|
190
|
-
lines.push(' fields: {');
|
|
191
|
-
for (const field of def.fields) {
|
|
192
|
-
const props: string[] = [];
|
|
193
|
-
props.push(`type: '${escapeStringLiteral(field.type)}'`);
|
|
194
|
-
if (field.default_value !== undefined && field.default_value !== null) {
|
|
195
|
-
props.push(`default: ${serializeDefault(field.default_value)}`);
|
|
196
|
-
}
|
|
197
|
-
if (field.validation?.enum) {
|
|
198
|
-
const enumValues = field.validation.enum
|
|
199
|
-
.map(v => `'${escapeStringLiteral(v)}'`)
|
|
200
|
-
.join(', ');
|
|
201
|
-
props.push(`enum: [${enumValues}] as const`);
|
|
202
|
-
}
|
|
203
|
-
if (field.required) {
|
|
204
|
-
props.push('required: true');
|
|
205
|
-
}
|
|
206
|
-
lines.push(` ${field.name}: { ${props.join(', ')} },`);
|
|
207
|
-
}
|
|
208
|
-
lines.push(' },');
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (def.states && def.states.length > 0) {
|
|
212
|
-
lines.push(' states: {');
|
|
213
|
-
for (const state of def.states) {
|
|
214
|
-
if (state.type === 'initial' || state.type === 'final') {
|
|
215
|
-
lines.push(` ${state.name}: { type: '${state.type}' },`);
|
|
216
|
-
} else {
|
|
217
|
-
lines.push(` ${state.name}: {},`);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
lines.push(' },');
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (def.transitions && def.transitions.length > 0) {
|
|
224
|
-
lines.push(' transitions: {');
|
|
225
|
-
for (const transition of def.transitions) {
|
|
226
|
-
const tProps: string[] = [];
|
|
227
|
-
if (transition.from.length === 1) {
|
|
228
|
-
tProps.push(`from: '${escapeStringLiteral(transition.from[0])}'`);
|
|
229
|
-
} else {
|
|
230
|
-
const fromArr = transition.from.map(f => `'${escapeStringLiteral(f)}'`).join(', ');
|
|
231
|
-
tProps.push(`from: [${fromArr}]`);
|
|
232
|
-
}
|
|
233
|
-
tProps.push(`to: '${escapeStringLiteral(transition.to)}'`);
|
|
234
|
-
lines.push(` ${transition.name}: { ${tProps.join(', ')} },`);
|
|
235
|
-
}
|
|
236
|
-
lines.push(' },');
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
lines.push('} as const);');
|
|
240
|
-
lines.push('');
|
|
241
|
-
|
|
242
|
-
return lines.join('\n');
|
|
243
|
-
}
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { transform } from '../index';
|
|
3
|
-
|
|
4
|
-
function forward(source: string): string {
|
|
5
|
-
return transform(source, { direction: 'forward', annotate: false }).code;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function forwardAnnotated(source: string): string {
|
|
9
|
-
return transform(source, { direction: 'forward', annotate: true }).code;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
describe('forward transform', () => {
|
|
13
|
-
describe('element mapping', () => {
|
|
14
|
-
it('div with flex → Row', () => {
|
|
15
|
-
const input = `const App = () => <div className="flex items-center gap-2">hello</div>;`;
|
|
16
|
-
const output = forward(input);
|
|
17
|
-
expect(output).toContain('<Row');
|
|
18
|
-
expect(output).toContain('items-center gap-2');
|
|
19
|
-
expect(output).not.toContain('"flex ');
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('div with flex flex-col → Stack', () => {
|
|
23
|
-
const input = `const App = () => <div className="flex flex-col gap-4">hello</div>;`;
|
|
24
|
-
const output = forward(input);
|
|
25
|
-
expect(output).toContain('<Stack');
|
|
26
|
-
expect(output).toContain('gap-4');
|
|
27
|
-
expect(output).not.toContain('flex-col');
|
|
28
|
-
expect(output).not.toContain('"flex ');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('div with grid → Grid', () => {
|
|
32
|
-
const input = `const App = () => <div className="grid grid-cols-3 gap-2">hello</div>;`;
|
|
33
|
-
const output = forward(input);
|
|
34
|
-
expect(output).toContain('<Grid');
|
|
35
|
-
expect(output).not.toContain('"grid ');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('div without flex/grid → Stack', () => {
|
|
39
|
-
const input = `const App = () => <div className="p-4 bg-gray-800">hello</div>;`;
|
|
40
|
-
const output = forward(input);
|
|
41
|
-
expect(output).toContain('<Stack');
|
|
42
|
-
expect(output).toContain('p-4 bg-gray-800');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('span → Text', () => {
|
|
46
|
-
const input = `const App = () => <span className="text-sm text-gray-300">hello</span>;`;
|
|
47
|
-
const output = forward(input);
|
|
48
|
-
expect(output).toContain('<Text');
|
|
49
|
-
expect(output).toContain('text-sm text-gray-300');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('p → Text', () => {
|
|
53
|
-
const input = `const App = () => <p className="text-base">content</p>;`;
|
|
54
|
-
const output = forward(input);
|
|
55
|
-
expect(output).toContain('<Text');
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('h1-h6 → Text with variant', () => {
|
|
59
|
-
const input = `const App = () => <h2 className="font-bold">Title</h2>;`;
|
|
60
|
-
const output = forward(input);
|
|
61
|
-
expect(output).toContain('<Text');
|
|
62
|
-
expect(output).toContain('variant="h2"');
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('button → Button', () => {
|
|
66
|
-
const input = `const App = () => <button className="px-4 py-2" onClick={handleClick}>Go</button>;`;
|
|
67
|
-
const output = forward(input);
|
|
68
|
-
expect(output).toContain('<Button');
|
|
69
|
-
expect(output).toContain('onPress');
|
|
70
|
-
expect(output).not.toContain('onClick');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('a → Link', () => {
|
|
74
|
-
const input = `const App = () => <a href="/page" className="text-blue-400">Link</a>;`;
|
|
75
|
-
const output = forward(input);
|
|
76
|
-
expect(output).toContain('<Link');
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('input → TextInput', () => {
|
|
80
|
-
const input = `const App = () => <input type="text" className="w-full" />;`;
|
|
81
|
-
const output = forward(input);
|
|
82
|
-
expect(output).toContain('<TextInput');
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('textarea → TextInput multiline', () => {
|
|
86
|
-
const input = `const App = () => <textarea className="w-full h-20" />;`;
|
|
87
|
-
const output = forward(input);
|
|
88
|
-
expect(output).toContain('<TextInput');
|
|
89
|
-
expect(output).toContain('multiline');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('img → Image', () => {
|
|
93
|
-
const input = `const App = () => <img src="/avatar.png" className="w-9 h-9 rounded-full" />;`;
|
|
94
|
-
const output = forward(input);
|
|
95
|
-
expect(output).toContain('<Image');
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('preserves motion.div untouched', () => {
|
|
99
|
-
const input = `const App = () => <motion.div className="flex" initial={{ opacity: 0 }}>hi</motion.div>;`;
|
|
100
|
-
const output = forward(input);
|
|
101
|
-
expect(output).toContain('motion.div');
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('preserves PascalCase components', () => {
|
|
105
|
-
const input = `const App = () => <MyComponent className="flex">hi</MyComponent>;`;
|
|
106
|
-
const output = forward(input);
|
|
107
|
-
expect(output).toContain('<MyComponent');
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
describe('className cleanup', () => {
|
|
112
|
-
it('removes flex from Row className', () => {
|
|
113
|
-
const input = `const App = () => <div className="flex items-center gap-2">hi</div>;`;
|
|
114
|
-
const output = forward(input);
|
|
115
|
-
// Should have items-center gap-2 but not flex
|
|
116
|
-
expect(output).toMatch(/className="items-center gap-2"/);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('removes flex and flex-col from Stack className', () => {
|
|
120
|
-
const input = `const App = () => <div className="flex flex-col gap-4 p-2">hi</div>;`;
|
|
121
|
-
const output = forward(input);
|
|
122
|
-
expect(output).toMatch(/className="gap-4 p-2"/);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('handles cn() utility', () => {
|
|
126
|
-
const input = `const App = () => <div className={cn("flex items-center", isActive && "bg-blue-500")}>hi</div>;`;
|
|
127
|
-
const output = forward(input);
|
|
128
|
-
expect(output).toContain('<Row');
|
|
129
|
-
expect(output).toContain('"items-center"');
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('handles template literals', () => {
|
|
133
|
-
const input = 'const App = () => <div className={`flex items-center ${cls}`}>hi</div>;';
|
|
134
|
-
const output = forward(input);
|
|
135
|
-
expect(output).toContain('<Row');
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
describe('control flow', () => {
|
|
140
|
-
it('converts && conditional to <Show>', () => {
|
|
141
|
-
const input = `const App = () => <div className="flex">{visible && <span>hi</span>}</div>;`;
|
|
142
|
-
const output = forward(input);
|
|
143
|
-
expect(output).toContain('<Show');
|
|
144
|
-
expect(output).toContain('when={visible}');
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('converts .map() to <Each>', () => {
|
|
148
|
-
const input = `const App = () => <div className="flex flex-col">{items.map(item => <span key={item.id}>{item.name}</span>)}</div>;`;
|
|
149
|
-
const output = forward(input);
|
|
150
|
-
expect(output).toContain('<Each');
|
|
151
|
-
expect(output).toContain('items={items}');
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('converts ternary to dual <Show>', () => {
|
|
155
|
-
const input = `const App = () => <div className="flex">{active ? <span>on</span> : <span>off</span>}</div>;`;
|
|
156
|
-
const output = forward(input);
|
|
157
|
-
expect(output).toContain('<Show');
|
|
158
|
-
// Should have two Show elements
|
|
159
|
-
const showCount = (output.match(/<Show/g) || []).length;
|
|
160
|
-
expect(showCount).toBe(2);
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
describe('annotations', () => {
|
|
165
|
-
it('adds @mm-original annotation when enabled', () => {
|
|
166
|
-
const output = forwardAnnotated(
|
|
167
|
-
`const App = () => <div className="flex items-center">hi</div>;`,
|
|
168
|
-
);
|
|
169
|
-
expect(output).toContain('@mm-original');
|
|
170
|
-
expect(output).toContain('div');
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('omits annotation when disabled', () => {
|
|
174
|
-
const output = forward(
|
|
175
|
-
`const App = () => <div className="flex items-center">hi</div>;`,
|
|
176
|
-
);
|
|
177
|
-
expect(output).not.toContain('@mm-original');
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
describe('imports', () => {
|
|
182
|
-
it('adds atom import', () => {
|
|
183
|
-
const input = `import React from 'react';\nconst App = () => <div className="flex">hi</div>;`;
|
|
184
|
-
const output = forward(input);
|
|
185
|
-
expect(output).toContain('@mindmatrix/react/atoms');
|
|
186
|
-
expect(output).toContain('Row');
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
describe('real-world patterns', () => {
|
|
191
|
-
it('transforms a channel list item', () => {
|
|
192
|
-
const input = `
|
|
193
|
-
const ChannelItem = ({ channel }) => (
|
|
194
|
-
<div className="flex items-center gap-2 px-2 py-1.5 rounded-md hover:bg-gray-800">
|
|
195
|
-
<span className="text-sm text-gray-300 truncate flex-1">{channel.name}</span>
|
|
196
|
-
{channel.unread > 0 && (
|
|
197
|
-
<span className="bg-blue-500 text-white text-xs px-1.5 rounded-full">
|
|
198
|
-
{channel.unread}
|
|
199
|
-
</span>
|
|
200
|
-
)}
|
|
201
|
-
</div>
|
|
202
|
-
);`;
|
|
203
|
-
const output = forward(input);
|
|
204
|
-
expect(output).toContain('<Row');
|
|
205
|
-
expect(output).toContain('<Text');
|
|
206
|
-
expect(output).toContain('<Show');
|
|
207
|
-
expect(output).toContain('when={channel.unread > 0}');
|
|
208
|
-
expect(output).toContain('hover:bg-gray-800');
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it('transforms a message list', () => {
|
|
212
|
-
const input = `
|
|
213
|
-
const Messages = ({ messages }) => (
|
|
214
|
-
<div className="flex flex-col gap-1">
|
|
215
|
-
{messages.map((msg) => (
|
|
216
|
-
<div key={msg.id} className="flex items-start gap-3 px-4">
|
|
217
|
-
<img src={msg.avatar} className="w-9 h-9 rounded-full" />
|
|
218
|
-
<div className="flex flex-col flex-1 min-w-0">
|
|
219
|
-
<span className="font-semibold">{msg.sender}</span>
|
|
220
|
-
<p className="text-sm">{msg.content}</p>
|
|
221
|
-
</div>
|
|
222
|
-
</div>
|
|
223
|
-
))}
|
|
224
|
-
</div>
|
|
225
|
-
);`;
|
|
226
|
-
const output = forward(input);
|
|
227
|
-
expect(output).toContain('<Stack');
|
|
228
|
-
expect(output).toContain('<Each');
|
|
229
|
-
expect(output).toContain('<Row');
|
|
230
|
-
expect(output).toContain('<Image');
|
|
231
|
-
expect(output).toContain('<Text');
|
|
232
|
-
// Verify all Tailwind classes preserved
|
|
233
|
-
expect(output).toContain('gap-1');
|
|
234
|
-
expect(output).toContain('items-start gap-3 px-4');
|
|
235
|
-
expect(output).toContain('w-9 h-9 rounded-full');
|
|
236
|
-
expect(output).toContain('font-semibold');
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
});
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { transform } from '../index';
|
|
3
|
-
|
|
4
|
-
function reverse(source: string): string {
|
|
5
|
-
return transform(source, { direction: 'reverse' }).code;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
describe('reverse transform', () => {
|
|
9
|
-
describe('element mapping', () => {
|
|
10
|
-
it('Row → div with flex', () => {
|
|
11
|
-
const input = `const App = () => <Row className="items-center gap-2">hello</Row>;`;
|
|
12
|
-
const output = reverse(input);
|
|
13
|
-
expect(output).toContain('<div');
|
|
14
|
-
expect(output).toContain('flex items-center gap-2');
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('Stack → div with flex flex-col', () => {
|
|
18
|
-
const input = `const App = () => <Stack className="gap-4 p-2">hello</Stack>;`;
|
|
19
|
-
const output = reverse(input);
|
|
20
|
-
expect(output).toContain('<div');
|
|
21
|
-
expect(output).toContain('flex flex-col gap-4 p-2');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('Grid → div with grid', () => {
|
|
25
|
-
const input = `const App = () => <Grid className="grid-cols-3">hello</Grid>;`;
|
|
26
|
-
const output = reverse(input);
|
|
27
|
-
expect(output).toContain('<div');
|
|
28
|
-
expect(output).toContain('grid grid-cols-3');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('Text → span', () => {
|
|
32
|
-
const input = `const App = () => <Text className="text-sm">hello</Text>;`;
|
|
33
|
-
const output = reverse(input);
|
|
34
|
-
expect(output).toContain('<span');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('Text with variant="h2" → h2', () => {
|
|
38
|
-
const input = `const App = () => <Text variant="h2" className="font-bold">Title</Text>;`;
|
|
39
|
-
const output = reverse(input);
|
|
40
|
-
expect(output).toContain('<h2');
|
|
41
|
-
expect(output).not.toContain('variant=');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('Button → button with onClick', () => {
|
|
45
|
-
const input = `const App = () => <Button className="px-4" onPress={handleClick}>Go</Button>;`;
|
|
46
|
-
const output = reverse(input);
|
|
47
|
-
expect(output).toContain('<button');
|
|
48
|
-
expect(output).toContain('onClick');
|
|
49
|
-
expect(output).not.toContain('onPress');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('Link → a', () => {
|
|
53
|
-
const input = `const App = () => <Link href="/page">Go</Link>;`;
|
|
54
|
-
const output = reverse(input);
|
|
55
|
-
expect(output).toContain('<a');
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('TextInput → input', () => {
|
|
59
|
-
const input = `const App = () => <TextInput className="w-full" />;`;
|
|
60
|
-
const output = reverse(input);
|
|
61
|
-
expect(output).toContain('<input');
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('TextInput multiline → textarea', () => {
|
|
65
|
-
const input = `const App = () => <TextInput multiline className="w-full" />;`;
|
|
66
|
-
const output = reverse(input);
|
|
67
|
-
expect(output).toContain('<textarea');
|
|
68
|
-
expect(output).not.toContain('multiline');
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('Image → img', () => {
|
|
72
|
-
const input = `const App = () => <Image src="/avatar.png" className="w-9 h-9" />;`;
|
|
73
|
-
const output = reverse(input);
|
|
74
|
-
expect(output).toContain('<img');
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe('control flow', () => {
|
|
79
|
-
it('Show → conditional &&', () => {
|
|
80
|
-
const input = `const App = () => <div><Show when={visible}><span>hi</span></Show></div>;`;
|
|
81
|
-
const output = reverse(input);
|
|
82
|
-
expect(output).toContain('visible &&');
|
|
83
|
-
expect(output).not.toContain('<Show');
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('Each → .map()', () => {
|
|
87
|
-
const input = `const App = () => <div><Each items={items} as="item">{(item) => <span>{item.name}</span>}</Each></div>;`;
|
|
88
|
-
const output = reverse(input);
|
|
89
|
-
expect(output).toContain('.map(');
|
|
90
|
-
expect(output).not.toContain('<Each');
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('Each with keyField restores key prop', () => {
|
|
94
|
-
const input = `const App = () => <div><Each items={items} as="item" keyField={item.id}>{(item) => <span>{item.name}</span>}</Each></div>;`;
|
|
95
|
-
const output = reverse(input);
|
|
96
|
-
expect(output).toContain('.map(');
|
|
97
|
-
expect(output).toContain('key={');
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe('className injection', () => {
|
|
102
|
-
it('adds flex to Row without className', () => {
|
|
103
|
-
const input = `const App = () => <Row>hello</Row>;`;
|
|
104
|
-
const output = reverse(input);
|
|
105
|
-
expect(output).toContain('className="flex"');
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('adds flex flex-col to Stack without className', () => {
|
|
109
|
-
const input = `const App = () => <Stack>hello</Stack>;`;
|
|
110
|
-
const output = reverse(input);
|
|
111
|
-
expect(output).toContain('className="flex flex-col"');
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('preserves existing classes when injecting', () => {
|
|
115
|
-
const input = `const App = () => <Row className="items-center gap-2">hello</Row>;`;
|
|
116
|
-
const output = reverse(input);
|
|
117
|
-
expect(output).toContain('flex items-center gap-2');
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe('imports', () => {
|
|
122
|
-
it('removes atom imports', () => {
|
|
123
|
-
const input = `import { Row, Text } from '@mindmatrix/react/atoms';\nconst App = () => <Row><Text>hi</Text></Row>;`;
|
|
124
|
-
const output = reverse(input);
|
|
125
|
-
expect(output).not.toContain("from '@mindmatrix/react/atoms'");
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('preserves non-atom imports', () => {
|
|
129
|
-
const input = `import { Row } from '@mindmatrix/react/atoms';\nimport { cn } from './utils';\nconst App = () => <Row>hi</Row>;`;
|
|
130
|
-
const output = reverse(input);
|
|
131
|
-
expect(output).toContain("from './utils'");
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe('annotation-guided reverse', () => {
|
|
136
|
-
it('uses @mm-original to restore exact tag', () => {
|
|
137
|
-
const input = `const App = () => (
|
|
138
|
-
/* @mm-original main */
|
|
139
|
-
<Stack className="p-4">hello</Stack>
|
|
140
|
-
);`;
|
|
141
|
-
const output = reverse(input);
|
|
142
|
-
expect(output).toContain('<main');
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
});
|