Skip to content

Commit 352d370

Browse files
committed
wit: emit multi-package, single-file WIT with a top-level un-nested root package
See bytecodealliance/wasm-tools#1700 and WebAssembly/component-model#380
1 parent 8c82315 commit 352d370

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

wit/wit.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,20 @@ func (r *Resolve) WIT(_ Node, _ string) string {
5858
slices.SortFunc(packages, func(a, b *Package) int {
5959
return strings.Compare(a.Name.String(), b.Name.String())
6060
})
61-
// Special case if only single package.
62-
if len(packages) == 1 {
63-
return packages[0].WIT(nil, "")
64-
}
65-
// Use single-file, multi-package style:
66-
// https://github.com/WebAssembly/component-model/pull/340
67-
// https://github.com/bytecodealliance/wasm-tools/pull/1577
6861
var b strings.Builder
6962
for i, p := range packages {
70-
if i > 0 {
63+
if i == 0 {
64+
// Context == nil means write non-nested form of package
65+
// https://github.com/bytecodealliance/wasm-tools/pull/1700
66+
b.WriteString(p.WIT(nil, ""))
67+
} else {
7168
b.WriteRune('\n')
7269
b.WriteRune('\n')
70+
// Context == *Resolve means write single-file, multi-package style:
71+
// https://github.com/WebAssembly/component-model/pull/340
72+
// https://github.com/bytecodealliance/wasm-tools/pull/1577
73+
b.WriteString(p.WIT(r, ""))
7374
}
74-
b.WriteString(p.WIT(r, ""))
7575
}
7676
return b.String()
7777
}

0 commit comments

Comments
 (0)