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

Infinite loop code generated with JSX + ES5 onChange attribute via anonymous function #2854

Closed
vvo opened this issue Nov 23, 2021 · 1 comment · Fixed by #3289
Closed

Infinite loop code generated with JSX + ES5 onChange attribute via anonymous function #2854

vvo opened this issue Nov 23, 2021 · 1 comment · Fixed by #3289

Comments

@vvo
Copy link

vvo commented Nov 23, 2021

Describe the bug

Hi there,

I discovered this bug while working on my big Next.js 12 application using SWC and then reduced it to a very simple example on a fresh new create-next-app with Next.js 12. And I was able to reproduce it on the SWC playground too.

PS: The playground share functionality is not working at the moment.

Input code

function App() {
  return <Form />
}

function Form({ onChange = function () {} }) {
  return (
    <input
      onChange={function () {
        onChange();
      }}
    />
  );
}

Output code

function App() {
    return React.createElement(Form, null);
}
function Form(param) {
    var _onChange = param.onChange, onChange = _onChange === void 0 ? function() {
    } : _onChange;
    return React.createElement("input", {
        onChange: function onChange() {
            onChange();
        }
    });
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": true
    },
    "target": "es5",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Playground link

SWC playground share functionality not working at the moment

Expected behavior

The generated code should not trigger an infinite loop

Version

1.2.11

Additional context

Do we need to rename anonymous functions when compiling to ES5?

Here's a live Next.js demo:

@vvo vvo added the C-bug label Nov 23, 2021
@kdy1 kdy1 modified the milestones: v1.2.112, v1.2.113, v1.2.114, v1.2.115 Nov 23, 2021
@kdy1 kdy1 modified the milestones: v1.2.115, v1.2.116, v1.2.117, v1.2.118, v1.2.119 Dec 1, 2021
@kdy1 kdy1 modified the milestones: v1.2.119, v1.2.120, v1.2.121 Dec 10, 2021
@kdy1 kdy1 modified the milestones: v1.2.121, v1.2.122, v1.2.123, v1.2.124 Dec 19, 2021
@kdy1 kdy1 modified the milestones: v1.2.124, v1.2.125 Dec 29, 2021
@kdy1 kdy1 modified the milestones: v1.2.126, v1.2.127 Jan 2, 2022
@kdy1 kdy1 modified the milestones: v1.2.127, v1.2.128, v1.2.129 Jan 5, 2022
@kdy1 kdy1 modified the milestones: v1.2.129, v1.2.130, v1.2.131 Jan 13, 2022
kdy1 added a commit to kdy1/swc that referenced this issue Jan 17, 2022
kdy1 added a commit that referenced this issue Jan 17, 2022
swc_ecma_transforms_base:
 - Ignore names of jsx attributes. (Closes #2854)
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 19, 2022

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 Oct 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging a pull request may close this issue.

3 participants