Skip to content

Commit

Permalink
Use a Path with NodeField
Browse files Browse the repository at this point in the history
Summary:
Pass along the name of the field the Node is from throughout visiting
the AST.

If the user is manually visiting any children, the correct field must be
passed along as well.

Reviewed By: tmikov

Differential Revision: D32339610

fbshipit-source-id: e207c804b8b694ad0134ca5e5423d8d8ad7edcf0
  • Loading branch information
avp authored and facebook-github-bot committed Nov 17, 2021
1 parent 42ae0e9 commit bc63f9b
Show file tree
Hide file tree
Showing 11 changed files with 873 additions and 402 deletions.
131 changes: 131 additions & 0 deletions unsupported/juno/crates/juno/src/ast/field.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/// The name of the field of an AST node.
#[derive(Debug, Copy, Clone, PartialEq)]
#[allow(non_camel_case_types)]
pub enum NodeField {
accessibility,
alternate,
argument,
arguments,
assertions,
attributes,
block,
body,
bound,
call_properties,
callee,
cases,
check_type,
children,
closing_element,
closing_fragment,
computed,
consequent,
constraint,
cooked,
declaration,
declarations,
declare,
decorators,
default,
delegate,
directive,
discriminant,
element_type,
element_types,
elements,
exact,
explicit_type,
export,
export_kind,
exported,
expr_name,
expression,
expressions,
extends,
extends_type,
false_t_ype,
finalizer,
flags,
generator,
handler,
has_unknown_members,
id,
implements,
impltype,
import_kind,
imported,
index_type,
indexers,
inexact,
init,
initializer,
internal_slots,
is_async,
is_await,
is_static,
key,
kind,
label,
left,
literal,
local,
members,
meta,
method,
mixins,
name,
namespace,
object,
object_type,
opening_element,
opening_fragment,
operator,
optional,
param,
parameter,
parameter_name,
parameters,
params,
pattern,
predicate,
prefix,
properties,
property,
proto,
qualification,
quasi,
quasis,
raw,
readonly,
rest,
return_type,
right,
self_closing,
shorthand,
source,
specifiers,
super_class,
super_type_parameters,
supertype,
tag,
tail,
test,
this,
trailing_comma,
true_type,
type_annotation,
type_arguments,
type_name,
type_parameters,
types,
update,
value,
variance,
}
26 changes: 21 additions & 5 deletions unsupported/juno/crates/juno/src/ast/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ macro_rules! gen_nodekind_enum {
..
}) => {
$($(
$field.visit_child(ctx, visitor, self);
$field.visit_child(
ctx,
visitor,
Path::new(self, NodeField::$field),
);
)*)?
}
),*
Expand All @@ -103,7 +107,10 @@ macro_rules! gen_nodekind_enum {
builder::Builder::$kind(mut builder) => {
$($(
if let TransformResult::Changed($field) = (&builder.inner.$field)
.visit_child_mut(ctx, visitor, self) {
.visit_child_mut(
ctx,
visitor,
Path::new(self, NodeField::$field)) {
builder.$field($field);
}
)*)?
Expand All @@ -129,7 +136,10 @@ macro_rules! gen_nodekind_enum {
builder::Builder::$kind(mut builder) => {
$($(
if let TransformResult::Changed($field) = (&builder.inner.$field)
.visit_child_mut(ctx, visitor, self) {
.visit_child_mut(
ctx,
visitor,
Path::new(self, NodeField::$field)) {
builder.$field($field);
}
)*)?
Expand Down Expand Up @@ -157,7 +167,10 @@ macro_rules! gen_nodekind_enum {
builder::Builder::$kind(mut builder) => {
$($(
if let TransformResult::Changed($field) = (&builder.inner.$field)
.visit_child_mut(ctx, visitor, self) {
.visit_child_mut(
ctx,
visitor,
Path::new(self, NodeField::$field)) {
builder.$field($field);
}
)*)?
Expand Down Expand Up @@ -186,7 +199,10 @@ macro_rules! gen_nodekind_enum {
builder::Builder::$kind(mut builder) => {
$($(
if let TransformResult::Changed($field) = (&builder.inner.$field)
.visit_child_mut(ctx, visitor, self) {
.visit_child_mut(
ctx,
visitor,
Path::new(self, NodeField::$field)) {
builder.$field($field);
}
)*)?
Expand Down
Loading

0 comments on commit bc63f9b

Please sign in to comment.