@@ -2131,18 +2131,14 @@ async function minifyCSS(
2131
2131
code : Buffer . from ( css ) ,
2132
2132
minify : true ,
2133
2133
} )
2134
- if ( warnings . length ) {
2135
- const messages = warnings . map (
2136
- ( warning ) =>
2137
- `${ warning . message } \n` +
2138
- generateCodeFrame ( css , {
2139
- line : warning . loc . line ,
2140
- column : warning . loc . column - 1 , // 1-based
2141
- } ) ,
2142
- )
2143
- config . logger . warn (
2144
- colors . yellow ( `warnings when minifying css:\n${ messages . join ( '\n' ) } ` ) ,
2145
- )
2134
+
2135
+ for ( const warning of warnings ) {
2136
+ let msg = `[lightningcss minify] ${ warning . message } `
2137
+ msg += `\n${ generateCodeFrame ( css , {
2138
+ line : warning . loc . line ,
2139
+ column : warning . loc . column - 1 , // 1-based
2140
+ } ) } `
2141
+ config . logger . warn ( colors . yellow ( msg ) )
2146
2142
}
2147
2143
2148
2144
// NodeJS res.code = Buffer
@@ -2152,6 +2148,11 @@ async function minifyCSS(
2152
2148
return decoder . decode ( code ) + ( inlined ? '' : '\n' )
2153
2149
} catch ( e ) {
2154
2150
e . message = `[lightningcss minify] ${ e . message } `
2151
+ const friendlyMessage = getLightningCssErrorMessageForIeSyntaxes ( css )
2152
+ if ( friendlyMessage ) {
2153
+ e . message += friendlyMessage
2154
+ }
2155
+
2155
2156
if ( e . loc ) {
2156
2157
e . loc = {
2157
2158
line : e . loc . line ,
@@ -2171,7 +2172,7 @@ async function minifyCSS(
2171
2172
if ( warnings . length ) {
2172
2173
const msgs = await formatMessages ( warnings , { kind : 'warning' } )
2173
2174
config . logger . warn (
2174
- colors . yellow ( `warnings when minifying css: \n${ msgs . join ( '\n' ) } ` ) ,
2175
+ colors . yellow ( `[esbuild css minify] \n${ msgs . join ( '\n' ) } ` ) ,
2175
2176
)
2176
2177
}
2177
2178
// esbuild output does return a linebreak at the end
@@ -3503,23 +3504,11 @@ async function compileLightningCSS(
3503
3504
line : e . loc . line ,
3504
3505
column : e . loc . column - 1 , // 1-based
3505
3506
}
3506
- // add friendly error for https://github.com/parcel-bundler/lightningcss/issues/39
3507
3507
try {
3508
3508
const code = fs . readFileSync ( e . fileName , 'utf-8' )
3509
- const commonIeMessage =
3510
- ', which was used in the past to support old Internet Explorer versions.' +
3511
- ' This is not a valid CSS syntax and will be ignored by modern browsers. ' +
3512
- '\nWhile this is not supported by LightningCSS, you can set `css.lightningcss.errorRecovery: true` to strip these codes.'
3513
- if ( / [ \s ; { ] \* [ a - z A - Z - ] [ \w - ] + \s * : / . test ( code ) ) {
3514
- // https://stackoverflow.com/a/1667560
3515
- e . message +=
3516
- '.\nThis file contains star property hack (e.g. `*zoom`)' +
3517
- commonIeMessage
3518
- } else if ( / m i n - w i d t h : \s * 0 \\ 0 / . test ( code ) ) {
3519
- // https://stackoverflow.com/a/14585820
3520
- e . message +=
3521
- '.\nThis file contains @media zero hack (e.g. `@media (min-width: 0\\0)`)' +
3522
- commonIeMessage
3509
+ const friendlyMessage = getLightningCssErrorMessageForIeSyntaxes ( code )
3510
+ if ( friendlyMessage ) {
3511
+ e . message += friendlyMessage
3523
3512
}
3524
3513
} catch { }
3525
3514
}
@@ -3596,6 +3585,31 @@ async function compileLightningCSS(
3596
3585
}
3597
3586
}
3598
3587
3588
+ // friendly error for https://github.com/parcel-bundler/lightningcss/issues/39
3589
+ function getLightningCssErrorMessageForIeSyntaxes (
3590
+ code : string ,
3591
+ ) : string | undefined {
3592
+ const commonIeMessage =
3593
+ ', which was used in the past to support old Internet Explorer versions.' +
3594
+ ' This is not a valid CSS syntax and will be ignored by modern browsers. ' +
3595
+ '\nWhile this is not supported by LightningCSS, you can set `css.lightningcss.errorRecovery: true` to strip these codes.'
3596
+ if ( / [ \s ; { ] \* [ a - z A - Z - ] [ \w - ] + \s * : / . test ( code ) ) {
3597
+ // https://stackoverflow.com/a/1667560
3598
+ return (
3599
+ '.\nThis file contains star property hack (e.g. `*zoom`)' +
3600
+ commonIeMessage
3601
+ )
3602
+ }
3603
+ if ( / m i n - w i d t h : \s * 0 \\ 0 / . test ( code ) ) {
3604
+ // https://stackoverflow.com/a/14585820
3605
+ return (
3606
+ '.\nThis file contains @media zero hack (e.g. `@media (min-width: 0\\0)`)' +
3607
+ commonIeMessage
3608
+ )
3609
+ }
3610
+ return undefined
3611
+ }
3612
+
3599
3613
// Convert https://esbuild.github.io/api/#target
3600
3614
// To https://github.com/parcel-bundler/lightningcss/blob/master/node/targets.d.ts
3601
3615
0 commit comments