Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inserting children before or after JSXElement failing #9682

AbhiSivaprasad opened this Issue Mar 14, 2019 · 1 comment


None yet
2 participants
Copy link

AbhiSivaprasad commented Mar 14, 2019

Bug Report

Input Code



Expected behavior/code

  { /* JSXExpressionContainer */}

Current Behavior
Currently it is possible to insert a JSX Element as a sibling to a JSX element child using path.insertAfter or path.insertBefore. However, inserting a JSX expression container as a sibling is failing even though it is legal to have a JSX expression container sibling in the AST.

TypeError: Property body[0] of BlockStatement expected node to be of a type ["Statement"] but instead got "JSXExpressionContainer"
at validate (node_modules/@babel/types/lib/definitions/utils.js:128:13)
     at validator (node_modules/@babel/types/lib/definitions/utils.js:97:7)
     at Object.validate (node_modules/@babel/types/lib/definitions/utils.js:172:7)
     at validate (node_modules/@babel/types/lib/validators/validate.js:17:9)
     at builder (node_modules/@babel/types/lib/builders/builder.js:46:27)
     at Object.BlockStatement (node_modules/@babel/types/lib/builders/generated/index.js:260:31)
     at NodePath.replaceExpressionWithStatements (node_modules/@babel/traverse/lib/path/replacement.js:209:57)
     at NodePath.insertAfter (node_modules/@babel/traverse/lib/path/modification.js:128:17)
     at NodePath.replaceWithMultiple (node_modules/@babel/traverse/lib/path/replacement.js:85:22)
     at PluginPass.JSXElement (src/codemod/javascript/jsx.ts:30:17)

Scanning @babel/types, I see that JSXExpressionContainer does not alias with expression or statement which insertAfter and insertBefore require. However, since this is a valid AST it should be possible.


This comment has been minimized.

Copy link

babel-bot commented Mar 14, 2019

Hey @AbhiSivaprasad! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
that typically always has someone willing to help. You can sign-up here
for an invite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.