2 (function (TypeScript) {
3 function hasFlag(val, flag) {
4 return (val & flag) != 0;
6 TypeScript.hasFlag = hasFlag;
7 (function (ErrorRecoverySet) {
8 ErrorRecoverySet._map = [];
9 ErrorRecoverySet.None = 0;
10 ErrorRecoverySet.Comma = 1;
11 ErrorRecoverySet.SColon = 1 << 1;
12 ErrorRecoverySet.Asg = 1 << 2;
13 ErrorRecoverySet.BinOp = 1 << 3;
14 ErrorRecoverySet.RBrack = 1 << 4;
15 ErrorRecoverySet.RCurly = 1 << 5;
16 ErrorRecoverySet.RParen = 1 << 6;
17 ErrorRecoverySet.Dot = 1 << 7;
18 ErrorRecoverySet.Colon = 1 << 8;
19 ErrorRecoverySet.PrimType = 1 << 9;
20 ErrorRecoverySet.AddOp = 1 << 10;
21 ErrorRecoverySet.LCurly = 1 << 11;
22 ErrorRecoverySet.PreOp = 1 << 12;
23 ErrorRecoverySet.RegExp = 1 << 13;
24 ErrorRecoverySet.LParen = 1 << 14;
25 ErrorRecoverySet.LBrack = 1 << 15;
26 ErrorRecoverySet.Scope = 1 << 16;
27 ErrorRecoverySet.In = 1 << 17;
28 ErrorRecoverySet.SCase = 1 << 18;
29 ErrorRecoverySet.Else = 1 << 19;
30 ErrorRecoverySet.Catch = 1 << 20;
31 ErrorRecoverySet.Var = 1 << 21;
32 ErrorRecoverySet.Stmt = 1 << 22;
33 ErrorRecoverySet.While = 1 << 23;
34 ErrorRecoverySet.ID = 1 << 24;
35 ErrorRecoverySet.Prefix = 1 << 25;
36 ErrorRecoverySet.Literal = 1 << 26;
37 ErrorRecoverySet.RLit = 1 << 27;
38 ErrorRecoverySet.Func = 1 << 28;
39 ErrorRecoverySet.EOF = 1 << 29;
40 ErrorRecoverySet.TypeScriptS = 1 << 30;
41 ErrorRecoverySet.ExprStart = ErrorRecoverySet.SColon | ErrorRecoverySet.AddOp | ErrorRecoverySet.LCurly | ErrorRecoverySet.PreOp | ErrorRecoverySet.RegExp | ErrorRecoverySet.LParen | ErrorRecoverySet.LBrack | ErrorRecoverySet.ID | ErrorRecoverySet.Prefix | ErrorRecoverySet.RLit | ErrorRecoverySet.Func | ErrorRecoverySet.Literal;
42 ErrorRecoverySet.StmtStart = ErrorRecoverySet.ExprStart | ErrorRecoverySet.SColon | ErrorRecoverySet.Var | ErrorRecoverySet.Stmt | ErrorRecoverySet.While | ErrorRecoverySet.TypeScriptS;
43 ErrorRecoverySet.Postfix = ErrorRecoverySet.Dot | ErrorRecoverySet.LParen | ErrorRecoverySet.LBrack;
44 })(TypeScript.ErrorRecoverySet || (TypeScript.ErrorRecoverySet = {}));
45 var ErrorRecoverySet = TypeScript.ErrorRecoverySet;
46 (function (AllowedElements) {
47 AllowedElements._map = [];
48 AllowedElements.None = 0;
49 AllowedElements.ModuleDeclarations = 1 << 2;
50 AllowedElements.ClassDeclarations = 1 << 3;
51 AllowedElements.InterfaceDeclarations = 1 << 4;
52 AllowedElements.AmbientDeclarations = 1 << 10;
53 AllowedElements.Properties = 1 << 11;
54 AllowedElements.Global = AllowedElements.ModuleDeclarations | AllowedElements.ClassDeclarations | AllowedElements.InterfaceDeclarations | AllowedElements.AmbientDeclarations;
55 AllowedElements.QuickParse = AllowedElements.Global | AllowedElements.Properties;
56 })(TypeScript.AllowedElements || (TypeScript.AllowedElements = {}));
57 var AllowedElements = TypeScript.AllowedElements;
58 (function (Modifiers) {
61 Modifiers.Private = 1;
62 Modifiers.Public = 1 << 1;
63 Modifiers.Readonly = 1 << 2;
64 Modifiers.Ambient = 1 << 3;
65 Modifiers.Exported = 1 << 4;
66 Modifiers.Getter = 1 << 5;
67 Modifiers.Setter = 1 << 6;
68 Modifiers.Static = 1 << 7;
69 })(TypeScript.Modifiers || (TypeScript.Modifiers = {}));
70 var Modifiers = TypeScript.Modifiers;
71 (function (ASTFlags) {
74 ASTFlags.ExplicitSemicolon = 1;
75 ASTFlags.AutomaticSemicolon = 1 << 1;
76 ASTFlags.Writeable = 1 << 2;
77 ASTFlags.Error = 1 << 3;
78 ASTFlags.DotLHSPartial = 1 << 4;
79 ASTFlags.DotLHS = 1 << 5;
80 ASTFlags.IsStatement = 1 << 6;
81 ASTFlags.StrictMode = 1 << 7;
82 ASTFlags.PossibleOptionalParameter = 1 << 8;
83 ASTFlags.ClassBaseConstructorCall = 1 << 9;
84 ASTFlags.OptionalName = 1 << 10;
85 ASTFlags.SkipNextRParen = 1 << 11;
86 })(TypeScript.ASTFlags || (TypeScript.ASTFlags = {}));
87 var ASTFlags = TypeScript.ASTFlags;
88 (function (DeclFlags) {
91 DeclFlags.Exported = 1;
92 DeclFlags.Private = 1 << 1;
93 DeclFlags.Public = 1 << 2;
94 DeclFlags.Ambient = 1 << 3;
95 DeclFlags.Static = 1 << 4;
96 DeclFlags.LocalStatic = 1 << 5;
97 DeclFlags.GetAccessor = 1 << 6;
98 DeclFlags.SetAccessor = 1 << 7;
99 })(TypeScript.DeclFlags || (TypeScript.DeclFlags = {}));
100 var DeclFlags = TypeScript.DeclFlags;
101 (function (ModuleFlags) {
102 ModuleFlags._map = [];
103 ModuleFlags.None = 0;
104 ModuleFlags.Exported = 1;
105 ModuleFlags.Private = 1 << 1;
106 ModuleFlags.Public = 1 << 2;
107 ModuleFlags.Ambient = 1 << 3;
108 ModuleFlags.Static = 1 << 4;
109 ModuleFlags.LocalStatic = 1 << 5;
110 ModuleFlags.GetAccessor = 1 << 6;
111 ModuleFlags.SetAccessor = 1 << 7;
112 ModuleFlags.IsEnum = 1 << 8;
113 ModuleFlags.ShouldEmitModuleDecl = 1 << 9;
114 ModuleFlags.IsWholeFile = 1 << 10;
115 ModuleFlags.IsDynamic = 1 << 11;
116 ModuleFlags.MustCaptureThis = 1 << 12;
117 })(TypeScript.ModuleFlags || (TypeScript.ModuleFlags = {}));
118 var ModuleFlags = TypeScript.ModuleFlags;
119 (function (SymbolFlags) {
120 SymbolFlags._map = [];
121 SymbolFlags.None = 0;
122 SymbolFlags.Exported = 1;
123 SymbolFlags.Private = 1 << 1;
124 SymbolFlags.Public = 1 << 2;
125 SymbolFlags.Ambient = 1 << 3;
126 SymbolFlags.Static = 1 << 4;
127 SymbolFlags.LocalStatic = 1 << 5;
128 SymbolFlags.GetAccessor = 1 << 6;
129 SymbolFlags.SetAccessor = 1 << 7;
130 SymbolFlags.Property = 1 << 8;
131 SymbolFlags.Readonly = 1 << 9;
132 SymbolFlags.ModuleMember = 1 << 10;
133 SymbolFlags.InterfaceMember = 1 << 11;
134 SymbolFlags.ClassMember = 1 << 12;
135 SymbolFlags.BuiltIn = 1 << 13;
136 SymbolFlags.TypeSetDuringScopeAssignment = 1 << 14;
137 SymbolFlags.Constant = 1 << 15;
138 SymbolFlags.Optional = 1 << 16;
139 SymbolFlags.RecursivelyReferenced = 1 << 17;
140 SymbolFlags.Bound = 1 << 18;
141 SymbolFlags.CompilerGenerated = 1 << 19;
142 })(TypeScript.SymbolFlags || (TypeScript.SymbolFlags = {}));
143 var SymbolFlags = TypeScript.SymbolFlags;
144 (function (VarFlags) {
147 VarFlags.Exported = 1;
148 VarFlags.Private = 1 << 1;
149 VarFlags.Public = 1 << 2;
150 VarFlags.Ambient = 1 << 3;
151 VarFlags.Static = 1 << 4;
152 VarFlags.LocalStatic = 1 << 5;
153 VarFlags.GetAccessor = 1 << 6;
154 VarFlags.SetAccessor = 1 << 7;
155 VarFlags.AutoInit = 1 << 8;
156 VarFlags.Property = 1 << 9;
157 VarFlags.Readonly = 1 << 10;
158 VarFlags.Class = 1 << 11;
159 VarFlags.ClassProperty = 1 << 12;
160 VarFlags.ClassBodyProperty = 1 << 13;
161 VarFlags.ClassConstructorProperty = 1 << 14;
162 VarFlags.ClassSuperMustBeFirstCallInConstructor = 1 << 15;
163 VarFlags.Constant = 1 << 16;
164 VarFlags.MustCaptureThis = 1 << 17;
165 })(TypeScript.VarFlags || (TypeScript.VarFlags = {}));
166 var VarFlags = TypeScript.VarFlags;
167 (function (FncFlags) {
170 FncFlags.Exported = 1;
171 FncFlags.Private = 1 << 1;
172 FncFlags.Public = 1 << 2;
173 FncFlags.Ambient = 1 << 3;
174 FncFlags.Static = 1 << 4;
175 FncFlags.LocalStatic = 1 << 5;
176 FncFlags.GetAccessor = 1 << 6;
177 FncFlags.SetAccessor = 1 << 7;
178 FncFlags.Definition = 1 << 8;
179 FncFlags.Signature = 1 << 9;
180 FncFlags.Method = 1 << 10;
181 FncFlags.HasReturnExpression = 1 << 11;
182 FncFlags.CallMember = 1 << 12;
183 FncFlags.ConstructMember = 1 << 13;
184 FncFlags.HasSelfReference = 1 << 14;
185 FncFlags.IsFatArrowFunction = 1 << 15;
186 FncFlags.IndexerMember = 1 << 16;
187 FncFlags.IsFunctionExpression = 1 << 17;
188 FncFlags.ClassMethod = 1 << 18;
189 FncFlags.ClassPropertyMethodExported = 1 << 19;
190 FncFlags.HasSuperReferenceInFatArrowFunction = 1 << 20;
191 FncFlags.IsPropertyBound = 1 << 21;
192 })(TypeScript.FncFlags || (TypeScript.FncFlags = {}));
193 var FncFlags = TypeScript.FncFlags;
194 (function (SignatureFlags) {
195 SignatureFlags._map = [];
196 SignatureFlags.None = 0;
197 SignatureFlags.IsIndexer = 1;
198 SignatureFlags.IsStringIndexer = 1 << 1;
199 SignatureFlags.IsNumberIndexer = 1 << 2;
200 })(TypeScript.SignatureFlags || (TypeScript.SignatureFlags = {}));
201 var SignatureFlags = TypeScript.SignatureFlags;
202 function ToDeclFlags(fncOrVarOrSymbolOrModuleFlags) {
203 return fncOrVarOrSymbolOrModuleFlags;
205 TypeScript.ToDeclFlags = ToDeclFlags;
206 (function (TypeFlags) {
209 TypeFlags.HasImplementation = 1;
210 TypeFlags.HasSelfReference = 1 << 1;
211 TypeFlags.MergeResult = 1 << 2;
212 TypeFlags.IsEnum = 1 << 3;
213 TypeFlags.BuildingName = 1 << 4;
214 TypeFlags.HasBaseType = 1 << 5;
215 TypeFlags.HasBaseTypeOfObject = 1 << 6;
216 TypeFlags.IsClass = 1 << 7;
217 })(TypeScript.TypeFlags || (TypeScript.TypeFlags = {}));
218 var TypeFlags = TypeScript.TypeFlags;
219 (function (TypeRelationshipFlags) {
220 TypeRelationshipFlags._map = [];
221 TypeRelationshipFlags.SuccessfulComparison = 0;
222 TypeRelationshipFlags.SourceIsNullTargetIsVoidOrUndefined = 1;
223 TypeRelationshipFlags.RequiredPropertyIsMissing = 1 << 1;
224 TypeRelationshipFlags.IncompatibleSignatures = 1 << 2;
225 TypeRelationshipFlags.SourceSignatureHasTooManyParameters = 3;
226 TypeRelationshipFlags.IncompatibleReturnTypes = 1 << 4;
227 TypeRelationshipFlags.IncompatiblePropertyTypes = 1 << 5;
228 TypeRelationshipFlags.IncompatibleParameterTypes = 1 << 6;
229 })(TypeScript.TypeRelationshipFlags || (TypeScript.TypeRelationshipFlags = {}));
230 var TypeRelationshipFlags = TypeScript.TypeRelationshipFlags;
231 (function (CodeGenTarget) {
232 CodeGenTarget._map = [];
233 CodeGenTarget.ES3 = 0;
234 CodeGenTarget.ES5 = 1;
235 })(TypeScript.CodeGenTarget || (TypeScript.CodeGenTarget = {}));
236 var CodeGenTarget = TypeScript.CodeGenTarget;
237 (function (ModuleGenTarget) {
238 ModuleGenTarget._map = [];
239 ModuleGenTarget.Synchronous = 0;
240 ModuleGenTarget.Asynchronous = 1;
241 ModuleGenTarget.Local = 1 << 1;
242 })(TypeScript.ModuleGenTarget || (TypeScript.ModuleGenTarget = {}));
243 var ModuleGenTarget = TypeScript.ModuleGenTarget;
244 TypeScript.codeGenTarget = CodeGenTarget.ES3;
245 TypeScript.moduleGenTarget = ModuleGenTarget.Synchronous;
246 TypeScript.optimizeModuleCodeGen = true;
247 function flagsToString(e, flags) {
249 for(var i = 1; i < (1 << 31); i = i << 1) {
250 if((flags & i) != 0) {
253 if(builder.length > 0) {
264 TypeScript.flagsToString = flagsToString;
265 })(TypeScript || (TypeScript = {}));
267 (function (TypeScript) {
268 (function (NodeType) {
270 NodeType._map[0] = "None";
272 NodeType._map[1] = "Empty";
274 NodeType._map[2] = "EmptyExpr";
275 NodeType.EmptyExpr = 2;
276 NodeType._map[3] = "True";
278 NodeType._map[4] = "False";
280 NodeType._map[5] = "This";
282 NodeType._map[6] = "Super";
284 NodeType._map[7] = "QString";
285 NodeType.QString = 7;
286 NodeType._map[8] = "Regex";
288 NodeType._map[9] = "Null";
290 NodeType._map[10] = "ArrayLit";
291 NodeType.ArrayLit = 10;
292 NodeType._map[11] = "ObjectLit";
293 NodeType.ObjectLit = 11;
294 NodeType._map[12] = "Void";
296 NodeType._map[13] = "Comma";
298 NodeType._map[14] = "Pos";
300 NodeType._map[15] = "Neg";
302 NodeType._map[16] = "Delete";
303 NodeType.Delete = 16;
304 NodeType._map[17] = "Await";
306 NodeType._map[18] = "In";
308 NodeType._map[19] = "Dot";
310 NodeType._map[20] = "From";
312 NodeType._map[21] = "Is";
314 NodeType._map[22] = "InstOf";
315 NodeType.InstOf = 22;
316 NodeType._map[23] = "Typeof";
317 NodeType.Typeof = 23;
318 NodeType._map[24] = "NumberLit";
319 NodeType.NumberLit = 24;
320 NodeType._map[25] = "Name";
322 NodeType._map[26] = "TypeRef";
323 NodeType.TypeRef = 26;
324 NodeType._map[27] = "Index";
326 NodeType._map[28] = "Call";
328 NodeType._map[29] = "New";
330 NodeType._map[30] = "Asg";
332 NodeType._map[31] = "AsgAdd";
333 NodeType.AsgAdd = 31;
334 NodeType._map[32] = "AsgSub";
335 NodeType.AsgSub = 32;
336 NodeType._map[33] = "AsgDiv";
337 NodeType.AsgDiv = 33;
338 NodeType._map[34] = "AsgMul";
339 NodeType.AsgMul = 34;
340 NodeType._map[35] = "AsgMod";
341 NodeType.AsgMod = 35;
342 NodeType._map[36] = "AsgAnd";
343 NodeType.AsgAnd = 36;
344 NodeType._map[37] = "AsgXor";
345 NodeType.AsgXor = 37;
346 NodeType._map[38] = "AsgOr";
348 NodeType._map[39] = "AsgLsh";
349 NodeType.AsgLsh = 39;
350 NodeType._map[40] = "AsgRsh";
351 NodeType.AsgRsh = 40;
352 NodeType._map[41] = "AsgRs2";
353 NodeType.AsgRs2 = 41;
354 NodeType._map[42] = "ConditionalExpression";
355 NodeType.ConditionalExpression = 42;
356 NodeType._map[43] = "LogOr";
358 NodeType._map[44] = "LogAnd";
359 NodeType.LogAnd = 44;
360 NodeType._map[45] = "Or";
362 NodeType._map[46] = "Xor";
364 NodeType._map[47] = "And";
366 NodeType._map[48] = "Eq";
368 NodeType._map[49] = "Ne";
370 NodeType._map[50] = "Eqv";
372 NodeType._map[51] = "NEqv";
374 NodeType._map[52] = "Lt";
376 NodeType._map[53] = "Le";
378 NodeType._map[54] = "Gt";
380 NodeType._map[55] = "Ge";
382 NodeType._map[56] = "Add";
384 NodeType._map[57] = "Sub";
386 NodeType._map[58] = "Mul";
388 NodeType._map[59] = "Div";
390 NodeType._map[60] = "Mod";
392 NodeType._map[61] = "Lsh";
394 NodeType._map[62] = "Rsh";
396 NodeType._map[63] = "Rs2";
398 NodeType._map[64] = "Not";
400 NodeType._map[65] = "LogNot";
401 NodeType.LogNot = 65;
402 NodeType._map[66] = "IncPre";
403 NodeType.IncPre = 66;
404 NodeType._map[67] = "DecPre";
405 NodeType.DecPre = 67;
406 NodeType._map[68] = "IncPost";
407 NodeType.IncPost = 68;
408 NodeType._map[69] = "DecPost";
409 NodeType.DecPost = 69;
410 NodeType._map[70] = "TypeAssertion";
411 NodeType.TypeAssertion = 70;
412 NodeType._map[71] = "FuncDecl";
413 NodeType.FuncDecl = 71;
414 NodeType._map[72] = "Member";
415 NodeType.Member = 72;
416 NodeType._map[73] = "VarDecl";
417 NodeType.VarDecl = 73;
418 NodeType._map[74] = "ArgDecl";
419 NodeType.ArgDecl = 74;
420 NodeType._map[75] = "Return";
421 NodeType.Return = 75;
422 NodeType._map[76] = "Break";
424 NodeType._map[77] = "Continue";
425 NodeType.Continue = 77;
426 NodeType._map[78] = "Throw";
428 NodeType._map[79] = "For";
430 NodeType._map[80] = "ForIn";
432 NodeType._map[81] = "If";
434 NodeType._map[82] = "While";
436 NodeType._map[83] = "DoWhile";
437 NodeType.DoWhile = 83;
438 NodeType._map[84] = "Block";
440 NodeType._map[85] = "Case";
442 NodeType._map[86] = "Switch";
443 NodeType.Switch = 86;
444 NodeType._map[87] = "Try";
446 NodeType._map[88] = "TryCatch";
447 NodeType.TryCatch = 88;
448 NodeType._map[89] = "TryFinally";
449 NodeType.TryFinally = 89;
450 NodeType._map[90] = "Finally";
451 NodeType.Finally = 90;
452 NodeType._map[91] = "Catch";
454 NodeType._map[92] = "List";
456 NodeType._map[93] = "Script";
457 NodeType.Script = 93;
458 NodeType._map[94] = "ClassDeclaration";
459 NodeType.ClassDeclaration = 94;
460 NodeType._map[95] = "InterfaceDeclaration";
461 NodeType.InterfaceDeclaration = 95;
462 NodeType._map[96] = "ModuleDeclaration";
463 NodeType.ModuleDeclaration = 96;
464 NodeType._map[97] = "ImportDeclaration";
465 NodeType.ImportDeclaration = 97;
466 NodeType._map[98] = "With";
468 NodeType._map[99] = "Label";
470 NodeType._map[100] = "LabeledStatement";
471 NodeType.LabeledStatement = 100;
472 NodeType._map[101] = "EBStart";
473 NodeType.EBStart = 101;
474 NodeType._map[102] = "GotoEB";
475 NodeType.GotoEB = 102;
476 NodeType._map[103] = "EndCode";
477 NodeType.EndCode = 103;
478 NodeType._map[104] = "Error";
479 NodeType.Error = 104;
480 NodeType._map[105] = "Comment";
481 NodeType.Comment = 105;
482 NodeType._map[106] = "Debugger";
483 NodeType.Debugger = 106;
484 NodeType.GeneralNode = NodeType.FuncDecl;
485 NodeType.LastAsg = NodeType.AsgRs2;
486 })(TypeScript.NodeType || (TypeScript.NodeType = {}));
487 var NodeType = TypeScript.NodeType;
488 })(TypeScript || (TypeScript = {}));
490 (function (TypeScript) {
491 var BlockIntrinsics = (function () {
492 function BlockIntrinsics() {
493 this.prototype = undefined;
494 this.toString = undefined;
495 this.toLocaleString = undefined;
496 this.valueOf = undefined;
497 this.hasOwnProperty = undefined;
498 this.propertyIsEnumerable = undefined;
499 this.isPrototypeOf = undefined;
500 this["constructor"] = undefined;
502 return BlockIntrinsics;
504 TypeScript.BlockIntrinsics = BlockIntrinsics;
505 var StringHashTable = (function () {
506 function StringHashTable() {
508 this.table = (new BlockIntrinsics());
510 StringHashTable.prototype.getAllKeys = function () {
512 for(var k in this.table) {
513 if(this.table[k] != undefined) {
514 result[result.length] = k;
519 StringHashTable.prototype.add = function (key, data) {
520 if(this.table[key] != undefined) {
523 this.table[key] = data;
527 StringHashTable.prototype.addOrUpdate = function (key, data) {
528 if(this.table[key] != undefined) {
529 this.table[key] = data;
532 this.table[key] = data;
536 StringHashTable.prototype.map = function (fn, context) {
537 for(var k in this.table) {
538 var data = this.table[k];
539 if(data != undefined) {
540 fn(k, this.table[k], context);
544 StringHashTable.prototype.every = function (fn, context) {
545 for(var k in this.table) {
546 var data = this.table[k];
547 if(data != undefined) {
548 if(!fn(k, this.table[k], context)) {
555 StringHashTable.prototype.some = function (fn, context) {
556 for(var k in this.table) {
557 var data = this.table[k];
558 if(data != undefined) {
559 if(fn(k, this.table[k], context)) {
566 StringHashTable.prototype.count = function () {
567 return this.itemCount;
569 StringHashTable.prototype.lookup = function (key) {
570 var data = this.table[key];
571 if(data != undefined) {
577 return StringHashTable;
579 TypeScript.StringHashTable = StringHashTable;
580 var DualStringHashTable = (function () {
581 function DualStringHashTable(primaryTable, secondaryTable) {
582 this.primaryTable = primaryTable;
583 this.secondaryTable = secondaryTable;
584 this.insertPrimary = true;
586 DualStringHashTable.prototype.getAllKeys = function () {
587 return this.primaryTable.getAllKeys().concat(this.secondaryTable.getAllKeys());
589 DualStringHashTable.prototype.add = function (key, data) {
590 if(this.insertPrimary) {
591 return this.primaryTable.add(key, data);
593 return this.secondaryTable.add(key, data);
596 DualStringHashTable.prototype.addOrUpdate = function (key, data) {
597 if(this.insertPrimary) {
598 return this.primaryTable.addOrUpdate(key, data);
600 return this.secondaryTable.addOrUpdate(key, data);
603 DualStringHashTable.prototype.map = function (fn, context) {
604 this.primaryTable.map(fn, context);
605 this.secondaryTable.map(fn, context);
607 DualStringHashTable.prototype.every = function (fn, context) {
608 return this.primaryTable.every(fn, context) && this.secondaryTable.every(fn, context);
610 DualStringHashTable.prototype.some = function (fn, context) {
611 return this.primaryTable.some(fn, context) || this.secondaryTable.some(fn, context);
613 DualStringHashTable.prototype.count = function () {
614 return this.primaryTable.count() + this.secondaryTable.count();
616 DualStringHashTable.prototype.lookup = function (key) {
617 var data = this.primaryTable.lookup(key);
618 if(data != undefined) {
621 return this.secondaryTable.lookup(key);
624 return DualStringHashTable;
626 TypeScript.DualStringHashTable = DualStringHashTable;
627 function numberHashFn(key) {
629 key = (key ^ 61) ^ (key >>> 16);
630 key = key + (key << 3);
631 key = key ^ (key >>> 4);
633 key = key ^ (key >>> 15);
636 TypeScript.numberHashFn = numberHashFn;
637 function combineHashes(key1, key2) {
638 return key2 ^ ((key1 >> 5) + key1);
640 TypeScript.combineHashes = combineHashes;
641 var HashEntry = (function () {
642 function HashEntry(key, data) {
648 TypeScript.HashEntry = HashEntry;
649 var HashTable = (function () {
650 function HashTable(size, hashFn, equalsFn) {
652 this.hashFn = hashFn;
653 this.equalsFn = equalsFn;
655 this.table = new Array();
656 for(var i = 0; i < this.size; i++) {
657 this.table[i] = null;
660 HashTable.prototype.add = function (key, data) {
662 var entry = new HashEntry(key, data);
663 var val = this.hashFn(key);
664 val = val % this.size;
665 for(current = this.table[val]; current != null; current = current.next) {
666 if(this.equalsFn(key, current.key)) {
670 entry.next = this.table[val];
671 this.table[val] = entry;
675 HashTable.prototype.remove = function (key) {
677 var val = this.hashFn(key);
678 val = val % this.size;
680 var prevEntry = null;
681 for(current = this.table[val]; current != null; current = current.next) {
682 if(this.equalsFn(key, current.key)) {
683 result = current.data;
686 prevEntry.next = current.next;
688 this.table[val] = current.next;
696 HashTable.prototype.count = function () {
697 return this.itemCount;
699 HashTable.prototype.lookup = function (key) {
701 var val = this.hashFn(key);
702 val = val % this.size;
703 for(current = this.table[val]; current != null; current = current.next) {
704 if(this.equalsFn(key, current.key)) {
705 return (current.data);
712 TypeScript.HashTable = HashTable;
713 var SimpleHashTable = (function () {
714 function SimpleHashTable() {
718 SimpleHashTable.prototype.lookup = function (key, findValue) {
719 var searchArray = this.keys;
721 searchArray = this.values;
723 for(var i = 0; i < searchArray.length; i++) {
724 if(searchArray[i] == key) {
733 SimpleHashTable.prototype.add = function (key, data) {
734 var lookupData = this.lookup(key);
738 this.keys[this.keys.length] = key;
739 this.values[this.values.length] = data;
742 return SimpleHashTable;
744 TypeScript.SimpleHashTable = SimpleHashTable;
745 })(TypeScript || (TypeScript = {}));
746 var __extends = this.__extends || function (d, b) {
747 function __() { this.constructor = d; }
748 __.prototype = b.prototype;
749 d.prototype = new __();
752 (function (TypeScript) {
753 var ASTSpan = (function () {
760 TypeScript.ASTSpan = ASTSpan;
761 var AST = (function (_super) {
762 __extends(AST, _super);
763 function AST(nodeType) {
765 this.nodeType = nodeType;
767 this.flags = TypeScript.ASTFlags.Writeable;
768 this.passCreated = TypeScript.CompilerDiagnostics.analysisPass;
769 this.preComments = null;
770 this.postComments = null;
771 this.docComments = null;
772 this.isParenthesized = false;
774 AST.prototype.isExpression = function () {
777 AST.prototype.isStatementOrExpression = function () {
780 AST.prototype.isCompoundStatement = function () {
783 AST.prototype.isLeaf = function () {
784 return this.isStatementOrExpression() && (!this.isCompoundStatement());
786 AST.prototype.isDeclaration = function () {
789 AST.prototype.typeCheck = function (typeFlow) {
790 switch(this.nodeType) {
791 case TypeScript.NodeType.Error:
792 case TypeScript.NodeType.EmptyExpr: {
793 this.type = typeFlow.anyType;
797 case TypeScript.NodeType.This: {
798 return typeFlow.typeCheckThis(this);
801 case TypeScript.NodeType.Null: {
802 this.type = typeFlow.nullType;
806 case TypeScript.NodeType.False:
807 case TypeScript.NodeType.True: {
808 this.type = typeFlow.booleanType;
812 case TypeScript.NodeType.Super: {
813 return typeFlow.typeCheckSuper(this);
816 case TypeScript.NodeType.EndCode:
817 case TypeScript.NodeType.Empty:
818 case TypeScript.NodeType.Void: {
819 this.type = typeFlow.voidType;
824 throw new Error("please implement in derived class");
830 AST.prototype.emit = function (emitter, tokenId, startLine) {
831 emitter.emitParensAndCommentsInPlace(this, true);
832 switch(this.nodeType) {
833 case TypeScript.NodeType.This: {
834 emitter.recordSourceMappingStart(this);
835 if(emitter.thisFnc && (TypeScript.hasFlag(emitter.thisFnc.fncFlags, TypeScript.FncFlags.IsFatArrowFunction))) {
836 emitter.writeToOutput("_this");
838 emitter.writeToOutput("this");
840 emitter.recordSourceMappingEnd(this);
844 case TypeScript.NodeType.Null: {
845 emitter.recordSourceMappingStart(this);
846 emitter.writeToOutput("null");
847 emitter.recordSourceMappingEnd(this);
851 case TypeScript.NodeType.False: {
852 emitter.recordSourceMappingStart(this);
853 emitter.writeToOutput("false");
854 emitter.recordSourceMappingEnd(this);
858 case TypeScript.NodeType.True: {
859 emitter.recordSourceMappingStart(this);
860 emitter.writeToOutput("true");
861 emitter.recordSourceMappingEnd(this);
865 case TypeScript.NodeType.Super: {
866 emitter.recordSourceMappingStart(this);
867 emitter.emitSuperReference();
868 emitter.recordSourceMappingEnd(this);
872 case TypeScript.NodeType.EndCode:
873 case TypeScript.NodeType.Error:
874 case TypeScript.NodeType.EmptyExpr: {
878 case TypeScript.NodeType.Empty: {
879 emitter.recordSourceMappingStart(this);
880 emitter.recordSourceMappingEnd(this);
884 case TypeScript.NodeType.Void: {
885 emitter.recordSourceMappingStart(this);
886 emitter.writeToOutput("void ");
887 emitter.recordSourceMappingEnd(this);
892 throw new Error("please implement in derived class");
896 emitter.emitParensAndCommentsInPlace(this, false);
898 AST.prototype.print = function (context) {
908 if(context.parser !== null) {
909 context.parser.getSourceLineCol(lineCol, this.minChar);
910 context.parser.getSourceLineCol(limLineCol, this.limChar);
911 context.write("(" + lineCol.line + "," + lineCol.col + ")--" + "(" + limLineCol.line + "," + limLineCol.col + "): ");
913 var lab = this.printLabel();
914 if(TypeScript.hasFlag(this.flags, TypeScript.ASTFlags.Error)) {
917 context.writeLine(lab);
919 AST.prototype.printLabel = function () {
920 if(TypeScript.nodeTypeTable[this.nodeType] !== undefined) {
921 return TypeScript.nodeTypeTable[this.nodeType];
923 return (TypeScript.NodeType)._map[this.nodeType];
926 AST.prototype.addToControlFlow = function (context) {
927 context.walker.options.goChildren = false;
928 context.addContent(this);
930 AST.prototype.netFreeUses = function (container, freeUses) {
932 AST.prototype.treeViewLabel = function () {
933 return (TypeScript.NodeType)._map[this.nodeType];
935 AST.getResolvedIdentifierName = function getResolvedIdentifierName(name) {
942 while(i <= name.length - 6) {
943 if(name.charAt(i) == '\\' && name.charAt(i + 1) == 'u') {
944 var charCode = parseInt(name.substr(i + 2, 4), 16);
945 resolved += name.substr(start, i - start);
946 resolved += String.fromCharCode(charCode);
953 resolved += name.substring(start);
956 AST.prototype.getDocComments = function () {
957 if(!this.isDeclaration() || !this.preComments || this.preComments.length == 0) {
960 if(!this.docComments) {
961 var preCommentsLength = this.preComments.length;
962 var docComments = [];
963 for(var i = preCommentsLength - 1; i >= 0; i--) {
964 if(this.preComments[i].isDocComment()) {
965 var prevDocComment = docComments.length > 0 ? docComments[docComments.length - 1] : null;
966 if(prevDocComment == null || (this.preComments[i].limLine == prevDocComment.minLine || this.preComments[i].limLine + 1 == prevDocComment.minLine)) {
967 docComments.push(this.preComments[i]);
973 this.docComments = docComments.reverse();
975 return this.docComments;
979 TypeScript.AST = AST;
980 var IncompleteAST = (function (_super) {
981 __extends(IncompleteAST, _super);
982 function IncompleteAST(min, lim) {
983 _super.call(this, TypeScript.NodeType.Error);
987 return IncompleteAST;
989 TypeScript.IncompleteAST = IncompleteAST;
990 var ASTList = (function (_super) {
991 __extends(ASTList, _super);
993 _super.call(this, TypeScript.NodeType.List);
994 this.enclosingScope = null;
995 this.members = new Array();
997 ASTList.prototype.addToControlFlow = function (context) {
998 var len = this.members.length;
999 for(var i = 0; i < len; i++) {
1000 if(context.noContinuation) {
1001 context.addUnreachable(this.members[i]);
1004 this.members[i] = context.walk(this.members[i], this);
1007 context.walker.options.goChildren = false;
1009 ASTList.prototype.append = function (ast) {
1010 this.members[this.members.length] = ast;
1013 ASTList.prototype.appendAll = function (ast) {
1014 if(ast.nodeType == TypeScript.NodeType.List) {
1016 for(var i = 0, len = list.members.length; i < len; i++) {
1017 this.append(list.members[i]);
1024 ASTList.prototype.emit = function (emitter, tokenId, startLine) {
1025 emitter.recordSourceMappingStart(this);
1026 emitter.emitJavascriptList(this, null, TypeScript.TokenID.Semicolon, startLine, false, false);
1027 emitter.recordSourceMappingEnd(this);
1029 ASTList.prototype.typeCheck = function (typeFlow) {
1030 var len = this.members.length;
1031 typeFlow.nestingLevel++;
1032 for(var i = 0; i < len; i++) {
1033 if(this.members[i]) {
1034 this.members[i] = this.members[i].typeCheck(typeFlow);
1037 typeFlow.nestingLevel--;
1042 TypeScript.ASTList = ASTList;
1043 var Identifier = (function (_super) {
1044 __extends(Identifier, _super);
1045 function Identifier(actualText, hasEscapeSequence) {
1046 _super.call(this, TypeScript.NodeType.Name);
1047 this.actualText = actualText;
1048 this.hasEscapeSequence = hasEscapeSequence;
1051 this.setText(actualText, hasEscapeSequence);
1053 Identifier.prototype.setText = function (actualText, hasEscapeSequence) {
1054 this.actualText = actualText;
1055 if(hasEscapeSequence) {
1056 this.text = AST.getResolvedIdentifierName(actualText);
1058 this.text = actualText;
1061 Identifier.prototype.isMissing = function () {
1064 Identifier.prototype.isLeaf = function () {
1067 Identifier.prototype.treeViewLabel = function () {
1068 return "id: " + this.actualText;
1070 Identifier.prototype.printLabel = function () {
1071 if(this.actualText) {
1072 return "id: " + this.actualText;
1077 Identifier.prototype.typeCheck = function (typeFlow) {
1078 return typeFlow.typeCheckName(this);
1080 Identifier.prototype.emit = function (emitter, tokenId, startLine) {
1081 emitter.emitJavascriptName(this, true);
1083 Identifier.fromToken = function fromToken(token) {
1084 return new Identifier(token.getText(), (token).hasEscapeSequence);
1088 TypeScript.Identifier = Identifier;
1089 var MissingIdentifier = (function (_super) {
1090 __extends(MissingIdentifier, _super);
1091 function MissingIdentifier() {
1092 _super.call(this, "__missing");
1094 MissingIdentifier.prototype.isMissing = function () {
1097 MissingIdentifier.prototype.emit = function (emitter, tokenId, startLine) {
1099 return MissingIdentifier;
1101 TypeScript.MissingIdentifier = MissingIdentifier;
1102 var Label = (function (_super) {
1103 __extends(Label, _super);
1104 function Label(id) {
1105 _super.call(this, TypeScript.NodeType.Label);
1108 Label.prototype.printLabel = function () {
1109 return this.id.actualText + ":";
1111 Label.prototype.typeCheck = function (typeFlow) {
1112 this.type = typeFlow.voidType;
1115 Label.prototype.emit = function (emitter, tokenId, startLine) {
1116 emitter.emitParensAndCommentsInPlace(this, true);
1117 emitter.recordSourceMappingStart(this);
1118 emitter.recordSourceMappingStart(this.id);
1119 emitter.writeToOutput(this.id.actualText);
1120 emitter.recordSourceMappingEnd(this.id);
1121 emitter.writeLineToOutput(":");
1122 emitter.recordSourceMappingEnd(this);
1123 emitter.emitParensAndCommentsInPlace(this, false);
1127 TypeScript.Label = Label;
1128 var Expression = (function (_super) {
1129 __extends(Expression, _super);
1130 function Expression(nodeType) {
1131 _super.call(this, nodeType);
1133 Expression.prototype.isExpression = function () {
1136 Expression.prototype.isStatementOrExpression = function () {
1141 TypeScript.Expression = Expression;
1142 var UnaryExpression = (function (_super) {
1143 __extends(UnaryExpression, _super);
1144 function UnaryExpression(nodeType, operand) {
1145 _super.call(this, nodeType);
1146 this.operand = operand;
1147 this.targetType = null;
1148 this.castTerm = null;
1150 UnaryExpression.prototype.addToControlFlow = function (context) {
1151 _super.prototype.addToControlFlow.call(this, context);
1152 if(this.nodeType == TypeScript.NodeType.Throw) {
1153 context.returnStmt();
1156 UnaryExpression.prototype.typeCheck = function (typeFlow) {
1157 switch(this.nodeType) {
1158 case TypeScript.NodeType.Not: {
1159 return typeFlow.typeCheckBitNot(this);
1162 case TypeScript.NodeType.LogNot: {
1163 return typeFlow.typeCheckLogNot(this);
1166 case TypeScript.NodeType.Pos:
1167 case TypeScript.NodeType.Neg: {
1168 return typeFlow.typeCheckUnaryNumberOperator(this);
1171 case TypeScript.NodeType.IncPost:
1172 case TypeScript.NodeType.IncPre:
1173 case TypeScript.NodeType.DecPost:
1174 case TypeScript.NodeType.DecPre: {
1175 return typeFlow.typeCheckIncOrDec(this);
1178 case TypeScript.NodeType.ArrayLit: {
1179 typeFlow.typeCheckArrayLit(this);
1183 case TypeScript.NodeType.ObjectLit: {
1184 typeFlow.typeCheckObjectLit(this);
1188 case TypeScript.NodeType.Throw: {
1189 this.operand = typeFlow.typeCheck(this.operand);
1190 this.type = typeFlow.voidType;
1194 case TypeScript.NodeType.Typeof: {
1195 this.operand = typeFlow.typeCheck(this.operand);
1196 this.type = typeFlow.stringType;
1200 case TypeScript.NodeType.Delete: {
1201 this.operand = typeFlow.typeCheck(this.operand);
1202 this.type = typeFlow.booleanType;
1206 case TypeScript.NodeType.TypeAssertion: {
1207 this.castTerm = typeFlow.typeCheck(this.castTerm);
1208 var applyTargetType = !this.operand.isParenthesized;
1209 var targetType = applyTargetType ? this.castTerm.type : null;
1210 typeFlow.checker.typeCheckWithContextualType(targetType, typeFlow.checker.inProvisionalTypecheckMode(), true, this.operand);
1211 typeFlow.castWithCoercion(this.operand, this.castTerm.type, false, true);
1212 this.type = this.castTerm.type;
1216 case TypeScript.NodeType.Void: {
1217 this.operand = typeFlow.typeCheck(this.operand);
1218 this.type = typeFlow.checker.undefinedType;
1223 throw new Error("please implement in derived class");
1229 UnaryExpression.prototype.emit = function (emitter, tokenId, startLine) {
1230 emitter.emitParensAndCommentsInPlace(this, true);
1231 emitter.recordSourceMappingStart(this);
1232 switch(this.nodeType) {
1233 case TypeScript.NodeType.IncPost: {
1234 emitter.emitJavascript(this.operand, TypeScript.TokenID.PlusPlus, false);
1235 emitter.writeToOutput("++");
1239 case TypeScript.NodeType.LogNot: {
1240 emitter.writeToOutput("!");
1241 emitter.emitJavascript(this.operand, TypeScript.TokenID.Exclamation, false);
1245 case TypeScript.NodeType.DecPost: {
1246 emitter.emitJavascript(this.operand, TypeScript.TokenID.MinusMinus, false);
1247 emitter.writeToOutput("--");
1251 case TypeScript.NodeType.ObjectLit: {
1252 emitter.emitObjectLiteral(this.operand);
1256 case TypeScript.NodeType.ArrayLit: {
1257 emitter.emitArrayLiteral(this.operand);
1261 case TypeScript.NodeType.Not: {
1262 emitter.writeToOutput("~");
1263 emitter.emitJavascript(this.operand, TypeScript.TokenID.Tilde, false);
1267 case TypeScript.NodeType.Neg: {
1268 emitter.writeToOutput("-");
1269 if(this.operand.nodeType == TypeScript.NodeType.Neg) {
1270 this.operand.isParenthesized = true;
1272 emitter.emitJavascript(this.operand, TypeScript.TokenID.Minus, false);
1276 case TypeScript.NodeType.Pos: {
1277 emitter.writeToOutput("+");
1278 if(this.operand.nodeType == TypeScript.NodeType.Pos) {
1279 this.operand.isParenthesized = true;
1281 emitter.emitJavascript(this.operand, TypeScript.TokenID.Plus, false);
1285 case TypeScript.NodeType.IncPre: {
1286 emitter.writeToOutput("++");
1287 emitter.emitJavascript(this.operand, TypeScript.TokenID.PlusPlus, false);
1291 case TypeScript.NodeType.DecPre: {
1292 emitter.writeToOutput("--");
1293 emitter.emitJavascript(this.operand, TypeScript.TokenID.MinusMinus, false);
1297 case TypeScript.NodeType.Throw: {
1298 emitter.writeToOutput("throw ");
1299 emitter.emitJavascript(this.operand, TypeScript.TokenID.Tilde, false);
1300 emitter.writeToOutput(";");
1304 case TypeScript.NodeType.Typeof: {
1305 emitter.writeToOutput("typeof ");
1306 emitter.emitJavascript(this.operand, TypeScript.TokenID.Tilde, false);
1310 case TypeScript.NodeType.Delete: {
1311 emitter.writeToOutput("delete ");
1312 emitter.emitJavascript(this.operand, TypeScript.TokenID.Tilde, false);
1316 case TypeScript.NodeType.Void: {
1317 emitter.writeToOutput("void ");
1318 emitter.emitJavascript(this.operand, TypeScript.TokenID.Tilde, false);
1322 case TypeScript.NodeType.TypeAssertion: {
1323 emitter.emitJavascript(this.operand, TypeScript.TokenID.Tilde, false);
1328 throw new Error("please implement in derived class");
1332 emitter.recordSourceMappingEnd(this);
1333 emitter.emitParensAndCommentsInPlace(this, false);
1335 return UnaryExpression;
1337 TypeScript.UnaryExpression = UnaryExpression;
1338 var CallExpression = (function (_super) {
1339 __extends(CallExpression, _super);
1340 function CallExpression(nodeType, target, arguments) {
1341 _super.call(this, nodeType);
1342 this.target = target;
1343 this.arguments = arguments;
1344 this.signature = null;
1345 this.minChar = this.target.minChar;
1347 CallExpression.prototype.typeCheck = function (typeFlow) {
1348 if(this.nodeType == TypeScript.NodeType.New) {
1349 return typeFlow.typeCheckNew(this);
1351 return typeFlow.typeCheckCall(this);
1354 CallExpression.prototype.emit = function (emitter, tokenId, startLine) {
1355 emitter.emitParensAndCommentsInPlace(this, true);
1356 emitter.recordSourceMappingStart(this);
1357 if(this.nodeType == TypeScript.NodeType.New) {
1358 emitter.emitNew(this.target, this.arguments);
1360 emitter.emitCall(this, this.target, this.arguments);
1362 emitter.recordSourceMappingEnd(this);
1363 emitter.emitParensAndCommentsInPlace(this, false);
1365 return CallExpression;
1367 TypeScript.CallExpression = CallExpression;
1368 var BinaryExpression = (function (_super) {
1369 __extends(BinaryExpression, _super);
1370 function BinaryExpression(nodeType, operand1, operand2) {
1371 _super.call(this, nodeType);
1372 this.operand1 = operand1;
1373 this.operand2 = operand2;
1375 BinaryExpression.prototype.typeCheck = function (typeFlow) {
1376 switch(this.nodeType) {
1377 case TypeScript.NodeType.Dot: {
1378 return typeFlow.typeCheckDotOperator(this);
1381 case TypeScript.NodeType.Asg: {
1382 return typeFlow.typeCheckAsgOperator(this);
1385 case TypeScript.NodeType.Add:
1386 case TypeScript.NodeType.Sub:
1387 case TypeScript.NodeType.Mul:
1388 case TypeScript.NodeType.Div:
1389 case TypeScript.NodeType.Mod:
1390 case TypeScript.NodeType.Or:
1391 case TypeScript.NodeType.And: {
1392 return typeFlow.typeCheckArithmeticOperator(this, false);
1395 case TypeScript.NodeType.Xor: {
1396 return typeFlow.typeCheckBitwiseOperator(this, false);
1399 case TypeScript.NodeType.Ne:
1400 case TypeScript.NodeType.Eq: {
1402 if(typeFlow.checker.styleSettings.eqeqeq) {
1403 text = TypeScript.nodeTypeTable[this.nodeType];
1404 typeFlow.checker.errorReporter.styleError(this, "use of " + text);
1406 if(typeFlow.checker.styleSettings.eqnull) {
1407 text = TypeScript.nodeTypeTable[this.nodeType];
1408 if((this.operand2 !== null) && (this.operand2.nodeType == TypeScript.NodeType.Null)) {
1409 typeFlow.checker.errorReporter.styleError(this, "use of " + text + " to compare with null");
1415 case TypeScript.NodeType.Eqv:
1416 case TypeScript.NodeType.NEqv:
1417 case TypeScript.NodeType.Lt:
1418 case TypeScript.NodeType.Le:
1419 case TypeScript.NodeType.Ge:
1420 case TypeScript.NodeType.Gt: {
1421 return typeFlow.typeCheckBooleanOperator(this);
1424 case TypeScript.NodeType.Index: {
1425 return typeFlow.typeCheckIndex(this);
1428 case TypeScript.NodeType.Member: {
1429 this.type = typeFlow.voidType;
1433 case TypeScript.NodeType.LogOr: {
1434 return typeFlow.typeCheckLogOr(this);
1437 case TypeScript.NodeType.LogAnd: {
1438 return typeFlow.typeCheckLogAnd(this);
1441 case TypeScript.NodeType.AsgAdd:
1442 case TypeScript.NodeType.AsgSub:
1443 case TypeScript.NodeType.AsgMul:
1444 case TypeScript.NodeType.AsgDiv:
1445 case TypeScript.NodeType.AsgMod:
1446 case TypeScript.NodeType.AsgOr:
1447 case TypeScript.NodeType.AsgAnd: {
1448 return typeFlow.typeCheckArithmeticOperator(this, true);
1451 case TypeScript.NodeType.AsgXor: {
1452 return typeFlow.typeCheckBitwiseOperator(this, true);
1455 case TypeScript.NodeType.Lsh:
1456 case TypeScript.NodeType.Rsh:
1457 case TypeScript.NodeType.Rs2: {
1458 return typeFlow.typeCheckShift(this, false);
1461 case TypeScript.NodeType.AsgLsh:
1462 case TypeScript.NodeType.AsgRsh:
1463 case TypeScript.NodeType.AsgRs2: {
1464 return typeFlow.typeCheckShift(this, true);
1467 case TypeScript.NodeType.Comma: {
1468 return typeFlow.typeCheckCommaOperator(this);
1471 case TypeScript.NodeType.InstOf: {
1472 return typeFlow.typeCheckInstOf(this);
1475 case TypeScript.NodeType.In: {
1476 return typeFlow.typeCheckInOperator(this);
1479 case TypeScript.NodeType.From: {
1480 typeFlow.checker.errorReporter.simpleError(this, "Illegal use of 'from' keyword in binary expression");
1485 throw new Error("please implement in derived class");
1491 BinaryExpression.prototype.emit = function (emitter, tokenId, startLine) {
1492 var binTokenId = TypeScript.nodeTypeToTokTable[this.nodeType];
1493 emitter.emitParensAndCommentsInPlace(this, true);
1494 emitter.recordSourceMappingStart(this);
1495 if(binTokenId != undefined) {
1496 emitter.emitJavascript(this.operand1, binTokenId, false);
1497 if(TypeScript.tokenTable[binTokenId].text == "instanceof") {
1498 emitter.writeToOutput(" instanceof ");
1500 if(TypeScript.tokenTable[binTokenId].text == "in") {
1501 emitter.writeToOutput(" in ");
1503 emitter.writeToOutputTrimmable(" " + TypeScript.tokenTable[binTokenId].text + " ");
1506 emitter.emitJavascript(this.operand2, binTokenId, false);
1508 switch(this.nodeType) {
1509 case TypeScript.NodeType.Dot: {
1510 if(!emitter.tryEmitConstant(this)) {
1511 emitter.emitJavascript(this.operand1, TypeScript.TokenID.Dot, false);
1512 emitter.writeToOutput(".");
1513 emitter.emitJavascriptName(this.operand2, false);
1518 case TypeScript.NodeType.Index: {
1519 emitter.emitIndex(this.operand1, this.operand2);
1523 case TypeScript.NodeType.Member: {
1524 if(this.operand2.nodeType == TypeScript.NodeType.FuncDecl && (this.operand2).isAccessor()) {
1525 var funcDecl = this.operand2;
1526 if(TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.GetAccessor)) {
1527 emitter.writeToOutput("get ");
1529 emitter.writeToOutput("set ");
1531 emitter.emitJavascript(this.operand1, TypeScript.TokenID.Colon, false);
1533 emitter.emitJavascript(this.operand1, TypeScript.TokenID.Colon, false);
1534 emitter.writeToOutputTrimmable(": ");
1536 emitter.emitJavascript(this.operand2, TypeScript.TokenID.Comma, false);
1540 case TypeScript.NodeType.Comma: {
1541 emitter.emitJavascript(this.operand1, TypeScript.TokenID.Comma, false);
1542 if(emitter.emitState.inObjectLiteral) {
1543 emitter.writeLineToOutput(", ");
1545 emitter.writeToOutput(",");
1547 emitter.emitJavascript(this.operand2, TypeScript.TokenID.Comma, false);
1551 case TypeScript.NodeType.Is: {
1552 throw new Error("should be de-sugared during type check");
1556 throw new Error("please implement in derived class");
1561 emitter.recordSourceMappingEnd(this);
1562 emitter.emitParensAndCommentsInPlace(this, false);
1564 return BinaryExpression;
1566 TypeScript.BinaryExpression = BinaryExpression;
1567 var ConditionalExpression = (function (_super) {
1568 __extends(ConditionalExpression, _super);
1569 function ConditionalExpression(operand1, operand2, operand3) {
1570 _super.call(this, TypeScript.NodeType.ConditionalExpression);
1571 this.operand1 = operand1;
1572 this.operand2 = operand2;
1573 this.operand3 = operand3;
1575 ConditionalExpression.prototype.typeCheck = function (typeFlow) {
1576 return typeFlow.typeCheckQMark(this);
1578 ConditionalExpression.prototype.emit = function (emitter, tokenId, startLine) {
1579 emitter.emitParensAndCommentsInPlace(this, true);
1580 emitter.recordSourceMappingStart(this);
1581 emitter.emitJavascript(this.operand1, TypeScript.TokenID.Question, false);
1582 emitter.writeToOutput(" ? ");
1583 emitter.emitJavascript(this.operand2, TypeScript.TokenID.Question, false);
1584 emitter.writeToOutput(" : ");
1585 emitter.emitJavascript(this.operand3, TypeScript.TokenID.Question, false);
1586 emitter.recordSourceMappingEnd(this);
1587 emitter.emitParensAndCommentsInPlace(this, false);
1589 return ConditionalExpression;
1591 TypeScript.ConditionalExpression = ConditionalExpression;
1592 var NumberLiteral = (function (_super) {
1593 __extends(NumberLiteral, _super);
1594 function NumberLiteral(value, hasEmptyFraction) {
1595 _super.call(this, TypeScript.NodeType.NumberLit);
1597 this.hasEmptyFraction = hasEmptyFraction;
1598 this.isNegativeZero = false;
1600 NumberLiteral.prototype.typeCheck = function (typeFlow) {
1601 this.type = typeFlow.doubleType;
1604 NumberLiteral.prototype.treeViewLabel = function () {
1605 return "num: " + this.printLabel();
1607 NumberLiteral.prototype.emit = function (emitter, tokenId, startLine) {
1608 emitter.emitParensAndCommentsInPlace(this, true);
1609 emitter.recordSourceMappingStart(this);
1610 if(this.isNegativeZero) {
1611 emitter.writeToOutput("-");
1613 emitter.writeToOutput(this.value.toString());
1614 if(this.hasEmptyFraction) {
1615 emitter.writeToOutput(".0");
1617 emitter.recordSourceMappingEnd(this);
1618 emitter.emitParensAndCommentsInPlace(this, false);
1620 NumberLiteral.prototype.printLabel = function () {
1621 if(Math.floor(this.value) != this.value) {
1622 return this.value.toFixed(2).toString();
1624 if(this.hasEmptyFraction) {
1625 return this.value.toString() + ".0";
1627 return this.value.toString();
1631 return NumberLiteral;
1633 TypeScript.NumberLiteral = NumberLiteral;
1634 var RegexLiteral = (function (_super) {
1635 __extends(RegexLiteral, _super);
1636 function RegexLiteral(regex) {
1637 _super.call(this, TypeScript.NodeType.Regex);
1640 RegexLiteral.prototype.typeCheck = function (typeFlow) {
1641 this.type = typeFlow.regexType;
1644 RegexLiteral.prototype.emit = function (emitter, tokenId, startLine) {
1645 emitter.emitParensAndCommentsInPlace(this, true);
1646 emitter.recordSourceMappingStart(this);
1647 emitter.writeToOutput(this.regex.toString());
1648 emitter.recordSourceMappingEnd(this);
1649 emitter.emitParensAndCommentsInPlace(this, false);
1651 return RegexLiteral;
1653 TypeScript.RegexLiteral = RegexLiteral;
1654 var StringLiteral = (function (_super) {
1655 __extends(StringLiteral, _super);
1656 function StringLiteral(text) {
1657 _super.call(this, TypeScript.NodeType.QString);
1660 StringLiteral.prototype.emit = function (emitter, tokenId, startLine) {
1661 emitter.emitParensAndCommentsInPlace(this, true);
1662 emitter.recordSourceMappingStart(this);
1663 emitter.emitStringLiteral(this.text);
1664 emitter.recordSourceMappingEnd(this);
1665 emitter.emitParensAndCommentsInPlace(this, false);
1667 StringLiteral.prototype.typeCheck = function (typeFlow) {
1668 this.type = typeFlow.stringType;
1671 StringLiteral.prototype.treeViewLabel = function () {
1672 return "st: " + this.text;
1674 StringLiteral.prototype.printLabel = function () {
1677 return StringLiteral;
1679 TypeScript.StringLiteral = StringLiteral;
1680 var ModuleElement = (function (_super) {
1681 __extends(ModuleElement, _super);
1682 function ModuleElement(nodeType) {
1683 _super.call(this, nodeType);
1685 return ModuleElement;
1687 TypeScript.ModuleElement = ModuleElement;
1688 var ImportDeclaration = (function (_super) {
1689 __extends(ImportDeclaration, _super);
1690 function ImportDeclaration(id, alias) {
1691 _super.call(this, TypeScript.NodeType.ImportDeclaration);
1694 this.varFlags = TypeScript.VarFlags.None;
1695 this.isDynamicImport = false;
1697 ImportDeclaration.prototype.isStatementOrExpression = function () {
1700 ImportDeclaration.prototype.isDeclaration = function () {
1703 ImportDeclaration.prototype.emit = function (emitter, tokenId, startLine) {
1704 var mod = this.alias.type;
1705 if(!this.isDynamicImport || (this.id.sym && !(this.id.sym).onlyReferencedAsTypeRef)) {
1706 var prevModAliasId = emitter.modAliasId;
1707 var prevFirstModAlias = emitter.firstModAlias;
1708 emitter.recordSourceMappingStart(this);
1709 emitter.emitParensAndCommentsInPlace(this, true);
1710 emitter.writeToOutput("var " + this.id.actualText + " = ");
1711 emitter.modAliasId = this.id.actualText;
1712 emitter.firstModAlias = this.firstAliasedModToString();
1713 emitter.emitJavascript(this.alias, TypeScript.TokenID.Tilde, false);
1714 if(!this.isDynamicImport) {
1715 emitter.writeToOutput(";");
1717 emitter.emitParensAndCommentsInPlace(this, false);
1718 emitter.recordSourceMappingEnd(this);
1719 emitter.modAliasId = prevModAliasId;
1720 emitter.firstModAlias = prevFirstModAlias;
1723 ImportDeclaration.prototype.typeCheck = function (typeFlow) {
1724 return typeFlow.typeCheckImportDecl(this);
1726 ImportDeclaration.prototype.getAliasName = function (aliasAST) {
1727 if (typeof aliasAST === "undefined") { aliasAST = this.alias; }
1728 if(aliasAST.nodeType == TypeScript.NodeType.Name) {
1729 return (aliasAST).actualText;
1731 var dotExpr = aliasAST;
1732 return this.getAliasName(dotExpr.operand1) + "." + this.getAliasName(dotExpr.operand2);
1735 ImportDeclaration.prototype.firstAliasedModToString = function () {
1736 if(this.alias.nodeType == TypeScript.NodeType.Name) {
1737 return (this.alias).actualText;
1739 var dotExpr = this.alias;
1740 var firstMod = dotExpr.operand1;
1741 return firstMod.actualText;
1744 return ImportDeclaration;
1746 TypeScript.ImportDeclaration = ImportDeclaration;
1747 var BoundDecl = (function (_super) {
1748 __extends(BoundDecl, _super);
1749 function BoundDecl(id, nodeType, nestingLevel) {
1750 _super.call(this, nodeType);
1752 this.nestingLevel = nestingLevel;
1754 this.typeExpr = null;
1755 this.varFlags = TypeScript.VarFlags.None;
1758 BoundDecl.prototype.isDeclaration = function () {
1761 BoundDecl.prototype.isStatementOrExpression = function () {
1764 BoundDecl.prototype.isPrivate = function () {
1765 return TypeScript.hasFlag(this.varFlags, TypeScript.VarFlags.Private);
1767 BoundDecl.prototype.isPublic = function () {
1768 return TypeScript.hasFlag(this.varFlags, TypeScript.VarFlags.Public);
1770 BoundDecl.prototype.isProperty = function () {
1771 return TypeScript.hasFlag(this.varFlags, TypeScript.VarFlags.Property);
1773 BoundDecl.prototype.typeCheck = function (typeFlow) {
1774 return typeFlow.typeCheckBoundDecl(this);
1776 BoundDecl.prototype.printLabel = function () {
1777 return this.treeViewLabel();
1781 TypeScript.BoundDecl = BoundDecl;
1782 var VarDecl = (function (_super) {
1783 __extends(VarDecl, _super);
1784 function VarDecl(id, nest) {
1785 _super.call(this, id, TypeScript.NodeType.VarDecl, nest);
1787 VarDecl.prototype.isAmbient = function () {
1788 return TypeScript.hasFlag(this.varFlags, TypeScript.VarFlags.Ambient);
1790 VarDecl.prototype.isExported = function () {
1791 return TypeScript.hasFlag(this.varFlags, TypeScript.VarFlags.Exported);
1793 VarDecl.prototype.isStatic = function () {
1794 return TypeScript.hasFlag(this.varFlags, TypeScript.VarFlags.Static);
1796 VarDecl.prototype.emit = function (emitter, tokenId, startLine) {
1797 emitter.emitJavascriptVarDecl(this, tokenId);
1799 VarDecl.prototype.treeViewLabel = function () {
1800 return "var " + this.id.actualText;
1804 TypeScript.VarDecl = VarDecl;
1805 var ArgDecl = (function (_super) {
1806 __extends(ArgDecl, _super);
1807 function ArgDecl(id) {
1808 _super.call(this, id, TypeScript.NodeType.ArgDecl, 0);
1809 this.isOptional = false;
1810 this.parameterPropertySym = null;
1812 ArgDecl.prototype.isOptionalArg = function () {
1813 return this.isOptional || this.init;
1815 ArgDecl.prototype.treeViewLabel = function () {
1816 return "arg: " + this.id.actualText;
1818 ArgDecl.prototype.emit = function (emitter, tokenId, startLine) {
1819 emitter.emitParensAndCommentsInPlace(this, true);
1820 emitter.recordSourceMappingStart(this);
1821 emitter.writeToOutput(this.id.actualText);
1822 emitter.recordSourceMappingEnd(this);
1823 emitter.emitParensAndCommentsInPlace(this, false);
1827 TypeScript.ArgDecl = ArgDecl;
1829 var FuncDecl = (function (_super) {
1830 __extends(FuncDecl, _super);
1831 function FuncDecl(name, bod, isConstructor, arguments, vars, scopes, statics, nodeType) {
1832 _super.call(this, nodeType);
1835 this.isConstructor = isConstructor;
1836 this.arguments = arguments;
1838 this.scopes = scopes;
1839 this.statics = statics;
1841 this.fncFlags = TypeScript.FncFlags.None;
1842 this.returnTypeAnnotation = null;
1843 this.variableArgList = false;
1844 this.jumpRefs = null;
1845 this.internalNameCache = null;
1846 this.tmp1Declared = false;
1847 this.enclosingFnc = null;
1848 this.freeVariables = [];
1849 this.unitIndex = -1;
1850 this.classDecl = null;
1851 this.boundToProperty = null;
1852 this.isOverload = false;
1853 this.innerStaticFuncs = [];
1854 this.isTargetTypedAsMethod = false;
1855 this.isInlineCallLiteral = false;
1856 this.accessorSymbol = null;
1857 this.leftCurlyCount = 0;
1858 this.rightCurlyCount = 0;
1859 this.returnStatementsWithExpressions = [];
1860 this.scopeType = null;
1861 this.endingToken = null;
1863 FuncDecl.prototype.isDeclaration = function () {
1866 FuncDecl.prototype.internalName = function () {
1867 if(this.internalNameCache == null) {
1868 var extName = this.getNameText();
1870 this.internalNameCache = "_internal_" + extName;
1872 this.internalNameCache = "_internal_" + internalId++;
1875 return this.internalNameCache;
1877 FuncDecl.prototype.hasSelfReference = function () {
1878 return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.HasSelfReference);
1880 FuncDecl.prototype.setHasSelfReference = function () {
1881 this.fncFlags |= TypeScript.FncFlags.HasSelfReference;
1883 FuncDecl.prototype.hasSuperReferenceInFatArrowFunction = function () {
1884 return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.HasSuperReferenceInFatArrowFunction);
1886 FuncDecl.prototype.setHasSuperReferenceInFatArrowFunction = function () {
1887 this.fncFlags |= TypeScript.FncFlags.HasSuperReferenceInFatArrowFunction;
1889 FuncDecl.prototype.addCloRef = function (id, sym) {
1890 if(this.envids == null) {
1891 this.envids = new Array();
1893 this.envids[this.envids.length] = id;
1894 var outerFnc = this.enclosingFnc;
1896 while(outerFnc && (outerFnc.type.symbol != sym.container)) {
1897 outerFnc.addJumpRef(sym);
1898 outerFnc = outerFnc.enclosingFnc;
1901 return this.envids.length - 1;
1903 FuncDecl.prototype.addJumpRef = function (sym) {
1904 if(this.jumpRefs == null) {
1905 this.jumpRefs = new Array();
1907 var id = new Identifier(sym.name);
1908 this.jumpRefs[this.jumpRefs.length] = id;
1910 id.cloId = this.addCloRef(id, null);
1912 FuncDecl.prototype.buildControlFlow = function () {
1913 var entry = new TypeScript.BasicBlock();
1914 var exit = new TypeScript.BasicBlock();
1915 var context = new TypeScript.ControlFlowContext(entry, exit);
1916 var controlFlowPrefix = function (ast, parent, walker) {
1917 ast.addToControlFlow(walker.state);
1920 var walker = TypeScript.getAstWalkerFactory().getWalker(controlFlowPrefix, null, null, context);
1921 context.walker = walker;
1922 walker.walk(this.bod, this);
1925 FuncDecl.prototype.typeCheck = function (typeFlow) {
1926 return typeFlow.typeCheckFunction(this);
1928 FuncDecl.prototype.emit = function (emitter, tokenId, startLine) {
1929 emitter.emitJavascriptFunction(this);
1931 FuncDecl.prototype.getNameText = function () {
1933 return this.name.actualText;
1938 FuncDecl.prototype.isMethod = function () {
1939 return (this.fncFlags & TypeScript.FncFlags.Method) != TypeScript.FncFlags.None;
1941 FuncDecl.prototype.isCallMember = function () {
1942 return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.CallMember);
1944 FuncDecl.prototype.isConstructMember = function () {
1945 return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.ConstructMember);
1947 FuncDecl.prototype.isIndexerMember = function () {
1948 return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.IndexerMember);
1950 FuncDecl.prototype.isSpecialFn = function () {
1951 return this.isCallMember() || this.isIndexerMember() || this.isConstructMember();
1953 FuncDecl.prototype.isAnonymousFn = function () {
1954 return this.name === null;
1956 FuncDecl.prototype.isAccessor = function () {
1957 return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.GetAccessor) || TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.SetAccessor);
1959 FuncDecl.prototype.isGetAccessor = function () {
1960 return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.GetAccessor);
1962 FuncDecl.prototype.isSetAccessor = function () {
1963 return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.SetAccessor);
1965 FuncDecl.prototype.isAmbient = function () {
1966 return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.Ambient);
1968 FuncDecl.prototype.isExported = function () {
1969 return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.Exported);
1971 FuncDecl.prototype.isPrivate = function () {
1972 return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.Private);
1974 FuncDecl.prototype.isPublic = function () {
1975 return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.Public);
1977 FuncDecl.prototype.isStatic = function () {
1978 return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.Static);
1980 FuncDecl.prototype.treeViewLabel = function () {
1981 if(this.name == null) {
1984 return "func: " + this.name.actualText;
1987 FuncDecl.prototype.ClearFlags = function () {
1988 this.fncFlags = TypeScript.FncFlags.None;
1990 FuncDecl.prototype.isSignature = function () {
1991 return (this.fncFlags & TypeScript.FncFlags.Signature) != TypeScript.FncFlags.None;
1995 TypeScript.FuncDecl = FuncDecl;
1996 var LocationInfo = (function () {
1997 function LocationInfo(filename, lineMap, unitIndex) {
1998 this.filename = filename;
1999 this.lineMap = lineMap;
2000 this.unitIndex = unitIndex;
2002 return LocationInfo;
2004 TypeScript.LocationInfo = LocationInfo;
2005 TypeScript.unknownLocationInfo = new LocationInfo("unknown", null, -1);
2006 var Script = (function (_super) {
2007 __extends(Script, _super);
2008 function Script(vars, scopes) {
2009 _super.call(this, new Identifier("script"), null, false, null, vars, scopes, null, TypeScript.NodeType.Script);
2010 this.locationInfo = null;
2011 this.referencedFiles = [];
2012 this.requiresGlobal = false;
2013 this.requiresExtendsBlock = false;
2014 this.isResident = false;
2015 this.isDeclareFile = false;
2016 this.hasBeenTypeChecked = false;
2017 this.topLevelMod = null;
2018 this.leftCurlyCount = 0;
2019 this.rightCurlyCount = 0;
2020 this.containsUnicodeChar = false;
2021 this.containsUnicodeCharInComment = false;
2022 this.externallyVisibleImportedSymbols = [];
2024 this.scopes = scopes;
2026 Script.prototype.setCachedEmitRequired = function (value) {
2027 this.cachedEmitRequired = value;
2028 return this.cachedEmitRequired;
2030 Script.prototype.typeCheck = function (typeFlow) {
2031 return typeFlow.typeCheckScript(this);
2033 Script.prototype.treeViewLabel = function () {
2036 Script.prototype.emitRequired = function (emitOptions) {
2037 if(this.cachedEmitRequired != undefined) {
2038 return this.cachedEmitRequired;
2040 if(!this.isDeclareFile && !this.isResident && this.bod) {
2041 for(var i = 0, len = this.bod.members.length; i < len; i++) {
2042 var stmt = this.bod.members[i];
2043 if(stmt.nodeType == TypeScript.NodeType.ModuleDeclaration) {
2044 if(!TypeScript.hasFlag((stmt).modFlags, TypeScript.ModuleFlags.ShouldEmitModuleDecl | TypeScript.ModuleFlags.Ambient)) {
2045 return this.setCachedEmitRequired(true);
2048 if(stmt.nodeType == TypeScript.NodeType.ClassDeclaration) {
2049 if(!TypeScript.hasFlag((stmt).varFlags, TypeScript.VarFlags.Ambient)) {
2050 return this.setCachedEmitRequired(true);
2053 if(stmt.nodeType == TypeScript.NodeType.VarDecl) {
2054 if(!TypeScript.hasFlag((stmt).varFlags, TypeScript.VarFlags.Ambient)) {
2055 return this.setCachedEmitRequired(true);
2058 if(stmt.nodeType == TypeScript.NodeType.FuncDecl) {
2059 if(!(stmt).isSignature()) {
2060 return this.setCachedEmitRequired(true);
2063 if(stmt.nodeType != TypeScript.NodeType.InterfaceDeclaration && stmt.nodeType != TypeScript.NodeType.Empty) {
2064 return this.setCachedEmitRequired(true);
2071 if(emitOptions.emitComments && ((this.bod.preComments && this.bod.preComments.length > 0) || (this.bod.postComments && this.bod.postComments.length > 0))) {
2072 return this.setCachedEmitRequired(true);
2075 return this.setCachedEmitRequired(false);
2077 Script.prototype.emit = function (emitter, tokenId, startLine) {
2078 if(this.emitRequired(emitter.emitOptions)) {
2079 emitter.emitParensAndCommentsInPlace(this.bod, true);
2080 emitter.emitJavascriptList(this.bod, null, TypeScript.TokenID.Semicolon, true, false, false, true, this.requiresExtendsBlock);
2081 emitter.emitParensAndCommentsInPlace(this.bod, false);
2084 Script.prototype.AddExternallyVisibleImportedSymbol = function (symbol, checker) {
2085 if(this.isExternallyVisibleSymbol(symbol)) {
2088 if(!symbol.getType().symbol.isExternallyVisible(checker)) {
2090 var moduleName = symbol.getType().symbol.prettyName;
2091 if(!TypeScript.isQuoted(moduleName)) {
2094 checker.errorReporter.simpleError(symbol.declAST, "Externally visible import statement uses non exported module " + quotes + moduleName + quotes);
2096 this.externallyVisibleImportedSymbols.push(symbol);
2098 Script.prototype.isExternallyVisibleSymbol = function (symbol) {
2099 for(var i = 0; i < this.externallyVisibleImportedSymbols.length; i++) {
2100 if(this.externallyVisibleImportedSymbols[i] == symbol) {
2108 TypeScript.Script = Script;
2109 var NamedDeclaration = (function (_super) {
2110 __extends(NamedDeclaration, _super);
2111 function NamedDeclaration(nodeType, name, members) {
2112 _super.call(this, nodeType);
2114 this.members = members;
2115 this.leftCurlyCount = 0;
2116 this.rightCurlyCount = 0;
2118 NamedDeclaration.prototype.isDeclaration = function () {
2121 return NamedDeclaration;
2123 TypeScript.NamedDeclaration = NamedDeclaration;
2124 var ModuleDeclaration = (function (_super) {
2125 __extends(ModuleDeclaration, _super);
2126 function ModuleDeclaration(name, members, vars, scopes, endingToken) {
2127 _super.call(this, TypeScript.NodeType.ModuleDeclaration, name, members);
2128 this.endingToken = endingToken;
2129 this.modFlags = TypeScript.ModuleFlags.ShouldEmitModuleDecl;
2130 this.amdDependencies = [];
2131 this.containsUnicodeChar = false;
2132 this.containsUnicodeCharInComment = false;
2134 this.scopes = scopes;
2135 this.prettyName = this.name.actualText;
2137 ModuleDeclaration.prototype.isExported = function () {
2138 return TypeScript.hasFlag(this.modFlags, TypeScript.ModuleFlags.Exported);
2140 ModuleDeclaration.prototype.isAmbient = function () {
2141 return TypeScript.hasFlag(this.modFlags, TypeScript.ModuleFlags.Ambient);
2143 ModuleDeclaration.prototype.isEnum = function () {
2144 return TypeScript.hasFlag(this.modFlags, TypeScript.ModuleFlags.IsEnum);
2146 ModuleDeclaration.prototype.recordNonInterface = function () {
2147 this.modFlags &= ~TypeScript.ModuleFlags.ShouldEmitModuleDecl;
2149 ModuleDeclaration.prototype.typeCheck = function (typeFlow) {
2150 return typeFlow.typeCheckModule(this);
2152 ModuleDeclaration.prototype.emit = function (emitter, tokenId, startLine) {
2153 if(!TypeScript.hasFlag(this.modFlags, TypeScript.ModuleFlags.ShouldEmitModuleDecl)) {
2154 emitter.emitParensAndCommentsInPlace(this, true);
2155 emitter.recordSourceMappingStart(this);
2156 emitter.emitJavascriptModule(this);
2157 emitter.recordSourceMappingEnd(this);
2158 emitter.emitParensAndCommentsInPlace(this, false);
2161 return ModuleDeclaration;
2162 })(NamedDeclaration);
2163 TypeScript.ModuleDeclaration = ModuleDeclaration;
2164 var TypeDeclaration = (function (_super) {
2165 __extends(TypeDeclaration, _super);
2166 function TypeDeclaration(nodeType, name, extendsList, implementsList, members) {
2167 _super.call(this, nodeType, name, members);
2168 this.extendsList = extendsList;
2169 this.implementsList = implementsList;
2170 this.varFlags = TypeScript.VarFlags.None;
2172 TypeDeclaration.prototype.isExported = function () {
2173 return TypeScript.hasFlag(this.varFlags, TypeScript.VarFlags.Exported);
2175 TypeDeclaration.prototype.isAmbient = function () {
2176 return TypeScript.hasFlag(this.varFlags, TypeScript.VarFlags.Ambient);
2178 return TypeDeclaration;
2179 })(NamedDeclaration);
2180 TypeScript.TypeDeclaration = TypeDeclaration;
2181 var ClassDeclaration = (function (_super) {
2182 __extends(ClassDeclaration, _super);
2183 function ClassDeclaration(name, members, extendsList, implementsList) {
2184 _super.call(this, TypeScript.NodeType.ClassDeclaration, name, extendsList, implementsList, members);
2185 this.knownMemberNames = {
2187 this.constructorDecl = null;
2188 this.constructorNestingLevel = 0;
2189 this.endingToken = null;
2191 ClassDeclaration.prototype.typeCheck = function (typeFlow) {
2192 return typeFlow.typeCheckClass(this);
2194 ClassDeclaration.prototype.emit = function (emitter, tokenId, startLine) {
2195 emitter.emitJavascriptClass(this);
2197 return ClassDeclaration;
2198 })(TypeDeclaration);
2199 TypeScript.ClassDeclaration = ClassDeclaration;
2200 var InterfaceDeclaration = (function (_super) {
2201 __extends(InterfaceDeclaration, _super);
2202 function InterfaceDeclaration(name, members, extendsList, implementsList) {
2203 _super.call(this, TypeScript.NodeType.InterfaceDeclaration, name, extendsList, implementsList, members);
2205 InterfaceDeclaration.prototype.typeCheck = function (typeFlow) {
2206 return typeFlow.typeCheckInterface(this);
2208 InterfaceDeclaration.prototype.emit = function (emitter, tokenId, startLine) {
2210 return InterfaceDeclaration;
2211 })(TypeDeclaration);
2212 TypeScript.InterfaceDeclaration = InterfaceDeclaration;
2213 var Statement = (function (_super) {
2214 __extends(Statement, _super);
2215 function Statement(nodeType) {
2216 _super.call(this, nodeType);
2217 this.flags |= TypeScript.ASTFlags.IsStatement;
2219 Statement.prototype.isLoop = function () {
2222 Statement.prototype.isStatementOrExpression = function () {
2225 Statement.prototype.isCompoundStatement = function () {
2226 return this.isLoop();
2228 Statement.prototype.typeCheck = function (typeFlow) {
2229 this.type = typeFlow.voidType;
2234 TypeScript.Statement = Statement;
2235 var LabeledStatement = (function (_super) {
2236 __extends(LabeledStatement, _super);
2237 function LabeledStatement(labels, stmt) {
2238 _super.call(this, TypeScript.NodeType.LabeledStatement);
2239 this.labels = labels;
2242 LabeledStatement.prototype.emit = function (emitter, tokenId, startLine) {
2243 emitter.emitParensAndCommentsInPlace(this, true);
2244 emitter.recordSourceMappingStart(this);
2246 var labelsLen = this.labels.members.length;
2247 for(var i = 0; i < labelsLen; i++) {
2248 this.labels.members[i].emit(emitter, tokenId, startLine);
2251 this.stmt.emit(emitter, tokenId, true);
2252 emitter.recordSourceMappingEnd(this);
2253 emitter.emitParensAndCommentsInPlace(this, false);
2255 LabeledStatement.prototype.typeCheck = function (typeFlow) {
2256 typeFlow.typeCheck(this.labels);
2257 this.stmt = this.stmt.typeCheck(typeFlow);
2260 LabeledStatement.prototype.addToControlFlow = function (context) {
2261 var beforeBB = context.current;
2262 var bb = new TypeScript.BasicBlock();
2263 context.current = bb;
2264 beforeBB.addSuccessor(bb);
2266 return LabeledStatement;
2268 TypeScript.LabeledStatement = LabeledStatement;
2269 var Block = (function (_super) {
2270 __extends(Block, _super);
2271 function Block(statements, isStatementBlock) {
2272 _super.call(this, TypeScript.NodeType.Block);
2273 this.statements = statements;
2274 this.isStatementBlock = isStatementBlock;
2276 Block.prototype.emit = function (emitter, tokenId, startLine) {
2277 emitter.emitParensAndCommentsInPlace(this, true);
2278 emitter.recordSourceMappingStart(this);
2279 if(this.isStatementBlock) {
2280 emitter.writeLineToOutput(" {");
2281 emitter.indenter.increaseIndent();
2283 emitter.setInVarBlock(this.statements.members.length);
2285 var temp = emitter.setInObjectLiteral(false);
2286 if(this.statements) {
2287 emitter.emitJavascriptList(this.statements, null, TypeScript.TokenID.Semicolon, true, false, false);
2289 if(this.isStatementBlock) {
2290 emitter.indenter.decreaseIndent();
2291 emitter.emitIndent();
2292 emitter.writeToOutput("}");
2294 emitter.setInObjectLiteral(temp);
2295 emitter.recordSourceMappingEnd(this);
2296 emitter.emitParensAndCommentsInPlace(this, false);
2298 Block.prototype.addToControlFlow = function (context) {
2299 var afterIfNeeded = new TypeScript.BasicBlock();
2300 context.pushStatement(this, context.current, afterIfNeeded);
2301 if(this.statements) {
2302 context.walk(this.statements, this);
2304 context.walker.options.goChildren = false;
2305 context.popStatement();
2306 if(afterIfNeeded.predecessors.length > 0) {
2307 context.current.addSuccessor(afterIfNeeded);
2308 context.current = afterIfNeeded;
2311 Block.prototype.typeCheck = function (typeFlow) {
2312 if(!typeFlow.checker.styleSettings.emptyBlocks) {
2313 if((this.statements === null) || (this.statements.members.length == 0)) {
2314 typeFlow.checker.errorReporter.styleError(this, "empty block");
2317 typeFlow.typeCheck(this.statements);
2322 TypeScript.Block = Block;
2323 var Jump = (function (_super) {
2324 __extends(Jump, _super);
2325 function Jump(nodeType) {
2326 _super.call(this, nodeType);
2328 this.resolvedTarget = null;
2330 Jump.prototype.hasExplicitTarget = function () {
2331 return (this.target);
2333 Jump.prototype.setResolvedTarget = function (parser, stmt) {
2335 this.resolvedTarget = stmt;
2338 if(this.nodeType === TypeScript.NodeType.Continue) {
2339 parser.reportParseError("continue statement applies only to loops");
2342 if((stmt.nodeType == TypeScript.NodeType.Switch) || this.hasExplicitTarget()) {
2343 this.resolvedTarget = stmt;
2346 parser.reportParseError("break statement with no label can apply only to a loop or switch statement");
2351 Jump.prototype.addToControlFlow = function (context) {
2352 _super.prototype.addToControlFlow.call(this, context);
2353 context.unconditionalBranch(this.resolvedTarget, (this.nodeType == TypeScript.NodeType.Continue));
2355 Jump.prototype.emit = function (emitter, tokenId, startLine) {
2356 emitter.emitParensAndCommentsInPlace(this, true);
2357 emitter.recordSourceMappingStart(this);
2358 if(this.nodeType == TypeScript.NodeType.Break) {
2359 emitter.writeToOutput("break");
2361 emitter.writeToOutput("continue");
2363 if(this.hasExplicitTarget()) {
2364 emitter.writeToOutput(" " + this.target);
2366 emitter.recordSourceMappingEnd(this);
2367 emitter.writeToOutput(";");
2368 emitter.emitParensAndCommentsInPlace(this, false);
2372 TypeScript.Jump = Jump;
2373 var WhileStatement = (function (_super) {
2374 __extends(WhileStatement, _super);
2375 function WhileStatement(cond) {
2376 _super.call(this, TypeScript.NodeType.While);
2380 WhileStatement.prototype.isLoop = function () {
2383 WhileStatement.prototype.emit = function (emitter, tokenId, startLine) {
2384 emitter.emitParensAndCommentsInPlace(this, true);
2385 emitter.recordSourceMappingStart(this);
2386 var temp = emitter.setInObjectLiteral(false);
2387 emitter.writeToOutput("while(");
2388 emitter.emitJavascript(this.cond, TypeScript.TokenID.While, false);
2389 emitter.writeToOutput(")");
2390 emitter.emitJavascriptStatements(this.body, false);
2391 emitter.setInObjectLiteral(temp);
2392 emitter.recordSourceMappingEnd(this);
2393 emitter.emitParensAndCommentsInPlace(this, false);
2395 WhileStatement.prototype.typeCheck = function (typeFlow) {
2396 return typeFlow.typeCheckWhile(this);
2398 WhileStatement.prototype.addToControlFlow = function (context) {
2399 var loopHeader = context.current;
2400 var loopStart = new TypeScript.BasicBlock();
2401 var afterLoop = new TypeScript.BasicBlock();
2402 loopHeader.addSuccessor(loopStart);
2403 context.current = loopStart;
2404 context.addContent(this.cond);
2405 var condBlock = context.current;
2406 var targetInfo = null;
2408 context.current = new TypeScript.BasicBlock();
2409 condBlock.addSuccessor(context.current);
2410 context.pushStatement(this, loopStart, afterLoop);
2411 context.walk(this.body, this);
2412 targetInfo = context.popStatement();
2414 if(!(context.noContinuation)) {
2415 var loopEnd = context.current;
2416 loopEnd.addSuccessor(loopStart);
2418 context.current = afterLoop;
2419 condBlock.addSuccessor(afterLoop);
2420 context.noContinuation = false;
2421 context.walker.options.goChildren = false;
2423 return WhileStatement;
2425 TypeScript.WhileStatement = WhileStatement;
2426 var DoWhileStatement = (function (_super) {
2427 __extends(DoWhileStatement, _super);
2428 function DoWhileStatement() {
2429 _super.call(this, TypeScript.NodeType.DoWhile);
2431 this.whileAST = null;
2434 DoWhileStatement.prototype.isLoop = function () {
2437 DoWhileStatement.prototype.emit = function (emitter, tokenId, startLine) {
2438 emitter.emitParensAndCommentsInPlace(this, true);
2439 emitter.recordSourceMappingStart(this);
2440 var temp = emitter.setInObjectLiteral(false);
2441 emitter.writeToOutput("do");
2442 emitter.emitJavascriptStatements(this.body, true);
2443 emitter.recordSourceMappingStart(this.whileAST);
2444 emitter.writeToOutput("while");
2445 emitter.recordSourceMappingEnd(this.whileAST);
2446 emitter.writeToOutput('(');
2447 emitter.emitJavascript(this.cond, TypeScript.TokenID.CloseParen, false);
2448 emitter.writeToOutput(")");
2449 emitter.setInObjectLiteral(temp);
2450 emitter.recordSourceMappingEnd(this);
2451 emitter.writeToOutput(";");
2452 emitter.emitParensAndCommentsInPlace(this, false);
2454 DoWhileStatement.prototype.typeCheck = function (typeFlow) {
2455 return typeFlow.typeCheckDoWhile(this);
2457 DoWhileStatement.prototype.addToControlFlow = function (context) {
2458 var loopHeader = context.current;
2459 var loopStart = new TypeScript.BasicBlock();
2460 var afterLoop = new TypeScript.BasicBlock();
2461 loopHeader.addSuccessor(loopStart);
2462 context.current = loopStart;
2463 var targetInfo = null;
2465 context.pushStatement(this, loopStart, afterLoop);
2466 context.walk(this.body, this);
2467 targetInfo = context.popStatement();
2469 if(!(context.noContinuation)) {
2470 var loopEnd = context.current;
2471 loopEnd.addSuccessor(loopStart);
2472 context.addContent(this.cond);
2473 context.current = afterLoop;
2474 loopEnd.addSuccessor(afterLoop);
2476 context.addUnreachable(this.cond);
2478 context.walker.options.goChildren = false;
2480 return DoWhileStatement;
2482 TypeScript.DoWhileStatement = DoWhileStatement;
2483 var IfStatement = (function (_super) {
2484 __extends(IfStatement, _super);
2485 function IfStatement(cond) {
2486 _super.call(this, TypeScript.NodeType.If);
2488 this.elseBod = null;
2489 this.statement = new ASTSpan();
2491 IfStatement.prototype.isCompoundStatement = function () {
2494 IfStatement.prototype.emit = function (emitter, tokenId, startLine) {
2495 emitter.emitParensAndCommentsInPlace(this, true);
2496 emitter.recordSourceMappingStart(this);
2497 var temp = emitter.setInObjectLiteral(false);
2498 emitter.recordSourceMappingStart(this.statement);
2499 emitter.writeToOutput("if(");
2500 emitter.emitJavascript(this.cond, TypeScript.TokenID.If, false);
2501 emitter.writeToOutput(")");
2502 emitter.recordSourceMappingEnd(this.statement);
2503 emitter.emitJavascriptStatements(this.thenBod, true);
2505 if(this.elseBod.nodeType === TypeScript.NodeType.If) {
2506 emitter.writeToOutput(" else ");
2507 this.elseBod.emit(emitter, tokenId, false);
2509 emitter.writeToOutput(" else");
2510 emitter.emitJavascriptStatements(this.elseBod, true);
2513 emitter.setInObjectLiteral(temp);
2514 emitter.recordSourceMappingEnd(this);
2515 emitter.emitParensAndCommentsInPlace(this, false);
2517 IfStatement.prototype.typeCheck = function (typeFlow) {
2518 return typeFlow.typeCheckIf(this);
2520 IfStatement.prototype.addToControlFlow = function (context) {
2521 this.cond.addToControlFlow(context);
2522 var afterIf = new TypeScript.BasicBlock();
2523 var beforeIf = context.current;
2524 context.pushStatement(this, beforeIf, afterIf);
2525 var hasContinuation = false;
2526 context.current = new TypeScript.BasicBlock();
2527 beforeIf.addSuccessor(context.current);
2528 context.walk(this.thenBod, this);
2529 if(!context.noContinuation) {
2530 hasContinuation = true;
2531 context.current.addSuccessor(afterIf);
2534 context.current = new TypeScript.BasicBlock();
2535 context.noContinuation = false;
2536 beforeIf.addSuccessor(context.current);
2537 context.walk(this.elseBod, this);
2538 if(!context.noContinuation) {
2539 hasContinuation = true;
2540 context.current.addSuccessor(afterIf);
2542 if(hasContinuation) {
2543 context.noContinuation = false;
2547 beforeIf.addSuccessor(afterIf);
2548 context.noContinuation = false;
2549 hasContinuation = true;
2551 var targetInfo = context.popStatement();
2552 if(afterIf.predecessors.length > 0) {
2553 context.noContinuation = false;
2554 hasContinuation = true;
2556 if(hasContinuation) {
2557 context.current = afterIf;
2559 context.walker.options.goChildren = false;
2563 TypeScript.IfStatement = IfStatement;
2564 var ReturnStatement = (function (_super) {
2565 __extends(ReturnStatement, _super);
2566 function ReturnStatement() {
2567 _super.call(this, TypeScript.NodeType.Return);
2568 this.returnExpression = null;
2570 ReturnStatement.prototype.emit = function (emitter, tokenId, startLine) {
2571 emitter.emitParensAndCommentsInPlace(this, true);
2572 emitter.recordSourceMappingStart(this);
2573 var temp = emitter.setInObjectLiteral(false);
2574 if(this.returnExpression) {
2575 emitter.writeToOutput("return ");
2576 emitter.emitJavascript(this.returnExpression, TypeScript.TokenID.Semicolon, false);
2577 if(this.returnExpression.nodeType === TypeScript.NodeType.FuncDecl) {
2578 emitter.writeToOutput(";");
2581 emitter.writeToOutput("return;");
2583 emitter.setInObjectLiteral(temp);
2584 emitter.recordSourceMappingEnd(this);
2585 emitter.emitParensAndCommentsInPlace(this, false);
2587 ReturnStatement.prototype.addToControlFlow = function (context) {
2588 _super.prototype.addToControlFlow.call(this, context);
2589 context.returnStmt();
2591 ReturnStatement.prototype.typeCheck = function (typeFlow) {
2592 return typeFlow.typeCheckReturn(this);
2594 return ReturnStatement;
2596 TypeScript.ReturnStatement = ReturnStatement;
2597 var EndCode = (function (_super) {
2598 __extends(EndCode, _super);
2599 function EndCode() {
2600 _super.call(this, TypeScript.NodeType.EndCode);
2604 TypeScript.EndCode = EndCode;
2605 var ForInStatement = (function (_super) {
2606 __extends(ForInStatement, _super);
2607 function ForInStatement(lval, obj) {
2608 _super.call(this, TypeScript.NodeType.ForIn);
2611 this.statement = new ASTSpan();
2612 if(this.lval && (this.lval.nodeType == TypeScript.NodeType.VarDecl)) {
2613 (this.lval).varFlags |= TypeScript.VarFlags.AutoInit;
2616 ForInStatement.prototype.isLoop = function () {
2619 ForInStatement.prototype.isFiltered = function () {
2621 var singleItem = null;
2622 if(this.body.nodeType == TypeScript.NodeType.List) {
2623 var stmts = this.body;
2624 if(stmts.members.length == 1) {
2625 singleItem = stmts.members[0];
2628 singleItem = this.body;
2630 if(singleItem !== null) {
2631 if(singleItem.nodeType == TypeScript.NodeType.Block) {
2632 var block = singleItem;
2633 if((block.statements !== null) && (block.statements.members.length == 1)) {
2634 singleItem = block.statements.members[0];
2637 if(singleItem.nodeType == TypeScript.NodeType.If) {
2638 var cond = (singleItem).cond;
2639 if(cond.nodeType == TypeScript.NodeType.Call) {
2640 var target = (cond).target;
2641 if(target.nodeType == TypeScript.NodeType.Dot) {
2643 if((binex.operand1.nodeType == TypeScript.NodeType.Name) && (this.obj.nodeType == TypeScript.NodeType.Name) && ((binex.operand1).actualText == (this.obj).actualText)) {
2644 var prop = binex.operand2;
2645 if(prop.actualText == "hasOwnProperty") {
2646 var args = (cond).arguments;
2647 if((args !== null) && (args.members.length == 1)) {
2648 var arg = args.members[0];
2649 if((arg.nodeType == TypeScript.NodeType.Name) && (this.lval.nodeType == TypeScript.NodeType.Name)) {
2650 if(((this.lval).actualText) == (arg).actualText) {
2664 ForInStatement.prototype.emit = function (emitter, tokenId, startLine) {
2665 emitter.emitParensAndCommentsInPlace(this, true);
2666 emitter.recordSourceMappingStart(this);
2667 var temp = emitter.setInObjectLiteral(false);
2668 emitter.recordSourceMappingStart(this.statement);
2669 emitter.writeToOutput("for(");
2670 emitter.emitJavascript(this.lval, TypeScript.TokenID.For, false);
2671 emitter.writeToOutput(" in ");
2672 emitter.emitJavascript(this.obj, TypeScript.TokenID.For, false);
2673 emitter.writeToOutput(")");
2674 emitter.recordSourceMappingEnd(this.statement);
2675 emitter.emitJavascriptStatements(this.body, true);
2676 emitter.setInObjectLiteral(temp);
2677 emitter.recordSourceMappingEnd(this);
2678 emitter.emitParensAndCommentsInPlace(this, false);
2680 ForInStatement.prototype.typeCheck = function (typeFlow) {
2681 if(typeFlow.checker.styleSettings.forin) {
2682 if(!this.isFiltered()) {
2683 typeFlow.checker.errorReporter.styleError(this, "no hasOwnProperty filter");
2686 return typeFlow.typeCheckForIn(this);
2688 ForInStatement.prototype.addToControlFlow = function (context) {
2690 context.addContent(this.lval);
2693 context.addContent(this.obj);
2695 var loopHeader = context.current;
2696 var loopStart = new TypeScript.BasicBlock();
2697 var afterLoop = new TypeScript.BasicBlock();
2698 loopHeader.addSuccessor(loopStart);
2699 context.current = loopStart;
2701 context.pushStatement(this, loopStart, afterLoop);
2702 context.walk(this.body, this);
2703 context.popStatement();
2705 if(!(context.noContinuation)) {
2706 var loopEnd = context.current;
2707 loopEnd.addSuccessor(loopStart);
2709 context.current = afterLoop;
2710 context.noContinuation = false;
2711 loopHeader.addSuccessor(afterLoop);
2712 context.walker.options.goChildren = false;
2714 return ForInStatement;
2716 TypeScript.ForInStatement = ForInStatement;
2717 var ForStatement = (function (_super) {
2718 __extends(ForStatement, _super);
2719 function ForStatement(init) {
2720 _super.call(this, TypeScript.NodeType.For);
2723 ForStatement.prototype.isLoop = function () {
2726 ForStatement.prototype.emit = function (emitter, tokenId, startLine) {
2727 emitter.emitParensAndCommentsInPlace(this, true);
2728 emitter.recordSourceMappingStart(this);
2729 var temp = emitter.setInObjectLiteral(false);
2730 emitter.writeToOutput("for(");
2732 if(this.init.nodeType != TypeScript.NodeType.List) {
2733 emitter.emitJavascript(this.init, TypeScript.TokenID.For, false);
2735 emitter.setInVarBlock((this.init).members.length);
2736 emitter.emitJavascriptList(this.init, null, TypeScript.TokenID.For, false, false, false);
2739 emitter.writeToOutput("; ");
2740 emitter.emitJavascript(this.cond, TypeScript.TokenID.For, false);
2741 emitter.writeToOutput("; ");
2742 emitter.emitJavascript(this.incr, TypeScript.TokenID.For, false);
2743 emitter.writeToOutput(")");
2744 emitter.emitJavascriptStatements(this.body, true);
2745 emitter.setInObjectLiteral(temp);
2746 emitter.recordSourceMappingEnd(this);
2747 emitter.emitParensAndCommentsInPlace(this, false);
2749 ForStatement.prototype.typeCheck = function (typeFlow) {
2750 return typeFlow.typeCheckFor(this);
2752 ForStatement.prototype.addToControlFlow = function (context) {
2754 context.addContent(this.init);
2756 var loopHeader = context.current;
2757 var loopStart = new TypeScript.BasicBlock();
2758 var afterLoop = new TypeScript.BasicBlock();
2759 loopHeader.addSuccessor(loopStart);
2760 context.current = loopStart;
2761 var condBlock = null;
2762 var continueTarget = loopStart;
2765 incrBB = new TypeScript.BasicBlock();
2766 continueTarget = incrBB;
2769 condBlock = context.current;
2770 context.addContent(this.cond);
2771 context.current = new TypeScript.BasicBlock();
2772 condBlock.addSuccessor(context.current);
2774 var targetInfo = null;
2776 context.pushStatement(this, continueTarget, afterLoop);
2777 context.walk(this.body, this);
2778 targetInfo = context.popStatement();
2781 if(context.noContinuation) {
2782 if(incrBB.predecessors.length == 0) {
2783 context.addUnreachable(this.incr);
2786 context.current.addSuccessor(incrBB);
2787 context.current = incrBB;
2788 context.addContent(this.incr);
2791 var loopEnd = context.current;
2792 if(!(context.noContinuation)) {
2793 loopEnd.addSuccessor(loopStart);
2796 condBlock.addSuccessor(afterLoop);
2797 context.noContinuation = false;
2799 if(afterLoop.predecessors.length > 0) {
2800 context.noContinuation = false;
2801 context.current = afterLoop;
2803 context.walker.options.goChildren = false;
2805 return ForStatement;
2807 TypeScript.ForStatement = ForStatement;
2808 var WithStatement = (function (_super) {
2809 __extends(WithStatement, _super);
2810 function WithStatement(expr) {
2811 _super.call(this, TypeScript.NodeType.With);
2813 this.withSym = null;
2815 WithStatement.prototype.isCompoundStatement = function () {
2818 WithStatement.prototype.emit = function (emitter, tokenId, startLine) {
2819 emitter.emitParensAndCommentsInPlace(this, true);
2820 emitter.recordSourceMappingStart(this);
2821 emitter.writeToOutput("with (");
2823 emitter.emitJavascript(this.expr, TypeScript.TokenID.With, false);
2825 emitter.writeToOutput(")");
2826 emitter.emitJavascriptStatements(this.body, true);
2827 emitter.recordSourceMappingEnd(this);
2828 emitter.emitParensAndCommentsInPlace(this, false);
2830 WithStatement.prototype.typeCheck = function (typeFlow) {
2831 return typeFlow.typeCheckWith(this);
2833 return WithStatement;
2835 TypeScript.WithStatement = WithStatement;
2836 var SwitchStatement = (function (_super) {
2837 __extends(SwitchStatement, _super);
2838 function SwitchStatement(val) {
2839 _super.call(this, TypeScript.NodeType.Switch);
2841 this.defaultCase = null;
2842 this.statement = new ASTSpan();
2844 SwitchStatement.prototype.isCompoundStatement = function () {
2847 SwitchStatement.prototype.emit = function (emitter, tokenId, startLine) {
2848 emitter.emitParensAndCommentsInPlace(this, true);
2849 emitter.recordSourceMappingStart(this);
2850 var temp = emitter.setInObjectLiteral(false);
2851 emitter.recordSourceMappingStart(this.statement);
2852 emitter.writeToOutput("switch(");
2853 emitter.emitJavascript(this.val, TypeScript.TokenID.Identifier, false);
2854 emitter.writeToOutput(")");
2855 emitter.recordSourceMappingEnd(this.statement);
2856 emitter.writeLineToOutput(" {");
2857 emitter.indenter.increaseIndent();
2858 var casesLen = this.caseList.members.length;
2859 for(var i = 0; i < casesLen; i++) {
2860 var caseExpr = this.caseList.members[i];
2861 emitter.emitJavascript(caseExpr, TypeScript.TokenID.Case, true);
2863 emitter.indenter.decreaseIndent();
2864 emitter.emitIndent();
2865 emitter.writeToOutput("}");
2866 emitter.setInObjectLiteral(temp);
2867 emitter.recordSourceMappingEnd(this);
2868 emitter.emitParensAndCommentsInPlace(this, false);
2870 SwitchStatement.prototype.typeCheck = function (typeFlow) {
2871 var len = this.caseList.members.length;
2872 this.val = typeFlow.typeCheck(this.val);
2873 for(var i = 0; i < len; i++) {
2874 this.caseList.members[i] = typeFlow.typeCheck(this.caseList.members[i]);
2876 this.defaultCase = typeFlow.typeCheck(this.defaultCase);
2877 this.type = typeFlow.voidType;
2880 SwitchStatement.prototype.addToControlFlow = function (context) {
2881 var condBlock = context.current;
2882 context.addContent(this.val);
2883 var execBlock = new TypeScript.BasicBlock();
2884 var afterSwitch = new TypeScript.BasicBlock();
2885 condBlock.addSuccessor(execBlock);
2886 context.pushSwitch(execBlock);
2887 context.current = execBlock;
2888 context.pushStatement(this, execBlock, afterSwitch);
2889 context.walk(this.caseList, this);
2890 context.popSwitch();
2891 var targetInfo = context.popStatement();
2892 var hasCondContinuation = (this.defaultCase == null);
2893 if(this.defaultCase == null) {
2894 condBlock.addSuccessor(afterSwitch);
2896 if(afterSwitch.predecessors.length > 0) {
2897 context.noContinuation = false;
2898 context.current = afterSwitch;
2900 context.noContinuation = true;
2902 context.walker.options.goChildren = false;
2904 return SwitchStatement;
2906 TypeScript.SwitchStatement = SwitchStatement;
2907 var CaseStatement = (function (_super) {
2908 __extends(CaseStatement, _super);
2909 function CaseStatement() {