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

Throw unexpected token error for } and > in JSXText nodes #108

Merged
merged 5 commits into from
Feb 26, 2020

Conversation

kaicataldo
Copy link
Contributor

@kaicataldo kaicataldo commented Jan 23, 2020

Fixes #106

Thoughts on the error message? The corresponding PR to babel also lists the HTML entity.

This is my first time contributing to this repository, so please let me know if I should be doing anything differently.

}
}
},
// '<LeftRight left=<a /> right=<b>monkeys /> gorillas</b> />': {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on what to do with this? It looks like this this is still in the test suite.

Copy link
Contributor Author

@kaicataldo kaicataldo Jan 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this was altered to the correct form in the corresponding PR to babel. Should we do the same here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this to include valid as well as invalid variants of this.

@@ -3958,3 +3958,657 @@ for (var ns in fbTestFixture) {
});
}
}

testFail("<LeftRight left=<a /> right=<b>monkeys /> gorillas</b> />", 'Unexpected token. Did you mean {">"} instead? (1:40)')
testFail("<A>foo{</A>", "Unexpected token (1:8)")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These already throw an error.


testFail("<LeftRight left=<a /> right=<b>monkeys /> gorillas</b> />", 'Unexpected token. Did you mean {">"} instead? (1:40)')
testFail("<A>foo{</A>", "Unexpected token (1:8)")
testFail("<A>foo<</A>", "Unexpected token (1:7)")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These already throw an error.

@RReverser
Copy link
Member

Thanks for the PR.

I'm surprised this was not noticed for literally years since the change to spec was made... On one hand, it seems reasonable to fix it, but on another, I'm worried about breaking backwards compatibility in case there are projects that depend on this (and it seems all of the tools happily accepted these chars before).

@kaicataldo
Copy link
Contributor Author

Thanks for the review!

I believe both Babel and TypeScript are adding this error, and ESLint is currently working on a major release in which we could add this breaking change. Another option on the ESLint side of things would be to check this in Espree, though I’m not sure of the performance implications of that, and it does feel to me like this should be in this plugin.

Totally understand where you’re coming from, though! If this isn’t likely to land, I can explore the alternative I laid out above.

@RReverser
Copy link
Member

RReverser commented Jan 26, 2020

@kaicataldo I wonder if it would make sense to:

  1. Land this in Acorn JSX under an option (disabled by default).
  2. Land this in major ESLint release with that option enabled by default.
  3. Wait couple of months (?) until projects update.
  4. Flip the default in major Acorn JSX release.

UPD: Or, I guess, we could just ship this in a major Acorn JSX now, given that there is little or no planned maintenance for the current major version.

@kaicataldo
Copy link
Contributor Author

Either of those options sounds good to me! What would you prefer?

@kaicataldo kaicataldo force-pushed the disallow-jsxtext-tokens branch from 976d571 to 88ffffc Compare January 26, 2020 18:50
@kaicataldo kaicataldo force-pushed the disallow-jsxtext-tokens branch from 88ffffc to a5ebc8e Compare January 26, 2020 18:54
@kaicataldo kaicataldo force-pushed the disallow-jsxtext-tokens branch from b09b210 to b8654eb Compare January 26, 2020 19:06
@kaicataldo kaicataldo force-pushed the disallow-jsxtext-tokens branch from 08ac2f8 to 71541e5 Compare January 26, 2020 19:16
@kaicataldo
Copy link
Contributor Author

Just wanted to follow up to see how you'd like to proceed. Thanks!

@RReverser
Copy link
Member

I suppose we can even publish this as 5.2.0 - technically it's a minor breaking change, and semver-wise this would still prevent accidental automatic upgrade.

@kaicataldo
Copy link
Contributor Author

That makes sense to me. Is there anything else you need from me before merging this?

@RReverser
Copy link
Member

No, sorry, just been busy. I'll try to get to this on the weekend.

@kaicataldo
Copy link
Contributor Author

No worries! Just wanted to make sure I wasn't holding anything up :)

@RReverser RReverser merged commit d886ffc into acornjs:master Feb 26, 2020
@RReverser
Copy link
Member

Apologies for the delay, and thanks again for the PR! Released as 5.2.0.

@kaicataldo
Copy link
Contributor Author

No worries! Thanks for maintaining this project :)

@kaicataldo kaicataldo deleted the disallow-jsxtext-tokens branch February 26, 2020 16:48
@ljharb
Copy link

ljharb commented Mar 2, 2020

This minor release did, indeed, break eslint-plugin-react: jsx-eslint/eslint-plugin-react#2583. There are no "minor" breaking changes :-(

@RReverser
Copy link
Member

@ljharb I'm sorry for that :( This was a tough choice with unclear fallout due to it being, in theory, a bugfix to what should've never worked. I suppose unpublishing at this point might equally break users who started relying on the new version, so will have to leave as-is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: throw syntax error for } and > in JSX text.
3 participants