From 123ff04371a4b06f90a47f7aeab4e60fddffc6d4 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Sat, 14 Dec 2024 17:39:40 +0100 Subject: [PATCH] WIP --- cli/tools/lint/ast_buf.rs | 2 +- cli/tools/lint/swc.rs | 41 +++++++++++++++++---------------------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/cli/tools/lint/ast_buf.rs b/cli/tools/lint/ast_buf.rs index 28589a1e58..301bd186a8 100644 --- a/cli/tools/lint/ast_buf.rs +++ b/cli/tools/lint/ast_buf.rs @@ -576,7 +576,7 @@ impl StringTable { } } -#[derive(Debug, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct NodeRef(pub usize); #[derive(Debug)] diff --git a/cli/tools/lint/swc.rs b/cli/tools/lint/swc.rs index e9de5d3fb5..d52bc984e2 100644 --- a/cli/tools/lint/swc.rs +++ b/cli/tools/lint/swc.rs @@ -1556,6 +1556,8 @@ fn serialize_decl( let id = ctx.header(AstNode::TSInterface, parent, &node.span, 4); let declare_pos = ctx.bool_field(AstProp::Declare); + let body_id = ctx.next_id(); + ctx.header(AstNode::TSInterfaceBody, id, &node.body.span, 4); // FIXME let ident_id = serialize_ident(ctx, &node.id, id); @@ -1566,18 +1568,14 @@ fn serialize_decl( .extends .iter() .map(|item| { - let child_id = ctx.next_id(); - let expr_id = serialize_expr(ctx, &item.expr, child_id); + let child_id = + ctx.header(AstNode::TSInterfaceHeritage, id, &item.span, 1); + let expr_pos = ctx.ref_field(AstProp::Expression); + + let expr = serialize_expr(ctx, &item.expr, child_id); - ctx.write_node( - child_id, - AstNode::TSInterfaceHeritage, - id, - &item.span, - 1, - ); // FIXME - ctx.write_id(expr_id); + ctx.write_ref(expr_pos, expr); child_id }) @@ -1628,14 +1626,10 @@ fn serialize_decl( }) .collect::>(); - let body_id = ctx.next_id(); - ctx.write_node(body_id, AstNode::TSInterfaceBody, id, &node.body.span, 4); - // FIXME // ctx.write_ids( body_elem_ids); ctx.write_bool(declare_pos, node.declare); - ctx.write_flags(&flags); ctx.write_id(ident_id); ctx.write_id(type_param); @@ -2340,12 +2334,12 @@ fn serialize_ts_type( pos } TsType::TsTypeQuery(node) => { - let id = ctx.header(AstNode::TSTypeQuery, parent, &node.span, 1); + let pos = ctx.header(AstNode::TSTypeQuery, parent, &node.span, 1); let name_pos = ctx.ref_field(AstProp::ExprName); let expr_name = match &node.expr_name { TsTypeQueryExpr::TsEntityName(entity) => { - serialize_ts_entity_name(ctx, entity, id) + serialize_ts_entity_name(ctx, entity, pos) } TsTypeQueryExpr::Import(ts_import_type) => todo!(), }; @@ -2354,22 +2348,23 @@ fn serialize_ts_type( ctx.write_ref(name_pos, expr_name); - id + pos } TsType::TsTypeLit(ts_type_lit) => todo!(), TsType::TsArrayType(ts_array_type) => todo!(), TsType::TsTupleType(node) => { - let id = ctx.next_id(); + let pos = ctx.header(AstNode::TSTupleType, parent, &node.span, 1); + let children_pos = ctx.ref_vec_field(AstProp::ElementTypes); + let children = node .elem_types .iter() .map(|elem| todo!()) .collect::>(); - ctx.write_node(id, AstNode::TSTupleType, parent, &node.span, 1); - ctx.write_ids(AstProp::ElementTypes, children); + ctx.write_refs(children_pos, children); - id + pos } TsType::TsOptionalType(ts_optional_type) => todo!(), TsType::TsRestType(ts_rest_type) => todo!(), @@ -2501,8 +2496,8 @@ fn serialize_ts_type( fn serialize_ts_entity_name( ctx: &mut SerializeCtx, node: &TsEntityName, - parent: usize, -) -> usize { + parent: NodeRef, +) -> NodeRef { match &node { TsEntityName::TsQualifiedName(ts_qualified_name) => todo!(), TsEntityName::Ident(ident) => serialize_ident(ctx, ident, parent),