File tree 2 files changed +44
-2
lines changed
crates/swc_ecma_transforms_react/src/refresh
2 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -249,6 +249,12 @@ where
249
249
} ) ;
250
250
}
251
251
252
+ comments. with_leading ( n. lo , |comments| {
253
+ if comments. iter ( ) . any ( |c| c. text . contains ( "@refresh reset" ) ) {
254
+ should_refresh = true
255
+ }
256
+ } ) ;
257
+
252
258
comments. with_trailing ( n. lo , |comments| {
253
259
if comments. iter ( ) . any ( |c| c. text . contains ( "@refresh reset" ) ) {
254
260
should_refresh = true
@@ -265,14 +271,18 @@ impl<C: Comments> VisitMut for Refresh<C> {
265
271
// Does anyone write react without esmodule?
266
272
// fn visit_mut_script(&mut self, _: &mut Script) {}
267
273
268
- fn visit_mut_module_items ( & mut self , module_items : & mut Vec < ModuleItem > ) {
274
+ fn visit_mut_module ( & mut self , n : & mut Module ) {
269
275
if !self . enable {
270
276
return ;
271
277
}
272
278
273
279
// to collect comments
274
- self . visit_module_items ( module_items) ;
280
+ self . visit_module ( n) ;
281
+
282
+ self . visit_mut_module_items ( & mut n. body ) ;
283
+ }
275
284
285
+ fn visit_mut_module_items ( & mut self , module_items : & mut Vec < ModuleItem > ) {
276
286
let used_in_jsx = collect_ident_in_jsx ( module_items) ;
277
287
278
288
let mut items = Vec :: with_capacity ( module_items. len ( ) ) ;
Original file line number Diff line number Diff line change @@ -1535,3 +1535,35 @@ const a = (a)=>{
1535
1535
}
1536
1536
"#
1537
1537
) ;
1538
+
1539
+ test ! (
1540
+ :: swc_ecma_parser:: Syntax :: Es ( :: swc_ecma_parser:: EsConfig {
1541
+ jsx: true ,
1542
+ ..Default :: default ( )
1543
+ } ) ,
1544
+ tr,
1545
+ issue_6022,
1546
+ r#"/* @refresh reset */
1547
+ import { useState } from 'react';
1548
+
1549
+ function Counter() {
1550
+ const [count, setCount] = useState(0);
1551
+
1552
+ return (
1553
+ <button type="button" onClick={() => setCount(c => c + 1)}>{count}</button>
1554
+ );
1555
+ }
1556
+ "# ,
1557
+ r#"var _s = $RefreshSig$();
1558
+ import { useState } from 'react';
1559
+ function Counter() {
1560
+ _s();
1561
+ const [count, setCount] = useState(0);
1562
+ return <button type="button" onClick={()=>setCount((c)=>c + 1)}>{count}</button>;
1563
+ }
1564
+ _s(Counter, "useState{[count, setCount](0)}", true);
1565
+ _c = Counter;
1566
+ var _c;
1567
+ $RefreshReg$(_c, "Counter");
1568
+ "#
1569
+ ) ;
You can’t perform that action at this time.
0 commit comments