|
| 1 | +//// [staticAnonymousTypeNotReferencingTypeParameter.ts] |
| 2 | +function outer<T>(x: T) { |
| 3 | + class Inner { |
| 4 | + static y: T = x; |
| 5 | + } |
| 6 | + return Inner; |
| 7 | +} |
| 8 | +let y: number = outer(5).y; |
| 9 | + |
| 10 | +class ListWrapper2 { |
| 11 | + static clone<T>(dit: typeof ListWrapper2, array: T[]): T[] { return array.slice(0); } |
| 12 | + static reversed<T>(dit: typeof ListWrapper2, array: T[]): T[] { |
| 13 | + var a = ListWrapper2.clone(dit, array); |
| 14 | + return a; |
| 15 | + } |
| 16 | +} |
| 17 | +namespace tessst { |
| 18 | + /** |
| 19 | + * Iterates through 'array' by index and performs the callback on each element of array until the callback |
| 20 | + * returns a truthy value, then returns that value. |
| 21 | + * If no such value is found, the callback is applied to each element of array and undefined is returned. |
| 22 | + */ |
| 23 | + export function funkyFor<T, U>(array: T[], callback: (element: T, index: number) => U): U { |
| 24 | + if (array) { |
| 25 | + for (let i = 0, len = array.length; i < len; i++) { |
| 26 | + const result = callback(array[i], i); |
| 27 | + if (result) { |
| 28 | + return result; |
| 29 | + } |
| 30 | + } |
| 31 | + } |
| 32 | + return undefined; |
| 33 | + } |
| 34 | +} |
| 35 | +interface Scanner { |
| 36 | + scanRange<T>(start: number, length: number, callback: () => T): T; |
| 37 | +} |
| 38 | +class ListWrapper { |
| 39 | + // JS has no way to express a statically fixed size list, but dart does so we |
| 40 | + // keep both methods. |
| 41 | + static createFixedSize(dit: typeof ListWrapper, size: number): any[] { return new Array(size); } |
| 42 | + static createGrowableSize(dit: typeof ListWrapper, size: number): any[] { return new Array(size); } |
| 43 | + static clone<T>(dit: typeof ListWrapper, array: T[]): T[] { return array.slice(0); } |
| 44 | + static forEachWithIndex<T>(dit: typeof ListWrapper, array: T[], fn: (t: T, n: number) => void) { |
| 45 | + for (var i = 0; i < array.length; i++) { |
| 46 | + fn(array[i], i); |
| 47 | + } |
| 48 | + } |
| 49 | + static first<T>(dit: typeof ListWrapper, array: T[]): T { |
| 50 | + if (!array) return null; |
| 51 | + return array[0]; |
| 52 | + } |
| 53 | + static last<T>(dit: typeof ListWrapper, array: T[]): T { |
| 54 | + if (!array || array.length == 0) return null; |
| 55 | + return array[array.length - 1]; |
| 56 | + } |
| 57 | + static indexOf<T>(dit: typeof ListWrapper, array: T[], value: T, startIndex: number = 0): number { |
| 58 | + return array.indexOf(value, startIndex); |
| 59 | + } |
| 60 | + static contains<T>(dit: typeof ListWrapper, list: T[], el: T): boolean { return list.indexOf(el) !== -1; } |
| 61 | + static reversed<T>(dit: typeof ListWrapper, array: T[]): T[] { |
| 62 | + var a = ListWrapper.clone(dit, array); |
| 63 | + let scanner: Scanner; |
| 64 | + scanner.scanRange(3, 5, () => { }); |
| 65 | + return tessst.funkyFor(array, t => t.toString()) ? a.reverse() : a; |
| 66 | + } |
| 67 | + static concat(dit: typeof ListWrapper, a: any[], b: any[]): any[] { return a.concat(b); } |
| 68 | + static insert<T>(dit: typeof ListWrapper, list: T[], index: number, value: T) { list.splice(index, 0, value); } |
| 69 | + static removeAt<T>(dit: typeof ListWrapper, list: T[], index: number): T { |
| 70 | + var res = list[index]; |
| 71 | + list.splice(index, 1); |
| 72 | + return res; |
| 73 | + } |
| 74 | + static removeAll<T>(dit: typeof ListWrapper, list: T[], items: T[]) { |
| 75 | + for (var i = 0; i < items.length; ++i) { |
| 76 | + var index = list.indexOf(items[i]); |
| 77 | + list.splice(index, 1); |
| 78 | + } |
| 79 | + } |
| 80 | + static remove<T>(dit: typeof ListWrapper, list: T[], el: T): boolean { |
| 81 | + var index = list.indexOf(el); |
| 82 | + if (index > -1) { |
| 83 | + list.splice(index, 1); |
| 84 | + return true; |
| 85 | + } |
| 86 | + return false; |
| 87 | + } |
| 88 | + static clear(dit: typeof ListWrapper, list: any[]) { list.length = 0; } |
| 89 | + static isEmpty(dit: typeof ListWrapper, list: any[]): boolean { return list.length == 0; } |
| 90 | + static fill(dit: typeof ListWrapper, list: any[], value: any, start: number = 0, end: number = null) { |
| 91 | + list.fill(value, start, end === null ? list.length : end); |
| 92 | + } |
| 93 | + static equals(dit: typeof ListWrapper, a: any[], b: any[]): boolean { |
| 94 | + if (a.length != b.length) return false; |
| 95 | + for (var i = 0; i < a.length; ++i) { |
| 96 | + if (a[i] !== b[i]) return false; |
| 97 | + } |
| 98 | + return true; |
| 99 | + } |
| 100 | + static slice<T>(dit: typeof ListWrapper, l: T[], from: number = 0, to: number = null): T[] { |
| 101 | + return l.slice(from, to === null ? undefined : to); |
| 102 | + } |
| 103 | + static splice<T>(dit: typeof ListWrapper, l: T[], from: number, length: number): T[] { return l.splice(from, length); } |
| 104 | + static sort<T>(dit: typeof ListWrapper, l: T[], compareFn?: (a: T, b: T) => number) { |
| 105 | + if (isPresent(compareFn)) { |
| 106 | + l.sort(compareFn); |
| 107 | + } else { |
| 108 | + l.sort(); |
| 109 | + } |
| 110 | + } |
| 111 | + static toString<T>(dit: typeof ListWrapper, l: T[]): string { return l.toString(); } |
| 112 | + static toJSON<T>(dit: typeof ListWrapper, l: T[]): string { return JSON.stringify(l); } |
| 113 | + |
| 114 | + static maximum<T>(dit: typeof ListWrapper, list: T[], predicate: (t: T) => number): T { |
| 115 | + if (list.length == 0) { |
| 116 | + return null; |
| 117 | + } |
| 118 | + var solution: T = null; |
| 119 | + var maxValue = -Infinity; |
| 120 | + for (var index = 0; index < list.length; index++) { |
| 121 | + var candidate = list[index]; |
| 122 | + if (isBlank(candidate)) { |
| 123 | + continue; |
| 124 | + } |
| 125 | + var candidateValue = predicate(candidate); |
| 126 | + if (candidateValue > maxValue) { |
| 127 | + solution = candidate; |
| 128 | + maxValue = candidateValue; |
| 129 | + } |
| 130 | + } |
| 131 | + return solution; |
| 132 | + } |
| 133 | +} |
| 134 | +let cloned = ListWrapper.clone(ListWrapper, [1,2,3,4]); |
| 135 | +declare function isBlank(x: any): boolean; |
| 136 | +declare function isPresent<T>(compareFn?: (a: T, b: T) => number): boolean; |
| 137 | +interface Array<T> { |
| 138 | + fill(value: any, start: number, end: number): void; |
| 139 | +} |
| 140 | + |
| 141 | +//// [staticAnonymousTypeNotReferencingTypeParameter.js] |
| 142 | +function outer(x) { |
| 143 | + var Inner = (function () { |
| 144 | + function Inner() { |
| 145 | + } |
| 146 | + Inner.y = x; |
| 147 | + return Inner; |
| 148 | + }()); |
| 149 | + return Inner; |
| 150 | +} |
| 151 | +var y = outer(5).y; |
| 152 | +var ListWrapper2 = (function () { |
| 153 | + function ListWrapper2() { |
| 154 | + } |
| 155 | + ListWrapper2.clone = function (dit, array) { return array.slice(0); }; |
| 156 | + ListWrapper2.reversed = function (dit, array) { |
| 157 | + var a = ListWrapper2.clone(dit, array); |
| 158 | + return a; |
| 159 | + }; |
| 160 | + return ListWrapper2; |
| 161 | +}()); |
| 162 | +var tessst; |
| 163 | +(function (tessst) { |
| 164 | + /** |
| 165 | + * Iterates through 'array' by index and performs the callback on each element of array until the callback |
| 166 | + * returns a truthy value, then returns that value. |
| 167 | + * If no such value is found, the callback is applied to each element of array and undefined is returned. |
| 168 | + */ |
| 169 | + function funkyFor(array, callback) { |
| 170 | + if (array) { |
| 171 | + for (var i = 0, len = array.length; i < len; i++) { |
| 172 | + var result = callback(array[i], i); |
| 173 | + if (result) { |
| 174 | + return result; |
| 175 | + } |
| 176 | + } |
| 177 | + } |
| 178 | + return undefined; |
| 179 | + } |
| 180 | + tessst.funkyFor = funkyFor; |
| 181 | +})(tessst || (tessst = {})); |
| 182 | +var ListWrapper = (function () { |
| 183 | + function ListWrapper() { |
| 184 | + } |
| 185 | + // JS has no way to express a statically fixed size list, but dart does so we |
| 186 | + // keep both methods. |
| 187 | + ListWrapper.createFixedSize = function (dit, size) { return new Array(size); }; |
| 188 | + ListWrapper.createGrowableSize = function (dit, size) { return new Array(size); }; |
| 189 | + ListWrapper.clone = function (dit, array) { return array.slice(0); }; |
| 190 | + ListWrapper.forEachWithIndex = function (dit, array, fn) { |
| 191 | + for (var i = 0; i < array.length; i++) { |
| 192 | + fn(array[i], i); |
| 193 | + } |
| 194 | + }; |
| 195 | + ListWrapper.first = function (dit, array) { |
| 196 | + if (!array) |
| 197 | + return null; |
| 198 | + return array[0]; |
| 199 | + }; |
| 200 | + ListWrapper.last = function (dit, array) { |
| 201 | + if (!array || array.length == 0) |
| 202 | + return null; |
| 203 | + return array[array.length - 1]; |
| 204 | + }; |
| 205 | + ListWrapper.indexOf = function (dit, array, value, startIndex) { |
| 206 | + if (startIndex === void 0) { startIndex = 0; } |
| 207 | + return array.indexOf(value, startIndex); |
| 208 | + }; |
| 209 | + ListWrapper.contains = function (dit, list, el) { return list.indexOf(el) !== -1; }; |
| 210 | + ListWrapper.reversed = function (dit, array) { |
| 211 | + var a = ListWrapper.clone(dit, array); |
| 212 | + var scanner; |
| 213 | + scanner.scanRange(3, 5, function () { }); |
| 214 | + return tessst.funkyFor(array, function (t) { return t.toString(); }) ? a.reverse() : a; |
| 215 | + }; |
| 216 | + ListWrapper.concat = function (dit, a, b) { return a.concat(b); }; |
| 217 | + ListWrapper.insert = function (dit, list, index, value) { list.splice(index, 0, value); }; |
| 218 | + ListWrapper.removeAt = function (dit, list, index) { |
| 219 | + var res = list[index]; |
| 220 | + list.splice(index, 1); |
| 221 | + return res; |
| 222 | + }; |
| 223 | + ListWrapper.removeAll = function (dit, list, items) { |
| 224 | + for (var i = 0; i < items.length; ++i) { |
| 225 | + var index = list.indexOf(items[i]); |
| 226 | + list.splice(index, 1); |
| 227 | + } |
| 228 | + }; |
| 229 | + ListWrapper.remove = function (dit, list, el) { |
| 230 | + var index = list.indexOf(el); |
| 231 | + if (index > -1) { |
| 232 | + list.splice(index, 1); |
| 233 | + return true; |
| 234 | + } |
| 235 | + return false; |
| 236 | + }; |
| 237 | + ListWrapper.clear = function (dit, list) { list.length = 0; }; |
| 238 | + ListWrapper.isEmpty = function (dit, list) { return list.length == 0; }; |
| 239 | + ListWrapper.fill = function (dit, list, value, start, end) { |
| 240 | + if (start === void 0) { start = 0; } |
| 241 | + if (end === void 0) { end = null; } |
| 242 | + list.fill(value, start, end === null ? list.length : end); |
| 243 | + }; |
| 244 | + ListWrapper.equals = function (dit, a, b) { |
| 245 | + if (a.length != b.length) |
| 246 | + return false; |
| 247 | + for (var i = 0; i < a.length; ++i) { |
| 248 | + if (a[i] !== b[i]) |
| 249 | + return false; |
| 250 | + } |
| 251 | + return true; |
| 252 | + }; |
| 253 | + ListWrapper.slice = function (dit, l, from, to) { |
| 254 | + if (from === void 0) { from = 0; } |
| 255 | + if (to === void 0) { to = null; } |
| 256 | + return l.slice(from, to === null ? undefined : to); |
| 257 | + }; |
| 258 | + ListWrapper.splice = function (dit, l, from, length) { return l.splice(from, length); }; |
| 259 | + ListWrapper.sort = function (dit, l, compareFn) { |
| 260 | + if (isPresent(compareFn)) { |
| 261 | + l.sort(compareFn); |
| 262 | + } |
| 263 | + else { |
| 264 | + l.sort(); |
| 265 | + } |
| 266 | + }; |
| 267 | + ListWrapper.toString = function (dit, l) { return l.toString(); }; |
| 268 | + ListWrapper.toJSON = function (dit, l) { return JSON.stringify(l); }; |
| 269 | + ListWrapper.maximum = function (dit, list, predicate) { |
| 270 | + if (list.length == 0) { |
| 271 | + return null; |
| 272 | + } |
| 273 | + var solution = null; |
| 274 | + var maxValue = -Infinity; |
| 275 | + for (var index = 0; index < list.length; index++) { |
| 276 | + var candidate = list[index]; |
| 277 | + if (isBlank(candidate)) { |
| 278 | + continue; |
| 279 | + } |
| 280 | + var candidateValue = predicate(candidate); |
| 281 | + if (candidateValue > maxValue) { |
| 282 | + solution = candidate; |
| 283 | + maxValue = candidateValue; |
| 284 | + } |
| 285 | + } |
| 286 | + return solution; |
| 287 | + }; |
| 288 | + return ListWrapper; |
| 289 | +}()); |
| 290 | +var cloned = ListWrapper.clone(ListWrapper, [1, 2, 3, 4]); |
0 commit comments