question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dead-code-elimination erroneously tries to inline expressions into JSXIdentifiers.

See original GitHub issue

Reproduction 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:open
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
hzoocommented, Nov 15, 2017

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)

0reactions
boopathicommented, Nov 18, 2017

Using isExpression sounds good

Aside: From the JSX Spec

JSXElementName :
  JSXIdentifier
  JSXNamespacedName
  JSXMemberExpression

I could go submit a quick PR to babel-types to get that changed and then make the non-JSX requiring PR here. Does that sound reasonable?

👍 Sure. Thanks.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found