@@ -104,13 +104,14 @@ export interface CSSModulesOptions {
104
104
105
105
const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)($|\\?)`
106
106
const cssLangRE = new RegExp ( cssLangs )
107
+ // eslint-disable-next-line regexp/no-unused-capturing-group
107
108
const cssModuleRE = new RegExp ( `\\.module${ cssLangs } ` )
108
- const directRequestRE = / ( \? | & ) d i r e c t \b /
109
- const htmlProxyRE = / ( \? | & ) h t m l - p r o x y \b /
109
+ const directRequestRE = / (?: \? | & ) d i r e c t \b /
110
+ const htmlProxyRE = / (?: \? | & ) h t m l - p r o x y \b /
110
111
const commonjsProxyRE = / \? c o m m o n j s - p r o x y /
111
- const inlineRE = / ( \? | & ) i n l i n e \b /
112
- const inlineCSSRE = / ( \? | & ) i n l i n e - c s s \b /
113
- const usedRE = / ( \? | & ) u s e d \b /
112
+ const inlineRE = / (?: \? | & ) i n l i n e \b /
113
+ const inlineCSSRE = / (?: \? | & ) i n l i n e - c s s \b /
114
+ const usedRE = / (?: \? | & ) u s e d \b /
114
115
const varRE = / ^ v a r \( / i
115
116
116
117
const cssBundleName = 'style.css'
@@ -1163,11 +1164,13 @@ type CssUrlReplacer = (
1163
1164
) => string | Promise < string >
1164
1165
// https://drafts.csswg.org/css-syntax-3/#identifier-code-point
1165
1166
export const cssUrlRE =
1166
- / (?< = ^ | [ ^ \w \- \u0080 - \uffff ] ) u r l \( \s * ( ' [ ^ ' ] + ' | " [ ^ " ] + " | [ ^ ' " ) ] + ) \s * \) /
1167
+ / (?< = ^ | [ ^ \w \- \u0080 - \uffff ] ) u r l \( ( \s * ( ' [ ^ ' ] + ' | " [ ^ " ] + " ) \s * | [ ^ ' " ) ] + ) \) /
1167
1168
export const cssDataUriRE =
1168
- / (?< = ^ | [ ^ \w \- \u0080 - \uffff ] ) d a t a - u r i \( \s * ( ' [ ^ ' ] + ' | " [ ^ " ] + " | [ ^ ' " ) ] + ) \s * \) /
1169
+ / (?< = ^ | [ ^ \w \- \u0080 - \uffff ] ) d a t a - u r i \( ( \s * ( ' [ ^ ' ] + ' | " [ ^ " ] + " ) \s * | [ ^ ' " ) ] + ) \) /
1169
1170
export const importCssRE = / @ i m p o r t ( ' [ ^ ' ] + \. c s s ' | " [ ^ " ] + \. c s s " | [ ^ ' " ) ] + \. c s s ) /
1170
- const cssImageSetRE = / (?< = i m a g e - s e t \( ) ( (?: [ \w \- ] + \( [ ^ \) ] * \) | [ ^ ) ] ) * ) (? = \) ) /
1171
+ // Assuming a function name won't be longer than 256 chars
1172
+ // eslint-disable-next-line regexp/no-unused-capturing-group -- doesn't detect asyncReplace usage
1173
+ const cssImageSetRE = / (?< = i m a g e - s e t \( ) ( (?: [ \w \- ] { 1 , 256 } \( [ ^ ) ] * \) | [ ^ ) ] ) * ) (? = \) ) /
1171
1174
1172
1175
const UrlRewritePostcssPlugin : PostCSS . PluginCreator < {
1173
1176
replacer : CssUrlReplacer
@@ -1223,7 +1226,7 @@ function rewriteCssUrls(
1223
1226
) : Promise < string > {
1224
1227
return asyncReplace ( css , cssUrlRE , async ( match ) => {
1225
1228
const [ matched , rawUrl ] = match
1226
- return await doUrlReplace ( rawUrl , matched , replacer )
1229
+ return await doUrlReplace ( rawUrl . trim ( ) , matched , replacer )
1227
1230
} )
1228
1231
}
1229
1232
@@ -1233,7 +1236,7 @@ function rewriteCssDataUris(
1233
1236
) : Promise < string > {
1234
1237
return asyncReplace ( css , cssDataUriRE , async ( match ) => {
1235
1238
const [ matched , rawUrl ] = match
1236
- return await doUrlReplace ( rawUrl , matched , replacer , 'data-uri' )
1239
+ return await doUrlReplace ( rawUrl . trim ( ) , matched , replacer , 'data-uri' )
1237
1240
} )
1238
1241
}
1239
1242
@@ -1250,7 +1253,7 @@ function rewriteImportCss(
1250
1253
// TODO: image and cross-fade could contain a "url" that needs to be processed
1251
1254
// https://drafts.csswg.org/css-images-4/#image-notation
1252
1255
// https://drafts.csswg.org/css-images-4/#cross-fade-function
1253
- const cssNotProcessedRE = / ( g r a d i e n t | e l e m e n t | c r o s s - f a d e | i m a g e ) \( /
1256
+ const cssNotProcessedRE = / (?: g r a d i e n t | e l e m e n t | c r o s s - f a d e | i m a g e ) \( /
1254
1257
1255
1258
async function rewriteCssImageSet (
1256
1259
css : string ,
@@ -1379,7 +1382,7 @@ export async function hoistAtRules(css: string): Promise<string> {
1379
1382
// to top when multiple files are concatenated.
1380
1383
// match until semicolon that's not in quotes
1381
1384
const atImportRE =
1382
- / @ i m p o r t \s * (?: u r l \( [ ^ \ )] * \) | " ( [ ^ " ] | (?< = \\ ) " ) * " | ' ( [ ^ ' ] | (?< = \\ ) ' ) * ' | [ ^ ; ] * ) . * ? ; / gm
1385
+ / @ i m p o r t (?: \s * (?: u r l \( [ ^ ) ] * \) | " (?: [ ^ " ] | (?< = \\ ) " ) * " | ' (?: [ ^ ' ] | (?< = \\ ) ' ) * ' ) . * ? | [ ^ ; ] * ) ; / g
1383
1386
while ( ( match = atImportRE . exec ( cleanCss ) ) ) {
1384
1387
s . remove ( match . index , match . index + match [ 0 ] . length )
1385
1388
// Use `appendLeft` instead of `prepend` to preserve original @import order
@@ -1389,7 +1392,7 @@ export async function hoistAtRules(css: string): Promise<string> {
1389
1392
// #6333
1390
1393
// CSS @charset must be the top-first in the file, hoist the first to top
1391
1394
const atCharsetRE =
1392
- / @ c h a r s e t \s * (?: " ( [ ^ " ] | (?< = \\ ) " ) * " | ' ( [ ^ ' ] | (?< = \\ ) ' ) * ' | [ ^ ; ] * ) . * ? ; / gm
1395
+ / @ c h a r s e t (?: \s * (?: " (?: [ ^ " ] | (?< = \\ ) " ) * " | ' (?: [ ^ ' ] | (?< = \\ ) ' ) * ' ) . * ? | [ ^ ; ] * ) ; / g
1393
1396
let foundCharset = false
1394
1397
while ( ( match = atCharsetRE . exec ( cleanCss ) ) ) {
1395
1398
s . remove ( match . index , match . index + match [ 0 ] . length )
0 commit comments