@@ -111,13 +111,14 @@ export interface CSSModulesOptions {
111
111
112
112
const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)($|\\?)`
113
113
const cssLangRE = new RegExp ( cssLangs )
114
+ // eslint-disable-next-line regexp/no-unused-capturing-group
114
115
const cssModuleRE = new RegExp ( `\\.module${ cssLangs } ` )
115
- const directRequestRE = / ( \? | & ) d i r e c t \b /
116
- const htmlProxyRE = / ( \? | & ) h t m l - p r o x y \b /
116
+ const directRequestRE = / (?: \? | & ) d i r e c t \b /
117
+ const htmlProxyRE = / (?: \? | & ) h t m l - p r o x y \b /
117
118
const commonjsProxyRE = / \? c o m m o n j s - p r o x y /
118
- const inlineRE = / ( \? | & ) i n l i n e \b /
119
- const inlineCSSRE = / ( \? | & ) i n l i n e - c s s \b /
120
- const usedRE = / ( \? | & ) u s e d \b /
119
+ const inlineRE = / (?: \? | & ) i n l i n e \b /
120
+ const inlineCSSRE = / (?: \? | & ) i n l i n e - c s s \b /
121
+ const usedRE = / (?: \? | & ) u s e d \b /
121
122
const varRE = / ^ v a r \( / i
122
123
123
124
const cssBundleName = 'style.css'
@@ -1175,11 +1176,12 @@ type CssUrlReplacer = (
1175
1176
) => string | Promise < string >
1176
1177
// https://drafts.csswg.org/css-syntax-3/#identifier-code-point
1177
1178
export const cssUrlRE =
1178
- / (?< = ^ | [ ^ \w \- \u0080 - \uffff ] ) u r l \( \s * ( ' [ ^ ' ] + ' | " [ ^ " ] + " | [ ^ ' " ) ] + ) \s * \) /
1179
+ / (?< = ^ | [ ^ \w \- \u0080 - \uffff ] ) u r l \( ( \s * ( ' [ ^ ' ] + ' | " [ ^ " ] + " ) \s * | [ ^ ' " ) ] + ) \) /
1179
1180
export const cssDataUriRE =
1180
- / (?< = ^ | [ ^ \w \- \u0080 - \uffff ] ) d a t a - u r i \( \s * ( ' [ ^ ' ] + ' | " [ ^ " ] + " | [ ^ ' " ) ] + ) \s * \) /
1181
+ / (?< = ^ | [ ^ \w \- \u0080 - \uffff ] ) d a t a - u r i \( ( \s * ( ' [ ^ ' ] + ' | " [ ^ " ] + " ) \s * | [ ^ ' " ) ] + ) \) /
1181
1182
export const importCssRE = / @ i m p o r t ( ' [ ^ ' ] + \. c s s ' | " [ ^ " ] + \. c s s " | [ ^ ' " ) ] + \. c s s ) /
1182
- const cssImageSetRE = / (?< = i m a g e - s e t \( ) ( (?: [ \w \- ] + \( [ ^ \) ] * \) | [ ^ ) ] ) * ) (? = \) ) /
1183
+ // eslint-disable-next-line regexp/no-unused-capturing-group, regexp/no-super-linear-backtracking -- TODO: FIXME backtracking
1184
+ const cssImageSetRE = / (?< = i m a g e - s e t \( ) ( (?: [ \w \- ] + \( [ ^ ) ] * \) | [ ^ ) ] ) * ) (? = \) ) /
1183
1185
1184
1186
const UrlRewritePostcssPlugin : PostCSS . PluginCreator < {
1185
1187
replacer : CssUrlReplacer
@@ -1235,7 +1237,7 @@ function rewriteCssUrls(
1235
1237
) : Promise < string > {
1236
1238
return asyncReplace ( css , cssUrlRE , async ( match ) => {
1237
1239
const [ matched , rawUrl ] = match
1238
- return await doUrlReplace ( rawUrl , matched , replacer )
1240
+ return await doUrlReplace ( rawUrl . trim ( ) , matched , replacer )
1239
1241
} )
1240
1242
}
1241
1243
@@ -1245,7 +1247,7 @@ function rewriteCssDataUris(
1245
1247
) : Promise < string > {
1246
1248
return asyncReplace ( css , cssDataUriRE , async ( match ) => {
1247
1249
const [ matched , rawUrl ] = match
1248
- return await doUrlReplace ( rawUrl , matched , replacer , 'data-uri' )
1250
+ return await doUrlReplace ( rawUrl . trim ( ) , matched , replacer , 'data-uri' )
1249
1251
} )
1250
1252
}
1251
1253
@@ -1262,7 +1264,7 @@ function rewriteImportCss(
1262
1264
// TODO: image and cross-fade could contain a "url" that needs to be processed
1263
1265
// https://drafts.csswg.org/css-images-4/#image-notation
1264
1266
// https://drafts.csswg.org/css-images-4/#cross-fade-function
1265
- 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 ) \( /
1267
+ 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 ) \( /
1266
1268
1267
1269
async function rewriteCssImageSet (
1268
1270
css : string ,
@@ -1391,7 +1393,7 @@ export async function hoistAtRules(css: string): Promise<string> {
1391
1393
// to top when multiple files are concatenated.
1392
1394
// match until semicolon that's not in quotes
1393
1395
const atImportRE =
1394
- / @ i m p o r t \s * (?: u r l \( [ ^ \ )] * \) | " ( [ ^ " ] | (?< = \\ ) " ) * " | ' ( [ ^ ' ] | (?< = \\ ) ' ) * ' | [ ^ ; ] * ) . * ? ; / gm
1396
+ / @ i m p o r t (?: \s * (?: u r l \( [ ^ ) ] * \) | " (?: [ ^ " ] | (?< = \\ ) " ) * " | ' (?: [ ^ ' ] | (?< = \\ ) ' ) * ' ) . * ? | [ ^ ; ] * ) ; / g
1395
1397
while ( ( match = atImportRE . exec ( cleanCss ) ) ) {
1396
1398
s . remove ( match . index , match . index + match [ 0 ] . length )
1397
1399
// Use `appendLeft` instead of `prepend` to preserve original @import order
@@ -1401,7 +1403,7 @@ export async function hoistAtRules(css: string): Promise<string> {
1401
1403
// #6333
1402
1404
// CSS @charset must be the top-first in the file, hoist the first to top
1403
1405
const atCharsetRE =
1404
- / @ c h a r s e t \s * (?: " ( [ ^ " ] | (?< = \\ ) " ) * " | ' ( [ ^ ' ] | (?< = \\ ) ' ) * ' | [ ^ ; ] * ) . * ? ; / gm
1406
+ / @ c h a r s e t (?: \s * (?: " (?: [ ^ " ] | (?< = \\ ) " ) * " | ' (?: [ ^ ' ] | (?< = \\ ) ' ) * ' ) . * ? | [ ^ ; ] * ) ; / g
1405
1407
let foundCharset = false
1406
1408
while ( ( match = atCharsetRE . exec ( cleanCss ) ) ) {
1407
1409
s . remove ( match . index , match . index + match [ 0 ] . length )
0 commit comments