letlet.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. if (this.WScript && this.WScript.LoadScriptFile) {
  6. this.WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
  7. }
  8. var tests = [
  9. {
  10. name: "'let' should not be an allowed name in let declarations",
  11. body: function() {
  12. assert.throws(function () { eval("let test = 2, let = 1;"), SyntaxError, "'let' is not an allowed identifier in lexical declarations" });
  13. }
  14. },
  15. {
  16. name: "'let' should not be an allowed name in const declarations",
  17. body: function () {
  18. assert.throws(function () { eval("const let = 1, test = 2;"), SyntaxError, "'let' is not an allowed identifier in lexical declarations" });
  19. }
  20. },
  21. {
  22. name: "'let' should not be an allowed name in destructuring let declarations",
  23. body: function () {
  24. assert.throws(function () { eval("let [a, let, b] = [1, 2, 3];"), SyntaxError, "'let' is not an allowed identifier in lexical declarations" });
  25. }
  26. },
  27. {
  28. name: "'let' should not be an allowed name in destructuring const declarations",
  29. body: function () {
  30. assert.throws(function () { eval("const [a, let, b] = [1, 2, 3];"), SyntaxError, "'let' is not an allowed identifier in lexical declarations" });
  31. }
  32. },
  33. {
  34. name: "'let' should not be an allowed name in 'for(let .. in ..)' declarations",
  35. body: function () {
  36. assert.throws(function () { eval("for(let let in { }) { };"), SyntaxError, "'let' is not an allowed identifier in lexical declarations" });
  37. }
  38. },
  39. {
  40. name: "'let' is OK if used in var declarations",
  41. body: function () { var let = 1, test = 2; }
  42. },
  43. ]
  44. testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });