@@ -28,6 +28,7 @@ import (
2828 "github.com/evanw/esbuild/internal/compat"
2929 "github.com/evanw/esbuild/internal/config"
3030 "github.com/evanw/esbuild/internal/css_ast"
31+ "github.com/evanw/esbuild/internal/css_lexer"
3132 "github.com/evanw/esbuild/internal/fs"
3233 "github.com/evanw/esbuild/internal/graph"
3334 "github.com/evanw/esbuild/internal/helpers"
@@ -524,6 +525,23 @@ func validateJSXExpr(log logger.Log, text string, name string) config.DefineExpr
524525 return config.DefineExpr {}
525526}
526527
528+ func validateCSSIdentifier (log logger.Log , ident string ) string {
529+ for i , c := range ident {
530+ if i == 0 {
531+ if ! css_lexer .IsNameStart (c ) {
532+ log .AddError (nil , logger.Range {}, fmt .Sprintf ("Invalid CSS prefix: %q" , ident ))
533+ return ""
534+ }
535+ } else {
536+ if ! css_lexer .IsNameContinue (c ) {
537+ log .AddError (nil , logger.Range {}, fmt .Sprintf ("Invalid CSS prefix: %q" , ident ))
538+ return ""
539+ }
540+ }
541+ }
542+ return ident
543+ }
544+
527545func validateDefines (
528546 log logger.Log ,
529547 defines map [string ]string ,
@@ -1257,6 +1275,7 @@ func validateBuildOptions(
12571275 MangleProps : validateRegex (log , "mangle props" , buildOpts .MangleProps ),
12581276 ReserveProps : validateRegex (log , "reserve props" , buildOpts .ReserveProps ),
12591277 MangleQuoted : buildOpts .MangleQuoted == MangleQuotedTrue ,
1278+ LocalCSSPrefix : validateCSSIdentifier (log , buildOpts .LocalCSSPrefix ),
12601279 DropLabels : append ([]string {}, buildOpts .DropLabels ... ),
12611280 DropDebugger : (buildOpts .Drop & DropDebugger ) != 0 ,
12621281 AllowOverwrite : buildOpts .AllowOverwrite ,
0 commit comments