Skip to content

Commit c10ba4e

Browse files
akbngRobinMalfait
andauthored
Fix fractional values not being parsed properly inside arbitrary properties (#9705)
* remove redundant closing bracket in regex pattern * test fractional spacing values in theme function * add test that ensures arbitrary properties are separate * update changelog Co-authored-by: Robin Malfait <[email protected]>
1 parent 88dcb6e commit c10ba4e

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Exclude non-relevant selectors when generating rules with the important modifier ([#9677](https://github.com/tailwindlabs/tailwindcss/issues/9677))
1515
- Fix merging of arrays during config resolution ([#9706](https://github.com/tailwindlabs/tailwindcss/issues/9706))
1616
- Ensure configured `font-feature-settings` are included in Preflight ([#9707](https://github.com/tailwindlabs/tailwindcss/pull/9707))
17+
- Fix fractional values not being parsed properly inside arbitrary properties ([#9705](https://github.com/tailwindlabs/tailwindcss/pull/9705))
1718

1819
## [3.2.1] - 2022-10-21
1920

src/lib/defaultExtractor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function* buildRegExps(context) {
2929

3030
let utility = regex.any([
3131
// Arbitrary properties
32-
/\[[^\s:'"`]+:[^\s\]]+\]/,
32+
/\[[^\s:'"`]+:[^\s]+\]/,
3333

3434
// Utilities
3535
regex.pattern([

tests/arbitrary-properties.test.js

+92
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,37 @@ test('basic arbitrary properties', () => {
2727
})
2828
})
2929

30+
test('different arbitrary properties are picked up separately', () => {
31+
let config = {
32+
content: [
33+
{
34+
raw: html`<div class="[foo:bar] [bar:baz]"></div>`,
35+
},
36+
],
37+
corePlugins: { preflight: false },
38+
}
39+
40+
let input = css`
41+
@tailwind base;
42+
@tailwind components;
43+
@tailwind utilities;
44+
`
45+
46+
return run(input, config).then((result) => {
47+
expect(result.css).toMatchFormattedCss(css`
48+
${defaults}
49+
50+
.\[foo\:bar\] {
51+
foo: bar;
52+
}
53+
54+
.\[bar\:baz\] {
55+
bar: baz;
56+
}
57+
`)
58+
})
59+
})
60+
3061
test('arbitrary properties with modifiers', () => {
3162
let config = {
3263
content: [
@@ -296,6 +327,67 @@ test('invalid arbitrary property 2', () => {
296327
})
297328
})
298329

330+
test('using fractional spacing values inside theme() function', () => {
331+
let config = {
332+
content: [
333+
{
334+
raw: html`<div
335+
class="[border:_calc(5vw_-_theme(spacing[2.5]))_double_theme('colors.fuchsia.700')]"
336+
></div>`,
337+
},
338+
],
339+
corePlugins: { preflight: false },
340+
}
341+
342+
let input = css`
343+
@tailwind base;
344+
@tailwind components;
345+
@tailwind utilities;
346+
`
347+
348+
return run(input, config).then((result) => {
349+
expect(result.css).toMatchFormattedCss(css`
350+
${defaults}
351+
352+
.\[border\:_calc\(5vw_-_theme\(spacing\[2\.5\]\)\)_double_theme\(\'colors\.fuchsia\.700\'\)\] {
353+
border: calc(5vw - 0.625rem) double #a21caf;
354+
}
355+
`)
356+
})
357+
})
358+
359+
test('using multiple arbitrary props having fractional spacing values', () => {
360+
let config = {
361+
content: [
362+
{
363+
raw: html`<div
364+
class="[height:_calc(100vh_-_theme(spacing[2.5]))] [box-shadow:_0_calc(theme(spacing[0.5])_*_-1)_theme(colors.red.400)_inset]"
365+
></div>`,
366+
},
367+
],
368+
corePlugins: { preflight: false },
369+
}
370+
371+
let input = css`
372+
@tailwind base;
373+
@tailwind components;
374+
@tailwind utilities;
375+
`
376+
377+
return run(input, config).then((result) => {
378+
return expect(result.css).toMatchFormattedCss(css`
379+
${defaults}
380+
381+
.\[height\:_calc\(100vh_-_theme\(spacing\[2\.5\]\)\)\] {
382+
height: calc(100vh - 0.625rem);
383+
}
384+
.\[box-shadow\:_0_calc\(theme\(spacing\[0\.5\]\)_\*_-1\)_theme\(colors\.red\.400\)_inset\] {
385+
box-shadow: 0 calc(0.125rem * -1) #f87171 inset;
386+
}
387+
`)
388+
})
389+
})
390+
299391
it('should be possible to read theme values in arbitrary properties (without quotes)', () => {
300392
let config = {
301393
content: [{ raw: html`<div class="[--a:theme(colors.blue.500)] [color:var(--a)]"></div>` }],

0 commit comments

Comments
 (0)