function-duplicate-parameters.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. test("function with duplicate parameter names", () => {
  2. function foo(bar, _, bar) {
  3. return bar;
  4. }
  5. expect(foo(1, 2, 3)).toBe(3);
  6. });
  7. test("syntax errors", () => {
  8. // Regular function in strict mode
  9. expect(`
  10. "use strict";
  11. function foo(bar, bar) {}
  12. `).not.toEval();
  13. // Arrow function in strict mode
  14. expect(`
  15. "use strict";
  16. const foo = (bar, bar) => {};
  17. `).not.toEval();
  18. // Arrow function in non-strict mode
  19. expect(`
  20. const foo = (bar, bar) => {};
  21. `).not.toEval();
  22. // Regular function with rest parameter
  23. expect(`
  24. function foo(bar, ...bar) {}
  25. `).not.toEval();
  26. // Arrow function with rest parameter
  27. expect(`
  28. const foo = (bar, ...bar) => {};
  29. `).not.toEval();
  30. // Regular function with default parameter
  31. expect(`
  32. function foo(bar, bar = 1) {}
  33. `).not.toEval();
  34. // Arrow function with default parameter
  35. expect(`
  36. const foo = (bar, bar = 1) => {};
  37. `).not.toEval();
  38. });