-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fixed false positive syntax errors with in inside for #54801
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
jakebailey
merged 1 commit into
microsoft:main
from
Andarist:fix/syntax-err-in-inside-for
Jul 20, 2023
Merged
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions
20
tests/baselines/reference/parserForInStatement8.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,20 @@ | ||
parserForInStatement8.ts(3,10): error TS2461: Type 'string' is not an array type. | ||
parserForInStatement8.ts(3,10): error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern. | ||
parserForInStatement8.ts(4,10): error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern. | ||
parserForInStatement8.ts(4,11): error TS2339: Property 'x' does not exist on type 'String'. | ||
|
||
|
||
==== parserForInStatement8.ts (4 errors) ==== | ||
// repro from https://github.com/microsoft/TypeScript/issues/54769 | ||
|
||
for (let [x = 'a' in {}] in { '': 0 }) console.log(x) | ||
~~~~~~~~~~~~~~~ | ||
!!! error TS2461: Type 'string' is not an array type. | ||
~~~~~~~~~~~~~~~ | ||
!!! error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern. | ||
for (let {x = 'a' in {}} in { '': 0 }) console.log(x) | ||
~~~~~~~~~~~~~~~ | ||
!!! error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern. | ||
~ | ||
!!! error TS2339: Property 'x' does not exist on type 'String'. | ||
|
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,15 @@ | ||
//// [tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement8.ts] //// | ||
|
||
//// [parserForInStatement8.ts] | ||
// repro from https://github.com/microsoft/TypeScript/issues/54769 | ||
|
||
for (let [x = 'a' in {}] in { '': 0 }) console.log(x) | ||
for (let {x = 'a' in {}} in { '': 0 }) console.log(x) | ||
|
||
|
||
//// [parserForInStatement8.js] | ||
// repro from https://github.com/microsoft/TypeScript/issues/54769 | ||
for (var _a = (void 0)[0], x = _a === void 0 ? 'a' in {} : _a in { '': 0 }) | ||
console.log(x); | ||
for (var _b = (void 0).x, x = _b === void 0 ? 'a' in {} : _b in { '': 0 }) | ||
console.log(x); | ||
Comment on lines
+12
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this isn't the correct output but since binding patterns on the left side of for-in are not supported by TS today, I think that it's fine to leave it as is for now |
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,21 @@ | ||
//// [tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement8.ts] //// | ||
|
||
=== parserForInStatement8.ts === | ||
// repro from https://github.com/microsoft/TypeScript/issues/54769 | ||
|
||
for (let [x = 'a' in {}] in { '': 0 }) console.log(x) | ||
>x : Symbol(x, Decl(parserForInStatement8.ts, 2, 10)) | ||
>'' : Symbol('', Decl(parserForInStatement8.ts, 2, 29)) | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>x : Symbol(x, Decl(parserForInStatement8.ts, 2, 10)) | ||
|
||
for (let {x = 'a' in {}} in { '': 0 }) console.log(x) | ||
>x : Symbol(x, Decl(parserForInStatement8.ts, 3, 10)) | ||
>'' : Symbol('', Decl(parserForInStatement8.ts, 3, 29)) | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>x : Symbol(x, Decl(parserForInStatement8.ts, 3, 10)) | ||
|
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,33 @@ | ||
//// [tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement8.ts] //// | ||
|
||
=== parserForInStatement8.ts === | ||
// repro from https://github.com/microsoft/TypeScript/issues/54769 | ||
|
||
for (let [x = 'a' in {}] in { '': 0 }) console.log(x) | ||
>x : any | ||
>'a' in {} : boolean | ||
>'a' : "a" | ||
>{} : {} | ||
>{ '': 0 } : { '': number; } | ||
>'' : number | ||
>0 : 0 | ||
>console.log(x) : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>x : any | ||
|
||
for (let {x = 'a' in {}} in { '': 0 }) console.log(x) | ||
>x : any | ||
>'a' in {} : boolean | ||
>'a' : "a" | ||
>{} : {} | ||
>{ '': 0 } : { '': number; } | ||
>'' : number | ||
>0 : 0 | ||
>console.log(x) : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>x : any | ||
|
11 changes: 11 additions & 0 deletions
11
tests/baselines/reference/parserForOfStatement25.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,11 @@ | ||
parserForOfStatement25.ts(4,11): error TS2339: Property 'x' does not exist on type '{}'. | ||
|
||
|
||
==== parserForOfStatement25.ts (1 errors) ==== | ||
// repro from https://github.com/microsoft/TypeScript/issues/54769 | ||
|
||
for (let [x = 'a' in {}] of [[]]) console.log(x) | ||
for (let {x = 'a' in {}} of [{}]) console.log(x) | ||
~ | ||
!!! error TS2339: Property 'x' does not exist on type '{}'. | ||
|
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,15 @@ | ||
//// [tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement25.ts] //// | ||
|
||
//// [parserForOfStatement25.ts] | ||
// repro from https://github.com/microsoft/TypeScript/issues/54769 | ||
|
||
for (let [x = 'a' in {}] of [[]]) console.log(x) | ||
for (let {x = 'a' in {}} of [{}]) console.log(x) | ||
|
||
|
||
//// [parserForOfStatement25.js] | ||
// repro from https://github.com/microsoft/TypeScript/issues/54769 | ||
for (let [x = 'a' in {}] of [[]]) | ||
console.log(x); | ||
for (let { x = 'a' in {} } of [{}]) | ||
console.log(x); |
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,19 @@ | ||
//// [tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement25.ts] //// | ||
|
||
=== parserForOfStatement25.ts === | ||
// repro from https://github.com/microsoft/TypeScript/issues/54769 | ||
|
||
for (let [x = 'a' in {}] of [[]]) console.log(x) | ||
>x : Symbol(x, Decl(parserForOfStatement25.ts, 2, 10)) | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>x : Symbol(x, Decl(parserForOfStatement25.ts, 2, 10)) | ||
|
||
for (let {x = 'a' in {}} of [{}]) console.log(x) | ||
>x : Symbol(x, Decl(parserForOfStatement25.ts, 3, 10)) | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>x : Symbol(x, Decl(parserForOfStatement25.ts, 3, 10)) | ||
|
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,31 @@ | ||
//// [tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement25.ts] //// | ||
|
||
=== parserForOfStatement25.ts === | ||
// repro from https://github.com/microsoft/TypeScript/issues/54769 | ||
|
||
for (let [x = 'a' in {}] of [[]]) console.log(x) | ||
>x : boolean | ||
>'a' in {} : boolean | ||
>'a' : "a" | ||
>{} : {} | ||
>[[]] : undefined[][] | ||
>[] : undefined[] | ||
>console.log(x) : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>x : boolean | ||
|
||
for (let {x = 'a' in {}} of [{}]) console.log(x) | ||
>x : any | ||
>'a' in {} : boolean | ||
>'a' : "a" | ||
>{} : {} | ||
>[{}] : {}[] | ||
>{} : {} | ||
>console.log(x) : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>x : any | ||
|
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,15 @@ | ||
//// [tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement9.ts] //// | ||
|
||
//// [parserForStatement9.ts] | ||
// repro from https://github.com/microsoft/TypeScript/issues/54769 | ||
|
||
for (let [x = 'a' in {}] = []; !x; x = !x) console.log(x) | ||
for (let {x = 'a' in {}} = {}; !x; x = !x) console.log(x) | ||
|
||
|
||
//// [parserForStatement9.js] | ||
// repro from https://github.com/microsoft/TypeScript/issues/54769 | ||
for (var _a = [][0], x = _a === void 0 ? 'a' in {} : _a; !x; x = !x) | ||
console.log(x); | ||
for (var _b = {}.x, x = _b === void 0 ? 'a' in {} : _b; !x; x = !x) | ||
console.log(x); |
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,25 @@ | ||
//// [tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement9.ts] //// | ||
|
||
=== parserForStatement9.ts === | ||
// repro from https://github.com/microsoft/TypeScript/issues/54769 | ||
|
||
for (let [x = 'a' in {}] = []; !x; x = !x) console.log(x) | ||
>x : Symbol(x, Decl(parserForStatement9.ts, 2, 10)) | ||
>x : Symbol(x, Decl(parserForStatement9.ts, 2, 10)) | ||
>x : Symbol(x, Decl(parserForStatement9.ts, 2, 10)) | ||
>x : Symbol(x, Decl(parserForStatement9.ts, 2, 10)) | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>x : Symbol(x, Decl(parserForStatement9.ts, 2, 10)) | ||
|
||
for (let {x = 'a' in {}} = {}; !x; x = !x) console.log(x) | ||
>x : Symbol(x, Decl(parserForStatement9.ts, 3, 10)) | ||
>x : Symbol(x, Decl(parserForStatement9.ts, 3, 10)) | ||
>x : Symbol(x, Decl(parserForStatement9.ts, 3, 10)) | ||
>x : Symbol(x, Decl(parserForStatement9.ts, 3, 10)) | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>x : Symbol(x, Decl(parserForStatement9.ts, 3, 10)) | ||
|
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,41 @@ | ||
//// [tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement9.ts] //// | ||
|
||
=== parserForStatement9.ts === | ||
// repro from https://github.com/microsoft/TypeScript/issues/54769 | ||
|
||
for (let [x = 'a' in {}] = []; !x; x = !x) console.log(x) | ||
>x : boolean | ||
>'a' in {} : boolean | ||
>'a' : "a" | ||
>{} : {} | ||
>[] : [] | ||
>!x : boolean | ||
>x : boolean | ||
>x = !x : boolean | ||
>x : boolean | ||
>!x : boolean | ||
>x : boolean | ||
>console.log(x) : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>x : boolean | ||
|
||
for (let {x = 'a' in {}} = {}; !x; x = !x) console.log(x) | ||
>x : boolean | ||
>'a' in {} : boolean | ||
>'a' : "a" | ||
>{} : {} | ||
>{} : { x?: boolean; } | ||
>!x : boolean | ||
>x : boolean | ||
>x = !x : boolean | ||
>x : boolean | ||
>!x : boolean | ||
>x : boolean | ||
>console.log(x) : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>x : boolean | ||
|
4 changes: 4 additions & 0 deletions
4
tests/cases/conformance/parser/ecmascript5/Statements/parserForInStatement8.ts
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,4 @@ | ||
// repro from https://github.com/microsoft/TypeScript/issues/54769 | ||
|
||
for (let [x = 'a' in {}] in { '': 0 }) console.log(x) | ||
for (let {x = 'a' in {}} in { '': 0 }) console.log(x) |
4 changes: 4 additions & 0 deletions
4
tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement9.ts
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,4 @@ | ||
// repro from https://github.com/microsoft/TypeScript/issues/54769 | ||
|
||
for (let [x = 'a' in {}] = []; !x; x = !x) console.log(x) | ||
for (let {x = 'a' in {}} = {}; !x; x = !x) console.log(x) |
6 changes: 6 additions & 0 deletions
6
tests/cases/conformance/parser/ecmascript6/Iterators/parserForOfStatement25.ts
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,6 @@ | ||
// @target: esnext | ||
|
||
// repro from https://github.com/microsoft/TypeScript/issues/54769 | ||
|
||
for (let [x = 'a' in {}] of [[]]) console.log(x) | ||
for (let {x = 'a' in {}} of [{}]) console.log(x) |
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.
Those errors are not correct but that's a separate issue
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.
How challenging is that to fix?
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'm looking into this but it's the first time that I even opened the files related to downleveling syntax here so it might take a moment (if I don't lose interest in this, that is).
undefined
shouldn't be emitted (at least in this case)Uncaught SyntaxError: Invalid left-hand side in for-in loop: Must have a single binding.
)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.
It’s legal to use destructuring in
for..in
? What would that even mean since the value is always a string (or symbol)?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.
Strings are iterable so u could read its characters through an array pattern, or some prototype methods/properties through an object pattern.
Is it useful? Not rly. Is it legal? Apparently yes :P
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 close the loop on this one, if you don't think you'll get around to fixing this in this PR, can you add a note to the test case that says "hey, this is wrong" and file an issue, or similar?
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.
Er, actually, is #54853 that PR?
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.
Yes, it is.
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.
Alright, I guess we can just leave the PR as-is?
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.
Yes, i think so.