fix(traverse): exit scope early if enter it late (#3493)

Fixes #3490.
This commit is contained in:
overlookmotel 2024-05-31 17:53:23 +00:00
parent 55bbde2888
commit 3967a15b60
2 changed files with 7 additions and 5 deletions

View file

@ -69,6 +69,7 @@ function generateWalkForStruct(type, types) {
`\`visited_node\` attr says to enter scope before field '${enterFieldName}' `
+ `in '${type.name}', but that field is not visited`
);
if (scopeEnterField === visitedFields[0]) scopeEnterField = undefined;
}
// TODO: Maybe this isn't quite right. `scope_id` fields are `Cell<Option<ScopeId>>`,
@ -203,8 +204,9 @@ function generateWalkForStruct(type, types) {
${enterScopeCode}
traverser.enter_${typeSnakeName}(&mut *node, ctx);
${fieldsCodes.join('\n')}
${enterScopeCode ? '' : exitScopeCode}
traverser.exit_${typeSnakeName}(&mut *node, ctx);
${exitScopeCode}
${enterScopeCode ? exitScopeCode : ''}
}
`.replace(/\n\s*\n+/g, '\n');
}

View file

@ -1934,10 +1934,10 @@ pub(crate) unsafe fn walk_switch_statement<'a, Tr: Traverse<'a>>(
walk_switch_case(traverser, item as *mut _, ctx);
}
ctx.pop_stack();
traverser.exit_switch_statement(&mut *node, ctx);
if let Some(previous_scope_id) = previous_scope_id {
ctx.set_current_scope_id(previous_scope_id);
}
traverser.exit_switch_statement(&mut *node, ctx);
}
pub(crate) unsafe fn walk_switch_case<'a, Tr: Traverse<'a>>(
@ -2503,10 +2503,10 @@ pub(crate) unsafe fn walk_class<'a, Tr: Traverse<'a>>(
}
}
ctx.pop_stack();
traverser.exit_class(&mut *node, ctx);
if let Some(previous_scope_id) = previous_scope_id {
ctx.set_current_scope_id(previous_scope_id);
}
traverser.exit_class(&mut *node, ctx);
}
pub(crate) unsafe fn walk_class_body<'a, Tr: Traverse<'a>>(
@ -3644,10 +3644,10 @@ pub(crate) unsafe fn walk_ts_enum_declaration<'a, Tr: Traverse<'a>>(
walk_ts_enum_member(traverser, item as *mut _, ctx);
}
ctx.pop_stack();
traverser.exit_ts_enum_declaration(&mut *node, ctx);
if let Some(previous_scope_id) = previous_scope_id {
ctx.set_current_scope_id(previous_scope_id);
}
traverser.exit_ts_enum_declaration(&mut *node, ctx);
}
pub(crate) unsafe fn walk_ts_enum_member<'a, Tr: Traverse<'a>>(
@ -4842,10 +4842,10 @@ pub(crate) unsafe fn walk_ts_module_declaration<'a, Tr: Traverse<'a>>(
walk_ts_module_declaration_body(traverser, field as *mut _, ctx);
}
ctx.pop_stack();
traverser.exit_ts_module_declaration(&mut *node, ctx);
if let Some(previous_scope_id) = previous_scope_id {
ctx.set_current_scope_id(previous_scope_id);
}
traverser.exit_ts_module_declaration(&mut *node, ctx);
}
pub(crate) unsafe fn walk_ts_module_declaration_name<'a, Tr: Traverse<'a>>(