mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-17 01:49:41 -05:00
Fixed false positive syntax errors with in inside for (#54801)
Co-authored-by: Evan Wallace <evan.exe@gmail.com>
This commit is contained in:
committed by
GitHub
parent
e607c8ed81
commit
2623fe7049
@@ -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);
|
||||
}
|
||||
|
||||
20
tests/baselines/reference/parserForInStatement8.errors.txt
Normal file
20
tests/baselines/reference/parserForInStatement8.errors.txt
Normal 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'.
|
||||
|
||||
15
tests/baselines/reference/parserForInStatement8.js
Normal file
15
tests/baselines/reference/parserForInStatement8.js
Normal 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);
|
||||
21
tests/baselines/reference/parserForInStatement8.symbols
Normal file
21
tests/baselines/reference/parserForInStatement8.symbols
Normal 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))
|
||||
|
||||
33
tests/baselines/reference/parserForInStatement8.types
Normal file
33
tests/baselines/reference/parserForInStatement8.types
Normal 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
|
||||
|
||||
11
tests/baselines/reference/parserForOfStatement25.errors.txt
Normal file
11
tests/baselines/reference/parserForOfStatement25.errors.txt
Normal 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 '{}'.
|
||||
|
||||
15
tests/baselines/reference/parserForOfStatement25.js
Normal file
15
tests/baselines/reference/parserForOfStatement25.js
Normal 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);
|
||||
19
tests/baselines/reference/parserForOfStatement25.symbols
Normal file
19
tests/baselines/reference/parserForOfStatement25.symbols
Normal 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))
|
||||
|
||||
31
tests/baselines/reference/parserForOfStatement25.types
Normal file
31
tests/baselines/reference/parserForOfStatement25.types
Normal 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
|
||||
|
||||
15
tests/baselines/reference/parserForStatement9.js
Normal file
15
tests/baselines/reference/parserForStatement9.js
Normal 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);
|
||||
25
tests/baselines/reference/parserForStatement9.symbols
Normal file
25
tests/baselines/reference/parserForStatement9.symbols
Normal 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))
|
||||
|
||||
41
tests/baselines/reference/parserForStatement9.types
Normal file
41
tests/baselines/reference/parserForStatement9.types
Normal 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
|
||||
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user