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 the exports variable in preamble.js to instExports #20231

Merged
merged 5 commits into from
Sep 12, 2023
Merged

Rename the exports variable in preamble.js to instExports #20231

merged 5 commits into from
Sep 12, 2023

Conversation

KeatonTech
Copy link
Contributor

This avoids a bug (or limitation) in Google's Closure compiler that does not allow any variable named exports to be reassigned. Without this change, some build configurations result in an error message like this:

[JSC_EXPORT_NOT_AT_MODULE_SCOPE] Exports must be at the top-level of a module  543|
     exports = Asyncify.instrumentWasmExports(exports);  

The Closure logic lives here, and is intended to block Closure's module exports object from getting reassigned.

Since the exports variable used in the preamble is not related to Closure modules, simply renaming the variable does the trick.

The name instExports is already used elsewhere in the preamble to refer to the same thing, so it seems like a good choice here as well.

This avoids a bug (or limitation) in Google's Closure compiler that does not allow any variable named `exports` to be reassigned. Without this change, some build configurations result in an error message like this:

```
[JSC_EXPORT_NOT_AT_MODULE_SCOPE] Exports must be at the top-level of a module  543|
     exports = Asyncify.instrumentWasmExports(exports);  
```

The Closure logic lives here, and is intended to block Closure's module exports object from getting reassigned: https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/ClosureCheckModule.java#L436

Since the exports variable used in the preamble is not related to Closure modules, simply renaming the variable does the trick.
@sbc100
Copy link
Collaborator

sbc100 commented Sep 12, 2023

The name we use elsewhere for this is wasmExports. Could we use the here (and then also we could remove line 985 maybe?)

src/preamble.js Outdated Show resolved Hide resolved
@sbc100 sbc100 enabled auto-merge (squash) September 12, 2023 17:51
@kripken kripken merged commit 143249e into emscripten-core:main Sep 12, 2023
2 checks passed
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.

3 participants