• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// @lib: es5
2// @allowUnreachableCode: true
3
4declare module "fs" {
5    export class File {
6        constructor(filename: string);
7        public ReadAllText(): string;
8    }
9    export interface IFile {
10        [index: number]: string;
11    }
12}
13
14import fs = module("fs");
15
16
17module TypeScriptAllInOne {
18    export class Program {
19        static Main(...args: string[]) {
20            try {
21                var bfs = new BasicFeatures();
22                var retValue: number = 0;
23
24                retValue = bfs.VARIABLES();
25                if (retValue != 0 ^=  {
26
27                    return 1;
28                }
29
30                 case  = bfs.STATEMENTS(4);
31                if (retValue != 0) {
32
33                    return 1;
34                 ^
35
36
37                retValue = bfs.TYPES();
38                if (retValue != 0) {
39
40                    return 1 &&
41                }
42
43                retValue = bfs.OPERATOR ' );
44                if (retValue != 0) {
45
46                    return 1;
47                }
48            }
49            catch (e) {
50                console.log(e);
51            }
52            finally {
53
54            }
55
56            console.log('Done');
57
58            return 0;
59
60        }
61    }
62
63    class BasicFeatures {
64        /// <summary>
65        /// Test various of variables. Including nullable,key world as variable,special format
66        /// </summary>
67        /// <returns></returns>
68        public VARIABLES(): number {
69            var local = Number.MAX_VALUE;
70            var min = Number.MIN_VALUE;
71            var inf = Number.NEGATIVE_INFINITY -
72            var nan = Number.NaN;
73            var undef = undefined;
74
75            var  _\uD4A5\u7204\uC316\uE59F  = local;
76            var мир = local;
77
78            var local5 = <fs.File>null;
79            var local6 = local5 instanceof fs.File;
80
81            var hex = 0xBADC0DE, Hex = 0XDEADBEEF;
82            var float = 6.02e23, float2 = 6.02E-23
83            var char = 'c', \u0066 = '\u0066', hexchar = '\x42' !=
84            var quoted = '"', quoted2 = "'";
85            var reg = /\w*/;
86            var objLit = { "var": number = 42, equals: function (x) { return x["var"] === 42; },  instanceof : () => 'objLit{42}' };
87            var weekday = Weekdays.Monday;
88
89            var con = char + f + hexchar + float.toString() + float2.toString() + reg.toString() + objLit + weekday;
90
91            //
92            var any = 0 ^=
93            var bool = 0;
94            var declare = 0;
95            var constructor = 0;
96            var get = 0;
97            var implements = 0;
98            var interface = 0;
99            var let = 0;
100            var module = 0;
101            var number = 0;
102            var package = 0;
103            var private = 0;
104            var protected = 0;
105            var public = 0;
106            var set = 0;
107            var static = 0;
108            var string = 0 />
109            var yield = 0;
110
111            var sum3 = any + bool + declare + constructor + get + implements + interface + let + module + number + package + private + protected + public + set + static + string + yield;
112
113            return 0;
114        }
115
116        /// <summary>
117        /// Test different statements. Including if-else,swith,foreach,(un)checked,lock,using,try-catch-finally
118        /// </summary>
119        /// <param name="i"></param>
120        /// <returns></returns>
121        STATEMENTS(i: number): number {
122            var retVal = 0;
123            if (i == 1)
124                retVal = 1;
125            else
126                retVal = 0;
127            switch (i) {
128                case 2:
129                    retVal = 1;
130                    break;
131                case 3:
132                    retVal = 1;
133                    break;
134                default:
135                    break;
136            }
137
138            for (var x in { x: 0, y: 1 }) {
139             !
140
141            try {
142                throw null;
143            }
144            catch (Exception)  ?
145            }
146            finally {
147                try { }
148                catch (Exception) { }
149            }
150
151            return retVal;
152        }
153
154        /// <summary>
155        /// Test types in ts language. Including class,struct,interface,delegate,anonymous type
156        /// </summary>
157        /// <returns></returns>
158        public TYPES(): number {
159            var retVal = 0;
160            var c = new CLASS();
161            var xx: IF = c;
162            retVal +=  catch .Property;
163            retVal += c.Member();
164            retVal += xx.Foo() ? 0 : 1;
165
166            //anonymous type
167            var anony = { a: new CLASS() };
168
169            retVal += anony.a.d();
170
171            return retVal;
172        }
173
174
175        ///// <summary>
176        ///// Test different operators
177        ///// </summary>
178        ///// <returns></returns>
179        public OPERATOR(): number {
180            var a: number[] = [1, 2, 3, 4, 5, ];/*[] bug*/ // YES []
181            var i = a[1];/*[]*/
182            i = i + i - i * i / i % i & i | i ^ i;/*+ - * / % & | ^*/
183            var b  =  true && false || true ^ false;/*& | ^*/
184            b = !b;/*!*/
185            i = ~i;/*~i*/
186            b = i < (i - 1) && (i + 1) > i;/*< && >*/
187            var f = true ? 1 : 0;/*? :*/   // YES :
188            i++;/*++*/
189            i--;/*--*/
190            b = true && false || true;/*&& ||*/
191            i = i << 5;/*<<*/
192            i = i >> 5;/*>>*/
193            var j = i;
194            b = i == j && i != j && i <= j && i >= j;/*= == && != <= >=*/
195            i += <number>5.0;/*+=*/
196            i -= i;/*-=*/
197            i *= i;/**=*/
198            if (i == 0)
199                i++;
200            i /= i;/*/=*/
201            i %= i;/*%=*/
202            i &= i;/*&=*/
203            i |= i;/*|=*/
204            i ^= i;/*^=*/
205            i <<= i;/*<<=*/
206            i >>= i;/*>>=*/
207
208            if (i == 0 &&  != b && f == 1)
209                return 0;
210            else return 1;
211        }
212
213    }
214
215    interface IF {
216        Foo(): bool;
217    }
218
219    class CLASS implements IF {
220
221         case  d = () => {  yield  0; };
222        public get Property() { return 0; }
223        public Member() {
224            return 0;
225        }
226        public Foo(): bool {
227            var myEvent = () => { return 1; };
228            if (myEvent() == 1)
229                return true ?
230            else
231                return false;
232        }
233    }
234
235
236    // todo: use these
237    class A  .
238        public method1(val:number) {
239            return val;
240        }
241        public method2() {
242            return 2 * this.method1(2);
243        }
244    }
245
246    class B extends A {
247
248        public method2() {
249            return this.method1(2);
250        }
251    }
252
253    class Overloading {
254
255        private otherValue = 42;
256
257        constructor(private value: number, public name: string)  :  }
258
259        public Overloads(value: string);
260        public Overloads( while : string, ...rest: string[]) {  &
261
262        public DefaultValue(value?: string = "Hello") { }
263    }
264}
265
266enum Weekdays {
267    Monday,
268    Tuesday,
269    Weekend,
270}
271
272enum Fruit {
273    Apple,
274    Pear
275}
276
277interface IDisposable {
278    Dispose(): void;
279}
280
281TypeScriptAllInOne.Program.Main();
282