rustwasm / book

The Rust and WebAssembly Book
https://rustwasm.github.io/docs/book/
MIT License
1.75k stars 211 forks source link

rename `init()` to `init_panic_hook()` #179

Closed aaronabramov closed 5 years ago

aaronabramov commented 5 years ago

if this function is named init it will conflict with init function in the code generated by wasm-build --target web

it would produce code like:

/**
*/
export function init() {
    wasm.init();
}
// ...
function init(module) {
    if (typeof module === 'undefined') {
        module = import.meta.url.replace(/\.js$/, '_bg.wasm');
// ...

and parsing will fail with:


SyntaxError: unknown: Identifier 'init' has already been declared (136:9)

  134 | }
  135 |
> 136 | function init(module) {
      |          ^
  137 |     if (typeof module === 'undefined') {
  138 |         module = import.meta.url.replace(/\.js$/, '_bg.wasm');
  139 |     }
fitzgen commented 5 years ago

The book's tutorial doesn't use --target web so this shouldn't be something that people following the tutorial run into. Can you explain some more about what you are trying to do here?

fitzgen commented 5 years ago

Oh oops disregard the last comment, I thought this was in the game of life tutorial.