• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright JS Foundation and other contributors, http://js.foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/* Declaring let */
16
17/* Note: l\u0065t is let */
18
19function check_syntax_error (code) {
20  try {
21    eval(code)
22    assert (false)
23  } catch (e) {
24    assert (e instanceof SyntaxError)
25  }
26}
27
28function check_strict_syntax_error (code) {
29  "use strict"
30
31  try {
32    eval(code)
33    assert (false)
34  } catch (e) {
35    assert (e instanceof SyntaxError)
36  }
37}
38
39check_syntax_error("let let = 5")
40check_syntax_error("const [let] = [1]")
41check_syntax_error("const l\u0065t = 6")
42check_syntax_error("let [l\u0065t] = [2]")
43check_syntax_error("l\\u0065t a")
44check_strict_syntax_error("var let = 5")
45check_strict_syntax_error("function let() {}")
46check_strict_syntax_error("for (let in []) ;")
47check_strict_syntax_error("l\\u0065t;")
48
49var let = 1
50assert(let === 1)
51
52var [let] = [2]
53assert(let === 2)
54
55var x = 0;
56let = [ () => x = 1 ]
57
58l\u0065t[0]()
59assert(x === 1)
60
61function f1()
62{
63  var a = 0
64
65  function let(l\u0065t) {
66    a = let
67  }
68
69  let(3)
70
71  assert(a === 3)
72}
73f1()
74
75function f2()
76{
77  var let = [1]
78
79  /* First: destructuring pattern definition */
80  let
81  [a] = [2]
82
83  assert(a === 2)
84
85  a = 0
86
87  /* Second: property access */
88  l\u0065t
89  [a] = [3]
90
91  assert(let[0][0] === 3)
92}
93f2()
94
95var arr = []
96
97for (let in ["x","y"])
98  arr.push(let)
99
100assert(arr[0] === "0")
101assert(arr[1] === "1")
102
103/* Let and arrow */
104
105for (let => 4; false ; ) ;
106
107let => 5
108
109/* Let label */
110let: break let
111