jsx tag namespace
v4.5.4, v4.6.0-dev.20211221
Playground link with relevant code
import React from "react"; function MyComponent() { return <svg : path />; }
TypeScript reports errors:
Type 'true' is not assignable to type 'string | undefined'. Identifier expected.
TypeScript compiler generates undesired JavaScript:
import React from "react"; function MyComponent() { return React.createElement("svg", { path: true }); }
It looks like TypeScript is interpreting svg : path similar to svg path. According to the JSX specification, whitespace is allowed around the : token.
svg : path
svg path
:
TypeScript treats the code as if it was the following:
import React from "react"; function MyComponent() { return <svg:path />; // Note: no spaces around ':'. }
generating the following JavaScript:
import React from "react"; function MyComponent() { return React.createElement("svg:path", null); }
Babel, ESLint, and Flow interpret the code this way. ESBuild seems to have the same interpretation as TypeScript.
We should parse this better, but namespaced elements are not yet supported. See also #7411
Activity
RyanCavanaugh commentedon Jan 4, 2022
We should parse this better, but namespaced elements are not yet supported. See also #7411