-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Conversation
There was a problem hiding this 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/checker.ts
Outdated
@@ -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 => { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
e610faa
to
b8cf1bc
Compare
5e81b32
to
a52a1d0
Compare
rebased to resolve conflict |
a52a1d0
to
389efeb
Compare
rebased to resolve conflict again |
Co-authored-by: Andrew Branch <[email protected]>
Co-authored-by: Andrew Branch <[email protected]>
* 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) ...
Is the code fix still woring? I cannot use it in 4.3.0-dev-20210323. Is it removed or a regression? |
I think it must be a regression. |
Should I open a new issue for it? Or is there a fix already on the fly? |
You can open a new issue. The weird thing is that tests are of course passing. So some investigation is probably needed. |
Before:
After:
Only one error with the correct length (but trivia is included, I don't know how to remove it from the error range)
With code fix:
After code fix:
After fix all: