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

Optional chaining operator does not compile #15827

Closed
mmarczell-graphisoft opened this issue Dec 20, 2021 · 5 comments · Fixed by #19805
Closed

Optional chaining operator does not compile #15827

mmarczell-graphisoft opened this issue Dec 20, 2021 · 5 comments · Fixed by #19805

Comments

@mmarczell-graphisoft
Copy link
Contributor

This does not compile:

#include <emscripten.h>

int main() {
	EM_ASM({
		console?.log("");
	});
}

Error message:

/Volumes/SSD/git/emsdk/upstream/emscripten/third_party/terser/terser.js:8327
        var ret = node != null ? MOZ_TO_ME[node.type](node) : null;
                                                     ^

TypeError: MOZ_TO_ME[node.type] is not a function
    at from_moz (/Volumes/SSD/git/emsdk/upstream/emscripten/third_party/terser/terser.js:8327:54)
    at Object.ExpressionStatement (/Volumes/SSD/git/emsdk/upstream/emscripten/third_party/terser/terser.js:7468:23)
    at from_moz (/Volumes/SSD/git/emsdk/upstream/emscripten/third_party/terser/terser.js:8327:54)
    at Array.map (<anonymous>)
    at Object.From_Moz_BlockStatement [as BlockStatement] (eval at map (/Volumes/SSD/git/emsdk/upstream/emscripten/third_party/terser/terser.js:8313:21), <anonymous>:7:14)
    at from_moz (/Volumes/SSD/git/emsdk/upstream/emscripten/third_party/terser/terser.js:8327:54)
    at Object.FunctionExpression (/Volumes/SSD/git/emsdk/upstream/emscripten/third_party/terser/terser.js:7452:44)
    at from_moz (/Volumes/SSD/git/emsdk/upstream/emscripten/third_party/terser/terser.js:8327:54)
    at Object.Property (/Volumes/SSD/git/emsdk/upstream/emscripten/third_party/terser/terser.js:7500:28)
    at from_moz (/Volumes/SSD/git/emsdk/upstream/emscripten/third_party/terser/terser.js:8327:54)
emcc: error: '/Volumes/SSD/git/emsdk/node/14.15.5_64bit/bin/node /Volumes/SSD/git/emsdk/upstream/emscripten/tools/acorn-optimizer.js /var/folders/4c/w1bj9h4d5_df436ckn8xxmqr0000gq/T/emscripten_temp_h10gr7ju/main_temp.js AJSDCE minifyWhitespace' failed (returned 1)

This might be related to other problems with terser: #13297, #12410

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.0.0 (3fd52e107187b8a169bb04a02b9f982c8a075205)
clang version 14.0.0 (https://github.com/llvm/llvm-project 4348cd42c385e71b63e5da7e492172cff6a79d7b)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /Volumes/SSD/git/emsdk/upstream/bin

Failing command line in full:

emcc -O3 main.cpp -o main_temp.js
@mmarczell-graphisoft mmarczell-graphisoft changed the title Null coalescing operator does not compile Optional chaining operator does not compile Dec 20, 2021
@mmarczell-graphisoft
Copy link
Contributor Author

@sbc100 might this also be fixed by the recent terser update?

@sbc100
Copy link
Collaborator

sbc100 commented Jun 28, 2022

Yup! Looks like this works now. Thanks for following up.

@sbc100 sbc100 closed this as completed Jun 28, 2022
@sbc100 sbc100 reopened this Jun 28, 2022
@sbc100
Copy link
Collaborator

sbc100 commented Jun 28, 2022

Nope, I spoke to soon. Seems to still be an issue.

@sbc100
Copy link
Collaborator

sbc100 commented Jun 28, 2022

Looks like the version of terser we updated to still doesn't support ChainExpression

@dholl
Copy link

dholl commented May 25, 2023

This just bit me as well. I was inspired by this sample code from here:

if (!navigator.mediaDevices?.enumerateDevices) {
    console.log("enumerateDevices() not supported.");
}

My code was compiling & running with Debug or RelWithDebInfo builds, but my Release build was failing during the link stage with the same cryptic error:

/home/somewhere/emsdk/upstream/emscripten/third_party/terser/terser.js:21475
          var ret = node != null ? MOZ_TO_ME[node.type](node) : null;
                                                       ^
TypeError: MOZ_TO_ME[node.type] is not a function

When I instrumented terser.js file to print out node.type, I found "ChainExpression", and after figuring out what a ChainExpression was, I replaced the ?. in my code to get Release builds working again.

So, I'm happy for now and very appreciative of the work put into emscripten, but it took a while to figure out that optimized release builds are allergic to ?..

sbc100 added a commit that referenced this issue Jul 6, 2023
I was hoping this version would make optional chaining work but sadly
it looks like we will need to update v5 for that to work.

See #15827
sbc100 added a commit that referenced this issue Jul 6, 2023
I was hoping this version would make optional chaining work but sadly
it looks like we will need to update v5 for that to work.

See #15827
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 a pull request may close this issue.

3 participants