Skip to content

Commit

Permalink
Fix type inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Apr 30, 2024
1 parent b218244 commit 4da2a3a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
16 changes: 16 additions & 0 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ pub fn traverse<'a, T: Traverse<'a>>(
// walk_traversable_program(traverser, program, ctx, tk);
}

// TODO: Delete this - just for testing type layouts.
// The `inherit_variants!` macro has screwed up `layout_inspect` - it can't see these inherited types.
#[derive(layout_inspect::Inspect)]
pub enum FakeForTestingInheritedTypes<'a> {
Program(Box<'a, Program<'a>>),
MemberExpression(Box<'a, MemberExpression<'a>>),
Expression(Box<'a, Expression<'a>>),
SimpleAssignmentTarget(Box<'a, SimpleAssignmentTarget<'a>>),
AssignmentTargetPattern(Box<'a, AssignmentTargetPattern<'a>>),
AssignmentTarget(Box<'a, AssignmentTarget<'a>>),
Declaration(Box<'a, Declaration<'a>>),
ModuleDeclaration(Box<'a, ModuleDeclaration<'a>>),
TSType(Box<'a, TSTypeName<'a>>),
TSTypeName(Box<'a, TSTypeName<'a>>),
}

#[ast_node]
#[derive(Debug, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
Expand Down
1 change: 1 addition & 0 deletions tasks/inspect_ast/lib/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ console.log('--------------------');
console.log('> Nested enums:');
const nestedEnums = Object.values(types).flatMap((type) => {
if (type.kind !== 'enum') return [];
if (type.name === 'FakeForTestingInheritedTypes') return [];
return type.variants.filter(({type: variantType}) => (
variantType?.kind === 'enum'
|| (variantType?.kind === 'box' && variantType.value.kind === 'enum')
Expand Down
4 changes: 2 additions & 2 deletions tasks/inspect_ast/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

use layout_inspect::inspect;

use oxc_ast::ast::Program;
use oxc_ast::ast::FakeForTestingInheritedTypes;

pub fn main() {
let types = inspect::<Program>();
let types = inspect::<FakeForTestingInheritedTypes>();
let json = serde_json::to_string_pretty(&types).unwrap();
println!("{json}");
}

0 comments on commit 4da2a3a

Please sign in to comment.