Skip to content

Commit 79b37a8

Browse files
authored
Ensure invalid typehints are not generated (#5590)
1 parent abcd9ac commit 79b37a8

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/util/pluginUtils.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,12 @@ let typeMap = {
284284
lookup: asLookupValue,
285285
}
286286

287+
let supportedTypes = Object.keys(typeMap)
288+
287289
function splitAtFirst(input, delim) {
288-
return (([first, ...rest]) => [first, rest.join(delim)])(input.split(delim))
290+
let idx = input.indexOf(delim)
291+
if (idx === -1) return [undefined, input]
292+
return [input.slice(0, idx), input.slice(idx + 1)]
289293
}
290294

291295
export function coerceValue(type, modifier, values, tailwindConfig) {
@@ -294,7 +298,11 @@ export function coerceValue(type, modifier, values, tailwindConfig) {
294298
if (isArbitraryValue(modifier)) {
295299
let [explicitType, value] = splitAtFirst(modifier.slice(1, -1), ':')
296300

297-
if (value.length > 0 && Object.keys(typeMap).includes(explicitType)) {
301+
if (explicitType !== undefined && !supportedTypes.includes(explicitType)) {
302+
return []
303+
}
304+
305+
if (value.length > 0 && supportedTypes.includes(explicitType)) {
298306
return [asValue(`[${value}]`, values, tailwindConfig), explicitType]
299307
}
300308

tests/arbitrary-values.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ test('arbitrary values', () => {
1616
})
1717
})
1818

19+
it('should not generate any css if an unknown typehint is used', () => {
20+
let config = {
21+
content: [
22+
{
23+
raw: html`<div class="inset-[hmm:12px]"></div>`,
24+
},
25+
],
26+
}
27+
28+
return run('@tailwind utilities', config).then((result) => {
29+
return expect(result.css).toMatchFormattedCss(css``)
30+
})
31+
})
32+
1933
it('should convert _ to spaces', () => {
2034
let config = {
2135
content: [

0 commit comments

Comments
 (0)