Address comments

Signed-off-by: harupy <hkawamura0130@gmail.com>
This commit is contained in:
harupy 2022-12-12 22:14:05 +09:00
parent cfbf5f0f63
commit 3d8a245870

View file

@ -361,10 +361,11 @@ IfStatement: ast::Stmt = {
// Determine last else:
let mut last = s3.map(|s| s.2).unwrap_or_default();
let end_location = last
.last()
.map(|last| last.end_location)
.or_else(|| s2.last().map(|last| last.4.last().unwrap().end_location))
.unwrap_or_else(|| body.last().unwrap().end_location);
.last()
.or_else(|| s2.last().and_then(|last| last.4.last()))
.or_else(|| body.last())
.unwrap()
.end_location;
// handle elif:
for i in s2.into_iter().rev() {
let x = ast::Stmt {
@ -387,11 +388,12 @@ IfStatement: ast::Stmt = {
WhileStatement: ast::Stmt = {
<location:@L> "while" <test:NamedExpressionTest> ":" <body:Suite> <s2:("else" ":" Suite)?> => {
let end_location = s2
.as_ref()
.map(|s| s.2.last().unwrap().end_location)
.unwrap_or_else(|| body.last().unwrap().end_location);
let orelse = s2.map(|s| s.2).unwrap_or_default();
let end_location = orelse
.last()
.or_else(|| body.last())
.unwrap()
.end_location;
ast::Stmt {
custom: (),
location,
@ -407,12 +409,13 @@ WhileStatement: ast::Stmt = {
ForStatement: ast::Stmt = {
<location:@L> <is_async:"async"?> "for" <target:ExpressionList> "in" <iter:TestList> ":" <body:Suite> <s2:("else" ":" Suite)?> => {
let end_location = s2
.as_ref()
.map(|s| s.2.last().unwrap().end_location)
.unwrap_or_else(|| body.last().unwrap().end_location)
.unwrap();
let orelse = s2.map(|s| s.2).unwrap_or_default();
let end_location = orelse
.last()
.or_else(|| body.last())
.unwrap()
.end_location
.unwrap();
let target = Box::new(set_context(target, ast::ExprContext::Store));
let iter = Box::new(iter);
let type_comment = None;