From 24375810449156d424d87a7db45eaaacdcf8b45f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 5 Jan 2023 14:36:30 -0600 Subject: [PATCH] Handle inline exports on types for components (#873) This was accidentally left out from text expanding. --- crates/wast/src/component/expand.rs | 11 +++++++++++ crates/wast/src/component/export.rs | 8 ++++++++ crates/wast/src/component/types.rs | 2 +- tests/local/component-model/inline-exports.wast | 3 +++ .../local/component-model/inline-exports.wast/0.print | 4 ++++ 5 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/local/component-model/inline-exports.wast create mode 100644 tests/snapshots/local/component-model/inline-exports.wast/0.print diff --git a/crates/wast/src/component/expand.rs b/crates/wast/src/component/expand.rs index d2de08550c..02cf9c2940 100644 --- a/crates/wast/src/component/expand.rs +++ b/crates/wast/src/component/expand.rs @@ -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>) { diff --git a/crates/wast/src/component/export.rs b/crates/wast/src/component/export.rs index 48fe000a23..8d3135894a 100644 --- a/crates/wast/src/component/export.rs +++ b/crates/wast/src/component/export.rs @@ -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> { diff --git a/crates/wast/src/component/types.rs b/crates/wast/src/component/types.rs index 9e9500b4c4..0ff8cc0183 100644 --- a/crates/wast/src/component/types.rs +++ b/crates/wast/src/component/types.rs @@ -133,7 +133,7 @@ pub struct Type<'a> { pub name: Option>, /// 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>, } diff --git a/tests/local/component-model/inline-exports.wast b/tests/local/component-model/inline-exports.wast new file mode 100644 index 0000000000..3cefeb79e7 --- /dev/null +++ b/tests/local/component-model/inline-exports.wast @@ -0,0 +1,3 @@ +(component + (type (export "foo") u8) +) diff --git a/tests/snapshots/local/component-model/inline-exports.wast/0.print b/tests/snapshots/local/component-model/inline-exports.wast/0.print new file mode 100644 index 0000000000..ed84a2648b --- /dev/null +++ b/tests/snapshots/local/component-model/inline-exports.wast/0.print @@ -0,0 +1,4 @@ +(component + (type (;0;) u8) + (export (;1;) "foo" (type 0)) +) \ No newline at end of file