123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- // This file must not be formatted by prettier. Make sure your IDE
- // respects the .prettierignore file!
- test("new-expression parsing", () => {
- function Foo() {
- this.x = 1;
- }
- let foo = new Foo();
- expect(foo.x).toBe(1);
- foo = new Foo
- expect(foo.x).toBe(1);
- foo = new
- Foo
- ();
- expect(foo.x).toBe(1);
- foo = new Foo + 2
- expect(foo).toBe("[object Object]2");
- });
- test("new-expressions with object keys", () => {
- let a = {
- b: function () {
- this.x = 2;
- },
- };
- foo = new a.b();
- expect(foo.x).toBe(2);
- foo = new a.b;
- expect(foo.x).toBe(2);
- foo = new
- a.b();
- expect(foo.x).toBe(2);
- });
- test("new-expressions with function calls", () => {
- function funcGetter() {
- return function (a, b) {
- this.x = a + b;
- };
- }
- foo = new funcGetter()(1, 5);
- expect(foo).toBeUndefined();
- foo = new (funcGetter())(1, 5);
- expect(foo.x).toBe(6);
- });
|