Skip to content

Don't recover from "adjacent jsx elements" parser error#10682

Merged
nicolo-ribaudo merged 1 commit intobabel:masterfrom
nicolo-ribaudo:adjacent-jsx-throw
Nov 8, 2019
Merged

Don't recover from "adjacent jsx elements" parser error#10682
nicolo-ribaudo merged 1 commit intobabel:masterfrom
nicolo-ribaudo:adjacent-jsx-throw

Conversation

@nicolo-ribaudo
Copy link
Copy Markdown
Member

Q                       A
Fixed Issues? prettier/prettier#6881
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Whenever we recover from a parser error, we have to build an invalid AST so that the recovered error is actionable by other tools.
While implementing error recovery, I missed that when we find adjacent JSX nodes I was just throwing away a lot of AST nodes.

This is causing problems with Prettier because, when we parse <a/><b/>, we just generate the AST for the first JSX element and thus prettier doesn't re-print the second one.

I considered wrapping the two nodes with a "fake" fragment, but I decided not to do it because of ASI which doesn't work with JSX elements: in this example, I would want to insert a comma after the first JSX element rather than having a fragment.

const el = do {
  let x = <span>x</span>

  <div>{x}</div>
}

@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: parser area: errors labels Nov 8, 2019
@nicolo-ribaudo nicolo-ribaudo merged commit 0287c0f into babel:master Nov 8, 2019
@nicolo-ribaudo nicolo-ribaudo deleted the adjacent-jsx-throw branch November 8, 2019 20:23
@lock lock Bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Feb 8, 2020
@lock lock Bot locked as resolved and limited conversation to collaborators Feb 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: errors outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants