letvar.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. function write(x) { WScript.Echo(x); }
  6. // var after let at function scope should be redeclaration error
  7. try {
  8. eval(
  9. "(function () {" +
  10. " let x = 'let x';" +
  11. " var x = 'redeclaration error';" +
  12. " write(x);" +
  13. "})();"
  14. );
  15. } catch (e) {
  16. write(e);
  17. }
  18. // var after let in non-function block scope should be valid;
  19. // var declaration should reassing let bound symbol, but should
  20. // also introduce function scoped variable, initialized to undefined
  21. // (Make sure there is no difference whether the let binding is used
  22. // or not before the var declaration)
  23. // (Blue bug 145660)
  24. try {
  25. eval(
  26. "(function () {" +
  27. " {" +
  28. " let x = 'let x';" +
  29. " var x = 'var x';" +
  30. " write(x);" +
  31. " }" +
  32. " write(x);" +
  33. " {" +
  34. " let y = 'let y';" +
  35. " write(y);" +
  36. " var y = 'var y';" +
  37. " write(y);" +
  38. " }" +
  39. " write(y);" +
  40. "})();"
  41. );
  42. } catch (e) {
  43. write(e);
  44. }
  45. // var before let in non-function block scope should raise a
  46. // Use Berfore Declaration error.
  47. try {
  48. eval(
  49. "(function () {" +
  50. " {" +
  51. " var x = 'var x';" +
  52. " let x = 'let x';" +
  53. " write(x);" +
  54. " }" +
  55. " write(x);" +
  56. "})();"
  57. );
  58. } catch (e) {
  59. write(e);
  60. }