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
12 changes: 10 additions & 2 deletions src/util/pluginUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,12 @@ let typeMap = {
lookup: asLookupValue,
}

let supportedTypes = Object.keys(typeMap)

function splitAtFirst(input, delim) {
return (([first, ...rest]) => [first, rest.join(delim)])(input.split(delim))
let idx = input.indexOf(delim)
if (idx === -1) return [undefined, input]
return [input.slice(0, idx), input.slice(idx + 1)]
}

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

if (value.length > 0 && Object.keys(typeMap).includes(explicitType)) {
if (explicitType !== undefined && !supportedTypes.includes(explicitType)) {
return []
}

if (value.length > 0 && supportedTypes.includes(explicitType)) {
return [asValue(`[${value}]`, values, tailwindConfig), explicitType]
}

Expand Down
14 changes: 14 additions & 0 deletions tests/arbitrary-values.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ test('arbitrary values', () => {
})
})

it('should not generate any css if an unknown typehint is used', () => {
let config = {
content: [
{
raw: html`<div class="inset-[hmm:12px]"></div>`,
},
],
}

return run('@tailwind utilities', config).then((result) => {
return expect(result.css).toMatchFormattedCss(css``)
})
})

it('should convert _ to spaces', () => {
let config = {
content: [
Expand Down