Skip to content
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

rename init() to init_panic_hook() #179

Merged
merged 1 commit into from
Jul 24, 2019
Merged

Conversation

aaronabramov
Copy link
Contributor

@aaronabramov aaronabramov commented Jul 16, 2019

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 |     }

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:
```js
/**
*/
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
Copy link
Member

fitzgen commented Jul 24, 2019

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
Copy link
Member

fitzgen commented Jul 24, 2019

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

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@fitzgen fitzgen merged commit 0cef4e2 into rustwasm:master Jul 24, 2019
@aaronabramov aaronabramov deleted the patch-1 branch July 24, 2019 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants