Skip to content

Wrong cursorOffset with multi-line comment #14811

@hyrious

Description

@hyrious

Environments:

  • Prettier Version: 2.8.8
  • Running Prettier via: Node.js API
  • Runtime: Node.js 18.16.0
  • Operating System: macOS
  • Prettier plugins (if any):

Steps to reproduce:

Save this script and run it:

import prettier from "prettier";

const code = `
// All messages are represented in JSON.
// So, the prettierd.py controls a subprocess which spawns "node {this_file}".
import {  } from "fs"
`; //   ^ cursor here

console.log(
  prettier.formatWithCursor(code, {
    cursorOffset: 129,
    parser: "babel",
  })
); // => { cursorOffset: 65 }

Expected behavior:

Expect the returned cursorOffset to be around 129, right in the {}.

Actual behavior:

It returns 65, which is in the comments.

Frankly, I don't even find a minimal case to reproduce this issue (the code above is all I could make, changing any line of the comment may make the result correct).

Metadata

Metadata

Assignees

Labels

area:rangesIssues about formatting/ignoring/etc segments of fileslang:javascriptIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions