var-scoping.js 982 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. test("basic functionality", () => {
  2. function foo() {
  3. i = 3;
  4. expect(i).toBe(3);
  5. var i;
  6. }
  7. foo();
  8. var caught_exception;
  9. try {
  10. j = i;
  11. } catch (e) {
  12. caught_exception = e;
  13. }
  14. expect(caught_exception).not.toBeUndefined();
  15. });
  16. test("Issue #8198 arrow function escapes function scope", () => {
  17. const b = 3;
  18. function f() {
  19. expect(b).toBe(3);
  20. (() => {
  21. expect(b).toBe(3);
  22. var a = "wat";
  23. eval("var b=a;");
  24. expect(b).toBe("wat");
  25. })();
  26. expect(b).toBe(3);
  27. }
  28. f();
  29. expect(b).toBe(3);
  30. });
  31. test("Referencing the declared var in the initializer of a duplicate var declaration", () => {
  32. function c(e) {
  33. e.foo;
  34. }
  35. function h() {}
  36. function go() {
  37. var p = true;
  38. var p = h() || c(p);
  39. return 0;
  40. }
  41. // It's all good as long as go() doesn't throw.
  42. expect(go()).toBe(0);
  43. });