From faa5e8849be45e1009dc1d0f862ca782ee0a1ee9 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Sun, 15 Mar 2026 22:04:58 +0100 Subject: [PATCH] Cleanup inconsistencies related to (regex) escapes (#19804) This PR does some generic cleanup to the codebase. I'm playing with oxfmt and oxlint and noticed some unnecessary escapes. Might add these dependencies to the project later (and rolldown for building). But baby steps for now. ## Test plan 1. All tests should still pass --- integrations/utils.ts | 2 +- integrations/vite/react-router.test.ts | 2 +- integrations/vite/svelte.test.ts | 2 +- packages/@tailwindcss-node/src/urls.ts | 2 +- packages/@tailwindcss-postcss/src/index.test.ts | 2 +- .../src/codemods/config/migrate-postcss.ts | 8 ++++---- packages/@tailwindcss-vite/src/index.ts | 4 ++-- packages/tailwindcss/src/candidate.test.ts | 2 -- packages/tailwindcss/src/canonicalize-candidates.ts | 8 ++++---- packages/tailwindcss/src/compat/apply-config-to-theme.ts | 2 +- packages/tailwindcss/src/css-parser.test.ts | 2 +- packages/tailwindcss/src/utils/infer-data-type.ts | 2 +- 12 files changed, 18 insertions(+), 20 deletions(-) diff --git a/integrations/utils.ts b/integrations/utils.ts index c5d3306c4..f9638b857 100644 --- a/integrations/utils.ts +++ b/integrations/utils.ts @@ -569,7 +569,7 @@ export async function fetchStyles(base: string, path = '/'): Promise { let index = await fetch(`${base}${path}`) let html = await index.text() - let linkRegex = /]*>([\s\S]*?)<\/style>/gi let stylesheets: string[] = [] diff --git a/integrations/vite/react-router.test.ts b/integrations/vite/react-router.test.ts index 9d8fae9b8..98b0c928d 100644 --- a/integrations/vite/react-router.test.ts +++ b/integrations/vite/react-router.test.ts @@ -196,7 +196,7 @@ test('build mode', { fs: WORKSPACE }, async ({ spawn, exec, expect }) => { let url = '' await process.onStdout((m) => { - let match = /\[react-router-serve\]\s*(http.*)\ \/?/.exec(m) + let match = /\[react-router-serve\]\s*(http.*) \/?/.exec(m) if (match) url = match[1] return url != '' }) diff --git a/integrations/vite/svelte.test.ts b/integrations/vite/svelte.test.ts index 107494207..e186c3f85 100644 --- a/integrations/vite/svelte.test.ts +++ b/integrations/vite/svelte.test.ts @@ -101,7 +101,7 @@ test( await fs.expectFileToContain(files[0][0], [ candidate`underline`, '.global{color:var(--color-green-500,oklch(72.3% .219 149.579));animation:2s ease-in-out infinite globalKeyframes}', - /\.local.svelte-.*\{color:var\(--color-red-500\,oklch\(63\.7% \.237 25\.331\)\);animation:2s ease-in-out infinite svelte-.*-localKeyframes\}/, + /\.local.svelte-.*\{color:var\(--color-red-500,oklch\(63\.7% \.237 25\.331\)\);animation:2s ease-in-out infinite svelte-.*-localKeyframes\}/, /@keyframes globalKeyframes\{/, /@keyframes svelte-.*-localKeyframes\{/, ]) diff --git a/packages/@tailwindcss-node/src/urls.ts b/packages/@tailwindcss-node/src/urls.ts index d6bc22926..61695a9d1 100644 --- a/packages/@tailwindcss-node/src/urls.ts +++ b/packages/@tailwindcss-node/src/urls.ts @@ -154,7 +154,7 @@ function skipUrlReplacer(rawUrl: string, aliases?: string[]) { return ( isExternalUrl(rawUrl) || isDataUrl(rawUrl) || - !rawUrl[0].match(/[\.a-zA-Z0-9_]/) || + !rawUrl[0].match(/[.a-zA-Z0-9_]/) || functionCallRE.test(rawUrl) ) } diff --git a/packages/@tailwindcss-postcss/src/index.test.ts b/packages/@tailwindcss-postcss/src/index.test.ts index 593ef70cf..ff12e09ef 100644 --- a/packages/@tailwindcss-postcss/src/index.test.ts +++ b/packages/@tailwindcss-postcss/src/index.test.ts @@ -43,7 +43,7 @@ test("`@import 'tailwindcss'` is replaced with the generated CSS", async () => { }) expect(result.messages).toContainEqual({ type: 'dir-dependency', - dir: expect.stringMatching(/example-project[\/|\\]src$/g), + dir: expect.stringMatching(/example-project[/|\\]src$/g), glob: expect.stringMatching(/^\*\*\/\*/g), parent: expect.any(String), plugin: expect.any(String), diff --git a/packages/@tailwindcss-upgrade/src/codemods/config/migrate-postcss.ts b/packages/@tailwindcss-upgrade/src/codemods/config/migrate-postcss.ts index b44d1ea61..512f3df59 100644 --- a/packages/@tailwindcss-upgrade/src/codemods/config/migrate-postcss.ts +++ b/packages/@tailwindcss-upgrade/src/codemods/config/migrate-postcss.ts @@ -136,16 +136,16 @@ async function migratePostCSSJSConfig(configPath: string): Promise<{ didRemovePostCSSImport: boolean } | null> { function isTailwindCSSPlugin(line: string) { - return /['"]?tailwindcss['"]?\: ?\{\}/.test(line) + return /['"]?tailwindcss['"]?: ?\{\}/.test(line) } function isPostCSSImportPlugin(line: string) { - return /['"]?postcss-import['"]?\: ?\{\}/.test(line) + return /['"]?postcss-import['"]?: ?\{\}/.test(line) } function isAutoprefixerPlugin(line: string) { - return /['"]?autoprefixer['"]?\: ?\{\}/.test(line) + return /['"]?autoprefixer['"]?: ?\{\}/.test(line) } function isTailwindCSSNestingPlugin(line: string) { - return /['"]tailwindcss\/nesting['"]\: ?(\{\}|['"]postcss-nesting['"])/.test(line) + return /['"]tailwindcss\/nesting['"]: ?(\{\}|['"]postcss-nesting['"])/.test(line) } info('Migrating PostCSS configuration…') diff --git a/packages/@tailwindcss-vite/src/index.ts b/packages/@tailwindcss-vite/src/index.ts index 6dfc7b227..cd0249680 100644 --- a/packages/@tailwindcss-vite/src/index.ts +++ b/packages/@tailwindcss-vite/src/index.ts @@ -24,7 +24,7 @@ import * as vite from 'vite' const DEBUG = env.DEBUG const SPECIAL_QUERY_RE = /[?&](?:worker|sharedworker|raw|url)\b/ const COMMON_JS_PROXY_RE = /\?commonjs-proxy/ -const INLINE_STYLE_ID_RE = /[?&]index\=\d+\.css$/ +const INLINE_STYLE_ID_RE = /[?&]index=\d+\.css$/ export type PluginOptions = { /** @@ -415,7 +415,7 @@ class Root { // crash Vite. We work around this for now by ignoring updates to them. // // https://github.com/tailwindlabs/tailwindcss/issues/16877 - if (/[\#\?].*\.svg$/.test(file)) { + if (/[#?].*\.svg$/.test(file)) { return } _addWatchFile(file) diff --git a/packages/tailwindcss/src/candidate.test.ts b/packages/tailwindcss/src/candidate.test.ts index c3bb7b9e8..d66bfcd66 100644 --- a/packages/tailwindcss/src/candidate.test.ts +++ b/packages/tailwindcss/src/candidate.test.ts @@ -2043,8 +2043,6 @@ const candidates = [ ['bg-[var(--spacing)_-_1px]', 'bg-[var(--spacing)-1px]'], ['bg-[var(--_spacing)]', 'bg-(--_spacing)'], ['bg-(--_spacing)', 'bg-(--_spacing)'], - ['bg-[var(--\_spacing)]', 'bg-(--_spacing)'], - ['bg-(--\_spacing)', 'bg-(--_spacing)'], ['bg-[-1px_-1px]', 'bg-[-1px_-1px]'], ['p-[round(to-zero,1px)]', 'p-[round(to-zero,1px)]'], ['w-1/2', 'w-1/2'], diff --git a/packages/tailwindcss/src/canonicalize-candidates.ts b/packages/tailwindcss/src/canonicalize-candidates.ts index d1b3b361b..f26516c13 100644 --- a/packages/tailwindcss/src/canonicalize-candidates.ts +++ b/packages/tailwindcss/src/canonicalize-candidates.ts @@ -92,7 +92,7 @@ interface DesignSystem extends BaseDesignSystem { [CANONICALIZE_UTILITY_KEY]: DefaultMap> [CONVERTER_KEY]: (input: string, options?: Convert) => [string, CandidateModifier | null] [SPACING_KEY]: DefaultMap | null - [UTILITY_SIGNATURE_KEY]: DefaultMap> + [UTILITY_SIGNATURE_KEY]: DefaultMap> [STATIC_UTILITIES_KEY]: DefaultMap< SignatureOptions, DefaultMap>> @@ -102,7 +102,7 @@ interface DesignSystem extends BaseDesignSystem { DefaultMap>> > [PRE_COMPUTED_UTILITIES_KEY]: DefaultMap> - [VARIANT_SIGNATURE_KEY]: DefaultMap + [VARIANT_SIGNATURE_KEY]: DefaultMap [PRE_COMPUTED_VARIANTS_KEY]: DefaultMap } } @@ -2095,7 +2095,7 @@ function createUtilitySignatureCache( designSystem: DesignSystem, ): DesignSystem['storage'][typeof UTILITY_SIGNATURE_KEY] { return new DefaultMap((options: SignatureOptions) => { - return new DefaultMap((utility) => { + return new DefaultMap((utility) => { try { // Ensure the prefix is added to the utility if it is not already present. utility = @@ -2463,7 +2463,7 @@ export const VARIANT_SIGNATURE_KEY = Symbol() function createVariantSignatureCache( designSystem: DesignSystem, ): DesignSystem['storage'][typeof VARIANT_SIGNATURE_KEY] { - return new DefaultMap((variant) => { + return new DefaultMap((variant) => { try { // Ensure the prefix is added to the utility if it is not already present. variant = diff --git a/packages/tailwindcss/src/compat/apply-config-to-theme.ts b/packages/tailwindcss/src/compat/apply-config-to-theme.ts index 885d2d9ba..8757520ee 100644 --- a/packages/tailwindcss/src/compat/apply-config-to-theme.ts +++ b/packages/tailwindcss/src/compat/apply-config-to-theme.ts @@ -172,7 +172,7 @@ const OLD_TO_NEW_NAMESPACE: Record = { transitionTimingFunction: 'ease', } -const IS_VALID_KEY = /^[a-zA-Z0-9-_%/\.]+$/ +const IS_VALID_KEY = /^[a-zA-Z0-9-_%/.]+$/ export function keyPathToCssProperty(path: string[]) { // In some special cases the `DEFAULT` key did not map to a "default" utility diff --git a/packages/tailwindcss/src/css-parser.test.ts b/packages/tailwindcss/src/css-parser.test.ts index 5f0aa2287..6caeb9f16 100644 --- a/packages/tailwindcss/src/css-parser.test.ts +++ b/packages/tailwindcss/src/css-parser.test.ts @@ -212,7 +212,7 @@ describe.each(['Unix', 'Windows'])('Line endings: %s', (lineEndings) => { { kind: 'declaration', property: 'content', - value: `'These are not the end \"\\' of the string'`, + value: `'These are not the end "\\' of the string'`, important: false, }, ]) diff --git a/packages/tailwindcss/src/utils/infer-data-type.ts b/packages/tailwindcss/src/utils/infer-data-type.ts index 587bae785..afaab7c60 100644 --- a/packages/tailwindcss/src/utils/infer-data-type.ts +++ b/packages/tailwindcss/src/utils/infer-data-type.ts @@ -184,7 +184,7 @@ function isPercentage(value: string): boolean { /* -------------------------------------------------------------------------- */ -const IS_FRACTION = new RegExp(`^${HAS_NUMBER.source}\s*/\s*${HAS_NUMBER.source}$`) +const IS_FRACTION = new RegExp(`^${HAS_NUMBER.source}\\s*/\\s*${HAS_NUMBER.source}$`) function isFraction(value: string): boolean { return IS_FRACTION.test(value) || hasMathFn(value)