From a9306971ae68bf2eb3dfead38fae4558979fb733 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Thu, 11 Aug 2022 01:53:49 +0900 Subject: [PATCH] Fix with-statement location --- src/compile.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/compile.rs b/src/compile.rs index f183433..184f410 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -1393,12 +1393,15 @@ impl Compiler { body: &[ast::Stmt], is_async: bool, ) -> CompileResult<()> { + let with_location = self.current_source_location; + let end_blocks = items .iter() .map(|item| { let end_block = self.new_block(); self.compile_expression(&item.context_expr)?; + self.set_source_location(with_location); if is_async { self.emit(Instruction::BeforeAsyncWith); self.emit(Instruction::GetAwaitable); @@ -1411,6 +1414,7 @@ impl Compiler { match &item.optional_vars { Some(var) => { + self.set_source_location(var.location); self.compile_store(var)?; } None => { @@ -1425,6 +1429,7 @@ impl Compiler { // sort of "stack up" the layers of with blocks: // with a, b: body -> start_with(a) start_with(b) body() end_with(b) end_with(a) + self.set_source_location(with_location); for end_block in end_blocks.into_iter().rev() { self.emit(Instruction::PopBlock); self.emit(Instruction::EnterFinally);