Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
chore: step 9, fix early return
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Dec 29, 2022
1 parent cdf4c03 commit 22ddd6f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ impl SameIdentifiers {
Self::next_static_expression(left, right)
}
AnyAssignmentLike::None | AnyAssignmentLike::Identifiers { .. } => {
Some(self.current_assignment_like.clone())
let new_assignment = self.current_assignment_like.clone();
self.current_assignment_like = AnyAssignmentLike::None;
Some(new_assignment)
}
}
}
Expand Down Expand Up @@ -333,11 +335,6 @@ impl Iterator for SameIdentifiers {
loop {
let new_assignment_like = self.next_assignment_like()?;

// if the queue is empty, we set the current assignment to `None`,
// so the next iteration will stop
if self.assignment_queue.is_empty() {
self.current_assignment_like = AnyAssignmentLike::None;
}
match new_assignment_like {
// if we are here, it's plausible that we consumed the current iterator and we have to
// resume the previous one
Expand Down
2 changes: 1 addition & 1 deletion crates/rome_js_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ mod tests {
String::from_utf8(buffer).unwrap()
}

const SOURCE: &str = r#"a[b] = a[b]"#;
const SOURCE: &str = r#"a = a"#;

let parsed = parse(SOURCE, FileId::zero(), SourceType::jsx());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,30 @@ invalid.js:3:11 lint/nursery/noSelfAssignment ━━━━━━━━━━━
5 │ ({a, b} = {a, b});
```

```
invalid.js:3:14 lint/nursery/noSelfAssignment ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! b is assigned to itself.
1 │ a = a;
2 │ [a] = [a];
> 3 │ [a, b] = [a, b];
│ ^
4 │ [a, ...b] = [a, ...b];
5 │ ({a, b} = {a, b});
i This is where is assigned.
1 │ a = a;
2 │ [a] = [a];
> 3 │ [a, b] = [a, b];
│ ^
4 │ [a, ...b] = [a, ...b];
5 │ ({a, b} = {a, b});
```

```
Expand Down Expand Up @@ -141,6 +165,30 @@ invalid.js:5:12 lint/nursery/noSelfAssignment ━━━━━━━━━━━
7 │ [{a}, {b}] = [{a}, {b}];
```

```
invalid.js:5:15 lint/nursery/noSelfAssignment ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! b is assigned to itself.
3 │ [a, b] = [a, b];
4 │ [a, ...b] = [a, ...b];
> 5 │ ({a, b} = {a, b});
│ ^
6 │ [[a], [b]] = [[a], [b]];
7 │ [{a}, {b}] = [{a}, {b}];
i This is where is assigned.
3 │ [a, b] = [a, b];
4 │ [a, ...b] = [a, ...b];
> 5 │ ({a, b} = {a, b});
│ ^
6 │ [[a], [b]] = [[a], [b]];
7 │ [{a}, {b}] = [{a}, {b}];
```

```
Expand Down

0 comments on commit 22ddd6f

Please sign in to comment.