2020-12-26 15:24:24 +00:00
|
|
|
// prettier-ignore
|
2020-07-03 21:39:25 +00:00
|
|
|
test("new-expression parsing", () => {
|
2020-07-06 14:37:45 +00:00
|
|
|
function Foo() {
|
|
|
|
this.x = 1;
|
|
|
|
}
|
2020-07-05 16:27:00 +00:00
|
|
|
|
2020-07-06 14:37:45 +00:00
|
|
|
let foo = new Foo();
|
|
|
|
expect(foo.x).toBe(1);
|
2020-07-05 16:27:00 +00:00
|
|
|
|
2020-07-06 14:37:45 +00:00
|
|
|
foo = new Foo
|
|
|
|
expect(foo.x).toBe(1);
|
2020-07-05 16:27:00 +00:00
|
|
|
|
2020-07-06 14:37:45 +00:00
|
|
|
foo = new
|
|
|
|
Foo
|
|
|
|
();
|
|
|
|
expect(foo.x).toBe(1);
|
2020-07-05 16:27:00 +00:00
|
|
|
|
2020-07-06 14:37:45 +00:00
|
|
|
foo = new Foo + 2
|
|
|
|
expect(foo).toBe("[object Object]2");
|
2020-07-03 21:39:25 +00:00
|
|
|
});
|
2020-05-28 22:10:22 +00:00
|
|
|
|
2020-12-26 15:24:24 +00:00
|
|
|
// prettier-ignore
|
2020-07-03 21:39:25 +00:00
|
|
|
test("new-expressions with object keys", () => {
|
2020-07-06 14:37:45 +00:00
|
|
|
let a = {
|
|
|
|
b: function () {
|
|
|
|
this.x = 2;
|
|
|
|
},
|
|
|
|
};
|
2020-07-05 16:27:00 +00:00
|
|
|
|
2020-07-06 14:37:45 +00:00
|
|
|
foo = new a.b();
|
|
|
|
expect(foo.x).toBe(2);
|
2020-07-05 16:27:00 +00:00
|
|
|
|
2020-07-06 14:37:45 +00:00
|
|
|
foo = new a.b;
|
|
|
|
expect(foo.x).toBe(2);
|
2020-07-05 16:27:00 +00:00
|
|
|
|
2020-07-06 14:37:45 +00:00
|
|
|
foo = new
|
|
|
|
a.b();
|
|
|
|
expect(foo.x).toBe(2);
|
2020-07-03 21:39:25 +00:00
|
|
|
});
|
2020-05-28 22:10:22 +00:00
|
|
|
|
2020-07-03 21:39:25 +00:00
|
|
|
test("new-expressions with function calls", () => {
|
2020-07-06 14:37:45 +00:00
|
|
|
function funcGetter() {
|
|
|
|
return function (a, b) {
|
|
|
|
this.x = a + b;
|
|
|
|
};
|
|
|
|
}
|
2020-07-05 16:27:00 +00:00
|
|
|
|
2020-07-06 14:37:45 +00:00
|
|
|
foo = new funcGetter()(1, 5);
|
|
|
|
expect(foo).toBeUndefined();
|
2020-07-05 16:27:00 +00:00
|
|
|
|
2020-07-06 14:37:45 +00:00
|
|
|
foo = new (funcGetter())(1, 5);
|
|
|
|
expect(foo.x).toBe(6);
|
2020-07-03 21:39:25 +00:00
|
|
|
});
|