@@ -6,7 +6,7 @@ use swc_config::merge::Merge;
6
6
use swc_core:: common:: comments:: Comments ;
7
7
use swc_core:: common:: iter:: IdentifyLast ;
8
8
use swc_core:: common:: util:: take:: Take ;
9
- use swc_core:: common:: { FileName , Mark , SourceMap , Span , Spanned , DUMMY_SP } ;
9
+ use swc_core:: common:: { FileName , Mark , SourceMap , Span , Spanned , DUMMY_SP , SyntaxContext } ;
10
10
use swc_core:: ecma:: ast:: * ;
11
11
use swc_core:: ecma:: atoms:: { Atom , JsWord } ;
12
12
use swc_core:: ecma:: utils:: { drop_span, prepend_stmt, quote_ident, ExprFactory , StmtLike } ;
@@ -53,7 +53,10 @@ pub fn parse_expr_for_jsx(
53
53
src : String ,
54
54
top_level_mark : Mark ,
55
55
) -> Arc < Box < Expr > > {
56
- let fm = cm. new_source_file ( FileName :: Custom ( format ! ( "<jsx-config-{}.js>" , name) ) , src) ;
56
+ let fm = cm. new_source_file (
57
+ FileName :: Custom ( format ! ( "<jsx-config-{}.js>" , name) ) . into ( ) ,
58
+ src
59
+ ) ;
57
60
58
61
parse_file_as_expr (
59
62
& fm,
@@ -86,7 +89,7 @@ pub fn parse_expr_for_jsx(
86
89
fn apply_mark ( e : & mut Expr , mark : Mark ) {
87
90
match e {
88
91
Expr :: Ident ( i) => {
89
- i. span = i. span . apply_mark ( mark) ;
92
+ i. ctxt = i. ctxt . apply_mark ( mark) ;
90
93
}
91
94
Expr :: Member ( MemberExpr { obj, .. } ) => {
92
95
apply_mark ( obj, mark) ;
@@ -138,7 +141,7 @@ fn merge_imports(
138
141
. specifiers
139
142
. push ( ImportSpecifier :: Named ( ImportNamedSpecifier {
140
143
span : DUMMY_SP ,
141
- local : quote_ident ! ( * import_to_add) ,
144
+ local : quote_ident ! ( * import_to_add) . into ( ) ,
142
145
imported : None ,
143
146
is_type_only : false ,
144
147
} ) )
@@ -285,7 +288,7 @@ where
285
288
286
289
let fragment = self
287
290
. import_create_fragment
288
- . get_or_insert_with ( || quote_ident ! ( "createFragment" ) )
291
+ . get_or_insert_with ( || quote_ident ! ( "createFragment" ) . into ( ) )
289
292
. clone ( ) ;
290
293
291
294
let mut children_requires_normalization: bool = false ;
@@ -314,11 +317,11 @@ where
314
317
span : DUMMY_SP ,
315
318
callee : self
316
319
. import_create_text_vnode
317
- . get_or_insert_with ( || quote_ident ! ( "createTextVNode" ) )
320
+ . get_or_insert_with ( || quote_ident ! ( "createTextVNode" ) . into ( ) )
318
321
. clone ( )
319
322
. as_callee ( ) ,
320
323
args : vec ! [ s. as_arg( ) ] ,
321
- type_args : Default :: default ( ) ,
324
+ .. Default :: default ( )
322
325
} ) ) ,
323
326
}
324
327
}
@@ -376,6 +379,7 @@ where
376
379
callee : fragment. as_callee ( ) ,
377
380
args : create_fragment_vnode_args ( children, false , child_flags as u16 , None , None ) ,
378
381
type_args : None ,
382
+ ..Default :: default ( )
379
383
} )
380
384
}
381
385
@@ -399,7 +403,7 @@ where
399
403
if ident. sym == "Fragment" {
400
404
vnode_kind = VNodeType :: Fragment ;
401
405
mut_flags = VNodeFlags :: ComponentUnknown as u16 ;
402
- name_expr = Expr :: Ident ( Ident :: new ( "createFragment" . into ( ) , ident. span ) ) ;
406
+ name_expr = Expr :: Ident ( Ident :: new ( "createFragment" . into ( ) , ident. span . into ( ) , Default :: default ( ) ) ) ;
403
407
} else {
404
408
vnode_kind = Component ;
405
409
mut_flags = VNodeFlags :: ComponentUnknown as u16 ;
@@ -424,7 +428,7 @@ where
424
428
425
429
return Expr :: Invalid ( Invalid { span : DUMMY_SP } ) ;
426
430
}
427
- JSXElementName :: JSXMemberExpr ( JSXMemberExpr { obj, prop } ) => {
431
+ JSXElementName :: JSXMemberExpr ( JSXMemberExpr { obj, prop, .. } ) => {
428
432
vnode_kind = Component ;
429
433
mut_flags = VNodeFlags :: ComponentUnknown as u16 ;
430
434
@@ -520,9 +524,9 @@ where
520
524
. props
521
525
. push ( PropOrSpread :: Prop ( Box :: new ( Prop :: KeyValue (
522
526
KeyValueProp {
523
- key : PropName :: Ident ( Ident :: new (
527
+ key : PropName :: Ident ( IdentName :: new (
524
528
"onDblClick" . into ( ) ,
525
- span,
529
+ span
526
530
) ) ,
527
531
value : match attr. value {
528
532
Some ( v) => jsx_attr_value_to_expr ( v)
@@ -688,10 +692,9 @@ where
688
692
value : converted_sym. into ( ) ,
689
693
} )
690
694
} else {
691
- PropName :: Ident ( Ident {
695
+ PropName :: Ident ( IdentName {
692
696
span : i. span ,
693
- sym : converted_sym. into ( ) ,
694
- optional : i. optional ,
697
+ sym : converted_sym. into ( )
695
698
} )
696
699
} ;
697
700
@@ -702,7 +705,7 @@ where
702
705
value,
703
706
} ) ) ) ) ;
704
707
}
705
- JSXAttrName :: JSXNamespacedName ( JSXNamespacedName { ns, name } ) => {
708
+ JSXAttrName :: JSXNamespacedName ( JSXNamespacedName { ns, name, .. } ) => {
706
709
let value = match attr. value {
707
710
Some ( v) => {
708
711
jsx_attr_value_to_expr ( v) . expect ( "empty expression container?" )
@@ -767,9 +770,10 @@ where
767
770
spread : None ,
768
771
expr : Box :: new ( Expr :: Call ( CallExpr {
769
772
span : DUMMY_SP ,
773
+ ctxt : SyntaxContext :: empty ( ) . apply_mark ( self . unresolved_mark ) ,
770
774
callee : self
771
775
. import_create_text_vnode
772
- . get_or_insert_with ( || quote_ident ! ( "createTextVNode" ) )
776
+ . get_or_insert_with ( || quote_ident ! ( "createTextVNode" ) . into ( ) )
773
777
. clone ( )
774
778
. as_callee ( ) ,
775
779
args : vec ! [ s. as_arg( ) ] ,
@@ -832,10 +836,11 @@ where
832
836
spread : None ,
833
837
expr : Box :: new ( Expr :: Call ( CallExpr {
834
838
span : DUMMY_SP ,
839
+ ctxt : SyntaxContext :: empty ( ) . apply_mark ( self . unresolved_mark ) ,
835
840
callee : self
836
841
. import_create_text_vnode
837
842
. get_or_insert_with ( || {
838
- quote_ident ! ( "createTextVNode" )
843
+ quote_ident ! ( "createTextVNode" ) . into ( )
839
844
} )
840
845
. clone ( )
841
846
. as_callee ( ) ,
@@ -963,15 +968,15 @@ where
963
968
964
969
let create_method = if vnode_kind == Component {
965
970
self . import_create_component
966
- . get_or_insert_with ( || quote_ident ! ( "createComponentVNode" ) )
971
+ . get_or_insert_with ( || quote_ident ! ( "createComponentVNode" ) . into ( ) )
967
972
. clone ( )
968
973
} else if vnode_kind == VNodeType :: Element {
969
974
self . import_create_vnode
970
- . get_or_insert_with ( || quote_ident ! ( "createVNode" ) )
975
+ . get_or_insert_with ( || quote_ident ! ( "createVNode" ) . into ( ) )
971
976
. clone ( )
972
977
} else {
973
978
self . import_create_fragment
974
- . get_or_insert_with ( || quote_ident ! ( "createFragment" ) )
979
+ . get_or_insert_with ( || quote_ident ! ( "createFragment" ) . into ( ) )
975
980
. clone ( )
976
981
} ;
977
982
@@ -1016,6 +1021,7 @@ where
1016
1021
1017
1022
let create_expr = Expr :: Call ( CallExpr {
1018
1023
span,
1024
+ ctxt : SyntaxContext :: empty ( ) . apply_mark ( self . unresolved_mark ) ,
1019
1025
callee : create_method. as_callee ( ) ,
1020
1026
args : create_method_args,
1021
1027
type_args : Default :: default ( ) ,
@@ -1024,9 +1030,10 @@ where
1024
1030
if needs_normalization {
1025
1031
return Expr :: Call ( CallExpr {
1026
1032
span,
1033
+ ctxt : SyntaxContext :: empty ( ) . apply_mark ( self . unresolved_mark ) ,
1027
1034
callee : self
1028
1035
. import_normalize_props
1029
- . get_or_insert_with ( || quote_ident ! ( "normalizeProps" ) )
1036
+ . get_or_insert_with ( || quote_ident ! ( "normalizeProps" ) . into ( ) )
1030
1037
. clone ( )
1031
1038
. as_callee ( ) ,
1032
1039
args : vec ! [ create_expr. as_arg( ) ] ,
@@ -1354,7 +1361,7 @@ where
1354
1361
. map ( |imported| {
1355
1362
ImportSpecifier :: Named ( ImportNamedSpecifier {
1356
1363
span : DUMMY_SP ,
1357
- local : quote_ident ! ( imported) ,
1364
+ local : quote_ident ! ( imported) . into ( ) ,
1358
1365
imported : None ,
1359
1366
is_type_only : false ,
1360
1367
} )
@@ -1393,6 +1400,7 @@ where
1393
1400
fn add_require ( imports : Vec < & str > , src : & str , unresolved_mark : Mark ) -> Stmt {
1394
1401
Stmt :: Decl ( Decl :: Var ( Box :: new ( VarDecl {
1395
1402
span : DUMMY_SP ,
1403
+ ctxt : SyntaxContext :: empty ( ) . apply_mark ( unresolved_mark) ,
1396
1404
kind : VarDeclKind :: Const ,
1397
1405
declare : false ,
1398
1406
decls : vec ! [ VarDeclarator {
@@ -1407,6 +1415,7 @@ fn add_require(imports: Vec<&str>, src: &str, unresolved_mark: Mark) -> Stmt {
1407
1415
key: BindingIdent {
1408
1416
id: Ident {
1409
1417
span: DUMMY_SP ,
1418
+ ctxt: SyntaxContext :: empty( ) . apply_mark( unresolved_mark) ,
1410
1419
sym: imported. into( ) ,
1411
1420
optional: false ,
1412
1421
} ,
@@ -1422,10 +1431,12 @@ fn add_require(imports: Vec<&str>, src: &str, unresolved_mark: Mark) -> Stmt {
1422
1431
// require('inferno')
1423
1432
init: Some ( Box :: new( Expr :: Call ( CallExpr {
1424
1433
span: DUMMY_SP ,
1434
+ ctxt: SyntaxContext :: empty( ) . apply_mark( unresolved_mark) ,
1425
1435
callee: Callee :: Expr ( Box :: new( Expr :: Ident ( Ident {
1426
- span : DUMMY_SP . apply_mark( unresolved_mark) ,
1436
+ ctxt : SyntaxContext :: empty ( ) . apply_mark( unresolved_mark) ,
1427
1437
sym: "require" . into( ) ,
1428
1438
optional: false ,
1439
+ ..Default :: default ( )
1429
1440
} ) ) ) ,
1430
1441
args: vec![ ExprOrSpread {
1431
1442
spread: None ,
0 commit comments