@@ -9,7 +9,7 @@ use oxc_diagnostics::OxcDiagnostic;
9
9
10
10
use oxc_macros:: declare_oxc_lint;
11
11
use oxc_semantic:: {
12
- pg:: neighbors_filtered_by_edge_weight, AssignmentValue , BasicBlockElement , EdgeType , Register ,
12
+ pg:: neighbors_filtered_by_edge_weight, EdgeType , InstructionKind , ReturnInstructionKind ,
13
13
} ;
14
14
use oxc_span:: Span ;
15
15
@@ -229,49 +229,28 @@ impl GetterReturn {
229
229
}
230
230
231
231
// Scan through the values in this basic block.
232
- for entry in cfg. basic_block ( * basic_block_id) {
233
- match entry {
234
- // If the element is an assignment.
235
- //
236
- // Everything you can write in javascript that would have
237
- // the function continue are expressed as assignments in the cfg.
238
- BasicBlockElement :: Assignment ( to_reg, val) => {
239
- // If the assignment is to the return register.
240
- //
241
- // The return register is a special register that return statements
242
- // assign the returned value to.
243
- if matches ! ( to_reg, Register :: Return ) {
232
+ for entry in cfg. basic_block ( * basic_block_id) . instructions ( ) {
233
+ match entry. kind {
234
+ // If the element is a return.
244
235
// `allow_implicit` allows returning without a value to not
245
- // fail the rule. We check for this by checking if the value
246
- // being returned in the cfg this is expressed as
247
- // `AssignmentValue::ImplicitUndefined`.
248
- //
249
- // There is an assumption being made here that returning an
250
- // `undefined` will put the `undefined` directly into the
251
- // return and will not put the `undefined` into an immediate
252
- // register and return the register. However, the tests for
253
- // this rule enforce that this invariant is not broken.
254
- if !self . allow_implicit
255
- && matches ! ( val, AssignmentValue :: ImplicitUndefined )
256
- {
257
- // Return false as the second argument to signify we should
258
- // not continue walking this branch, as we know a return
259
- // is the end of this path.
260
- return ( DefinitelyReturnsOrThrowsOrUnreachable :: No , false ) ;
261
- }
236
+ // fail the rule.
237
+ // Return false as the second argument to signify we should
238
+ // not continue walking this branch, as we know a return
239
+ // is the end of this path.
240
+ InstructionKind :: Return ( ReturnInstructionKind :: ImplicitUndefined ) if !self . allow_implicit => {
241
+ return ( DefinitelyReturnsOrThrowsOrUnreachable :: No , false ) ;
242
+ }
262
243
// Otherwise, we definitely returned since we assigned
263
244
// to the return register.
264
245
//
265
246
// Return false as the second argument to signify we should
266
247
// not continue walking this branch, as we know a return
267
248
// is the end of this path.
268
- return ( DefinitelyReturnsOrThrowsOrUnreachable :: Yes , false ) ;
269
- }
270
- }
249
+ | InstructionKind :: Return ( _)
271
250
// Throws are classified as returning.
272
251
//
273
252
// todo: test with catching...
274
- BasicBlockElement :: Throw ( _ ) |
253
+ | InstructionKind :: Throw
275
254
// Although the unreachable code is not returned, it will never be executed.
276
255
// There is no point in checking it for return.
277
256
//
@@ -283,12 +262,13 @@ impl GetterReturn {
283
262
// return -1;
284
263
// ```
285
264
// Make return useless.
286
- BasicBlockElement :: Unreachable => {
287
-
288
- return ( DefinitelyReturnsOrThrowsOrUnreachable :: Yes , false ) ;
265
+ | InstructionKind :: Unreachable =>{
266
+ return ( DefinitelyReturnsOrThrowsOrUnreachable :: Yes , false ) ;
289
267
}
290
268
// Ignore irrelevant elements.
291
- BasicBlockElement :: Break ( _) => { }
269
+ | InstructionKind :: Break
270
+ | InstructionKind :: Statement
271
+ | InstructionKind :: Jump { .. } => { }
292
272
}
293
273
}
294
274
0 commit comments