Skip to content

async <T,>() => {} + new line + (...) is transformed to IIFE #17472

@hi-ogawa

Description

@hi-ogawa

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

reproduction on repl https://babeljs.io/repl#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&corejs=3.42&code_lz=IYZwngdgxgBAPAFQDQD4AUBKGBeFMDeAvgFBoCMGA3EA&shippedProposals=true&evaluate=true&sourceType=module&lineWrap=true&presets=typescript&prettier=true&version=7.28.2

async <T,>() => {}
(1);

Configuration file name

No response

Configuration

see repl

Current and expected behavior

Current behavior: transformed to IIFE and changes semantics

(async () => {})(1);

Expected behavior: it shouldn't change semantics. for example, tsc's output https://www.typescriptlang.org/play/?module=1#code/IYZwngdgxgBAPAFQDQD4AUBKGBeFMDeAvgFBoCMGA3EA

"use strict";
async () => { };
(1);

Environment

(repl)
babel: 7.28.2

Possible solution

No response

Additional context

Originally reported in vitejs/vite-plugin-react#690, which had slightly more complex code:

const funA = async <T,>(arg1: T) => {
  console.log(arg1)
}
(a as A).register(funA);

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: typescriptoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: parser

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions