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

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

Closed
jeengbe opened this issue Apr 17, 2024 · 1 comment · Fixed by #8874
Closed

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

jeengbe opened this issue Apr 17, 2024 · 1 comment · Fixed by #8874
Assignees
Labels
Milestone

Comments

@jeengbe
Copy link

jeengbe commented Apr 17, 2024

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

@jeengbe jeengbe added the C-bug label Apr 17, 2024
@jeengbe jeengbe changed the title Regression in v1.4.15: ReferenceError: resource is not defined with using code Regression in v1.4.15: ReferenceError: resource is not defined in strict mode Apr 17, 2024
@kdy1 kdy1 self-assigned this Apr 17, 2024
@kdy1 kdy1 added this to the Planned milestone Apr 17, 2024
kdy1 added a commit that referenced this issue Apr 18, 2024
@kdy1 kdy1 modified the milestones: Planned, v1.4.16 Apr 18, 2024
@swc-bot
Copy link
Collaborator

swc-bot commented May 18, 2024

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.

@swc-project swc-project locked as resolved and limited conversation to collaborators May 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants