-
Notifications
You must be signed in to change notification settings - Fork 44
Description
Tracking issue to upgrade ComponentizeJS to the latest WIT syntax.
For kebab names, the integration remains identical to the current implementation, ie:
package local:app
world app {
import fn: func () -> string;
import iface: interface {
test: func () -> string
}
export fn: func () -> string;
export iface: interface {
test: func () -> string
}
}
can be represented by the JS ESM source:
import fnImport from 'fn';
import { test } from 'iface';
export function fn () {
return fnImport();
}
export const iface = {
test () {
return test();
}
};In the recent jco@0.8.0 release, the WIT wasn't quite represented correctly for namespaces which require a conversion, resulting in a need for some further refinements described in bytecodealliance/jco#91.
When handling namespaces, we effectively perform a "conversion" from the namespace semantics to the ESM semantics, exactly as described in the JCO issue there.
The convention with aliasing semantics becomes for componentizing a world:
package my:package
interface test {
hello: func () -> string
}
world test {
import wasi:filesystem/types
import test
export wasi:filesystem/types
export test
}
becomes the corresponding ESM source written by the user:
import * as types from 'wasi:filesystem/types';
import { hello } from 'test';
// export aliases
export const types = {
fn () {], // ...
};
export const test = {
hello () {}
};If there were an aliasing conflict, say there already existed interface name exports for test and types, then we would need the code author to instead write:
import * as types from 'wasi:filesystem/types';
import { hello } from 'test';
// when the world has these namespace interface exports already,
// eg from another interface via:
// export another:package/types
// export another:package/test
// then the base alias can only be the first or neither
export const types = /*...*/;
export const test = /*...*/;
// now we must then export the full canonical names for the duplicates,
// by defining local variables,
const wasiFilesystemTypes = {
hello () {}
};
const myPackageTest = {
fn () {], // ...
};
// then we export them using the "string export" syntax for ES modules
export { wasiFilesystemTypes as 'wasi:filesystem/types', myPackageTest as 'my:package/test' }The major concern with this Componentize convention for implementing external namespaces, is that when there is a conflict this new authoring style wouldn't be known to the user, so they would need to be informed that they must switch authoring modes into this full convention.
The alternative would be to always require the full verbose export mode without aliasing in componentize workflows to avoid such a cliff.