Fix with-statement location

This commit is contained in:
Jeong YunWon 2022-08-11 01:53:49 +09:00
parent 75b886bcd6
commit a9306971ae

View file

@ -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);