Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"import-fresh": "^3.3.0",
"import-from": "^4.0.0",
"jest": "^27.4.7",
"jsesc": "^2.5.2",
"license-checker": "^25.0.1",
"line-column": "^1.0.2",
"object-hash": "^2.2.0",
Expand Down
8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import requireFresh from 'import-fresh'
import objectHash from 'object-hash'
import * as svelte from 'prettier-plugin-svelte'
import lineColumn from 'line-column'
import jsesc from 'jsesc'

let contextMap = new Map()

Expand Down Expand Up @@ -168,6 +169,13 @@ function transformHtml(attributes, computedAttributes = []) {
if (isStringLiteral(path.node)) {
if (sortStringLiteral(path.node, { env })) {
didChange = true

// https://github.com/benjamn/recast/issues/171#issuecomment-224996336
let quote = path.node.extra.raw[0]
let value = jsesc(path.node.value, {
quotes: quote === "'" ? 'single' : 'double',
})
path.node.value = new String(quote + value + quote)
}
}
this.traverse(path)
Expand Down
1 change: 1 addition & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ let vue = [
t`<div :class="\`${yes}\`"></div>`,
t`<div :class="\`${yes} \${someVar}\`"></div>`,
t`<div :class="someVar! ? \`${yes}\` : \`${yes}\`"></div>`, // ts
t`<div :class="someVar ? someFunc(someVar as string) + '${yes}' : ''"></div>`, // ts
[
`<div :class="\`sm:block inline flex\${someVar}\`"></div>`,
`<div :class="\`inline sm:block flex\${someVar}\`"></div>`,
Expand Down