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

Broken code for strict mode is generated #71

Open
Katarn opened this issue Apr 5, 2022 · 0 comments
Open

Broken code for strict mode is generated #71

Katarn opened this issue Apr 5, 2022 · 0 comments

Comments

@Katarn
Copy link

Katarn commented Apr 5, 2022

Hello.

I made a minimal example demonstrating the problem: https://github.com/Katarn/fast-async-bug.

Code from this file: https://github.com/Katarn/fast-async-bug/blob/master/src/index.js transpiled in the following code:

// <...>

"use strict";

// <...>

var MyClass = function () {
    function MyClass() {
        _classCallCheck(this, MyClass);
    }

    _createClass(MyClass, [{
        key: "run",
        value: function run() {
            return new Promise(function ($return, $error) {
                if (false) {}
                else {
                    if (false) {}
                    else {
                        return Promise.resolve(console.log("if block 3")).then(function ($await_5) {
                            try {
                                return $If_2.call(this);
                            } catch ($boundEx) {
                                return $error($boundEx);
                            }
                        }.bind(this), $error);
                    }

                    function $If_2() {
                        return $If_1.call(this);
                    }
                }

                function $If_1() {
                    return $return();
                }
            });
        }
    }]);

    return MyClass;
}();

// <...>

When I run it in an old browser that the @babel/preset-env polyfill is intended for, I get the following error in the console:

Uncaught SyntaxError: In strict mode code, functions can only be declared at top level or immediately within another function. 

You can reproduce the bug on Chromium build 205xxx and less, for example, from here: https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Win/. There are builds for other operating systems also.

@Katarn Katarn changed the title Broken code is generated in strict mode Broken code for strict mode is generated Apr 5, 2022
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

No branches or pull requests

1 participant