invalid-lhs-in-assignment.js 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. test("assignment to function call", () => {
  2. expect(() => {
  3. function foo() {}
  4. foo() = "foo";
  5. }).toThrowWithMessage(ReferenceError, "Invalid left-hand side in assignment");
  6. });
  7. test("assignment to function call in strict mode", () => {
  8. expect("'use strict'; foo() = 'foo'").not.toEval();
  9. });
  10. test("assignment to inline function call", () => {
  11. expect(() => {
  12. (function () {})() = "foo";
  13. }).toThrowWithMessage(ReferenceError, "Invalid left-hand side in assignment");
  14. });
  15. test("assignment to invalid LHS is syntax error", () => {
  16. expect("1 += 1").not.toEval();
  17. expect("1 -= 1").not.toEval();
  18. expect("1 *= 1").not.toEval();
  19. expect("1 /= 1").not.toEval();
  20. expect("1 %= 1").not.toEval();
  21. expect("1 **= 1").not.toEval();
  22. expect("1 &= 1").not.toEval();
  23. expect("1 |= 1").not.toEval();
  24. expect("1 ^= 1").not.toEval();
  25. expect("1 <<= 1").not.toEval();
  26. expect("1 >>= 1").not.toEval();
  27. expect("1 >>>= 1").not.toEval();
  28. expect("1 = 1").not.toEval();
  29. });