diff --git a/CHANGELOG.md b/CHANGELOG.md index 9605a2a..5c1d2d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.1.1] - 2025-11-15 +### Changed +- Evaluate `__can__` guards before business expressions when merging into `v-if` / `v-else-if` branches to keep short-circuit order predictable. + ## [1.1.0] - 2025-11-15 ### Added - Automatically mirror `v-can` guards across `v-else-if` / `v-else` branches and surface the inferred expression in documentation and fixtures. @@ -35,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - English README describing usage, playground, and contribution guide. - Roadmap and release prep guidance. +[1.1.1]: https://github.com/eduvia-app/nuxt-can/releases/tag/v1.1.1 [1.1.0]: https://github.com/eduvia-app/nuxt-can/releases/tag/v1.1.0 [1.0.1]: https://github.com/eduvia-app/nuxt-can/releases/tag/v1.0.1 [1.0.0]: https://github.com/eduvia-app/nuxt-can/releases/tag/v1.0.0 diff --git a/README.md b/README.md index 8ae4619..229f88a 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Now you can write directives that stay type-safe: ```vue - +

Access denied

``` @@ -101,10 +101,10 @@ Once the first branch of a conditional chain carries `v-can`, the transformer au Transforms into: ```vue -
+
Draft state
-
+
Pending state
diff --git a/ROADMAP.md b/ROADMAP.md index 2a135fa..238c8ad 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -59,7 +59,7 @@ Ce document sert de guide de travail pour construire le plugin Nuxt et son trans ### 🚀 Phase 4 — Transformation des nœuds `v-can` - Convertir l’expression en chemin `['segment1','segment2',…]`. - Chercher un `v-if` existant : - - `v-if="expr"` → `v-if="(expr) && __can__(path)"`. + - `v-if="expr"` → `v-if="__can__(path) && (expr)"`. - Sans `v-if` → ajouter `v-if="__can__(path)"`. - Interdire `v-can` sur des éléments possédant déjà `v-else` / `v-else-if` (lever une erreur compilateur). @@ -125,7 +125,7 @@ Avant : Après compilation : ```vue -
+
Modifier le contrat
``` @@ -141,7 +141,7 @@ Avant : Après compilation : ```vue - +

Acces refuse

``` diff --git a/package.json b/package.json index 852e81b..d2ba789 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@eduvia-app/nuxt-can", - "version": "1.1.0", + "version": "1.1.1", "description": "Nuxt directives (`v-can`, `v-cannot`) to layer permissions without touching business v-ifs.", "author": "Eduvia ", "homepage": "https://github.com/eduvia-app/nuxt-can#readme", diff --git a/src/runtime/transformer/patches.ts b/src/runtime/transformer/patches.ts index 0c783af..70c1817 100644 --- a/src/runtime/transformer/patches.ts +++ b/src/runtime/transformer/patches.ts @@ -317,7 +317,7 @@ function mergeGuardIntoConditional(params: { ctx.patches.push({ start: ctx.templateStart + conditionDirective.loc.start.offset, end: ctx.templateStart + conditionDirective.loc.end.offset, - text: `v-if="(${conditionExpression}) && ${canInvocation}"`, + text: `v-if="${canInvocation} && (${conditionExpression})"`, }) return @@ -333,7 +333,7 @@ function mergeGuardIntoConditional(params: { ctx.patches.push({ start: ctx.templateStart + conditionDirective.loc.start.offset, end: ctx.templateStart + conditionDirective.loc.end.offset, - text: `v-else-if="(${conditionExpression}) && ${canInvocation}"`, + text: `v-else-if="${canInvocation} && (${conditionExpression})"`, }) return diff --git a/test/transform-can.test.ts b/test/transform-can.test.ts index 2fc54e1..2ff6b51 100644 --- a/test/transform-can.test.ts +++ b/test/transform-can.test.ts @@ -27,7 +27,7 @@ describe('transformCan', () => {
`) - expect(code).toContain(`v-if="(isReady) && __can__('contract', 'create')"`) + expect(code).toContain(`v-if="__can__('contract', 'create') && (isReady)"`) }) it('throws when v-cannot is used without a preceding v-can', () => { @@ -56,8 +56,8 @@ describe('transformCan', () => {

Denied

`) - expect(code).toContain(`v-if="(ready) && __can__('employee', 'view')"`) - expect(code).toContain(`v-else-if="(later) && __can__('employee', 'view')"`) + expect(code).toContain(`v-if="__can__('employee', 'view') && (ready)"`) + expect(code).toContain(`v-else-if="__can__('employee', 'view') && (later)"`) expect(code).toContain(`v-else-if="__can__('employee', 'view')"`) expect(code).toContain(`v-if="!(__can__('employee', 'view'))"`) })