Skip to content

Implement "export/import * from" #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
torch2424 opened this issue Feb 10, 2018 · 12 comments
Closed

Implement "export/import * from" #27

torch2424 opened this issue Feb 10, 2018 · 12 comments

Comments

@torch2424
Copy link
Contributor

So after creating #21

I now realize why I came to the conclusion import did not work.

If you try export * from 'myfile', you will get the following console output:

screen shot 2018-02-10 at 12 44 02 am

And if I remember correctly, imports dont work this way as well.

Thank you!

@dcodeIO
Copy link
Member

dcodeIO commented Feb 10, 2018

That's right, wildcard exports and imports are not handled yet. Going to take a look and marking this issue as enhancement until then :)

@torch2424
Copy link
Contributor Author

Awesome, thank you! :)

@gustavomick
Copy link

Any workaround in the meantime?

@dcodeIO
Copy link
Member

dcodeIO commented Feb 20, 2018

Normal imports and exports should work, as should imports and exports of entire namespaces. Just the wildcard isn't implemented yet.

@gustavomick
Copy link

Thanks what if I need to import a wasm,eg. compiled code from c++ to wasm then importing that to ts. Any viable way to make that work? Thanks.

@dcodeIO
Copy link
Member

dcodeIO commented Feb 20, 2018

Linking wasms is a bit tricky currently. What I have in mind for this case is that the compiler could be provided with a base wasm, appending any additional code to it. would that work for your use case?

Other than that there are tools like wasm-merge that can combine multiple wasms into one, resolving imports agains exports. That could already work today, but last time I checked this didn't seem to work reliably.

@gustavomick
Copy link

@dcodeIO thanks sorry about the late answer, i currently on vacations :).

i was thinking about creating empty interfaces/type/mocks on typescript, using them from my main typescript code, then compiling to wasm and then replacing those mocks with real wasm implementations (that were previously compiled from c++ to wasm). that make sense? although not sure how to do that. if you have any suggestion will be helpful thanks.

@dcodeIO
Copy link
Member

dcodeIO commented Mar 31, 2018

That should be possible as well. On the AssemblyScript side, you'd then have a .ts file that declares the exported interface of the other wasm, which the AS module then imports. On the JS side, you'd then provide the other wasm for this import and it should just work.

declare namespace MyCppModule {
  export function someFunction(): i32;
}

// use it
MyCppModule.someFunction();
...

And simply give { MyCppModule: myCppModuleInstanceExports } as an import when instantiating the AS module.

@gustavomick
Copy link

@dcodeIO im missing something in here, how do i compile so my typescriptfile.wasm get linked to my cppfile.wasm file instead of the linked to the ts mock?
i thought i would had to create a workaround script to merge them, replacing the mock with the real implementation, how that part should work?

@dcodeIO
Copy link
Member

dcodeIO commented Apr 2, 2018

Merging, or real linking, might be more complicated because a linker will have to move around data segments, table elements etc. and update their indexes where used. There is wasm-merge which might, or might not, help.

My example above was based on the assumption that you'd then have two WebAssembly modules, with the exports of your cpp module being provided as imports to the typescript module.

@gustavomick
Copy link

ok ill try to read about this, thanks 👍

@dcodeIO dcodeIO changed the title Export/Import * from file does not work Implement "export/import * from" Jul 10, 2018
@torch2424
Copy link
Contributor Author

Closed by #489 😄

willemneal pushed a commit to willemneal/assemblyscript that referenced this issue May 31, 2019
radu-matei pushed a commit to radu-matei/assemblyscript that referenced this issue Oct 13, 2020
Bumps [assemblyscript](https://github.com/AssemblyScript/assemblyscript) from 0.9.2 to 0.9.4.
- [Release notes](https://github.com/AssemblyScript/assemblyscript/releases)
- [Commits](AssemblyScript/assemblyscript@v0.9.2...v0.9.4)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
radu-matei pushed a commit to radu-matei/assemblyscript that referenced this issue Oct 13, 2020
* 'master' of github.com:jedisct1/wasa:
  Fixed the memory leak for Time.sleep (AssemblyScript#33)
  Improve Descriptor (AssemblyScript#25)
  Bump assemblyscript from 0.9.2 to 0.9.4 (AssemblyScript#27)
  Deps
  Optimizations + update dependencies (AssemblyScript#21)
  Bump @as-pect/cli from 2.7.0 to 2.8.1 (AssemblyScript#23)
  Bump assemblyscript from 0.9.1 to 0.9.2 (AssemblyScript#24)
  Fix Date.now to return milliseconds instead of microseconds (AssemblyScript#19)
  Bump assemblyscript from 0.9.0 to 0.9.1 (AssemblyScript#17)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants