Fixed false positive syntax errors with in inside for (#54801)

Co-authored-by: Evan Wallace <evan.exe@gmail.com>
This commit is contained in:
Mateusz Burzyński
2023-07-20 21:13:44 +02:00
committed by GitHub
parent e607c8ed81
commit 2623fe7049
15 changed files with 262 additions and 2 deletions

View File

@@ -7487,7 +7487,7 @@ namespace Parser {
function parseObjectBindingPattern(): ObjectBindingPattern {
const pos = getNodePos();
parseExpected(SyntaxKind.OpenBraceToken);
const elements = parseDelimitedList(ParsingContext.ObjectBindingElements, parseObjectBindingElement);
const elements = allowInAnd(() => parseDelimitedList(ParsingContext.ObjectBindingElements, parseObjectBindingElement));
parseExpected(SyntaxKind.CloseBraceToken);
return finishNode(factory.createObjectBindingPattern(elements), pos);
}
@@ -7495,7 +7495,7 @@ namespace Parser {
function parseArrayBindingPattern(): ArrayBindingPattern {
const pos = getNodePos();
parseExpected(SyntaxKind.OpenBracketToken);
const elements = parseDelimitedList(ParsingContext.ArrayBindingElements, parseArrayBindingElement);
const elements = allowInAnd(() => parseDelimitedList(ParsingContext.ArrayBindingElements, parseArrayBindingElement));
parseExpected(SyntaxKind.CloseBracketToken);
return finishNode(factory.createArrayBindingPattern(elements), pos);
}

View File

@@ -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'.

View File

@@ -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);

View File

@@ -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))

View File

@@ -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

View File

@@ -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 '{}'.

View File

@@ -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);

View File

@@ -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))

View File

@@ -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

View File

@@ -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);

View File

@@ -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))

View File

@@ -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

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)