Migrating from React: qatjs migrate
qatjs migrate react-checkout --audit
qatjs migrate react-checkout --dry
qatjs migrate react-checkout
qatjs migrate react-checkout --to qxqatjs migrate <dir> rewrites a React app in place, with the React → Qat dictionary.
The default target is standard .tsx — the smaller diff, and your tsc, Prettier and ESLint keep
working (tsx.md); --to qx goes all the way. --dry reports without writing; --json
prints the report as data.
What it cannot convert stays visible: a // TODO:qat line saying what to do, with the original
code in the comment. Every React construct it meets is counted, so you know how much was automatic.
React → Qat
What each React construct becomes — the table qatjs migrate works from, and the one
qatjs init gives coding agents (AGENTS.md):
| React | Qat |
|---|---|
useState |
state (setX(v) → x = v) |
useMemo |
derived |
useCallback, memo, forwardRef |
removed |
useEffect(fn, []) / useLayoutEffect |
mount |
useEffect(fn, [a]) |
effect or watch(a, ...) |
useRef |
let x + ref={x} |
useContext / Provider |
inject / provide |
useReducer |
store() or plain function + state |
| ErrorBoundary | {try}{catch}{/try} |
Suspense + use() |
load + {if (x.loading)} |
useTransition |
transition() / defer() |
{a && <B/>}, ? : |
{if}{else}{/if} |
.map(... key) |
{for}{/for} + key |
className, htmlFor, onClick |
class, for, on:click (onClick is accepted on elements too) |
value + onChange |
bind:value |
On an app we did not write
qatjs migrate was run on ts-redux-react-realworld-example-app
(the RealWorld "Conduit" app in React 17 + Redux Toolkit + react-router 5; MIT; commit cb39756):
44 source files, 2,423 lines, plus 18 test files (2,352 lines) that migrate leaves as they are.
Coverage counts every React construct, including what migrate does not know: a scan of its output
counts any React left (imports, React.* types, unconverted hooks, className/onX on elements,
undefined React components) and every compile error as left by hand.
to .tsx |
to .qx |
|
|---|---|---|
| first run | 245 of 281 converted (87%), 36 left | — |
| after the fixes below | 291 of 303 (96%), 12 left | 291 of 304 (96%), 13 left |
with guard wrappers and HashRouter |
293 of 299 (98%), 6 left | 293 of 300 (97.7%), 7 left |
(The totals grew because the fixed version recognizes constructs the first one did not count; the
number left by hand is the comparable figure. Each row is a file of benchmarks/migrate/:
realworld-before.json, realworld-after-tsx.json and -qx.json, realworld-phase6-tsx.json and
-qx.json.)
The ten construct types left after the first run, and what changed:
| Left after the first run | Count | Now |
|---|---|---|
React.FormEvent type |
7 | DOM Event |
<Route> (react-router 5) |
6 | routes.js, pages by their named exports; exact-less paths get /** |
React.ChangeEvent type |
5 | InputEvent & { target: T; currentTarget: T } (accepted by on:input and on:change) |
<Redirect> |
3 | a redirect() route |
compile error: <If> as a component's result |
3 | allowed — a block can be a component's result (the compiler accepts it) |
.map(…) that is not one element |
3 | statements before the return, conditional rows, nested maps, destructured items |
compile error: {...{ a, b }} on an element |
3 | expanded into attributes |
.map() inside && |
2 | <If> around <For> |
React.KeyboardEvent type |
1 | DOM KeyboardEvent |
NavLink |
1 | still by hand (the active class) |
Also fixed on the way: a custom hook's parameters are accessors only where they are values (one
typed or called as a function is passed as is); destructuring a hook's result reads its signal
(const { user } = useStore(…) → storeState().user); a render that returns a computed
expression (return article.match({ some: (a) => <X /> })) or returns early becomes a function
result that re-runs with what it reads; useLocation(); names that collide with Qat's (load).
Three more: render props and children as a function are recognized
and counted, and a component that returns children(value) re-renders when the value changes
(tested in examples/migrate/react-checkout, Orders.jsx); --write-package rewrites
package.json from the audit.
Two more dictionary entries are mechanical:
- Route guard wrappers (react-router 5): a component that renders
<Route {...rest}>{children}</Route>with{cond && <Redirect to="/x" />}becomes, at each use inside<Switch>,guard(() => !cond, page(…), { redirect: '/x' })in routes.js, the use's props substituted (<UserOnly logged={isLoggedIn()}>→guard(() => isLoggedIn(), …), with the import); the wrapper's definition goes. When the condition is the layout's own value (Conduit:userIsLogged, computed inApp), the guard is written with it and a// TODO:qatsays to read the same value there — a guard runs before any component. HashRouter: the wrapper goes,/#/xlinks become/x, and the entry sends old/#/…URLs and bookmarks to their path (history.replaceState) before the first render.
All the way, on the same app (one run, not repeated since; unlike the table above, its numbers have
no file in benchmarks/migrate/):
| Step | Result |
|---|---|
qatjs migrate --keep-unconverted |
296 of 302 constructs converted (98%), 1 file bridged (the header, a React 17 island), tsconfig.json set for Qat: the app runs at once (checked in Chrome with its API stubbed) |
qatjs migrate --ai, through qatjs mcp |
the 6 TODOs left (5 guard values, 1 NavLink) put to the agent: 2 proposals (one answer wrote all five guards from the Redux store), both applied; no TODO and no island left; the guards redirect as before |
qatjs check afterwards |
0 type errors in the migrated source (with useUnknownInCatchVariables: false, which migrate sets for a project written for TypeScript 4.3); the 18 test files are still React's and report theirs |
Left on this app after the first step: those five guards' value (one TODO each) and one NavLink; in .qx also one
component whose several roots have text between them (.qx roots are elements; .tsx handles it).
A 32k-line app builds: HospitalRun's frontend at c45aa100 (CRA 3, Redux,
react-query 2, @hospitalrun/components).
qatjs migrate --write-packageconverts 1,531 of 1,709 constructs (90%) in 0.8 s.qatjs compressbuilds it in 1.9 s: 137 chunks, 8.1 kB of initial JS.
What it needed, done by migrate now:
react/react-domstay while a React library is kept (its components run in islands, on React 17'srender);react-reduxstays while the hand-leftuseSelectors import it;process.env.REACT_APP_*isimport.meta.env.PUBLIC_*, and the one no.envdefines is written asruntime;import * as xandimport './x.css'survive;- a context provider that returns its children is a component.
What it needed by hand: the browser packages of the Node built-ins PouchDB imports (events,
util, assert, stream-browserify, crypto-browserify, process). CRA's webpack 4 put them
in; qatjs compress names each one (QX-COMPRESS-UNRESOLVED) and uses it once it is installed.
It does not start in the browser before its TODOs are done (184 constructs: useHistory,
useSelector, react-query 2's hooks): the root layout's useSelector stops it.
qatjs migrate react-checkout --write-package --dryOn the RealWorld app, --write-package removes react, react-dom, react-redux,
react-router-dom, react-scripts, @types/react* and @testing-library/react, adds qat,
@qatjs/router, @qatjs/store, @qatjs/toolchain and @testing-library/dom, keeps Redux Toolkit,
axios, ramda, date-fns and the rest, and moves start/build to qatjs dev/qatjs compress
(react-scripts test has no qat equivalent: it says so).
What is left
qatjs migrate react-checkout --keep-unconverted--keep-unconvertedmakes the app run on day one.- A component file that still holds React, or a
// TODO:qat, stays React. Its original is kept as<name>.react.tsxand its migrated name mounts it as an island:island()from@qatjs/bridge-react/island, with the app's own React (18+ withcreateRoot, 17 withrender). - What the island imports that migrate changed (a hook, a component) comes along as React too,
as
.reactcopies of the originals. What migrate left alone (a store, types, services) is shared, so an island and the Qat pages read the same store. - Props and callbacks pass as they are; Qat children are not passed.
- A guard whose value is still to write lets everyone in, with one console warning, instead of failing.
--write-packagekeeps React and the packages the islands import.- On the RealWorld app, the header (one
NavLink) runs as React and everything else is Qat.
- A component file that still holds React, or a
--aiputs each remaining// TODO:qatto the agent connected toqatjs mcp, through MCP sampling.- What goes with it: the file, the React original, the React → Qat dictionary and the project's
AGENTS.md. - The proposal is shown as a diff and applied only when you answer yes (
--yesapplies without asking);qatjs checkruns at the end. qatjs mcpmust be running for the project: open your agent there, connected as in dev.md.
- What goes with it: the file, the React original, the React → Qat dictionary and the project's
The state flow first: --map
qatjs migrate react-checkout --map
qatjs migrate react-checkout --map --json
qatjs migrate react-checkout --apply-mapThe first prints Markdown with a Mermaid graph. --json prints { schema: 1, components, contexts, slices, proposals }. --apply-map performs the safe proposals, then the conversion.
A React app's state is spread over Contexts, hook state, store slices and props passed down.
Converted one file at a time, it keeps that shape. --map reads the app first, without running
it. It draws the flow as a graph: each Context with its providers and its consumers (a consumer
through a custom hook counts), each Redux slice with the components that select from it, each
useReducer, and each prop as it is passed from component to component. Then it proposes the Qat
shape:
| it finds | it proposes | safe |
|---|---|---|
| Contexts provided by one component, or sharing most of their consumers | one store() |
no: review how they are written |
| a prop passed down 3 or more levels by components that only pass it on | provide at the origin, inject where it is read |
when the name is the same all the way, each component passes it on as x={x} with destructured props, and each one in between has a single parent |
a useReducer whose state and dispatch stay in its component |
component state; the reducer stays a plain function |
yes |
| a slice read by one component | component state |
no: its actions may be dispatched elsewhere |
Each proposal links its files. --apply-map performs only the safe ones, on the React source, so
that the conversion that follows sees them. A prop passed down becomes a Context in
src/qat-map/, provided where the prop starts and read where it is used. The components in
between stop receiving it. migrate then turns the Context into provide/inject. Run --map
again: an applied proposal is no longer listed.
On three apps we did not write (pinned commits; read, never installed or run):
| app | components | Contexts | slices | proposals | safe | time |
|---|---|---|---|---|---|---|
| Conduit (Redux Toolkit) | 42 | 0 | 8 | 3 slices read by one page | 0 | 25 ms |
| HospitalRun frontend (Redux + Contexts) | 99 | 4 | 6 | 2 Context pairs provided together, 2 slices | 0 | 104 ms |
| Taskcafe frontend (Apollo + Contexts) | 187 | 2 | 0 | 5 props passed 3–4 levels | 2 | 120 ms |
The build config: --config
qatjs migrate webpack-dashboard --config webpack.config.js --dry
qatjs migrate webpack-dashboard --config webpack.config.jsQat has no config file, so a webpack or Vite config (--config vite.config.ts) becomes the
conventions that replace it. Create React App keeps its config inside react-scripts: --config react-scripts reads its conventions instead (public/index.html, REACT_APP_*, proxy and
homepage in package.json, a baseUrl). The config is read, never run: its syntax is evaluated
as far as it is literal (strings, objects, path.resolve(__dirname, …), JSON.stringify(…),
plugin constructors and their options).
| section | becomes |
|---|---|
| entry (and HtmlWebpackPlugin's template and title) | index.html with the entry's module script |
| alias | package.json#imports (@ → #src/*), and the imports in src/ rewritten, with their files' extensions |
define, EnvironmentPlugin, REACT_APP_* |
.env (PUBLIC_ names), and the reads rewritten to import.meta.env.PUBLIC_… |
| devServer / server: proxy, port, https | --proxy /api=…, --port, --https in the package's dev script |
| devtool, output.path, build.outDir, build.sourcemap | --sourcemap, --out in the compress script |
| Module Federation (webpack's plugin, Vite's) | qat.federate.js |
| splitChunks, optimization, manualChunks | convention, delete: page() boundaries are the chunks |
| loaders: babel/ts/swc, css/style, postcss, sass, assets | nothing (Qat does it), postcss.config.*, .scss with sass-embedded |
| plugins: MiniCssExtract, Copy (public/), ForkTsChecker, BundleAnalyzer, Workbox | nothing, public/, qatjs check, --analyze, --pwa |
| other Vite plugins | package.json#qat.plugins (qat runs Vite plugins) |
anything else (svgr, CSS Modules, a rewrite in a proxy, performance, unknown plugins) |
manual, with what to do |
Each section is reported as mapped, convention (nothing to write: delete it) or MANUAL. The
old config is removed only when nothing is manual; otherwise it stays, for the rows you finish by
hand. Run it after the code step (qatjs migrate <dir>): the alias rewrites name the files as they
are then. --json prints the report (schema migrate-config).
| config | sections mapped | manual | the file |
|---|---|---|---|
Conduit (CRA, --config react-scripts) |
14 of 14 (100%) | — | inside react-scripts (--write-package removes the package) |
| examples/migrate/webpack-dashboard (webpack 5, written for this test) | 26 of 29 (90%) | the SVG rule (@svgr/webpack), SentryWebpackPlugin, performance |
kept |
The audit
--audit classifies every dependency before you start. On examples/migrate/react-checkout:
react replaced by qat
react-dom replaced by qat (render)
react-router-dom replaced by @qatjs/router
@tanstack/react-query replaced by @qatjs/load
zustand replaced by @qatjs/store
styled-components replaced by <style> in .qx (class and style:--var bindings)
react-hook-form replaced by @qatjs/form
react-helmet-async replaced by @qatjs/head
@mui/material keep via bridge-react React components: mount them in a bridge-react island (its own React copy)
recharts keep via bridge-react React components: mount them in a bridge-react island (its own React copy)
clsx replaced by class:name={…} bindings (or keep: it works as is)
date-fns works as is framework-independent
zod works as is framework-independent
next no equivalent a React framework (routing, SSR, server components): the app moves, not the package
@vitejs/plugin-react replaced by nothing (qat compiles JSX)
vite replaced by qatjs dev / qatjs compress
typescript works as is framework-independent(@reduxjs/toolkit and redux are framework-independent: works as is, with @qatjs/store as the
Qat-native alternative; @testing-library/react is replaced by @testing-library/dom; @types/x
follows x.)
Works as is: no React in it. Replaced by: the dictionary's answer. Keep via bridge-react: React components you keep for now, each in an island with its own React (federation). No equivalent: the app moves off it.
The same tables classify import specifiers: auditImports(['react-dom/client', '@mui/material/Button'])
from @qatjs/toolchain/src/migrate.js is a pure function (no node_modules lookup unless you pass
metadata). The migrate playground on the docs site runs it, with convert(), in the browser
(packages/toolchain/dist/browser/qat-migrate.js, built by build-browser.mjs).
The migration
src/App.jsx → src/App.tsx: 13/15 automatic, 2 TODO:qat
src/components/Countdown.jsx → src/components/Countdown.tsx: 5/5 automatic
src/components/Input.jsx → src/components/Input.tsx: 3/4 automatic, 1 TODO:qat
src/components/OrderList.jsx → src/components/OrderList.tsx: 5/5 automatic
src/components/Summary.jsx → src/components/Summary.tsx: 10/10 automatic
src/hooks/useDebounce.js → src/hooks/useDebounce.js: 5/5 automatic
src/main.jsx → src/main.js: 3/3 automatic
src/pages/Cart.jsx → src/pages/Cart.tsx: 10/10 automatic
src/pages/Checkout.jsx → src/pages/Checkout.tsx: 47/48 automatic, 1 TODO:qat
src/pages/Orders.jsx → src/pages/Orders.tsx: 8/8 automatic
src/store/cart.js → src/store/cart.js: 7/7 automatic
src/theme.js → src/theme.js: 2/2 automatic
118 of 122 React constructs converted automatically (97%), target tsx(--to qx: 118 of 122, 97%.) Every converted file compiles with no diagnostics, and after
--write-package, qatjs check on the sample gives 0 errors (17 warnings). What else to know:
- Run it with
--write-packageto run the result: without it, package.json still lists React and noqat, andqatjs devhas nothing to serve (migrate says so).--write-packagetakes React and its libraries out, puts inqatand the@qatjs/*packages the code imports, and setsqat.lintclass-unknowntowarn: the classes the React app used with no CSS rule, which React never checked, are warnings until you define them. Two things stay, and it says which: a package the migrated code still imports (a hand-leftuseSelectorkeepsreact-reduxuntil its// TODO:qatis done), andreact/react-domwhile a React component library is kept (@mui/material,@hospitalrun/components: its components run in bridge-react islands, on the app's React). - What is left is marked in the file. Each construct migrate could not convert gets a
// TODO:qatline under the file's imports (hook useHistory (5×): not converted, still React), as well as a line in the report. - Run it once. On a project whose sources already import
@qatjs/core, it converts nothing and says so;--write-packagethen writes package.json alone. - A
.tsxmade from a.jsxstarts with// @ts-nocheckand a note: its code never had types, so TypeScript's strict checks would fail on it first. Add the types, then remove the line. - A layout's other URLs: where React's
<Routes>matched nothing, React still showed the layout (the nav). The route table gets'/'and'*'pages that render nothing inside the layout, so it does the same.
What it does:
| React | becomes |
|---|---|
useState, setX(v), setX(n => n + 1) |
state; x.set(v) (.tsx) or x = v (.qx) |
useMemo, useCallback, memo |
derived; the plain function; the component |
useEffect(fn, []) / useEffect(fn, [a]) |
mount(fn) / effect(fn) (dependencies are tracked) |
useRef |
let x + ref={x}; x.current → x |
useContext, createContext(d), <Ctx.Provider value> |
inject(Ctx) ?? Ctx.default; { default: d }; provide(Ctx, …) with live getters |
useReducer(r, init) |
state(init) and dispatch = (a) => s.set(r(s(), a)) |
a custom hook useX(a) |
plain reactive JS (signal, effect); its arguments become accessors, called as useX(() => a) (a default too: initial = () => false); what it returns is its signals — alone, or in the tuple or object it returns (return [on, toggle], read on() by the caller) |
const left = todos.filter(…).length in a component's body |
derived: React computes it at every render; a body that runs once would keep the first value |
lazy(() => import('./Chart')), <Suspense fallback> |
import Chart from './Chart'; the children (qatjs compress finds what to load late) |
<button {...rest}> |
as written (@qatjs/core/spread) |
strokeWidth, ariaLabel, xlinkHref, defaultValue on an element |
stroke-width, aria-label, xlink:href, value |
useContext(Ctx) anywhere, const useAuth = () => useContext(Auth) |
inject(Ctx) ?? Ctx.default; the hook's callers read what was provided as it is (auth.user) |
usePrevious (a ref written in an effect, read in the render) |
a signal a watch writes: the value before the last change |
useId(), useImperativeHandle(ref, () => h) (+ its forwardRef), X.propTypes, prop-types |
an id; expose(h); removed |
forwardRef((props, ref) => <input ref={ref} />) — the ref only handed on, to an element or a component |
let forwardedRef given to that ref, and mount(() => expose(forwardedRef)): the parent's ref holds what stood there, once it is there |
const propTypes = {…}; X.propTypes = propTypes, const defaultProps = {…}; X.defaultProps = defaultProps |
the types and their const go; each default into the props pattern ({ size = 18 }) — all of them, or none and a note |
<>{ok ? children : fallback}</>, <Fragment> |
the expression; <> |
.map((x, i) => <li key={i}>) |
{for} / <For> without a key (rows by position) |
| hooks written in a component's file | stay there (effect/watch in a function named use… are the component's) |
<Routes><Route path element> |
a generated routes.js (that component is the layout, with <qat-outlet />) |
useParams, useSearchParams().get, useNavigate, <Link to> |
params(), query(name, ''), navigate(), <a href> |
useQuery({ queryKey, queryFn }), useMutation |
load(queryFn, { key: () => queryKey }); an object with mutate() and a pending state |
zustand create((set, get) => …), useStore(s => s.x) |
store({ state, derived, actions }); the store's signal |
| styled-components / emotion | a class rule (<style>, or a .css imported with { scope: 'component' }) and a CSS custom property per interpolation |
className, htmlFor, onClick, value + onChange |
class, for, onClick (kept: Qat accepts it on elements; onChange on a text field becomes on:input), bind:value |
{a && <B/>}, ? :, .map(x => <li key>), <>…</> |
{if} / <If>, {for} / <For key>, several roots |
ReactDOM.createRoot(el).render(<App />) |
render(routes, el) |
A class component is first written as the function component it stands for — its state as
states, componentDidMount/componentWillUnmount as one mount, its methods as functions,
this.props.x as a prop — and X.defaultProps (or static defaultProps) as the defaults of the
props pattern. A class that cannot be said exactly stays a class and is said:
componentDidUpdate, a contextType, setState with a callback, this passed on.
Said, not converted: React's Children/cloneElement/createPortal, such a class, a
defaultProps whose prop a ...rest hides, a hook that returns a ref's value.
Left for you on the sample: a forwardRef whose ref is used
for more than handing it on (a Qat parent's ref gets what the child expose()s), and a styled
interpolation that reads the theme. The custom-hook rule is the important one: in Qat a component runs once, so a hook that
received query would see its first value forever; migrate passes () => query instead.
Three more apps, whole (D350)
Three public React apps were migrated to .qx and every output file compiled — the count
migrate prints is of constructs; whether the result is a program is another question, and the one
that found the most. Sources only, never run:
bulletproof-react (apps/react-vite, TypeScript,
react-query, zustand, shadcn-style components; commit 9506629),
jira_clone (client, JavaScript, styled-components,
prop-types; 26a9e77), and
tailwind-dashboard-template (173f641).
| App | files, lines | converted, before → after | compile errors in the output, before → after |
|---|---|---|---|
| bulletproof-react | 116, 6,108 | 85 % → 92 % | 13 and 3 files the compiler could not finish → 1 (enum, which .qx does not read) |
| jira_clone | 134, 6,977 | 65 % → 77 % | 2 → 2 |
| dashboard template | 45, 5,742 | 94 % → 94 % | 4 → 1 |
What is left, and why: jira's 198 styled interpolations that are not functions of props
(${color.primary}, ${font.size(15)}, ${mixin.clickable} — values and whole declarations from
the app's own style helpers); a NavLink that names a class or a style for the active link (65
in the dashboard: the link is an <a>, which the router marks aria-current="page" — the rule
for a[aria-current="page"] is yours to write; a NavLink that only links is converted);
react-query's and zustand's hooks used through
the app's own wrappers; and the files whose fragment holds bare text among its roots. (A
fragment that begins with an expression — a layout's <>{children}<Footer /></> — is its roots
now: .qx takes an expression as the first of them in the result's parentheses.)
From Angular
qatjs migrate my-angular-app --audit
qatjs migrate my-angular-app --map
qatjs migrate my-angular-app --dry
qatjs migrate my-angular-app --write-package
qatjs migrate my-angular-app --keep-unconvertedThe same command, on an Angular 17+ standalone app: @angular/core in its dependencies, or an
angular.json. It is detected by those, so there is nothing to choose. The target is .qx. The
flags are the React ones:
--dryreports without writing,--jsongives the report as data;--auditsays what each dependency becomes;--write-packageswaps Angular's packages for Qat's andng serve/ng buildforqatjs dev/qatjs compress;--aihands each// TODO:qatleft to the agent connected toqatjs mcp.
Each converted file replaces the Angular one: a component's .ts, its template and its stylesheet
become one .qx. index.html moves to the app's root with Qat's entry. The helpers the
converted code uses are written to src/qat-migrate/:
http.js: HttpClient's calls as promises, the interceptors ashttp.use,HttpParams;pipes.js: Angular's pipes on Intl;router.js: guards, resolvers, the route streams;forms.js,lifecycle.js,outlet.qx, andsnack-bar.jsfor MatSnackBar.
What it does
| Angular | becomes |
|---|---|
a standalone @Component (class, template, styles) |
one .qx component: the class's members in its body, the template its JSX, the styles its scoped <style> (:host → :scope, ::ng-deep x → :global(x)) |
signal, computed, effect |
state, derived, effect |
input(), @Input, input.required, model(), an @Input setter |
props (a setter runs with the prop at setup and on each change: onInput) |
output(), @Output + EventEmitter, x.emit(v) |
emits<…>(), emit('x', v) |
| a field written later / read only | state / const |
| a getter | derived |
ngOnInit |
its statements in setup, in a block (setup runs once with the props set: ngOnInit's moment) |
ngOnChanges(changes) |
the same function: once at setup, then on each change of a prop, with Angular's SimpleChanges (onChanges) |
ngAfterViewInit, ngOnDestroy, DestroyRef.onDestroy |
mount, unmount |
@ViewChild/viewChild, #ref |
let x + ref={x} |
@if/*ngIf (; else, as), @for/*ngFor (track, $index, $first…, @empty), @switch, @let, @defer, <ng-container>, <ng-content> |
{if}, {for} + key, {switch}, the expression where the name is read, the content at once, its children, {children} |
[prop], [class.x], [style.x.px], [attr.x], [ngClass], [ngStyle], (event), (keyup.enter), [(ngModel)], [(x)] |
the attribute, class:x, style:x, the attribute, class: per key, style, on:event, a key check, bind:value/bind:checked, bind:x |
pipes: date, currency, number, percent, json, uppercase, slice, keyvalue, async, the app's own, translate |
Intl helpers, JavaScript, the converted pipe's function, t() from @qatjs/core/i18n |
jhiTranslate / translate attributes (+ translateValues) |
{t(key, values)} |
a root service (providedIn: 'root', @Service()) |
its class, and its one instance exported (export const orders = new OrdersService()) |
a service a component provides; an InjectionToken |
provide(X, new X()) there and inject(X) below; a root factory's value, or a provide key |
inject(X), constructor injection |
the service's instance |
HttpClient, an interceptor (req.clone({ url, setHeaders }), next(req)) |
http.get/post/…, promises; http.use(fn) with the same function |
the routes: component, loadComponent, children, loadChildren, redirectTo, **, canActivate/canMatch, resolve, the bootstrapped component |
@qatjs/router's table: page, layout, a redirect, *, guard(ngGuard([...])), the page's load (the page gets the values as data), the root layout |
router.navigate([...]), routerLink, snapshot.params/queryParams, route.params/data streams, NavigationEnd |
navigate(path), href, params() / the URL's, an effect re-run on each navigation (routeChanged()) |
FormGroup, FormBuilder.group, Validators.*, formControlName, [formGroup], .value, .valid, .patchValue, .reset, get('x')?.errors?.required |
form({ … }) with the rules as the schema, ref={f.field('x')}, f.values, f.valid, Object.assign(f.values, …), f.reset(), invalidBy(f, 'x', 'required') (the field's ValidityState) |
a lone FormControl, [formControl] |
a state, bind:value |
app.config.ts: withInterceptors([...]), provideAppInitializer(fn) |
http.use in order; initializers, run by main.js before it renders |
Angular Material: card, form field, label, error, hint, icon, divider, toolbar, list, grid, select/option, progress, sidenav, expansion panel, chips (display), button and input looks, matTooltip |
HTML elements with the Material class kept (<article class="mat-card">), title |
mat-checkbox, mat-slide-toggle, mat-radio-group, mat-button-toggle-group, mat-menu + trigger, mat-tab-group, mat-table, the date picker, mat-slider, MatSnackBar |
qat/ui's Checkbox, Toggle, RadioGroup, Segmented, Menu, Tabs (qatjs add them); a <table> with {for} and {switch}; type="date"; type="range"; toast() |
<fa-icon> (angular-fontawesome), FaIconLibrary.addIcons |
<FaIcon> on FontAwesome's own svg-core, library.add |
*rxLet / *ngrxLet |
{if} with its value named |
RxJS converts by what the stream is. The converter reads the services first: which fields
hold state (a BehaviorSubject, or what derives from one), and which methods return a request.
- A request (HttpClient, a service method returning one,
of,forkJoin/combineLatestof requests) becomes a promise.pipe(map, tap, catchError, switchMap, finalize)become its steps, andsubscribe(next, error)itsthen. - State becomes a signal or a
computed. Itssubscribebecomes aneffectin setup, which runs again on each change, as the subscription did. In an event handler, or withtake(1), it reads the current value once. - A stream over time stays as it was, with a
// TODO:qatnaming the operator:timer,interval,debounceTime,filter, aSubjectof events,valueChanges,merge,router.eventsother than NavigationEnd. - Requests mixed with state in one
combineLatestread the state once, and are named.
On three apps we did not write
Each was cloned at a pinned commit as data: nothing was installed, nothing of it ran during the
conversion. Run node benchmarks/migrate/angular.mjs to repeat it. The per-category numbers and
every unconverted kind are in benchmarks/migrate/angular-<app>.json. Coverage counts every
construct met, converted or not, plus each output's compile errors (a module that does not parse
counts too).
| app | lines | converted | lowest categories |
|---|---|---|---|
angular-realworld-example-app dd99ed2 (MIT; Angular 21) |
2.5k | 620 of 634, 97.8% | 5 accessibility errors of the source (below); forms 97% |
ng-matero d351bf5 (MIT; Angular 22, Material) |
16.4k | 2,829 of 3,179, 89.0% | third-party components 0 of 60 (@ng-matero/extensions, ngx-permissions, formly); RxJS 57%; services 79%; Material 87% |
jhipster-sample-app 6b000b5 (Apache-2.0; Angular 22) |
13.1k | 2,482 of 2,585, 96.0% | third-party components 106 of 119 (the 13 left are ng-bootstrap's); RxJS 85% |
With --keep-unconverted, a component not converted in full stays Angular, mounted through
@qatjs/bridge-angular. The app's components its template uses stay with it, because an Angular
template renders Angular components only. The rest converts at 98.6%, 95.7% and 96.1%, while
339, 2,453 and 1,977 constructs keep running as Angular.
The two large apps build. ng-matero and jhipster-sample-app, converted with
--write-package and installed as it wrote package.json, pass qatjs compress:
- ng-matero: 3.9 s, 112 chunks, 7.9 kB of initial JS;
- jhipster: 1.5 s, 65 chunks, 8.2 kB, after one step by hand.
What it took, done by migrate now:
- the files of several components keep all of them;
- tsconfig
paths(@shared, jhipster's catch-all*) become the relative imports they name; - the qat/ui components the templates use are copied in;
sass-embeddedis added for the components' SCSS;- what the converted code still imports stays in package.json: Angular Material for its SCSS mixins, Angular for a bridged library, rxjs for a stream left to a person.
jhipster's step by hand: angular.json runs two esbuild plugins of its own, an i18n merge and
some defines. migrate names them as TODOs. Ported as one Rollup plugin in
package.json#qat.plugins (30 lines), they are what qatjs compress needed.
Neither app starts in the browser before its TODOs are done, and the first one stops it. For
ng-matero that is the inject() of a library service (ngx-permissions, MatDialog); for
jhipster, NgbModal. That is 252 and 113 // TODO:qat lines, listed by kind in the JSON.
It runs. RealWorld, converted, was built and opened in Chromium against the live RealWorld API.
The person's part was five alt texts: the source's <img>s have none, and Qat refuses an image
without one. Its qatjs compress takes 0.26 s, with 22 chunks and 7.8 kB of initial JS. In dev and
in the build, these flows work:
- the feed loads, through the converted interceptors and the initializer;
- an article opens;
- a wrong sign-in shows the API's error;
- a tag filters the feed. Running it found what compiling each file could not: a resolver left unattached, a type imported as a value, a component's named export as a route, a local shadowing a member. Each was fixed in the converter, with a fixture case.
What the map changes: nothing in the numbers. Its safe proposals are what the conversion
already does: a store module per stateful root service, an API module per request-only service,
provide/inject for a component's provider, a token's factory as its value. --apply-map
lists them. The unsafe ones need a person:
qatjs apiwhen the repository has an OpenAPI spec;- a stateless service read by one class, folded into it;
- the interceptors.
The DI graph first: --map
qatjs migrate <dir> --map prints the services (root or provided, and what each holds: state,
requests), who injects them, the tokens and the interceptors, as Markdown with a Mermaid graph or
as --json. It took 20–51 ms on the apps above (ms.map in benchmarks/migrate/angular-*.json).
Limits
- Third-party Angular components (ng-bootstrap, @ng-matero/extensions, ngx-permissions, formly…)
are named, not converted. Keep them with
--keep-unconverted, or replace them with qat/ui. - Material beyond the table above (autocomplete, stepper, paginator, sort headers, dialogs, bottom sheets, tree, chip listbox) is named. Material's look is not carried: the elements keep Material's classes, for the app's CSS or the qat theme.
- Streams over time, as listed above, and class-based interceptors and guards.
ngDoCheck,@HostBinding/@HostListener,host: {}, structural directives of the app's own,[innerHTML]are named. So are attribute directives: an action (ref) or a component does what they did.- Guards run before the URL changes: a guard's
state.urlis the current URL, not the target (named where read).falsesends to the guard's redirect (/), where Angular stayed put. - App initializers are not awaited. An
EMPTYin a converted chain is a promise that never settles (so the steps after it do not run), and awaiting one would block the app. - An error by validator reads the field's
ValidityState, so a custom validator's key is true whenever the field has an error.