Skip to content

Commit 5a00b63

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 5a00b63

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

wit/bindgen/generator.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2436,7 +2436,30 @@ 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 `wasi:io/[email protected]` will be transformed into the generated world:
2449+
// `world wasi-io-WORLD-imports-v020-rc-x2023-x11-x10{}`
2450+
// See https://component-model.bytecodealliance.org/design/wit.html#identifiers
2451+
// and https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md#package-names
2452+
"-0", "-x0",
2453+
"-1", "-x1",
2454+
"-2", "-x2",
2455+
"-3", "-x3",
2456+
"-4", "-x4",
2457+
"-5", "-x5",
2458+
"-6", "-x6",
2459+
"-7", "-x7",
2460+
"-8", "-x8",
2461+
"-9", "-x9",
2462+
)
24402463

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

0 commit comments

Comments
 (0)