Skip to content

CSS in JS crashes with variable wrapped in quotes #5219

@SimenB

Description

@SimenB

Prettier 1.16.4
Playground link

--parser babel

Input:

import { css } from 'emotion';

const pathToFont = '/some/font';

const someStyle = css`
  src: "${pathToFont}";
`;

Output:

Error: Couldn't insert all the expressions
    at transformCssDoc (https://prettier.io/lib/standalone.js:22171:11)
    at Object.embed$4 [as embed] (https://prettier.io/lib/standalone.js:22011:18)
    at Object.printSubtree (https://prettier.io/lib/standalone.js:15781:31)
    at callPluginPrintFunction (https://prettier.io/lib/standalone.js:15898:29)
    at https://prettier.io/lib/standalone.js:15863:16
    at Object.printComments (https://prettier.io/lib/standalone.js:15586:17)
    at printGenerically (https://prettier.io/lib/standalone.js:15862:22)
    at FastPath.call (https://prettier.io/lib/standalone.js:15700:16)
    at printPathNoParens (https://prettier.io/lib/standalone.js:25178:91)
    at Object.genericPrint$3 [as print] (https://prettier.io/lib/standalone.js:23541:28)

Expected behavior:

For Prettier not to crash 😅

This is a reduced example, real world case is a @font-face declaration. I do think the quotes are not necessary, but Prettier shouldn't crash, it's valid CSS

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:multiparserIssues with printing one language inside another, like CSS-in-JSlang:css/scss/lessIssues affecting CSS, Less or SCSSlocked-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