Skip to content

Curly braces and from keyword stripped off of import statements #7912

@3dos

Description

@3dos

Prettier 2.0.2
Playground link

--arrow-parens avoid
--parser babel
--no-semi
--single-quote
--trailing-comma none

You may wonder what would be the use case for this kind of behavior. It happened to me as I wrote a generator cli for a project creating several files based on user input data and automatically applying a prettier format when those are generated. One of the files provides the empty import statement with the comment in the middle of the curly braces to invite the developer to import what he should from a precise package.

I currently use the first version commented with // works in the example to work around the issue.

Input:

// works
import {} from 'something'

// breaks
import { /* comment */ } from 'some-package'

// breaks too
import {
  // Comment
} from 'some other package'

Output:

// works
import {} from 'something'

// breaks
import /* comment */ 'some-package'

// breaks too
import // Comment
'some other package'

Expected behavior:

// works
import {} from 'something'

// breaks
import { /* comment */ } from 'some-package'

// breaks too
import {
  // Comment
} from 'some other package'

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang: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