diff --git a/src/util/pluginUtils.js b/src/util/pluginUtils.js index 7252314f47f9..ddd499002445 100644 --- a/src/util/pluginUtils.js +++ b/src/util/pluginUtils.js @@ -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] } diff --git a/tests/arbitrary-values.test.js b/tests/arbitrary-values.test.js index 2472d7a773d3..e223ddebe5d9 100644 --- a/tests/arbitrary-values.test.js +++ b/tests/arbitrary-values.test.js @@ -16,6 +16,20 @@ test('arbitrary values', () => { }) }) +it('should not generate any css if an unknown typehint is used', () => { + let config = { + content: [ + { + raw: html`
`, + }, + ], + } + + return run('@tailwind utilities', config).then((result) => { + return expect(result.css).toMatchFormattedCss(css``) + }) +}) + it('should convert _ to spaces', () => { let config = { content: [