Skip to content

Commit 4a71d5c

Browse files
committed
fix: bug that incorrectly generates WIT worlds with words that start with a digit from packages using valid semver
Signed-off-by: Andrew Steurer <[email protected]>
1 parent 55a8715 commit 4a71d5c

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

wit/bindgen/generator.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2436,7 +2436,34 @@ func (g *generator) newPackage(w *wit.World, i *wit.Interface, name string) (*ge
24362436
return pkg, nil
24372437
}
24382438

2439-
var replacer = strings.NewReplacer("/", "-", ":", "-", "@", "-v", ".", "", "%", "")
2439+
var replacer = strings.NewReplacer(
2440+
"/", "-",
2441+
":", "-",
2442+
"@", "-v",
2443+
".", "",
2444+
"%", "",
2445+
// The below replacements will ensure that worlds generated from the package name
2446+
// follow WIT identifier rules disallowing words to begin with a digit
2447+
// and still allow package names to use semver.
2448+
// For example, the package `wasi:io/[email protected]` used to generate the following world:
2449+
//
2450+
// world wasi-io-WORLD-imports-v020-rc-x2023-x11-x10`{
2451+
// ...
2452+
///}
2453+
///
2454+
// See https://component-model.bytecodealliance.org/design/wit.html#identifiers
2455+
// and https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md#package-names
2456+
"-0", "-x0",
2457+
"-1", "-x1",
2458+
"-2", "-x2",
2459+
"-3", "-x3",
2460+
"-4", "-x4",
2461+
"-5", "-x5",
2462+
"-6", "-x6",
2463+
"-7", "-x7",
2464+
"-8", "-x8",
2465+
"-9", "-x9",
2466+
)
24402467

24412468
// componentEmbed runs generated WIT through wasm-tools to generate a wasm file with a component-type custom section.
24422469
func (g *generator) componentEmbed(witData string) ([]byte, error) {

0 commit comments

Comments
 (0)