File tree Expand file tree Collapse file tree 11 files changed +352
-235
lines changed Expand file tree Collapse file tree 11 files changed +352
-235
lines changed Original file line number Diff line number Diff line change 1+ export const add = {
2+ add ( x , y ) {
3+ return x + y ;
4+ }
5+ } ;
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " adder-wasm" ,
3+ "description" : " Simple codebase for compiling an add interface to WebAssembly with jco" ,
4+ "type" : " module"
5+ }
Original file line number Diff line number Diff line change 1+ import { add } from "./dist/transpiled/adder.js" ;
2+
3+ console . log ( "1 + 2 = " + add . add ( 1 , 2 ) ) ;
Original file line number Diff line number Diff line change 1+ package example : string-reverse-upper @ 0.1.0;
2+
3+ @since (version = 0.1.0 )
4+ interface reversed-upper {
5+ reverse-and-uppercase : func (s : string ) -> string ;
6+ }
7+
8+ world revup {
9+ //
10+ // NOTE, the import below translates to:
11+ // <namespace>:<package>/<interface>@<package version>
12+ //
13+ import example :string-reverse /reverse @ 0.1.0 ;
14+
15+ export reversed-upper ;
16+ }
Original file line number Diff line number Diff line change 1+ /**
2+ * If this import listed below is missing, please run
3+ *
4+ * ```
5+ * npm run build && npm run compose && npm run transpile`
6+ * ```
7+ */
8+ import { reversedUpper } from "./dist/transpiled/string-reverse-upper.js" ;
9+
10+ const result = reversedUpper . reverseAndUppercase ( "!dlroW olleH" ) ;
11+
12+ console . log ( `reverseAndUppercase('!dlroW olleH') = ${ result } ` ) ;
Original file line number Diff line number Diff line change 1+ /**
2+ * This module is the JS implementation of the `revup` WIT world
3+ */
4+
5+ /**
6+ * The import here is *virtual*. It refers to the `import`ed `reverse` interface in component.wit.
7+ *
8+ * These types *do not resolve* when the first `string-reverse-upper` component is built,
9+ * but the types are relevant for the resulting *composed* component.
10+ */
11+ import { reverseString } from 'example:string-reverse/[email protected] ' ; 12+
13+ /**
14+ * The JavaScript export below represents the export of the `reversed-upper` interface,
15+ * which which contains `revup` as it's primary exported function.
16+ */
17+ export const reversedUpper = {
18+ /**
19+ * Represents the implementation of the `reverse-and-uppercase` function in the `reversed-upper` interface
20+ *
21+ * This function makes use of `reverse-string` which is *imported* from another WebAssembly binary.
22+ */
23+ reverseAndUppercase ( s ) {
24+ return reverseString ( s ) . toLocaleUpperCase ( ) ;
25+ } ,
26+ } ;
Original file line number Diff line number Diff line change 1+ package example : string-reverse @ 0.1.0;
2+
3+ @since (version = 0.1.0 )
4+ interface reverse {
5+ reverse-string : func (s : string ) -> string ;
6+ }
7+
8+ world string-reverse {
9+ export reverse ;
10+ }
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " string-reverse" ,
3+ "description" : " Simple codebase for compiling a string reversing interface to WebAssembly with jco" ,
4+ "type" : " module"
5+ }
Original file line number Diff line number Diff line change 1+ // If this import listed below is missing, please run `npm run transpile`
2+ import { reverse } from "./dist/transpiled/string-reverse.js" ;
3+
4+ const reversed = reverse . reverseString ( "!dlroW olleH" ) ;
5+
6+ console . log ( `reverseString('!dlroW olleH') = ${ reversed } ` ) ;
Original file line number Diff line number Diff line change 1+ /**
2+ * This module is the JS implementation of the `string-reverse` WIT world
3+ */
4+
5+ /**
6+ * The JavaScript export below represents the export of the `reverse` interface,
7+ * which which contains `reverse-string` as its primary exported function.
8+ */
9+ export const reverse = {
10+ /**
11+ * This JavaScript will be interpreted by `jco` and turned into a
12+ * WebAssembly binary with a single export (this `reverse` function).
13+ */
14+ reverseString ( s ) {
15+ return s . split ( "" )
16+ . reverse ( )
17+ . join ( "" ) ;
18+ }
19+ } ;
You can’t perform that action at this time.
0 commit comments