Skip to content

Commit

Permalink
Fix v-bind expression (#212)
Browse files Browse the repository at this point in the history
closes #212
  • Loading branch information
Christopher Quadflieg committed May 7, 2021
1 parent 69a2669 commit 4827855
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ import {
unwrapLineFeeds
} from './utils/common';
import { isSvelteInterpolation } from './utils/svelte';
import { isVueEventBinding, isVueExpression, isVueVForWithOf, isVueVOnExpression } from './utils/vue';
import {
isVueEventBinding,
isVueExpression,
isVueVBindExpression,
isVueVForWithOf,
isVueVOnExpression
} from './utils/vue';

const logger: Logger = createLogger(console);
if (process.env.NODE_ENV === 'test') {
Expand Down Expand Up @@ -862,6 +868,8 @@ export class PugPrinter {
val = this.formatVueExpression(val);
} else if (isVueEventBinding(token.name)) {
val = this.formatVueEventBinding(val);
} else if (isVueVBindExpression(token.name)) {
val = this.formatDelegatePrettier(val, '__js_expression');
} else if (isVueVOnExpression(token.name)) {
val = this.formatDelegatePrettier(val, '__js_expression');
} else if (isAngularBinding(token.name)) {
Expand Down
25 changes: 25 additions & 0 deletions src/utils/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,31 @@ export function isVueVForWithOf(name: string, val: string): boolean {
return 'v-for' === name && val.includes('of');
}

/**
* Indicates whether the attribute name is a Vue v-bind.
*
* ---
*
* Example expression:
* ```
* v-btn(v-bind="$attrs")
* ```
*
* In this case `name` is `v-bind`.
*
* ---
*
* Checks for: `v-bind`.
*
* ---
*
* @param name Name of tag attribute.
* @returns `true` if `name` passes the vue `v-bind` check, otherwise `false`.
*/
export function isVueVBindExpression(name: string): boolean {
return 'v-bind' === name;
}

/**
* Indicates whether the attribute name is a Vue v-on.
*
Expand Down
1 change: 1 addition & 0 deletions tests/frameworks/vue/v-bind/formatted.pug
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
a(v-bind="{ ...$attrs }") ...
a(v-bind:href="url") ...
a(:href="url") ...
a(:[key]="url") ...
1 change: 1 addition & 0 deletions tests/frameworks/vue/v-bind/unformatted.pug
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
a(v-bind="{ ...$attrs }") ...
a(v-bind:href=" url ") ...
a(:href=" url ") ...
a(:[key]=" url ") ...

0 comments on commit 4827855

Please sign in to comment.