Skip to content

Commit

Permalink
Add a method to output enum variant name
Browse files Browse the repository at this point in the history
Summary:
Will use this to improve our current error message and logging. Right now, we have a generic message on unsupported flow type, but we don't know which flow type is invovled

used in next diff in the stack

Reviewed By: evanyeung

Differential Revision: D58311850

fbshipit-source-id: 9550741d2591e8b00e935ae5ee618dcd41548f37
  • Loading branch information
tyao1 authored and facebook-github-bot committed Jun 12, 2024
1 parent 319c8be commit 2aafa0f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ pub trait Range {
fn range(&self) -> SourceRange;
}

pub trait Introspection {
fn name(&self) -> &'static str;
}

impl Default for SourceType {
fn default() -> Self {
Self::Module
Expand Down
15 changes: 14 additions & 1 deletion unsupported/hermes/crates/hermes_estree_codegen/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl Grammar {
use std::num::NonZeroU32;
use serde::ser::{Serializer, SerializeMap};
use serde::{Serialize,Deserialize};
use crate::{JsValue, Binding, SourceRange, Number, ESTreeNode, Range};
use crate::{JsValue, Binding, SourceRange, Number, ESTreeNode, Range, Introspection};

#(#object_defs)*

Expand Down Expand Up @@ -765,6 +765,11 @@ impl Enum {
quote!(Self::#variant(node) => node.range())
});

let name_variants = sorted_variants.iter().map(|name| {
let variant = format_ident!("{}", name);
quote!(Self::#variant(_) => #name)
});

quote! {
#[derive(Serialize, Clone, Debug)]
#[serde(untagged)]
Expand Down Expand Up @@ -797,6 +802,14 @@ impl Enum {
}
}
}

impl Introspection for #name {
fn name(&self) -> &'static str {
match self {
#(#name_variants),*
}
}
}
}
}

Expand Down

0 comments on commit 2aafa0f

Please sign in to comment.