@@ -118,7 +118,7 @@ pub fn parse_expr_for_jsx(
118
118
src : String ,
119
119
top_level_mark : Mark ,
120
120
) -> Arc < Box < Expr > > {
121
- let fm = cm. new_source_file ( FileName :: Internal ( format ! ( "< jsx-config-{}.js> " , name) ) , src) ;
121
+ let fm = cm. new_source_file ( FileName :: Internal ( format ! ( "jsx-config-{}.js" , name) ) , src) ;
122
122
123
123
parse_file_as_expr (
124
124
& fm,
@@ -131,7 +131,7 @@ pub fn parse_expr_for_jsx(
131
131
if HANDLER . is_set ( ) {
132
132
HANDLER . with ( |h| {
133
133
e. into_diagnostic ( h)
134
- . note ( "error detected while parsing option for classic jsx transform " )
134
+ . note ( "Failed to parse jsx pragma " )
135
135
. emit ( )
136
136
} )
137
137
}
@@ -339,30 +339,34 @@ impl JsxDirectives {
339
339
}
340
340
Some ( "@jsxFrag" ) => {
341
341
if let Some ( src) = val {
342
- // TODO: Optimize
343
- let mut e = ( * parse_expr_for_jsx (
344
- cm,
345
- "module-jsx-pragma-frag" ,
346
- src. to_string ( ) ,
347
- top_level_mark,
348
- ) )
349
- . clone ( ) ;
350
- respan ( & mut e, cmt. span ) ;
351
- res. pragma_frag = Some ( e. into ( ) )
342
+ if is_valid_for_pragma ( src) {
343
+ // TODO: Optimize
344
+ let mut e = ( * parse_expr_for_jsx (
345
+ cm,
346
+ "module-jsx-pragma-frag" ,
347
+ src. to_string ( ) ,
348
+ top_level_mark,
349
+ ) )
350
+ . clone ( ) ;
351
+ respan ( & mut e, cmt. span ) ;
352
+ res. pragma_frag = Some ( e. into ( ) )
353
+ }
352
354
}
353
355
}
354
356
Some ( "@jsx" ) => {
355
357
if let Some ( src) = val {
356
- // TODO: Optimize
357
- let mut e = ( * parse_expr_for_jsx (
358
- cm,
359
- "module-jsx-pragma" ,
360
- src. to_string ( ) ,
361
- top_level_mark,
362
- ) )
363
- . clone ( ) ;
364
- respan ( & mut e, cmt. span ) ;
365
- res. pragma = Some ( e. into ( ) ) ;
358
+ if is_valid_for_pragma ( src) {
359
+ // TODO: Optimize
360
+ let mut e = ( * parse_expr_for_jsx (
361
+ cm,
362
+ "module-jsx-pragma" ,
363
+ src. to_string ( ) ,
364
+ top_level_mark,
365
+ ) )
366
+ . clone ( ) ;
367
+ respan ( & mut e, cmt. span ) ;
368
+ res. pragma = Some ( e. into ( ) ) ;
369
+ }
366
370
}
367
371
}
368
372
_ => { }
@@ -375,6 +379,24 @@ impl JsxDirectives {
375
379
}
376
380
}
377
381
382
+ fn is_valid_for_pragma ( s : & str ) -> bool {
383
+ if s. is_empty ( ) {
384
+ return false ;
385
+ }
386
+
387
+ if !s. starts_with ( |c : char | Ident :: is_valid_start ( c) ) {
388
+ return false ;
389
+ }
390
+
391
+ for c in s. chars ( ) {
392
+ if !Ident :: is_valid_continue ( c) && c != '.' {
393
+ return false ;
394
+ }
395
+ }
396
+
397
+ true
398
+ }
399
+
378
400
impl < C > Jsx < C >
379
401
where
380
402
C : Comments ,
0 commit comments