linaria icon indicating copy to clipboard operation
linaria copied to clipboard

Could not parse valid code

Open Mavrin opened this issue 3 years ago • 1 comments

Environment

  • Linaria version: 4.1.2
  • Bundler (+ version): webpack 5
  • Node.js version: 16
  • OS: Mac

Description

I have code:

function Root() {
  return <div>test</div>
}
function render() {}

function renderApp() {
  const reactElement = <Root></Root>;
  const rootElement = document.getElementById("root");
  render(reactElement, rootElement);
}

I get error:

Property body of FunctionDeclaration expected node to be of a type ["BlockStatement"] but instead got undefined

if I comment render(reactElement, rootElement);. Code will be parsed without errors.

Reproducible Demo

https://github.com/Mavrin/linaria-issue

Mavrin avatar Aug 01 '22 23:08 Mavrin

also expression like this could not be parsed

 const checkHoveredStateTimeoutId = useRef<ReturnType<typeof setTimeout> | null>();
Property exprName of TSTypeQuery expected node to be of a type ["TSEntityName","TSImportType"] but instead got undefined

Mavrin avatar Aug 02 '22 08:08 Mavrin

I also got the Property body of FunctionDeclaration expected node to be of a type ["BlockStatement"] but instead got undefined error on code like this:

import { useState } from 'react'

export function useBreakpoint(breakpoint: number): boolean {
  const [match] = useState(window.innerWidth >= breakpoint)

  return match
}

It worked once I extracted window.innerWidth >= breakpoint into a separate function.

kryops avatar Aug 14 '22 16:08 kryops