[compiler] Treat zero-argument new Date() as impure during render (…
Commit ff8f88f [compiler] Treat zero-argument ## Summary react-hooks/purity already reports Date.now() during render, but not new Date() / new Date().getTime() / new Date().getFullYear(). Those also read the current clock. React's purity docs list new Date() next to Date.now(). Zero-argument new Date() is now treated as an impure call (same diagnostic as Date.now()). Constructing from an explicit timestamp stays allowed: new Date(timestamp). Fixes #37553 ## How did you test this change? - yarn snap --pattern "**/*new-date*" (4 fixtures passed) - yarn workspace eslint-plugin-react-compiler test -- ImpureFunctionCallsRule (4 tests passed) Made with Cursor --------- Co-authored-by: Pieter De Baets new Date() as impure during render (#37576)1 parent 6e9c55c commit ff8f88f 16 files changed Lines changed: 364 additions & 19 deletions File tree - compiler - crates - react_compiler_hir/src - react_compiler_inference/src - packages - babel-plugin-react-compiler/src - HIR - Inference - tests/fixtures/compiler - new-mutability - eslint-plugin-react-compiler/tests | Original file line number | Diff line number | Diff line change | | |---|---|---|---| | ||| 2188 | 2188 | | | 2189 | 2189 | | | 2190 | 2190 | | | 2191 | | - | | | 2191 | + | | | 2192 | + | | | 2193 | + | | 2192 | 2194 | | | 2193 | 2195 | | | 2194 | 2196 | | | | ||| 2203 | 2205 | | | 2204 | 2206 | | | 2205 | 2207 | | | 2206 | | - | | | 2208 | + | | | 2209 | + | | | 2210 | + | | | 2211 | + | | | 2212 | + | | | 2213 | + | | | 2214 | + | | | 2215 | + | | | 2216 | + | | | 2217 | + | | | 2218 | + | | | 2219 | + | | | 2220 | + | | | 2221 | + | | | 2222 | + | | 2207 | 2223 | | | 2208 | 2224 | | | 2209 | 2225 | | | | | Original file line number | Diff line number | Diff line change | | |---|---|---|---| | ||| 108 | 108 | | | 109 | 109 | | | 110 | 110 | | | | 111 | + | | | 112 | + | | | 113 | + | | 111 | 114 | | | 112 | 115 | | | 113 | 116 | | | | ||| 226 | 229 | | | 227 | 230 | | | 228 | 231 | | | | 232 | + | | 229 | 233 | | | 230 | 234 | | | 231 | 235 | | | | ||| 258 | 262 | | | 259 | 263 | | | 260 | 264 | | | | 265 | + | | 261 | 266 | | | 262 | 267 | | | 263 | 268 | | | | ||| 315 | 320 | | | 316 | 321 | | | 317 | 322 | | | | 323 | + | | 318 | 324 | | | 319 | 325 | | | 320 | 326 | | | | ||| 332 | 338 | | | 333 | 339 | | | 334 | 340 | | | | 341 | + | | 335 | 342 | | | 336 | 343 | | | 337 | 344 | | | | Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change | | |---|---|---|---| | ||| 2767 | 2767 | | | 2768 | 2768 | | | 2769 | 2769 | | | 2770 | | - | | | 2770 | + | | | 2771 | + | | | 2772 | + | | | 2773 | + | | 2771 | 2774 | | | 2772 | 2775 | | | 2773 | 2776 | | | | Lines changed: 32 additions & 14 deletions | Original file line number | Diff line number | Diff line change | | |---|---|---|---| | ||| 280 | 280 | | | 281 | 281 | | | 282 | 282 | | | 283 | | - | | 284 | | - | | | 283 | + | | | 284 | + | | 285 | 285 | | | 286 | | - | | 287 | | - | | 288 | | - | | 289 | | - | | 290 | | - | | 291 | | - | | 292 | | - | | 293 | | - | | 294 | | - | | 295 | | - | | 296 | | - | | | 286 | + | | | 287 | + | | | 288 | + | | | 289 | + | | | 290 | + | | | 291 | + | | | 292 | + | | | 293 | + | | | 294 | + | | | 295 | + | | | 296 | + | | | 297 | + | | | 298 | + | | | 299 | + | | 297 | 300 | | | 298 | | - | | | 301 | + | | | 302 | + | | | 303 | + | | | 304 | + | | | 305 | + | | | 306 | + | | | 307 | + | | | 308 | + | | | 309 | + | | | 310 | + | | | 311 | + | | | 312 | + | | | 313 | + | | | 314 | + | | | 315 | + | | | 316 | + | | 299 | 317 | | | 300 | 318 | | | 301 | 319 | | | | Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change | | |---|---|---|---| | ||| 331 | 331 | | | 332 | 332 | | | 333 | 333 | | | | 334 | + | | | 335 | + | | | 336 | + | | | 337 | + | | | 338 | + | | 334 | 339 | | | 335 | 340 | | | 336 | 341 | | | | Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change | | |---|---|---|---| | ||| 2340 | 2340 | | | 2341 | 2341 | | | 2342 | 2342 | | | 2343 | | - | | | 2343 | + | | | 2344 | + | | | 2345 | + | | | 2346 | + | | | 2347 | + | | 2344 | 2348 | | | 2345 | 2349 | | | 2346 | 2350 | | | | Lines changed: 62 additions & 0 deletions | Original file line number | Diff line number | Diff line change | | |---|---|---|---| | ||| | 1 | + | | | 2 | + | | | 3 | + | | | 4 | + | | | 5 | + | | | 6 | + | | | 7 | + | | | 8 | + | | | 9 | + | | | 10 | + | | | 11 | + | | | 12 | + | | | 13 | + | | | 14 | + | | | 15 | + | | | 16 | + | | | 17 | + | | | 18 | + | | | 19 | + | | | 20 | + | | | 21 | + | | | 22 | + | | | 23 | + | | | 24 | + | | | 25 | + | | | 26 | + | | | 27 | + | | | 28 | + | | | 29 | + | | | 30 | + | | | 31 | + | | | 32 | + | | | 33 | + | | | 34 | + | | | 35 | + | | | 36 | + | | | 37 | + | | | 38 | + | | | 39 | + | | | 40 | + | | | 41 | + | | | 42 | + | | | 43 | + | | | 44 | + | | | 45 | + | | | 46 | + | | | 47 | + | | | 48 | + | | | 49 | + | | | 50 | + | | | 51 | + | | | 52 | + | | | 53 | + | | | 54 | + | | | 55 | + | | | 56 | + | | | 57 | + | | | 58 | + | | | 59 | + | | | 60 | + | | | 61 | + | | | 62 | + | Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change | | |---|---|---|---| | ||| | 1 | + | | | 2 | + | | | 3 | + | | | 4 | + | | | 5 | + | | | 6 | + | | | 7 | + | | | 8 | + | Lines changed: 62 additions & 0 deletions | Original file line number | Diff line number | Diff line change | | |---|---|---|---| | ||| | 1 | + | | | 2 | + | | | 3 | + | | | 4 | + | | | 5 | + | | | 6 | + | | | 7 | + | | | 8 | + | | | 9 | + | | | 10 | + | | | 11 | + | | | 12 | + | | | 13 | + | | | 14 | + | | | 15 | + | | | 16 | + | | | 17 | + | | | 18 | + | | | 19 | + | | | 20 | + | | | 21 | + | | | 22 | + | | | 23 | + | | | 24 | + | | | 25 | + | | | 26 | + | | | 27 | + | | | 28 | + | | | 29 | + | | | 30 | + | | | 31 | + | | | 32 | + | | | 33 | + | | | 34 | + | | | 35 | + | | | 36 | + | | | 37 | + | | | 38 | + | | | 39 | + | | | 40 | + | | | 41 | + | | | 42 | + | | | 43 | + | | | 44 | + | | | 45 | + | | | 46 | + | | | 47 | + | | | 48 | + | | | 49 | + | | | 50 | + | | | 51 | + | | | 52 | + | | | 53 | + | | | 54 | + | | | 55 | + | | | 56 | + | | | 57 | + | | | 58 | + | | | 59 | + | | | 60 | + | | | 61 | + | | | 62 | + | Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change | | |---|---|---|---| | ||| | 1 | + | | | 2 | + | | | 3 | + | | | 4 | + | | | 5 | + | | | 6 | + | | | 7 | + | | | 8 | + | 0 commit comments
Comments
No comments yet. Start the discussion.