duplicated-variable-declarations.js 1.1 KB

123456789101112131415161718192021222324252627282930
  1. describe("duplicated variable declarations should throw", () => {
  2. test("given two declarations in the same statement", () => {
  3. expect("let a, a;").not.toEval();
  4. expect("const a, a;").not.toEval();
  5. expect("var a, a;").toEval();
  6. });
  7. test("fail to parse if repeated over multiple statements", () => {
  8. expect("let a; var a;").not.toEval();
  9. expect("let b, a; var c, a;").not.toEval();
  10. expect("const a; var a;").not.toEval();
  11. expect("const b, a; var c, a;").not.toEval();
  12. });
  13. test("should fail to parse even if variable first declared with var", () => {
  14. expect("var a; let a;").not.toEval();
  15. expect("var a; let b, a;").not.toEval();
  16. expect("var a; const a;").not.toEval();
  17. expect("var a; const b, a;").not.toEval();
  18. });
  19. test("special cases with for loops", () => {
  20. expect("for (var a;;) { let a; }").toEval();
  21. expect("for (let a;;) { let a; }").toEval();
  22. expect("for (var a;;) { var a; }").toEval();
  23. expect("for (let a;;) { var a; }").not.toEval();
  24. });
  25. });