Closed
Description
Bug Report
π Search Terms
for in syntax error
π Version & Regression Information
- This is the behavior in every version available in the playground
β― Playground Link
Playground link with relevant code
π» Code
for (let [x = 'a' in {}] of [[]]) console.log(x)
for (let {x = 'a' in {}} of [{}]) console.log(x)
for (let [x = 'a' in {}] in { '': 0 }) console.log(x)
for (let {x = 'a' in {}} in { '': 0 }) console.log(x)
for (let [x = 'a' in {}] = []; !x; x = !x) console.log(x)
for (let {x = 'a' in {}} = {}; !x; x = !x) console.log(x)
π Actual behavior
When run, this code should print false
six times. Each false
is the value of x
which has been default-initialized.
π Expected behavior
TypeScript incorrectly generates syntax errors and generates the following invalid JavaScript output:
"use strict";
for (let [x = 'a'] in {})
;
of[[]];
console.log(x);
for (let { x = 'a', in: {} } of [{}])
console.log(x);
for (let [x = 'a'] in {})
;
in { '': 0 };
console.log(x);
for (let { x = 'a', in: {} } in { '': 0 })
console.log(x);
for (let [x = 'a'] in {})
;
[];
!x;
x = !x;
console.log(x);
for (let { x = 'a', in: {} } = {}; !x; x = !x)
console.log(x);
This came up because I was using VSCode to look at some JavaScript language tests and it was incorrectly showing syntax errors. I'm reporting this because it doesn't seem ideal that VSCode's JavaScript language support would treat valid JavaScript as invalid, and also because I believe the fix for this is relatively straightforward (probably something to do with DisallowInContext
in the parser?).