Skip to content

Commit

Permalink
Use babel to parse JS expressions in Vue/Angular (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradlc authored Jan 24, 2022
1 parent 1b1689c commit c28df3a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ function transformHtml(attributes, computedAttributes = []) {
continue
}

let ast = recast.parse(`let __prettier_temp__ = ${attr.value}`)
let ast = recast.parse(`let __prettier_temp__ = ${attr.value}`, {
parser: prettierParserBabel.parsers.babel,
})
let didChange = false

astTypes.visit(ast, {
Expand Down
1 change: 1 addition & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ let vue = [
t`<div :class="'${yes}' + '${yes}'"></div>`,
t`<div :class="['${yes}', '${yes}']"></div>`,
t`<div :class="[cond ? '${yes}' : '${yes}']"></div>`,
t`<div :class="[someVar ?? '${yes}']"></div>`,
t`<div :class="{ '${yes}': true }"></div>`,
t`<div :class="clsx('${yes}')"></div>`,
t`<div :class="\`${yes}\`"></div>`,
Expand Down

0 comments on commit c28df3a

Please sign in to comment.