@@ -1288,8 +1288,6 @@ export async function preprocessCSS(
1288
1288
return await compileCSS ( filename , code , config )
1289
1289
}
1290
1290
1291
- const postcssReturnsVirtualFilesRE = / ^ < .+ > $ /
1292
-
1293
1291
export async function formatPostcssSourceMap (
1294
1292
rawMap : ExistingRawSourceMap ,
1295
1293
file : string ,
@@ -1299,7 +1297,8 @@ export async function formatPostcssSourceMap(
1299
1297
const sources = rawMap . sources . map ( ( source ) => {
1300
1298
const cleanSource = cleanUrl ( decodeURIComponent ( source ) )
1301
1299
1302
- if ( postcssReturnsVirtualFilesRE . test ( cleanSource ) ) {
1300
+ // postcss virtual files
1301
+ if ( cleanSource [ 0 ] === '<' && cleanSource [ cleanSource . length - 1 ] === '>' ) {
1303
1302
return `\0${ cleanSource } `
1304
1303
}
1305
1304
@@ -1373,7 +1372,7 @@ async function resolvePostcssConfig(
1373
1372
const searchPath =
1374
1373
typeof inlineOptions === 'string' ? inlineOptions : config . root
1375
1374
result = postcssrc ( { } , searchPath ) . catch ( ( e ) => {
1376
- if ( ! / N o P o s t C S S C o n f i g f o u n d / . test ( e . message ) ) {
1375
+ if ( ! e . message . includes ( ' No PostCSS Config found' ) ) {
1377
1376
if ( e instanceof Error ) {
1378
1377
const { name, message, stack } = e
1379
1378
e . name = 'Failed to load PostCSS config'
@@ -1654,6 +1653,11 @@ function resolveMinifyCssEsbuildOptions(
1654
1653
}
1655
1654
}
1656
1655
1656
+ const atImportRE =
1657
+ / @ i m p o r t (?: \s * (?: u r l \( [ ^ ) ] * \) | " (?: [ ^ " ] | (?< = \\ ) " ) * " | ' (?: [ ^ ' ] | (?< = \\ ) ' ) * ' ) .* ?| [ ^ ; ] * ) ; / g
1658
+ const atCharsetRE =
1659
+ / @ c h a r s e t (?: \s * (?: " (?: [ ^ " ] | (?< = \\ ) " ) * " | ' (?: [ ^ ' ] | (?< = \\ ) ' ) * ' ) .* ?| [ ^ ; ] * ) ; / g
1660
+
1657
1661
export async function hoistAtRules ( css : string ) : Promise < string > {
1658
1662
const s = new MagicString ( css )
1659
1663
const cleanCss = emptyCssComments ( css )
@@ -1663,8 +1667,7 @@ export async function hoistAtRules(css: string): Promise<string> {
1663
1667
// CSS @import can only appear at top of the file. We need to hoist all @import
1664
1668
// to top when multiple files are concatenated.
1665
1669
// match until semicolon that's not in quotes
1666
- const atImportRE =
1667
- / @ i m p o r t (?: \s * (?: u r l \( [ ^ ) ] * \) | " (?: [ ^ " ] | (?< = \\ ) " ) * " | ' (?: [ ^ ' ] | (?< = \\ ) ' ) * ' ) .* ?| [ ^ ; ] * ) ; / g
1670
+ atImportRE . lastIndex = 0
1668
1671
while ( ( match = atImportRE . exec ( cleanCss ) ) ) {
1669
1672
s . remove ( match . index , match . index + match [ 0 ] . length )
1670
1673
// Use `appendLeft` instead of `prepend` to preserve original @import order
@@ -1673,8 +1676,7 @@ export async function hoistAtRules(css: string): Promise<string> {
1673
1676
1674
1677
// #6333
1675
1678
// CSS @charset must be the top-first in the file, hoist the first to top
1676
- const atCharsetRE =
1677
- / @ c h a r s e t (?: \s * (?: " (?: [ ^ " ] | (?< = \\ ) " ) * " | ' (?: [ ^ ' ] | (?< = \\ ) ' ) * ' ) .* ?| [ ^ ; ] * ) ; / g
1679
+ atCharsetRE . lastIndex = 0
1678
1680
let foundCharset = false
1679
1681
while ( ( match = atCharsetRE . exec ( cleanCss ) ) ) {
1680
1682
s . remove ( match . index , match . index + match [ 0 ] . length )
@@ -2406,8 +2408,8 @@ export const convertTargets = (
2406
2408
2407
2409
for ( const entry of entriesWithoutES ) {
2408
2410
if ( entry === 'esnext' ) continue
2409
- const index = entry . match ( versionRE ) ?. index
2410
- if ( index ) {
2411
+ const index = entry . search ( versionRE )
2412
+ if ( index >= 0 ) {
2411
2413
const browser = map [ entry . slice ( 0 , index ) ]
2412
2414
if ( browser === false ) continue // No mapping available
2413
2415
if ( browser ) {
0 commit comments