Vue support: components, templates and composables #1
Loading…
Reference in a new issue
No description provided.
Delete branch "vue-support"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds Vue 3 support:
.vuefiles are checked like.tsfiles, every existing rule also runs inside templates, and 18 Vue-specific rules are added. Design and decisions:notes/vue.md.How it works
sfc.rsturns a component into one virtual TypeScript program:<script>at module level (shared by every instance),<script setup>per instance (its bindings are exempt fromno-mutable-global, but its functions stay top-level so failures are still followed across files), then the template as statements. A source map sends diagnostics, code frames and quick fixes back into the.vuefile; fixes that would touch generated code are dropped.template.rsis our own template parser (Rust, so the CLI and WASM stay Node-free). Handlers become detached callbacks, souncaught-propagation,must-use-resultandfloating-rejectionwork in templates unchanged.{{ JSON.parse(x) }}is reported asunhandled-failure.defineProps()is treated as borrowed, soprops.x.y = …/v-model="props.x"get a props-specificno-param-mutation.vue.rsholds the script-side rules; they also run in.tsfiles importing fromvue(composables).New rules
vue-sfc,vue-ref-value,vue-lost-reactivity,vue-setup-after-await,vue-async-race,vue-side-effect-in-render,vue-render-cost,vue-deep-watch,vue-prefer-shallow-ref,vue-inject-key,vue-async-component,vue-v-for-key,vue-v-if-with-v-for,vue-exhaustive-v-if,vue-v-html,vue-unsafe-url,vue-ssr-browser-global,vue-hydration-mismatch.listener-cleanupnow covers component setup. SSR rules apply only with"safe-ts": { "vue": { "ssr": true } }inpackage.jsonor a Nuxt dependency.Tooling and packages
safeTs()beforevue()checks components and rewrites their script blocks in place.examples/vue/is a small working app, covered byscripts/vite-check.mjs.@evobug/safe-ts-vue:useTask,AsyncState,useListener/useInterval,injectRequired,safeUrl/safeHref.@evobug/safe-ts-feature-vue-router:push/replace/isReadyreject,resolvethrows (written from vue-router 4, not verified against an installed copy).docs/guide/vue.md, one page per rule, README sections.Enums in templates, and values that may be missing (second commit)
<Match :on="value">from@evobug/safe-ts-vue/match: one slot per variant (#Ready="{ value }"),#_for the rest.vue-matchchecks every variant has a slot and every slot is a variant. Variants come from the value's declaration (ref<T>(),defineProps<...>(),useTask, return types,v-forover a typed list) and theEnum<...>it names, here or in the file it is imported from.<Match>into av-ifchain and rewrites slot props into reads of the value, so nothing of it is left at runtime. TheMatchcomponent renders whatever the transform can't rewrite (e.g.:on="find(id)").vue-exhaustive-v-ifnow knows the variants: a chain covering all of them passes, a chain missing one names it.vue-maybe-undefined: the template reads into aref()without a value, an optional prop,defineModel()orinject()without a default, and nov-if/&&/?:/?.checks it first.vue-template-ref:useElement(typed withoutnull) for elements the template always renders, read after mount. UseuseOptionalElementfor elements underv-if,useElementsinsidev-for.vue-split-state/vue-ref-without-value:loading/error/datarefs, or a rendered ref that stays undefined until loaded. Both point touseTask+AsyncState.examples/vueuses<Match>;scripts/vite-check.mjschecks that it is compiled into av-ifchain.Decisions (defaults, easy to change in
notes/vue.md)vue-sfc), not checked further.app.config.errorHandler/onErrorCaptureddon't count as handling.createRouter()+router.push()staysno-mutable-global; useuseRouter().Known gaps
.vuefiles to JS plugins, so no safe-ts diagnostics in.vuein the editor (CLI and Vite work).vue-tscfor type-checking emitted components; Nuxt auto-imports aren't followed;emitisn't linked to the parent's handler; no Vue playground preset.Testing
cargo test --no-fail-fast: all pass except thefeaturesfixture (createDecipherivexpectation), which already fails onmain.npm run test:std: 115/116; thefeature-nodeinventory failure (Node 26.13 API drift) already fails onmain.tests/docs.rs,scripts/docs-typecheck.mjs),npm run test:vite,npm run typecheck,tsc -p packages/safe-ts-vue, and@evobug/safe-ts-vue's 41 tests pass.package-lock.jsonchanged vianpm install --offline(new workspaces).A Vue demo in the docs (third commit)
docs/guide/vue-demo.mdruns one component written two ways, side by side in the browser, against a fake server (slow, fast, failing). Without safe-ts it crashes on a failed first load, shows an older response over a newer one, and keeps an error that never clears. WithuseTaskand<Match>it does none of that.```demoblock in the VitePress config). The demo's components go through the safe-ts transform, so the browser runs the compiledv-ifchain.vue_demo_shows_its_problems(tests/docs.rs) keeps the plain version reportingvue-async-race,vue-maybe-undefinedandvue-split-state, and the safe-ts version clean.{{ user.name }}in inline code is rendered by VitePress.npm run build -w docspasses.🤖 Generated with Claude Code
A new guide page runs the same profile panel twice, side by side in the browser, against a fake server: written the usual way (loading/error/data refs and an async watcher) and with useTask and <Match>. Three tries show the crash, the async race and the error that never clears, each next to the rule that reports it. The code and the reports on the page are generated at build time from the files that run (a ```demo block in the VitePress config), and the demo's components go through the safe-ts transform, so the browser runs the compiled v-if chain. A test keeps the plain version producing its rules and the safe-ts version clean. Also fixes the docs build: two sentences had {{ }} in inline code, which VitePress renders. Co-Authored-By: Claude Opus 5.5 <[email protected]>