Skip to content

Duplicate declaration error is thrown on const declaration in nested async functions #8899

@JLHwung

Description

@JLHwung

Bug Report

Current Behavior
babel throws

Duplicate declaration "foo" (This is an error on an internal node. Probably an internal error.)

Input Code

  • REPL or Repo link if applicable:

https://babeljs.io/repl#?babili=false&browsers=Chrome%20%3E%3D%2045%2Clast%202%20Firefox%20versions%2Cie%20%3E%3D%209%2CEdge%20%3E%3D%2012%2CiOS%20%3E%3D%209%2CAndroid%20%3E%3D%204%2Clast%202%20ChromeAndroid%20versions&build=&builtIns=false&spec=false&loose=false&code_lz=BQQwzgngdgxgBMAlHAvAPjgbwFBzw8aeJVDHffGAeyjABc4AzKq1OAFgCYBuXfAX0RI-g4XiA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=&prettier=false&targets=&version=7.0.0-beta.34&envVersion=7.0.0-beta.34

Note: you have to manually add @babel/transform-regenerator 7.0.0 plugin since the url does not synchronize plugin selections.

(async () => {
    (async () => {
      const foo = 42;
    })()
  })()
  

Expected behavior/code
Compiled as regenerator calls

Babel Configuration (.babelrc, package.json, cli command)

module.exports = {
    plugins: [
        "@babel/transform-regenerator"
    ]
}

Environment

  • Babel version(s): v7.0.0
  • Node/npm version: Node 10
  • OS: macOS 10.14
  • Monorepo no
  • How you are using Babel: cli

Possible Solution
Workaround: add await to the nested async function.

Additional context/Screenshots
Possibly related: #8525

Metadata

Metadata

Assignees

No one assigned

    Labels

    outdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions