Skip to content

Commit ca55c2d

Browse files
committed
Handle quote escapes in LESS when sorting @apply
It’s perfect since the AST doesn’t actually have information on these (it’s just strings) but this should be good enough.
1 parent db0bd74 commit ca55c2d

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/index.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,14 +810,33 @@ function transformCss(ast: any, { env }: TransformerContext) {
810810
node.params,
811811
)
812812

813-
node.params = sortClasses(node.params, {
813+
let classList = node.params
814+
815+
let prefix = ''
816+
let suffix = ''
817+
818+
if (classList.startsWith('~"') && classList.endsWith('"')) {
819+
prefix = '~"'
820+
suffix = '"'
821+
classList = classList.slice(2, -1)
822+
isImportant = false
823+
} else if (classList.startsWith("~'") && classList.endsWith("'")) {
824+
prefix = "~'"
825+
suffix = "'"
826+
classList = classList.slice(2, -1)
827+
isImportant = false
828+
}
829+
830+
classList = sortClasses(classList, {
814831
env,
815832
ignoreLast: isImportant,
816833
collapseWhitespace: {
817834
start: false,
818835
end: !isImportant,
819836
},
820837
})
838+
839+
node.params = `${prefix}${classList}${suffix}`
821840
}
822841
})
823842
}

tests/tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ export let tests: Record<string, TestEntry[]> = {
266266
t`@apply ${yes} #{'''!important'''};`,
267267
t`@apply ${yes} #{"'"'"!important"'"'"};`,
268268
],
269-
less: [...css, t`@apply ${yes} !important;`],
269+
less: [...css, t`@apply ${yes} !important;`, t`@apply ~"${yes}";`, t`@apply ~'${yes}';`],
270270
babel: javascript,
271271
typescript: javascript,
272272
'babel-ts': javascript,

0 commit comments

Comments
 (0)