babel / babel/minify

plugin dead-code-elimination cannot handle arrow function to JSXIdentifier inside function

Open
#948 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
4.4k
Forks
217
PR merge metrics
No merged PRs in 30d

Description

## Bug Report

**Current Behavior**
use babel with `@babel/plugin-syntax-jsx` plugin to parse the following code snippet will lead to errors.

```
TypeError: Property name of JSXOpeningElement expected node to be of a type ["JSXIdentifier","JSXMemberExpression"] but instead got "ArrowFunctionExpression"
```

**Input Code**

snippet.js

```js
it("should support nested Profilers", () => {
const FunctionComponent = ({ label }) =>

{label}
;
return
});
```

but if you remove the top `it` function it will be parsed.

**Expected behavior/code**
parse successfully without errors

**Babel Configuration (.babelrc, package.json, cli command)**

```js
./node_modules/.bin/babel --plugins @babel/plugin-syntax-jsx snippet.js
```

**Environment**
- Babel version(s): v7.3.4
- Node/npm version: [Node 11/npm 6]
- OS: [OSX 10.13.6]
- How you are using Babel: cli

**Possible Solution**

**Additional context/Screenshots**
Add any other context about the problem here. If applicable, add screenshots to help explain.

Contributor guide

Open the contributing guide

Research direction

Start by running the provided Babel CLI command with @babel/plugin-syntax-jsx against snippet.js and reproducing the nested arrow-function JSX error. Trace how the dead-code-elimination plugin handles the JSXIdentifier inside the outer it function; done means the snippet parses successfully without the TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
babel, javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.