bytecodealliance / jco

JavaScript toolchain for working with WebAssembly Components
https://bytecodealliance.github.io/jco/
Apache License 2.0
640 stars 63 forks source link

Transpile command generates invalid JS with `--import-bindings=...` #511

Closed buismaarten closed 2 weeks ago

buismaarten commented 1 month ago

Using --import-bindings=direct-optimized:

...
    trampoline16 = Descriptor.prototype.getFlags( memory: memory0,);
    trampoline17 = filesystemErrorCode( memory: memory0,);
    trampoline18 = Descriptor.prototype.writeViaStream( memory: memory0,);
    trampoline19 = Descriptor.prototype.appendViaStream( memory: memory0,);
    trampoline20 = Descriptor.prototype.getType( memory: memory0,);
    trampoline21 = Descriptor.prototype.stat( memory: memory0,);
    trampoline22 = OutputStream.prototype.checkWrite( memory: memory0,);
    trampoline23 = OutputStream.prototype.write( memory: memory0,);
    trampoline24 = OutputStream.prototype.blockingFlush( memory: memory0,);
    trampoline25 = OutputStream.prototype.blockingWriteAndFlush( memory: memory0,);
    trampoline26 = getDirectories( memory: memory0, realloc: realloc0,);
    trampoline27 = getTerminalStdin( memory: memory0,);
    trampoline28 = getTerminalStdout( memory: memory0,);
    trampoline29 = getTerminalStderr( memory: memory0,);
...                                 ^^^^^^^^^^^^^^^^^^^ here

Using --import-bindings=optimized (note the single quotes inside single quote string):

...
    if (!getStderr[symbolCabiLower]) {
      throw new TypeError('import for "wasi:cli/stderr@0.2.0" does not define a Symbol.for('cabiLower') optimized binding');
    } //                 ^^^                                                              ^^^ here
    trampoline10 = getStderr[symbolCabiLower]( resourceTables: [handleTable3],);
    if (!getStdin[symbolCabiLower]) {
      throw new TypeError('import for "wasi:cli/stdin@0.2.0" does not define a Symbol.for('cabiLower') optimized binding');
    } //                 ^^^                                                             ^^^ here
    trampoline13 = getStdin[symbolCabiLower]( resourceTables: [handleTable2],);
    if (!getStdout[symbolCabiLower]) {
      throw new TypeError('import for "wasi:cli/stdout@0.2.0" does not define a Symbol.for('cabiLower') optimized binding');
    } //                 ^^^                                                              ^^^ here
    trampoline14 = getStdout[symbolCabiLower]( resourceTables: [handleTable3],);
    if (!exit[symbolCabiLower]) {
      throw new TypeError('import for "wasi:cli/exit@0.2.0" does not define a Symbol.for('cabiLower') optimized binding');
    } //                 ^^^                                                            ^^^ here
...
guybedford commented 3 weeks ago

Thanks so much for reporting this one - fix in https://github.com/bytecodealliance/jco/pull/516.