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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Regression. Babel generates invalid code. #15111

Closed
1 task
andy128k opened this issue Nov 1, 2022 · 4 comments 路 Fixed by #15118
Closed
1 task

[Bug]: Regression. Babel generates invalid code. #15111

andy128k opened this issue Nov 1, 2022 · 4 comments 路 Fixed by #15118
Labels
i: bug i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: generator

Comments

@andy128k
Copy link

andy128k commented Nov 1, 2022

馃捇

  • Would you like to work on a fix?

How are you using Babel?

babel-loader (webpack)

Input code

import { apiLogout } from "../api";
import { reportError } from "../libs/report_error";

export function logout() {
  return reportError(async (/*dispatch*/) => {
    await apiLogout();
    window.location.reload();
  });
}

Configuration file name

babel.config.js

Configuration

module.exports = function(api) {
  const isTest = api.env('test');

  const envOptions = isTest
    ? {
      "targets": {
        "node": "current"
      }
    }
    : {
      modules: false,
      useBuiltIns: 'usage',
      corejs: "3.25",
      // debug: true,
    };

  return {
    "presets": [
      ["@babel/preset-env", envOptions],
      "@babel/preset-react"
    ],
  };
};

Current and expected behavior

After an upgrade from 7.19.3 to 7.19.6 I've got a following failure.

ERROR in ./assets/actions/user.js 12:5
Module parse failed: Unexpected token (12:5)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| export function logout() {
|   return reportError(async /*dispatch*/
>   () => {
|     await apiLogout();
|     window.location.reload();
 @ ./assets/actions/index.js 2:0-37 12:13-24
 @ ./assets/app.js 6:0-37 12:15-23

Babel inserts a new line and breaks async closure (I guess, auto-insertion of semicolon is involved).

The same error is reproducible in an online playground with other versions: 7.17.12 generates correct code while 7.20.1 generates invalid code

Environment

Environment w/o the issue

System:
OS: Linux 6.0 Debian GNU/Linux bookworm/sid
Binaries:
Node: 14.20.0 - ~/apps/nodejs/bin/node
Yarn: 1.22.19 - ~/apps/nodejs/bin/yarn
npm: 6.14.17 - ~/apps/nodejs/bin/npm
npmPackages:
@babel/core: ^7 => 7.19.3
@babel/eslint-parser: ^7 => 7.19.1
@babel/preset-env: ^7 => 7.19.3
@babel/preset-react: ^7 => 7.18.6
babel-jest: ^29 => 29.1.2
babel-loader: ^8.0.0 => 8.2.5
eslint: ^8.2 => 8.24.0
jest: ^29 => 29.1.2
webpack: ^5 => 5.74.0

Environment with the issue (after yarn upgrade)

System:
OS: Linux 6.0 Debian GNU/Linux bookworm/sid
Binaries:
Node: 14.20.0 - ~/apps/nodejs/bin/node
Yarn: 1.22.19 - ~/apps/nodejs/bin/yarn
npm: 6.14.17 - ~/apps/nodejs/bin/npm
npmPackages:
@babel/core: ^7 => 7.19.6
@babel/eslint-parser: ^7 => 7.19.1
@babel/preset-env: ^7 => 7.19.4
@babel/preset-react: ^7 => 7.18.6
babel-jest: ^29 => 29.2.2
babel-loader: ^8.0.0 => 8.2.5
eslint: ^8.2 => 8.26.0
jest: ^29 => 29.2.2
webpack: ^5 => 5.74.0

Possible solution

No response

Additional context

No response

@babel-bot
Copy link
Collaborator

Hey @andy128k! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.

@nicolo-ribaudo
Copy link
Member

Introduced by #15080, I'll work on a fix.

@arredgroup
Copy link

Hi! I have the same issue :(

@liuxingbaoyu
Copy link
Member

@arredgroup Hi, have you tried the latest version?

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Feb 4, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: generator
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants