webstorm-styled-components icon indicating copy to clipboard operation
webstorm-styled-components copied to clipboard

An error appears randomly when using "css" function inside template string - ':' term expected"

Open vitalybe opened this issue 5 years ago • 10 comments

  • IDE name and version: WebStorm 2019.2.3 Build #WS-192.6817.13, built on September 24, 2019 Runtime version: 11.0.4+10-b304.69 x86_64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o macOS 10.13.6
  • Styled-components plugin version: 1.0.11

Problem description:

In some cases, when there is a css function inside templated string I'm getting the following error: ':' term expected

This error doesn't appear all the time. If I play around with the code it will randomly hide and appear later on. This error only appears when the plugin is enabled, so I assume it comes from it. This behavior seems to be a regression since I've been using the plugin for a long time and never saw it before.

Example of code that this error sometimes appear:

const OptionLabel = styled.div`
  ${(props: {}) => css`
    margin-bottom: 0.3em;
  `};
`;

Screenshot:

image

Adding/Removing a semicolon doesn't help. The only solution I found so far is to avoid nesting css entirely.

vitalybe avatar Oct 17 '19 12:10 vitalybe

Looks like it's still an issue

FedorSherbakov avatar Apr 18 '20 11:04 FedorSherbakov

Confirmed. Another workaround is putting the css string at the end.

Error:

const ErrorDiv = styled.div`
  ${(props: {}) =>
    css`
      color: red;
    `}
  color: blue;
`;

No Error:

export const NoErrorDiv = styled.div`
  color: blue;
  ${(props: {}) =>
    css`
      color: red;
    `}
`;

simon-ging avatar Jul 10 '20 09:07 simon-ging

Confirmed. Another workaround is putting the css string at the end.

Error:

const ErrorDiv = styled.div`
  ${(props: {}) =>
    css`
      color: red;
    `}
  color: blue;
`;

No Error:

export const NoErrorDiv = styled.div`
  color: blue;
  ${(props: {}) =>
    css`
      color: red;
    `}
`;

this solution didn't work in my case: Screenshot from 2020-08-25 19-43-49

I also added styled, media and css in the styled-components plugin settings

Sebdevar avatar Aug 25 '20 23:08 Sebdevar

👀

changyeamoon avatar Sep 01 '20 22:09 changyeamoon

This Issue has been open for almost a year now without any comment by maintainers. It would be nice to get some info about this bug.

  1. Is this registered as bug?
  2. Will this bug be fixed or is it being worked on?

Thank you for you support

I keep thinking there's an error in my file while it's simply this bug.

pixelass avatar Sep 03 '20 14:09 pixelass

The most annoying part of this issue is fixed in the latest 203 EAP, it was a bug inside the platform. I mean strange errors in those cases (issue):

const OptionLabel = styled.div`
  ${(props: {}) => css`
    margin-bottom: 0.3em;
  `};
`;

The next kind of errors should be fixed by the PR above. It's more complicated because it can't be fixed in 100% of cases. The provided heuristic checks whether the expression inside the template literal contains nested style-components injection. If so, we can assume that this expression is a complete and valid CSS fragment. For more details, see the pull request itself.

const ErrorDiv = styled.div`
  ${(props: {}) =>
    css`
      color: red;
    `}
  color: blue;
`;

Also, the 203 EAP finally allows formatting injections with multiple parts (issue). It works in the IDE by default, but for this plugin it will be enabled by the same PR above.

vepanimas avatar Sep 23 '20 19:09 vepanimas

@rosdi this is the wrong repository for your problem. This package is for styled-components or emotion

pixelass avatar Jan 25 '21 11:01 pixelass

sorry... deleted.

rosdi avatar Jan 27 '21 17:01 rosdi

@rosdi this is the wrong repository for your problem. This package is for styled-components or emotion

Does this support @emotion/styled? This comment is the only reference to it in the whole repository.

simonbuchan avatar Sep 28 '22 23:09 simonbuchan

Not sure if this is related, but getting same random "Term expected" message. No issues running the code or running lint. Screenshot 2024-04-05 at 23 46 59

joetidee avatar Apr 05 '24 22:04 joetidee