-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fix parser regression for bad related diagnostic on missing matching brackets #44158
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
Merged
sandersn
merged 8 commits into
microsoft:main
from
jessetrinity:fixParserBracketMatching
Mar 16, 2022
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3cb457a
Revert "Revert #43460 and #40884 (#44175)"
jessetrinity e38a0ce
fix missing opening brace match error
jessetrinity fa19d47
refactor parseExpectedMatchingBrackets
jessetrinity c26543f
use getNodePos
jessetrinity 0490253
accept baselines
jessetrinity 4e3ebb2
Merge branch 'main' into fixParserBracketMatching
sandersn f02bd72
delete mistakenly added files
sandersn 18a4df4
Revert getNodePos addition
sandersn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
tests/baselines/reference/missingCloseBracketInArray.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
tests/cases/compiler/missingCloseBracketInArray.ts(1,48): error TS1005: ']' expected. | ||
|
||
|
||
==== tests/cases/compiler/missingCloseBracketInArray.ts (1 errors) ==== | ||
var alphas:string[] = alphas = ["1","2","3","4" | ||
|
||
!!! error TS1005: ']' expected. | ||
!!! related TS1007 tests/cases/compiler/missingCloseBracketInArray.ts:1:32: The parser expected to find a ']' to match the '[' token here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
//// [missingCloseBracketInArray.ts] | ||
var alphas:string[] = alphas = ["1","2","3","4" | ||
|
||
//// [missingCloseBracketInArray.js] | ||
var alphas = alphas = ["1", "2", "3", "4"]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
=== tests/cases/compiler/missingCloseBracketInArray.ts === | ||
var alphas:string[] = alphas = ["1","2","3","4" | ||
>alphas : Symbol(alphas, Decl(missingCloseBracketInArray.ts, 0, 3)) | ||
>alphas : Symbol(alphas, Decl(missingCloseBracketInArray.ts, 0, 3)) | ||
|
11 changes: 11 additions & 0 deletions
11
tests/baselines/reference/missingCloseBracketInArray.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
=== tests/cases/compiler/missingCloseBracketInArray.ts === | ||
var alphas:string[] = alphas = ["1","2","3","4" | ||
>alphas : string[] | ||
>alphas = ["1","2","3","4" : string[] | ||
>alphas : string[] | ||
>["1","2","3","4" : string[] | ||
>"1" : "1" | ||
>"2" : "2" | ||
>"3" : "3" | ||
>"4" : "4" | ||
|
32 changes: 32 additions & 0 deletions
32
tests/baselines/reference/missingCloseParenStatements.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
tests/cases/compiler/missingCloseParenStatements.ts(2,26): error TS1005: ')' expected. | ||
tests/cases/compiler/missingCloseParenStatements.ts(4,5): error TS1005: ')' expected. | ||
tests/cases/compiler/missingCloseParenStatements.ts(8,39): error TS1005: ')' expected. | ||
tests/cases/compiler/missingCloseParenStatements.ts(11,35): error TS1005: ')' expected. | ||
|
||
|
||
==== tests/cases/compiler/missingCloseParenStatements.ts (4 errors) ==== | ||
var a1, a2, a3 = 0; | ||
if ( a1 && (a2 + a3 > 0) { | ||
~ | ||
!!! error TS1005: ')' expected. | ||
!!! related TS1007 tests/cases/compiler/missingCloseParenStatements.ts:2:4: The parser expected to find a ')' to match the '(' token here. | ||
while( (a2 > 0) && a1 | ||
{ | ||
~ | ||
!!! error TS1005: ')' expected. | ||
!!! related TS1007 tests/cases/compiler/missingCloseParenStatements.ts:3:10: The parser expected to find a ')' to match the '(' token here. | ||
do { | ||
var i = i + 1; | ||
a1 = a1 + i; | ||
with ((a2 + a3 > 0) && a1 { | ||
~ | ||
!!! error TS1005: ')' expected. | ||
!!! related TS1007 tests/cases/compiler/missingCloseParenStatements.ts:8:18: The parser expected to find a ')' to match the '(' token here. | ||
console.log(x); | ||
} | ||
} while (i < 5 && (a1 > 5); | ||
~ | ||
!!! error TS1005: ')' expected. | ||
!!! related TS1007 tests/cases/compiler/missingCloseParenStatements.ts:11:17: The parser expected to find a ')' to match the '(' token here. | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//// [missingCloseParenStatements.ts] | ||
var a1, a2, a3 = 0; | ||
if ( a1 && (a2 + a3 > 0) { | ||
while( (a2 > 0) && a1 | ||
{ | ||
do { | ||
var i = i + 1; | ||
a1 = a1 + i; | ||
with ((a2 + a3 > 0) && a1 { | ||
console.log(x); | ||
} | ||
} while (i < 5 && (a1 > 5); | ||
} | ||
} | ||
|
||
//// [missingCloseParenStatements.js] | ||
var a1, a2, a3 = 0; | ||
if (a1 && (a2 + a3 > 0)) { | ||
while ((a2 > 0) && a1) { | ||
do { | ||
var i = i + 1; | ||
a1 = a1 + i; | ||
with ((a2 + a3 > 0) && a1) { | ||
console.log(x); | ||
} | ||
} while (i < 5 && (a1 > 5)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Having to repeat openBracePosition/openBraceParsed every time is still a bit noisy. You could eliminate it using a closure, but I don't think it's worth the performance cost. Still, uh, here's what it would look like:
And then the first few lines of parseExpectedMatchingBrackets look like this:
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.
ahh, that's better. Why does it have significantly worse performance though?
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 have to create a closure each time, which closes over
openKind
,closeKind
,openPosition
,openParsed
. The naive way to compile this is to put them onto the heap, so the GC now has 4 numbers and a function to collect.However, those are all numbers or booleans, and v8 might emit fast code. I have no idea; so it's probably worth testing if you like the change enough -- the existing perf suite certainly has enough brackets to stress it.