Skip to content

Casting error while parsing code #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mstarkman opened this issue Sep 2, 2017 · 7 comments
Closed

Casting error while parsing code #16

mstarkman opened this issue Sep 2, 2017 · 7 comments
Labels

Comments

@mstarkman
Copy link

Error Message:

com.intellij.lang.javascript.psi.impl.JSCallExpressionImpl cannot be cast to com.intellij.lang.javascript.psi.JSReferenceExpression

Details:

java.lang.ClassCastException: com.intellij.lang.javascript.psi.impl.JSCallExpressionImpl cannot be cast to com.intellij.lang.javascript.psi.JSReferenceExpression
	at com.intellij.StyledComponents.PatternsKt.getReferenceParts(Patterns.kt:54)
	at com.intellij.StyledComponents.PatternsKt$withNameStartingWith$1.accepts(Patterns.kt:41)
	at com.intellij.StyledComponents.PatternsKt$withNameStartingWith$1.accepts(Patterns.kt:39)
	at com.intellij.patterns.ObjectPattern.accepts(ObjectPattern.java:58)
	at com.intellij.patterns.CollectionPattern$5.accepts(CollectionPattern.java:80)
	at com.intellij.patterns.CollectionPattern$5.accepts(CollectionPattern.java:77)
	at com.intellij.patterns.ObjectPattern.accepts(ObjectPattern.java:58)
	at com.intellij.patterns.PatternConditionPlus.process(PatternConditionPlus.java:45)
	at com.intellij.patterns.PatternConditionPlus.process(PatternConditionPlus.java:26)
	at com.intellij.patterns.TreeElementPattern$2.processValues(TreeElementPattern.java:88)
	at com.intellij.patterns.PatternConditionPlus.accepts(PatternConditionPlus.java:41)
	at com.intellij.patterns.ObjectPattern.accepts(ObjectPattern.java:58)
	at com.intellij.patterns.StandardPatterns$3.accepts(StandardPatterns.java:118)
	at com.intellij.patterns.ObjectPattern.accepts(ObjectPattern.java:53)
	at com.intellij.patterns.CollectionPattern$3.accepts(CollectionPattern.java:55)
	at com.intellij.patterns.CollectionPattern$3.accepts(CollectionPattern.java:52)
	at com.intellij.patterns.ObjectPattern.accepts(ObjectPattern.java:58)
	at com.intellij.patterns.PatternConditionPlus.process(PatternConditionPlus.java:45)
	at com.intellij.patterns.PatternConditionPlus.process(PatternConditionPlus.java:26)
	at com.intellij.patterns.TreeElementPattern$2.processValues(TreeElementPattern.java:88)
	at com.intellij.patterns.PatternConditionPlus.accepts(PatternConditionPlus.java:41)
	at com.intellij.patterns.ObjectPattern.accepts(ObjectPattern.java:58)
	at com.intellij.patterns.PatternConditionPlus.process(PatternConditionPlus.java:45)
	at com.intellij.patterns.PatternConditionPlus.process(PatternConditionPlus.java:26)
	at com.intellij.patterns.TreeElementPattern$4.processValues(TreeElementPattern.java:127)
	at com.intellij.patterns.PatternConditionPlus.accepts(PatternConditionPlus.java:41)
	at com.intellij.patterns.ObjectPattern.accepts(ObjectPattern.java:58)
	at com.intellij.patterns.ObjectPattern.accepts(ObjectPattern.java:48)
	at com.intellij.StyledComponents.StyledComponentsInjector.getLanguagesToInject(StyledComponentsInjector.kt:38)
	at com.intellij.psi.impl.source.tree.injected.InjectedPsiCachedValueProvider$MyInjProcessor.process(InjectedPsiCachedValueProvider.java:82)
	at com.intellij.psi.impl.source.tree.injected.InjectedLanguageManagerImpl.processInPlaceInjectorsFor(InjectedLanguageManagerImpl.java:461)
	at com.intellij.psi.impl.source.tree.injected.InjectedPsiCachedValueProvider.doCompute(InjectedPsiCachedValueProvider.java:62)
	at com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil.probeElementsUp(InjectedLanguageUtil.java:312)
	at com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil.enumerate(InjectedLanguageUtil.java:144)
	at com.intellij.codeInsight.daemon.impl.InjectedGeneralHighlightingPass.a(InjectedGeneralHighlightingPass.java:185)
	at com.intellij.concurrency.ApplierCompleter.a(ApplierCompleter.java:133)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1161)
	at com.intellij.concurrency.ApplierCompleter.b(ApplierCompleter.java:105)
	at com.intellij.openapi.progress.impl.CoreProgressManager.a(CoreProgressManager.java:548)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:493)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:94)
	at com.intellij.concurrency.ApplierCompleter.a(ApplierCompleter.java:116)
	at com.intellij.concurrency.ApplierCompleter.c(ApplierCompleter.java:96)
	at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:142)
	at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:250)
	at com.intellij.concurrency.ApplierCompleter.compute(ApplierCompleter.java:96)
	at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

This is the file that it seems to be failing on:

