Skip to content

Prettier breaks with interpolation and complex CSS selector #2883

Closed

Description

@brikou

Prettier 1.7.0
Playground link

--parser typescript
--tab-width 4

Input:

export const foo = css`
&.foo .${bar}::before,&.foo[value="hello"] .${bar}::before {
	position: absolute;
}
`;

Output:

Error: Error: Couldn't insert all the expressions

Expected behavior:

export const foo = css`
    &.foo .${bar}::before,
    &.foo[value="hello"] .${bar}::before {
        position: absolute;
    }
`;

If I replace before,& by before, & (space before &), it works but is not pretty...

Thank you to look at this :D you are wonderful!

Activity

  1. brikou commented on Sep 23, 2017

    @brikou
    Author

    Here is another example

    Prettier 1.7.0
    Playground link

    --tab-width 4

    Input:

    export const foo = css`
    a.${bar}:focus,a.${bar}:hover {
      color: red;
    }
    `;

    Output:

    Error: Error: Couldn't insert all the expressions
  2. brikou commented on Sep 23, 2017

    @brikou
    Author

    another example, this one iis really anoying because no workaround can be applied (like adding a space)

    Prettier 1.7.0
    Playground link

    --tab-width 4

    Input:

    export const global = css`
    button.${foo}.${bar} {
      color: #fff;
    }
    `;

    Output:

    Error: Error: Couldn't insert all the expressions
  3. brikou commented on Sep 23, 2017

    @brikou
    Author

    Thanks @lydell for updating comments

  4. added
    lang:css/scss/less
    on Sep 23, 2017
  5. added
    area:multiparser
    on May 14, 2018
  6. fisker commented on Nov 19, 2019

    @fisker
    Member

    new Error

    Prettier 1.19.1
    Playground link

    --parser typescript
    --tab-width 4

    Input:

    export const foo = css`
    &.foo .${bar}::before,&.foo[value="hello"] .${bar}::before {
    	position: absolute;
    }
    `;

    Output:

    Error: Couldn't insert all the expressions
        at transformCssDoc (https://prettier.io/lib/standalone.js:22539:13)
        at Object.embed$3 [as embed] (https://prettier.io/lib/standalone.js:22377:20)
        at Object.printSubtree (https://prettier.io/lib/standalone.js:15170:30)
        at callPluginPrintFunction (https://prettier.io/lib/standalone.js:15288:31)
        at https://prettier.io/lib/standalone.js:15253:18
        at Object.printComments (https://prettier.io/lib/standalone.js:14974:19)
        at printGenerically (https://prettier.io/lib/standalone.js:15252:24)
        at FastPath.call (https://prettier.io/lib/standalone.js:15089:18)
        at printPathNoParens (https://prettier.io/lib/standalone.js:26413:92)
        at Object.genericPrint$3 [as print] (https://prettier.io/lib/standalone.js:24859:30)
  7. added
    locked-due-to-inactivity
    on Aug 6, 2020
  8. locked as resolved and limited conversation to collaborators on Aug 6, 2020
  9. added theissue type on Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:multiparserlang:css/scss/lesslocked-due-to-inactivity

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions