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

Improve error range for ts2657 (jsx expr must have parent element), add code fix for it #37917

Merged
merged 9 commits into from
Jun 1, 2020

Conversation

Jack-Works
Copy link
Contributor

Before:
image

After:
Only one error with the correct length (but trivia is included, I don't know how to remove it from the error range)
image

With code fix:
image

After code fix:
image

After fix all:
image

@sandersn sandersn added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Apr 21, 2020
Copy link
Member

@andrewbranch andrewbranch left a comment

Choose a reason for hiding this comment

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

Just a few nits; I think this looks like a big improvement.

src/compiler/diagnosticMessages.json Outdated Show resolved Hide resolved
src/compiler/parser.ts Outdated Show resolved Hide resolved
src/compiler/checker.ts Outdated Show resolved Hide resolved
@@ -28347,7 +28347,15 @@ namespace ts {
}
case SyntaxKind.CommaToken:
if (!compilerOptions.allowUnreachableCode && isSideEffectFree(left) && !isEvalNode(right)) {
error(left, Diagnostics.Left_side_of_comma_operator_is_unused_and_has_no_side_effects);
const sf = getSourceFileOfNode(left);
const isInDiag2657 = sf.parseDiagnostics.some(diag => {
Copy link
Member

Choose a reason for hiding this comment

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

You could consider using forEach or a for/of loop to terminate once diag.start > left.end.

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 didn't catch that, Array.some can quite early, I think it is same as for/of + break

Copy link
Member

Choose a reason for hiding this comment

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

I mean that with .some, if you don’t find the diagnostic you’re looking for, you’ll keep looking all the way to the end of the array. But since these diagnostics are added in the order that the parser sees them, you know that after you move all the way past the end of left, you’re not going to find what you’re looking for at all. So while .some can terminate early in the positive case, you also have an opportunity to terminate early in the negative case.

That said, I don’t think it’s a big deal since this is an error scenario and the body of the loop isn’t expensive.

src/compiler/parser.ts Outdated Show resolved Hide resolved
src/compiler/diagnosticMessages.json Outdated Show resolved Hide resolved
src/compiler/parser.ts Show resolved Hide resolved
@Jack-Works
Copy link
Contributor Author

rebased to resolve conflict

@Jack-Works
Copy link
Contributor Author

rebased to resolve conflict again

src/compiler/diagnosticMessages.json Outdated Show resolved Hide resolved
src/services/codefixes/wrapJsxInFragment.ts Outdated Show resolved Hide resolved
@Jack-Works Jack-Works requested a review from andrewbranch June 1, 2020 19:04
@andrewbranch andrewbranch merged commit 8e290e5 into microsoft:master Jun 1, 2020
cangSDARM added a commit to cangSDARM/TypeScript that referenced this pull request Jun 2, 2020
* upstream/master: (78 commits)
  LEGO: check in for master to temporary branch.
  Skip default when initially iterating exports in __importStar, same as __exportStar (microsoft#38808)
  fix line endings
  Improve error range for ts2657 (jsx expr must have parent element), add code fix for it (microsoft#37917)
  fix(32341): add prefix name for module exports properties (microsoft#38541)
  fix(19385): add space after brace in the multiline string template (microsoft#38742)
  fix(38815): dive in arrow functions to check only this usage instead of checking all statements (microsoft#38865)
  LEGO: check in for master to temporary branch.
  LEGO: check in for master to temporary branch.
  LEGO: check in for master to temporary branch.
  LEGO: check in for master to temporary branch.
  LEGO: check in for master to temporary branch.
  LEGO: check in for master to temporary branch.
  LEGO: check in for master to temporary branch.
  LEGO: check in for master to temporary branch.
  Convert HTML tags in doc-comments into markdown
  fix linting error
  LEGO: check in for master to temporary branch.
  LEGO: check in for master to temporary branch.
  fix(38722): change error message for use-before-declaration on const enum (microsoft#38728)
  ...
@Jack-Works Jack-Works deleted the codefix/jsx-2695 branch February 26, 2021 05:29
@Jack-Works
Copy link
Contributor Author

Is the code fix still woring? I cannot use it in 4.3.0-dev-20210323. Is it removed or a regression?

@andrewbranch
Copy link
Member

I think it must be a regression.

@Jack-Works
Copy link
Contributor Author

I think it must be a regression.

Should I open a new issue for it? Or is there a fix already on the fly?

@andrewbranch
Copy link
Member

You can open a new issue. The weird thing is that tests are of course passing. So some investigation is probably needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants