Skip to content

Commit e14a94b

Browse files
Fix Glimmer Concatenation (#119)
* test(Glimmer): Add Failing Test For Glimmer Concatenation Glimmer supports concatenation via the `(concat)` helper. The plugin is currently incorrectly breaking up the concatenation This adds a failing test showing the issue. * fix(Glimmer): Fix Glimmer Concatenation Use ignoreLast in a Glimmer StringLiteral if the parent is a SubExpression (meaning helper) and the last character of the node value is not whitespace Meaning `(concat "border-l-blue border-" @color)` does not get sorted While `(concat "border-l-blue border ")` does get sorted * fix(Glimmer): Only Fix Concat Helper The main issue is with (concat) so we will hardcode that in If in the future we think we need more helpers we can do that * Update changelog * Tweak regex --------- Co-authored-by: Jordan Pittman <[email protected]>
1 parent 0a5e7d3 commit e14a94b

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Fixed
11+
12+
- Don't sort classes in Glimmer `concat` helper.
1113

1214
## [0.2.2] - 2023-01-24
1315

16+
### Fixed
17+
1418
- Add prettier plugins to peer dependencies ([#114](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/114))
1519
- Traverse await expression blocks in Svelte ([#118](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/118))
1620

src/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,12 @@ function transformGlimmer(ast, { env }) {
340340
return
341341
}
342342

343-
node.value = sortClasses(node.value, { env })
343+
const isConcat = parent.type === 'SubExpression' && parent.path.original === 'concat';
344+
345+
node.value = sortClasses(node.value, {
346+
env,
347+
ignoreLast: isConcat && !/[^\S\r\n]$/.test(node.value),
348+
})
344349
},
345350
})
346351
}

tests/test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ let glimmer = [
159159
t`<div class></div>`,
160160
t`<div class=''></div>`,
161161
t`{{link 'Some page' href=person.url class='${no}'}}`,
162+
t`<div class='{{if @isTrue (concat "border-l-4 border-" @borderColor)}}'></div>`,
163+
[
164+
`<div class='{{if @isTrue (concat "border-opacity-30 border-l-4 border-" @borderColor)}}'></div>`,
165+
`<div class='{{if @isTrue (concat "border-l-4 border-opacity-30 border-" @borderColor)}}'></div>`,
166+
],
167+
[
168+
`<div class='{{if @isTrue (concat "border-l-4 border " @borderColor)}}'></div>`,
169+
`<div class='{{if @isTrue (concat "border border-l-4 " @borderColor)}}'></div>`,
170+
],
171+
[
172+
`<div class='{{if @isTrue (nope "border-l-4 border-" @borderColor)}}'></div>`,
173+
`<div class='{{if @isTrue (nope "border- border-l-4" @borderColor)}}'></div>`,
174+
],
162175
]
163176

164177
let tests = {

0 commit comments

Comments
 (0)