swc-project / swc

Rust-based platform for the Web

Home Page:https://swc.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Regression in `v1.4.15`: `ReferenceError: resource is not defined` in strict mode

jeengbe opened this issue · comments

Describe the bug

Updating from .14 -> .15, code with using fails in strict mode with ReferenceError: resource is not defined.

This is the generated _using_ctx():

        function _using_ctx() {
            var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
                var err = new Error();
                err.name = "SuppressedError";
                err.suppressed = suppressed;
                err.error = error;
                return err;
            }
              , empty = {}
              , stack = [];
            function using(isAwait, value) {
                if (value != null) {
                    if (Object(value) !== value) {
                        throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
                    }
                    if (isAwait) {
                        var dispose = value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
                    }
                    if (dispose == null) {
                        dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
                    }
                    if (typeof dispose !== "function") {
                        throw new TypeError(`Property [Symbol.dispose] is not a function.`);
                    }
                    stack.push({
                        v: value,
                        d: dispose,
                        a: isAwait
                    });
                } else if (isAwait) {
                    stack.push({
                        d: value,
                        a: isAwait
                    });
                }
                return value;
            }
            return {
                e: empty,
                u: using.bind(null, false),
                a: using.bind(null, true),
                d: function() {
                    var error = this.e;
                    function next() {
                        while (resource = stack.pop()) {
                        //     ^^^^^ fails here
                            try {
                                var resource1, disposalResult = resource1.d && resource1.d.call(resource1.v);
                                if (resource1.a) {
                                    return Promise.resolve(disposalResult).then(next, err);
                                }
                            } catch (e) {
                                return err(e);
                            }
                        }
                        if (error !== empty)
                            throw error;
                    }
                    function err(e) {
                        error = error !== empty ? new _disposeSuppressedError(error,e) : e;
                        return next();
                    }
                    return next();
                }
            };

The test is run in strict mode.

Input code

No response

Config

      '@swc/jest',
      {
        jsc: {
          parser: {
            syntax: 'typescript',
            decorators: true,
          },
        },
      },

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.4.15&code=H4sIAAAAAAAAAystzsxLV6hQsFUoy89MUTCwBgAGGiiaEQAAAA%3D%3D&config=H4sIAAAAAAAAA1WPSw7DIAwF9zkF8rrbdtE79BCIOhERP9mOVBTl7oUE0maH3xszsA5KwcwGnmotxzIkTYx0ziXhHER%2FSgKSE7IhmwRuvRWu1agd4x5tRwOiaUKpW8j3hoOLkbHjLfM22DH%2FC030iZD5ClZUh8nhVTc0Jfj4XvayfaQ%2B9tA%2F4Ad12XkxWH71TaEFh%2B0LYuVI0xQBAAA%3D

Note that the produced code has to be run in strict mode.

SWC Info output

No response

Expected behavior

n/a

Actual behavior

No response

Version

1.4.15

Additional context

This change broke it: #8860

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.