Skip to content

looks like leading comments wrong when var decls not ends with semi #9102

@HairyRabbit

Description

@HairyRabbit

Bug Report

Bugs maybe

Current Behavior
See the below astexplorer.net screenshots, the second var decl haven't leading comments:

image
image

If the first decl ends by semi, it works fine

Input Code

  • REPL or Repo link if applicable:

I write a plugin to transform my code, it works with the leading comments

var s = `
/**
 * @test
 */
const a = {
  b: 42
}

/**
 * @test
 */
const c = 42
`
require('@babel/core').transform(s, { plugins: [
  function plugin(path) {
    return {
      visitor: {
        VariableDeclaration(path) { console.log(path.node.leadingComments, path.toString()) }
      }
    }
  }
]})

output:

image

Environment

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Has PRarea: commentsoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: parser

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions