Skip to content

Broken code for strict mode is generated #71

Open

Description

@Katarn

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.

Activity

  1. changed the title [-]Broken code is generated in strict mode[/-] [+]Broken code for strict mode is generated[/+] on Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions