Skip to content

CSS in JS crashes with variable wrapped in quotes #5219

Closed

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

Activity

  1. SimenB commented on Feb 11, 2019

    @SimenB
    ContributorAuthor

    Still an issue in 1.16 (updated the OP)

  2. added
    lang:css/scss/less
    area:multiparser
    on Feb 11, 2019
  3. StephenHaney commented on May 25, 2019

    @StephenHaney

    Possibly related: I get the same error when I have too many interpolations in my Styled Components I'm trying to format.

    In this Playground link, remove one interpolation block to successfully output prettified code. The syntax inside the blocks is identical, so it's just the number of interpolation blocks that causes the crash.

    Playground Link

  4. fisker commented on Nov 4, 2019

    @fisker
    Member

    minimum reproduction

    Prettier 1.18.2
    Playground link

    --parser typescript
    --single-quote
    --tab-width 5
    --use-tabs

    Input:

    css`
      src: "${pathToFont}";
    `

    Output:

    transformCssDoc@https://prettier.io/lib/standalone.js:22212:11
    embed$4@https://prettier.io/lib/standalone.js:22050:18
    printSubtree@https://prettier.io/lib/standalone.js:15816:31
    callPluginPrintFunction@https://prettier.io/lib/standalone.js:15934:29
    printGenerically/res<@https://prettier.io/lib/standalone.js:15899:16
    printComments@https://prettier.io/lib/standalone.js:15621:22
    printGenerically@https://prettier.io/lib/standalone.js:15898:22
    call@https://prettier.io/lib/standalone.js:15735:24
    printPathNoParens@https://prettier.io/lib/standalone.js:25282:91
    genericPrint$3@https://prettier.io/lib/standalone.js:23704:45
    callPluginPrintFunction@https://prettier.io/lib/standalone.js:15948:18
    printGenerically/res<@https://prettier.io/lib/standalone.js:15899:16
    printComments@https://prettier.io/lib/standalone.js:15621:22
    printGenerically@https://prettier.io/lib/standalone.js:15898:22
    call@https://prettier.io/lib/standalone.js:15735:24
    printPathNoParens@https://prettier.io/lib/standalone.js:24018:30
    genericPrint$3@https://prettier.io/lib/standalone.js:23704:45
    callPluginPrintFunction@https://prettier.io/lib/standalone.js:15948:18
    printGenerically/res<@https://prettier.io/lib/standalone.js:15899:16
    printComments@https://prettier.io/lib/standalone.js:15621:22
    printGenerically@https://prettier.io/lib/standalone.js:15898:22
    printStatementSequence/<@https://prettier.io/lib/standalone.js:26174:28
    map@https://prettier.io/lib/standalone.js:15801:21
    printStatementSequence@https://prettier.io/lib/standalone.js:26158:8
    printPathNoParens/<@https://prettier.io/lib/standalone.js:23987:16
    call@https://prettier.io/lib/standalone.js:15735:24
    printPathNoParens@https://prettier.io/lib/standalone.js:23986:23
    genericPrint$3@https://prettier.io/lib/standalone.js:23704:45
    callPluginPrintFunction@https://prettier.io/lib/standalone.js:15948:18
    printGenerically/res<@https://prettier.io/lib/standalone.js:15899:16
    printComments@https://prettier.io/lib/standalone.js:15621:22
    printGenerically@https://prettier.io/lib/standalone.js:15898:22
    printAstToDoc@https://prettier.io/lib/standalone.js:15910:32
    coreFormat@https://prettier.io/lib/standalone.js:16229:24
    format@https://prettier.io/lib/standalone.js:16476:73
    formatWithCursor@https://prettier.io/lib/standalone.js:16492:12
    withPlugins/<@https://prettier.io/lib/standalone.js:30992:15
    format@https://prettier.io/lib/standalone.js:31000:12
    formatCode@https://prettier.io/worker.js:234:21
    handleMessage@https://prettier.io/worker.js:185:18
    self.onmessage@https://prettier.io/worker.js:155:14
  5. alexander-akait commented on Nov 5, 2019

    @alexander-akait
    Member
  6. added
    locked-due-to-inactivity
    on Aug 6, 2020
  7. locked as resolved and limited conversation to collaborators on Aug 6, 2020
  8. 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