1 // Copyright 2015 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Flags: --harmony-sloppy --harmony-sloppy-let --harmony-destructuring-bind 6 // Flags: --legacy-const 7 8 // let is usable as a variable with var or legacy const, not let or ES6 const 9 10 (function (){ 11 assertEquals(undefined, let); 12 13 var let; 14 15 let = 5; 16 assertEquals(5, let); 17 18 (function() { var let = 1; assertEquals(1, let); })(); 19 assertEquals(5, let); 20 })(); 21 22 assertThrows(function() { return let; }, ReferenceError); 23 24 (function() { 25 var let, sum = 0; 26 for (let in [1, 2, 3, 4]) sum += Number(let); 27 assertEquals(6, sum); 28 29 (function() { for (var let of [4, 5]) sum += let; })(); 30 assertEquals(15, sum); 31 32 (function() { for (var let in [6]) sum += Number([6][let]); })(); 33 assertEquals(21, sum); 34 35 for (let = 7; let < 8; let++) sum += let; 36 assertEquals(28, sum); 37 assertEquals(8, let); 38 39 (function() { for (var let = 8; let < 9; let++) sum += let; })(); 40 assertEquals(36, sum); 41 assertEquals(8, let); 42 })(); 43 44 assertThrows(function() { return let; }, ReferenceError); 45 46 (function () { 47 let obj = {}; 48 var {let} = {let() { return obj; }}; 49 let().x = 1; 50 assertEquals(1, obj.x); 51 })(); 52 53 (function () { 54 let obj = {}; 55 const [let] = [function() { return obj; }]; 56 let().x = 1; 57 assertEquals(1, obj.x); 58 })(); 59 60 (function() { 61 function let() { 62 return 1; 63 } 64 assertEquals(1, let()); 65 })() 66 67 assertThrows('for (let of []) {}', SyntaxError); 68