|
| 1 | +import * as util from "../../util"; |
| 2 | + |
| 3 | +test("property on function", () => { |
| 4 | + util.testFunction` |
| 5 | + function foo(s: string) { return s; } |
| 6 | + foo.bar = "bar"; |
| 7 | + return foo("foo") + foo.bar; |
| 8 | + `.expectToMatchJsResult(); |
| 9 | +}); |
| 10 | + |
| 11 | +test("property on void function", () => { |
| 12 | + util.testFunction` |
| 13 | + function foo(this: void, s: string) { return s; } |
| 14 | + foo.bar = "bar"; |
| 15 | + return foo("foo") + foo.bar; |
| 16 | + `.expectToMatchJsResult(); |
| 17 | +}); |
| 18 | + |
| 19 | +test("property on recursively referenced function", () => { |
| 20 | + util.testFunction` |
| 21 | + function foo(s: string) { return s + foo.bar; } |
| 22 | + foo.bar = "bar"; |
| 23 | + return foo("foo") + foo.bar; |
| 24 | + `.expectToMatchJsResult(); |
| 25 | +}); |
| 26 | + |
| 27 | +test("property on hoisted function", () => { |
| 28 | + util.testFunction` |
| 29 | + foo.bar = "bar"; |
| 30 | + function foo(s: string) { return s; } |
| 31 | + return foo("foo") + foo.bar; |
| 32 | + `.expectToMatchJsResult(); |
| 33 | +}); |
| 34 | + |
| 35 | +test("function merged with namespace", () => { |
| 36 | + util.testModule` |
| 37 | + function foo(s: string) { return s; } |
| 38 | + namespace foo { |
| 39 | + export let bar = "bar"; |
| 40 | + } |
| 41 | + export const result = foo("foo") + foo.bar; |
| 42 | + ` |
| 43 | + .setReturnExport("result") |
| 44 | + .expectToEqual("foobar"); |
| 45 | +}); |
| 46 | + |
| 47 | +test("function with property assigned to variable", () => { |
| 48 | + util.testFunction` |
| 49 | + const foo = function(s: string) { return s; }; |
| 50 | + foo.bar = "bar"; |
| 51 | + return foo("foo") + foo.bar; |
| 52 | + `.expectToMatchJsResult(); |
| 53 | +}); |
| 54 | + |
| 55 | +test("void function with property assigned to variable", () => { |
| 56 | + util.testFunction` |
| 57 | + const foo = function(this: void, s: string) { return s; }; |
| 58 | + foo.bar = "bar"; |
| 59 | + return foo("foo") + foo.bar; |
| 60 | + `.expectToMatchJsResult(); |
| 61 | +}); |
| 62 | + |
| 63 | +test("recursively referenced function with property assigned to variable", () => { |
| 64 | + util.testFunction` |
| 65 | + const foo = function(s: string) { return s + foo.bar; }; |
| 66 | + foo.bar = "bar"; |
| 67 | + return foo("foo") + foo.bar; |
| 68 | + `.expectToMatchJsResult(); |
| 69 | +}); |
| 70 | + |
| 71 | +test("named recursively referenced function with property assigned to variable", () => { |
| 72 | + util.testFunction` |
| 73 | + const foo = function baz(s: string) { return s + foo.bar + baz.bar; }; |
| 74 | + foo.bar = "bar"; |
| 75 | + return foo("foo") + foo.bar; |
| 76 | + `.expectToMatchJsResult(); |
| 77 | +}); |
| 78 | + |
| 79 | +test("arrow function with property assigned to variable", () => { |
| 80 | + util.testFunction` |
| 81 | + const foo: { (s: string): string; bar: string; } = s => s; |
| 82 | + foo.bar = "bar"; |
| 83 | + return foo("foo") + foo.bar; |
| 84 | + `.expectToMatchJsResult(); |
| 85 | +}); |
| 86 | + |
| 87 | +test("void arrow function with property assigned to variable", () => { |
| 88 | + util.testFunction` |
| 89 | + const foo: { (this: void, s: string): string; bar: string; } = s => s; |
| 90 | + foo.bar = "bar"; |
| 91 | + return foo("foo") + foo.bar; |
| 92 | + `.expectToMatchJsResult(); |
| 93 | +}); |
| 94 | + |
| 95 | +test("recursively referenced arrow function with property assigned to variable", () => { |
| 96 | + util.testFunction` |
| 97 | + const foo: { (s: string): string; bar: string; } = s => s + foo.bar; |
| 98 | + foo.bar = "bar"; |
| 99 | + return foo("foo") + foo.bar; |
| 100 | + `.expectToMatchJsResult(); |
| 101 | +}); |
| 102 | + |
| 103 | +test("property on generator function", () => { |
| 104 | + util.testFunction` |
| 105 | + function *foo(s: string) { yield s; } |
| 106 | + foo.bar = "bar"; |
| 107 | + for (const s of foo("foo")) { |
| 108 | + return s + foo.bar; |
| 109 | + } |
| 110 | + `.expectToMatchJsResult(); |
| 111 | +}); |
| 112 | + |
| 113 | +test("generator function assigned to variable", () => { |
| 114 | + util.testFunction` |
| 115 | + const foo = function *(s: string) { yield s; } |
| 116 | + foo.bar = "bar"; |
| 117 | + for (const s of foo("foo")) { |
| 118 | + return s + foo.bar; |
| 119 | + } |
| 120 | + `.expectToMatchJsResult(); |
| 121 | +}); |
| 122 | + |
| 123 | +test("property on async function", () => { |
| 124 | + util.testFunction` |
| 125 | + let result = ""; |
| 126 | + async function foo(s: string) { result = s + foo.bar; } |
| 127 | + foo.bar = "bar"; |
| 128 | + void foo("foo"); |
| 129 | + return result; |
| 130 | + `.expectToMatchJsResult(); |
| 131 | +}); |
| 132 | + |
| 133 | +test("async function with property assigned to variable", () => { |
| 134 | + util.testFunction` |
| 135 | + let result = ""; |
| 136 | + const foo = async function(s: string) { result = s + foo.bar; } |
| 137 | + foo.bar = "bar"; |
| 138 | + void foo("foo"); |
| 139 | + return result; |
| 140 | + `.expectToMatchJsResult(); |
| 141 | +}); |
| 142 | + |
| 143 | +test("async arrow function with property assigned to variable", () => { |
| 144 | + util.testFunction` |
| 145 | + let result = ""; |
| 146 | + const foo: { (s: string): Promise<void>; bar: string; } = async s => { result = s + foo.bar; }; |
| 147 | + foo.bar = "bar"; |
| 148 | + void foo("foo"); |
| 149 | + return result; |
| 150 | + `.expectToMatchJsResult(); |
| 151 | +}); |
| 152 | + |
| 153 | +test("call function with property using call method", () => { |
| 154 | + util.testFunction` |
| 155 | + function foo(s: string) { return this + s; } |
| 156 | + foo.baz = "baz"; |
| 157 | + return foo.call("foo", "bar") + foo.baz; |
| 158 | + `.expectToMatchJsResult(); |
| 159 | +}); |
| 160 | + |
| 161 | +test("call function with property using apply method", () => { |
| 162 | + util.testFunction` |
| 163 | + function foo(s: string) { return this + s; } |
| 164 | + foo.baz = "baz"; |
| 165 | + return foo.apply("foo", ["bar"]) + foo.baz; |
| 166 | + `.expectToMatchJsResult(); |
| 167 | +}); |
| 168 | + |
| 169 | +test("call function with property using bind method", () => { |
| 170 | + util.testFunction` |
| 171 | + function foo(s: string) { return this + s; } |
| 172 | + foo.baz = "baz"; |
| 173 | + return foo.bind("foo", "bar")() + foo.baz; |
| 174 | + `.expectToMatchJsResult(); |
| 175 | +}); |
0 commit comments