From 6bcb4450739f542ffeb8191e898b0fce4b0d6e63 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Fri, 10 Jun 2022 10:32:37 +0200 Subject: [PATCH] `\` are valid arbitrary variant tokens We use `\` for escaping `.` or `_` so they should be part of the arbitrary variant regex. --- src/lib/defaultExtractor.js | 2 +- tests/arbitrary-variants.test.js | 54 ++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/lib/defaultExtractor.js b/src/lib/defaultExtractor.js index c3e5b642cc3f..fa2cc92b8f17 100644 --- a/src/lib/defaultExtractor.js +++ b/src/lib/defaultExtractor.js @@ -69,7 +69,7 @@ function* buildRegExps(context) { '((?=((', regex.any( [ - regex.pattern([/([^\s"'`\[\\]+-)?\[[^\s"'`\\]+\]/, separator]), + regex.pattern([/([^\s"'`\[\\]+-)?\[[^\s"'`]+\]/, separator]), regex.pattern([/[^\s"'`\[\\]+/, separator]), ], true diff --git a/tests/arbitrary-variants.test.js b/tests/arbitrary-variants.test.js index ffa4a70732d4..2d94d557b45a 100644 --- a/tests/arbitrary-variants.test.js +++ b/tests/arbitrary-variants.test.js @@ -405,3 +405,57 @@ test('with @apply', () => { `) }) }) + +test('keeps escaped underscores', () => { + let config = { + content: [ + { + raw: '
', + }, + ], + corePlugins: { preflight: false }, + } + + let input = ` + @tailwind base; + @tailwind components; + @tailwind utilities; + ` + + return run(input, config).then((result) => { + expect(result.css).toMatchFormattedCss(css` + ${defaults} + + .\[\&_\.foo\\_\\_bar\]\:underline .foo__bar { + text-decoration-line: underline; + } + `) + }) +}) + +test('keeps escaped underscores with multiple arbitrary variants', () => { + let config = { + content: [ + { + raw: '
', + }, + ], + corePlugins: { preflight: false }, + } + + let input = ` + @tailwind base; + @tailwind components; + @tailwind utilities; + ` + + return run(input, config).then((result) => { + expect(result.css).toMatchFormattedCss(css` + ${defaults} + + .\[\&_\.foo\\_\\_bar\]\:\[\&_\.bar\\_\\_baz\]\:underline .bar__baz .foo__bar { + text-decoration-line: underline; + } + `) + }) +})