Ensure invalid typehints are not generated (#5590)
This commit is contained in:
parent
abcd9acd18
commit
79b37a874c
2 changed files with 24 additions and 2 deletions
|
|
@ -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) {
|
||||
|
|
@ -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]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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: [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue