swc
swc copied to clipboard
Parser crashes on `as` assertion
Describe the bug
Hi,
We faced a parser error while trying to use https://github.com/vitejs/vite-plugin-react-swc instead of the default Babel parser from ViteJS.
For the record, Babel failed (https://github.com/babel/babel/issues/15990#issuecomment-1729617074) to parse the following code in a similar fashion.
TS has absolutely no issue with it, see https://www.typescriptlang.org/play?ts=4.8.4&ssl=7&ssc=75&pln=1&pc=1#code/JYWwDg9gTgLgBAJQKYEMDGMA0cDecBiArgHYbATEDCE4FSx8AvnAGZQ1wBEUqGnA3AChBaCgGd4AWQCe1WsXrwAvHAA8AFUwA+ABRh2YMQC446gJRwlW3ILh24PGISjE1AE2AA3LXgBSAZQB5ADkAOgkoYGIAc2AWaT0DMQtGVQB6D28hRiERcXgAI0JgABs3GTlIBQZLNU1dCys4CpoqxQ1rFDECEjIKSroGDv4gA.
Input code
import React, { FunctionComponent } from "react";
const MyComponent = <T,>(props: T) => {
return <div>{ JSON.stringify(props) }</div>;
};
const buildMyComponent = <T,>() => MyComponent<T> as FunctionComponent<T>;
Config
No response
Playground link
https://play.swc.rs/?version=1.3.86&code=H4sIAAAAAAAAA22OzQrCMBCE73mKoScLRe82zUXwIKigfYHaHwnYTdlshVLy7rYKKugcZz5mxradY8GpLkpJMGLbUynW0cZNAdUkCGjYtYh4RqJUqdKRF%2ByHD5JB54lZdOw6v0YeIzMYFSZxLT0TdGXvZsTufDwsvbClq22GFx8j6NUcpyq8yy%2B9vVV%2FFp7NX77ODQr%2Fe3ry0wcTfPp32gAAAA%3D%3D&config=H4sIAAAAAAAAA1WPSw7CMAxE9z1F5DUL1AUL7sAhouBWQfkpdiWqqncnf2AXv5nJ2MckBLxIwV0c6ZmGICNhHHMitDuW70SA94Ckog4Ml64yZYnjhoWcVQCWcUXOIaT5Os8tAMZ7woQXaQgbs9rpZf%2BtVN6GiET%2FxmyVbjUjXxun1grWP7citlPyunWDG3xNvWx8DJoePVnuOD9fu6hdFgEAAA%3D%3D
SWC Info output
No response
Expected behavior
The parser should not fail.
Actual behavior
Syntax Error.
Version
1.3.86
Additional context
No response
@kdy1 I also opened https://github.com/microsoft/TypeScript/issues/55806 since it would be great to have parsing of as
to be changed in TSC too.