Skip to content

Commit

Permalink
Update crates/oxc_traverse/scripts/lib/walk.mjs
Browse files Browse the repository at this point in the history
Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
  • Loading branch information
DonIsaac and overlookmotel committed Oct 9, 2024
1 parent 9cf43d4 commit acff844
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
13 changes: 5 additions & 8 deletions crates/oxc_traverse/scripts/lib/walk.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function generateWalkForStruct(type, types) {
/** @type {Field | undefined} */
let scopeEnterField,
/** @type {Field | undefined} */
exitScopeField;
scopeExitField;
let enterScopeCode = '', exitScopeCode = '';

if (scopeArgs && scopeIdField) {
Expand All @@ -97,16 +97,13 @@ function generateWalkForStruct(type, types) {
// Get field to exit scope before
const exitFieldName = scopeArgs.exitScopeBefore;
if (exitFieldName) {
exitScopeField = visitedFields.find(field => field.name === exitFieldName);
scopeExitField = visitedFields.find(field => field.name === exitFieldName);
assert(
exitScopeField,
scopeExitField,
`\`ast\` attr says to exit scope before field '${exitFieldName}' ` +
`in '${type.name}', but that field is not visited`,
);
}
// else {
// exitScopeField = visitedFields[visitedFields.length - 1];
// }

// TODO: Maybe this isn't quite right. `scope_id` fields are `Cell<Option<ScopeId>>`,
// so visitor is able to alter the `scope_id` of a node from higher up the tree,
Expand All @@ -125,7 +122,7 @@ function generateWalkForStruct(type, types) {
fieldCamelName = snakeToCamel(field.name);
const scopeCode = field === scopeEnterField
? enterScopeCode
: field === exitScopeField
: field === scopeExitField
? exitScopeCode
: '';

Expand Down Expand Up @@ -232,7 +229,7 @@ function generateWalkForStruct(type, types) {
) {
traverser.enter_${typeSnakeName}(&mut *node, ctx);
${fieldsCodes.join('\n')}
${exitScopeField ? '' : exitScopeCode}
${scopeExitField ? '' : exitScopeCode}
traverser.exit_${typeSnakeName}(&mut *node, ctx);
}
`.replace(/\n\s*\n+/g, '\n');
Expand Down
4 changes: 2 additions & 2 deletions tasks/ast_tools/src/generators/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,9 @@ impl<'a> VisitBuilder<'a> {
exit_scope_at.is_none(),
"Scopes cannot be exited more than once. Remove the extra `#[scope(exit_before)]` attribute(s)."
);
let scope_leave = &scope_events.1;
let scope_exit = &scope_events.1;
result = quote! {
#scope_leave
#scope_exit
#result
};
exit_scope_at = Some(ix);
Expand Down

0 comments on commit acff844

Please sign in to comment.