Skip to content

Commit

Permalink
Handle inline exports on types for components (#873)
Browse files Browse the repository at this point in the history
This was accidentally left out from text expanding.
  • Loading branch information
alexcrichton authored Jan 5, 2023
1 parent d79620f commit 2437581
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
11 changes: 11 additions & 0 deletions crates/wast/src/component/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,17 @@ impl<'a> Expander<'a> {
TypeDef::Component(t) => t.key().insert(self, index),
TypeDef::Instance(t) => t.key().insert(self, index),
}
for (name, url) in field.exports.names.drain(..) {
self.component_fields_to_append
.push(ComponentField::Export(ComponentExport {
span: field.span,
id: None,
debug_name: None,
name,
url,
kind: ComponentExportKind::ty(field.span, id),
}));
}
}

fn expand_func_ty(&mut self, ty: &mut ComponentFunctionType<'a>) {
Expand Down
8 changes: 8 additions & 0 deletions crates/wast/src/component/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ impl<'a> ComponentExportKind<'a> {
export_names: Default::default(),
})
}

pub(crate) fn ty(span: Span, id: Id<'a>) -> Self {
Self::Type(ItemRef {
kind: kw::r#type(span),
idx: Index::Id(id),
export_names: Default::default(),
})
}
}

impl<'a> Parse<'a> for ComponentExportKind<'a> {
Expand Down
2 changes: 1 addition & 1 deletion crates/wast/src/component/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub struct Type<'a> {
pub name: Option<NameAnnotation<'a>>,
/// If present, inline export annotations which indicate names this
/// definition should be exported under.
pub exports: core::InlineExport<'a>,
pub exports: InlineExport<'a>,
/// The type definition.
pub def: TypeDef<'a>,
}
Expand Down
3 changes: 3 additions & 0 deletions tests/local/component-model/inline-exports.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(component
(type (export "foo") u8)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(component
(type (;0;) u8)
(export (;1;) "foo" (type 0))
)

0 comments on commit 2437581

Please sign in to comment.