dead-code-elimination erroneously tries to inline expressions into JSXIdentifiers.
See original GitHub issueReproduction on RunKit: https://runkit.com/tolmasky/dead-code-inlines-jsxidentifiers
function Input(element)
{
var ElementType = element || "input";
return <ElementType ref = "input" />;
}
This will try to put (element || "input")
into the actual JSX element, (something like <(element||"input") ref = "input/>
), which is not allowed, and will thus throw this error:
TypeError: unknown: Property name of JSXOpeningElement expected node to be of a type [“JSXIdentifier”,“JSXMemberExpression”] but instead got “LogicalExpression”
It is important that I run this before my actual React transforms, since there are in-between transforms that rely on the right code having been removed, so I can not use as a temporary workaround switching the order of the transformations.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Can no longer inject style rule from a const string since ...
It seems impossible to inject a style rule from a const string using styled-jsx version 2. Since this feature was supported in version...
Read more >How to find dead code in a large react project?
Solution: For node projects, run the following command in your project root: npx unimported. If you're using flow type annotations, ...
Read more >API - esbuild
Dead -code elimination within function bodies; Function inlining; Cross-statement constant propagation; Object shape modeling; Allocation sinking; Method ...
Read more >Strict mode - JavaScript - MDN Web Docs
Strict mode makes several changes to normal JavaScript semantics: Eliminates some JavaScript silent errors by changing them to throw errors.
Read more >Introducing JSX
It is called JSX, and it is a syntax extension to JavaScript. We recommend using it with React to ... Embedding Expressions in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I believe this is because @tolmasky actually is using jsx as code instead of for react? yeah hard to say since it does feel wrong to add all these workarounds everywhere (unless we could make that generic too)
Using
isExpression
sounds goodAside: From the JSX Spec
👍 Sure. Thanks.