const ListItemWrapper = styled.div`
  display: flex;
  align-items: center;
  min-width: 0;
  height: 5.125rem;
  margin-top: ${smallSpacing};
  padding-right: ${smallSpacing};
  background-color: ${pureWhite};
  cursor: pointer;

  &:hover {
    box-shadow: ${bottomBoxShadow};
  }
`

const TypeIconWrapper = styled.div`
  display: flex;
  flex: 0 0 5.125rem;
  align-items: center;
  justify-content: center;
  height: 100%;
  background-color: ${lightPink};

  ${toTablet} { /* stylelint-disable-line */
    /* stylelint-disable-next-line declaration-empty-line-before */
    flex: 0 0 4px;
  }

  ${ListItemWrapper}:hover & { /* stylelint-disable-line */
    /* stylelint-disable-next-line declaration-empty-line-before */
    background-color: ${mediumPink};
  }
`

const StyledTypeIcon = styled(Icon)`
  display: flex;

  ${toTablet} { /* stylelint-disable-line */
    /* stylelint-disable-next-line declaration-empty-line-before */
    display: none;
  }
`

const Avatar = styled.div`
  flex: 0 0 2.714rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.714rem;
  margin: 0 1.3125rem;
  padding: 0;
  border-radius: 50%;
  background-color: ${ruleGray};
  color: ${lightBlack};
  font-size: 1rem;
  font-weight: 400;
  line-height: 0;
`

const ClientWrapper = styled.div`
  display: flex;
  flex: 1 1 0;
  flex-wrap: wrap;
  align-content: center;
  align-items: center;
  justify-content: flex-start;
  min-width: 0;
`

const ClientName = styled.div`
  flex: 1 1 auto;
  font-size: 1.29rem;
  line-height: 1.556em;
  ${typTruncating}

  ${ListItemWrapper}:hover & { /* stylelint-disable-line */
    /* stylelint-disable-next-line declaration-empty-line-before */
    color: ${hpPink};
  }
`

const ClientStatus = styled.div`
  ${typMiniLabels}
  flex: 1 1 100%;
`

const CallToActionWrapper = styled.div`
  display: none;
  flex: 0 1 10%;
  align-content: center;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  margin-right: ${mediumSpacing};

  ${fromTablet} { /* stylelint-disable-line */
    /* stylelint-disable-next-line declaration-empty-line-before */
    ${ListItemWrapper}:hover & { /* stylelint-disable-line */
      /* stylelint-disable-next-line declaration-empty-line-before */
      display: flex;
    }
  }
`

const ContactMenu = styled.div`
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
`

const ContactMenuDropdownTrigger = styled.div`
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  cursor: pointer;
`

const ContactMenuIcon = styled(Icon).attrs({ iconName: 'contact_card' })`
  line-height: 0;

  ${ContactMenu}:hover & { /* stylelint-disable-line */
    /* stylelint-disable-next-line declaration-empty-line-before */
    svg path,
    svg polygon {
      fill: ${actionColor};
    }
  }

  ${toTablet} { /* stylelint-disable-line */
    /* stylelint-disable-next-line declaration-empty-line-before */
    display: none;
  }
`

const ContactMenuDownArrow = styled(Icon).attrs({ iconName: 'down_arrow' })`
  line-height: 0;
`
@mstarkman
Copy link
Author

@daedlock This is from version 1.0.

image

@daedlock
Copy link
Member

daedlock commented Sep 3, 2017

Reproduced on Intellij 2017.2

This seems be the trigger

const ContactMenuIcon = styled(Icon).attrs({ iconName: 'contact_card' })`
...
`;

If we remove the following, the error disappears.

.attrs({ iconName: 'contact_card' })

@undeadcat. If I am not mistaken, it's an issue with Patterns.kt#getReferencePart() expecting a reference expression while it's getting a call expression.

@daedlock daedlock added the bug label Sep 3, 2017
undeadcat added a commit to undeadcat/webstorm-styled-components that referenced this issue Sep 3, 2017
@undeadcat
Copy link
Contributor

D'oh!
Fixed. Thanks.

@mstarkman If you've downloaded the plugin from the IDE (not via zip file), the IDE will show a notification when the plugin can be updated.

I would aim to publish a new version by end of monday - tuesday, possibly with fixes for other issues if that's ok with everyone. I would not publish a new version for every bug because too many 'update available' notifications can be annoying.

@daedlock
Copy link
Member

daedlock commented Sep 3, 2017

@undeadcat. Agreed

@mstarkman
Copy link
Author

Thanks @undeadcat! I'll keep an eye out for it in the IDE. Does the also cover the case of using extend.attrs({}) (https://www.styled-components.com/docs/basics#extending-styles)? We use that also and wasn't covered by another tool, so I just wanted to ask. This would be some example code:

const StyledIcon = styled(Icon)`
  height: 24px;
  width: 24px;
`

const FilterIcon = StyledIcon.extend.attrs({ iconName: 'filter' })`
  line-height: 0;
  margin-right: 1rem;
`

daedlock added a commit that referenced this issue Sep 4, 2017
Fix #16, update description in plugin.xml
@daedlock
Copy link
Member

daedlock commented Sep 4, 2017

@mstarkman
Copy link
Author

@daedlock This seems to be working in most cases for my code. However, the .extend.attrs({}) still isn't working properly. I've created a separate issue for it here: #28.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants