tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

typescript-compiler.js (1232383B)


      1 var TypeScript;
      2 (function (TypeScript) {
      3    function hasFlag(val, flag) {
      4        return (val & flag) != 0;
      5    }
      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) {
     59        Modifiers._map = [];
     60        Modifiers.None = 0;
     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) {
     72        ASTFlags._map = [];
     73        ASTFlags.None = 0;
     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) {
     89        DeclFlags._map = [];
     90        DeclFlags.None = 0;
     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) {
    145        VarFlags._map = [];
    146        VarFlags.None = 0;
    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) {
    168        FncFlags._map = [];
    169        FncFlags.None = 0;
    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;
    204    }
    205    TypeScript.ToDeclFlags = ToDeclFlags;
    206    (function (TypeFlags) {
    207        TypeFlags._map = [];
    208        TypeFlags.None = 0;
    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) {
    248        var builder = "";
    249        for(var i = 1; i < (1 << 31); i = i << 1) {
    250            if((flags & i) != 0) {
    251                for(var k in e) {
    252                    if(e[k] == i) {
    253                        if(builder.length > 0) {
    254                            builder += "|";
    255                        }
    256                        builder += k;
    257                        break;
    258                    }
    259                }
    260            }
    261        }
    262        return builder;
    263    }
    264    TypeScript.flagsToString = flagsToString;
    265 })(TypeScript || (TypeScript = {}));
    266 var TypeScript;
    267 (function (TypeScript) {
    268    (function (NodeType) {
    269        NodeType._map = [];
    270        NodeType._map[0] = "None";
    271        NodeType.None = 0;
    272        NodeType._map[1] = "Empty";
    273        NodeType.Empty = 1;
    274        NodeType._map[2] = "EmptyExpr";
    275        NodeType.EmptyExpr = 2;
    276        NodeType._map[3] = "True";
    277        NodeType.True = 3;
    278        NodeType._map[4] = "False";
    279        NodeType.False = 4;
    280        NodeType._map[5] = "This";
    281        NodeType.This = 5;
    282        NodeType._map[6] = "Super";
    283        NodeType.Super = 6;
    284        NodeType._map[7] = "QString";
    285        NodeType.QString = 7;
    286        NodeType._map[8] = "Regex";
    287        NodeType.Regex = 8;
    288        NodeType._map[9] = "Null";
    289        NodeType.Null = 9;
    290        NodeType._map[10] = "ArrayLit";
    291        NodeType.ArrayLit = 10;
    292        NodeType._map[11] = "ObjectLit";
    293        NodeType.ObjectLit = 11;
    294        NodeType._map[12] = "Void";
    295        NodeType.Void = 12;
    296        NodeType._map[13] = "Comma";
    297        NodeType.Comma = 13;
    298        NodeType._map[14] = "Pos";
    299        NodeType.Pos = 14;
    300        NodeType._map[15] = "Neg";
    301        NodeType.Neg = 15;
    302        NodeType._map[16] = "Delete";
    303        NodeType.Delete = 16;
    304        NodeType._map[17] = "Await";
    305        NodeType.Await = 17;
    306        NodeType._map[18] = "In";
    307        NodeType.In = 18;
    308        NodeType._map[19] = "Dot";
    309        NodeType.Dot = 19;
    310        NodeType._map[20] = "From";
    311        NodeType.From = 20;
    312        NodeType._map[21] = "Is";
    313        NodeType.Is = 21;
    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";
    321        NodeType.Name = 25;
    322        NodeType._map[26] = "TypeRef";
    323        NodeType.TypeRef = 26;
    324        NodeType._map[27] = "Index";
    325        NodeType.Index = 27;
    326        NodeType._map[28] = "Call";
    327        NodeType.Call = 28;
    328        NodeType._map[29] = "New";
    329        NodeType.New = 29;
    330        NodeType._map[30] = "Asg";
    331        NodeType.Asg = 30;
    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";
    347        NodeType.AsgOr = 38;
    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";
    357        NodeType.LogOr = 43;
    358        NodeType._map[44] = "LogAnd";
    359        NodeType.LogAnd = 44;
    360        NodeType._map[45] = "Or";
    361        NodeType.Or = 45;
    362        NodeType._map[46] = "Xor";
    363        NodeType.Xor = 46;
    364        NodeType._map[47] = "And";
    365        NodeType.And = 47;
    366        NodeType._map[48] = "Eq";
    367        NodeType.Eq = 48;
    368        NodeType._map[49] = "Ne";
    369        NodeType.Ne = 49;
    370        NodeType._map[50] = "Eqv";
    371        NodeType.Eqv = 50;
    372        NodeType._map[51] = "NEqv";
    373        NodeType.NEqv = 51;
    374        NodeType._map[52] = "Lt";
    375        NodeType.Lt = 52;
    376        NodeType._map[53] = "Le";
    377        NodeType.Le = 53;
    378        NodeType._map[54] = "Gt";
    379        NodeType.Gt = 54;
    380        NodeType._map[55] = "Ge";
    381        NodeType.Ge = 55;
    382        NodeType._map[56] = "Add";
    383        NodeType.Add = 56;
    384        NodeType._map[57] = "Sub";
    385        NodeType.Sub = 57;
    386        NodeType._map[58] = "Mul";
    387        NodeType.Mul = 58;
    388        NodeType._map[59] = "Div";
    389        NodeType.Div = 59;
    390        NodeType._map[60] = "Mod";
    391        NodeType.Mod = 60;
    392        NodeType._map[61] = "Lsh";
    393        NodeType.Lsh = 61;
    394        NodeType._map[62] = "Rsh";
    395        NodeType.Rsh = 62;
    396        NodeType._map[63] = "Rs2";
    397        NodeType.Rs2 = 63;
    398        NodeType._map[64] = "Not";
    399        NodeType.Not = 64;
    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";
    423        NodeType.Break = 76;
    424        NodeType._map[77] = "Continue";
    425        NodeType.Continue = 77;
    426        NodeType._map[78] = "Throw";
    427        NodeType.Throw = 78;
    428        NodeType._map[79] = "For";
    429        NodeType.For = 79;
    430        NodeType._map[80] = "ForIn";
    431        NodeType.ForIn = 80;
    432        NodeType._map[81] = "If";
    433        NodeType.If = 81;
    434        NodeType._map[82] = "While";
    435        NodeType.While = 82;
    436        NodeType._map[83] = "DoWhile";
    437        NodeType.DoWhile = 83;
    438        NodeType._map[84] = "Block";
    439        NodeType.Block = 84;
    440        NodeType._map[85] = "Case";
    441        NodeType.Case = 85;
    442        NodeType._map[86] = "Switch";
    443        NodeType.Switch = 86;
    444        NodeType._map[87] = "Try";
    445        NodeType.Try = 87;
    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";
    453        NodeType.Catch = 91;
    454        NodeType._map[92] = "List";
    455        NodeType.List = 92;
    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";
    467        NodeType.With = 98;
    468        NodeType._map[99] = "Label";
    469        NodeType.Label = 99;
    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 = {}));
    489 var 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;
    501        }
    502        return BlockIntrinsics;
    503    })();
    504    TypeScript.BlockIntrinsics = BlockIntrinsics;    
    505    var StringHashTable = (function () {
    506        function StringHashTable() {
    507            this.itemCount = 0;
    508            this.table = (new BlockIntrinsics());
    509        }
    510        StringHashTable.prototype.getAllKeys = function () {
    511            var result = [];
    512            for(var k in this.table) {
    513                if(this.table[k] != undefined) {
    514                    result[result.length] = k;
    515                }
    516            }
    517            return result;
    518        };
    519        StringHashTable.prototype.add = function (key, data) {
    520            if(this.table[key] != undefined) {
    521                return false;
    522            }
    523            this.table[key] = data;
    524            this.itemCount++;
    525            return true;
    526        };
    527        StringHashTable.prototype.addOrUpdate = function (key, data) {
    528            if(this.table[key] != undefined) {
    529                this.table[key] = data;
    530                return false;
    531            }
    532            this.table[key] = data;
    533            this.itemCount++;
    534            return true;
    535        };
    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);
    541                }
    542            }
    543        };
    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)) {
    549                        return false;
    550                    }
    551                }
    552            }
    553            return true;
    554        };
    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)) {
    560                        return true;
    561                    }
    562                }
    563            }
    564            return false;
    565        };
    566        StringHashTable.prototype.count = function () {
    567            return this.itemCount;
    568        };
    569        StringHashTable.prototype.lookup = function (key) {
    570            var data = this.table[key];
    571            if(data != undefined) {
    572                return data;
    573            } else {
    574                return (null);
    575            }
    576        };
    577        return StringHashTable;
    578    })();
    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;
    585        }
    586        DualStringHashTable.prototype.getAllKeys = function () {
    587            return this.primaryTable.getAllKeys().concat(this.secondaryTable.getAllKeys());
    588        };
    589        DualStringHashTable.prototype.add = function (key, data) {
    590            if(this.insertPrimary) {
    591                return this.primaryTable.add(key, data);
    592            } else {
    593                return this.secondaryTable.add(key, data);
    594            }
    595        };
    596        DualStringHashTable.prototype.addOrUpdate = function (key, data) {
    597            if(this.insertPrimary) {
    598                return this.primaryTable.addOrUpdate(key, data);
    599            } else {
    600                return this.secondaryTable.addOrUpdate(key, data);
    601            }
    602        };
    603        DualStringHashTable.prototype.map = function (fn, context) {
    604            this.primaryTable.map(fn, context);
    605            this.secondaryTable.map(fn, context);
    606        };
    607        DualStringHashTable.prototype.every = function (fn, context) {
    608            return this.primaryTable.every(fn, context) && this.secondaryTable.every(fn, context);
    609        };
    610        DualStringHashTable.prototype.some = function (fn, context) {
    611            return this.primaryTable.some(fn, context) || this.secondaryTable.some(fn, context);
    612        };
    613        DualStringHashTable.prototype.count = function () {
    614            return this.primaryTable.count() + this.secondaryTable.count();
    615        };
    616        DualStringHashTable.prototype.lookup = function (key) {
    617            var data = this.primaryTable.lookup(key);
    618            if(data != undefined) {
    619                return data;
    620            } else {
    621                return this.secondaryTable.lookup(key);
    622            }
    623        };
    624        return DualStringHashTable;
    625    })();
    626    TypeScript.DualStringHashTable = DualStringHashTable;    
    627    function numberHashFn(key) {
    628        var c2 = 668265261;
    629        key = (key ^ 61) ^ (key >>> 16);
    630        key = key + (key << 3);
    631        key = key ^ (key >>> 4);
    632        key = key * c2;
    633        key = key ^ (key >>> 15);
    634        return key;
    635    }
    636    TypeScript.numberHashFn = numberHashFn;
    637    function combineHashes(key1, key2) {
    638        return key2 ^ ((key1 >> 5) + key1);
    639    }
    640    TypeScript.combineHashes = combineHashes;
    641    var HashEntry = (function () {
    642        function HashEntry(key, data) {
    643            this.key = key;
    644            this.data = data;
    645        }
    646        return HashEntry;
    647    })();
    648    TypeScript.HashEntry = HashEntry;    
    649    var HashTable = (function () {
    650        function HashTable(size, hashFn, equalsFn) {
    651            this.size = size;
    652            this.hashFn = hashFn;
    653            this.equalsFn = equalsFn;
    654            this.itemCount = 0;
    655            this.table = new Array();
    656            for(var i = 0; i < this.size; i++) {
    657                this.table[i] = null;
    658            }
    659        }
    660        HashTable.prototype.add = function (key, data) {
    661            var current;
    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)) {
    667                    return false;
    668                }
    669            }
    670            entry.next = this.table[val];
    671            this.table[val] = entry;
    672            this.itemCount++;
    673            return true;
    674        };
    675        HashTable.prototype.remove = function (key) {
    676            var current;
    677            var val = this.hashFn(key);
    678            val = val % this.size;
    679            var result = null;
    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;
    684                    this.itemCount--;
    685                    if(prevEntry) {
    686                        prevEntry.next = current.next;
    687                    } else {
    688                        this.table[val] = current.next;
    689                    }
    690                    break;
    691                }
    692                prevEntry = current;
    693            }
    694            return result;
    695        };
    696        HashTable.prototype.count = function () {
    697            return this.itemCount;
    698        };
    699        HashTable.prototype.lookup = function (key) {
    700            var current;
    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);
    706                }
    707            }
    708            return (null);
    709        };
    710        return HashTable;
    711    })();
    712    TypeScript.HashTable = HashTable;    
    713    var SimpleHashTable = (function () {
    714        function SimpleHashTable() {
    715            this.keys = [];
    716            this.values = [];
    717        }
    718        SimpleHashTable.prototype.lookup = function (key, findValue) {
    719            var searchArray = this.keys;
    720            if(findValue) {
    721                searchArray = this.values;
    722            }
    723            for(var i = 0; i < searchArray.length; i++) {
    724                if(searchArray[i] == key) {
    725                    return {
    726                        key: this.keys[i],
    727                        data: this.values[i]
    728                    };
    729                }
    730            }
    731            return null;
    732        };
    733        SimpleHashTable.prototype.add = function (key, data) {
    734            var lookupData = this.lookup(key);
    735            if(lookupData) {
    736                return false;
    737            }
    738            this.keys[this.keys.length] = key;
    739            this.values[this.values.length] = data;
    740            return true;
    741        };
    742        return SimpleHashTable;
    743    })();
    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 __();
    750 };
    751 var TypeScript;
    752 (function (TypeScript) {
    753    var ASTSpan = (function () {
    754        function ASTSpan() {
    755            this.minChar = -1;
    756            this.limChar = -1;
    757        }
    758        return ASTSpan;
    759    })();
    760    TypeScript.ASTSpan = ASTSpan;    
    761    var AST = (function (_super) {
    762        __extends(AST, _super);
    763        function AST(nodeType) {
    764                _super.call(this);
    765            this.nodeType = nodeType;
    766            this.type = null;
    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;
    773        }
    774        AST.prototype.isExpression = function () {
    775            return false;
    776        };
    777        AST.prototype.isStatementOrExpression = function () {
    778            return false;
    779        };
    780        AST.prototype.isCompoundStatement = function () {
    781            return false;
    782        };
    783        AST.prototype.isLeaf = function () {
    784            return this.isStatementOrExpression() && (!this.isCompoundStatement());
    785        };
    786        AST.prototype.isDeclaration = function () {
    787            return false;
    788        };
    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;
    794                    break;
    795 
    796                }
    797                case TypeScript.NodeType.This: {
    798                    return typeFlow.typeCheckThis(this);
    799 
    800                }
    801                case TypeScript.NodeType.Null: {
    802                    this.type = typeFlow.nullType;
    803                    break;
    804 
    805                }
    806                case TypeScript.NodeType.False:
    807                case TypeScript.NodeType.True: {
    808                    this.type = typeFlow.booleanType;
    809                    break;
    810 
    811                }
    812                case TypeScript.NodeType.Super: {
    813                    return typeFlow.typeCheckSuper(this);
    814 
    815                }
    816                case TypeScript.NodeType.EndCode:
    817                case TypeScript.NodeType.Empty:
    818                case TypeScript.NodeType.Void: {
    819                    this.type = typeFlow.voidType;
    820                    break;
    821 
    822                }
    823                default: {
    824                    throw new Error("please implement in derived class");
    825 
    826                }
    827            }
    828            return this;
    829        };
    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");
    837                    } else {
    838                        emitter.writeToOutput("this");
    839                    }
    840                    emitter.recordSourceMappingEnd(this);
    841                    break;
    842 
    843                }
    844                case TypeScript.NodeType.Null: {
    845                    emitter.recordSourceMappingStart(this);
    846                    emitter.writeToOutput("null");
    847                    emitter.recordSourceMappingEnd(this);
    848                    break;
    849 
    850                }
    851                case TypeScript.NodeType.False: {
    852                    emitter.recordSourceMappingStart(this);
    853                    emitter.writeToOutput("false");
    854                    emitter.recordSourceMappingEnd(this);
    855                    break;
    856 
    857                }
    858                case TypeScript.NodeType.True: {
    859                    emitter.recordSourceMappingStart(this);
    860                    emitter.writeToOutput("true");
    861                    emitter.recordSourceMappingEnd(this);
    862                    break;
    863 
    864                }
    865                case TypeScript.NodeType.Super: {
    866                    emitter.recordSourceMappingStart(this);
    867                    emitter.emitSuperReference();
    868                    emitter.recordSourceMappingEnd(this);
    869                    break;
    870 
    871                }
    872                case TypeScript.NodeType.EndCode:
    873                case TypeScript.NodeType.Error:
    874                case TypeScript.NodeType.EmptyExpr: {
    875                    break;
    876 
    877                }
    878                case TypeScript.NodeType.Empty: {
    879                    emitter.recordSourceMappingStart(this);
    880                    emitter.recordSourceMappingEnd(this);
    881                    break;
    882 
    883                }
    884                case TypeScript.NodeType.Void: {
    885                    emitter.recordSourceMappingStart(this);
    886                    emitter.writeToOutput("void ");
    887                    emitter.recordSourceMappingEnd(this);
    888                    break;
    889 
    890                }
    891                default: {
    892                    throw new Error("please implement in derived class");
    893 
    894                }
    895            }
    896            emitter.emitParensAndCommentsInPlace(this, false);
    897        };
    898        AST.prototype.print = function (context) {
    899            context.startLine();
    900            var lineCol = {
    901                line: -1,
    902                col: -1
    903            };
    904            var limLineCol = {
    905                line: -1,
    906                col: -1
    907            };
    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 + "): ");
    912            }
    913            var lab = this.printLabel();
    914            if(TypeScript.hasFlag(this.flags, TypeScript.ASTFlags.Error)) {
    915                lab += " (Error)";
    916            }
    917            context.writeLine(lab);
    918        };
    919        AST.prototype.printLabel = function () {
    920            if(TypeScript.nodeTypeTable[this.nodeType] !== undefined) {
    921                return TypeScript.nodeTypeTable[this.nodeType];
    922            } else {
    923                return (TypeScript.NodeType)._map[this.nodeType];
    924            }
    925        };
    926        AST.prototype.addToControlFlow = function (context) {
    927            context.walker.options.goChildren = false;
    928            context.addContent(this);
    929        };
    930        AST.prototype.netFreeUses = function (container, freeUses) {
    931        };
    932        AST.prototype.treeViewLabel = function () {
    933            return (TypeScript.NodeType)._map[this.nodeType];
    934        };
    935        AST.getResolvedIdentifierName = function getResolvedIdentifierName(name) {
    936            if(!name) {
    937                return "";
    938            }
    939            var resolved = "";
    940            var start = 0;
    941            var i = 0;
    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);
    947                    i += 6;
    948                    start = i;
    949                    continue;
    950                }
    951                i++;
    952            }
    953            resolved += name.substring(start);
    954            return resolved;
    955        }
    956        AST.prototype.getDocComments = function () {
    957            if(!this.isDeclaration() || !this.preComments || this.preComments.length == 0) {
    958                return [];
    959            }
    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]);
    968                            continue;
    969                        }
    970                    }
    971                    break;
    972                }
    973                this.docComments = docComments.reverse();
    974            }
    975            return this.docComments;
    976        };
    977        return AST;
    978    })(ASTSpan);
    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);
    984            this.minChar = min;
    985            this.limChar = lim;
    986        }
    987        return IncompleteAST;
    988    })(AST);
    989    TypeScript.IncompleteAST = IncompleteAST;    
    990    var ASTList = (function (_super) {
    991        __extends(ASTList, _super);
    992        function ASTList() {
    993                _super.call(this, TypeScript.NodeType.List);
    994            this.enclosingScope = null;
    995            this.members = new Array();
    996        }
    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]);
   1002                    break;
   1003                } else {
   1004                    this.members[i] = context.walk(this.members[i], this);
   1005                }
   1006            }
   1007            context.walker.options.goChildren = false;
   1008        };
   1009        ASTList.prototype.append = function (ast) {
   1010            this.members[this.members.length] = ast;
   1011            return this;
   1012        };
   1013        ASTList.prototype.appendAll = function (ast) {
   1014            if(ast.nodeType == TypeScript.NodeType.List) {
   1015                var list = ast;
   1016                for(var i = 0, len = list.members.length; i < len; i++) {
   1017                    this.append(list.members[i]);
   1018                }
   1019            } else {
   1020                this.append(ast);
   1021            }
   1022            return this;
   1023        };
   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);
   1028        };
   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);
   1035                }
   1036            }
   1037            typeFlow.nestingLevel--;
   1038            return this;
   1039        };
   1040        return ASTList;
   1041    })(AST);
   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;
   1049            this.sym = null;
   1050            this.cloId = -1;
   1051            this.setText(actualText, hasEscapeSequence);
   1052        }
   1053        Identifier.prototype.setText = function (actualText, hasEscapeSequence) {
   1054            this.actualText = actualText;
   1055            if(hasEscapeSequence) {
   1056                this.text = AST.getResolvedIdentifierName(actualText);
   1057            } else {
   1058                this.text = actualText;
   1059            }
   1060        };
   1061        Identifier.prototype.isMissing = function () {
   1062            return false;
   1063        };
   1064        Identifier.prototype.isLeaf = function () {
   1065            return true;
   1066        };
   1067        Identifier.prototype.treeViewLabel = function () {
   1068            return "id: " + this.actualText;
   1069        };
   1070        Identifier.prototype.printLabel = function () {
   1071            if(this.actualText) {
   1072                return "id: " + this.actualText;
   1073            } else {
   1074                return "name node";
   1075            }
   1076        };
   1077        Identifier.prototype.typeCheck = function (typeFlow) {
   1078            return typeFlow.typeCheckName(this);
   1079        };
   1080        Identifier.prototype.emit = function (emitter, tokenId, startLine) {
   1081            emitter.emitJavascriptName(this, true);
   1082        };
   1083        Identifier.fromToken = function fromToken(token) {
   1084            return new Identifier(token.getText(), (token).hasEscapeSequence);
   1085        }
   1086        return Identifier;
   1087    })(AST);
   1088    TypeScript.Identifier = Identifier;    
   1089    var MissingIdentifier = (function (_super) {
   1090        __extends(MissingIdentifier, _super);
   1091        function MissingIdentifier() {
   1092                _super.call(this, "__missing");
   1093        }
   1094        MissingIdentifier.prototype.isMissing = function () {
   1095            return true;
   1096        };
   1097        MissingIdentifier.prototype.emit = function (emitter, tokenId, startLine) {
   1098        };
   1099        return MissingIdentifier;
   1100    })(Identifier);
   1101    TypeScript.MissingIdentifier = MissingIdentifier;    
   1102    var Label = (function (_super) {
   1103        __extends(Label, _super);
   1104        function Label(id) {
   1105                _super.call(this, TypeScript.NodeType.Label);
   1106            this.id = id;
   1107        }
   1108        Label.prototype.printLabel = function () {
   1109            return this.id.actualText + ":";
   1110        };
   1111        Label.prototype.typeCheck = function (typeFlow) {
   1112            this.type = typeFlow.voidType;
   1113            return this;
   1114        };
   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);
   1124        };
   1125        return Label;
   1126    })(AST);
   1127    TypeScript.Label = Label;    
   1128    var Expression = (function (_super) {
   1129        __extends(Expression, _super);
   1130        function Expression(nodeType) {
   1131                _super.call(this, nodeType);
   1132        }
   1133        Expression.prototype.isExpression = function () {
   1134            return true;
   1135        };
   1136        Expression.prototype.isStatementOrExpression = function () {
   1137            return true;
   1138        };
   1139        return Expression;
   1140    })(AST);
   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;
   1149        }
   1150        UnaryExpression.prototype.addToControlFlow = function (context) {
   1151            _super.prototype.addToControlFlow.call(this, context);
   1152            if(this.nodeType == TypeScript.NodeType.Throw) {
   1153                context.returnStmt();
   1154            }
   1155        };
   1156        UnaryExpression.prototype.typeCheck = function (typeFlow) {
   1157            switch(this.nodeType) {
   1158                case TypeScript.NodeType.Not: {
   1159                    return typeFlow.typeCheckBitNot(this);
   1160 
   1161                }
   1162                case TypeScript.NodeType.LogNot: {
   1163                    return typeFlow.typeCheckLogNot(this);
   1164 
   1165                }
   1166                case TypeScript.NodeType.Pos:
   1167                case TypeScript.NodeType.Neg: {
   1168                    return typeFlow.typeCheckUnaryNumberOperator(this);
   1169 
   1170                }
   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);
   1176 
   1177                }
   1178                case TypeScript.NodeType.ArrayLit: {
   1179                    typeFlow.typeCheckArrayLit(this);
   1180                    return this;
   1181 
   1182                }
   1183                case TypeScript.NodeType.ObjectLit: {
   1184                    typeFlow.typeCheckObjectLit(this);
   1185                    return this;
   1186 
   1187                }
   1188                case TypeScript.NodeType.Throw: {
   1189                    this.operand = typeFlow.typeCheck(this.operand);
   1190                    this.type = typeFlow.voidType;
   1191                    return this;
   1192 
   1193                }
   1194                case TypeScript.NodeType.Typeof: {
   1195                    this.operand = typeFlow.typeCheck(this.operand);
   1196                    this.type = typeFlow.stringType;
   1197                    return this;
   1198 
   1199                }
   1200                case TypeScript.NodeType.Delete: {
   1201                    this.operand = typeFlow.typeCheck(this.operand);
   1202                    this.type = typeFlow.booleanType;
   1203                    break;
   1204 
   1205                }
   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;
   1213                    return this;
   1214 
   1215                }
   1216                case TypeScript.NodeType.Void: {
   1217                    this.operand = typeFlow.typeCheck(this.operand);
   1218                    this.type = typeFlow.checker.undefinedType;
   1219                    break;
   1220 
   1221                }
   1222                default: {
   1223                    throw new Error("please implement in derived class");
   1224 
   1225                }
   1226            }
   1227            return this;
   1228        };
   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("++");
   1236                    break;
   1237 
   1238                }
   1239                case TypeScript.NodeType.LogNot: {
   1240                    emitter.writeToOutput("!");
   1241                    emitter.emitJavascript(this.operand, TypeScript.TokenID.Exclamation, false);
   1242                    break;
   1243 
   1244                }
   1245                case TypeScript.NodeType.DecPost: {
   1246                    emitter.emitJavascript(this.operand, TypeScript.TokenID.MinusMinus, false);
   1247                    emitter.writeToOutput("--");
   1248                    break;
   1249 
   1250                }
   1251                case TypeScript.NodeType.ObjectLit: {
   1252                    emitter.emitObjectLiteral(this.operand);
   1253                    break;
   1254 
   1255                }
   1256                case TypeScript.NodeType.ArrayLit: {
   1257                    emitter.emitArrayLiteral(this.operand);
   1258                    break;
   1259 
   1260                }
   1261                case TypeScript.NodeType.Not: {
   1262                    emitter.writeToOutput("~");
   1263                    emitter.emitJavascript(this.operand, TypeScript.TokenID.Tilde, false);
   1264                    break;
   1265 
   1266                }
   1267                case TypeScript.NodeType.Neg: {
   1268                    emitter.writeToOutput("-");
   1269                    if(this.operand.nodeType == TypeScript.NodeType.Neg) {
   1270                        this.operand.isParenthesized = true;
   1271                    }
   1272                    emitter.emitJavascript(this.operand, TypeScript.TokenID.Minus, false);
   1273                    break;
   1274 
   1275                }
   1276                case TypeScript.NodeType.Pos: {
   1277                    emitter.writeToOutput("+");
   1278                    if(this.operand.nodeType == TypeScript.NodeType.Pos) {
   1279                        this.operand.isParenthesized = true;
   1280                    }
   1281                    emitter.emitJavascript(this.operand, TypeScript.TokenID.Plus, false);
   1282                    break;
   1283 
   1284                }
   1285                case TypeScript.NodeType.IncPre: {
   1286                    emitter.writeToOutput("++");
   1287                    emitter.emitJavascript(this.operand, TypeScript.TokenID.PlusPlus, false);
   1288                    break;
   1289 
   1290                }
   1291                case TypeScript.NodeType.DecPre: {
   1292                    emitter.writeToOutput("--");
   1293                    emitter.emitJavascript(this.operand, TypeScript.TokenID.MinusMinus, false);
   1294                    break;
   1295 
   1296                }
   1297                case TypeScript.NodeType.Throw: {
   1298                    emitter.writeToOutput("throw ");
   1299                    emitter.emitJavascript(this.operand, TypeScript.TokenID.Tilde, false);
   1300                    emitter.writeToOutput(";");
   1301                    break;
   1302 
   1303                }
   1304                case TypeScript.NodeType.Typeof: {
   1305                    emitter.writeToOutput("typeof ");
   1306                    emitter.emitJavascript(this.operand, TypeScript.TokenID.Tilde, false);
   1307                    break;
   1308 
   1309                }
   1310                case TypeScript.NodeType.Delete: {
   1311                    emitter.writeToOutput("delete ");
   1312                    emitter.emitJavascript(this.operand, TypeScript.TokenID.Tilde, false);
   1313                    break;
   1314 
   1315                }
   1316                case TypeScript.NodeType.Void: {
   1317                    emitter.writeToOutput("void ");
   1318                    emitter.emitJavascript(this.operand, TypeScript.TokenID.Tilde, false);
   1319                    break;
   1320 
   1321                }
   1322                case TypeScript.NodeType.TypeAssertion: {
   1323                    emitter.emitJavascript(this.operand, TypeScript.TokenID.Tilde, false);
   1324                    break;
   1325 
   1326                }
   1327                default: {
   1328                    throw new Error("please implement in derived class");
   1329 
   1330                }
   1331            }
   1332            emitter.recordSourceMappingEnd(this);
   1333            emitter.emitParensAndCommentsInPlace(this, false);
   1334        };
   1335        return UnaryExpression;
   1336    })(Expression);
   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;
   1346        }
   1347        CallExpression.prototype.typeCheck = function (typeFlow) {
   1348            if(this.nodeType == TypeScript.NodeType.New) {
   1349                return typeFlow.typeCheckNew(this);
   1350            } else {
   1351                return typeFlow.typeCheckCall(this);
   1352            }
   1353        };
   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);
   1359            } else {
   1360                emitter.emitCall(this, this.target, this.arguments);
   1361            }
   1362            emitter.recordSourceMappingEnd(this);
   1363            emitter.emitParensAndCommentsInPlace(this, false);
   1364        };
   1365        return CallExpression;
   1366    })(Expression);
   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;
   1374        }
   1375        BinaryExpression.prototype.typeCheck = function (typeFlow) {
   1376            switch(this.nodeType) {
   1377                case TypeScript.NodeType.Dot: {
   1378                    return typeFlow.typeCheckDotOperator(this);
   1379 
   1380                }
   1381                case TypeScript.NodeType.Asg: {
   1382                    return typeFlow.typeCheckAsgOperator(this);
   1383 
   1384                }
   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);
   1393 
   1394                }
   1395                case TypeScript.NodeType.Xor: {
   1396                    return typeFlow.typeCheckBitwiseOperator(this, false);
   1397 
   1398                }
   1399                case TypeScript.NodeType.Ne:
   1400                case TypeScript.NodeType.Eq: {
   1401                    var text;
   1402                    if(typeFlow.checker.styleSettings.eqeqeq) {
   1403                        text = TypeScript.nodeTypeTable[this.nodeType];
   1404                        typeFlow.checker.errorReporter.styleError(this, "use of " + text);
   1405                    } else {
   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");
   1410                            }
   1411                        }
   1412                    }
   1413 
   1414                }
   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);
   1422 
   1423                }
   1424                case TypeScript.NodeType.Index: {
   1425                    return typeFlow.typeCheckIndex(this);
   1426 
   1427                }
   1428                case TypeScript.NodeType.Member: {
   1429                    this.type = typeFlow.voidType;
   1430                    return this;
   1431 
   1432                }
   1433                case TypeScript.NodeType.LogOr: {
   1434                    return typeFlow.typeCheckLogOr(this);
   1435 
   1436                }
   1437                case TypeScript.NodeType.LogAnd: {
   1438                    return typeFlow.typeCheckLogAnd(this);
   1439 
   1440                }
   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);
   1449 
   1450                }
   1451                case TypeScript.NodeType.AsgXor: {
   1452                    return typeFlow.typeCheckBitwiseOperator(this, true);
   1453 
   1454                }
   1455                case TypeScript.NodeType.Lsh:
   1456                case TypeScript.NodeType.Rsh:
   1457                case TypeScript.NodeType.Rs2: {
   1458                    return typeFlow.typeCheckShift(this, false);
   1459 
   1460                }
   1461                case TypeScript.NodeType.AsgLsh:
   1462                case TypeScript.NodeType.AsgRsh:
   1463                case TypeScript.NodeType.AsgRs2: {
   1464                    return typeFlow.typeCheckShift(this, true);
   1465 
   1466                }
   1467                case TypeScript.NodeType.Comma: {
   1468                    return typeFlow.typeCheckCommaOperator(this);
   1469 
   1470                }
   1471                case TypeScript.NodeType.InstOf: {
   1472                    return typeFlow.typeCheckInstOf(this);
   1473 
   1474                }
   1475                case TypeScript.NodeType.In: {
   1476                    return typeFlow.typeCheckInOperator(this);
   1477 
   1478                }
   1479                case TypeScript.NodeType.From: {
   1480                    typeFlow.checker.errorReporter.simpleError(this, "Illegal use of 'from' keyword in binary expression");
   1481                    break;
   1482 
   1483                }
   1484                default: {
   1485                    throw new Error("please implement in derived class");
   1486 
   1487                }
   1488            }
   1489            return this;
   1490        };
   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 ");
   1499                } else {
   1500                    if(TypeScript.tokenTable[binTokenId].text == "in") {
   1501                        emitter.writeToOutput(" in ");
   1502                    } else {
   1503                        emitter.writeToOutputTrimmable(" " + TypeScript.tokenTable[binTokenId].text + " ");
   1504                    }
   1505                }
   1506                emitter.emitJavascript(this.operand2, binTokenId, false);
   1507            } else {
   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);
   1514                        }
   1515                        break;
   1516 
   1517                    }
   1518                    case TypeScript.NodeType.Index: {
   1519                        emitter.emitIndex(this.operand1, this.operand2);
   1520                        break;
   1521 
   1522                    }
   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 ");
   1528                            } else {
   1529                                emitter.writeToOutput("set ");
   1530                            }
   1531                            emitter.emitJavascript(this.operand1, TypeScript.TokenID.Colon, false);
   1532                        } else {
   1533                            emitter.emitJavascript(this.operand1, TypeScript.TokenID.Colon, false);
   1534                            emitter.writeToOutputTrimmable(": ");
   1535                        }
   1536                        emitter.emitJavascript(this.operand2, TypeScript.TokenID.Comma, false);
   1537                        break;
   1538 
   1539                    }
   1540                    case TypeScript.NodeType.Comma: {
   1541                        emitter.emitJavascript(this.operand1, TypeScript.TokenID.Comma, false);
   1542                        if(emitter.emitState.inObjectLiteral) {
   1543                            emitter.writeLineToOutput(", ");
   1544                        } else {
   1545                            emitter.writeToOutput(",");
   1546                        }
   1547                        emitter.emitJavascript(this.operand2, TypeScript.TokenID.Comma, false);
   1548                        break;
   1549 
   1550                    }
   1551                    case TypeScript.NodeType.Is: {
   1552                        throw new Error("should be de-sugared during type check");
   1553 
   1554                    }
   1555                    default: {
   1556                        throw new Error("please implement in derived class");
   1557 
   1558                    }
   1559                }
   1560            }
   1561            emitter.recordSourceMappingEnd(this);
   1562            emitter.emitParensAndCommentsInPlace(this, false);
   1563        };
   1564        return BinaryExpression;
   1565    })(Expression);
   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;
   1574        }
   1575        ConditionalExpression.prototype.typeCheck = function (typeFlow) {
   1576            return typeFlow.typeCheckQMark(this);
   1577        };
   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);
   1588        };
   1589        return ConditionalExpression;
   1590    })(Expression);
   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);
   1596            this.value = value;
   1597            this.hasEmptyFraction = hasEmptyFraction;
   1598            this.isNegativeZero = false;
   1599        }
   1600        NumberLiteral.prototype.typeCheck = function (typeFlow) {
   1601            this.type = typeFlow.doubleType;
   1602            return this;
   1603        };
   1604        NumberLiteral.prototype.treeViewLabel = function () {
   1605            return "num: " + this.printLabel();
   1606        };
   1607        NumberLiteral.prototype.emit = function (emitter, tokenId, startLine) {
   1608            emitter.emitParensAndCommentsInPlace(this, true);
   1609            emitter.recordSourceMappingStart(this);
   1610            if(this.isNegativeZero) {
   1611                emitter.writeToOutput("-");
   1612            }
   1613            emitter.writeToOutput(this.value.toString());
   1614            if(this.hasEmptyFraction) {
   1615                emitter.writeToOutput(".0");
   1616            }
   1617            emitter.recordSourceMappingEnd(this);
   1618            emitter.emitParensAndCommentsInPlace(this, false);
   1619        };
   1620        NumberLiteral.prototype.printLabel = function () {
   1621            if(Math.floor(this.value) != this.value) {
   1622                return this.value.toFixed(2).toString();
   1623            } else {
   1624                if(this.hasEmptyFraction) {
   1625                    return this.value.toString() + ".0";
   1626                } else {
   1627                    return this.value.toString();
   1628                }
   1629            }
   1630        };
   1631        return NumberLiteral;
   1632    })(Expression);
   1633    TypeScript.NumberLiteral = NumberLiteral;    
   1634    var RegexLiteral = (function (_super) {
   1635        __extends(RegexLiteral, _super);
   1636        function RegexLiteral(regex) {
   1637                _super.call(this, TypeScript.NodeType.Regex);
   1638            this.regex = regex;
   1639        }
   1640        RegexLiteral.prototype.typeCheck = function (typeFlow) {
   1641            this.type = typeFlow.regexType;
   1642            return this;
   1643        };
   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);
   1650        };
   1651        return RegexLiteral;
   1652    })(Expression);
   1653    TypeScript.RegexLiteral = RegexLiteral;    
   1654    var StringLiteral = (function (_super) {
   1655        __extends(StringLiteral, _super);
   1656        function StringLiteral(text) {
   1657                _super.call(this, TypeScript.NodeType.QString);
   1658            this.text = text;
   1659        }
   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);
   1666        };
   1667        StringLiteral.prototype.typeCheck = function (typeFlow) {
   1668            this.type = typeFlow.stringType;
   1669            return this;
   1670        };
   1671        StringLiteral.prototype.treeViewLabel = function () {
   1672            return "st: " + this.text;
   1673        };
   1674        StringLiteral.prototype.printLabel = function () {
   1675            return this.text;
   1676        };
   1677        return StringLiteral;
   1678    })(Expression);
   1679    TypeScript.StringLiteral = StringLiteral;    
   1680    var ModuleElement = (function (_super) {
   1681        __extends(ModuleElement, _super);
   1682        function ModuleElement(nodeType) {
   1683                _super.call(this, nodeType);
   1684        }
   1685        return ModuleElement;
   1686    })(AST);
   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);
   1692            this.id = id;
   1693            this.alias = alias;
   1694            this.varFlags = TypeScript.VarFlags.None;
   1695            this.isDynamicImport = false;
   1696        }
   1697        ImportDeclaration.prototype.isStatementOrExpression = function () {
   1698            return true;
   1699        };
   1700        ImportDeclaration.prototype.isDeclaration = function () {
   1701            return true;
   1702        };
   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(";");
   1716                }
   1717                emitter.emitParensAndCommentsInPlace(this, false);
   1718                emitter.recordSourceMappingEnd(this);
   1719                emitter.modAliasId = prevModAliasId;
   1720                emitter.firstModAlias = prevFirstModAlias;
   1721            }
   1722        };
   1723        ImportDeclaration.prototype.typeCheck = function (typeFlow) {
   1724            return typeFlow.typeCheckImportDecl(this);
   1725        };
   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;
   1730            } else {
   1731                var dotExpr = aliasAST;
   1732                return this.getAliasName(dotExpr.operand1) + "." + this.getAliasName(dotExpr.operand2);
   1733            }
   1734        };
   1735        ImportDeclaration.prototype.firstAliasedModToString = function () {
   1736            if(this.alias.nodeType == TypeScript.NodeType.Name) {
   1737                return (this.alias).actualText;
   1738            } else {
   1739                var dotExpr = this.alias;
   1740                var firstMod = dotExpr.operand1;
   1741                return firstMod.actualText;
   1742            }
   1743        };
   1744        return ImportDeclaration;
   1745    })(ModuleElement);
   1746    TypeScript.ImportDeclaration = ImportDeclaration;    
   1747    var BoundDecl = (function (_super) {
   1748        __extends(BoundDecl, _super);
   1749        function BoundDecl(id, nodeType, nestingLevel) {
   1750                _super.call(this, nodeType);
   1751            this.id = id;
   1752            this.nestingLevel = nestingLevel;
   1753            this.init = null;
   1754            this.typeExpr = null;
   1755            this.varFlags = TypeScript.VarFlags.None;
   1756            this.sym = null;
   1757        }
   1758        BoundDecl.prototype.isDeclaration = function () {
   1759            return true;
   1760        };
   1761        BoundDecl.prototype.isStatementOrExpression = function () {
   1762            return true;
   1763        };
   1764        BoundDecl.prototype.isPrivate = function () {
   1765            return TypeScript.hasFlag(this.varFlags, TypeScript.VarFlags.Private);
   1766        };
   1767        BoundDecl.prototype.isPublic = function () {
   1768            return TypeScript.hasFlag(this.varFlags, TypeScript.VarFlags.Public);
   1769        };
   1770        BoundDecl.prototype.isProperty = function () {
   1771            return TypeScript.hasFlag(this.varFlags, TypeScript.VarFlags.Property);
   1772        };
   1773        BoundDecl.prototype.typeCheck = function (typeFlow) {
   1774            return typeFlow.typeCheckBoundDecl(this);
   1775        };
   1776        BoundDecl.prototype.printLabel = function () {
   1777            return this.treeViewLabel();
   1778        };
   1779        return BoundDecl;
   1780    })(AST);
   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);
   1786        }
   1787        VarDecl.prototype.isAmbient = function () {
   1788            return TypeScript.hasFlag(this.varFlags, TypeScript.VarFlags.Ambient);
   1789        };
   1790        VarDecl.prototype.isExported = function () {
   1791            return TypeScript.hasFlag(this.varFlags, TypeScript.VarFlags.Exported);
   1792        };
   1793        VarDecl.prototype.isStatic = function () {
   1794            return TypeScript.hasFlag(this.varFlags, TypeScript.VarFlags.Static);
   1795        };
   1796        VarDecl.prototype.emit = function (emitter, tokenId, startLine) {
   1797            emitter.emitJavascriptVarDecl(this, tokenId);
   1798        };
   1799        VarDecl.prototype.treeViewLabel = function () {
   1800            return "var " + this.id.actualText;
   1801        };
   1802        return VarDecl;
   1803    })(BoundDecl);
   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;
   1811        }
   1812        ArgDecl.prototype.isOptionalArg = function () {
   1813            return this.isOptional || this.init;
   1814        };
   1815        ArgDecl.prototype.treeViewLabel = function () {
   1816            return "arg: " + this.id.actualText;
   1817        };
   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);
   1824        };
   1825        return ArgDecl;
   1826    })(BoundDecl);
   1827    TypeScript.ArgDecl = ArgDecl;    
   1828    var internalId = 0;
   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);
   1833            this.name = name;
   1834            this.bod = bod;
   1835            this.isConstructor = isConstructor;
   1836            this.arguments = arguments;
   1837            this.vars = vars;
   1838            this.scopes = scopes;
   1839            this.statics = statics;
   1840            this.hint = null;
   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;
   1862        }
   1863        FuncDecl.prototype.isDeclaration = function () {
   1864            return true;
   1865        };
   1866        FuncDecl.prototype.internalName = function () {
   1867            if(this.internalNameCache == null) {
   1868                var extName = this.getNameText();
   1869                if(extName) {
   1870                    this.internalNameCache = "_internal_" + extName;
   1871                } else {
   1872                    this.internalNameCache = "_internal_" + internalId++;
   1873                }
   1874            }
   1875            return this.internalNameCache;
   1876        };
   1877        FuncDecl.prototype.hasSelfReference = function () {
   1878            return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.HasSelfReference);
   1879        };
   1880        FuncDecl.prototype.setHasSelfReference = function () {
   1881            this.fncFlags |= TypeScript.FncFlags.HasSelfReference;
   1882        };
   1883        FuncDecl.prototype.hasSuperReferenceInFatArrowFunction = function () {
   1884            return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.HasSuperReferenceInFatArrowFunction);
   1885        };
   1886        FuncDecl.prototype.setHasSuperReferenceInFatArrowFunction = function () {
   1887            this.fncFlags |= TypeScript.FncFlags.HasSuperReferenceInFatArrowFunction;
   1888        };
   1889        FuncDecl.prototype.addCloRef = function (id, sym) {
   1890            if(this.envids == null) {
   1891                this.envids = new Array();
   1892            }
   1893            this.envids[this.envids.length] = id;
   1894            var outerFnc = this.enclosingFnc;
   1895            if(sym) {
   1896                while(outerFnc && (outerFnc.type.symbol != sym.container)) {
   1897                    outerFnc.addJumpRef(sym);
   1898                    outerFnc = outerFnc.enclosingFnc;
   1899                }
   1900            }
   1901            return this.envids.length - 1;
   1902        };
   1903        FuncDecl.prototype.addJumpRef = function (sym) {
   1904            if(this.jumpRefs == null) {
   1905                this.jumpRefs = new Array();
   1906            }
   1907            var id = new Identifier(sym.name);
   1908            this.jumpRefs[this.jumpRefs.length] = id;
   1909            id.sym = sym;
   1910            id.cloId = this.addCloRef(id, null);
   1911        };
   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);
   1918                return ast;
   1919            };
   1920            var walker = TypeScript.getAstWalkerFactory().getWalker(controlFlowPrefix, null, null, context);
   1921            context.walker = walker;
   1922            walker.walk(this.bod, this);
   1923            return context;
   1924        };
   1925        FuncDecl.prototype.typeCheck = function (typeFlow) {
   1926            return typeFlow.typeCheckFunction(this);
   1927        };
   1928        FuncDecl.prototype.emit = function (emitter, tokenId, startLine) {
   1929            emitter.emitJavascriptFunction(this);
   1930        };
   1931        FuncDecl.prototype.getNameText = function () {
   1932            if(this.name) {
   1933                return this.name.actualText;
   1934            } else {
   1935                return this.hint;
   1936            }
   1937        };
   1938        FuncDecl.prototype.isMethod = function () {
   1939            return (this.fncFlags & TypeScript.FncFlags.Method) != TypeScript.FncFlags.None;
   1940        };
   1941        FuncDecl.prototype.isCallMember = function () {
   1942            return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.CallMember);
   1943        };
   1944        FuncDecl.prototype.isConstructMember = function () {
   1945            return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.ConstructMember);
   1946        };
   1947        FuncDecl.prototype.isIndexerMember = function () {
   1948            return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.IndexerMember);
   1949        };
   1950        FuncDecl.prototype.isSpecialFn = function () {
   1951            return this.isCallMember() || this.isIndexerMember() || this.isConstructMember();
   1952        };
   1953        FuncDecl.prototype.isAnonymousFn = function () {
   1954            return this.name === null;
   1955        };
   1956        FuncDecl.prototype.isAccessor = function () {
   1957            return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.GetAccessor) || TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.SetAccessor);
   1958        };
   1959        FuncDecl.prototype.isGetAccessor = function () {
   1960            return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.GetAccessor);
   1961        };
   1962        FuncDecl.prototype.isSetAccessor = function () {
   1963            return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.SetAccessor);
   1964        };
   1965        FuncDecl.prototype.isAmbient = function () {
   1966            return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.Ambient);
   1967        };
   1968        FuncDecl.prototype.isExported = function () {
   1969            return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.Exported);
   1970        };
   1971        FuncDecl.prototype.isPrivate = function () {
   1972            return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.Private);
   1973        };
   1974        FuncDecl.prototype.isPublic = function () {
   1975            return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.Public);
   1976        };
   1977        FuncDecl.prototype.isStatic = function () {
   1978            return TypeScript.hasFlag(this.fncFlags, TypeScript.FncFlags.Static);
   1979        };
   1980        FuncDecl.prototype.treeViewLabel = function () {
   1981            if(this.name == null) {
   1982                return "funcExpr";
   1983            } else {
   1984                return "func: " + this.name.actualText;
   1985            }
   1986        };
   1987        FuncDecl.prototype.ClearFlags = function () {
   1988            this.fncFlags = TypeScript.FncFlags.None;
   1989        };
   1990        FuncDecl.prototype.isSignature = function () {
   1991            return (this.fncFlags & TypeScript.FncFlags.Signature) != TypeScript.FncFlags.None;
   1992        };
   1993        return FuncDecl;
   1994    })(AST);
   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;
   2001        }
   2002        return LocationInfo;
   2003    })();
   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 = [];
   2023            this.vars = vars;
   2024            this.scopes = scopes;
   2025        }
   2026        Script.prototype.setCachedEmitRequired = function (value) {
   2027            this.cachedEmitRequired = value;
   2028            return this.cachedEmitRequired;
   2029        };
   2030        Script.prototype.typeCheck = function (typeFlow) {
   2031            return typeFlow.typeCheckScript(this);
   2032        };
   2033        Script.prototype.treeViewLabel = function () {
   2034            return "Script";
   2035        };
   2036        Script.prototype.emitRequired = function (emitOptions) {
   2037            if(this.cachedEmitRequired != undefined) {
   2038                return this.cachedEmitRequired;
   2039            }
   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);
   2046                        }
   2047                    } else {
   2048                        if(stmt.nodeType == TypeScript.NodeType.ClassDeclaration) {
   2049                            if(!TypeScript.hasFlag((stmt).varFlags, TypeScript.VarFlags.Ambient)) {
   2050                                return this.setCachedEmitRequired(true);
   2051                            }
   2052                        } else {
   2053                            if(stmt.nodeType == TypeScript.NodeType.VarDecl) {
   2054                                if(!TypeScript.hasFlag((stmt).varFlags, TypeScript.VarFlags.Ambient)) {
   2055                                    return this.setCachedEmitRequired(true);
   2056                                }
   2057                            } else {
   2058                                if(stmt.nodeType == TypeScript.NodeType.FuncDecl) {
   2059                                    if(!(stmt).isSignature()) {
   2060                                        return this.setCachedEmitRequired(true);
   2061                                    }
   2062                                } else {
   2063                                    if(stmt.nodeType != TypeScript.NodeType.InterfaceDeclaration && stmt.nodeType != TypeScript.NodeType.Empty) {
   2064                                        return this.setCachedEmitRequired(true);
   2065                                    }
   2066                                }
   2067                            }
   2068                        }
   2069                    }
   2070                }
   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);
   2073                }
   2074            }
   2075            return this.setCachedEmitRequired(false);
   2076        };
   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);
   2082            }
   2083        };
   2084        Script.prototype.AddExternallyVisibleImportedSymbol = function (symbol, checker) {
   2085            if(this.isExternallyVisibleSymbol(symbol)) {
   2086                return;
   2087            }
   2088            if(!symbol.getType().symbol.isExternallyVisible(checker)) {
   2089                var quotes = "";
   2090                var moduleName = symbol.getType().symbol.prettyName;
   2091                if(!TypeScript.isQuoted(moduleName)) {
   2092                    quotes = "'";
   2093                }
   2094                checker.errorReporter.simpleError(symbol.declAST, "Externally visible import statement uses non exported module " + quotes + moduleName + quotes);
   2095            }
   2096            this.externallyVisibleImportedSymbols.push(symbol);
   2097        };
   2098        Script.prototype.isExternallyVisibleSymbol = function (symbol) {
   2099            for(var i = 0; i < this.externallyVisibleImportedSymbols.length; i++) {
   2100                if(this.externallyVisibleImportedSymbols[i] == symbol) {
   2101                    return true;
   2102                }
   2103            }
   2104            return false;
   2105        };
   2106        return Script;
   2107    })(FuncDecl);
   2108    TypeScript.Script = Script;    
   2109    var NamedDeclaration = (function (_super) {
   2110        __extends(NamedDeclaration, _super);
   2111        function NamedDeclaration(nodeType, name, members) {
   2112                _super.call(this, nodeType);
   2113            this.name = name;
   2114            this.members = members;
   2115            this.leftCurlyCount = 0;
   2116            this.rightCurlyCount = 0;
   2117        }
   2118        NamedDeclaration.prototype.isDeclaration = function () {
   2119            return true;
   2120        };
   2121        return NamedDeclaration;
   2122    })(ModuleElement);
   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;
   2133            this.vars = vars;
   2134            this.scopes = scopes;
   2135            this.prettyName = this.name.actualText;
   2136        }
   2137        ModuleDeclaration.prototype.isExported = function () {
   2138            return TypeScript.hasFlag(this.modFlags, TypeScript.ModuleFlags.Exported);
   2139        };
   2140        ModuleDeclaration.prototype.isAmbient = function () {
   2141            return TypeScript.hasFlag(this.modFlags, TypeScript.ModuleFlags.Ambient);
   2142        };
   2143        ModuleDeclaration.prototype.isEnum = function () {
   2144            return TypeScript.hasFlag(this.modFlags, TypeScript.ModuleFlags.IsEnum);
   2145        };
   2146        ModuleDeclaration.prototype.recordNonInterface = function () {
   2147            this.modFlags &= ~TypeScript.ModuleFlags.ShouldEmitModuleDecl;
   2148        };
   2149        ModuleDeclaration.prototype.typeCheck = function (typeFlow) {
   2150            return typeFlow.typeCheckModule(this);
   2151        };
   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);
   2159            }
   2160        };
   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;
   2171        }
   2172        TypeDeclaration.prototype.isExported = function () {
   2173            return TypeScript.hasFlag(this.varFlags, TypeScript.VarFlags.Exported);
   2174        };
   2175        TypeDeclaration.prototype.isAmbient = function () {
   2176            return TypeScript.hasFlag(this.varFlags, TypeScript.VarFlags.Ambient);
   2177        };
   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 = {
   2186            };
   2187            this.constructorDecl = null;
   2188            this.constructorNestingLevel = 0;
   2189            this.endingToken = null;
   2190        }
   2191        ClassDeclaration.prototype.typeCheck = function (typeFlow) {
   2192            return typeFlow.typeCheckClass(this);
   2193        };
   2194        ClassDeclaration.prototype.emit = function (emitter, tokenId, startLine) {
   2195            emitter.emitJavascriptClass(this);
   2196        };
   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);
   2204        }
   2205        InterfaceDeclaration.prototype.typeCheck = function (typeFlow) {
   2206            return typeFlow.typeCheckInterface(this);
   2207        };
   2208        InterfaceDeclaration.prototype.emit = function (emitter, tokenId, startLine) {
   2209        };
   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;
   2218        }
   2219        Statement.prototype.isLoop = function () {
   2220            return false;
   2221        };
   2222        Statement.prototype.isStatementOrExpression = function () {
   2223            return true;
   2224        };
   2225        Statement.prototype.isCompoundStatement = function () {
   2226            return this.isLoop();
   2227        };
   2228        Statement.prototype.typeCheck = function (typeFlow) {
   2229            this.type = typeFlow.voidType;
   2230            return this;
   2231        };
   2232        return Statement;
   2233    })(ModuleElement);
   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;
   2240            this.stmt = stmt;
   2241        }
   2242        LabeledStatement.prototype.emit = function (emitter, tokenId, startLine) {
   2243            emitter.emitParensAndCommentsInPlace(this, true);
   2244            emitter.recordSourceMappingStart(this);
   2245            if(this.labels) {
   2246                var labelsLen = this.labels.members.length;
   2247                for(var i = 0; i < labelsLen; i++) {
   2248                    this.labels.members[i].emit(emitter, tokenId, startLine);
   2249                }
   2250            }
   2251            this.stmt.emit(emitter, tokenId, true);
   2252            emitter.recordSourceMappingEnd(this);
   2253            emitter.emitParensAndCommentsInPlace(this, false);
   2254        };
   2255        LabeledStatement.prototype.typeCheck = function (typeFlow) {
   2256            typeFlow.typeCheck(this.labels);
   2257            this.stmt = this.stmt.typeCheck(typeFlow);
   2258            return this;
   2259        };
   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);
   2265        };
   2266        return LabeledStatement;
   2267    })(Statement);
   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;
   2275        }
   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();
   2282            } else {
   2283                emitter.setInVarBlock(this.statements.members.length);
   2284            }
   2285            var temp = emitter.setInObjectLiteral(false);
   2286            if(this.statements) {
   2287                emitter.emitJavascriptList(this.statements, null, TypeScript.TokenID.Semicolon, true, false, false);
   2288            }
   2289            if(this.isStatementBlock) {
   2290                emitter.indenter.decreaseIndent();
   2291                emitter.emitIndent();
   2292                emitter.writeToOutput("}");
   2293            }
   2294            emitter.setInObjectLiteral(temp);
   2295            emitter.recordSourceMappingEnd(this);
   2296            emitter.emitParensAndCommentsInPlace(this, false);
   2297        };
   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);
   2303            }
   2304            context.walker.options.goChildren = false;
   2305            context.popStatement();
   2306            if(afterIfNeeded.predecessors.length > 0) {
   2307                context.current.addSuccessor(afterIfNeeded);
   2308                context.current = afterIfNeeded;
   2309            }
   2310        };
   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");
   2315                }
   2316            }
   2317            typeFlow.typeCheck(this.statements);
   2318            return this;
   2319        };
   2320        return Block;
   2321    })(Statement);
   2322    TypeScript.Block = Block;    
   2323    var Jump = (function (_super) {
   2324        __extends(Jump, _super);
   2325        function Jump(nodeType) {
   2326                _super.call(this, nodeType);
   2327            this.target = null;
   2328            this.resolvedTarget = null;
   2329        }
   2330        Jump.prototype.hasExplicitTarget = function () {
   2331            return (this.target);
   2332        };
   2333        Jump.prototype.setResolvedTarget = function (parser, stmt) {
   2334            if(stmt.isLoop()) {
   2335                this.resolvedTarget = stmt;
   2336                return true;
   2337            }
   2338            if(this.nodeType === TypeScript.NodeType.Continue) {
   2339                parser.reportParseError("continue statement applies only to loops");
   2340                return false;
   2341            } else {
   2342                if((stmt.nodeType == TypeScript.NodeType.Switch) || this.hasExplicitTarget()) {
   2343                    this.resolvedTarget = stmt;
   2344                    return true;
   2345                } else {
   2346                    parser.reportParseError("break statement with no label can apply only to a loop or switch statement");
   2347                    return false;
   2348                }
   2349            }
   2350        };
   2351        Jump.prototype.addToControlFlow = function (context) {
   2352            _super.prototype.addToControlFlow.call(this, context);
   2353            context.unconditionalBranch(this.resolvedTarget, (this.nodeType == TypeScript.NodeType.Continue));
   2354        };
   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");
   2360            } else {
   2361                emitter.writeToOutput("continue");
   2362            }
   2363            if(this.hasExplicitTarget()) {
   2364                emitter.writeToOutput(" " + this.target);
   2365            }
   2366            emitter.recordSourceMappingEnd(this);
   2367            emitter.writeToOutput(";");
   2368            emitter.emitParensAndCommentsInPlace(this, false);
   2369        };
   2370        return Jump;
   2371    })(Statement);
   2372    TypeScript.Jump = Jump;    
   2373    var WhileStatement = (function (_super) {
   2374        __extends(WhileStatement, _super);
   2375        function WhileStatement(cond) {
   2376                _super.call(this, TypeScript.NodeType.While);
   2377            this.cond = cond;
   2378            this.body = null;
   2379        }
   2380        WhileStatement.prototype.isLoop = function () {
   2381            return true;
   2382        };
   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);
   2394        };
   2395        WhileStatement.prototype.typeCheck = function (typeFlow) {
   2396            return typeFlow.typeCheckWhile(this);
   2397        };
   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;
   2407            if(this.body) {
   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();
   2413            }
   2414            if(!(context.noContinuation)) {
   2415                var loopEnd = context.current;
   2416                loopEnd.addSuccessor(loopStart);
   2417            }
   2418            context.current = afterLoop;
   2419            condBlock.addSuccessor(afterLoop);
   2420            context.noContinuation = false;
   2421            context.walker.options.goChildren = false;
   2422        };
   2423        return WhileStatement;
   2424    })(Statement);
   2425    TypeScript.WhileStatement = WhileStatement;    
   2426    var DoWhileStatement = (function (_super) {
   2427        __extends(DoWhileStatement, _super);
   2428        function DoWhileStatement() {
   2429                _super.call(this, TypeScript.NodeType.DoWhile);
   2430            this.body = null;
   2431            this.whileAST = null;
   2432            this.cond = null;
   2433        }
   2434        DoWhileStatement.prototype.isLoop = function () {
   2435            return true;
   2436        };
   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);
   2453        };
   2454        DoWhileStatement.prototype.typeCheck = function (typeFlow) {
   2455            return typeFlow.typeCheckDoWhile(this);
   2456        };
   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;
   2464            if(this.body) {
   2465                context.pushStatement(this, loopStart, afterLoop);
   2466                context.walk(this.body, this);
   2467                targetInfo = context.popStatement();
   2468            }
   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);
   2475            } else {
   2476                context.addUnreachable(this.cond);
   2477            }
   2478            context.walker.options.goChildren = false;
   2479        };
   2480        return DoWhileStatement;
   2481    })(Statement);
   2482    TypeScript.DoWhileStatement = DoWhileStatement;    
   2483    var IfStatement = (function (_super) {
   2484        __extends(IfStatement, _super);
   2485        function IfStatement(cond) {
   2486                _super.call(this, TypeScript.NodeType.If);
   2487            this.cond = cond;
   2488            this.elseBod = null;
   2489            this.statement = new ASTSpan();
   2490        }
   2491        IfStatement.prototype.isCompoundStatement = function () {
   2492            return true;
   2493        };
   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);
   2504            if(this.elseBod) {
   2505                if(this.elseBod.nodeType === TypeScript.NodeType.If) {
   2506                    emitter.writeToOutput(" else ");
   2507                    this.elseBod.emit(emitter, tokenId, false);
   2508                } else {
   2509                    emitter.writeToOutput(" else");
   2510                    emitter.emitJavascriptStatements(this.elseBod, true);
   2511                }
   2512            }
   2513            emitter.setInObjectLiteral(temp);
   2514            emitter.recordSourceMappingEnd(this);
   2515            emitter.emitParensAndCommentsInPlace(this, false);
   2516        };
   2517        IfStatement.prototype.typeCheck = function (typeFlow) {
   2518            return typeFlow.typeCheckIf(this);
   2519        };
   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);
   2532            }
   2533            if(this.elseBod) {
   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);
   2541                } else {
   2542                    if(hasContinuation) {
   2543                        context.noContinuation = false;
   2544                    }
   2545                }
   2546            } else {
   2547                beforeIf.addSuccessor(afterIf);
   2548                context.noContinuation = false;
   2549                hasContinuation = true;
   2550            }
   2551            var targetInfo = context.popStatement();
   2552            if(afterIf.predecessors.length > 0) {
   2553                context.noContinuation = false;
   2554                hasContinuation = true;
   2555            }
   2556            if(hasContinuation) {
   2557                context.current = afterIf;
   2558            }
   2559            context.walker.options.goChildren = false;
   2560        };
   2561        return IfStatement;
   2562    })(Statement);
   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;
   2569        }
   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(";");
   2579                }
   2580            } else {
   2581                emitter.writeToOutput("return;");
   2582            }
   2583            emitter.setInObjectLiteral(temp);
   2584            emitter.recordSourceMappingEnd(this);
   2585            emitter.emitParensAndCommentsInPlace(this, false);
   2586        };
   2587        ReturnStatement.prototype.addToControlFlow = function (context) {
   2588            _super.prototype.addToControlFlow.call(this, context);
   2589            context.returnStmt();
   2590        };
   2591        ReturnStatement.prototype.typeCheck = function (typeFlow) {
   2592            return typeFlow.typeCheckReturn(this);
   2593        };
   2594        return ReturnStatement;
   2595    })(Statement);
   2596    TypeScript.ReturnStatement = ReturnStatement;    
   2597    var EndCode = (function (_super) {
   2598        __extends(EndCode, _super);
   2599        function EndCode() {
   2600                _super.call(this, TypeScript.NodeType.EndCode);
   2601        }
   2602        return EndCode;
   2603    })(AST);
   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);
   2609            this.lval = lval;
   2610            this.obj = obj;
   2611            this.statement = new ASTSpan();
   2612            if(this.lval && (this.lval.nodeType == TypeScript.NodeType.VarDecl)) {
   2613                (this.lval).varFlags |= TypeScript.VarFlags.AutoInit;
   2614            }
   2615        }
   2616        ForInStatement.prototype.isLoop = function () {
   2617            return true;
   2618        };
   2619        ForInStatement.prototype.isFiltered = function () {
   2620            if(this.body) {
   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];
   2626                    }
   2627                } else {
   2628                    singleItem = this.body;
   2629                }
   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];
   2635                        }
   2636                    }
   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) {
   2642                                var binex = target;
   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) {
   2651                                                    return true;
   2652                                                }
   2653                                            }
   2654                                        }
   2655                                    }
   2656                                }
   2657                            }
   2658                        }
   2659                    }
   2660                }
   2661            }
   2662            return false;
   2663        };
   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);
   2679        };
   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");
   2684                }
   2685            }
   2686            return typeFlow.typeCheckForIn(this);
   2687        };
   2688        ForInStatement.prototype.addToControlFlow = function (context) {
   2689            if(this.lval) {
   2690                context.addContent(this.lval);
   2691            }
   2692            if(this.obj) {
   2693                context.addContent(this.obj);
   2694            }
   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;
   2700            if(this.body) {
   2701                context.pushStatement(this, loopStart, afterLoop);
   2702                context.walk(this.body, this);
   2703                context.popStatement();
   2704            }
   2705            if(!(context.noContinuation)) {
   2706                var loopEnd = context.current;
   2707                loopEnd.addSuccessor(loopStart);
   2708            }
   2709            context.current = afterLoop;
   2710            context.noContinuation = false;
   2711            loopHeader.addSuccessor(afterLoop);
   2712            context.walker.options.goChildren = false;
   2713        };
   2714        return ForInStatement;
   2715    })(Statement);
   2716    TypeScript.ForInStatement = ForInStatement;    
   2717    var ForStatement = (function (_super) {
   2718        __extends(ForStatement, _super);
   2719        function ForStatement(init) {
   2720                _super.call(this, TypeScript.NodeType.For);
   2721            this.init = init;
   2722        }
   2723        ForStatement.prototype.isLoop = function () {
   2724            return true;
   2725        };
   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(");
   2731            if(this.init) {
   2732                if(this.init.nodeType != TypeScript.NodeType.List) {
   2733                    emitter.emitJavascript(this.init, TypeScript.TokenID.For, false);
   2734                } else {
   2735                    emitter.setInVarBlock((this.init).members.length);
   2736                    emitter.emitJavascriptList(this.init, null, TypeScript.TokenID.For, false, false, false);
   2737                }
   2738            }
   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);
   2748        };
   2749        ForStatement.prototype.typeCheck = function (typeFlow) {
   2750            return typeFlow.typeCheckFor(this);
   2751        };
   2752        ForStatement.prototype.addToControlFlow = function (context) {
   2753            if(this.init) {
   2754                context.addContent(this.init);
   2755            }
   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;
   2763            var incrBB = null;
   2764            if(this.incr) {
   2765                incrBB = new TypeScript.BasicBlock();
   2766                continueTarget = incrBB;
   2767            }
   2768            if(this.cond) {
   2769                condBlock = context.current;
   2770                context.addContent(this.cond);
   2771                context.current = new TypeScript.BasicBlock();
   2772                condBlock.addSuccessor(context.current);
   2773            }
   2774            var targetInfo = null;
   2775            if(this.body) {
   2776                context.pushStatement(this, continueTarget, afterLoop);
   2777                context.walk(this.body, this);
   2778                targetInfo = context.popStatement();
   2779            }
   2780            if(this.incr) {
   2781                if(context.noContinuation) {
   2782                    if(incrBB.predecessors.length == 0) {
   2783                        context.addUnreachable(this.incr);
   2784                    }
   2785                } else {
   2786                    context.current.addSuccessor(incrBB);
   2787                    context.current = incrBB;
   2788                    context.addContent(this.incr);
   2789                }
   2790            }
   2791            var loopEnd = context.current;
   2792            if(!(context.noContinuation)) {
   2793                loopEnd.addSuccessor(loopStart);
   2794            }
   2795            if(condBlock) {
   2796                condBlock.addSuccessor(afterLoop);
   2797                context.noContinuation = false;
   2798            }
   2799            if(afterLoop.predecessors.length > 0) {
   2800                context.noContinuation = false;
   2801                context.current = afterLoop;
   2802            }
   2803            context.walker.options.goChildren = false;
   2804        };
   2805        return ForStatement;
   2806    })(Statement);
   2807    TypeScript.ForStatement = ForStatement;    
   2808    var WithStatement = (function (_super) {
   2809        __extends(WithStatement, _super);
   2810        function WithStatement(expr) {
   2811                _super.call(this, TypeScript.NodeType.With);
   2812            this.expr = expr;
   2813            this.withSym = null;
   2814        }
   2815        WithStatement.prototype.isCompoundStatement = function () {
   2816            return true;
   2817        };
   2818        WithStatement.prototype.emit = function (emitter, tokenId, startLine) {
   2819            emitter.emitParensAndCommentsInPlace(this, true);
   2820            emitter.recordSourceMappingStart(this);
   2821            emitter.writeToOutput("with (");
   2822            if(this.expr) {
   2823                emitter.emitJavascript(this.expr, TypeScript.TokenID.With, false);
   2824            }
   2825            emitter.writeToOutput(")");
   2826            emitter.emitJavascriptStatements(this.body, true);
   2827            emitter.recordSourceMappingEnd(this);
   2828            emitter.emitParensAndCommentsInPlace(this, false);
   2829        };
   2830        WithStatement.prototype.typeCheck = function (typeFlow) {
   2831            return typeFlow.typeCheckWith(this);
   2832        };
   2833        return WithStatement;
   2834    })(Statement);
   2835    TypeScript.WithStatement = WithStatement;    
   2836    var SwitchStatement = (function (_super) {
   2837        __extends(SwitchStatement, _super);
   2838        function SwitchStatement(val) {
   2839                _super.call(this, TypeScript.NodeType.Switch);
   2840            this.val = val;
   2841            this.defaultCase = null;
   2842            this.statement = new ASTSpan();
   2843        }
   2844        SwitchStatement.prototype.isCompoundStatement = function () {
   2845            return true;
   2846        };
   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);
   2862            }
   2863            emitter.indenter.decreaseIndent();
   2864            emitter.emitIndent();
   2865            emitter.writeToOutput("}");
   2866            emitter.setInObjectLiteral(temp);
   2867            emitter.recordSourceMappingEnd(this);
   2868            emitter.emitParensAndCommentsInPlace(this, false);
   2869        };
   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]);
   2875            }
   2876            this.defaultCase = typeFlow.typeCheck(this.defaultCase);
   2877            this.type = typeFlow.voidType;
   2878            return this;
   2879        };
   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);
   2895            }
   2896            if(afterSwitch.predecessors.length > 0) {
   2897                context.noContinuation = false;
   2898                context.current = afterSwitch;
   2899            } else {
   2900                context.noContinuation = true;
   2901            }
   2902            context.walker.options.goChildren = false;
   2903        };
   2904        return SwitchStatement;
   2905    })(Statement);
   2906    TypeScript.SwitchStatement = SwitchStatement;    
   2907    var CaseStatement = (function (_super) {
   2908        __extends(CaseStatement, _super);
   2909        function CaseStatement() {
   2910                _super.call(this, TypeScript.NodeType.Case);
   2911            this.expr = null;
   2912        }
   2913        CaseStatement.prototype.emit = function (emitter, tokenId, startLine) {
   2914            emitter.emitParensAndCommentsInPlace(this, true);
   2915            emitter.recordSourceMappingStart(this);
   2916            if(this.expr) {
   2917                emitter.writeToOutput("case ");
   2918                emitter.emitJavascript(this.expr, TypeScript.TokenID.Identifier, false);
   2919            } else {
   2920                emitter.writeToOutput("default");
   2921            }
   2922            emitter.writeToOutput(":");
   2923            if(this.body.members.length == 1 && this.body.members[0].nodeType == TypeScript.NodeType.Block) {
   2924                emitter.emitJavascriptStatements(this.body, false);
   2925            } else {
   2926                emitter.writeLineToOutput("");
   2927                emitter.indenter.increaseIndent();
   2928                emitter.emitBareJavascriptStatements(this.body);
   2929                emitter.indenter.decreaseIndent();
   2930            }
   2931            emitter.recordSourceMappingEnd(this);
   2932            emitter.emitParensAndCommentsInPlace(this, false);
   2933        };
   2934        CaseStatement.prototype.typeCheck = function (typeFlow) {
   2935            this.expr = typeFlow.typeCheck(this.expr);
   2936            typeFlow.typeCheck(this.body);
   2937            this.type = typeFlow.voidType;
   2938            return this;
   2939        };
   2940        CaseStatement.prototype.addToControlFlow = function (context) {
   2941            var execBlock = new TypeScript.BasicBlock();
   2942            var sw = context.currentSwitch[context.currentSwitch.length - 1];
   2943            if(this.expr) {
   2944                var exprBlock = new TypeScript.BasicBlock();
   2945                context.current = exprBlock;
   2946                sw.addSuccessor(exprBlock);
   2947                context.addContent(this.expr);
   2948                exprBlock.addSuccessor(execBlock);
   2949            } else {
   2950                sw.addSuccessor(execBlock);
   2951            }
   2952            context.current = execBlock;
   2953            if(this.body) {
   2954                context.walk(this.body, this);
   2955            }
   2956            context.noContinuation = false;
   2957            context.walker.options.goChildren = false;
   2958        };
   2959        return CaseStatement;
   2960    })(Statement);
   2961    TypeScript.CaseStatement = CaseStatement;    
   2962    var TypeReference = (function (_super) {
   2963        __extends(TypeReference, _super);
   2964        function TypeReference(term, arrayCount) {
   2965                _super.call(this, TypeScript.NodeType.TypeRef);
   2966            this.term = term;
   2967            this.arrayCount = arrayCount;
   2968        }
   2969        TypeReference.prototype.emit = function (emitter, tokenId, startLine) {
   2970            throw new Error("should not emit a type ref");
   2971        };
   2972        TypeReference.prototype.typeCheck = function (typeFlow) {
   2973            var prevInTCTR = typeFlow.inTypeRefTypeCheck;
   2974            typeFlow.inTypeRefTypeCheck = true;
   2975            var typeLink = TypeScript.getTypeLink(this, typeFlow.checker, true);
   2976            typeFlow.checker.resolveTypeLink(typeFlow.scope, typeLink, false);
   2977            if(this.term) {
   2978                typeFlow.typeCheck(this.term);
   2979            }
   2980            typeFlow.checkForVoidConstructor(typeLink.type, this);
   2981            this.type = typeLink.type;
   2982            if(this.term) {
   2983                this.term.type = this.type;
   2984            }
   2985            typeFlow.inTypeRefTypeCheck = prevInTCTR;
   2986            return this;
   2987        };
   2988        return TypeReference;
   2989    })(AST);
   2990    TypeScript.TypeReference = TypeReference;    
   2991    var TryFinally = (function (_super) {
   2992        __extends(TryFinally, _super);
   2993        function TryFinally(tryNode, finallyNode) {
   2994                _super.call(this, TypeScript.NodeType.TryFinally);
   2995            this.tryNode = tryNode;
   2996            this.finallyNode = finallyNode;
   2997        }
   2998        TryFinally.prototype.isCompoundStatement = function () {
   2999            return true;
   3000        };
   3001        TryFinally.prototype.emit = function (emitter, tokenId, startLine) {
   3002            emitter.recordSourceMappingStart(this);
   3003            emitter.emitJavascript(this.tryNode, TypeScript.TokenID.Try, false);
   3004            emitter.emitJavascript(this.finallyNode, TypeScript.TokenID.Finally, false);
   3005            emitter.recordSourceMappingEnd(this);
   3006        };
   3007        TryFinally.prototype.typeCheck = function (typeFlow) {
   3008            this.tryNode = typeFlow.typeCheck(this.tryNode);
   3009            this.finallyNode = typeFlow.typeCheck(this.finallyNode);
   3010            this.type = typeFlow.voidType;
   3011            return this;
   3012        };
   3013        TryFinally.prototype.addToControlFlow = function (context) {
   3014            var afterFinally = new TypeScript.BasicBlock();
   3015            context.walk(this.tryNode, this);
   3016            var finBlock = new TypeScript.BasicBlock();
   3017            if(context.current) {
   3018                context.current.addSuccessor(finBlock);
   3019            }
   3020            context.current = finBlock;
   3021            context.pushStatement(this, null, afterFinally);
   3022            context.walk(this.finallyNode, this);
   3023            if(!context.noContinuation && context.current) {
   3024                context.current.addSuccessor(afterFinally);
   3025            }
   3026            if(afterFinally.predecessors.length > 0) {
   3027                context.current = afterFinally;
   3028            } else {
   3029                context.noContinuation = true;
   3030            }
   3031            context.popStatement();
   3032            context.walker.options.goChildren = false;
   3033        };
   3034        return TryFinally;
   3035    })(Statement);
   3036    TypeScript.TryFinally = TryFinally;    
   3037    var TryCatch = (function (_super) {
   3038        __extends(TryCatch, _super);
   3039        function TryCatch(tryNode, catchNode) {
   3040                _super.call(this, TypeScript.NodeType.TryCatch);
   3041            this.tryNode = tryNode;
   3042            this.catchNode = catchNode;
   3043        }
   3044        TryCatch.prototype.isCompoundStatement = function () {
   3045            return true;
   3046        };
   3047        TryCatch.prototype.emit = function (emitter, tokenId, startLine) {
   3048            emitter.emitParensAndCommentsInPlace(this, true);
   3049            emitter.recordSourceMappingStart(this);
   3050            emitter.emitJavascript(this.tryNode, TypeScript.TokenID.Try, false);
   3051            emitter.emitJavascript(this.catchNode, TypeScript.TokenID.Catch, false);
   3052            emitter.recordSourceMappingEnd(this);
   3053            emitter.emitParensAndCommentsInPlace(this, false);
   3054        };
   3055        TryCatch.prototype.addToControlFlow = function (context) {
   3056            var beforeTry = context.current;
   3057            var tryBlock = new TypeScript.BasicBlock();
   3058            beforeTry.addSuccessor(tryBlock);
   3059            context.current = tryBlock;
   3060            var afterTryCatch = new TypeScript.BasicBlock();
   3061            context.pushStatement(this, null, afterTryCatch);
   3062            context.walk(this.tryNode, this);
   3063            if(!context.noContinuation) {
   3064                if(context.current) {
   3065                    context.current.addSuccessor(afterTryCatch);
   3066                }
   3067            }
   3068            context.current = new TypeScript.BasicBlock();
   3069            beforeTry.addSuccessor(context.current);
   3070            context.walk(this.catchNode, this);
   3071            context.popStatement();
   3072            if(!context.noContinuation) {
   3073                if(context.current) {
   3074                    context.current.addSuccessor(afterTryCatch);
   3075                }
   3076            }
   3077            context.current = afterTryCatch;
   3078            context.walker.options.goChildren = false;
   3079        };
   3080        TryCatch.prototype.typeCheck = function (typeFlow) {
   3081            this.tryNode = typeFlow.typeCheck(this.tryNode);
   3082            this.catchNode = typeFlow.typeCheck(this.catchNode);
   3083            this.type = typeFlow.voidType;
   3084            return this;
   3085        };
   3086        return TryCatch;
   3087    })(Statement);
   3088    TypeScript.TryCatch = TryCatch;    
   3089    var Try = (function (_super) {
   3090        __extends(Try, _super);
   3091        function Try(body) {
   3092                _super.call(this, TypeScript.NodeType.Try);
   3093            this.body = body;
   3094        }
   3095        Try.prototype.emit = function (emitter, tokenId, startLine) {
   3096            emitter.emitParensAndCommentsInPlace(this, true);
   3097            emitter.recordSourceMappingStart(this);
   3098            emitter.writeToOutput("try ");
   3099            emitter.emitJavascript(this.body, TypeScript.TokenID.Try, false);
   3100            emitter.recordSourceMappingEnd(this);
   3101            emitter.emitParensAndCommentsInPlace(this, false);
   3102        };
   3103        Try.prototype.typeCheck = function (typeFlow) {
   3104            this.body = typeFlow.typeCheck(this.body);
   3105            return this;
   3106        };
   3107        Try.prototype.addToControlFlow = function (context) {
   3108            if(this.body) {
   3109                context.walk(this.body, this);
   3110            }
   3111            context.walker.options.goChildren = false;
   3112            context.noContinuation = false;
   3113        };
   3114        return Try;
   3115    })(Statement);
   3116    TypeScript.Try = Try;    
   3117    var Catch = (function (_super) {
   3118        __extends(Catch, _super);
   3119        function Catch(param, body) {
   3120                _super.call(this, TypeScript.NodeType.Catch);
   3121            this.param = param;
   3122            this.body = body;
   3123            this.statement = new ASTSpan();
   3124            this.containedScope = null;
   3125            if(this.param) {
   3126                this.param.varFlags |= TypeScript.VarFlags.AutoInit;
   3127            }
   3128        }
   3129        Catch.prototype.emit = function (emitter, tokenId, startLine) {
   3130            emitter.emitParensAndCommentsInPlace(this, true);
   3131            emitter.recordSourceMappingStart(this);
   3132            emitter.writeToOutput(" ");
   3133            emitter.recordSourceMappingStart(this.statement);
   3134            emitter.writeToOutput("catch (");
   3135            emitter.emitJavascript(this.param, TypeScript.TokenID.OpenParen, false);
   3136            emitter.writeToOutput(")");
   3137            emitter.recordSourceMappingEnd(this.statement);
   3138            emitter.emitJavascript(this.body, TypeScript.TokenID.Catch, false);
   3139            emitter.recordSourceMappingEnd(this);
   3140            emitter.emitParensAndCommentsInPlace(this, false);
   3141        };
   3142        Catch.prototype.addToControlFlow = function (context) {
   3143            if(this.param) {
   3144                context.addContent(this.param);
   3145                var bodBlock = new TypeScript.BasicBlock();
   3146                context.current.addSuccessor(bodBlock);
   3147                context.current = bodBlock;
   3148            }
   3149            if(this.body) {
   3150                context.walk(this.body, this);
   3151            }
   3152            context.noContinuation = false;
   3153            context.walker.options.goChildren = false;
   3154        };
   3155        Catch.prototype.typeCheck = function (typeFlow) {
   3156            var prevScope = typeFlow.scope;
   3157            typeFlow.scope = this.containedScope;
   3158            this.param = typeFlow.typeCheck(this.param);
   3159            var exceptVar = new TypeScript.ValueLocation();
   3160            var varSym = new TypeScript.VariableSymbol((this.param).id.text, this.param.minChar, typeFlow.checker.locationInfo.unitIndex, exceptVar);
   3161            exceptVar.symbol = varSym;
   3162            exceptVar.typeLink = new TypeScript.TypeLink();
   3163            exceptVar.typeLink.type = typeFlow.anyType;
   3164            var thisFnc = typeFlow.thisFnc;
   3165            if(thisFnc && thisFnc.type) {
   3166                exceptVar.symbol.container = thisFnc.type.symbol;
   3167            } else {
   3168                exceptVar.symbol.container = null;
   3169            }
   3170            this.param.sym = exceptVar.symbol;
   3171            typeFlow.scope.enter(exceptVar.symbol.container, this.param, exceptVar.symbol, typeFlow.checker.errorReporter, false, false, false);
   3172            this.body = typeFlow.typeCheck(this.body);
   3173            if(typeFlow.checker.inProvisionalTypecheckMode()) {
   3174                var table = typeFlow.scope.getTable();
   3175                (table).secondaryTable.table[exceptVar.symbol.name] = undefined;
   3176            }
   3177            this.type = typeFlow.voidType;
   3178            typeFlow.scope = prevScope;
   3179            return this;
   3180        };
   3181        return Catch;
   3182    })(Statement);
   3183    TypeScript.Catch = Catch;    
   3184    var Finally = (function (_super) {
   3185        __extends(Finally, _super);
   3186        function Finally(body) {
   3187                _super.call(this, TypeScript.NodeType.Finally);
   3188            this.body = body;
   3189        }
   3190        Finally.prototype.emit = function (emitter, tokenId, startLine) {
   3191            emitter.emitParensAndCommentsInPlace(this, true);
   3192            emitter.recordSourceMappingStart(this);
   3193            emitter.writeToOutput("finally");
   3194            emitter.emitJavascript(this.body, TypeScript.TokenID.Finally, false);
   3195            emitter.recordSourceMappingEnd(this);
   3196            emitter.emitParensAndCommentsInPlace(this, false);
   3197        };
   3198        Finally.prototype.addToControlFlow = function (context) {
   3199            if(this.body) {
   3200                context.walk(this.body, this);
   3201            }
   3202            context.walker.options.goChildren = false;
   3203            context.noContinuation = false;
   3204        };
   3205        Finally.prototype.typeCheck = function (typeFlow) {
   3206            this.body = typeFlow.typeCheck(this.body);
   3207            return this;
   3208        };
   3209        return Finally;
   3210    })(Statement);
   3211    TypeScript.Finally = Finally;    
   3212    var Comment = (function (_super) {
   3213        __extends(Comment, _super);
   3214        function Comment(content, isBlockComment, endsLine) {
   3215                _super.call(this, TypeScript.NodeType.Comment);
   3216            this.content = content;
   3217            this.isBlockComment = isBlockComment;
   3218            this.endsLine = endsLine;
   3219            this.text = null;
   3220            this.docCommentText = null;
   3221        }
   3222        Comment.prototype.getText = function () {
   3223            if(this.text == null) {
   3224                if(this.isBlockComment) {
   3225                    this.text = this.content.split("\n");
   3226                    for(var i = 0; i < this.text.length; i++) {
   3227                        this.text[i] = this.text[i].replace(/^\s+|\s+$/g, '');
   3228                    }
   3229                } else {
   3230                    this.text = [
   3231                        (this.content.replace(/^\s+|\s+$/g, ''))
   3232                    ];
   3233                }
   3234            }
   3235            return this.text;
   3236        };
   3237        Comment.prototype.isDocComment = function () {
   3238            if(this.isBlockComment) {
   3239                return this.content.charAt(2) == "*";
   3240            }
   3241            return false;
   3242        };
   3243        Comment.prototype.getDocCommentText = function () {
   3244            if(this.docCommentText == null) {
   3245                this.docCommentText = Comment.cleanJSDocComment(this.content);
   3246            }
   3247            return this.docCommentText;
   3248        };
   3249        Comment.consumeLeadingSpace = function consumeLeadingSpace(line, startIndex, maxSpacesToRemove) {
   3250            var endIndex = line.length;
   3251            if(maxSpacesToRemove != undefined) {
   3252                endIndex = TypeScript.min(startIndex + maxSpacesToRemove, endIndex);
   3253            }
   3254            for(; startIndex < endIndex; startIndex++) {
   3255                var charCode = line.charCodeAt(startIndex);
   3256                if(charCode != TypeScript.LexCodeSpace && charCode != TypeScript.LexCodeTAB) {
   3257                    return startIndex;
   3258                }
   3259            }
   3260            if(endIndex != line.length) {
   3261                return endIndex;
   3262            }
   3263            return -1;
   3264        }
   3265        Comment.isSpaceChar = function isSpaceChar(line, index) {
   3266            var length = line.length;
   3267            if(index < length) {
   3268                var charCode = line.charCodeAt(index);
   3269                return charCode == TypeScript.LexCodeSpace || charCode == TypeScript.LexCodeTAB;
   3270            }
   3271            return index == length;
   3272        }
   3273        Comment.cleanDocCommentLine = function cleanDocCommentLine(line, jsDocStyleComment, jsDocLineSpaceToRemove) {
   3274            var nonSpaceIndex = Comment.consumeLeadingSpace(line, 0);
   3275            if(nonSpaceIndex != -1) {
   3276                var jsDocSpacesRemoved = nonSpaceIndex;
   3277                if(jsDocStyleComment && line.charAt(nonSpaceIndex) == '*') {
   3278                    var startIndex = nonSpaceIndex + 1;
   3279                    nonSpaceIndex = Comment.consumeLeadingSpace(line, startIndex, jsDocLineSpaceToRemove);
   3280                    if(nonSpaceIndex != -1) {
   3281                        jsDocSpacesRemoved = nonSpaceIndex - startIndex;
   3282                    } else {
   3283                        return null;
   3284                    }
   3285                }
   3286                return {
   3287                    minChar: nonSpaceIndex,
   3288                    limChar: line.charAt(line.length - 1) == "\r" ? line.length - 1 : line.length,
   3289                    jsDocSpacesRemoved: jsDocSpacesRemoved
   3290                };
   3291            }
   3292            return null;
   3293        }
   3294        Comment.cleanJSDocComment = function cleanJSDocComment(content, spacesToRemove) {
   3295            var docCommentLines = [];
   3296            content = content.replace("/**", "");
   3297            if(content.length >= 2 && content.charAt(content.length - 1) == "/" && content.charAt(content.length - 2) == "*") {
   3298                content = content.substring(0, content.length - 2);
   3299            }
   3300            var lines = content.split("\n");
   3301            var inParamTag = false;
   3302            for(var l = 0; l < lines.length; l++) {
   3303                var line = lines[l];
   3304                var cleanLinePos = Comment.cleanDocCommentLine(line, true, spacesToRemove);
   3305                if(!cleanLinePos) {
   3306                    continue;
   3307                }
   3308                var docCommentText = "";
   3309                var prevPos = cleanLinePos.minChar;
   3310                for(var i = line.indexOf("@", cleanLinePos.minChar); 0 <= i && i < cleanLinePos.limChar; i = line.indexOf("@", i + 1)) {
   3311                    var wasInParamtag = inParamTag;
   3312                    if(line.indexOf("param", i + 1) == i + 1 && Comment.isSpaceChar(line, i + 6)) {
   3313                        if(!wasInParamtag) {
   3314                            docCommentText += line.substring(prevPos, i);
   3315                        }
   3316                        prevPos = i;
   3317                        inParamTag = true;
   3318                    } else {
   3319                        if(wasInParamtag) {
   3320                            prevPos = i;
   3321                            inParamTag = false;
   3322                        }
   3323                    }
   3324                }
   3325                if(!inParamTag) {
   3326                    docCommentText += line.substring(prevPos, cleanLinePos.limChar);
   3327                }
   3328                var newCleanPos = Comment.cleanDocCommentLine(docCommentText, false);
   3329                if(newCleanPos) {
   3330                    if(spacesToRemove == undefined) {
   3331                        spacesToRemove = cleanLinePos.jsDocSpacesRemoved;
   3332                    }
   3333                    docCommentLines.push(docCommentText);
   3334                }
   3335            }
   3336            return docCommentLines.join("\n");
   3337        }
   3338        Comment.getDocCommentText = function getDocCommentText(comments) {
   3339            var docCommentText = [];
   3340            for(var c = 0; c < comments.length; c++) {
   3341                var commentText = comments[c].getDocCommentText();
   3342                if(commentText != "") {
   3343                    docCommentText.push(commentText);
   3344                }
   3345            }
   3346            return docCommentText.join("\n");
   3347        }
   3348        Comment.getParameterDocCommentText = function getParameterDocCommentText(param, fncDocComments) {
   3349            if(fncDocComments.length == 0 || !fncDocComments[0].isBlockComment) {
   3350                return "";
   3351            }
   3352            for(var i = 0; i < fncDocComments.length; i++) {
   3353                var commentContents = fncDocComments[i].content;
   3354                for(var j = commentContents.indexOf("@param", 0); 0 <= j; j = commentContents.indexOf("@param", j)) {
   3355                    j += 6;
   3356                    if(!Comment.isSpaceChar(commentContents, j)) {
   3357                        continue;
   3358                    }
   3359                    j = Comment.consumeLeadingSpace(commentContents, j);
   3360                    if(j == -1) {
   3361                        break;
   3362                    }
   3363                    if(commentContents.charCodeAt(j) == TypeScript.LexCodeLC) {
   3364                        j++;
   3365                        var charCode = 0;
   3366                        for(var curlies = 1; j < commentContents.length; j++) {
   3367                            charCode = commentContents.charCodeAt(j);
   3368                            if(charCode == TypeScript.LexCodeLC) {
   3369                                curlies++;
   3370                                continue;
   3371                            }
   3372                            if(charCode == TypeScript.LexCodeRC) {
   3373                                curlies--;
   3374                                if(curlies == 0) {
   3375                                    break;
   3376                                } else {
   3377                                    continue;
   3378                                }
   3379                            }
   3380                            if(charCode == TypeScript.LexCodeAtSign) {
   3381                                break;
   3382                            }
   3383                        }
   3384                        if(j == commentContents.length) {
   3385                            break;
   3386                        }
   3387                        if(charCode == TypeScript.LexCodeAtSign) {
   3388                            continue;
   3389                        }
   3390                        j = Comment.consumeLeadingSpace(commentContents, j + 1);
   3391                        if(j == -1) {
   3392                            break;
   3393                        }
   3394                    }
   3395                    if(param != commentContents.substr(j, param.length) || !Comment.isSpaceChar(commentContents, j + param.length)) {
   3396                        continue;
   3397                    }
   3398                    j = Comment.consumeLeadingSpace(commentContents, j + param.length);
   3399                    if(j == -1) {
   3400                        return "";
   3401                    }
   3402                    var endOfParam = commentContents.indexOf("@", j);
   3403                    var paramHelpString = commentContents.substring(j, endOfParam < 0 ? commentContents.length : endOfParam);
   3404                    var paramSpacesToRemove = undefined;
   3405                    var paramLineIndex = commentContents.substring(0, j).lastIndexOf("\n") + 1;
   3406                    if(paramLineIndex != 0) {
   3407                        if(paramLineIndex < j && commentContents.charAt(paramLineIndex + 1) == "\r") {
   3408                            paramLineIndex++;
   3409                        }
   3410                    }
   3411                    var startSpaceRemovalIndex = Comment.consumeLeadingSpace(commentContents, paramLineIndex);
   3412                    if(startSpaceRemovalIndex != j && commentContents.charAt(startSpaceRemovalIndex) == "*") {
   3413                        paramSpacesToRemove = j - startSpaceRemovalIndex - 1;
   3414                    }
   3415                    return Comment.cleanJSDocComment(paramHelpString, paramSpacesToRemove);
   3416                }
   3417            }
   3418            return "";
   3419        }
   3420        Comment.getDocCommentTextOfSignatures = function getDocCommentTextOfSignatures(signatures) {
   3421            var comments = [];
   3422            for(var i = 0; i < signatures.length; i++) {
   3423                var signatureDocComment = TypeScript.Comment.getDocCommentText(signatures[i].declAST.getDocComments());
   3424                if(signatureDocComment != "") {
   3425                    comments.push(signatureDocComment);
   3426                }
   3427            }
   3428            return comments.join("\n");
   3429        }
   3430        return Comment;
   3431    })(AST);
   3432    TypeScript.Comment = Comment;    
   3433    var DebuggerStatement = (function (_super) {
   3434        __extends(DebuggerStatement, _super);
   3435        function DebuggerStatement() {
   3436                _super.call(this, TypeScript.NodeType.Debugger);
   3437        }
   3438        DebuggerStatement.prototype.emit = function (emitter, tokenId, startLine) {
   3439            emitter.emitParensAndCommentsInPlace(this, true);
   3440            emitter.recordSourceMappingStart(this);
   3441            emitter.writeLineToOutput("debugger;");
   3442            emitter.recordSourceMappingEnd(this);
   3443            emitter.emitParensAndCommentsInPlace(this, false);
   3444        };
   3445        return DebuggerStatement;
   3446    })(Statement);
   3447    TypeScript.DebuggerStatement = DebuggerStatement;    
   3448 })(TypeScript || (TypeScript = {}));
   3449 var TypeScript;
   3450 (function (TypeScript) {
   3451    var AstWalkOptions = (function () {
   3452        function AstWalkOptions() {
   3453            this.goChildren = true;
   3454            this.goNextSibling = true;
   3455            this.reverseSiblings = false;
   3456        }
   3457        AstWalkOptions.prototype.stopWalk = function (stop) {
   3458            if (typeof stop === "undefined") { stop = true; }
   3459            this.goChildren = !stop;
   3460            this.goNextSibling = !stop;
   3461        };
   3462        return AstWalkOptions;
   3463    })();
   3464    TypeScript.AstWalkOptions = AstWalkOptions;    
   3465    var AstWalker = (function () {
   3466        function AstWalker(childrenWalkers, pre, post, options, state) {
   3467            this.childrenWalkers = childrenWalkers;
   3468            this.pre = pre;
   3469            this.post = post;
   3470            this.options = options;
   3471            this.state = state;
   3472        }
   3473        AstWalker.prototype.walk = function (ast, parent) {
   3474            var preAst = this.pre(ast, parent, this);
   3475            if(preAst === undefined) {
   3476                preAst = ast;
   3477            }
   3478            if(this.options.goChildren) {
   3479                var svGoSib = this.options.goNextSibling;
   3480                this.options.goNextSibling = true;
   3481                this.childrenWalkers[ast.nodeType](ast, parent, this);
   3482                this.options.goNextSibling = svGoSib;
   3483            } else {
   3484                this.options.goChildren = true;
   3485            }
   3486            if(this.post) {
   3487                var postAst = this.post(preAst, parent, this);
   3488                if(postAst === undefined) {
   3489                    postAst = preAst;
   3490                }
   3491                return postAst;
   3492            } else {
   3493                return preAst;
   3494            }
   3495        };
   3496        return AstWalker;
   3497    })();    
   3498    var AstWalkerFactory = (function () {
   3499        function AstWalkerFactory() {
   3500            this.childrenWalkers = [];
   3501            this.initChildrenWalkers();
   3502        }
   3503        AstWalkerFactory.prototype.walk = function (ast, pre, post, options, state) {
   3504            return this.getWalker(pre, post, options, state).walk(ast, null);
   3505        };
   3506        AstWalkerFactory.prototype.getWalker = function (pre, post, options, state) {
   3507            return this.getSlowWalker(pre, post, options, state);
   3508        };
   3509        AstWalkerFactory.prototype.getSlowWalker = function (pre, post, options, state) {
   3510            if(!options) {
   3511                options = new AstWalkOptions();
   3512            }
   3513            return new AstWalker(this.childrenWalkers, pre, post, options, state);
   3514        };
   3515        AstWalkerFactory.prototype.initChildrenWalkers = function () {
   3516            this.childrenWalkers[TypeScript.NodeType.None] = ChildrenWalkers.walkNone;
   3517            this.childrenWalkers[TypeScript.NodeType.Empty] = ChildrenWalkers.walkNone;
   3518            this.childrenWalkers[TypeScript.NodeType.EmptyExpr] = ChildrenWalkers.walkNone;
   3519            this.childrenWalkers[TypeScript.NodeType.True] = ChildrenWalkers.walkNone;
   3520            this.childrenWalkers[TypeScript.NodeType.False] = ChildrenWalkers.walkNone;
   3521            this.childrenWalkers[TypeScript.NodeType.This] = ChildrenWalkers.walkNone;
   3522            this.childrenWalkers[TypeScript.NodeType.Super] = ChildrenWalkers.walkNone;
   3523            this.childrenWalkers[TypeScript.NodeType.QString] = ChildrenWalkers.walkNone;
   3524            this.childrenWalkers[TypeScript.NodeType.Regex] = ChildrenWalkers.walkNone;
   3525            this.childrenWalkers[TypeScript.NodeType.Null] = ChildrenWalkers.walkNone;
   3526            this.childrenWalkers[TypeScript.NodeType.ArrayLit] = ChildrenWalkers.walkUnaryExpressionChildren;
   3527            this.childrenWalkers[TypeScript.NodeType.ObjectLit] = ChildrenWalkers.walkUnaryExpressionChildren;
   3528            this.childrenWalkers[TypeScript.NodeType.Void] = ChildrenWalkers.walkUnaryExpressionChildren;
   3529            this.childrenWalkers[TypeScript.NodeType.Comma] = ChildrenWalkers.walkBinaryExpressionChildren;
   3530            this.childrenWalkers[TypeScript.NodeType.Pos] = ChildrenWalkers.walkUnaryExpressionChildren;
   3531            this.childrenWalkers[TypeScript.NodeType.Neg] = ChildrenWalkers.walkUnaryExpressionChildren;
   3532            this.childrenWalkers[TypeScript.NodeType.Delete] = ChildrenWalkers.walkUnaryExpressionChildren;
   3533            this.childrenWalkers[TypeScript.NodeType.Await] = ChildrenWalkers.walkUnaryExpressionChildren;
   3534            this.childrenWalkers[TypeScript.NodeType.In] = ChildrenWalkers.walkBinaryExpressionChildren;
   3535            this.childrenWalkers[TypeScript.NodeType.Dot] = ChildrenWalkers.walkBinaryExpressionChildren;
   3536            this.childrenWalkers[TypeScript.NodeType.From] = ChildrenWalkers.walkBinaryExpressionChildren;
   3537            this.childrenWalkers[TypeScript.NodeType.Is] = ChildrenWalkers.walkBinaryExpressionChildren;
   3538            this.childrenWalkers[TypeScript.NodeType.InstOf] = ChildrenWalkers.walkBinaryExpressionChildren;
   3539            this.childrenWalkers[TypeScript.NodeType.Typeof] = ChildrenWalkers.walkUnaryExpressionChildren;
   3540            this.childrenWalkers[TypeScript.NodeType.NumberLit] = ChildrenWalkers.walkNone;
   3541            this.childrenWalkers[TypeScript.NodeType.Name] = ChildrenWalkers.walkNone;
   3542            this.childrenWalkers[TypeScript.NodeType.TypeRef] = ChildrenWalkers.walkTypeReferenceChildren;
   3543            this.childrenWalkers[TypeScript.NodeType.Index] = ChildrenWalkers.walkBinaryExpressionChildren;
   3544            this.childrenWalkers[TypeScript.NodeType.Call] = ChildrenWalkers.walkCallExpressionChildren;
   3545            this.childrenWalkers[TypeScript.NodeType.New] = ChildrenWalkers.walkCallExpressionChildren;
   3546            this.childrenWalkers[TypeScript.NodeType.Asg] = ChildrenWalkers.walkBinaryExpressionChildren;
   3547            this.childrenWalkers[TypeScript.NodeType.AsgAdd] = ChildrenWalkers.walkBinaryExpressionChildren;
   3548            this.childrenWalkers[TypeScript.NodeType.AsgSub] = ChildrenWalkers.walkBinaryExpressionChildren;
   3549            this.childrenWalkers[TypeScript.NodeType.AsgDiv] = ChildrenWalkers.walkBinaryExpressionChildren;
   3550            this.childrenWalkers[TypeScript.NodeType.AsgMul] = ChildrenWalkers.walkBinaryExpressionChildren;
   3551            this.childrenWalkers[TypeScript.NodeType.AsgMod] = ChildrenWalkers.walkBinaryExpressionChildren;
   3552            this.childrenWalkers[TypeScript.NodeType.AsgAnd] = ChildrenWalkers.walkBinaryExpressionChildren;
   3553            this.childrenWalkers[TypeScript.NodeType.AsgXor] = ChildrenWalkers.walkBinaryExpressionChildren;
   3554            this.childrenWalkers[TypeScript.NodeType.AsgOr] = ChildrenWalkers.walkBinaryExpressionChildren;
   3555            this.childrenWalkers[TypeScript.NodeType.AsgLsh] = ChildrenWalkers.walkBinaryExpressionChildren;
   3556            this.childrenWalkers[TypeScript.NodeType.AsgRsh] = ChildrenWalkers.walkBinaryExpressionChildren;
   3557            this.childrenWalkers[TypeScript.NodeType.AsgRs2] = ChildrenWalkers.walkBinaryExpressionChildren;
   3558            this.childrenWalkers[TypeScript.NodeType.ConditionalExpression] = ChildrenWalkers.walkTrinaryExpressionChildren;
   3559            this.childrenWalkers[TypeScript.NodeType.LogOr] = ChildrenWalkers.walkBinaryExpressionChildren;
   3560            this.childrenWalkers[TypeScript.NodeType.LogAnd] = ChildrenWalkers.walkBinaryExpressionChildren;
   3561            this.childrenWalkers[TypeScript.NodeType.Or] = ChildrenWalkers.walkBinaryExpressionChildren;
   3562            this.childrenWalkers[TypeScript.NodeType.Xor] = ChildrenWalkers.walkBinaryExpressionChildren;
   3563            this.childrenWalkers[TypeScript.NodeType.And] = ChildrenWalkers.walkBinaryExpressionChildren;
   3564            this.childrenWalkers[TypeScript.NodeType.Eq] = ChildrenWalkers.walkBinaryExpressionChildren;
   3565            this.childrenWalkers[TypeScript.NodeType.Ne] = ChildrenWalkers.walkBinaryExpressionChildren;
   3566            this.childrenWalkers[TypeScript.NodeType.Eqv] = ChildrenWalkers.walkBinaryExpressionChildren;
   3567            this.childrenWalkers[TypeScript.NodeType.NEqv] = ChildrenWalkers.walkBinaryExpressionChildren;
   3568            this.childrenWalkers[TypeScript.NodeType.Lt] = ChildrenWalkers.walkBinaryExpressionChildren;
   3569            this.childrenWalkers[TypeScript.NodeType.Le] = ChildrenWalkers.walkBinaryExpressionChildren;
   3570            this.childrenWalkers[TypeScript.NodeType.Gt] = ChildrenWalkers.walkBinaryExpressionChildren;
   3571            this.childrenWalkers[TypeScript.NodeType.Ge] = ChildrenWalkers.walkBinaryExpressionChildren;
   3572            this.childrenWalkers[TypeScript.NodeType.Add] = ChildrenWalkers.walkBinaryExpressionChildren;
   3573            this.childrenWalkers[TypeScript.NodeType.Sub] = ChildrenWalkers.walkBinaryExpressionChildren;
   3574            this.childrenWalkers[TypeScript.NodeType.Mul] = ChildrenWalkers.walkBinaryExpressionChildren;
   3575            this.childrenWalkers[TypeScript.NodeType.Div] = ChildrenWalkers.walkBinaryExpressionChildren;
   3576            this.childrenWalkers[TypeScript.NodeType.Mod] = ChildrenWalkers.walkBinaryExpressionChildren;
   3577            this.childrenWalkers[TypeScript.NodeType.Lsh] = ChildrenWalkers.walkBinaryExpressionChildren;
   3578            this.childrenWalkers[TypeScript.NodeType.Rsh] = ChildrenWalkers.walkBinaryExpressionChildren;
   3579            this.childrenWalkers[TypeScript.NodeType.Rs2] = ChildrenWalkers.walkBinaryExpressionChildren;
   3580            this.childrenWalkers[TypeScript.NodeType.Not] = ChildrenWalkers.walkUnaryExpressionChildren;
   3581            this.childrenWalkers[TypeScript.NodeType.LogNot] = ChildrenWalkers.walkUnaryExpressionChildren;
   3582            this.childrenWalkers[TypeScript.NodeType.IncPre] = ChildrenWalkers.walkUnaryExpressionChildren;
   3583            this.childrenWalkers[TypeScript.NodeType.DecPre] = ChildrenWalkers.walkUnaryExpressionChildren;
   3584            this.childrenWalkers[TypeScript.NodeType.IncPost] = ChildrenWalkers.walkUnaryExpressionChildren;
   3585            this.childrenWalkers[TypeScript.NodeType.DecPost] = ChildrenWalkers.walkUnaryExpressionChildren;
   3586            this.childrenWalkers[TypeScript.NodeType.TypeAssertion] = ChildrenWalkers.walkUnaryExpressionChildren;
   3587            this.childrenWalkers[TypeScript.NodeType.FuncDecl] = ChildrenWalkers.walkFuncDeclChildren;
   3588            this.childrenWalkers[TypeScript.NodeType.Member] = ChildrenWalkers.walkBinaryExpressionChildren;
   3589            this.childrenWalkers[TypeScript.NodeType.VarDecl] = ChildrenWalkers.walkBoundDeclChildren;
   3590            this.childrenWalkers[TypeScript.NodeType.ArgDecl] = ChildrenWalkers.walkBoundDeclChildren;
   3591            this.childrenWalkers[TypeScript.NodeType.Return] = ChildrenWalkers.walkReturnStatementChildren;
   3592            this.childrenWalkers[TypeScript.NodeType.Break] = ChildrenWalkers.walkNone;
   3593            this.childrenWalkers[TypeScript.NodeType.Continue] = ChildrenWalkers.walkNone;
   3594            this.childrenWalkers[TypeScript.NodeType.Throw] = ChildrenWalkers.walkUnaryExpressionChildren;
   3595            this.childrenWalkers[TypeScript.NodeType.For] = ChildrenWalkers.walkForStatementChildren;
   3596            this.childrenWalkers[TypeScript.NodeType.ForIn] = ChildrenWalkers.walkForInStatementChildren;
   3597            this.childrenWalkers[TypeScript.NodeType.If] = ChildrenWalkers.walkIfStatementChildren;
   3598            this.childrenWalkers[TypeScript.NodeType.While] = ChildrenWalkers.walkWhileStatementChildren;
   3599            this.childrenWalkers[TypeScript.NodeType.DoWhile] = ChildrenWalkers.walkDoWhileStatementChildren;
   3600            this.childrenWalkers[TypeScript.NodeType.Block] = ChildrenWalkers.walkBlockChildren;
   3601            this.childrenWalkers[TypeScript.NodeType.Case] = ChildrenWalkers.walkCaseStatementChildren;
   3602            this.childrenWalkers[TypeScript.NodeType.Switch] = ChildrenWalkers.walkSwitchStatementChildren;
   3603            this.childrenWalkers[TypeScript.NodeType.Try] = ChildrenWalkers.walkTryChildren;
   3604            this.childrenWalkers[TypeScript.NodeType.TryCatch] = ChildrenWalkers.walkTryCatchChildren;
   3605            this.childrenWalkers[TypeScript.NodeType.TryFinally] = ChildrenWalkers.walkTryFinallyChildren;
   3606            this.childrenWalkers[TypeScript.NodeType.Finally] = ChildrenWalkers.walkFinallyChildren;
   3607            this.childrenWalkers[TypeScript.NodeType.Catch] = ChildrenWalkers.walkCatchChildren;
   3608            this.childrenWalkers[TypeScript.NodeType.List] = ChildrenWalkers.walkListChildren;
   3609            this.childrenWalkers[TypeScript.NodeType.Script] = ChildrenWalkers.walkScriptChildren;
   3610            this.childrenWalkers[TypeScript.NodeType.ClassDeclaration] = ChildrenWalkers.walkClassDeclChildren;
   3611            this.childrenWalkers[TypeScript.NodeType.InterfaceDeclaration] = ChildrenWalkers.walkTypeDeclChildren;
   3612            this.childrenWalkers[TypeScript.NodeType.ModuleDeclaration] = ChildrenWalkers.walkModuleDeclChildren;
   3613            this.childrenWalkers[TypeScript.NodeType.ImportDeclaration] = ChildrenWalkers.walkImportDeclChildren;
   3614            this.childrenWalkers[TypeScript.NodeType.With] = ChildrenWalkers.walkWithStatementChildren;
   3615            this.childrenWalkers[TypeScript.NodeType.Label] = ChildrenWalkers.walkLabelChildren;
   3616            this.childrenWalkers[TypeScript.NodeType.LabeledStatement] = ChildrenWalkers.walkLabeledStatementChildren;
   3617            this.childrenWalkers[TypeScript.NodeType.EBStart] = ChildrenWalkers.walkNone;
   3618            this.childrenWalkers[TypeScript.NodeType.GotoEB] = ChildrenWalkers.walkNone;
   3619            this.childrenWalkers[TypeScript.NodeType.EndCode] = ChildrenWalkers.walkNone;
   3620            this.childrenWalkers[TypeScript.NodeType.Error] = ChildrenWalkers.walkNone;
   3621            this.childrenWalkers[TypeScript.NodeType.Comment] = ChildrenWalkers.walkNone;
   3622            this.childrenWalkers[TypeScript.NodeType.Debugger] = ChildrenWalkers.walkNone;
   3623            for(var e in (TypeScript.NodeType)._map) {
   3624                if((this.childrenWalkers)[e] === undefined) {
   3625                    throw new Error("initWalkers function is not up to date with enum content!");
   3626                }
   3627            }
   3628        };
   3629        return AstWalkerFactory;
   3630    })();
   3631    TypeScript.AstWalkerFactory = AstWalkerFactory;    
   3632    var globalAstWalkerFactory;
   3633    function getAstWalkerFactory() {
   3634        if(!globalAstWalkerFactory) {
   3635            globalAstWalkerFactory = new AstWalkerFactory();
   3636        }
   3637        return globalAstWalkerFactory;
   3638    }
   3639    TypeScript.getAstWalkerFactory = getAstWalkerFactory;
   3640    var ChildrenWalkers;
   3641    (function (ChildrenWalkers) {
   3642        function walkNone(preAst, parent, walker) {
   3643        }
   3644        ChildrenWalkers.walkNone = walkNone;
   3645        function walkListChildren(preAst, parent, walker) {
   3646            var len = preAst.members.length;
   3647            if(walker.options.reverseSiblings) {
   3648                for(var i = len - 1; i >= 0; i--) {
   3649                    if(walker.options.goNextSibling) {
   3650                        preAst.members[i] = walker.walk(preAst.members[i], preAst);
   3651                    }
   3652                }
   3653            } else {
   3654                for(var i = 0; i < len; i++) {
   3655                    if(walker.options.goNextSibling) {
   3656                        preAst.members[i] = walker.walk(preAst.members[i], preAst);
   3657                    }
   3658                }
   3659            }
   3660        }
   3661        ChildrenWalkers.walkListChildren = walkListChildren;
   3662        function walkUnaryExpressionChildren(preAst, parent, walker) {
   3663            if(preAst.castTerm) {
   3664                preAst.castTerm = walker.walk(preAst.castTerm, preAst);
   3665            }
   3666            if(preAst.operand) {
   3667                preAst.operand = walker.walk(preAst.operand, preAst);
   3668            }
   3669        }
   3670        ChildrenWalkers.walkUnaryExpressionChildren = walkUnaryExpressionChildren;
   3671        function walkBinaryExpressionChildren(preAst, parent, walker) {
   3672            if(walker.options.reverseSiblings) {
   3673                if(preAst.operand2) {
   3674                    preAst.operand2 = walker.walk(preAst.operand2, preAst);
   3675                }
   3676                if((preAst.operand1) && (walker.options.goNextSibling)) {
   3677                    preAst.operand1 = walker.walk(preAst.operand1, preAst);
   3678                }
   3679            } else {
   3680                if(preAst.operand1) {
   3681                    preAst.operand1 = walker.walk(preAst.operand1, preAst);
   3682                }
   3683                if((preAst.operand2) && (walker.options.goNextSibling)) {
   3684                    preAst.operand2 = walker.walk(preAst.operand2, preAst);
   3685                }
   3686            }
   3687        }
   3688        ChildrenWalkers.walkBinaryExpressionChildren = walkBinaryExpressionChildren;
   3689        function walkTypeReferenceChildren(preAst, parent, walker) {
   3690            if(preAst.term) {
   3691                preAst.term = walker.walk(preAst.term, preAst);
   3692            }
   3693        }
   3694        ChildrenWalkers.walkTypeReferenceChildren = walkTypeReferenceChildren;
   3695        function walkCallExpressionChildren(preAst, parent, walker) {
   3696            if(!walker.options.reverseSiblings) {
   3697                preAst.target = walker.walk(preAst.target, preAst);
   3698            }
   3699            if(preAst.arguments && (walker.options.goNextSibling)) {
   3700                preAst.arguments = walker.walk(preAst.arguments, preAst);
   3701            }
   3702            if((walker.options.reverseSiblings) && (walker.options.goNextSibling)) {
   3703                preAst.target = walker.walk(preAst.target, preAst);
   3704            }
   3705        }
   3706        ChildrenWalkers.walkCallExpressionChildren = walkCallExpressionChildren;
   3707        function walkTrinaryExpressionChildren(preAst, parent, walker) {
   3708            if(preAst.operand1) {
   3709                preAst.operand1 = walker.walk(preAst.operand1, preAst);
   3710            }
   3711            if(preAst.operand2 && (walker.options.goNextSibling)) {
   3712                preAst.operand2 = walker.walk(preAst.operand2, preAst);
   3713            }
   3714            if(preAst.operand3 && (walker.options.goNextSibling)) {
   3715                preAst.operand3 = walker.walk(preAst.operand3, preAst);
   3716            }
   3717        }
   3718        ChildrenWalkers.walkTrinaryExpressionChildren = walkTrinaryExpressionChildren;
   3719        function walkFuncDeclChildren(preAst, parent, walker) {
   3720            if(preAst.name) {
   3721                preAst.name = walker.walk(preAst.name, preAst);
   3722            }
   3723            if(preAst.arguments && (preAst.arguments.members.length > 0) && (walker.options.goNextSibling)) {
   3724                preAst.arguments = walker.walk(preAst.arguments, preAst);
   3725            }
   3726            if(preAst.returnTypeAnnotation && (walker.options.goNextSibling)) {
   3727                preAst.returnTypeAnnotation = walker.walk(preAst.returnTypeAnnotation, preAst);
   3728            }
   3729            if(preAst.bod && (preAst.bod.members.length > 0) && (walker.options.goNextSibling)) {
   3730                preAst.bod = walker.walk(preAst.bod, preAst);
   3731            }
   3732        }
   3733        ChildrenWalkers.walkFuncDeclChildren = walkFuncDeclChildren;
   3734        function walkBoundDeclChildren(preAst, parent, walker) {
   3735            if(preAst.id) {
   3736                preAst.id = walker.walk(preAst.id, preAst);
   3737            }
   3738            if(preAst.init) {
   3739                preAst.init = walker.walk(preAst.init, preAst);
   3740            }
   3741            if((preAst.typeExpr) && (walker.options.goNextSibling)) {
   3742                preAst.typeExpr = walker.walk(preAst.typeExpr, preAst);
   3743            }
   3744        }
   3745        ChildrenWalkers.walkBoundDeclChildren = walkBoundDeclChildren;
   3746        function walkReturnStatementChildren(preAst, parent, walker) {
   3747            if(preAst.returnExpression) {
   3748                preAst.returnExpression = walker.walk(preAst.returnExpression, preAst);
   3749            }
   3750        }
   3751        ChildrenWalkers.walkReturnStatementChildren = walkReturnStatementChildren;
   3752        function walkForStatementChildren(preAst, parent, walker) {
   3753            if(preAst.init) {
   3754                preAst.init = walker.walk(preAst.init, preAst);
   3755            }
   3756            if(preAst.cond && walker.options.goNextSibling) {
   3757                preAst.cond = walker.walk(preAst.cond, preAst);
   3758            }
   3759            if(preAst.incr && walker.options.goNextSibling) {
   3760                preAst.incr = walker.walk(preAst.incr, preAst);
   3761            }
   3762            if(preAst.body && walker.options.goNextSibling) {
   3763                preAst.body = walker.walk(preAst.body, preAst);
   3764            }
   3765        }
   3766        ChildrenWalkers.walkForStatementChildren = walkForStatementChildren;
   3767        function walkForInStatementChildren(preAst, parent, walker) {
   3768            preAst.lval = walker.walk(preAst.lval, preAst);
   3769            if(walker.options.goNextSibling) {
   3770                preAst.obj = walker.walk(preAst.obj, preAst);
   3771            }
   3772            if(preAst.body && (walker.options.goNextSibling)) {
   3773                preAst.body = walker.walk(preAst.body, preAst);
   3774            }
   3775        }
   3776        ChildrenWalkers.walkForInStatementChildren = walkForInStatementChildren;
   3777        function walkIfStatementChildren(preAst, parent, walker) {
   3778            preAst.cond = walker.walk(preAst.cond, preAst);
   3779            if(preAst.thenBod && (walker.options.goNextSibling)) {
   3780                preAst.thenBod = walker.walk(preAst.thenBod, preAst);
   3781            }
   3782            if(preAst.elseBod && (walker.options.goNextSibling)) {
   3783                preAst.elseBod = walker.walk(preAst.elseBod, preAst);
   3784            }
   3785        }
   3786        ChildrenWalkers.walkIfStatementChildren = walkIfStatementChildren;
   3787        function walkWhileStatementChildren(preAst, parent, walker) {
   3788            preAst.cond = walker.walk(preAst.cond, preAst);
   3789            if(preAst.body && (walker.options.goNextSibling)) {
   3790                preAst.body = walker.walk(preAst.body, preAst);
   3791            }
   3792        }
   3793        ChildrenWalkers.walkWhileStatementChildren = walkWhileStatementChildren;
   3794        function walkDoWhileStatementChildren(preAst, parent, walker) {
   3795            preAst.cond = walker.walk(preAst.cond, preAst);
   3796            if(preAst.body && (walker.options.goNextSibling)) {
   3797                preAst.body = walker.walk(preAst.body, preAst);
   3798            }
   3799        }
   3800        ChildrenWalkers.walkDoWhileStatementChildren = walkDoWhileStatementChildren;
   3801        function walkBlockChildren(preAst, parent, walker) {
   3802            if(preAst.statements) {
   3803                preAst.statements = walker.walk(preAst.statements, preAst);
   3804            }
   3805        }
   3806        ChildrenWalkers.walkBlockChildren = walkBlockChildren;
   3807        function walkCaseStatementChildren(preAst, parent, walker) {
   3808            if(preAst.expr) {
   3809                preAst.expr = walker.walk(preAst.expr, preAst);
   3810            }
   3811            if(preAst.body && walker.options.goNextSibling) {
   3812                preAst.body = walker.walk(preAst.body, preAst);
   3813            }
   3814        }
   3815        ChildrenWalkers.walkCaseStatementChildren = walkCaseStatementChildren;
   3816        function walkSwitchStatementChildren(preAst, parent, walker) {
   3817            if(preAst.val) {
   3818                preAst.val = walker.walk(preAst.val, preAst);
   3819            }
   3820            if((preAst.caseList) && walker.options.goNextSibling) {
   3821                preAst.caseList = walker.walk(preAst.caseList, preAst);
   3822            }
   3823        }
   3824        ChildrenWalkers.walkSwitchStatementChildren = walkSwitchStatementChildren;
   3825        function walkTryChildren(preAst, parent, walker) {
   3826            if(preAst.body) {
   3827                preAst.body = walker.walk(preAst.body, preAst);
   3828            }
   3829        }
   3830        ChildrenWalkers.walkTryChildren = walkTryChildren;
   3831        function walkTryCatchChildren(preAst, parent, walker) {
   3832            if(preAst.tryNode) {
   3833                preAst.tryNode = walker.walk(preAst.tryNode, preAst);
   3834            }
   3835            if((preAst.catchNode) && walker.options.goNextSibling) {
   3836                preAst.catchNode = walker.walk(preAst.catchNode, preAst);
   3837            }
   3838        }
   3839        ChildrenWalkers.walkTryCatchChildren = walkTryCatchChildren;
   3840        function walkTryFinallyChildren(preAst, parent, walker) {
   3841            if(preAst.tryNode) {
   3842                preAst.tryNode = walker.walk(preAst.tryNode, preAst);
   3843            }
   3844            if(preAst.finallyNode && walker.options.goNextSibling) {
   3845                preAst.finallyNode = walker.walk(preAst.finallyNode, preAst);
   3846            }
   3847        }
   3848        ChildrenWalkers.walkTryFinallyChildren = walkTryFinallyChildren;
   3849        function walkFinallyChildren(preAst, parent, walker) {
   3850            if(preAst.body) {
   3851                preAst.body = walker.walk(preAst.body, preAst);
   3852            }
   3853        }
   3854        ChildrenWalkers.walkFinallyChildren = walkFinallyChildren;
   3855        function walkCatchChildren(preAst, parent, walker) {
   3856            if(preAst.param) {
   3857                preAst.param = walker.walk(preAst.param, preAst);
   3858            }
   3859            if((preAst.body) && walker.options.goNextSibling) {
   3860                preAst.body = walker.walk(preAst.body, preAst);
   3861            }
   3862        }
   3863        ChildrenWalkers.walkCatchChildren = walkCatchChildren;
   3864        function walkRecordChildren(preAst, parent, walker) {
   3865            preAst.name = walker.walk(preAst.name, preAst);
   3866            if(walker.options.goNextSibling && preAst.members) {
   3867                preAst.members = walker.walk(preAst.members, preAst);
   3868            }
   3869        }
   3870        ChildrenWalkers.walkRecordChildren = walkRecordChildren;
   3871        function walkNamedTypeChildren(preAst, parent, walker) {
   3872            walkRecordChildren(preAst, parent, walker);
   3873        }
   3874        ChildrenWalkers.walkNamedTypeChildren = walkNamedTypeChildren;
   3875        function walkClassDeclChildren(preAst, parent, walker) {
   3876            walkNamedTypeChildren(preAst, parent, walker);
   3877            if(walker.options.goNextSibling && preAst.extendsList) {
   3878                preAst.extendsList = walker.walk(preAst.extendsList, preAst);
   3879            }
   3880            if(walker.options.goNextSibling && preAst.implementsList) {
   3881                preAst.implementsList = walker.walk(preAst.implementsList, preAst);
   3882            }
   3883        }
   3884        ChildrenWalkers.walkClassDeclChildren = walkClassDeclChildren;
   3885        function walkScriptChildren(preAst, parent, walker) {
   3886            if(preAst.bod) {
   3887                preAst.bod = walker.walk(preAst.bod, preAst);
   3888            }
   3889        }
   3890        ChildrenWalkers.walkScriptChildren = walkScriptChildren;
   3891        function walkTypeDeclChildren(preAst, parent, walker) {
   3892            walkNamedTypeChildren(preAst, parent, walker);
   3893            if(walker.options.goNextSibling && preAst.extendsList) {
   3894                preAst.extendsList = walker.walk(preAst.extendsList, preAst);
   3895            }
   3896            if(walker.options.goNextSibling && preAst.implementsList) {
   3897                preAst.implementsList = walker.walk(preAst.implementsList, preAst);
   3898            }
   3899        }
   3900        ChildrenWalkers.walkTypeDeclChildren = walkTypeDeclChildren;
   3901        function walkModuleDeclChildren(preAst, parent, walker) {
   3902            walkRecordChildren(preAst, parent, walker);
   3903        }
   3904        ChildrenWalkers.walkModuleDeclChildren = walkModuleDeclChildren;
   3905        function walkImportDeclChildren(preAst, parent, walker) {
   3906            if(preAst.id) {
   3907                preAst.id = walker.walk(preAst.id, preAst);
   3908            }
   3909            if(preAst.alias) {
   3910                preAst.alias = walker.walk(preAst.alias, preAst);
   3911            }
   3912        }
   3913        ChildrenWalkers.walkImportDeclChildren = walkImportDeclChildren;
   3914        function walkWithStatementChildren(preAst, parent, walker) {
   3915            if(preAst.expr) {
   3916                preAst.expr = walker.walk(preAst.expr, preAst);
   3917            }
   3918            if(preAst.body && walker.options.goNextSibling) {
   3919                preAst.body = walker.walk(preAst.body, preAst);
   3920            }
   3921        }
   3922        ChildrenWalkers.walkWithStatementChildren = walkWithStatementChildren;
   3923        function walkLabelChildren(preAst, parent, walker) {
   3924        }
   3925        ChildrenWalkers.walkLabelChildren = walkLabelChildren;
   3926        function walkLabeledStatementChildren(preAst, parent, walker) {
   3927            preAst.labels = walker.walk(preAst.labels, preAst);
   3928            if(walker.options.goNextSibling) {
   3929                preAst.stmt = walker.walk(preAst.stmt, preAst);
   3930            }
   3931        }
   3932        ChildrenWalkers.walkLabeledStatementChildren = walkLabeledStatementChildren;
   3933    })(ChildrenWalkers || (ChildrenWalkers = {}));
   3934 })(TypeScript || (TypeScript = {}));
   3935 var TypeScript;
   3936 (function (TypeScript) {
   3937    (function (AstWalkerWithDetailCallback) {
   3938        function walk(script, callback) {
   3939            var pre = function (cur, parent) {
   3940                walker.options.goChildren = AstWalkerCallback(true, cur, callback);
   3941                return cur;
   3942            };
   3943            var post = function (cur, parent) {
   3944                AstWalkerCallback(false, cur, callback);
   3945                return cur;
   3946            };
   3947            var walker = TypeScript.getAstWalkerFactory().getWalker(pre, post);
   3948            walker.walk(script, null);
   3949        }
   3950        AstWalkerWithDetailCallback.walk = walk;
   3951        function AstWalkerCallback(pre, ast, callback) {
   3952            var nodeType = ast.nodeType;
   3953            var callbackString = (TypeScript.NodeType)._map[nodeType] + "Callback";
   3954            if(callback[callbackString]) {
   3955                return callback[callbackString](pre, ast);
   3956            }
   3957            if(callback.DefaultCallback) {
   3958                return callback.DefaultCallback(pre, ast);
   3959            }
   3960            return true;
   3961        }
   3962    })(TypeScript.AstWalkerWithDetailCallback || (TypeScript.AstWalkerWithDetailCallback = {}));
   3963    var AstWalkerWithDetailCallback = TypeScript.AstWalkerWithDetailCallback;
   3964 })(TypeScript || (TypeScript = {}));
   3965 var TypeScript;
   3966 (function (TypeScript) {
   3967    function lastOf(items) {
   3968        return (items === null || items.length === 0) ? null : items[items.length - 1];
   3969    }
   3970    TypeScript.lastOf = lastOf;
   3971    function max(a, b) {
   3972        return a >= b ? a : b;
   3973    }
   3974    TypeScript.max = max;
   3975    function min(a, b) {
   3976        return a <= b ? a : b;
   3977    }
   3978    TypeScript.min = min;
   3979    var AstPath = (function () {
   3980        function AstPath() {
   3981            this.asts = [];
   3982            this.top = -1;
   3983        }
   3984        AstPath.reverseIndexOf = function reverseIndexOf(items, index) {
   3985            return (items === null || items.length <= index) ? null : items[items.length - index - 1];
   3986        }
   3987        AstPath.prototype.clone = function () {
   3988            var clone = new AstPath();
   3989            clone.asts = this.asts.map(function (value) {
   3990                return value;
   3991            });
   3992            clone.top = this.top;
   3993            return clone;
   3994        };
   3995        AstPath.prototype.pop = function () {
   3996            var head = this.ast();
   3997            this.up();
   3998            while(this.asts.length > this.count()) {
   3999                this.asts.pop();
   4000            }
   4001            return head;
   4002        };
   4003        AstPath.prototype.push = function (ast) {
   4004            while(this.asts.length > this.count()) {
   4005                this.asts.pop();
   4006            }
   4007            this.top = this.asts.length;
   4008            this.asts.push(ast);
   4009        };
   4010        AstPath.prototype.up = function () {
   4011            if(this.top <= -1) {
   4012                throw new Error("Invalid call to 'up'");
   4013            }
   4014            this.top--;
   4015        };
   4016        AstPath.prototype.down = function () {
   4017            if(this.top == this.ast.length - 1) {
   4018                throw new Error("Invalid call to 'down'");
   4019            }
   4020            this.top++;
   4021        };
   4022        AstPath.prototype.nodeType = function () {
   4023            if(this.ast() == null) {
   4024                return TypeScript.NodeType.None;
   4025            }
   4026            return this.ast().nodeType;
   4027        };
   4028        AstPath.prototype.ast = function () {
   4029            return AstPath.reverseIndexOf(this.asts, this.asts.length - (this.top + 1));
   4030        };
   4031        AstPath.prototype.parent = function () {
   4032            return AstPath.reverseIndexOf(this.asts, this.asts.length - this.top);
   4033        };
   4034        AstPath.prototype.count = function () {
   4035            return this.top + 1;
   4036        };
   4037        AstPath.prototype.get = function (index) {
   4038            return this.asts[index];
   4039        };
   4040        AstPath.prototype.isNameOfClass = function () {
   4041            if(this.ast() === null || this.parent() === null) {
   4042                return false;
   4043            }
   4044            return (this.ast().nodeType === TypeScript.NodeType.Name) && (this.parent().nodeType === TypeScript.NodeType.ClassDeclaration) && ((this.parent()).name === this.ast());
   4045        };
   4046        AstPath.prototype.isNameOfInterface = function () {
   4047            if(this.ast() === null || this.parent() === null) {
   4048                return false;
   4049            }
   4050            return (this.ast().nodeType === TypeScript.NodeType.Name) && (this.parent().nodeType === TypeScript.NodeType.InterfaceDeclaration) && ((this.parent()).name === this.ast());
   4051        };
   4052        AstPath.prototype.isNameOfArgument = function () {
   4053            if(this.ast() === null || this.parent() === null) {
   4054                return false;
   4055            }
   4056            return (this.ast().nodeType === TypeScript.NodeType.Name) && (this.parent().nodeType === TypeScript.NodeType.ArgDecl) && ((this.parent()).id === this.ast());
   4057        };
   4058        AstPath.prototype.isNameOfVariable = function () {
   4059            if(this.ast() === null || this.parent() === null) {
   4060                return false;
   4061            }
   4062            return (this.ast().nodeType === TypeScript.NodeType.Name) && (this.parent().nodeType === TypeScript.NodeType.VarDecl) && ((this.parent()).id === this.ast());
   4063        };
   4064        AstPath.prototype.isNameOfModule = function () {
   4065            if(this.ast() === null || this.parent() === null) {
   4066                return false;
   4067            }
   4068            return (this.ast().nodeType === TypeScript.NodeType.Name) && (this.parent().nodeType === TypeScript.NodeType.ModuleDeclaration) && ((this.parent()).name === this.ast());
   4069        };
   4070        AstPath.prototype.isNameOfFunction = function () {
   4071            if(this.ast() === null || this.parent() === null) {
   4072                return false;
   4073            }
   4074            return (this.ast().nodeType === TypeScript.NodeType.Name) && (this.parent().nodeType === TypeScript.NodeType.FuncDecl) && ((this.parent()).name === this.ast());
   4075        };
   4076        AstPath.prototype.isChildOfScript = function () {
   4077            var ast = lastOf(this.asts);
   4078            return this.count() >= 3 && this.asts[this.top] === ast && this.asts[this.top - 1].nodeType === TypeScript.NodeType.List && this.asts[this.top - 2].nodeType === TypeScript.NodeType.Script;
   4079        };
   4080        AstPath.prototype.isChildOfModule = function () {
   4081            var ast = lastOf(this.asts);
   4082            return this.count() >= 3 && this.asts[this.top] === ast && this.asts[this.top - 1].nodeType === TypeScript.NodeType.List && this.asts[this.top - 2].nodeType === TypeScript.NodeType.ModuleDeclaration;
   4083        };
   4084        AstPath.prototype.isChildOfClass = function () {
   4085            var ast = lastOf(this.asts);
   4086            return this.count() >= 3 && this.asts[this.top] === ast && this.asts[this.top - 1].nodeType === TypeScript.NodeType.List && this.asts[this.top - 2].nodeType === TypeScript.NodeType.ClassDeclaration;
   4087        };
   4088        AstPath.prototype.isArgumentOfClassConstructor = function () {
   4089            var ast = lastOf(this.asts);
   4090            return this.count() >= 5 && this.asts[this.top] === ast && this.asts[this.top - 1].nodeType === TypeScript.NodeType.List && this.asts[this.top - 2].nodeType === TypeScript.NodeType.FuncDecl && this.asts[this.top - 3].nodeType === TypeScript.NodeType.List && this.asts[this.top - 4].nodeType === TypeScript.NodeType.ClassDeclaration && ((this.asts[this.top - 2]).isConstructor) && ((this.asts[this.top - 2]).arguments === this.asts[this.top - 1]) && ((this.asts[this.top - 4]).constructorDecl === this.asts[this.top - 2]);
   4091        };
   4092        AstPath.prototype.isChildOfInterface = function () {
   4093            var ast = lastOf(this.asts);
   4094            return this.count() >= 3 && this.asts[this.top] === ast && this.asts[this.top - 1].nodeType === TypeScript.NodeType.List && this.asts[this.top - 2].nodeType === TypeScript.NodeType.InterfaceDeclaration;
   4095        };
   4096        AstPath.prototype.isTopLevelImplicitModule = function () {
   4097            return this.count() >= 1 && this.asts[this.top].nodeType === TypeScript.NodeType.ModuleDeclaration && TypeScript.hasFlag((this.asts[this.top]).modFlags, TypeScript.ModuleFlags.IsWholeFile);
   4098        };
   4099        AstPath.prototype.isBodyOfTopLevelImplicitModule = function () {
   4100            return this.count() >= 2 && this.asts[this.top - 0].nodeType === TypeScript.NodeType.List && this.asts[this.top - 1].nodeType === TypeScript.NodeType.ModuleDeclaration && (this.asts[this.top - 1]).members == this.asts[this.top - 0] && TypeScript.hasFlag((this.asts[this.top - 1]).modFlags, TypeScript.ModuleFlags.IsWholeFile);
   4101        };
   4102        AstPath.prototype.isBodyOfScript = function () {
   4103            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Script && (this.asts[this.top - 1]).bod == this.asts[this.top - 0];
   4104        };
   4105        AstPath.prototype.isBodyOfSwitch = function () {
   4106            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Switch && (this.asts[this.top - 1]).caseList == this.asts[this.top - 0];
   4107        };
   4108        AstPath.prototype.isBodyOfModule = function () {
   4109            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.ModuleDeclaration && (this.asts[this.top - 1]).members == this.asts[this.top - 0];
   4110        };
   4111        AstPath.prototype.isBodyOfClass = function () {
   4112            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.ClassDeclaration && (this.asts[this.top - 1]).members == this.asts[this.top - 0];
   4113        };
   4114        AstPath.prototype.isBodyOfFunction = function () {
   4115            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.FuncDecl && (this.asts[this.top - 1]).bod == this.asts[this.top - 0];
   4116        };
   4117        AstPath.prototype.isBodyOfInterface = function () {
   4118            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.InterfaceDeclaration && (this.asts[this.top - 1]).members == this.asts[this.top - 0];
   4119        };
   4120        AstPath.prototype.isBodyOfBlock = function () {
   4121            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Block && (this.asts[this.top - 1]).statements == this.asts[this.top - 0];
   4122        };
   4123        AstPath.prototype.isBodyOfFor = function () {
   4124            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.For && (this.asts[this.top - 1]).body == this.asts[this.top - 0];
   4125        };
   4126        AstPath.prototype.isBodyOfCase = function () {
   4127            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Case && (this.asts[this.top - 1]).body == this.asts[this.top - 0];
   4128        };
   4129        AstPath.prototype.isBodyOfTry = function () {
   4130            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Try && (this.asts[this.top - 1]).body == this.asts[this.top - 0];
   4131        };
   4132        AstPath.prototype.isBodyOfCatch = function () {
   4133            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Catch && (this.asts[this.top - 1]).body == this.asts[this.top - 0];
   4134        };
   4135        AstPath.prototype.isBodyOfDoWhile = function () {
   4136            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.DoWhile && (this.asts[this.top - 1]).body == this.asts[this.top - 0];
   4137        };
   4138        AstPath.prototype.isBodyOfWhile = function () {
   4139            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.While && (this.asts[this.top - 1]).body == this.asts[this.top - 0];
   4140        };
   4141        AstPath.prototype.isBodyOfForIn = function () {
   4142            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.ForIn && (this.asts[this.top - 1]).body == this.asts[this.top - 0];
   4143        };
   4144        AstPath.prototype.isBodyOfWith = function () {
   4145            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.With && (this.asts[this.top - 1]).body == this.asts[this.top - 0];
   4146        };
   4147        AstPath.prototype.isBodyOfFinally = function () {
   4148            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Finally && (this.asts[this.top - 1]).body == this.asts[this.top - 0];
   4149        };
   4150        AstPath.prototype.isCaseOfSwitch = function () {
   4151            return this.count() >= 3 && this.asts[this.top - 2].nodeType === TypeScript.NodeType.Switch && this.asts[this.top - 1].nodeType === TypeScript.NodeType.List && (this.asts[this.top - 2]).caseList == this.asts[this.top - 1];
   4152        };
   4153        AstPath.prototype.isDefaultCaseOfSwitch = function () {
   4154            return this.count() >= 3 && this.asts[this.top - 2].nodeType === TypeScript.NodeType.Switch && this.asts[this.top - 1].nodeType === TypeScript.NodeType.List && (this.asts[this.top - 2]).caseList == this.asts[this.top - 1] && (this.asts[this.top - 2]).defaultCase == this.asts[this.top - 0];
   4155        };
   4156        AstPath.prototype.isListOfObjectLit = function () {
   4157            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.ObjectLit && this.asts[this.top - 0].nodeType === TypeScript.NodeType.List && (this.asts[this.top - 1]).operand == this.asts[this.top - 0];
   4158        };
   4159        AstPath.prototype.isBodyOfObjectLit = function () {
   4160            return this.isListOfObjectLit();
   4161        };
   4162        AstPath.prototype.isEmptyListOfObjectLit = function () {
   4163            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.ObjectLit && this.asts[this.top - 0].nodeType === TypeScript.NodeType.List && (this.asts[this.top - 1]).operand == this.asts[this.top - 0] && (this.asts[this.top - 0]).members.length == 0;
   4164        };
   4165        AstPath.prototype.isMemberOfObjectLit = function () {
   4166            return this.count() >= 3 && this.asts[this.top - 2].nodeType === TypeScript.NodeType.ObjectLit && this.asts[this.top - 1].nodeType === TypeScript.NodeType.List && this.asts[this.top - 0].nodeType === TypeScript.NodeType.Member && (this.asts[this.top - 2]).operand == this.asts[this.top - 1];
   4167        };
   4168        AstPath.prototype.isNameOfMemberOfObjectLit = function () {
   4169            return this.count() >= 4 && this.asts[this.top - 3].nodeType === TypeScript.NodeType.ObjectLit && this.asts[this.top - 2].nodeType === TypeScript.NodeType.List && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Member && this.asts[this.top - 0].nodeType === TypeScript.NodeType.Name && (this.asts[this.top - 3]).operand == this.asts[this.top - 2];
   4170        };
   4171        AstPath.prototype.isListOfArrayLit = function () {
   4172            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.ArrayLit && this.asts[this.top - 0].nodeType === TypeScript.NodeType.List && (this.asts[this.top - 1]).operand == this.asts[this.top - 0];
   4173        };
   4174        AstPath.prototype.isTargetOfMember = function () {
   4175            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Member && (this.asts[this.top - 1]).operand1 === this.asts[this.top - 0];
   4176        };
   4177        AstPath.prototype.isMemberOfMember = function () {
   4178            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Member && (this.asts[this.top - 1]).operand2 === this.asts[this.top - 0];
   4179        };
   4180        AstPath.prototype.isItemOfList = function () {
   4181            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.List;
   4182        };
   4183        AstPath.prototype.isThenOfIf = function () {
   4184            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.If && (this.asts[this.top - 1]).thenBod == this.asts[this.top - 0];
   4185        };
   4186        AstPath.prototype.isElseOfIf = function () {
   4187            return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.If && (this.asts[this.top - 1]).elseBod == this.asts[this.top - 0];
   4188        };
   4189        AstPath.prototype.isBodyOfDefaultCase = function () {
   4190            return this.isBodyOfCase();
   4191        };
   4192        AstPath.prototype.isSingleStatementList = function () {
   4193            return this.count() >= 1 && this.asts[this.top].nodeType === TypeScript.NodeType.List && (this.asts[this.top]).members.length === 1;
   4194        };
   4195        AstPath.prototype.isArgumentListOfFunction = function () {
   4196            return this.count() >= 2 && this.asts[this.top - 0].nodeType === TypeScript.NodeType.List && this.asts[this.top - 1].nodeType === TypeScript.NodeType.FuncDecl && (this.asts[this.top - 1]).arguments === this.asts[this.top - 0];
   4197        };
   4198        AstPath.prototype.isArgumentOfFunction = function () {
   4199            return this.count() >= 3 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.List && this.asts[this.top - 2].nodeType === TypeScript.NodeType.FuncDecl && (this.asts[this.top - 2]).arguments === this.asts[this.top - 1];
   4200        };
   4201        AstPath.prototype.isArgumentListOfCall = function () {
   4202            return this.count() >= 2 && this.asts[this.top - 0].nodeType === TypeScript.NodeType.List && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Call && (this.asts[this.top - 1]).arguments === this.asts[this.top - 0];
   4203        };
   4204        AstPath.prototype.isArgumentListOfNew = function () {
   4205            return this.count() >= 2 && this.asts[this.top - 0].nodeType === TypeScript.NodeType.List && this.asts[this.top - 1].nodeType === TypeScript.NodeType.New && (this.asts[this.top - 1]).arguments === this.asts[this.top - 0];
   4206        };
   4207        AstPath.prototype.isSynthesizedBlock = function () {
   4208            return this.count() >= 1 && this.asts[this.top - 0].nodeType === TypeScript.NodeType.Block && (this.asts[this.top - 0]).isStatementBlock === false;
   4209        };
   4210        return AstPath;
   4211    })();
   4212    TypeScript.AstPath = AstPath;    
   4213    function isValidAstNode(ast) {
   4214        if(ast === null) {
   4215            return false;
   4216        }
   4217        if(ast.minChar === -1 || ast.limChar === -1) {
   4218            return false;
   4219        }
   4220        return true;
   4221    }
   4222    TypeScript.isValidAstNode = isValidAstNode;
   4223    var AstPathContext = (function () {
   4224        function AstPathContext() {
   4225            this.path = new TypeScript.AstPath();
   4226        }
   4227        return AstPathContext;
   4228    })();
   4229    TypeScript.AstPathContext = AstPathContext;    
   4230    (function (GetAstPathOptions) {
   4231        GetAstPathOptions._map = [];
   4232        GetAstPathOptions.Default = 0;
   4233        GetAstPathOptions.EdgeInclusive = 1;
   4234        GetAstPathOptions.DontPruneSearchBasedOnPosition = 1 << 1;
   4235    })(TypeScript.GetAstPathOptions || (TypeScript.GetAstPathOptions = {}));
   4236    var GetAstPathOptions = TypeScript.GetAstPathOptions;
   4237    function getAstPathToPosition(script, pos, options) {
   4238        if (typeof options === "undefined") { options = GetAstPathOptions.Default; }
   4239        var lookInComments = function (comments) {
   4240            if(comments && comments.length > 0) {
   4241                for(var i = 0; i < comments.length; i++) {
   4242                    var minChar = comments[i].minChar;
   4243                    var limChar = comments[i].limChar;
   4244                    if(!comments[i].isBlockComment) {
   4245                        limChar++;
   4246                    }
   4247                    if(pos >= minChar && pos < limChar) {
   4248                        ctx.path.push(comments[i]);
   4249                    }
   4250                }
   4251            }
   4252        };
   4253        var pre = function (cur, parent, walker) {
   4254            if(isValidAstNode(cur)) {
   4255                var inclusive = TypeScript.hasFlag(options, GetAstPathOptions.EdgeInclusive) || cur.nodeType === TypeScript.NodeType.Name || pos === script.limChar;
   4256                var minChar = cur.minChar;
   4257                var limChar = cur.limChar + (inclusive ? 1 : 0);
   4258                if(pos >= minChar && pos < limChar) {
   4259                    var previous = ctx.path.ast();
   4260                    if(previous == null || (cur.minChar >= previous.minChar && cur.limChar <= previous.limChar)) {
   4261                        ctx.path.push(cur);
   4262                    } else {
   4263                    }
   4264                }
   4265                if(pos < limChar) {
   4266                    lookInComments(cur.preComments);
   4267                }
   4268                if(pos >= minChar) {
   4269                    lookInComments(cur.postComments);
   4270                }
   4271                if(!TypeScript.hasFlag(options, GetAstPathOptions.DontPruneSearchBasedOnPosition)) {
   4272                    walker.options.goChildren = (minChar <= pos && pos <= limChar);
   4273                }
   4274            }
   4275            return cur;
   4276        };
   4277        var ctx = new AstPathContext();
   4278        TypeScript.getAstWalkerFactory().walk(script, pre, null, null, ctx);
   4279        return ctx.path;
   4280    }
   4281    TypeScript.getAstPathToPosition = getAstPathToPosition;
   4282    function getTokenizationOffset(script, position) {
   4283        var bestOffset = 0;
   4284        var pre = function (cur, parent, walker) {
   4285            if(TypeScript.isValidAstNode(cur)) {
   4286                if(cur.minChar <= position) {
   4287                    bestOffset = max(bestOffset, cur.minChar);
   4288                }
   4289                if(cur.minChar > position || cur.limChar < bestOffset) {
   4290                    walker.options.goChildren = false;
   4291                }
   4292            }
   4293            return cur;
   4294        };
   4295        TypeScript.getAstWalkerFactory().walk(script, pre);
   4296        return bestOffset;
   4297    }
   4298    TypeScript.getTokenizationOffset = getTokenizationOffset;
   4299    function walkAST(ast, callback) {
   4300        var pre = function (cur, parent, walker) {
   4301            var path = walker.state;
   4302            path.push(cur);
   4303            callback(path, walker);
   4304            return cur;
   4305        };
   4306        var post = function (cur, parent, walker) {
   4307            var path = walker.state;
   4308            path.pop();
   4309            return cur;
   4310        };
   4311        var path = new AstPath();
   4312        TypeScript.getAstWalkerFactory().walk(ast, pre, post, null, path);
   4313    }
   4314    TypeScript.walkAST = walkAST;
   4315 })(TypeScript || (TypeScript = {}));
   4316 var TypeScript;
   4317 (function (TypeScript) {
   4318    var AstLogger = (function () {
   4319        function AstLogger(logger) {
   4320            this.logger = logger;
   4321        }
   4322        AstLogger.prototype.logScript = function (script) {
   4323            var _this = this;
   4324            this.logLinemap(script.locationInfo.lineMap);
   4325            var stack = [];
   4326            var pre = function (cur, parent) {
   4327                stack.push(cur);
   4328                var indent = (stack.length - 1) * 2;
   4329                _this.logComments(script, cur.preComments, indent);
   4330                _this.logNode(script, cur, indent);
   4331                _this.logComments(script, cur.postComments, indent);
   4332                return cur;
   4333            };
   4334            var post = function (cur, parent) {
   4335                stack.pop();
   4336                return cur;
   4337            };
   4338            TypeScript.getAstWalkerFactory().walk(script, pre, post);
   4339        };
   4340        AstLogger.prototype.logNode = function (script, cur, indent) {
   4341            var msg = this.addPadding("", indent, "| ", true);
   4342            msg = msg.concat("+ " + cur.treeViewLabel());
   4343            msg = this.addPadding(msg, 70, " ", false);
   4344            msg = msg + this.addLineColumn(script, cur.minChar);
   4345            msg = this.addPadding(msg, 80, " ", false);
   4346            msg = msg + "=> ";
   4347            msg = msg + this.addLineColumn(script, cur.limChar);
   4348            msg = this.addPadding(msg, 102, " ", false);
   4349            msg = msg.concat("[" + this.addPadding(cur.minChar.toString(), 1, " ", true) + ", " + this.addPadding(cur.limChar.toString(), 1, " ", true) + "]");
   4350            msg = this.addPadding(msg, 115, " ", false);
   4351            msg = msg.concat("sym=" + (cur).sym);
   4352            msg = this.addPadding(msg, 135, " ", false);
   4353            msg = msg.concat("type=" + (cur.type === null ? "null" : cur.type.getTypeName()));
   4354            this.logger.log(msg);
   4355        };
   4356        AstLogger.prototype.logComments = function (script, comments, indent) {
   4357            if(comments == null) {
   4358                return;
   4359            }
   4360            for(var i = 0; i < comments.length; i++) {
   4361                this.logNode(script, comments[i], indent);
   4362            }
   4363        };
   4364        AstLogger.prototype.logLinemap = function (linemap) {
   4365            var result = "[";
   4366            for(var i = 0; i < linemap.length; i++) {
   4367                if(i > 0) {
   4368                    result += ",";
   4369                }
   4370                result += linemap[i];
   4371            }
   4372            result += "]";
   4373            this.logger.log("linemap: " + result);
   4374        };
   4375        AstLogger.prototype.addPadding = function (s, targetLength, paddingString, leftPadding) {
   4376            var result = (leftPadding ? "" : s);
   4377            for(var i = s.length; i < targetLength; i++) {
   4378                result = result + paddingString;
   4379            }
   4380            result = result + (leftPadding ? s : "");
   4381            return result;
   4382        };
   4383        AstLogger.prototype.addLineColumn = function (script, position) {
   4384            var lineInfo = {
   4385                line: -1,
   4386                col: -1
   4387            };
   4388            TypeScript.getSourceLineColFromMap(lineInfo, position, script.locationInfo.lineMap);
   4389            if(lineInfo.col !== -1) {
   4390                lineInfo.col++;
   4391            }
   4392            return "(" + lineInfo.line + ", " + lineInfo.col + ")";
   4393        };
   4394        return AstLogger;
   4395    })();
   4396    TypeScript.AstLogger = AstLogger;    
   4397 })(TypeScript || (TypeScript = {}));
   4398 var TypeScript;
   4399 (function (TypeScript) {
   4400    var Binder = (function () {
   4401        function Binder(checker) {
   4402            this.checker = checker;
   4403        }
   4404        Binder.prototype.resolveBaseTypeLinks = function (typeLinks, scope) {
   4405            var extendsList = null;
   4406            if(typeLinks) {
   4407                extendsList = new Array();
   4408                for(var i = 0, len = typeLinks.length; i < len; i++) {
   4409                    extendsList[i] = this.checker.resolveBaseTypeLink(typeLinks[i], scope);
   4410                }
   4411            }
   4412            return extendsList;
   4413        };
   4414        Binder.prototype.resolveBases = function (scope, type) {
   4415            type.extendsList = this.resolveBaseTypeLinks(type.extendsTypeLinks, scope);
   4416            var i = 0, len = type.extendsList.length;
   4417            var derivedIsClass = type.isClassInstance();
   4418            for(; i < len; i++) {
   4419                var baseIsClass = type.extendsList[i].isClassInstance();
   4420                if(type.extendsList[i] != this.checker.anyType) {
   4421                    var baseRef = type.extendsTypeLinks[i].ast;
   4422                    if(derivedIsClass) {
   4423                        if(!baseIsClass) {
   4424                            this.checker.errorReporter.simpleError(baseRef, "A class may only extend other classes, " + type.extendsList[i].symbol.fullName() + " is not a class.");
   4425                        }
   4426                    } else {
   4427                        if(baseIsClass) {
   4428                            this.checker.errorReporter.simpleError(baseRef, "An interface may only extend other interfaces, " + type.extendsList[i].symbol.fullName() + " is a class.");
   4429                        }
   4430                    }
   4431                }
   4432            }
   4433            type.implementsList = this.resolveBaseTypeLinks(type.implementsTypeLinks, scope);
   4434            if(type.implementsList) {
   4435                for(i = 0 , len = type.implementsList.length; i < len; i++) {
   4436                    var iface = type.implementsList[i];
   4437                    var baseRef = type.implementsTypeLinks[i].ast;
   4438                    if(iface.isClassInstance()) {
   4439                        if(derivedIsClass) {
   4440                            this.checker.errorReporter.simpleError(baseRef, "A class may only implement an interface; " + iface.symbol.fullName() + " is a class.");
   4441                        }
   4442                    }
   4443                }
   4444            }
   4445        };
   4446        Binder.prototype.resolveSignatureGroup = function (signatureGroup, scope, instanceType) {
   4447            var supplyVar = !(signatureGroup.hasImplementation);
   4448            for(var i = 0, len = signatureGroup.signatures.length; i < len; i++) {
   4449                var signature = signatureGroup.signatures[i];
   4450                if(instanceType) {
   4451                    signature.returnType.type = instanceType;
   4452                } else {
   4453                    this.checker.resolveTypeLink(scope, signature.returnType, supplyVar);
   4454                }
   4455                var paramLen = signature.parameters.length;
   4456                for(var j = 0; j < paramLen; j++) {
   4457                    this.bindSymbol(scope, signature.parameters[j]);
   4458                }
   4459                if(signature.hasVariableArgList) {
   4460                    var lastParam = signature.parameters[paramLen - 1];
   4461                    lastParam.argsOffset = paramLen - 1;
   4462                    if(!lastParam.getType().isArray()) {
   4463                        this.checker.errorReporter.simpleErrorFromSym(lastParam, "... parameter must have array type");
   4464                        lastParam.parameter.typeLink.type = this.checker.makeArrayType(lastParam.parameter.typeLink.type);
   4465                    }
   4466                }
   4467            }
   4468        };
   4469        Binder.prototype.bindType = function (scope, type, instanceType) {
   4470            if(instanceType) {
   4471                this.bindType(scope, instanceType, null);
   4472            }
   4473            if(type.hasMembers()) {
   4474                var members = type.members;
   4475                var ambientMembers = type.ambientMembers;
   4476                var typeMembers = type.getAllEnclosedTypes();
   4477                var ambientTypeMembers = type.getAllAmbientEnclosedTypes();
   4478                var memberScope = new TypeScript.SymbolTableScope(members, ambientMembers, typeMembers, ambientTypeMembers, type.symbol);
   4479                var agg = new TypeScript.SymbolAggregateScope(type.symbol);
   4480                var prevCurrentModDecl = this.checker.currentModDecl;
   4481                var prevBindStatus = this.checker.inBind;
   4482                agg.addParentScope(memberScope);
   4483                agg.addParentScope(scope);
   4484                if(type.isModuleType()) {
   4485                    this.checker.currentModDecl = type.symbol.declAST;
   4486                    this.checker.inBind = true;
   4487                }
   4488                if(members) {
   4489                    this.bind(agg, type.members.allMembers);
   4490                }
   4491                if(typeMembers) {
   4492                    this.bind(agg, typeMembers.allMembers);
   4493                }
   4494                if(ambientMembers) {
   4495                    this.bind(agg, ambientMembers.allMembers);
   4496                }
   4497                if(ambientTypeMembers) {
   4498                    this.bind(agg, ambientTypeMembers.allMembers);
   4499                }
   4500                this.checker.currentModDecl = prevCurrentModDecl;
   4501                this.checker.inBind = prevBindStatus;
   4502            }
   4503            if(type.extendsTypeLinks) {
   4504                this.resolveBases(scope, type);
   4505            }
   4506            if(type.construct) {
   4507                this.resolveSignatureGroup(type.construct, scope, instanceType);
   4508            }
   4509            if(type.call) {
   4510                this.resolveSignatureGroup(type.call, scope, null);
   4511            }
   4512            if(type.index) {
   4513                this.resolveSignatureGroup(type.index, scope, null);
   4514            }
   4515            if(type.elementType) {
   4516                this.bindType(scope, type.elementType, null);
   4517            }
   4518        };
   4519        Binder.prototype.bindSymbol = function (scope, symbol) {
   4520            if(!symbol.bound) {
   4521                var prevLocationInfo = this.checker.locationInfo;
   4522                if((this.checker.units) && (symbol.unitIndex >= 0) && (symbol.unitIndex < this.checker.units.length)) {
   4523                    this.checker.locationInfo = this.checker.units[symbol.unitIndex];
   4524                }
   4525                switch(symbol.kind()) {
   4526                    case TypeScript.SymbolKind.Type: {
   4527                        if(symbol.flags & TypeScript.SymbolFlags.Bound) {
   4528                            break;
   4529                        }
   4530                        var typeSymbol = symbol;
   4531                        typeSymbol.flags |= TypeScript.SymbolFlags.Bound;
   4532                        if(typeSymbol.aliasLink && !typeSymbol.type && typeSymbol.aliasLink.alias.nodeType == TypeScript.NodeType.Name) {
   4533                            var modPath = (typeSymbol.aliasLink.alias).text;
   4534                            var modSym = this.checker.findSymbolForDynamicModule(modPath, this.checker.locationInfo.filename, function (id) {
   4535                                return scope.find(id, false, true);
   4536                            });
   4537                            if(modSym) {
   4538                                typeSymbol.type = modSym.getType();
   4539                            }
   4540                        }
   4541                        if(typeSymbol.type && typeSymbol.type != this.checker.gloModType) {
   4542                            this.bindType(scope, typeSymbol.type, typeSymbol.instanceType);
   4543                            if(typeSymbol.type.isModuleType()) {
   4544                                for(var i = 0; i < typeSymbol.expansions.length; i++) {
   4545                                    this.bindType(scope, typeSymbol.expansions[i], typeSymbol.instanceType);
   4546                                }
   4547                            }
   4548                        }
   4549                        break;
   4550 
   4551                    }
   4552                    case TypeScript.SymbolKind.Field: {
   4553                        this.checker.resolveTypeLink(scope, (symbol).field.typeLink, false);
   4554                        break;
   4555 
   4556                    }
   4557                    case TypeScript.SymbolKind.Parameter: {
   4558                        this.checker.resolveTypeLink(scope, (symbol).parameter.typeLink, true);
   4559                        break;
   4560 
   4561                    }
   4562                }
   4563                this.checker.locationInfo = prevLocationInfo;
   4564            }
   4565            symbol.bound = true;
   4566        };
   4567        Binder.prototype.bind = function (scope, table) {
   4568            table.map(function (key, sym, binder) {
   4569                binder.bindSymbol(scope, sym);
   4570            }, this);
   4571        };
   4572        return Binder;
   4573    })();
   4574    TypeScript.Binder = Binder;    
   4575 })(TypeScript || (TypeScript = {}));
   4576 var TypeScript;
   4577 (function (TypeScript) {
   4578    var Base64Format = (function () {
   4579        function Base64Format() { }
   4580        Base64Format.encodedValues = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
   4581        Base64Format.encode = function encode(inValue) {
   4582            if(inValue < 64) {
   4583                return Base64Format.encodedValues.charAt(inValue);
   4584            }
   4585            throw TypeError(inValue + ": not a 64 based value");
   4586        }
   4587        Base64Format.decodeChar = function decodeChar(inChar) {
   4588            if(inChar.length === 1) {
   4589                return Base64Format.encodedValues.indexOf(inChar);
   4590            } else {
   4591                throw TypeError('"' + inChar + '" must have length 1');
   4592            }
   4593        }
   4594        return Base64Format;
   4595    })();    
   4596    var Base64VLQFormat = (function () {
   4597        function Base64VLQFormat() { }
   4598        Base64VLQFormat.encode = function encode(inValue) {
   4599            if(inValue < 0) {
   4600                inValue = ((-inValue) << 1) + 1;
   4601            } else {
   4602                inValue = inValue << 1;
   4603            }
   4604            var encodedStr = "";
   4605            do {
   4606                var currentDigit = inValue & 31;
   4607                inValue = inValue >> 5;
   4608                if(inValue > 0) {
   4609                    currentDigit = currentDigit | 32;
   4610                }
   4611                encodedStr = encodedStr + Base64Format.encode(currentDigit);
   4612            }while(inValue > 0)
   4613            return encodedStr;
   4614        }
   4615        Base64VLQFormat.decode = function decode(inString) {
   4616            var result = 0;
   4617            var negative = false;
   4618            var shift = 0;
   4619            for(var i = 0; i < inString.length; i++) {
   4620                var byte = Base64Format.decodeChar(inString[i]);
   4621                if(i === 0) {
   4622                    if((byte & 1) === 1) {
   4623                        negative = true;
   4624                    }
   4625                    result = (byte >> 1) & 15;
   4626                } else {
   4627                    result = result | ((byte & 31) << shift);
   4628                }
   4629                shift += (i == 0) ? 4 : 5;
   4630                if((byte & 32) === 32) {
   4631                } else {
   4632                    return {
   4633                        value: negative ? -(result) : result,
   4634                        rest: inString.substr(i + 1)
   4635                    };
   4636                }
   4637            }
   4638            throw new Error('Base64 value "' + inString + '" finished with a continuation bit');
   4639        }
   4640        return Base64VLQFormat;
   4641    })();
   4642    TypeScript.Base64VLQFormat = Base64VLQFormat;    
   4643 })(TypeScript || (TypeScript = {}));
   4644 var JSON2 = {
   4645 };
   4646 ((function () {
   4647    'use strict';
   4648    function f(n) {
   4649        return n < 10 ? '0' + n : n;
   4650    }
   4651    if(typeof Date.prototype.toJSON !== 'function') {
   4652        Date.prototype.toJSON = function (key) {
   4653            return isFinite(this.valueOf()) ? this.getUTCFullYear() + '-' + f(this.getUTCMonth() + 1) + '-' + f(this.getUTCDate()) + 'T' + f(this.getUTCHours()) + ':' + f(this.getUTCMinutes()) + ':' + f(this.getUTCSeconds()) + 'Z' : null;
   4654        };
   4655        var strProto = String.prototype;
   4656        var numProto = Number.prototype;
   4657        numProto.JSON = strProto.JSON = (Boolean).prototype.toJSON = function (key) {
   4658            return this.valueOf();
   4659        };
   4660    }
   4661    var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, gap, indent, meta = {
   4662 '\b': '\\b',
   4663 '\t': '\\t',
   4664 '\n': '\\n',
   4665 '\f': '\\f',
   4666 '\r': '\\r',
   4667 '"': '\\"',
   4668 '\\': '\\\\'    }, rep;
   4669    function quote(string) {
   4670        escapable.lastIndex = 0;
   4671        return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
   4672            var c = meta[a];
   4673            return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
   4674        }) + '"' : '"' + string + '"';
   4675    }
   4676    function str(key, holder) {
   4677        var i, k = null, v, length, mind = gap, partial, value = holder[key];
   4678        if(value && typeof value === 'object' && typeof value.toJSON === 'function') {
   4679            value = value.toJSON(key);
   4680        }
   4681        if(typeof rep === 'function') {
   4682            value = rep.call(holder, key, value);
   4683        }
   4684        switch(typeof value) {
   4685            case 'string': {
   4686                return quote(value);
   4687 
   4688            }
   4689            case 'number': {
   4690                return isFinite(value) ? String(value) : 'null';
   4691 
   4692            }
   4693            case 'boolean':
   4694            case 'null': {
   4695                return String(value);
   4696 
   4697            }
   4698            case 'object': {
   4699                if(!value) {
   4700                    return 'null';
   4701                }
   4702                gap += indent;
   4703                partial = [];
   4704                if(Object.prototype.toString.apply(value, []) === '[object Array]') {
   4705                    length = value.length;
   4706                    for(i = 0; i < length; i += 1) {
   4707                        partial[i] = str(i, value) || 'null';
   4708                    }
   4709                    v = partial.length === 0 ? '[]' : gap ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : '[' + partial.join(',') + ']';
   4710                    gap = mind;
   4711                    return v;
   4712                }
   4713                if(rep && typeof rep === 'object') {
   4714                    length = rep.length;
   4715                    for(i = 0; i < length; i += 1) {
   4716                        if(typeof rep[i] === 'string') {
   4717                            k = rep[i];
   4718                            v = str(k, value);
   4719                            if(v) {
   4720                                partial.push(quote(k) + (gap ? ': ' : ':') + v);
   4721                            }
   4722                        }
   4723                    }
   4724                } else {
   4725                    for(k in value) {
   4726                        if(Object.prototype.hasOwnProperty.call(value, k)) {
   4727                            v = str(k, value);
   4728                            if(v) {
   4729                                partial.push(quote(k) + (gap ? ': ' : ':') + v);
   4730                            }
   4731                        }
   4732                    }
   4733                }
   4734                v = partial.length === 0 ? '{}' : gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' : '{' + partial.join(',') + '}';
   4735                gap = mind;
   4736                return v;
   4737 
   4738            }
   4739        }
   4740    }
   4741    if(typeof JSON2.stringify !== 'function') {
   4742        JSON2.stringify = function (value, replacer, space) {
   4743            var i;
   4744            gap = '';
   4745            indent = '';
   4746            if(typeof space === 'number') {
   4747                for(i = 0; i < space; i += 1) {
   4748                    indent += ' ';
   4749                }
   4750            } else {
   4751                if(typeof space === 'string') {
   4752                    indent = space;
   4753                }
   4754            }
   4755            rep = replacer;
   4756            if(replacer && typeof replacer !== 'function' && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) {
   4757                throw new Error('JSON.stringify');
   4758            }
   4759            return str('', {
   4760                '': value
   4761            });
   4762        };
   4763    }
   4764    if(typeof JSON2.parse !== 'function') {
   4765        JSON2.parse = function (text, reviver) {
   4766            var j;
   4767            function walk(holder, key) {
   4768                var k = null, v, value = holder[key];
   4769                if(value && typeof value === 'object') {
   4770                    for(k in value) {
   4771                        if(Object.prototype.hasOwnProperty.call(value, k)) {
   4772                            v = walk(value, k);
   4773                            if(v !== undefined) {
   4774                                value[k] = v;
   4775                            } else {
   4776                                delete value[k];
   4777                            }
   4778                        }
   4779                    }
   4780                }
   4781                return reviver.call(holder, key, value);
   4782            }
   4783            text = String(text);
   4784            cx.lastIndex = 0;
   4785            if(cx.test(text)) {
   4786                text = text.replace(cx, function (a) {
   4787                    return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
   4788                });
   4789            }
   4790            if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
   4791                j = eval('(' + text + ')');
   4792                return typeof reviver === 'function' ? walk({
   4793                    '': j
   4794                }, '') : j;
   4795            }
   4796            throw new SyntaxError('JSON.parse');
   4797        };
   4798    }
   4799 })());
   4800 var TypeScript;
   4801 (function (TypeScript) {
   4802    var SourceMapPosition = (function () {
   4803        function SourceMapPosition() { }
   4804        return SourceMapPosition;
   4805    })();
   4806    TypeScript.SourceMapPosition = SourceMapPosition;    
   4807    var SourceMapping = (function () {
   4808        function SourceMapping() {
   4809            this.start = new SourceMapPosition();
   4810            this.end = new SourceMapPosition();
   4811            this.nameIndex = -1;
   4812            this.childMappings = [];
   4813        }
   4814        return SourceMapping;
   4815    })();
   4816    TypeScript.SourceMapping = SourceMapping;    
   4817    var SourceMapper = (function () {
   4818        function SourceMapper(tsFileName, jsFileName, jsFile, sourceMapOut, errorReporter) {
   4819            this.jsFile = jsFile;
   4820            this.sourceMapOut = sourceMapOut;
   4821            this.errorReporter = errorReporter;
   4822            this.sourceMappings = [];
   4823            this.currentMappings = [];
   4824            this.names = [];
   4825            this.currentNameIndex = [];
   4826            this.currentMappings.push(this.sourceMappings);
   4827            jsFileName = TypeScript.switchToForwardSlashes(jsFileName);
   4828            this.jsFileName = TypeScript.getPrettyName(jsFileName, false, true);
   4829            var removalIndex = jsFileName.lastIndexOf(this.jsFileName);
   4830            var fixedPath = jsFileName.substring(0, removalIndex);
   4831            this.tsFileName = TypeScript.getRelativePathToFixedPath(fixedPath, tsFileName);
   4832        }
   4833        SourceMapper.MapFileExtension = ".map";
   4834        SourceMapper.EmitSourceMapping = function EmitSourceMapping(allSourceMappers) {
   4835            var sourceMapper = allSourceMappers[0];
   4836            sourceMapper.jsFile.WriteLine("//@ sourceMappingURL=" + sourceMapper.jsFileName + SourceMapper.MapFileExtension);
   4837            var sourceMapOut = sourceMapper.sourceMapOut;
   4838            var mappingsString = "";
   4839            var tsFiles = [];
   4840            var prevEmittedColumn = 0;
   4841            var prevEmittedLine = 0;
   4842            var prevSourceColumn = 0;
   4843            var prevSourceLine = 0;
   4844            var prevSourceIndex = 0;
   4845            var prevNameIndex = 0;
   4846            var namesList = [];
   4847            var namesCount = 0;
   4848            var emitComma = false;
   4849            var recordedPosition = null;
   4850            for(var sourceMapperIndex = 0; sourceMapperIndex < allSourceMappers.length; sourceMapperIndex++) {
   4851                sourceMapper = allSourceMappers[sourceMapperIndex];
   4852                var currentSourceIndex = tsFiles.length;
   4853                tsFiles.push(sourceMapper.tsFileName);
   4854                if(sourceMapper.names.length > 0) {
   4855                    namesList.push.apply(namesList, sourceMapper.names);
   4856                }
   4857                var recordSourceMapping = function (mappedPosition, nameIndex) {
   4858                    if(recordedPosition != null && recordedPosition.emittedColumn == mappedPosition.emittedColumn && recordedPosition.emittedLine == mappedPosition.emittedLine) {
   4859                        return;
   4860                    }
   4861                    if(prevEmittedLine !== mappedPosition.emittedLine) {
   4862                        while(prevEmittedLine < mappedPosition.emittedLine) {
   4863                            prevEmittedColumn = 0;
   4864                            mappingsString = mappingsString + ";";
   4865                            prevEmittedLine++;
   4866                        }
   4867                        emitComma = false;
   4868                    } else {
   4869                        if(emitComma) {
   4870                            mappingsString = mappingsString + ",";
   4871                        }
   4872                    }
   4873                    mappingsString = mappingsString + TypeScript.Base64VLQFormat.encode(mappedPosition.emittedColumn - prevEmittedColumn);
   4874                    prevEmittedColumn = mappedPosition.emittedColumn;
   4875                    mappingsString = mappingsString + TypeScript.Base64VLQFormat.encode(currentSourceIndex - prevSourceIndex);
   4876                    prevSourceIndex = currentSourceIndex;
   4877                    mappingsString = mappingsString + TypeScript.Base64VLQFormat.encode(mappedPosition.sourceLine - 1 - prevSourceLine);
   4878                    prevSourceLine = mappedPosition.sourceLine - 1;
   4879                    mappingsString = mappingsString + TypeScript.Base64VLQFormat.encode(mappedPosition.sourceColumn - prevSourceColumn);
   4880                    prevSourceColumn = mappedPosition.sourceColumn;
   4881                    if(nameIndex >= 0) {
   4882                        mappingsString = mappingsString + TypeScript.Base64VLQFormat.encode(namesCount + nameIndex - prevNameIndex);
   4883                        prevNameIndex = namesCount + nameIndex;
   4884                    }
   4885                    emitComma = true;
   4886                    recordedPosition = mappedPosition;
   4887                };
   4888                var recordSourceMappingSiblings = function (sourceMappings) {
   4889                    for(var i = 0; i < sourceMappings.length; i++) {
   4890                        var sourceMapping = sourceMappings[i];
   4891                        recordSourceMapping(sourceMapping.start, sourceMapping.nameIndex);
   4892                        recordSourceMappingSiblings(sourceMapping.childMappings);
   4893                        recordSourceMapping(sourceMapping.end, sourceMapping.nameIndex);
   4894                    }
   4895                };
   4896                recordSourceMappingSiblings(sourceMapper.sourceMappings, -1);
   4897                namesCount = namesCount + sourceMapper.names.length;
   4898            }
   4899            if(mappingsString != "") {
   4900                sourceMapOut.Write(JSON2.stringify({
   4901                    version: 3,
   4902                    file: sourceMapper.jsFileName,
   4903                    sources: tsFiles,
   4904                    names: namesList,
   4905                    mappings: mappingsString
   4906                }));
   4907            }
   4908            try  {
   4909                sourceMapOut.Close();
   4910            } catch (ex) {
   4911                sourceMapper.errorReporter.emitterError(null, ex.message);
   4912            }
   4913        }
   4914        return SourceMapper;
   4915    })();
   4916    TypeScript.SourceMapper = SourceMapper;    
   4917 })(TypeScript || (TypeScript = {}));
   4918 var TypeScript;
   4919 (function (TypeScript) {
   4920    (function (EmitContainer) {
   4921        EmitContainer._map = [];
   4922        EmitContainer._map[0] = "Prog";
   4923        EmitContainer.Prog = 0;
   4924        EmitContainer._map[1] = "Module";
   4925        EmitContainer.Module = 1;
   4926        EmitContainer._map[2] = "DynamicModule";
   4927        EmitContainer.DynamicModule = 2;
   4928        EmitContainer._map[3] = "Class";
   4929        EmitContainer.Class = 3;
   4930        EmitContainer._map[4] = "Constructor";
   4931        EmitContainer.Constructor = 4;
   4932        EmitContainer._map[5] = "Function";
   4933        EmitContainer.Function = 5;
   4934        EmitContainer._map[6] = "Args";
   4935        EmitContainer.Args = 6;
   4936        EmitContainer._map[7] = "Interface";
   4937        EmitContainer.Interface = 7;
   4938    })(TypeScript.EmitContainer || (TypeScript.EmitContainer = {}));
   4939    var EmitContainer = TypeScript.EmitContainer;
   4940    var EmitState = (function () {
   4941        function EmitState() {
   4942            this.column = 0;
   4943            this.line = 0;
   4944            this.pretty = false;
   4945            this.inObjectLiteral = false;
   4946            this.container = EmitContainer.Prog;
   4947        }
   4948        return EmitState;
   4949    })();
   4950    TypeScript.EmitState = EmitState;    
   4951    var EmitOptions = (function () {
   4952        function EmitOptions(settings) {
   4953            this.ioHost = null;
   4954            this.outputMany = true;
   4955            this.commonDirectoryPath = "";
   4956            this.minWhitespace = settings.minWhitespace;
   4957            this.propagateConstants = settings.propagateConstants;
   4958            this.emitComments = settings.emitComments;
   4959            this.outputOption = settings.outputOption;
   4960        }
   4961        EmitOptions.prototype.mapOutputFileName = function (fileName, extensionChanger) {
   4962            if(this.outputMany) {
   4963                var updatedFileName = fileName;
   4964                if(this.outputOption != "") {
   4965                    updatedFileName = fileName.replace(this.commonDirectoryPath, "");
   4966                    updatedFileName = this.outputOption + updatedFileName;
   4967                }
   4968                return extensionChanger(updatedFileName, false);
   4969            } else {
   4970                return extensionChanger(this.outputOption, true);
   4971            }
   4972        };
   4973        return EmitOptions;
   4974    })();
   4975    TypeScript.EmitOptions = EmitOptions;    
   4976    var Indenter = (function () {
   4977        function Indenter() {
   4978            this.indentAmt = 0;
   4979        }
   4980        Indenter.indentStep = 4;
   4981        Indenter.indentStepString = "    ";
   4982        Indenter.indentStrings = [];
   4983        Indenter.prototype.increaseIndent = function () {
   4984            this.indentAmt += Indenter.indentStep;
   4985        };
   4986        Indenter.prototype.decreaseIndent = function () {
   4987            this.indentAmt -= Indenter.indentStep;
   4988        };
   4989        Indenter.prototype.getIndent = function () {
   4990            var indentString = Indenter.indentStrings[this.indentAmt];
   4991            if(indentString === undefined) {
   4992                indentString = "";
   4993                for(var i = 0; i < this.indentAmt; i = i + Indenter.indentStep) {
   4994                    indentString += Indenter.indentStepString;
   4995                }
   4996                Indenter.indentStrings[this.indentAmt] = indentString;
   4997            }
   4998            return indentString;
   4999        };
   5000        return Indenter;
   5001    })();
   5002    TypeScript.Indenter = Indenter;    
   5003    var Emitter = (function () {
   5004        function Emitter(checker, emittingFileName, outfile, emitOptions, errorReporter) {
   5005            this.checker = checker;
   5006            this.emittingFileName = emittingFileName;
   5007            this.outfile = outfile;
   5008            this.emitOptions = emitOptions;
   5009            this.errorReporter = errorReporter;
   5010            this.prologueEmitted = false;
   5011            this.thisClassNode = null;
   5012            this.thisFnc = null;
   5013            this.moduleDeclList = [];
   5014            this.moduleName = "";
   5015            this.emitState = new EmitState();
   5016            this.indenter = new Indenter();
   5017            this.ambientModule = false;
   5018            this.modAliasId = null;
   5019            this.firstModAlias = null;
   5020            this.allSourceMappers = [];
   5021            this.sourceMapper = null;
   5022            this.captureThisStmtString = "var _this = this;";
   5023            this.varListCountStack = [
   5024                0
   5025            ];
   5026        }
   5027        Emitter.prototype.setSourceMappings = function (mapper) {
   5028            this.allSourceMappers.push(mapper);
   5029            this.sourceMapper = mapper;
   5030        };
   5031        Emitter.prototype.writeToOutput = function (s) {
   5032            this.outfile.Write(s);
   5033            this.emitState.column += s.length;
   5034        };
   5035        Emitter.prototype.writeToOutputTrimmable = function (s) {
   5036            if(this.emitOptions.minWhitespace) {
   5037                s = s.replace(/[\s]*/g, '');
   5038            }
   5039            this.writeToOutput(s);
   5040        };
   5041        Emitter.prototype.writeLineToOutput = function (s) {
   5042            if(this.emitOptions.minWhitespace) {
   5043                this.writeToOutput(s);
   5044                var c = s.charCodeAt(s.length - 1);
   5045                if(!((c == TypeScript.LexCodeSpace) || (c == TypeScript.LexCodeSMC) || (c == TypeScript.LexCodeLBR))) {
   5046                    this.writeToOutput(' ');
   5047                }
   5048            } else {
   5049                this.outfile.WriteLine(s);
   5050                this.emitState.column = 0;
   5051                this.emitState.line++;
   5052            }
   5053        };
   5054        Emitter.prototype.writeCaptureThisStatement = function (ast) {
   5055            this.emitIndent();
   5056            this.recordSourceMappingStart(ast);
   5057            this.writeToOutput(this.captureThisStmtString);
   5058            this.recordSourceMappingEnd(ast);
   5059            this.writeLineToOutput("");
   5060        };
   5061        Emitter.prototype.setInVarBlock = function (count) {
   5062            this.varListCountStack[this.varListCountStack.length - 1] = count;
   5063        };
   5064        Emitter.prototype.setInObjectLiteral = function (val) {
   5065            var temp = this.emitState.inObjectLiteral;
   5066            this.emitState.inObjectLiteral = val;
   5067            return temp;
   5068        };
   5069        Emitter.prototype.setContainer = function (c) {
   5070            var temp = this.emitState.container;
   5071            this.emitState.container = c;
   5072            return temp;
   5073        };
   5074        Emitter.prototype.getIndentString = function () {
   5075            if(this.emitOptions.minWhitespace) {
   5076                return "";
   5077            } else {
   5078                return this.indenter.getIndent();
   5079            }
   5080        };
   5081        Emitter.prototype.emitIndent = function () {
   5082            this.writeToOutput(this.getIndentString());
   5083        };
   5084        Emitter.prototype.emitCommentInPlace = function (comment) {
   5085            this.recordSourceMappingStart(comment);
   5086            var text = comment.getText();
   5087            var hadNewLine = false;
   5088            if(comment.isBlockComment) {
   5089                if(this.emitState.column == 0) {
   5090                    this.emitIndent();
   5091                }
   5092                this.writeToOutput(text[0]);
   5093                if(text.length > 1 || comment.endsLine) {
   5094                    this.writeLineToOutput("");
   5095                    for(var i = 1; i < text.length; i++) {
   5096                        this.emitIndent();
   5097                        this.writeLineToOutput(text[i]);
   5098                    }
   5099                    hadNewLine = true;
   5100                }
   5101            } else {
   5102                if(this.emitState.column == 0) {
   5103                    this.emitIndent();
   5104                }
   5105                this.writeLineToOutput(text[0]);
   5106                hadNewLine = true;
   5107            }
   5108            if(hadNewLine) {
   5109                this.emitIndent();
   5110            } else {
   5111                this.writeToOutput(" ");
   5112            }
   5113            this.recordSourceMappingEnd(comment);
   5114        };
   5115        Emitter.prototype.emitParensAndCommentsInPlace = function (ast, pre) {
   5116            var comments = pre ? ast.preComments : ast.postComments;
   5117            if(ast.isParenthesized && !pre) {
   5118                this.writeToOutput(")");
   5119            }
   5120            if(this.emitOptions.emitComments && comments && comments.length != 0) {
   5121                for(var i = 0; i < comments.length; i++) {
   5122                    this.emitCommentInPlace(comments[i]);
   5123                }
   5124            }
   5125            if(ast.isParenthesized && pre) {
   5126                this.writeToOutput("(");
   5127            }
   5128        };
   5129        Emitter.prototype.emitObjectLiteral = function (content) {
   5130            this.writeLineToOutput("{");
   5131            this.indenter.increaseIndent();
   5132            var inObjectLiteral = this.setInObjectLiteral(true);
   5133            this.emitJavascriptList(content, ",", TypeScript.TokenID.Comma, true, false, false);
   5134            this.setInObjectLiteral(inObjectLiteral);
   5135            this.indenter.decreaseIndent();
   5136            this.emitIndent();
   5137            this.writeToOutput("}");
   5138        };
   5139        Emitter.prototype.emitArrayLiteral = function (content) {
   5140            this.writeToOutput("[");
   5141            if(content) {
   5142                this.writeLineToOutput("");
   5143                this.indenter.increaseIndent();
   5144                this.emitJavascriptList(content, ", ", TypeScript.TokenID.Comma, true, false, false);
   5145                this.indenter.decreaseIndent();
   5146                this.emitIndent();
   5147            }
   5148            this.writeToOutput("]");
   5149        };
   5150        Emitter.prototype.emitNew = function (target, args) {
   5151            this.writeToOutput("new ");
   5152            if(target.nodeType == TypeScript.NodeType.TypeRef) {
   5153                var typeRef = target;
   5154                if(typeRef.arrayCount) {
   5155                    this.writeToOutput("Array()");
   5156                } else {
   5157                    this.emitJavascript(typeRef.term, TypeScript.TokenID.Tilde, false);
   5158                    this.writeToOutput("()");
   5159                }
   5160            } else {
   5161                this.emitJavascript(target, TypeScript.TokenID.Tilde, false);
   5162                this.recordSourceMappingStart(args);
   5163                this.writeToOutput("(");
   5164                this.emitJavascriptList(args, ", ", TypeScript.TokenID.Comma, false, false, false);
   5165                this.writeToOutput(")");
   5166                this.recordSourceMappingEnd(args);
   5167            }
   5168        };
   5169        Emitter.prototype.tryEmitConstant = function (dotExpr) {
   5170            if(!this.emitOptions.propagateConstants) {
   5171                return false;
   5172            }
   5173            var propertyName = dotExpr.operand2;
   5174            if(propertyName && propertyName.sym && propertyName.sym.isVariable()) {
   5175                if(TypeScript.hasFlag(propertyName.sym.flags, TypeScript.SymbolFlags.Constant)) {
   5176                    if(propertyName.sym.declAST) {
   5177                        var boundDecl = propertyName.sym.declAST;
   5178                        if(boundDecl.init && (boundDecl.init.nodeType == TypeScript.NodeType.NumberLit)) {
   5179                            var numLit = boundDecl.init;
   5180                            this.writeToOutput(numLit.value.toString());
   5181                            var comment = " /* ";
   5182                            comment += propertyName.actualText;
   5183                            comment += " */ ";
   5184                            this.writeToOutput(comment);
   5185                            return true;
   5186                        }
   5187                    }
   5188                }
   5189            }
   5190            return false;
   5191        };
   5192        Emitter.prototype.emitCall = function (callNode, target, args) {
   5193            if(!this.emitSuperCall(callNode)) {
   5194                if(!TypeScript.hasFlag(callNode.flags, TypeScript.ASTFlags.ClassBaseConstructorCall)) {
   5195                    if(target.nodeType == TypeScript.NodeType.FuncDecl && !target.isParenthesized) {
   5196                        this.writeToOutput("(");
   5197                    }
   5198                    if(callNode.target.nodeType == TypeScript.NodeType.Super && this.emitState.container == EmitContainer.Constructor) {
   5199                        this.writeToOutput("_super.call");
   5200                    } else {
   5201                        this.emitJavascript(target, TypeScript.TokenID.OpenParen, false);
   5202                    }
   5203                    if(target.nodeType == TypeScript.NodeType.FuncDecl && !target.isParenthesized) {
   5204                        this.writeToOutput(")");
   5205                    }
   5206                    this.recordSourceMappingStart(args);
   5207                    this.writeToOutput("(");
   5208                    if(callNode.target.nodeType == TypeScript.NodeType.Super && this.emitState.container == EmitContainer.Constructor) {
   5209                        this.writeToOutput("this");
   5210                        if(args && args.members.length) {
   5211                            this.writeToOutput(", ");
   5212                        }
   5213                    }
   5214                    this.emitJavascriptList(args, ", ", TypeScript.TokenID.Comma, false, false, false);
   5215                    this.writeToOutput(")");
   5216                    this.recordSourceMappingEnd(args);
   5217                } else {
   5218                    this.indenter.decreaseIndent();
   5219                    this.indenter.decreaseIndent();
   5220                    var constructorCall = new TypeScript.ASTList();
   5221                    constructorCall.members[0] = callNode;
   5222                    this.emitConstructorCalls(constructorCall, this.thisClassNode);
   5223                    this.indenter.increaseIndent();
   5224                    this.indenter.increaseIndent();
   5225                }
   5226            }
   5227        };
   5228        Emitter.prototype.emitConstructorCalls = function (bases, classDecl) {
   5229            if(bases == null) {
   5230                return;
   5231            }
   5232            var basesLen = bases.members.length;
   5233            this.recordSourceMappingStart(classDecl);
   5234            for(var i = 0; i < basesLen; i++) {
   5235                var baseExpr = bases.members[i];
   5236                var baseSymbol = null;
   5237                if(baseExpr.nodeType == TypeScript.NodeType.Call) {
   5238                    baseSymbol = (baseExpr).target.type.symbol;
   5239                } else {
   5240                    baseSymbol = baseExpr.type.symbol;
   5241                }
   5242                var baseName = baseSymbol.name;
   5243                if(baseSymbol.declModule != classDecl.type.symbol.declModule) {
   5244                    baseName = baseSymbol.fullName();
   5245                }
   5246                if(baseExpr.nodeType == TypeScript.NodeType.Call) {
   5247                    this.emitIndent();
   5248                    this.writeToOutput("_super.call(this");
   5249                    var args = (baseExpr).arguments;
   5250                    if(args && (args.members.length > 0)) {
   5251                        this.writeToOutput(", ");
   5252                        this.emitJavascriptList(args, ", ", TypeScript.TokenID.Comma, false, false, false);
   5253                    }
   5254                    this.writeToOutput(")");
   5255                } else {
   5256                    if(baseExpr.type && (baseExpr.type.isClassInstance())) {
   5257                        this.emitIndent();
   5258                        this.writeToOutput(classDecl.name.actualText + "._super.constructor");
   5259                        this.writeToOutput(".call(this)");
   5260                    }
   5261                }
   5262            }
   5263            this.recordSourceMappingEnd(classDecl);
   5264        };
   5265        Emitter.prototype.emitInnerFunction = function (funcDecl, printName, isMember, bases, hasSelfRef, classDecl) {
   5266            var isClassConstructor = funcDecl.isConstructor && TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.ClassMethod);
   5267            var hasNonObjectBaseType = isClassConstructor && TypeScript.hasFlag(this.thisClassNode.type.instanceType.typeFlags, TypeScript.TypeFlags.HasBaseType) && !TypeScript.hasFlag(this.thisClassNode.type.instanceType.typeFlags, TypeScript.TypeFlags.HasBaseTypeOfObject);
   5268            var classPropertiesMustComeAfterSuperCall = hasNonObjectBaseType && TypeScript.hasFlag((this.thisClassNode).varFlags, TypeScript.VarFlags.ClassSuperMustBeFirstCallInConstructor);
   5269            var shouldParenthesize = TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.IsFunctionExpression) && !funcDecl.isParenthesized && !funcDecl.isAccessor() && (TypeScript.hasFlag(funcDecl.flags, TypeScript.ASTFlags.ExplicitSemicolon) || TypeScript.hasFlag(funcDecl.flags, TypeScript.ASTFlags.AutomaticSemicolon));
   5270            this.emitParensAndCommentsInPlace(funcDecl, true);
   5271            if(shouldParenthesize) {
   5272                this.writeToOutput("(");
   5273            }
   5274            this.recordSourceMappingStart(funcDecl);
   5275            if(!(funcDecl.isAccessor() && (funcDecl.accessorSymbol).isObjectLitField)) {
   5276                this.writeToOutput("function ");
   5277            }
   5278            if(printName) {
   5279                var id = funcDecl.getNameText();
   5280                if(id && !funcDecl.isAccessor()) {
   5281                    if(funcDecl.name) {
   5282                        this.recordSourceMappingStart(funcDecl.name);
   5283                    }
   5284                    this.writeToOutput(id);
   5285                    if(funcDecl.name) {
   5286                        this.recordSourceMappingEnd(funcDecl.name);
   5287                    }
   5288                }
   5289            }
   5290            this.writeToOutput("(");
   5291            var argsLen = 0;
   5292            var i = 0;
   5293            var arg;
   5294            var defaultArgs = [];
   5295            if(funcDecl.arguments) {
   5296                var tempContainer = this.setContainer(EmitContainer.Args);
   5297                argsLen = funcDecl.arguments.members.length;
   5298                var printLen = argsLen;
   5299                if(funcDecl.variableArgList) {
   5300                    printLen--;
   5301                }
   5302                for(i = 0; i < printLen; i++) {
   5303                    arg = funcDecl.arguments.members[i];
   5304                    if(arg.init) {
   5305                        defaultArgs.push(arg);
   5306                    }
   5307                    this.emitJavascript(arg, TypeScript.TokenID.OpenParen, false);
   5308                    if(i < (printLen - 1)) {
   5309                        this.writeToOutput(", ");
   5310                    }
   5311                }
   5312                this.setContainer(tempContainer);
   5313            }
   5314            this.writeLineToOutput(") {");
   5315            if(funcDecl.isConstructor) {
   5316                this.recordSourceMappingNameStart("constructor");
   5317            } else {
   5318                if(funcDecl.isGetAccessor()) {
   5319                    this.recordSourceMappingNameStart("get_" + funcDecl.getNameText());
   5320                } else {
   5321                    if(funcDecl.isSetAccessor()) {
   5322                        this.recordSourceMappingNameStart("set_" + funcDecl.getNameText());
   5323                    } else {
   5324                        this.recordSourceMappingNameStart(funcDecl.getNameText());
   5325                    }
   5326                }
   5327            }
   5328            this.indenter.increaseIndent();
   5329            for(i = 0; i < defaultArgs.length; i++) {
   5330                var arg = defaultArgs[i];
   5331                this.emitIndent();
   5332                this.recordSourceMappingStart(arg);
   5333                this.writeToOutput("if (typeof " + arg.id.actualText + " === \"undefined\") { ");
   5334                this.recordSourceMappingStart(arg.id);
   5335                this.writeToOutput(arg.id.actualText);
   5336                this.recordSourceMappingEnd(arg.id);
   5337                this.writeToOutput(" = ");
   5338                this.emitJavascript(arg.init, TypeScript.TokenID.OpenParen, false);
   5339                this.writeLineToOutput("; }");
   5340                this.recordSourceMappingEnd(arg);
   5341            }
   5342            if(funcDecl.isConstructor && ((funcDecl.classDecl).varFlags & TypeScript.VarFlags.MustCaptureThis)) {
   5343                this.writeCaptureThisStatement(funcDecl);
   5344            }
   5345            if(funcDecl.isConstructor && !classPropertiesMustComeAfterSuperCall) {
   5346                if(funcDecl.arguments) {
   5347                    argsLen = funcDecl.arguments.members.length;
   5348                    for(i = 0; i < argsLen; i++) {
   5349                        arg = funcDecl.arguments.members[i];
   5350                        if((arg.varFlags & TypeScript.VarFlags.Property) != TypeScript.VarFlags.None) {
   5351                            this.emitIndent();
   5352                            this.recordSourceMappingStart(arg);
   5353                            this.recordSourceMappingStart(arg.id);
   5354                            this.writeToOutput("this." + arg.id.actualText);
   5355                            this.recordSourceMappingEnd(arg.id);
   5356                            this.writeToOutput(" = ");
   5357                            this.recordSourceMappingStart(arg.id);
   5358                            this.writeToOutput(arg.id.actualText);
   5359                            this.recordSourceMappingEnd(arg.id);
   5360                            this.writeLineToOutput(";");
   5361                            this.recordSourceMappingEnd(arg);
   5362                        }
   5363                    }
   5364                }
   5365                if(!TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.ClassMethod)) {
   5366                    this.emitConstructorCalls(bases, classDecl);
   5367                }
   5368            }
   5369            if(hasSelfRef) {
   5370                this.writeCaptureThisStatement(funcDecl);
   5371            }
   5372            if(funcDecl.variableArgList) {
   5373                argsLen = funcDecl.arguments.members.length;
   5374                var lastArg = funcDecl.arguments.members[argsLen - 1];
   5375                this.emitIndent();
   5376                this.recordSourceMappingStart(lastArg);
   5377                this.writeToOutput("var ");
   5378                this.recordSourceMappingStart(lastArg.id);
   5379                this.writeToOutput(lastArg.id.actualText);
   5380                this.recordSourceMappingEnd(lastArg.id);
   5381                this.writeLineToOutput(" = [];");
   5382                this.recordSourceMappingEnd(lastArg);
   5383                this.emitIndent();
   5384                this.writeToOutput("for (");
   5385                this.recordSourceMappingStart(lastArg);
   5386                this.writeToOutput("var _i = 0;");
   5387                this.recordSourceMappingEnd(lastArg);
   5388                this.writeToOutput(" ");
   5389                this.recordSourceMappingStart(lastArg);
   5390                this.writeToOutput("_i < (arguments.length - " + (argsLen - 1) + ")");
   5391                this.recordSourceMappingEnd(lastArg);
   5392                this.writeToOutput("; ");
   5393                this.recordSourceMappingStart(lastArg);
   5394                this.writeToOutput("_i++");
   5395                this.recordSourceMappingEnd(lastArg);
   5396                this.writeLineToOutput(") {");
   5397                this.indenter.increaseIndent();
   5398                this.emitIndent();
   5399                this.recordSourceMappingStart(lastArg);
   5400                this.writeToOutput(lastArg.id.actualText + "[_i] = arguments[_i + " + (argsLen - 1) + "];");
   5401                this.recordSourceMappingEnd(lastArg);
   5402                this.writeLineToOutput("");
   5403                this.indenter.decreaseIndent();
   5404                this.emitIndent();
   5405                this.writeLineToOutput("}");
   5406            }
   5407            if(funcDecl.isConstructor && TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.ClassMethod) && !classPropertiesMustComeAfterSuperCall) {
   5408                var nProps = (this.thisClassNode.members).members.length;
   5409                for(var i = 0; i < nProps; i++) {
   5410                    if((this.thisClassNode.members).members[i].nodeType == TypeScript.NodeType.VarDecl) {
   5411                        var varDecl = (this.thisClassNode.members).members[i];
   5412                        if(!TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.Static) && varDecl.init) {
   5413                            this.emitIndent();
   5414                            this.emitJavascriptVarDecl(varDecl, TypeScript.TokenID.Tilde);
   5415                            this.writeLineToOutput("");
   5416                        }
   5417                    }
   5418                }
   5419            }
   5420            this.emitBareJavascriptStatements(funcDecl.bod, classPropertiesMustComeAfterSuperCall);
   5421            this.indenter.decreaseIndent();
   5422            this.emitIndent();
   5423            this.recordSourceMappingStart(funcDecl.endingToken);
   5424            this.writeToOutput("}");
   5425            this.recordSourceMappingNameEnd();
   5426            this.recordSourceMappingEnd(funcDecl.endingToken);
   5427            this.recordSourceMappingEnd(funcDecl);
   5428            if(shouldParenthesize) {
   5429                this.writeToOutput(")");
   5430            }
   5431            this.recordSourceMappingEnd(funcDecl);
   5432            this.emitParensAndCommentsInPlace(funcDecl, false);
   5433            if(!isMember && !TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.IsFunctionExpression) && (TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Definition) || funcDecl.isConstructor)) {
   5434                this.writeLineToOutput("");
   5435            } else {
   5436                if(TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.IsFunctionExpression)) {
   5437                    if(TypeScript.hasFlag(funcDecl.flags, TypeScript.ASTFlags.ExplicitSemicolon) || TypeScript.hasFlag(funcDecl.flags, TypeScript.ASTFlags.AutomaticSemicolon)) {
   5438                        this.writeLineToOutput(";");
   5439                    }
   5440                }
   5441            }
   5442        };
   5443        Emitter.prototype.emitJavascriptModule = function (moduleDecl) {
   5444            var modName = moduleDecl.name.actualText;
   5445            if(TypeScript.isTSFile(modName)) {
   5446                moduleDecl.name.setText(modName.substring(0, modName.length - 3));
   5447            } else {
   5448                if(TypeScript.isSTRFile(modName)) {
   5449                    moduleDecl.name.setText(modName.substring(0, modName.length - 4));
   5450                }
   5451            }
   5452            if(!TypeScript.hasFlag(moduleDecl.modFlags, TypeScript.ModuleFlags.Ambient)) {
   5453                var isDynamicMod = TypeScript.hasFlag(moduleDecl.modFlags, TypeScript.ModuleFlags.IsDynamic);
   5454                var prevOutFile = this.outfile;
   5455                var prevOutFileName = this.emittingFileName;
   5456                var prevAllSourceMappers = this.allSourceMappers;
   5457                var prevSourceMapper = this.sourceMapper;
   5458                var prevColumn = this.emitState.column;
   5459                var prevLine = this.emitState.line;
   5460                var temp = this.setContainer(EmitContainer.Module);
   5461                var svModuleName = this.moduleName;
   5462                var isExported = TypeScript.hasFlag(moduleDecl.modFlags, TypeScript.ModuleFlags.Exported);
   5463                this.moduleDeclList[this.moduleDeclList.length] = moduleDecl;
   5464                var isWholeFile = TypeScript.hasFlag(moduleDecl.modFlags, TypeScript.ModuleFlags.IsWholeFile);
   5465                this.moduleName = moduleDecl.name.actualText;
   5466                if(isDynamicMod) {
   5467                    var tsModFileName = TypeScript.stripQuotes(moduleDecl.name.actualText);
   5468                    var modFilePath = TypeScript.trimModName(tsModFileName) + ".js";
   5469                    modFilePath = this.emitOptions.mapOutputFileName(modFilePath, TypeScript.TypeScriptCompiler.mapToJSFileName);
   5470                    if(this.emitOptions.ioHost) {
   5471                        if(TypeScript.switchToForwardSlashes(modFilePath) != TypeScript.switchToForwardSlashes(this.emittingFileName)) {
   5472                            this.emittingFileName = modFilePath;
   5473                            var useUTF8InOutputfile = moduleDecl.containsUnicodeChar || (this.emitOptions.emitComments && moduleDecl.containsUnicodeCharInComment);
   5474                            this.outfile = this.createFile(this.emittingFileName, useUTF8InOutputfile);
   5475                            if(prevSourceMapper != null) {
   5476                                this.allSourceMappers = [];
   5477                                var sourceMappingFile = this.createFile(this.emittingFileName + TypeScript.SourceMapper.MapFileExtension, false);
   5478                                this.setSourceMappings(new TypeScript.SourceMapper(tsModFileName, this.emittingFileName, this.outfile, sourceMappingFile, this.errorReporter));
   5479                                this.emitState.column = 0;
   5480                                this.emitState.line = 0;
   5481                            }
   5482                        } else {
   5483                            TypeScript.CompilerDiagnostics.assert(this.emitOptions.outputMany, "Cannot have dynamic modules compiling into single file");
   5484                        }
   5485                    }
   5486                    this.setContainer(EmitContainer.DynamicModule);
   5487                    this.recordSourceMappingStart(moduleDecl);
   5488                    if(TypeScript.moduleGenTarget == TypeScript.ModuleGenTarget.Asynchronous) {
   5489                        var dependencyList = "[\"require\", \"exports\"";
   5490                        var importList = "require, exports";
   5491                        var importStatement = null;
   5492                        for(var i = 0; i < (moduleDecl.mod).importedModules.length; i++) {
   5493                            importStatement = (moduleDecl.mod).importedModules[i];
   5494                            if(importStatement.id.sym && !(importStatement.id.sym).onlyReferencedAsTypeRef) {
   5495                                if(i <= (moduleDecl.mod).importedModules.length - 1) {
   5496                                    dependencyList += ", ";
   5497                                    importList += ", ";
   5498                                }
   5499                                importList += "__" + importStatement.id.actualText + "__";
   5500                                dependencyList += importStatement.firstAliasedModToString();
   5501                            }
   5502                        }
   5503                        for(var i = 0; i < moduleDecl.amdDependencies.length; i++) {
   5504                            dependencyList += ", \"" + moduleDecl.amdDependencies[i] + "\"";
   5505                        }
   5506                        dependencyList += "]";
   5507                        this.writeLineToOutput("define(" + dependencyList + "," + " function(" + importList + ") {");
   5508                    } else {
   5509                    }
   5510                } else {
   5511                    if(!isExported) {
   5512                        this.recordSourceMappingStart(moduleDecl);
   5513                        this.writeToOutput("var ");
   5514                        this.recordSourceMappingStart(moduleDecl.name);
   5515                        this.writeToOutput(this.moduleName);
   5516                        this.recordSourceMappingEnd(moduleDecl.name);
   5517                        this.writeLineToOutput(";");
   5518                        this.recordSourceMappingEnd(moduleDecl);
   5519                        this.emitIndent();
   5520                    }
   5521                    this.writeToOutput("(");
   5522                    this.recordSourceMappingStart(moduleDecl);
   5523                    this.writeToOutput("function (");
   5524                    this.recordSourceMappingStart(moduleDecl.name);
   5525                    this.writeToOutput(this.moduleName);
   5526                    this.recordSourceMappingEnd(moduleDecl.name);
   5527                    this.writeLineToOutput(") {");
   5528                }
   5529                if(!isWholeFile) {
   5530                    this.recordSourceMappingNameStart(this.moduleName);
   5531                }
   5532                if(!isDynamicMod || TypeScript.moduleGenTarget == TypeScript.ModuleGenTarget.Asynchronous) {
   5533                    this.indenter.increaseIndent();
   5534                }
   5535                if(moduleDecl.modFlags & TypeScript.ModuleFlags.MustCaptureThis) {
   5536                    this.writeCaptureThisStatement(moduleDecl);
   5537                }
   5538                this.emitJavascriptList(moduleDecl.members, null, TypeScript.TokenID.Semicolon, true, false, false);
   5539                if(!isDynamicMod || TypeScript.moduleGenTarget == TypeScript.ModuleGenTarget.Asynchronous) {
   5540                    this.indenter.decreaseIndent();
   5541                }
   5542                this.emitIndent();
   5543                if(isDynamicMod) {
   5544                    if(TypeScript.moduleGenTarget == TypeScript.ModuleGenTarget.Asynchronous) {
   5545                        this.writeLineToOutput("})");
   5546                    } else {
   5547                    }
   5548                    if(!isWholeFile) {
   5549                        this.recordSourceMappingNameEnd();
   5550                    }
   5551                    this.recordSourceMappingEnd(moduleDecl);
   5552                    if(this.outfile != prevOutFile) {
   5553                        this.Close();
   5554                        if(prevSourceMapper != null) {
   5555                            this.allSourceMappers = prevAllSourceMappers;
   5556                            this.sourceMapper = prevSourceMapper;
   5557                            this.emitState.column = prevColumn;
   5558                            this.emitState.line = prevLine;
   5559                        }
   5560                        this.outfile = prevOutFile;
   5561                        this.emittingFileName = prevOutFileName;
   5562                    }
   5563                } else {
   5564                    var containingMod = null;
   5565                    if(moduleDecl.type && moduleDecl.type.symbol.container && moduleDecl.type.symbol.container.declAST) {
   5566                        containingMod = moduleDecl.type.symbol.container.declAST;
   5567                    }
   5568                    var parentIsDynamic = containingMod && TypeScript.hasFlag(containingMod.modFlags, TypeScript.ModuleFlags.IsDynamic);
   5569                    this.recordSourceMappingStart(moduleDecl.endingToken);
   5570                    if(temp == EmitContainer.Prog && isExported) {
   5571                        this.writeToOutput("}");
   5572                        if(!isWholeFile) {
   5573                            this.recordSourceMappingNameEnd();
   5574                        }
   5575                        this.recordSourceMappingEnd(moduleDecl.endingToken);
   5576                        this.writeLineToOutput(")(this." + this.moduleName + " || (this." + this.moduleName + " = {}));");
   5577                    } else {
   5578                        if(isExported || temp == EmitContainer.Prog) {
   5579                            var dotMod = svModuleName != "" ? (parentIsDynamic ? "exports" : svModuleName) + "." : svModuleName;
   5580                            this.writeToOutput("}");
   5581                            if(!isWholeFile) {
   5582                                this.recordSourceMappingNameEnd();
   5583                            }
   5584                            this.recordSourceMappingEnd(moduleDecl.endingToken);
   5585                            this.writeLineToOutput(")(" + dotMod + this.moduleName + " || (" + dotMod + this.moduleName + " = {}));");
   5586                        } else {
   5587                            if(!isExported && temp != EmitContainer.Prog) {
   5588                                this.writeToOutput("}");
   5589                                if(!isWholeFile) {
   5590                                    this.recordSourceMappingNameEnd();
   5591                                }
   5592                                this.recordSourceMappingEnd(moduleDecl.endingToken);
   5593                                this.writeLineToOutput(")(" + this.moduleName + " || (" + this.moduleName + " = {}));");
   5594                            } else {
   5595                                this.writeToOutput("}");
   5596                                if(!isWholeFile) {
   5597                                    this.recordSourceMappingNameEnd();
   5598                                }
   5599                                this.recordSourceMappingEnd(moduleDecl.endingToken);
   5600                                this.writeLineToOutput(")();");
   5601                            }
   5602                        }
   5603                    }
   5604                    this.recordSourceMappingEnd(moduleDecl);
   5605                    if(temp != EmitContainer.Prog && isExported) {
   5606                        this.emitIndent();
   5607                        this.recordSourceMappingStart(moduleDecl);
   5608                        if(parentIsDynamic) {
   5609                            this.writeLineToOutput("var " + this.moduleName + " = exports." + this.moduleName + ";");
   5610                        } else {
   5611                            this.writeLineToOutput("var " + this.moduleName + " = " + svModuleName + "." + this.moduleName + ";");
   5612                        }
   5613                        this.recordSourceMappingEnd(moduleDecl);
   5614                    }
   5615                }
   5616                this.setContainer(temp);
   5617                this.moduleName = svModuleName;
   5618                this.moduleDeclList.length--;
   5619            }
   5620        };
   5621        Emitter.prototype.emitIndex = function (operand1, operand2) {
   5622            var temp = this.setInObjectLiteral(false);
   5623            this.emitJavascript(operand1, TypeScript.TokenID.Tilde, false);
   5624            this.writeToOutput("[");
   5625            this.emitJavascriptList(operand2, ", ", TypeScript.TokenID.Comma, false, false, false);
   5626            this.writeToOutput("]");
   5627            this.setInObjectLiteral(temp);
   5628        };
   5629        Emitter.prototype.emitStringLiteral = function (text) {
   5630            this.writeToOutput(text);
   5631        };
   5632        Emitter.prototype.emitJavascriptFunction = function (funcDecl) {
   5633            if(TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Signature) || funcDecl.isOverload) {
   5634                return;
   5635            }
   5636            var temp;
   5637            var tempFnc = this.thisFnc;
   5638            this.thisFnc = funcDecl;
   5639            if(funcDecl.isConstructor) {
   5640                temp = this.setContainer(EmitContainer.Constructor);
   5641            } else {
   5642                temp = this.setContainer(EmitContainer.Function);
   5643            }
   5644            var bases = null;
   5645            var hasSelfRef = false;
   5646            var funcName = funcDecl.getNameText();
   5647            if((this.emitState.inObjectLiteral || !funcDecl.isAccessor()) && ((temp != EmitContainer.Constructor) || ((funcDecl.fncFlags & TypeScript.FncFlags.Method) == TypeScript.FncFlags.None))) {
   5648                var tempLit = this.setInObjectLiteral(false);
   5649                if(this.thisClassNode) {
   5650                    bases = this.thisClassNode.extendsList;
   5651                }
   5652                hasSelfRef = Emitter.shouldCaptureThis(funcDecl);
   5653                this.recordSourceMappingStart(funcDecl);
   5654                if(TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Exported | TypeScript.FncFlags.ClassPropertyMethodExported) && funcDecl.type.symbol.container == this.checker.gloMod && !funcDecl.isConstructor) {
   5655                    this.writeToOutput("this." + funcName + " = ");
   5656                    this.emitInnerFunction(funcDecl, false, false, bases, hasSelfRef, this.thisClassNode);
   5657                } else {
   5658                    this.emitInnerFunction(funcDecl, (funcDecl.name && !funcDecl.name.isMissing()), false, bases, hasSelfRef, this.thisClassNode);
   5659                }
   5660                this.setInObjectLiteral(tempLit);
   5661            }
   5662            this.setContainer(temp);
   5663            this.thisFnc = tempFnc;
   5664            if(TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Definition)) {
   5665                if(TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Static)) {
   5666                    if(this.thisClassNode) {
   5667                        if(funcDecl.isAccessor()) {
   5668                            this.emitPropertyAccessor(funcDecl, this.thisClassNode.name.actualText, false);
   5669                        } else {
   5670                            this.emitIndent();
   5671                            this.recordSourceMappingStart(funcDecl);
   5672                            this.writeLineToOutput(this.thisClassNode.name.actualText + "." + funcName + " = " + funcName + ";");
   5673                            this.recordSourceMappingEnd(funcDecl);
   5674                        }
   5675                    }
   5676                } else {
   5677                    if((this.emitState.container == EmitContainer.Module || this.emitState.container == EmitContainer.DynamicModule) && TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Exported | TypeScript.FncFlags.ClassPropertyMethodExported)) {
   5678                        this.emitIndent();
   5679                        var modName = this.emitState.container == EmitContainer.Module ? this.moduleName : "exports";
   5680                        this.recordSourceMappingStart(funcDecl);
   5681                        this.writeLineToOutput(modName + "." + funcName + " = " + funcName + ";");
   5682                        this.recordSourceMappingEnd(funcDecl);
   5683                    }
   5684                }
   5685            }
   5686        };
   5687        Emitter.prototype.emitAmbientVarDecl = function (varDecl) {
   5688            if(varDecl.init) {
   5689                this.emitParensAndCommentsInPlace(varDecl, true);
   5690                this.recordSourceMappingStart(varDecl);
   5691                this.recordSourceMappingStart(varDecl.id);
   5692                this.writeToOutput(varDecl.id.actualText);
   5693                this.recordSourceMappingEnd(varDecl.id);
   5694                this.writeToOutput(" = ");
   5695                this.emitJavascript(varDecl.init, TypeScript.TokenID.Comma, false);
   5696                this.recordSourceMappingEnd(varDecl);
   5697                this.writeToOutput(";");
   5698                this.emitParensAndCommentsInPlace(varDecl, false);
   5699            }
   5700        };
   5701        Emitter.prototype.varListCount = function () {
   5702            return this.varListCountStack[this.varListCountStack.length - 1];
   5703        };
   5704        Emitter.prototype.emitVarDeclVar = function () {
   5705            if(this.varListCount() >= 0) {
   5706                this.writeToOutput("var ");
   5707                this.setInVarBlock(-this.varListCount());
   5708            }
   5709            return true;
   5710        };
   5711        Emitter.prototype.onEmitVar = function () {
   5712            if(this.varListCount() > 0) {
   5713                this.setInVarBlock(this.varListCount() - 1);
   5714            } else {
   5715                if(this.varListCount() < 0) {
   5716                    this.setInVarBlock(this.varListCount() + 1);
   5717                }
   5718            }
   5719        };
   5720        Emitter.prototype.emitJavascriptVarDecl = function (varDecl, tokenId) {
   5721            if((varDecl.varFlags & TypeScript.VarFlags.Ambient) == TypeScript.VarFlags.Ambient) {
   5722                this.emitAmbientVarDecl(varDecl);
   5723                this.onEmitVar();
   5724            } else {
   5725                var sym = varDecl.sym;
   5726                var hasInitializer = (varDecl.init != null);
   5727                this.emitParensAndCommentsInPlace(varDecl, true);
   5728                this.recordSourceMappingStart(varDecl);
   5729                if(sym && sym.isMember() && sym.container && (sym.container.kind() == TypeScript.SymbolKind.Type)) {
   5730                    var type = (sym.container).type;
   5731                    if(type.isClass() && (!TypeScript.hasFlag(sym.flags, TypeScript.SymbolFlags.ModuleMember))) {
   5732                        if(this.emitState.container != EmitContainer.Args) {
   5733                            if(TypeScript.hasFlag(sym.flags, TypeScript.SymbolFlags.Static)) {
   5734                                this.writeToOutput(sym.container.name + ".");
   5735                            } else {
   5736                                this.writeToOutput("this.");
   5737                            }
   5738                        }
   5739                    } else {
   5740                        if(type.hasImplementation()) {
   5741                            if(!TypeScript.hasFlag(sym.flags, TypeScript.SymbolFlags.Exported) && (sym.container == this.checker.gloMod || !TypeScript.hasFlag(sym.flags, TypeScript.SymbolFlags.Property))) {
   5742                                this.emitVarDeclVar();
   5743                            } else {
   5744                                if(TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.LocalStatic)) {
   5745                                    this.writeToOutput(".");
   5746                                } else {
   5747                                    if(this.emitState.container == EmitContainer.DynamicModule) {
   5748                                        this.writeToOutput("exports.");
   5749                                    } else {
   5750                                        this.writeToOutput(this.moduleName + ".");
   5751                                    }
   5752                                }
   5753                            }
   5754                        } else {
   5755                            if(tokenId != TypeScript.TokenID.OpenParen) {
   5756                                if(TypeScript.hasFlag(sym.flags, TypeScript.SymbolFlags.Exported) && sym.container == this.checker.gloMod) {
   5757                                    this.writeToOutput("this.");
   5758                                } else {
   5759                                    this.emitVarDeclVar();
   5760                                }
   5761                            }
   5762                        }
   5763                    }
   5764                } else {
   5765                    if(tokenId != TypeScript.TokenID.OpenParen) {
   5766                        this.emitVarDeclVar();
   5767                    }
   5768                }
   5769                this.recordSourceMappingStart(varDecl.id);
   5770                this.writeToOutput(varDecl.id.actualText);
   5771                this.recordSourceMappingEnd(varDecl.id);
   5772                if(hasInitializer) {
   5773                    this.writeToOutputTrimmable(" = ");
   5774                    this.varListCountStack.push(0);
   5775                    this.emitJavascript(varDecl.init, TypeScript.TokenID.Comma, false);
   5776                    this.varListCountStack.pop();
   5777                }
   5778                this.onEmitVar();
   5779                if((tokenId != TypeScript.TokenID.OpenParen)) {
   5780                    if(this.varListCount() < 0) {
   5781                        this.writeToOutput(", ");
   5782                    } else {
   5783                        if(tokenId != TypeScript.TokenID.For) {
   5784                            this.writeToOutputTrimmable(";");
   5785                        }
   5786                    }
   5787                }
   5788                this.recordSourceMappingEnd(varDecl);
   5789                this.emitParensAndCommentsInPlace(varDecl, false);
   5790            }
   5791        };
   5792        Emitter.prototype.declEnclosed = function (moduleDecl) {
   5793            if(moduleDecl == null) {
   5794                return true;
   5795            }
   5796            for(var i = 0, len = this.moduleDeclList.length; i < len; i++) {
   5797                if(this.moduleDeclList[i] == moduleDecl) {
   5798                    return true;
   5799                }
   5800            }
   5801            return false;
   5802        };
   5803        Emitter.prototype.emitJavascriptName = function (name, addThis) {
   5804            var sym = name.sym;
   5805            this.emitParensAndCommentsInPlace(name, true);
   5806            this.recordSourceMappingStart(name);
   5807            if(!name.isMissing()) {
   5808                if(addThis && (this.emitState.container != EmitContainer.Args) && sym) {
   5809                    if(sym.container && (sym.container.name != TypeScript.globalId)) {
   5810                        if(TypeScript.hasFlag(sym.flags, TypeScript.SymbolFlags.Static) && (TypeScript.hasFlag(sym.flags, TypeScript.SymbolFlags.Property))) {
   5811                            if(sym.declModule && TypeScript.hasFlag(sym.declModule.modFlags, TypeScript.ModuleFlags.IsDynamic)) {
   5812                                this.writeToOutput("exports.");
   5813                            } else {
   5814                                this.writeToOutput(sym.container.name + ".");
   5815                            }
   5816                        } else {
   5817                            if(sym.kind() == TypeScript.SymbolKind.Field) {
   5818                                var fieldSym = sym;
   5819                                if(TypeScript.hasFlag(fieldSym.flags, TypeScript.SymbolFlags.ModuleMember)) {
   5820                                    if((sym.container != this.checker.gloMod) && ((TypeScript.hasFlag(sym.flags, TypeScript.SymbolFlags.Property)) || TypeScript.hasFlag(sym.flags, TypeScript.SymbolFlags.Exported))) {
   5821                                        if(TypeScript.hasFlag(sym.declModule.modFlags, TypeScript.ModuleFlags.IsDynamic)) {
   5822                                            this.writeToOutput("exports.");
   5823                                        } else {
   5824                                            this.writeToOutput(sym.container.name + ".");
   5825                                        }
   5826                                    }
   5827                                } else {
   5828                                    if(sym.isInstanceProperty()) {
   5829                                        this.emitThis();
   5830                                        this.writeToOutput(".");
   5831                                    }
   5832                                }
   5833                            } else {
   5834                                if(sym.kind() == TypeScript.SymbolKind.Type) {
   5835                                    if(sym.isInstanceProperty()) {
   5836                                        var typeSym = sym;
   5837                                        var type = typeSym.type;
   5838                                        if(type.call && !TypeScript.hasFlag(sym.flags, TypeScript.SymbolFlags.ModuleMember)) {
   5839                                            this.emitThis();
   5840                                            this.writeToOutput(".");
   5841                                        }
   5842                                    } else {
   5843                                        if((sym.unitIndex != this.checker.locationInfo.unitIndex) || (!this.declEnclosed(sym.declModule))) {
   5844                                            this.writeToOutput(sym.container.name + ".");
   5845                                        }
   5846                                    }
   5847                                }
   5848                            }
   5849                        }
   5850                    } else {
   5851                        if(sym.container == this.checker.gloMod && TypeScript.hasFlag(sym.flags, TypeScript.SymbolFlags.Exported) && !TypeScript.hasFlag(sym.flags, TypeScript.SymbolFlags.Ambient) && !((sym.isType() || sym.isMember()) && sym.declModule && TypeScript.hasFlag(sym.declModule.modFlags, TypeScript.ModuleFlags.Ambient)) && this.emitState.container == EmitContainer.Prog && sym.declAST.nodeType != TypeScript.NodeType.FuncDecl) {
   5852                            this.writeToOutput("this.");
   5853                        }
   5854                    }
   5855                }
   5856                if(sym && sym.declAST && sym.declAST.nodeType == TypeScript.NodeType.ModuleDeclaration && (TypeScript.hasFlag((sym.declAST).modFlags, TypeScript.ModuleFlags.IsDynamic))) {
   5857                    var moduleDecl = sym.declAST;
   5858                    if(TypeScript.moduleGenTarget == TypeScript.ModuleGenTarget.Asynchronous) {
   5859                        this.writeLineToOutput("__" + this.modAliasId + "__;");
   5860                    } else {
   5861                        var modPath = name.actualText;
   5862                        var isAmbient = moduleDecl.mod.symbol.declAST && TypeScript.hasFlag((moduleDecl.mod.symbol.declAST).modFlags, TypeScript.ModuleFlags.Ambient);
   5863                        modPath = isAmbient ? modPath : this.firstModAlias ? this.firstModAlias : TypeScript.quoteBaseName(modPath);
   5864                        modPath = isAmbient ? modPath : (!TypeScript.isRelative(TypeScript.stripQuotes(modPath)) ? TypeScript.quoteStr("./" + TypeScript.stripQuotes(modPath)) : modPath);
   5865                        this.writeToOutput("require(" + modPath + ")");
   5866                    }
   5867                } else {
   5868                    this.writeToOutput(name.actualText);
   5869                }
   5870            }
   5871            this.recordSourceMappingEnd(name);
   5872            this.emitParensAndCommentsInPlace(name, false);
   5873        };
   5874        Emitter.prototype.emitJavascriptStatements = function (stmts, emitEmptyBod) {
   5875            if(stmts) {
   5876                if(stmts.nodeType != TypeScript.NodeType.Block) {
   5877                    var hasContents = (stmts && (stmts.nodeType != TypeScript.NodeType.List || ((stmts).members.length > 0)));
   5878                    if(emitEmptyBod || hasContents) {
   5879                        var hasOnlyBlockStatement = ((stmts.nodeType == TypeScript.NodeType.Block) || ((stmts.nodeType == TypeScript.NodeType.List) && ((stmts).members.length == 1) && ((stmts).members[0].nodeType == TypeScript.NodeType.Block)));
   5880                        this.recordSourceMappingStart(stmts);
   5881                        if(!hasOnlyBlockStatement) {
   5882                            this.writeLineToOutput(" {");
   5883                            this.indenter.increaseIndent();
   5884                        }
   5885                        this.emitJavascriptList(stmts, null, TypeScript.TokenID.Semicolon, true, false, false);
   5886                        if(!hasOnlyBlockStatement) {
   5887                            this.writeLineToOutput("");
   5888                            this.indenter.decreaseIndent();
   5889                            this.emitIndent();
   5890                            this.writeToOutput("}");
   5891                        }
   5892                        this.recordSourceMappingEnd(stmts);
   5893                    }
   5894                } else {
   5895                    this.emitJavascript(stmts, TypeScript.TokenID.Semicolon, true);
   5896                }
   5897            } else {
   5898                if(emitEmptyBod) {
   5899                    this.writeToOutput("{ }");
   5900                }
   5901            }
   5902        };
   5903        Emitter.prototype.emitBareJavascriptStatements = function (stmts, emitClassPropertiesAfterSuperCall) {
   5904            if (typeof emitClassPropertiesAfterSuperCall === "undefined") { emitClassPropertiesAfterSuperCall = false; }
   5905            if(stmts.nodeType != TypeScript.NodeType.Block) {
   5906                if(stmts.nodeType == TypeScript.NodeType.List) {
   5907                    var stmtList = stmts;
   5908                    if((stmtList.members.length == 2) && (stmtList.members[0].nodeType == TypeScript.NodeType.Block) && (stmtList.members[1].nodeType == TypeScript.NodeType.EndCode)) {
   5909                        this.emitJavascript(stmtList.members[0], TypeScript.TokenID.Semicolon, true);
   5910                        this.writeLineToOutput("");
   5911                    } else {
   5912                        this.emitJavascriptList(stmts, null, TypeScript.TokenID.Semicolon, true, false, emitClassPropertiesAfterSuperCall);
   5913                    }
   5914                } else {
   5915                    this.emitJavascript(stmts, TypeScript.TokenID.Semicolon, true);
   5916                }
   5917            } else {
   5918                this.emitJavascript(stmts, TypeScript.TokenID.Semicolon, true);
   5919            }
   5920        };
   5921        Emitter.prototype.recordSourceMappingNameStart = function (name) {
   5922            if(this.sourceMapper) {
   5923                var finalName = name;
   5924                if(!name) {
   5925                    finalName = "";
   5926                } else {
   5927                    if(this.sourceMapper.currentNameIndex.length > 0) {
   5928                        finalName = this.sourceMapper.names[this.sourceMapper.currentNameIndex.length - 1] + "." + name;
   5929                    }
   5930                }
   5931                this.sourceMapper.names.push(finalName);
   5932                this.sourceMapper.currentNameIndex.push(this.sourceMapper.names.length - 1);
   5933            }
   5934        };
   5935        Emitter.prototype.recordSourceMappingNameEnd = function () {
   5936            if(this.sourceMapper) {
   5937                this.sourceMapper.currentNameIndex.pop();
   5938            }
   5939        };
   5940        Emitter.prototype.recordSourceMappingStart = function (ast) {
   5941            if(this.sourceMapper && TypeScript.isValidAstNode(ast)) {
   5942                var lineCol = {
   5943                    line: -1,
   5944                    col: -1
   5945                };
   5946                var sourceMapping = new TypeScript.SourceMapping();
   5947                sourceMapping.start.emittedColumn = this.emitState.column;
   5948                sourceMapping.start.emittedLine = this.emitState.line;
   5949                TypeScript.getSourceLineColFromMap(lineCol, ast.minChar, this.checker.locationInfo.lineMap);
   5950                sourceMapping.start.sourceColumn = lineCol.col;
   5951                sourceMapping.start.sourceLine = lineCol.line;
   5952                TypeScript.getSourceLineColFromMap(lineCol, ast.limChar, this.checker.locationInfo.lineMap);
   5953                sourceMapping.end.sourceColumn = lineCol.col;
   5954                sourceMapping.end.sourceLine = lineCol.line;
   5955                if(this.sourceMapper.currentNameIndex.length > 0) {
   5956                    sourceMapping.nameIndex = this.sourceMapper.currentNameIndex[this.sourceMapper.currentNameIndex.length - 1];
   5957                }
   5958                var siblings = this.sourceMapper.currentMappings[this.sourceMapper.currentMappings.length - 1];
   5959                siblings.push(sourceMapping);
   5960                this.sourceMapper.currentMappings.push(sourceMapping.childMappings);
   5961            }
   5962        };
   5963        Emitter.prototype.recordSourceMappingEnd = function (ast) {
   5964            if(this.sourceMapper && TypeScript.isValidAstNode(ast)) {
   5965                this.sourceMapper.currentMappings.pop();
   5966                var siblings = this.sourceMapper.currentMappings[this.sourceMapper.currentMappings.length - 1];
   5967                var sourceMapping = siblings[siblings.length - 1];
   5968                sourceMapping.end.emittedColumn = this.emitState.column;
   5969                sourceMapping.end.emittedLine = this.emitState.line;
   5970            }
   5971        };
   5972        Emitter.prototype.Close = function () {
   5973            if(this.sourceMapper != null) {
   5974                TypeScript.SourceMapper.EmitSourceMapping(this.allSourceMappers);
   5975            }
   5976            try  {
   5977                this.outfile.Close();
   5978            } catch (ex) {
   5979                this.errorReporter.emitterError(null, ex.message);
   5980            }
   5981        };
   5982        Emitter.prototype.emitJavascriptList = function (ast, delimiter, tokenId, startLine, onlyStatics, emitClassPropertiesAfterSuperCall, emitPrologue, requiresExtendsBlock) {
   5983            if (typeof emitClassPropertiesAfterSuperCall === "undefined") { emitClassPropertiesAfterSuperCall = false; }
   5984            if (typeof emitPrologue === "undefined") { emitPrologue = false; }
   5985            if(ast == null) {
   5986                return;
   5987            } else {
   5988                if(ast.nodeType != TypeScript.NodeType.List) {
   5989                    this.emitPrologue(emitPrologue);
   5990                    this.emitJavascript(ast, tokenId, startLine);
   5991                } else {
   5992                    var list = ast;
   5993                    if(list.members.length == 0) {
   5994                        return;
   5995                    }
   5996                    this.emitParensAndCommentsInPlace(ast, true);
   5997                    var len = list.members.length;
   5998                    for(var i = 0; i < len; i++) {
   5999                        if(emitPrologue) {
   6000                            if(i == 1 || !TypeScript.hasFlag(list.flags, TypeScript.ASTFlags.StrictMode)) {
   6001                                this.emitPrologue(requiresExtendsBlock);
   6002                                emitPrologue = false;
   6003                            }
   6004                        }
   6005                        if(i == 1 && emitClassPropertiesAfterSuperCall) {
   6006                            var constructorDecl = (this.thisClassNode).constructorDecl;
   6007                            if(constructorDecl && constructorDecl.arguments) {
   6008                                var argsLen = constructorDecl.arguments.members.length;
   6009                                for(var iArg = 0; iArg < argsLen; iArg++) {
   6010                                    var arg = constructorDecl.arguments.members[iArg];
   6011                                    if((arg.varFlags & TypeScript.VarFlags.Property) != TypeScript.VarFlags.None) {
   6012                                        this.emitIndent();
   6013                                        this.recordSourceMappingStart(arg);
   6014                                        this.recordSourceMappingStart(arg.id);
   6015                                        this.writeToOutput("this." + arg.id.actualText);
   6016                                        this.recordSourceMappingEnd(arg.id);
   6017                                        this.writeToOutput(" = ");
   6018                                        this.recordSourceMappingStart(arg.id);
   6019                                        this.writeToOutput(arg.id.actualText);
   6020                                        this.recordSourceMappingEnd(arg.id);
   6021                                        this.writeLineToOutput(";");
   6022                                        this.recordSourceMappingEnd(arg);
   6023                                    }
   6024                                }
   6025                            }
   6026                            var nProps = (this.thisClassNode.members).members.length;
   6027                            for(var iMember = 0; iMember < nProps; iMember++) {
   6028                                if((this.thisClassNode.members).members[iMember].nodeType == TypeScript.NodeType.VarDecl) {
   6029                                    var varDecl = (this.thisClassNode.members).members[iMember];
   6030                                    if(!TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.Static) && varDecl.init) {
   6031                                        this.emitIndent();
   6032                                        this.emitJavascriptVarDecl(varDecl, TypeScript.TokenID.Tilde);
   6033                                        this.writeLineToOutput("");
   6034                                    }
   6035                                }
   6036                            }
   6037                        }
   6038                        var emitNode = list.members[i];
   6039                        var isStaticDecl = (emitNode.nodeType == TypeScript.NodeType.FuncDecl && TypeScript.hasFlag((emitNode).fncFlags, TypeScript.FncFlags.Static)) || (emitNode.nodeType == TypeScript.NodeType.VarDecl && TypeScript.hasFlag((emitNode).varFlags, TypeScript.VarFlags.Static));
   6040                        if(onlyStatics ? !isStaticDecl : isStaticDecl) {
   6041                            continue;
   6042                        }
   6043                        this.emitJavascript(emitNode, tokenId, startLine);
   6044                        if(delimiter && (i < (len - 1))) {
   6045                            if(startLine) {
   6046                                this.writeLineToOutput(delimiter);
   6047                            } else {
   6048                                this.writeToOutput(delimiter);
   6049                            }
   6050                        } else {
   6051                            if(startLine && (emitNode.nodeType != TypeScript.NodeType.ModuleDeclaration) && (emitNode.nodeType != TypeScript.NodeType.InterfaceDeclaration) && (!((emitNode.nodeType == TypeScript.NodeType.VarDecl) && ((((emitNode).varFlags) & TypeScript.VarFlags.Ambient) == TypeScript.VarFlags.Ambient) && (((emitNode).init) == null)) && this.varListCount() >= 0) && (emitNode.nodeType != TypeScript.NodeType.Block || (emitNode).isStatementBlock) && (emitNode.nodeType != TypeScript.NodeType.EndCode) && (emitNode.nodeType != TypeScript.NodeType.FuncDecl)) {
   6052                                this.writeLineToOutput("");
   6053                            }
   6054                        }
   6055                    }
   6056                    this.emitParensAndCommentsInPlace(ast, false);
   6057                }
   6058            }
   6059        };
   6060        Emitter.prototype.emitJavascript = function (ast, tokenId, startLine) {
   6061            if(ast == null) {
   6062                return;
   6063            }
   6064            if(startLine && (this.indenter.indentAmt > 0) && (ast.nodeType != TypeScript.NodeType.List) && (ast.nodeType != TypeScript.NodeType.Block)) {
   6065                if((ast.nodeType != TypeScript.NodeType.InterfaceDeclaration) && (!((ast.nodeType == TypeScript.NodeType.VarDecl) && ((((ast).varFlags) & TypeScript.VarFlags.Ambient) == TypeScript.VarFlags.Ambient) && (((ast).init) == null)) && this.varListCount() >= 0) && (ast.nodeType != TypeScript.NodeType.EndCode) && ((ast.nodeType != TypeScript.NodeType.FuncDecl) || (this.emitState.container != EmitContainer.Constructor))) {
   6066                    this.emitIndent();
   6067                }
   6068            }
   6069            ast.emit(this, tokenId, startLine);
   6070            if((tokenId == TypeScript.TokenID.Semicolon) && (ast.nodeType < TypeScript.NodeType.GeneralNode)) {
   6071                this.writeToOutput(";");
   6072            }
   6073        };
   6074        Emitter.prototype.emitPropertyAccessor = function (funcDecl, className, isProto) {
   6075            if(!(funcDecl.accessorSymbol).hasBeenEmitted) {
   6076                var accessorSymbol = funcDecl.accessorSymbol;
   6077                this.emitIndent();
   6078                this.recordSourceMappingStart(funcDecl);
   6079                this.writeLineToOutput("Object.defineProperty(" + className + (isProto ? ".prototype, \"" : ", \"") + funcDecl.name.actualText + "\"" + ", {");
   6080                this.indenter.increaseIndent();
   6081                if(accessorSymbol.getter) {
   6082                    var getter = accessorSymbol.getter.declAST;
   6083                    this.emitIndent();
   6084                    this.recordSourceMappingStart(getter);
   6085                    this.writeToOutput("get: ");
   6086                    this.emitInnerFunction(getter, false, isProto, null, Emitter.shouldCaptureThis(getter), null);
   6087                    this.writeLineToOutput(",");
   6088                }
   6089                if(accessorSymbol.setter) {
   6090                    var setter = accessorSymbol.setter.declAST;
   6091                    this.emitIndent();
   6092                    this.recordSourceMappingStart(setter);
   6093                    this.writeToOutput("set: ");
   6094                    this.emitInnerFunction(setter, false, isProto, null, Emitter.shouldCaptureThis(setter), null);
   6095                    this.writeLineToOutput(",");
   6096                }
   6097                this.emitIndent();
   6098                this.writeLineToOutput("enumerable: true,");
   6099                this.emitIndent();
   6100                this.writeLineToOutput("configurable: true");
   6101                this.indenter.decreaseIndent();
   6102                this.emitIndent();
   6103                this.writeLineToOutput("});");
   6104                this.recordSourceMappingEnd(funcDecl);
   6105                accessorSymbol.hasBeenEmitted = true;
   6106            }
   6107        };
   6108        Emitter.prototype.emitPrototypeMember = function (member, className) {
   6109            if(member.nodeType == TypeScript.NodeType.FuncDecl) {
   6110                var funcDecl = member;
   6111                if(funcDecl.isAccessor()) {
   6112                    this.emitPropertyAccessor(funcDecl, className, true);
   6113                } else {
   6114                    this.emitIndent();
   6115                    this.recordSourceMappingStart(funcDecl);
   6116                    this.writeToOutput(className + ".prototype." + funcDecl.getNameText() + " = ");
   6117                    this.emitInnerFunction(funcDecl, false, true, null, Emitter.shouldCaptureThis(funcDecl), null);
   6118                    this.writeLineToOutput(";");
   6119                }
   6120            } else {
   6121                if(member.nodeType == TypeScript.NodeType.VarDecl) {
   6122                    var varDecl = member;
   6123                    if(varDecl.init) {
   6124                        this.emitIndent();
   6125                        this.recordSourceMappingStart(varDecl);
   6126                        this.recordSourceMappingStart(varDecl.id);
   6127                        this.writeToOutput(className + ".prototype." + varDecl.id.actualText);
   6128                        this.recordSourceMappingEnd(varDecl.id);
   6129                        this.writeToOutput(" = ");
   6130                        this.emitJavascript(varDecl.init, TypeScript.TokenID.Equals, false);
   6131                        this.recordSourceMappingEnd(varDecl);
   6132                        this.writeLineToOutput(";");
   6133                    }
   6134                }
   6135            }
   6136        };
   6137        Emitter.prototype.emitAddBaseMethods = function (className, base, classDecl) {
   6138            if(base.members) {
   6139                var baseSymbol = base.symbol;
   6140                var baseName = baseSymbol.name;
   6141                if(baseSymbol.declModule != classDecl.type.symbol.declModule) {
   6142                    baseName = baseSymbol.fullName();
   6143                }
   6144                base.members.allMembers.map(function (key, s, c) {
   6145                    var sym = s;
   6146                    if((sym.kind() == TypeScript.SymbolKind.Type) && (sym).type.call) {
   6147                        this.recordSourceMappingStart(sym.declAST);
   6148                        this.writeLineToOutput(className + ".prototype." + sym.name + " = " + baseName + ".prototype." + sym.name + ";");
   6149                        this.recordSourceMappingEnd(sym.declAST);
   6150                    }
   6151                }, null);
   6152            }
   6153            if(base.extendsList) {
   6154                for(var i = 0, len = base.extendsList.length; i < len; i++) {
   6155                    this.emitAddBaseMethods(className, base.extendsList[i], classDecl);
   6156                }
   6157            }
   6158        };
   6159        Emitter.prototype.emitJavascriptClass = function (classDecl) {
   6160            if(!TypeScript.hasFlag(classDecl.varFlags, TypeScript.VarFlags.Ambient)) {
   6161                var svClassNode = this.thisClassNode;
   6162                var i = 0;
   6163                this.thisClassNode = classDecl;
   6164                var className = classDecl.name.actualText;
   6165                this.emitParensAndCommentsInPlace(classDecl, true);
   6166                var temp = this.setContainer(EmitContainer.Class);
   6167                this.recordSourceMappingStart(classDecl);
   6168                if(TypeScript.hasFlag(classDecl.varFlags, TypeScript.VarFlags.Exported) && classDecl.type.symbol.container == this.checker.gloMod) {
   6169                    this.writeToOutput("this." + className);
   6170                } else {
   6171                    this.writeToOutput("var " + className);
   6172                }
   6173                var hasBaseClass = classDecl.extendsList && classDecl.extendsList.members.length;
   6174                var baseNameDecl = null;
   6175                var baseName = null;
   6176                if(hasBaseClass) {
   6177                    this.writeLineToOutput(" = (function (_super) {");
   6178                } else {
   6179                    this.writeLineToOutput(" = (function () {");
   6180                }
   6181                this.recordSourceMappingNameStart(className);
   6182                this.indenter.increaseIndent();
   6183                if(hasBaseClass) {
   6184                    baseNameDecl = classDecl.extendsList.members[0];
   6185                    baseName = baseNameDecl.nodeType == TypeScript.NodeType.Call ? (baseNameDecl).target : baseNameDecl;
   6186                    this.emitIndent();
   6187                    this.writeLineToOutput("__extends(" + className + ", _super);");
   6188                }
   6189                this.emitIndent();
   6190                var constrDecl = classDecl.constructorDecl;
   6191                if(constrDecl) {
   6192                    this.emitJavascript(classDecl.constructorDecl, TypeScript.TokenID.OpenParen, false);
   6193                } else {
   6194                    var wroteProps = 0;
   6195                    this.recordSourceMappingStart(classDecl);
   6196                    this.indenter.increaseIndent();
   6197                    this.writeToOutput("function " + classDecl.name.actualText + "() {");
   6198                    this.recordSourceMappingNameStart("constructor");
   6199                    if(hasBaseClass) {
   6200                        this.writeLineToOutput("");
   6201                        this.emitIndent();
   6202                        this.writeLineToOutput("_super.apply(this, arguments);");
   6203                        wroteProps++;
   6204                    }
   6205                    if(classDecl.varFlags & TypeScript.VarFlags.MustCaptureThis) {
   6206                        this.writeCaptureThisStatement(classDecl);
   6207                    }
   6208                    var members = (this.thisClassNode.members).members;
   6209                    for(var i = 0; i < members.length; i++) {
   6210                        if(members[i].nodeType == TypeScript.NodeType.VarDecl) {
   6211                            var varDecl = members[i];
   6212                            if(!TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.Static) && varDecl.init) {
   6213                                this.writeLineToOutput("");
   6214                                this.emitIndent();
   6215                                this.emitJavascriptVarDecl(varDecl, TypeScript.TokenID.Tilde);
   6216                                wroteProps++;
   6217                            }
   6218                        }
   6219                    }
   6220                    if(wroteProps) {
   6221                        this.writeLineToOutput("");
   6222                        this.indenter.decreaseIndent();
   6223                        this.emitIndent();
   6224                        this.writeLineToOutput("}");
   6225                    } else {
   6226                        this.writeLineToOutput(" }");
   6227                        this.indenter.decreaseIndent();
   6228                    }
   6229                    this.recordSourceMappingNameEnd();
   6230                    this.recordSourceMappingEnd(classDecl);
   6231                }
   6232                var membersLen = classDecl.members.members.length;
   6233                for(var j = 0; j < membersLen; j++) {
   6234                    var memberDecl = classDecl.members.members[j];
   6235                    if(memberDecl.nodeType == TypeScript.NodeType.FuncDecl) {
   6236                        var fn = memberDecl;
   6237                        if(TypeScript.hasFlag(fn.fncFlags, TypeScript.FncFlags.Method) && !fn.isSignature()) {
   6238                            if(!TypeScript.hasFlag(fn.fncFlags, TypeScript.FncFlags.Static)) {
   6239                                this.emitPrototypeMember(fn, className);
   6240                            } else {
   6241                                if(fn.isAccessor()) {
   6242                                    this.emitPropertyAccessor(fn, this.thisClassNode.name.actualText, false);
   6243                                } else {
   6244                                    this.emitIndent();
   6245                                    this.recordSourceMappingStart(fn);
   6246                                    this.writeToOutput(classDecl.name.actualText + "." + fn.name.actualText + " = ");
   6247                                    this.emitInnerFunction(fn, (fn.name && !fn.name.isMissing()), true, null, Emitter.shouldCaptureThis(fn), null);
   6248                                    this.writeLineToOutput(";");
   6249                                }
   6250                            }
   6251                        }
   6252                    } else {
   6253                        if(memberDecl.nodeType == TypeScript.NodeType.VarDecl) {
   6254                            var varDecl = memberDecl;
   6255                            if(TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.Static)) {
   6256                                if(varDecl.init) {
   6257                                    this.emitIndent();
   6258                                    this.recordSourceMappingStart(varDecl);
   6259                                    this.writeToOutput(classDecl.name.actualText + "." + varDecl.id.actualText + " = ");
   6260                                    this.emitJavascript(varDecl.init, TypeScript.TokenID.Equals, false);
   6261                                    this.writeLineToOutput(";");
   6262                                    this.recordSourceMappingEnd(varDecl);
   6263                                }
   6264                            }
   6265                        } else {
   6266                            throw Error("We want to catch this");
   6267                        }
   6268                    }
   6269                }
   6270                this.emitIndent();
   6271                this.recordSourceMappingStart(classDecl.endingToken);
   6272                this.writeLineToOutput("return " + className + ";");
   6273                this.recordSourceMappingEnd(classDecl.endingToken);
   6274                this.indenter.decreaseIndent();
   6275                this.emitIndent();
   6276                this.recordSourceMappingStart(classDecl.endingToken);
   6277                this.writeToOutput("}");
   6278                this.recordSourceMappingNameEnd();
   6279                this.recordSourceMappingEnd(classDecl.endingToken);
   6280                this.recordSourceMappingStart(classDecl);
   6281                this.writeToOutput(")(");
   6282                if(hasBaseClass) {
   6283                    this.emitJavascript(baseName, TypeScript.TokenID.Tilde, false);
   6284                }
   6285                this.writeToOutput(");");
   6286                this.recordSourceMappingEnd(classDecl);
   6287                if((temp == EmitContainer.Module || temp == EmitContainer.DynamicModule) && TypeScript.hasFlag(classDecl.varFlags, TypeScript.VarFlags.Exported)) {
   6288                    this.writeLineToOutput("");
   6289                    this.emitIndent();
   6290                    var modName = temp == EmitContainer.Module ? this.moduleName : "exports";
   6291                    this.recordSourceMappingStart(classDecl);
   6292                    this.writeToOutput(modName + "." + className + " = " + className + ";");
   6293                    this.recordSourceMappingEnd(classDecl);
   6294                }
   6295                this.emitIndent();
   6296                this.recordSourceMappingEnd(classDecl);
   6297                this.emitParensAndCommentsInPlace(classDecl, false);
   6298                this.setContainer(temp);
   6299                this.thisClassNode = svClassNode;
   6300            }
   6301        };
   6302        Emitter.prototype.emitPrologue = function (reqInherits) {
   6303            if(!this.prologueEmitted) {
   6304                if(reqInherits) {
   6305                    this.prologueEmitted = true;
   6306                    this.writeLineToOutput("var __extends = this.__extends || function (d, b) {");
   6307                    this.writeLineToOutput("    function __() { this.constructor = d; }");
   6308                    this.writeLineToOutput("    __.prototype = b.prototype;");
   6309                    this.writeLineToOutput("    d.prototype = new __();");
   6310                    this.writeLineToOutput("};");
   6311                }
   6312                if(this.checker.mustCaptureGlobalThis) {
   6313                    this.prologueEmitted = true;
   6314                    this.writeLineToOutput(this.captureThisStmtString);
   6315                }
   6316            }
   6317        };
   6318        Emitter.prototype.emitSuperReference = function () {
   6319            this.writeToOutput("_super.prototype");
   6320        };
   6321        Emitter.prototype.emitSuperCall = function (callEx) {
   6322            if(callEx.target.nodeType == TypeScript.NodeType.Dot) {
   6323                var dotNode = callEx.target;
   6324                if(dotNode.operand1.nodeType == TypeScript.NodeType.Super) {
   6325                    this.emitJavascript(dotNode, TypeScript.TokenID.OpenParen, false);
   6326                    this.writeToOutput(".call(");
   6327                    this.emitThis();
   6328                    if(callEx.arguments && callEx.arguments.members.length > 0) {
   6329                        this.writeToOutput(", ");
   6330                        this.emitJavascriptList(callEx.arguments, ", ", TypeScript.TokenID.Comma, false, false, false);
   6331                    }
   6332                    this.writeToOutput(")");
   6333                    return true;
   6334                }
   6335            }
   6336            return false;
   6337        };
   6338        Emitter.prototype.emitThis = function () {
   6339            if(this.thisFnc && !this.thisFnc.isMethod() && (!this.thisFnc.isConstructor)) {
   6340                this.writeToOutput("_this");
   6341            } else {
   6342                this.writeToOutput("this");
   6343            }
   6344        };
   6345        Emitter.shouldCaptureThis = function shouldCaptureThis(func) {
   6346            return func.hasSelfReference() || func.hasSuperReferenceInFatArrowFunction();
   6347        }
   6348        Emitter.prototype.createFile = function (fileName, useUTF8) {
   6349            try  {
   6350                return this.emitOptions.ioHost.createFile(fileName, useUTF8);
   6351            } catch (ex) {
   6352                this.errorReporter.emitterError(null, ex.message);
   6353            }
   6354        };
   6355        return Emitter;
   6356    })();
   6357    TypeScript.Emitter = Emitter;    
   6358 })(TypeScript || (TypeScript = {}));
   6359 var TypeScript;
   6360 (function (TypeScript) {
   6361    var ErrorReporter = (function () {
   6362        function ErrorReporter(outfile) {
   6363            this.outfile = outfile;
   6364            this.parser = null;
   6365            this.checker = null;
   6366            this.lineCol = {
   6367                line: 0,
   6368                col: 0
   6369            };
   6370            this.emitAsComments = true;
   6371            this.hasErrors = false;
   6372            this.pushToErrorSink = false;
   6373            this.errorSink = [];
   6374        }
   6375        ErrorReporter.prototype.getCapturedErrors = function () {
   6376            return this.errorSink;
   6377        };
   6378        ErrorReporter.prototype.freeCapturedErrors = function () {
   6379            this.errorSink = [];
   6380        };
   6381        ErrorReporter.prototype.captureError = function (emsg) {
   6382            this.errorSink[this.errorSink.length] = emsg;
   6383        };
   6384        ErrorReporter.prototype.setErrOut = function (outerr) {
   6385            this.outfile = outerr;
   6386            this.emitAsComments = false;
   6387        };
   6388        ErrorReporter.prototype.emitPrefix = function () {
   6389            if(this.emitAsComments) {
   6390                this.outfile.Write("// ");
   6391            }
   6392            this.outfile.Write(this.checker.locationInfo.filename + "(" + this.lineCol.line + "," + this.lineCol.col + "): ");
   6393        };
   6394        ErrorReporter.prototype.writePrefix = function (ast) {
   6395            if(ast) {
   6396                this.setError(ast);
   6397            } else {
   6398                this.lineCol.line = 0;
   6399                this.lineCol.col = 0;
   6400            }
   6401            this.emitPrefix();
   6402        };
   6403        ErrorReporter.prototype.writePrefixFromSym = function (symbol) {
   6404            if(symbol && this.checker.locationInfo.lineMap) {
   6405                TypeScript.getSourceLineColFromMap(this.lineCol, symbol.location, this.checker.locationInfo.lineMap);
   6406            } else {
   6407                this.lineCol.line = -1;
   6408                this.lineCol.col = -1;
   6409            }
   6410            this.emitPrefix();
   6411        };
   6412        ErrorReporter.prototype.setError = function (ast) {
   6413            if(ast) {
   6414                ast.flags |= TypeScript.ASTFlags.Error;
   6415                if(this.checker.locationInfo.lineMap) {
   6416                    TypeScript.getSourceLineColFromMap(this.lineCol, ast.minChar, this.checker.locationInfo.lineMap);
   6417                }
   6418            }
   6419        };
   6420        ErrorReporter.prototype.reportError = function (ast, message) {
   6421            if(this.pushToErrorSink) {
   6422                this.captureError(message);
   6423                return;
   6424            }
   6425            this.hasErrors = true;
   6426            if(ast && this.parser.errorRecovery && this.parser.errorCallback) {
   6427                var len = (ast.limChar - ast.minChar);
   6428                this.parser.errorCallback(ast.minChar, len, message, this.checker.locationInfo.unitIndex);
   6429            } else {
   6430                this.writePrefix(ast);
   6431                this.outfile.WriteLine(message);
   6432            }
   6433        };
   6434        ErrorReporter.prototype.reportErrorFromSym = function (symbol, message) {
   6435            if(this.pushToErrorSink) {
   6436                this.captureError(message);
   6437                return;
   6438            }
   6439            this.hasErrors = true;
   6440            if(this.parser.errorRecovery && this.parser.errorCallback) {
   6441                this.parser.errorCallback(symbol.location, symbol.length, message, this.checker.locationInfo.unitIndex);
   6442            } else {
   6443                this.writePrefixFromSym(symbol);
   6444                this.outfile.WriteLine(message);
   6445            }
   6446        };
   6447        ErrorReporter.prototype.emitterError = function (ast, message) {
   6448            this.reportError(ast, message);
   6449            throw Error("EmitError");
   6450        };
   6451        ErrorReporter.prototype.duplicateIdentifier = function (ast, name) {
   6452            this.reportError(ast, "Duplicate identifier '" + name + "'");
   6453        };
   6454        ErrorReporter.prototype.showRef = function (ast, text, symbol) {
   6455            var defLineCol = {
   6456                line: -1,
   6457                col: -1
   6458            };
   6459            this.parser.getSourceLineCol(defLineCol, symbol.location);
   6460            this.reportError(ast, "symbol " + text + " defined at (" + defLineCol.line + "," + defLineCol.col + ")");
   6461        };
   6462        ErrorReporter.prototype.unresolvedSymbol = function (ast, name) {
   6463            this.reportError(ast, "The name '" + name + "' does not exist in the current scope");
   6464        };
   6465        ErrorReporter.prototype.symbolDoesNotReferToAValue = function (ast, name) {
   6466            this.reportError(ast, "The name '" + name + "' does not refer to a value");
   6467        };
   6468        ErrorReporter.prototype.styleError = function (ast, msg) {
   6469            var bkThrow = this.pushToErrorSink;
   6470            this.pushToErrorSink = false;
   6471            this.reportError(ast, "STYLE: " + msg);
   6472            this.pushToErrorSink = bkThrow;
   6473        };
   6474        ErrorReporter.prototype.simpleError = function (ast, msg) {
   6475            this.reportError(ast, msg);
   6476        };
   6477        ErrorReporter.prototype.simpleErrorFromSym = function (sym, msg) {
   6478            this.reportErrorFromSym(sym, msg);
   6479        };
   6480        ErrorReporter.prototype.invalidSuperReference = function (ast) {
   6481            this.simpleError(ast, "Keyword 'super' can only be used inside a class instance method");
   6482        };
   6483        ErrorReporter.prototype.valueCannotBeModified = function (ast) {
   6484            this.simpleError(ast, "The left-hand side of an assignment expression must be a variable, property or indexer");
   6485        };
   6486        ErrorReporter.prototype.invalidCall = function (ast, nodeType, scope) {
   6487            var targetType = ast.target.type;
   6488            var typeName = targetType.getScopedTypeName(scope);
   6489            if(targetType.construct && (nodeType == TypeScript.NodeType.Call)) {
   6490                this.reportError(ast, "Value of type '" + typeName + "' is not callable.  Did you mean to include 'new'?");
   6491            } else {
   6492                var catString = (nodeType == TypeScript.NodeType.Call) ? "callable" : "newable";
   6493                this.reportError(ast, "Value of type '" + typeName + "' is not " + catString);
   6494            }
   6495        };
   6496        ErrorReporter.prototype.indexLHS = function (ast, scope) {
   6497            var targetType = ast.operand1.type.getScopedTypeName(scope);
   6498            var indexType = ast.operand2.type.getScopedTypeName(scope);
   6499            this.simpleError(ast, "Value of type '" + targetType + "' is not indexable by type '" + indexType + "'");
   6500        };
   6501        ErrorReporter.prototype.incompatibleTypes = function (ast, t1, t2, op, scope, comparisonInfo) {
   6502            if(!t1) {
   6503                t1 = this.checker.anyType;
   6504            }
   6505            if(!t2) {
   6506                t2 = this.checker.anyType;
   6507            }
   6508            var reason = comparisonInfo ? comparisonInfo.message : "";
   6509            if(op) {
   6510                this.reportError(ast, "Operator '" + op + "' cannot be applied to types '" + t1.getScopedTypeName(scope) + "' and '" + t2.getScopedTypeName(scope) + "'" + (reason ? ": " + reason : ""));
   6511            } else {
   6512                this.reportError(ast, "Cannot convert '" + t1.getScopedTypeName(scope) + "' to '" + t2.getScopedTypeName(scope) + "'" + (reason ? ": " + reason : ""));
   6513            }
   6514        };
   6515        ErrorReporter.prototype.expectedClassOrInterface = function (ast) {
   6516            this.simpleError(ast, "Expected var, class, interface, or module");
   6517        };
   6518        ErrorReporter.prototype.unaryOperatorTypeError = function (ast, op, type) {
   6519            this.reportError(ast, "Operator '" + op + "' cannot be applied to type '" + type.getTypeName() + "'");
   6520        };
   6521        return ErrorReporter;
   6522    })();
   6523    TypeScript.ErrorReporter = ErrorReporter;    
   6524 })(TypeScript || (TypeScript = {}));
   6525 var TypeScript;
   6526 (function (TypeScript) {
   6527    (function (TypeContext) {
   6528        TypeContext._map = [];
   6529        TypeContext.NoTypes = 0;
   6530        TypeContext.ArraySuffix = 1;
   6531        TypeContext.Primitive = 2;
   6532        TypeContext.Named = 4;
   6533        TypeContext.AllSimpleTypes = TypeContext.Primitive | TypeContext.Named;
   6534        TypeContext.AllTypes = TypeContext.Primitive | TypeContext.Named | TypeContext.ArraySuffix;
   6535    })(TypeScript.TypeContext || (TypeScript.TypeContext = {}));
   6536    var TypeContext = TypeScript.TypeContext;
   6537    (function (ParseState) {
   6538        ParseState._map = [];
   6539        ParseState._map[0] = "None";
   6540        ParseState.None = 0;
   6541        ParseState._map[1] = "StartScript";
   6542        ParseState.StartScript = 1;
   6543        ParseState._map[2] = "StartStatementList";
   6544        ParseState.StartStatementList = 2;
   6545        ParseState._map[3] = "StartStatement";
   6546        ParseState.StartStatement = 3;
   6547        ParseState._map[4] = "StartFncDecl";
   6548        ParseState.StartFncDecl = 4;
   6549        ParseState._map[5] = "FncDeclName";
   6550        ParseState.FncDeclName = 5;
   6551        ParseState._map[6] = "FncDeclArgs";
   6552        ParseState.FncDeclArgs = 6;
   6553        ParseState._map[7] = "FncDeclReturnType";
   6554        ParseState.FncDeclReturnType = 7;
   6555        ParseState._map[8] = "ForInit";
   6556        ParseState.ForInit = 8;
   6557        ParseState._map[9] = "ForInitAfterVar";
   6558        ParseState.ForInitAfterVar = 9;
   6559        ParseState._map[10] = "ForCondStart";
   6560        ParseState.ForCondStart = 10;
   6561        ParseState._map[11] = "EndStmtList";
   6562        ParseState.EndStmtList = 11;
   6563        ParseState._map[12] = "EndScript";
   6564        ParseState.EndScript = 12;
   6565    })(TypeScript.ParseState || (TypeScript.ParseState = {}));
   6566    var ParseState = TypeScript.ParseState;
   6567    var QuickParseResult = (function () {
   6568        function QuickParseResult(Script, endLexState) {
   6569            this.Script = Script;
   6570            this.endLexState = endLexState;
   6571        }
   6572        return QuickParseResult;
   6573    })();
   6574    TypeScript.QuickParseResult = QuickParseResult;    
   6575    var Parser = (function () {
   6576        function Parser() {
   6577            this.varLists = [];
   6578            this.scopeLists = [];
   6579            this.staticsLists = [];
   6580            this.scanner = new TypeScript.Scanner();
   6581            this.currentToken = null;
   6582            this.needTerminator = false;
   6583            this.inFunction = false;
   6584            this.inInterfaceDecl = false;
   6585            this.currentClassDecl = null;
   6586            this.inFncDecl = false;
   6587            this.anonId = new TypeScript.Identifier("_anonymous");
   6588            this.style_requireSemi = false;
   6589            this.style_funcInLoop = true;
   6590            this.incremental = false;
   6591            this.errorRecovery = false;
   6592            this.outfile = undefined;
   6593            this.errorCallback = null;
   6594            this.state = ParseState.StartStatementList;
   6595            this.ambientModule = false;
   6596            this.ambientClass = false;
   6597            this.topLevel = true;
   6598            this.allowImportDeclaration = true;
   6599            this.currentUnitIndex = (-1);
   6600            this.prevIDTok = null;
   6601            this.statementInfoStack = new Array();
   6602            this.hasTopLevelImportOrExport = false;
   6603            this.strictMode = false;
   6604            this.nestingLevel = 0;
   6605            this.prevExpr = null;
   6606            this.currentClassDefinition = null;
   6607            this.parsingClassConstructorDefinition = false;
   6608            this.parsingDeclareFile = false;
   6609            this.amdDependencies = [];
   6610            this.inferPropertiesFromThisAssignment = false;
   6611            this.requiresExtendsBlock = false;
   6612            this.fname = "";
   6613        }
   6614        Parser.prototype.resetStmtStack = function () {
   6615            this.statementInfoStack = new Array();
   6616        };
   6617        Parser.prototype.inLoop = function () {
   6618            for(var j = this.statementInfoStack.length - 1; j >= 0; j--) {
   6619                if(this.statementInfoStack[j].stmt.isLoop()) {
   6620                    return true;
   6621                }
   6622            }
   6623            return false;
   6624        };
   6625        Parser.prototype.pushStmt = function (stmt, labels) {
   6626            var info = {
   6627                stmt: stmt,
   6628                labels: labels
   6629            };
   6630            this.statementInfoStack.push(info);
   6631        };
   6632        Parser.prototype.popStmt = function () {
   6633            return this.statementInfoStack.pop();
   6634        };
   6635        Parser.prototype.resolveJumpTarget = function (jump) {
   6636            var resolvedTarget = TypeScript.AST.getResolvedIdentifierName(jump.target);
   6637            var len = this.statementInfoStack.length;
   6638            for(var i = len - 1; i >= 0; i--) {
   6639                var info = this.statementInfoStack[i];
   6640                if(jump.target) {
   6641                    if(info.labels && (info.labels.members.length > 0)) {
   6642                        for(var j = 0, labLen = info.labels.members.length; j < labLen; j++) {
   6643                            var label = info.labels.members[j];
   6644                            if(label.id.text == resolvedTarget) {
   6645                                jump.setResolvedTarget(this, info.stmt);
   6646                                return;
   6647                            }
   6648                        }
   6649                    }
   6650                } else {
   6651                    if(info.stmt.isLoop()) {
   6652                        jump.setResolvedTarget(this, info.stmt);
   6653                        return;
   6654                    } else {
   6655                        if((info.stmt.nodeType == TypeScript.NodeType.Switch) && (jump.nodeType == TypeScript.NodeType.Break)) {
   6656                            jump.setResolvedTarget(this, info.stmt);
   6657                            return;
   6658                        }
   6659                    }
   6660                }
   6661            }
   6662            if(jump.target) {
   6663                this.reportParseError("could not find enclosing statement with label " + jump.target);
   6664            } else {
   6665                if(jump.nodeType == TypeScript.NodeType.Break) {
   6666                    this.reportParseError("break statement requires enclosing loop or switch");
   6667                } else {
   6668                    this.reportParseError("continue statement requires enclosing loop");
   6669                }
   6670            }
   6671        };
   6672        Parser.prototype.setErrorRecovery = function (outfile) {
   6673            this.outfile = outfile;
   6674            this.errorRecovery = true;
   6675        };
   6676        Parser.prototype.getSourceLineCol = function (lineCol, minChar) {
   6677            TypeScript.getSourceLineColFromMap(lineCol, minChar, this.scanner.lineMap);
   6678        };
   6679        Parser.prototype.createRef = function (text, hasEscapeSequence, minChar) {
   6680            var id = new TypeScript.Identifier(text, hasEscapeSequence);
   6681            id.minChar = minChar;
   6682            return id;
   6683        };
   6684        Parser.prototype.reportParseStyleError = function (message) {
   6685            this.reportParseError("STYLE: " + message);
   6686        };
   6687        Parser.prototype.reportParseError = function (message, startPos, pos) {
   6688            if (typeof startPos === "undefined") { startPos = this.scanner.startPos; }
   6689            if (typeof pos === "undefined") { pos = this.scanner.pos; }
   6690            var len = Math.max(1, pos - startPos);
   6691            if(this.errorCallback) {
   6692                this.errorCallback(startPos, len, message, this.currentUnitIndex);
   6693            } else {
   6694                if(this.errorRecovery) {
   6695                    var lineCol = {
   6696                        line: -1,
   6697                        col: -1
   6698                    };
   6699                    this.getSourceLineCol(lineCol, startPos);
   6700                    if(this.outfile) {
   6701                        this.outfile.WriteLine("// " + this.fname + " (" + lineCol.line + "," + lineCol.col + "): " + message);
   6702                    }
   6703                } else {
   6704                    throw new SyntaxError(this.fname + " (" + this.scanner.line + "," + this.scanner.col + "): " + message);
   6705                }
   6706            }
   6707        };
   6708        Parser.prototype.checkNextToken = function (tokenId, errorRecoverySet, errorText) {
   6709            if (typeof errorText === "undefined") { errorText = null; }
   6710            this.currentToken = this.scanner.scan();
   6711            this.checkCurrentToken(tokenId, errorRecoverySet, errorText);
   6712        };
   6713        Parser.prototype.skip = function (errorRecoverySet) {
   6714            errorRecoverySet |= TypeScript.ErrorRecoverySet.EOF;
   6715            var ersTok = TypeScript.ErrorRecoverySet.None;
   6716            var tokenInfo = TypeScript.lookupToken(this.currentToken.tokenId);
   6717            if(tokenInfo != undefined) {
   6718                ersTok = tokenInfo.ers;
   6719            }
   6720            var pendingRightCurlies = 0;
   6721            while(((ersTok & errorRecoverySet) == TypeScript.ErrorRecoverySet.None) || (this.currentToken.tokenId == TypeScript.TokenID.CloseBrace) && (pendingRightCurlies > 0)) {
   6722                if(this.currentToken.tokenId == TypeScript.TokenID.OpenBrace) {
   6723                    pendingRightCurlies++;
   6724                } else {
   6725                    if(this.currentToken.tokenId == TypeScript.TokenID.CloseBrace) {
   6726                        pendingRightCurlies--;
   6727                    }
   6728                }
   6729                this.currentToken = this.scanner.scan();
   6730                ersTok = TypeScript.ErrorRecoverySet.None;
   6731                tokenInfo = TypeScript.lookupToken(this.currentToken.tokenId);
   6732                if(tokenInfo != undefined) {
   6733                    ersTok = tokenInfo.ers;
   6734                }
   6735            }
   6736        };
   6737        Parser.prototype.checkCurrentToken = function (tokenId, errorRecoverySet, errorText) {
   6738            if (typeof errorText === "undefined") { errorText = null; }
   6739            if(this.currentToken.tokenId != tokenId) {
   6740                errorText = errorText == null ? ("Expected '" + TypeScript.tokenTable[tokenId].text + "'") : errorText;
   6741                this.reportParseError(errorText);
   6742                if(this.errorRecovery) {
   6743                    this.skip(errorRecoverySet);
   6744                }
   6745            } else {
   6746                this.currentToken = this.scanner.scan();
   6747            }
   6748        };
   6749        Parser.prototype.pushDeclLists = function () {
   6750            this.staticsLists.push(new TypeScript.ASTList());
   6751            this.varLists.push(new TypeScript.ASTList());
   6752            this.scopeLists.push(new TypeScript.ASTList());
   6753        };
   6754        Parser.prototype.popDeclLists = function () {
   6755            this.staticsLists.pop();
   6756            this.varLists.pop();
   6757            this.scopeLists.pop();
   6758        };
   6759        Parser.prototype.topVarList = function () {
   6760            return this.varLists[this.varLists.length - 1];
   6761        };
   6762        Parser.prototype.topScopeList = function () {
   6763            return this.scopeLists[this.scopeLists.length - 1];
   6764        };
   6765        Parser.prototype.topStaticsList = function () {
   6766            return this.staticsLists[this.staticsLists.length - 1];
   6767        };
   6768        Parser.prototype.parseComment = function (comment) {
   6769            if(comment) {
   6770                var c = new TypeScript.Comment(comment.value, comment.isBlock, comment.endsLine);
   6771                c.minChar = comment.startPos;
   6772                c.limChar = comment.startPos + comment.value.length;
   6773                var lineCol = {
   6774                    line: -1,
   6775                    col: -1
   6776                };
   6777                this.getSourceLineCol(lineCol, c.minChar);
   6778                c.minLine = lineCol.line;
   6779                this.getSourceLineCol(lineCol, c.limChar);
   6780                c.limLine = lineCol.line;
   6781                if(!comment.isBlock && comment.value.length > 3 && comment.value.substring(0, 3) == "///") {
   6782                    var dependencyPath = TypeScript.getAdditionalDependencyPath(comment.value);
   6783                    if(dependencyPath) {
   6784                        this.amdDependencies.push(dependencyPath);
   6785                    }
   6786                    if(TypeScript.getImplicitImport(comment.value)) {
   6787                        this.hasTopLevelImportOrExport = true;
   6788                    }
   6789                }
   6790                return c;
   6791            } else {
   6792                return null;
   6793            }
   6794        };
   6795        Parser.prototype.parseCommentsInner = function (comments) {
   6796            if(comments) {
   6797                var commentASTs = new Array();
   6798                for(var i = 0; i < comments.length; i++) {
   6799                    commentASTs.push(this.parseComment(comments[i]));
   6800                }
   6801                return commentASTs;
   6802            } else {
   6803                return null;
   6804            }
   6805        };
   6806        Parser.prototype.parseComments = function () {
   6807            var comments = this.scanner.getComments();
   6808            return this.parseCommentsInner(comments);
   6809        };
   6810        Parser.prototype.parseCommentsForLine = function (line) {
   6811            var comments = this.scanner.getCommentsForLine(line);
   6812            return this.parseCommentsInner(comments);
   6813        };
   6814        Parser.prototype.combineComments = function (comment1, comment2) {
   6815            if(comment1 == null) {
   6816                return comment2;
   6817            } else {
   6818                if(comment2 == null) {
   6819                    return comment1;
   6820                } else {
   6821                    return comment1.concat(comment2);
   6822                }
   6823            }
   6824        };
   6825        Parser.prototype.parseEnumDecl = function (errorRecoverySet, modifiers) {
   6826            var leftCurlyCount = this.scanner.leftCurlyCount;
   6827            var rightCurlyCount = this.scanner.rightCurlyCount;
   6828            var name = null;
   6829            if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) || TypeScript.convertTokToID(this.currentToken, this.strictMode)) {
   6830                name = TypeScript.Identifier.fromToken(this.currentToken);
   6831                name.minChar = this.scanner.startPos;
   6832                name.limChar = this.scanner.pos;
   6833                this.currentToken = this.scanner.scan();
   6834            } else {
   6835                this.reportParseError("Enum declaration requires identifier");
   6836                if(this.errorRecovery) {
   6837                    name = new TypeScript.MissingIdentifier();
   6838                    name.minChar = this.scanner.startPos;
   6839                    name.limChar = this.scanner.startPos;
   6840                    name.flags |= TypeScript.ASTFlags.Error;
   6841                }
   6842            }
   6843            var membersMinChar = this.scanner.startPos;
   6844            this.checkCurrentToken(TypeScript.TokenID.OpenBrace, errorRecoverySet | TypeScript.ErrorRecoverySet.ID);
   6845            this.pushDeclLists();
   6846            var members = new TypeScript.ASTList();
   6847            members.minChar = membersMinChar;
   6848            var mapDecl = new TypeScript.VarDecl(new TypeScript.Identifier("_map"), 0);
   6849            mapDecl.varFlags |= TypeScript.VarFlags.Exported;
   6850            mapDecl.varFlags |= TypeScript.VarFlags.Private;
   6851            mapDecl.varFlags |= (TypeScript.VarFlags.Property | TypeScript.VarFlags.Public);
   6852            mapDecl.init = new TypeScript.UnaryExpression(TypeScript.NodeType.ArrayLit, null);
   6853            members.append(mapDecl);
   6854            var lastValue = null;
   6855            for(; ; ) {
   6856                var minChar = this.scanner.startPos;
   6857                var limChar;
   6858                var memberName = null;
   6859                var memberValue = null;
   6860                var preComments = null;
   6861                var postComments = null;
   6862                if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) || TypeScript.convertTokToIDName(this.currentToken)) {
   6863                    memberName = TypeScript.Identifier.fromToken(this.currentToken);
   6864                    memberName.minChar = this.scanner.startPos;
   6865                    memberName.limChar = this.scanner.pos;
   6866                } else {
   6867                    if(this.currentToken.tokenId == TypeScript.TokenID.CloseBrace) {
   6868                        break;
   6869                    } else {
   6870                        this.reportParseError("Expected identifer of enum member");
   6871                        if(this.errorRecovery) {
   6872                            memberName = new TypeScript.MissingIdentifier();
   6873                            memberName.minChar = this.scanner.startPos;
   6874                            memberName.limChar = this.scanner.startPos;
   6875                            memberName.flags |= TypeScript.ASTFlags.Error;
   6876                        }
   6877                    }
   6878                }
   6879                limChar = this.scanner.pos;
   6880                preComments = this.parseComments();
   6881                this.currentToken = this.scanner.scan();
   6882                postComments = this.parseComments();
   6883                if(this.currentToken.tokenId == TypeScript.TokenID.Equals) {
   6884                    this.currentToken = this.scanner.scan();
   6885                    memberValue = this.parseExpr(errorRecoverySet, TypeScript.OperatorPrecedence.Comma, true, TypeContext.NoTypes);
   6886                    lastValue = memberValue;
   6887                    limChar = memberValue.limChar;
   6888                } else {
   6889                    if(lastValue == null) {
   6890                        memberValue = new TypeScript.NumberLiteral(0);
   6891                        lastValue = memberValue;
   6892                    } else {
   6893                        memberValue = new TypeScript.NumberLiteral(lastValue.value + 1);
   6894                        lastValue = memberValue;
   6895                    }
   6896                    var map = new TypeScript.BinaryExpression(TypeScript.NodeType.Asg, new TypeScript.BinaryExpression(TypeScript.NodeType.Index, new TypeScript.Identifier("_map"), memberValue), new TypeScript.StringLiteral('"' + memberName.actualText + '"'));
   6897                    members.append(map);
   6898                }
   6899                var member = new TypeScript.VarDecl(memberName, this.nestingLevel);
   6900                member.minChar = minChar;
   6901                member.limChar = limChar;
   6902                member.init = memberValue;
   6903                member.typeExpr = new TypeScript.TypeReference(this.createRef(name.actualText, name.hasEscapeSequence, -1), 0);
   6904                member.varFlags |= (TypeScript.VarFlags.Readonly | TypeScript.VarFlags.Property);
   6905                if(memberValue.nodeType == TypeScript.NodeType.NumberLit) {
   6906                    member.varFlags |= TypeScript.VarFlags.Constant;
   6907                }
   6908                member.preComments = preComments;
   6909                members.append(member);
   6910                member.postComments = postComments;
   6911                member.varFlags |= TypeScript.VarFlags.Exported;
   6912                if(this.currentToken.tokenId == TypeScript.TokenID.Comma) {
   6913                    this.currentToken = this.scanner.scan();
   6914                    member.postComments = this.combineComments(member.postComments, this.parseCommentsForLine(this.scanner.prevLine));
   6915                    if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) || (TypeScript.convertTokToIDName(this.currentToken))) {
   6916                        continue;
   6917                    }
   6918                }
   6919                break;
   6920            }
   6921            var endingToken = new TypeScript.ASTSpan();
   6922            endingToken.minChar = this.scanner.startPos;
   6923            endingToken.limChar = this.scanner.pos;
   6924            this.checkCurrentToken(TypeScript.TokenID.CloseBrace, errorRecoverySet);
   6925            members.limChar = this.scanner.lastTokenLimChar();
   6926            var modDecl = new TypeScript.ModuleDeclaration(name, members, this.topVarList(), this.topScopeList(), endingToken);
   6927            modDecl.modFlags |= TypeScript.ModuleFlags.IsEnum;
   6928            this.popDeclLists();
   6929            modDecl.leftCurlyCount = this.scanner.leftCurlyCount - leftCurlyCount;
   6930            modDecl.rightCurlyCount = this.scanner.rightCurlyCount - rightCurlyCount;
   6931            return modDecl;
   6932        };
   6933        Parser.prototype.parseDottedName = function (enclosedList) {
   6934            this.currentToken = this.scanner.scan();
   6935            if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) || TypeScript.convertTokToID(this.currentToken, this.strictMode)) {
   6936                var id = TypeScript.Identifier.fromToken(this.currentToken);
   6937                id.preComments = this.parseComments();
   6938                enclosedList[enclosedList.length] = id;
   6939                id.minChar = this.scanner.startPos;
   6940                id.limChar = this.scanner.pos;
   6941                this.currentToken = this.scanner.scan();
   6942                if(this.currentToken.tokenId == TypeScript.TokenID.Dot) {
   6943                    this.parseDottedName(enclosedList);
   6944                }
   6945            } else {
   6946                this.reportParseError("need identifier after '.'");
   6947            }
   6948        };
   6949        Parser.prototype.isValidImportPath = function (importPath) {
   6950            importPath = TypeScript.stripQuotes(importPath);
   6951            if(!importPath || importPath.indexOf(':') != -1 || importPath.indexOf('\\') != -1 || importPath.charAt(0) == '/') {
   6952                return false;
   6953            }
   6954            return true;
   6955        };
   6956        Parser.prototype.parseImportDeclaration = function (errorRecoverySet, modifiers) {
   6957            var name = null;
   6958            var alias = null;
   6959            var importDecl = null;
   6960            var minChar = this.scanner.startPos;
   6961            var isDynamicImport = false;
   6962            this.currentToken = this.scanner.scan();
   6963            if(this.currentToken.tokenId == TypeScript.TokenID.Identifier || TypeScript.convertTokToID(this.currentToken, this.strictMode)) {
   6964                name = TypeScript.Identifier.fromToken(this.currentToken);
   6965            } else {
   6966                this.reportParseError("Expected identifer after 'import'");
   6967                name = new TypeScript.MissingIdentifier();
   6968            }
   6969            name.minChar = this.scanner.startPos;
   6970            name.limChar = this.scanner.pos;
   6971            this.currentToken = this.scanner.scan();
   6972            this.checkCurrentToken(TypeScript.TokenID.Equals, errorRecoverySet | TypeScript.ErrorRecoverySet.ID);
   6973            var aliasPreComments = this.parseComments();
   6974            var limChar;
   6975            if(this.currentToken.tokenId == TypeScript.TokenID.Identifier || TypeScript.convertTokToID(this.currentToken, this.strictMode)) {
   6976                if(this.currentToken.tokenId == TypeScript.TokenID.Module) {
   6977                    limChar = this.scanner.pos;
   6978                    this.currentToken = this.scanner.scan();
   6979                    if(this.currentToken.tokenId == TypeScript.TokenID.OpenParen) {
   6980                        this.currentToken = this.scanner.scan();
   6981                        if(this.currentToken.tokenId == TypeScript.TokenID.StringLiteral || this.currentToken.tokenId == TypeScript.TokenID.Identifier || TypeScript.convertTokToID(this.currentToken, this.strictMode)) {
   6982                            if(this.currentToken.tokenId == TypeScript.TokenID.StringLiteral) {
   6983                                if(this.topLevel) {
   6984                                    this.hasTopLevelImportOrExport = true;
   6985                                } else {
   6986                                    if(!this.allowImportDeclaration) {
   6987                                        this.reportParseError("Import declaration of external module is permitted only in global or top level dynamic modules");
   6988                                    }
   6989                                }
   6990                                var aliasText = this.currentToken.getText();
   6991                                alias = TypeScript.Identifier.fromToken(this.currentToken);
   6992                                alias.minChar = this.scanner.startPos;
   6993                                alias.limChar = this.scanner.pos;
   6994                                if(!this.isValidImportPath((alias).text)) {
   6995                                    this.reportParseError("Invalid import path");
   6996                                }
   6997                                isDynamicImport = true;
   6998                                this.currentToken = this.scanner.scan();
   6999                                alias.preComments = aliasPreComments;
   7000                            } else {
   7001                                alias = this.parseExpr(errorRecoverySet | TypeScript.ErrorRecoverySet.SColon, TypeScript.OperatorPrecedence.Assignment, true, TypeContext.NoTypes);
   7002                                alias.preComments = aliasPreComments;
   7003                            }
   7004                        }
   7005                        limChar = this.scanner.pos;
   7006                        this.checkCurrentToken(TypeScript.TokenID.CloseParen, errorRecoverySet | TypeScript.ErrorRecoverySet.ID);
   7007                        if(alias) {
   7008                            alias.postComments = this.parseComments();
   7009                        }
   7010                    }
   7011                } else {
   7012                    alias = this.parseExpr(errorRecoverySet | TypeScript.ErrorRecoverySet.SColon, TypeScript.OperatorPrecedence.Assignment, true, TypeContext.NoTypes);
   7013                    limChar = this.scanner.pos;
   7014                }
   7015            } else {
   7016                this.reportParseError("Expected module name");
   7017                alias = new TypeScript.MissingIdentifier();
   7018                alias.minChar = this.scanner.startPos;
   7019                if(this.currentToken.tokenId == TypeScript.TokenID.Semicolon) {
   7020                    alias.limChar = this.scanner.startPos;
   7021                } else {
   7022                    alias.limChar = this.scanner.pos;
   7023                    this.currentToken = this.scanner.scan();
   7024                }
   7025                alias.flags |= TypeScript.ASTFlags.Error;
   7026                limChar = alias.limChar;
   7027            }
   7028            importDecl = new TypeScript.ImportDeclaration(name, alias);
   7029            importDecl.isDynamicImport = isDynamicImport;
   7030            importDecl.minChar = minChar;
   7031            importDecl.limChar = limChar;
   7032            return importDecl;
   7033        };
   7034        Parser.prototype.parseModuleDecl = function (errorRecoverySet, modifiers, preComments) {
   7035            var leftCurlyCount = this.scanner.leftCurlyCount;
   7036            var rightCurlyCount = this.scanner.rightCurlyCount;
   7037            var svAmbient = this.ambientModule;
   7038            var svTopLevel = this.topLevel;
   7039            this.topLevel = false;
   7040            if(this.parsingDeclareFile || svAmbient || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Ambient)) {
   7041                this.ambientModule = true;
   7042            }
   7043            this.currentToken = this.scanner.scan();
   7044            var name = null;
   7045            var enclosedList = null;
   7046            this.pushDeclLists();
   7047            var minChar = this.scanner.startPos;
   7048            var isDynamicMod = false;
   7049            if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) || (this.currentToken.tokenId == TypeScript.TokenID.StringLiteral) || (!TypeScript.isPrimitiveTypeToken(this.currentToken) && TypeScript.convertTokToID(this.currentToken, this.strictMode))) {
   7050                var nameText = this.currentToken.getText();
   7051                if(this.currentToken.tokenId == TypeScript.TokenID.StringLiteral) {
   7052                    isDynamicMod = true;
   7053                    if(!this.ambientModule) {
   7054                        this.reportParseError("Only ambient dynamic modules may have string literal names");
   7055                    }
   7056                    if(!svTopLevel) {
   7057                        this.reportParseError("Dynamic modules may not be nested within other modules");
   7058                    }
   7059                }
   7060                name = TypeScript.Identifier.fromToken(this.currentToken);
   7061                name.minChar = this.scanner.startPos;
   7062                name.limChar = this.scanner.pos;
   7063                this.currentToken = this.scanner.scan();
   7064            } else {
   7065                if(this.currentToken.tokenId == TypeScript.TokenID.OpenBrace) {
   7066                    this.reportParseError("Module name missing");
   7067                    name = new TypeScript.Identifier("");
   7068                    name.minChar = minChar;
   7069                    name.limChar = minChar;
   7070                }
   7071            }
   7072            if(this.currentToken.tokenId == TypeScript.TokenID.Dot) {
   7073                enclosedList = new Array();
   7074                this.parseDottedName(enclosedList);
   7075            }
   7076            if(name == null) {
   7077                name = new TypeScript.MissingIdentifier();
   7078            }
   7079            var moduleBody = new TypeScript.ASTList();
   7080            var bodyMinChar = this.scanner.startPos;
   7081            this.checkCurrentToken(TypeScript.TokenID.OpenBrace, errorRecoverySet | TypeScript.ErrorRecoverySet.ID);
   7082            if(svTopLevel && isDynamicMod) {
   7083                this.allowImportDeclaration = true;
   7084            } else {
   7085                this.allowImportDeclaration = false;
   7086            }
   7087            this.parseStatementList(errorRecoverySet | TypeScript.ErrorRecoverySet.RCurly, moduleBody, true, true, TypeScript.AllowedElements.Global, modifiers);
   7088            moduleBody.minChar = bodyMinChar;
   7089            moduleBody.limChar = this.scanner.pos;
   7090            var endingToken = new TypeScript.ASTSpan();
   7091            endingToken.minChar = this.scanner.startPos;
   7092            endingToken.limChar = this.scanner.pos;
   7093            this.checkCurrentToken(TypeScript.TokenID.CloseBrace, errorRecoverySet);
   7094            var limChar = this.scanner.lastTokenLimChar();
   7095            var moduleDecl;
   7096            this.allowImportDeclaration = svTopLevel;
   7097            if(enclosedList && (enclosedList.length > 0)) {
   7098                var len = enclosedList.length;
   7099                var innerName = enclosedList[len - 1];
   7100                var innerDecl = new TypeScript.ModuleDeclaration(innerName, moduleBody, this.topVarList(), this.topScopeList(), endingToken);
   7101                innerDecl.preComments = preComments;
   7102                if(this.parsingDeclareFile || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Ambient)) {
   7103                    innerDecl.modFlags |= TypeScript.ModuleFlags.Ambient;
   7104                }
   7105                innerDecl.modFlags |= TypeScript.ModuleFlags.Exported;
   7106                innerDecl.minChar = minChar;
   7107                innerDecl.limChar = limChar;
   7108                this.popDeclLists();
   7109                var outerModBod;
   7110                for(var i = len - 2; i >= 0; i--) {
   7111                    outerModBod = new TypeScript.ASTList();
   7112                    outerModBod.append(innerDecl);
   7113                    innerName = enclosedList[i];
   7114                    innerDecl = new TypeScript.ModuleDeclaration(innerName, outerModBod, new TypeScript.ASTList(), new TypeScript.ASTList(), endingToken);
   7115                    outerModBod.minChar = innerDecl.minChar = minChar;
   7116                    outerModBod.limChar = innerDecl.limChar = limChar;
   7117                    if(this.parsingDeclareFile || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Ambient)) {
   7118                        innerDecl.modFlags |= TypeScript.ModuleFlags.Ambient;
   7119                    }
   7120                    innerDecl.modFlags |= TypeScript.ModuleFlags.Exported;
   7121                }
   7122                outerModBod = new TypeScript.ASTList();
   7123                outerModBod.append(innerDecl);
   7124                outerModBod.minChar = minChar;
   7125                outerModBod.limChar = limChar;
   7126                moduleDecl = new TypeScript.ModuleDeclaration(name, outerModBod, new TypeScript.ASTList(), new TypeScript.ASTList(), endingToken);
   7127            } else {
   7128                moduleDecl = new TypeScript.ModuleDeclaration(name, moduleBody, this.topVarList(), this.topScopeList(), endingToken);
   7129                moduleDecl.preComments = preComments;
   7130                this.popDeclLists();
   7131            }
   7132            if(this.parsingDeclareFile || svAmbient || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Ambient)) {
   7133                moduleDecl.modFlags |= TypeScript.ModuleFlags.Ambient;
   7134            }
   7135            if(svAmbient || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Exported)) {
   7136                moduleDecl.modFlags |= TypeScript.ModuleFlags.Exported;
   7137            }
   7138            if(isDynamicMod) {
   7139                moduleDecl.modFlags |= TypeScript.ModuleFlags.IsDynamic;
   7140            }
   7141            this.ambientModule = svAmbient;
   7142            this.topLevel = svTopLevel;
   7143            moduleDecl.leftCurlyCount = this.scanner.leftCurlyCount - leftCurlyCount;
   7144            moduleDecl.rightCurlyCount = this.scanner.rightCurlyCount - rightCurlyCount;
   7145            moduleDecl.limChar = moduleBody.limChar;
   7146            return moduleDecl;
   7147        };
   7148        Parser.prototype.parseTypeReferenceTail = function (errorRecoverySet, minChar, term) {
   7149            var result = new TypeScript.TypeReference(term, 0);
   7150            result.minChar = minChar;
   7151            while(this.currentToken.tokenId == TypeScript.TokenID.OpenBracket) {
   7152                this.currentToken = this.scanner.scan();
   7153                result.arrayCount++;
   7154                this.checkCurrentToken(TypeScript.TokenID.CloseBracket, errorRecoverySet | TypeScript.ErrorRecoverySet.LBrack);
   7155            }
   7156            result.limChar = this.scanner.lastTokenLimChar();
   7157            return result;
   7158        };
   7159        Parser.prototype.parseNamedType = function (errorRecoverySet, minChar, term, tail) {
   7160            this.currentToken = this.scanner.scan();
   7161            if(this.currentToken.tokenId == TypeScript.TokenID.Dot) {
   7162                var curpos = this.scanner.pos;
   7163                this.currentToken = this.scanner.scan();
   7164                if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) || ((!this.errorRecovery || !this.scanner.lastTokenHadNewline()) && TypeScript.convertTokToID(this.currentToken, this.strictMode))) {
   7165                    var op2 = TypeScript.Identifier.fromToken(this.currentToken);
   7166                    op2.minChar = this.scanner.startPos;
   7167                    op2.limChar = this.scanner.pos;
   7168                    var dotNode = new TypeScript.BinaryExpression(TypeScript.NodeType.Dot, term, op2);
   7169                    dotNode.minChar = term.minChar;
   7170                    dotNode.limChar = op2.limChar;
   7171                    return this.parseNamedType(errorRecoverySet, minChar, dotNode, tail);
   7172                } else {
   7173                    this.reportParseError("need identifier after '.'");
   7174                    if(this.errorRecovery) {
   7175                        term.flags |= TypeScript.ASTFlags.DotLHS;
   7176                        term.limChar = this.scanner.lastTokenLimChar();
   7177                        return term;
   7178                    } else {
   7179                        var eop2 = new TypeScript.MissingIdentifier();
   7180                        eop2.minChar = this.scanner.pos;
   7181                        eop2.limChar = this.scanner.pos;
   7182                        var edotNode = new TypeScript.BinaryExpression(TypeScript.NodeType.Dot, term, eop2);
   7183                        edotNode.flags |= TypeScript.ASTFlags.Error;
   7184                        edotNode.minChar = term.minChar;
   7185                        edotNode.limChar = eop2.limChar;
   7186                        return this.parseNamedType(errorRecoverySet, minChar, edotNode, tail);
   7187                    }
   7188                }
   7189            } else {
   7190                if(tail) {
   7191                    return this.parseTypeReferenceTail(errorRecoverySet, minChar, term);
   7192                } else {
   7193                    return term;
   7194                }
   7195            }
   7196        };
   7197        Parser.prototype.parseTypeReference = function (errorRecoverySet, allowVoid) {
   7198            var minChar = this.scanner.startPos;
   7199            var isConstructorMember = false;
   7200            switch(this.currentToken.tokenId) {
   7201                case TypeScript.TokenID.Void: {
   7202                    if(!allowVoid) {
   7203                        this.reportParseError("void not a valid type in this context");
   7204                    }
   7205 
   7206                }
   7207                case TypeScript.TokenID.Any:
   7208                case TypeScript.TokenID.Number:
   7209                case TypeScript.TokenID.Bool:
   7210                case TypeScript.TokenID.String: {
   7211                    var text = TypeScript.tokenTable[this.currentToken.tokenId].text;
   7212                    var predefinedIdentifier = new TypeScript.Identifier(text);
   7213                    predefinedIdentifier.minChar = minChar;
   7214                    predefinedIdentifier.limChar = this.scanner.pos;
   7215                    this.currentToken = this.scanner.scan();
   7216                    return this.parseTypeReferenceTail(errorRecoverySet, minChar, predefinedIdentifier);
   7217                }
   7218 
   7219                case TypeScript.TokenID.Identifier: {
   7220                    var ident = this.createRef(this.currentToken.getText(), (this.currentToken).hasEscapeSequence, minChar);
   7221                    ident.limChar = this.scanner.pos;
   7222                    return this.parseNamedType(errorRecoverySet, minChar, ident, true);
   7223 
   7224                }
   7225                case TypeScript.TokenID.OpenBrace: {
   7226                    return this.parseObjectType(minChar, errorRecoverySet);
   7227 
   7228                }
   7229                case TypeScript.TokenID.New: {
   7230                    this.currentToken = this.scanner.scan();
   7231                    if(this.currentToken.tokenId != TypeScript.TokenID.OpenParen) {
   7232                        this.reportParseError("Expected '('");
   7233                    } else {
   7234                        isConstructorMember = true;
   7235                    }
   7236 
   7237                }
   7238                case TypeScript.TokenID.OpenParen: {
   7239                    var formals = new TypeScript.ASTList();
   7240                    var variableArgList = this.parseFormalParameterList(errorRecoverySet | TypeScript.ErrorRecoverySet.RParen, formals, false, true, false, false, false, false, null, true);
   7241                    this.checkCurrentToken(TypeScript.TokenID.EqualsGreaterThan, errorRecoverySet);
   7242                    var returnType = this.parseTypeReference(errorRecoverySet, true);
   7243                    var funcDecl = new TypeScript.FuncDecl(null, null, false, formals, null, null, null, TypeScript.NodeType.FuncDecl);
   7244                    funcDecl.returnTypeAnnotation = returnType;
   7245                    funcDecl.variableArgList = variableArgList;
   7246                    funcDecl.fncFlags |= TypeScript.FncFlags.Signature;
   7247                    if(isConstructorMember) {
   7248                        funcDecl.fncFlags |= TypeScript.FncFlags.ConstructMember;
   7249                        funcDecl.hint = "_construct";
   7250                        funcDecl.classDecl = null;
   7251                    }
   7252                    funcDecl.minChar = minChar;
   7253                    return this.parseTypeReferenceTail(errorRecoverySet, minChar, funcDecl);
   7254                }
   7255 
   7256                default: {
   7257                    this.reportParseError("Expected type name");
   7258                    var etr = new TypeScript.TypeReference(null, 0);
   7259                    etr.flags |= TypeScript.ASTFlags.Error;
   7260                    etr.minChar = this.scanner.pos;
   7261                    etr.limChar = this.scanner.pos;
   7262                    return etr;
   7263 
   7264                }
   7265            }
   7266        };
   7267        Parser.prototype.parseObjectType = function (minChar, errorRecoverySet) {
   7268            this.currentToken = this.scanner.scan();
   7269            var members = new TypeScript.ASTList();
   7270            members.minChar = minChar;
   7271            var prevInInterfaceDecl = this.inInterfaceDecl;
   7272            this.inInterfaceDecl = true;
   7273            this.parseTypeMemberList(errorRecoverySet | TypeScript.ErrorRecoverySet.RCurly, members);
   7274            this.inInterfaceDecl = prevInInterfaceDecl;
   7275            this.checkCurrentToken(TypeScript.TokenID.CloseBrace, errorRecoverySet);
   7276            var interfaceDecl = new TypeScript.InterfaceDeclaration(this.anonId, members, null, null);
   7277            interfaceDecl.minChar = minChar;
   7278            interfaceDecl.limChar = members.limChar;
   7279            return this.parseTypeReferenceTail(errorRecoverySet, minChar, interfaceDecl);
   7280        };
   7281        Parser.prototype.parseFunctionBlock = function (errorRecoverySet, allowedElements, parentModifiers, bod, bodMinChar) {
   7282            this.state = ParseState.StartStatementList;
   7283            this.checkCurrentToken(TypeScript.TokenID.OpenBrace, errorRecoverySet | TypeScript.ErrorRecoverySet.StmtStart);
   7284            var savedInFunction = this.inFunction;
   7285            this.inFunction = true;
   7286            this.parseStatementList(errorRecoverySet | TypeScript.ErrorRecoverySet.RCurly | TypeScript.ErrorRecoverySet.StmtStart, bod, true, false, allowedElements, parentModifiers);
   7287            bod.minChar = bodMinChar;
   7288            bod.limChar = this.scanner.pos;
   7289            this.inFunction = savedInFunction;
   7290            var ec = new TypeScript.EndCode();
   7291            ec.minChar = bod.limChar;
   7292            ec.limChar = ec.minChar;
   7293            bod.append(ec);
   7294        };
   7295        Parser.prototype.parseFunctionStatements = function (errorRecoverySet, name, isConstructor, isMethod, args, allowedElements, minChar, requiresSignature, parentModifiers) {
   7296            this.pushDeclLists();
   7297            var svStmtStack = this.statementInfoStack;
   7298            this.resetStmtStack();
   7299            var bod = null;
   7300            var wasShorthand = false;
   7301            var isAnonLambda = false;
   7302            var limChar;
   7303            if(requiresSignature) {
   7304                limChar = this.scanner.pos;
   7305                if(this.currentToken.tokenId === TypeScript.TokenID.OpenBrace) {
   7306                    this.reportParseError("Function declarations are not permitted within interfaces, ambient modules or classes");
   7307                    bod = new TypeScript.ASTList();
   7308                    var bodMinChar = this.scanner.startPos;
   7309                    this.parseFunctionBlock(errorRecoverySet, allowedElements, parentModifiers, bod, bodMinChar);
   7310                    this.checkCurrentToken(TypeScript.TokenID.CloseBrace, errorRecoverySet);
   7311                    if(this.currentToken.tokenId === TypeScript.TokenID.Semicolon) {
   7312                        this.currentToken = this.scanner.scan();
   7313                    }
   7314                } else {
   7315                    this.checkCurrentToken(TypeScript.TokenID.Semicolon, errorRecoverySet, "Expected ';'");
   7316                }
   7317            } else {
   7318                bod = new TypeScript.ASTList();
   7319                var bodMinChar = this.scanner.startPos;
   7320                if(this.currentToken.tokenId == TypeScript.TokenID.EqualsGreaterThan) {
   7321                    if(isMethod) {
   7322                        this.reportParseError("'=>' may not be used for class methods");
   7323                    }
   7324                    wasShorthand = true;
   7325                    this.currentToken = this.scanner.scan();
   7326                }
   7327                if(wasShorthand && this.currentToken.tokenId != TypeScript.TokenID.OpenBrace) {
   7328                    var retExpr = this.parseExpr(errorRecoverySet | TypeScript.ErrorRecoverySet.SColon, TypeScript.OperatorPrecedence.Assignment, true, TypeContext.NoTypes);
   7329                    var retStmt = new TypeScript.ReturnStatement();
   7330                    retStmt.returnExpression = retExpr;
   7331                    retStmt.minChar = retExpr.minChar;
   7332                    retStmt.limChar = retExpr.limChar;
   7333                    bod.minChar = bodMinChar;
   7334                    bod.append(retStmt);
   7335                } else {
   7336                    isAnonLambda = wasShorthand;
   7337                    this.parseFunctionBlock(errorRecoverySet, allowedElements, parentModifiers, bod, bodMinChar);
   7338                }
   7339                limChar = this.scanner.pos;
   7340            }
   7341            var funcDecl = new TypeScript.FuncDecl(name, bod, isConstructor, args, this.topVarList(), this.topScopeList(), this.topStaticsList(), TypeScript.NodeType.FuncDecl);
   7342            this.popDeclLists();
   7343            var scopeList = this.topScopeList();
   7344            scopeList.append(funcDecl);
   7345            var staticFuncDecl = false;
   7346            if(!requiresSignature) {
   7347                if(!wasShorthand || isAnonLambda) {
   7348                    funcDecl.endingToken = new TypeScript.ASTSpan();
   7349                    funcDecl.endingToken.minChar = this.scanner.startPos;
   7350                    funcDecl.endingToken.limChar = this.scanner.pos;
   7351                    this.checkCurrentToken(TypeScript.TokenID.CloseBrace, errorRecoverySet);
   7352                    if(isAnonLambda) {
   7353                        funcDecl.fncFlags |= TypeScript.FncFlags.IsFatArrowFunction;
   7354                    }
   7355                } else {
   7356                    funcDecl.fncFlags |= TypeScript.FncFlags.IsFatArrowFunction;
   7357                    funcDecl.endingToken = new TypeScript.ASTSpan();
   7358                    funcDecl.endingToken.minChar = bod.members[0].minChar;
   7359                    funcDecl.endingToken.limChar = bod.members[0].limChar;
   7360                }
   7361            }
   7362            funcDecl.minChar = minChar;
   7363            funcDecl.limChar = limChar;
   7364            if(!requiresSignature) {
   7365                funcDecl.fncFlags |= TypeScript.FncFlags.Definition;
   7366            }
   7367            this.statementInfoStack = svStmtStack;
   7368            return funcDecl;
   7369        };
   7370        Parser.prototype.transformAnonymousArgsIntoFormals = function (formals, argList) {
   7371            var _this = this;
   7372            var translateBinExOperand = function (operand) {
   7373                if(operand.nodeType == TypeScript.NodeType.Comma) {
   7374                    return _this.transformAnonymousArgsIntoFormals(formals, operand);
   7375                } else {
   7376                    if(operand.nodeType == TypeScript.NodeType.Name || operand.nodeType == TypeScript.NodeType.Asg) {
   7377                        var opArg = operand.nodeType == TypeScript.NodeType.Asg ? (operand).operand1 : operand;
   7378                        var arg = new TypeScript.ArgDecl(opArg);
   7379                        arg.preComments = opArg.preComments;
   7380                        arg.postComments = opArg.postComments;
   7381                        arg.minChar = operand.minChar;
   7382                        arg.limChar = operand.limChar;
   7383                        if(TypeScript.hasFlag(opArg.flags, TypeScript.ASTFlags.PossibleOptionalParameter)) {
   7384                            arg.isOptional = true;
   7385                        }
   7386                        if(operand.nodeType == TypeScript.NodeType.Asg) {
   7387                            arg.init = (operand).operand2;
   7388                        }
   7389                        formals.append(arg);
   7390                        return arg.isOptional || arg.init;
   7391                    } else {
   7392                        _this.reportParseError("Invalid lambda argument");
   7393                    }
   7394                }
   7395                return false;
   7396            };
   7397            if(argList) {
   7398                if(argList.nodeType == TypeScript.NodeType.Comma) {
   7399                    var commaList = argList;
   7400                    if(commaList.operand1.isParenthesized) {
   7401                        this.reportParseError("Invalid lambda argument", commaList.operand1.minChar, commaList.operand1.limChar);
   7402                    }
   7403                    if(commaList.operand2.isParenthesized) {
   7404                        this.reportParseError("Invalid lambda argument", commaList.operand2.minChar, commaList.operand2.limChar);
   7405                    }
   7406                    var isOptional = translateBinExOperand(commaList.operand1);
   7407                    isOptional = translateBinExOperand(commaList.operand2) || isOptional;
   7408                    return isOptional;
   7409                } else {
   7410                    return translateBinExOperand(argList);
   7411                }
   7412            }
   7413        };
   7414        Parser.prototype.parseFormalParameterList = function (errorRecoverySet, formals, isClassConstr, isSig, isIndexer, isGetter, isSetter, isLambda, preProcessedLambdaArgs, expectClosingRParen) {
   7415            formals.minChar = this.scanner.startPos;
   7416            if(isIndexer) {
   7417                this.currentToken = this.scanner.scan();
   7418            } else {
   7419                if(!isLambda) {
   7420                    this.checkCurrentToken(TypeScript.TokenID.OpenParen, errorRecoverySet | TypeScript.ErrorRecoverySet.RParen);
   7421                }
   7422            }
   7423            var sawEllipsis = false;
   7424            var firstArg = true;
   7425            var hasOptional = false;
   7426            var haveFirstArgID = false;
   7427            if(isLambda && preProcessedLambdaArgs && preProcessedLambdaArgs.nodeType != TypeScript.NodeType.EmptyExpr) {
   7428                hasOptional = this.transformAnonymousArgsIntoFormals(formals, preProcessedLambdaArgs);
   7429                haveFirstArgID = true;
   7430            }
   7431            while(true) {
   7432                var munchedArg = false;
   7433                var argFlags = TypeScript.VarFlags.None;
   7434                var argMinChar = this.scanner.startPos;
   7435                if(this.inferPropertiesFromThisAssignment && this.currentToken.tokenId == TypeScript.TokenID.This) {
   7436                    if(!isClassConstr) {
   7437                        this.reportParseError("Instance property declarations using 'this' may only be used in class constructors");
   7438                    }
   7439                    this.currentToken = this.scanner.scan();
   7440                    argFlags |= (TypeScript.VarFlags.Public | TypeScript.VarFlags.Property);
   7441                    if(this.currentClassDefinition) {
   7442                        this.currentClassDefinition.varFlags |= TypeScript.VarFlags.ClassSuperMustBeFirstCallInConstructor;
   7443                    }
   7444                }
   7445                if(this.currentToken.tokenId == TypeScript.TokenID.Public) {
   7446                    argFlags |= (TypeScript.VarFlags.Public | TypeScript.VarFlags.Property);
   7447                    if(this.currentClassDefinition) {
   7448                        this.currentClassDefinition.varFlags |= TypeScript.VarFlags.ClassSuperMustBeFirstCallInConstructor;
   7449                    }
   7450                } else {
   7451                    if(this.currentToken.tokenId == TypeScript.TokenID.Private) {
   7452                        argFlags |= (TypeScript.VarFlags.Private | TypeScript.VarFlags.Property);
   7453                        if(this.currentClassDefinition) {
   7454                            this.currentClassDefinition.varFlags |= TypeScript.VarFlags.ClassSuperMustBeFirstCallInConstructor;
   7455                        }
   7456                    } else {
   7457                        if(this.currentToken.tokenId == TypeScript.TokenID.Static && isClassConstr) {
   7458                            this.reportParseError("Static properties can not be declared as parameter properties");
   7459                            this.currentToken = this.scanner.scan();
   7460                        }
   7461                    }
   7462                }
   7463                if(argFlags != TypeScript.VarFlags.None) {
   7464                    if(!isClassConstr) {
   7465                        this.reportParseError("only constructor parameters can be properties");
   7466                    }
   7467                    this.currentToken = this.scanner.scan();
   7468                    if(TypeScript.isModifier(this.currentToken)) {
   7469                        this.reportParseError("Multiple modifiers may not be applied to parameters");
   7470                        this.currentToken = this.scanner.scan();
   7471                    }
   7472                    if(this.inferPropertiesFromThisAssignment && this.currentToken.tokenId == TypeScript.TokenID.This) {
   7473                        if(!isClassConstr) {
   7474                            this.reportParseError("Instance property declarations using 'this' may only be used in class constructors");
   7475                        }
   7476                        this.currentToken = this.scanner.scan();
   7477                        this.currentToken = this.scanner.scan();
   7478                    }
   7479                } else {
   7480                    if(this.currentToken.tokenId == TypeScript.TokenID.DotDotDot) {
   7481                        sawEllipsis = true;
   7482                        this.currentToken = this.scanner.scan();
   7483                        if(!(this.currentToken.tokenId == TypeScript.TokenID.Identifier) || TypeScript.convertTokToID(this.currentToken, this.strictMode)) {
   7484                            this.reportParseError("'...' parameters require both a parameter name and an array type annotation to be specified");
   7485                            sawEllipsis = false;
   7486                        }
   7487                    }
   7488                }
   7489                var argId = null;
   7490                if(!haveFirstArgID && (this.currentToken.tokenId == TypeScript.TokenID.Identifier) || TypeScript.convertTokToID(this.currentToken, this.strictMode)) {
   7491                    argId = TypeScript.Identifier.fromToken(this.currentToken);
   7492                    argId.minChar = this.scanner.startPos;
   7493                    argId.limChar = this.scanner.pos;
   7494                }
   7495                if(haveFirstArgID || argId) {
   7496                    munchedArg = true;
   7497                    var type = null;
   7498                    var arg = null;
   7499                    if(haveFirstArgID && formals.members.length) {
   7500                        arg = formals.members[formals.members.length - 1];
   7501                        if(arg.isOptional) {
   7502                            hasOptional = true;
   7503                        }
   7504                    } else {
   7505                        arg = new TypeScript.ArgDecl(argId);
   7506                        if(isGetter) {
   7507                            this.reportParseError("Property getters may not take any arguments");
   7508                        }
   7509                        if(isSetter && !firstArg) {
   7510                            this.reportParseError("Property setters may only take one argument");
   7511                        }
   7512                        arg.minChar = argMinChar;
   7513                        arg.preComments = this.parseComments();
   7514                        this.currentToken = this.scanner.scan();
   7515                    }
   7516                    if(this.currentToken.tokenId == TypeScript.TokenID.Question) {
   7517                        arg.isOptional = true;
   7518                        hasOptional = true;
   7519                        this.currentToken = this.scanner.scan();
   7520                    }
   7521                    if(this.currentToken.tokenId == TypeScript.TokenID.Colon) {
   7522                        this.currentToken = this.scanner.scan();
   7523                        type = this.parseTypeReference(errorRecoverySet, false);
   7524                    }
   7525                    if(this.currentToken.tokenId == TypeScript.TokenID.Equals) {
   7526                        if(isSig) {
   7527                            this.reportParseError("Arguments in signatures may not have default values");
   7528                        }
   7529                        hasOptional = true;
   7530                        this.currentToken = this.scanner.scan();
   7531                        arg.init = this.parseExpr(TypeScript.ErrorRecoverySet.Comma | errorRecoverySet, TypeScript.OperatorPrecedence.Comma, false, TypeContext.NoTypes);
   7532                    }
   7533                    if(hasOptional && !arg.isOptionalArg() && !sawEllipsis) {
   7534                        this.reportParseError("Optional parameters may only be followed by other optional parameters");
   7535                    }
   7536                    if(sawEllipsis && arg.isOptionalArg()) {
   7537                        this.reportParseError("Varargs may not be optional or have default parameters");
   7538                    }
   7539                    if(sawEllipsis && !type) {
   7540                        this.reportParseError("'...' parameters require both a parameter name and an array type annotation to be specified");
   7541                    }
   7542                    arg.postComments = this.parseComments();
   7543                    arg.typeExpr = type;
   7544                    arg.limChar = this.scanner.lastTokenLimChar();
   7545                    arg.varFlags |= argFlags;
   7546                    if(!haveFirstArgID) {
   7547                        formals.append(arg);
   7548                    } else {
   7549                        haveFirstArgID = false;
   7550                    }
   7551                }
   7552                firstArg = false;
   7553                if(this.currentToken.tokenId == TypeScript.TokenID.Comma) {
   7554                    if((munchedArg) && (!sawEllipsis)) {
   7555                        this.currentToken = this.scanner.scan();
   7556                        continue;
   7557                    } else {
   7558                        this.reportParseError("Unexpected ',' in argument list");
   7559                        if(this.errorRecovery) {
   7560                            this.currentToken = this.scanner.scan();
   7561                            continue;
   7562                        }
   7563                    }
   7564                } else {
   7565                    break;
   7566                }
   7567            }
   7568            if(isIndexer) {
   7569                this.checkCurrentToken(TypeScript.TokenID.CloseBracket, errorRecoverySet | TypeScript.ErrorRecoverySet.LCurly | TypeScript.ErrorRecoverySet.SColon);
   7570            } else {
   7571                if(expectClosingRParen) {
   7572                    this.checkCurrentToken(TypeScript.TokenID.CloseParen, errorRecoverySet | TypeScript.ErrorRecoverySet.LCurly | TypeScript.ErrorRecoverySet.SColon);
   7573                }
   7574            }
   7575            formals.limChar = this.scanner.lastTokenLimChar();
   7576            return sawEllipsis;
   7577        };
   7578        Parser.prototype.parseFncDecl = function (errorRecoverySet, isDecl, requiresSignature, isMethod, methodName, indexer, isStatic, markedAsAmbient, modifiers, lambdaArgContext, expectClosingRParen) {
   7579            var leftCurlyCount = this.scanner.leftCurlyCount;
   7580            var rightCurlyCount = this.scanner.rightCurlyCount;
   7581            var prevInConstr = this.parsingClassConstructorDefinition;
   7582            this.parsingClassConstructorDefinition = false;
   7583            var name = null;
   7584            var fnMin = this.scanner.startPos;
   7585            var minChar = this.scanner.pos;
   7586            var prevNestingLevel = this.nestingLevel;
   7587            var preComments = this.parseComments();
   7588            var isLambda = !!lambdaArgContext;
   7589            this.nestingLevel = 0;
   7590            if((!this.style_funcInLoop) && this.inLoop()) {
   7591                this.reportParseStyleError("function declaration in loop");
   7592            }
   7593            if(!isMethod && !isStatic && !indexer && !lambdaArgContext) {
   7594                this.currentToken = this.scanner.scan();
   7595                this.state = ParseState.StartFncDecl;
   7596                if((this.currentToken.tokenId != TypeScript.TokenID.Identifier) && (!TypeScript.convertTokToID(this.currentToken, this.strictMode))) {
   7597                    if(isDecl) {
   7598                        this.reportParseError("Function declaration must include identifier");
   7599                        this.nestingLevel = prevNestingLevel;
   7600                        return new TypeScript.IncompleteAST(fnMin, this.scanner.pos);
   7601                    }
   7602                } else {
   7603                    name = TypeScript.Identifier.fromToken(this.currentToken);
   7604                    name.minChar = this.scanner.startPos;
   7605                    name.limChar = this.scanner.pos;
   7606                    this.currentToken = this.scanner.scan();
   7607                }
   7608            } else {
   7609                if(methodName) {
   7610                    name = methodName;
   7611                }
   7612            }
   7613            this.state = ParseState.FncDeclName;
   7614            var args = new TypeScript.ASTList();
   7615            var variableArgList = false;
   7616            var isOverload = false;
   7617            var isGetter = TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Getter);
   7618            var isSetter = TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Setter);
   7619            if((this.currentToken.tokenId == TypeScript.TokenID.OpenParen) || (indexer && (this.currentToken.tokenId == TypeScript.TokenID.OpenBracket)) || (lambdaArgContext && (lambdaArgContext.preProcessedLambdaArgs || this.currentToken.tokenId == TypeScript.TokenID.DotDotDot))) {
   7620                variableArgList = this.parseFormalParameterList(errorRecoverySet, args, false, requiresSignature, indexer, isGetter, isSetter, isLambda, lambdaArgContext ? lambdaArgContext.preProcessedLambdaArgs : null, expectClosingRParen);
   7621            }
   7622            this.state = ParseState.FncDeclArgs;
   7623            var returnType = null;
   7624            if(this.currentToken.tokenId == TypeScript.TokenID.Colon) {
   7625                this.currentToken = this.scanner.scan();
   7626                if(TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Setter)) {
   7627                    this.reportParseError("Property setters may not declare a return type");
   7628                }
   7629                returnType = this.parseTypeReference(errorRecoverySet, true);
   7630            }
   7631            if(indexer && args.members.length == 0) {
   7632                this.reportParseError("Index signatures require a parameter type to be specified");
   7633            }
   7634            this.state = ParseState.FncDeclReturnType;
   7635            if(isLambda && this.currentToken.tokenId != TypeScript.TokenID.EqualsGreaterThan) {
   7636                this.reportParseError("Expected '=>'");
   7637            }
   7638            if(isDecl && !(this.parsingDeclareFile || markedAsAmbient) && (!isMethod || !(this.ambientModule || this.ambientClass || this.inInterfaceDecl)) && this.currentToken.tokenId == TypeScript.TokenID.Semicolon) {
   7639                isOverload = true;
   7640                isDecl = false;
   7641                requiresSignature = true;
   7642            }
   7643            var svInFncDecl = this.inFncDecl;
   7644            this.inFncDecl = true;
   7645            var funcDecl = this.parseFunctionStatements(errorRecoverySet | TypeScript.ErrorRecoverySet.RCurly, name, false, isMethod, args, TypeScript.AllowedElements.None, minChar, requiresSignature, TypeScript.Modifiers.None);
   7646            this.inFncDecl = svInFncDecl;
   7647            funcDecl.variableArgList = variableArgList;
   7648            funcDecl.isOverload = isOverload;
   7649            if(!requiresSignature) {
   7650                funcDecl.fncFlags |= TypeScript.FncFlags.Definition;
   7651            }
   7652            if(isStatic) {
   7653                funcDecl.fncFlags |= TypeScript.FncFlags.Static;
   7654            }
   7655            if(requiresSignature) {
   7656                funcDecl.fncFlags |= TypeScript.FncFlags.Signature;
   7657            }
   7658            if(indexer) {
   7659                funcDecl.fncFlags |= TypeScript.FncFlags.IndexerMember;
   7660            }
   7661            funcDecl.returnTypeAnnotation = returnType;
   7662            if(isMethod) {
   7663                funcDecl.fncFlags |= TypeScript.FncFlags.Method;
   7664                funcDecl.fncFlags |= TypeScript.FncFlags.ClassPropertyMethodExported;
   7665            }
   7666            funcDecl.leftCurlyCount = this.scanner.leftCurlyCount - leftCurlyCount;
   7667            funcDecl.rightCurlyCount = this.scanner.rightCurlyCount - rightCurlyCount;
   7668            this.nestingLevel = prevNestingLevel;
   7669            this.parsingClassConstructorDefinition = prevInConstr;
   7670            funcDecl.preComments = preComments;
   7671            return funcDecl;
   7672        };
   7673        Parser.prototype.convertToTypeReference = function (ast) {
   7674            var result;
   7675            switch(ast.nodeType) {
   7676                case TypeScript.NodeType.TypeRef: {
   7677                    return ast;
   7678 
   7679                }
   7680                case TypeScript.NodeType.Name: {
   7681                    result = new TypeScript.TypeReference(ast, 0);
   7682                    result.minChar = ast.minChar;
   7683                    result.limChar = ast.limChar;
   7684                    return result;
   7685 
   7686                }
   7687                case TypeScript.NodeType.Index: {
   7688                    var expr = ast;
   7689                    result = this.convertToTypeReference(expr.operand1);
   7690                    if(result) {
   7691                        result.arrayCount++;
   7692                        result.minChar = expr.minChar;
   7693                        result.limChar = expr.limChar;
   7694                        return result;
   7695                    } else {
   7696                        var etr = new TypeScript.AST(TypeScript.NodeType.Error);
   7697                        return etr;
   7698                    }
   7699                }
   7700 
   7701            }
   7702            return null;
   7703        };
   7704        Parser.prototype.parseArgList = function (errorRecoverySet) {
   7705            var args = new TypeScript.ASTList();
   7706            args.minChar = this.scanner.startPos;
   7707            this.currentToken = this.scanner.scan();
   7708            if(this.currentToken.tokenId !== TypeScript.TokenID.CloseParen) {
   7709                while(true) {
   7710                    if(args.members.length > 65535) {
   7711                        this.reportParseError("max number of args exceeded");
   7712                        break;
   7713                    }
   7714                    var arg = this.parseExpr(TypeScript.ErrorRecoverySet.Comma | errorRecoverySet, TypeScript.OperatorPrecedence.Comma, true, TypeContext.NoTypes);
   7715                    args.append(arg);
   7716                    if(this.currentToken.tokenId != TypeScript.TokenID.Comma) {
   7717                        break;
   7718                    }
   7719                    this.currentToken = this.scanner.scan();
   7720                }
   7721            }
   7722            args.limChar = this.scanner.pos;
   7723            return args;
   7724        };
   7725        Parser.prototype.parseBaseList = function (extendsList, implementsList, errorRecoverySet, isClass) {
   7726            var keyword = true;
   7727            var currentList = extendsList;
   7728            for(; ; ) {
   7729                if(keyword) {
   7730                    if(this.currentToken.tokenId === TypeScript.TokenID.Implements) {
   7731                        currentList = implementsList;
   7732                    } else {
   7733                        if(this.currentToken.tokenId == TypeScript.TokenID.Extends && !this.requiresExtendsBlock) {
   7734                            this.requiresExtendsBlock = isClass;
   7735                        }
   7736                    }
   7737                    this.currentToken = this.scanner.scan();
   7738                    keyword = false;
   7739                }
   7740                var baseName = null;
   7741                if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) || TypeScript.convertTokToID(this.currentToken, this.strictMode)) {
   7742                    var minChar = this.scanner.startPos;
   7743                    baseName = TypeScript.Identifier.fromToken(this.currentToken);
   7744                    baseName.minChar = minChar;
   7745                    baseName.limChar = this.scanner.pos;
   7746                    baseName = this.parseNamedType(errorRecoverySet | TypeScript.ErrorRecoverySet.LCurly, minChar, baseName, false);
   7747                } else {
   7748                    this.reportParseError("Expected base name");
   7749                    if(this.errorRecovery) {
   7750                        baseName = new TypeScript.MissingIdentifier();
   7751                        baseName.minChar = this.scanner.pos;
   7752                        baseName.limChar = this.scanner.pos;
   7753                        baseName.flags |= TypeScript.ASTFlags.Error;
   7754                    }
   7755                }
   7756                if(this.currentToken.tokenId == TypeScript.TokenID.OpenParen) {
   7757                    if(isClass) {
   7758                        this.reportParseError("Base classes may only be initialized via a 'super' call within the constructor body");
   7759                    } else {
   7760                        this.reportParseError("Interfaces may not be extended with a call expression");
   7761                    }
   7762                } else {
   7763                    currentList.append(baseName);
   7764                }
   7765                if(isClass && currentList == extendsList && extendsList.members.length > 1) {
   7766                    this.reportParseError("A class may only extend one other class");
   7767                }
   7768                if(this.currentToken.tokenId == TypeScript.TokenID.Comma) {
   7769                    this.currentToken = this.scanner.scan();
   7770                    continue;
   7771                } else {
   7772                    if((this.currentToken.tokenId == TypeScript.TokenID.Extends) || (this.currentToken.tokenId == TypeScript.TokenID.Implements)) {
   7773                        if(this.currentToken.tokenId == TypeScript.TokenID.Extends && !this.requiresExtendsBlock) {
   7774                            this.requiresExtendsBlock = isClass;
   7775                        }
   7776                        currentList = extendsList;
   7777                        keyword = true;
   7778                        continue;
   7779                    }
   7780                }
   7781                break;
   7782            }
   7783        };
   7784        Parser.prototype.parseClassDecl = function (errorRecoverySet, minChar, modifiers) {
   7785            var leftCurlyCount = this.scanner.leftCurlyCount;
   7786            var rightCurlyCount = this.scanner.rightCurlyCount;
   7787            if((modifiers & TypeScript.Modifiers.Readonly) != TypeScript.Modifiers.None) {
   7788                this.reportParseError("const modifier is implicit for class");
   7789            }
   7790            if(this.parsingDeclareFile || this.ambientModule) {
   7791                modifiers |= TypeScript.Modifiers.Ambient;
   7792                modifiers |= TypeScript.Modifiers.Exported;
   7793            }
   7794            var classIsMarkedAsAmbient = this.parsingDeclareFile || (modifiers & TypeScript.Modifiers.Ambient) != TypeScript.Modifiers.None;
   7795            var svAmbientClass = this.ambientClass;
   7796            this.ambientClass = classIsMarkedAsAmbient;
   7797            this.currentToken = this.scanner.scan();
   7798            var name = null;
   7799            if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) || (!TypeScript.isPrimitiveTypeToken(this.currentToken) && TypeScript.convertTokToID(this.currentToken, this.strictMode))) {
   7800                name = TypeScript.Identifier.fromToken(this.currentToken);
   7801                name.minChar = this.scanner.startPos;
   7802                name.limChar = this.scanner.pos;
   7803                this.currentToken = this.scanner.scan();
   7804            } else {
   7805                this.reportParseError("class missing name");
   7806                if(this.errorRecovery) {
   7807                    name = new TypeScript.MissingIdentifier();
   7808                    name.minChar = this.scanner.pos;
   7809                    name.limChar = this.scanner.pos;
   7810                    name.flags |= TypeScript.ASTFlags.Error;
   7811                }
   7812            }
   7813            var extendsList = null;
   7814            var implementsList = null;
   7815            var requiresSignature = false;
   7816            if((this.currentToken.tokenId == TypeScript.TokenID.Extends) || (this.currentToken.tokenId == TypeScript.TokenID.Implements)) {
   7817                extendsList = new TypeScript.ASTList();
   7818                implementsList = new TypeScript.ASTList();
   7819                this.parseBaseList(extendsList, implementsList, errorRecoverySet, true);
   7820            }
   7821            var classDecl = new TypeScript.ClassDeclaration(name, new TypeScript.ASTList(), extendsList, implementsList);
   7822            this.currentClassDefinition = classDecl;
   7823            this.parseClassElements(classDecl, errorRecoverySet, modifiers);
   7824            if(this.ambientModule || this.parsingDeclareFile || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Exported)) {
   7825                classDecl.varFlags |= TypeScript.VarFlags.Exported;
   7826            }
   7827            if(this.ambientModule || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Ambient)) {
   7828                classDecl.varFlags |= TypeScript.VarFlags.Ambient;
   7829            }
   7830            classDecl.varFlags |= TypeScript.VarFlags.Class;
   7831            this.ambientClass = svAmbientClass;
   7832            classDecl.leftCurlyCount = this.scanner.leftCurlyCount - leftCurlyCount;
   7833            classDecl.rightCurlyCount = this.scanner.rightCurlyCount - rightCurlyCount;
   7834            return classDecl;
   7835        };
   7836        Parser.prototype.parseClassElements = function (classDecl, errorRecoverySet, parentModifiers) {
   7837            var modifiers = parentModifiers;
   7838            var resetModifiers = false;
   7839            var membersMinChar = this.scanner.startPos;
   7840            this.checkCurrentToken(TypeScript.TokenID.OpenBrace, errorRecoverySet);
   7841            this.nestingLevel++;
   7842            var currentMemberMinChar = this.scanner.startPos;
   7843            var wasGetOrSetId = false;
   7844            while(!(this.currentToken.tokenId == TypeScript.TokenID.CloseBrace || this.currentToken.tokenId == TypeScript.TokenID.EndOfFile)) {
   7845                var scanNext = true;
   7846                var publicOrPrivateFlags = TypeScript.Modifiers.Public | TypeScript.Modifiers.Private;
   7847                if(this.currentToken.tokenId == TypeScript.TokenID.Get) {
   7848                    if(modifiers & TypeScript.Modifiers.Getter) {
   7849                        this.reportParseError("Duplicate 'get' declaration in class body");
   7850                    }
   7851                    if(modifiers & TypeScript.Modifiers.Setter) {
   7852                        this.reportParseError("Getter already marked as a setter");
   7853                    }
   7854                    modifiers |= TypeScript.Modifiers.Getter;
   7855                } else {
   7856                    if(this.currentToken.tokenId == TypeScript.TokenID.Set) {
   7857                        if(modifiers & TypeScript.Modifiers.Setter) {
   7858                            this.reportParseError("Duplicate 'set' declaration in class body");
   7859                        }
   7860                        if(modifiers & TypeScript.Modifiers.Getter) {
   7861                            this.reportParseError("Setter already marked as a getter");
   7862                        }
   7863                        modifiers |= TypeScript.Modifiers.Setter;
   7864                    } else {
   7865                        if(this.currentToken.tokenId == TypeScript.TokenID.Private) {
   7866                            if(modifiers & publicOrPrivateFlags) {
   7867                                this.reportParseError("Multiple modifiers may not be applied to class members");
   7868                            }
   7869                            modifiers |= TypeScript.Modifiers.Private;
   7870                        } else {
   7871                            if(this.currentToken.tokenId == TypeScript.TokenID.Public) {
   7872                                if(modifiers & publicOrPrivateFlags) {
   7873                                    this.reportParseError("Multiple modifiers may not be applied to class members");
   7874                                }
   7875                                modifiers |= TypeScript.Modifiers.Public;
   7876                            } else {
   7877                                if(this.currentToken.tokenId == TypeScript.TokenID.Static) {
   7878                                    if(modifiers & TypeScript.Modifiers.Static) {
   7879                                        this.reportParseError("Multiple modifiers may not be applied to class members");
   7880                                    }
   7881                                    modifiers |= TypeScript.Modifiers.Static;
   7882                                } else {
   7883                                    if(this.currentToken.tokenId == TypeScript.TokenID.Constructor) {
   7884                                        if(modifiers != parentModifiers) {
   7885                                            this.reportParseError("Constructors may not have modifiers");
   7886                                        }
   7887                                        this.parseClassConstructorDeclaration(currentMemberMinChar, errorRecoverySet, modifiers);
   7888                                        scanNext = false;
   7889                                        resetModifiers = true;
   7890                                    } else {
   7891                                        if(wasGetOrSetId || this.currentToken.tokenId == TypeScript.TokenID.Identifier || TypeScript.convertTokToIDName(this.currentToken)) {
   7892                                            var idText = wasGetOrSetId ? ((modifiers & TypeScript.Modifiers.Getter) ? "get" : "set") : this.currentToken.getText();
   7893                                            var id = wasGetOrSetId ? new TypeScript.Identifier(idText) : TypeScript.Identifier.fromToken(this.currentToken);
   7894                                            id.minChar = this.scanner.startPos;
   7895                                            id.limChar = this.scanner.pos;
   7896                                            if(wasGetOrSetId) {
   7897                                                modifiers = modifiers ^ ((modifiers & TypeScript.Modifiers.Getter) ? TypeScript.Modifiers.Getter : TypeScript.Modifiers.Setter);
   7898                                                wasGetOrSetId = false;
   7899                                            } else {
   7900                                                this.currentToken = this.scanner.scan();
   7901                                            }
   7902                                            if(this.currentToken.tokenId == TypeScript.TokenID.OpenParen) {
   7903                                                this.parseClassMemberFunctionDeclaration(id, currentMemberMinChar, errorRecoverySet, modifiers);
   7904                                                scanNext = false;
   7905                                            } else {
   7906                                                if(modifiers & TypeScript.Modifiers.Getter || modifiers & TypeScript.Modifiers.Setter) {
   7907                                                    this.reportParseError("Property accessors must be functions");
   7908                                                }
   7909                                                var varDecl = this.parseClassMemberVariableDeclaration(id, currentMemberMinChar, false, errorRecoverySet, modifiers);
   7910                                                if(varDecl.init && varDecl.init.nodeType == TypeScript.NodeType.FuncDecl) {
   7911                                                    if(this.currentToken.tokenId == TypeScript.TokenID.CloseBrace) {
   7912                                                        scanNext = false;
   7913                                                    }
   7914                                                } else {
   7915                                                    if(varDecl.init && varDecl.init.nodeType == TypeScript.NodeType.ObjectLit && this.currentToken.tokenId != TypeScript.TokenID.Semicolon) {
   7916                                                        scanNext = false;
   7917                                                        varDecl.init.flags |= TypeScript.ASTFlags.AutomaticSemicolon;
   7918                                                    } else {
   7919                                                        if(this.currentToken.tokenId != TypeScript.TokenID.Semicolon) {
   7920                                                            this.reportParseError("Expected ';'");
   7921                                                            scanNext = false;
   7922                                                        }
   7923                                                    }
   7924                                                }
   7925                                            }
   7926                                            resetModifiers = true;
   7927                                        } else {
   7928                                            if(this.currentToken.tokenId == TypeScript.TokenID.Super) {
   7929                                                this.reportParseError("Base class initializers must be the first statement in a class definition");
   7930                                            } else {
   7931                                                if(!wasGetOrSetId && ((modifiers & TypeScript.Modifiers.Getter) || (modifiers & TypeScript.Modifiers.Setter)) && ((this.currentToken.tokenId == TypeScript.TokenID.OpenParen) || (this.currentToken.tokenId == TypeScript.TokenID.Equals) || (this.currentToken.tokenId == TypeScript.TokenID.Colon) || (this.currentToken.tokenId == TypeScript.TokenID.Semicolon))) {
   7932                                                    wasGetOrSetId = true;
   7933                                                    scanNext = false;
   7934                                                } else {
   7935                                                    if(this.currentToken.tokenId != TypeScript.TokenID.Semicolon) {
   7936                                                        this.reportParseError("Unexpected '" + this.currentToken.getText() + "' in class definition");
   7937                                                        resetModifiers = true;
   7938                                                    }
   7939                                                }
   7940                                            }
   7941                                        }
   7942                                    }
   7943                                }
   7944                            }
   7945                        }
   7946                    }
   7947                }
   7948                if(scanNext) {
   7949                    this.currentToken = this.scanner.scan();
   7950                    if (this.currentToken === undefined) this.currentToken = this.scanner.scan();
   7951                }
   7952                if(resetModifiers) {
   7953                    modifiers = parentModifiers;
   7954                    currentMemberMinChar = this.scanner.startPos;
   7955                    resetModifiers = false;
   7956                }
   7957            }
   7958            var membersLimChar = this.scanner.pos;
   7959            if(this.currentToken.tokenId == TypeScript.TokenID.CloseBrace) {
   7960                classDecl.endingToken = new TypeScript.ASTSpan();
   7961                classDecl.endingToken.minChar = this.scanner.startPos;
   7962                classDecl.endingToken.limChar = this.scanner.pos;
   7963                if(!this.currentClassDefinition.members.members.length) {
   7964                    this.currentClassDefinition.preComments = this.parseComments();
   7965                }
   7966                this.currentToken = this.scanner.scan();
   7967            }
   7968            this.nestingLevel--;
   7969            this.currentClassDefinition.members.minChar = membersMinChar;
   7970            this.currentClassDefinition.members.limChar = membersLimChar;
   7971            this.currentClassDefinition.limChar = membersLimChar;
   7972            this.currentClassDefinition = null;
   7973        };
   7974        Parser.prototype.parseClassConstructorDeclaration = function (minChar, errorRecoverySet, modifiers) {
   7975            this.parsingClassConstructorDefinition = true;
   7976            var isAmbient = this.parsingDeclareFile || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Ambient);
   7977            var args = new TypeScript.ASTList();
   7978            var variableArgList = false;
   7979            var preComments = this.parseComments();
   7980            this.currentToken = this.scanner.scan();
   7981            if(this.currentToken.tokenId == TypeScript.TokenID.OpenParen) {
   7982                variableArgList = this.parseFormalParameterList(errorRecoverySet, args, true, isAmbient, false, false, false, false, null, true);
   7983                if(args.members.length > 0) {
   7984                    var lastArg = args.members[args.members.length - 1];
   7985                }
   7986            }
   7987            var requiresSignature = isAmbient || this.currentToken.tokenId == TypeScript.TokenID.Semicolon;
   7988            if(requiresSignature) {
   7989                for(var i = 0; i < args.members.length; i++) {
   7990                    var arg = args.members[i];
   7991                    if(TypeScript.hasFlag(arg.varFlags, TypeScript.VarFlags.Property)) {
   7992                        this.reportParseError("Overload or ambient signatures may not specify parameter properties", arg.minChar, arg.limChar);
   7993                    }
   7994                }
   7995            }
   7996            if(!requiresSignature) {
   7997                this.currentClassDefinition.constructorNestingLevel = this.nestingLevel + 1;
   7998            }
   7999            var constructorFuncDecl = this.parseFunctionStatements(errorRecoverySet | TypeScript.ErrorRecoverySet.RCurly, this.currentClassDefinition.name, true, false, args, TypeScript.AllowedElements.Properties, minChar, requiresSignature, modifiers);
   8000            constructorFuncDecl.preComments = preComments;
   8001            if(requiresSignature && !isAmbient) {
   8002                constructorFuncDecl.isOverload = true;
   8003            }
   8004            constructorFuncDecl.variableArgList = variableArgList;
   8005            this.currentClassDecl = null;
   8006            constructorFuncDecl.returnTypeAnnotation = this.convertToTypeReference(this.currentClassDefinition.name);
   8007            constructorFuncDecl.classDecl = this.currentClassDefinition;
   8008            if(isAmbient) {
   8009                constructorFuncDecl.fncFlags |= TypeScript.FncFlags.Ambient;
   8010            }
   8011            if(requiresSignature) {
   8012                constructorFuncDecl.fncFlags |= TypeScript.FncFlags.Signature;
   8013            }
   8014            if(this.ambientModule || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Exported)) {
   8015                constructorFuncDecl.fncFlags |= TypeScript.FncFlags.Exported;
   8016            }
   8017            if(this.currentClassDefinition.constructorDecl) {
   8018                if(!isAmbient && !this.currentClassDefinition.constructorDecl.isSignature() && !constructorFuncDecl.isSignature()) {
   8019                    this.reportParseError("Duplicate constructor definition");
   8020                }
   8021            }
   8022            if(isAmbient || !constructorFuncDecl.isSignature()) {
   8023                this.currentClassDefinition.constructorDecl = constructorFuncDecl;
   8024            }
   8025            constructorFuncDecl.fncFlags |= TypeScript.FncFlags.ClassMethod;
   8026            this.currentClassDefinition.members.members[this.currentClassDefinition.members.members.length] = constructorFuncDecl;
   8027            this.parsingClassConstructorDefinition = false;
   8028            return constructorFuncDecl;
   8029        };
   8030        Parser.prototype.parseClassMemberVariableDeclaration = function (text, minChar, isDeclaredInConstructor, errorRecoverySet, modifiers) {
   8031            var varDecl = new TypeScript.VarDecl(text, this.nestingLevel);
   8032            varDecl.minChar = minChar;
   8033            var isStatic = false;
   8034            varDecl.preComments = this.parseComments();
   8035            if(this.currentToken.tokenId == TypeScript.TokenID.Colon) {
   8036                this.currentToken = this.scanner.scan();
   8037                varDecl.typeExpr = this.parseTypeReference(errorRecoverySet | TypeScript.ErrorRecoverySet.Asg | TypeScript.ErrorRecoverySet.Comma, false);
   8038                if(varDecl.typeExpr && varDecl.typeExpr.nodeType == TypeScript.NodeType.TypeRef) {
   8039                    var typeExpr = (varDecl.typeExpr);
   8040                    if(typeExpr.term && typeExpr.term.nodeType == TypeScript.NodeType.FuncDecl) {
   8041                        typeExpr.term.preComments = varDecl.preComments;
   8042                    }
   8043                }
   8044            }
   8045            if(this.currentToken.tokenId == TypeScript.TokenID.Equals) {
   8046                if(this.parsingDeclareFile || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Ambient)) {
   8047                    this.reportParseError("context does not permit variable initializer");
   8048                    if(this.errorRecovery) {
   8049                        this.skip(errorRecoverySet);
   8050                        varDecl.flags |= TypeScript.ASTFlags.Error;
   8051                        varDecl.limChar = this.scanner.lastTokenLimChar();
   8052                        return varDecl;
   8053                    }
   8054                }
   8055                this.currentToken = this.scanner.scan();
   8056                varDecl.init = this.parseExpr(TypeScript.ErrorRecoverySet.Comma | errorRecoverySet, TypeScript.OperatorPrecedence.Comma, true, TypeContext.NoTypes);
   8057                varDecl.limChar = varDecl.init.limChar;
   8058                if(!(modifiers & TypeScript.Modifiers.Static)) {
   8059                    this.currentClassDefinition.varFlags |= TypeScript.VarFlags.ClassSuperMustBeFirstCallInConstructor;
   8060                }
   8061            } else {
   8062                varDecl.limChar = this.scanner.pos;
   8063            }
   8064            if(modifiers & TypeScript.Modifiers.Static) {
   8065                varDecl.varFlags |= TypeScript.VarFlags.Static;
   8066                isStatic = true;
   8067            }
   8068            if((modifiers & TypeScript.Modifiers.Private) != TypeScript.Modifiers.None) {
   8069                varDecl.varFlags |= TypeScript.VarFlags.Private;
   8070            } else {
   8071                varDecl.varFlags |= TypeScript.VarFlags.Public;
   8072            }
   8073            varDecl.varFlags |= TypeScript.VarFlags.Property;
   8074            if(isDeclaredInConstructor) {
   8075                varDecl.varFlags |= TypeScript.VarFlags.ClassConstructorProperty;
   8076            }
   8077            if(!isDeclaredInConstructor && !isStatic) {
   8078                varDecl.varFlags |= TypeScript.VarFlags.ClassBodyProperty;
   8079            }
   8080            this.currentClassDefinition.knownMemberNames[text.actualText] = true;
   8081            if(!isDeclaredInConstructor) {
   8082                this.currentClassDefinition.members.members[this.currentClassDefinition.members.members.length] = varDecl;
   8083            }
   8084            varDecl.postComments = this.parseComments();
   8085            return varDecl;
   8086        };
   8087        Parser.prototype.parseClassMemberFunctionDeclaration = function (methodName, minChar, errorRecoverySet, modifiers) {
   8088            var wasAccessorID = this.prevIDTok != null;
   8089            var isAccessor = TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Getter) || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Setter);
   8090            var isStatic = TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Static);
   8091            var isAmbient = this.ambientModule || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Ambient);
   8092            errorRecoverySet |= TypeScript.ErrorRecoverySet.RParen;
   8093            if(isAccessor && (modifiers & TypeScript.Modifiers.Ambient)) {
   8094                this.reportParseError("Property accessors may not be declared in ambient classes");
   8095            }
   8096            var ast = this.parseFncDecl(errorRecoverySet, true, isAmbient, true, methodName, false, isStatic, isAmbient, modifiers, null, true);
   8097            if(ast.nodeType == TypeScript.NodeType.Error) {
   8098                return ast;
   8099            }
   8100            var funcDecl = ast;
   8101            funcDecl.minChar = minChar;
   8102            if(funcDecl.bod !== null) {
   8103                funcDecl.limChar = funcDecl.bod.limChar;
   8104            }
   8105            if(modifiers & TypeScript.Modifiers.Private) {
   8106                funcDecl.fncFlags |= TypeScript.FncFlags.Private;
   8107            } else {
   8108                funcDecl.fncFlags |= TypeScript.FncFlags.Public;
   8109            }
   8110            if(isStatic) {
   8111                funcDecl.fncFlags |= TypeScript.FncFlags.Static;
   8112            }
   8113            if(isAccessor) {
   8114                if(TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Getter)) {
   8115                    funcDecl.fncFlags |= TypeScript.FncFlags.GetAccessor;
   8116                    funcDecl.hint = "get" + funcDecl.name.actualText;
   8117                } else {
   8118                    funcDecl.fncFlags |= TypeScript.FncFlags.SetAccessor;
   8119                    funcDecl.hint = "set" + funcDecl.name.actualText;
   8120                }
   8121                funcDecl.fncFlags |= TypeScript.FncFlags.IsFunctionExpression;
   8122                if(TypeScript.codeGenTarget < TypeScript.CodeGenTarget.ES5) {
   8123                    this.reportParseError("Property accessors are only available when targeting ES5 or greater", funcDecl.minChar, funcDecl.limChar);
   8124                }
   8125            }
   8126            funcDecl.fncFlags |= TypeScript.FncFlags.ClassMethod;
   8127            this.currentClassDefinition.knownMemberNames[methodName.actualText] = true;
   8128            this.currentClassDefinition.members.members[this.currentClassDefinition.members.members.length] = funcDecl;
   8129            return funcDecl;
   8130        };
   8131        Parser.prototype.parseTypeMember = function (errorRecoverySet) {
   8132            var minChar = this.scanner.startPos;
   8133            var propertyDecl = this.parsePropertyDeclaration(errorRecoverySet, TypeScript.Modifiers.Public, true, false);
   8134            if(propertyDecl) {
   8135                propertyDecl.minChar = minChar;
   8136                if(propertyDecl.nodeType == TypeScript.NodeType.VarDecl) {
   8137                    this.checkCurrentToken(TypeScript.TokenID.Semicolon, errorRecoverySet);
   8138                }
   8139            }
   8140            return propertyDecl;
   8141        };
   8142        Parser.prototype.parseTypeMemberList = function (errorRecoverySet, members) {
   8143            errorRecoverySet |= TypeScript.ErrorRecoverySet.TypeScriptS;
   8144            while(true) {
   8145                switch(this.currentToken.tokenId) {
   8146                    case TypeScript.TokenID.CloseBrace:
   8147                    case TypeScript.TokenID.EndOfFile: {
   8148                        members.limChar = this.scanner.pos;
   8149                        return;
   8150 
   8151                    }
   8152                }
   8153                var element = this.parseTypeMember(errorRecoverySet);
   8154                if(element) {
   8155                    members.append(element);
   8156                }
   8157            }
   8158        };
   8159        Parser.prototype.parseInterfaceDecl = function (errorRecoverySet, modifiers) {
   8160            var leftCurlyCount = this.scanner.leftCurlyCount;
   8161            var rightCurlyCount = this.scanner.rightCurlyCount;
   8162            this.currentToken = this.scanner.scan();
   8163            var minChar = this.scanner.pos;
   8164            var name = null;
   8165            if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) || (!TypeScript.isPrimitiveTypeToken(this.currentToken) && TypeScript.convertTokToID(this.currentToken, this.strictMode))) {
   8166                name = TypeScript.Identifier.fromToken(this.currentToken);
   8167                name.minChar = this.scanner.startPos;
   8168                name.limChar = this.scanner.pos;
   8169                this.currentToken = this.scanner.scan();
   8170            } else {
   8171                this.reportParseError("interface missing name");
   8172                if(this.errorRecovery) {
   8173                    name = new TypeScript.MissingIdentifier();
   8174                    name.minChar = this.scanner.pos;
   8175                    name.limChar = this.scanner.pos;
   8176                    name.flags |= TypeScript.ASTFlags.Error;
   8177                }
   8178            }
   8179            var extendsList = null;
   8180            var implementsList = null;
   8181            if(this.currentToken.tokenId === TypeScript.TokenID.Extends || this.currentToken.tokenId === TypeScript.TokenID.Implements) {
   8182                if(this.currentToken.tokenId === TypeScript.TokenID.Implements) {
   8183                    this.reportParseError("Expected 'extends'");
   8184                }
   8185                extendsList = new TypeScript.ASTList();
   8186                implementsList = new TypeScript.ASTList();
   8187                extendsList.minChar = this.scanner.startPos;
   8188                this.parseBaseList(extendsList, implementsList, errorRecoverySet, false);
   8189            }
   8190            var membersMinChar = this.scanner.startPos;
   8191            this.checkCurrentToken(TypeScript.TokenID.OpenBrace, errorRecoverySet | TypeScript.ErrorRecoverySet.TypeScriptS);
   8192            var members = new TypeScript.ASTList();
   8193            members.minChar = membersMinChar;
   8194            var prevInInterfaceDecl = this.inInterfaceDecl;
   8195            this.inInterfaceDecl = true;
   8196            this.parseTypeMemberList(errorRecoverySet | TypeScript.ErrorRecoverySet.RCurly, members);
   8197            this.inInterfaceDecl = prevInInterfaceDecl;
   8198            this.checkCurrentToken(TypeScript.TokenID.CloseBrace, errorRecoverySet);
   8199            var interfaceDecl = new TypeScript.InterfaceDeclaration(name, members, extendsList, null);
   8200            if(TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Private)) {
   8201                interfaceDecl.varFlags |= TypeScript.VarFlags.Private;
   8202            }
   8203            if(TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Public)) {
   8204                interfaceDecl.varFlags |= TypeScript.VarFlags.Public;
   8205            }
   8206            if(this.parsingDeclareFile || this.ambientModule || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Exported)) {
   8207                interfaceDecl.varFlags |= TypeScript.VarFlags.Exported;
   8208            }
   8209            interfaceDecl.limChar = members.limChar;
   8210            interfaceDecl.leftCurlyCount = this.scanner.leftCurlyCount - leftCurlyCount;
   8211            interfaceDecl.rightCurlyCount = this.scanner.rightCurlyCount - rightCurlyCount;
   8212            return interfaceDecl;
   8213        };
   8214        Parser.prototype.makeVarDecl = function (id, nest) {
   8215            var varDecl = new TypeScript.VarDecl(id, nest);
   8216            var currentVarList = this.topVarList();
   8217            if(currentVarList) {
   8218                currentVarList.append(varDecl);
   8219            }
   8220            return varDecl;
   8221        };
   8222        Parser.prototype.parsePropertyDeclaration = function (errorRecoverySet, modifiers, requireSignature, isStatic) {
   8223            var text = null;
   8224            var minChar = this.scanner.startPos;
   8225            var nameLimChar = minChar;
   8226            var isNew = false;
   8227            var isIndexer = false;
   8228            var wasAccessorID = this.prevIDTok != null;
   8229            var isAccessor = TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Getter) || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Setter);
   8230            if(this.parsingDeclareFile || this.ambientModule || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Ambient)) {
   8231                requireSignature = true;
   8232            }
   8233            if(this.currentToken.tokenId == TypeScript.TokenID.OpenParen && !wasAccessorID) {
   8234                if(!requireSignature && !isStatic) {
   8235                    this.reportParseError("Expected identifier in property declaration");
   8236                    if(this.errorRecovery) {
   8237                        this.skip(errorRecoverySet);
   8238                        text = new TypeScript.MissingIdentifier();
   8239                    }
   8240                }
   8241            } else {
   8242                if(this.currentToken.tokenId == TypeScript.TokenID.New) {
   8243                    if(requireSignature) {
   8244                        this.currentToken = this.scanner.scan();
   8245                        if(this.currentToken.tokenId == TypeScript.TokenID.OpenParen) {
   8246                            isNew = true;
   8247                        }
   8248                    }
   8249                    if(!isNew) {
   8250                        if(!requireSignature) {
   8251                            this.currentToken = this.scanner.scan();
   8252                        }
   8253                        text = new TypeScript.Identifier("new");
   8254                        text.minChar = this.scanner.pos - 3;
   8255                        text.limChar = this.scanner.pos;
   8256                        nameLimChar = this.scanner.pos;
   8257                    }
   8258                } else {
   8259                    if((this.currentToken.tokenId == TypeScript.TokenID.OpenBracket) && requireSignature) {
   8260                        isIndexer = true;
   8261                        text = new TypeScript.Identifier("__item");
   8262                    } else {
   8263                        if((this.currentToken.tokenId != TypeScript.TokenID.Identifier) && (!TypeScript.convertTokToIDName(this.currentToken)) && !wasAccessorID) {
   8264                            this.reportParseError("Expected identifier in property declaration");
   8265                            if(this.errorRecovery) {
   8266                                var eminChar = this.scanner.startPos;
   8267                                var curpos = this.scanner.pos;
   8268                                this.skip(errorRecoverySet & (~TypeScript.ErrorRecoverySet.Comma));
   8269                                if(this.scanner.pos == curpos) {
   8270                                    this.currentToken = this.scanner.scan();
   8271                                }
   8272                                var epd = new TypeScript.VarDecl(new TypeScript.MissingIdentifier(), this.nestingLevel);
   8273                                epd.flags |= TypeScript.ASTFlags.Error;
   8274                                epd.minChar = eminChar;
   8275                                epd.limChar = this.scanner.lastTokenLimChar();
   8276                                return epd;
   8277                            }
   8278                        } else {
   8279                            if(wasAccessorID) {
   8280                                text = TypeScript.Identifier.fromToken(this.prevIDTok);
   8281                                text.minChar = this.scanner.lastTokenLimChar() - 3;
   8282                                text.limChar = this.scanner.lastTokenLimChar();
   8283                                nameLimChar = text.limChar;
   8284                                if(TypeScript.codeGenTarget < TypeScript.CodeGenTarget.ES5) {
   8285                                    this.reportParseError("Property accessors are only available when targeting ES5 or greater");
   8286                                }
   8287                                if(this.currentToken.getText() == text.actualText && this.currentToken != this.prevIDTok) {
   8288                                    this.currentToken = this.scanner.scan();
   8289                                }
   8290                                this.prevIDTok = null;
   8291                            } else {
   8292                                text = TypeScript.Identifier.fromToken(this.currentToken);
   8293                                text.minChar = this.scanner.startPos;
   8294                                text.limChar = this.scanner.pos;
   8295                                nameLimChar = this.scanner.pos;
   8296                                this.currentToken = this.scanner.scan();
   8297                            }
   8298                        }
   8299                    }
   8300                }
   8301            }
   8302            if(this.currentToken.tokenId == TypeScript.TokenID.Question) {
   8303                if(this.inInterfaceDecl && text) {
   8304                    text.flags |= TypeScript.ASTFlags.OptionalName;
   8305                } else {
   8306                    this.reportParseError("Optional properties may only be declared on interface or object types");
   8307                }
   8308                this.currentToken = this.scanner.scan();
   8309            }
   8310            if((this.currentToken.tokenId == TypeScript.TokenID.OpenParen) || (isIndexer && (this.currentToken.tokenId == TypeScript.TokenID.OpenBracket))) {
   8311                var ers = errorRecoverySet | TypeScript.ErrorRecoverySet.RParen;
   8312                if(isIndexer) {
   8313                    ers = errorRecoverySet | TypeScript.ErrorRecoverySet.RBrack;
   8314                }
   8315                var ast = this.parseFncDecl(ers, true, requireSignature, !this.inFncDecl, text, isIndexer, isStatic, (this.parsingDeclareFile || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Ambient)), modifiers, null, true);
   8316                var funcDecl;
   8317                if(ast.nodeType == TypeScript.NodeType.Error) {
   8318                    return ast;
   8319                } else {
   8320                    funcDecl = ast;
   8321                }
   8322                if(funcDecl.name) {
   8323                    funcDecl.name.minChar = minChar;
   8324                    funcDecl.name.limChar = nameLimChar;
   8325                }
   8326                if((modifiers & TypeScript.Modifiers.Public) != TypeScript.Modifiers.None) {
   8327                    funcDecl.fncFlags |= TypeScript.FncFlags.Public;
   8328                }
   8329                if((modifiers & TypeScript.Modifiers.Private) != TypeScript.Modifiers.None) {
   8330                    funcDecl.fncFlags |= TypeScript.FncFlags.Private;
   8331                }
   8332                if(isStatic) {
   8333                    funcDecl.fncFlags |= TypeScript.FncFlags.Static;
   8334                }
   8335                if(this.parsingDeclareFile || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Ambient)) {
   8336                    funcDecl.fncFlags |= TypeScript.FncFlags.Ambient;
   8337                }
   8338                if(isAccessor) {
   8339                    if(TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Getter)) {
   8340                        funcDecl.fncFlags |= TypeScript.FncFlags.GetAccessor;
   8341                        funcDecl.hint = "get" + funcDecl.name.actualText;
   8342                    } else {
   8343                        funcDecl.fncFlags |= TypeScript.FncFlags.SetAccessor;
   8344                        funcDecl.hint = "set" + funcDecl.name.actualText;
   8345                    }
   8346                    funcDecl.fncFlags |= TypeScript.FncFlags.IsFunctionExpression;
   8347                    if(modifiers & TypeScript.Modifiers.Ambient) {
   8348                        this.reportParseError("Property accessors may not be declared in ambient types");
   8349                    }
   8350                }
   8351                if(text == null) {
   8352                    if(isNew) {
   8353                        funcDecl.fncFlags |= TypeScript.FncFlags.ConstructMember;
   8354                        funcDecl.hint = "_construct";
   8355                        funcDecl.classDecl = this.currentClassDecl;
   8356                    } else {
   8357                        funcDecl.hint = "_call";
   8358                        funcDecl.fncFlags |= TypeScript.FncFlags.CallMember;
   8359                    }
   8360                }
   8361                return funcDecl;
   8362            } else {
   8363                var varDecl = new TypeScript.VarDecl(text, this.nestingLevel);
   8364                varDecl.preComments = this.parseComments();
   8365                varDecl.minChar = minChar;
   8366                if(this.currentToken.tokenId == TypeScript.TokenID.Colon) {
   8367                    this.currentToken = this.scanner.scan();
   8368                    varDecl.typeExpr = this.parseTypeReference(errorRecoverySet | TypeScript.ErrorRecoverySet.Asg | TypeScript.ErrorRecoverySet.Comma, false);
   8369                    if(varDecl.typeExpr && varDecl.typeExpr.nodeType == TypeScript.NodeType.TypeRef) {
   8370                        var typeExpr = (varDecl.typeExpr);
   8371                        if(typeExpr.term && typeExpr.term.nodeType == TypeScript.NodeType.FuncDecl) {
   8372                            typeExpr.term.preComments = varDecl.preComments;
   8373                        }
   8374                    }
   8375                }
   8376                if(this.currentToken.tokenId == TypeScript.TokenID.Equals) {
   8377                    if(requireSignature) {
   8378                        this.reportParseError("context does not permit variable initializer");
   8379                        if(this.errorRecovery) {
   8380                            this.skip(errorRecoverySet);
   8381                            varDecl.flags |= TypeScript.ASTFlags.Error;
   8382                            varDecl.limChar = this.scanner.lastTokenLimChar();
   8383                            return varDecl;
   8384                        }
   8385                    }
   8386                    this.currentToken = this.scanner.scan();
   8387                    varDecl.init = this.parseExpr(TypeScript.ErrorRecoverySet.Comma | errorRecoverySet, TypeScript.OperatorPrecedence.Comma, true, TypeContext.NoTypes);
   8388                    varDecl.limChar = varDecl.init.limChar;
   8389                    if(varDecl.init.nodeType == TypeScript.NodeType.FuncDecl) {
   8390                        var funcDecl = varDecl.init;
   8391                        funcDecl.hint = varDecl.id.text;
   8392                        funcDecl.boundToProperty = varDecl;
   8393                    } else {
   8394                        if(isAccessor) {
   8395                            this.reportParseError("Accessors may only be functions");
   8396                        }
   8397                    }
   8398                } else {
   8399                    varDecl.limChar = this.scanner.pos;
   8400                }
   8401                if((modifiers & TypeScript.Modifiers.Readonly) != TypeScript.Modifiers.None) {
   8402                    varDecl.varFlags |= TypeScript.VarFlags.Readonly;
   8403                }
   8404                if(isStatic) {
   8405                    varDecl.varFlags |= TypeScript.VarFlags.Static;
   8406                }
   8407                if((modifiers & TypeScript.Modifiers.Public) != TypeScript.Modifiers.None) {
   8408                    varDecl.varFlags |= TypeScript.VarFlags.Public;
   8409                }
   8410                if((modifiers & TypeScript.Modifiers.Private) != TypeScript.Modifiers.None) {
   8411                    varDecl.varFlags |= TypeScript.VarFlags.Private;
   8412                }
   8413                varDecl.varFlags |= TypeScript.VarFlags.Property;
   8414                return varDecl;
   8415            }
   8416        };
   8417        Parser.prototype.parseVariableDeclaration = function (errorRecoverySet, modifiers, allowIn, isStatic) {
   8418            var isConst = TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Readonly);
   8419            var minChar = this.scanner.startPos;
   8420            var varDecl = null;
   8421            var declList = null;
   8422            var multivar = false;
   8423            this.currentToken = this.scanner.scan();
   8424            var varDeclPreComments = this.parseComments();
   8425            while(true) {
   8426                if((this.currentToken.tokenId != TypeScript.TokenID.Identifier) && (!TypeScript.convertTokToID(this.currentToken, this.strictMode))) {
   8427                    this.reportParseError("Expected identifier in variable declaration");
   8428                    if(this.errorRecovery) {
   8429                        varDecl = new TypeScript.VarDecl(new TypeScript.MissingIdentifier(), this.nestingLevel);
   8430                        varDecl.minChar = minChar;
   8431                        this.skip(errorRecoverySet);
   8432                        varDecl.flags |= TypeScript.ASTFlags.Error;
   8433                        varDecl.limChar = this.scanner.lastTokenLimChar();
   8434                        return varDecl;
   8435                    }
   8436                }
   8437                var varDeclName = TypeScript.Identifier.fromToken(this.currentToken);
   8438                if(this.strictMode && (varDeclName.text == "eval")) {
   8439                    this.reportParseError("'eval' may not name a variable in strict mode");
   8440                }
   8441                varDecl = this.makeVarDecl(varDeclName, this.nestingLevel);
   8442                varDecl.id.minChar = this.scanner.startPos;
   8443                varDecl.id.limChar = this.scanner.pos;
   8444                varDecl.preComments = varDeclPreComments;
   8445                if(isStatic) {
   8446                    varDecl.varFlags |= TypeScript.VarFlags.Static;
   8447                }
   8448                if(TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Readonly)) {
   8449                    varDecl.varFlags |= TypeScript.VarFlags.Readonly;
   8450                }
   8451                if(this.parsingDeclareFile || this.ambientModule || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Ambient)) {
   8452                    varDecl.varFlags |= TypeScript.VarFlags.Ambient;
   8453                }
   8454                if(this.parsingDeclareFile || this.ambientModule || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Exported)) {
   8455                    varDecl.varFlags |= TypeScript.VarFlags.Exported;
   8456                }
   8457                varDecl.minChar = minChar;
   8458                if(declList) {
   8459                    declList.append(varDecl);
   8460                }
   8461                this.currentToken = this.scanner.scan();
   8462                if(this.currentToken.tokenId == TypeScript.TokenID.Colon) {
   8463                    this.currentToken = this.scanner.scan();
   8464                    var prevInFncDecl = this.inFncDecl;
   8465                    this.inFncDecl = false;
   8466                    varDecl.typeExpr = this.parseTypeReference(errorRecoverySet | TypeScript.ErrorRecoverySet.Asg | TypeScript.ErrorRecoverySet.Comma, false);
   8467                    this.inFncDecl = prevInFncDecl;
   8468                }
   8469                if(this.currentToken.tokenId == TypeScript.TokenID.Equals) {
   8470                    if(TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.Ambient)) {
   8471                        this.reportParseError("Ambient variable can not have an initializer");
   8472                    }
   8473                    this.currentToken = this.scanner.scan();
   8474                    varDecl.init = this.parseExpr(TypeScript.ErrorRecoverySet.Comma | errorRecoverySet, TypeScript.OperatorPrecedence.Comma, allowIn, TypeContext.NoTypes);
   8475                    varDecl.limChar = varDecl.init.limChar;
   8476                    if(varDecl.init.nodeType == TypeScript.NodeType.FuncDecl) {
   8477                        var funcDecl = varDecl.init;
   8478                        funcDecl.hint = varDecl.id.actualText;
   8479                    }
   8480                } else {
   8481                    if(isConst) {
   8482                        this.reportParseError("const declaration requires initializer");
   8483                    }
   8484                    varDecl.limChar = this.scanner.pos;
   8485                }
   8486                varDecl.postComments = this.parseCommentsForLine(this.scanner.line);
   8487                if(this.currentToken.tokenId != TypeScript.TokenID.Comma) {
   8488                    if(declList) {
   8489                        declList.limChar = varDecl.limChar;
   8490                        return declList;
   8491                    } else {
   8492                        return varDecl;
   8493                    }
   8494                }
   8495                if(!multivar) {
   8496                    declList = new TypeScript.ASTList();
   8497                    declList.minChar = varDecl.minChar;
   8498                    declList.append(varDecl);
   8499                    multivar = true;
   8500                }
   8501                this.currentToken = this.scanner.scan();
   8502                minChar = this.scanner.startPos;
   8503            }
   8504        };
   8505        Parser.prototype.parseMemberList = function (errorRecoverySet) {
   8506            var elements = new TypeScript.ASTList();
   8507            if(this.currentToken.tokenId == TypeScript.TokenID.CloseBrace) {
   8508                return elements;
   8509            }
   8510            var idHint = null;
   8511            var memberName = null;
   8512            var memberExpr = null;
   8513            var member = null;
   8514            var minChar = this.scanner.startPos;
   8515            var isSet = false;
   8516            var skippedTokenForGetSetId = false;
   8517            var getSetTok = null;
   8518            var getSetStartPos = 0;
   8519            var getSetPos = 0;
   8520            for(; ; ) {
   8521                var accessorPattern = false;
   8522                if(this.currentToken.tokenId == TypeScript.TokenID.Get || this.currentToken.tokenId == TypeScript.TokenID.Set) {
   8523                    isSet = this.currentToken.tokenId == TypeScript.TokenID.Set;
   8524                    getSetTok = this.currentToken;
   8525                    getSetStartPos = this.scanner.startPos;
   8526                    getSetPos = this.scanner.pos;
   8527                    this.currentToken = this.scanner.scan();
   8528                    if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) || TypeScript.convertTokToIDName(this.currentToken)) {
   8529                        idHint = isSet ? "set" : "get";
   8530                        idHint = idHint + this.currentToken.getText();
   8531                        memberName = TypeScript.Identifier.fromToken(this.currentToken);
   8532                        memberName.minChar = this.scanner.startPos;
   8533                        accessorPattern = true;
   8534                        if(TypeScript.codeGenTarget < TypeScript.CodeGenTarget.ES5) {
   8535                            this.reportParseError("Property accessors are only available when targeting ES5 or greater");
   8536                        }
   8537                    } else {
   8538                        if(this.currentToken.tokenId != TypeScript.TokenID.Colon) {
   8539                            this.reportParseError("Expected identifier, string or number as accessor name");
   8540                        } else {
   8541                            skippedTokenForGetSetId = true;
   8542                            memberName = TypeScript.Identifier.fromToken(getSetTok);
   8543                            memberName.minChar = getSetStartPos;
   8544                            memberName.limChar = getSetPos;
   8545                        }
   8546                    }
   8547                } else {
   8548                    if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) || TypeScript.convertTokToIDName(this.currentToken)) {
   8549                        idHint = this.currentToken.getText();
   8550                        memberName = TypeScript.Identifier.fromToken(this.currentToken);
   8551                        memberName.minChar = this.scanner.startPos;
   8552                        memberName.limChar = this.scanner.pos;
   8553                    } else {
   8554                        if(this.currentToken.tokenId == TypeScript.TokenID.StringLiteral) {
   8555                            idHint = this.currentToken.getText();
   8556                            memberName = new TypeScript.StringLiteral(idHint);
   8557                            memberName.minChar = this.scanner.startPos;
   8558                            memberName.limChar = this.scanner.pos;
   8559                        } else {
   8560                            if(this.currentToken.tokenId == TypeScript.TokenID.NumberLiteral) {
   8561                                var ntok = this.currentToken;
   8562                                idHint = ntok.value.toString();
   8563                                memberName = new TypeScript.StringLiteral(idHint);
   8564                                memberName.minChar = this.scanner.startPos;
   8565                                memberName.limChar = this.scanner.pos;
   8566                            } else {
   8567                                this.reportParseError("Expected identifier, string or number as member name");
   8568                                if(this.errorRecovery) {
   8569                                    memberName = new TypeScript.MissingIdentifier();
   8570                                    memberName.minChar = this.scanner.startPos;
   8571                                    memberName.flags |= TypeScript.ASTFlags.Error;
   8572                                    this.skip(errorRecoverySet | TypeScript.ErrorRecoverySet.Comma);
   8573                                    memberName.limChar = this.scanner.lastTokenLimChar();
   8574                                }
   8575                            }
   8576                        }
   8577                    }
   8578                }
   8579                if(!skippedTokenForGetSetId) {
   8580                    this.currentToken = this.scanner.scan();
   8581                } else {
   8582                    skippedTokenForGetSetId = false;
   8583                }
   8584                if(this.currentToken.tokenId == TypeScript.TokenID.Question) {
   8585                    memberName.flags |= TypeScript.ASTFlags.OptionalName;
   8586                    this.currentToken = this.scanner.scan();
   8587                }
   8588                if(accessorPattern) {
   8589                    var args = new TypeScript.ASTList();
   8590                    this.parseFormalParameterList(errorRecoverySet | TypeScript.ErrorRecoverySet.RParen, args, false, true, false, !isSet, isSet, false, null, true);
   8591                    var funcDecl = this.parseFunctionStatements(errorRecoverySet | TypeScript.ErrorRecoverySet.RCurly, memberName, false, true, args, TypeScript.AllowedElements.None, this.scanner.startPos, false, TypeScript.Modifiers.None);
   8592                    if(isSet && funcDecl.returnTypeAnnotation) {
   8593                        this.reportParseError("Property setters may not declare a return type");
   8594                    }
   8595                    funcDecl.fncFlags |= isSet ? TypeScript.FncFlags.SetAccessor : TypeScript.FncFlags.GetAccessor;
   8596                    funcDecl.fncFlags |= TypeScript.FncFlags.IsFunctionExpression;
   8597                    funcDecl.hint = idHint;
   8598                    memberExpr = funcDecl;
   8599                    member = new TypeScript.BinaryExpression(TypeScript.NodeType.Member, memberName, memberExpr);
   8600                    member.minChar = memberName.minChar;
   8601                    if(memberExpr.nodeType == TypeScript.NodeType.FuncDecl) {
   8602                        var funcDecl = memberExpr;
   8603                        funcDecl.hint = idHint;
   8604                    }
   8605                } else {
   8606                    if(this.currentToken.tokenId == TypeScript.TokenID.Colon) {
   8607                        this.currentToken = this.scanner.scan();
   8608                        memberExpr = this.parseExpr(TypeScript.ErrorRecoverySet.Comma | errorRecoverySet, TypeScript.OperatorPrecedence.Comma, true, TypeContext.NoTypes);
   8609                        if(memberExpr.nodeType == TypeScript.NodeType.TypeRef) {
   8610                            this.reportParseError("Expected 'new' on array declaration in member definition");
   8611                        }
   8612                        member = new TypeScript.BinaryExpression(TypeScript.NodeType.Member, memberName, memberExpr);
   8613                        member.minChar = memberName.minChar;
   8614                        if(memberExpr.nodeType == TypeScript.NodeType.FuncDecl) {
   8615                            var funcDecl = memberExpr;
   8616                            funcDecl.hint = idHint;
   8617                        }
   8618                    } else {
   8619                        this.reportParseError("Expected ':' in member definition");
   8620                        if(this.errorRecovery) {
   8621                            this.skip(errorRecoverySet);
   8622                            elements.flags |= TypeScript.ASTFlags.Error;
   8623                            elements.minChar = minChar;
   8624                            elements.limChar = this.scanner.lastTokenLimChar();
   8625                            return elements;
   8626                        }
   8627                    }
   8628                }
   8629                idHint = null;
   8630                elements.append(member);
   8631                member.limChar = this.scanner.lastTokenLimChar();
   8632                if(this.currentToken.tokenId != TypeScript.TokenID.Comma) {
   8633                    break;
   8634                } else {
   8635                    this.currentToken = this.scanner.scan();
   8636                }
   8637                if(this.currentToken.tokenId == TypeScript.TokenID.CloseBrace) {
   8638                    break;
   8639                }
   8640            }
   8641            if(member) {
   8642                elements.limChar = member.limChar;
   8643            }
   8644            elements.minChar = minChar;
   8645            return elements;
   8646        };
   8647        Parser.prototype.parseArrayList = function (errorRecoverySet) {
   8648            var elements = null;
   8649            if(this.currentToken.tokenId == TypeScript.TokenID.CloseBracket) {
   8650                return elements;
   8651            } else {
   8652                elements = new TypeScript.ASTList();
   8653                elements.minChar = this.scanner.startPos;
   8654            }
   8655            var arg;
   8656            for(; ; ) {
   8657                if((this.currentToken.tokenId == TypeScript.TokenID.Comma) || (this.currentToken.tokenId == TypeScript.TokenID.CloseBracket)) {
   8658                    arg = new TypeScript.AST(TypeScript.NodeType.EmptyExpr);
   8659                } else {
   8660                    arg = this.parseExpr(TypeScript.ErrorRecoverySet.Comma | errorRecoverySet, TypeScript.OperatorPrecedence.Comma, true, TypeContext.NoTypes);
   8661                }
   8662                elements.append(arg);
   8663                if(this.currentToken.tokenId != TypeScript.TokenID.Comma) {
   8664                    break;
   8665                }
   8666                this.currentToken = this.scanner.scan();
   8667            }
   8668            elements.limChar = this.scanner.lastTokenLimChar();
   8669            return elements;
   8670        };
   8671        Parser.prototype.parseArrayLiteral = function (errorRecoverySet) {
   8672            var arrayLiteral = null;
   8673            arrayLiteral = new TypeScript.UnaryExpression(TypeScript.NodeType.ArrayLit, this.parseArrayList(errorRecoverySet));
   8674            return arrayLiteral;
   8675        };
   8676        Parser.prototype.parseTerm = function (errorRecoverySet, allowCall, typeContext, inCast) {
   8677            var ast = null;
   8678            var sawId = false;
   8679            var inNew = false;
   8680            var minChar = this.scanner.startPos;
   8681            var limChar = this.scanner.pos;
   8682            var parseAsLambda = false;
   8683            var expectlambdaRParen = false;
   8684            switch(this.currentToken.tokenId) {
   8685                case TypeScript.TokenID.Number:
   8686                case TypeScript.TokenID.Bool:
   8687                case TypeScript.TokenID.Any:
   8688                case TypeScript.TokenID.String: {
   8689                    var tid = new TypeScript.Identifier(TypeScript.tokenTable[this.currentToken.tokenId].text);
   8690                    if(TypeScript.hasFlag(typeContext, TypeContext.Primitive)) {
   8691                        ast = new TypeScript.TypeReference(tid, 0);
   8692                        sawId = true;
   8693                    } else {
   8694                        ast = tid;
   8695                        sawId = true;
   8696                    }
   8697                    ast.minChar = minChar;
   8698                    this.currentToken = this.scanner.scan();
   8699                    limChar = this.scanner.lastTokenLimChar();
   8700                    break;
   8701 
   8702                }
   8703                case TypeScript.TokenID.This: {
   8704                    ast = new TypeScript.AST(TypeScript.NodeType.This);
   8705                    ast.minChar = minChar;
   8706                    this.currentToken = this.scanner.scan();
   8707                    limChar = this.scanner.lastTokenLimChar();
   8708                    break;
   8709 
   8710                }
   8711                case TypeScript.TokenID.Super: {
   8712                    ast = new TypeScript.AST(TypeScript.NodeType.Super);
   8713                    ast.minChar = minChar;
   8714                    this.currentToken = this.scanner.scan();
   8715                    limChar = this.scanner.lastTokenLimChar();
   8716                    break;
   8717 
   8718                }
   8719                case TypeScript.TokenID.True: {
   8720                    ast = new TypeScript.AST(TypeScript.NodeType.True);
   8721                    this.currentToken = this.scanner.scan();
   8722                    ast.minChar = minChar;
   8723                    break;
   8724 
   8725                }
   8726                case TypeScript.TokenID.False: {
   8727                    ast = new TypeScript.AST(TypeScript.NodeType.False);
   8728                    this.currentToken = this.scanner.scan();
   8729                    ast.minChar = minChar;
   8730                    break;
   8731 
   8732                }
   8733                case TypeScript.TokenID.Null: {
   8734                    ast = new TypeScript.AST(TypeScript.NodeType.Null);
   8735                    this.currentToken = this.scanner.scan();
   8736                    ast.minChar = minChar;
   8737                    break;
   8738 
   8739                }
   8740                case TypeScript.TokenID.New: {
   8741                    minChar = this.scanner.pos;
   8742                    this.currentToken = this.scanner.scan();
   8743                    var target = this.parseTerm(errorRecoverySet, false, TypeContext.AllSimpleTypes, inCast);
   8744                    if(target.nodeType == TypeScript.NodeType.Error || (target.nodeType == TypeScript.NodeType.Index && (target).operand1.nodeType == TypeScript.NodeType.TypeRef)) {
   8745                        this.reportParseError("Cannot invoke 'new' on this expression");
   8746                    } else {
   8747                        ast = new TypeScript.CallExpression(TypeScript.NodeType.New, target, null);
   8748                        ast.minChar = minChar;
   8749                        limChar = this.scanner.lastTokenLimChar();
   8750                        inNew = true;
   8751                    }
   8752                    break;
   8753 
   8754                }
   8755                case TypeScript.TokenID.Function: {
   8756                    minChar = this.scanner.pos;
   8757                    ast = this.parseFncDecl(errorRecoverySet, false, false, false, null, false, false, false, TypeScript.Modifiers.None, null, true);
   8758                    (ast).fncFlags |= TypeScript.FncFlags.IsFunctionExpression;
   8759                    ast.minChar = minChar;
   8760                    limChar = this.scanner.lastTokenLimChar();
   8761                    ast.limChar = limChar;
   8762                    break;
   8763 
   8764                }
   8765            }
   8766            if(ast == null) {
   8767                if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) || TypeScript.convertTokToID(this.currentToken, this.strictMode)) {
   8768                    var idText = this.currentToken.getText();
   8769                    ast = this.createRef(idText, (this.currentToken).hasEscapeSequence, minChar);
   8770                    sawId = true;
   8771                    ast.minChar = minChar;
   8772                    this.currentToken = this.scanner.scan();
   8773                    if(this.currentToken.tokenId == TypeScript.TokenID.Question) {
   8774                        ast.flags |= TypeScript.ASTFlags.PossibleOptionalParameter;
   8775                    }
   8776                    limChar = this.scanner.lastTokenLimChar();
   8777                }
   8778            }
   8779            if(inCast) {
   8780                this.checkCurrentToken(TypeScript.TokenID.GreaterThan, errorRecoverySet);
   8781            }
   8782            if(ast == null) {
   8783                switch(this.currentToken.tokenId) {
   8784                    case TypeScript.TokenID.OpenParen: {
   8785                        minChar = this.scanner.pos;
   8786                        var prevTokId = this.scanner.previousToken().tokenId;
   8787                        this.currentToken = this.scanner.scan();
   8788                        var couldBeLambda = prevTokId == TypeScript.TokenID.OpenParen || prevTokId == TypeScript.TokenID.Comma || prevTokId == TypeScript.TokenID.EqualsEquals || prevTokId == TypeScript.TokenID.Colon;
   8789                        if(couldBeLambda && this.currentToken.tokenId == TypeScript.TokenID.CloseParen) {
   8790                            parseAsLambda = true;
   8791                            expectlambdaRParen = false;
   8792                            this.currentToken = this.scanner.scan();
   8793                        } else {
   8794                            if(couldBeLambda && this.currentToken.tokenId == TypeScript.TokenID.DotDotDot) {
   8795                                parseAsLambda = true;
   8796                                expectlambdaRParen = true;
   8797                            } else {
   8798                                ast = this.parseExpr(errorRecoverySet | TypeScript.ErrorRecoverySet.RParen, TypeScript.OperatorPrecedence.None, true, TypeContext.NoTypes, couldBeLambda);
   8799                                limChar = this.scanner.lastTokenLimChar();
   8800                                parseAsLambda = couldBeLambda && (ast.nodeType == TypeScript.NodeType.Name || ast.nodeType == TypeScript.NodeType.Comma) && (this.currentToken.tokenId == TypeScript.TokenID.Colon || this.currentToken.tokenId == TypeScript.TokenID.Question);
   8801                                expectlambdaRParen = true;
   8802                            }
   8803                        }
   8804                        if((ast && !parseAsLambda)) {
   8805                            if(TypeScript.hasFlag(ast.flags, TypeScript.ASTFlags.SkipNextRParen)) {
   8806                                ast.flags = ast.flags & (~(TypeScript.ASTFlags.SkipNextRParen));
   8807                                break;
   8808                            }
   8809                            this.checkCurrentToken(TypeScript.TokenID.CloseParen, errorRecoverySet);
   8810                            ast.isParenthesized = true;
   8811                        }
   8812                        break;
   8813 
   8814                    }
   8815                    case TypeScript.TokenID.NumberLiteral: {
   8816                        var numTok = this.currentToken;
   8817                        this.currentToken = this.scanner.scan();
   8818                        ast = new TypeScript.NumberLiteral(numTok.value, numTok.hasEmptyFraction);
   8819                        ast.minChar = minChar;
   8820                        limChar = this.scanner.lastTokenLimChar();
   8821                        break;
   8822                    }
   8823 
   8824                    case TypeScript.TokenID.StringLiteral: {
   8825                        ast = new TypeScript.StringLiteral(this.currentToken.getText());
   8826                        this.currentToken = this.scanner.scan();
   8827                        ast.minChar = minChar;
   8828                        limChar = this.scanner.lastTokenLimChar();
   8829                        break;
   8830 
   8831                    }
   8832                    case TypeScript.TokenID.RegularExpressionLiteral: {
   8833                        var rtok = this.currentToken;
   8834                        ast = new TypeScript.RegexLiteral(rtok.regex);
   8835                        this.currentToken = this.scanner.scan();
   8836                        ast.minChar = minChar;
   8837                        limChar = this.scanner.lastTokenLimChar();
   8838                        break;
   8839                    }
   8840 
   8841                    case TypeScript.TokenID.OpenBracket: {
   8842                        minChar = this.scanner.startPos;
   8843                        this.currentToken = this.scanner.scan();
   8844                        ast = this.parseArrayLiteral(TypeScript.ErrorRecoverySet.RBrack | errorRecoverySet);
   8845                        ast.minChar = minChar;
   8846                        limChar = this.scanner.pos;
   8847                        this.checkCurrentToken(TypeScript.TokenID.CloseBracket, errorRecoverySet);
   8848                        break;
   8849 
   8850                    }
   8851                    case TypeScript.TokenID.OpenBrace: {
   8852                        minChar = this.scanner.startPos;
   8853                        this.currentToken = this.scanner.scan();
   8854                        var members = this.parseMemberList(TypeScript.ErrorRecoverySet.RCurly | errorRecoverySet);
   8855                        this.checkCurrentToken(TypeScript.TokenID.CloseBrace, errorRecoverySet);
   8856                        ast = new TypeScript.UnaryExpression(TypeScript.NodeType.ObjectLit, members);
   8857                        ast.minChar = minChar;
   8858                        limChar = this.scanner.lastTokenLimChar();
   8859                        members.minChar = minChar;
   8860                        members.limChar = limChar;
   8861                        break;
   8862 
   8863                    }
   8864                    case TypeScript.TokenID.LessThan: {
   8865                        minChar = this.scanner.startPos;
   8866                        this.currentToken = this.scanner.scan();
   8867                        var term = this.parseTypeReference(TypeScript.ErrorRecoverySet.BinOp, false);
   8868                        this.checkCurrentToken(TypeScript.TokenID.GreaterThan, errorRecoverySet);
   8869                        ast = new TypeScript.UnaryExpression(TypeScript.NodeType.TypeAssertion, this.parseExpr(errorRecoverySet, TypeScript.OperatorPrecedence.Unary, false, TypeContext.NoTypes));
   8870                        (ast).castTerm = term;
   8871                        break;
   8872 
   8873                    }
   8874                    default: {
   8875                        if(this.prevExpr && TypeScript.hasFlag(this.prevExpr.flags, TypeScript.ASTFlags.PossibleOptionalParameter)) {
   8876                            parseAsLambda = true;
   8877                            ast = this.prevExpr;
   8878                        } else {
   8879                            this.reportParseError("Check format of expression term");
   8880                            if(this.errorRecovery) {
   8881                                var ident = new TypeScript.MissingIdentifier();
   8882                                ident.minChar = minChar;
   8883                                ident.flags |= TypeScript.ASTFlags.Error;
   8884                                this.skip(errorRecoverySet | TypeScript.ErrorRecoverySet.Postfix);
   8885                                if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) || TypeScript.convertTokToID(this.currentToken, this.strictMode)) {
   8886                                    ident.setText(this.currentToken.getText(), (this.currentToken).hasEscapeSequence);
   8887                                    this.currentToken = this.scanner.scan();
   8888                                    limChar = this.scanner.lastTokenLimChar();
   8889                                } else {
   8890                                    limChar = this.scanner.lastTokenLimChar();
   8891                                }
   8892                                ast = ident;
   8893                            }
   8894                        }
   8895 
   8896                    }
   8897                }
   8898            }
   8899            if(parseAsLambda) {
   8900                if(this.currentToken.tokenId == TypeScript.TokenID.Colon || this.currentToken.tokenId == TypeScript.TokenID.Comma || this.currentToken.tokenId == TypeScript.TokenID.CloseParen || this.currentToken.tokenId == TypeScript.TokenID.DotDotDot) {
   8901                    ast = this.parseLambdaExpr(errorRecoverySet, ast, true, expectlambdaRParen);
   8902                    ast.minChar = minChar;
   8903                    limChar = this.scanner.lastTokenLimChar();
   8904                    ast.limChar = limChar;
   8905                } else {
   8906                    if(ast) {
   8907                        ast.isParenthesized = true;
   8908                    }
   8909                }
   8910            }
   8911            if(sawId && (typeContext != TypeContext.NoTypes)) {
   8912                typeContext |= TypeContext.ArraySuffix;
   8913            }
   8914            var postFix = this.parsePostfixOperators(errorRecoverySet, ast, allowCall, inNew, typeContext, minChar, limChar);
   8915            if(postFix) {
   8916                if(sawId && (postFix.nodeType == TypeScript.NodeType.Index)) {
   8917                    var binExpr = postFix;
   8918                    if(binExpr.operand2 == null) {
   8919                        postFix = this.convertToTypeReference(postFix);
   8920                    }
   8921                }
   8922                postFix.minChar = minChar;
   8923                postFix.limChar = TypeScript.max(postFix.limChar, this.scanner.lastTokenLimChar());
   8924                return postFix;
   8925            } else {
   8926                return new TypeScript.AST(TypeScript.NodeType.Error);
   8927            }
   8928        };
   8929        Parser.prototype.parseLambdaExpr = function (errorRecoverySet, lambdaArgs, skipNextRParen, expectClosingRParen) {
   8930            var ast = this.parseFncDecl(errorRecoverySet, false, false, false, null, false, false, false, TypeScript.Modifiers.None, {
   8931                preProcessedLambdaArgs: lambdaArgs
   8932            }, expectClosingRParen);
   8933            (ast).fncFlags |= TypeScript.FncFlags.IsFunctionExpression;
   8934            (ast).fncFlags |= TypeScript.FncFlags.IsFatArrowFunction;
   8935            if(!skipNextRParen) {
   8936                ast.flags |= TypeScript.ASTFlags.SkipNextRParen;
   8937            }
   8938            ast.limChar = this.scanner.lastTokenLimChar();
   8939            ; ;
   8940            return ast;
   8941        };
   8942        Parser.prototype.parseExpr = function (errorRecoverySet, minPrecedence, allowIn, typeContext, possiblyInLambda) {
   8943            if (typeof possiblyInLambda === "undefined") { possiblyInLambda = false; }
   8944            var ast = null;
   8945            var tokenInfo = TypeScript.lookupToken(this.currentToken.tokenId);
   8946            var canAssign = true;
   8947            var idHint = null;
   8948            var minChar = this.scanner.startPos;
   8949            var preComments = this.parseComments();
   8950            var exprIsAnonLambda = false;
   8951            if((tokenInfo != undefined) && (tokenInfo.unopNodeType != TypeScript.NodeType.None)) {
   8952                canAssign = false;
   8953                this.currentToken = this.scanner.scan();
   8954                var tempExpr = this.parseExpr(TypeScript.ErrorRecoverySet.BinOp | errorRecoverySet, tokenInfo.unopPrecedence, allowIn, TypeContext.NoTypes);
   8955                if((tokenInfo.unopNodeType == TypeScript.NodeType.Pos) && (tempExpr.nodeType == TypeScript.NodeType.NumberLit)) {
   8956                    ast = tempExpr;
   8957                } else {
   8958                    if((tokenInfo.unopNodeType == TypeScript.NodeType.Neg) && (tempExpr.nodeType == TypeScript.NodeType.NumberLit)) {
   8959                        var numLit = tempExpr;
   8960                        numLit.value = (-numLit.value);
   8961                        if(numLit.value == 0) {
   8962                            numLit.isNegativeZero = true;
   8963                        }
   8964                        ast = tempExpr;
   8965                    } else {
   8966                        ast = new TypeScript.UnaryExpression(tokenInfo.unopNodeType, tempExpr);
   8967                        ast.limChar = tempExpr.limChar;
   8968                    }
   8969                }
   8970                ast.minChar = minChar;
   8971            } else {
   8972                ast = this.parseTerm(TypeScript.ErrorRecoverySet.BinOp | TypeScript.ErrorRecoverySet.AddOp | errorRecoverySet, true, typeContext, false);
   8973                var id;
   8974                var temp;
   8975                if(ast.nodeType == TypeScript.NodeType.Name) {
   8976                    id = ast;
   8977                    idHint = id.actualText;
   8978                } else {
   8979                    if(ast.nodeType == TypeScript.NodeType.Dot) {
   8980                        var subsumedExpr = false;
   8981                        if(this.inferPropertiesFromThisAssignment && (this.currentToken.tokenId == TypeScript.TokenID.Colon || this.currentToken.tokenId == TypeScript.TokenID.Equals) && this.parsingClassConstructorDefinition && this.nestingLevel == this.currentClassDefinition.constructorNestingLevel && (ast).operand1.nodeType == TypeScript.NodeType.This) {
   8982                            if((ast).operand2.nodeType == TypeScript.NodeType.Name) {
   8983                                var op2ID = ((ast).operand2);
   8984                                if(!this.currentClassDefinition.knownMemberNames[op2ID.actualText]) {
   8985                                    ast = this.parseClassMemberVariableDeclaration(op2ID, ast.minChar, true, errorRecoverySet, TypeScript.Modifiers.Public);
   8986                                    subsumedExpr = true;
   8987                                }
   8988                            }
   8989                        }
   8990                        if(!subsumedExpr) {
   8991                            temp = ast;
   8992                            while(temp.nodeType == TypeScript.NodeType.Dot) {
   8993                                var binExpr = temp;
   8994                                temp = binExpr.operand2;
   8995                            }
   8996                            if(temp.nodeType == TypeScript.NodeType.Name) {
   8997                                id = temp;
   8998                                idHint = id.actualText;
   8999                            }
   9000                        }
   9001                    }
   9002                }
   9003                if((!this.scanner.lastTokenHadNewline()) && ((this.currentToken.tokenId == TypeScript.TokenID.PlusPlus) || (this.currentToken.tokenId == TypeScript.TokenID.MinusMinus))) {
   9004                    canAssign = false;
   9005                    var operand = ast;
   9006                    ast = new TypeScript.UnaryExpression((this.currentToken.tokenId == TypeScript.TokenID.PlusPlus) ? TypeScript.NodeType.IncPost : TypeScript.NodeType.DecPost, operand);
   9007                    ast.limChar = this.scanner.pos;
   9008                    ast.minChar = operand.minChar;
   9009                    this.currentToken = this.scanner.scan();
   9010                }
   9011            }
   9012            for(; ; ) {
   9013                tokenInfo = TypeScript.lookupToken(this.currentToken.tokenId);
   9014                if((tokenInfo == undefined) || (tokenInfo.binopNodeType == TypeScript.NodeType.None)) {
   9015                    break;
   9016                }
   9017                if((!allowIn) && (tokenInfo.binopNodeType == TypeScript.NodeType.In)) {
   9018                    break;
   9019                }
   9020                if(tokenInfo.binopPrecedence == TypeScript.OperatorPrecedence.Assignment) {
   9021                    if(tokenInfo.binopPrecedence < minPrecedence) {
   9022                        break;
   9023                    }
   9024                    if(!canAssign) {
   9025                        this.reportParseError("illegal assignment");
   9026                    }
   9027                } else {
   9028                    if(tokenInfo.binopPrecedence <= minPrecedence) {
   9029                        break;
   9030                    }
   9031                }
   9032                if(possiblyInLambda && this.currentToken.tokenId == TypeScript.TokenID.Comma && this.scanner.getLookAheadToken().tokenId == TypeScript.TokenID.DotDotDot) {
   9033                    exprIsAnonLambda = true;
   9034                    canAssign = false;
   9035                    ast = this.parseLambdaExpr(errorRecoverySet, ast, false, true);
   9036                    break;
   9037                }
   9038                this.currentToken = this.scanner.scan();
   9039                canAssign = false;
   9040                if(tokenInfo.binopNodeType == TypeScript.NodeType.ConditionalExpression) {
   9041                    if(possiblyInLambda && (this.currentToken.tokenId == TypeScript.TokenID.Equals || this.currentToken.tokenId == TypeScript.TokenID.Colon || this.currentToken.tokenId == TypeScript.TokenID.CloseParen || this.currentToken.tokenId == TypeScript.TokenID.Comma)) {
   9042                        exprIsAnonLambda = true;
   9043                        canAssign = true;
   9044                    } else {
   9045                        this.prevExpr = ast;
   9046                        var whenTrue = this.parseExpr(errorRecoverySet | TypeScript.ErrorRecoverySet.Colon, TypeScript.OperatorPrecedence.Assignment, allowIn, TypeContext.NoTypes);
   9047                        this.prevExpr = null;
   9048                        this.checkCurrentToken(TypeScript.TokenID.Colon, errorRecoverySet | TypeScript.ErrorRecoverySet.ExprStart);
   9049                        var whenFalse = this.parseExpr(errorRecoverySet | TypeScript.ErrorRecoverySet.BinOp, TypeScript.OperatorPrecedence.Assignment, allowIn, TypeContext.NoTypes);
   9050                        ast = new TypeScript.ConditionalExpression(ast, whenTrue, whenFalse);
   9051                    }
   9052                } else {
   9053                    var tc = TypeContext.NoTypes;
   9054                    var binExpr2;
   9055                    binExpr2 = new TypeScript.BinaryExpression(tokenInfo.binopNodeType, ast, this.parseExpr(errorRecoverySet | TypeScript.ErrorRecoverySet.BinOp, tokenInfo.binopPrecedence, allowIn, TypeContext.NoTypes, possiblyInLambda));
   9056                    if(binExpr2.operand2.nodeType == TypeScript.NodeType.FuncDecl) {
   9057                        var funcDecl = binExpr2.operand2;
   9058                        funcDecl.hint = idHint;
   9059                    }
   9060                    binExpr2.minChar = ast.minChar;
   9061                    binExpr2.limChar = this.scanner.lastTokenLimChar();
   9062                    idHint = null;
   9063                    ast = binExpr2;
   9064                }
   9065            }
   9066            if(canAssign) {
   9067                ast.flags |= TypeScript.ASTFlags.Writeable;
   9068            }
   9069            if(!exprIsAnonLambda) {
   9070                ast.minChar = minChar;
   9071                ast.limChar = TypeScript.max(ast.limChar, this.scanner.lastTokenLimChar());
   9072                ast.preComments = preComments;
   9073                ast.postComments = this.parseCommentsForLine(this.scanner.line);
   9074            }
   9075            return ast;
   9076        };
   9077        Parser.prototype.parsePostfixOperators = function (errorRecoverySet, ast, allowCall, inNew, typeContext, lhsMinChar, lhsLimChar) {
   9078            var count = 0;
   9079            if(!ast) {
   9080                ast = new TypeScript.AST(TypeScript.NodeType.EmptyExpr);
   9081                ast.isParenthesized = true;
   9082            }
   9083            ast.minChar = lhsMinChar;
   9084            ast.limChar = lhsLimChar;
   9085            for(; ; ) {
   9086                switch(this.currentToken.tokenId) {
   9087                    case TypeScript.TokenID.OpenParen: {
   9088                        if(inNew) {
   9089                            var callExpr = ast;
   9090                            callExpr.arguments = this.parseArgList(errorRecoverySet);
   9091                            inNew = false;
   9092                        } else {
   9093                            if(!allowCall) {
   9094                                return ast;
   9095                            }
   9096                            ast = new TypeScript.CallExpression(TypeScript.NodeType.Call, ast, this.parseArgList(errorRecoverySet));
   9097                            ast.minChar = lhsMinChar;
   9098                        }
   9099                        ast.limChar = this.scanner.pos;
   9100                        this.checkCurrentToken(TypeScript.TokenID.CloseParen, errorRecoverySet);
   9101                        break;
   9102 
   9103                    }
   9104                    case TypeScript.TokenID.OpenBracket: {
   9105                        this.currentToken = this.scanner.scan();
   9106                        if(this.currentToken.tokenId == TypeScript.TokenID.CloseBracket) {
   9107                            if(TypeScript.hasFlag(typeContext, TypeContext.ArraySuffix)) {
   9108                                this.currentToken = this.scanner.scan();
   9109                                if(ast.nodeType == TypeScript.NodeType.TypeRef) {
   9110                                    var typeRef = ast;
   9111                                    typeRef.arrayCount++;
   9112                                } else {
   9113                                    ast = new TypeScript.BinaryExpression(TypeScript.NodeType.Index, ast, null);
   9114                                }
   9115                                ast.limChar = this.scanner.pos;
   9116                                break;
   9117                            }
   9118                        }
   9119                        ast = new TypeScript.BinaryExpression(TypeScript.NodeType.Index, ast, this.parseExpr(errorRecoverySet | TypeScript.ErrorRecoverySet.RBrack, TypeScript.OperatorPrecedence.None, true, TypeContext.NoTypes));
   9120                        ast.minChar = lhsMinChar;
   9121                        ast.limChar = this.scanner.pos;
   9122                        this.checkCurrentToken(TypeScript.TokenID.CloseBracket, errorRecoverySet);
   9123                        break;
   9124 
   9125                    }
   9126                    case TypeScript.TokenID.Dot: {
   9127                        var name = null;
   9128                        var curpos = this.scanner.pos;
   9129                        this.currentToken = this.scanner.scan();
   9130                        if (this.currentToken === undefined) {
   9131                            this.currentToken = this.scanner.scan();
   9132                            continue;
   9133                        }
   9134                        if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) || ((!this.errorRecovery || !this.scanner.lastTokenHadNewline()) && TypeScript.convertTokToIDName(this.currentToken))) {
   9135                            ast.flags |= TypeScript.ASTFlags.DotLHS;
   9136                            name = this.createRef(this.currentToken.getText(), (this.currentToken).hasEscapeSequence, this.scanner.startPos);
   9137                            name.limChar = this.scanner.pos;
   9138                            this.currentToken = this.scanner.scan();
   9139                        } else {
   9140                            this.reportParseError("Expected identifier following dot");
   9141                            if(this.errorRecovery) {
   9142                                this.skip(errorRecoverySet);
   9143                                ast.flags |= (TypeScript.ASTFlags.Error | TypeScript.ASTFlags.DotLHS);
   9144                                return ast;
   9145                            } else {
   9146                                name = new TypeScript.MissingIdentifier();
   9147                            }
   9148                        }
   9149                        ast = new TypeScript.BinaryExpression(TypeScript.NodeType.Dot, ast, name);
   9150                        ast.minChar = lhsMinChar;
   9151                        ast.limChar = this.scanner.lastTokenLimChar();
   9152                        break;
   9153                    }
   9154 
   9155                    case TypeScript.TokenID.EqualsGreaterThan: {
   9156                        ast = this.parseFncDecl(errorRecoverySet, false, false, false, null, false, false, false, TypeScript.Modifiers.None, {
   9157                            preProcessedLambdaArgs: ast
   9158                        }, false);
   9159                        (ast).fncFlags |= TypeScript.FncFlags.IsFunctionExpression;
   9160                        ast.minChar = lhsMinChar;
   9161                        ast.limChar = this.scanner.lastTokenLimChar();
   9162                        break;
   9163 
   9164                    }
   9165                    default: {
   9166                        return ast;
   9167 
   9168                    }
   9169                }
   9170            }
   9171        };
   9172        Parser.prototype.parseTry = function (tryNode, errorRecoverySet, parentModifiers) {
   9173            var minChar = this.scanner.startPos;
   9174            var preComments = this.parseComments();
   9175            this.currentToken = this.scanner.scan();
   9176            if(this.currentToken.tokenId != TypeScript.TokenID.OpenBrace) {
   9177                this.reportParseError("Expected '{'");
   9178                if(this.errorRecovery) {
   9179                    var etryNode = tryNode;
   9180                    etryNode.minChar = minChar;
   9181                    etryNode.limChar = this.scanner.lastTokenLimChar();
   9182                    etryNode.flags |= TypeScript.ASTFlags.Error;
   9183                    return etryNode;
   9184                }
   9185            }
   9186            tryNode.body = this.parseStatement(errorRecoverySet, TypeScript.AllowedElements.None, parentModifiers);
   9187            tryNode.minChar = minChar;
   9188            tryNode.limChar = tryNode.body.limChar;
   9189            tryNode.preComments = preComments;
   9190            tryNode.postComments = this.parseComments();
   9191            return tryNode;
   9192        };
   9193        Parser.prototype.parseCatch = function (errorRecoverySet, parentModifiers) {
   9194            var catchMinChar = this.scanner.startPos;
   9195            var preComments = this.parseComments();
   9196            this.currentToken = this.scanner.scan();
   9197            this.checkCurrentToken(TypeScript.TokenID.OpenParen, errorRecoverySet | TypeScript.ErrorRecoverySet.ExprStart);
   9198            if((this.currentToken.tokenId != TypeScript.TokenID.Identifier) || TypeScript.convertTokToID(this.currentToken, this.strictMode)) {
   9199                this.reportParseError("Expected identifier in catch header");
   9200                if(this.errorRecovery) {
   9201                    this.skip(errorRecoverySet);
   9202                    var ecatch = new TypeScript.Catch(new TypeScript.VarDecl(new TypeScript.MissingIdentifier(), this.nestingLevel), new TypeScript.Statement(TypeScript.NodeType.Empty));
   9203                    ecatch.statement.minChar = catchMinChar;
   9204                    ecatch.statement.limChar = this.scanner.pos;
   9205                    ecatch.minChar = this.scanner.startPos;
   9206                    ecatch.limChar = this.scanner.pos;
   9207                    ecatch.flags |= TypeScript.ASTFlags.Error;
   9208                    return ecatch;
   9209                }
   9210            }
   9211            var param = new TypeScript.VarDecl(TypeScript.Identifier.fromToken(this.currentToken), this.nestingLevel);
   9212            param.id.minChar = this.scanner.startPos;
   9213            param.id.limChar = this.scanner.pos;
   9214            param.minChar = param.id.minChar;
   9215            param.limChar = param.id.limChar;
   9216            this.currentToken = this.scanner.scan();
   9217            var statementPos = this.scanner.pos;
   9218            this.checkCurrentToken(TypeScript.TokenID.CloseParen, errorRecoverySet | TypeScript.ErrorRecoverySet.StmtStart);
   9219            if(this.currentToken.tokenId != TypeScript.TokenID.OpenBrace) {
   9220                this.reportParseError("Expected '{' to start catch body");
   9221                if(this.errorRecovery) {
   9222                    this.skip(errorRecoverySet);
   9223                    var ecatch = new TypeScript.Catch(new TypeScript.VarDecl(new TypeScript.MissingIdentifier(), this.nestingLevel), new TypeScript.Statement(TypeScript.NodeType.Empty));
   9224                    ecatch.statement.minChar = catchMinChar;
   9225                    ecatch.statement.limChar = statementPos;
   9226                    ecatch.minChar = this.scanner.startPos;
   9227                    ecatch.limChar = this.scanner.pos;
   9228                    ecatch.flags |= TypeScript.ASTFlags.Error;
   9229                    return ecatch;
   9230                }
   9231            }
   9232            var catchStmt = this.parseStatement(errorRecoverySet, TypeScript.AllowedElements.None, parentModifiers);
   9233            var catchNode = new TypeScript.Catch(param, catchStmt);
   9234            catchNode.statement.minChar = catchMinChar;
   9235            catchNode.statement.limChar = statementPos;
   9236            catchNode.minChar = catchMinChar;
   9237            catchNode.limChar = catchStmt.limChar;
   9238            catchNode.preComments = preComments;
   9239            catchNode.postComments = this.parseComments();
   9240            return catchNode;
   9241        };
   9242        Parser.prototype.parseFinally = function (errorRecoverySet, parentModifiers) {
   9243            var finMinChar = this.scanner.startPos;
   9244            var preComments = this.parseComments();
   9245            this.currentToken = this.scanner.scan();
   9246            if(this.currentToken.tokenId != TypeScript.TokenID.OpenBrace) {
   9247                this.reportParseError("Expected '{' to start body of finally statement");
   9248                if(this.errorRecovery) {
   9249                    this.skip(errorRecoverySet);
   9250                    var efin = new TypeScript.Finally(new TypeScript.Statement(TypeScript.NodeType.Empty));
   9251                    efin.flags |= TypeScript.ASTFlags.Error;
   9252                    efin.minChar = this.scanner.startPos;
   9253                    efin.limChar = this.scanner.pos;
   9254                    return efin;
   9255                }
   9256            }
   9257            var finBody = this.parseStatement(errorRecoverySet, TypeScript.AllowedElements.None, parentModifiers);
   9258            var fin = new TypeScript.Finally(finBody);
   9259            fin.minChar = finMinChar;
   9260            fin.limChar = fin.body.limChar;
   9261            fin.preComments = preComments;
   9262            fin.postComments = this.parseComments();
   9263            return fin;
   9264        };
   9265        Parser.prototype.parseTryCatchFinally = function (errorRecoverySet, parentModifiers, labelList) {
   9266            var tryPart = new TypeScript.Try(null);
   9267            var tryMinChar = this.scanner.startPos;
   9268            this.pushStmt(tryPart, labelList);
   9269            this.parseTry(tryPart, errorRecoverySet | TypeScript.ErrorRecoverySet.Catch, parentModifiers);
   9270            this.popStmt();
   9271            var tc = null;
   9272            var tf = null;
   9273            if(this.currentToken.tokenId == TypeScript.TokenID.Catch) {
   9274                var catchPart = this.parseCatch(errorRecoverySet | TypeScript.ErrorRecoverySet.Catch, parentModifiers);
   9275                tc = new TypeScript.TryCatch(tryPart, catchPart);
   9276                tc.minChar = tryPart.minChar;
   9277                tc.limChar = catchPart.limChar;
   9278            }
   9279            if(this.currentToken.tokenId != TypeScript.TokenID.Finally) {
   9280                if(tc == null) {
   9281                    this.reportParseError("try with neither catch nor finally");
   9282                    if(this.errorRecovery) {
   9283                        var etf = new TypeScript.TryFinally(tryPart, new TypeScript.Finally(new TypeScript.AST(TypeScript.NodeType.Empty)));
   9284                        etf.flags |= TypeScript.ASTFlags.Error;
   9285                        etf.minChar = this.scanner.startPos;
   9286                        etf.limChar = this.scanner.pos;
   9287                        return etf;
   9288                    }
   9289                    return new TypeScript.TryFinally(tryPart, new TypeScript.Finally(new TypeScript.AST(TypeScript.NodeType.Empty)));
   9290                } else {
   9291                    return tc;
   9292                }
   9293            } else {
   9294                if(tc) {
   9295                    tryPart = tc;
   9296                }
   9297                var finallyPart = this.parseFinally(errorRecoverySet, parentModifiers);
   9298                tf = new TypeScript.TryFinally(tryPart, finallyPart);
   9299                tf.minChar = tryMinChar;
   9300                tf.limChar = finallyPart.limChar;
   9301                return tf;
   9302            }
   9303        };
   9304        Parser.prototype.parseStatement = function (errorRecoverySet, allowedElements, parentModifiers) {
   9305            var ast = null;
   9306            var labelList = null;
   9307            var astList = null;
   9308            var temp;
   9309            var modifiers = TypeScript.Modifiers.None;
   9310            var minChar = this.scanner.startPos;
   9311            var forInOk = false;
   9312            var needTerminator = false;
   9313            var fnOrVar = null;
   9314            var preComments = this.parseComments();
   9315            this.state = ParseState.StartStatement;
   9316            function isAmbient() {
   9317                return TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Ambient) || TypeScript.hasFlag(parentModifiers, TypeScript.Modifiers.Ambient);
   9318            }
   9319            function mayNotBeExported() {
   9320                if(TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Exported)) {
   9321                    this.reportError("Statement may not be exported");
   9322                }
   9323            }
   9324            for(; ; ) {
   9325                switch(this.currentToken.tokenId) {
   9326                    case TypeScript.TokenID.EndOfFile: {
   9327                        ast = new TypeScript.AST(TypeScript.NodeType.Error);
   9328                        ast.minChar = minChar;
   9329                        ast.limChar = this.scanner.pos;
   9330                        break;
   9331 
   9332                    }
   9333                    case TypeScript.TokenID.Function: {
   9334                        if(this.parsingDeclareFile || isAmbient() || this.ambientModule) {
   9335                            this.currentToken = this.scanner.scan();
   9336                            fnOrVar = this.parsePropertyDeclaration(errorRecoverySet | TypeScript.ErrorRecoverySet.SColon, modifiers, true, false);
   9337                            if(fnOrVar.nodeType == TypeScript.NodeType.VarDecl) {
   9338                                this.reportParseError("function keyword can only introduce function declaration");
   9339                            } else {
   9340                                if((fnOrVar.nodeType == TypeScript.NodeType.FuncDecl) && ((fnOrVar).fncFlags , TypeScript.FncFlags.IsFatArrowFunction)) {
   9341                                    needTerminator = true;
   9342                                }
   9343                            }
   9344                            ast = fnOrVar;
   9345                            if(this.parsingDeclareFile || this.ambientModule && ast.nodeType == TypeScript.NodeType.FuncDecl) {
   9346                                (ast).fncFlags |= TypeScript.FncFlags.Exported;
   9347                            }
   9348                        } else {
   9349                            ast = this.parseFncDecl(errorRecoverySet, true, false, false, null, false, false, isAmbient(), modifiers, null, true);
   9350                            if(TypeScript.hasFlag((ast).fncFlags, TypeScript.FncFlags.IsFatArrowFunction)) {
   9351                                needTerminator = true;
   9352                            }
   9353                            if(this.ambientModule) {
   9354                                this.reportParseError("function declaration not permitted within ambient module");
   9355                            }
   9356                            if(TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Exported)) {
   9357                                (ast).fncFlags |= TypeScript.FncFlags.Exported;
   9358                            }
   9359                        }
   9360                        break;
   9361 
   9362                    }
   9363                    case TypeScript.TokenID.Module: {
   9364                        if((allowedElements & TypeScript.AllowedElements.ModuleDeclarations) == TypeScript.AllowedElements.None) {
   9365                            this.reportParseError("module not allowed in this context");
   9366                            this.currentToken = this.scanner.scan();
   9367                            ast = new TypeScript.AST(TypeScript.NodeType.Error);
   9368                            ast.minChar = minChar;
   9369                            ast.limChar = this.scanner.lastTokenLimChar();
   9370                        } else {
   9371                            ast = this.parseModuleDecl(errorRecoverySet, modifiers, preComments);
   9372                            preComments = null;
   9373                        }
   9374                        break;
   9375 
   9376                    }
   9377                    case TypeScript.TokenID.Import: {
   9378                        if((allowedElements & TypeScript.AllowedElements.ModuleDeclarations) == TypeScript.AllowedElements.None) {
   9379                            this.reportParseError("module not allowed in this context");
   9380                            this.currentToken = this.scanner.scan();
   9381                            ast = new TypeScript.AST(TypeScript.NodeType.Error);
   9382                            ast.minChar = minChar;
   9383                            ast.limChar = this.scanner.lastTokenLimChar();
   9384                        } else {
   9385                            if(TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Exported)) {
   9386                                this.reportParseError("export keyword not permitted on import declaration");
   9387                            }
   9388                            ast = this.parseImportDeclaration(errorRecoverySet, modifiers);
   9389                            needTerminator = true;
   9390                        }
   9391                        break;
   9392 
   9393                    }
   9394                    case TypeScript.TokenID.Export: {
   9395                        if((allowedElements & TypeScript.AllowedElements.ModuleDeclarations) == TypeScript.AllowedElements.None) {
   9396                            this.reportParseError("'export' statements are only allowed at the global and module levels");
   9397                            this.currentToken = this.scanner.scan();
   9398                            ast = new TypeScript.AST(TypeScript.NodeType.Error);
   9399                            ast.minChar = minChar;
   9400                            ast.limChar = this.scanner.lastTokenLimChar();
   9401                        }
   9402                        if(this.topLevel) {
   9403                            this.hasTopLevelImportOrExport = true;
   9404                        }
   9405                        modifiers |= TypeScript.Modifiers.Exported;
   9406                        this.currentToken = this.scanner.scan();
   9407                        break;
   9408 
   9409                    }
   9410                    case TypeScript.TokenID.Private: {
   9411                        modifiers |= TypeScript.Modifiers.Private;
   9412                        this.currentToken = this.scanner.scan();
   9413                        if(this.parsingClassConstructorDefinition) {
   9414                            if(!this.inferPropertiesFromThisAssignment) {
   9415                                this.reportParseError("Property declarations are not permitted within constructor bodies");
   9416                            }
   9417                            minChar = this.scanner.pos;
   9418                            if(this.inferPropertiesFromThisAssignment && (this.currentToken.tokenId != TypeScript.TokenID.This || (this.currentToken = this.scanner.scan()).tokenId != TypeScript.TokenID.Dot)) {
   9419                                this.reportParseError("Expected 'this.' for property declaration");
   9420                                this.currentToken = this.scanner.scan();
   9421                                ast = new TypeScript.AST(TypeScript.NodeType.Error);
   9422                                ast.minChar = minChar;
   9423                                ast.limChar = this.scanner.lastTokenLimChar();
   9424                            } else {
   9425                                this.currentToken = this.scanner.scan();
   9426                                var id = TypeScript.Identifier.fromToken(this.currentToken);
   9427                                id.minChar = this.scanner.startPos;
   9428                                id.limChar = this.scanner.pos;
   9429                                this.currentToken = this.scanner.scan();
   9430                                ast = this.parseClassMemberVariableDeclaration(id, minChar, this.parsingClassConstructorDefinition, errorRecoverySet, modifiers);
   9431                            }
   9432                        } else {
   9433                            if(this.currentToken.tokenId != TypeScript.TokenID.Interface) {
   9434                                if(this.currentToken.tokenId == TypeScript.TokenID.Get) {
   9435                                    this.prevIDTok = this.currentToken;
   9436                                    this.currentToken = this.scanner.scan();
   9437                                    if(TypeScript.codeGenTarget < TypeScript.CodeGenTarget.ES5) {
   9438                                        this.reportParseError("Property accessors are only available when targeting ES5 or greater");
   9439                                    }
   9440                                    if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) || TypeScript.convertTokToID(this.currentToken, this.strictMode)) {
   9441                                        modifiers |= TypeScript.Modifiers.Getter;
   9442                                        this.prevIDTok = null;
   9443                                    }
   9444                                } else {
   9445                                    if(this.currentToken.tokenId == TypeScript.TokenID.Set) {
   9446                                        this.prevIDTok = this.currentToken;
   9447                                        this.currentToken = this.scanner.scan();
   9448                                        if(TypeScript.codeGenTarget < TypeScript.CodeGenTarget.ES5) {
   9449                                            this.reportParseError("Property accessors are only available when targeting ES5 or greater");
   9450                                        }
   9451                                        if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) || TypeScript.convertTokToID(this.currentToken, this.strictMode)) {
   9452                                            modifiers |= TypeScript.Modifiers.Setter;
   9453                                            this.prevIDTok = null;
   9454                                        }
   9455                                    }
   9456                                }
   9457                                fnOrVar = this.parsePropertyDeclaration(errorRecoverySet | TypeScript.ErrorRecoverySet.SColon, modifiers, isAmbient(), false);
   9458                                if((fnOrVar.nodeType == TypeScript.NodeType.VarDecl) || ((fnOrVar.nodeType == TypeScript.NodeType.FuncDecl) && (TypeScript.hasFlag((fnOrVar).fncFlags, TypeScript.FncFlags.IsFatArrowFunction)))) {
   9459                                    needTerminator = true;
   9460                                }
   9461                                ast = fnOrVar;
   9462                            }
   9463                        }
   9464                        break;
   9465 
   9466                    }
   9467                    case TypeScript.TokenID.Public: {
   9468                        if(this.parsingClassConstructorDefinition) {
   9469                            if(!this.inferPropertiesFromThisAssignment) {
   9470                                this.reportParseError("Property declarations are not permitted within constructor bodies");
   9471                            }
   9472                            this.currentToken = this.scanner.scan();
   9473                            minChar = this.scanner.pos;
   9474                            modifiers |= TypeScript.Modifiers.Public;
   9475                            if(this.inferPropertiesFromThisAssignment && (this.currentToken.tokenId != TypeScript.TokenID.This || (this.currentToken = this.scanner.scan()).tokenId != TypeScript.TokenID.Dot)) {
   9476                                this.reportParseError("Expected 'this.' for property declaration");
   9477                                this.currentToken = this.scanner.scan();
   9478                                ast = new TypeScript.AST(TypeScript.NodeType.Error);
   9479                                ast.minChar = minChar;
   9480                                ast.limChar = this.scanner.lastTokenLimChar();
   9481                            } else {
   9482                                this.currentToken = this.scanner.scan();
   9483                                var id = TypeScript.Identifier.fromToken(this.currentToken);
   9484                                id.minChar = this.scanner.startPos;
   9485                                id.limChar = this.scanner.pos;
   9486                                this.currentToken = this.scanner.scan();
   9487                                ast = this.parseClassMemberVariableDeclaration(id, minChar, this.parsingClassConstructorDefinition, errorRecoverySet, modifiers);
   9488                            }
   9489                        } else {
   9490                            if((allowedElements & TypeScript.AllowedElements.Properties) == TypeScript.AllowedElements.None) {
   9491                                this.reportParseError("'property' statements are only allowed within classes");
   9492                                this.currentToken = this.scanner.scan();
   9493                                ast = new TypeScript.AST(TypeScript.NodeType.Error);
   9494                                ast.minChar = minChar;
   9495                                ast.limChar = this.scanner.lastTokenLimChar();
   9496                            } else {
   9497                                modifiers |= TypeScript.Modifiers.Public;
   9498                                this.currentToken = this.scanner.scan();
   9499                                if(this.currentToken.tokenId == TypeScript.TokenID.Get) {
   9500                                    this.prevIDTok = this.currentToken;
   9501                                    this.currentToken = this.scanner.scan();
   9502                                    if(TypeScript.codeGenTarget < TypeScript.CodeGenTarget.ES5) {
   9503                                        this.reportParseError("Property accessors are only available when targeting ES5 or greater");
   9504                                    }
   9505                                    if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) || TypeScript.convertTokToID(this.currentToken, this.strictMode)) {
   9506                                        modifiers |= TypeScript.Modifiers.Getter;
   9507                                        this.prevIDTok = null;
   9508                                    }
   9509                                } else {
   9510                                    if(this.currentToken.tokenId == TypeScript.TokenID.Set) {
   9511                                        this.prevIDTok = this.currentToken;
   9512                                        this.currentToken = this.scanner.scan();
   9513                                        if(TypeScript.codeGenTarget < TypeScript.CodeGenTarget.ES5) {
   9514                                            this.reportParseError("Property accessors are only available when targeting ES5 or greater");
   9515                                        }
   9516                                        if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) || TypeScript.convertTokToID(this.currentToken, this.strictMode)) {
   9517                                            modifiers |= TypeScript.Modifiers.Setter;
   9518                                            this.prevIDTok = null;
   9519                                        }
   9520                                    }
   9521                                }
   9522                                fnOrVar = this.parsePropertyDeclaration(errorRecoverySet | TypeScript.ErrorRecoverySet.SColon, modifiers, isAmbient(), false);
   9523                                if((fnOrVar.nodeType == TypeScript.NodeType.VarDecl) || ((fnOrVar.nodeType == TypeScript.NodeType.FuncDecl) && TypeScript.hasFlag((fnOrVar).fncFlags, TypeScript.FncFlags.IsFatArrowFunction))) {
   9524                                    needTerminator = true;
   9525                                }
   9526                                ast = fnOrVar;
   9527                            }
   9528                        }
   9529                        break;
   9530 
   9531                    }
   9532                    case TypeScript.TokenID.Declare: {
   9533                        if(!(allowedElements & TypeScript.AllowedElements.AmbientDeclarations)) {
   9534                            this.reportParseError("Ambient declarations are only allowed at the top-level or module scopes");
   9535                        }
   9536                        if(!this.parsingDeclareFile && TypeScript.hasFlag(parentModifiers, TypeScript.Modifiers.Ambient)) {
   9537                            this.reportParseError("Duplicate ambient declaration in this context. (Is the enclosing module or class already ambient?)");
   9538                        }
   9539                        modifiers |= TypeScript.Modifiers.Ambient;
   9540                        this.currentToken = this.scanner.scan();
   9541                        break;
   9542 
   9543                    }
   9544                    case TypeScript.TokenID.Class: {
   9545                        if((allowedElements & TypeScript.AllowedElements.ClassDeclarations) == TypeScript.AllowedElements.None) {
   9546                            this.reportParseError("class not allowed in this context");
   9547                            this.currentToken = this.scanner.scan();
   9548                            ast = new TypeScript.AST(TypeScript.NodeType.Error);
   9549                            ast.minChar = minChar;
   9550                            ast.limChar = this.scanner.lastTokenLimChar();
   9551                        } else {
   9552                            ast = this.parseClassDecl(errorRecoverySet, minChar, modifiers);
   9553                        }
   9554                        break;
   9555 
   9556                    }
   9557                    case TypeScript.TokenID.Interface: {
   9558                        if((allowedElements & TypeScript.AllowedElements.InterfaceDeclarations) == TypeScript.AllowedElements.None) {
   9559                            this.reportParseError("interface not allowed in this context");
   9560                            this.currentToken = this.scanner.scan();
   9561                            ast = new TypeScript.AST(TypeScript.NodeType.Error);
   9562                            ast.minChar = minChar;
   9563                            ast.limChar = this.scanner.lastTokenLimChar();
   9564                        } else {
   9565                            ast = this.parseInterfaceDecl(errorRecoverySet, modifiers);
   9566                        }
   9567                        break;
   9568 
   9569                    }
   9570                    case TypeScript.TokenID.Var: {
   9571                        var declAst = this.parseVariableDeclaration(errorRecoverySet | TypeScript.ErrorRecoverySet.StmtStart, modifiers, true, false);
   9572                        if(declAst.nodeType == TypeScript.NodeType.VarDecl) {
   9573                            ast = declAst;
   9574                        } else {
   9575                            ast = new TypeScript.Block(declAst, false);
   9576                        }
   9577                        needTerminator = true;
   9578                        break;
   9579 
   9580                    }
   9581                    case TypeScript.TokenID.Static: {
   9582                        if(this.currentClassDecl == null) {
   9583                            this.reportParseError("Statics may only be class members");
   9584                        }
   9585                        mayNotBeExported();
   9586                        modifiers |= TypeScript.Modifiers.Public;
   9587                        this.currentToken = this.scanner.scan();
   9588                        if(this.currentToken.tokenId == TypeScript.TokenID.Get) {
   9589                            this.prevIDTok = this.currentToken;
   9590                            this.currentToken = this.scanner.scan();
   9591                            if(TypeScript.codeGenTarget < TypeScript.CodeGenTarget.ES5) {
   9592                                this.reportParseError("Property accessors are only available when targeting ES5 or greater");
   9593                            }
   9594                            if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) || TypeScript.convertTokToID(this.currentToken, this.strictMode)) {
   9595                                modifiers |= TypeScript.Modifiers.Getter;
   9596                                this.prevIDTok = null;
   9597                            }
   9598                        } else {
   9599                            if(this.currentToken.tokenId == TypeScript.TokenID.Set) {
   9600                                this.currentToken = this.scanner.scan();
   9601                                if(TypeScript.codeGenTarget < TypeScript.CodeGenTarget.ES5) {
   9602                                    this.reportParseError("Property accessors are only available when targeting ES5 or greater");
   9603                                }
   9604                                if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) || TypeScript.convertTokToID(this.currentToken, this.strictMode)) {
   9605                                    modifiers |= TypeScript.Modifiers.Setter;
   9606                                }
   9607                            }
   9608                        }
   9609                        if(isAmbient()) {
   9610                            modifiers |= TypeScript.Modifiers.Ambient;
   9611                        }
   9612                        fnOrVar = this.parsePropertyDeclaration(errorRecoverySet | TypeScript.ErrorRecoverySet.SColon, modifiers, this.parsingDeclareFile || (modifiers & TypeScript.Modifiers.Ambient) != TypeScript.Modifiers.None, true);
   9613                        var staticsList = this.topStaticsList();
   9614                        if(staticsList && fnOrVar.nodeType == TypeScript.NodeType.VarDecl) {
   9615                            staticsList.append(fnOrVar);
   9616                        }
   9617                        if(fnOrVar.nodeType == TypeScript.NodeType.VarDecl || ((fnOrVar.nodeType == TypeScript.NodeType.FuncDecl) && TypeScript.hasFlag((fnOrVar).fncFlags, TypeScript.FncFlags.IsFatArrowFunction))) {
   9618                            needTerminator = true;
   9619                        }
   9620                        ast = fnOrVar;
   9621                        break;
   9622 
   9623                    }
   9624                    case TypeScript.TokenID.For: {
   9625                        mayNotBeExported();
   9626                        if(modifiers != TypeScript.Modifiers.None) {
   9627                            this.reportParseError("syntax error: for statement does not take modifiers");
   9628                        }
   9629                        minChar = this.scanner.startPos;
   9630                        this.checkNextToken(TypeScript.TokenID.OpenParen, errorRecoverySet | TypeScript.ErrorRecoverySet.ExprStart | TypeScript.ErrorRecoverySet.Var);
   9631                        this.state = ParseState.ForInit;
   9632                        forInOk = true;
   9633                        switch(this.currentToken.tokenId) {
   9634                            case TypeScript.TokenID.Var: {
   9635                                temp = this.parseVariableDeclaration(errorRecoverySet | TypeScript.ErrorRecoverySet.SColon | TypeScript.ErrorRecoverySet.In, TypeScript.Modifiers.None, false, false);
   9636                                break;
   9637 
   9638                            }
   9639                            case TypeScript.TokenID.Semicolon: {
   9640                                temp = null;
   9641                                this.state = ParseState.ForCondStart;
   9642                                break;
   9643 
   9644                            }
   9645                            default: {
   9646                                temp = this.parseExpr(errorRecoverySet | TypeScript.ErrorRecoverySet.SColon | TypeScript.ErrorRecoverySet.In, TypeScript.OperatorPrecedence.None, false, TypeContext.NoTypes);
   9647                                break;
   9648 
   9649                            }
   9650                        }
   9651                        this.state = ParseState.ForInitAfterVar;
   9652                        if(this.currentToken.tokenId == TypeScript.TokenID.In) {
   9653                            if((temp == null) || (!forInOk)) {
   9654                                this.reportParseError("malformed for statement");
   9655                                if(this.errorRecovery) {
   9656                                    this.skip(errorRecoverySet | TypeScript.ErrorRecoverySet.StmtStart);
   9657                                    ast = new TypeScript.AST(TypeScript.NodeType.Empty);
   9658                                    ast.flags |= TypeScript.ASTFlags.Error;
   9659                                }
   9660                            } else {
   9661                                this.currentToken = this.scanner.scan();
   9662                                var forInStmt = new TypeScript.ForInStatement(temp, this.parseExpr(TypeScript.ErrorRecoverySet.RParen | errorRecoverySet, TypeScript.OperatorPrecedence.Comma, false, TypeContext.NoTypes));
   9663                                forInStmt.limChar = this.scanner.pos;
   9664                                forInStmt.statement.minChar = minChar;
   9665                                forInStmt.statement.limChar = this.scanner.pos;
   9666                                this.checkCurrentToken(TypeScript.TokenID.CloseParen, TypeScript.ErrorRecoverySet.StmtStart | errorRecoverySet);
   9667                                this.pushStmt(forInStmt, labelList);
   9668                                forInStmt.body = this.parseStatement(errorRecoverySet, allowedElements, parentModifiers);
   9669                                this.popStmt();
   9670                                forInStmt.minChar = minChar;
   9671                                ast = forInStmt;
   9672                            }
   9673                        } else {
   9674                            var forStmt = new TypeScript.ForStatement(temp);
   9675                            forStmt.minChar = minChar;
   9676                            this.checkCurrentToken(TypeScript.TokenID.Semicolon, errorRecoverySet);
   9677                            if(this.currentToken.tokenId == TypeScript.TokenID.Semicolon) {
   9678                                forStmt.cond = null;
   9679                            } else {
   9680                                forStmt.cond = this.parseExpr(errorRecoverySet | TypeScript.ErrorRecoverySet.SColon | TypeScript.ErrorRecoverySet.RParen, TypeScript.OperatorPrecedence.None, true, TypeContext.NoTypes);
   9681                                if(this.currentToken.tokenId != TypeScript.TokenID.Semicolon) {
   9682                                    this.skip(errorRecoverySet | TypeScript.ErrorRecoverySet.StmtStart);
   9683                                    ast = forStmt;
   9684                                    ast.flags |= TypeScript.ASTFlags.Error;
   9685                                }
   9686                            }
   9687                            this.currentToken = this.scanner.scan();
   9688                            if(this.currentToken.tokenId == TypeScript.TokenID.CloseParen) {
   9689                                forStmt.incr = null;
   9690                            } else {
   9691                                forStmt.incr = this.parseExpr(errorRecoverySet | TypeScript.ErrorRecoverySet.SColon | TypeScript.ErrorRecoverySet.RParen, TypeScript.OperatorPrecedence.None, true, TypeContext.NoTypes);
   9692                            }
   9693                            this.checkCurrentToken(TypeScript.TokenID.CloseParen, errorRecoverySet | TypeScript.ErrorRecoverySet.LCurly);
   9694                            this.pushStmt(forStmt, labelList);
   9695                            forStmt.body = this.parseStatement(errorRecoverySet, allowedElements, parentModifiers);
   9696                            this.popStmt();
   9697                            forStmt.limChar = forStmt.body.limChar;
   9698                            ast = forStmt;
   9699                        }
   9700                        break;
   9701 
   9702                    }
   9703                    case TypeScript.TokenID.With: {
   9704 {
   9705                            if(TypeScript.codeGenTarget < TypeScript.CodeGenTarget.ES5) {
   9706                                this.reportParseError("'with' statements are only available in ES5 codegen mode or better");
   9707                            }
   9708                            if(this.strictMode) {
   9709                                this.reportParseError("'with' statements are not available in strict mode");
   9710                            }
   9711                            mayNotBeExported();
   9712                            if(modifiers != TypeScript.Modifiers.None) {
   9713                                this.reportParseError("'with' statement does not take modifiers");
   9714                            }
   9715                            minChar = this.scanner.startPos;
   9716                            this.checkNextToken(TypeScript.TokenID.OpenParen, errorRecoverySet | TypeScript.ErrorRecoverySet.ExprStart | TypeScript.ErrorRecoverySet.Var);
   9717                            var expr = this.parseExpr(errorRecoverySet | TypeScript.ErrorRecoverySet.Colon, TypeScript.OperatorPrecedence.None, true, TypeContext.NoTypes);
   9718                            this.checkCurrentToken(TypeScript.TokenID.CloseParen, errorRecoverySet | TypeScript.ErrorRecoverySet.LCurly);
   9719                            var withStmt = new TypeScript.WithStatement(expr);
   9720                            withStmt.body = this.parseStatement(errorRecoverySet, allowedElements, parentModifiers);
   9721                            withStmt.minChar = minChar;
   9722                            withStmt.limChar = withStmt.body.limChar;
   9723                            ast = withStmt;
   9724                        }
   9725                        break;
   9726 
   9727                    }
   9728                    case TypeScript.TokenID.Switch: {
   9729                        mayNotBeExported();
   9730                        if(modifiers != TypeScript.Modifiers.None) {
   9731                            this.reportParseError("'switch' statement does not take modifiers");
   9732                        }
   9733                        this.checkNextToken(TypeScript.TokenID.OpenParen, errorRecoverySet | TypeScript.ErrorRecoverySet.ExprStart);
   9734                        var switchStmt = new TypeScript.SwitchStatement(this.parseExpr(errorRecoverySet | TypeScript.ErrorRecoverySet.RParen, TypeScript.OperatorPrecedence.None, true, TypeContext.NoTypes));
   9735                        switchStmt.statement.minChar = minChar;
   9736                        switchStmt.statement.limChar = this.scanner.pos;
   9737                        this.checkCurrentToken(TypeScript.TokenID.CloseParen, errorRecoverySet | TypeScript.ErrorRecoverySet.LCurly);
   9738                        var caseListMinChar = this.scanner.startPos;
   9739                        this.checkCurrentToken(TypeScript.TokenID.OpenBrace, errorRecoverySet | TypeScript.ErrorRecoverySet.SCase);
   9740                        switchStmt.defaultCase = null;
   9741                        switchStmt.caseList = new TypeScript.ASTList();
   9742                        var caseStmt = null;
   9743                        this.pushStmt(switchStmt, labelList);
   9744                        for(; ; ) {
   9745                            if((this.currentToken.tokenId == TypeScript.TokenID.Case) || (this.currentToken.tokenId == TypeScript.TokenID.Default)) {
   9746                                var isDefault = (this.currentToken.tokenId == TypeScript.TokenID.Default);
   9747                                caseStmt = new TypeScript.CaseStatement();
   9748                                caseStmt.minChar = this.scanner.startPos;
   9749                                this.currentToken = this.scanner.scan();
   9750                                if(isDefault) {
   9751                                    switchStmt.defaultCase = caseStmt;
   9752                                } else {
   9753                                    caseStmt.expr = this.parseExpr(errorRecoverySet | TypeScript.ErrorRecoverySet.Colon, TypeScript.OperatorPrecedence.None, true, TypeContext.NoTypes);
   9754                                }
   9755                                this.checkCurrentToken(TypeScript.TokenID.Colon, errorRecoverySet | TypeScript.ErrorRecoverySet.StmtStart);
   9756                                caseStmt.body = new TypeScript.ASTList();
   9757                                this.parseStatementList(errorRecoverySet | TypeScript.ErrorRecoverySet.RCurly, caseStmt.body, false, true, allowedElements, modifiers);
   9758                                caseStmt.limChar = caseStmt.body.limChar;
   9759                                switchStmt.caseList.append(caseStmt);
   9760                            } else {
   9761                                break;
   9762                            }
   9763                        }
   9764                        switchStmt.caseList.minChar = caseListMinChar;
   9765                        switchStmt.caseList.limChar = this.scanner.pos;
   9766                        switchStmt.limChar = switchStmt.caseList.limChar;
   9767                        this.checkCurrentToken(TypeScript.TokenID.CloseBrace, errorRecoverySet);
   9768                        this.popStmt();
   9769                        ast = switchStmt;
   9770                        break;
   9771                    }
   9772 
   9773                    case TypeScript.TokenID.While: {
   9774                        mayNotBeExported();
   9775                        if(modifiers != TypeScript.Modifiers.None) {
   9776                            this.reportParseError("'while' statement does not take modifiers");
   9777                        }
   9778                        minChar = this.scanner.startPos;
   9779                        this.checkNextToken(TypeScript.TokenID.OpenParen, TypeScript.ErrorRecoverySet.ExprStart | errorRecoverySet);
   9780                        var whileStmt = new TypeScript.WhileStatement(this.parseExpr(errorRecoverySet | TypeScript.ErrorRecoverySet.RParen, TypeScript.OperatorPrecedence.None, true, TypeContext.NoTypes));
   9781                        whileStmt.minChar = minChar;
   9782                        this.checkCurrentToken(TypeScript.TokenID.CloseParen, errorRecoverySet | TypeScript.ErrorRecoverySet.StmtStart);
   9783                        this.pushStmt(whileStmt, labelList);
   9784                        whileStmt.body = this.parseStatement(errorRecoverySet, allowedElements, parentModifiers);
   9785                        whileStmt.limChar = whileStmt.body.limChar;
   9786                        this.popStmt();
   9787                        ast = whileStmt;
   9788                        break;
   9789                    }
   9790 
   9791                    case TypeScript.TokenID.Do: {
   9792                        mayNotBeExported();
   9793                        if(modifiers != TypeScript.Modifiers.None) {
   9794                            this.reportParseError("'do' statement does not take modifiers");
   9795                        }
   9796                        minChar = this.scanner.startPos;
   9797                        this.currentToken = this.scanner.scan();
   9798                        var doStmt = new TypeScript.DoWhileStatement();
   9799                        doStmt.minChar = minChar;
   9800                        this.pushStmt(doStmt, labelList);
   9801                        doStmt.body = this.parseStatement(errorRecoverySet | TypeScript.ErrorRecoverySet.While, allowedElements, parentModifiers);
   9802                        this.popStmt();
   9803                        doStmt.whileAST = new TypeScript.Identifier("while");
   9804                        doStmt.whileAST.minChar = this.scanner.startPos;
   9805                        this.checkCurrentToken(TypeScript.TokenID.While, errorRecoverySet | TypeScript.ErrorRecoverySet.LParen);
   9806                        doStmt.whileAST.limChar = doStmt.whileAST.minChar + 5;
   9807                        this.checkCurrentToken(TypeScript.TokenID.OpenParen, errorRecoverySet | TypeScript.ErrorRecoverySet.ExprStart);
   9808                        doStmt.cond = this.parseExpr(errorRecoverySet | TypeScript.ErrorRecoverySet.RParen, TypeScript.OperatorPrecedence.None, true, TypeContext.NoTypes);
   9809                        doStmt.limChar = this.scanner.pos;
   9810                        this.checkCurrentToken(TypeScript.TokenID.CloseParen, errorRecoverySet);
   9811                        ast = doStmt;
   9812                        if(this.currentToken.tokenId == TypeScript.TokenID.Semicolon) {
   9813                            this.currentToken = this.scanner.scan();
   9814                        }
   9815                        break;
   9816                    }
   9817 
   9818                    case TypeScript.TokenID.If: {
   9819                        mayNotBeExported();
   9820                        if(modifiers != TypeScript.Modifiers.None) {
   9821                            this.reportParseError("if statement does not take modifiers");
   9822                        }
   9823                        minChar = this.scanner.startPos;
   9824                        this.checkNextToken(TypeScript.TokenID.OpenParen, errorRecoverySet | TypeScript.ErrorRecoverySet.ExprStart);
   9825                        var ifStmt = new TypeScript.IfStatement(this.parseExpr(errorRecoverySet | TypeScript.ErrorRecoverySet.LParen, TypeScript.OperatorPrecedence.None, true, TypeContext.NoTypes));
   9826                        ifStmt.minChar = minChar;
   9827                        ifStmt.statement.minChar = minChar;
   9828                        ifStmt.statement.limChar = this.scanner.pos;
   9829                        this.checkCurrentToken(TypeScript.TokenID.CloseParen, errorRecoverySet | TypeScript.ErrorRecoverySet.StmtStart);
   9830                        this.pushStmt(ifStmt, labelList);
   9831                        ifStmt.thenBod = this.parseStatement(TypeScript.ErrorRecoverySet.Else | errorRecoverySet, allowedElements, parentModifiers);
   9832                        ifStmt.limChar = ifStmt.thenBod.limChar;
   9833                        if(this.currentToken.tokenId == TypeScript.TokenID.Else) {
   9834                            this.currentToken = this.scanner.scan();
   9835                            ifStmt.elseBod = this.parseStatement(errorRecoverySet, allowedElements, parentModifiers);
   9836                            ifStmt.limChar = ifStmt.elseBod.limChar;
   9837                        }
   9838                        this.popStmt();
   9839                        ast = ifStmt;
   9840                        break;
   9841                    }
   9842 
   9843                    case TypeScript.TokenID.Try: {
   9844                        mayNotBeExported();
   9845                        if(modifiers != TypeScript.Modifiers.None) {
   9846                            this.reportParseError("try statement does not take modifiers");
   9847                        }
   9848                        minChar = this.scanner.startPos;
   9849                        ast = this.parseTryCatchFinally(errorRecoverySet, parentModifiers, labelList);
   9850                        break;
   9851                    }
   9852 
   9853                    case TypeScript.TokenID.OpenBrace: {
   9854                        mayNotBeExported();
   9855                        if(modifiers != TypeScript.Modifiers.None) {
   9856                            this.reportParseError("block does not take modifiers");
   9857                        }
   9858                        minChar = this.scanner.startPos;
   9859                        this.currentToken = this.scanner.scan();
   9860                        var block = new TypeScript.Block(new TypeScript.ASTList(), true);
   9861                        this.pushStmt(block, labelList);
   9862                        this.parseStatementList(errorRecoverySet | TypeScript.ErrorRecoverySet.RCurly, block.statements, false, false, TypeScript.AllowedElements.None, modifiers);
   9863                        this.popStmt();
   9864                        block.statements.minChar = minChar;
   9865                        block.statements.limChar = this.scanner.pos;
   9866                        block.minChar = block.statements.minChar;
   9867                        block.limChar = block.statements.limChar;
   9868                        this.checkCurrentToken(TypeScript.TokenID.CloseBrace, errorRecoverySet);
   9869                        ast = block;
   9870                        break;
   9871                    }
   9872 
   9873                    case TypeScript.TokenID.Semicolon: {
   9874                        mayNotBeExported();
   9875                        if(modifiers != TypeScript.Modifiers.None) {
   9876                            this.reportParseError("modifier can not appear here");
   9877                        }
   9878                        ast = new TypeScript.AST(TypeScript.NodeType.Empty);
   9879                        this.currentToken = this.scanner.scan();
   9880                        break;
   9881 
   9882                    }
   9883                    case TypeScript.TokenID.Break:
   9884                    case TypeScript.TokenID.Continue: {
   9885                        mayNotBeExported();
   9886                        if(modifiers != TypeScript.Modifiers.None) {
   9887                            this.reportParseError("modifiers can not appear before jump statement");
   9888                        }
   9889                        var jump = new TypeScript.Jump((this.currentToken.tokenId == TypeScript.TokenID.Break) ? TypeScript.NodeType.Break : TypeScript.NodeType.Continue);
   9890                        this.currentToken = this.scanner.scan();
   9891                        if((this.currentToken.tokenId == TypeScript.TokenID.Identifier) && (!this.scanner.lastTokenHadNewline())) {
   9892                            jump.target = this.currentToken.getText();
   9893                            this.currentToken = this.scanner.scan();
   9894                        }
   9895                        this.resolveJumpTarget(jump);
   9896                        ast = jump;
   9897                        needTerminator = true;
   9898                        break;
   9899                    }
   9900 
   9901                    case TypeScript.TokenID.Return: {
   9902                        mayNotBeExported();
   9903                        if(modifiers != TypeScript.Modifiers.None) {
   9904                            this.reportParseError("modifiers can not appear before return statement");
   9905                        }
   9906                        if(!this.inFunction) {
   9907                            this.reportParseError("return statement outside of function body");
   9908                        }
   9909                        minChar = this.scanner.startPos;
   9910                        this.currentToken = this.scanner.scan();
   9911                        var retStmt = new TypeScript.ReturnStatement();
   9912                        retStmt.minChar = minChar;
   9913                        if((this.currentToken.tokenId != TypeScript.TokenID.Semicolon) && (this.currentToken.tokenId != TypeScript.TokenID.CloseBrace) && (!(this.scanner.lastTokenHadNewline()))) {
   9914                            retStmt.returnExpression = this.parseExpr(errorRecoverySet | TypeScript.ErrorRecoverySet.SColon, TypeScript.OperatorPrecedence.None, true, TypeContext.NoTypes);
   9915                        }
   9916                        needTerminator = true;
   9917                        retStmt.limChar = this.scanner.lastTokenLimChar();
   9918                        ast = retStmt;
   9919                        break;
   9920                    }
   9921 
   9922                    case TypeScript.TokenID.Throw: {
   9923                        mayNotBeExported();
   9924                        if(modifiers != TypeScript.Modifiers.None) {
   9925                            this.reportParseError("modifiers can not appear before a throw statement");
   9926                        }
   9927                        minChar = this.scanner.startPos;
   9928                        this.currentToken = this.scanner.scan();
   9929                        if((this.currentToken.tokenId != TypeScript.TokenID.Semicolon) && (this.currentToken.tokenId != TypeScript.TokenID.CloseBrace) && (!(this.scanner.lastTokenHadNewline()))) {
   9930                            temp = this.parseExpr(errorRecoverySet | TypeScript.ErrorRecoverySet.SColon, TypeScript.OperatorPrecedence.None, true, TypeContext.NoTypes);
   9931                        } else {
   9932                            this.reportParseError("throw with no target");
   9933                            temp = null;
   9934                        }
   9935                        ast = new TypeScript.UnaryExpression(TypeScript.NodeType.Throw, temp);
   9936                        ast.limChar = this.scanner.lastTokenLimChar();
   9937                        needTerminator = true;
   9938                        break;
   9939 
   9940                    }
   9941                    case TypeScript.TokenID.Enum: {
   9942                        this.currentToken = this.scanner.scan();
   9943                        ast = this.parseEnumDecl(errorRecoverySet, modifiers);
   9944                        ast.minChar = minChar;
   9945                        ast.limChar = this.scanner.lastTokenLimChar();
   9946                        if(this.parsingDeclareFile || this.ambientModule || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Ambient)) {
   9947                            (ast).modFlags |= TypeScript.ModuleFlags.Ambient;
   9948                        }
   9949                        if(this.parsingDeclareFile || this.ambientModule || TypeScript.hasFlag(modifiers, TypeScript.Modifiers.Exported)) {
   9950                            (ast).modFlags |= TypeScript.ModuleFlags.Exported;
   9951                        }
   9952                        break;
   9953 
   9954                    }
   9955                    case TypeScript.TokenID.Debugger: {
   9956                        mayNotBeExported();
   9957                        if(modifiers != TypeScript.Modifiers.None) {
   9958                            this.reportParseError("modifiers can not appear before debugger statement");
   9959                        }
   9960                        minChar = this.scanner.startPos;
   9961                        this.currentToken = this.scanner.scan();
   9962                        var debuggerStmt = new TypeScript.DebuggerStatement();
   9963                        debuggerStmt.minChar = minChar;
   9964                        needTerminator = true;
   9965                        debuggerStmt.limChar = this.scanner.lastTokenLimChar();
   9966                        ast = debuggerStmt;
   9967                        break;
   9968 
   9969                    }
   9970                    default: {
   9971                        if(modifiers != TypeScript.Modifiers.None) {
   9972                            this.reportParseError("modifiers can not appear before an expression statement or label");
   9973                        }
   9974                        minChar = this.scanner.startPos;
   9975                        var svPos = this.scanner.pos;
   9976                        temp = this.parseExpr(TypeScript.ErrorRecoverySet.Colon | TypeScript.ErrorRecoverySet.StmtStart | errorRecoverySet, TypeScript.OperatorPrecedence.None, true, TypeContext.NoTypes);
   9977                        if(this.scanner.pos == svPos) {
   9978                            this.currentToken = this.scanner.scan();
   9979                            ast = temp;
   9980                        } else {
   9981                            if((this.currentToken.tokenId == TypeScript.TokenID.Colon) && (!this.scanner.lastTokenHadNewline()) && temp && (temp.nodeType == TypeScript.NodeType.Name)) {
   9982                                if(labelList == null) {
   9983                                    labelList = new TypeScript.ASTList();
   9984                                }
   9985                                labelList.append(new TypeScript.Label(temp));
   9986                                this.currentToken = this.scanner.scan();
   9987                            } else {
   9988                                ast = temp;
   9989                                needTerminator = true;
   9990                            }
   9991                        }
   9992 
   9993                    }
   9994                }
   9995                if(ast) {
   9996                    break;
   9997                }
   9998            }
   9999            if(needTerminator) {
  10000                switch(this.currentToken.tokenId) {
  10001                    case TypeScript.TokenID.Semicolon: {
  10002                        this.currentToken = this.scanner.scan();
  10003                        ast.flags |= TypeScript.ASTFlags.ExplicitSemicolon;
  10004                        break;
  10005 
  10006                    }
  10007                    case TypeScript.TokenID.EndOfFile: {
  10008                        ast.limChar = this.scanner.pos;
  10009 
  10010                    }
  10011                    case TypeScript.TokenID.CloseBrace: {
  10012                        ast.flags |= TypeScript.ASTFlags.AutomaticSemicolon;
  10013                        if(this.style_requireSemi) {
  10014                            this.reportParseStyleError("no automatic semicolon");
  10015                        }
  10016                        break;
  10017 
  10018                    }
  10019                    default: {
  10020                        if(!this.scanner.lastTokenHadNewline()) {
  10021                            this.reportParseError("Expected ';'");
  10022                        } else {
  10023                            ast.flags |= TypeScript.ASTFlags.AutomaticSemicolon;
  10024                            if(this.style_requireSemi) {
  10025                                this.reportParseStyleError("no automatic semicolon");
  10026                            }
  10027                        }
  10028                        break;
  10029 
  10030                    }
  10031                }
  10032            }
  10033            if(labelList) {
  10034                ast = new TypeScript.LabeledStatement(labelList, ast);
  10035            }
  10036            ast.minChar = minChar;
  10037            ast.limChar = TypeScript.max(ast.limChar, this.scanner.lastTokenLimChar());
  10038            if(preComments) {
  10039                ast.preComments = preComments;
  10040            }
  10041            if(this.ambientModule && (!this.okAmbientModuleMember(ast))) {
  10042                this.reportParseError("statement not permitted within ambient module");
  10043            }
  10044            ast.flags |= TypeScript.ASTFlags.IsStatement;
  10045            return ast;
  10046        };
  10047        Parser.prototype.okAmbientModuleMember = function (ast) {
  10048            var nt = ast.nodeType;
  10049            return (nt == TypeScript.NodeType.ClassDeclaration) || (nt == TypeScript.NodeType.ImportDeclaration) || (nt == TypeScript.NodeType.InterfaceDeclaration) || (nt == TypeScript.NodeType.ModuleDeclaration) || (nt == TypeScript.NodeType.Empty) || (nt == TypeScript.NodeType.VarDecl) || ((nt == TypeScript.NodeType.Block) && !(ast).isStatementBlock) || ((nt == TypeScript.NodeType.FuncDecl) && ((ast).isMethod()));
  10050        };
  10051        Parser.prototype.parseStatementList = function (errorRecoverySet, statements, sourceElms, noLeadingCase, allowedElements, parentModifiers) {
  10052            var directivePrologue = sourceElms;
  10053            statements.minChar = this.scanner.startPos;
  10054            var limChar = this.scanner.pos;
  10055            var innerStmts = (allowedElements & TypeScript.AllowedElements.ModuleDeclarations) == TypeScript.AllowedElements.None;
  10056            var classNope = (allowedElements & TypeScript.AllowedElements.ClassDeclarations) == TypeScript.AllowedElements.None;
  10057            errorRecoverySet |= TypeScript.ErrorRecoverySet.TypeScriptS | TypeScript.ErrorRecoverySet.RCurly;
  10058            this.state = ParseState.StartStatementList;
  10059            var oldStrictMode = this.strictMode;
  10060            this.nestingLevel++;
  10061            for(; ; ) {
  10062                if((this.currentToken.tokenId == TypeScript.TokenID.CloseBrace) || (noLeadingCase && ((this.currentToken.tokenId == TypeScript.TokenID.Case) || (this.currentToken.tokenId == TypeScript.TokenID.Default))) || (innerStmts && (this.currentToken.tokenId == TypeScript.TokenID.Export)) || (classNope && (this.currentToken.tokenId == TypeScript.TokenID.Class)) || (this.currentToken.tokenId == TypeScript.TokenID.EndOfFile)) {
  10063                    this.state = ParseState.EndStmtList;
  10064                    statements.limChar = limChar;
  10065                    if(statements.members.length == 0) {
  10066                        statements.preComments = this.parseComments();
  10067                    } else {
  10068                        statements.postComments = this.parseComments();
  10069                    }
  10070                    this.strictMode = oldStrictMode;
  10071                    this.nestingLevel--;
  10072                    return;
  10073                }
  10074                var stmt = this.parseStatement(errorRecoverySet & (~(TypeScript.ErrorRecoverySet.Else | TypeScript.ErrorRecoverySet.RParen | TypeScript.ErrorRecoverySet.Catch | TypeScript.ErrorRecoverySet.Colon)), allowedElements, parentModifiers);
  10075                if(stmt) {
  10076                    stmt.postComments = this.combineComments(stmt.postComments, this.parseCommentsForLine(this.scanner.prevLine));
  10077                    statements.append(stmt);
  10078                    limChar = stmt.limChar;
  10079                    if(directivePrologue) {
  10080                        if(stmt.nodeType == TypeScript.NodeType.QString) {
  10081                            var qstring = stmt;
  10082                            if(qstring.text == "\"use strict\"") {
  10083                                statements.flags |= TypeScript.ASTFlags.StrictMode;
  10084                                this.strictMode = true;
  10085                            } else {
  10086                                directivePrologue = false;
  10087                            }
  10088                        } else {
  10089                            directivePrologue = false;
  10090                        }
  10091                    }
  10092                }
  10093            }
  10094        };
  10095        Parser.prototype.quickParse = function (sourceText, filename, unitIndex) {
  10096            var svGenTarget = TypeScript.moduleGenTarget;
  10097            try  {
  10098                TypeScript.moduleGenTarget = TypeScript.ModuleGenTarget.Local;
  10099                var script = this.parse(sourceText, filename, unitIndex, TypeScript.AllowedElements.QuickParse);
  10100                return new QuickParseResult(script, this.scanner.lexState);
  10101            }finally {
  10102                TypeScript.moduleGenTarget = svGenTarget;
  10103            }
  10104        };
  10105        Parser.prototype.parse = function (sourceText, filename, unitIndex, allowedElements) {
  10106            if (typeof allowedElements === "undefined") { allowedElements = TypeScript.AllowedElements.Global; }
  10107            var _this = this;
  10108            this.ambientModule = false;
  10109            this.topLevel = true;
  10110            this.hasTopLevelImportOrExport = false;
  10111            this.requiresExtendsBlock = false;
  10112            this.fname = filename;
  10113            this.currentUnitIndex = unitIndex;
  10114            this.amdDependencies = [];
  10115            this.scanner.resetComments();
  10116            this.scanner.setErrorHandler(function (message) {
  10117                return _this.reportParseError(message);
  10118            });
  10119            this.scanner.setSourceText(sourceText, TypeScript.LexMode.File);
  10120            var leftCurlyCount = this.scanner.leftCurlyCount;
  10121            var rightCurlyCount = this.scanner.rightCurlyCount;
  10122            var minChar = this.scanner.pos;
  10123            this.currentToken = this.scanner.scan();
  10124            this.pushDeclLists();
  10125            var bod = new TypeScript.ASTList();
  10126            bod.minChar = minChar;
  10127            this.state = ParseState.StartScript;
  10128            this.parsingDeclareFile = TypeScript.isDSTRFile(filename) || TypeScript.isDTSFile(filename);
  10129            while(true) {
  10130                this.parseStatementList(TypeScript.ErrorRecoverySet.EOF | TypeScript.ErrorRecoverySet.Func, bod, true, false, allowedElements, TypeScript.Modifiers.None);
  10131                if(this.currentToken.tokenId === TypeScript.TokenID.EndOfFile) {
  10132                    break;
  10133                }
  10134                var badToken = TypeScript.tokenTable[this.currentToken.tokenId];
  10135                this.reportParseError("Unexpected statement block terminator '" + badToken.text + "'");
  10136                this.currentToken = this.scanner.scan();
  10137            }
  10138            this.state = ParseState.EndScript;
  10139            bod.limChar = this.scanner.pos;
  10140            var topLevelMod = null;
  10141            if(TypeScript.moduleGenTarget != TypeScript.ModuleGenTarget.Local && this.hasTopLevelImportOrExport) {
  10142                var correctedFileName = TypeScript.switchToForwardSlashes(filename);
  10143                var id = new TypeScript.Identifier(correctedFileName);
  10144                topLevelMod = new TypeScript.ModuleDeclaration(id, bod, this.topVarList(), this.topScopeList(), null);
  10145                topLevelMod.modFlags |= TypeScript.ModuleFlags.IsDynamic;
  10146                topLevelMod.modFlags |= TypeScript.ModuleFlags.IsWholeFile;
  10147                topLevelMod.modFlags |= TypeScript.ModuleFlags.Exported;
  10148                if(this.parsingDeclareFile) {
  10149                    topLevelMod.modFlags |= TypeScript.ModuleFlags.Ambient;
  10150                }
  10151                topLevelMod.minChar = minChar;
  10152                topLevelMod.limChar = this.scanner.pos;
  10153                topLevelMod.prettyName = TypeScript.getPrettyName(correctedFileName);
  10154                topLevelMod.containsUnicodeChar = this.scanner.seenUnicodeChar;
  10155                topLevelMod.containsUnicodeCharInComment = this.scanner.seenUnicodeCharInComment;
  10156                topLevelMod.amdDependencies = this.amdDependencies;
  10157                bod = new TypeScript.ASTList();
  10158                bod.minChar = topLevelMod.minChar;
  10159                bod.limChar = topLevelMod.limChar;
  10160                bod.append(topLevelMod);
  10161            }
  10162            var script = new TypeScript.Script(this.topVarList(), this.topScopeList());
  10163            script.bod = bod;
  10164            this.popDeclLists();
  10165            script.minChar = minChar;
  10166            script.limChar = this.scanner.pos;
  10167            script.locationInfo = new TypeScript.LocationInfo(filename, this.scanner.lineMap, unitIndex);
  10168            script.leftCurlyCount = this.scanner.leftCurlyCount - leftCurlyCount;
  10169            script.rightCurlyCount = this.scanner.rightCurlyCount - rightCurlyCount;
  10170            script.isDeclareFile = this.parsingDeclareFile;
  10171            script.topLevelMod = topLevelMod;
  10172            script.containsUnicodeChar = this.scanner.seenUnicodeChar;
  10173            script.containsUnicodeCharInComment = this.scanner.seenUnicodeCharInComment;
  10174            script.requiresExtendsBlock = this.requiresExtendsBlock;
  10175            return script;
  10176        };
  10177        return Parser;
  10178    })();
  10179    TypeScript.Parser = Parser;    
  10180    function quickParse(logger, scopeStartAST, sourceText, minChar, limChar, errorCapture) {
  10181        var fragment = sourceText.getText(minChar, limChar);
  10182        logger.log("Quick parse range (" + minChar + "," + limChar + "): \"" + TypeScript.stringToLiteral(fragment, 100) + "\"");
  10183        var quickParser = new Parser();
  10184        quickParser.setErrorRecovery(null);
  10185        quickParser.errorCallback = errorCapture;
  10186        var quickClassDecl = new TypeScript.ClassDeclaration(null, null, null, null);
  10187        quickParser.currentClassDecl = quickClassDecl;
  10188        var result = quickParser.quickParse(new TypeScript.StringSourceText(fragment), "", 0);
  10189        return result;
  10190    }
  10191    TypeScript.quickParse = quickParse;
  10192 })(TypeScript || (TypeScript = {}));
  10193 var TypeScript;
  10194 (function (TypeScript) {
  10195    var PrintContext = (function () {
  10196        function PrintContext(outfile, parser) {
  10197            this.outfile = outfile;
  10198            this.parser = parser;
  10199            this.builder = "";
  10200            this.indent1 = "  ";
  10201            this.indentStrings = [];
  10202            this.indentAmt = 0;
  10203        }
  10204        PrintContext.prototype.increaseIndent = function () {
  10205            this.indentAmt++;
  10206        };
  10207        PrintContext.prototype.decreaseIndent = function () {
  10208            this.indentAmt--;
  10209        };
  10210        PrintContext.prototype.startLine = function () {
  10211            if(this.builder.length > 0) {
  10212                TypeScript.CompilerDiagnostics.Alert(this.builder);
  10213            }
  10214            var indentString = this.indentStrings[this.indentAmt];
  10215            if(indentString === undefined) {
  10216                indentString = "";
  10217                for(var i = 0; i < this.indentAmt; i++) {
  10218                    indentString += this.indent1;
  10219                }
  10220                this.indentStrings[this.indentAmt] = indentString;
  10221            }
  10222            this.builder += indentString;
  10223        };
  10224        PrintContext.prototype.write = function (s) {
  10225            this.builder += s;
  10226        };
  10227        PrintContext.prototype.writeLine = function (s) {
  10228            this.builder += s;
  10229            this.outfile.WriteLine(this.builder);
  10230            this.builder = "";
  10231        };
  10232        return PrintContext;
  10233    })();
  10234    TypeScript.PrintContext = PrintContext;    
  10235    function prePrintAST(ast, parent, walker) {
  10236        var pc = walker.state;
  10237        ast.print(pc);
  10238        pc.increaseIndent();
  10239        return ast;
  10240    }
  10241    TypeScript.prePrintAST = prePrintAST;
  10242    function postPrintAST(ast, parent, walker) {
  10243        var pc = walker.state;
  10244        pc.decreaseIndent();
  10245        return ast;
  10246    }
  10247    TypeScript.postPrintAST = postPrintAST;
  10248 })(TypeScript || (TypeScript = {}));
  10249 var TypeScript;
  10250 (function (TypeScript) {
  10251    TypeScript.LexEOF = (-1);
  10252    TypeScript.LexCodeNWL = 10;
  10253    TypeScript.LexCodeRET = 13;
  10254    TypeScript.LexCodeLS = 8232;
  10255    TypeScript.LexCodePS = 8233;
  10256    TypeScript.LexCodeTAB = 9;
  10257    TypeScript.LexCodeVTAB = 11;
  10258    TypeScript.LexCode_e = 'e'.charCodeAt(0);
  10259    TypeScript.LexCode_E = 'E'.charCodeAt(0);
  10260    TypeScript.LexCode_x = 'x'.charCodeAt(0);
  10261    TypeScript.LexCode_X = 'X'.charCodeAt(0);
  10262    TypeScript.LexCode_a = 'a'.charCodeAt(0);
  10263    TypeScript.LexCode_A = 'A'.charCodeAt(0);
  10264    TypeScript.LexCode_f = 'f'.charCodeAt(0);
  10265    TypeScript.LexCode_F = 'F'.charCodeAt(0);
  10266    TypeScript.LexCode_g = 'g'.charCodeAt(0);
  10267    TypeScript.LexCode_m = 'm'.charCodeAt(0);
  10268    TypeScript.LexCode_i = 'i'.charCodeAt(0);
  10269    TypeScript.LexCode_u = 'u'.charCodeAt(0);
  10270    TypeScript.LexCode_0 = '0'.charCodeAt(0);
  10271    TypeScript.LexCode_9 = '9'.charCodeAt(0);
  10272    TypeScript.LexCode_8 = '8'.charCodeAt(0);
  10273    TypeScript.LexCode_7 = '7'.charCodeAt(0);
  10274    TypeScript.LexCodeBSL = '\\'.charCodeAt(0);
  10275    TypeScript.LexCodeSHP = '#'.charCodeAt(0);
  10276    TypeScript.LexCodeBNG = '!'.charCodeAt(0);
  10277    TypeScript.LexCodeQUO = '"'.charCodeAt(0);
  10278    TypeScript.LexCodeAPO = '\''.charCodeAt(0);
  10279    TypeScript.LexCodePCT = '%'.charCodeAt(0);
  10280    TypeScript.LexCodeAMP = '&'.charCodeAt(0);
  10281    TypeScript.LexCodeLPR = '('.charCodeAt(0);
  10282    TypeScript.LexCodeRPR = ')'.charCodeAt(0);
  10283    TypeScript.LexCodePLS = '+'.charCodeAt(0);
  10284    TypeScript.LexCodeMIN = '-'.charCodeAt(0);
  10285    TypeScript.LexCodeMUL = '*'.charCodeAt(0);
  10286    TypeScript.LexCodeSLH = '/'.charCodeAt(0);
  10287    TypeScript.LexCodeXOR = '^'.charCodeAt(0);
  10288    TypeScript.LexCodeCMA = ','.charCodeAt(0);
  10289    TypeScript.LexCodeDOT = '.'.charCodeAt(0);
  10290    TypeScript.LexCodeLT = '<'.charCodeAt(0);
  10291    TypeScript.LexCodeEQ = '='.charCodeAt(0);
  10292    TypeScript.LexCodeGT = '>'.charCodeAt(0);
  10293    TypeScript.LexCodeQUE = '?'.charCodeAt(0);
  10294    TypeScript.LexCodeLBR = '['.charCodeAt(0);
  10295    TypeScript.LexCodeRBR = ']'.charCodeAt(0);
  10296    TypeScript.LexCodeUSC = '_'.charCodeAt(0);
  10297    TypeScript.LexCodeLC = '{'.charCodeAt(0);
  10298    TypeScript.LexCodeRC = '}'.charCodeAt(0);
  10299    TypeScript.LexCodeBAR = '|'.charCodeAt(0);
  10300    TypeScript.LexCodeTIL = '~'.charCodeAt(0);
  10301    TypeScript.LexCodeCOL = ':'.charCodeAt(0);
  10302    TypeScript.LexCodeSMC = ';'.charCodeAt(0);
  10303    TypeScript.LexCodeUnderscore = '_'.charCodeAt(0);
  10304    TypeScript.LexCodeDollar = '$'.charCodeAt(0);
  10305    TypeScript.LexCodeSpace = 32;
  10306    TypeScript.LexCodeAtSign = '@'.charCodeAt(0);
  10307    TypeScript.LexCodeASCIIChars = 128;
  10308    TypeScript.LexKeywordTable = undefined;
  10309    var autoToken = new Array(TypeScript.LexCodeASCIIChars);
  10310    var lexIdStartTable = new Array(TypeScript.LexCodeASCIIChars);
  10311    var unicodeES3IdStart = [
  10312        170, 
  10313        170, 
  10314        181, 
  10315        181, 
  10316        186, 
  10317        186, 
  10318        192, 
  10319        214, 
  10320        216, 
  10321        246, 
  10322        248, 
  10323        543, 
  10324        546, 
  10325        563, 
  10326        592, 
  10327        685, 
  10328        688, 
  10329        696, 
  10330        699, 
  10331        705, 
  10332        720, 
  10333        721, 
  10334        736, 
  10335        740, 
  10336        750, 
  10337        750, 
  10338        890, 
  10339        890, 
  10340        902, 
  10341        902, 
  10342        904, 
  10343        906, 
  10344        908, 
  10345        908, 
  10346        910, 
  10347        929, 
  10348        931, 
  10349        974, 
  10350        976, 
  10351        983, 
  10352        986, 
  10353        1011, 
  10354        1024, 
  10355        1153, 
  10356        1164, 
  10357        1220, 
  10358        1223, 
  10359        1224, 
  10360        1227, 
  10361        1228, 
  10362        1232, 
  10363        1269, 
  10364        1272, 
  10365        1273, 
  10366        1329, 
  10367        1366, 
  10368        1369, 
  10369        1369, 
  10370        1377, 
  10371        1415, 
  10372        1488, 
  10373        1514, 
  10374        1520, 
  10375        1522, 
  10376        1569, 
  10377        1594, 
  10378        1600, 
  10379        1610, 
  10380        1649, 
  10381        1747, 
  10382        1749, 
  10383        1749, 
  10384        1765, 
  10385        1766, 
  10386        1786, 
  10387        1788, 
  10388        1808, 
  10389        1808, 
  10390        1810, 
  10391        1836, 
  10392        1920, 
  10393        1957, 
  10394        2309, 
  10395        2361, 
  10396        2365, 
  10397        2365, 
  10398        2384, 
  10399        2384, 
  10400        2392, 
  10401        2401, 
  10402        2437, 
  10403        2444, 
  10404        2447, 
  10405        2448, 
  10406        2451, 
  10407        2472, 
  10408        2474, 
  10409        2480, 
  10410        2482, 
  10411        2482, 
  10412        2486, 
  10413        2489, 
  10414        2524, 
  10415        2525, 
  10416        2527, 
  10417        2529, 
  10418        2544, 
  10419        2545, 
  10420        2565, 
  10421        2570, 
  10422        2575, 
  10423        2576, 
  10424        2579, 
  10425        2600, 
  10426        2602, 
  10427        2608, 
  10428        2610, 
  10429        2611, 
  10430        2613, 
  10431        2614, 
  10432        2616, 
  10433        2617, 
  10434        2649, 
  10435        2652, 
  10436        2654, 
  10437        2654, 
  10438        2674, 
  10439        2676, 
  10440        2693, 
  10441        2699, 
  10442        2701, 
  10443        2701, 
  10444        2703, 
  10445        2705, 
  10446        2707, 
  10447        2728, 
  10448        2730, 
  10449        2736, 
  10450        2738, 
  10451        2739, 
  10452        2741, 
  10453        2745, 
  10454        2749, 
  10455        2749, 
  10456        2768, 
  10457        2768, 
  10458        2784, 
  10459        2784, 
  10460        2821, 
  10461        2828, 
  10462        2831, 
  10463        2832, 
  10464        2835, 
  10465        2856, 
  10466        2858, 
  10467        2864, 
  10468        2866, 
  10469        2867, 
  10470        2870, 
  10471        2873, 
  10472        2877, 
  10473        2877, 
  10474        2908, 
  10475        2909, 
  10476        2911, 
  10477        2913, 
  10478        2949, 
  10479        2954, 
  10480        2958, 
  10481        2960, 
  10482        2962, 
  10483        2965, 
  10484        2969, 
  10485        2970, 
  10486        2972, 
  10487        2972, 
  10488        2974, 
  10489        2975, 
  10490        2979, 
  10491        2980, 
  10492        2984, 
  10493        2986, 
  10494        2990, 
  10495        2997, 
  10496        2999, 
  10497        3001, 
  10498        3077, 
  10499        3084, 
  10500        3086, 
  10501        3088, 
  10502        3090, 
  10503        3112, 
  10504        3114, 
  10505        3123, 
  10506        3125, 
  10507        3129, 
  10508        3168, 
  10509        3169, 
  10510        3205, 
  10511        3212, 
  10512        3214, 
  10513        3216, 
  10514        3218, 
  10515        3240, 
  10516        3242, 
  10517        3251, 
  10518        3253, 
  10519        3257, 
  10520        3294, 
  10521        3294, 
  10522        3296, 
  10523        3297, 
  10524        3333, 
  10525        3340, 
  10526        3342, 
  10527        3344, 
  10528        3346, 
  10529        3368, 
  10530        3370, 
  10531        3385, 
  10532        3424, 
  10533        3425, 
  10534        3461, 
  10535        3478, 
  10536        3482, 
  10537        3505, 
  10538        3507, 
  10539        3515, 
  10540        3517, 
  10541        3517, 
  10542        3520, 
  10543        3526, 
  10544        3585, 
  10545        3632, 
  10546        3634, 
  10547        3635, 
  10548        3648, 
  10549        3654, 
  10550        3713, 
  10551        3714, 
  10552        3716, 
  10553        3716, 
  10554        3719, 
  10555        3720, 
  10556        3722, 
  10557        3722, 
  10558        3725, 
  10559        3725, 
  10560        3732, 
  10561        3735, 
  10562        3737, 
  10563        3743, 
  10564        3745, 
  10565        3747, 
  10566        3749, 
  10567        3749, 
  10568        3751, 
  10569        3751, 
  10570        3754, 
  10571        3755, 
  10572        3757, 
  10573        3760, 
  10574        3762, 
  10575        3763, 
  10576        3773, 
  10577        3773, 
  10578        3776, 
  10579        3780, 
  10580        3782, 
  10581        3782, 
  10582        3804, 
  10583        3805, 
  10584        3840, 
  10585        3840, 
  10586        3904, 
  10587        3911, 
  10588        3913, 
  10589        3946, 
  10590        3976, 
  10591        3979, 
  10592        4096, 
  10593        4129, 
  10594        4131, 
  10595        4135, 
  10596        4137, 
  10597        4138, 
  10598        4176, 
  10599        4181, 
  10600        4256, 
  10601        4293, 
  10602        4304, 
  10603        4342, 
  10604        4352, 
  10605        4441, 
  10606        4447, 
  10607        4514, 
  10608        4520, 
  10609        4601, 
  10610        4608, 
  10611        4614, 
  10612        4616, 
  10613        4678, 
  10614        4680, 
  10615        4680, 
  10616        4682, 
  10617        4685, 
  10618        4688, 
  10619        4694, 
  10620        4696, 
  10621        4696, 
  10622        4698, 
  10623        4701, 
  10624        4704, 
  10625        4742, 
  10626        4744, 
  10627        4744, 
  10628        4746, 
  10629        4749, 
  10630        4752, 
  10631        4782, 
  10632        4784, 
  10633        4784, 
  10634        4786, 
  10635        4789, 
  10636        4792, 
  10637        4798, 
  10638        4800, 
  10639        4800, 
  10640        4802, 
  10641        4805, 
  10642        4808, 
  10643        4814, 
  10644        4816, 
  10645        4822, 
  10646        4824, 
  10647        4846, 
  10648        4848, 
  10649        4878, 
  10650        4880, 
  10651        4880, 
  10652        4882, 
  10653        4885, 
  10654        4888, 
  10655        4894, 
  10656        4896, 
  10657        4934, 
  10658        4936, 
  10659        4954, 
  10660        5024, 
  10661        5108, 
  10662        5121, 
  10663        5740, 
  10664        5743, 
  10665        5750, 
  10666        5761, 
  10667        5786, 
  10668        5792, 
  10669        5866, 
  10670        6016, 
  10671        6067, 
  10672        6176, 
  10673        6263, 
  10674        6272, 
  10675        6312, 
  10676        7680, 
  10677        7835, 
  10678        7840, 
  10679        7929, 
  10680        7936, 
  10681        7957, 
  10682        7960, 
  10683        7965, 
  10684        7968, 
  10685        8005, 
  10686        8008, 
  10687        8013, 
  10688        8016, 
  10689        8023, 
  10690        8025, 
  10691        8025, 
  10692        8027, 
  10693        8027, 
  10694        8029, 
  10695        8029, 
  10696        8031, 
  10697        8061, 
  10698        8064, 
  10699        8116, 
  10700        8118, 
  10701        8124, 
  10702        8126, 
  10703        8126, 
  10704        8130, 
  10705        8132, 
  10706        8134, 
  10707        8140, 
  10708        8144, 
  10709        8147, 
  10710        8150, 
  10711        8155, 
  10712        8160, 
  10713        8172, 
  10714        8178, 
  10715        8180, 
  10716        8182, 
  10717        8188, 
  10718        8319, 
  10719        8319, 
  10720        8450, 
  10721        8450, 
  10722        8455, 
  10723        8455, 
  10724        8458, 
  10725        8467, 
  10726        8469, 
  10727        8469, 
  10728        8473, 
  10729        8477, 
  10730        8484, 
  10731        8484, 
  10732        8486, 
  10733        8486, 
  10734        8488, 
  10735        8488, 
  10736        8490, 
  10737        8493, 
  10738        8495, 
  10739        8497, 
  10740        8499, 
  10741        8505, 
  10742        8544, 
  10743        8579, 
  10744        12293, 
  10745        12295, 
  10746        12321, 
  10747        12329, 
  10748        12337, 
  10749        12341, 
  10750        12344, 
  10751        12346, 
  10752        12353, 
  10753        12436, 
  10754        12445, 
  10755        12446, 
  10756        12449, 
  10757        12538, 
  10758        12540, 
  10759        12542, 
  10760        12549, 
  10761        12588, 
  10762        12593, 
  10763        12686, 
  10764        12704, 
  10765        12727, 
  10766        13312, 
  10767        13312, 
  10768        19893, 
  10769        19893, 
  10770        19968, 
  10771        19968, 
  10772        40869, 
  10773        40869, 
  10774        40960, 
  10775        42124, 
  10776        44032, 
  10777        44032, 
  10778        55203, 
  10779        55203, 
  10780        63744, 
  10781        64045, 
  10782        64256, 
  10783        64262, 
  10784        64275, 
  10785        64279, 
  10786        64285, 
  10787        64285, 
  10788        64287, 
  10789        64296, 
  10790        64298, 
  10791        64310, 
  10792        64312, 
  10793        64316, 
  10794        64318, 
  10795        64318, 
  10796        64320, 
  10797        64321, 
  10798        64323, 
  10799        64324, 
  10800        64326, 
  10801        64433, 
  10802        64467, 
  10803        64829, 
  10804        64848, 
  10805        64911, 
  10806        64914, 
  10807        64967, 
  10808        65008, 
  10809        65019, 
  10810        65136, 
  10811        65138, 
  10812        65140, 
  10813        65140, 
  10814        65142, 
  10815        65276, 
  10816        65313, 
  10817        65338, 
  10818        65345, 
  10819        65370, 
  10820        65382, 
  10821        65470, 
  10822        65474, 
  10823        65479, 
  10824        65482, 
  10825        65487, 
  10826        65490, 
  10827        65495, 
  10828        65498, 
  10829        65500
  10830    ];
  10831    var unicodeES3IdCont = [
  10832        768, 
  10833        846, 
  10834        864, 
  10835        866, 
  10836        1155, 
  10837        1158, 
  10838        1425, 
  10839        1441, 
  10840        1443, 
  10841        1465, 
  10842        1467, 
  10843        1469, 
  10844        1471, 
  10845        1471, 
  10846        1473, 
  10847        1474, 
  10848        1476, 
  10849        1476, 
  10850        1611, 
  10851        1621, 
  10852        1632, 
  10853        1641, 
  10854        1648, 
  10855        1648, 
  10856        1750, 
  10857        1756, 
  10858        1759, 
  10859        1764, 
  10860        1767, 
  10861        1768, 
  10862        1770, 
  10863        1773, 
  10864        1776, 
  10865        1785, 
  10866        1809, 
  10867        1809, 
  10868        1840, 
  10869        1866, 
  10870        1958, 
  10871        1968, 
  10872        2305, 
  10873        2307, 
  10874        2364, 
  10875        2364, 
  10876        2366, 
  10877        2381, 
  10878        2385, 
  10879        2388, 
  10880        2402, 
  10881        2403, 
  10882        2406, 
  10883        2415, 
  10884        2433, 
  10885        2435, 
  10886        2492, 
  10887        2492, 
  10888        2494, 
  10889        2500, 
  10890        2503, 
  10891        2504, 
  10892        2507, 
  10893        2509, 
  10894        2519, 
  10895        2519, 
  10896        2530, 
  10897        2531, 
  10898        2534, 
  10899        2543, 
  10900        2562, 
  10901        2562, 
  10902        2620, 
  10903        2620, 
  10904        2622, 
  10905        2626, 
  10906        2631, 
  10907        2632, 
  10908        2635, 
  10909        2637, 
  10910        2662, 
  10911        2673, 
  10912        2689, 
  10913        2691, 
  10914        2748, 
  10915        2748, 
  10916        2750, 
  10917        2757, 
  10918        2759, 
  10919        2761, 
  10920        2763, 
  10921        2765, 
  10922        2790, 
  10923        2799, 
  10924        2817, 
  10925        2819, 
  10926        2876, 
  10927        2876, 
  10928        2878, 
  10929        2883, 
  10930        2887, 
  10931        2888, 
  10932        2891, 
  10933        2893, 
  10934        2902, 
  10935        2903, 
  10936        2918, 
  10937        2927, 
  10938        2946, 
  10939        2947, 
  10940        3006, 
  10941        3010, 
  10942        3014, 
  10943        3016, 
  10944        3018, 
  10945        3021, 
  10946        3031, 
  10947        3031, 
  10948        3047, 
  10949        3055, 
  10950        3073, 
  10951        3075, 
  10952        3134, 
  10953        3140, 
  10954        3142, 
  10955        3144, 
  10956        3146, 
  10957        3149, 
  10958        3157, 
  10959        3158, 
  10960        3174, 
  10961        3183, 
  10962        3202, 
  10963        3203, 
  10964        3262, 
  10965        3268, 
  10966        3270, 
  10967        3272, 
  10968        3274, 
  10969        3277, 
  10970        3285, 
  10971        3286, 
  10972        3302, 
  10973        3311, 
  10974        3330, 
  10975        3331, 
  10976        3390, 
  10977        3395, 
  10978        3398, 
  10979        3400, 
  10980        3402, 
  10981        3405, 
  10982        3415, 
  10983        3415, 
  10984        3430, 
  10985        3439, 
  10986        3458, 
  10987        3459, 
  10988        3530, 
  10989        3530, 
  10990        3535, 
  10991        3540, 
  10992        3542, 
  10993        3542, 
  10994        3544, 
  10995        3551, 
  10996        3570, 
  10997        3571, 
  10998        3633, 
  10999        3633, 
  11000        3636, 
  11001        3642, 
  11002        3655, 
  11003        3662, 
  11004        3664, 
  11005        3673, 
  11006        3761, 
  11007        3761, 
  11008        3764, 
  11009        3769, 
  11010        3771, 
  11011        3772, 
  11012        3784, 
  11013        3789, 
  11014        3792, 
  11015        3801, 
  11016        3864, 
  11017        3865, 
  11018        3872, 
  11019        3881, 
  11020        3893, 
  11021        3893, 
  11022        3895, 
  11023        3895, 
  11024        3897, 
  11025        3897, 
  11026        3902, 
  11027        3903, 
  11028        3953, 
  11029        3972, 
  11030        3974, 
  11031        3975, 
  11032        3984, 
  11033        3991, 
  11034        3993, 
  11035        4028, 
  11036        4038, 
  11037        4038, 
  11038        4140, 
  11039        4146, 
  11040        4150, 
  11041        4153, 
  11042        4160, 
  11043        4169, 
  11044        4182, 
  11045        4185, 
  11046        4969, 
  11047        4977, 
  11048        6068, 
  11049        6099, 
  11050        6112, 
  11051        6121, 
  11052        6160, 
  11053        6169, 
  11054        6313, 
  11055        6313, 
  11056        8255, 
  11057        8256, 
  11058        8400, 
  11059        8412, 
  11060        8417, 
  11061        8417, 
  11062        12330, 
  11063        12335, 
  11064        12441, 
  11065        12442, 
  11066        12539, 
  11067        12539, 
  11068        64286, 
  11069        64286, 
  11070        65056, 
  11071        65059, 
  11072        65075, 
  11073        65076, 
  11074        65101, 
  11075        65103, 
  11076        65296, 
  11077        65305, 
  11078        65343, 
  11079        65343, 
  11080        65381, 
  11081        65381
  11082    ];
  11083    var unicodeES5IdStart = [
  11084        170, 
  11085        170, 
  11086        181, 
  11087        181, 
  11088        186, 
  11089        186, 
  11090        192, 
  11091        214, 
  11092        216, 
  11093        246, 
  11094        248, 
  11095        705, 
  11096        710, 
  11097        721, 
  11098        736, 
  11099        740, 
  11100        748, 
  11101        748, 
  11102        750, 
  11103        750, 
  11104        880, 
  11105        884, 
  11106        886, 
  11107        887, 
  11108        890, 
  11109        893, 
  11110        902, 
  11111        902, 
  11112        904, 
  11113        906, 
  11114        908, 
  11115        908, 
  11116        910, 
  11117        929, 
  11118        931, 
  11119        1013, 
  11120        1015, 
  11121        1153, 
  11122        1162, 
  11123        1319, 
  11124        1329, 
  11125        1366, 
  11126        1369, 
  11127        1369, 
  11128        1377, 
  11129        1415, 
  11130        1488, 
  11131        1514, 
  11132        1520, 
  11133        1522, 
  11134        1568, 
  11135        1610, 
  11136        1646, 
  11137        1647, 
  11138        1649, 
  11139        1747, 
  11140        1749, 
  11141        1749, 
  11142        1765, 
  11143        1766, 
  11144        1774, 
  11145        1775, 
  11146        1786, 
  11147        1788, 
  11148        1791, 
  11149        1791, 
  11150        1808, 
  11151        1808, 
  11152        1810, 
  11153        1839, 
  11154        1869, 
  11155        1957, 
  11156        1969, 
  11157        1969, 
  11158        1994, 
  11159        2026, 
  11160        2036, 
  11161        2037, 
  11162        2042, 
  11163        2042, 
  11164        2048, 
  11165        2069, 
  11166        2074, 
  11167        2074, 
  11168        2084, 
  11169        2084, 
  11170        2088, 
  11171        2088, 
  11172        2112, 
  11173        2136, 
  11174        2208, 
  11175        2208, 
  11176        2210, 
  11177        2220, 
  11178        2308, 
  11179        2361, 
  11180        2365, 
  11181        2365, 
  11182        2384, 
  11183        2384, 
  11184        2392, 
  11185        2401, 
  11186        2417, 
  11187        2423, 
  11188        2425, 
  11189        2431, 
  11190        2437, 
  11191        2444, 
  11192        2447, 
  11193        2448, 
  11194        2451, 
  11195        2472, 
  11196        2474, 
  11197        2480, 
  11198        2482, 
  11199        2482, 
  11200        2486, 
  11201        2489, 
  11202        2493, 
  11203        2493, 
  11204        2510, 
  11205        2510, 
  11206        2524, 
  11207        2525, 
  11208        2527, 
  11209        2529, 
  11210        2544, 
  11211        2545, 
  11212        2565, 
  11213        2570, 
  11214        2575, 
  11215        2576, 
  11216        2579, 
  11217        2600, 
  11218        2602, 
  11219        2608, 
  11220        2610, 
  11221        2611, 
  11222        2613, 
  11223        2614, 
  11224        2616, 
  11225        2617, 
  11226        2649, 
  11227        2652, 
  11228        2654, 
  11229        2654, 
  11230        2674, 
  11231        2676, 
  11232        2693, 
  11233        2701, 
  11234        2703, 
  11235        2705, 
  11236        2707, 
  11237        2728, 
  11238        2730, 
  11239        2736, 
  11240        2738, 
  11241        2739, 
  11242        2741, 
  11243        2745, 
  11244        2749, 
  11245        2749, 
  11246        2768, 
  11247        2768, 
  11248        2784, 
  11249        2785, 
  11250        2821, 
  11251        2828, 
  11252        2831, 
  11253        2832, 
  11254        2835, 
  11255        2856, 
  11256        2858, 
  11257        2864, 
  11258        2866, 
  11259        2867, 
  11260        2869, 
  11261        2873, 
  11262        2877, 
  11263        2877, 
  11264        2908, 
  11265        2909, 
  11266        2911, 
  11267        2913, 
  11268        2929, 
  11269        2929, 
  11270        2947, 
  11271        2947, 
  11272        2949, 
  11273        2954, 
  11274        2958, 
  11275        2960, 
  11276        2962, 
  11277        2965, 
  11278        2969, 
  11279        2970, 
  11280        2972, 
  11281        2972, 
  11282        2974, 
  11283        2975, 
  11284        2979, 
  11285        2980, 
  11286        2984, 
  11287        2986, 
  11288        2990, 
  11289        3001, 
  11290        3024, 
  11291        3024, 
  11292        3077, 
  11293        3084, 
  11294        3086, 
  11295        3088, 
  11296        3090, 
  11297        3112, 
  11298        3114, 
  11299        3123, 
  11300        3125, 
  11301        3129, 
  11302        3133, 
  11303        3133, 
  11304        3160, 
  11305        3161, 
  11306        3168, 
  11307        3169, 
  11308        3205, 
  11309        3212, 
  11310        3214, 
  11311        3216, 
  11312        3218, 
  11313        3240, 
  11314        3242, 
  11315        3251, 
  11316        3253, 
  11317        3257, 
  11318        3261, 
  11319        3261, 
  11320        3294, 
  11321        3294, 
  11322        3296, 
  11323        3297, 
  11324        3313, 
  11325        3314, 
  11326        3333, 
  11327        3340, 
  11328        3342, 
  11329        3344, 
  11330        3346, 
  11331        3386, 
  11332        3389, 
  11333        3389, 
  11334        3406, 
  11335        3406, 
  11336        3424, 
  11337        3425, 
  11338        3450, 
  11339        3455, 
  11340        3461, 
  11341        3478, 
  11342        3482, 
  11343        3505, 
  11344        3507, 
  11345        3515, 
  11346        3517, 
  11347        3517, 
  11348        3520, 
  11349        3526, 
  11350        3585, 
  11351        3632, 
  11352        3634, 
  11353        3635, 
  11354        3648, 
  11355        3654, 
  11356        3713, 
  11357        3714, 
  11358        3716, 
  11359        3716, 
  11360        3719, 
  11361        3720, 
  11362        3722, 
  11363        3722, 
  11364        3725, 
  11365        3725, 
  11366        3732, 
  11367        3735, 
  11368        3737, 
  11369        3743, 
  11370        3745, 
  11371        3747, 
  11372        3749, 
  11373        3749, 
  11374        3751, 
  11375        3751, 
  11376        3754, 
  11377        3755, 
  11378        3757, 
  11379        3760, 
  11380        3762, 
  11381        3763, 
  11382        3773, 
  11383        3773, 
  11384        3776, 
  11385        3780, 
  11386        3782, 
  11387        3782, 
  11388        3804, 
  11389        3807, 
  11390        3840, 
  11391        3840, 
  11392        3904, 
  11393        3911, 
  11394        3913, 
  11395        3948, 
  11396        3976, 
  11397        3980, 
  11398        4096, 
  11399        4138, 
  11400        4159, 
  11401        4159, 
  11402        4176, 
  11403        4181, 
  11404        4186, 
  11405        4189, 
  11406        4193, 
  11407        4193, 
  11408        4197, 
  11409        4198, 
  11410        4206, 
  11411        4208, 
  11412        4213, 
  11413        4225, 
  11414        4238, 
  11415        4238, 
  11416        4256, 
  11417        4293, 
  11418        4295, 
  11419        4295, 
  11420        4301, 
  11421        4301, 
  11422        4304, 
  11423        4346, 
  11424        4348, 
  11425        4680, 
  11426        4682, 
  11427        4685, 
  11428        4688, 
  11429        4694, 
  11430        4696, 
  11431        4696, 
  11432        4698, 
  11433        4701, 
  11434        4704, 
  11435        4744, 
  11436        4746, 
  11437        4749, 
  11438        4752, 
  11439        4784, 
  11440        4786, 
  11441        4789, 
  11442        4792, 
  11443        4798, 
  11444        4800, 
  11445        4800, 
  11446        4802, 
  11447        4805, 
  11448        4808, 
  11449        4822, 
  11450        4824, 
  11451        4880, 
  11452        4882, 
  11453        4885, 
  11454        4888, 
  11455        4954, 
  11456        4992, 
  11457        5007, 
  11458        5024, 
  11459        5108, 
  11460        5121, 
  11461        5740, 
  11462        5743, 
  11463        5759, 
  11464        5761, 
  11465        5786, 
  11466        5792, 
  11467        5866, 
  11468        5870, 
  11469        5872, 
  11470        5888, 
  11471        5900, 
  11472        5902, 
  11473        5905, 
  11474        5920, 
  11475        5937, 
  11476        5952, 
  11477        5969, 
  11478        5984, 
  11479        5996, 
  11480        5998, 
  11481        6000, 
  11482        6016, 
  11483        6067, 
  11484        6103, 
  11485        6103, 
  11486        6108, 
  11487        6108, 
  11488        6176, 
  11489        6263, 
  11490        6272, 
  11491        6312, 
  11492        6314, 
  11493        6314, 
  11494        6320, 
  11495        6389, 
  11496        6400, 
  11497        6428, 
  11498        6480, 
  11499        6509, 
  11500        6512, 
  11501        6516, 
  11502        6528, 
  11503        6571, 
  11504        6593, 
  11505        6599, 
  11506        6656, 
  11507        6678, 
  11508        6688, 
  11509        6740, 
  11510        6823, 
  11511        6823, 
  11512        6917, 
  11513        6963, 
  11514        6981, 
  11515        6987, 
  11516        7043, 
  11517        7072, 
  11518        7086, 
  11519        7087, 
  11520        7098, 
  11521        7141, 
  11522        7168, 
  11523        7203, 
  11524        7245, 
  11525        7247, 
  11526        7258, 
  11527        7293, 
  11528        7401, 
  11529        7404, 
  11530        7406, 
  11531        7409, 
  11532        7413, 
  11533        7414, 
  11534        7424, 
  11535        7615, 
  11536        7680, 
  11537        7957, 
  11538        7960, 
  11539        7965, 
  11540        7968, 
  11541        8005, 
  11542        8008, 
  11543        8013, 
  11544        8016, 
  11545        8023, 
  11546        8025, 
  11547        8025, 
  11548        8027, 
  11549        8027, 
  11550        8029, 
  11551        8029, 
  11552        8031, 
  11553        8061, 
  11554        8064, 
  11555        8116, 
  11556        8118, 
  11557        8124, 
  11558        8126, 
  11559        8126, 
  11560        8130, 
  11561        8132, 
  11562        8134, 
  11563        8140, 
  11564        8144, 
  11565        8147, 
  11566        8150, 
  11567        8155, 
  11568        8160, 
  11569        8172, 
  11570        8178, 
  11571        8180, 
  11572        8182, 
  11573        8188, 
  11574        8305, 
  11575        8305, 
  11576        8319, 
  11577        8319, 
  11578        8336, 
  11579        8348, 
  11580        8450, 
  11581        8450, 
  11582        8455, 
  11583        8455, 
  11584        8458, 
  11585        8467, 
  11586        8469, 
  11587        8469, 
  11588        8473, 
  11589        8477, 
  11590        8484, 
  11591        8484, 
  11592        8486, 
  11593        8486, 
  11594        8488, 
  11595        8488, 
  11596        8490, 
  11597        8493, 
  11598        8495, 
  11599        8505, 
  11600        8508, 
  11601        8511, 
  11602        8517, 
  11603        8521, 
  11604        8526, 
  11605        8526, 
  11606        8544, 
  11607        8584, 
  11608        11264, 
  11609        11310, 
  11610        11312, 
  11611        11358, 
  11612        11360, 
  11613        11492, 
  11614        11499, 
  11615        11502, 
  11616        11506, 
  11617        11507, 
  11618        11520, 
  11619        11557, 
  11620        11559, 
  11621        11559, 
  11622        11565, 
  11623        11565, 
  11624        11568, 
  11625        11623, 
  11626        11631, 
  11627        11631, 
  11628        11648, 
  11629        11670, 
  11630        11680, 
  11631        11686, 
  11632        11688, 
  11633        11694, 
  11634        11696, 
  11635        11702, 
  11636        11704, 
  11637        11710, 
  11638        11712, 
  11639        11718, 
  11640        11720, 
  11641        11726, 
  11642        11728, 
  11643        11734, 
  11644        11736, 
  11645        11742, 
  11646        11823, 
  11647        11823, 
  11648        12293, 
  11649        12295, 
  11650        12321, 
  11651        12329, 
  11652        12337, 
  11653        12341, 
  11654        12344, 
  11655        12348, 
  11656        12353, 
  11657        12438, 
  11658        12445, 
  11659        12447, 
  11660        12449, 
  11661        12538, 
  11662        12540, 
  11663        12543, 
  11664        12549, 
  11665        12589, 
  11666        12593, 
  11667        12686, 
  11668        12704, 
  11669        12730, 
  11670        12784, 
  11671        12799, 
  11672        13312, 
  11673        13312, 
  11674        19893, 
  11675        19893, 
  11676        19968, 
  11677        19968, 
  11678        40908, 
  11679        40908, 
  11680        40960, 
  11681        42124, 
  11682        42192, 
  11683        42237, 
  11684        42240, 
  11685        42508, 
  11686        42512, 
  11687        42527, 
  11688        42538, 
  11689        42539, 
  11690        42560, 
  11691        42606, 
  11692        42623, 
  11693        42647, 
  11694        42656, 
  11695        42735, 
  11696        42775, 
  11697        42783, 
  11698        42786, 
  11699        42888, 
  11700        42891, 
  11701        42894, 
  11702        42896, 
  11703        42899, 
  11704        42912, 
  11705        42922, 
  11706        43000, 
  11707        43009, 
  11708        43011, 
  11709        43013, 
  11710        43015, 
  11711        43018, 
  11712        43020, 
  11713        43042, 
  11714        43072, 
  11715        43123, 
  11716        43138, 
  11717        43187, 
  11718        43250, 
  11719        43255, 
  11720        43259, 
  11721        43259, 
  11722        43274, 
  11723        43301, 
  11724        43312, 
  11725        43334, 
  11726        43360, 
  11727        43388, 
  11728        43396, 
  11729        43442, 
  11730        43471, 
  11731        43471, 
  11732        43520, 
  11733        43560, 
  11734        43584, 
  11735        43586, 
  11736        43588, 
  11737        43595, 
  11738        43616, 
  11739        43638, 
  11740        43642, 
  11741        43642, 
  11742        43648, 
  11743        43695, 
  11744        43697, 
  11745        43697, 
  11746        43701, 
  11747        43702, 
  11748        43705, 
  11749        43709, 
  11750        43712, 
  11751        43712, 
  11752        43714, 
  11753        43714, 
  11754        43739, 
  11755        43741, 
  11756        43744, 
  11757        43754, 
  11758        43762, 
  11759        43764, 
  11760        43777, 
  11761        43782, 
  11762        43785, 
  11763        43790, 
  11764        43793, 
  11765        43798, 
  11766        43808, 
  11767        43814, 
  11768        43816, 
  11769        43822, 
  11770        43968, 
  11771        44002, 
  11772        44032, 
  11773        44032, 
  11774        55203, 
  11775        55203, 
  11776        55216, 
  11777        55238, 
  11778        55243, 
  11779        55291, 
  11780        63744, 
  11781        64109, 
  11782        64112, 
  11783        64217, 
  11784        64256, 
  11785        64262, 
  11786        64275, 
  11787        64279, 
  11788        64285, 
  11789        64285, 
  11790        64287, 
  11791        64296, 
  11792        64298, 
  11793        64310, 
  11794        64312, 
  11795        64316, 
  11796        64318, 
  11797        64318, 
  11798        64320, 
  11799        64321, 
  11800        64323, 
  11801        64324, 
  11802        64326, 
  11803        64433, 
  11804        64467, 
  11805        64829, 
  11806        64848, 
  11807        64911, 
  11808        64914, 
  11809        64967, 
  11810        65008, 
  11811        65019, 
  11812        65136, 
  11813        65140, 
  11814        65142, 
  11815        65276, 
  11816        65313, 
  11817        65338, 
  11818        65345, 
  11819        65370, 
  11820        65382, 
  11821        65470, 
  11822        65474, 
  11823        65479, 
  11824        65482, 
  11825        65487, 
  11826        65490, 
  11827        65495, 
  11828        65498, 
  11829        65500
  11830    ];
  11831    var unicodeES5IdCont = [
  11832        768, 
  11833        879, 
  11834        1155, 
  11835        1159, 
  11836        1425, 
  11837        1469, 
  11838        1471, 
  11839        1471, 
  11840        1473, 
  11841        1474, 
  11842        1476, 
  11843        1477, 
  11844        1479, 
  11845        1479, 
  11846        1552, 
  11847        1562, 
  11848        1611, 
  11849        1641, 
  11850        1648, 
  11851        1648, 
  11852        1750, 
  11853        1756, 
  11854        1759, 
  11855        1764, 
  11856        1767, 
  11857        1768, 
  11858        1770, 
  11859        1773, 
  11860        1776, 
  11861        1785, 
  11862        1809, 
  11863        1809, 
  11864        1840, 
  11865        1866, 
  11866        1958, 
  11867        1968, 
  11868        1984, 
  11869        1993, 
  11870        2027, 
  11871        2035, 
  11872        2070, 
  11873        2073, 
  11874        2075, 
  11875        2083, 
  11876        2085, 
  11877        2087, 
  11878        2089, 
  11879        2093, 
  11880        2137, 
  11881        2139, 
  11882        2276, 
  11883        2302, 
  11884        2304, 
  11885        2307, 
  11886        2362, 
  11887        2364, 
  11888        2366, 
  11889        2383, 
  11890        2385, 
  11891        2391, 
  11892        2402, 
  11893        2403, 
  11894        2406, 
  11895        2415, 
  11896        2433, 
  11897        2435, 
  11898        2492, 
  11899        2492, 
  11900        2494, 
  11901        2500, 
  11902        2503, 
  11903        2504, 
  11904        2507, 
  11905        2509, 
  11906        2519, 
  11907        2519, 
  11908        2530, 
  11909        2531, 
  11910        2534, 
  11911        2543, 
  11912        2561, 
  11913        2563, 
  11914        2620, 
  11915        2620, 
  11916        2622, 
  11917        2626, 
  11918        2631, 
  11919        2632, 
  11920        2635, 
  11921        2637, 
  11922        2641, 
  11923        2641, 
  11924        2662, 
  11925        2673, 
  11926        2677, 
  11927        2677, 
  11928        2689, 
  11929        2691, 
  11930        2748, 
  11931        2748, 
  11932        2750, 
  11933        2757, 
  11934        2759, 
  11935        2761, 
  11936        2763, 
  11937        2765, 
  11938        2786, 
  11939        2787, 
  11940        2790, 
  11941        2799, 
  11942        2817, 
  11943        2819, 
  11944        2876, 
  11945        2876, 
  11946        2878, 
  11947        2884, 
  11948        2887, 
  11949        2888, 
  11950        2891, 
  11951        2893, 
  11952        2902, 
  11953        2903, 
  11954        2914, 
  11955        2915, 
  11956        2918, 
  11957        2927, 
  11958        2946, 
  11959        2946, 
  11960        3006, 
  11961        3010, 
  11962        3014, 
  11963        3016, 
  11964        3018, 
  11965        3021, 
  11966        3031, 
  11967        3031, 
  11968        3046, 
  11969        3055, 
  11970        3073, 
  11971        3075, 
  11972        3134, 
  11973        3140, 
  11974        3142, 
  11975        3144, 
  11976        3146, 
  11977        3149, 
  11978        3157, 
  11979        3158, 
  11980        3170, 
  11981        3171, 
  11982        3174, 
  11983        3183, 
  11984        3202, 
  11985        3203, 
  11986        3260, 
  11987        3260, 
  11988        3262, 
  11989        3268, 
  11990        3270, 
  11991        3272, 
  11992        3274, 
  11993        3277, 
  11994        3285, 
  11995        3286, 
  11996        3298, 
  11997        3299, 
  11998        3302, 
  11999        3311, 
  12000        3330, 
  12001        3331, 
  12002        3390, 
  12003        3396, 
  12004        3398, 
  12005        3400, 
  12006        3402, 
  12007        3405, 
  12008        3415, 
  12009        3415, 
  12010        3426, 
  12011        3427, 
  12012        3430, 
  12013        3439, 
  12014        3458, 
  12015        3459, 
  12016        3530, 
  12017        3530, 
  12018        3535, 
  12019        3540, 
  12020        3542, 
  12021        3542, 
  12022        3544, 
  12023        3551, 
  12024        3570, 
  12025        3571, 
  12026        3633, 
  12027        3633, 
  12028        3636, 
  12029        3642, 
  12030        3655, 
  12031        3662, 
  12032        3664, 
  12033        3673, 
  12034        3761, 
  12035        3761, 
  12036        3764, 
  12037        3769, 
  12038        3771, 
  12039        3772, 
  12040        3784, 
  12041        3789, 
  12042        3792, 
  12043        3801, 
  12044        3864, 
  12045        3865, 
  12046        3872, 
  12047        3881, 
  12048        3893, 
  12049        3893, 
  12050        3895, 
  12051        3895, 
  12052        3897, 
  12053        3897, 
  12054        3902, 
  12055        3903, 
  12056        3953, 
  12057        3972, 
  12058        3974, 
  12059        3975, 
  12060        3981, 
  12061        3991, 
  12062        3993, 
  12063        4028, 
  12064        4038, 
  12065        4038, 
  12066        4139, 
  12067        4158, 
  12068        4160, 
  12069        4169, 
  12070        4182, 
  12071        4185, 
  12072        4190, 
  12073        4192, 
  12074        4194, 
  12075        4196, 
  12076        4199, 
  12077        4205, 
  12078        4209, 
  12079        4212, 
  12080        4226, 
  12081        4237, 
  12082        4239, 
  12083        4253, 
  12084        4957, 
  12085        4959, 
  12086        5906, 
  12087        5908, 
  12088        5938, 
  12089        5940, 
  12090        5970, 
  12091        5971, 
  12092        6002, 
  12093        6003, 
  12094        6068, 
  12095        6099, 
  12096        6109, 
  12097        6109, 
  12098        6112, 
  12099        6121, 
  12100        6155, 
  12101        6157, 
  12102        6160, 
  12103        6169, 
  12104        6313, 
  12105        6313, 
  12106        6432, 
  12107        6443, 
  12108        6448, 
  12109        6459, 
  12110        6470, 
  12111        6479, 
  12112        6576, 
  12113        6592, 
  12114        6600, 
  12115        6601, 
  12116        6608, 
  12117        6617, 
  12118        6679, 
  12119        6683, 
  12120        6741, 
  12121        6750, 
  12122        6752, 
  12123        6780, 
  12124        6783, 
  12125        6793, 
  12126        6800, 
  12127        6809, 
  12128        6912, 
  12129        6916, 
  12130        6964, 
  12131        6980, 
  12132        6992, 
  12133        7001, 
  12134        7019, 
  12135        7027, 
  12136        7040, 
  12137        7042, 
  12138        7073, 
  12139        7085, 
  12140        7088, 
  12141        7097, 
  12142        7142, 
  12143        7155, 
  12144        7204, 
  12145        7223, 
  12146        7232, 
  12147        7241, 
  12148        7248, 
  12149        7257, 
  12150        7376, 
  12151        7378, 
  12152        7380, 
  12153        7400, 
  12154        7405, 
  12155        7405, 
  12156        7410, 
  12157        7412, 
  12158        7616, 
  12159        7654, 
  12160        7676, 
  12161        7679, 
  12162        8204, 
  12163        8205, 
  12164        8255, 
  12165        8256, 
  12166        8276, 
  12167        8276, 
  12168        8400, 
  12169        8412, 
  12170        8417, 
  12171        8417, 
  12172        8421, 
  12173        8432, 
  12174        11503, 
  12175        11505, 
  12176        11647, 
  12177        11647, 
  12178        11744, 
  12179        11775, 
  12180        12330, 
  12181        12335, 
  12182        12441, 
  12183        12442, 
  12184        42528, 
  12185        42537, 
  12186        42607, 
  12187        42607, 
  12188        42612, 
  12189        42621, 
  12190        42655, 
  12191        42655, 
  12192        42736, 
  12193        42737, 
  12194        43010, 
  12195        43010, 
  12196        43014, 
  12197        43014, 
  12198        43019, 
  12199        43019, 
  12200        43043, 
  12201        43047, 
  12202        43136, 
  12203        43137, 
  12204        43188, 
  12205        43204, 
  12206        43216, 
  12207        43225, 
  12208        43232, 
  12209        43249, 
  12210        43264, 
  12211        43273, 
  12212        43302, 
  12213        43309, 
  12214        43335, 
  12215        43347, 
  12216        43392, 
  12217        43395, 
  12218        43443, 
  12219        43456, 
  12220        43472, 
  12221        43481, 
  12222        43561, 
  12223        43574, 
  12224        43587, 
  12225        43587, 
  12226        43596, 
  12227        43597, 
  12228        43600, 
  12229        43609, 
  12230        43643, 
  12231        43643, 
  12232        43696, 
  12233        43696, 
  12234        43698, 
  12235        43700, 
  12236        43703, 
  12237        43704, 
  12238        43710, 
  12239        43711, 
  12240        43713, 
  12241        43713, 
  12242        43755, 
  12243        43759, 
  12244        43765, 
  12245        43766, 
  12246        44003, 
  12247        44010, 
  12248        44012, 
  12249        44013, 
  12250        44016, 
  12251        44025, 
  12252        64286, 
  12253        64286, 
  12254        65024, 
  12255        65039, 
  12256        65056, 
  12257        65062, 
  12258        65075, 
  12259        65076, 
  12260        65101, 
  12261        65103, 
  12262        65296, 
  12263        65305, 
  12264        65343, 
  12265        65343
  12266    ];
  12267    function LexLookUpUnicodeMap(code, map) {
  12268        var lo = 0;
  12269        var hi = map.length;
  12270        var mid;
  12271        while(lo + 1 < hi) {
  12272            mid = lo + (hi - lo) / 2;
  12273            mid -= mid % 2;
  12274            if(map[mid] <= code && code <= map[mid + 1]) {
  12275                return true;
  12276            }
  12277            if(code < map[mid]) {
  12278                hi = mid;
  12279            } else {
  12280                lo = mid + 2;
  12281            }
  12282        }
  12283        return false;
  12284    }
  12285    TypeScript.LexLookUpUnicodeMap = LexLookUpUnicodeMap;
  12286    function LexIsUnicodeDigit(code) {
  12287        if(TypeScript.codeGenTarget == TypeScript.CodeGenTarget.ES3) {
  12288            return LexLookUpUnicodeMap(code, unicodeES3IdCont);
  12289        } else {
  12290            return LexLookUpUnicodeMap(code, unicodeES5IdCont);
  12291        }
  12292    }
  12293    TypeScript.LexIsUnicodeDigit = LexIsUnicodeDigit;
  12294    function LexIsUnicodeIdStart(code) {
  12295        if(TypeScript.codeGenTarget == TypeScript.CodeGenTarget.ES3) {
  12296            return LexLookUpUnicodeMap(code, unicodeES3IdStart);
  12297        } else {
  12298            return LexLookUpUnicodeMap(code, unicodeES5IdStart);
  12299        }
  12300    }
  12301    TypeScript.LexIsUnicodeIdStart = LexIsUnicodeIdStart;
  12302    function LexInitialize() {
  12303        TypeScript.initializeStaticTokens();
  12304        autoToken[TypeScript.LexCodeLPR] = TypeScript.staticTokens[TypeScript.TokenID.OpenParen];
  12305        autoToken[TypeScript.LexCodeRPR] = TypeScript.staticTokens[TypeScript.TokenID.CloseParen];
  12306        autoToken[TypeScript.LexCodeCMA] = TypeScript.staticTokens[TypeScript.TokenID.Comma];
  12307        autoToken[TypeScript.LexCodeSMC] = TypeScript.staticTokens[TypeScript.TokenID.Semicolon];
  12308        autoToken[TypeScript.LexCodeLBR] = TypeScript.staticTokens[TypeScript.TokenID.OpenBracket];
  12309        autoToken[TypeScript.LexCodeRBR] = TypeScript.staticTokens[TypeScript.TokenID.CloseBracket];
  12310        autoToken[TypeScript.LexCodeTIL] = TypeScript.staticTokens[TypeScript.TokenID.Tilde];
  12311        autoToken[TypeScript.LexCodeQUE] = TypeScript.staticTokens[TypeScript.TokenID.Question];
  12312        autoToken[TypeScript.LexCodeLC] = TypeScript.staticTokens[TypeScript.TokenID.OpenBrace];
  12313        autoToken[TypeScript.LexCodeRC] = TypeScript.staticTokens[TypeScript.TokenID.CloseBrace];
  12314        autoToken[TypeScript.LexCodeCOL] = TypeScript.staticTokens[TypeScript.TokenID.Colon];
  12315        TypeScript.LexKeywordTable = new TypeScript.StringHashTable();
  12316        for(var i in (TypeScript.TokenID)._map) {
  12317            if((i) <= TypeScript.TokenID.LimKeyword) {
  12318                TypeScript.LexKeywordTable.add((TypeScript.TokenID)._map[i].toLowerCase(), i);
  12319            }
  12320        }
  12321        for(var j = 0; j < TypeScript.LexCodeASCIIChars; j++) {
  12322            if(LexIsIdentifierStartChar(j)) {
  12323                lexIdStartTable[j] = true;
  12324            } else {
  12325                lexIdStartTable[j] = false;
  12326            }
  12327        }
  12328    }
  12329    TypeScript.LexInitialize = LexInitialize;
  12330    function LexAdjustIndent(code, indentAmt) {
  12331        if((code == TypeScript.LexCodeLBR) || (code == TypeScript.LexCodeLC) || (code == TypeScript.LexCodeLPR)) {
  12332            return indentAmt + 1;
  12333        } else {
  12334            if((code == TypeScript.LexCodeRBR) || (code == TypeScript.LexCodeRC) || (code == TypeScript.LexCodeRPR)) {
  12335                return indentAmt - 1;
  12336            } else {
  12337                return indentAmt;
  12338            }
  12339        }
  12340    }
  12341    TypeScript.LexAdjustIndent = LexAdjustIndent;
  12342    function LexIsIdentifierStartChar(code) {
  12343        return (((code >= 97) && (code <= 122)) || ((code >= 65) && (code <= 90)) || (code == TypeScript.LexCodeDollar) || (code == TypeScript.LexCodeUnderscore));
  12344    }
  12345    TypeScript.LexIsIdentifierStartChar = LexIsIdentifierStartChar;
  12346    function LexIsDigit(code) {
  12347        return ((code >= 48) && (code <= 57));
  12348    }
  12349    TypeScript.LexIsDigit = LexIsDigit;
  12350    function LexIsIdentifierChar(code) {
  12351        return lexIdStartTable[code] || LexIsDigit(code);
  12352    }
  12353    TypeScript.LexIsIdentifierChar = LexIsIdentifierChar;
  12354    function LexMatchingOpen(code) {
  12355        if(code == TypeScript.LexCodeRBR) {
  12356            return TypeScript.LexCodeLBR;
  12357        } else {
  12358            if(code == TypeScript.LexCodeRC) {
  12359                return TypeScript.LexCodeLC;
  12360            } else {
  12361                if(code == TypeScript.LexCodeRPR) {
  12362                    return TypeScript.LexCodeLPR;
  12363                } else {
  12364                    return 0;
  12365                }
  12366            }
  12367        }
  12368    }
  12369    TypeScript.LexMatchingOpen = LexMatchingOpen;
  12370    (function (NumberScanState) {
  12371        NumberScanState._map = [];
  12372        NumberScanState._map[0] = "Start";
  12373        NumberScanState.Start = 0;
  12374        NumberScanState._map[1] = "InFraction";
  12375        NumberScanState.InFraction = 1;
  12376        NumberScanState._map[2] = "InEmptyFraction";
  12377        NumberScanState.InEmptyFraction = 2;
  12378        NumberScanState._map[3] = "InExponent";
  12379        NumberScanState.InExponent = 3;
  12380    })(TypeScript.NumberScanState || (TypeScript.NumberScanState = {}));
  12381    var NumberScanState = TypeScript.NumberScanState;
  12382    (function (LexState) {
  12383        LexState._map = [];
  12384        LexState._map[0] = "Start";
  12385        LexState.Start = 0;
  12386        LexState._map[1] = "InMultilineComment";
  12387        LexState.InMultilineComment = 1;
  12388        LexState._map[2] = "InMultilineSingleQuoteString";
  12389        LexState.InMultilineSingleQuoteString = 2;
  12390        LexState._map[3] = "InMultilineDoubleQuoteString";
  12391        LexState.InMultilineDoubleQuoteString = 3;
  12392    })(TypeScript.LexState || (TypeScript.LexState = {}));
  12393    var LexState = TypeScript.LexState;
  12394    (function (LexMode) {
  12395        LexMode._map = [];
  12396        LexMode._map[0] = "Line";
  12397        LexMode.Line = 0;
  12398        LexMode._map[1] = "File";
  12399        LexMode.File = 1;
  12400    })(TypeScript.LexMode || (TypeScript.LexMode = {}));
  12401    var LexMode = TypeScript.LexMode;
  12402    (function (CommentStyle) {
  12403        CommentStyle._map = [];
  12404        CommentStyle._map[0] = "Line";
  12405        CommentStyle.Line = 0;
  12406        CommentStyle._map[1] = "Block";
  12407        CommentStyle.Block = 1;
  12408    })(TypeScript.CommentStyle || (TypeScript.CommentStyle = {}));
  12409    var CommentStyle = TypeScript.CommentStyle;
  12410    var StringSourceText = (function () {
  12411        function StringSourceText(text) {
  12412            this.text = text;
  12413        }
  12414        StringSourceText.prototype.getText = function (start, end) {
  12415            return this.text.substring(start, end);
  12416        };
  12417        StringSourceText.prototype.getLength = function () {
  12418            return this.text.length;
  12419        };
  12420        return StringSourceText;
  12421    })();
  12422    TypeScript.StringSourceText = StringSourceText;    
  12423    var SourceTextSegment = (function () {
  12424        function SourceTextSegment(segmentStart, segmentEnd, segment) {
  12425            this.segmentStart = segmentStart;
  12426            this.segmentEnd = segmentEnd;
  12427            this.segment = segment;
  12428        }
  12429        SourceTextSegment.prototype.charCodeAt = function (index) {
  12430            return this.segment.charCodeAt(index - this.segmentStart);
  12431        };
  12432        SourceTextSegment.prototype.substring = function (start, end) {
  12433            return this.segment.substring(start - this.segmentStart, end - this.segmentStart);
  12434        };
  12435        return SourceTextSegment;
  12436    })();
  12437    TypeScript.SourceTextSegment = SourceTextSegment;    
  12438    var AggerateSourceTextSegment = (function () {
  12439        function AggerateSourceTextSegment(seg1, seg2) {
  12440            this.seg1 = seg1;
  12441            this.seg2 = seg2;
  12442        }
  12443        AggerateSourceTextSegment.prototype.charCodeAt = function (index) {
  12444            if(this.seg1.segmentStart <= index && index < this.seg1.segmentEnd) {
  12445                return this.seg1.segment.charCodeAt(index - this.seg1.segmentStart);
  12446            }
  12447            return this.seg2.segment.charCodeAt(index - this.seg2.segmentStart);
  12448        };
  12449        AggerateSourceTextSegment.prototype.substring = function (start, end) {
  12450            if(this.seg1.segmentStart <= start && end <= this.seg1.segmentEnd) {
  12451                return this.seg1.segment.substring(start - this.seg1.segmentStart, end - this.seg1.segmentStart);
  12452            }
  12453            return this.seg2.segment.substring(start - this.seg2.segmentStart) + this.seg1.segment.substring(0, end - this.seg1.segmentStart);
  12454        };
  12455        return AggerateSourceTextSegment;
  12456    })();
  12457    TypeScript.AggerateSourceTextSegment = AggerateSourceTextSegment;    
  12458    var ScannerTextStream = (function () {
  12459        function ScannerTextStream(sourceText) {
  12460            this.sourceText = sourceText;
  12461            this.agg = new AggerateSourceTextSegment(ScannerTextStream.emptySegment, ScannerTextStream.emptySegment);
  12462            this.len = this.sourceText.getLength();
  12463        }
  12464        ScannerTextStream.emptySegment = new SourceTextSegment(0, 0, "");
  12465        ScannerTextStream.prototype.max = function (a, b) {
  12466            return a >= b ? a : b;
  12467        };
  12468        ScannerTextStream.prototype.min = function (a, b) {
  12469            return a <= b ? a : b;
  12470        };
  12471        ScannerTextStream.prototype.fetchSegment = function (start, end) {
  12472            if(this.agg.seg1.segmentStart <= start && end <= this.agg.seg1.segmentEnd) {
  12473                return this.agg.seg1;
  12474            }
  12475            if(this.agg.seg2.segmentStart <= start && end <= this.agg.seg1.segmentEnd) {
  12476                return this.agg;
  12477            }
  12478            var prev = this.agg.seg1;
  12479            var s = prev.segmentEnd;
  12480            var e = TypeScript.max(s + 512, end);
  12481            e = TypeScript.min(e, this.len);
  12482            var src = this.sourceText.getText(s, e);
  12483            var newSeg = new SourceTextSegment(s, e, src);
  12484            this.agg.seg2 = prev;
  12485            this.agg.seg1 = newSeg;
  12486            return this.agg;
  12487        };
  12488        ScannerTextStream.prototype.charCodeAt = function (index) {
  12489            return this.fetchSegment(index, index + 1).charCodeAt(index);
  12490        };
  12491        ScannerTextStream.prototype.substring = function (start, end) {
  12492            return this.fetchSegment(start, end).substring(start, end);
  12493        };
  12494        return ScannerTextStream;
  12495    })();
  12496    TypeScript.ScannerTextStream = ScannerTextStream;    
  12497    var SavedTokens = (function () {
  12498        function SavedTokens() {
  12499            this.prevToken = null;
  12500            this.curSavedToken = null;
  12501            this.prevSavedToken = null;
  12502            this.prevToken = null;
  12503            this.currentToken = 0;
  12504            this.tokens = new Array();
  12505            this.seenUnicodeChar = false;
  12506            this.seenUnicodeCharInComment = false;
  12507            this.prevLine = 1;
  12508            this.line = 1;
  12509            this.col = 0;
  12510            this.lexState = LexState.Start;
  12511            this.commentStack = new Array();
  12512            this.lineMap = [];
  12513        }
  12514        SavedTokens.prototype.previousToken = function () {
  12515            return this.prevToken;
  12516        };
  12517        SavedTokens.prototype.close = function () {
  12518            this.currentToken = 0;
  12519        };
  12520        SavedTokens.prototype.addToken = function (tok, scanner) {
  12521            this.tokens[this.currentToken++] = new TypeScript.SavedToken(tok, scanner.startPos, scanner.pos);
  12522        };
  12523        SavedTokens.prototype.scan = function () {
  12524            this.startLine = this.line;
  12525            this.startPos = this.col;
  12526            if(this.currentTokenIndex == this.currentTokens.length) {
  12527                if(this.line < this.lineMap.length) {
  12528                    this.line++;
  12529                    this.col = 0;
  12530                    this.currentTokenIndex = 0;
  12531                    this.currentTokens = this.tokensByLine[this.line];
  12532                } else {
  12533                    return TypeScript.staticTokens[TypeScript.TokenID.EndOfFile];
  12534                }
  12535            }
  12536            if(this.currentTokenIndex < this.currentTokens.length) {
  12537                this.prevToken = this.curSavedToken.tok;
  12538                this.prevSavedToken = this.curSavedToken;
  12539                this.curSavedToken = this.currentTokens[this.currentTokenIndex++];
  12540                var curToken = this.curSavedToken.tok;
  12541                this.pos = this.curSavedToken.limChar;
  12542                this.col += (this.curSavedToken.limChar - this.curSavedToken.minChar);
  12543                this.startPos = this.curSavedToken.minChar;
  12544                this.prevLine = this.line;
  12545                return curToken;
  12546            } else {
  12547                return TypeScript.staticTokens[TypeScript.TokenID.EndOfFile];
  12548            }
  12549        };
  12550        SavedTokens.prototype.syncToTok = function (offset) {
  12551            this.line = getLineNumberFromPosition(this.lineMap, offset);
  12552            this.currentTokenIndex = 0;
  12553            var tmpCol = offset - this.lineMap[this.line];
  12554            while((this.lexStateByLine[this.line] == LexState.InMultilineComment) && (this.line > 0)) {
  12555                this.line--;
  12556                tmpCol = 0;
  12557            }
  12558            var lenMin1 = this.lineMap.length - 1;
  12559            this.currentTokens = this.tokensByLine[this.line];
  12560            while((this.currentTokens.length == 0) && (this.line < lenMin1)) {
  12561                this.line++;
  12562                this.currentTokens = this.tokensByLine[this.line];
  12563                tmpCol = 0;
  12564            }
  12565            if(this.line <= lenMin1) {
  12566                while((this.currentTokenIndex < this.currentTokens.length) && (tmpCol > this.currentTokens[this.currentTokenIndex].limChar)) {
  12567                    this.currentTokenIndex++;
  12568                }
  12569                if(this.currentTokenIndex < this.currentTokens.length) {
  12570                    this.col = this.currentTokens[this.currentTokenIndex].minChar;
  12571                    return this.col + this.lineMap[this.line];
  12572                }
  12573            }
  12574            return -1;
  12575        };
  12576        SavedTokens.prototype.lastTokenLimChar = function () {
  12577            if(this.prevSavedToken !== null) {
  12578                return this.prevSavedToken.limChar;
  12579            } else {
  12580                return 0;
  12581            }
  12582        };
  12583        SavedTokens.prototype.lastTokenHadNewline = function () {
  12584            return this.prevLine != this.startLine;
  12585        };
  12586        SavedTokens.prototype.pushComment = function (comment) {
  12587            this.commentStack.push(comment);
  12588        };
  12589        SavedTokens.prototype.getComments = function () {
  12590            var stack = this.commentStack;
  12591            this.commentStack = [];
  12592            return stack;
  12593        };
  12594        SavedTokens.prototype.getCommentsForLine = function (line) {
  12595            var comments = null;
  12596            while((this.commentStack.length > 0) && (this.commentStack[0].line == line)) {
  12597                if(comments == null) {
  12598                    comments = [
  12599                        this.commentStack.shift()
  12600                    ];
  12601                } else {
  12602                    comments = comments.concat([
  12603                        this.commentStack.shift()
  12604                    ]);
  12605                }
  12606            }
  12607            return comments;
  12608        };
  12609        SavedTokens.prototype.resetComments = function () {
  12610            this.commentStack = [];
  12611        };
  12612        SavedTokens.prototype.setSourceText = function (newSrc, textMode) {
  12613        };
  12614        SavedTokens.prototype.setErrorHandler = function (reportError) {
  12615        };
  12616        SavedTokens.prototype.getLookAheadToken = function () {
  12617            throw new Error("Invalid operation.");
  12618        };
  12619        return SavedTokens;
  12620    })();
  12621    TypeScript.SavedTokens = SavedTokens;    
  12622    var Scanner = (function () {
  12623        function Scanner() {
  12624            this.prevLine = 1;
  12625            this.line = 1;
  12626            this.col = 0;
  12627            this.pos = 0;
  12628            this.startPos = 0;
  12629            this.len = 0;
  12630            this.lineMap = [];
  12631            this.ch = TypeScript.LexEOF;
  12632            this.lexState = LexState.Start;
  12633            this.mode = LexMode.File;
  12634            this.scanComments = true;
  12635            this.interveningWhitespace = false;
  12636            this.interveningWhitespacePos = 0;
  12637            this.leftCurlyCount = 0;
  12638            this.rightCurlyCount = 0;
  12639            this.commentStack = new Array();
  12640            this.saveScan = null;
  12641            this.seenUnicodeChar = false;
  12642            this.seenUnicodeCharInComment = false;
  12643            this.prevTok = TypeScript.staticTokens[TypeScript.TokenID.EndOfFile];
  12644            this.startCol = this.col;
  12645            this.startLine = this.line;
  12646            this.lineMap[1] = 0;
  12647            if(!TypeScript.LexKeywordTable) {
  12648                LexInitialize();
  12649            }
  12650        }
  12651        Scanner.prototype.previousToken = function () {
  12652            return this.prevTok;
  12653        };
  12654        Scanner.prototype.setSourceText = function (newSrc, textMode) {
  12655            this.mode = textMode;
  12656            this.scanComments = (this.mode === LexMode.Line);
  12657            this.pos = 0;
  12658            this.interveningWhitespacePos = 0;
  12659            this.startPos = 0;
  12660            this.line = 1;
  12661            this.col = 0;
  12662            this.startCol = this.col;
  12663            this.startLine = this.line;
  12664            this.len = 0;
  12665            this.src = newSrc.getText(0, newSrc.getLength());
  12666            this.len = this.src.length;
  12667            this.lineMap = [];
  12668            this.lineMap[1] = 0;
  12669            this.commentStack = [];
  12670            this.leftCurlyCount = 0;
  12671            this.rightCurlyCount = 0;
  12672            this.seenUnicodeChar = false;
  12673            this.seenUnicodeCharInComment = false;
  12674        };
  12675        Scanner.prototype.setErrorHandler = function (reportError) {
  12676            this.reportError = reportError;
  12677        };
  12678        Scanner.prototype.setSaveScan = function (savedTokens) {
  12679            this.saveScan = savedTokens;
  12680        };
  12681        Scanner.prototype.setText = function (newSrc, textMode) {
  12682            this.setSourceText(new StringSourceText(newSrc), textMode);
  12683        };
  12684        Scanner.prototype.setScanComments = function (value) {
  12685            this.scanComments = value;
  12686        };
  12687        Scanner.prototype.getLexState = function () {
  12688            return this.lexState;
  12689        };
  12690        Scanner.prototype.tokenStart = function () {
  12691            this.startPos = this.pos;
  12692            this.startLine = this.line;
  12693            this.startCol = this.col;
  12694            this.interveningWhitespace = false;
  12695        };
  12696        Scanner.prototype.peekChar = function () {
  12697            if(this.pos < this.len) {
  12698                return this.src.charCodeAt(this.pos);
  12699            } else {
  12700                return TypeScript.LexEOF;
  12701            }
  12702        };
  12703        Scanner.prototype.peekCharAt = function (index) {
  12704            if(index < this.len) {
  12705                return this.src.charCodeAt(index);
  12706            } else {
  12707                return TypeScript.LexEOF;
  12708            }
  12709        };
  12710        Scanner.prototype.IsHexDigit = function (c) {
  12711            return ((c >= TypeScript.LexCode_0) && (c <= TypeScript.LexCode_9)) || ((c >= TypeScript.LexCode_A) && (c <= TypeScript.LexCode_F)) || ((c >= TypeScript.LexCode_a) && (c <= TypeScript.LexCode_f));
  12712        };
  12713        Scanner.prototype.IsOctalDigit = function (c) {
  12714            return ((c >= TypeScript.LexCode_0) && (c <= TypeScript.LexCode_7)) || ((c >= TypeScript.LexCode_a) && (c <= TypeScript.LexCode_f));
  12715        };
  12716        Scanner.prototype.scanHexDigits = function () {
  12717            var atLeastOneDigit = false;
  12718            for(; ; ) {
  12719                if(this.IsHexDigit(this.ch)) {
  12720                    this.nextChar();
  12721                    atLeastOneDigit = true;
  12722                } else {
  12723                    if(atLeastOneDigit) {
  12724                        return new TypeScript.NumberLiteralToken(parseInt(this.src.substring(this.startPos, this.pos)));
  12725                    } else {
  12726                        return null;
  12727                    }
  12728                }
  12729            }
  12730        };
  12731        Scanner.prototype.scanOctalDigits = function () {
  12732            var atLeastOneDigit = false;
  12733            for(; ; ) {
  12734                if(this.IsOctalDigit(this.ch)) {
  12735                    this.nextChar();
  12736                    atLeastOneDigit = true;
  12737                } else {
  12738                    if(atLeastOneDigit) {
  12739                        return new TypeScript.NumberLiteralToken(parseInt(this.src.substring(this.startPos, this.pos)));
  12740                    } else {
  12741                        return null;
  12742                    }
  12743                }
  12744            }
  12745        };
  12746        Scanner.prototype.scanDecimalNumber = function (state) {
  12747            var atLeastOneDigit = false;
  12748            var svPos = this.pos;
  12749            var svCol = this.col;
  12750            for(; ; ) {
  12751                if(LexIsDigit(this.ch)) {
  12752                    atLeastOneDigit = true;
  12753                    if(this.ch != TypeScript.LexCode_0 && state == NumberScanState.InEmptyFraction) {
  12754                        state = NumberScanState.InFraction;
  12755                    }
  12756                    this.nextChar();
  12757                } else {
  12758                    if(this.ch == TypeScript.LexCodeDOT) {
  12759                        if(state == NumberScanState.Start) {
  12760                            this.nextChar();
  12761                            state = NumberScanState.InEmptyFraction;
  12762                        } else {
  12763                            if(atLeastOneDigit) {
  12764                                return new TypeScript.NumberLiteralToken(parseFloat(this.src.substring(this.startPos, this.pos)), state == NumberScanState.InEmptyFraction);
  12765                            } else {
  12766                                this.pos = svPos;
  12767                                this.col = svCol;
  12768                                return null;
  12769                            }
  12770                        }
  12771                    } else {
  12772                        if((this.ch == TypeScript.LexCode_e) || (this.ch == TypeScript.LexCode_E)) {
  12773                            if(state == NumberScanState.Start) {
  12774                                if(atLeastOneDigit) {
  12775                                    atLeastOneDigit = false;
  12776                                    this.nextChar();
  12777                                    state = NumberScanState.InExponent;
  12778                                } else {
  12779                                    this.pos = svPos;
  12780                                    this.col = svCol;
  12781                                    return null;
  12782                                }
  12783                            } else {
  12784                                if(state == NumberScanState.InFraction || state == NumberScanState.InEmptyFraction) {
  12785                                    this.nextChar();
  12786                                    state = NumberScanState.InExponent;
  12787                                    atLeastOneDigit = false;
  12788                                } else {
  12789                                    if(atLeastOneDigit) {
  12790                                        return new TypeScript.NumberLiteralToken(parseFloat(this.src.substring(this.startPos, this.pos)));
  12791                                    } else {
  12792                                        this.pos = svPos;
  12793                                        this.col = svCol;
  12794                                        return null;
  12795                                    }
  12796                                }
  12797                            }
  12798                        } else {
  12799                            if((this.ch == TypeScript.LexCodePLS) || (this.ch == TypeScript.LexCodeMIN)) {
  12800                                if(state == NumberScanState.InExponent) {
  12801                                    if(!atLeastOneDigit) {
  12802                                        this.nextChar();
  12803                                    } else {
  12804                                        this.pos = svPos;
  12805                                        this.col = svCol;
  12806                                        return null;
  12807                                    }
  12808                                } else {
  12809                                    if(state == NumberScanState.InEmptyFraction || state == NumberScanState.InFraction) {
  12810                                        return new TypeScript.NumberLiteralToken(parseFloat(this.src.substring(this.startPos, this.pos)), state == NumberScanState.InEmptyFraction);
  12811                                    } else {
  12812                                        if(!atLeastOneDigit) {
  12813                                            this.pos = svPos;
  12814                                            this.col = svCol;
  12815                                            return null;
  12816                                        } else {
  12817                                            return new TypeScript.NumberLiteralToken(parseFloat(this.src.substring(this.startPos, this.pos)));
  12818                                        }
  12819                                    }
  12820                                }
  12821                            } else {
  12822                                if(!atLeastOneDigit) {
  12823                                    this.pos = svPos;
  12824                                    this.col = svCol;
  12825                                    return null;
  12826                                } else {
  12827                                    return new TypeScript.NumberLiteralToken(parseFloat(this.src.substring(this.startPos, this.pos)), state == NumberScanState.InEmptyFraction);
  12828                                }
  12829                            }
  12830                        }
  12831                    }
  12832                }
  12833            }
  12834        };
  12835        Scanner.prototype.scanNumber = function () {
  12836            if(this.peekChar() == TypeScript.LexCode_0) {
  12837                switch(this.peekCharAt(this.pos + 1)) {
  12838                    case TypeScript.LexCode_x:
  12839                    case TypeScript.LexCode_X: {
  12840                        this.advanceChar(2);
  12841                        return this.scanHexDigits();
  12842 
  12843                    }
  12844                    case TypeScript.LexCode_8:
  12845                    case TypeScript.LexCode_9:
  12846                    case TypeScript.LexCodeDOT: {
  12847                        return this.scanDecimalNumber(NumberScanState.Start);
  12848 
  12849                    }
  12850                    default: {
  12851                        return this.scanOctalDigits();
  12852 
  12853                    }
  12854                }
  12855            } else {
  12856                return this.scanDecimalNumber(NumberScanState.Start);
  12857            }
  12858        };
  12859        Scanner.prototype.scanFraction = function () {
  12860            return this.scanDecimalNumber(NumberScanState.InFraction);
  12861        };
  12862        Scanner.prototype.newLine = function () {
  12863            this.col = 0;
  12864            if(this.mode == LexMode.File) {
  12865                this.line++;
  12866                this.lineMap[this.line] = this.pos + 1;
  12867            }
  12868        };
  12869        Scanner.prototype.finishMultilineComment = function () {
  12870            var ch2;
  12871            this.lexState = LexState.InMultilineComment;
  12872            while(this.pos < this.len) {
  12873                if(this.ch == TypeScript.LexCodeMUL) {
  12874                    ch2 = this.peekCharAt(this.pos + 1);
  12875                    if(ch2 == TypeScript.LexCodeSLH) {
  12876                        this.advanceChar(2);
  12877                        if(this.mode == LexMode.File) {
  12878                            this.tokenStart();
  12879                        }
  12880                        this.lexState = LexState.Start;
  12881                        return true;
  12882                    }
  12883                } else {
  12884                    if(this.ch == TypeScript.LexCodeNWL) {
  12885                        this.newLine();
  12886                        if(this.mode == LexMode.Line) {
  12887                            this.nextChar();
  12888                            return false;
  12889                        }
  12890                    } else {
  12891                        if(this.ch >= TypeScript.LexCodeASCIIChars) {
  12892                            this.seenUnicodeCharInComment = true;
  12893                        }
  12894                    }
  12895                }
  12896                this.nextChar();
  12897            }
  12898            return false;
  12899        };
  12900        Scanner.prototype.pushComment = function (comment) {
  12901            this.commentStack.push(comment);
  12902        };
  12903        Scanner.prototype.getComments = function () {
  12904            var stack = this.commentStack;
  12905            this.commentStack = [];
  12906            return stack;
  12907        };
  12908        Scanner.prototype.getCommentsForLine = function (line) {
  12909            var comments = null;
  12910            while((this.commentStack.length > 0) && (this.commentStack[0].line == line)) {
  12911                if(comments == null) {
  12912                    comments = [
  12913                        this.commentStack.shift()
  12914                    ];
  12915                } else {
  12916                    comments = comments.concat([
  12917                        this.commentStack.shift()
  12918                    ]);
  12919                }
  12920            }
  12921            return comments;
  12922        };
  12923        Scanner.prototype.resetComments = function () {
  12924            this.commentStack = [];
  12925        };
  12926        Scanner.prototype.endsLine = function (c) {
  12927            return (c == TypeScript.LexCodeNWL) || (c == TypeScript.LexCodeRET) || (c == TypeScript.LexCodeLS) || (c == TypeScript.LexCodePS);
  12928        };
  12929        Scanner.prototype.finishSinglelineComment = function () {
  12930            while(this.pos < this.len) {
  12931                if(this.endsLine(this.ch)) {
  12932                    break;
  12933                }
  12934                if(this.ch >= TypeScript.LexCodeASCIIChars) {
  12935                    this.seenUnicodeCharInComment = true;
  12936                }
  12937                this.nextChar();
  12938            }
  12939            if(this.mode == LexMode.File) {
  12940                this.tokenStart();
  12941            }
  12942        };
  12943        Scanner.prototype.tokenText = function () {
  12944            return this.src.substring(this.startPos, this.pos);
  12945        };
  12946        Scanner.prototype.findClosingSLH = function () {
  12947            var index = this.pos;
  12948            var ch2 = this.src.charCodeAt(index);
  12949            var prevCh = 0;
  12950            var liveEsc = false;
  12951            while(!this.endsLine(ch2) && (index < this.len)) {
  12952                if((ch2 == TypeScript.LexCodeSLH) && (!liveEsc)) {
  12953                    return index;
  12954                }
  12955                prevCh = ch2;
  12956                index++;
  12957                if(liveEsc) {
  12958                    liveEsc = false;
  12959                } else {
  12960                    liveEsc = (prevCh == TypeScript.LexCodeBSL);
  12961                }
  12962                ch2 = this.src.charCodeAt(index);
  12963            }
  12964            return -1;
  12965        };
  12966        Scanner.prototype.speculateRegex = function () {
  12967            if(TypeScript.noRegexTable[this.prevTok.tokenId] != undefined) {
  12968                return null;
  12969            }
  12970            var svPos = this.pos;
  12971            var svCol = this.col;
  12972            var index = this.findClosingSLH();
  12973            if(index > 0) {
  12974                var pattern = this.src.substring(svPos, index);
  12975                var flags = "";
  12976                this.pos = index + 1;
  12977                this.ch = this.peekChar();
  12978                var flagsStart = this.pos;
  12979                while((this.ch == TypeScript.LexCode_i) || (this.ch == TypeScript.LexCode_g) || (this.ch == TypeScript.LexCode_m)) {
  12980                    this.nextChar();
  12981                }
  12982                if((this.pos - flagsStart) > 3) {
  12983                    return null;
  12984                } else {
  12985                    flags = this.src.substring(flagsStart, this.pos);
  12986                }
  12987                var regex = undefined;
  12988                try  {
  12989                    regex = new RegExp(pattern, flags);
  12990                } catch (regexException) {
  12991                }
  12992                if(regex) {
  12993                    this.col = svCol + (this.pos - this.startPos);
  12994                    return new TypeScript.RegularExpressionLiteralToken(regex);
  12995                }
  12996            }
  12997            this.pos = svPos;
  12998            this.col = svCol;
  12999            return null;
  13000        };
  13001        Scanner.prototype.lastTokenHadNewline = function () {
  13002            return this.prevLine != this.startLine;
  13003        };
  13004        Scanner.prototype.lastTokenLimChar = function () {
  13005            return this.interveningWhitespace ? this.interveningWhitespacePos : this.startPos;
  13006        };
  13007        Scanner.prototype.advanceChar = function (amt) {
  13008            this.pos += amt;
  13009            this.col += amt;
  13010            this.ch = this.peekChar();
  13011        };
  13012        Scanner.prototype.nextChar = function () {
  13013            this.pos++;
  13014            this.col++;
  13015            this.ch = this.peekChar();
  13016        };
  13017        Scanner.prototype.getLookAheadToken = function () {
  13018            var prevLine = this.prevLine;
  13019            var line = this.line;
  13020            var col = this.col;
  13021            var pos = this.pos;
  13022            var startPos = this.startPos;
  13023            var startCol = this.startCol;
  13024            var startLine = this.startLine;
  13025            var ch = this.ch;
  13026            var prevTok = this.prevTok;
  13027            var lexState = this.lexState;
  13028            var interveningWhitespace = this.interveningWhitespace;
  13029            var interveningWhitespacePos = this.interveningWhitespacePos;
  13030            var leftCurlyCount = this.leftCurlyCount;
  13031            var rightCurlyCount = this.rightCurlyCount;
  13032            var seenUnicodeChar = this.seenUnicodeChar;
  13033            var seenUnicodeCharInComment = this.seenUnicodeCharInComment;
  13034            var commentStackLength = this.commentStack.length;
  13035            var lookAheadToken = this.scan();
  13036            this.prevLine = prevLine;
  13037            this.line = line;
  13038            this.col = col;
  13039            this.pos = pos;
  13040            this.startPos = startPos;
  13041            this.startCol = startCol;
  13042            this.startLine = startLine;
  13043            this.ch = ch;
  13044            this.prevTok = prevTok;
  13045            this.lexState = lexState;
  13046            this.interveningWhitespace = interveningWhitespace;
  13047            this.interveningWhitespacePos = interveningWhitespacePos;
  13048            this.leftCurlyCount = leftCurlyCount;
  13049            this.rightCurlyCount = rightCurlyCount;
  13050            this.seenUnicodeChar = seenUnicodeChar;
  13051            this.seenUnicodeCharInComment = seenUnicodeCharInComment;
  13052            this.commentStack.length = commentStackLength;
  13053            return lookAheadToken;
  13054        };
  13055        Scanner.prototype.scanInLine = function () {
  13056            if((this.lexState == LexState.InMultilineComment) && (this.scanComments)) {
  13057                this.ch = this.peekChar();
  13058                var commentLine = this.line;
  13059                this.finishMultilineComment();
  13060                if(this.startPos < this.pos) {
  13061                    var commentText = this.src.substring(this.startPos, this.pos);
  13062                    this.tokenStart();
  13063                    return new TypeScript.CommentToken(TypeScript.TokenID.Comment, commentText, true, this.startPos, commentLine, true);
  13064                } else {
  13065                    return TypeScript.staticTokens[TypeScript.TokenID.EndOfFile];
  13066                }
  13067            } else {
  13068                if(this.lexState == LexState.InMultilineSingleQuoteString && this.pos < this.len) {
  13069                    this.ch = TypeScript.LexCodeAPO;
  13070                    this.lexState = LexState.Start;
  13071                    return this.scanStringConstant();
  13072                } else {
  13073                    if(this.lexState == LexState.InMultilineDoubleQuoteString && this.pos < this.len) {
  13074                        this.ch = TypeScript.LexCodeQUO;
  13075                        this.lexState = LexState.Start;
  13076                        return this.scanStringConstant();
  13077                    }
  13078                }
  13079            }
  13080            this.prevLine = this.line;
  13081            var prevTok = this.innerScan();
  13082            if(prevTok.tokenId != TypeScript.TokenID.Whitespace) {
  13083                this.prevTok = prevTok;
  13084            }
  13085            return prevTok;
  13086        };
  13087        Scanner.prototype.scan = function () {
  13088            this.prevLine = this.line;
  13089            this.prevTok = this.innerScan();
  13090            if(this.saveScan) {
  13091                this.saveScan.addToken(this.prevTok, this);
  13092            }
  13093            return this.prevTok;
  13094        };
  13095        Scanner.prototype.isValidUnicodeIdentifierChar = function () {
  13096            var valid = LexIsUnicodeIdStart(this.ch) || LexIsUnicodeDigit(this.ch);
  13097            this.seenUnicodeChar = this.seenUnicodeChar || valid;
  13098            return valid;
  13099        };
  13100        Scanner.prototype.scanStringConstant = function () {
  13101            var endCode = this.ch;
  13102            this.nextChar();
  13103            scanStringConstantLoop:
  13104 for(; ; ) {
  13105                switch(this.ch) {
  13106                    case TypeScript.LexEOF: {
  13107                        this.reportScannerError("Unterminated string constant");
  13108                        break scanStringConstantLoop;
  13109 
  13110                    }
  13111                    case TypeScript.LexCodeLS:
  13112                    case TypeScript.LexCodePS: {
  13113                        this.seenUnicodeChar = true;
  13114 
  13115                    }
  13116                    case TypeScript.LexCodeRET:
  13117                    case TypeScript.LexCodeNWL: {
  13118                        this.reportScannerError("Unterminated string constant");
  13119                        break scanStringConstantLoop;
  13120 
  13121                    }
  13122                    case TypeScript.LexCodeAPO:
  13123                    case TypeScript.LexCodeQUO: {
  13124                        if(this.ch == endCode) {
  13125                            this.nextChar();
  13126                            break scanStringConstantLoop;
  13127                        }
  13128                        break;
  13129 
  13130                    }
  13131                    case TypeScript.LexCodeBSL: {
  13132                        this.nextChar();
  13133                        switch(this.ch) {
  13134                            case TypeScript.LexCodeAPO:
  13135                            case TypeScript.LexCodeQUO:
  13136                            case TypeScript.LexCodeBSL: {
  13137                                this.nextChar();
  13138                                continue scanStringConstantLoop;
  13139 
  13140                            }
  13141                            case TypeScript.LexCodeLS:
  13142                            case TypeScript.LexCodePS: {
  13143                                this.seenUnicodeChar = true;
  13144 
  13145                            }
  13146                            case TypeScript.LexCodeRET:
  13147                            case TypeScript.LexCodeNWL: {
  13148                                if(this.ch == TypeScript.LexCodeRET && this.peekCharAt(this.pos + 1) == TypeScript.LexCodeNWL) {
  13149                                    this.nextChar();
  13150                                }
  13151                                this.nextChar();
  13152                                this.newLine();
  13153                                if(this.mode == LexMode.Line) {
  13154                                    this.lexState = endCode == TypeScript.LexCodeAPO ? LexState.InMultilineSingleQuoteString : LexState.InMultilineDoubleQuoteString;
  13155                                    break scanStringConstantLoop;
  13156                                }
  13157                                break;
  13158 
  13159                            }
  13160                            case TypeScript.LexCode_x:
  13161                            case TypeScript.LexCode_u: {
  13162                                var expectedHexDigits = this.ch == TypeScript.LexCode_x ? 2 : 4;
  13163                                this.nextChar();
  13164                                for(var i = 0; i < expectedHexDigits; i++) {
  13165                                    if(this.IsHexDigit(this.ch)) {
  13166                                        this.nextChar();
  13167                                    } else {
  13168                                        this.reportScannerError("Invalid Unicode escape sequence");
  13169                                        break;
  13170                                    }
  13171                                }
  13172                                continue scanStringConstantLoop;
  13173 
  13174                            }
  13175                        }
  13176                        break;
  13177 
  13178                    }
  13179                }
  13180                if(this.ch >= TypeScript.LexCodeASCIIChars) {
  13181                    this.seenUnicodeChar = true;
  13182                }
  13183                this.nextChar();
  13184            }
  13185            return new TypeScript.StringLiteralToken(this.src.substring(this.startPos, this.pos));
  13186        };
  13187        Scanner.prototype.scanIdentifier = function () {
  13188            var hasEscape = false;
  13189            var isFirstChar = (this.ch == TypeScript.LexCodeBSL);
  13190            var hasUnicode = false;
  13191            for(; ; ) {
  13192                while(lexIdStartTable[this.ch] || LexIsDigit(this.ch) || (this.ch >= TypeScript.LexCodeASCIIChars && this.isValidUnicodeIdentifierChar())) {
  13193                    this.nextChar();
  13194                }
  13195                if(this.ch == TypeScript.LexCodeBSL) {
  13196                    this.nextChar();
  13197                    if(this.ch == TypeScript.LexCode_u) {
  13198                        this.nextChar();
  13199                        for(var h = 0; h < 4; h++) {
  13200                            if(this.IsHexDigit(this.ch)) {
  13201                                this.nextChar();
  13202                            } else {
  13203                                this.reportScannerError("Invalid Unicode escape sequence");
  13204                                return TypeScript.staticTokens[TypeScript.TokenID.Error];
  13205                            }
  13206                        }
  13207                        var hexChar = parseInt(this.src.substring(this.pos - 4, this.pos), 16);
  13208                        if(lexIdStartTable[hexChar] || (!isFirstChar && LexIsDigit(hexChar)) || (hexChar >= TypeScript.LexCodeASCIIChars && (LexIsUnicodeIdStart(hexChar) || (!isFirstChar && LexIsUnicodeDigit(hexChar))))) {
  13209                        } else {
  13210                            this.reportScannerError("Invalid identifier character");
  13211                            return TypeScript.staticTokens[TypeScript.TokenID.Error];
  13212                        }
  13213                        hasEscape = true;
  13214                        isFirstChar = false;
  13215                        continue;
  13216                    }
  13217                    this.reportScannerError("Invalid Unicode escape sequence");
  13218                    return TypeScript.staticTokens[TypeScript.TokenID.Error];
  13219                }
  13220                break;
  13221            }
  13222            var id;
  13223            var text = this.src.substring(this.startPos, this.pos);
  13224            if(!hasEscape && (id = TypeScript.LexKeywordTable.lookup(text)) != null) {
  13225                return TypeScript.staticTokens[id];
  13226            } else {
  13227                return new TypeScript.IdentifierToken(text, hasEscape);
  13228            }
  13229        };
  13230        Scanner.prototype.innerScan = function () {
  13231            var rtok;
  13232            this.tokenStart();
  13233            this.ch = this.peekChar();
  13234            start:
  13235 while(this.pos < this.len) {
  13236                if(lexIdStartTable[this.ch] || this.ch == TypeScript.LexCodeBSL || (this.ch >= TypeScript.LexCodeASCIIChars && LexIsUnicodeIdStart(this.ch))) {
  13237                    return this.scanIdentifier();
  13238                } else {
  13239                    if(this.ch == TypeScript.LexCodeSpace) {
  13240                        if(!this.interveningWhitespace) {
  13241                            this.interveningWhitespacePos = this.pos;
  13242                        }
  13243                        do {
  13244                            this.nextChar();
  13245                        }while(this.ch == TypeScript.LexCodeSpace)
  13246                        if(this.mode == LexMode.Line) {
  13247                            var whitespaceText = this.src.substring(this.startPos, this.pos);
  13248                            return new TypeScript.WhitespaceToken(TypeScript.TokenID.Whitespace, whitespaceText);
  13249                        } else {
  13250                            this.tokenStart();
  13251                            this.interveningWhitespace = true;
  13252                        }
  13253                    } else {
  13254                        if(this.ch == TypeScript.LexCodeSLH) {
  13255                            this.nextChar();
  13256                            var commentText;
  13257                            if(this.ch == TypeScript.LexCodeSLH) {
  13258                                if(!this.interveningWhitespace) {
  13259                                    this.interveningWhitespacePos = this.pos - 1;
  13260                                }
  13261                                var commentStartPos = this.pos - 1;
  13262                                var commentStartLine = this.line;
  13263                                this.finishSinglelineComment();
  13264                                var commentText = this.src.substring(commentStartPos, this.pos);
  13265                                var commentToken = new TypeScript.CommentToken(TypeScript.TokenID.Comment, commentText, false, commentStartPos, commentStartLine, false);
  13266                                if(this.scanComments) {
  13267                                    this.startPos = commentStartPos;
  13268                                    return commentToken;
  13269                                } else {
  13270                                    this.pushComment(commentToken);
  13271                                }
  13272                                this.interveningWhitespace = true;
  13273                            } else {
  13274                                if(this.ch == TypeScript.LexCodeMUL) {
  13275                                    if(!this.interveningWhitespace) {
  13276                                        this.interveningWhitespacePos = this.pos - 1;
  13277                                    }
  13278                                    var commentStartPos = this.pos - 1;
  13279                                    var commentStartLine = this.line;
  13280                                    this.nextChar();
  13281                                    this.finishMultilineComment();
  13282                                    var commentText = this.src.substring(commentStartPos, this.pos);
  13283                                    var endsLine = this.endsLine(this.peekChar());
  13284                                    var commentToken = new TypeScript.CommentToken(TypeScript.TokenID.Comment, commentText, true, commentStartPos, commentStartLine, endsLine);
  13285                                    if(this.scanComments) {
  13286                                        this.startPos = commentStartPos;
  13287                                        return commentToken;
  13288                                    } else {
  13289                                        this.pushComment(commentToken);
  13290                                    }
  13291                                    this.interveningWhitespace = true;
  13292                                } else {
  13293                                    var regexTok = this.speculateRegex();
  13294                                    if(regexTok) {
  13295                                        return regexTok;
  13296                                    } else {
  13297                                        if(this.peekCharAt(this.pos) == TypeScript.LexCodeEQ) {
  13298                                            this.nextChar();
  13299                                            return TypeScript.staticTokens[TypeScript.TokenID.SlashEquals];
  13300                                        } else {
  13301                                            return TypeScript.staticTokens[TypeScript.TokenID.Slash];
  13302                                        }
  13303                                    }
  13304                                }
  13305                            }
  13306                        } else {
  13307                            if(this.ch == TypeScript.LexCodeSMC) {
  13308                                this.nextChar();
  13309                                return TypeScript.staticTokens[TypeScript.TokenID.Semicolon];
  13310                            } else {
  13311                                if((this.ch == TypeScript.LexCodeAPO) || (this.ch == TypeScript.LexCodeQUO)) {
  13312                                    return this.scanStringConstant();
  13313                                } else {
  13314                                    if(autoToken[this.ch]) {
  13315                                        var atok = autoToken[this.ch];
  13316                                        if(atok.tokenId == TypeScript.TokenID.OpenBrace) {
  13317                                            this.leftCurlyCount++;
  13318                                        } else {
  13319                                            if(atok.tokenId == TypeScript.TokenID.CloseBrace) {
  13320                                                this.rightCurlyCount++;
  13321                                            }
  13322                                        }
  13323                                        this.nextChar();
  13324                                        return atok;
  13325                                    } else {
  13326                                        if((this.ch >= TypeScript.LexCode_0) && (this.ch <= TypeScript.LexCode_9)) {
  13327                                            rtok = this.scanNumber();
  13328                                            if(rtok) {
  13329                                                return rtok;
  13330                                            } else {
  13331                                                this.nextChar();
  13332                                                return TypeScript.staticTokens[TypeScript.TokenID.Error];
  13333                                            }
  13334                                        } else {
  13335                                            switch(this.ch) {
  13336                                                case TypeScript.LexCodeTAB:
  13337                                                case TypeScript.LexCodeVTAB: {
  13338                                                    if(!this.interveningWhitespace) {
  13339                                                        this.interveningWhitespacePos = this.pos;
  13340                                                    }
  13341                                                    if(this.mode == LexMode.Line) {
  13342                                                        do {
  13343                                                            this.nextChar();
  13344                                                        }while((this.ch == TypeScript.LexCodeSpace) || (this.ch == 9))
  13345                                                        var wsText = this.src.substring(this.startPos, this.pos);
  13346                                                        return new TypeScript.WhitespaceToken(TypeScript.TokenID.Whitespace, wsText);
  13347                                                    } else {
  13348                                                        this.interveningWhitespace = true;
  13349                                                    }
  13350 
  13351                                                }
  13352                                                case 255:
  13353                                                case 254:
  13354                                                case 239:
  13355                                                case 187:
  13356                                                case 191:
  13357                                                case TypeScript.LexCodeLS:
  13358                                                case TypeScript.LexCodePS:
  13359                                                case TypeScript.LexCodeNWL:
  13360                                                case TypeScript.LexCodeRET: {
  13361                                                    if(this.ch == TypeScript.LexCodeNWL) {
  13362                                                        this.newLine();
  13363                                                        if(this.mode == LexMode.Line) {
  13364                                                            return TypeScript.staticTokens[TypeScript.TokenID.EndOfFile];
  13365                                                        }
  13366                                                    }
  13367                                                    if(!this.interveningWhitespace) {
  13368                                                        this.interveningWhitespacePos = this.pos;
  13369                                                    }
  13370                                                    this.nextChar();
  13371                                                    this.tokenStart();
  13372                                                    this.interveningWhitespace = true;
  13373                                                    break;
  13374 
  13375                                                }
  13376                                                case TypeScript.LexCodeDOT: {
  13377                                                    if(this.peekCharAt(this.pos + 1) == TypeScript.LexCodeDOT) {
  13378                                                        if(this.peekCharAt(this.pos + 2) == TypeScript.LexCodeDOT) {
  13379                                                            this.advanceChar(3);
  13380                                                            return TypeScript.staticTokens[TypeScript.TokenID.DotDotDot];
  13381                                                        } else {
  13382                                                            this.nextChar();
  13383                                                            return TypeScript.staticTokens[TypeScript.TokenID.Dot];
  13384                                                        }
  13385                                                    } else {
  13386                                                        this.nextChar();
  13387                                                        rtok = this.scanFraction();
  13388                                                        if(rtok) {
  13389                                                            return rtok;
  13390                                                        } else {
  13391                                                            return TypeScript.staticTokens[TypeScript.TokenID.Dot];
  13392                                                        }
  13393                                                    }
  13394                                                }
  13395 
  13396                                                case TypeScript.LexCodeEQ: {
  13397                                                    if(this.peekCharAt(this.pos + 1) == TypeScript.LexCodeEQ) {
  13398                                                        if(this.peekCharAt(this.pos + 2) == TypeScript.LexCodeEQ) {
  13399                                                            this.advanceChar(3);
  13400                                                            return TypeScript.staticTokens[TypeScript.TokenID.EqualsEqualsEquals];
  13401                                                        } else {
  13402                                                            this.advanceChar(2);
  13403                                                            return TypeScript.staticTokens[TypeScript.TokenID.EqualsEquals];
  13404                                                        }
  13405                                                    } else {
  13406                                                        if(this.peekCharAt(this.pos + 1) == TypeScript.LexCodeGT) {
  13407                                                            this.advanceChar(2);
  13408                                                            return TypeScript.staticTokens[TypeScript.TokenID.EqualsGreaterThan];
  13409                                                        } else {
  13410                                                            this.nextChar();
  13411                                                            return TypeScript.staticTokens[TypeScript.TokenID.Equals];
  13412                                                        }
  13413                                                    }
  13414 
  13415                                                }
  13416                                                case TypeScript.LexCodeBNG: {
  13417                                                    if(this.peekCharAt(this.pos + 1) == TypeScript.LexCodeEQ) {
  13418                                                        if(this.peekCharAt(this.pos + 2) == TypeScript.LexCodeEQ) {
  13419                                                            this.advanceChar(3);
  13420                                                            return TypeScript.staticTokens[TypeScript.TokenID.ExclamationEqualsEquals];
  13421                                                        } else {
  13422                                                            this.advanceChar(2);
  13423                                                            return TypeScript.staticTokens[TypeScript.TokenID.ExclamationEquals];
  13424                                                        }
  13425                                                    } else {
  13426                                                        this.nextChar();
  13427                                                        return TypeScript.staticTokens[TypeScript.TokenID.Exclamation];
  13428                                                    }
  13429 
  13430                                                }
  13431                                                case TypeScript.LexCodePLS: {
  13432                                                    if(this.peekCharAt(this.pos + 1) == TypeScript.LexCodeEQ) {
  13433                                                        this.advanceChar(2);
  13434                                                        return TypeScript.staticTokens[TypeScript.TokenID.PlusEquals];
  13435                                                    } else {
  13436                                                        if(this.peekCharAt(this.pos + 1) == TypeScript.LexCodePLS) {
  13437                                                            this.advanceChar(2);
  13438                                                            return TypeScript.staticTokens[TypeScript.TokenID.PlusPlus];
  13439                                                        } else {
  13440                                                            this.nextChar();
  13441                                                            return TypeScript.staticTokens[TypeScript.TokenID.Plus];
  13442                                                        }
  13443                                                    }
  13444 
  13445                                                }
  13446                                                case TypeScript.LexCodeMIN: {
  13447                                                    if(this.peekCharAt(this.pos + 1) == TypeScript.LexCodeEQ) {
  13448                                                        this.advanceChar(2);
  13449                                                        return TypeScript.staticTokens[TypeScript.TokenID.MinusEquals];
  13450                                                    } else {
  13451                                                        if(this.peekCharAt(this.pos + 1) == TypeScript.LexCodeMIN) {
  13452                                                            this.advanceChar(2);
  13453                                                            return TypeScript.staticTokens[TypeScript.TokenID.MinusMinus];
  13454                                                        } else {
  13455                                                            this.nextChar();
  13456                                                            return TypeScript.staticTokens[TypeScript.TokenID.Minus];
  13457                                                        }
  13458                                                    }
  13459 
  13460                                                }
  13461                                                case TypeScript.LexCodeMUL: {
  13462                                                    if(this.peekCharAt(this.pos + 1) == TypeScript.LexCodeEQ) {
  13463                                                        this.advanceChar(2);
  13464                                                        return TypeScript.staticTokens[TypeScript.TokenID.AsteriskEquals];
  13465                                                    } else {
  13466                                                        this.nextChar();
  13467                                                        return TypeScript.staticTokens[TypeScript.TokenID.Asterisk];
  13468                                                    }
  13469 
  13470                                                }
  13471                                                case TypeScript.LexCodePCT: {
  13472                                                    if(this.peekCharAt(this.pos + 1) == TypeScript.LexCodeEQ) {
  13473                                                        this.advanceChar(2);
  13474                                                        return TypeScript.staticTokens[TypeScript.TokenID.PercentEquals];
  13475                                                    } else {
  13476                                                        this.nextChar();
  13477                                                        return TypeScript.staticTokens[TypeScript.TokenID.Percent];
  13478                                                    }
  13479 
  13480                                                }
  13481                                                case TypeScript.LexCodeLT: {
  13482                                                    if(this.peekCharAt(this.pos + 1) == TypeScript.LexCodeLT) {
  13483                                                        if(this.peekCharAt(this.pos + 2) == TypeScript.LexCodeEQ) {
  13484                                                            this.advanceChar(3);
  13485                                                            return TypeScript.staticTokens[TypeScript.TokenID.LessThanLessThanEquals];
  13486                                                        } else {
  13487                                                            this.advanceChar(2);
  13488                                                            return TypeScript.staticTokens[TypeScript.TokenID.LessThanLessThan];
  13489                                                        }
  13490                                                    } else {
  13491                                                        if(this.peekCharAt(this.pos + 1) == TypeScript.LexCodeEQ) {
  13492                                                            this.advanceChar(2);
  13493                                                            return TypeScript.staticTokens[TypeScript.TokenID.LessThanEquals];
  13494                                                        } else {
  13495                                                            this.nextChar();
  13496                                                            return TypeScript.staticTokens[TypeScript.TokenID.LessThan];
  13497                                                        }
  13498                                                    }
  13499 
  13500                                                }
  13501                                                case TypeScript.LexCodeGT: {
  13502                                                    if(this.peekCharAt(this.pos + 1) == TypeScript.LexCodeGT) {
  13503                                                        if(this.peekCharAt(this.pos + 2) == TypeScript.LexCodeEQ) {
  13504                                                            this.advanceChar(3);
  13505                                                            return TypeScript.staticTokens[TypeScript.TokenID.GreaterThanGreaterThanEquals];
  13506                                                        } else {
  13507                                                            if(this.peekCharAt(this.pos + 2) == TypeScript.LexCodeGT) {
  13508                                                                if(this.peekCharAt(this.pos + 3) == TypeScript.LexCodeEQ) {
  13509                                                                    this.advanceChar(4);
  13510                                                                    return TypeScript.staticTokens[TypeScript.TokenID.GreaterThanGreaterThanGreaterThanEquals];
  13511                                                                } else {
  13512                                                                    this.advanceChar(3);
  13513                                                                    return TypeScript.staticTokens[TypeScript.TokenID.GreaterThanGreaterThanGreaterThan];
  13514                                                                }
  13515                                                            } else {
  13516                                                                this.advanceChar(2);
  13517                                                                return TypeScript.staticTokens[TypeScript.TokenID.GreaterThanGreaterThan];
  13518                                                            }
  13519                                                        }
  13520                                                    } else {
  13521                                                        if(this.peekCharAt(this.pos + 1) == TypeScript.LexCodeEQ) {
  13522                                                            this.advanceChar(2);
  13523                                                            return TypeScript.staticTokens[TypeScript.TokenID.GreaterThanEquals];
  13524                                                        } else {
  13525                                                            this.nextChar();
  13526                                                            return TypeScript.staticTokens[TypeScript.TokenID.GreaterThan];
  13527                                                        }
  13528                                                    }
  13529 
  13530                                                }
  13531                                                case TypeScript.LexCodeXOR: {
  13532                                                    if(this.peekCharAt(this.pos + 1) == TypeScript.LexCodeEQ) {
  13533                                                        this.advanceChar(2);
  13534                                                        return TypeScript.staticTokens[TypeScript.TokenID.CaretEquals];
  13535                                                    } else {
  13536                                                        this.nextChar();
  13537                                                        return TypeScript.staticTokens[TypeScript.TokenID.Caret];
  13538                                                    }
  13539 
  13540                                                }
  13541                                                case TypeScript.LexCodeBAR: {
  13542                                                    if(this.peekCharAt(this.pos + 1) == TypeScript.LexCodeEQ) {
  13543                                                        this.advanceChar(2);
  13544                                                        return TypeScript.staticTokens[TypeScript.TokenID.BarEquals];
  13545                                                    } else {
  13546                                                        if(this.peekCharAt(this.pos + 1) == TypeScript.LexCodeBAR) {
  13547                                                            this.advanceChar(2);
  13548                                                            return TypeScript.staticTokens[TypeScript.TokenID.BarBar];
  13549                                                        } else {
  13550                                                            this.nextChar();
  13551                                                            return TypeScript.staticTokens[TypeScript.TokenID.Bar];
  13552                                                        }
  13553                                                    }
  13554 
  13555                                                }
  13556                                                case TypeScript.LexCodeAMP: {
  13557                                                    if(this.peekCharAt(this.pos + 1) == TypeScript.LexCodeEQ) {
  13558                                                        this.advanceChar(2);
  13559                                                        return TypeScript.staticTokens[TypeScript.TokenID.AmpersandEquals];
  13560                                                    } else {
  13561                                                        if(this.peekCharAt(this.pos + 1) == TypeScript.LexCodeAMP) {
  13562                                                            this.advanceChar(2);
  13563                                                            return TypeScript.staticTokens[TypeScript.TokenID.AmpersandAmpersand];
  13564                                                        } else {
  13565                                                            this.nextChar();
  13566                                                            return TypeScript.staticTokens[TypeScript.TokenID.And];
  13567                                                        }
  13568                                                    }
  13569 
  13570                                                }
  13571                                                default: {
  13572                                                    this.reportScannerError("Invalid character");
  13573                                                    this.nextChar();
  13574                                                    continue start;
  13575 
  13576                                                }
  13577                                            }
  13578                                        }
  13579                                    }
  13580                                }
  13581                            }
  13582                        }
  13583                    }
  13584                }
  13585            }
  13586            return TypeScript.staticTokens[TypeScript.TokenID.EndOfFile];
  13587        };
  13588        Scanner.prototype.reportScannerError = function (message) {
  13589            if(this.reportError) {
  13590                this.reportError(message);
  13591            }
  13592        };
  13593        return Scanner;
  13594    })();
  13595    TypeScript.Scanner = Scanner;    
  13596    function convertTokToIDName(tok) {
  13597        return convertTokToIDBase(tok, true, false);
  13598    }
  13599    TypeScript.convertTokToIDName = convertTokToIDName;
  13600    function convertTokToID(tok, strictMode) {
  13601        return convertTokToIDBase(tok, false, strictMode);
  13602    }
  13603    TypeScript.convertTokToID = convertTokToID;
  13604    function convertTokToIDBase(tok, identifierName, strictMode) {
  13605        if(tok.tokenId <= TypeScript.TokenID.LimKeyword) {
  13606            var tokInfo = TypeScript.lookupToken(tok.tokenId);
  13607            if(tokInfo != undefined) {
  13608                var resFlags = TypeScript.Reservation.Javascript | TypeScript.Reservation.JavascriptFuture;
  13609                if(strictMode) {
  13610                    resFlags |= TypeScript.Reservation.JavascriptFutureStrict;
  13611                }
  13612                if(identifierName || !TypeScript.hasFlag(tokInfo.reservation, resFlags)) {
  13613                    return true;
  13614                }
  13615            } else {
  13616                return false;
  13617            }
  13618        } else {
  13619            return false;
  13620        }
  13621    }
  13622    function getLineNumberFromPosition(lineMap, position) {
  13623        if(position === -1) {
  13624            return 0;
  13625        }
  13626        var min = 0;
  13627        var max = lineMap.length - 1;
  13628        while(min < max) {
  13629            var med = (min + max) >> 1;
  13630            if(position < lineMap[med]) {
  13631                max = med - 1;
  13632            } else {
  13633                if(position < lineMap[med + 1]) {
  13634                    min = max = med;
  13635                } else {
  13636                    min = med + 1;
  13637                }
  13638            }
  13639        }
  13640        return min;
  13641    }
  13642    TypeScript.getLineNumberFromPosition = getLineNumberFromPosition;
  13643    function getSourceLineColFromMap(lineCol, minChar, lineMap) {
  13644        var line = getLineNumberFromPosition(lineMap, minChar);
  13645        if(line > 0) {
  13646            lineCol.line = line;
  13647            lineCol.col = (minChar - lineMap[line]);
  13648        }
  13649    }
  13650    TypeScript.getSourceLineColFromMap = getSourceLineColFromMap;
  13651    function getLineColumnFromPosition(script, position) {
  13652        var result = {
  13653            line: -1,
  13654            col: -1
  13655        };
  13656        getSourceLineColFromMap(result, position, script.locationInfo.lineMap);
  13657        if(result.col >= 0) {
  13658            result.col++;
  13659        }
  13660        return result;
  13661    }
  13662    TypeScript.getLineColumnFromPosition = getLineColumnFromPosition;
  13663    function getPositionFromLineColumn(script, line, column) {
  13664        return script.locationInfo.lineMap[line] + (column - 1);
  13665    }
  13666    TypeScript.getPositionFromLineColumn = getPositionFromLineColumn;
  13667    function isPrimitiveTypeToken(token) {
  13668        switch(token.tokenId) {
  13669            case TypeScript.TokenID.Any:
  13670            case TypeScript.TokenID.Bool:
  13671            case TypeScript.TokenID.Number:
  13672            case TypeScript.TokenID.String: {
  13673                return true;
  13674 
  13675            }
  13676        }
  13677        return false;
  13678    }
  13679    TypeScript.isPrimitiveTypeToken = isPrimitiveTypeToken;
  13680    function isModifier(token) {
  13681        switch(token.tokenId) {
  13682            case TypeScript.TokenID.Public:
  13683            case TypeScript.TokenID.Private:
  13684            case TypeScript.TokenID.Static: {
  13685                return true;
  13686 
  13687            }
  13688        }
  13689        return false;
  13690    }
  13691    TypeScript.isModifier = isModifier;
  13692 })(TypeScript || (TypeScript = {}));
  13693 var TypeScript;
  13694 (function (TypeScript) {
  13695    var AssignScopeContext = (function () {
  13696        function AssignScopeContext(scopeChain, typeFlow, modDeclChain) {
  13697            this.scopeChain = scopeChain;
  13698            this.typeFlow = typeFlow;
  13699            this.modDeclChain = modDeclChain;
  13700        }
  13701        return AssignScopeContext;
  13702    })();
  13703    TypeScript.AssignScopeContext = AssignScopeContext;    
  13704    function pushAssignScope(scope, context, type, classType, fnc) {
  13705        var chain = new TypeScript.ScopeChain(null, context.scopeChain, scope);
  13706        chain.thisType = type;
  13707        chain.classType = classType;
  13708        chain.fnc = fnc;
  13709        context.scopeChain = chain;
  13710    }
  13711    TypeScript.pushAssignScope = pushAssignScope;
  13712    function popAssignScope(context) {
  13713        context.scopeChain = context.scopeChain.previous;
  13714    }
  13715    TypeScript.popAssignScope = popAssignScope;
  13716    function instanceCompare(a, b) {
  13717        if(((a == null) || (!a.isInstanceProperty()))) {
  13718            return b;
  13719        } else {
  13720            return a;
  13721        }
  13722    }
  13723    TypeScript.instanceCompare = instanceCompare;
  13724    function instanceFilterStop(s) {
  13725        return s.isInstanceProperty();
  13726    }
  13727    TypeScript.instanceFilterStop = instanceFilterStop;
  13728    var ScopeSearchFilter = (function () {
  13729        function ScopeSearchFilter(select, stop) {
  13730            this.select = select;
  13731            this.stop = stop;
  13732            this.result = null;
  13733        }
  13734        ScopeSearchFilter.prototype.reset = function () {
  13735            this.result = null;
  13736        };
  13737        ScopeSearchFilter.prototype.update = function (b) {
  13738            this.result = this.select(this.result, b);
  13739            if(this.result) {
  13740                return this.stop(this.result);
  13741            } else {
  13742                return false;
  13743            }
  13744        };
  13745        return ScopeSearchFilter;
  13746    })();
  13747    TypeScript.ScopeSearchFilter = ScopeSearchFilter;    
  13748    TypeScript.instanceFilter = new ScopeSearchFilter(instanceCompare, instanceFilterStop);
  13749    function preAssignModuleScopes(ast, context) {
  13750        var moduleDecl = ast;
  13751        var memberScope = null;
  13752        var aggScope = null;
  13753        if(moduleDecl.name && moduleDecl.mod) {
  13754            moduleDecl.name.sym = moduleDecl.mod.symbol;
  13755        }
  13756        var mod = moduleDecl.mod;
  13757        if(!mod) {
  13758            return;
  13759        }
  13760        memberScope = new TypeScript.SymbolTableScope(mod.members, mod.ambientMembers, mod.enclosedTypes, mod.ambientEnclosedTypes, mod.symbol);
  13761        mod.memberScope = memberScope;
  13762        context.modDeclChain.push(moduleDecl);
  13763        context.typeFlow.checker.currentModDecl = moduleDecl;
  13764        aggScope = new TypeScript.SymbolAggregateScope(mod.symbol);
  13765        aggScope.addParentScope(memberScope);
  13766        aggScope.addParentScope(context.scopeChain.scope);
  13767        pushAssignScope(aggScope, context, null, null, null);
  13768        mod.containedScope = aggScope;
  13769        if(mod.symbol) {
  13770            context.typeFlow.addLocalsFromScope(mod.containedScope, mod.symbol, moduleDecl.vars, mod.members.privateMembers, true);
  13771        }
  13772    }
  13773    TypeScript.preAssignModuleScopes = preAssignModuleScopes;
  13774    function preAssignClassScopes(ast, context) {
  13775        var classDecl = ast;
  13776        var memberScope = null;
  13777        var aggScope = null;
  13778        if(classDecl.name && classDecl.type) {
  13779            classDecl.name.sym = classDecl.type.symbol;
  13780        }
  13781        var classType = ast.type;
  13782        if(classType) {
  13783            var classSym = classType.symbol;
  13784            memberScope = context.typeFlow.checker.scopeOf(classType);
  13785            aggScope = new TypeScript.SymbolAggregateScope(classType.symbol);
  13786            aggScope.addParentScope(memberScope);
  13787            aggScope.addParentScope(context.scopeChain.scope);
  13788            classType.containedScope = aggScope;
  13789            classType.memberScope = memberScope;
  13790            var instanceType = classType.instanceType;
  13791            memberScope = context.typeFlow.checker.scopeOf(instanceType);
  13792            instanceType.memberScope = memberScope;
  13793            aggScope = new TypeScript.SymbolAggregateScope(instanceType.symbol);
  13794            aggScope.addParentScope(context.scopeChain.scope);
  13795            pushAssignScope(aggScope, context, instanceType, classType, null);
  13796            instanceType.containedScope = aggScope;
  13797        } else {
  13798            ast.type = context.typeFlow.anyType;
  13799        }
  13800    }
  13801    TypeScript.preAssignClassScopes = preAssignClassScopes;
  13802    function preAssignInterfaceScopes(ast, context) {
  13803        var interfaceDecl = ast;
  13804        var memberScope = null;
  13805        var aggScope = null;
  13806        if(interfaceDecl.name && interfaceDecl.type) {
  13807            interfaceDecl.name.sym = interfaceDecl.type.symbol;
  13808        }
  13809        var interfaceType = ast.type;
  13810        memberScope = context.typeFlow.checker.scopeOf(interfaceType);
  13811        interfaceType.memberScope = memberScope;
  13812        aggScope = new TypeScript.SymbolAggregateScope(interfaceType.symbol);
  13813        aggScope.addParentScope(memberScope);
  13814        aggScope.addParentScope(context.scopeChain.scope);
  13815        pushAssignScope(aggScope, context, null, null, null);
  13816        interfaceType.containedScope = aggScope;
  13817    }
  13818    TypeScript.preAssignInterfaceScopes = preAssignInterfaceScopes;
  13819    function preAssignWithScopes(ast, context) {
  13820        var withStmt = ast;
  13821        var withType = withStmt.type;
  13822        var members = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  13823        var ambientMembers = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  13824        var withType = new TypeScript.Type();
  13825        var withSymbol = new TypeScript.WithSymbol(withStmt.minChar, context.typeFlow.checker.locationInfo.unitIndex, withType);
  13826        withType.members = members;
  13827        withType.ambientMembers = ambientMembers;
  13828        withType.symbol = withSymbol;
  13829        withType.setHasImplementation();
  13830        withStmt.type = withType;
  13831        var withScope = new TypeScript.SymbolScopeBuilder(withType.members, withType.ambientMembers, null, null, context.scopeChain.scope, withType.symbol);
  13832        pushAssignScope(withScope, context, null, null, null);
  13833        withType.containedScope = withScope;
  13834    }
  13835    TypeScript.preAssignWithScopes = preAssignWithScopes;
  13836    function preAssignFuncDeclScopes(ast, context) {
  13837        var funcDecl = ast;
  13838        var container = null;
  13839        var localContainer = null;
  13840        if(funcDecl.type) {
  13841            localContainer = ast.type.symbol;
  13842        }
  13843        var isStatic = TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Static);
  13844        var isInnerStatic = isStatic && context.scopeChain.fnc != null;
  13845        var parentScope = isInnerStatic ? context.scopeChain.fnc.type.memberScope : context.scopeChain.scope;
  13846        if(context.scopeChain.thisType && (!funcDecl.isConstructor || TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.ClassMethod))) {
  13847            var instType = context.scopeChain.thisType;
  13848            if(!(instType.typeFlags & TypeScript.TypeFlags.IsClass) && !TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.ClassMethod)) {
  13849                if(!funcDecl.isMethod() || isStatic) {
  13850                    parentScope = instType.constructorScope;
  13851                } else {
  13852                    parentScope = instType.containedScope;
  13853                }
  13854            } else {
  13855                if(context.scopeChain.previous.scope.container && context.scopeChain.previous.scope.container.declAST && context.scopeChain.previous.scope.container.declAST.nodeType == TypeScript.NodeType.FuncDecl && (context.scopeChain.previous.scope.container.declAST).isConstructor) {
  13856                    parentScope = instType.constructorScope;
  13857                } else {
  13858                    if(isStatic && context.scopeChain.classType) {
  13859                        parentScope = context.scopeChain.classType.containedScope;
  13860                    } else {
  13861                        parentScope = instType.containedScope;
  13862                    }
  13863                }
  13864            }
  13865            container = instType.symbol;
  13866        } else {
  13867            if(funcDecl.isConstructor && context.scopeChain.thisType) {
  13868                container = context.scopeChain.thisType.symbol;
  13869            }
  13870        }
  13871        if(funcDecl.type == null || TypeScript.hasFlag(funcDecl.type.symbol.flags, TypeScript.SymbolFlags.TypeSetDuringScopeAssignment)) {
  13872            if(context.scopeChain.fnc && context.scopeChain.fnc.type) {
  13873                container = context.scopeChain.fnc.type.symbol;
  13874            }
  13875            var funcScope = null;
  13876            var outerFnc = context.scopeChain.fnc;
  13877            var nameText = funcDecl.name ? funcDecl.name.actualText : null;
  13878            var fgSym = null;
  13879            if(isStatic) {
  13880                if(outerFnc.type.members == null && container.getType().memberScope) {
  13881                    outerFnc.type.members = ((container).type.memberScope).valueMembers;
  13882                }
  13883                funcScope = context.scopeChain.fnc.type.memberScope;
  13884                outerFnc.innerStaticFuncs[outerFnc.innerStaticFuncs.length] = funcDecl;
  13885            } else {
  13886                funcScope = context.scopeChain.scope;
  13887            }
  13888            if(nameText && nameText != "__missing" && !funcDecl.isAccessor()) {
  13889                if(isStatic) {
  13890                    fgSym = funcScope.findLocal(nameText, false, false);
  13891                } else {
  13892                    fgSym = funcScope.findLocal(nameText, false, false);
  13893                }
  13894            }
  13895            context.typeFlow.checker.createFunctionSignature(funcDecl, container, funcScope, fgSym, fgSym == null);
  13896            if(!funcDecl.accessorSymbol && (funcDecl.fncFlags & TypeScript.FncFlags.ClassMethod) && container && ((!fgSym || fgSym.declAST.nodeType != TypeScript.NodeType.FuncDecl) && funcDecl.isAccessor()) || (fgSym && fgSym.isAccessor())) {
  13897                funcDecl.accessorSymbol = context.typeFlow.checker.createAccessorSymbol(funcDecl, fgSym, container.getType(), (funcDecl.isMethod() && isStatic), true, funcScope, container);
  13898            }
  13899            funcDecl.type.symbol.flags |= TypeScript.SymbolFlags.TypeSetDuringScopeAssignment;
  13900        }
  13901        if(funcDecl.name && funcDecl.type) {
  13902            funcDecl.name.sym = funcDecl.type.symbol;
  13903        }
  13904        funcDecl.scopeType = funcDecl.type;
  13905        if(funcDecl.isOverload) {
  13906            return;
  13907        }
  13908        var funcTable = new TypeScript.StringHashTable();
  13909        var funcMembers = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(funcTable, new TypeScript.StringHashTable()));
  13910        var ambientFuncTable = new TypeScript.StringHashTable();
  13911        var ambientFuncMembers = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(ambientFuncTable, new TypeScript.StringHashTable()));
  13912        var funcStaticTable = new TypeScript.StringHashTable();
  13913        var funcStaticMembers = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(funcStaticTable, new TypeScript.StringHashTable()));
  13914        var ambientFuncStaticTable = new TypeScript.StringHashTable();
  13915        var ambientFuncStaticMembers = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(ambientFuncStaticTable, new TypeScript.StringHashTable()));
  13916        funcDecl.unitIndex = context.typeFlow.checker.locationInfo.unitIndex;
  13917        var locals = new TypeScript.SymbolScopeBuilder(funcMembers, ambientFuncMembers, null, null, parentScope, localContainer);
  13918        var statics = new TypeScript.SymbolScopeBuilder(funcStaticMembers, ambientFuncStaticMembers, null, null, parentScope, null);
  13919        if(funcDecl.isConstructor && context.scopeChain.thisType) {
  13920            context.scopeChain.thisType.constructorScope = locals;
  13921        }
  13922        funcDecl.symbols = funcTable;
  13923        if(!funcDecl.isSpecialFn()) {
  13924            var group = funcDecl.type;
  13925            var signature = funcDecl.signature;
  13926            if(!funcDecl.isConstructor) {
  13927                group.containedScope = locals;
  13928                locals.container = group.symbol;
  13929                group.memberScope = statics;
  13930                statics.container = group.symbol;
  13931            }
  13932            funcDecl.enclosingFnc = context.scopeChain.fnc;
  13933            group.enclosingType = isStatic ? context.scopeChain.classType : context.scopeChain.thisType;
  13934            var fgSym = ast.type.symbol;
  13935            if(((funcDecl.fncFlags & TypeScript.FncFlags.Signature) == TypeScript.FncFlags.None) && funcDecl.vars) {
  13936                context.typeFlow.addLocalsFromScope(locals, fgSym, funcDecl.vars, funcTable, false);
  13937                context.typeFlow.addLocalsFromScope(statics, fgSym, funcDecl.statics, funcStaticTable, false);
  13938            }
  13939            if(signature.parameters) {
  13940                var len = signature.parameters.length;
  13941                for(var i = 0; i < len; i++) {
  13942                    var paramSym = signature.parameters[i];
  13943                    context.typeFlow.checker.resolveTypeLink(locals, paramSym.parameter.typeLink, true);
  13944                }
  13945            }
  13946            context.typeFlow.checker.resolveTypeLink(locals, signature.returnType, funcDecl.isSignature());
  13947        }
  13948        if(!funcDecl.isConstructor || TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.ClassMethod)) {
  13949            var thisType = (funcDecl.isConstructor && TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.ClassMethod)) ? context.scopeChain.thisType : null;
  13950            pushAssignScope(locals, context, thisType, null, funcDecl);
  13951        }
  13952        if(funcDecl.name && TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.IsFunctionExpression)) {
  13953            if(funcDecl.name.sym) {
  13954                funcTable.add(funcDecl.name.actualText, funcDecl.name.sym);
  13955            }
  13956        }
  13957    }
  13958    TypeScript.preAssignFuncDeclScopes = preAssignFuncDeclScopes;
  13959    function preAssignCatchScopes(ast, context) {
  13960        var catchBlock = ast;
  13961        if(catchBlock.param) {
  13962            var catchTable = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  13963            var catchLocals = new TypeScript.SymbolScopeBuilder(catchTable, null, null, null, context.scopeChain.scope, context.scopeChain.scope.container);
  13964            catchBlock.containedScope = catchLocals;
  13965            pushAssignScope(catchLocals, context, context.scopeChain.thisType, context.scopeChain.classType, context.scopeChain.fnc);
  13966        }
  13967    }
  13968    TypeScript.preAssignCatchScopes = preAssignCatchScopes;
  13969    function preAssignScopes(ast, parent, walker) {
  13970        var context = walker.state;
  13971        var go = true;
  13972        if(ast) {
  13973            if(ast.nodeType == TypeScript.NodeType.List) {
  13974                var list = ast;
  13975                list.enclosingScope = context.scopeChain.scope;
  13976            } else {
  13977                if(ast.nodeType == TypeScript.NodeType.ModuleDeclaration) {
  13978                    preAssignModuleScopes(ast, context);
  13979                } else {
  13980                    if(ast.nodeType == TypeScript.NodeType.ClassDeclaration) {
  13981                        preAssignClassScopes(ast, context);
  13982                    } else {
  13983                        if(ast.nodeType == TypeScript.NodeType.InterfaceDeclaration) {
  13984                            preAssignInterfaceScopes(ast, context);
  13985                        } else {
  13986                            if(ast.nodeType == TypeScript.NodeType.With) {
  13987                                preAssignWithScopes(ast, context);
  13988                            } else {
  13989                                if(ast.nodeType == TypeScript.NodeType.FuncDecl) {
  13990                                    preAssignFuncDeclScopes(ast, context);
  13991                                } else {
  13992                                    if(ast.nodeType == TypeScript.NodeType.Catch) {
  13993                                        preAssignCatchScopes(ast, context);
  13994                                    } else {
  13995                                        if(ast.nodeType == TypeScript.NodeType.TypeRef) {
  13996                                            go = false;
  13997                                        }
  13998                                    }
  13999                                }
  14000                            }
  14001                        }
  14002                    }
  14003                }
  14004            }
  14005        }
  14006        walker.options.goChildren = go;
  14007        return ast;
  14008    }
  14009    TypeScript.preAssignScopes = preAssignScopes;
  14010    function postAssignScopes(ast, parent, walker) {
  14011        var context = walker.state;
  14012        var go = true;
  14013        if(ast) {
  14014            if(ast.nodeType == TypeScript.NodeType.ModuleDeclaration) {
  14015                var prevModDecl = ast;
  14016                popAssignScope(context);
  14017                context.modDeclChain.pop();
  14018                if(context.modDeclChain.length >= 1) {
  14019                    context.typeFlow.checker.currentModDecl = context.modDeclChain[context.modDeclChain.length - 1];
  14020                }
  14021            } else {
  14022                if(ast.nodeType == TypeScript.NodeType.ClassDeclaration) {
  14023                    popAssignScope(context);
  14024                } else {
  14025                    if(ast.nodeType == TypeScript.NodeType.InterfaceDeclaration) {
  14026                        popAssignScope(context);
  14027                    } else {
  14028                        if(ast.nodeType == TypeScript.NodeType.With) {
  14029                            popAssignScope(context);
  14030                        } else {
  14031                            if(ast.nodeType == TypeScript.NodeType.FuncDecl) {
  14032                                var funcDecl = ast;
  14033                                if((!funcDecl.isConstructor || TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.ClassMethod)) && !funcDecl.isOverload) {
  14034                                    popAssignScope(context);
  14035                                }
  14036                            } else {
  14037                                if(ast.nodeType == TypeScript.NodeType.Catch) {
  14038                                    var catchBlock = ast;
  14039                                    if(catchBlock.param) {
  14040                                        popAssignScope(context);
  14041                                    }
  14042                                } else {
  14043                                    go = false;
  14044                                }
  14045                            }
  14046                        }
  14047                    }
  14048                }
  14049            }
  14050        }
  14051        walker.options.goChildren = go;
  14052        return ast;
  14053    }
  14054    TypeScript.postAssignScopes = postAssignScopes;
  14055 })(TypeScript || (TypeScript = {}));
  14056 var TypeScript;
  14057 (function (TypeScript) {
  14058    var TypeCollectionContext = (function () {
  14059        function TypeCollectionContext(scopeChain, checker) {
  14060            this.scopeChain = scopeChain;
  14061            this.checker = checker;
  14062            this.script = null;
  14063        }
  14064        return TypeCollectionContext;
  14065    })();
  14066    TypeScript.TypeCollectionContext = TypeCollectionContext;    
  14067    var MemberScopeContext = (function () {
  14068        function MemberScopeContext(flow, pos, matchFlag) {
  14069            this.flow = flow;
  14070            this.pos = pos;
  14071            this.matchFlag = matchFlag;
  14072            this.type = null;
  14073            this.ast = null;
  14074            this.options = new TypeScript.AstWalkOptions();
  14075        }
  14076        return MemberScopeContext;
  14077    })();
  14078    TypeScript.MemberScopeContext = MemberScopeContext;    
  14079    var EnclosingScopeContext = (function () {
  14080        function EnclosingScopeContext(logger, script, text, pos, isMemberCompletion) {
  14081            this.logger = logger;
  14082            this.script = script;
  14083            this.text = text;
  14084            this.pos = pos;
  14085            this.isMemberCompletion = isMemberCompletion;
  14086            this.scopeGetter = null;
  14087            this.objectLiteralScopeGetter = null;
  14088            this.scopeStartAST = null;
  14089            this.skipNextFuncDeclForClass = false;
  14090            this.deepestModuleDecl = null;
  14091            this.enclosingClassDecl = null;
  14092            this.enclosingObjectLit = null;
  14093            this.publicsOnly = true;
  14094            this.useFullAst = false;
  14095        }
  14096        EnclosingScopeContext.prototype.getScope = function () {
  14097            return this.scopeGetter();
  14098        };
  14099        EnclosingScopeContext.prototype.getObjectLiteralScope = function () {
  14100            return this.objectLiteralScopeGetter();
  14101        };
  14102        EnclosingScopeContext.prototype.getScopeAST = function () {
  14103            return this.scopeStartAST;
  14104        };
  14105        EnclosingScopeContext.prototype.getScopePosition = function () {
  14106            return this.scopeStartAST.minChar;
  14107        };
  14108        EnclosingScopeContext.prototype.getScriptFragmentStartAST = function () {
  14109            return this.scopeStartAST;
  14110        };
  14111        EnclosingScopeContext.prototype.getScriptFragmentPosition = function () {
  14112            return this.getScriptFragmentStartAST().minChar;
  14113        };
  14114        EnclosingScopeContext.prototype.getScriptFragment = function () {
  14115            if(this.scriptFragment == null) {
  14116                var ast = this.getScriptFragmentStartAST();
  14117                var minChar = ast.minChar;
  14118                var limChar = (this.isMemberCompletion ? this.pos : this.pos + 1);
  14119                this.scriptFragment = TypeScript.quickParse(this.logger, ast, this.text, minChar, limChar, null).Script;
  14120            }
  14121            return this.scriptFragment;
  14122        };
  14123        return EnclosingScopeContext;
  14124    })();
  14125    TypeScript.EnclosingScopeContext = EnclosingScopeContext;    
  14126    function preFindMemberScope(ast, parent, walker) {
  14127        var memScope = walker.state;
  14128        if(TypeScript.hasFlag(ast.flags, memScope.matchFlag) && ((memScope.pos < 0) || (memScope.pos == ast.limChar))) {
  14129            memScope.ast = ast;
  14130            if((ast.type == null) && (memScope.pos >= 0)) {
  14131                memScope.flow.inScopeTypeCheck(ast, memScope.scope);
  14132            }
  14133            memScope.type = ast.type;
  14134            memScope.options.stopWalk();
  14135        }
  14136        return ast;
  14137    }
  14138    TypeScript.preFindMemberScope = preFindMemberScope;
  14139    function pushTypeCollectionScope(container, valueMembers, ambientValueMembers, enclosedTypes, ambientEnclosedTypes, context, thisType, classType, moduleDecl) {
  14140        var builder = new TypeScript.SymbolScopeBuilder(valueMembers, ambientValueMembers, enclosedTypes, ambientEnclosedTypes, null, container);
  14141        var chain = new TypeScript.ScopeChain(container, context.scopeChain, builder);
  14142        chain.thisType = thisType;
  14143        chain.classType = classType;
  14144        chain.moduleDecl = moduleDecl;
  14145        context.scopeChain = chain;
  14146    }
  14147    TypeScript.pushTypeCollectionScope = pushTypeCollectionScope;
  14148    function popTypeCollectionScope(context) {
  14149        context.scopeChain = context.scopeChain.previous;
  14150    }
  14151    TypeScript.popTypeCollectionScope = popTypeCollectionScope;
  14152    function preFindEnclosingScope(ast, parent, walker) {
  14153        var context = walker.state;
  14154        var minChar = ast.minChar;
  14155        var limChar = ast.limChar;
  14156        if(ast.nodeType == TypeScript.NodeType.Script && context.pos > limChar) {
  14157            limChar = context.pos;
  14158        }
  14159        if((minChar <= context.pos) && (limChar >= context.pos)) {
  14160            switch(ast.nodeType) {
  14161                case TypeScript.NodeType.Script: {
  14162                    var script = ast;
  14163                    context.scopeGetter = function () {
  14164                        return script.bod === null ? null : script.bod.enclosingScope;
  14165                    };
  14166                    context.scopeStartAST = script;
  14167                    break;
  14168 
  14169                }
  14170                case TypeScript.NodeType.ClassDeclaration: {
  14171                    context.scopeGetter = function () {
  14172                        return (ast.type === null || ast.type.instanceType.containedScope === null) ? null : ast.type.instanceType.containedScope;
  14173                    };
  14174                    context.scopeStartAST = ast;
  14175                    context.enclosingClassDecl = ast;
  14176                    break;
  14177 
  14178                }
  14179                case TypeScript.NodeType.ObjectLit: {
  14180                    var objectLit = ast;
  14181                    if(objectLit.targetType) {
  14182                        context.scopeGetter = function () {
  14183                            return objectLit.targetType.containedScope;
  14184                        };
  14185                        context.objectLiteralScopeGetter = function () {
  14186                            return objectLit.targetType.memberScope;
  14187                        };
  14188                        context.enclosingObjectLit = objectLit;
  14189                    }
  14190                    break;
  14191 
  14192                }
  14193                case TypeScript.NodeType.ModuleDeclaration: {
  14194                    context.deepestModuleDecl = ast;
  14195                    context.scopeGetter = function () {
  14196                        return ast.type === null ? null : ast.type.containedScope;
  14197                    };
  14198                    context.scopeStartAST = ast;
  14199                    break;
  14200 
  14201                }
  14202                case TypeScript.NodeType.InterfaceDeclaration: {
  14203                    context.scopeGetter = function () {
  14204                        return (ast.type === null) ? null : ast.type.containedScope;
  14205                    };
  14206                    context.scopeStartAST = ast;
  14207                    break;
  14208 
  14209                }
  14210                case TypeScript.NodeType.FuncDecl: {
  14211 {
  14212                        var funcDecl = ast;
  14213                        if(context.skipNextFuncDeclForClass) {
  14214                            context.skipNextFuncDeclForClass = false;
  14215                        } else {
  14216                            context.scopeGetter = function () {
  14217                                if(funcDecl.isConstructor && TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.ClassMethod)) {
  14218                                    if(ast.type && ast.type.enclosingType) {
  14219                                        return ast.type.enclosingType.constructorScope;
  14220                                    }
  14221                                }
  14222                                if(funcDecl.scopeType) {
  14223                                    return funcDecl.scopeType.containedScope;
  14224                                }
  14225                                if(funcDecl.type) {
  14226                                    return funcDecl.type.containedScope;
  14227                                }
  14228                                return null;
  14229                            };
  14230                            context.scopeStartAST = ast;
  14231                        }
  14232                    }
  14233                    break;
  14234 
  14235                }
  14236            }
  14237            walker.options.goChildren = true;
  14238        } else {
  14239            walker.options.goChildren = false;
  14240        }
  14241        return ast;
  14242    }
  14243    TypeScript.preFindEnclosingScope = preFindEnclosingScope;
  14244    function findEnclosingScopeAt(logger, script, text, pos, isMemberCompletion) {
  14245        var context = new EnclosingScopeContext(logger, script, text, pos, isMemberCompletion);
  14246        TypeScript.getAstWalkerFactory().walk(script, preFindEnclosingScope, null, null, context);
  14247        if(context.scopeStartAST === null) {
  14248            return null;
  14249        }
  14250        return context;
  14251    }
  14252    TypeScript.findEnclosingScopeAt = findEnclosingScopeAt;
  14253 })(TypeScript || (TypeScript = {}));
  14254 var TypeScript;
  14255 (function (TypeScript) {
  14256    var Signature = (function () {
  14257        function Signature() {
  14258            this.hasVariableArgList = false;
  14259            this.parameters = null;
  14260            this.declAST = null;
  14261            this.typeCheckStatus = TypeScript.TypeCheckStatus.NotStarted;
  14262            this.nonOptionalParameterCount = 0;
  14263        }
  14264        Signature.prototype.specializeType = function (pattern, replacement, checker) {
  14265            var result = new Signature();
  14266            if(this.hasVariableArgList) {
  14267                result.hasVariableArgList = true;
  14268            }
  14269            result.returnType = new TypeScript.TypeLink();
  14270            if(this.returnType.type) {
  14271                result.returnType.type = this.returnType.type.specializeType(pattern, replacement, checker, false);
  14272            } else {
  14273                result.returnType.type = checker.anyType;
  14274            }
  14275            if(this.parameters) {
  14276                result.parameters = [];
  14277                for(var i = 0, len = this.parameters.length; i < len; i++) {
  14278                    var oldSym = this.parameters[i];
  14279                    var paramDef = new TypeScript.ValueLocation();
  14280                    var paramSym = new TypeScript.ParameterSymbol(oldSym.name, oldSym.location, checker.locationInfo.unitIndex, paramDef);
  14281                    paramSym.declAST = this.declAST;
  14282                    paramDef.symbol = paramSym;
  14283                    paramDef.typeLink = new TypeScript.TypeLink();
  14284                    result.parameters[i] = paramSym;
  14285                    var oldType = oldSym.getType();
  14286                    if(oldType) {
  14287                        paramDef.typeLink.type = oldType.specializeType(pattern, replacement, checker, false);
  14288                        paramSym.declAST.type = paramDef.typeLink.type;
  14289                    } else {
  14290                        paramDef.typeLink.type = checker.anyType;
  14291                    }
  14292                }
  14293            }
  14294            result.nonOptionalParameterCount = this.nonOptionalParameterCount;
  14295            result.declAST = this.declAST;
  14296            return result;
  14297        };
  14298        Signature.prototype.toString = function () {
  14299            return this.toStringHelper(false, false, null);
  14300        };
  14301        Signature.prototype.toStringHelper = function (shortform, brackets, scope) {
  14302            return this.toStringHelperEx(shortform, brackets, scope).toString();
  14303        };
  14304        Signature.prototype.toStringHelperEx = function (shortform, brackets, scope, prefix) {
  14305            if (typeof prefix === "undefined") { prefix = ""; }
  14306            var builder = new TypeScript.MemberNameArray();
  14307            if(brackets) {
  14308                builder.prefix = prefix + "[";
  14309            } else {
  14310                builder.prefix = prefix + "(";
  14311            }
  14312            var paramLen = this.parameters.length;
  14313            var len = this.hasVariableArgList ? paramLen - 1 : paramLen;
  14314            for(var i = 0; i < len; i++) {
  14315                builder.add(TypeScript.MemberName.create(this.parameters[i].name + (this.parameters[i].isOptional() ? "?" : "") + ": "));
  14316                builder.add(this.parameters[i].getType().getScopedTypeNameEx(scope));
  14317                if(i < paramLen - 1) {
  14318                    builder.add(TypeScript.MemberName.create(", "));
  14319                }
  14320            }
  14321            if(this.hasVariableArgList) {
  14322                builder.add(TypeScript.MemberName.create("..." + this.parameters[i].name + ": "));
  14323                builder.add(this.parameters[i].getType().getScopedTypeNameEx(scope));
  14324            }
  14325            if(shortform) {
  14326                if(brackets) {
  14327                    builder.add(TypeScript.MemberName.create("] => "));
  14328                } else {
  14329                    builder.add(TypeScript.MemberName.create(") => "));
  14330                }
  14331            } else {
  14332                if(brackets) {
  14333                    builder.add(TypeScript.MemberName.create("]: "));
  14334                } else {
  14335                    builder.add(TypeScript.MemberName.create("): "));
  14336                }
  14337            }
  14338            if(this.returnType.type) {
  14339                builder.add(this.returnType.type.getScopedTypeNameEx(scope));
  14340            } else {
  14341                builder.add(TypeScript.MemberName.create("any"));
  14342            }
  14343            return builder;
  14344        };
  14345        return Signature;
  14346    })();
  14347    TypeScript.Signature = Signature;    
  14348    var SignatureGroup = (function () {
  14349        function SignatureGroup() {
  14350            this.signatures = [];
  14351            this.hasImplementation = true;
  14352            this.definitionSignature = null;
  14353            this.hasBeenTypechecked = false;
  14354            this.flags = TypeScript.SignatureFlags.None;
  14355        }
  14356        SignatureGroup.prototype.addSignature = function (signature) {
  14357            if(this.signatures == null) {
  14358                this.signatures = new Array();
  14359            }
  14360            this.signatures[this.signatures.length] = signature;
  14361            if(signature.declAST && !signature.declAST.isOverload && !signature.declAST.isSignature() && !TypeScript.hasFlag(signature.declAST.fncFlags, TypeScript.FncFlags.Ambient) && TypeScript.hasFlag(signature.declAST.fncFlags, TypeScript.FncFlags.Definition)) {
  14362                this.definitionSignature = signature;
  14363            }
  14364        };
  14365        SignatureGroup.prototype.toString = function () {
  14366            return this.signatures.toString();
  14367        };
  14368        SignatureGroup.prototype.toStrings = function (prefix, shortform, scope) {
  14369            var result = [];
  14370            var len = this.signatures.length;
  14371            if(len > 1) {
  14372                shortform = false;
  14373            }
  14374            for(var i = 0; i < len; i++) {
  14375                if(len > 1 && this.signatures[i] == this.definitionSignature) {
  14376                    continue;
  14377                }
  14378                if(this.flags & TypeScript.SignatureFlags.IsIndexer) {
  14379                    result.push(this.signatures[i].toStringHelperEx(shortform, true, scope));
  14380                } else {
  14381                    result.push(this.signatures[i].toStringHelperEx(shortform, false, scope, prefix));
  14382                }
  14383            }
  14384            return result;
  14385        };
  14386        SignatureGroup.prototype.specializeType = function (pattern, replacement, checker) {
  14387            var result = new SignatureGroup();
  14388            if(this.signatures) {
  14389                for(var i = 0, len = this.signatures.length; i < len; i++) {
  14390                    result.addSignature(this.signatures[i].specializeType(pattern, replacement, checker));
  14391                }
  14392            }
  14393            return result;
  14394        };
  14395        SignatureGroup.prototype.verifySignatures = function (checker) {
  14396            var len = 0;
  14397            if(this.signatures && ((len = this.signatures.length) > 0)) {
  14398                for(var i = 0; i < len; i++) {
  14399                    for(var j = i + 1; j < len; j++) {
  14400                        if(this.signatures[i].declAST && this.signatures[j].declAST && (!TypeScript.hasFlag(this.signatures[i].declAST.fncFlags, TypeScript.FncFlags.Definition) && !TypeScript.hasFlag(this.signatures[j].declAST.fncFlags, TypeScript.FncFlags.Definition)) && checker.signaturesAreIdentical(this.signatures[i], this.signatures[j])) {
  14401                            checker.errorReporter.simpleError(this.signatures[i].declAST, (this.signatures[i].declAST && this.signatures[i].declAST.name) ? "Signature for '" + this.signatures[i].declAST.name.actualText + "' is duplicated" : "Signature is duplicated");
  14402                        }
  14403                    }
  14404                    if(this.definitionSignature) {
  14405                        if(!checker.signatureIsAssignableToTarget(this.definitionSignature, this.signatures[i])) {
  14406                            checker.errorReporter.simpleError(this.signatures[i].declAST, "Overload signature is not compatible with function definition");
  14407                        }
  14408                    }
  14409                }
  14410            }
  14411        };
  14412        SignatureGroup.prototype.typeCheck = function (checker, ast, hasConstruct) {
  14413            if(this.hasBeenTypechecked) {
  14414                return;
  14415            }
  14416            this.hasBeenTypechecked = true;
  14417            var len = 0;
  14418            if(this.signatures && ((len = this.signatures.length) > 0)) {
  14419                for(var i = 0; i < len; i++) {
  14420                    if(!hasConstruct && !this.definitionSignature && this.signatures[i].declAST && this.signatures[i].declAST.isOverload && !TypeScript.hasFlag(this.signatures[i].declAST.fncFlags, TypeScript.FncFlags.Ambient)) {
  14421                        checker.errorReporter.simpleError(this.signatures[i].declAST, "Overload declaration lacks definition");
  14422                    }
  14423                    if(this.signatures[i].declAST && this.signatures[i].declAST.isConstructor && this.signatures[i].declAST.classDecl && this.signatures[i].declAST.classDecl.type.symbol.typeCheckStatus == TypeScript.TypeCheckStatus.NotStarted) {
  14424                        checker.typeFlow.typeCheck(this.signatures[i].declAST.classDecl);
  14425                    }
  14426                    checker.typeFlow.typeCheck(this.signatures[i].declAST);
  14427                }
  14428                this.verifySignatures(checker);
  14429            }
  14430        };
  14431        return SignatureGroup;
  14432    })();
  14433    TypeScript.SignatureGroup = SignatureGroup;    
  14434 })(TypeScript || (TypeScript = {}));
  14435 var TypeScript;
  14436 (function (TypeScript) {
  14437    (function (TypeCheckStatus) {
  14438        TypeCheckStatus._map = [];
  14439        TypeCheckStatus._map[0] = "NotStarted";
  14440        TypeCheckStatus.NotStarted = 0;
  14441        TypeCheckStatus._map[1] = "Started";
  14442        TypeCheckStatus.Started = 1;
  14443        TypeCheckStatus._map[2] = "Finished";
  14444        TypeCheckStatus.Finished = 2;
  14445    })(TypeScript.TypeCheckStatus || (TypeScript.TypeCheckStatus = {}));
  14446    var TypeCheckStatus = TypeScript.TypeCheckStatus;
  14447    function aLexicallyEnclosesB(a, b) {
  14448        if(a.declAST && b && b.declAST && a.declAST.nodeType == TypeScript.NodeType.FuncDecl) {
  14449            return a.declAST.minChar <= b.declAST.minChar && a.declAST.limChar >= b.declAST.limChar;
  14450        } else {
  14451            return false;
  14452        }
  14453    }
  14454    TypeScript.aLexicallyEnclosesB = aLexicallyEnclosesB;
  14455    function aEnclosesB(a, b) {
  14456        while(a.container) {
  14457            if(a == b || aLexicallyEnclosesB(a.container, b)) {
  14458                return true;
  14459            }
  14460            a = a.container;
  14461        }
  14462        return false;
  14463    }
  14464    TypeScript.aEnclosesB = aEnclosesB;
  14465    var Symbol = (function () {
  14466        function Symbol(name, location, length, unitIndex) {
  14467            this.name = name;
  14468            this.location = location;
  14469            this.length = length;
  14470            this.unitIndex = unitIndex;
  14471            this.bound = false;
  14472            this.flags = TypeScript.SymbolFlags.None;
  14473            this.isObjectLitField = false;
  14474            this.declAST = null;
  14475            this.declModule = null;
  14476            this.passSymbolCreated = TypeScript.CompilerDiagnostics.analysisPass;
  14477        }
  14478        Symbol.prototype.instanceScope = function () {
  14479            return null;
  14480        };
  14481        Symbol.prototype.isVariable = function () {
  14482            return false;
  14483        };
  14484        Symbol.prototype.isMember = function () {
  14485            return false;
  14486        };
  14487        Symbol.prototype.isInferenceSymbol = function () {
  14488            return false;
  14489        };
  14490        Symbol.prototype.isWith = function () {
  14491            return false;
  14492        };
  14493        Symbol.prototype.writeable = function () {
  14494            return false;
  14495        };
  14496        Symbol.prototype.isType = function () {
  14497            return false;
  14498        };
  14499        Symbol.prototype.getType = function () {
  14500            return null;
  14501        };
  14502        Symbol.prototype.isAccessor = function () {
  14503            return false;
  14504        };
  14505        Symbol.prototype.isInstanceProperty = function () {
  14506            return TypeScript.hasFlag(this.flags, TypeScript.SymbolFlags.Property) && (!TypeScript.hasFlag(this.flags, TypeScript.SymbolFlags.ModuleMember));
  14507        };
  14508        Symbol.prototype.getTypeName = function (scope) {
  14509            return this.getTypeNameEx(scope).toString();
  14510        };
  14511        Symbol.prototype.getTypeNameEx = function (scope) {
  14512            return TypeScript.MemberName.create(this.toString());
  14513        };
  14514        Symbol.prototype.getOptionalNameString = function () {
  14515            return TypeScript.hasFlag(this.flags, TypeScript.SymbolFlags.Optional) ? "?" : "";
  14516        };
  14517        Symbol.prototype.pathToRoot = function () {
  14518            var path = new Array();
  14519            var node = this;
  14520            while(node && (node.name != TypeScript.globalId)) {
  14521                path[path.length] = node;
  14522                node = node.container;
  14523            }
  14524            return path;
  14525        };
  14526        Symbol.prototype.findCommonAncestorPath = function (b) {
  14527            if(this.container == null) {
  14528                return new Array();
  14529            }
  14530            var aPath = this.container.pathToRoot();
  14531            var bPath;
  14532            if(b) {
  14533                bPath = b.pathToRoot();
  14534            } else {
  14535                bPath = new Array();
  14536            }
  14537            var commonNodeIndex = -1;
  14538            for(var i = 0, aLen = aPath.length; i < aLen; i++) {
  14539                var aNode = aPath[i];
  14540                for(var j = 0, bLen = bPath.length; j < bLen; j++) {
  14541                    var bNode = bPath[j];
  14542                    if(aNode == bNode) {
  14543                        commonNodeIndex = i;
  14544                        break;
  14545                    }
  14546                }
  14547                if(commonNodeIndex >= 0) {
  14548                    break;
  14549                }
  14550            }
  14551            if(commonNodeIndex >= 0) {
  14552                return aPath.slice(0, commonNodeIndex);
  14553            } else {
  14554                return aPath;
  14555            }
  14556        };
  14557        Symbol.prototype.getPrettyName = function (scopeSymbol) {
  14558            return this.name;
  14559        };
  14560        Symbol.prototype.scopeRelativeName = function (scope) {
  14561            if(scope == null) {
  14562                return this.getPrettyName(null) + this.getOptionalNameString();
  14563            }
  14564            var lca = this.findCommonAncestorPath(scope.container);
  14565            var builder = "";
  14566            for(var i = 0, len = lca.length; i < len; i++) {
  14567                var prettyName = lca[i].getPrettyName(i == len - 1 ? scope.container : lca[i + 1]);
  14568                builder = prettyName + "." + builder;
  14569            }
  14570            builder += this.getPrettyName(len == 0 ? scope.container : lca[0]) + this.getOptionalNameString();
  14571            return builder;
  14572        };
  14573        Symbol.prototype.fullName = function () {
  14574            var builder = this.name;
  14575            var ancestor = this.container;
  14576            while(ancestor && (ancestor.name != TypeScript.globalId)) {
  14577                builder = ancestor.name + "." + builder;
  14578                ancestor = ancestor.container;
  14579            }
  14580            return builder;
  14581        };
  14582        Symbol.prototype.isExternallyVisible = function (checker) {
  14583            if(this == checker.gloMod) {
  14584                return true;
  14585            }
  14586            if(TypeScript.hasFlag(this.flags, TypeScript.SymbolFlags.Private)) {
  14587                return false;
  14588            }
  14589            if(!TypeScript.hasFlag(this.flags, TypeScript.SymbolFlags.Exported)) {
  14590                return this.container == checker.gloMod;
  14591            }
  14592            return this.container.isExternallyVisible(checker);
  14593        };
  14594        Symbol.prototype.visible = function (scope, checker) {
  14595            if(checker == null || this.container == checker.gloMod) {
  14596                return true;
  14597            }
  14598            if(TypeScript.hasFlag(this.flags, TypeScript.SymbolFlags.ModuleMember)) {
  14599                if(TypeScript.hasFlag(this.flags, TypeScript.SymbolFlags.Exported)) {
  14600                    if(!TypeScript.hasFlag(this.flags, TypeScript.SymbolFlags.Private)) {
  14601                        return true;
  14602                    } else {
  14603                        return aEnclosesB(this, scope.container);
  14604                    }
  14605                } else {
  14606                    return checker && (checker.currentModDecl == this.declModule) || (checker.currentModDecl && checker.currentModDecl.mod && checker.currentModDecl.mod.symbol && this.declModule && this.declModule.mod && this.declModule.mod.symbol && aEnclosesB(checker.currentModDecl.mod.symbol, this.declModule.mod.symbol));
  14607                }
  14608            } else {
  14609                var isFunction = this.declAST && this.declAST.nodeType == TypeScript.NodeType.FuncDecl;
  14610                var isMethod = isFunction && (this.declAST).isMethod();
  14611                var isStaticFunction = isFunction && TypeScript.hasFlag((this.declAST).fncFlags, TypeScript.FncFlags.Static);
  14612                var isPrivateMethod = isMethod && TypeScript.hasFlag((this.declAST).fncFlags, TypeScript.FncFlags.Private);
  14613                var isAlias = this.isType() && (this).aliasLink;
  14614                if(this.isMember() || isMethod || isStaticFunction || isAlias) {
  14615                    if(TypeScript.hasFlag(this.flags, TypeScript.SymbolFlags.Private) || isPrivateMethod) {
  14616                        if(scope.container == null && this.container != scope.container) {
  14617                            return false;
  14618                        } else {
  14619                            return this.container == null ? true : aEnclosesB(scope.container, this.container);
  14620                        }
  14621                    } else {
  14622                        return true;
  14623                    }
  14624                } else {
  14625                    if(this.container) {
  14626                        return aEnclosesB(this, scope.container);
  14627                    } else {
  14628                        return true;
  14629                    }
  14630                }
  14631            }
  14632        };
  14633        Symbol.prototype.addRef = function (identifier) {
  14634            if(!this.refs) {
  14635                this.refs = [];
  14636            }
  14637            this.refs[this.refs.length] = identifier;
  14638        };
  14639        Symbol.prototype.toString = function () {
  14640            if(this.name) {
  14641                return this.name;
  14642            } else {
  14643                return "_anonymous";
  14644            }
  14645        };
  14646        Symbol.prototype.print = function (outfile) {
  14647            outfile.Write(this.toString());
  14648        };
  14649        Symbol.prototype.specializeType = function (pattern, replacement, checker) {
  14650            throw new Error("please implement in derived class");
  14651        };
  14652        Symbol.prototype.setType = function (type) {
  14653            throw new Error("please implement in derived class");
  14654        };
  14655        Symbol.prototype.kind = function () {
  14656            throw new Error("please implement in derived class");
  14657        };
  14658        Symbol.prototype.getInterfaceDeclFromSymbol = function (checker) {
  14659            if(this.declAST != null) {
  14660                if(this.declAST.nodeType == TypeScript.NodeType.InterfaceDeclaration) {
  14661                    return this.declAST;
  14662                } else {
  14663                    if(this.container != null && this.container != checker.gloMod && this.container.declAST.nodeType == TypeScript.NodeType.InterfaceDeclaration) {
  14664                        return this.container.declAST;
  14665                    }
  14666                }
  14667            }
  14668            return null;
  14669        };
  14670        Symbol.prototype.getVarDeclFromSymbol = function () {
  14671            if(this.declAST != null && this.declAST.nodeType == TypeScript.NodeType.VarDecl) {
  14672                return this.declAST;
  14673            }
  14674            return null;
  14675        };
  14676        Symbol.prototype.getDocComments = function () {
  14677            if(this.declAST != null) {
  14678                return this.declAST.getDocComments();
  14679            }
  14680            return [];
  14681        };
  14682        Symbol.prototype.isStatic = function () {
  14683            return TypeScript.hasFlag(this.flags, TypeScript.SymbolFlags.Static);
  14684        };
  14685        return Symbol;
  14686    })();
  14687    TypeScript.Symbol = Symbol;    
  14688    var ValueLocation = (function () {
  14689        function ValueLocation() { }
  14690        return ValueLocation;
  14691    })();
  14692    TypeScript.ValueLocation = ValueLocation;    
  14693    var InferenceSymbol = (function (_super) {
  14694        __extends(InferenceSymbol, _super);
  14695        function InferenceSymbol(name, location, length, unitIndex) {
  14696                _super.call(this, name, location, length, unitIndex);
  14697            this.typeCheckStatus = TypeCheckStatus.NotStarted;
  14698        }
  14699        InferenceSymbol.prototype.isInferenceSymbol = function () {
  14700            return true;
  14701        };
  14702        InferenceSymbol.prototype.transferVarFlags = function (varFlags) {
  14703            if(TypeScript.hasFlag(varFlags, TypeScript.VarFlags.Ambient)) {
  14704                this.flags |= TypeScript.SymbolFlags.Ambient;
  14705            }
  14706            if(TypeScript.hasFlag(varFlags, TypeScript.VarFlags.Constant)) {
  14707                this.flags |= TypeScript.SymbolFlags.Constant;
  14708            }
  14709            if(TypeScript.hasFlag(varFlags, TypeScript.VarFlags.Static)) {
  14710                this.flags |= TypeScript.SymbolFlags.Static;
  14711            }
  14712            if(TypeScript.hasFlag(varFlags, TypeScript.VarFlags.Property)) {
  14713                this.flags |= TypeScript.SymbolFlags.Property;
  14714            }
  14715            if(TypeScript.hasFlag(varFlags, TypeScript.VarFlags.Private)) {
  14716                this.flags |= TypeScript.SymbolFlags.Private;
  14717            }
  14718            if(TypeScript.hasFlag(varFlags, TypeScript.VarFlags.Public)) {
  14719                this.flags |= TypeScript.SymbolFlags.Public;
  14720            }
  14721            if(TypeScript.hasFlag(varFlags, TypeScript.VarFlags.Readonly)) {
  14722                this.flags |= TypeScript.SymbolFlags.Readonly;
  14723            }
  14724            if(TypeScript.hasFlag(varFlags, TypeScript.VarFlags.Exported)) {
  14725                this.flags |= TypeScript.SymbolFlags.Exported;
  14726            }
  14727        };
  14728        return InferenceSymbol;
  14729    })(Symbol);
  14730    TypeScript.InferenceSymbol = InferenceSymbol;    
  14731    var TypeSymbol = (function (_super) {
  14732        __extends(TypeSymbol, _super);
  14733        function TypeSymbol(locName, location, length, unitIndex, type) {
  14734                _super.call(this, locName, location, length, unitIndex);
  14735            this.type = type;
  14736            this.expansions = [];
  14737            this.expansionsDeclAST = [];
  14738            this.isDynamic = false;
  14739            this.isMethod = false;
  14740            this.aliasLink = null;
  14741            this.onlyReferencedAsTypeRef = TypeScript.optimizeModuleCodeGen;
  14742            this.prettyName = this.name;
  14743        }
  14744        TypeSymbol.prototype.addLocation = function (loc) {
  14745            if(this.additionalLocations == null) {
  14746                this.additionalLocations = [];
  14747            }
  14748            this.additionalLocations[this.additionalLocations.length] = loc;
  14749        };
  14750        TypeSymbol.prototype.kind = function () {
  14751            return TypeScript.SymbolKind.Type;
  14752        };
  14753        TypeSymbol.prototype.isType = function () {
  14754            return true;
  14755        };
  14756        TypeSymbol.prototype.getType = function () {
  14757            return this.type;
  14758        };
  14759        TypeSymbol.prototype.getTypeNameEx = function (scope) {
  14760            return this.type.getMemberTypeNameEx(this.name ? this.name + this.getOptionalNameString() : "", false, false, scope);
  14761        };
  14762        TypeSymbol.prototype.instanceScope = function () {
  14763            if(!(this.type.typeFlags & TypeScript.TypeFlags.IsClass) && this.type.isClass()) {
  14764                return this.type.instanceType.constructorScope;
  14765            } else {
  14766                return this.type.containedScope;
  14767            }
  14768        };
  14769        TypeSymbol.prototype.toString = function () {
  14770            var result = this.type.getTypeName();
  14771            if(this.name) {
  14772                result = this.name + ":" + result;
  14773            }
  14774            return result;
  14775        };
  14776        TypeSymbol.prototype.isClass = function () {
  14777            return this.instanceType != null;
  14778        };
  14779        TypeSymbol.prototype.isFunction = function () {
  14780            return this.declAST != null && this.declAST.nodeType == TypeScript.NodeType.FuncDecl;
  14781        };
  14782        TypeSymbol.prototype.specializeType = function (pattern, replacement, checker) {
  14783            if(this.type == pattern) {
  14784                return replacement.symbol;
  14785            } else {
  14786                var replType = this.type.specializeType(pattern, replacement, checker, false);
  14787                if(replType != this.type) {
  14788                    var result = new TypeSymbol(this.name, -1, 0, -1, replType);
  14789                    return result;
  14790                } else {
  14791                    return this;
  14792                }
  14793            }
  14794        };
  14795        TypeSymbol.prototype.getPrettyName = function (scopeSymbol) {
  14796            if(!!scopeSymbol && TypeScript.isQuoted(this.prettyName) && this.type.isModuleType()) {
  14797                var symbolPath = scopeSymbol.pathToRoot();
  14798                var prettyName = this.getPrettyNameOfDynamicModule(symbolPath);
  14799                if(prettyName != null) {
  14800                    return prettyName.name;
  14801                }
  14802            }
  14803            return this.prettyName;
  14804        };
  14805        TypeSymbol.prototype.getPrettyNameOfDynamicModule = function (scopeSymbolPath) {
  14806            var scopeSymbolPathLength = scopeSymbolPath.length;
  14807            var externalSymbol = null;
  14808            if(scopeSymbolPath.length > 0 && scopeSymbolPath[scopeSymbolPathLength - 1].getType().isModuleType() && (scopeSymbolPath[scopeSymbolPathLength - 1]).isDynamic) {
  14809                if(scopeSymbolPathLength > 1 && scopeSymbolPath[scopeSymbolPathLength - 2].getType().isModuleType() && (scopeSymbolPath[scopeSymbolPathLength - 2]).isDynamic) {
  14810                    var moduleType = scopeSymbolPath[scopeSymbolPathLength - 2].getType();
  14811                    externalSymbol = moduleType.findDynamicModuleName(this.type);
  14812                }
  14813                if(externalSymbol == null) {
  14814                    var moduleType = scopeSymbolPath[scopeSymbolPathLength - 1].getType();
  14815                    externalSymbol = moduleType.findDynamicModuleName(this.type);
  14816                }
  14817            }
  14818            return externalSymbol;
  14819        };
  14820        TypeSymbol.prototype.getDocComments = function () {
  14821            var comments = [];
  14822            if(this.declAST != null) {
  14823                comments = comments.concat(this.declAST.getDocComments());
  14824            }
  14825            for(var i = 0; i < this.expansionsDeclAST.length; i++) {
  14826                comments = comments.concat(this.expansionsDeclAST[i].getDocComments());
  14827            }
  14828            return comments;
  14829        };
  14830        return TypeSymbol;
  14831    })(InferenceSymbol);
  14832    TypeScript.TypeSymbol = TypeSymbol;    
  14833    var WithSymbol = (function (_super) {
  14834        __extends(WithSymbol, _super);
  14835        function WithSymbol(location, unitIndex, withType) {
  14836                _super.call(this, "with", location, 4, unitIndex, withType);
  14837        }
  14838        WithSymbol.prototype.isWith = function () {
  14839            return true;
  14840        };
  14841        return WithSymbol;
  14842    })(TypeSymbol);
  14843    TypeScript.WithSymbol = WithSymbol;    
  14844    var FieldSymbol = (function (_super) {
  14845        __extends(FieldSymbol, _super);
  14846        function FieldSymbol(name, location, unitIndex, canWrite, field) {
  14847                _super.call(this, name, location, name.length, unitIndex);
  14848            this.canWrite = canWrite;
  14849            this.field = field;
  14850            this.getter = null;
  14851            this.setter = null;
  14852            this.hasBeenEmitted = false;
  14853            this.name = name;
  14854            this.location = location;
  14855        }
  14856        FieldSymbol.prototype.kind = function () {
  14857            return TypeScript.SymbolKind.Field;
  14858        };
  14859        FieldSymbol.prototype.writeable = function () {
  14860            return this.isAccessor() ? this.setter != null : this.canWrite;
  14861        };
  14862        FieldSymbol.prototype.getType = function () {
  14863            return this.field.typeLink.type;
  14864        };
  14865        FieldSymbol.prototype.getTypeNameEx = function (scope) {
  14866            return TypeScript.MemberName.create(this.field.typeLink.type.getScopedTypeNameEx(scope), this.name + this.getOptionalNameString() + ": ", "");
  14867        };
  14868        FieldSymbol.prototype.isMember = function () {
  14869            return true;
  14870        };
  14871        FieldSymbol.prototype.setType = function (type) {
  14872            this.field.typeLink.type = type;
  14873        };
  14874        FieldSymbol.prototype.isAccessor = function () {
  14875            return this.getter != null || this.setter != null;
  14876        };
  14877        FieldSymbol.prototype.isVariable = function () {
  14878            return true;
  14879        };
  14880        FieldSymbol.prototype.toString = function () {
  14881            return this.getTypeNameEx(null).toString();
  14882        };
  14883        FieldSymbol.prototype.specializeType = function (pattern, replacement, checker) {
  14884            var rType = this.field.typeLink.type.specializeType(pattern, replacement, checker, false);
  14885            if(rType != this.field.typeLink.type) {
  14886                var fieldDef = new ValueLocation();
  14887                var result = new FieldSymbol(this.name, 0, checker.locationInfo.unitIndex, this.canWrite, fieldDef);
  14888                result.flags = this.flags;
  14889                fieldDef.symbol = result;
  14890                fieldDef.typeLink = new TypeScript.TypeLink();
  14891                result.setType(rType);
  14892                result.typeCheckStatus = TypeCheckStatus.Finished;
  14893                return result;
  14894            } else {
  14895                return this;
  14896            }
  14897        };
  14898        FieldSymbol.prototype.getDocComments = function () {
  14899            if(this.getter != null || this.setter != null) {
  14900                var comments = [];
  14901                if(this.getter != null) {
  14902                    comments = comments.concat(this.getter.getDocComments());
  14903                }
  14904                if(this.setter != null) {
  14905                    comments = comments.concat(this.setter.getDocComments());
  14906                }
  14907                return comments;
  14908            } else {
  14909                if(this.declAST != null) {
  14910                    return this.declAST.getDocComments();
  14911                }
  14912            }
  14913            return [];
  14914        };
  14915        return FieldSymbol;
  14916    })(InferenceSymbol);
  14917    TypeScript.FieldSymbol = FieldSymbol;    
  14918    var ParameterSymbol = (function (_super) {
  14919        __extends(ParameterSymbol, _super);
  14920        function ParameterSymbol(name, location, unitIndex, parameter) {
  14921                _super.call(this, name, location, name.length, unitIndex);
  14922            this.parameter = parameter;
  14923            this.paramDocComment = null;
  14924            this.funcDecl = null;
  14925            this.argsOffset = (-1);
  14926            this.name = name;
  14927            this.location = location;
  14928        }
  14929        ParameterSymbol.prototype.kind = function () {
  14930            return TypeScript.SymbolKind.Parameter;
  14931        };
  14932        ParameterSymbol.prototype.writeable = function () {
  14933            return true;
  14934        };
  14935        ParameterSymbol.prototype.getType = function () {
  14936            return this.parameter.typeLink.type;
  14937        };
  14938        ParameterSymbol.prototype.setType = function (type) {
  14939            this.parameter.typeLink.type = type;
  14940        };
  14941        ParameterSymbol.prototype.isVariable = function () {
  14942            return true;
  14943        };
  14944        ParameterSymbol.prototype.isOptional = function () {
  14945            if(this.parameter && this.parameter.symbol && this.parameter.symbol.declAST) {
  14946                return (this.parameter.symbol.declAST).isOptional;
  14947            } else {
  14948                return false;
  14949            }
  14950        };
  14951        ParameterSymbol.prototype.getTypeNameEx = function (scope) {
  14952            return TypeScript.MemberName.create(this.getType().getScopedTypeNameEx(scope), this.name + (this.isOptional() ? "?" : "") + ": ", "");
  14953        };
  14954        ParameterSymbol.prototype.toString = function () {
  14955            return this.getTypeNameEx(null).toString();
  14956        };
  14957        ParameterSymbol.prototype.specializeType = function (pattern, replacement, checker) {
  14958            var rType = this.parameter.typeLink.type.specializeType(pattern, replacement, checker, false);
  14959            if(this.parameter.typeLink.type != rType) {
  14960                var paramDef = new ValueLocation();
  14961                var result = new ParameterSymbol(this.name, 0, checker.locationInfo.unitIndex, paramDef);
  14962                paramDef.symbol = result;
  14963                result.setType(rType);
  14964                return result;
  14965            } else {
  14966                return this;
  14967            }
  14968        };
  14969        ParameterSymbol.prototype.getParameterDocComments = function () {
  14970            if(!this.paramDocComment) {
  14971                var parameterComments = [];
  14972                if(this.funcDecl) {
  14973                    var fncDocComments = this.funcDecl.getDocComments();
  14974                    var paramComment = TypeScript.Comment.getParameterDocCommentText(this.name, fncDocComments);
  14975                    if(paramComment != "") {
  14976                        parameterComments.push(paramComment);
  14977                    }
  14978                }
  14979                var docComments = TypeScript.Comment.getDocCommentText(this.getDocComments());
  14980                if(docComments != "") {
  14981                    parameterComments.push(docComments);
  14982                }
  14983                this.paramDocComment = parameterComments.join("\n");
  14984            }
  14985            return this.paramDocComment;
  14986        };
  14987        return ParameterSymbol;
  14988    })(InferenceSymbol);
  14989    TypeScript.ParameterSymbol = ParameterSymbol;    
  14990    var VariableSymbol = (function (_super) {
  14991        __extends(VariableSymbol, _super);
  14992        function VariableSymbol(name, location, unitIndex, variable) {
  14993                _super.call(this, name, location, name.length, unitIndex);
  14994            this.variable = variable;
  14995        }
  14996        VariableSymbol.prototype.kind = function () {
  14997            return TypeScript.SymbolKind.Variable;
  14998        };
  14999        VariableSymbol.prototype.writeable = function () {
  15000            return true;
  15001        };
  15002        VariableSymbol.prototype.getType = function () {
  15003            return this.variable.typeLink.type;
  15004        };
  15005        VariableSymbol.prototype.getTypeNameEx = function (scope) {
  15006            return TypeScript.MemberName.create(this.getType().getScopedTypeNameEx(scope), this.name + ": ", "");
  15007        };
  15008        VariableSymbol.prototype.setType = function (type) {
  15009            this.variable.typeLink.type = type;
  15010        };
  15011        VariableSymbol.prototype.isVariable = function () {
  15012            return true;
  15013        };
  15014        return VariableSymbol;
  15015    })(InferenceSymbol);
  15016    TypeScript.VariableSymbol = VariableSymbol;    
  15017 })(TypeScript || (TypeScript = {}));
  15018 var TypeScript;
  15019 (function (TypeScript) {
  15020    var ScopedMembers = (function () {
  15021        function ScopedMembers(dualMembers) {
  15022            this.dualMembers = dualMembers;
  15023            this.allMembers = this.dualMembers;
  15024            this.publicMembers = this.dualMembers.primaryTable;
  15025            this.privateMembers = this.dualMembers.secondaryTable;
  15026        }
  15027        ScopedMembers.prototype.addPublicMember = function (key, data) {
  15028            return this.dualMembers.primaryTable.add(key, data);
  15029        };
  15030        ScopedMembers.prototype.addPrivateMember = function (key, data) {
  15031            return this.dualMembers.secondaryTable.add(key, data);
  15032        };
  15033        return ScopedMembers;
  15034    })();
  15035    TypeScript.ScopedMembers = ScopedMembers;    
  15036    (function (SymbolKind) {
  15037        SymbolKind._map = [];
  15038        SymbolKind._map[0] = "None";
  15039        SymbolKind.None = 0;
  15040        SymbolKind._map[1] = "Type";
  15041        SymbolKind.Type = 1;
  15042        SymbolKind._map[2] = "Field";
  15043        SymbolKind.Field = 2;
  15044        SymbolKind._map[3] = "Parameter";
  15045        SymbolKind.Parameter = 3;
  15046        SymbolKind._map[4] = "Variable";
  15047        SymbolKind.Variable = 4;
  15048    })(TypeScript.SymbolKind || (TypeScript.SymbolKind = {}));
  15049    var SymbolKind = TypeScript.SymbolKind;
  15050    var SymbolScope = (function () {
  15051        function SymbolScope(container) {
  15052            this.container = container;
  15053        }
  15054        SymbolScope.prototype.printLabel = function () {
  15055            return "base";
  15056        };
  15057        SymbolScope.prototype.getAllSymbolNames = function (members) {
  15058            return [
  15059                "please", 
  15060                "implement", 
  15061                "in", 
  15062                "derived", 
  15063                "classes"
  15064            ];
  15065        };
  15066        SymbolScope.prototype.getAllTypeSymbolNames = function (members) {
  15067            return [
  15068                "please", 
  15069                "implement", 
  15070                "in", 
  15071                "derived", 
  15072                "classes"
  15073            ];
  15074        };
  15075        SymbolScope.prototype.getAllValueSymbolNames = function (members) {
  15076            return [
  15077                "please", 
  15078                "implement", 
  15079                "in", 
  15080                "derived", 
  15081                "classes"
  15082            ];
  15083        };
  15084        SymbolScope.prototype.search = function (filter, name, publicOnly, typespace) {
  15085            return null;
  15086        };
  15087        SymbolScope.prototype.findLocal = function (name, publicOnly, typespace) {
  15088            return null;
  15089        };
  15090        SymbolScope.prototype.find = function (name, publicOnly, typespace) {
  15091            return null;
  15092        };
  15093        SymbolScope.prototype.findImplementation = function (name, publicOnly, typespace) {
  15094            return null;
  15095        };
  15096        SymbolScope.prototype.findAmbient = function (name, publicOnly, typespace) {
  15097            return null;
  15098        };
  15099        SymbolScope.prototype.print = function (outfile) {
  15100            if(this.container) {
  15101                outfile.WriteLine(this.printLabel() + " scope with container: " + this.container.name + "...");
  15102            } else {
  15103                outfile.WriteLine(this.printLabel() + " scope...");
  15104            }
  15105        };
  15106        SymbolScope.prototype.enter = function (container, ast, symbol, errorReporter, publicOnly, typespace, ambient) {
  15107            throw new Error("please implement in derived class");
  15108        };
  15109        SymbolScope.prototype.getTable = function () {
  15110            throw new Error("please implement in derived class");
  15111        };
  15112        return SymbolScope;
  15113    })();
  15114    TypeScript.SymbolScope = SymbolScope;    
  15115    function symbolCanBeUsed(sym, publicOnly) {
  15116        return publicOnly ? !(TypeScript.hasFlag(sym.flags, TypeScript.SymbolFlags.Private) || (sym.declAST && sym.declAST.nodeType == TypeScript.NodeType.FuncDecl && TypeScript.hasFlag((sym.declAST).fncFlags, TypeScript.FncFlags.Private))) : true;
  15117    }
  15118    var SymbolAggregateScope = (function (_super) {
  15119        __extends(SymbolAggregateScope, _super);
  15120        function SymbolAggregateScope(container) {
  15121                _super.call(this, container);
  15122            this.valueCache = null;
  15123            this.valueImplCache = null;
  15124            this.valueAmbientCache = null;
  15125            this.typeCache = null;
  15126            this.typeImplCache = null;
  15127            this.typeAmbientCache = null;
  15128            this.parents = null;
  15129            this.container = container;
  15130        }
  15131        SymbolAggregateScope.prototype.printLabel = function () {
  15132            return "agg";
  15133        };
  15134        SymbolAggregateScope.prototype.search = function (filter, name, publicOnly, typespace) {
  15135            if(this.parents) {
  15136                for(var i = 0; i < this.parents.length; i++) {
  15137                    var sym = this.parents[i].search(filter, name, publicOnly, typespace);
  15138                    if(sym) {
  15139                        if(filter.update(sym)) {
  15140                            return sym;
  15141                        }
  15142                    }
  15143                }
  15144            }
  15145            return filter.result;
  15146        };
  15147        SymbolAggregateScope.prototype.getAllSymbolNames = function (members) {
  15148            var result = [];
  15149            if(this.parents) {
  15150                for(var i = 0; i < this.parents.length; i++) {
  15151                    var parentResult = this.parents[i].getAllSymbolNames(members);
  15152                    if(parentResult) {
  15153                        result = result.concat(parentResult);
  15154                    }
  15155                }
  15156            }
  15157            return result;
  15158        };
  15159        SymbolAggregateScope.prototype.getAllTypeSymbolNames = function (members) {
  15160            var result = [];
  15161            if(this.parents) {
  15162                for(var i = 0; i < this.parents.length; i++) {
  15163                    var parentResult = this.parents[i].getAllTypeSymbolNames(members);
  15164                    if(parentResult) {
  15165                        result = result.concat(parentResult);
  15166                    }
  15167                }
  15168            }
  15169            return result;
  15170        };
  15171        SymbolAggregateScope.prototype.getAllValueSymbolNames = function (members) {
  15172            var result = [];
  15173            if(this.parents) {
  15174                for(var i = 0; i < this.parents.length; i++) {
  15175                    var parentResult = this.parents[i].getAllValueSymbolNames(members);
  15176                    if(parentResult) {
  15177                        result = result.concat(parentResult);
  15178                    }
  15179                }
  15180            }
  15181            return result;
  15182        };
  15183        SymbolAggregateScope.prototype.print = function (outfile) {
  15184            _super.prototype.print.call(this, outfile);
  15185            if(this.parents) {
  15186                for(var i = 0; i < this.parents.length; i++) {
  15187                    this.parents[i].print(outfile);
  15188                }
  15189            }
  15190        };
  15191        SymbolAggregateScope.prototype.findImplementation = function (name, publicOnly, typespace) {
  15192            var sym = null;
  15193            var i = 0;
  15194            var implCache = this.valueImplCache;
  15195            if(typespace) {
  15196                implCache = this.typeImplCache;
  15197            }
  15198            if(implCache && ((sym = implCache.lookup(name)) != null) && (publicOnly ? !(TypeScript.hasFlag(sym.flags, TypeScript.SymbolFlags.Private) || (sym.declAST && sym.declAST.nodeType == TypeScript.NodeType.FuncDecl && TypeScript.hasFlag((sym.declAST).fncFlags, TypeScript.FncFlags.Private))) : true)) {
  15199                return sym;
  15200            }
  15201            if(this.parents) {
  15202                for(i = 0; i < this.parents.length; i++) {
  15203                    sym = this.parents[i].findImplementation(name, publicOnly, typespace);
  15204                    if(sym) {
  15205                        break;
  15206                    }
  15207                }
  15208            }
  15209            if(implCache) {
  15210                if(typespace) {
  15211                    this.typeImplCache = new TypeScript.StringHashTable();
  15212                    implCache = this.typeImplCache;
  15213                } else {
  15214                    this.valueImplCache = new TypeScript.StringHashTable();
  15215                    implCache = this.valueImplCache;
  15216                }
  15217            }
  15218            implCache.add(name, sym);
  15219            return sym;
  15220        };
  15221        SymbolAggregateScope.prototype.find = function (name, publicOnly, typespace) {
  15222            var sym = null;
  15223            var i = 0;
  15224            var cache = this.valueCache;
  15225            if(typespace) {
  15226                cache = this.typeCache;
  15227            }
  15228            if(cache && ((sym = cache.lookup(name)) != null) && (publicOnly ? !(TypeScript.hasFlag(sym.flags, TypeScript.SymbolFlags.Private) || (sym.declAST && sym.declAST.nodeType == TypeScript.NodeType.FuncDecl && TypeScript.hasFlag((sym.declAST).fncFlags, TypeScript.FncFlags.Private))) : true)) {
  15229                return sym;
  15230            }
  15231            if(this.parents) {
  15232                for(i = 0; i < this.parents.length; i++) {
  15233                    sym = this.parents[i].find(name, publicOnly, typespace);
  15234                    if(sym) {
  15235                        break;
  15236                    }
  15237                }
  15238            }
  15239            if(cache == null) {
  15240                if(typespace) {
  15241                    this.typeCache = new TypeScript.StringHashTable();
  15242                    cache = this.typeCache;
  15243                } else {
  15244                    this.valueCache = new TypeScript.StringHashTable();
  15245                    cache = this.valueCache;
  15246                }
  15247            }
  15248            cache.add(name, sym);
  15249            return sym;
  15250        };
  15251        SymbolAggregateScope.prototype.findAmbient = function (name, publicOnly, typespace) {
  15252            var sym = null;
  15253            var i = 0;
  15254            var cache = this.valueAmbientCache;
  15255            if(typespace) {
  15256                cache = this.typeAmbientCache;
  15257            }
  15258            if(cache && ((sym = cache.lookup(name)) != null)) {
  15259                return sym;
  15260            }
  15261            if(this.parents) {
  15262                for(i = 0; i < this.parents.length; i++) {
  15263                    sym = this.parents[i].findAmbient(name, publicOnly, typespace);
  15264                    if(sym) {
  15265                        break;
  15266                    }
  15267                }
  15268            }
  15269            if(cache == null) {
  15270                if(typespace) {
  15271                    this.typeAmbientCache = new TypeScript.StringHashTable();
  15272                    cache = this.typeAmbientCache;
  15273                } else {
  15274                    this.valueAmbientCache = new TypeScript.StringHashTable();
  15275                    cache = this.valueAmbientCache;
  15276                }
  15277            }
  15278            cache.add(name, sym);
  15279            return sym;
  15280        };
  15281        SymbolAggregateScope.prototype.addParentScope = function (parent) {
  15282            if(this.parents == null) {
  15283                this.parents = new Array();
  15284            }
  15285            this.parents[this.parents.length] = parent;
  15286        };
  15287        return SymbolAggregateScope;
  15288    })(SymbolScope);
  15289    TypeScript.SymbolAggregateScope = SymbolAggregateScope;    
  15290    var SymbolTableScope = (function (_super) {
  15291        __extends(SymbolTableScope, _super);
  15292        function SymbolTableScope(valueMembers, ambientValueMembers, enclosedTypes, ambientEnclosedTypes, container) {
  15293                _super.call(this, container);
  15294            this.valueMembers = valueMembers;
  15295            this.ambientValueMembers = ambientValueMembers;
  15296            this.enclosedTypes = enclosedTypes;
  15297            this.ambientEnclosedTypes = ambientEnclosedTypes;
  15298            this.container = container;
  15299        }
  15300        SymbolTableScope.prototype.printLabel = function () {
  15301            return "table";
  15302        };
  15303        SymbolTableScope.prototype.getAllSymbolNames = function (members) {
  15304            var result = this.getAllTypeSymbolNames(members);
  15305            return result.concat(this.getAllValueSymbolNames(members));
  15306        };
  15307        SymbolTableScope.prototype.getAllTypeSymbolNames = function (members) {
  15308            var result = [];
  15309            if(this.ambientEnclosedTypes) {
  15310                result = result.concat(this.ambientEnclosedTypes.allMembers.getAllKeys());
  15311            }
  15312            if(this.enclosedTypes) {
  15313                result = result.concat(this.enclosedTypes.allMembers.getAllKeys());
  15314            }
  15315            return result;
  15316        };
  15317        SymbolTableScope.prototype.getAllValueSymbolNames = function (members) {
  15318            var result = [];
  15319            if(this.ambientValueMembers) {
  15320                result = result.concat(this.ambientValueMembers.allMembers.getAllKeys());
  15321            }
  15322            if(this.valueMembers) {
  15323                result = result.concat(this.valueMembers.allMembers.getAllKeys());
  15324            }
  15325            return result;
  15326        };
  15327        SymbolTableScope.prototype.search = function (filter, name, publicOnly, typespace) {
  15328            var sym = this.find(name, publicOnly, typespace);
  15329            filter.update(sym);
  15330            return filter.result;
  15331        };
  15332        SymbolTableScope.prototype.find = function (name, publicOnly, typespace) {
  15333            var table = null;
  15334            var ambientTable = null;
  15335            if(typespace) {
  15336                table = (this.enclosedTypes == null) ? null : publicOnly ? this.enclosedTypes.publicMembers : this.enclosedTypes.allMembers;
  15337                ambientTable = (this.ambientEnclosedTypes == null) ? null : publicOnly ? this.ambientEnclosedTypes.publicMembers : this.ambientEnclosedTypes.allMembers;
  15338            } else {
  15339                table = (this.valueMembers == null) ? null : publicOnly ? this.valueMembers.publicMembers : this.valueMembers.allMembers;
  15340                ambientTable = (this.ambientValueMembers == null) ? null : publicOnly ? this.ambientValueMembers.publicMembers : this.ambientValueMembers.allMembers;
  15341            }
  15342            if(ambientTable) {
  15343                var s = ambientTable.lookup(name);
  15344                if(s) {
  15345                    return s;
  15346                }
  15347            }
  15348            if(table) {
  15349                var s = table.lookup(name);
  15350                if(s) {
  15351                    return s;
  15352                }
  15353            }
  15354            return null;
  15355        };
  15356        SymbolTableScope.prototype.findAmbient = function (name, publicOnly, typespace) {
  15357            var ambientTable = (this.ambientValueMembers == null) ? null : publicOnly ? this.ambientValueMembers.publicMembers : this.ambientValueMembers.allMembers;
  15358            if(typespace) {
  15359                ambientTable = (this.ambientEnclosedTypes == null) ? null : publicOnly ? this.ambientEnclosedTypes.publicMembers : this.ambientEnclosedTypes.allMembers;
  15360            }
  15361            if(ambientTable) {
  15362                var s = ambientTable.lookup(name);
  15363                if(s) {
  15364                    return s;
  15365                }
  15366            }
  15367            return null;
  15368        };
  15369        SymbolTableScope.prototype.print = function (outfile) {
  15370            _super.prototype.print.call(this, outfile);
  15371            if(this.ambientValueMembers) {
  15372                this.ambientValueMembers.allMembers.map(function (key, sym, context) {
  15373                    outfile.WriteLine("  " + key);
  15374                }, null);
  15375            }
  15376            if(this.valueMembers) {
  15377                this.valueMembers.allMembers.map(function (key, sym, context) {
  15378                    outfile.WriteLine("  " + key);
  15379                }, null);
  15380            }
  15381            if(this.ambientEnclosedTypes) {
  15382                this.ambientEnclosedTypes.allMembers.map(function (key, sym, context) {
  15383                    outfile.WriteLine("  " + key);
  15384                }, null);
  15385            }
  15386            if(this.enclosedTypes) {
  15387                this.enclosedTypes.allMembers.map(function (key, sym, context) {
  15388                    outfile.WriteLine("  " + key);
  15389                }, null);
  15390            }
  15391        };
  15392        SymbolTableScope.prototype.findImplementation = function (name, publicOnly, typespace) {
  15393            var sym = this.find(name, publicOnly, typespace);
  15394            if(sym) {
  15395                if(sym.kind() == SymbolKind.Type) {
  15396                    var typeSym = sym;
  15397                    if(!typeSym.type.hasImplementation()) {
  15398                        sym = null;
  15399                    }
  15400                } else {
  15401                    if(sym.container) {
  15402                        if(sym.container.kind() == SymbolKind.Type) {
  15403                            var ctypeSym = sym.container;
  15404                            if(!ctypeSym.type.hasImplementation()) {
  15405                                sym = null;
  15406                            }
  15407                        }
  15408                    }
  15409                }
  15410            }
  15411            return sym;
  15412        };
  15413        SymbolTableScope.prototype.getTable = function () {
  15414            return this.valueMembers.publicMembers;
  15415        };
  15416        return SymbolTableScope;
  15417    })(SymbolScope);
  15418    TypeScript.SymbolTableScope = SymbolTableScope;    
  15419    var SymbolScopeBuilder = (function (_super) {
  15420        __extends(SymbolScopeBuilder, _super);
  15421        function SymbolScopeBuilder(valueMembers, ambientValueMembers, enclosedTypes, ambientEnclosedTypes, parent, container) {
  15422                _super.call(this, container);
  15423            this.valueMembers = valueMembers;
  15424            this.ambientValueMembers = ambientValueMembers;
  15425            this.enclosedTypes = enclosedTypes;
  15426            this.ambientEnclosedTypes = ambientEnclosedTypes;
  15427            this.parent = parent;
  15428            this.container = container;
  15429        }
  15430        SymbolScopeBuilder.prototype.printLabel = function () {
  15431            return "builder";
  15432        };
  15433        SymbolScopeBuilder.prototype.getAllSymbolNames = function (members) {
  15434            var result = this.getAllTypeSymbolNames(members);
  15435            return result.concat(this.getAllValueSymbolNames(members));
  15436        };
  15437        SymbolScopeBuilder.prototype.getAllTypeSymbolNames = function (members) {
  15438            var result = [];
  15439            if(this.ambientEnclosedTypes) {
  15440                result = result.concat(this.ambientEnclosedTypes.allMembers.getAllKeys());
  15441            }
  15442            if(this.enclosedTypes) {
  15443                result = result.concat(this.enclosedTypes.allMembers.getAllKeys());
  15444            }
  15445            if(!members && this.parent) {
  15446                var parentResult = this.parent.getAllTypeSymbolNames(members);
  15447                if(parentResult) {
  15448                    result = result.concat(parentResult);
  15449                }
  15450            }
  15451            return result;
  15452        };
  15453        SymbolScopeBuilder.prototype.getAllValueSymbolNames = function (members) {
  15454            var result = [];
  15455            if(this.ambientValueMembers) {
  15456                result = result.concat(this.ambientValueMembers.allMembers.getAllKeys());
  15457            }
  15458            if(this.valueMembers) {
  15459                result = result.concat(this.valueMembers.allMembers.getAllKeys());
  15460            }
  15461            if(!members && this.parent) {
  15462                var parentResult = this.parent.getAllValueSymbolNames(members);
  15463                if(parentResult) {
  15464                    result = result.concat(parentResult);
  15465                }
  15466            }
  15467            return result;
  15468        };
  15469        SymbolScopeBuilder.prototype.search = function (filter, name, publicOnly, typespace) {
  15470            var sym = null;
  15471            var table = (this.valueMembers == null) ? null : publicOnly ? this.valueMembers.publicMembers : this.valueMembers.allMembers;
  15472            var ambientTable = (this.ambientValueMembers == null) ? null : publicOnly ? this.ambientValueMembers.publicMembers : this.ambientValueMembers.allMembers;
  15473            if(typespace) {
  15474                table = (this.enclosedTypes == null) ? null : publicOnly ? this.enclosedTypes.publicMembers : this.enclosedTypes.allMembers;
  15475                ambientTable = (this.ambientEnclosedTypes == null) ? null : publicOnly ? this.ambientEnclosedTypes.publicMembers : this.ambientEnclosedTypes.allMembers;
  15476            }
  15477            if(ambientTable) {
  15478                if((sym = ambientTable.lookup(name)) != null) {
  15479                    if(filter.update(sym)) {
  15480                        return sym;
  15481                    }
  15482                }
  15483            }
  15484            if(table) {
  15485                if((sym = table.lookup(name)) != null) {
  15486                    if(filter.update(sym)) {
  15487                        return sym;
  15488                    }
  15489                }
  15490            }
  15491            if(this.parent) {
  15492                sym = this.parent.search(filter, name, publicOnly, typespace);
  15493                if(sym) {
  15494                    if(filter.update(sym)) {
  15495                        return sym;
  15496                    }
  15497                }
  15498            }
  15499            return filter.result;
  15500        };
  15501        SymbolScopeBuilder.prototype.print = function (outfile) {
  15502            _super.prototype.print.call(this, outfile);
  15503            if(this.ambientValueMembers) {
  15504                this.ambientValueMembers.allMembers.map(function (key, s, context) {
  15505                    var sym = s;
  15506                    outfile.WriteLine("  " + key);
  15507                }, null);
  15508            }
  15509            if(this.valueMembers) {
  15510                this.valueMembers.allMembers.map(function (key, s, context) {
  15511                    var sym = s;
  15512                    outfile.WriteLine("  " + key);
  15513                }, null);
  15514            }
  15515            if(this.ambientEnclosedTypes) {
  15516                this.ambientEnclosedTypes.allMembers.map(function (key, s, context) {
  15517                    var sym = s;
  15518                    outfile.WriteLine("  " + key);
  15519                }, null);
  15520            }
  15521            if(this.enclosedTypes) {
  15522                this.enclosedTypes.allMembers.map(function (key, s, context) {
  15523                    var sym = s;
  15524                    outfile.WriteLine("  " + key);
  15525                }, null);
  15526            }
  15527            if(this.parent) {
  15528                this.parent.print(outfile);
  15529            }
  15530        };
  15531        SymbolScopeBuilder.prototype.find = function (name, publicOnly, typespace) {
  15532            var sym = null;
  15533            var table = (this.valueMembers == null) ? null : publicOnly ? this.valueMembers.publicMembers : this.valueMembers.allMembers;
  15534            var ambientTable = (this.ambientValueMembers == null) ? null : publicOnly ? this.ambientValueMembers.publicMembers : this.ambientValueMembers.allMembers;
  15535            if(typespace) {
  15536                table = (this.enclosedTypes == null) ? null : publicOnly ? this.enclosedTypes.publicMembers : this.enclosedTypes.allMembers;
  15537                ambientTable = (this.ambientEnclosedTypes == null) ? null : publicOnly ? this.ambientEnclosedTypes.publicMembers : this.ambientEnclosedTypes.allMembers;
  15538            }
  15539            if(ambientTable && ((sym = ambientTable.lookup(name)) != null)) {
  15540                return sym;
  15541            }
  15542            if(table && ((sym = table.lookup(name)) != null)) {
  15543                return sym;
  15544            }
  15545            if(this.parent) {
  15546                return this.parent.find(name, publicOnly, typespace);
  15547            }
  15548            return null;
  15549        };
  15550        SymbolScopeBuilder.prototype.findAmbient = function (name, publicOnly, typespace) {
  15551            var sym = null;
  15552            var ambientTable = (this.ambientValueMembers == null) ? null : publicOnly ? this.ambientValueMembers.publicMembers : this.ambientValueMembers.allMembers;
  15553            if(typespace) {
  15554                ambientTable = (this.ambientEnclosedTypes == null) ? null : publicOnly ? this.ambientEnclosedTypes.publicMembers : this.ambientEnclosedTypes.allMembers;
  15555            }
  15556            if(ambientTable && ((sym = ambientTable.lookup(name)) != null)) {
  15557                return sym;
  15558            }
  15559            if(this.parent) {
  15560                return this.parent.findAmbient(name, publicOnly, typespace);
  15561            }
  15562            return null;
  15563        };
  15564        SymbolScopeBuilder.prototype.findLocal = function (name, publicOnly, typespace) {
  15565            var sym = null;
  15566            var table = (this.valueMembers == null) ? null : publicOnly ? this.valueMembers.publicMembers : this.valueMembers.allMembers;
  15567            var ambientTable = (this.ambientValueMembers == null) ? null : publicOnly ? this.ambientValueMembers.publicMembers : this.ambientValueMembers.allMembers;
  15568            if(typespace) {
  15569                table = (this.enclosedTypes == null) ? null : publicOnly ? this.enclosedTypes.publicMembers : this.enclosedTypes.allMembers;
  15570                ambientTable = (this.ambientEnclosedTypes == null) ? null : publicOnly ? this.ambientEnclosedTypes.publicMembers : this.ambientEnclosedTypes.allMembers;
  15571            }
  15572            if(table) {
  15573                if((sym = table.lookup(name)) != null) {
  15574                    if(sym) {
  15575                        return sym;
  15576                    }
  15577                }
  15578            }
  15579            if(ambientTable) {
  15580                if((sym = ambientTable.lookup(name)) != null) {
  15581                    if(sym) {
  15582                        return sym;
  15583                    }
  15584                }
  15585            }
  15586            return null;
  15587        };
  15588        SymbolScopeBuilder.prototype.enter = function (container, ast, symbol, errorReporter, insertAsPublic, typespace, ambient) {
  15589            var table = null;
  15590            if(ambient) {
  15591                if(typespace) {
  15592                    table = (this.ambientEnclosedTypes == null) ? null : insertAsPublic ? this.ambientEnclosedTypes.publicMembers : this.ambientEnclosedTypes.privateMembers;
  15593                } else {
  15594                    table = (this.ambientValueMembers == null) ? null : insertAsPublic ? this.ambientValueMembers.publicMembers : this.ambientValueMembers.privateMembers;
  15595                }
  15596            } else {
  15597                if(typespace) {
  15598                    table = (this.enclosedTypes == null) ? null : insertAsPublic ? this.enclosedTypes.publicMembers : this.enclosedTypes.privateMembers;
  15599                } else {
  15600                    table = (this.valueMembers == null) ? null : insertAsPublic ? this.valueMembers.publicMembers : this.valueMembers.privateMembers;
  15601                }
  15602            }
  15603            if(table) {
  15604                if(!table.add(symbol.name, symbol)) {
  15605                    errorReporter.duplicateIdentifier(ast, symbol.name);
  15606                }
  15607            } else {
  15608                TypeScript.CompilerDiagnostics.Alert("YYYYY");
  15609            }
  15610            symbol.container = container;
  15611        };
  15612        SymbolScopeBuilder.prototype.getTable = function () {
  15613            return this.valueMembers.allMembers;
  15614        };
  15615        return SymbolScopeBuilder;
  15616    })(SymbolScope);
  15617    TypeScript.SymbolScopeBuilder = SymbolScopeBuilder;    
  15618    var FilteredSymbolScope = (function (_super) {
  15619        __extends(FilteredSymbolScope, _super);
  15620        function FilteredSymbolScope(scope, container, filter) {
  15621                _super.call(this, container);
  15622            this.scope = scope;
  15623            this.filter = filter;
  15624        }
  15625        FilteredSymbolScope.prototype.print = function (outfile) {
  15626            this.scope.print(outfile);
  15627        };
  15628        FilteredSymbolScope.prototype.find = function (name, publicOnly, typespace) {
  15629            this.filter.reset();
  15630            return this.scope.search(this.filter, name, publicOnly, typespace);
  15631        };
  15632        FilteredSymbolScope.prototype.findLocal = function (name, publicOnly, typespace) {
  15633            return this.scope.findLocal(name, publicOnly, typespace);
  15634        };
  15635        return FilteredSymbolScope;
  15636    })(SymbolScope);
  15637    TypeScript.FilteredSymbolScope = FilteredSymbolScope;    
  15638    var FilteredSymbolScopeBuilder = (function (_super) {
  15639        __extends(FilteredSymbolScopeBuilder, _super);
  15640        function FilteredSymbolScopeBuilder(valueMembers, parent, container, filter) {
  15641                _super.call(this, valueMembers, null, null, null, parent, container);
  15642            this.filter = filter;
  15643        }
  15644        FilteredSymbolScopeBuilder.prototype.findLocal = function (name, publicOnly, typespace) {
  15645            var sym = _super.prototype.findLocal.call(this, name, publicOnly, typespace);
  15646            if(sym) {
  15647                if(!this.filter(sym)) {
  15648                    return null;
  15649                }
  15650            }
  15651            return sym;
  15652        };
  15653        FilteredSymbolScopeBuilder.prototype.search = function (filter, name, publicOnly, typespace) {
  15654            throw new Error("please implement");
  15655        };
  15656        FilteredSymbolScopeBuilder.prototype.find = function (name, publicOnly, typespace) {
  15657            var sym = _super.prototype.findLocal.call(this, name, publicOnly, typespace);
  15658            if(sym) {
  15659                if(!this.filter(sym)) {
  15660                    return null;
  15661                }
  15662            }
  15663            return _super.prototype.find.call(this, name, publicOnly, typespace);
  15664        };
  15665        return FilteredSymbolScopeBuilder;
  15666    })(SymbolScopeBuilder);
  15667    TypeScript.FilteredSymbolScopeBuilder = FilteredSymbolScopeBuilder;    
  15668 })(TypeScript || (TypeScript = {}));
  15669 var TypeScript;
  15670 (function (TypeScript) {
  15671    (function (TokenID) {
  15672        TokenID._map = [];
  15673        TokenID._map[0] = "Any";
  15674        TokenID.Any = 0;
  15675        TokenID._map[1] = "Bool";
  15676        TokenID.Bool = 1;
  15677        TokenID._map[2] = "Break";
  15678        TokenID.Break = 2;
  15679        TokenID._map[3] = "Case";
  15680        TokenID.Case = 3;
  15681        TokenID._map[4] = "Catch";
  15682        TokenID.Catch = 4;
  15683        TokenID._map[5] = "Class";
  15684        TokenID.Class = 5;
  15685        TokenID._map[6] = "Const";
  15686        TokenID.Const = 6;
  15687        TokenID._map[7] = "Continue";
  15688        TokenID.Continue = 7;
  15689        TokenID._map[8] = "Debugger";
  15690        TokenID.Debugger = 8;
  15691        TokenID._map[9] = "Default";
  15692        TokenID.Default = 9;
  15693        TokenID._map[10] = "Delete";
  15694        TokenID.Delete = 10;
  15695        TokenID._map[11] = "Do";
  15696        TokenID.Do = 11;
  15697        TokenID._map[12] = "Else";
  15698        TokenID.Else = 12;
  15699        TokenID._map[13] = "Enum";
  15700        TokenID.Enum = 13;
  15701        TokenID._map[14] = "Export";
  15702        TokenID.Export = 14;
  15703        TokenID._map[15] = "Extends";
  15704        TokenID.Extends = 15;
  15705        TokenID._map[16] = "Declare";
  15706        TokenID.Declare = 16;
  15707        TokenID._map[17] = "False";
  15708        TokenID.False = 17;
  15709        TokenID._map[18] = "Finally";
  15710        TokenID.Finally = 18;
  15711        TokenID._map[19] = "For";
  15712        TokenID.For = 19;
  15713        TokenID._map[20] = "Function";
  15714        TokenID.Function = 20;
  15715        TokenID._map[21] = "Constructor";
  15716        TokenID.Constructor = 21;
  15717        TokenID._map[22] = "Get";
  15718        TokenID.Get = 22;
  15719        TokenID._map[23] = "If";
  15720        TokenID.If = 23;
  15721        TokenID._map[24] = "Implements";
  15722        TokenID.Implements = 24;
  15723        TokenID._map[25] = "Import";
  15724        TokenID.Import = 25;
  15725        TokenID._map[26] = "In";
  15726        TokenID.In = 26;
  15727        TokenID._map[27] = "InstanceOf";
  15728        TokenID.InstanceOf = 27;
  15729        TokenID._map[28] = "Interface";
  15730        TokenID.Interface = 28;
  15731        TokenID._map[29] = "Let";
  15732        TokenID.Let = 29;
  15733        TokenID._map[30] = "Module";
  15734        TokenID.Module = 30;
  15735        TokenID._map[31] = "New";
  15736        TokenID.New = 31;
  15737        TokenID._map[32] = "Number";
  15738        TokenID.Number = 32;
  15739        TokenID._map[33] = "Null";
  15740        TokenID.Null = 33;
  15741        TokenID._map[34] = "Package";
  15742        TokenID.Package = 34;
  15743        TokenID._map[35] = "Private";
  15744        TokenID.Private = 35;
  15745        TokenID._map[36] = "Protected";
  15746        TokenID.Protected = 36;
  15747        TokenID._map[37] = "Public";
  15748        TokenID.Public = 37;
  15749        TokenID._map[38] = "Return";
  15750        TokenID.Return = 38;
  15751        TokenID._map[39] = "Set";
  15752        TokenID.Set = 39;
  15753        TokenID._map[40] = "Static";
  15754        TokenID.Static = 40;
  15755        TokenID._map[41] = "String";
  15756        TokenID.String = 41;
  15757        TokenID._map[42] = "Super";
  15758        TokenID.Super = 42;
  15759        TokenID._map[43] = "Switch";
  15760        TokenID.Switch = 43;
  15761        TokenID._map[44] = "This";
  15762        TokenID.This = 44;
  15763        TokenID._map[45] = "Throw";
  15764        TokenID.Throw = 45;
  15765        TokenID._map[46] = "True";
  15766        TokenID.True = 46;
  15767        TokenID._map[47] = "Try";
  15768        TokenID.Try = 47;
  15769        TokenID._map[48] = "TypeOf";
  15770        TokenID.TypeOf = 48;
  15771        TokenID._map[49] = "Var";
  15772        TokenID.Var = 49;
  15773        TokenID._map[50] = "Void";
  15774        TokenID.Void = 50;
  15775        TokenID._map[51] = "With";
  15776        TokenID.With = 51;
  15777        TokenID._map[52] = "While";
  15778        TokenID.While = 52;
  15779        TokenID._map[53] = "Yield";
  15780        TokenID.Yield = 53;
  15781        TokenID._map[54] = "Semicolon";
  15782        TokenID.Semicolon = 54;
  15783        TokenID._map[55] = "OpenParen";
  15784        TokenID.OpenParen = 55;
  15785        TokenID._map[56] = "CloseParen";
  15786        TokenID.CloseParen = 56;
  15787        TokenID._map[57] = "OpenBracket";
  15788        TokenID.OpenBracket = 57;
  15789        TokenID._map[58] = "CloseBracket";
  15790        TokenID.CloseBracket = 58;
  15791        TokenID._map[59] = "OpenBrace";
  15792        TokenID.OpenBrace = 59;
  15793        TokenID._map[60] = "CloseBrace";
  15794        TokenID.CloseBrace = 60;
  15795        TokenID._map[61] = "Comma";
  15796        TokenID.Comma = 61;
  15797        TokenID._map[62] = "Equals";
  15798        TokenID.Equals = 62;
  15799        TokenID._map[63] = "PlusEquals";
  15800        TokenID.PlusEquals = 63;
  15801        TokenID._map[64] = "MinusEquals";
  15802        TokenID.MinusEquals = 64;
  15803        TokenID._map[65] = "AsteriskEquals";
  15804        TokenID.AsteriskEquals = 65;
  15805        TokenID._map[66] = "SlashEquals";
  15806        TokenID.SlashEquals = 66;
  15807        TokenID._map[67] = "PercentEquals";
  15808        TokenID.PercentEquals = 67;
  15809        TokenID._map[68] = "AmpersandEquals";
  15810        TokenID.AmpersandEquals = 68;
  15811        TokenID._map[69] = "CaretEquals";
  15812        TokenID.CaretEquals = 69;
  15813        TokenID._map[70] = "BarEquals";
  15814        TokenID.BarEquals = 70;
  15815        TokenID._map[71] = "LessThanLessThanEquals";
  15816        TokenID.LessThanLessThanEquals = 71;
  15817        TokenID._map[72] = "GreaterThanGreaterThanEquals";
  15818        TokenID.GreaterThanGreaterThanEquals = 72;
  15819        TokenID._map[73] = "GreaterThanGreaterThanGreaterThanEquals";
  15820        TokenID.GreaterThanGreaterThanGreaterThanEquals = 73;
  15821        TokenID._map[74] = "Question";
  15822        TokenID.Question = 74;
  15823        TokenID._map[75] = "Colon";
  15824        TokenID.Colon = 75;
  15825        TokenID._map[76] = "BarBar";
  15826        TokenID.BarBar = 76;
  15827        TokenID._map[77] = "AmpersandAmpersand";
  15828        TokenID.AmpersandAmpersand = 77;
  15829        TokenID._map[78] = "Bar";
  15830        TokenID.Bar = 78;
  15831        TokenID._map[79] = "Caret";
  15832        TokenID.Caret = 79;
  15833        TokenID._map[80] = "And";
  15834        TokenID.And = 80;
  15835        TokenID._map[81] = "EqualsEquals";
  15836        TokenID.EqualsEquals = 81;
  15837        TokenID._map[82] = "ExclamationEquals";
  15838        TokenID.ExclamationEquals = 82;
  15839        TokenID._map[83] = "EqualsEqualsEquals";
  15840        TokenID.EqualsEqualsEquals = 83;
  15841        TokenID._map[84] = "ExclamationEqualsEquals";
  15842        TokenID.ExclamationEqualsEquals = 84;
  15843        TokenID._map[85] = "LessThan";
  15844        TokenID.LessThan = 85;
  15845        TokenID._map[86] = "LessThanEquals";
  15846        TokenID.LessThanEquals = 86;
  15847        TokenID._map[87] = "GreaterThan";
  15848        TokenID.GreaterThan = 87;
  15849        TokenID._map[88] = "GreaterThanEquals";
  15850        TokenID.GreaterThanEquals = 88;
  15851        TokenID._map[89] = "LessThanLessThan";
  15852        TokenID.LessThanLessThan = 89;
  15853        TokenID._map[90] = "GreaterThanGreaterThan";
  15854        TokenID.GreaterThanGreaterThan = 90;
  15855        TokenID._map[91] = "GreaterThanGreaterThanGreaterThan";
  15856        TokenID.GreaterThanGreaterThanGreaterThan = 91;
  15857        TokenID._map[92] = "Plus";
  15858        TokenID.Plus = 92;
  15859        TokenID._map[93] = "Minus";
  15860        TokenID.Minus = 93;
  15861        TokenID._map[94] = "Asterisk";
  15862        TokenID.Asterisk = 94;
  15863        TokenID._map[95] = "Slash";
  15864        TokenID.Slash = 95;
  15865        TokenID._map[96] = "Percent";
  15866        TokenID.Percent = 96;
  15867        TokenID._map[97] = "Tilde";
  15868        TokenID.Tilde = 97;
  15869        TokenID._map[98] = "Exclamation";
  15870        TokenID.Exclamation = 98;
  15871        TokenID._map[99] = "PlusPlus";
  15872        TokenID.PlusPlus = 99;
  15873        TokenID._map[100] = "MinusMinus";
  15874        TokenID.MinusMinus = 100;
  15875        TokenID._map[101] = "Dot";
  15876        TokenID.Dot = 101;
  15877        TokenID._map[102] = "DotDotDot";
  15878        TokenID.DotDotDot = 102;
  15879        TokenID._map[103] = "Error";
  15880        TokenID.Error = 103;
  15881        TokenID._map[104] = "EndOfFile";
  15882        TokenID.EndOfFile = 104;
  15883        TokenID._map[105] = "EqualsGreaterThan";
  15884        TokenID.EqualsGreaterThan = 105;
  15885        TokenID._map[106] = "Identifier";
  15886        TokenID.Identifier = 106;
  15887        TokenID._map[107] = "StringLiteral";
  15888        TokenID.StringLiteral = 107;
  15889        TokenID._map[108] = "RegularExpressionLiteral";
  15890        TokenID.RegularExpressionLiteral = 108;
  15891        TokenID._map[109] = "NumberLiteral";
  15892        TokenID.NumberLiteral = 109;
  15893        TokenID._map[110] = "Whitespace";
  15894        TokenID.Whitespace = 110;
  15895        TokenID._map[111] = "Comment";
  15896        TokenID.Comment = 111;
  15897        TokenID._map[112] = "Lim";
  15898        TokenID.Lim = 112;
  15899        TokenID.LimFixed = TokenID.EqualsGreaterThan;
  15900        TokenID.LimKeyword = TokenID.Yield;
  15901    })(TypeScript.TokenID || (TypeScript.TokenID = {}));
  15902    var TokenID = TypeScript.TokenID;
  15903    TypeScript.tokenTable = new Array();
  15904    TypeScript.nodeTypeTable = new Array();
  15905    TypeScript.nodeTypeToTokTable = new Array();
  15906    TypeScript.noRegexTable = new Array();
  15907    TypeScript.noRegexTable[TokenID.Identifier] = true;
  15908    TypeScript.noRegexTable[TokenID.StringLiteral] = true;
  15909    TypeScript.noRegexTable[TokenID.NumberLiteral] = true;
  15910    TypeScript.noRegexTable[TokenID.RegularExpressionLiteral] = true;
  15911    TypeScript.noRegexTable[TokenID.This] = true;
  15912    TypeScript.noRegexTable[TokenID.PlusPlus] = true;
  15913    TypeScript.noRegexTable[TokenID.MinusMinus] = true;
  15914    TypeScript.noRegexTable[TokenID.CloseParen] = true;
  15915    TypeScript.noRegexTable[TokenID.CloseBracket] = true;
  15916    TypeScript.noRegexTable[TokenID.CloseBrace] = true;
  15917    TypeScript.noRegexTable[TokenID.True] = true;
  15918    TypeScript.noRegexTable[TokenID.False] = true;
  15919    (function (OperatorPrecedence) {
  15920        OperatorPrecedence._map = [];
  15921        OperatorPrecedence._map[0] = "None";
  15922        OperatorPrecedence.None = 0;
  15923        OperatorPrecedence._map[1] = "Comma";
  15924        OperatorPrecedence.Comma = 1;
  15925        OperatorPrecedence._map[2] = "Assignment";
  15926        OperatorPrecedence.Assignment = 2;
  15927        OperatorPrecedence._map[3] = "Conditional";
  15928        OperatorPrecedence.Conditional = 3;
  15929        OperatorPrecedence._map[4] = "LogicalOr";
  15930        OperatorPrecedence.LogicalOr = 4;
  15931        OperatorPrecedence._map[5] = "LogicalAnd";
  15932        OperatorPrecedence.LogicalAnd = 5;
  15933        OperatorPrecedence._map[6] = "BitwiseOr";
  15934        OperatorPrecedence.BitwiseOr = 6;
  15935        OperatorPrecedence._map[7] = "BitwiseExclusiveOr";
  15936        OperatorPrecedence.BitwiseExclusiveOr = 7;
  15937        OperatorPrecedence._map[8] = "BitwiseAnd";
  15938        OperatorPrecedence.BitwiseAnd = 8;
  15939        OperatorPrecedence._map[9] = "Equality";
  15940        OperatorPrecedence.Equality = 9;
  15941        OperatorPrecedence._map[10] = "Relational";
  15942        OperatorPrecedence.Relational = 10;
  15943        OperatorPrecedence._map[11] = "Shift";
  15944        OperatorPrecedence.Shift = 11;
  15945        OperatorPrecedence._map[12] = "Additive";
  15946        OperatorPrecedence.Additive = 12;
  15947        OperatorPrecedence._map[13] = "Multiplicative";
  15948        OperatorPrecedence.Multiplicative = 13;
  15949        OperatorPrecedence._map[14] = "Unary";
  15950        OperatorPrecedence.Unary = 14;
  15951        OperatorPrecedence._map[15] = "Lim";
  15952        OperatorPrecedence.Lim = 15;
  15953    })(TypeScript.OperatorPrecedence || (TypeScript.OperatorPrecedence = {}));
  15954    var OperatorPrecedence = TypeScript.OperatorPrecedence;
  15955    (function (Reservation) {
  15956        Reservation._map = [];
  15957        Reservation.None = 0;
  15958        Reservation.Javascript = 1;
  15959        Reservation.JavascriptFuture = 2;
  15960        Reservation.TypeScript = 4;
  15961        Reservation.JavascriptFutureStrict = 8;
  15962        Reservation.TypeScriptAndJS = Reservation.Javascript | Reservation.TypeScript;
  15963        Reservation.TypeScriptAndJSFuture = Reservation.JavascriptFuture | Reservation.TypeScript;
  15964        Reservation.TypeScriptAndJSFutureStrict = Reservation.JavascriptFutureStrict | Reservation.TypeScript;
  15965    })(TypeScript.Reservation || (TypeScript.Reservation = {}));
  15966    var Reservation = TypeScript.Reservation;
  15967    var TokenInfo = (function () {
  15968        function TokenInfo(tokenId, reservation, binopPrecedence, binopNodeType, unopPrecedence, unopNodeType, text, ers) {
  15969            this.tokenId = tokenId;
  15970            this.reservation = reservation;
  15971            this.binopPrecedence = binopPrecedence;
  15972            this.binopNodeType = binopNodeType;
  15973            this.unopPrecedence = unopPrecedence;
  15974            this.unopNodeType = unopNodeType;
  15975            this.text = text;
  15976            this.ers = ers;
  15977        }
  15978        return TokenInfo;
  15979    })();
  15980    TypeScript.TokenInfo = TokenInfo;    
  15981    function setTokenInfo(tokenId, reservation, binopPrecedence, binopNodeType, unopPrecedence, unopNodeType, text, ers) {
  15982        if(tokenId !== undefined) {
  15983            TypeScript.tokenTable[tokenId] = new TokenInfo(tokenId, reservation, binopPrecedence, binopNodeType, unopPrecedence, unopNodeType, text, ers);
  15984            if(binopNodeType != TypeScript.NodeType.None) {
  15985                TypeScript.nodeTypeTable[binopNodeType] = text;
  15986                TypeScript.nodeTypeToTokTable[binopNodeType] = tokenId;
  15987            }
  15988            if(unopNodeType != TypeScript.NodeType.None) {
  15989                TypeScript.nodeTypeTable[unopNodeType] = text;
  15990            }
  15991        }
  15992    }
  15993    setTokenInfo(TokenID.Any, Reservation.TypeScript, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "any", TypeScript.ErrorRecoverySet.PrimType);
  15994    setTokenInfo(TokenID.Bool, Reservation.TypeScript, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "bool", TypeScript.ErrorRecoverySet.PrimType);
  15995    setTokenInfo(TokenID.Break, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "break", TypeScript.ErrorRecoverySet.Stmt);
  15996    setTokenInfo(TokenID.Case, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "case", TypeScript.ErrorRecoverySet.SCase);
  15997    setTokenInfo(TokenID.Catch, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "catch", TypeScript.ErrorRecoverySet.Catch);
  15998    setTokenInfo(TokenID.Class, Reservation.TypeScriptAndJSFuture, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "class", TypeScript.ErrorRecoverySet.TypeScriptS);
  15999    setTokenInfo(TokenID.Const, Reservation.TypeScriptAndJSFuture, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "const", TypeScript.ErrorRecoverySet.Var);
  16000    setTokenInfo(TokenID.Continue, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "continue", TypeScript.ErrorRecoverySet.Stmt);
  16001    setTokenInfo(TokenID.Debugger, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.Debugger, "debugger", TypeScript.ErrorRecoverySet.Stmt);
  16002    setTokenInfo(TokenID.Default, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "default", TypeScript.ErrorRecoverySet.SCase);
  16003    setTokenInfo(TokenID.Delete, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.Unary, TypeScript.NodeType.Delete, "delete", TypeScript.ErrorRecoverySet.Prefix);
  16004    setTokenInfo(TokenID.Do, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "do", TypeScript.ErrorRecoverySet.Stmt);
  16005    setTokenInfo(TokenID.Else, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "else", TypeScript.ErrorRecoverySet.Else);
  16006    setTokenInfo(TokenID.Enum, Reservation.TypeScriptAndJSFuture, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "enum", TypeScript.ErrorRecoverySet.TypeScriptS);
  16007    setTokenInfo(TokenID.Export, Reservation.TypeScriptAndJSFuture, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "export", TypeScript.ErrorRecoverySet.TypeScriptS);
  16008    setTokenInfo(TokenID.Extends, Reservation.TypeScriptAndJSFuture, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "extends", TypeScript.ErrorRecoverySet.None);
  16009    setTokenInfo(TokenID.Declare, Reservation.TypeScript, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "declare", TypeScript.ErrorRecoverySet.Stmt);
  16010    setTokenInfo(TokenID.False, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "false", TypeScript.ErrorRecoverySet.RLit);
  16011    setTokenInfo(TokenID.Finally, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "finally", TypeScript.ErrorRecoverySet.Catch);
  16012    setTokenInfo(TokenID.For, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "for", TypeScript.ErrorRecoverySet.Stmt);
  16013    setTokenInfo(TokenID.Function, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "function", TypeScript.ErrorRecoverySet.Func);
  16014    setTokenInfo(TokenID.Constructor, Reservation.TypeScriptAndJSFutureStrict, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "constructor", TypeScript.ErrorRecoverySet.Func);
  16015    setTokenInfo(TokenID.Get, Reservation.TypeScript, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "get", TypeScript.ErrorRecoverySet.Func);
  16016    setTokenInfo(TokenID.Set, Reservation.TypeScript, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "set", TypeScript.ErrorRecoverySet.Func);
  16017    setTokenInfo(TokenID.If, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "if", TypeScript.ErrorRecoverySet.Stmt);
  16018    setTokenInfo(TokenID.Implements, Reservation.TypeScriptAndJSFutureStrict, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "implements", TypeScript.ErrorRecoverySet.None);
  16019    setTokenInfo(TokenID.Import, Reservation.TypeScriptAndJSFuture, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "import", TypeScript.ErrorRecoverySet.TypeScriptS);
  16020    setTokenInfo(TokenID.In, Reservation.TypeScriptAndJS, OperatorPrecedence.Relational, TypeScript.NodeType.In, OperatorPrecedence.None, TypeScript.NodeType.None, "in", TypeScript.ErrorRecoverySet.None);
  16021    setTokenInfo(TokenID.InstanceOf, Reservation.TypeScriptAndJS, OperatorPrecedence.Relational, TypeScript.NodeType.InstOf, OperatorPrecedence.None, TypeScript.NodeType.None, "instanceof", TypeScript.ErrorRecoverySet.BinOp);
  16022    setTokenInfo(TokenID.Interface, Reservation.TypeScriptAndJSFutureStrict, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "interface", TypeScript.ErrorRecoverySet.TypeScriptS);
  16023    setTokenInfo(TokenID.Let, Reservation.JavascriptFutureStrict, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "let", TypeScript.ErrorRecoverySet.None);
  16024    setTokenInfo(TokenID.Module, Reservation.TypeScript, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "module", TypeScript.ErrorRecoverySet.TypeScriptS);
  16025    setTokenInfo(TokenID.New, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "new", TypeScript.ErrorRecoverySet.PreOp);
  16026    setTokenInfo(TokenID.Number, Reservation.TypeScript, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "number", TypeScript.ErrorRecoverySet.PrimType);
  16027    setTokenInfo(TokenID.Null, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "null", TypeScript.ErrorRecoverySet.RLit);
  16028    setTokenInfo(TokenID.Package, Reservation.JavascriptFutureStrict, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "package", TypeScript.ErrorRecoverySet.None);
  16029    setTokenInfo(TokenID.Private, Reservation.TypeScriptAndJSFutureStrict, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "private", TypeScript.ErrorRecoverySet.TypeScriptS);
  16030    setTokenInfo(TokenID.Protected, Reservation.JavascriptFutureStrict, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "protected", TypeScript.ErrorRecoverySet.None);
  16031    setTokenInfo(TokenID.Public, Reservation.TypeScriptAndJSFutureStrict, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "public", TypeScript.ErrorRecoverySet.TypeScriptS);
  16032    setTokenInfo(TokenID.Return, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "return", TypeScript.ErrorRecoverySet.Stmt);
  16033    setTokenInfo(TokenID.Static, Reservation.TypeScriptAndJSFutureStrict, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "static", TypeScript.ErrorRecoverySet.None);
  16034    setTokenInfo(TokenID.String, Reservation.TypeScript, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "string", TypeScript.ErrorRecoverySet.PrimType);
  16035    setTokenInfo(TokenID.Super, Reservation.TypeScriptAndJSFuture, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "super", TypeScript.ErrorRecoverySet.RLit);
  16036    setTokenInfo(TokenID.Switch, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "switch", TypeScript.ErrorRecoverySet.Stmt);
  16037    setTokenInfo(TokenID.This, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "this", TypeScript.ErrorRecoverySet.RLit);
  16038    setTokenInfo(TokenID.Throw, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "throw", TypeScript.ErrorRecoverySet.Stmt);
  16039    setTokenInfo(TokenID.True, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "true", TypeScript.ErrorRecoverySet.RLit);
  16040    setTokenInfo(TokenID.Try, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "try", TypeScript.ErrorRecoverySet.Stmt);
  16041    setTokenInfo(TokenID.TypeOf, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.Unary, TypeScript.NodeType.Typeof, "typeof", TypeScript.ErrorRecoverySet.Prefix);
  16042    setTokenInfo(TokenID.Var, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "var", TypeScript.ErrorRecoverySet.Var);
  16043    setTokenInfo(TokenID.Void, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.Unary, TypeScript.NodeType.Void, "void", TypeScript.ErrorRecoverySet.Prefix);
  16044    setTokenInfo(TokenID.With, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.With, "with", TypeScript.ErrorRecoverySet.Stmt);
  16045    setTokenInfo(TokenID.While, Reservation.TypeScriptAndJS, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "while", TypeScript.ErrorRecoverySet.While);
  16046    setTokenInfo(TokenID.Yield, Reservation.JavascriptFutureStrict, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "yield", TypeScript.ErrorRecoverySet.None);
  16047    setTokenInfo(TokenID.Identifier, Reservation.None, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "identifier", TypeScript.ErrorRecoverySet.ID);
  16048    setTokenInfo(TokenID.NumberLiteral, Reservation.None, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "numberLiteral", TypeScript.ErrorRecoverySet.Literal);
  16049    setTokenInfo(TokenID.RegularExpressionLiteral, Reservation.None, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "regex", TypeScript.ErrorRecoverySet.RegExp);
  16050    setTokenInfo(TokenID.StringLiteral, Reservation.None, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "qstring", TypeScript.ErrorRecoverySet.Literal);
  16051    setTokenInfo(TokenID.Semicolon, Reservation.None, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, ";", TypeScript.ErrorRecoverySet.SColon);
  16052    setTokenInfo(TokenID.CloseParen, Reservation.None, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, ")", TypeScript.ErrorRecoverySet.RParen);
  16053    setTokenInfo(TokenID.CloseBracket, Reservation.None, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "]", TypeScript.ErrorRecoverySet.RBrack);
  16054    setTokenInfo(TokenID.OpenBrace, Reservation.None, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "{", TypeScript.ErrorRecoverySet.LCurly);
  16055    setTokenInfo(TokenID.CloseBrace, Reservation.None, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "}", TypeScript.ErrorRecoverySet.RCurly);
  16056    setTokenInfo(TokenID.DotDotDot, Reservation.None, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "...", TypeScript.ErrorRecoverySet.None);
  16057    setTokenInfo(TokenID.Comma, Reservation.None, OperatorPrecedence.Comma, TypeScript.NodeType.Comma, OperatorPrecedence.None, TypeScript.NodeType.None, ",", TypeScript.ErrorRecoverySet.Comma);
  16058    setTokenInfo(TokenID.Equals, Reservation.None, OperatorPrecedence.Assignment, TypeScript.NodeType.Asg, OperatorPrecedence.None, TypeScript.NodeType.None, "=", TypeScript.ErrorRecoverySet.Asg);
  16059    setTokenInfo(TokenID.PlusEquals, Reservation.None, OperatorPrecedence.Assignment, TypeScript.NodeType.AsgAdd, OperatorPrecedence.None, TypeScript.NodeType.None, "+=", TypeScript.ErrorRecoverySet.BinOp);
  16060    setTokenInfo(TokenID.MinusEquals, Reservation.None, OperatorPrecedence.Assignment, TypeScript.NodeType.AsgSub, OperatorPrecedence.None, TypeScript.NodeType.None, "-=", TypeScript.ErrorRecoverySet.BinOp);
  16061    setTokenInfo(TokenID.AsteriskEquals, Reservation.None, OperatorPrecedence.Assignment, TypeScript.NodeType.AsgMul, OperatorPrecedence.None, TypeScript.NodeType.None, "*=", TypeScript.ErrorRecoverySet.BinOp);
  16062    setTokenInfo(TokenID.SlashEquals, Reservation.None, OperatorPrecedence.Assignment, TypeScript.NodeType.AsgDiv, OperatorPrecedence.None, TypeScript.NodeType.None, "/=", TypeScript.ErrorRecoverySet.BinOp);
  16063    setTokenInfo(TokenID.PercentEquals, Reservation.None, OperatorPrecedence.Assignment, TypeScript.NodeType.AsgMod, OperatorPrecedence.None, TypeScript.NodeType.None, "%=", TypeScript.ErrorRecoverySet.BinOp);
  16064    setTokenInfo(TokenID.AmpersandEquals, Reservation.None, OperatorPrecedence.Assignment, TypeScript.NodeType.AsgAnd, OperatorPrecedence.None, TypeScript.NodeType.None, "&=", TypeScript.ErrorRecoverySet.BinOp);
  16065    setTokenInfo(TokenID.CaretEquals, Reservation.None, OperatorPrecedence.Assignment, TypeScript.NodeType.AsgXor, OperatorPrecedence.None, TypeScript.NodeType.None, "^=", TypeScript.ErrorRecoverySet.BinOp);
  16066    setTokenInfo(TokenID.BarEquals, Reservation.None, OperatorPrecedence.Assignment, TypeScript.NodeType.AsgOr, OperatorPrecedence.None, TypeScript.NodeType.None, "|=", TypeScript.ErrorRecoverySet.BinOp);
  16067    setTokenInfo(TokenID.LessThanLessThanEquals, Reservation.None, OperatorPrecedence.Assignment, TypeScript.NodeType.AsgLsh, OperatorPrecedence.None, TypeScript.NodeType.None, "<<=", TypeScript.ErrorRecoverySet.BinOp);
  16068    setTokenInfo(TokenID.GreaterThanGreaterThanEquals, Reservation.None, OperatorPrecedence.Assignment, TypeScript.NodeType.AsgRsh, OperatorPrecedence.None, TypeScript.NodeType.None, ">>=", TypeScript.ErrorRecoverySet.BinOp);
  16069    setTokenInfo(TokenID.GreaterThanGreaterThanGreaterThanEquals, Reservation.None, OperatorPrecedence.Assignment, TypeScript.NodeType.AsgRs2, OperatorPrecedence.None, TypeScript.NodeType.None, ">>>=", TypeScript.ErrorRecoverySet.BinOp);
  16070    setTokenInfo(TokenID.Question, Reservation.None, OperatorPrecedence.Conditional, TypeScript.NodeType.ConditionalExpression, OperatorPrecedence.None, TypeScript.NodeType.None, "?", TypeScript.ErrorRecoverySet.BinOp);
  16071    setTokenInfo(TokenID.Colon, Reservation.None, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, ":", TypeScript.ErrorRecoverySet.Colon);
  16072    setTokenInfo(TokenID.BarBar, Reservation.None, OperatorPrecedence.LogicalOr, TypeScript.NodeType.LogOr, OperatorPrecedence.None, TypeScript.NodeType.None, "||", TypeScript.ErrorRecoverySet.BinOp);
  16073    setTokenInfo(TokenID.AmpersandAmpersand, Reservation.None, OperatorPrecedence.LogicalAnd, TypeScript.NodeType.LogAnd, OperatorPrecedence.None, TypeScript.NodeType.None, "&&", TypeScript.ErrorRecoverySet.BinOp);
  16074    setTokenInfo(TokenID.Bar, Reservation.None, OperatorPrecedence.BitwiseOr, TypeScript.NodeType.Or, OperatorPrecedence.None, TypeScript.NodeType.None, "|", TypeScript.ErrorRecoverySet.BinOp);
  16075    setTokenInfo(TokenID.Caret, Reservation.None, OperatorPrecedence.BitwiseExclusiveOr, TypeScript.NodeType.Xor, OperatorPrecedence.None, TypeScript.NodeType.None, "^", TypeScript.ErrorRecoverySet.BinOp);
  16076    setTokenInfo(TokenID.And, Reservation.None, OperatorPrecedence.BitwiseAnd, TypeScript.NodeType.And, OperatorPrecedence.None, TypeScript.NodeType.None, "&", TypeScript.ErrorRecoverySet.BinOp);
  16077    setTokenInfo(TokenID.EqualsEquals, Reservation.None, OperatorPrecedence.Equality, TypeScript.NodeType.Eq, OperatorPrecedence.None, TypeScript.NodeType.None, "==", TypeScript.ErrorRecoverySet.BinOp);
  16078    setTokenInfo(TokenID.ExclamationEquals, Reservation.None, OperatorPrecedence.Equality, TypeScript.NodeType.Ne, OperatorPrecedence.None, TypeScript.NodeType.None, "!=", TypeScript.ErrorRecoverySet.BinOp);
  16079    setTokenInfo(TokenID.EqualsEqualsEquals, Reservation.None, OperatorPrecedence.Equality, TypeScript.NodeType.Eqv, OperatorPrecedence.None, TypeScript.NodeType.None, "===", TypeScript.ErrorRecoverySet.BinOp);
  16080    setTokenInfo(TokenID.ExclamationEqualsEquals, Reservation.None, OperatorPrecedence.Equality, TypeScript.NodeType.NEqv, OperatorPrecedence.None, TypeScript.NodeType.None, "!==", TypeScript.ErrorRecoverySet.BinOp);
  16081    setTokenInfo(TokenID.LessThan, Reservation.None, OperatorPrecedence.Relational, TypeScript.NodeType.Lt, OperatorPrecedence.None, TypeScript.NodeType.None, "<", TypeScript.ErrorRecoverySet.BinOp);
  16082    setTokenInfo(TokenID.LessThanEquals, Reservation.None, OperatorPrecedence.Relational, TypeScript.NodeType.Le, OperatorPrecedence.None, TypeScript.NodeType.None, "<=", TypeScript.ErrorRecoverySet.BinOp);
  16083    setTokenInfo(TokenID.GreaterThan, Reservation.None, OperatorPrecedence.Relational, TypeScript.NodeType.Gt, OperatorPrecedence.None, TypeScript.NodeType.None, ">", TypeScript.ErrorRecoverySet.BinOp);
  16084    setTokenInfo(TokenID.GreaterThanEquals, Reservation.None, OperatorPrecedence.Relational, TypeScript.NodeType.Ge, OperatorPrecedence.None, TypeScript.NodeType.None, ">=", TypeScript.ErrorRecoverySet.BinOp);
  16085    setTokenInfo(TokenID.LessThanLessThan, Reservation.None, OperatorPrecedence.Shift, TypeScript.NodeType.Lsh, OperatorPrecedence.None, TypeScript.NodeType.None, "<<", TypeScript.ErrorRecoverySet.BinOp);
  16086    setTokenInfo(TokenID.GreaterThanGreaterThan, Reservation.None, OperatorPrecedence.Shift, TypeScript.NodeType.Rsh, OperatorPrecedence.None, TypeScript.NodeType.None, ">>", TypeScript.ErrorRecoverySet.BinOp);
  16087    setTokenInfo(TokenID.GreaterThanGreaterThanGreaterThan, Reservation.None, OperatorPrecedence.Shift, TypeScript.NodeType.Rs2, OperatorPrecedence.None, TypeScript.NodeType.None, ">>>", TypeScript.ErrorRecoverySet.BinOp);
  16088    setTokenInfo(TokenID.Plus, Reservation.None, OperatorPrecedence.Additive, TypeScript.NodeType.Add, OperatorPrecedence.Unary, TypeScript.NodeType.Pos, "+", TypeScript.ErrorRecoverySet.AddOp);
  16089    setTokenInfo(TokenID.Minus, Reservation.None, OperatorPrecedence.Additive, TypeScript.NodeType.Sub, OperatorPrecedence.Unary, TypeScript.NodeType.Neg, "-", TypeScript.ErrorRecoverySet.AddOp);
  16090    setTokenInfo(TokenID.Asterisk, Reservation.None, OperatorPrecedence.Multiplicative, TypeScript.NodeType.Mul, OperatorPrecedence.None, TypeScript.NodeType.None, "*", TypeScript.ErrorRecoverySet.BinOp);
  16091    setTokenInfo(TokenID.Slash, Reservation.None, OperatorPrecedence.Multiplicative, TypeScript.NodeType.Div, OperatorPrecedence.None, TypeScript.NodeType.None, "/", TypeScript.ErrorRecoverySet.BinOp);
  16092    setTokenInfo(TokenID.Percent, Reservation.None, OperatorPrecedence.Multiplicative, TypeScript.NodeType.Mod, OperatorPrecedence.None, TypeScript.NodeType.None, "%", TypeScript.ErrorRecoverySet.BinOp);
  16093    setTokenInfo(TokenID.Tilde, Reservation.None, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.Unary, TypeScript.NodeType.Not, "~", TypeScript.ErrorRecoverySet.PreOp);
  16094    setTokenInfo(TokenID.Exclamation, Reservation.None, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.Unary, TypeScript.NodeType.LogNot, "!", TypeScript.ErrorRecoverySet.PreOp);
  16095    setTokenInfo(TokenID.PlusPlus, Reservation.None, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.Unary, TypeScript.NodeType.IncPre, "++", TypeScript.ErrorRecoverySet.PreOp);
  16096    setTokenInfo(TokenID.MinusMinus, Reservation.None, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.Unary, TypeScript.NodeType.DecPre, "--", TypeScript.ErrorRecoverySet.PreOp);
  16097    setTokenInfo(TokenID.OpenParen, Reservation.None, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "(", TypeScript.ErrorRecoverySet.LParen);
  16098    setTokenInfo(TokenID.OpenBracket, Reservation.None, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "[", TypeScript.ErrorRecoverySet.LBrack);
  16099    setTokenInfo(TokenID.Dot, Reservation.None, OperatorPrecedence.Unary, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, ".", TypeScript.ErrorRecoverySet.Dot);
  16100    setTokenInfo(TokenID.EndOfFile, Reservation.None, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "<EOF>", TypeScript.ErrorRecoverySet.EOF);
  16101    setTokenInfo(TokenID.EqualsGreaterThan, Reservation.None, OperatorPrecedence.None, TypeScript.NodeType.None, OperatorPrecedence.None, TypeScript.NodeType.None, "=>", TypeScript.ErrorRecoverySet.None);
  16102    function lookupToken(tokenId) {
  16103        return TypeScript.tokenTable[tokenId];
  16104    }
  16105    TypeScript.lookupToken = lookupToken;
  16106    (function (TokenClass) {
  16107        TokenClass._map = [];
  16108        TokenClass._map[0] = "Punctuation";
  16109        TokenClass.Punctuation = 0;
  16110        TokenClass._map[1] = "Keyword";
  16111        TokenClass.Keyword = 1;
  16112        TokenClass._map[2] = "Operator";
  16113        TokenClass.Operator = 2;
  16114        TokenClass._map[3] = "Comment";
  16115        TokenClass.Comment = 3;
  16116        TokenClass._map[4] = "Whitespace";
  16117        TokenClass.Whitespace = 4;
  16118        TokenClass._map[5] = "Identifier";
  16119        TokenClass.Identifier = 5;
  16120        TokenClass._map[6] = "NumberLiteral";
  16121        TokenClass.NumberLiteral = 6;
  16122        TokenClass._map[7] = "StringLiteral";
  16123        TokenClass.StringLiteral = 7;
  16124        TokenClass._map[8] = "RegExpLiteral";
  16125        TokenClass.RegExpLiteral = 8;
  16126    })(TypeScript.TokenClass || (TypeScript.TokenClass = {}));
  16127    var TokenClass = TypeScript.TokenClass;
  16128    var SavedToken = (function () {
  16129        function SavedToken(tok, minChar, limChar) {
  16130            this.tok = tok;
  16131            this.minChar = minChar;
  16132            this.limChar = limChar;
  16133        }
  16134        return SavedToken;
  16135    })();
  16136    TypeScript.SavedToken = SavedToken;    
  16137    var Token = (function () {
  16138        function Token(tokenId) {
  16139            this.tokenId = tokenId;
  16140        }
  16141        Token.prototype.toString = function () {
  16142            return "token: " + this.tokenId + " " + this.getText() + " (" + (TokenID)._map[this.tokenId] + ")";
  16143        };
  16144        Token.prototype.print = function (line, outfile) {
  16145            outfile.WriteLine(this.toString() + ",on line" + line);
  16146        };
  16147        Token.prototype.getText = function () {
  16148            return TypeScript.tokenTable[this.tokenId].text;
  16149        };
  16150        Token.prototype.classification = function () {
  16151            if(this.tokenId <= TokenID.LimKeyword) {
  16152                return TokenClass.Keyword;
  16153            } else {
  16154                var tokenInfo = lookupToken(this.tokenId);
  16155                if(tokenInfo != undefined) {
  16156                    if((tokenInfo.unopNodeType != TypeScript.NodeType.None) || (tokenInfo.binopNodeType != TypeScript.NodeType.None)) {
  16157                        return TokenClass.Operator;
  16158                    }
  16159                }
  16160            }
  16161            return TokenClass.Punctuation;
  16162        };
  16163        return Token;
  16164    })();
  16165    TypeScript.Token = Token;    
  16166    var NumberLiteralToken = (function (_super) {
  16167        __extends(NumberLiteralToken, _super);
  16168        function NumberLiteralToken(value, hasEmptyFraction) {
  16169                _super.call(this, TokenID.NumberLiteral);
  16170            this.value = value;
  16171            this.hasEmptyFraction = hasEmptyFraction;
  16172        }
  16173        NumberLiteralToken.prototype.getText = function () {
  16174            return this.hasEmptyFraction ? this.value.toString() + ".0" : this.value.toString();
  16175        };
  16176        NumberLiteralToken.prototype.classification = function () {
  16177            return TokenClass.NumberLiteral;
  16178        };
  16179        return NumberLiteralToken;
  16180    })(Token);
  16181    TypeScript.NumberLiteralToken = NumberLiteralToken;    
  16182    var StringLiteralToken = (function (_super) {
  16183        __extends(StringLiteralToken, _super);
  16184        function StringLiteralToken(value) {
  16185                _super.call(this, TokenID.StringLiteral);
  16186            this.value = value;
  16187        }
  16188        StringLiteralToken.prototype.getText = function () {
  16189            return this.value;
  16190        };
  16191        StringLiteralToken.prototype.classification = function () {
  16192            return TokenClass.StringLiteral;
  16193        };
  16194        return StringLiteralToken;
  16195    })(Token);
  16196    TypeScript.StringLiteralToken = StringLiteralToken;    
  16197    var IdentifierToken = (function (_super) {
  16198        __extends(IdentifierToken, _super);
  16199        function IdentifierToken(value, hasEscapeSequence) {
  16200                _super.call(this, TokenID.Identifier);
  16201            this.value = value;
  16202            this.hasEscapeSequence = hasEscapeSequence;
  16203        }
  16204        IdentifierToken.prototype.getText = function () {
  16205            return this.value;
  16206        };
  16207        IdentifierToken.prototype.classification = function () {
  16208            return TokenClass.Identifier;
  16209        };
  16210        return IdentifierToken;
  16211    })(Token);
  16212    TypeScript.IdentifierToken = IdentifierToken;    
  16213    var WhitespaceToken = (function (_super) {
  16214        __extends(WhitespaceToken, _super);
  16215        function WhitespaceToken(tokenId, value) {
  16216                _super.call(this, tokenId);
  16217            this.value = value;
  16218        }
  16219        WhitespaceToken.prototype.getText = function () {
  16220            return this.value;
  16221        };
  16222        WhitespaceToken.prototype.classification = function () {
  16223            return TokenClass.Whitespace;
  16224        };
  16225        return WhitespaceToken;
  16226    })(Token);
  16227    TypeScript.WhitespaceToken = WhitespaceToken;    
  16228    var CommentToken = (function (_super) {
  16229        __extends(CommentToken, _super);
  16230        function CommentToken(tokenID, value, isBlock, startPos, line, endsLine) {
  16231                _super.call(this, tokenID);
  16232            this.value = value;
  16233            this.isBlock = isBlock;
  16234            this.startPos = startPos;
  16235            this.line = line;
  16236            this.endsLine = endsLine;
  16237        }
  16238        CommentToken.prototype.getText = function () {
  16239            return this.value;
  16240        };
  16241        CommentToken.prototype.classification = function () {
  16242            return TokenClass.Comment;
  16243        };
  16244        return CommentToken;
  16245    })(Token);
  16246    TypeScript.CommentToken = CommentToken;    
  16247    var RegularExpressionLiteralToken = (function (_super) {
  16248        __extends(RegularExpressionLiteralToken, _super);
  16249        function RegularExpressionLiteralToken(regex) {
  16250                _super.call(this, TokenID.RegularExpressionLiteral);
  16251            this.regex = regex;
  16252        }
  16253        RegularExpressionLiteralToken.prototype.getText = function () {
  16254            return this.regex.toString();
  16255        };
  16256        RegularExpressionLiteralToken.prototype.classification = function () {
  16257            return TokenClass.RegExpLiteral;
  16258        };
  16259        return RegularExpressionLiteralToken;
  16260    })(Token);
  16261    TypeScript.RegularExpressionLiteralToken = RegularExpressionLiteralToken;    
  16262    TypeScript.staticTokens = new Array();
  16263    function initializeStaticTokens() {
  16264        for(var i = 0; i <= TokenID.LimFixed; i++) {
  16265            TypeScript.staticTokens[i] = new Token(i);
  16266        }
  16267    }
  16268    TypeScript.initializeStaticTokens = initializeStaticTokens;
  16269 })(TypeScript || (TypeScript = {}));
  16270 var TypeScript;
  16271 (function (TypeScript) {
  16272    var ArrayCache = (function () {
  16273        function ArrayCache() {
  16274            this.arrayBase = null;
  16275        }
  16276        ArrayCache.prototype.specialize = function (arrInstType, checker) {
  16277            if(this.arrayBase == null) {
  16278                this.arrayBase = arrInstType.specializeType(checker.wildElm.type, this.arrayType.elementType, checker, true);
  16279            }
  16280            return this.arrayBase;
  16281        };
  16282        return ArrayCache;
  16283    })();
  16284    TypeScript.ArrayCache = ArrayCache;    
  16285    var TypeComparisonInfo = (function () {
  16286        function TypeComparisonInfo() {
  16287            this.onlyCaptureFirstError = false;
  16288            this.flags = TypeScript.TypeRelationshipFlags.SuccessfulComparison;
  16289            this.message = "";
  16290        }
  16291        TypeComparisonInfo.prototype.addMessageToFront = function (message) {
  16292            if(!this.onlyCaptureFirstError) {
  16293                this.message = this.message ? message + ":\n\t" + this.message : message;
  16294            } else {
  16295                this.setMessage(message);
  16296            }
  16297        };
  16298        TypeComparisonInfo.prototype.setMessage = function (message) {
  16299            this.message = message;
  16300        };
  16301        return TypeComparisonInfo;
  16302    })();
  16303    TypeScript.TypeComparisonInfo = TypeComparisonInfo;    
  16304    (function (TypeCheckCollectionMode) {
  16305        TypeCheckCollectionMode._map = [];
  16306        TypeCheckCollectionMode._map[0] = "Resident";
  16307        TypeCheckCollectionMode.Resident = 0;
  16308        TypeCheckCollectionMode._map[1] = "Transient";
  16309        TypeCheckCollectionMode.Transient = 1;
  16310    })(TypeScript.TypeCheckCollectionMode || (TypeScript.TypeCheckCollectionMode = {}));
  16311    var TypeCheckCollectionMode = TypeScript.TypeCheckCollectionMode;
  16312    var PersistentGlobalTypeState = (function () {
  16313        function PersistentGlobalTypeState(errorReporter) {
  16314            this.errorReporter = errorReporter;
  16315            this.importedGlobalsTable = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  16316            this.importedGlobalsTypeTable = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  16317            this.globals = null;
  16318            this.globalTypes = null;
  16319            this.ambientGlobals = null;
  16320            this.ambientGlobalTypes = null;
  16321            this.residentGlobalValues = new TypeScript.StringHashTable();
  16322            this.residentGlobalTypes = new TypeScript.StringHashTable();
  16323            this.residentGlobalAmbientValues = new TypeScript.StringHashTable();
  16324            this.residentGlobalAmbientTypes = new TypeScript.StringHashTable();
  16325            this.residentTypeCheck = true;
  16326            this.mod = null;
  16327            this.gloMod = null;
  16328            this.wildElm = null;
  16329            this.importedGlobals = new TypeScript.SymbolScopeBuilder(null, this.importedGlobalsTable, null, this.importedGlobalsTypeTable, null, null);
  16330            this.dualGlobalValues = new TypeScript.DualStringHashTable(this.residentGlobalValues, new TypeScript.StringHashTable());
  16331            this.dualGlobalTypes = new TypeScript.DualStringHashTable(this.residentGlobalTypes, new TypeScript.StringHashTable());
  16332            this.dualAmbientGlobalValues = new TypeScript.DualStringHashTable(this.residentGlobalAmbientValues, new TypeScript.StringHashTable());
  16333            this.dualAmbientGlobalTypes = new TypeScript.DualStringHashTable(this.residentGlobalAmbientTypes, new TypeScript.StringHashTable());
  16334            var dualGlobalScopedMembers = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(this.dualGlobalValues, new TypeScript.StringHashTable()));
  16335            var dualGlobalScopedAmbientMembers = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(this.dualAmbientGlobalValues, new TypeScript.StringHashTable()));
  16336            var dualGlobalScopedEnclosedTypes = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(this.dualGlobalTypes, new TypeScript.StringHashTable()));
  16337            var dualGlobalScopedAmbientEnclosedTypes = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(this.dualAmbientGlobalTypes, new TypeScript.StringHashTable()));
  16338            this.globalScope = new TypeScript.SymbolScopeBuilder(dualGlobalScopedMembers, dualGlobalScopedAmbientMembers, dualGlobalScopedEnclosedTypes, dualGlobalScopedAmbientEnclosedTypes, this.importedGlobals, null);
  16339            this.voidType = this.enterPrimitive(TypeScript.Primitive.Void, "void");
  16340            this.booleanType = this.enterPrimitive(TypeScript.Primitive.Boolean, "bool");
  16341            this.doubleType = this.enterPrimitive(TypeScript.Primitive.Double, "number");
  16342            this.importedGlobals.ambientEnclosedTypes.addPublicMember("number", this.doubleType.symbol);
  16343            this.stringType = this.enterPrimitive(TypeScript.Primitive.String, "string");
  16344            this.anyType = this.enterPrimitive(TypeScript.Primitive.Any, "any");
  16345            this.nullType = this.enterPrimitive(TypeScript.Primitive.Null, "null");
  16346            this.undefinedType = this.enterPrimitive(TypeScript.Primitive.Undefined, "undefined");
  16347            this.setCollectionMode(TypeCheckCollectionMode.Resident);
  16348            this.wildElm = new TypeScript.TypeSymbol("_element", -1, 0, -1, new TypeScript.Type());
  16349            this.importedGlobalsTypeTable.addPublicMember(this.wildElm.name, this.wildElm);
  16350            this.mod = new TypeScript.ModuleType(dualGlobalScopedEnclosedTypes, dualGlobalScopedAmbientEnclosedTypes);
  16351            this.mod.members = dualGlobalScopedMembers;
  16352            this.mod.ambientMembers = dualGlobalScopedAmbientMembers;
  16353            this.mod.containedScope = this.globalScope;
  16354            this.gloMod = new TypeScript.TypeSymbol(TypeScript.globalId, -1, 0, -1, this.mod);
  16355            this.mod.members.addPublicMember(this.gloMod.name, this.gloMod);
  16356            this.defineGlobalValue("undefined", this.undefinedType);
  16357        }
  16358        PersistentGlobalTypeState.prototype.enterPrimitive = function (flags, name) {
  16359            var primitive = new TypeScript.Type();
  16360            primitive.primitiveTypeClass = flags;
  16361            var symbol = new TypeScript.TypeSymbol(name, -1, name.length, -1, primitive);
  16362            symbol.typeCheckStatus = TypeScript.TypeCheckStatus.Finished;
  16363            primitive.symbol = symbol;
  16364            this.importedGlobals.enter(null, null, symbol, this.errorReporter, true, true, true);
  16365            return primitive;
  16366        };
  16367        PersistentGlobalTypeState.prototype.setCollectionMode = function (mode) {
  16368            this.residentTypeCheck = this.dualGlobalValues.insertPrimary = this.dualGlobalTypes.insertPrimary = this.dualAmbientGlobalValues.insertPrimary = this.dualAmbientGlobalTypes.insertPrimary = mode == TypeCheckCollectionMode.Resident;
  16369        };
  16370        PersistentGlobalTypeState.prototype.refreshPersistentState = function () {
  16371            this.globals = new TypeScript.StringHashTable();
  16372            this.globalTypes = new TypeScript.StringHashTable();
  16373            this.ambientGlobals = new TypeScript.StringHashTable();
  16374            this.ambientGlobalTypes = new TypeScript.StringHashTable();
  16375            this.globalTypes.add(this.voidType.symbol.name, this.voidType.symbol);
  16376            this.globalTypes.add(this.booleanType.symbol.name, this.booleanType.symbol);
  16377            this.globalTypes.add(this.doubleType.symbol.name, this.doubleType.symbol);
  16378            this.globalTypes.add("number", this.doubleType.symbol);
  16379            this.globalTypes.add(this.stringType.symbol.name, this.stringType.symbol);
  16380            this.globalTypes.add(this.anyType.symbol.name, this.anyType.symbol);
  16381            this.globalTypes.add(this.nullType.symbol.name, this.nullType.symbol);
  16382            this.globalTypes.add(this.undefinedType.symbol.name, this.undefinedType.symbol);
  16383            this.dualGlobalValues.secondaryTable = this.globals;
  16384            this.dualGlobalTypes.secondaryTable = this.globalTypes;
  16385            this.dualAmbientGlobalValues.secondaryTable = this.ambientGlobals;
  16386            this.dualAmbientGlobalTypes.secondaryTable = this.ambientGlobalTypes;
  16387        };
  16388        PersistentGlobalTypeState.prototype.defineGlobalValue = function (name, type) {
  16389            var valueLocation = new TypeScript.ValueLocation();
  16390            valueLocation.typeLink = new TypeScript.TypeLink();
  16391            var sym = new TypeScript.VariableSymbol(name, 0, -1, valueLocation);
  16392            sym.setType(type);
  16393            sym.typeCheckStatus = TypeScript.TypeCheckStatus.Finished;
  16394            sym.container = this.gloMod;
  16395            this.importedGlobalsTable.addPublicMember(name, sym);
  16396        };
  16397        return PersistentGlobalTypeState;
  16398    })();
  16399    TypeScript.PersistentGlobalTypeState = PersistentGlobalTypeState;    
  16400    var ContextualTypeContext = (function () {
  16401        function ContextualTypeContext(contextualType, provisional, contextID) {
  16402            this.contextualType = contextualType;
  16403            this.provisional = provisional;
  16404            this.contextID = contextID;
  16405            this.targetSig = null;
  16406            this.targetThis = null;
  16407            this.targetAccessorType = null;
  16408        }
  16409        return ContextualTypeContext;
  16410    })();
  16411    TypeScript.ContextualTypeContext = ContextualTypeContext;    
  16412    var ContextualTypingContextStack = (function () {
  16413        function ContextualTypingContextStack(checker) {
  16414            this.checker = checker;
  16415            this.contextStack = [];
  16416            this.hadProvisionalErrors = false;
  16417        }
  16418        ContextualTypingContextStack.contextID = TypeScript.TypeCheckStatus.Finished + 1;
  16419        ContextualTypingContextStack.prototype.pushContextualType = function (type, provisional) {
  16420            this.contextStack.push(new ContextualTypeContext(type, provisional, ContextualTypingContextStack.contextID++));
  16421            this.checker.errorReporter.pushToErrorSink = provisional;
  16422        };
  16423        ContextualTypingContextStack.prototype.popContextualType = function () {
  16424            var tc = this.contextStack.pop();
  16425            this.checker.errorReporter.pushToErrorSink = this.isProvisional();
  16426            this.hadProvisionalErrors = this.hadProvisionalErrors || (tc.provisional && (this.checker.errorReporter.getCapturedErrors().length));
  16427            this.checker.errorReporter.freeCapturedErrors();
  16428            return tc;
  16429        };
  16430        ContextualTypingContextStack.prototype.getContextualType = function () {
  16431            return (!this.contextStack.length ? null : this.contextStack[this.contextStack.length - 1]);
  16432        };
  16433        ContextualTypingContextStack.prototype.getContextID = function () {
  16434            return (!this.contextStack.length ? TypeScript.TypeCheckStatus.Finished : this.contextStack[this.contextStack.length - 1].contextID);
  16435        };
  16436        ContextualTypingContextStack.prototype.isProvisional = function () {
  16437            return (!this.contextStack.length ? false : this.contextStack[this.contextStack.length - 1].provisional);
  16438        };
  16439        return ContextualTypingContextStack;
  16440    })();
  16441    TypeScript.ContextualTypingContextStack = ContextualTypingContextStack;    
  16442    var TypeChecker = (function () {
  16443        function TypeChecker(persistentState) {
  16444            this.persistentState = persistentState;
  16445            this.errorReporter = null;
  16446            this.checkControlFlow = false;
  16447            this.printControlFlowGraph = false;
  16448            this.checkControlFlowUseDef = false;
  16449            this.styleSettings = null;
  16450            this.units = null;
  16451            this.anon = "_anonymous";
  16452            this.locationInfo = null;
  16453            this.typeFlow = null;
  16454            this.currentCompareA = null;
  16455            this.currentCompareB = null;
  16456            this.currentModDecl = null;
  16457            this.inBind = false;
  16458            this.inWith = false;
  16459            this.errorsOnWith = true;
  16460            this.currentContextualTypeContext = null;
  16461            this.resolvingBases = false;
  16462            this.canCallDefinitionSignature = false;
  16463            this.assignableCache = {
  16464            };
  16465            this.subtypeCache = {
  16466            };
  16467            this.identicalCache = {
  16468            };
  16469            this.provisionalStartedTypecheckObjects = [];
  16470            this.mustCaptureGlobalThis = false;
  16471            this.voidType = this.persistentState.voidType;
  16472            this.booleanType = this.persistentState.booleanType;
  16473            this.numberType = this.persistentState.doubleType;
  16474            this.stringType = this.persistentState.stringType;
  16475            this.anyType = this.persistentState.anyType;
  16476            this.nullType = this.persistentState.nullType;
  16477            this.undefinedType = this.persistentState.undefinedType;
  16478            this.globals = this.persistentState.dualGlobalValues;
  16479            this.globalTypes = this.persistentState.dualGlobalTypes;
  16480            this.ambientGlobals = this.persistentState.dualAmbientGlobalValues;
  16481            this.ambientGlobalTypes = this.persistentState.dualAmbientGlobalTypes;
  16482            this.gloModType = this.persistentState.mod;
  16483            this.gloMod = this.persistentState.gloMod;
  16484            this.wildElm = this.persistentState.wildElm;
  16485            this.globalScope = this.persistentState.globalScope;
  16486            this.typingContextStack = new ContextualTypingContextStack(this);
  16487        }
  16488        TypeChecker.prototype.setStyleOptions = function (style) {
  16489            this.styleSettings = style;
  16490        };
  16491        TypeChecker.prototype.setContextualType = function (type, provisional) {
  16492            this.typingContextStack.pushContextualType(type, provisional);
  16493            this.currentContextualTypeContext = this.typingContextStack.getContextualType();
  16494        };
  16495        TypeChecker.prototype.unsetContextualType = function () {
  16496            var lastTC = this.typingContextStack.popContextualType();
  16497            this.currentContextualTypeContext = this.typingContextStack.getContextualType();
  16498            return lastTC;
  16499        };
  16500        TypeChecker.prototype.hadProvisionalErrors = function () {
  16501            return this.typingContextStack.hadProvisionalErrors;
  16502        };
  16503        TypeChecker.prototype.resetProvisionalErrors = function () {
  16504            if(!this.typingContextStack.getContextualType()) {
  16505                this.typingContextStack.hadProvisionalErrors = false;
  16506            }
  16507        };
  16508        TypeChecker.prototype.typeCheckWithContextualType = function (contextType, provisional, condition, ast) {
  16509            if(condition) {
  16510                this.setContextualType(contextType, this.typingContextStack.isProvisional() || provisional);
  16511            }
  16512            this.typeFlow.typeCheck(ast);
  16513            if(condition) {
  16514                this.unsetContextualType();
  16515            }
  16516        };
  16517        TypeChecker.prototype.resetTargetType = function () {
  16518            this.currentContextualTypeContext = this.typingContextStack.getContextualType();
  16519        };
  16520        TypeChecker.prototype.killCurrentContextualType = function () {
  16521            this.currentContextualTypeContext = null;
  16522            this.errorReporter.pushToErrorSink = false;
  16523        };
  16524        TypeChecker.prototype.hasTargetType = function () {
  16525            return this.currentContextualTypeContext && this.currentContextualTypeContext.contextualType;
  16526        };
  16527        TypeChecker.prototype.getTargetTypeContext = function () {
  16528            return this.currentContextualTypeContext;
  16529        };
  16530        TypeChecker.prototype.inProvisionalTypecheckMode = function () {
  16531            return this.typingContextStack.isProvisional();
  16532        };
  16533        TypeChecker.prototype.getTypeCheckFinishedStatus = function () {
  16534            if(this.inProvisionalTypecheckMode()) {
  16535                return this.typingContextStack.getContextID();
  16536            }
  16537            return TypeScript.TypeCheckStatus.Finished;
  16538        };
  16539        TypeChecker.prototype.typeStatusIsFinished = function (status) {
  16540            return status == TypeScript.TypeCheckStatus.Finished || (this.inProvisionalTypecheckMode() && status == this.typingContextStack.getContextID());
  16541        };
  16542        TypeChecker.prototype.addStartedPTO = function (pto) {
  16543            if(this.inProvisionalTypecheckMode()) {
  16544                this.provisionalStartedTypecheckObjects[this.provisionalStartedTypecheckObjects.length] = pto;
  16545            }
  16546        };
  16547        TypeChecker.prototype.cleanStartedPTO = function () {
  16548            for(var i = 0; i < this.provisionalStartedTypecheckObjects.length; i++) {
  16549                if(this.provisionalStartedTypecheckObjects[i].typeCheckStatus >= this.typingContextStack.getContextID()) {
  16550                    this.provisionalStartedTypecheckObjects[i].typeCheckStatus = TypeScript.TypeCheckStatus.NotStarted;
  16551                }
  16552            }
  16553            this.provisionalStartedTypecheckObjects = [];
  16554        };
  16555        TypeChecker.prototype.collectTypes = function (ast) {
  16556            if(ast.nodeType == TypeScript.NodeType.Script) {
  16557                var script = ast;
  16558                this.locationInfo = script.locationInfo;
  16559            }
  16560            var globalChain = new TypeScript.ScopeChain(this.gloMod, null, this.globalScope);
  16561            var context = new TypeScript.TypeCollectionContext(globalChain, this);
  16562            TypeScript.getAstWalkerFactory().walk(ast, TypeScript.preCollectTypes, TypeScript.postCollectTypes, null, context);
  16563        };
  16564        TypeChecker.prototype.makeArrayType = function (type) {
  16565            if(type.arrayCache == null) {
  16566                type.arrayCache = new ArrayCache();
  16567                type.arrayCache.arrayType = new TypeScript.Type();
  16568                type.arrayCache.arrayType.elementType = type;
  16569                type.arrayCache.arrayType.symbol = type.symbol;
  16570            }
  16571            return type.arrayCache.arrayType;
  16572        };
  16573        TypeChecker.prototype.getParameterList = function (funcDecl, container) {
  16574            var args = funcDecl.arguments;
  16575            var parameterTable = null;
  16576            var parameterBuilder = null;
  16577            var len = args.members.length;
  16578            var nonOptionalParams = 0;
  16579            var result = [];
  16580            if(len > 0) {
  16581                parameterTable = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  16582                parameterBuilder = new TypeScript.SymbolScopeBuilder(parameterTable, null, null, null, null, container);
  16583                for(var i = 0; i < len; i++) {
  16584                    var parameter = args.members[i];
  16585                    var paramDef = new TypeScript.ValueLocation();
  16586                    var parameterSymbol = new TypeScript.ParameterSymbol(parameter.id.text, parameter.minChar, this.locationInfo.unitIndex, paramDef);
  16587                    parameterSymbol.declAST = parameter;
  16588                    parameterSymbol.funcDecl = funcDecl;
  16589                    parameter.id.sym = parameterSymbol;
  16590                    parameter.sym = parameterSymbol;
  16591                    paramDef.symbol = parameterSymbol;
  16592                    paramDef.typeLink = TypeScript.getTypeLink(parameter.typeExpr, this, false);
  16593                    parameterBuilder.enter(null, parameter, parameterSymbol, this.errorReporter, true, false, false);
  16594                    result[result.length] = parameterSymbol;
  16595                    if(!parameter.isOptionalArg()) {
  16596                        nonOptionalParams++;
  16597                    }
  16598                }
  16599            }
  16600            return {
  16601                parameters: result,
  16602                nonOptionalParameterCount: nonOptionalParams
  16603            };
  16604        };
  16605        TypeChecker.prototype.createFunctionSignature = function (funcDecl, container, scope, overloadGroupSym, addToScope) {
  16606            var isExported = TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Exported | TypeScript.FncFlags.ClassPropertyMethodExported) || container == this.gloMod;
  16607            var isStatic = TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Static);
  16608            var isPrivate = TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Private);
  16609            var isDefinition = TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Definition);
  16610            var isAmbient = TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Ambient);
  16611            var isConstructor = funcDecl.isConstructMember() || funcDecl.isConstructor;
  16612            var isGlobal = container == this.gloMod;
  16613            var signature = new TypeScript.Signature();
  16614            var isLambda = funcDecl.fncFlags & TypeScript.FncFlags.IsFunctionExpression;
  16615            if(funcDecl.returnTypeAnnotation || isDefinition) {
  16616                signature.returnType = TypeScript.getTypeLink(funcDecl.returnTypeAnnotation, this, false);
  16617            } else {
  16618                signature.returnType = new TypeScript.TypeLink();
  16619                signature.returnType.type = this.anyType;
  16620            }
  16621            signature.hasVariableArgList = funcDecl.variableArgList;
  16622            var sigData = this.getParameterList(funcDecl, container);
  16623            signature.parameters = sigData.parameters;
  16624            signature.nonOptionalParameterCount = sigData.nonOptionalParameterCount;
  16625            funcDecl.signature = signature;
  16626            signature.declAST = funcDecl;
  16627            var useOverloadGroupSym = overloadGroupSym && overloadGroupSym.getType() && !overloadGroupSym.isAccessor() && (funcDecl.isSignature() || (isAmbient == TypeScript.hasFlag(overloadGroupSym.flags, TypeScript.SymbolFlags.Ambient)));
  16628            if(useOverloadGroupSym && isPrivate != TypeScript.hasFlag(overloadGroupSym.flags, TypeScript.SymbolFlags.Private)) {
  16629                this.errorReporter.simpleError(funcDecl, "Public/Private visibility of overloads does not agree");
  16630            }
  16631            var groupType = useOverloadGroupSym ? overloadGroupSym.getType() : new TypeScript.Type();
  16632            if(isConstructor) {
  16633                if(groupType.construct == null) {
  16634                    groupType.construct = new TypeScript.SignatureGroup();
  16635                }
  16636                groupType.construct.addSignature(signature);
  16637                groupType.construct.hasImplementation = !(funcDecl.isSignature());
  16638                if(groupType.construct.hasImplementation) {
  16639                    groupType.setHasImplementation();
  16640                }
  16641            } else {
  16642                if(funcDecl.isIndexerMember()) {
  16643                    if(groupType.index == null) {
  16644                        groupType.index = new TypeScript.SignatureGroup();
  16645                        groupType.index.flags |= TypeScript.SignatureFlags.IsIndexer;
  16646                    }
  16647                    groupType.index.addSignature(signature);
  16648                    groupType.index.hasImplementation = !(funcDecl.isSignature());
  16649                    if(groupType.index.hasImplementation) {
  16650                        groupType.setHasImplementation();
  16651                    }
  16652                } else {
  16653                    if(groupType.call == null) {
  16654                        groupType.call = new TypeScript.SignatureGroup();
  16655                    }
  16656                    groupType.call.addSignature(signature);
  16657                    groupType.call.hasImplementation = !(funcDecl.isSignature());
  16658                    if(groupType.call.hasImplementation) {
  16659                        groupType.setHasImplementation();
  16660                    }
  16661                }
  16662            }
  16663            var instanceType = groupType.instanceType;
  16664            var funcName = null;
  16665            var usedHint = false;
  16666            if(funcDecl.name && !funcDecl.name.isMissing()) {
  16667                funcName = funcDecl.name.text;
  16668            } else {
  16669                if(funcDecl.hint) {
  16670                    funcName = funcDecl.hint;
  16671                    usedHint = true;
  16672                }
  16673            }
  16674            if(groupType.symbol == null) {
  16675                groupType.symbol = new TypeScript.TypeSymbol(funcName ? funcName : this.anon, funcDecl.minChar, funcDecl.limChar - funcDecl.minChar, this.locationInfo.unitIndex, groupType);
  16676                if(!useOverloadGroupSym) {
  16677                    groupType.symbol.declAST = funcDecl;
  16678                }
  16679            }
  16680            if(isStatic) {
  16681                groupType.symbol.flags |= TypeScript.SymbolFlags.Static;
  16682            }
  16683            if(isAmbient) {
  16684                groupType.symbol.flags |= TypeScript.SymbolFlags.Ambient;
  16685            }
  16686            if(isPrivate) {
  16687                groupType.symbol.flags |= TypeScript.SymbolFlags.Private;
  16688            }
  16689            groupType.symbol.isMethod = funcDecl.isMethod();
  16690            if(groupType.symbol.isMethod) {
  16691                groupType.symbol.flags |= TypeScript.SymbolFlags.Property;
  16692            }
  16693            funcDecl.type = groupType;
  16694            if(!isConstructor) {
  16695                if(funcName && !isLambda && !funcDecl.isAccessor() && !usedHint) {
  16696                    if(addToScope) {
  16697                        if(funcDecl.isMethod() && isStatic) {
  16698                            if(!(container).type.members.publicMembers.add(funcName, groupType.symbol)) {
  16699                                this.errorReporter.duplicateIdentifier(funcDecl, funcName);
  16700                            }
  16701                            groupType.symbol.container = container;
  16702                        } else {
  16703                            if(overloadGroupSym == null || (overloadGroupSym.declAST && !(overloadGroupSym.declAST).isOverload && (container.isType()))) {
  16704                                scope.enter(container, funcDecl, groupType.symbol, this.errorReporter, !isPrivate && (isExported || isStatic || isGlobal), false, isAmbient);
  16705                            }
  16706                        }
  16707                    } else {
  16708                        if(!funcDecl.isSpecialFn()) {
  16709                            groupType.symbol.container = container;
  16710                        }
  16711                    }
  16712                } else {
  16713                    if(!funcDecl.isSpecialFn()) {
  16714                        groupType.symbol.container = container;
  16715                    }
  16716                }
  16717            }
  16718            if(useOverloadGroupSym) {
  16719                var overloadGroupType = overloadGroupSym ? overloadGroupSym.getType() : null;
  16720                var classType = groupType;
  16721                if(classType != overloadGroupType) {
  16722                    if(classType.construct == null) {
  16723                        if(overloadGroupType && overloadGroupType.construct) {
  16724                            classType.construct = overloadGroupType.construct;
  16725                        } else {
  16726                            classType.construct = new TypeScript.SignatureGroup();
  16727                        }
  16728                    } else {
  16729                        if(overloadGroupType) {
  16730                            if(overloadGroupType.construct) {
  16731                                classType.construct.signatures.concat(overloadGroupType.construct.signatures);
  16732                            }
  16733                        }
  16734                    }
  16735                    if(overloadGroupType) {
  16736                        if(classType.call == null) {
  16737                            classType.call = overloadGroupType.call;
  16738                        } else {
  16739                            if(overloadGroupType.call) {
  16740                                classType.call.signatures.concat(overloadGroupType.call.signatures);
  16741                            }
  16742                        }
  16743                        if(!isStatic) {
  16744                            if(classType.instanceType == null) {
  16745                                classType.instanceType = overloadGroupType.instanceType;
  16746                            }
  16747                            var instanceType = classType.instanceType;
  16748                            if(instanceType) {
  16749                                if(instanceType.call == null) {
  16750                                    instanceType.call = overloadGroupType.call;
  16751                                } else {
  16752                                    if(overloadGroupType.call) {
  16753                                        instanceType.call.signatures.concat(overloadGroupType.call.signatures);
  16754                                    }
  16755                                }
  16756                            }
  16757                        }
  16758                        if(classType.index == null) {
  16759                            classType.index = overloadGroupType.index;
  16760                        } else {
  16761                            if(overloadGroupType.index) {
  16762                                classType.index.signatures.concat(overloadGroupType.index.signatures);
  16763                            }
  16764                        }
  16765                    }
  16766                }
  16767            }
  16768            return signature;
  16769        };
  16770        TypeChecker.prototype.createAccessorSymbol = function (funcDecl, fgSym, enclosingClass, addToMembers, isClassProperty, scope, container) {
  16771            var accessorSym = null;
  16772            var sig = funcDecl.signature;
  16773            var nameText = funcDecl.name.text;
  16774            var isStatic = TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Static);
  16775            var isPrivate = TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Private);
  16776            if(fgSym == null) {
  16777                var field = new TypeScript.ValueLocation();
  16778                accessorSym = new TypeScript.FieldSymbol(nameText, funcDecl.minChar, this.locationInfo.unitIndex, false, field);
  16779                field.symbol = accessorSym;
  16780                accessorSym.declAST = funcDecl;
  16781                if(TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.GetAccessor)) {
  16782                    if(accessorSym.getter) {
  16783                        this.errorReporter.simpleError(funcDecl, "Redeclaration of property getter");
  16784                    }
  16785                    accessorSym.getter = sig.declAST.type.symbol;
  16786                } else {
  16787                    if(accessorSym.setter) {
  16788                        this.errorReporter.simpleError(funcDecl, "Redeclaration of property setter");
  16789                    }
  16790                    accessorSym.setter = sig.declAST.type.symbol;
  16791                }
  16792                field.typeLink = TypeScript.getTypeLink(null, this, false);
  16793                if(addToMembers) {
  16794                    if(enclosingClass) {
  16795                        if(!enclosingClass.members.publicMembers.add(nameText, accessorSym)) {
  16796                            this.errorReporter.duplicateIdentifier(funcDecl, accessorSym.name);
  16797                        }
  16798                        accessorSym.container = enclosingClass.symbol;
  16799                    } else {
  16800                        this.errorReporter.simpleError(funcDecl, "Accessor property may not be added in this context");
  16801                    }
  16802                } else {
  16803                    scope.enter(container, funcDecl, accessorSym, this.errorReporter, !isPrivate || isStatic, false, false);
  16804                }
  16805                if(isClassProperty) {
  16806                    accessorSym.flags |= TypeScript.SymbolFlags.Property;
  16807                }
  16808                if(isStatic) {
  16809                    accessorSym.flags |= TypeScript.SymbolFlags.Static;
  16810                }
  16811                if(isPrivate) {
  16812                    accessorSym.flags |= TypeScript.SymbolFlags.Private;
  16813                } else {
  16814                    accessorSym.flags |= TypeScript.SymbolFlags.Public;
  16815                }
  16816            } else {
  16817                accessorSym = (fgSym);
  16818                if(isPrivate != TypeScript.hasFlag(accessorSym.flags, TypeScript.SymbolFlags.Private)) {
  16819                    this.errorReporter.simpleError(funcDecl, "Getter and setter accessors do not agree in visibility");
  16820                }
  16821                if(TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.GetAccessor)) {
  16822                    if(accessorSym.getter) {
  16823                        this.errorReporter.simpleError(funcDecl, "Redeclaration of property getter");
  16824                    }
  16825                    accessorSym.getter = funcDecl.type.symbol;
  16826                } else {
  16827                    if(accessorSym.setter) {
  16828                        this.errorReporter.simpleError(funcDecl, "Redeclaration of property setter");
  16829                    }
  16830                    accessorSym.setter = funcDecl.type.symbol;
  16831                }
  16832            }
  16833            return accessorSym;
  16834        };
  16835        TypeChecker.prototype.addBases = function (resultScope, type, baseContext) {
  16836            resultScope.addParentScope(new TypeScript.SymbolTableScope(type.members, type.ambientMembers, type.getAllEnclosedTypes(), type.getAllAmbientEnclosedTypes(), type.symbol));
  16837            var i = 0;
  16838            var parent;
  16839            if(type.extendsList) {
  16840                for(var len = type.extendsList.length; i < len; i++) {
  16841                    parent = type.extendsList[i];
  16842                    if(baseContext.baseId == parent.typeID) {
  16843                        this.errorReporter.reportErrorFromSym(parent.symbol, "Type '" + baseContext.base + "' is recursively referenced as a base class of itself");
  16844                        parent.symbol.flags |= TypeScript.SymbolFlags.RecursivelyReferenced;
  16845                        break;
  16846                    }
  16847                    this.addBases(resultScope, parent, baseContext);
  16848                }
  16849            }
  16850        };
  16851        TypeChecker.prototype.scopeOf = function (type) {
  16852            var resultScope = new TypeScript.SymbolAggregateScope(type.symbol);
  16853            var baseContext = {
  16854                base: type.symbol && type.symbol.name ? type.symbol.name : "{}",
  16855                baseId: type.typeID
  16856            };
  16857            this.addBases(resultScope, type, baseContext);
  16858            return resultScope;
  16859        };
  16860        TypeChecker.prototype.lookupMemberTypeSymbol = function (containingType, name) {
  16861            var symbol = null;
  16862            if(containingType.containedScope) {
  16863                symbol = containingType.containedScope.find(name, false, true);
  16864            } else {
  16865                if(containingType.members) {
  16866                    symbol = containingType.members.allMembers.lookup(name);
  16867                    if(symbol == null && containingType.ambientMembers) {
  16868                        symbol = containingType.ambientMembers.allMembers.lookup(name);
  16869                    }
  16870                }
  16871            }
  16872            if(symbol == null) {
  16873                var typeMembers = containingType.getAllEnclosedTypes();
  16874                var ambientTypeMembers = containingType.getAllAmbientEnclosedTypes();
  16875                if(typeMembers) {
  16876                    symbol = typeMembers.allMembers.lookup(name);
  16877                    if(symbol == null && ambientTypeMembers) {
  16878                        symbol = ambientTypeMembers.allMembers.lookup(name);
  16879                    }
  16880                }
  16881            }
  16882            if(symbol && symbol.isType()) {
  16883                return symbol;
  16884            } else {
  16885                return null;
  16886            }
  16887        };
  16888        TypeChecker.prototype.findSymbolForDynamicModule = function (idText, currentFileName, search) {
  16889            var originalIdText = idText;
  16890            var symbol = search(idText);
  16891            if(symbol == null) {
  16892                if(!symbol) {
  16893                    idText = TypeScript.swapQuotes(originalIdText);
  16894                    symbol = search(idText);
  16895                }
  16896                if(!symbol) {
  16897                    idText = TypeScript.stripQuotes(originalIdText) + ".ts";
  16898                    symbol = search(idText);
  16899                }
  16900                if(!symbol) {
  16901                    idText = TypeScript.stripQuotes(originalIdText) + ".str";
  16902                    symbol = search(idText);
  16903                }
  16904                if(!symbol) {
  16905                    idText = TypeScript.stripQuotes(originalIdText) + ".d.ts";
  16906                    symbol = search(idText);
  16907                }
  16908                if(!symbol) {
  16909                    idText = TypeScript.stripQuotes(originalIdText) + ".d.str";
  16910                    symbol = search(idText);
  16911                }
  16912                if(!symbol && !TypeScript.isRelative(originalIdText)) {
  16913                    idText = originalIdText;
  16914                    var strippedIdText = TypeScript.stripQuotes(idText);
  16915                    var path = TypeScript.getRootFilePath(TypeScript.switchToForwardSlashes(currentFileName));
  16916                    while(symbol == null && path != "") {
  16917                        idText = TypeScript.normalizePath(path + strippedIdText + ".ts");
  16918                        symbol = search(idText);
  16919                        if(symbol == null) {
  16920                            idText = TypeScript.changePathToSTR(idText);
  16921                            symbol = search(idText);
  16922                        }
  16923                        if(symbol == null) {
  16924                            idText = TypeScript.changePathToDTS(idText);
  16925                            symbol = search(idText);
  16926                        }
  16927                        if(symbol == null) {
  16928                            idText = TypeScript.changePathToDSTR(idText);
  16929                            symbol = search(idText);
  16930                        }
  16931                        if(symbol == null) {
  16932                            if(path === '/') {
  16933                                path = '';
  16934                            } else {
  16935                                path = TypeScript.normalizePath(path + "..");
  16936                                path = path && path != '/' ? path + '/' : path;
  16937                            }
  16938                        }
  16939                    }
  16940                }
  16941            }
  16942            return symbol;
  16943        };
  16944        TypeChecker.prototype.resolveTypeMember = function (scope, dotNode) {
  16945            var lhs = dotNode.operand1;
  16946            var rhs = dotNode.operand2;
  16947            var resultType = this.anyType;
  16948            var lhsType = this.anyType;
  16949            if(lhs && rhs && (rhs.nodeType == TypeScript.NodeType.Name)) {
  16950                if(lhs.nodeType == TypeScript.NodeType.Dot) {
  16951                    lhsType = this.resolveTypeMember(scope, lhs);
  16952                } else {
  16953                    if(lhs.nodeType == TypeScript.NodeType.Name) {
  16954                        var identifier = lhs;
  16955                        var symbol = scope.find(identifier.text, false, true);
  16956                        if(symbol == null) {
  16957                            this.errorReporter.unresolvedSymbol(identifier, identifier.actualText);
  16958                        } else {
  16959                            if(symbol.isType()) {
  16960                                var typeSymbol = symbol;
  16961                                if(typeSymbol.aliasLink && !typeSymbol.type && typeSymbol.aliasLink.alias.nodeType == TypeScript.NodeType.Name) {
  16962                                    var modPath = (typeSymbol.aliasLink.alias).text;
  16963                                    var modSym = this.findSymbolForDynamicModule(modPath, this.locationInfo.filename, function (id) {
  16964                                        return scope.find(id, false, true);
  16965                                    });
  16966                                    if(modSym) {
  16967                                        typeSymbol.type = modSym.getType();
  16968                                    }
  16969                                }
  16970                                if(TypeScript.optimizeModuleCodeGen && symbol) {
  16971                                    var symType = symbol.getType();
  16972                                    if(symType && typeSymbol.aliasLink && typeSymbol.onlyReferencedAsTypeRef) {
  16973                                        var modDecl = symType.symbol.declAST;
  16974                                        if(modDecl && TypeScript.hasFlag(modDecl.modFlags, TypeScript.ModuleFlags.IsDynamic)) {
  16975                                            typeSymbol.onlyReferencedAsTypeRef = !this.resolvingBases;
  16976                                        }
  16977                                    }
  16978                                }
  16979                                if(!symbol.visible(scope, this)) {
  16980                                    this.errorReporter.simpleError(lhs, "The symbol '" + identifier.actualText + "' is not visible at this point");
  16981                                }
  16982                                lhsType = symbol.getType();
  16983                                identifier.sym = symbol;
  16984                            } else {
  16985                                this.errorReporter.simpleError(lhs, "Expected type");
  16986                            }
  16987                        }
  16988                    }
  16989                }
  16990                if(!lhsType) {
  16991                    lhsType = this.anyType;
  16992                }
  16993                if(lhsType != this.anyType) {
  16994                    var rhsIdentifier = rhs;
  16995                    var resultSymbol = this.lookupMemberTypeSymbol(lhsType, rhsIdentifier.text);
  16996                    if(resultSymbol == null) {
  16997                        resultType = this.anyType;
  16998                        this.errorReporter.simpleError(dotNode, "Expected type");
  16999                    } else {
  17000                        resultType = resultSymbol.getType();
  17001                        if(!resultSymbol.visible(scope, this)) {
  17002                            this.errorReporter.simpleError(lhs, "The symbol '" + (rhs).actualText + "' is not visible at this point");
  17003                        }
  17004                    }
  17005                    rhsIdentifier.sym = resultType.symbol;
  17006                }
  17007            }
  17008            if(resultType.isClass()) {
  17009                resultType = resultType.instanceType;
  17010            }
  17011            return resultType;
  17012        };
  17013        TypeChecker.prototype.resolveFuncDecl = function (funcDecl, scope, fgSym) {
  17014            var functionGroupSymbol = this.createFunctionSignature(funcDecl, scope.container, scope, fgSym, false).declAST.type.symbol;
  17015            var signatures;
  17016            if(funcDecl.isConstructMember()) {
  17017                signatures = functionGroupSymbol.type.construct.signatures;
  17018            } else {
  17019                if(funcDecl.isIndexerMember()) {
  17020                    signatures = functionGroupSymbol.type.getInstanceType().index.signatures;
  17021                } else {
  17022                    signatures = functionGroupSymbol.type.call.signatures;
  17023                }
  17024            }
  17025            var signature = signatures[signatures.length - 1];
  17026            var len = signature.parameters.length;
  17027            for(var i = 0; i < len; i++) {
  17028                var paramSym = signature.parameters[i];
  17029                this.resolveTypeLink(scope, paramSym.parameter.typeLink, true);
  17030            }
  17031            if(len && funcDecl.variableArgList) {
  17032                if(!signature.parameters[len - 1].parameter.typeLink.type.elementType) {
  17033                    this.errorReporter.simpleErrorFromSym(signature.parameters[len - 1].parameter.symbol, "... parameter must have array type");
  17034                    signature.parameters[len - 1].parameter.typeLink.type = this.makeArrayType(signature.parameters[len - 1].parameter.typeLink.type);
  17035                }
  17036            }
  17037            this.resolveTypeLink(scope, signature.returnType, funcDecl.isSignature());
  17038            return functionGroupSymbol;
  17039        };
  17040        TypeChecker.prototype.resolveVarDecl = function (varDecl, scope) {
  17041            var field = new TypeScript.ValueLocation();
  17042            var fieldSymbol = new TypeScript.FieldSymbol(varDecl.id.text, varDecl.minChar, this.locationInfo.unitIndex, (varDecl.varFlags & TypeScript.VarFlags.Readonly) == TypeScript.VarFlags.None, field);
  17043            fieldSymbol.transferVarFlags(varDecl.varFlags);
  17044            field.symbol = fieldSymbol;
  17045            fieldSymbol.declAST = varDecl;
  17046            field.typeLink = TypeScript.getTypeLink(varDecl.typeExpr, this, varDecl.init == null);
  17047            this.resolveTypeLink(scope, field.typeLink, true);
  17048            varDecl.sym = fieldSymbol;
  17049            varDecl.type = field.typeLink.type;
  17050            return fieldSymbol;
  17051        };
  17052        TypeChecker.prototype.resolveTypeLink = function (scope, typeLink, supplyVar) {
  17053            var arrayCount = 0;
  17054            if(typeLink.type == null) {
  17055                var ast = typeLink.ast;
  17056                if(ast) {
  17057                    while(typeLink.type == null) {
  17058                        switch(ast.nodeType) {
  17059                            case TypeScript.NodeType.Name: {
  17060                                var identifier = ast;
  17061                                var symbol = scope.find(identifier.text, false, true);
  17062                                if(symbol == null) {
  17063                                    typeLink.type = this.anyType;
  17064                                    this.errorReporter.unresolvedSymbol(identifier, identifier.actualText);
  17065                                } else {
  17066                                    if(symbol.isType()) {
  17067                                        if(!symbol.visible(scope, this)) {
  17068                                            this.errorReporter.simpleError(ast, "The symbol '" + identifier.actualText + "' is not visible at this point");
  17069                                        }
  17070                                        identifier.sym = symbol;
  17071                                        typeLink.type = symbol.getType();
  17072                                        if(typeLink.type) {
  17073                                            if(typeLink.type.isClass()) {
  17074                                                typeLink.type = typeLink.type.instanceType;
  17075                                            }
  17076                                        } else {
  17077                                            typeLink.type = this.anyType;
  17078                                        }
  17079                                    } else {
  17080                                        typeLink.type = this.anyType;
  17081                                        this.errorReporter.simpleError(ast, "Expected type");
  17082                                    }
  17083                                }
  17084                                break;
  17085 
  17086                            }
  17087                            case TypeScript.NodeType.Dot: {
  17088                                typeLink.type = this.resolveTypeMember(scope, ast);
  17089                                break;
  17090 
  17091                            }
  17092                            case TypeScript.NodeType.TypeRef: {
  17093                                var typeRef = ast;
  17094                                arrayCount = typeRef.arrayCount;
  17095                                ast = typeRef.term;
  17096                                if(ast == null) {
  17097                                    typeLink.type = this.anyType;
  17098                                }
  17099                                break;
  17100 
  17101                            }
  17102                            case TypeScript.NodeType.InterfaceDeclaration: {
  17103                                var interfaceDecl = ast;
  17104                                var interfaceType = new TypeScript.Type();
  17105                                var interfaceSymbol = new TypeScript.TypeSymbol((interfaceDecl.name).text, ast.minChar, ast.limChar - ast.minChar, this.locationInfo.unitIndex, interfaceType);
  17106                                interfaceType.symbol = interfaceSymbol;
  17107                                interfaceType.members = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  17108                                interfaceType.containedScope = new TypeScript.SymbolTableScope(interfaceType.members, null, null, null, interfaceSymbol);
  17109                                interfaceType.containedScope.container = interfaceSymbol;
  17110                                interfaceType.memberScope = interfaceType.containedScope;
  17111                                var memberList = interfaceDecl.members;
  17112                                var props = memberList.members;
  17113                                var propsLen = props.length;
  17114                                for(var j = 0; j < propsLen; j++) {
  17115                                    var propDecl = props[j];
  17116                                    var propSym = null;
  17117                                    var addMember = true;
  17118                                    var id = null;
  17119                                    if(propDecl.nodeType == TypeScript.NodeType.FuncDecl) {
  17120                                        var funcDecl = propDecl;
  17121                                        id = funcDecl.name;
  17122                                        propSym = interfaceType.members.allMembers.lookup(funcDecl.getNameText());
  17123                                        addMember = (propSym == null);
  17124                                        if(funcDecl.isSpecialFn()) {
  17125                                            addMember = false;
  17126                                            propSym = this.resolveFuncDecl(funcDecl, scope, interfaceSymbol);
  17127                                        } else {
  17128                                            propSym = this.resolveFuncDecl(funcDecl, scope, propSym);
  17129                                        }
  17130                                        funcDecl.type = (propSym).type;
  17131                                    } else {
  17132                                        id = (propDecl).id;
  17133                                        propSym = this.resolveVarDecl(propDecl, scope);
  17134                                        addMember = !id.isMissing();
  17135                                    }
  17136                                    if(addMember) {
  17137                                        if(id && TypeScript.hasFlag(id.flags, TypeScript.ASTFlags.OptionalName)) {
  17138                                            propSym.flags |= TypeScript.SymbolFlags.Optional;
  17139                                        }
  17140                                        if(!interfaceType.members.allMembers.add(propSym.name, propSym)) {
  17141                                            this.errorReporter.duplicateIdentifier(ast, propSym.name);
  17142                                        }
  17143                                    }
  17144                                }
  17145                                ast.type = interfaceType;
  17146                                typeLink.type = interfaceType;
  17147                                break;
  17148 
  17149                            }
  17150                            case TypeScript.NodeType.FuncDecl: {
  17151                                var tsym = this.resolveFuncDecl(ast, scope, null);
  17152                                typeLink.type = tsym.type;
  17153                                break;
  17154 
  17155                            }
  17156                            default: {
  17157                                typeLink.type = this.anyType;
  17158                                this.errorReporter.simpleError(ast, "Expected type");
  17159                                break;
  17160 
  17161                            }
  17162                        }
  17163                    }
  17164                }
  17165                for(var count = arrayCount; count > 0; count--) {
  17166                    typeLink.type = this.makeArrayType(typeLink.type);
  17167                }
  17168                if(supplyVar && (typeLink.type == null)) {
  17169                    typeLink.type = this.anyType;
  17170                }
  17171                if(typeLink.ast) {
  17172                    typeLink.ast.type = typeLink.type;
  17173                }
  17174            }
  17175        };
  17176        TypeChecker.prototype.resolveBaseTypeLink = function (typeLink, scope) {
  17177            this.resolvingBases = true;
  17178            this.resolveTypeLink(scope, typeLink, true);
  17179            this.resolvingBases = false;
  17180            var extendsType = null;
  17181            if(typeLink.type.isClass()) {
  17182                extendsType = typeLink.type.instanceType;
  17183            } else {
  17184                extendsType = typeLink.type;
  17185            }
  17186            return extendsType;
  17187        };
  17188        TypeChecker.prototype.findMostApplicableSignature = function (signatures, args) {
  17189            if(signatures.length == 1) {
  17190                return {
  17191                    sig: signatures[0].signature,
  17192                    ambiguous: false
  17193                };
  17194            }
  17195            var best = signatures[0];
  17196            var Q = null;
  17197            var AType = null;
  17198            var PType = null;
  17199            var QType = null;
  17200            var ambiguous = false;
  17201            for(var qSig = 1; qSig < signatures.length; qSig++) {
  17202                Q = signatures[qSig];
  17203                var i = 0;
  17204                for(i = 0; args && i < args.members.length; i++) {
  17205                    AType = args.members[i].type;
  17206                    PType = i < best.signature.parameters.length ? best.signature.parameters[i].getType() : best.signature.parameters[best.signature.parameters.length - 1].getType().elementType;
  17207                    QType = i < Q.signature.parameters.length ? Q.signature.parameters[i].getType() : Q.signature.parameters[Q.signature.parameters.length - 1].getType().elementType;
  17208                    if(this.typesAreIdentical(PType, QType)) {
  17209                        continue;
  17210                    } else {
  17211                        if(this.typesAreIdentical(AType, PType)) {
  17212                            break;
  17213                        } else {
  17214                            if(this.typesAreIdentical(AType, QType)) {
  17215                                best = Q;
  17216                                break;
  17217                            } else {
  17218                                if(this.sourceIsSubtypeOfTarget(PType, QType)) {
  17219                                    break;
  17220                                } else {
  17221                                    if(this.sourceIsSubtypeOfTarget(QType, PType)) {
  17222                                        best = Q;
  17223                                        break;
  17224                                    } else {
  17225                                        if(Q.hadProvisionalErrors) {
  17226                                            break;
  17227                                        } else {
  17228                                            if(best.hadProvisionalErrors) {
  17229                                                best = Q;
  17230                                                break;
  17231                                            }
  17232                                        }
  17233                                    }
  17234                                }
  17235                            }
  17236                        }
  17237                    }
  17238                }
  17239                if(!args || i == args.members.length) {
  17240                    var collection = {
  17241                        getLength: function () {
  17242                            return 2;
  17243                        },
  17244                        setTypeAtIndex: function (index, type) {
  17245                        },
  17246                        getTypeAtIndex: function (index) {
  17247                            return index ? Q.signature.returnType.type : best.signature.returnType.type;
  17248                        }
  17249                    };
  17250                    var bct = this.findBestCommonType(best.signature.returnType.type, null, collection, true);
  17251                    ambiguous = !bct;
  17252                } else {
  17253                    ambiguous = false;
  17254                }
  17255            }
  17256            return {
  17257                sig: best.signature,
  17258                ambiguous: ambiguous
  17259            };
  17260        };
  17261        TypeChecker.prototype.getApplicableSignatures = function (signatures, args, comparisonInfo) {
  17262            var applicableSigs = [];
  17263            var memberType = null;
  17264            var miss = false;
  17265            var cxt = null;
  17266            var hadProvisionalErrors = false;
  17267            for(var i = 0; i < signatures.length; i++) {
  17268                miss = false;
  17269                for(var j = 0; j < args.members.length; j++) {
  17270                    if(j >= signatures[i].parameters.length) {
  17271                        continue;
  17272                    }
  17273                    memberType = signatures[i].parameters[j].getType();
  17274                    if(signatures[i].declAST.variableArgList && (j >= signatures[i].nonOptionalParameterCount - 1) && memberType.isArray()) {
  17275                        memberType = memberType.elementType;
  17276                    }
  17277                    if(memberType == this.anyType) {
  17278                        continue;
  17279                    } else {
  17280                        if(args.members[j].nodeType == TypeScript.NodeType.FuncDecl) {
  17281                            if(this.typeFlow.functionInterfaceType && memberType == this.typeFlow.functionInterfaceType) {
  17282                                continue;
  17283                            }
  17284                            if(!this.canContextuallyTypeFunction(memberType, args.members[j], true)) {
  17285                                if(this.canContextuallyTypeFunction(memberType, args.members[j], false)) {
  17286                                    this.typeFlow.typeCheck(args.members[j]);
  17287                                    if(!this.sourceIsAssignableToTarget(args.members[j].type, memberType, comparisonInfo)) {
  17288                                        break;
  17289                                    }
  17290                                } else {
  17291                                    break;
  17292                                }
  17293                            } else {
  17294                                this.typeCheckWithContextualType(memberType, true, true, args.members[j]);
  17295                                this.cleanStartedPTO();
  17296                                hadProvisionalErrors = this.hadProvisionalErrors();
  17297                                if(!this.sourceIsAssignableToTarget(args.members[j].type, memberType, comparisonInfo)) {
  17298                                    if(comparisonInfo) {
  17299                                        comparisonInfo.setMessage("Could not apply type '" + memberType.getTypeName() + "' to argument " + (j + 1) + ", which is of type '" + args.members[j].type.getTypeName() + "'");
  17300                                    }
  17301                                    miss = true;
  17302                                }
  17303                                this.resetProvisionalErrors();
  17304                                if(miss) {
  17305                                    break;
  17306                                }
  17307                            }
  17308                        } else {
  17309                            if(args.members[j].nodeType == TypeScript.NodeType.ObjectLit) {
  17310                                if(this.typeFlow.objectInterfaceType && memberType == this.typeFlow.objectInterfaceType) {
  17311                                    continue;
  17312                                }
  17313                                this.typeCheckWithContextualType(memberType, true, true, args.members[j]);
  17314                                this.cleanStartedPTO();
  17315                                hadProvisionalErrors = this.hadProvisionalErrors();
  17316                                if(!this.sourceIsAssignableToTarget(args.members[j].type, memberType, comparisonInfo)) {
  17317                                    if(comparisonInfo) {
  17318                                        comparisonInfo.setMessage("Could not apply type '" + memberType.getTypeName() + "' to argument " + (j + 1) + ", which is of type '" + args.members[j].type.getTypeName() + "'");
  17319                                    }
  17320                                    miss = true;
  17321                                }
  17322                                this.resetProvisionalErrors();
  17323                                if(miss) {
  17324                                    break;
  17325                                }
  17326                            } else {
  17327                                if(args.members[j].nodeType == TypeScript.NodeType.ArrayLit) {
  17328                                    if(this.typeFlow.arrayInterfaceType && memberType == this.typeFlow.arrayInterfaceType) {
  17329                                        continue;
  17330                                    }
  17331                                    this.typeCheckWithContextualType(memberType, true, true, args.members[j]);
  17332                                    this.cleanStartedPTO();
  17333                                    hadProvisionalErrors = this.hadProvisionalErrors();
  17334                                    if(!this.sourceIsAssignableToTarget(args.members[j].type, memberType, comparisonInfo)) {
  17335                                        if(comparisonInfo) {
  17336                                            comparisonInfo.setMessage("Could not apply type '" + memberType.getTypeName() + "' to argument " + (j + 1) + ", which is of type '" + args.members[j].type.getTypeName() + "'");
  17337                                        }
  17338                                        break;
  17339                                    }
  17340                                    this.resetProvisionalErrors();
  17341                                    if(miss) {
  17342                                        break;
  17343                                    }
  17344                                }
  17345                            }
  17346                        }
  17347                    }
  17348                }
  17349                if(j == args.members.length) {
  17350                    applicableSigs[applicableSigs.length] = {
  17351                        signature: signatures[i],
  17352                        hadProvisionalErrors: hadProvisionalErrors
  17353                    };
  17354                }
  17355                hadProvisionalErrors = false;
  17356            }
  17357            return applicableSigs;
  17358        };
  17359        TypeChecker.prototype.canContextuallyTypeFunction = function (candidateType, funcDecl, beStringent) {
  17360            if(funcDecl.isParenthesized || funcDecl.isMethod() || beStringent && funcDecl.returnTypeAnnotation || funcDecl.isInlineCallLiteral) {
  17361                return false;
  17362            }
  17363            beStringent = beStringent || (this.typeFlow.functionInterfaceType == candidateType);
  17364            if(!beStringent) {
  17365                return true;
  17366            }
  17367            if(!funcDecl.signature) {
  17368                this.createFunctionSignature(funcDecl, this.typeFlow.scope.container, this.typeFlow.scope, null, null);
  17369                this.typeFlow.typeCheck(funcDecl);
  17370            }
  17371            var signature = funcDecl.signature;
  17372            var paramLen = signature.parameters.length;
  17373            for(var i = 0; i < paramLen; i++) {
  17374                var param = signature.parameters[i];
  17375                var symbol = param;
  17376                var argDecl = symbol.declAST;
  17377                if(beStringent && argDecl.typeExpr) {
  17378                    return false;
  17379                }
  17380            }
  17381            if(candidateType.construct && candidateType.call) {
  17382                return false;
  17383            }
  17384            var candidateSigs = candidateType.construct ? candidateType.construct : candidateType.call;
  17385            if(!candidateSigs || candidateSigs.signatures.length > 1) {
  17386                return false;
  17387            }
  17388            return true;
  17389        };
  17390        TypeChecker.prototype.canContextuallyTypeObjectLiteral = function (targetType, objectLit) {
  17391            if(targetType == this.typeFlow.objectInterfaceType) {
  17392                return true;
  17393            }
  17394            var memberDecls = objectLit.operand;
  17395            if(!(memberDecls && targetType.memberScope)) {
  17396                return false;
  17397            }
  17398            var id = null;
  17399            var targetMember = null;
  17400            var text = "";
  17401            var foundSyms = {
  17402            };
  17403            for(var i = 0; i < memberDecls.members.length; i++) {
  17404                id = (memberDecls.members[i]).operand1;
  17405                if(id.nodeType == TypeScript.NodeType.Name) {
  17406                    text = (id).text;
  17407                } else {
  17408                    if(id.nodeType == TypeScript.NodeType.QString) {
  17409                        var idText = (id).text;
  17410                        text = idText.substring(1, idText.length - 1);
  17411                    } else {
  17412                        return false;
  17413                    }
  17414                }
  17415                targetMember = targetType.memberScope.find(text, true, false);
  17416                if(!targetMember) {
  17417                    return false;
  17418                }
  17419                foundSyms[text] = true;
  17420            }
  17421            var targetMembers = targetType.memberScope.getAllValueSymbolNames(true);
  17422            for(var i = 0; i < targetMembers.length; i++) {
  17423                var memberName = targetMembers[i];
  17424                var memberSym = targetType.memberScope.find(memberName, true, false);
  17425                if(!foundSyms[targetMembers[i]] && !TypeScript.hasFlag(memberSym.flags, TypeScript.SymbolFlags.Optional)) {
  17426                    return false;
  17427                }
  17428            }
  17429            return true;
  17430        };
  17431        TypeChecker.prototype.widenType = function (t) {
  17432            if(t == this.undefinedType || t == this.nullType) {
  17433                return this.anyType;
  17434            }
  17435            return t;
  17436        };
  17437        TypeChecker.prototype.isNullOrUndefinedType = function (t) {
  17438            return t == this.undefinedType || t == this.nullType;
  17439        };
  17440        TypeChecker.prototype.findBestCommonType = function (initialType, targetType, collection, acceptVoid, comparisonInfo) {
  17441            var i = 0;
  17442            var len = collection.getLength();
  17443            var nlastChecked = 0;
  17444            var bestCommonType = initialType;
  17445            if(targetType) {
  17446                bestCommonType = bestCommonType ? bestCommonType.mergeOrdered(targetType, this, acceptVoid) : targetType;
  17447            }
  17448            var convergenceType = bestCommonType;
  17449            while(nlastChecked < len) {
  17450                for(i = 0; i < len; i++) {
  17451                    if(i == nlastChecked) {
  17452                        continue;
  17453                    }
  17454                    if(convergenceType && (bestCommonType = convergenceType.mergeOrdered(collection.getTypeAtIndex(i), this, acceptVoid, comparisonInfo))) {
  17455                        convergenceType = bestCommonType;
  17456                    }
  17457                    if(bestCommonType == this.anyType || bestCommonType == null) {
  17458                        break;
  17459                    } else {
  17460                        if(targetType) {
  17461                            collection.setTypeAtIndex(i, targetType);
  17462                        }
  17463                    }
  17464                }
  17465                if(convergenceType && bestCommonType) {
  17466                    break;
  17467                }
  17468                nlastChecked++;
  17469                if(nlastChecked < len) {
  17470                    convergenceType = collection.getTypeAtIndex(nlastChecked);
  17471                }
  17472            }
  17473            return acceptVoid ? bestCommonType : (bestCommonType == this.voidType ? null : bestCommonType);
  17474        };
  17475        TypeChecker.prototype.typesAreIdentical = function (t1, t2) {
  17476            if(t1 == t2) {
  17477                return true;
  17478            }
  17479            if(!t1 || !t2) {
  17480                return false;
  17481            }
  17482            if(t1.isClass() || t1.isClassInstance()) {
  17483                return false;
  17484            }
  17485            var comboId = (t2.typeID << 16) | t1.typeID;
  17486            if(this.identicalCache[comboId]) {
  17487                return true;
  17488            }
  17489            if((t1.typeFlags & TypeScript.TypeFlags.IsEnum) || (t2.typeFlags & TypeScript.TypeFlags.IsEnum)) {
  17490                return false;
  17491            }
  17492            if(t1.isArray() || t2.isArray()) {
  17493                if(!(t1.isArray() && t2.isArray())) {
  17494                    return false;
  17495                }
  17496                this.identicalCache[comboId] = false;
  17497                var ret = this.typesAreIdentical(t1.elementType, t2.elementType);
  17498                if(ret) {
  17499                    this.subtypeCache[comboId] = true;
  17500                } else {
  17501                    this.subtypeCache[comboId] = undefined;
  17502                }
  17503                return ret;
  17504            }
  17505            if(t1.primitiveTypeClass != t2.primitiveTypeClass) {
  17506                return false;
  17507            }
  17508            this.identicalCache[comboId] = false;
  17509            if(t1.memberScope && t2.memberScope) {
  17510                var t1MemberKeys = t1.memberScope.getAllValueSymbolNames(true).sort();
  17511                var t2MemberKeys = t2.memberScope.getAllValueSymbolNames(true).sort();
  17512                if(t1MemberKeys.length != t2MemberKeys.length) {
  17513                    this.identicalCache[comboId] = undefined;
  17514                    return false;
  17515                }
  17516                var t1MemberSymbol = null;
  17517                var t2MemberSymbol = null;
  17518                var t1MemberType = null;
  17519                var t2MemberType = null;
  17520                for(var iMember = 0; iMember < t1MemberKeys.length; iMember++) {
  17521                    if(t1MemberKeys[iMember] != t2MemberKeys[iMember]) {
  17522                        this.identicalCache[comboId] = undefined;
  17523                        return false;
  17524                    }
  17525                    t1MemberSymbol = t1.memberScope.find(t1MemberKeys[iMember], false, false);
  17526                    t2MemberSymbol = t2.memberScope.find(t2MemberKeys[iMember], false, false);
  17527                    if((t1MemberSymbol.flags & TypeScript.SymbolFlags.Optional) != (t2MemberSymbol.flags & TypeScript.SymbolFlags.Optional)) {
  17528                        this.identicalCache[comboId] = undefined;
  17529                        return false;
  17530                    }
  17531                    t1MemberType = t1MemberSymbol.getType();
  17532                    t2MemberType = t2MemberSymbol.getType();
  17533                    if(t1MemberType && t2MemberType && (this.identicalCache[(t2MemberType.typeID << 16) | t1MemberType.typeID] != undefined)) {
  17534                        continue;
  17535                    }
  17536                    if(!this.typesAreIdentical(t1MemberType, t2MemberType)) {
  17537                        this.identicalCache[comboId] = undefined;
  17538                        return false;
  17539                    }
  17540                }
  17541            } else {
  17542                if(t1.memberScope || t2.memberScope) {
  17543                    this.identicalCache[comboId] = undefined;
  17544                    return false;
  17545                }
  17546            }
  17547            if(!this.signatureGroupsAreIdentical(t1.call, t2.call)) {
  17548                this.identicalCache[comboId] = undefined;
  17549                return false;
  17550            }
  17551            if(!this.signatureGroupsAreIdentical(t1.construct, t2.construct)) {
  17552                this.identicalCache[comboId] = undefined;
  17553                return false;
  17554            }
  17555            if(!this.signatureGroupsAreIdentical(t1.index, t2.index)) {
  17556                this.identicalCache[comboId] = undefined;
  17557                return false;
  17558            }
  17559            this.identicalCache[comboId] = true;
  17560            return true;
  17561        };
  17562        TypeChecker.prototype.signatureGroupsAreIdentical = function (sg1, sg2) {
  17563            if(sg1 == sg2) {
  17564                return true;
  17565            }
  17566            if(!sg1 || !sg2) {
  17567                return false;
  17568            }
  17569            if(sg1.signatures.length != sg2.signatures.length) {
  17570                return false;
  17571            }
  17572            var sig1 = null;
  17573            var sig2 = null;
  17574            var sigsMatch = false;
  17575            for(var iSig1 = 0; iSig1 < sg1.signatures.length; iSig1++) {
  17576                sig1 = sg1.signatures[iSig1];
  17577                for(var iSig2 = 0; iSig2 < sg2.signatures.length; iSig2++) {
  17578                    sig2 = sg2.signatures[iSig2];
  17579                    if(this.signaturesAreIdentical(sig1, sig2)) {
  17580                        sigsMatch = true;
  17581                        break;
  17582                    }
  17583                }
  17584                if(sigsMatch) {
  17585                    sigsMatch = false;
  17586                    continue;
  17587                }
  17588                return false;
  17589            }
  17590            return true;
  17591        };
  17592        TypeChecker.prototype.signaturesAreIdentical = function (s1, s2) {
  17593            if(s1.hasVariableArgList != s2.hasVariableArgList) {
  17594                return false;
  17595            }
  17596            if(s1.nonOptionalParameterCount != s2.nonOptionalParameterCount) {
  17597                return false;
  17598            }
  17599            if(s1.parameters.length != s2.parameters.length) {
  17600                return false;
  17601            }
  17602            if(!this.typesAreIdentical(s1.returnType.type, s2.returnType.type)) {
  17603                return false;
  17604            }
  17605            for(var iParam = 0; iParam < s1.parameters.length; iParam++) {
  17606                if(!this.typesAreIdentical(s1.parameters[iParam].parameter.typeLink.type, s2.parameters[iParam].parameter.typeLink.type)) {
  17607                    return false;
  17608                }
  17609            }
  17610            return true;
  17611        };
  17612        TypeChecker.prototype.sourceIsSubtypeOfTarget = function (source, target, comparisonInfo) {
  17613            return this.sourceIsRelatableToTarget(source, target, false, this.subtypeCache, comparisonInfo);
  17614        };
  17615        TypeChecker.prototype.signatureGroupIsSubtypeOfTarget = function (sg1, sg2, comparisonInfo) {
  17616            return this.signatureGroupIsRelatableToTarget(sg1, sg2, false, this.subtypeCache, comparisonInfo);
  17617        };
  17618        TypeChecker.prototype.signatureIsSubtypeOfTarget = function (s1, s2, comparisonInfo) {
  17619            return this.signatureIsRelatableToTarget(s1, s2, false, this.subtypeCache, comparisonInfo);
  17620        };
  17621        TypeChecker.prototype.sourceIsAssignableToTarget = function (source, target, comparisonInfo) {
  17622            return this.sourceIsRelatableToTarget(source, target, true, this.assignableCache, comparisonInfo);
  17623        };
  17624        TypeChecker.prototype.signatureGroupIsAssignableToTarget = function (sg1, sg2, comparisonInfo) {
  17625            return this.signatureGroupIsRelatableToTarget(sg1, sg2, true, this.assignableCache, comparisonInfo);
  17626        };
  17627        TypeChecker.prototype.signatureIsAssignableToTarget = function (s1, s2, comparisonInfo) {
  17628            return this.signatureIsRelatableToTarget(s1, s2, true, this.assignableCache, comparisonInfo);
  17629        };
  17630        TypeChecker.prototype.sourceIsRelatableToTarget = function (source, target, assignableTo, comparisonCache, comparisonInfo) {
  17631            if(source == target) {
  17632                return true;
  17633            }
  17634            if(!(source && target)) {
  17635                return true;
  17636            }
  17637            var comboId = (source.typeID << 16) | target.typeID;
  17638            if(comparisonCache[comboId] != undefined) {
  17639                return true;
  17640            }
  17641            if(assignableTo) {
  17642                if(source == this.anyType || target == this.anyType) {
  17643                    return true;
  17644                }
  17645            } else {
  17646                if(target == this.anyType) {
  17647                    return true;
  17648                }
  17649            }
  17650            if(source == this.undefinedType) {
  17651                return true;
  17652            }
  17653            if((source == this.nullType) && (target != this.undefinedType && target != this.voidType)) {
  17654                return true;
  17655            }
  17656            if(target == this.numberType && (source.typeFlags & TypeScript.TypeFlags.IsEnum)) {
  17657                return true;
  17658            }
  17659            if(source == this.numberType && (target.typeFlags & TypeScript.TypeFlags.IsEnum)) {
  17660                return true;
  17661            }
  17662            if((source.typeFlags & TypeScript.TypeFlags.IsEnum) || (target.typeFlags & TypeScript.TypeFlags.IsEnum)) {
  17663                return false;
  17664            }
  17665            if(source.isArray() || target.isArray()) {
  17666                if(!(source.isArray() && target.isArray())) {
  17667                    return false;
  17668                }
  17669                comparisonCache[comboId] = false;
  17670                var ret = this.sourceIsRelatableToTarget(source.elementType, target.elementType, assignableTo, comparisonCache, comparisonInfo);
  17671                if(ret) {
  17672                    comparisonCache[comboId] = true;
  17673                } else {
  17674                    comparisonCache[comboId] = undefined;
  17675                }
  17676                return ret;
  17677            }
  17678            if(source.primitiveTypeClass != target.primitiveTypeClass) {
  17679                if(target.primitiveTypeClass == TypeScript.Primitive.None) {
  17680                    if(source == this.numberType && this.typeFlow.numberInterfaceType) {
  17681                        source = this.typeFlow.numberInterfaceType;
  17682                    } else {
  17683                        if(source == this.stringType && this.typeFlow.stringInterfaceType) {
  17684                            source = this.typeFlow.stringInterfaceType;
  17685                        } else {
  17686                            if(source == this.booleanType && this.typeFlow.booleanInterfaceType) {
  17687                                source = this.typeFlow.booleanInterfaceType;
  17688                            } else {
  17689                                return false;
  17690                            }
  17691                        }
  17692                    }
  17693                } else {
  17694                    return false;
  17695                }
  17696            }
  17697            comparisonCache[comboId] = false;
  17698            if(source.hasBase(target)) {
  17699                comparisonCache[comboId] = true;
  17700                return true;
  17701            }
  17702            if(this.typeFlow.objectInterfaceType && target == this.typeFlow.objectInterfaceType) {
  17703                return true;
  17704            }
  17705            if(this.typeFlow.functionInterfaceType && (source.call || source.construct) && target == this.typeFlow.functionInterfaceType) {
  17706                return true;
  17707            }
  17708            if(target.isClass() || target.isClassInstance()) {
  17709                comparisonCache[comboId] = undefined;
  17710                return false;
  17711            }
  17712            if(target.memberScope && source.memberScope) {
  17713                var mPropKeys = target.memberScope.getAllValueSymbolNames(true);
  17714                var mProp = null;
  17715                var nProp = null;
  17716                var mPropType = null;
  17717                var nPropType = null;
  17718                var inferenceSymbol = null;
  17719                for(var iMProp = 0; iMProp < mPropKeys.length; iMProp++) {
  17720                    mProp = target.memberScope.find(mPropKeys[iMProp], false, false);
  17721                    nProp = source.memberScope.find(mPropKeys[iMProp], false, false);
  17722                    if(mProp.name == "arguments" && this.typeFlow.iargumentsInterfaceType && (this.typeFlow.iargumentsInterfaceType.symbol.flags & TypeScript.SymbolFlags.CompilerGenerated) && mProp.kind() == TypeScript.SymbolKind.Variable && (mProp).variable.typeLink.type == this.typeFlow.iargumentsInterfaceType) {
  17723                        continue;
  17724                    }
  17725                    if(mProp.isInferenceSymbol()) {
  17726                        inferenceSymbol = mProp;
  17727                        if(inferenceSymbol.typeCheckStatus == TypeScript.TypeCheckStatus.NotStarted) {
  17728                            this.typeFlow.typeCheck(mProp.declAST);
  17729                        }
  17730                    }
  17731                    mPropType = mProp.getType();
  17732                    if(!nProp) {
  17733                        if(this.typeFlow.objectInterfaceType) {
  17734                            nProp = this.typeFlow.objectInterfaceType.memberScope.find(mPropKeys[iMProp], false, false);
  17735                        }
  17736                        if(!nProp) {
  17737                            if(this.typeFlow.functionInterfaceType && (mPropType.call || mPropType.construct)) {
  17738                                nProp = this.typeFlow.functionInterfaceType.memberScope.find(mPropKeys[iMProp], false, false);
  17739                            }
  17740                            if(!nProp) {
  17741                                if(!(mProp.flags & TypeScript.SymbolFlags.Optional)) {
  17742                                    comparisonCache[comboId] = undefined;
  17743                                    if(comparisonInfo) {
  17744                                        comparisonInfo.flags |= TypeScript.TypeRelationshipFlags.RequiredPropertyIsMissing;
  17745                                        comparisonInfo.addMessageToFront("Type '" + source.getTypeName() + "' is missing property '" + mPropKeys[iMProp] + "' from type '" + target.getTypeName() + "'");
  17746                                    }
  17747                                    return false;
  17748                                } else {
  17749                                    continue;
  17750                                }
  17751                            }
  17752                        }
  17753                    }
  17754                    if(nProp.isInferenceSymbol()) {
  17755                        inferenceSymbol = nProp;
  17756                        if(inferenceSymbol.typeCheckStatus == TypeScript.TypeCheckStatus.NotStarted) {
  17757                            this.typeFlow.typeCheck(nProp.declAST);
  17758                        }
  17759                    }
  17760                    nPropType = nProp.getType();
  17761                    if(mPropType && nPropType && (comparisonCache[(nPropType.typeID << 16) | mPropType.typeID] != undefined)) {
  17762                        continue;
  17763                    }
  17764                    if(!this.sourceIsRelatableToTarget(nPropType, mPropType, assignableTo, comparisonCache, comparisonInfo)) {
  17765                        comparisonCache[comboId] = undefined;
  17766                        if(comparisonInfo) {
  17767                            comparisonInfo.flags |= TypeScript.TypeRelationshipFlags.IncompatiblePropertyTypes;
  17768                            comparisonInfo.addMessageToFront("Types of property '" + mProp.name + "' of types '" + source.getTypeName() + "' and '" + target.getTypeName() + "' are incompatible");
  17769                        }
  17770                        return false;
  17771                    }
  17772                }
  17773            }
  17774            if(source.call || target.call) {
  17775                if(!this.signatureGroupIsRelatableToTarget(source.call, target.call, assignableTo, comparisonCache, comparisonInfo)) {
  17776                    if(comparisonInfo) {
  17777                        if(source.call && target.call) {
  17778                            comparisonInfo.addMessageToFront("Call signatures of types '" + source.getTypeName() + "' and '" + target.getTypeName() + "' are incompatible");
  17779                        } else {
  17780                            var hasSig = target.call ? target.getTypeName() : source.getTypeName();
  17781                            var lacksSig = !target.call ? target.getTypeName() : source.getTypeName();
  17782                            comparisonInfo.setMessage("Type '" + hasSig + "' requires a call signature, but Type '" + lacksSig + "' lacks one");
  17783                        }
  17784                        comparisonInfo.flags |= TypeScript.TypeRelationshipFlags.IncompatibleSignatures;
  17785                    }
  17786                    comparisonCache[comboId] = undefined;
  17787                    return false;
  17788                }
  17789            }
  17790            if(source.construct || target.construct) {
  17791                if(!this.signatureGroupIsRelatableToTarget(source.construct, target.construct, assignableTo, comparisonCache, comparisonInfo)) {
  17792                    if(comparisonInfo) {
  17793                        if(source.construct && target.construct) {
  17794                            comparisonInfo.addMessageToFront("Construct signatures of types '" + source.getTypeName() + "' and '" + target.getTypeName() + "' are incompatible");
  17795                        } else {
  17796                            var hasSig = target.construct ? target.getTypeName() : source.getTypeName();
  17797                            var lacksSig = !target.construct ? target.getTypeName() : source.getTypeName();
  17798                            comparisonInfo.setMessage("Type '" + hasSig + "' requires a construct signature, but Type '" + lacksSig + "' lacks one");
  17799                        }
  17800                        comparisonInfo.flags |= TypeScript.TypeRelationshipFlags.IncompatibleSignatures;
  17801                    }
  17802                    comparisonCache[comboId] = undefined;
  17803                    return false;
  17804                }
  17805            }
  17806            if(target.index) {
  17807                var targetIndex = !target.index && this.typeFlow.objectInterfaceType ? this.typeFlow.objectInterfaceType.index : target.index;
  17808                var sourceIndex = !source.index && this.typeFlow.objectInterfaceType ? this.typeFlow.objectInterfaceType.index : source.index;
  17809                if(!this.signatureGroupIsRelatableToTarget(sourceIndex, targetIndex, assignableTo, comparisonCache, comparisonInfo)) {
  17810                    if(comparisonInfo) {
  17811                        comparisonInfo.addMessageToFront("Index signatures of types '" + source.getTypeName() + "' and '" + target.getTypeName() + "' are incompatible");
  17812                        comparisonInfo.flags |= TypeScript.TypeRelationshipFlags.IncompatibleSignatures;
  17813                    }
  17814                    comparisonCache[comboId] = undefined;
  17815                    return false;
  17816                }
  17817            }
  17818            comparisonCache[comboId] = true;
  17819            return true;
  17820        };
  17821        TypeChecker.prototype.signatureGroupIsRelatableToTarget = function (sourceSG, targetSG, assignableTo, comparisonCache, comparisonInfo) {
  17822            if(sourceSG == targetSG) {
  17823                return true;
  17824            }
  17825            if(!(sourceSG && targetSG)) {
  17826                return false;
  17827            }
  17828            var mSig = null;
  17829            var nSig = null;
  17830            var foundMatch = false;
  17831            for(var iMSig = 0; iMSig < targetSG.signatures.length; iMSig++) {
  17832                mSig = targetSG.signatures[iMSig];
  17833                for(var iNSig = 0; iNSig < sourceSG.signatures.length; iNSig++) {
  17834                    nSig = sourceSG.signatures[iNSig];
  17835                    if(this.signatureIsRelatableToTarget(nSig, mSig, assignableTo, comparisonCache, comparisonInfo)) {
  17836                        foundMatch = true;
  17837                        break;
  17838                    }
  17839                }
  17840                if(foundMatch) {
  17841                    foundMatch = false;
  17842                    continue;
  17843                }
  17844                return false;
  17845            }
  17846            return true;
  17847        };
  17848        TypeChecker.prototype.signatureIsRelatableToTarget = function (sourceSig, targetSig, assignableTo, comparisonCache, comparisonInfo) {
  17849            if(!sourceSig.parameters || !targetSig.parameters) {
  17850                return false;
  17851            }
  17852            var targetVarArgCount = targetSig.hasVariableArgList ? targetSig.nonOptionalParameterCount - 1 : targetSig.nonOptionalParameterCount;
  17853            var sourceVarArgCount = sourceSig.hasVariableArgList ? sourceSig.nonOptionalParameterCount - 1 : sourceSig.nonOptionalParameterCount;
  17854            if(sourceVarArgCount > targetVarArgCount && !targetSig.hasVariableArgList) {
  17855                if(comparisonInfo) {
  17856                    comparisonInfo.flags |= TypeScript.TypeRelationshipFlags.SourceSignatureHasTooManyParameters;
  17857                    comparisonInfo.addMessageToFront("Call signature expects " + targetVarArgCount + " or fewer parameters");
  17858                }
  17859                return false;
  17860            }
  17861            var sourceReturnType = sourceSig.returnType.type;
  17862            var targetReturnType = targetSig.returnType.type;
  17863            if(targetReturnType != this.voidType) {
  17864                if(!this.sourceIsRelatableToTarget(sourceReturnType, targetReturnType, assignableTo, comparisonCache, comparisonInfo)) {
  17865                    if(comparisonInfo) {
  17866                        comparisonInfo.flags |= TypeScript.TypeRelationshipFlags.IncompatibleReturnTypes;
  17867                    }
  17868                    return false;
  17869                }
  17870            }
  17871            var len = (sourceVarArgCount < targetVarArgCount && sourceSig.hasVariableArgList) ? targetVarArgCount : sourceVarArgCount;
  17872            var sourceParamType = null;
  17873            var targetParamType = null;
  17874            var sourceParamName = "";
  17875            var targetParamName = "";
  17876            for(var iSource = 0, iTarget = 0; iSource < len; iSource++ , iTarget++) {
  17877                if(!sourceSig.hasVariableArgList || iSource < sourceVarArgCount) {
  17878                    sourceParamType = (sourceSig.parameters[iSource]).parameter.typeLink.type;
  17879                    sourceParamName = (sourceSig.parameters[iSource]).parameter.symbol.name;
  17880                } else {
  17881                    if(iSource == sourceVarArgCount) {
  17882                        sourceParamType = (sourceSig.parameters[iSource]).parameter.typeLink.type;
  17883                        if(sourceParamType.elementType) {
  17884                            sourceParamType = sourceParamType.elementType;
  17885                        }
  17886                        sourceParamName = (sourceSig.parameters[iSource]).parameter.symbol.name;
  17887                    }
  17888                }
  17889                if(iTarget < targetSig.parameters.length && iTarget < targetVarArgCount) {
  17890                    targetParamType = (targetSig.parameters[iTarget]).parameter.typeLink.type;
  17891                    targetParamName = (targetSig.parameters[iTarget]).parameter.symbol.name;
  17892                } else {
  17893                    if(targetSig.hasVariableArgList && iTarget == targetVarArgCount) {
  17894                        targetParamType = (targetSig.parameters[iTarget]).parameter.typeLink.type;
  17895                        if(targetParamType.elementType) {
  17896                            targetParamType = targetParamType.elementType;
  17897                        }
  17898                        targetParamName = (targetSig.parameters[iTarget]).parameter.symbol.name;
  17899                    }
  17900                }
  17901                if(!(this.sourceIsRelatableToTarget(sourceParamType, targetParamType, assignableTo, comparisonCache, comparisonInfo) || this.sourceIsRelatableToTarget(targetParamType, sourceParamType, assignableTo, comparisonCache, comparisonInfo))) {
  17902                    if(comparisonInfo) {
  17903                        comparisonInfo.flags |= TypeScript.TypeRelationshipFlags.IncompatibleParameterTypes;
  17904                    }
  17905                    return false;
  17906                }
  17907            }
  17908            return true;
  17909        };
  17910        return TypeChecker;
  17911    })();
  17912    TypeScript.TypeChecker = TypeChecker;    
  17913 })(TypeScript || (TypeScript = {}));
  17914 var TypeScript;
  17915 (function (TypeScript) {
  17916    var Continuation = (function () {
  17917        function Continuation(normalBlock) {
  17918            this.normalBlock = normalBlock;
  17919            this.exceptionBlock = -1;
  17920        }
  17921        return Continuation;
  17922    })();
  17923    TypeScript.Continuation = Continuation;    
  17924    function getBaseTypeLinks(bases, baseTypeLinks) {
  17925        if(bases) {
  17926            var len = bases.members.length;
  17927            if(baseTypeLinks == null) {
  17928                baseTypeLinks = new Array();
  17929            }
  17930            for(var i = 0; i < len; i++) {
  17931                var baseExpr = bases.members[i];
  17932                var name = baseExpr;
  17933                var typeLink = new TypeScript.TypeLink();
  17934                typeLink.ast = name;
  17935                baseTypeLinks[baseTypeLinks.length] = typeLink;
  17936            }
  17937        }
  17938        return baseTypeLinks;
  17939    }
  17940    function getBases(type, typeDecl) {
  17941        type.extendsTypeLinks = getBaseTypeLinks(typeDecl.extendsList, type.extendsTypeLinks);
  17942        type.implementsTypeLinks = getBaseTypeLinks(typeDecl.implementsList, type.implementsTypeLinks);
  17943    }
  17944    function addPrototypeField(classType, ast, context) {
  17945        var field = new TypeScript.ValueLocation();
  17946        field.typeLink = new TypeScript.TypeLink();
  17947        field.typeLink.ast = ast;
  17948        field.typeLink.type = classType.instanceType;
  17949        var fieldSymbol = new TypeScript.FieldSymbol("prototype", ast.minChar, context.checker.locationInfo.unitIndex, true, field);
  17950        fieldSymbol.flags |= (TypeScript.SymbolFlags.Property | TypeScript.SymbolFlags.BuiltIn);
  17951        field.symbol = fieldSymbol;
  17952        fieldSymbol.declAST = ast;
  17953        classType.members.addPublicMember("prototype", fieldSymbol);
  17954    }
  17955    function createNewConstructGroupForType(type) {
  17956        var signature = new TypeScript.Signature();
  17957        signature.returnType = new TypeScript.TypeLink();
  17958        signature.returnType.type = type.instanceType;
  17959        signature.parameters = [];
  17960        type.construct = new TypeScript.SignatureGroup();
  17961        type.construct.addSignature(signature);
  17962    }
  17963    TypeScript.createNewConstructGroupForType = createNewConstructGroupForType;
  17964    function cloneParentConstructGroupForChildType(child, parent) {
  17965        child.construct = new TypeScript.SignatureGroup();
  17966        var sig = null;
  17967        if(!parent.construct) {
  17968            createNewConstructGroupForType(parent);
  17969        }
  17970        for(var i = 0; i < parent.construct.signatures.length; i++) {
  17971            sig = new TypeScript.Signature();
  17972            sig.parameters = parent.construct.signatures[i].parameters;
  17973            sig.nonOptionalParameterCount = parent.construct.signatures[i].nonOptionalParameterCount;
  17974            sig.typeCheckStatus = parent.construct.signatures[i].typeCheckStatus;
  17975            sig.declAST = parent.construct.signatures[i].declAST;
  17976            sig.returnType = new TypeScript.TypeLink();
  17977            sig.returnType.type = child.instanceType;
  17978            child.construct.addSignature(sig);
  17979        }
  17980    }
  17981    TypeScript.cloneParentConstructGroupForChildType = cloneParentConstructGroupForChildType;
  17982    TypeScript.globalId = "__GLO";
  17983    function findTypeSymbolInScopeChain(name, scopeChain) {
  17984        var symbol = scopeChain.scope.find(name, false, true);
  17985        if(symbol == null && scopeChain.previous) {
  17986            symbol = findTypeSymbolInScopeChain(name, scopeChain.previous);
  17987        }
  17988        return symbol;
  17989    }
  17990    function findSymbolFromAlias(alias, context) {
  17991        var symbol = null;
  17992        switch(alias.nodeType) {
  17993            case TypeScript.NodeType.Name: {
  17994                var name = (alias).text;
  17995                var isDynamic = TypeScript.isQuoted(name);
  17996                var findSym = function (id) {
  17997                    if(context.members) {
  17998                        return context.members.lookup(name);
  17999                    } else {
  18000                        return findTypeSymbolInScopeChain(name, context.topLevelScope);
  18001                    }
  18002                };
  18003                if(isDynamic) {
  18004                    symbol = context.tcContext.checker.findSymbolForDynamicModule(name, context.tcContext.script.locationInfo.filename, findSym);
  18005                } else {
  18006                    symbol = findSym(name);
  18007                }
  18008                break;
  18009 
  18010            }
  18011            case TypeScript.NodeType.Dot: {
  18012                var dottedExpr = alias;
  18013                var op1Sym = findSymbolFromAlias(dottedExpr.operand1, context);
  18014                if(op1Sym && op1Sym.getType()) {
  18015                    symbol = findSymbolFromAlias(dottedExpr.operand2, context);
  18016                }
  18017                break;
  18018 
  18019            }
  18020            default: {
  18021                break;
  18022 
  18023            }
  18024        }
  18025        if(symbol) {
  18026            var symType = symbol.getType();
  18027            if(symType) {
  18028                var members = symType.members;
  18029                if(members) {
  18030                    context.members = members.publicMembers;
  18031                }
  18032            }
  18033        }
  18034        return symbol;
  18035    }
  18036    function preCollectImportTypes(ast, parent, context) {
  18037        var scopeChain = context.scopeChain;
  18038        var typeSymbol = null;
  18039        var modType = null;
  18040        var importDecl = ast;
  18041        var aliasedModSymbol = findSymbolFromAlias(importDecl.alias, {
  18042            topLevelScope: scopeChain,
  18043            members: null,
  18044            tcContext: context
  18045        });
  18046        var isGlobal = context.scopeChain.container == context.checker.gloMod;
  18047        if(aliasedModSymbol) {
  18048            var aliasedModType = aliasedModSymbol.getType();
  18049            if(aliasedModType) {
  18050                modType = aliasedModType;
  18051            }
  18052        }
  18053        typeSymbol = new TypeScript.TypeSymbol(importDecl.id.text, importDecl.id.minChar, importDecl.limChar - importDecl.minChar, context.checker.locationInfo.unitIndex, modType);
  18054        typeSymbol.aliasLink = importDecl;
  18055        if(context.scopeChain.moduleDecl) {
  18056            typeSymbol.flags |= TypeScript.SymbolFlags.ModuleMember;
  18057            typeSymbol.declModule = context.scopeChain.moduleDecl;
  18058        }
  18059        typeSymbol.declAST = importDecl;
  18060        importDecl.id.sym = typeSymbol;
  18061        scopeChain.scope.enter(scopeChain.container, ast, typeSymbol, context.checker.errorReporter, isGlobal, true, false);
  18062        scopeChain.scope.enter(scopeChain.container, ast, typeSymbol, context.checker.errorReporter, isGlobal, false, false);
  18063        return true;
  18064    }
  18065    TypeScript.preCollectImportTypes = preCollectImportTypes;
  18066    function preCollectModuleTypes(ast, parent, context) {
  18067        var scopeChain = context.scopeChain;
  18068        var moduleDecl = ast;
  18069        var isAmbient = TypeScript.hasFlag(moduleDecl.modFlags, TypeScript.ModuleFlags.Ambient);
  18070        var isEnum = TypeScript.hasFlag(moduleDecl.modFlags, TypeScript.ModuleFlags.IsEnum);
  18071        var isGlobal = context.scopeChain.container == context.checker.gloMod;
  18072        var isExported = TypeScript.hasFlag(moduleDecl.modFlags, TypeScript.ModuleFlags.Exported);
  18073        var modName = (moduleDecl.name).text;
  18074        var isDynamic = TypeScript.isQuoted(modName);
  18075        var symbol = scopeChain.scope.findLocal(modName, false, false);
  18076        var typeSymbol = null;
  18077        var modType = null;
  18078        if((symbol == null) || (symbol.kind() != TypeScript.SymbolKind.Type)) {
  18079            if(modType == null) {
  18080                var enclosedTypes = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  18081                var ambientEnclosedTypes = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  18082                modType = new TypeScript.ModuleType(enclosedTypes, ambientEnclosedTypes);
  18083                if(isEnum) {
  18084                    modType.typeFlags |= TypeScript.TypeFlags.IsEnum;
  18085                }
  18086                modType.members = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  18087                modType.ambientMembers = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  18088                modType.setHasImplementation();
  18089            }
  18090            typeSymbol = new TypeScript.TypeSymbol(modName, moduleDecl.name.minChar, modName.length, context.checker.locationInfo.unitIndex, modType);
  18091            typeSymbol.isDynamic = TypeScript.isQuoted(moduleDecl.prettyName);
  18092            if(context.scopeChain.moduleDecl) {
  18093                typeSymbol.declModule = context.scopeChain.moduleDecl;
  18094            }
  18095            typeSymbol.declAST = moduleDecl;
  18096            typeSymbol.prettyName = moduleDecl.prettyName;
  18097            scopeChain.scope.enter(scopeChain.container, ast, typeSymbol, context.checker.errorReporter, isExported || isGlobal, true, isAmbient);
  18098            scopeChain.scope.enter(scopeChain.container, ast, typeSymbol, context.checker.errorReporter, isExported || isGlobal, false, isAmbient);
  18099            modType.symbol = typeSymbol;
  18100        } else {
  18101            if(symbol && symbol.declAST && symbol.declAST.nodeType != TypeScript.NodeType.ModuleDeclaration) {
  18102                context.checker.errorReporter.simpleError(moduleDecl, "Conflicting symbol name for module '" + modName + "'");
  18103            }
  18104            typeSymbol = symbol;
  18105            var publicEnclosedTypes = typeSymbol.type.getAllEnclosedTypes().publicMembers;
  18106            var publicEnclosedTypesTable = (publicEnclosedTypes == null) ? new TypeScript.StringHashTable() : publicEnclosedTypes;
  18107            var enclosedTypes = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(publicEnclosedTypesTable, new TypeScript.StringHashTable()));
  18108            var publicEnclosedAmbientTypes = typeSymbol.type.getAllAmbientEnclosedTypes().publicMembers;
  18109            var publicAmbientEnclosedTypesTable = (publicEnclosedAmbientTypes == null) ? new TypeScript.StringHashTable() : publicEnclosedAmbientTypes;
  18110            var ambientEnclosedTypes = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(publicAmbientEnclosedTypesTable, new TypeScript.StringHashTable()));
  18111            var publicMembers = typeSymbol.type.members.publicMembers;
  18112            var publicMembersTable = (publicMembers == null) ? new TypeScript.StringHashTable() : publicMembers;
  18113            var members = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(publicMembersTable, new TypeScript.StringHashTable()));
  18114            var publicAmbientMembers = typeSymbol.type.ambientMembers.publicMembers;
  18115            var publicAmbientMembersTable = (publicAmbientMembers == null) ? new TypeScript.StringHashTable() : publicAmbientMembers;
  18116            var ambientMembers = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(publicAmbientMembersTable, new TypeScript.StringHashTable()));
  18117            modType = new TypeScript.ModuleType(enclosedTypes, ambientEnclosedTypes);
  18118            if(isEnum) {
  18119                modType.typeFlags |= TypeScript.TypeFlags.IsEnum;
  18120            }
  18121            modType.members = members;
  18122            modType.ambientMembers = ambientMembers;
  18123            modType.setHasImplementation();
  18124            modType.symbol = typeSymbol;
  18125            typeSymbol.addLocation(moduleDecl.minChar);
  18126            typeSymbol.expansions.push(modType);
  18127            typeSymbol.expansionsDeclAST.push(moduleDecl);
  18128        }
  18129        if(context.scopeChain.moduleDecl) {
  18130            context.scopeChain.moduleDecl.recordNonInterface();
  18131        }
  18132        if(isExported) {
  18133            typeSymbol.flags |= TypeScript.SymbolFlags.Exported;
  18134        }
  18135        if((context.scopeChain.moduleDecl) || (context.scopeChain.container == context.checker.gloMod)) {
  18136            typeSymbol.flags |= TypeScript.SymbolFlags.ModuleMember;
  18137        }
  18138        moduleDecl.mod = modType;
  18139        TypeScript.pushTypeCollectionScope(typeSymbol, modType.members, modType.ambientMembers, modType.enclosedTypes, modType.ambientEnclosedTypes, context, null, null, moduleDecl);
  18140        return true;
  18141    }
  18142    TypeScript.preCollectModuleTypes = preCollectModuleTypes;
  18143    function preCollectClassTypes(ast, parent, context) {
  18144        var scopeChain = context.scopeChain;
  18145        var classDecl = ast;
  18146        var classType;
  18147        var instanceType;
  18148        var typeSymbol = null;
  18149        var className = (classDecl.name).text;
  18150        var alreadyInScope = false;
  18151        var isAmbient = TypeScript.hasFlag(classDecl.varFlags, TypeScript.VarFlags.Ambient);
  18152        var isExported = TypeScript.hasFlag(classDecl.varFlags, TypeScript.VarFlags.Exported);
  18153        var isGlobal = context.scopeChain.container == context.checker.gloMod;
  18154        var containerMod = scopeChain.container;
  18155        var foundValSymbol = false;
  18156        typeSymbol = scopeChain.scope.findLocal(className, false, true);
  18157        if(!typeSymbol) {
  18158            var valTypeSymbol = scopeChain.scope.findLocal(className, false, false);
  18159            if(valTypeSymbol && valTypeSymbol.isType() && valTypeSymbol.declAST && valTypeSymbol.declAST.nodeType == TypeScript.NodeType.FuncDecl && (valTypeSymbol.declAST).isSignature()) {
  18160                typeSymbol = valTypeSymbol;
  18161                foundValSymbol = true;
  18162                if(isExported) {
  18163                    typeSymbol.flags |= TypeScript.SymbolFlags.Exported;
  18164                }
  18165                if(isAmbient) {
  18166                    typeSymbol.flags |= TypeScript.SymbolFlags.Ambient;
  18167                }
  18168                context.scopeChain.scope.enter(context.scopeChain.container, ast, typeSymbol, context.checker.errorReporter, isExported || isGlobal, true, isAmbient);
  18169            }
  18170        }
  18171        if(typeSymbol && !foundValSymbol && (typeSymbol.declAST != classDecl)) {
  18172            typeSymbol = null;
  18173        }
  18174        if(typeSymbol == null) {
  18175            var valueSymbol = scopeChain.scope.findLocal(className, false, false);
  18176            classType = new TypeScript.Type();
  18177            classType.setHasImplementation();
  18178            instanceType = new TypeScript.Type();
  18179            instanceType.setHasImplementation();
  18180            classType.instanceType = instanceType;
  18181            classType.members = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  18182            classType.ambientMembers = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  18183            addPrototypeField(classType, classDecl, context);
  18184            instanceType.members = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  18185            instanceType.ambientMembers = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  18186            typeSymbol = new TypeScript.TypeSymbol(className, classDecl.name.minChar, className.length, context.checker.locationInfo.unitIndex, classType);
  18187            typeSymbol.declAST = classDecl;
  18188            typeSymbol.instanceType = instanceType;
  18189            classType.symbol = typeSymbol;
  18190            instanceType.symbol = typeSymbol;
  18191            if(context.scopeChain.moduleDecl) {
  18192                context.scopeChain.moduleDecl.recordNonInterface();
  18193                typeSymbol.declModule = context.scopeChain.moduleDecl;
  18194                typeSymbol.flags |= TypeScript.SymbolFlags.ModuleMember;
  18195            }
  18196            if(isExported) {
  18197                typeSymbol.flags |= TypeScript.SymbolFlags.Exported;
  18198            }
  18199            if(isAmbient) {
  18200                typeSymbol.flags |= TypeScript.SymbolFlags.Ambient;
  18201            }
  18202            ast.type = classType;
  18203            context.scopeChain.scope.enter(context.scopeChain.container, ast, typeSymbol, context.checker.errorReporter, isExported || isGlobal, true, isAmbient);
  18204            if(valueSymbol == null) {
  18205                context.scopeChain.scope.enter(context.scopeChain.container, ast, typeSymbol, context.checker.errorReporter, isExported || isGlobal, false, isAmbient);
  18206            }
  18207        } else {
  18208            classType = typeSymbol.type;
  18209            if(classType.instanceType == null) {
  18210                classType.instanceType = new TypeScript.Type();
  18211                classType.instanceType.setHasImplementation();
  18212                classType.instanceType.members = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  18213                classType.instanceType.symbol = classType.symbol;
  18214                classType.members = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  18215                classType.ambientMembers = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  18216            }
  18217            instanceType = classType.instanceType;
  18218            ast.type = classType;
  18219        }
  18220        if(!classDecl.constructorDecl) {
  18221            if(typeSymbol && typeSymbol.declAST && typeSymbol.declAST.type && typeSymbol.declAST.type.call && !(typeSymbol.declAST).isOverload) {
  18222                context.checker.errorReporter.duplicateIdentifier(typeSymbol.declAST, typeSymbol.name);
  18223            }
  18224            createNewConstructGroupForType(classDecl.type);
  18225        }
  18226        classType.typeFlags |= TypeScript.TypeFlags.IsClass;
  18227        instanceType.typeFlags |= TypeScript.TypeFlags.IsClass;
  18228        getBases(instanceType, classDecl);
  18229        TypeScript.pushTypeCollectionScope(typeSymbol, instanceType.members, instanceType.ambientMembers, null, null, context, instanceType, classType, null);
  18230        return true;
  18231    }
  18232    TypeScript.preCollectClassTypes = preCollectClassTypes;
  18233    function preCollectInterfaceTypes(ast, parent, context) {
  18234        var scopeChain = context.scopeChain;
  18235        var interfaceDecl = ast;
  18236        var interfaceSymbol = null;
  18237        var interfaceType = null;
  18238        var isExported = TypeScript.hasFlag(interfaceDecl.varFlags, TypeScript.VarFlags.Exported);
  18239        var isGlobal = context.scopeChain.container == context.checker.gloMod;
  18240        var alreadyInScope = true;
  18241        alreadyInScope = false;
  18242        var interfaceName = (interfaceDecl.name).text;
  18243        interfaceSymbol = scopeChain.scope.findLocal(interfaceName, false, true);
  18244        if(interfaceSymbol == null) {
  18245            interfaceType = new TypeScript.Type();
  18246            interfaceSymbol = new TypeScript.TypeSymbol(interfaceName, interfaceDecl.name.minChar, interfaceName.length, context.checker.locationInfo.unitIndex, interfaceType);
  18247            interfaceType.symbol = interfaceSymbol;
  18248            interfaceType.members = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  18249            interfaceType.ambientMembers = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  18250            interfaceSymbol.declAST = interfaceDecl;
  18251            interfaceSymbol.declModule = context.scopeChain.moduleDecl;
  18252        } else {
  18253            alreadyInScope = true;
  18254            interfaceType = interfaceSymbol.type;
  18255        }
  18256        if(!interfaceType) {
  18257            interfaceType = context.checker.anyType;
  18258        }
  18259        ast.type = interfaceType;
  18260        getBases(interfaceType, interfaceDecl);
  18261        if(isExported) {
  18262            interfaceSymbol.flags |= TypeScript.SymbolFlags.Exported;
  18263        }
  18264        if(context.scopeChain.moduleDecl) {
  18265            interfaceSymbol.flags |= TypeScript.SymbolFlags.ModuleMember;
  18266        }
  18267        if(!alreadyInScope) {
  18268            context.scopeChain.scope.enter(context.scopeChain.container, ast, interfaceSymbol, context.checker.errorReporter, isGlobal || isExported, true, false);
  18269        }
  18270        TypeScript.pushTypeCollectionScope(interfaceSymbol, interfaceType.members, interfaceType.ambientMembers, null, null, context, interfaceType, null, null);
  18271        return true;
  18272    }
  18273    TypeScript.preCollectInterfaceTypes = preCollectInterfaceTypes;
  18274    function preCollectArgDeclTypes(ast, parent, context) {
  18275        var scopeChain = context.scopeChain;
  18276        var argDecl = ast;
  18277        if(TypeScript.hasFlag(argDecl.varFlags, TypeScript.VarFlags.Public | TypeScript.VarFlags.Private)) {
  18278            var field = new TypeScript.ValueLocation();
  18279            var isPrivate = TypeScript.hasFlag(argDecl.varFlags, TypeScript.VarFlags.Private);
  18280            var fieldSymbol = new TypeScript.FieldSymbol(argDecl.id.text, argDecl.id.minChar, context.checker.locationInfo.unitIndex, !TypeScript.hasFlag(argDecl.varFlags, TypeScript.VarFlags.Readonly), field);
  18281            fieldSymbol.transferVarFlags(argDecl.varFlags);
  18282            field.symbol = fieldSymbol;
  18283            fieldSymbol.declAST = ast;
  18284            argDecl.parameterPropertySym = fieldSymbol;
  18285            context.scopeChain.scope.enter(context.scopeChain.container, ast, fieldSymbol, context.checker.errorReporter, !isPrivate, false, false);
  18286            field.typeLink = TypeScript.getTypeLink(argDecl.typeExpr, context.checker, argDecl.init == null);
  18287            argDecl.sym = fieldSymbol;
  18288        }
  18289        return false;
  18290    }
  18291    TypeScript.preCollectArgDeclTypes = preCollectArgDeclTypes;
  18292    function preCollectVarDeclTypes(ast, parent, context) {
  18293        var scopeChain = context.scopeChain;
  18294        var varDecl = ast;
  18295        var isAmbient = TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.Ambient);
  18296        var isExported = TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.Exported);
  18297        var isGlobal = context.scopeChain.container == context.checker.gloMod;
  18298        var isProperty = TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.Property);
  18299        var isStatic = TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.Static);
  18300        var isPrivate = TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.Private);
  18301        var isOptional = TypeScript.hasFlag(varDecl.id.flags, TypeScript.ASTFlags.OptionalName);
  18302        if(context.scopeChain.moduleDecl) {
  18303            context.scopeChain.moduleDecl.recordNonInterface();
  18304        }
  18305        if(isProperty || isExported || (context.scopeChain.container == context.checker.gloMod) || context.scopeChain.moduleDecl) {
  18306            if(isAmbient) {
  18307                var existingSym = scopeChain.scope.findLocal(varDecl.id.text, false, false);
  18308                if(existingSym) {
  18309                    varDecl.sym = existingSym;
  18310                    return false;
  18311                }
  18312            }
  18313            if(varDecl.id == null) {
  18314                context.checker.errorReporter.simpleError(varDecl, "Expected variable identifier at this location");
  18315                return false;
  18316            }
  18317            var field = new TypeScript.ValueLocation();
  18318            var fieldSymbol = new TypeScript.FieldSymbol(varDecl.id.text, varDecl.id.minChar, context.checker.locationInfo.unitIndex, (varDecl.varFlags & TypeScript.VarFlags.Readonly) == TypeScript.VarFlags.None, field);
  18319            fieldSymbol.transferVarFlags(varDecl.varFlags);
  18320            if(isOptional) {
  18321                fieldSymbol.flags |= TypeScript.SymbolFlags.Optional;
  18322            }
  18323            field.symbol = fieldSymbol;
  18324            fieldSymbol.declAST = ast;
  18325            if((context.scopeChain.moduleDecl) || (context.scopeChain.container == context.checker.gloMod)) {
  18326                fieldSymbol.flags |= TypeScript.SymbolFlags.ModuleMember;
  18327                fieldSymbol.declModule = context.scopeChain.moduleDecl;
  18328            }
  18329            if(TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.Property) && isStatic && context.scopeChain.classType) {
  18330                if(!context.scopeChain.classType.members.publicMembers.add(varDecl.id.text, fieldSymbol)) {
  18331                    context.checker.errorReporter.duplicateIdentifier(ast, fieldSymbol.name);
  18332                }
  18333                fieldSymbol.container = context.scopeChain.classType.symbol;
  18334            } else {
  18335                context.scopeChain.scope.enter(context.scopeChain.container, ast, fieldSymbol, context.checker.errorReporter, !isPrivate && (isProperty || isExported || isGlobal || isStatic), false, isAmbient);
  18336            }
  18337            if(TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.Exported)) {
  18338                fieldSymbol.flags |= TypeScript.SymbolFlags.Exported;
  18339            }
  18340            field.typeLink = TypeScript.getTypeLink(varDecl.typeExpr, context.checker, varDecl.init == null);
  18341            varDecl.sym = fieldSymbol;
  18342        }
  18343        return false;
  18344    }
  18345    TypeScript.preCollectVarDeclTypes = preCollectVarDeclTypes;
  18346    function preCollectFuncDeclTypes(ast, parent, context) {
  18347        var scopeChain = context.scopeChain;
  18348        if(context.scopeChain.moduleDecl) {
  18349            context.scopeChain.moduleDecl.recordNonInterface();
  18350        }
  18351        var funcDecl = ast;
  18352        var fgSym = null;
  18353        var nameText = funcDecl.getNameText();
  18354        var isExported = TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Exported | TypeScript.FncFlags.ClassPropertyMethodExported);
  18355        var isStatic = TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Static);
  18356        var isPrivate = TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Private);
  18357        var isConstructor = funcDecl.isConstructMember() || funcDecl.isConstructor;
  18358        var containerSym = (((funcDecl.isMethod() && isStatic) || funcDecl.isAccessor()) && context.scopeChain.classType ? context.scopeChain.classType.symbol : context.scopeChain.container);
  18359        var containerScope = context.scopeChain.scope;
  18360        var isGlobal = containerSym == context.checker.gloMod;
  18361        var isOptional = funcDecl.name && TypeScript.hasFlag(funcDecl.name.flags, TypeScript.ASTFlags.OptionalName);
  18362        var go = false;
  18363        var foundSymbol = false;
  18364        if(isConstructor && TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.ClassMethod)) {
  18365            containerSym = containerSym.container;
  18366            containerScope = scopeChain.previous.scope;
  18367        }
  18368        funcDecl.unitIndex = context.checker.locationInfo.unitIndex;
  18369        if(!funcDecl.isConstructor && containerSym && containerSym.declAST && containerSym.declAST.nodeType == TypeScript.NodeType.FuncDecl && (containerSym.declAST).isConstructor && !funcDecl.isMethod()) {
  18370            return go;
  18371        }
  18372        if(TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Signature)) {
  18373            var instType = context.scopeChain.thisType;
  18374            if(nameText && nameText != "__missing") {
  18375                if(isStatic) {
  18376                    fgSym = containerSym.type.members.allMembers.lookup(nameText);
  18377                } else {
  18378                    fgSym = containerScope.findLocal(nameText, false, false);
  18379                    if(fgSym == null) {
  18380                        fgSym = containerScope.findLocal(nameText, false, true);
  18381                    }
  18382                }
  18383                if(fgSym) {
  18384                    foundSymbol = true;
  18385                    if(!funcDecl.isSignature() && (TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Ambient) != TypeScript.hasFlag(fgSym.flags, TypeScript.SymbolFlags.Ambient))) {
  18386                        fgSym = null;
  18387                    }
  18388                }
  18389            }
  18390            if(fgSym == null) {
  18391                if(!(funcDecl.isSpecialFn())) {
  18392                    fgSym = context.checker.createFunctionSignature(funcDecl, containerSym, containerScope, null, !foundSymbol).declAST.type.symbol;
  18393                } else {
  18394                    fgSym = context.checker.createFunctionSignature(funcDecl, containerSym, containerScope, containerSym, false).declAST.type.symbol;
  18395                }
  18396                if(fgSym.declAST == null || !funcDecl.isSpecialFn()) {
  18397                    fgSym.declAST = ast;
  18398                }
  18399            } else {
  18400                if((fgSym.kind() == TypeScript.SymbolKind.Type)) {
  18401                    fgSym = context.checker.createFunctionSignature(funcDecl, containerSym, containerScope, fgSym, false).declAST.type.symbol;
  18402                } else {
  18403                    context.checker.errorReporter.simpleError(funcDecl, "Function or method '" + funcDecl.name.actualText + "' already declared as a property");
  18404                }
  18405            }
  18406            if(funcDecl.isSpecialFn() && !isStatic) {
  18407                funcDecl.type = instType ? instType : fgSym.type;
  18408            } else {
  18409                funcDecl.type = fgSym.type;
  18410            }
  18411        } else {
  18412            if(nameText) {
  18413                if(isStatic) {
  18414                    fgSym = containerSym.type.members.allMembers.lookup(nameText);
  18415                } else {
  18416                    if(funcDecl.isConstructor && context.scopeChain.previous) {
  18417                        fgSym = context.scopeChain.previous.scope.findLocal(nameText, false, false);
  18418                    }
  18419                    if(fgSym == null) {
  18420                        fgSym = containerScope.findLocal(nameText, false, false);
  18421                    }
  18422                }
  18423                if(fgSym) {
  18424                    foundSymbol = true;
  18425                    if(!isConstructor && fgSym.declAST.nodeType == TypeScript.NodeType.FuncDecl && !(fgSym.declAST).isAccessor() && !(fgSym.declAST).isSignature()) {
  18426                        fgSym = null;
  18427                        foundSymbol = false;
  18428                    }
  18429                }
  18430            }
  18431            if(fgSym && !fgSym.isAccessor() && fgSym.type && fgSym.type.construct && fgSym.type.construct.signatures != [] && (fgSym.type.construct.signatures[0].declAST == null || !TypeScript.hasFlag(fgSym.type.construct.signatures[0].declAST.fncFlags, TypeScript.FncFlags.Ambient)) && !funcDecl.isConstructor) {
  18432                context.checker.errorReporter.simpleError(funcDecl, "Functions may not have class overloads");
  18433            }
  18434            if(fgSym && !(fgSym.kind() == TypeScript.SymbolKind.Type) && funcDecl.isMethod() && !funcDecl.isAccessor() && !funcDecl.isConstructor) {
  18435                context.checker.errorReporter.simpleError(funcDecl, "Function or method '" + funcDecl.name.actualText + "' already declared as a property");
  18436                fgSym.type = context.checker.anyType;
  18437            }
  18438            var sig = context.checker.createFunctionSignature(funcDecl, containerSym, containerScope, fgSym, !foundSymbol);
  18439            if(((!fgSym || fgSym.declAST.nodeType != TypeScript.NodeType.FuncDecl) && funcDecl.isAccessor()) || (fgSym && fgSym.isAccessor())) {
  18440                funcDecl.accessorSymbol = context.checker.createAccessorSymbol(funcDecl, fgSym, containerSym.type, (funcDecl.isMethod() && isStatic), true, containerScope, containerSym);
  18441            }
  18442            funcDecl.type.symbol.declAST = ast;
  18443            if(funcDecl.isConstructor) {
  18444                go = true;
  18445            }
  18446            ; ;
  18447        }
  18448        if(isExported) {
  18449            if(funcDecl.type.call) {
  18450                funcDecl.type.symbol.flags |= TypeScript.SymbolFlags.Exported;
  18451            }
  18452            if(fgSym && !fgSym.isAccessor() && fgSym.kind() == TypeScript.SymbolKind.Type && fgSym.type.call) {
  18453                fgSym.flags |= TypeScript.SymbolFlags.Exported;
  18454            }
  18455        }
  18456        if(context.scopeChain.moduleDecl && !funcDecl.isSpecialFn()) {
  18457            funcDecl.type.symbol.flags |= TypeScript.SymbolFlags.ModuleMember;
  18458            funcDecl.type.symbol.declModule = context.scopeChain.moduleDecl;
  18459        }
  18460        if(fgSym && isOptional) {
  18461            fgSym.flags |= TypeScript.SymbolFlags.Optional;
  18462        }
  18463        return go;
  18464    }
  18465    TypeScript.preCollectFuncDeclTypes = preCollectFuncDeclTypes;
  18466    function preCollectTypes(ast, parent, walker) {
  18467        var context = walker.state;
  18468        var go = false;
  18469        var scopeChain = context.scopeChain;
  18470        if(ast.nodeType == TypeScript.NodeType.Script) {
  18471            var script = ast;
  18472            context.script = script;
  18473            go = true;
  18474        } else {
  18475            if(ast.nodeType == TypeScript.NodeType.List) {
  18476                go = true;
  18477            } else {
  18478                if(ast.nodeType == TypeScript.NodeType.ImportDeclaration) {
  18479                    go = preCollectImportTypes(ast, parent, context);
  18480                } else {
  18481                    if(ast.nodeType == TypeScript.NodeType.With) {
  18482                        go = false;
  18483                    } else {
  18484                        if(ast.nodeType == TypeScript.NodeType.ModuleDeclaration) {
  18485                            go = preCollectModuleTypes(ast, parent, context);
  18486                        } else {
  18487                            if(ast.nodeType == TypeScript.NodeType.ClassDeclaration) {
  18488                                go = preCollectClassTypes(ast, parent, context);
  18489                            } else {
  18490                                if(ast.nodeType == TypeScript.NodeType.Block) {
  18491                                    go = true;
  18492                                } else {
  18493                                    if(ast.nodeType == TypeScript.NodeType.InterfaceDeclaration) {
  18494                                        go = preCollectInterfaceTypes(ast, parent, context);
  18495                                    } else {
  18496                                        if(ast.nodeType == TypeScript.NodeType.ArgDecl) {
  18497                                            go = preCollectArgDeclTypes(ast, parent, context);
  18498                                        } else {
  18499                                            if(ast.nodeType == TypeScript.NodeType.VarDecl) {
  18500                                                go = preCollectVarDeclTypes(ast, parent, context);
  18501                                            } else {
  18502                                                if(ast.nodeType == TypeScript.NodeType.FuncDecl) {
  18503                                                    go = preCollectFuncDeclTypes(ast, parent, context);
  18504                                                } else {
  18505                                                    if(ast.isStatementOrExpression() && context.scopeChain.moduleDecl) {
  18506                                                        context.scopeChain.moduleDecl.recordNonInterface();
  18507                                                    }
  18508                                                }
  18509                                            }
  18510                                        }
  18511                                    }
  18512                                }
  18513                            }
  18514                        }
  18515                    }
  18516                }
  18517            }
  18518        }
  18519        walker.options.goChildren = go;
  18520        return ast;
  18521    }
  18522    TypeScript.preCollectTypes = preCollectTypes;
  18523    function postCollectTypes(ast, parent, walker) {
  18524        var context = walker.state;
  18525        if(ast.nodeType == TypeScript.NodeType.ModuleDeclaration) {
  18526            TypeScript.popTypeCollectionScope(context);
  18527        } else {
  18528            if(ast.nodeType == TypeScript.NodeType.ClassDeclaration) {
  18529                TypeScript.popTypeCollectionScope(context);
  18530            } else {
  18531                if(ast.nodeType == TypeScript.NodeType.InterfaceDeclaration) {
  18532                    TypeScript.popTypeCollectionScope(context);
  18533                }
  18534            }
  18535        }
  18536        return ast;
  18537    }
  18538    TypeScript.postCollectTypes = postCollectTypes;
  18539 })(TypeScript || (TypeScript = {}));
  18540 var TypeScript;
  18541 (function (TypeScript) {
  18542    var ScopeChain = (function () {
  18543        function ScopeChain(container, previous, scope) {
  18544            this.container = container;
  18545            this.previous = previous;
  18546            this.scope = scope;
  18547        }
  18548        return ScopeChain;
  18549    })();
  18550    TypeScript.ScopeChain = ScopeChain;    
  18551    var BBUseDefInfo = (function () {
  18552        function BBUseDefInfo(bb) {
  18553            this.bb = bb;
  18554            this.defsBySymbol = new Array();
  18555            this.useIndexBySymbol = new Array();
  18556        }
  18557        BBUseDefInfo.prototype.updateTop = function () {
  18558            var temp = new BitVector(this.top.bitCount);
  18559            for(var i = 0, succLen = this.bb.successors.length; i < succLen; i++) {
  18560                var succ = this.bb.successors[i];
  18561                if(succ.useDef) {
  18562                    temp.union(succ.useDef.top);
  18563                }
  18564            }
  18565            temp.difference(this.kill);
  18566            temp.union(this.gen);
  18567            var changed = temp.notEq(this.top);
  18568            this.top = temp;
  18569            return changed;
  18570        };
  18571        BBUseDefInfo.prototype.initialize = function (useDefContext) {
  18572            var _this = this;
  18573            var defSym = function (sym, context) {
  18574                if(context.isLocalSym(sym)) {
  18575                    var index = context.getSymbolIndex(sym);
  18576                    _this.useIndexBySymbol[index] = new Array();
  18577                    _this.defsBySymbol[index] = true;
  18578                }
  18579            };
  18580            var useSym = function (sym, context, ast) {
  18581                if(context.isLocalSym(sym)) {
  18582                    var symIndex = context.getSymbolIndex(sym);
  18583                    if(_this.useIndexBySymbol[symIndex] == undefined) {
  18584                        _this.useIndexBySymbol[symIndex] = new Array();
  18585                    }
  18586                    var symUses = _this.useIndexBySymbol[symIndex];
  18587                    var astIndex = context.getUseIndex(ast);
  18588                    context.addUse(symIndex, astIndex);
  18589                    symUses.push(astIndex);
  18590                }
  18591            };
  18592            function initUseDefPre(cur, parent, walker) {
  18593                var context = walker.state;
  18594                if(cur == null) {
  18595                    cur = null;
  18596                }
  18597                if(cur.nodeType == TypeScript.NodeType.VarDecl) {
  18598                    var varDecl = cur;
  18599                    if(varDecl.init || TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.AutoInit)) {
  18600                        defSym(varDecl.sym, context);
  18601                    }
  18602                } else {
  18603                    if(cur.nodeType == TypeScript.NodeType.Name) {
  18604                        if(parent) {
  18605                            if(parent.nodeType == TypeScript.NodeType.Asg) {
  18606                                var asg = parent;
  18607                                if(asg.operand1 == cur) {
  18608                                    return cur;
  18609                                }
  18610                            } else {
  18611                                if(parent.nodeType == TypeScript.NodeType.VarDecl) {
  18612                                    var parentDecl = parent;
  18613                                    if(parentDecl.id == cur) {
  18614                                        return cur;
  18615                                    }
  18616                                }
  18617                            }
  18618                        }
  18619                        var id = cur;
  18620                        useSym(id.sym, context, cur);
  18621                    } else {
  18622                        if((cur.nodeType >= TypeScript.NodeType.Asg) && (cur.nodeType <= TypeScript.NodeType.LastAsg)) {
  18623                            var asg = cur;
  18624                            if(asg.operand1 && (asg.operand1.nodeType == TypeScript.NodeType.Name)) {
  18625                                var id = asg.operand1;
  18626                                defSym(id.sym, context);
  18627                            }
  18628                        } else {
  18629                            if(cur.nodeType == TypeScript.NodeType.FuncDecl) {
  18630                                walker.options.goChildren = false;
  18631                            }
  18632                        }
  18633                    }
  18634                }
  18635                return cur;
  18636            }
  18637            var options = new TypeScript.AstWalkOptions();
  18638            options.reverseSiblings = true;
  18639            TypeScript.getAstWalkerFactory().walk(this.bb.content, initUseDefPre, null, options, useDefContext);
  18640        };
  18641        BBUseDefInfo.prototype.initializeGen = function (useDefContext) {
  18642            var symbolLen = this.useIndexBySymbol.length;
  18643            var bitCount = useDefContext.uses.length;
  18644            this.gen = new BitVector(bitCount);
  18645            for(var s = 0; s < symbolLen; s++) {
  18646                var symUses = this.useIndexBySymbol[s];
  18647                if((symUses != undefined) && (symUses.length > 0)) {
  18648                    for(var u = 0, uLen = symUses.length; u < uLen; u++) {
  18649                        this.gen.set(symUses[u], true);
  18650                    }
  18651                }
  18652            }
  18653            this.top = this.gen;
  18654        };
  18655        BBUseDefInfo.prototype.initializeKill = function (useDefContext) {
  18656            this.kill = new BitVector(this.gen.bitCount);
  18657            for(var s = 0, symbolLen = this.defsBySymbol.length; s < symbolLen; s++) {
  18658                if(this.defsBySymbol[s]) {
  18659                    var globalSymUses = useDefContext.useIndexBySymbol[s];
  18660                    if(globalSymUses) {
  18661                        for(var u = 0, useLen = globalSymUses.length; u < useLen; u++) {
  18662                            this.kill.set(globalSymUses[u], true);
  18663                        }
  18664                    }
  18665                }
  18666            }
  18667        };
  18668        return BBUseDefInfo;
  18669    })();
  18670    TypeScript.BBUseDefInfo = BBUseDefInfo;    
  18671    var UseDefContext = (function () {
  18672        function UseDefContext() {
  18673            this.useIndexBySymbol = new Array();
  18674            this.uses = new Array();
  18675            this.symbols = new Array();
  18676            this.symbolMap = new TypeScript.StringHashTable();
  18677            this.symbolCount = 0;
  18678        }
  18679        UseDefContext.prototype.getSymbolIndex = function (sym) {
  18680            var name = sym.name;
  18681            var index = (this.symbolMap.lookup(name));
  18682            if(index == null) {
  18683                index = this.symbolCount++;
  18684                this.symbols[index] = sym;
  18685                this.symbolMap.add(name, index);
  18686            }
  18687            return index;
  18688        };
  18689        UseDefContext.prototype.addUse = function (symIndex, astIndex) {
  18690            var useBySym = this.useIndexBySymbol[symIndex];
  18691            if(useBySym == undefined) {
  18692                useBySym = new Array();
  18693                this.useIndexBySymbol[symIndex] = useBySym;
  18694            }
  18695            useBySym[useBySym.length] = astIndex;
  18696        };
  18697        UseDefContext.prototype.getUseIndex = function (ast) {
  18698            this.uses[this.uses.length] = ast;
  18699            return this.uses.length - 1;
  18700        };
  18701        UseDefContext.prototype.isLocalSym = function (sym) {
  18702            return (sym && (sym.container == this.func) && (sym.kind() == TypeScript.SymbolKind.Variable));
  18703        };
  18704        UseDefContext.prototype.killSymbol = function (sym, bbUses) {
  18705            var index = this.symbolMap.lookup(sym.name);
  18706            var usesOfSym = this.useIndexBySymbol[index];
  18707            for(var k = 0, len = usesOfSym.length; k < len; k++) {
  18708                bbUses.set(usesOfSym[k], true);
  18709            }
  18710        };
  18711        return UseDefContext;
  18712    })();
  18713    TypeScript.UseDefContext = UseDefContext;    
  18714    var BitVector = (function () {
  18715        function BitVector(bitCount) {
  18716            this.bitCount = bitCount;
  18717            this.firstBits = 0;
  18718            this.restOfBits = null;
  18719            if(this.bitCount > BitVector.packBits) {
  18720                this.restOfBits = new Array();
  18721                var len = Math.floor(this.bitCount / BitVector.packBits);
  18722                for(var i = 0; i < len; i++) {
  18723                    this.restOfBits[i] = 0;
  18724                }
  18725            }
  18726        }
  18727        BitVector.packBits = 30;
  18728        BitVector.prototype.set = function (bitIndex, value) {
  18729            if(bitIndex < BitVector.packBits) {
  18730                if(value) {
  18731                    this.firstBits |= (1 << bitIndex);
  18732                } else {
  18733                    this.firstBits &= (~(1 << bitIndex));
  18734                }
  18735            } else {
  18736                var offset = Math.floor(bitIndex / BitVector.packBits) - 1;
  18737                var localIndex = bitIndex % BitVector.packBits;
  18738                if(value) {
  18739                    this.restOfBits[offset] |= (1 << localIndex);
  18740                } else {
  18741                    this.restOfBits[offset] &= (~(1 << localIndex));
  18742                }
  18743            }
  18744        };
  18745        BitVector.prototype.map = function (fn) {
  18746            var k;
  18747            for(k = 0; k < BitVector.packBits; k++) {
  18748                if(k == this.bitCount) {
  18749                    return;
  18750                }
  18751                if(((1 << k) & this.firstBits) != 0) {
  18752                    fn(k);
  18753                }
  18754            }
  18755            if(this.restOfBits) {
  18756                var len;
  18757                var cumu = BitVector.packBits;
  18758                for(k = 0 , len = this.restOfBits.length; k < len; k++) {
  18759                    var myBits = this.restOfBits[k];
  18760                    for(var j = 0; j < BitVector.packBits; j++) {
  18761                        if(((1 << j) & myBits) != 0) {
  18762                            fn(cumu);
  18763                        }
  18764                        cumu++;
  18765                        if(cumu == this.bitCount) {
  18766                            return;
  18767                        }
  18768                    }
  18769                }
  18770            }
  18771        };
  18772        BitVector.prototype.union = function (b) {
  18773            this.firstBits |= b.firstBits;
  18774            if(this.restOfBits) {
  18775                for(var k = 0, len = this.restOfBits.length; k < len; k++) {
  18776                    var myBits = this.restOfBits[k];
  18777                    var bBits = b.restOfBits[k];
  18778                    this.restOfBits[k] = myBits | bBits;
  18779                }
  18780            }
  18781        };
  18782        BitVector.prototype.intersection = function (b) {
  18783            this.firstBits &= b.firstBits;
  18784            if(this.restOfBits) {
  18785                for(var k = 0, len = this.restOfBits.length; k < len; k++) {
  18786                    var myBits = this.restOfBits[k];
  18787                    var bBits = b.restOfBits[k];
  18788                    this.restOfBits[k] = myBits & bBits;
  18789                }
  18790            }
  18791        };
  18792        BitVector.prototype.notEq = function (b) {
  18793            if(this.firstBits != b.firstBits) {
  18794                return true;
  18795            }
  18796            if(this.restOfBits) {
  18797                for(var k = 0, len = this.restOfBits.length; k < len; k++) {
  18798                    var myBits = this.restOfBits[k];
  18799                    var bBits = b.restOfBits[k];
  18800                    if(myBits != bBits) {
  18801                        return true;
  18802                    }
  18803                }
  18804            }
  18805            return false;
  18806        };
  18807        BitVector.prototype.difference = function (b) {
  18808            var oldFirstBits = this.firstBits;
  18809            this.firstBits &= (~b.firstBits);
  18810            if(this.restOfBits) {
  18811                for(var k = 0, len = this.restOfBits.length; k < len; k++) {
  18812                    var myBits = this.restOfBits[k];
  18813                    var bBits = b.restOfBits[k];
  18814                    this.restOfBits[k] &= (~bBits);
  18815                }
  18816            }
  18817        };
  18818        return BitVector;
  18819    })();
  18820    TypeScript.BitVector = BitVector;    
  18821    var BasicBlock = (function () {
  18822        function BasicBlock() {
  18823            this.predecessors = new Array();
  18824            this.index = -1;
  18825            this.markValue = 0;
  18826            this.successors = new Array();
  18827            this.useDef = null;
  18828            this.content = new TypeScript.ASTList();
  18829        }
  18830        BasicBlock.prototype.marked = function (markBase) {
  18831            return this.markValue > markBase;
  18832        };
  18833        BasicBlock.prototype.mark = function () {
  18834            this.markValue++;
  18835        };
  18836        BasicBlock.prototype.addSuccessor = function (successor) {
  18837            this.successors[this.successors.length] = successor;
  18838            successor.predecessors[successor.predecessors.length] = this;
  18839        };
  18840        return BasicBlock;
  18841    })();
  18842    TypeScript.BasicBlock = BasicBlock;    
  18843    var ControlFlowContext = (function () {
  18844        function ControlFlowContext(current, exit) {
  18845            this.current = current;
  18846            this.exit = exit;
  18847            this.entry = null;
  18848            this.unreachable = null;
  18849            this.noContinuation = false;
  18850            this.statementStack = new Array();
  18851            this.currentSwitch = new Array();
  18852            this.markBase = 0;
  18853            this.linearBBs = new Array();
  18854            this.entry = this.current;
  18855        }
  18856        ControlFlowContext.prototype.walk = function (ast, parent) {
  18857            return this.walker.walk(ast, parent);
  18858        };
  18859        ControlFlowContext.prototype.pushSwitch = function (bb) {
  18860            this.currentSwitch.push(bb);
  18861        };
  18862        ControlFlowContext.prototype.popSwitch = function () {
  18863            return this.currentSwitch.pop();
  18864        };
  18865        ControlFlowContext.prototype.reportUnreachable = function (er) {
  18866            if(this.unreachable && (this.unreachable.length > 0)) {
  18867                var len = this.unreachable.length;
  18868                for(var i = 0; i < len; i++) {
  18869                    var unreachableAST = this.unreachable[i];
  18870                    if(unreachableAST.nodeType != TypeScript.NodeType.EndCode) {
  18871                        er.simpleError(unreachableAST, "unreachable code");
  18872                    }
  18873                }
  18874            }
  18875        };
  18876        ControlFlowContext.prototype.printAST = function (ast, outfile) {
  18877            var printContext = new TypeScript.PrintContext(outfile, null);
  18878            printContext.increaseIndent();
  18879            TypeScript.getAstWalkerFactory().walk(ast, TypeScript.prePrintAST, TypeScript.postPrintAST, null, printContext);
  18880            printContext.decreaseIndent();
  18881        };
  18882        ControlFlowContext.prototype.printBlockContent = function (bb, outfile) {
  18883            var content = bb.content;
  18884            for(var i = 0, len = content.members.length; i < len; i++) {
  18885                var ast = content.members[i];
  18886                this.printAST(ast, outfile);
  18887            }
  18888        };
  18889        ControlFlowContext.prototype.bfs = function (nodeFunc, edgeFunc, preEdges, postEdges) {
  18890            var markValue = this.markBase++;
  18891            var q = new Array();
  18892            q[q.length] = this.entry;
  18893            while(q.length > 0) {
  18894                var bb = q.pop();
  18895                if(!(bb.marked(markValue))) {
  18896                    bb.mark();
  18897                    if(nodeFunc) {
  18898                        nodeFunc(bb);
  18899                    }
  18900                    var succLen = bb.successors.length;
  18901                    if(succLen > 0) {
  18902                        if(preEdges) {
  18903                            preEdges();
  18904                        }
  18905                        for(var j = succLen - 1; j >= 0; j--) {
  18906                            var successor = bb.successors[j];
  18907                            if(!(successor.marked(this.markBase))) {
  18908                                if(edgeFunc) {
  18909                                    edgeFunc(bb, successor);
  18910                                }
  18911                                q[q.length] = successor;
  18912                            }
  18913                        }
  18914                        if(postEdges) {
  18915                            postEdges();
  18916                        }
  18917                    }
  18918                }
  18919            }
  18920        };
  18921        ControlFlowContext.prototype.useDef = function (er, funcSym) {
  18922            var _this = this;
  18923            var useDefContext = new UseDefContext();
  18924            useDefContext.func = funcSym;
  18925            var useDefInit = function (bb) {
  18926                bb.useDef = new BBUseDefInfo(bb);
  18927                bb.useDef.initialize(useDefContext);
  18928                _this.linearBBs[_this.linearBBs.length] = bb;
  18929            };
  18930            this.bfs(useDefInit, null, null, null);
  18931            var i, bbLen;
  18932            for(i = 0 , bbLen = this.linearBBs.length; i < bbLen; i++) {
  18933                this.linearBBs[i].useDef.initializeGen(useDefContext);
  18934                this.linearBBs[i].useDef.initializeKill(useDefContext);
  18935            }
  18936            var changed = true;
  18937            while(changed) {
  18938                changed = false;
  18939                for(i = 0; i < bbLen; i++) {
  18940                    changed = this.linearBBs[i].useDef.updateTop() || changed;
  18941                }
  18942            }
  18943            var top = this.entry.useDef.top;
  18944            top.map(function (index) {
  18945                var ast = useDefContext.uses[index];
  18946                er.simpleError(ast, "use of variable '" + ast.actualText + "' that is not definitely assigned");
  18947            });
  18948        };
  18949        ControlFlowContext.prototype.print = function (outfile) {
  18950            var _this = this;
  18951            var index = 0;
  18952            var node = function (bb) {
  18953                if(bb.index < 0) {
  18954                    bb.index = index++;
  18955                }
  18956                if(bb == _this.exit) {
  18957                    outfile.WriteLine("Exit block with index " + bb.index);
  18958                } else {
  18959                    outfile.WriteLine("Basic block with index " + bb.index);
  18960                    _this.printBlockContent(bb, outfile);
  18961                }
  18962            };
  18963            function preEdges() {
  18964                outfile.Write("  Branches to ");
  18965            }
  18966            function postEdges() {
  18967                outfile.WriteLine("");
  18968            }
  18969            function edge(node1, node2) {
  18970                if(node2.index < 0) {
  18971                    node2.index = index++;
  18972                }
  18973                outfile.Write(node2.index + " ");
  18974            }
  18975            this.bfs(node, edge, preEdges, postEdges);
  18976            if(this.unreachable != null) {
  18977                for(var i = 0, len = this.unreachable.length; i < len; i++) {
  18978                    outfile.WriteLine("Unreachable basic block ...");
  18979                    this.printAST(this.unreachable[i], outfile);
  18980                }
  18981            }
  18982        };
  18983        ControlFlowContext.prototype.pushStatement = function (stmt, continueBB, breakBB) {
  18984            this.statementStack.push({
  18985                stmt: stmt,
  18986                continueBB: continueBB,
  18987                breakBB: breakBB
  18988            });
  18989        };
  18990        ControlFlowContext.prototype.popStatement = function () {
  18991            return this.statementStack.pop();
  18992        };
  18993        ControlFlowContext.prototype.returnStmt = function () {
  18994            this.current.addSuccessor(this.exit);
  18995            this.setUnreachable();
  18996        };
  18997        ControlFlowContext.prototype.setUnreachable = function () {
  18998            this.current = null;
  18999            this.noContinuation = true;
  19000        };
  19001        ControlFlowContext.prototype.addUnreachable = function (ast) {
  19002            if(this.unreachable === null) {
  19003                this.unreachable = new Array();
  19004            }
  19005            this.unreachable[this.unreachable.length] = ast;
  19006        };
  19007        ControlFlowContext.prototype.unconditionalBranch = function (target, isContinue) {
  19008            var targetBB = null;
  19009            for(var i = 0, len = this.statementStack.length; i < len; i++) {
  19010                var targetInfo = this.statementStack[i];
  19011                if(targetInfo.stmt == target) {
  19012                    if(isContinue) {
  19013                        targetBB = targetInfo.continueBB;
  19014                    } else {
  19015                        targetBB = targetInfo.breakBB;
  19016                    }
  19017                    break;
  19018                }
  19019            }
  19020            if(targetBB) {
  19021                this.current.addSuccessor(targetBB);
  19022            }
  19023            this.setUnreachable();
  19024        };
  19025        ControlFlowContext.prototype.addContent = function (ast) {
  19026            if(this.current) {
  19027                this.current.content.append(ast);
  19028            }
  19029        };
  19030        return ControlFlowContext;
  19031    })();
  19032    TypeScript.ControlFlowContext = ControlFlowContext;    
  19033    var ResolutionDataCache = (function () {
  19034        function ResolutionDataCache() {
  19035            this.cacheSize = 16;
  19036            this.rdCache = [];
  19037            this.nextUp = 0;
  19038            for(var i = 0; i < this.cacheSize; i++) {
  19039                this.rdCache[i] = {
  19040                    actuals: new Array(),
  19041                    exactCandidates: new Array(),
  19042                    conversionCandidates: new Array(),
  19043                    id: i
  19044                };
  19045            }
  19046        }
  19047        ResolutionDataCache.prototype.getResolutionData = function () {
  19048            var rd = null;
  19049            if(this.nextUp < this.cacheSize) {
  19050                rd = this.rdCache[this.nextUp];
  19051            }
  19052            if(rd == null) {
  19053                this.cacheSize++;
  19054                rd = {
  19055                    actuals: new Array(),
  19056                    exactCandidates: new Array(),
  19057                    conversionCandidates: new Array(),
  19058                    id: this.cacheSize
  19059                };
  19060                this.rdCache[this.cacheSize] = rd;
  19061            }
  19062            this.nextUp++;
  19063            return rd;
  19064        };
  19065        ResolutionDataCache.prototype.returnResolutionData = function (rd) {
  19066            rd.actuals.length = 0;
  19067            rd.exactCandidates.length = 0;
  19068            rd.conversionCandidates.length = 0;
  19069            this.nextUp = rd.id;
  19070        };
  19071        return ResolutionDataCache;
  19072    })();
  19073    TypeScript.ResolutionDataCache = ResolutionDataCache;    
  19074    var TypeFlow = (function () {
  19075        function TypeFlow(logger, initScope, parser, checker) {
  19076            this.logger = logger;
  19077            this.initScope = initScope;
  19078            this.parser = parser;
  19079            this.checker = checker;
  19080            this.thisFnc = null;
  19081            this.thisClassNode = null;
  19082            this.enclosingFncIsMethod = false;
  19083            this.arrayInterfaceType = null;
  19084            this.stringInterfaceType = null;
  19085            this.objectInterfaceType = null;
  19086            this.functionInterfaceType = null;
  19087            this.numberInterfaceType = null;
  19088            this.booleanInterfaceType = null;
  19089            this.iargumentsInterfaceType = null;
  19090            this.currentScript = null;
  19091            this.inImportTypeCheck = false;
  19092            this.inTypeRefTypeCheck = false;
  19093            this.inArrayElementTypeCheck = false;
  19094            this.resolutionDataCache = new ResolutionDataCache();
  19095            this.nestingLevel = 0;
  19096            this.inSuperCall = false;
  19097            this.checker.typeFlow = this;
  19098            this.scope = this.initScope;
  19099            this.globalScope = this.initScope;
  19100            this.doubleType = this.checker.numberType;
  19101            this.booleanType = this.checker.booleanType;
  19102            this.stringType = this.checker.stringType;
  19103            this.anyType = this.checker.anyType;
  19104            this.regexType = this.anyType;
  19105            this.nullType = this.checker.nullType;
  19106            this.voidType = this.checker.voidType;
  19107            this.arrayAnyType = this.checker.makeArrayType(this.anyType);
  19108        }
  19109        TypeFlow.prototype.initLibs = function () {
  19110            var arraySym = this.globalScope.find("Array", false, true);
  19111            if(arraySym && (arraySym.kind() == TypeScript.SymbolKind.Type)) {
  19112                this.arrayInterfaceType = (arraySym).type;
  19113            }
  19114            var stringSym = this.globalScope.find("String", false, true);
  19115            if(stringSym && (stringSym.kind() == TypeScript.SymbolKind.Type)) {
  19116                this.stringInterfaceType = (stringSym).type;
  19117            }
  19118            var objectSym = this.globalScope.find("Object", false, true);
  19119            if(objectSym && (objectSym.kind() == TypeScript.SymbolKind.Type)) {
  19120                this.objectInterfaceType = (objectSym).type;
  19121            }
  19122            var fnSym = this.globalScope.find("Function", false, true);
  19123            if(fnSym && (fnSym.kind() == TypeScript.SymbolKind.Type)) {
  19124                this.functionInterfaceType = (fnSym).type;
  19125            }
  19126            var numberSym = this.globalScope.find("Number", false, true);
  19127            if(numberSym && (numberSym.kind() == TypeScript.SymbolKind.Type)) {
  19128                this.numberInterfaceType = (numberSym).type;
  19129            }
  19130            var booleanSym = this.globalScope.find("Boolean", false, true);
  19131            if(booleanSym && (booleanSym.kind() == TypeScript.SymbolKind.Type)) {
  19132                this.booleanInterfaceType = (booleanSym).type;
  19133            }
  19134            var regexSym = this.globalScope.find("RegExp", false, true);
  19135            if(regexSym && (regexSym.kind() == TypeScript.SymbolKind.Type)) {
  19136                this.regexType = (regexSym).type;
  19137            }
  19138        };
  19139        TypeFlow.prototype.cast = function (ast, type) {
  19140            return this.castWithCoercion(ast, type, true, false);
  19141        };
  19142        TypeFlow.prototype.castWithCoercion = function (ast, type, applyCoercion, typeAssertion) {
  19143            var comparisonInfo = new TypeScript.TypeComparisonInfo();
  19144            if(this.checker.sourceIsAssignableToTarget(ast.type, type, comparisonInfo) || (typeAssertion && this.checker.sourceIsAssignableToTarget(type, ast.type, comparisonInfo))) {
  19145                if(applyCoercion) {
  19146                    if(type == null) {
  19147                        ast.type = this.anyType;
  19148                    } else {
  19149                        if(type.isClass()) {
  19150                            ast.type = type.instanceType;
  19151                        } else {
  19152                            ast.type = type;
  19153                        }
  19154                    }
  19155                }
  19156                return ast;
  19157            } else {
  19158                this.checker.errorReporter.incompatibleTypes(ast, ast.type, type, null, this.scope, comparisonInfo);
  19159                return ast;
  19160            }
  19161        };
  19162        TypeFlow.prototype.inScopeTypeCheck = function (ast, enclosingScope) {
  19163            var prevScope = this.scope;
  19164            this.scope = enclosingScope;
  19165            var svThisFnc = this.thisFnc;
  19166            var svThisType = this.thisType;
  19167            var svThisClassNode = this.thisClassNode;
  19168            var svCurrentModDecl = this.checker.currentModDecl;
  19169            var prevMethodStatus = this.enclosingFncIsMethod;
  19170            var container = this.scope.container;
  19171            var fnc = null;
  19172            while(container) {
  19173                if(container.kind() == TypeScript.SymbolKind.Type) {
  19174                    var typeSym = container;
  19175                    var type = typeSym.type;
  19176                    if(type.call) {
  19177                        if(fnc == null) {
  19178                            this.enclosingFncIsMethod = typeSym.isMethod;
  19179                            fnc = container.declAST;
  19180                        }
  19181                    }
  19182                    if(type.isClass()) {
  19183                        this.thisType = type.instanceType;
  19184                        if(typeSym.declAST && (typeSym.declAST.nodeType == TypeScript.NodeType.ClassDeclaration)) {
  19185                            this.thisClassNode = typeSym.declAST;
  19186                        }
  19187                        break;
  19188                    }
  19189                    if(type.isModuleType()) {
  19190                        this.checker.currentModDecl = typeSym.declAST;
  19191                        break;
  19192                    }
  19193                }
  19194                container = container.container;
  19195            }
  19196            this.thisFnc = fnc;
  19197            var updated = this.typeCheck(ast);
  19198            this.thisFnc = svThisFnc;
  19199            this.thisType = svThisType;
  19200            this.thisClassNode = svThisClassNode;
  19201            this.checker.currentModDecl = svCurrentModDecl;
  19202            this.enclosingFncIsMethod = prevMethodStatus;
  19203            this.scope = prevScope;
  19204            return updated;
  19205        };
  19206        TypeFlow.prototype.typeCheck = function (ast) {
  19207            if(ast) {
  19208                return ast.typeCheck(this);
  19209            } else {
  19210                return null;
  19211            }
  19212        };
  19213        TypeFlow.prototype.inScopeTypeCheckDecl = function (ast) {
  19214            if(ast.nodeType == TypeScript.NodeType.VarDecl || ast.nodeType == TypeScript.NodeType.ArgDecl) {
  19215                this.inScopeTypeCheckBoundDecl(ast);
  19216            } else {
  19217                if(ast.nodeType == TypeScript.NodeType.FuncDecl) {
  19218                    var funcDecl = ast;
  19219                    if(funcDecl.isAccessor()) {
  19220                        this.typeCheckFunction(funcDecl);
  19221                    }
  19222                }
  19223            }
  19224        };
  19225        TypeFlow.prototype.inScopeTypeCheckBoundDecl = function (varDecl) {
  19226            var sym = varDecl.sym;
  19227            var svThisFnc = this.thisFnc;
  19228            var svThisType = this.thisType;
  19229            var prevMethodStatus = this.enclosingFncIsMethod;
  19230            var prevLocationInfo = this.checker.locationInfo;
  19231            if(sym && sym.container) {
  19232                var instanceScope = TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.ClassConstructorProperty) ? sym.container.getType().constructorScope : sym.container.instanceScope();
  19233                if(TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.Property) && sym.container.declAST.nodeType == TypeScript.NodeType.FuncDecl) {
  19234                    this.thisFnc = sym.container.declAST;
  19235                }
  19236                if(instanceScope) {
  19237                    var prevScope = this.scope;
  19238                    this.scope = instanceScope;
  19239                    var container = sym.container;
  19240                    if(this.checker.units && (sym.unitIndex >= 0) && (sym.unitIndex < this.checker.units.length)) {
  19241                        this.checker.locationInfo = this.checker.units[sym.unitIndex];
  19242                    } else {
  19243                        this.checker.locationInfo = TypeScript.unknownLocationInfo;
  19244                    }
  19245                    while(container) {
  19246                        if(container.kind() == TypeScript.SymbolKind.Type) {
  19247                            var typeSym = container;
  19248                            var type = typeSym.type;
  19249                            if(type.call) {
  19250                                this.enclosingFncIsMethod = typeSym.isMethod;
  19251                            }
  19252                            if(type.isClass()) {
  19253                                this.thisType = type.instanceType;
  19254                                break;
  19255                            }
  19256                        }
  19257                        container = container.container;
  19258                    }
  19259                    this.typeCheckBoundDecl(varDecl);
  19260                    this.scope = prevScope;
  19261                }
  19262            }
  19263            this.thisFnc = svThisFnc;
  19264            this.thisType = svThisType;
  19265            this.checker.locationInfo = prevLocationInfo;
  19266            this.enclosingFncIsMethod = prevMethodStatus;
  19267        };
  19268        TypeFlow.prototype.resolveBoundDecl = function (varDecl) {
  19269            if(varDecl.typeExpr) {
  19270                if(varDecl.typeExpr.type == null || (varDecl.typeExpr.type && varDecl.typeExpr.type == this.anyType && this.scope) || varDecl.typeExpr.type.symbol == null || !this.checker.typeStatusIsFinished(varDecl.typeExpr.type.symbol.typeCheckStatus)) {
  19271                    this.typeCheck(varDecl.typeExpr);
  19272                }
  19273                varDecl.type = varDecl.typeExpr.type;
  19274                if(varDecl.sym) {
  19275                    varDecl.sym.setType(varDecl.type);
  19276                }
  19277            } else {
  19278                if(varDecl.init == null) {
  19279                    if(this.checker.styleSettings.implicitAny) {
  19280                        this.checker.errorReporter.styleError(varDecl, "type implicitly set to 'any'");
  19281                    }
  19282                    varDecl.type = this.anyType;
  19283                    if(varDecl.sym) {
  19284                        if(varDecl.sym.isType()) {
  19285                            var tsym = varDecl.sym;
  19286                            if(tsym.isMethod) {
  19287                                this.checker.errorReporter.simpleError(varDecl, "Cannot bind method group to variable.  (Did you mean to use 'declare function' instead of 'declare var'?)");
  19288                                return;
  19289                            } else {
  19290                                this.checker.errorReporter.simpleError(varDecl, "Cannot bind type to variable");
  19291                                return;
  19292                            }
  19293                        }
  19294                        varDecl.sym.setType(varDecl.type);
  19295                    }
  19296                }
  19297            }
  19298        };
  19299        TypeFlow.prototype.typeCheckBoundDecl = function (varDecl) {
  19300            var _this = this;
  19301            var infSym = varDecl.sym;
  19302            if(infSym == null) {
  19303                if(varDecl.init) {
  19304                    varDecl.init = this.typeCheck(varDecl.init);
  19305                    varDecl.type = this.checker.widenType(varDecl.init.type);
  19306                } else {
  19307                    if(this.checker.styleSettings.implicitAny) {
  19308                        this.checker.errorReporter.styleError(varDecl, "type implicitly set to 'any'");
  19309                    }
  19310                    varDecl.type = this.anyType;
  19311                }
  19312            } else {
  19313                if(infSym.typeCheckStatus == TypeScript.TypeCheckStatus.Started) {
  19314                    if(this.checker.styleSettings.implicitAny) {
  19315                        this.checker.errorReporter.styleError(varDecl, "type implicitly set to 'any'");
  19316                    }
  19317                    varDecl.type = this.anyType;
  19318                    infSym.setType(this.anyType);
  19319                } else {
  19320                    if(infSym.typeCheckStatus == TypeScript.TypeCheckStatus.NotStarted) {
  19321                        infSym.typeCheckStatus = TypeScript.TypeCheckStatus.Started;
  19322                        this.checker.addStartedPTO(infSym);
  19323                        var resolved = false;
  19324                        if(varDecl.type == null) {
  19325                            if(varDecl.typeExpr) {
  19326                                this.resolveBoundDecl(varDecl);
  19327                                resolved = true;
  19328                                varDecl.type = varDecl.typeExpr.type;
  19329                                infSym.typeCheckStatus = this.checker.getTypeCheckFinishedStatus();
  19330                            }
  19331                        }
  19332                        if(varDecl.init) {
  19333                            var isLocalStatic = TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.LocalStatic);
  19334                            var prevScope = this.scope;
  19335                            var applyTargetType = !varDecl.init.isParenthesized;
  19336                            if(isLocalStatic) {
  19337                                this.scope = varDecl.sym.container.getType().memberScope;
  19338                            }
  19339                            if(TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.Property) && this.thisClassNode) {
  19340                                TypeScript.getAstWalkerFactory().walk(varDecl.init, function (ast, parent, walker) {
  19341                                    if(ast && ast.nodeType == TypeScript.NodeType.FuncDecl) {
  19342                                        if(TypeScript.hasFlag((ast).fncFlags, TypeScript.FncFlags.IsFatArrowFunction)) {
  19343                                            (ast).fncFlags |= TypeScript.FncFlags.IsPropertyBound;
  19344                                        }
  19345                                        walker.options.goChildren = false;
  19346                                    }
  19347                                    return ast;
  19348                                });
  19349                            }
  19350                            this.checker.typeCheckWithContextualType(varDecl.type, this.checker.inProvisionalTypecheckMode(), applyTargetType, varDecl.init);
  19351                            this.scope = prevScope;
  19352                            if(varDecl.type) {
  19353                                var preserveScope = false;
  19354                                var preservedContainedScope = null;
  19355                                if(varDecl.init.type) {
  19356                                    preservedContainedScope = varDecl.init.type.containedScope;
  19357                                    preserveScope = true;
  19358                                    if(varDecl.init.type == this.voidType) {
  19359                                        this.checker.errorReporter.simpleError(varDecl, "Cannot assign type 'void' to variable '" + varDecl.id.actualText + "'");
  19360                                    }
  19361                                }
  19362                                varDecl.init = this.castWithCoercion(varDecl.init, varDecl.type, applyTargetType && !this.checker.inProvisionalTypecheckMode(), false);
  19363                                if(preserveScope && varDecl.init.type.containedScope == null) {
  19364                                    varDecl.init.type.containedScope = preservedContainedScope;
  19365                                }
  19366                            } else {
  19367                                varDecl.type = this.checker.widenType(varDecl.init.type);
  19368                                if(varDecl.type == this.voidType) {
  19369                                    this.checker.errorReporter.simpleError(varDecl, "Cannot assign type 'void' to variable '" + varDecl.id.actualText + "'");
  19370                                    varDecl.type = this.anyType;
  19371                                }
  19372                            }
  19373                            infSym.setType(varDecl.type);
  19374                        } else {
  19375                            if(!resolved) {
  19376                                this.resolveBoundDecl(varDecl);
  19377                            }
  19378                        }
  19379                        infSym.typeCheckStatus = this.checker.getTypeCheckFinishedStatus();
  19380                    } else {
  19381                        if(this.checker.typeStatusIsFinished(infSym.typeCheckStatus) && (infSym.declAST != varDecl)) {
  19382                            if(varDecl.init) {
  19383                                varDecl.init = this.typeCheck(varDecl.init);
  19384                                varDecl.type = infSym.getType();
  19385                                varDecl.init = this.cast(varDecl.init, varDecl.type);
  19386                            }
  19387                        }
  19388                    }
  19389                }
  19390            }
  19391            if(varDecl.id && varDecl.sym) {
  19392                varDecl.id.sym = varDecl.sym;
  19393            }
  19394            if(varDecl.sym && varDecl.sym.container) {
  19395                this.checkTypePrivacy(varDecl.sym.getType(), varDecl.sym, function (typeName, isModuleName) {
  19396                    return _this.varPrivacyErrorReporter(varDecl, typeName, isModuleName);
  19397                });
  19398            }
  19399            return varDecl;
  19400        };
  19401        TypeFlow.prototype.varPrivacyErrorReporter = function (varDecl, typeName, isModuleName) {
  19402            var typestring = "";
  19403            if(isModuleName) {
  19404                var quotestring = "";
  19405                if(!TypeScript.isQuoted(typeName)) {
  19406                    quotestring = "'";
  19407                }
  19408                typestring = " is using inaccessible module " + quotestring + typeName + quotestring;
  19409            } else {
  19410                typestring = " has or is using private type '" + typeName + "'";
  19411            }
  19412            if(TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.Public)) {
  19413                if(varDecl.sym.container.declAST.nodeType == TypeScript.NodeType.InterfaceDeclaration) {
  19414                    this.checker.errorReporter.simpleError(varDecl, "property '" + varDecl.sym.name + "' of exported interface" + typestring);
  19415                } else {
  19416                    this.checker.errorReporter.simpleError(varDecl, "public member '" + varDecl.sym.name + "' of exported class" + typestring);
  19417                }
  19418            } else {
  19419                this.checker.errorReporter.simpleError(varDecl, "exported variable '" + varDecl.sym.name + "'" + typestring);
  19420            }
  19421        };
  19422        TypeFlow.prototype.typeCheckSuper = function (ast) {
  19423            if(this.thisType && (this.enclosingFncIsMethod && !this.thisFnc.isStatic()) && this.thisType.baseClass()) {
  19424                ast.type = this.thisType.baseClass();
  19425            } else {
  19426                if(!this.enclosingFncIsMethod && this.thisType && this.thisType.baseClass() && this.thisFnc && TypeScript.hasFlag(this.thisFnc.fncFlags, TypeScript.FncFlags.IsFatArrowFunction)) {
  19427                    var enclosingFnc = this.thisFnc.enclosingFnc;
  19428                    while(TypeScript.hasFlag(enclosingFnc.fncFlags, TypeScript.FncFlags.IsFatArrowFunction)) {
  19429                        enclosingFnc = enclosingFnc.enclosingFnc;
  19430                    }
  19431                    if(enclosingFnc && (enclosingFnc.isMethod() || enclosingFnc.isConstructor) && !enclosingFnc.isStatic()) {
  19432                        ast.type = this.thisType.baseClass();
  19433                        enclosingFnc.setHasSuperReferenceInFatArrowFunction();
  19434                        return ast;
  19435                    }
  19436                }
  19437                ast.type = this.anyType;
  19438                this.checker.errorReporter.invalidSuperReference(ast);
  19439            }
  19440            return ast;
  19441        };
  19442        TypeFlow.prototype.typeCheckThis = function (ast) {
  19443            ast.type = this.anyType;
  19444            var illegalThisRef = false;
  19445            if(this.thisFnc == null) {
  19446                if(this.thisType) {
  19447                    if(this.thisClassNode && this.thisClassNode.nodeType == TypeScript.NodeType.ClassDeclaration) {
  19448                        illegalThisRef = true;
  19449                    } else {
  19450                        ast.type = this.thisType;
  19451                    }
  19452                } else {
  19453                    if(this.checker.currentModDecl) {
  19454                        this.checker.errorReporter.simpleError(ast, "'this' may not be referenced within module bodies");
  19455                    }
  19456                }
  19457            } else {
  19458                if(this.thisClassNode && (TypeScript.hasFlag(this.thisFnc.fncFlags, TypeScript.FncFlags.IsPropertyBound) || (this.inSuperCall && TypeScript.hasFlag((this.thisClassNode).varFlags, TypeScript.VarFlags.ClassSuperMustBeFirstCallInConstructor)))) {
  19459                    illegalThisRef = true;
  19460                }
  19461                if(this.thisFnc.isMethod() || this.thisFnc.isConstructor || this.thisFnc.isTargetTypedAsMethod) {
  19462                    if(this.thisType && !(this.thisFnc.fncFlags & TypeScript.FncFlags.Static)) {
  19463                        ast.type = this.thisType;
  19464                    }
  19465                }
  19466            }
  19467            if(!this.enclosingFncIsMethod && this.thisFnc && TypeScript.hasFlag(this.thisFnc.fncFlags, TypeScript.FncFlags.IsFatArrowFunction)) {
  19468                if(this.thisFnc.boundToProperty) {
  19469                    var container = this.thisFnc.boundToProperty.sym.container;
  19470                    if(container.declAST.nodeType == TypeScript.NodeType.FuncDecl) {
  19471                        (container.declAST).setHasSelfReference();
  19472                    }
  19473                } else {
  19474                    var encFnc = this.thisFnc.enclosingFnc;
  19475                    var firstEncFnc = encFnc;
  19476                    while(encFnc) {
  19477                        if(this.thisClassNode && TypeScript.hasFlag(encFnc.fncFlags, TypeScript.FncFlags.IsPropertyBound)) {
  19478                            illegalThisRef = true;
  19479                        }
  19480                        if(!TypeScript.hasFlag(encFnc.fncFlags, TypeScript.FncFlags.IsFatArrowFunction) || encFnc.hasSelfReference()) {
  19481                            encFnc.setHasSelfReference();
  19482                            break;
  19483                        }
  19484                        encFnc = encFnc.enclosingFnc;
  19485                    }
  19486                    if(!encFnc && firstEncFnc) {
  19487                        encFnc = firstEncFnc;
  19488                        encFnc.setHasSelfReference();
  19489                    } else {
  19490                        if(!encFnc) {
  19491                            if(this.thisClassNode) {
  19492                                (this.thisClassNode).varFlags |= TypeScript.VarFlags.MustCaptureThis;
  19493                            } else {
  19494                                if(this.checker.currentModDecl) {
  19495                                    this.checker.currentModDecl.modFlags |= TypeScript.ModuleFlags.MustCaptureThis;
  19496                                } else {
  19497                                    this.checker.mustCaptureGlobalThis = true;
  19498                                }
  19499                            }
  19500                        }
  19501                    }
  19502                    if(encFnc && (encFnc.isMethod() || encFnc.isConstructor) && this.thisType && !TypeScript.hasFlag(encFnc.fncFlags, TypeScript.FncFlags.Static)) {
  19503                        ast.type = this.thisType;
  19504                    }
  19505                }
  19506            }
  19507            if(illegalThisRef) {
  19508                this.checker.errorReporter.simpleError(ast, "Keyword 'this' cannot be referenced in initializers in a class body, or in super constructor calls");
  19509            }
  19510            return ast;
  19511        };
  19512        TypeFlow.prototype.setTypeFromSymbol = function (ast, symbol) {
  19513            if(symbol.isVariable()) {
  19514                if(symbol.isInferenceSymbol()) {
  19515                    var infSym = symbol;
  19516                    if(infSym.declAST && !this.checker.typeStatusIsFinished(infSym.typeCheckStatus)) {
  19517                        this.inScopeTypeCheckDecl(infSym.declAST);
  19518                    }
  19519                    if(!this.checker.styleSettings.innerScopeDeclEscape) {
  19520                        if(infSym.declAST && (infSym.declAST.nodeType == TypeScript.NodeType.VarDecl)) {
  19521                            if(this.nestingLevel < (infSym.declAST).nestingLevel) {
  19522                                this.checker.errorReporter.styleError(ast, "Illegal reference to a variable defined in more nested scope");
  19523                            }
  19524                        }
  19525                    }
  19526                }
  19527                ast.type = symbol.getType();
  19528                if(!symbol.writeable()) {
  19529                    ast.flags = ast.flags & (~(TypeScript.ASTFlags.Writeable));
  19530                }
  19531            } else {
  19532                if(symbol.isType()) {
  19533                    ast.type = symbol.getType();
  19534                    ast.flags = ast.flags & (~(TypeScript.ASTFlags.Writeable));
  19535                } else {
  19536                    ast.type = this.anyType;
  19537                    this.checker.errorReporter.symbolDoesNotReferToAValue(ast, symbol.name);
  19538                }
  19539            }
  19540        };
  19541        TypeFlow.prototype.typeCheckName = function (ast) {
  19542            var _this = this;
  19543            var identifier = ast;
  19544            if(this.checker.inWith) {
  19545                identifier.type = this.anyType;
  19546            } else {
  19547                var typespace = this.inTypeRefTypeCheck;
  19548                var idText = identifier.text;
  19549                var originalIdText = idText;
  19550                var isDynamicModuleName = TypeScript.isQuoted(identifier.text);
  19551                var symbol = this.scope.find(idText, false, typespace);
  19552                if(symbol == null && isDynamicModuleName) {
  19553                    symbol = this.checker.findSymbolForDynamicModule(idText, this.currentScript.locationInfo.filename, function (id) {
  19554                        return _this.scope.find(id, false, typespace);
  19555                    });
  19556                }
  19557                if(!symbol) {
  19558                    if(!identifier.isMissing()) {
  19559                        this.checker.errorReporter.unresolvedSymbol(identifier, identifier.text);
  19560                    }
  19561                    identifier.type = this.anyType;
  19562                } else {
  19563                    if(TypeScript.optimizeModuleCodeGen && symbol && symbol.isType()) {
  19564                        var symType = symbol.getType();
  19565                        if(symType && (symbol).aliasLink && (symbol).onlyReferencedAsTypeRef) {
  19566                            var modDecl = symType.symbol.declAST;
  19567                            if(modDecl && TypeScript.hasFlag(modDecl.modFlags, TypeScript.ModuleFlags.IsDynamic)) {
  19568                                (symbol).onlyReferencedAsTypeRef = this.inTypeRefTypeCheck;
  19569                            }
  19570                        }
  19571                    }
  19572                    if(symbol.declAST && symbol.declAST.nodeType == TypeScript.NodeType.FuncDecl && !(symbol.declAST).returnTypeAnnotation && (symbol.declAST).signature.typeCheckStatus == TypeScript.TypeCheckStatus.Started) {
  19573                        (symbol.declAST).type.symbol.flags |= TypeScript.SymbolFlags.RecursivelyReferenced;
  19574                        (symbol.declAST).signature.returnType.type = this.anyType;
  19575                    }
  19576                    this.setTypeFromSymbol(ast, symbol);
  19577                    identifier.sym = symbol;
  19578                    if(this.thisFnc) {
  19579                        if(this.thisFnc.type && symbol.container != this.thisFnc.type.symbol) {
  19580                            this.thisFnc.freeVariables[this.thisFnc.freeVariables.length] = symbol;
  19581                        }
  19582                    }
  19583                }
  19584            }
  19585            return ast;
  19586        };
  19587        TypeFlow.prototype.typeCheckScript = function (script) {
  19588            this.checker.locationInfo = script.locationInfo;
  19589            this.scope = this.checker.globalScope;
  19590            if(!script.topLevelMod) {
  19591                this.addLocalsFromScope(this.scope, this.checker.gloMod, script.vars, this.checker.globals, true);
  19592            }
  19593            this.currentScript = script;
  19594            script.bod = this.typeCheck(script.bod);
  19595            this.currentScript = null;
  19596            return script;
  19597        };
  19598        TypeFlow.prototype.typeCheckBitNot = function (ast) {
  19599            var unex = ast;
  19600            unex.operand = this.typeCheck(unex.operand);
  19601            unex.type = this.doubleType;
  19602            return unex;
  19603        };
  19604        TypeFlow.prototype.typeCheckUnaryNumberOperator = function (ast) {
  19605            var unex = ast;
  19606            unex.operand = this.typeCheck(unex.operand);
  19607            unex.type = this.doubleType;
  19608            return ast;
  19609        };
  19610        TypeFlow.prototype.typeCheckLogNot = function (ast) {
  19611            var unex = ast;
  19612            unex.operand = this.typeCheck(unex.operand);
  19613            unex.type = this.booleanType;
  19614            return unex;
  19615        };
  19616        TypeFlow.prototype.astIsWriteable = function (ast) {
  19617            return TypeScript.hasFlag(ast.flags, TypeScript.ASTFlags.Writeable);
  19618        };
  19619        TypeFlow.prototype.typeCheckIncOrDec = function (ast) {
  19620            var unex = ast;
  19621            var lval = unex.operand;
  19622            if(!this.astIsWriteable(unex)) {
  19623                this.checker.errorReporter.valueCannotBeModified(unex);
  19624                unex.type = this.doubleType;
  19625            } else {
  19626                unex = this.typeCheckUnaryNumberOperator(ast);
  19627                if(unex.operand.type != this.checker.numberType && unex.operand.type != this.checker.anyType && !(unex.operand.type.typeFlags & TypeScript.TypeFlags.IsEnum)) {
  19628                    this.checker.errorReporter.simpleError(ast, "'++' and '--' may only be applied to operands of type 'number' or 'any'");
  19629                }
  19630            }
  19631            return unex;
  19632        };
  19633        TypeFlow.prototype.typeCheckBitwiseOperator = function (ast, assignment) {
  19634            var binex = ast;
  19635            var resultType = null;
  19636            binex.operand1 = this.typeCheck(binex.operand1);
  19637            binex.operand2 = this.typeCheck(binex.operand2);
  19638            var leftType = binex.operand1.type;
  19639            var rightType = binex.operand2.type;
  19640            if(assignment && (!this.astIsWriteable(binex))) {
  19641                this.checker.errorReporter.valueCannotBeModified(binex);
  19642            }
  19643            if(this.checker.styleSettings.bitwise) {
  19644                this.checker.errorReporter.styleError(ast, "use of " + TypeScript.nodeTypeTable[binex.nodeType]);
  19645            }
  19646            if(this.checker.sourceIsSubtypeOfTarget(leftType, this.doubleType) && (this.checker.sourceIsSubtypeOfTarget(rightType, this.doubleType))) {
  19647                resultType = this.doubleType;
  19648            } else {
  19649                if((leftType == this.booleanType) && (rightType == this.booleanType)) {
  19650                    resultType = this.booleanType;
  19651                } else {
  19652                    if(leftType == this.anyType) {
  19653                        if((rightType == this.anyType) || (rightType == this.doubleType) || (rightType == this.booleanType)) {
  19654                            resultType = this.anyType;
  19655                        }
  19656                    } else {
  19657                        if(rightType == this.anyType) {
  19658                            if((leftType == this.anyType) || (leftType == this.doubleType) || (leftType == this.booleanType)) {
  19659                                resultType = this.anyType;
  19660                            }
  19661                        }
  19662                    }
  19663                }
  19664            }
  19665            if(resultType == null) {
  19666                resultType = this.anyType;
  19667                this.checker.errorReporter.incompatibleTypes(binex, leftType, rightType, binex.printLabel(), this.scope);
  19668            }
  19669            binex.type = resultType;
  19670            return binex;
  19671        };
  19672        TypeFlow.prototype.typeCheckArithmeticOperator = function (ast, assignment) {
  19673            var binex = ast;
  19674            binex.operand1 = this.typeCheck(binex.operand1);
  19675            binex.operand2 = this.typeCheck(binex.operand2);
  19676            var leftType = binex.operand1.type;
  19677            var rightType = binex.operand2.type;
  19678            if(assignment && (!this.astIsWriteable(binex.operand1))) {
  19679                this.checker.errorReporter.valueCannotBeModified(binex);
  19680            }
  19681            if(this.checker.styleSettings.bitwise && ((binex.nodeType == TypeScript.NodeType.And) || (binex.nodeType == TypeScript.NodeType.Or) || (binex.nodeType == TypeScript.NodeType.AsgAnd) || (binex.nodeType == TypeScript.NodeType.AsgOr))) {
  19682                this.checker.errorReporter.styleError(ast, "use of " + TypeScript.nodeTypeTable[binex.nodeType]);
  19683            }
  19684            if(leftType == null || rightType == null) {
  19685                this.checker.errorReporter.simpleError(binex, "Could not typecheck arithmetic operation.  Possible recursive typecheck error?");
  19686                binex.type = this.anyType;
  19687                return binex;
  19688            }
  19689            var nodeType = binex.nodeType;
  19690            if(this.checker.isNullOrUndefinedType(leftType)) {
  19691                leftType = rightType;
  19692            }
  19693            if(this.checker.isNullOrUndefinedType(rightType)) {
  19694                rightType = leftType;
  19695            }
  19696            leftType = this.checker.widenType(leftType);
  19697            rightType = this.checker.widenType(rightType);
  19698            if(nodeType == TypeScript.NodeType.Add || nodeType == TypeScript.NodeType.AsgAdd) {
  19699                if(leftType == this.checker.stringType || rightType == this.checker.stringType) {
  19700                    binex.type = this.checker.stringType;
  19701                } else {
  19702                    if(leftType == this.checker.numberType && rightType == this.checker.numberType) {
  19703                        binex.type = this.checker.numberType;
  19704                    } else {
  19705                        if(this.checker.sourceIsSubtypeOfTarget(leftType, this.checker.numberType) && this.checker.sourceIsSubtypeOfTarget(rightType, this.checker.numberType)) {
  19706                            binex.type = this.checker.numberType;
  19707                        } else {
  19708                            if(leftType == this.checker.anyType || rightType == this.checker.anyType) {
  19709                                binex.type = this.checker.anyType;
  19710                            } else {
  19711                                binex.type = this.anyType;
  19712                                this.checker.errorReporter.incompatibleTypes(binex, leftType, rightType, binex.printLabel(), this.scope);
  19713                            }
  19714                        }
  19715                    }
  19716                }
  19717            } else {
  19718                if(leftType == this.checker.numberType && rightType == this.checker.numberType) {
  19719                    binex.type = this.checker.numberType;
  19720                } else {
  19721                    if(this.checker.sourceIsSubtypeOfTarget(leftType, this.checker.numberType) && this.checker.sourceIsSubtypeOfTarget(rightType, this.checker.numberType)) {
  19722                        binex.type = this.checker.numberType;
  19723                    } else {
  19724                        if(leftType == this.checker.anyType || rightType == this.checker.anyType) {
  19725                            binex.type = this.checker.numberType;
  19726                        } else {
  19727                            binex.type = this.anyType;
  19728                            this.checker.errorReporter.incompatibleTypes(binex, leftType, rightType, binex.printLabel(), this.scope);
  19729                        }
  19730                    }
  19731                }
  19732            }
  19733            return binex;
  19734        };
  19735        TypeFlow.prototype.typeCheckDotOperator = function (ast) {
  19736            var binex = ast;
  19737            var leftIsFnc = false;
  19738            binex.operand1 = this.typeCheck(binex.operand1);
  19739            var leftType = binex.operand1.type;
  19740            var leftScope = null;
  19741            if(leftType) {
  19742                if(leftType == this.anyType) {
  19743                    binex.type = this.anyType;
  19744                    return binex;
  19745                } else {
  19746                    if(leftType == this.stringType) {
  19747                        if(this.stringInterfaceType) {
  19748                            leftScope = this.stringInterfaceType.memberScope;
  19749                        } else {
  19750                            binex.type = this.anyType;
  19751                            return binex;
  19752                        }
  19753                    } else {
  19754                        if(leftType == this.doubleType) {
  19755                            if(this.numberInterfaceType) {
  19756                                leftScope = this.numberInterfaceType.memberScope;
  19757                            } else {
  19758                                binex.type = this.anyType;
  19759                                return binex;
  19760                            }
  19761                        } else {
  19762                            if(leftType == this.booleanType) {
  19763                                if(this.booleanInterfaceType) {
  19764                                    leftScope = this.booleanInterfaceType.memberScope;
  19765                                } else {
  19766                                    binex.type = this.anyType;
  19767                                    return binex;
  19768                                }
  19769                            } else {
  19770                                if((leftType.call || leftType.construct) && leftType.members == null) {
  19771                                    if(this.functionInterfaceType) {
  19772                                        leftScope = this.functionInterfaceType.memberScope;
  19773                                    } else {
  19774                                        binex.type = this.anyType;
  19775                                        return binex;
  19776                                    }
  19777                                } else {
  19778                                    if(leftType.elementType) {
  19779                                        if(this.arrayInterfaceType) {
  19780                                            var arrInstType = leftType.elementType.getArrayBase(this.arrayInterfaceType, this.checker);
  19781                                            leftScope = arrInstType.memberScope;
  19782                                        } else {
  19783                                            binex.type = this.anyType;
  19784                                            return binex;
  19785                                        }
  19786                                    } else {
  19787                                        leftScope = leftType.memberScope;
  19788                                    }
  19789                                }
  19790                            }
  19791                        }
  19792                    }
  19793                }
  19794            }
  19795            if(leftScope == null) {
  19796                this.checker.errorReporter.expectedClassOrInterface(binex);
  19797                binex.type = this.anyType;
  19798            } else {
  19799                var propertyName = binex.operand2;
  19800                var lhsIsEnclosingType = (this.thisClassNode && binex.operand1.type == this.thisClassNode.type.instanceType) || this.inTypeRefTypeCheck;
  19801                var symbol = leftScope.find(propertyName.text, !lhsIsEnclosingType, this.inTypeRefTypeCheck);
  19802                if(!symbol) {
  19803                    if(this.objectInterfaceType && leftType) {
  19804                        if(leftType.isReferenceType()) {
  19805                            symbol = this.objectInterfaceType.memberScope.find(propertyName.text, false, this.inTypeRefTypeCheck);
  19806                        }
  19807                        if(!symbol) {
  19808                            if(this.functionInterfaceType && (leftType.call || leftType.construct)) {
  19809                                symbol = this.functionInterfaceType.memberScope.find(propertyName.text, false, this.inTypeRefTypeCheck);
  19810                            }
  19811                        }
  19812                    }
  19813                }
  19814                if(!symbol || (!symbol.visible(leftScope, this.checker))) {
  19815                    binex.type = this.anyType;
  19816                    if(symbol == null) {
  19817                        this.checker.errorReporter.simpleError(propertyName, "The property '" + propertyName.actualText + "' does not exist on value of type '" + leftType.getScopedTypeName(this.scope) + "'");
  19818                    } else {
  19819                        if(!this.inTypeRefTypeCheck) {
  19820                            this.checker.errorReporter.simpleError(binex, "The property '" + propertyName.actualText + " on type '" + leftType.getScopedTypeName(this.scope) + "' is not visible");
  19821                        }
  19822                    }
  19823                } else {
  19824                    if(symbol.isVariable()) {
  19825                        if(symbol.isInferenceSymbol()) {
  19826                            var infSym = symbol;
  19827                            if(infSym.declAST && !this.checker.typeStatusIsFinished(infSym.typeCheckStatus)) {
  19828                                this.inScopeTypeCheckDecl(infSym.declAST);
  19829                            }
  19830                        }
  19831                    }
  19832                    propertyName.sym = symbol;
  19833                    binex.type = symbol.getType();
  19834                }
  19835            }
  19836            if(binex.type == null) {
  19837                binex.type = this.anyType;
  19838            }
  19839            return binex;
  19840        };
  19841        TypeFlow.prototype.typeCheckBooleanOperator = function (ast) {
  19842            var binex = ast;
  19843            binex.operand1 = this.typeCheck(binex.operand1);
  19844            binex.operand2 = this.typeCheck(binex.operand2);
  19845            var leftType = binex.operand1.type;
  19846            var rightType = binex.operand2.type;
  19847            if((!(this.checker.sourceIsAssignableToTarget(leftType, rightType))) && (!(this.checker.sourceIsAssignableToTarget(rightType, leftType)))) {
  19848                this.checker.errorReporter.incompatibleTypes(binex, leftType, rightType, binex.printLabel(), this.scope);
  19849            }
  19850            binex.type = this.booleanType;
  19851            return binex;
  19852        };
  19853        TypeFlow.prototype.typeCheckAsgOperator = function (ast) {
  19854            var binex = ast;
  19855            var applyTargetType = !binex.operand2.isParenthesized;
  19856            binex.operand1 = this.typeCheck(binex.operand1);
  19857            this.checker.typeCheckWithContextualType(binex.operand1.type, this.checker.inProvisionalTypecheckMode(), applyTargetType, binex.operand2);
  19858            var leftType = binex.operand1.type;
  19859            var rightType = binex.operand2.type;
  19860            if(!(this.astIsWriteable(binex.operand1))) {
  19861                this.checker.errorReporter.valueCannotBeModified(binex);
  19862            }
  19863            if(binex.operand1.nodeType == TypeScript.NodeType.Call) {
  19864                var callEx = binex.operand1;
  19865            }
  19866            var preserveScope = false;
  19867            var preservedContainedScope = null;
  19868            if(binex.operand2.type) {
  19869                preservedContainedScope = binex.operand2.type.containedScope;
  19870                preserveScope = true;
  19871            }
  19872            binex.operand2 = this.castWithCoercion(binex.operand2, leftType, applyTargetType && !this.checker.inProvisionalTypecheckMode(), false);
  19873            if(preserveScope && binex.operand2.type.containedScope == null) {
  19874                binex.operand2.type.containedScope = preservedContainedScope;
  19875            }
  19876            binex.type = rightType;
  19877            return binex;
  19878        };
  19879        TypeFlow.prototype.typeCheckIndex = function (ast) {
  19880            var binex = ast;
  19881            binex.operand1 = this.typeCheck(binex.operand1);
  19882            binex.operand2 = this.typeCheck(binex.operand2);
  19883            if(!this.checker.styleSettings.literalSubscript) {
  19884                if(binex.operand2.nodeType == TypeScript.NodeType.QString) {
  19885                    this.checker.errorReporter.styleError(ast, "use literal subscript ('.') notation instead)");
  19886                }
  19887            }
  19888            var objExprType = binex.operand1.type;
  19889            var indexExprType = binex.operand2.type;
  19890            if(objExprType.elementType) {
  19891                if(indexExprType == this.checker.anyType || indexExprType == this.checker.numberType || TypeScript.hasFlag(indexExprType.typeFlags, TypeScript.TypeFlags.IsEnum)) {
  19892                    binex.type = objExprType.elementType;
  19893                } else {
  19894                    if(indexExprType == this.checker.stringType) {
  19895                        binex.type = this.checker.anyType;
  19896                    } else {
  19897                        this.checker.errorReporter.simpleError(binex, "Illegal property access");
  19898                        binex.type = this.checker.anyType;
  19899                    }
  19900                }
  19901            } else {
  19902                if(objExprType.index) {
  19903                    if(indexExprType == this.checker.anyType || !((objExprType.index.flags & TypeScript.SignatureFlags.IsStringIndexer) || (objExprType.index.flags & TypeScript.SignatureFlags.IsNumberIndexer)) || ((objExprType.index.flags & TypeScript.SignatureFlags.IsStringIndexer) && indexExprType == this.checker.stringType) || ((objExprType.index.flags & TypeScript.SignatureFlags.IsNumberIndexer) && (indexExprType == this.checker.numberType || TypeScript.hasFlag(indexExprType.typeFlags, TypeScript.TypeFlags.IsEnum)))) {
  19904                        var sig = this.resolveOverload(ast, objExprType.index);
  19905                        if(sig) {
  19906                            binex.type = sig.returnType.type;
  19907                        } else {
  19908                            binex.type = this.checker.anyType;
  19909                        }
  19910                    } else {
  19911                        if(indexExprType == this.checker.stringType) {
  19912                            binex.type = this.checker.anyType;
  19913                        } else {
  19914                            this.checker.errorReporter.simpleError(binex, "Illegal property access");
  19915                            binex.type = this.checker.anyType;
  19916                        }
  19917                    }
  19918                } else {
  19919                    if((objExprType == this.checker.anyType || objExprType == this.checker.stringType || objExprType == this.checker.numberType || objExprType == this.checker.booleanType || objExprType.isReferenceType()) && (indexExprType == this.checker.anyType || indexExprType == this.checker.stringType || (indexExprType == this.checker.numberType || TypeScript.hasFlag(indexExprType.typeFlags, TypeScript.TypeFlags.IsEnum)))) {
  19920                        binex.type = this.checker.anyType;
  19921                    } else {
  19922                        this.checker.errorReporter.simpleError(binex, "Illegal property access");
  19923                        binex.type = this.checker.anyType;
  19924                    }
  19925                }
  19926            }
  19927            return binex;
  19928        };
  19929        TypeFlow.prototype.typeCheckInOperator = function (binex) {
  19930            binex.operand1 = this.cast(this.typeCheck(binex.operand1), this.stringType);
  19931            binex.operand2 = this.typeCheck(binex.operand2);
  19932            if(!((binex.operand1.type == this.checker.anyType || binex.operand1.type == this.checker.stringType) && (binex.operand2.type == this.anyType || this.checker.sourceIsSubtypeOfTarget(binex.operand2.type, this.objectInterfaceType)))) {
  19933                this.checker.errorReporter.simpleError(binex, "The in operator requires the left operand to be of type Any or the String primitive type, and the right operand to be of type Any or an object type");
  19934            }
  19935            binex.type = this.booleanType;
  19936            return binex;
  19937        };
  19938        TypeFlow.prototype.typeCheckShift = function (binex, assignment) {
  19939            binex.operand1 = this.cast(this.typeCheck(binex.operand1), this.doubleType);
  19940            binex.operand2 = this.cast(this.typeCheck(binex.operand2), this.doubleType);
  19941            if(assignment && (!(this.astIsWriteable(binex.operand1)))) {
  19942                this.checker.errorReporter.valueCannotBeModified(binex);
  19943            }
  19944            binex.type = this.doubleType;
  19945            return binex;
  19946        };
  19947        TypeFlow.prototype.typeCheckQMark = function (trinex) {
  19948            trinex.operand1 = this.typeCheck(trinex.operand1);
  19949            trinex.operand2 = this.typeCheck(trinex.operand2);
  19950            trinex.operand3 = this.typeCheck(trinex.operand3);
  19951            var leftType = trinex.operand2.type;
  19952            var rightType = trinex.operand3.type;
  19953            if(leftType == rightType) {
  19954                trinex.type = leftType;
  19955            } else {
  19956                if(this.checker.sourceIsSubtypeOfTarget(leftType, rightType)) {
  19957                    trinex.type = rightType;
  19958                } else {
  19959                    if(this.checker.sourceIsSubtypeOfTarget(rightType, leftType)) {
  19960                        trinex.type = leftType;
  19961                    } else {
  19962                        trinex.type = this.anyType;
  19963                        this.checker.errorReporter.incompatibleTypes(trinex, leftType, rightType, trinex.printLabel(), this.scope);
  19964                    }
  19965                }
  19966            }
  19967            return trinex;
  19968        };
  19969        TypeFlow.prototype.addFormals = function (container, signature, table) {
  19970            var len = signature.parameters.length;
  19971            for(var i = 0; i < len; i++) {
  19972                var symbol = signature.parameters[i];
  19973                symbol.container = container;
  19974                table.add(symbol.name, symbol);
  19975            }
  19976        };
  19977        TypeFlow.prototype.addLocalsFromScope = function (scope, container, vars, table, isModContainer) {
  19978            var len = vars.members.length;
  19979            var hasArgsDef = false;
  19980            for(var i = 0; i < len; i++) {
  19981                var local = vars.members[i];
  19982                if(((local.sym == null) || (local.sym.kind() != TypeScript.SymbolKind.Field))) {
  19983                    var result = null;
  19984                    if((result = table.lookup(local.id.text)) == null) {
  19985                        var localVar = new TypeScript.ValueLocation();
  19986                        localVar.typeLink = new TypeScript.TypeLink();
  19987                        var varSym = null;
  19988                        if(TypeScript.hasFlag(local.varFlags, TypeScript.VarFlags.Static)) {
  19989                            local.varFlags |= TypeScript.VarFlags.LocalStatic;
  19990                            varSym = new TypeScript.FieldSymbol(local.id.text, local.minChar, this.checker.locationInfo.unitIndex, true, localVar);
  19991                        } else {
  19992                            varSym = new TypeScript.VariableSymbol(local.id.text, local.minChar, this.checker.locationInfo.unitIndex, localVar);
  19993                        }
  19994                        varSym.transferVarFlags(local.varFlags);
  19995                        localVar.symbol = varSym;
  19996                        varSym.declAST = local;
  19997                        localVar.typeLink.ast = local.typeExpr;
  19998                        this.checker.resolveTypeLink(scope, localVar.typeLink, false);
  19999                        if((local.type == null) && (local.init == null)) {
  20000                            local.type = this.anyType;
  20001                        }
  20002                        localVar.typeLink.type = local.type;
  20003                        localVar.symbol.container = container;
  20004                        local.sym = localVar.symbol;
  20005                        table.add(local.id.text, varSym);
  20006                        if(local.id.text == "arguments") {
  20007                            hasArgsDef = true;
  20008                        }
  20009                    } else {
  20010                        local.type = result.getType();
  20011                        local.sym = result;
  20012                    }
  20013                }
  20014            }
  20015            if(!isModContainer) {
  20016                if(!hasArgsDef) {
  20017                    var argLoc = new TypeScript.ValueLocation();
  20018                    argLoc.typeLink = new TypeScript.TypeLink();
  20019                    var theArgSym = new TypeScript.VariableSymbol("arguments", vars.minChar, this.checker.locationInfo.unitIndex, argLoc);
  20020                    if(!this.iargumentsInterfaceType) {
  20021                        var argumentsSym = scope.find("IArguments", false, true);
  20022                        if(argumentsSym) {
  20023                            argumentsSym.flags |= TypeScript.SymbolFlags.CompilerGenerated;
  20024                            this.iargumentsInterfaceType = argumentsSym.getType();
  20025                        } else {
  20026                            this.iargumentsInterfaceType = this.anyType;
  20027                        }
  20028                    }
  20029                    argLoc.typeLink.type = this.iargumentsInterfaceType;
  20030                    table.add("arguments", theArgSym);
  20031                }
  20032            }
  20033        };
  20034        TypeFlow.prototype.addConstructorLocalArgs = function (container, args, table, isClass) {
  20035            if(args) {
  20036                var len = args.members.length;
  20037                for(var i = 0; i < len; i++) {
  20038                    var local = args.members[i];
  20039                    if((local.sym == null) || (isClass || (local.sym.kind() != TypeScript.SymbolKind.Field))) {
  20040                        var result = null;
  20041                        if((result = table.lookup(local.id.text)) == null) {
  20042                            this.resolveBoundDecl(local);
  20043                            var localVar = new TypeScript.ValueLocation();
  20044                            localVar.typeLink = new TypeScript.TypeLink();
  20045                            var varSym = new TypeScript.ParameterSymbol(local.id.text, local.minChar, this.checker.locationInfo.unitIndex, localVar);
  20046                            varSym.declAST = local;
  20047                            localVar.symbol = varSym;
  20048                            localVar.typeLink.type = local.type;
  20049                            localVar.symbol.container = container;
  20050                            local.sym = localVar.symbol;
  20051                            table.add(local.id.text, varSym);
  20052                        } else {
  20053                            local.type = result.getType();
  20054                            local.sym = result;
  20055                        }
  20056                    }
  20057                }
  20058            }
  20059        };
  20060        TypeFlow.prototype.checkInitSelf = function (funcDecl) {
  20061            if(!funcDecl.isMethod()) {
  20062                var freeVars = funcDecl.freeVariables;
  20063                for(var k = 0, len = freeVars.length; k < len; k++) {
  20064                    var sym = freeVars[k];
  20065                    if(sym.isInstanceProperty()) {
  20066                        return true;
  20067                    }
  20068                }
  20069            }
  20070            var fns = funcDecl.scopes;
  20071            var fnsLen = fns.members.length;
  20072            for(var j = 0; j < fnsLen; j++) {
  20073                var fn = fns.members[j];
  20074                if(this.checkInitSelf(fn)) {
  20075                    return true;
  20076                }
  20077            }
  20078            return false;
  20079        };
  20080        TypeFlow.prototype.checkPromoteFreeVars = function (funcDecl, constructorSym) {
  20081            var freeVars = funcDecl.freeVariables;
  20082            for(var k = 0, len = freeVars.length; k < len; k++) {
  20083                var sym = freeVars[k];
  20084                if((!sym.isInstanceProperty()) && (sym.container == constructorSym)) {
  20085                    TypeScript.instanceFilter.reset();
  20086                    if(this.scope.search(TypeScript.instanceFilter, sym.name, false, false)) {
  20087                        this.checker.errorReporter.simpleError(funcDecl, "Constructor-local variable shadows class property '" + sym.name + "'. To access the class property, use 'self." + sym.name + "'");
  20088                    }
  20089                    this.checker.errorReporter.simpleError(funcDecl, "Constructor-local variables may not be accessed from instance method bodies. Consider changing local variable '" + sym.name + "' to a class property");
  20090                }
  20091            }
  20092        };
  20093        TypeFlow.prototype.allReturnsAreVoid = function (funcDecl) {
  20094            var allReturnsAreVoid = true;
  20095            if(funcDecl.signature.returnType.type == null) {
  20096                var preFindReturnExpressionTypes = function (ast, parent, walker) {
  20097                    var go = true;
  20098                    switch(ast.nodeType) {
  20099                        case TypeScript.NodeType.FuncDecl: {
  20100                            go = false;
  20101                            break;
  20102 
  20103                        }
  20104                        case TypeScript.NodeType.Return: {
  20105                            var returnStmt = ast;
  20106                            if(returnStmt.returnExpression) {
  20107                                allReturnsAreVoid = false;
  20108                                go = false;
  20109                            }
  20110 
  20111                        }
  20112                        default: {
  20113                            break;
  20114 
  20115                        }
  20116                    }
  20117                    walker.options.goChildren = go;
  20118                    walker.options.goNextSibling = go;
  20119                    return ast;
  20120                };
  20121                TypeScript.getAstWalkerFactory().walk(funcDecl.bod, preFindReturnExpressionTypes);
  20122            }
  20123            return allReturnsAreVoid;
  20124        };
  20125        TypeFlow.prototype.classConstructorHasSuperCall = function (funcDecl) {
  20126            var foundSuper = false;
  20127            var preFindSuperCall = function (ast, parent, walker) {
  20128                var go = true;
  20129                switch(ast.nodeType) {
  20130                    case TypeScript.NodeType.FuncDecl: {
  20131                        go = false;
  20132                        break;
  20133 
  20134                    }
  20135                    case TypeScript.NodeType.Call: {
  20136                        var call = ast;
  20137                        if(call.target.nodeType == TypeScript.NodeType.Super) {
  20138                            go = false;
  20139                            foundSuper = true;
  20140                            break;
  20141                        }
  20142                        break;
  20143 
  20144                    }
  20145                    default: {
  20146                        break;
  20147 
  20148                    }
  20149                }
  20150                walker.options.goChildren = go;
  20151                return ast;
  20152            };
  20153            TypeScript.getAstWalkerFactory().walk(funcDecl.bod, preFindSuperCall);
  20154            return foundSuper;
  20155        };
  20156        TypeFlow.prototype.baseListPrivacyErrorReporter = function (bases, i, declSymbol, extendsList, typeName, isModuleName) {
  20157            var baseSymbol = bases.members[i].type.symbol;
  20158            var declTypeString = (declSymbol.declAST.nodeType == TypeScript.NodeType.InterfaceDeclaration) ? "interface" : "class";
  20159            var baseListTypeString = extendsList ? "extends" : "implements";
  20160            var baseTypeString = (baseSymbol.declAST.nodeType == TypeScript.NodeType.InterfaceDeclaration) ? "interface" : "class";
  20161            var typestring = "";
  20162            if(isModuleName) {
  20163                var quotestring = "";
  20164                if(!TypeScript.isQuoted(typeName)) {
  20165                    quotestring = "'";
  20166                }
  20167                typestring = " is using inaccessible module ";
  20168                baseTypeString = " " + baseTypeString + " from private module " + quotestring + typeName + quotestring;
  20169            } else {
  20170                baseTypeString = " private " + baseTypeString + " '" + typeName + "'";
  20171            }
  20172            this.checker.errorReporter.simpleError(bases.members[i], "exported " + declTypeString + " '" + declSymbol.name + "' " + baseListTypeString + baseTypeString);
  20173        };
  20174        TypeFlow.prototype.typeCheckBaseListPrivacy = function (bases, declSymbol, extendsList) {
  20175            var _this = this;
  20176            if(bases) {
  20177                var basesLen = bases.members.length;
  20178                for(var i = 0; i < basesLen; i++) {
  20179                    if(!bases.members[i].type || bases.members[i].type == this.checker.anyType) {
  20180                        continue;
  20181                    }
  20182                    this.checkSymbolPrivacy(bases.members[i].type.symbol, declSymbol, function (typeName, isModuleName) {
  20183                        return _this.baseListPrivacyErrorReporter(bases, i, declSymbol, extendsList, typeName, isModuleName);
  20184                    });
  20185                }
  20186            }
  20187        };
  20188        TypeFlow.prototype.checkSymbolPrivacy = function (typeSymbol, declSymbol, errorCallback) {
  20189            var externalModuleSymbol = null;
  20190            var declSymbolPath = null;
  20191            if(typeSymbol.isExternallyVisible(this.checker)) {
  20192                var typeSymbolPath = typeSymbol.pathToRoot();
  20193                declSymbolPath = declSymbol.pathToRoot();
  20194                var typeSymbolLength = typeSymbolPath.length;
  20195                var declSymbolPathLength = declSymbolPath.length;
  20196                if(typeSymbolLength > 0) {
  20197                    if(typeSymbolPath[typeSymbolLength - 1].getType().isModuleType() && (typeSymbolPath[typeSymbolLength - 1]).isDynamic && typeSymbolPath[typeSymbolLength - 1] != declSymbolPath[declSymbolPathLength - 1]) {
  20198                        externalModuleSymbol = typeSymbolPath[typeSymbolLength - 1];
  20199                    } else {
  20200                        if(typeSymbolLength > 1) {
  20201                            if(typeSymbolPath[typeSymbolLength - 2].getType().isModuleType() && (typeSymbolPath[typeSymbolLength - 2]).isDynamic && (declSymbolPathLength == 1 || typeSymbolPath[typeSymbolLength - 2] != declSymbolPath[declSymbolPathLength - 2])) {
  20202                                externalModuleSymbol = typeSymbolPath[typeSymbolLength - 2];
  20203                            }
  20204                        }
  20205                    }
  20206                }
  20207                if(externalModuleSymbol == null) {
  20208                    return;
  20209                }
  20210            }
  20211            var interfaceDecl = declSymbol.getInterfaceDeclFromSymbol(this.checker);
  20212            if(interfaceDecl && !TypeScript.hasFlag(interfaceDecl.varFlags, TypeScript.VarFlags.Exported)) {
  20213                return;
  20214            }
  20215            var checkVisibilitySymbol = declSymbol;
  20216            var varDecl = declSymbol.getVarDeclFromSymbol();
  20217            if(varDecl) {
  20218                if(TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.Private)) {
  20219                    return;
  20220                } else {
  20221                    if(TypeScript.hasFlag(varDecl.varFlags, TypeScript.VarFlags.Public)) {
  20222                        checkVisibilitySymbol = declSymbol.container;
  20223                    }
  20224                }
  20225            }
  20226            if(checkVisibilitySymbol.isExternallyVisible(this.checker)) {
  20227                var privateSymbolName = typeSymbol.name;
  20228                if(externalModuleSymbol != null) {
  20229                    var prettyName = externalModuleSymbol.getPrettyNameOfDynamicModule(declSymbolPath);
  20230                    if(prettyName != null) {
  20231                        this.currentScript.AddExternallyVisibleImportedSymbol(prettyName.symbol, this.checker);
  20232                        return;
  20233                    } else {
  20234                        privateSymbolName = externalModuleSymbol.prettyName;
  20235                    }
  20236                }
  20237                errorCallback(privateSymbolName, typeSymbol.name != privateSymbolName);
  20238            }
  20239        };
  20240        TypeFlow.prototype.checkTypePrivacy = function (type, declSymbol, errorCallback) {
  20241            var _this = this;
  20242            if(!(type && type.primitiveTypeClass == TypeScript.Primitive.None)) {
  20243                return;
  20244            }
  20245            if(type.isArray()) {
  20246                return this.checkTypePrivacy(type.elementType, declSymbol, errorCallback);
  20247            }
  20248            if(type.symbol && type.symbol.name && type.symbol.name != "_anonymous" && (((type.call == null) && (type.construct == null) && (type.index == null)) || (type.members && (!type.isClass())))) {
  20249                return this.checkSymbolPrivacy(type.symbol, declSymbol, errorCallback);
  20250            }
  20251            if(type.members) {
  20252                type.members.allMembers.map(function (key, s, unused) {
  20253                    var sym = s;
  20254                    if(!TypeScript.hasFlag(sym.flags, TypeScript.SymbolFlags.BuiltIn)) {
  20255                        _this.checkTypePrivacy(sym.getType(), declSymbol, errorCallback);
  20256                    }
  20257                }, null);
  20258            }
  20259            this.checkSignatureGroupPrivacy(type.call, declSymbol, errorCallback);
  20260            this.checkSignatureGroupPrivacy(type.construct, declSymbol, errorCallback);
  20261            this.checkSignatureGroupPrivacy(type.index, declSymbol, errorCallback);
  20262        };
  20263        TypeFlow.prototype.checkSignatureGroupPrivacy = function (sgroup, declSymbol, errorCallback) {
  20264            if(sgroup) {
  20265                var len = sgroup.signatures.length;
  20266                for(var i = 0; i < sgroup.signatures.length; i++) {
  20267                    var signature = sgroup.signatures[i];
  20268                    if(len > 1 && signature == sgroup.definitionSignature) {
  20269                        continue;
  20270                    }
  20271                    if(signature.returnType) {
  20272                        this.checkTypePrivacy(signature.returnType.type, declSymbol, errorCallback);
  20273                    }
  20274                    var paramLen = signature.parameters.length;
  20275                    for(var j = 0; j < paramLen; j++) {
  20276                        var param = signature.parameters[j];
  20277                        this.checkTypePrivacy(param.getType(), declSymbol, errorCallback);
  20278                    }
  20279                }
  20280            }
  20281        };
  20282        TypeFlow.prototype.functionArgumentPrivacyErrorReporter = function (funcDecl, p, paramSymbol, typeName, isModuleName) {
  20283            var isGetter = funcDecl.isAccessor() && TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.GetAccessor);
  20284            var isSetter = funcDecl.isAccessor() && TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.SetAccessor);
  20285            var isPublicFunc = TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Public);
  20286            var isContainerInterface = funcDecl.type.symbol.getInterfaceDeclFromSymbol(this.checker) != null;
  20287            var typestring = "";
  20288            if(isModuleName) {
  20289                var quotestring = "";
  20290                if(!TypeScript.isQuoted(typeName)) {
  20291                    quotestring = "'";
  20292                }
  20293                typestring = " is using inaccessible module " + quotestring + typeName + quotestring;
  20294            } else {
  20295                typestring = " has or is using private type '" + typeName + "'";
  20296            }
  20297            if(!isContainerInterface) {
  20298                if(funcDecl.isConstructor) {
  20299                    this.checker.errorReporter.simpleError(funcDecl.arguments.members[p], "exported class's constructor parameter '" + paramSymbol.name + "'" + typestring);
  20300                } else {
  20301                    if(isSetter) {
  20302                        this.checker.errorReporter.simpleError(funcDecl.arguments.members[p], (isPublicFunc ? "public" : "exported") + " setter parameter '" + paramSymbol.name + "'" + typestring);
  20303                    } else {
  20304                        if(!isGetter) {
  20305                            this.checker.errorReporter.simpleError(funcDecl.arguments.members[p], (isPublicFunc ? "public" : "exported") + " function parameter '" + paramSymbol.name + "'" + typestring);
  20306                        }
  20307                    }
  20308                }
  20309            } else {
  20310                if(funcDecl.isConstructMember()) {
  20311                    this.checker.errorReporter.simpleError(funcDecl.arguments.members[p], "exported interface's constructor parameter '" + paramSymbol.name + "'" + typestring);
  20312                } else {
  20313                    if(funcDecl.isCallMember()) {
  20314                        this.checker.errorReporter.simpleError(funcDecl.arguments.members[p], "exported interface's call parameter '" + paramSymbol.name + "'" + typestring);
  20315                    } else {
  20316                        if(!funcDecl.isIndexerMember()) {
  20317                            this.checker.errorReporter.simpleError(funcDecl.arguments.members[p], "exported interface's function parameter '" + paramSymbol.name + "'" + typestring);
  20318                        }
  20319                    }
  20320                }
  20321            }
  20322        };
  20323        TypeFlow.prototype.returnTypePrivacyError = function (astError, funcDecl, typeName, isModuleName) {
  20324            var isGetter = funcDecl.isAccessor() && TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.GetAccessor);
  20325            var isSetter = funcDecl.isAccessor() && TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.SetAccessor);
  20326            var isPublicFunc = TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Public);
  20327            var isContainerInterface = funcDecl.type.symbol.getInterfaceDeclFromSymbol(this.checker) != null;
  20328            var typestring = "";
  20329            if(isModuleName) {
  20330                var quotestring = "";
  20331                if(!TypeScript.isQuoted(typeName)) {
  20332                    quotestring = "'";
  20333                }
  20334                typestring = " is using inaccessible module " + quotestring + typeName + quotestring;
  20335            } else {
  20336                typestring = " has or is using private type '" + typeName + "'";
  20337            }
  20338            if(!isContainerInterface) {
  20339                if(isGetter) {
  20340                    this.checker.errorReporter.simpleError(astError, (isPublicFunc ? "public" : "exported") + " getter return type" + typestring);
  20341                } else {
  20342                    if(!isSetter) {
  20343                        this.checker.errorReporter.simpleError(astError, (isPublicFunc ? "public" : "exported") + " function return type" + typestring);
  20344                    }
  20345                }
  20346            } else {
  20347                if(funcDecl.isConstructMember()) {
  20348                    this.checker.errorReporter.simpleError(astError, "exported interface's constructor return type" + typestring);
  20349                } else {
  20350                    if(funcDecl.isCallMember()) {
  20351                        this.checker.errorReporter.simpleError(astError, "exported interface's call return type" + typestring);
  20352                    } else {
  20353                        if(funcDecl.isIndexerMember()) {
  20354                            this.checker.errorReporter.simpleError(astError, "exported interface's indexer return type" + typestring);
  20355                        } else {
  20356                            this.checker.errorReporter.simpleError(astError, "exported interface's function return type" + typestring);
  20357                        }
  20358                    }
  20359                }
  20360            }
  20361        };
  20362        TypeFlow.prototype.functionReturnTypePrivacyErrorReporter = function (funcDecl, signature, typeName, isModuleName) {
  20363            var reportOnFuncDecl = false;
  20364            if(funcDecl.returnTypeAnnotation != null && funcDecl.returnTypeAnnotation.type == signature.returnType.type) {
  20365                this.returnTypePrivacyError(funcDecl.returnTypeAnnotation, funcDecl, typeName, isModuleName);
  20366            }
  20367            for(var i = 0; i < funcDecl.returnStatementsWithExpressions.length; i++) {
  20368                if(funcDecl.returnStatementsWithExpressions[i].type == signature.returnType.type) {
  20369                    this.returnTypePrivacyError(funcDecl.returnStatementsWithExpressions[i], funcDecl, typeName, isModuleName);
  20370                } else {
  20371                    reportOnFuncDecl = true;
  20372                }
  20373            }
  20374            if(reportOnFuncDecl) {
  20375                this.returnTypePrivacyError(funcDecl, funcDecl, typeName, isModuleName);
  20376            }
  20377        };
  20378        TypeFlow.prototype.typeCheckFunction = function (funcDecl) {
  20379            var _this = this;
  20380            this.nestingLevel = 0;
  20381            var fnType = funcDecl.type;
  20382            var fgSym = fnType.symbol;
  20383            var signature = funcDecl.signature;
  20384            if(this.checker.typeStatusIsFinished(signature.typeCheckStatus)) {
  20385                return funcDecl;
  20386            } else {
  20387                if(signature.typeCheckStatus == TypeScript.TypeCheckStatus.Started) {
  20388                    if(!funcDecl.returnTypeAnnotation && funcDecl.bod && !funcDecl.isSignature() && !(funcDecl.isConstructor) && this.allReturnsAreVoid(funcDecl)) {
  20389                        signature.returnType.type = this.voidType;
  20390                        return funcDecl;
  20391                    } else {
  20392                        if(funcDecl.returnTypeAnnotation == null) {
  20393                            if(this.checker.styleSettings.implicitAny) {
  20394                                this.checker.errorReporter.styleError(funcDecl, "type implicitly set to 'any'");
  20395                            }
  20396                            signature.returnType.type = this.anyType;
  20397                            fgSym.flags |= TypeScript.SymbolFlags.RecursivelyReferenced;
  20398                        }
  20399                        return funcDecl;
  20400                    }
  20401                }
  20402            }
  20403            signature.typeCheckStatus = TypeScript.TypeCheckStatus.Started;
  20404            this.checker.addStartedPTO(signature);
  20405            var prevScope = this.scope;
  20406            var prevFnc = this.thisFnc;
  20407            var prevMethodStatus = this.enclosingFncIsMethod;
  20408            var prevClassNode = this.thisClassNode;
  20409            this.enclosingFncIsMethod = funcDecl.isMethod() || funcDecl.isConstructor;
  20410            this.thisFnc = funcDecl;
  20411            var container = funcDecl.type.symbol;
  20412            var prevThisType = this.thisType;
  20413            var prevLocationInfo = this.checker.locationInfo;
  20414            var funcTable = null;
  20415            var acceptedContextualType = false;
  20416            var targetParams = null;
  20417            var targetReturnType = null;
  20418            var isGetter = funcDecl.isAccessor() && TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.GetAccessor);
  20419            var isSetter = funcDecl.isAccessor() && TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.SetAccessor);
  20420            var accessorType = (isGetter || isSetter) && funcDecl.accessorSymbol ? funcDecl.accessorSymbol.getType() : null;
  20421            var prevModDecl = this.checker.currentModDecl;
  20422            if(funcDecl.isConstructor && !funcDecl.isOverload) {
  20423                if(fnType.instanceType == null) {
  20424                    this.checker.errorReporter.simpleError(funcDecl, "Malformed function body (is this a class named the same as an existing interface?)");
  20425                    return funcDecl;
  20426                }
  20427                this.scope = fnType.instanceType.constructorScope;
  20428                var ssb = this.scope;
  20429                funcTable = ssb.valueMembers.allMembers;
  20430            } else {
  20431                if((funcDecl.isSpecialFn() && !(funcDecl.fncFlags & TypeScript.FncFlags.Signature)) || funcDecl.isOverload) {
  20432                    funcTable = funcDecl.symbols;
  20433                    if(!TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Static) && fnType.containedScope) {
  20434                        this.scope = fnType.containedScope;
  20435                    }
  20436                } else {
  20437                    if(funcDecl.bod) {
  20438                        this.scope = fnType.containedScope;
  20439                    }
  20440                    var ssb = this.scope;
  20441                    if(ssb && ssb.valueMembers) {
  20442                        funcTable = ssb.valueMembers.allMembers;
  20443                    }
  20444                }
  20445            }
  20446            if(funcDecl.isConstructor && funcDecl.bod && TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.ClassMethod)) {
  20447                var hasBaseType = TypeScript.hasFlag(funcDecl.classDecl.type.instanceType.typeFlags, TypeScript.TypeFlags.HasBaseType);
  20448                var noSuperCallAllowed = !hasBaseType || TypeScript.hasFlag(funcDecl.classDecl.type.instanceType.typeFlags, TypeScript.TypeFlags.HasBaseTypeOfObject);
  20449                var superCallMustBeFirst = TypeScript.hasFlag((funcDecl.classDecl).varFlags, TypeScript.VarFlags.ClassSuperMustBeFirstCallInConstructor);
  20450                if(noSuperCallAllowed && this.classConstructorHasSuperCall(funcDecl)) {
  20451                    this.checker.errorReporter.simpleError(funcDecl, "Calls to 'super' constructor are not allowed in classes that either inherit directly from 'Object' or have no base class");
  20452                } else {
  20453                    if(hasBaseType) {
  20454                        if(superCallMustBeFirst) {
  20455                            if(!funcDecl.bod || !funcDecl.bod.members.length || !((funcDecl.bod.members[0].nodeType == TypeScript.NodeType.Call && (funcDecl.bod.members[0]).target.nodeType == TypeScript.NodeType.Super) || (TypeScript.hasFlag(funcDecl.bod.flags, TypeScript.ASTFlags.StrictMode) && funcDecl.bod.members.length > 1 && funcDecl.bod.members[1].nodeType == TypeScript.NodeType.Call && (funcDecl.bod.members[1]).target.nodeType == TypeScript.NodeType.Super))) {
  20456                                this.checker.errorReporter.simpleError(funcDecl, "If a derived class contains initialized properties or constructor parameter properties, the first statement in the constructor body must be a call to the super constructor");
  20457                            }
  20458                        } else {
  20459                            if(!this.classConstructorHasSuperCall(funcDecl)) {
  20460                                this.checker.errorReporter.simpleError(funcDecl, "Constructors for derived classes must contain a call to the class's 'super' constructor");
  20461                            }
  20462                        }
  20463                    }
  20464                }
  20465            }
  20466            if(funcDecl.isMethod() && funcDecl.type.enclosingType) {
  20467                var enclosingClassNode = null;
  20468                if(funcDecl.type.enclosingType.symbol.declAST.nodeType == TypeScript.NodeType.FuncDecl) {
  20469                    enclosingClassNode = (funcDecl.type.enclosingType.symbol.declAST).classDecl;
  20470                } else {
  20471                    if(funcDecl.type.enclosingType.symbol.declAST.nodeType == TypeScript.NodeType.ClassDeclaration) {
  20472                        enclosingClassNode = funcDecl.type.enclosingType.symbol.declAST;
  20473                    }
  20474                }
  20475                if(enclosingClassNode) {
  20476                    this.thisClassNode = enclosingClassNode;
  20477                }
  20478            }
  20479            if(fnType.enclosingType) {
  20480                ; ;
  20481                var enclosingSym = fnType.symbol.container;
  20482                if(enclosingSym && enclosingSym.isType() && enclosingSym.getType().isClass()) {
  20483                    enclosingSym = enclosingSym.container;
  20484                }
  20485                if(enclosingSym && enclosingSym.declAST && enclosingSym.declAST.nodeType == TypeScript.NodeType.ModuleDeclaration) {
  20486                    this.checker.currentModDecl = enclosingSym.declAST;
  20487                }
  20488            }
  20489            if(funcDecl.unitIndex > 0) {
  20490                if(this.checker.units && (funcDecl.unitIndex < this.checker.units.length)) {
  20491                    this.checker.locationInfo = this.checker.units[funcDecl.unitIndex];
  20492                } else {
  20493                    this.checker.locationInfo = TypeScript.unknownLocationInfo;
  20494                }
  20495            }
  20496            if(fnType.enclosingType) {
  20497                this.thisType = fnType.enclosingType;
  20498            } else {
  20499                this.thisType = prevThisType;
  20500            }
  20501            var paramLen = signature.parameters.length;
  20502            if(!funcDecl.isConstructor && funcDecl.bod && !funcDecl.isSignature()) {
  20503                var tmpParamScope = this.scope;
  20504                var ssb = this.scope;
  20505                if(!funcDecl.isMethod() && funcDecl.returnTypeAnnotation == null) {
  20506                    if(prevScope && funcDecl.name && !funcDecl.name.isMissing()) {
  20507                        var considerSym = prevScope.findAmbient(funcDecl.name.text, false, false);
  20508                        if(considerSym && considerSym.declAST && considerSym.declAST.type) {
  20509                            this.checker.setContextualType(considerSym.declAST.type, false);
  20510                        }
  20511                    }
  20512                    if(this.checker.hasTargetType()) {
  20513                        var candidateTypeContext = this.checker.getTargetTypeContext();
  20514                        var candidateType = candidateTypeContext.contextualType;
  20515                        if(this.checker.canContextuallyTypeFunction(candidateType, funcDecl, true)) {
  20516                            var candidateSigs = candidateType.construct ? candidateType.construct : candidateType.call;
  20517                            candidateTypeContext.targetSig = candidateSigs.signatures[0];
  20518                            var candidateParams = candidateTypeContext.targetSig.parameters;
  20519                            targetParams = candidateParams;
  20520                            targetReturnType = candidateTypeContext.targetSig.returnType.type;
  20521                            if(candidateTypeContext.targetSig.declAST) {
  20522                                if(candidateTypeContext.targetSig.declAST.isConstructor) {
  20523                                    funcDecl.isTargetTypedAsMethod = true;
  20524                                } else {
  20525                                    if(candidateTypeContext.targetSig.declAST.isMethod()) {
  20526                                        funcDecl.isTargetTypedAsMethod = true;
  20527                                    }
  20528                                }
  20529                            }
  20530                            fgSym.type = candidateTypeContext.contextualType;
  20531                            acceptedContextualType = true;
  20532                        } else {
  20533                            if(candidateType && funcDecl.isAccessor()) {
  20534                                accessorType = candidateType;
  20535                                candidateTypeContext.targetAccessorType = accessorType;
  20536                            } else {
  20537                                this.checker.killCurrentContextualType();
  20538                            }
  20539                        }
  20540                    }
  20541                }
  20542                var paramTable = ssb.valueMembers;
  20543                this.scope = new TypeScript.SymbolScopeBuilder(paramTable, null, null, null, prevScope, container);
  20544                for(var p = 0; p < paramLen; p++) {
  20545                    var symbol = signature.parameters[p];
  20546                    var ast = symbol.declAST;
  20547                    if(this.checker.hasTargetType() && (targetParams && (this.checker.getTargetTypeContext().targetSig.hasVariableArgList || p < targetParams.length))) {
  20548                        var candidateTypeContext = this.checker.getTargetTypeContext();
  20549                        var hasVarArgList = candidateTypeContext.targetSig.hasVariableArgList;
  20550                        ast.type = hasVarArgList && p >= targetParams.length - 1 ? targetParams[targetParams.length - 1].getType().elementType : targetParams[p].getType();
  20551                        ast.sym.setType(ast.type);
  20552                        (ast.sym).typeCheckStatus = this.checker.getTypeCheckFinishedStatus();
  20553                    } else {
  20554                        this.typeCheck(ast);
  20555                    }
  20556                    if(isSetter && accessorType) {
  20557                        ast = this.cast(ast, accessorType);
  20558                    }
  20559                    symbol.container = container;
  20560                    this.checkTypePrivacy(symbol.getType(), container, function (typeName, isModuleName) {
  20561                        return _this.functionArgumentPrivacyErrorReporter(funcDecl, p, symbol, typeName, isModuleName);
  20562                    });
  20563                    paramTable.publicMembers.add(symbol.name, symbol);
  20564                }
  20565                this.scope = tmpParamScope;
  20566            } else {
  20567                this.typeCheck(funcDecl.arguments);
  20568                for(var p = 0; p < paramLen; p++) {
  20569                    signature.parameters[p].parameter.typeLink.type = funcDecl.arguments.members[p].type;
  20570                    this.checkTypePrivacy(signature.parameters[p].getType(), container, function (typeName, isModuleName) {
  20571                        return _this.functionArgumentPrivacyErrorReporter(funcDecl, p, signature.parameters[p], typeName, isModuleName);
  20572                    });
  20573                    if((funcDecl.arguments.members[p]).parameterPropertySym) {
  20574                        (funcDecl.arguments.members[p]).parameterPropertySym.setType(funcDecl.arguments.members[p].type);
  20575                    }
  20576                }
  20577                if((funcDecl.fncFlags & TypeScript.FncFlags.IndexerMember)) {
  20578                    if(!paramLen || paramLen > 1) {
  20579                        this.checker.errorReporter.simpleError(funcDecl, "Index signatures may take one and only one parameter");
  20580                    } else {
  20581                        if(funcDecl.arguments.members[0].type == this.checker.numberType) {
  20582                            fnType.index.flags |= TypeScript.SignatureFlags.IsNumberIndexer;
  20583                        } else {
  20584                            if(funcDecl.arguments.members[0].type == this.checker.stringType) {
  20585                                fnType.index.flags |= TypeScript.SignatureFlags.IsStringIndexer;
  20586                            } else {
  20587                                this.checker.errorReporter.simpleError(funcDecl.arguments.members[0], "Index signatures may only take 'string' or 'number' as their parameter");
  20588                            }
  20589                        }
  20590                    }
  20591                }
  20592            }
  20593            if(funcDecl.bod && (!funcDecl.isSignature())) {
  20594                if(!(funcDecl.isConstructor)) {
  20595                    this.addFormals(container, signature, funcTable);
  20596                } else {
  20597                    this.addConstructorLocalArgs(funcDecl.type.symbol, funcDecl.arguments, funcTable, TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.ClassMethod));
  20598                    if(this.thisClassNode && this.thisClassNode.extendsList) {
  20599                        var tmpScope = this.scope;
  20600                        var funcMembers = new TypeScript.ScopedMembers(funcTable);
  20601                        this.scope = new TypeScript.FilteredSymbolScopeBuilder(funcMembers, prevScope, funcDecl.type.symbol, function (sym) {
  20602                            return sym.kind() == TypeScript.SymbolKind.Parameter;
  20603                        });
  20604                        this.typeCheckBaseCalls(this.thisClassNode.extendsList);
  20605                        this.scope = tmpScope;
  20606                    }
  20607                }
  20608                var prevMod = this.checker.currentModDecl;
  20609                if(funcDecl.type && funcDecl.type.symbol && !funcDecl.isMethod() && funcDecl.type.symbol.declModule) {
  20610                    this.checker.currentModDecl = funcDecl.type.symbol.declModule;
  20611                }
  20612                if(acceptedContextualType) {
  20613                    this.checker.setContextualType(null, this.checker.inProvisionalTypecheckMode());
  20614                }
  20615                this.typeCheck(funcDecl.bod);
  20616                if(acceptedContextualType) {
  20617                    this.checker.unsetContextualType();
  20618                }
  20619                this.checker.currentModDecl = prevMod;
  20620                if(this.checker.checkControlFlow) {
  20621                    var cfg = funcDecl.buildControlFlow();
  20622                    if(this.checker.printControlFlowGraph) {
  20623                        cfg.print(this.checker.errorReporter.outfile);
  20624                    }
  20625                    cfg.reportUnreachable(this.checker.errorReporter);
  20626                    if(this.checker.checkControlFlowUseDef) {
  20627                        cfg.useDef(this.checker.errorReporter, funcDecl.type.symbol);
  20628                    }
  20629                }
  20630                if(funcDecl.isConstructor) {
  20631                    var fns = funcDecl.scopes;
  20632                    var fnsLen = fns.members.length;
  20633                    var freeVars;
  20634                    var sym;
  20635                    var j = 0;
  20636                    for(; j < fnsLen; j++) {
  20637                        var fn = fns.members[j];
  20638                        if(!fn.isSignature()) {
  20639                            if(TypeScript.hasFlag(fn.fncFlags, TypeScript.FncFlags.Method) && (!TypeScript.hasFlag(fn.fncFlags, TypeScript.FncFlags.Static))) {
  20640                                this.checkPromoteFreeVars(fn, funcDecl.type.symbol);
  20641                            }
  20642                        }
  20643                    }
  20644                }
  20645            }
  20646            this.scope = prevScope;
  20647            this.thisFnc = prevFnc;
  20648            this.thisClassNode = prevClassNode;
  20649            this.enclosingFncIsMethod = prevMethodStatus;
  20650            this.thisType = prevThisType;
  20651            this.checker.locationInfo = prevLocationInfo;
  20652            this.checker.currentModDecl = prevModDecl;
  20653            signature.typeCheckStatus = this.checker.getTypeCheckFinishedStatus();
  20654            if(funcDecl.returnTypeAnnotation) {
  20655                this.checkForVoidConstructor(funcDecl.returnTypeAnnotation.type, funcDecl.returnTypeAnnotation);
  20656                if(signature.returnType.type == null) {
  20657                    this.checker.resolveTypeLink(this.scope, signature.returnType, false);
  20658                }
  20659            } else {
  20660                if(targetReturnType) {
  20661                    signature.returnType.type = targetReturnType;
  20662                }
  20663            }
  20664            if(!(fgSym.flags & TypeScript.SymbolFlags.RecursivelyReferenced) && funcDecl.returnStatementsWithExpressions.length > 0) {
  20665                var collection = {
  20666                    getLength: function () {
  20667                        return funcDecl.returnStatementsWithExpressions.length;
  20668                    },
  20669                    setTypeAtIndex: function (index, type) {
  20670                        funcDecl.returnStatementsWithExpressions[index].type = type;
  20671                    },
  20672                    getTypeAtIndex: function (index) {
  20673                        return funcDecl.returnStatementsWithExpressions[index].type;
  20674                    }
  20675                };
  20676                var bestCommonReturnType = funcDecl.returnStatementsWithExpressions[0].type;
  20677                bestCommonReturnType = this.checker.findBestCommonType(bestCommonReturnType, null, collection, true);
  20678                if(bestCommonReturnType) {
  20679                    signature.returnType.type = this.checker.widenType(bestCommonReturnType);
  20680                } else {
  20681                    for(var i = 0; i < funcDecl.returnStatementsWithExpressions.length; i++) {
  20682                        this.checker.errorReporter.simpleError(funcDecl.returnStatementsWithExpressions[i], "Incompatible return type");
  20683                    }
  20684                    signature.returnType.type = this.anyType;
  20685                }
  20686            }
  20687            var onlyHasThrow = false;
  20688            if(signature.returnType.type == null) {
  20689                if(TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.HasReturnExpression)) {
  20690                    if(this.checker.styleSettings.implicitAny) {
  20691                        this.checker.errorReporter.styleError(funcDecl, "type implicitly set to 'any'");
  20692                    }
  20693                    signature.returnType.type = this.anyType;
  20694                } else {
  20695                    signature.returnType.type = this.voidType;
  20696                }
  20697            } else {
  20698                if(signature.returnType.type == this.nullType || signature.returnType.type == this.checker.undefinedType) {
  20699                    signature.returnType.type = this.anyType;
  20700                } else {
  20701                    if((signature.returnType.type != this.voidType && signature.returnType.type != this.checker.undefinedType && signature.returnType.type != this.anyType)) {
  20702                        if(!funcDecl.isSignature() && !funcDecl.isConstructor && !TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.HasReturnExpression) && !TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.IsFatArrowFunction)) {
  20703                            onlyHasThrow = (funcDecl.bod.members.length > 0) && (funcDecl.bod.members[0].nodeType == TypeScript.NodeType.Throw);
  20704                            if(!onlyHasThrow) {
  20705                                this.checker.errorReporter.simpleError(funcDecl.returnTypeAnnotation || funcDecl, "Function declared a non-void return type, but has no return expression");
  20706                            }
  20707                        }
  20708                        this.checkTypePrivacy(signature.returnType.type, container, function (typeName, isModuleName) {
  20709                            return _this.functionReturnTypePrivacyErrorReporter(funcDecl, signature, typeName, isModuleName);
  20710                        });
  20711                    }
  20712                }
  20713            }
  20714            if(funcDecl.accessorSymbol) {
  20715                var accessorType = funcDecl.accessorSymbol.getType();
  20716                if(!onlyHasThrow && TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.GetAccessor) && !TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.HasReturnExpression)) {
  20717                    this.checker.errorReporter.simpleError(funcDecl, "Getters must return a value");
  20718                }
  20719                if(accessorType) {
  20720                    if((TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.GetAccessor) && accessorType != signature.returnType.type) || (funcDecl.arguments.members.length > 0 && accessorType != funcDecl.arguments.members[0].type)) {
  20721                        this.checker.errorReporter.simpleError(funcDecl, "Getter and setter types do not agree");
  20722                    }
  20723                } else {
  20724                    if(TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.GetAccessor)) {
  20725                        funcDecl.accessorSymbol.setType(signature.returnType.type);
  20726                    } else {
  20727                        if(funcDecl.arguments.members.length != 1) {
  20728                            this.checker.errorReporter.simpleError(funcDecl, "Setters may have one and only one argument");
  20729                        } else {
  20730                            funcDecl.accessorSymbol.setType(funcDecl.arguments.members[0].type);
  20731                        }
  20732                    }
  20733                }
  20734            }
  20735            this.typeCheckOverloadSignatures(fnType, funcDecl);
  20736            return funcDecl;
  20737        };
  20738        TypeFlow.prototype.typeCheckBases = function (type) {
  20739            var seenInterface = false;
  20740            var bases = type.extendsList;
  20741            var baseLinks = type.extendsTypeLinks;
  20742            if(bases) {
  20743                var len = bases.length;
  20744                if(len > 0) {
  20745                    type.typeFlags |= TypeScript.TypeFlags.HasBaseType;
  20746                }
  20747                for(var i = 0; i < len; i++) {
  20748                    if(bases[i] == this.checker.anyType) {
  20749                        baseLinks[i].type = null;
  20750                        var oldErrors = this.checker.errorReporter.getCapturedErrors();
  20751                        TypeScript.CompilerDiagnostics.assert(oldErrors.length == 0, "There shouldnt be any contextual errors when typechecking base type names");
  20752                        this.checker.errorReporter.pushToErrorSink = true;
  20753                        bases[i] = this.checker.resolveBaseTypeLink(baseLinks[i], type.containedScope);
  20754                        this.checker.errorReporter.pushToErrorSink = false;
  20755                        this.checker.errorReporter.freeCapturedErrors();
  20756                    }
  20757                    var base = bases[i];
  20758                    var baseRef = baseLinks[i].ast;
  20759                    var baseTypeOfObject = base.symbol && base.symbol.name == "Object" && base.symbol.container == this.checker.gloMod;
  20760                    if(baseTypeOfObject) {
  20761                        type.typeFlags |= TypeScript.TypeFlags.HasBaseTypeOfObject;
  20762                    }
  20763                    if(base.isClassInstance()) {
  20764                        if(!(type.isClassInstance())) {
  20765                            this.checker.errorReporter.simpleError(baseRef, "Interface base type must be interface");
  20766                        } else {
  20767                            if(seenInterface) {
  20768                                this.checker.errorReporter.simpleError(baseRef, "Class may not follow interface as base type");
  20769                            }
  20770                        }
  20771                    } else {
  20772                        if(base.isModuleType()) {
  20773                            this.checker.errorReporter.simpleError(baseRef, "Types may not be derived from module types");
  20774                        } else {
  20775                            if(base.members) {
  20776                                if(!seenInterface) {
  20777                                    seenInterface = true;
  20778                                }
  20779                            } else {
  20780                                if(!(type.isClassInstance())) {
  20781                                    this.checker.errorReporter.simpleError(baseRef, "Interface base type must be interface");
  20782                                } else {
  20783                                    this.checker.errorReporter.simpleError(baseRef, "Base type must be interface or class");
  20784                                }
  20785                                break;
  20786                            }
  20787                        }
  20788                    }
  20789                }
  20790            }
  20791        };
  20792        TypeFlow.prototype.checkMembersImplementInterfaces = function (implementingType) {
  20793            var instanceType = implementingType.getInstanceType();
  20794            if(instanceType.implementsList) {
  20795                var len = instanceType.implementsList.length;
  20796                for(var i = 0; i < len; i++) {
  20797                    var interfaceType = instanceType.implementsList[i];
  20798                    var comparisonInfo = new TypeScript.TypeComparisonInfo();
  20799                    if(!this.checker.sourceIsSubtypeOfTarget(instanceType, interfaceType, comparisonInfo)) {
  20800                        var emsg = "Class '" + instanceType.getTypeName() + "' declares interface '" + interfaceType.getTypeName() + "' but does not implement it";
  20801                        if(!comparisonInfo.message) {
  20802                            this.checker.errorReporter.simpleErrorFromSym(instanceType.symbol, emsg);
  20803                        } else {
  20804                            this.checker.errorReporter.simpleErrorFromSym(instanceType.symbol, emsg + ": " + comparisonInfo.message);
  20805                        }
  20806                    }
  20807                }
  20808            }
  20809        };
  20810        TypeFlow.prototype.typeCheckBaseCalls = function (bases) {
  20811            if(bases == null) {
  20812                return;
  20813            }
  20814            var basesLen = bases.members.length;
  20815            for(var i = 0; i < basesLen; i++) {
  20816                var baseExpr = bases.members[i];
  20817                var baseSymbol = null;
  20818                if(baseExpr.nodeType == TypeScript.NodeType.Call) {
  20819                    this.typeCheckNew(baseExpr);
  20820                }
  20821            }
  20822        };
  20823        TypeFlow.prototype.assertUniqueNamesInBaseTypes = function (names, type, classDecl, checkUnique) {
  20824            var _this = this;
  20825            if(type) {
  20826                if(type.members) {
  20827                    type.members.publicMembers.map(function (key, s, c) {
  20828                        var sym = s;
  20829                        var dup = names.lookup(sym.name);
  20830                        if(dup) {
  20831                            if(checkUnique) {
  20832                                _this.checker.errorReporter.simpleError(classDecl, "duplicate member name in bases for " + classDecl.name.actualText + ": " + type.symbol.name + " and " + dup.container.name + " both contain member with name " + sym.name);
  20833                            }
  20834                        } else {
  20835                            names.add(sym.name, sym);
  20836                        }
  20837                    }, null);
  20838                }
  20839                if(type.extendsList) {
  20840                    var len = type.extendsList.length;
  20841                    for(var i = 0; i < len; i++) {
  20842                        if(!(type.extendsList[i].symbol.flags & TypeScript.SymbolFlags.RecursivelyReferenced)) {
  20843                            this.assertUniqueNamesInBaseTypes(names, type.extendsList[i], classDecl, checkUnique);
  20844                        }
  20845                    }
  20846                }
  20847            }
  20848        };
  20849        TypeFlow.prototype.checkBaseTypeMemberInheritance = function (derivedType, derivedTypeDecl) {
  20850            var _this = this;
  20851            var instanceType = derivedType.getInstanceType();
  20852            if(instanceType.extendsList == null) {
  20853                return;
  20854            }
  20855            var len = instanceType.extendsList.length;
  20856            if(len > 0) {
  20857                var names = new TypeScript.StringHashTable();
  20858                if(instanceType.isClassInstance()) {
  20859                    for(var i = 0; i < len; i++) {
  20860                        this.assertUniqueNamesInBaseTypes(names, instanceType.extendsList[i], derivedTypeDecl, i > 0);
  20861                    }
  20862                }
  20863                if(instanceType.members) {
  20864                    instanceType.members.publicMembers.map(function (key, s, c) {
  20865                        var sym = s;
  20866                        for(var j = 0; j < len; j++) {
  20867                            var base = instanceType.extendsList[j];
  20868                            if(base.memberScope == null) {
  20869                                _this.checker.errorReporter.simpleError(derivedTypeDecl, "Base type '" + base.symbol.name + "' lacks an implementation.");
  20870                            } else {
  20871                                var bSym = base.memberScope.find(sym.name, false, false);
  20872                                if(bSym) {
  20873                                    var aType = sym.getType();
  20874                                    var bType = bSym.getType();
  20875                                    if(!(_this.checker.sourceIsSubtypeOfTarget(aType, bType))) {
  20876                                        _this.checker.errorReporter.simpleErrorFromSym(sym, "Type of overridden member '" + sym.name + "' is not subtype of original member defined by type '" + bSym.container.name + "'");
  20877                                    } else {
  20878                                        if((sym.kind() == TypeScript.SymbolKind.Type) && (bSym.kind() == TypeScript.SymbolKind.Field)) {
  20879                                            _this.checker.errorReporter.simpleErrorFromSym(sym, "Cannot override field '" + sym.name + "' with method");
  20880                                        }
  20881                                    }
  20882                                }
  20883                            }
  20884                        }
  20885                    }, null);
  20886                }
  20887            }
  20888        };
  20889        TypeFlow.prototype.typeCheckClass = function (classDecl) {
  20890            var typeSymbol = classDecl.type.symbol;
  20891            if(typeSymbol.typeCheckStatus == TypeScript.TypeCheckStatus.Finished) {
  20892                return classDecl;
  20893            } else {
  20894                if(typeSymbol.typeCheckStatus == TypeScript.TypeCheckStatus.Started) {
  20895                    return classDecl;
  20896                } else {
  20897                    typeSymbol.typeCheckStatus = TypeScript.TypeCheckStatus.Started;
  20898                    this.checker.addStartedPTO(typeSymbol);
  20899                }
  20900            }
  20901            var prevScope = this.scope;
  20902            var svClassNode = this.thisClassNode;
  20903            this.thisClassNode = classDecl;
  20904            var classType = classDecl.type;
  20905            this.typeCheckBases(classType.instanceType);
  20906            this.typeCheckBaseListPrivacy(classDecl.extendsList, typeSymbol, true);
  20907            this.typeCheckBaseListPrivacy(classDecl.implementsList, typeSymbol, false);
  20908            var prevThisType = this.thisType;
  20909            this.thisType = classType.instanceType;
  20910            this.scope = classType.instanceType.containedScope;
  20911            if(classDecl.constructorDecl) {
  20912                this.scope = classType.instanceType.constructorScope;
  20913                var ssb = this.scope;
  20914                var funcTable = ssb.valueMembers.allMembers;
  20915                this.addConstructorLocalArgs(classDecl.constructorDecl.type.symbol, classDecl.constructorDecl.arguments, funcTable, true);
  20916            }
  20917            this.typeCheck(classDecl.members);
  20918            typeSymbol.typeCheckStatus = TypeScript.TypeCheckStatus.Finished;
  20919            this.checkBaseTypeMemberInheritance(classType, classDecl);
  20920            this.checkMembersImplementInterfaces(classType);
  20921            this.typeCheckOverloadSignatures(classType, classDecl);
  20922            this.typeCheckOverloadSignatures(classType.instanceType, classDecl);
  20923            if(!classDecl.constructorDecl) {
  20924                if(classDecl.extendsList && classDecl.extendsList.members.length && classDecl.extendsList.members[0].type && classDecl.extendsList.members[0].type.symbol.type.isClass()) {
  20925                    TypeScript.cloneParentConstructGroupForChildType(classDecl.type, classDecl.extendsList.members[0].type.symbol.type);
  20926                }
  20927            }
  20928            this.thisType = prevThisType;
  20929            this.thisClassNode = svClassNode;
  20930            this.scope = prevScope;
  20931            return classDecl;
  20932        };
  20933        TypeFlow.prototype.typeCheckOverloadSignatures = function (type, ast) {
  20934            if(type.call) {
  20935                type.call.typeCheck(this.checker, ast, type.construct != null);
  20936            }
  20937            if(type.construct) {
  20938                type.construct.typeCheck(this.checker, ast, false);
  20939            }
  20940            if(type.index) {
  20941                type.index.typeCheck(this.checker, ast, false);
  20942            }
  20943        };
  20944        TypeFlow.prototype.typeCheckInterface = function (interfaceDecl) {
  20945            this.typeCheckBases(interfaceDecl.type);
  20946            this.typeCheckBaseListPrivacy(interfaceDecl.extendsList, interfaceDecl.type.symbol, true);
  20947            this.typeCheck(interfaceDecl.members);
  20948            this.checkBaseTypeMemberInheritance(interfaceDecl.type, interfaceDecl);
  20949            if(interfaceDecl.extendsList) {
  20950                for(var i = 0; i < interfaceDecl.extendsList.members.length; i++) {
  20951                    if(interfaceDecl.extendsList.members[i].type.call) {
  20952                        if(interfaceDecl.type.call) {
  20953                            interfaceDecl.type.call.signatures = interfaceDecl.type.call.signatures.concat(interfaceDecl.extendsList.members[i].type.call.signatures);
  20954                        } else {
  20955                            interfaceDecl.type.call = interfaceDecl.extendsList.members[i].type.call;
  20956                        }
  20957                    }
  20958                    if(interfaceDecl.extendsList.members[i].type.construct) {
  20959                        if(interfaceDecl.type.construct) {
  20960                            interfaceDecl.type.construct.signatures = interfaceDecl.type.construct.signatures.concat(interfaceDecl.extendsList.members[i].type.construct.signatures);
  20961                        } else {
  20962                            interfaceDecl.type.construct = interfaceDecl.extendsList.members[i].type.construct;
  20963                        }
  20964                    }
  20965                    if(interfaceDecl.extendsList.members[i].type.index) {
  20966                        if(interfaceDecl.type.index) {
  20967                            interfaceDecl.type.index.signatures = interfaceDecl.type.index.signatures.concat(interfaceDecl.extendsList.members[i].type.index.signatures);
  20968                        } else {
  20969                            interfaceDecl.type.index = interfaceDecl.extendsList.members[i].type.index;
  20970                        }
  20971                    }
  20972                }
  20973            }
  20974            return interfaceDecl;
  20975        };
  20976        TypeFlow.prototype.typeCheckImportDecl = function (importDecl) {
  20977            var mod = importDecl.alias.type;
  20978            var sym = null;
  20979            var prevInImportTC = this.inImportTypeCheck;
  20980            this.inImportTypeCheck = true;
  20981            this.typeCheck(importDecl.alias);
  20982            mod = importDecl.alias.type;
  20983            if(mod == null) {
  20984                this.checker.errorReporter.simpleError(importDecl.alias, "Could not resolve module alias '" + importDecl.id.actualText + "'");
  20985                mod = this.checker.anyType;
  20986                (importDecl.id.sym).type = mod;
  20987            }
  20988            importDecl.id.type = mod;
  20989            sym = mod.symbol;
  20990            if(!mod.isModuleType()) {
  20991                this.checker.errorReporter.simpleError(importDecl.alias, "A module cannot be aliased to a non-module type");
  20992            } else {
  20993                sym.type = mod;
  20994                if(this.checker.typeFlow.currentScript && this.checker.typeFlow.currentScript.topLevelMod && this.checker.typeFlow.currentScript.topLevelMod.mod) {
  20995                    this.checker.typeFlow.currentScript.topLevelMod.mod.importedModules.push(importDecl);
  20996                }
  20997                (importDecl.id.sym).type = mod;
  20998                if(mod.symbol && mod.symbol.declAST) {
  20999                    (mod.symbol.declAST).modFlags &= ~TypeScript.ModuleFlags.ShouldEmitModuleDecl;
  21000                }
  21001            }
  21002            this.inImportTypeCheck = prevInImportTC;
  21003            return importDecl;
  21004        };
  21005        TypeFlow.prototype.typeCheckModule = function (moduleDecl) {
  21006            if(!moduleDecl.mod) {
  21007                return moduleDecl;
  21008            }
  21009            if(this.currentScript) {
  21010                this.currentScript.requiresGlobal = true;
  21011            }
  21012            var mod = moduleDecl.mod;
  21013            var sym = null;
  21014            var prevScope = this.scope;
  21015            var prevThisType = this.thisType;
  21016            var prevCurrentModDecl = this.checker.currentModDecl;
  21017            this.checker.currentModDecl = moduleDecl;
  21018            this.thisType = null;
  21019            this.scope = mod.containedScope;
  21020            this.typeCheck(moduleDecl.members);
  21021            sym = mod.symbol;
  21022            this.checker.currentModDecl = prevCurrentModDecl;
  21023            this.thisType = prevThisType;
  21024            this.scope = prevScope;
  21025            moduleDecl.type = mod;
  21026            if(sym) {
  21027                sym.typeCheckStatus = TypeScript.TypeCheckStatus.Finished;
  21028            }
  21029            return moduleDecl;
  21030        };
  21031        TypeFlow.prototype.typeCheckFor = function (forStmt) {
  21032            forStmt.init = this.typeCheck(forStmt.init);
  21033            this.nestingLevel++;
  21034            forStmt.cond = this.typeCheck(forStmt.cond);
  21035            this.typeCheckCondExpr(forStmt.cond);
  21036            forStmt.incr = this.typeCheck(forStmt.incr);
  21037            this.nestingLevel--;
  21038            forStmt.body = this.typeCheck(forStmt.body);
  21039            this.typeCheckCompoundStmtBlock(forStmt.body, "for statement");
  21040            forStmt.type = this.voidType;
  21041            return forStmt;
  21042        };
  21043        TypeFlow.prototype.typeCheckWith = function (withStmt) {
  21044            if(this.checker.errorsOnWith) {
  21045                this.checker.errorReporter.simpleError(withStmt.expr, "All symbols within a 'with' block will be typed as 'any'");
  21046            }
  21047            withStmt.expr = this.typeCheck(withStmt.expr);
  21048            this.checker.inWith = true;
  21049            withStmt.body = this.typeCheck(withStmt.body);
  21050            this.typeCheckCompoundStmtBlock(withStmt.body, "with statement");
  21051            this.checker.inWith = false;
  21052            return withStmt;
  21053        };
  21054        TypeFlow.prototype.typeCheckForIn = function (forInStmt) {
  21055            forInStmt.obj = this.typeCheck(forInStmt.obj);
  21056            forInStmt.lval = this.cast(this.typeCheck(forInStmt.lval), this.checker.stringType);
  21057            if(forInStmt.lval.nodeType == TypeScript.NodeType.VarDecl) {
  21058                var varDecl = forInStmt.lval;
  21059                if(varDecl.typeExpr) {
  21060                    this.checker.errorReporter.simpleError(varDecl, "Variable declarations for for/in expressions may not contain a type annotation");
  21061                }
  21062                if(varDecl.sym) {
  21063                    varDecl.sym.setType(this.checker.stringType);
  21064                }
  21065            }
  21066            forInStmt.body = this.typeCheck(forInStmt.body);
  21067            this.typeCheckCompoundStmtBlock(forInStmt.body, "for in statement");
  21068            return forInStmt;
  21069        };
  21070        TypeFlow.prototype.typeCheckWhile = function (whileStmt) {
  21071            whileStmt.cond = this.typeCheck(whileStmt.cond);
  21072            this.typeCheckCondExpr(whileStmt.cond);
  21073            whileStmt.body = this.typeCheck(whileStmt.body);
  21074            this.typeCheckCompoundStmtBlock(whileStmt.body, "while statement");
  21075            whileStmt.type = this.voidType;
  21076            return whileStmt;
  21077        };
  21078        TypeFlow.prototype.typeCheckDoWhile = function (doWhileStmt) {
  21079            doWhileStmt.cond = this.typeCheck(doWhileStmt.cond);
  21080            this.typeCheckCondExpr(doWhileStmt.cond);
  21081            doWhileStmt.body = this.typeCheck(doWhileStmt.body);
  21082            this.typeCheckCompoundStmtBlock(doWhileStmt.body, "do while statement");
  21083            doWhileStmt.type = this.voidType;
  21084            return doWhileStmt;
  21085        };
  21086        TypeFlow.prototype.typeCheckCondExpr = function (cond) {
  21087            if(this.checker.styleSettings.assignmentInCond) {
  21088                if((cond !== null) && (cond.nodeType >= TypeScript.NodeType.Asg) && (cond.nodeType <= TypeScript.NodeType.LastAsg)) {
  21089                    this.checker.errorReporter.simpleError(cond, "top-level assignment statement in conditional expression");
  21090                }
  21091            }
  21092        };
  21093        TypeFlow.prototype.typeCheckCompoundStmtBlock = function (stmts, stmtType) {
  21094            if(this.checker.styleSettings.blockInCompoundStmt && stmts) {
  21095                if(stmts.nodeType != TypeScript.NodeType.Block) {
  21096                    this.checker.errorReporter.styleError(stmts, stmtType + " requires a block");
  21097                }
  21098            }
  21099        };
  21100        TypeFlow.prototype.typeCheckIf = function (ifStmt) {
  21101            ifStmt.cond = this.typeCheck(ifStmt.cond);
  21102            this.typeCheckCondExpr(ifStmt.cond);
  21103            ifStmt.thenBod = this.typeCheck(ifStmt.thenBod);
  21104            ifStmt.elseBod = this.typeCheck(ifStmt.elseBod);
  21105            this.typeCheckCompoundStmtBlock(ifStmt.thenBod, "if statement");
  21106            this.typeCheckCompoundStmtBlock(ifStmt.elseBod, "if statement");
  21107            ifStmt.type = this.voidType;
  21108            return ifStmt;
  21109        };
  21110        TypeFlow.prototype.typeFromAccessorFuncDecl = function (funcDecl) {
  21111            if(!funcDecl.isAccessor()) {
  21112                return null;
  21113            }
  21114            if(TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.GetAccessor)) {
  21115                return funcDecl.type.call.signatures[0].returnType.type;
  21116            } else {
  21117                return funcDecl.type.call.signatures[0].parameters[0].getType();
  21118            }
  21119        };
  21120        TypeFlow.prototype.typeCheckObjectLit = function (objectLit) {
  21121            var resultType = new TypeScript.Type();
  21122            resultType.symbol = new TypeScript.TypeSymbol(this.checker.anon, objectLit.minChar, objectLit.limChar - objectLit.minChar, this.checker.locationInfo.unitIndex, resultType);
  21123            resultType.members = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  21124            resultType.memberScope = new TypeScript.SymbolTableScope(resultType.members, null, null, null, null);
  21125            var aggScope = new TypeScript.SymbolAggregateScope(resultType.symbol);
  21126            aggScope.addParentScope(resultType.memberScope);
  21127            aggScope.addParentScope(this.scope);
  21128            resultType.containedScope = aggScope;
  21129            var memberDecls = objectLit.operand;
  21130            var prevThisType = this.thisType;
  21131            var acceptTargetType = false;
  21132            var targetType = null;
  21133            if(this.checker.hasTargetType()) {
  21134                targetType = this.checker.getTargetTypeContext().contextualType;
  21135                if(targetType && targetType.symbol && !this.checker.typeStatusIsFinished(targetType.symbol.typeCheckStatus)) {
  21136                    if(targetType.symbol.declAST) {
  21137                        this.typeCheck(targetType.symbol.declAST);
  21138                    }
  21139                }
  21140                acceptTargetType = true;
  21141            }
  21142            if(memberDecls) {
  21143                for(var i = 0, len = memberDecls.members.length; i < len; i++) {
  21144                    var binex = memberDecls.members[i];
  21145                    var id = binex.operand1;
  21146                    var text;
  21147                    var targetMember = null;
  21148                    var fieldSymbol = null;
  21149                    if(id.nodeType == TypeScript.NodeType.Name) {
  21150                        text = (id).text;
  21151                    } else {
  21152                        if(id.nodeType == TypeScript.NodeType.QString) {
  21153                            var idText = (id).text;
  21154                            text = idText.substring(1, idText.length - 1);
  21155                        } else {
  21156                            this.checker.errorReporter.simpleError(objectLit, "malformed object literal");
  21157                            resultType = this.anyType;
  21158                            break;
  21159                        }
  21160                    }
  21161                    if(acceptTargetType && targetType.memberScope) {
  21162                        targetMember = targetType.memberScope.find(text, false, false);
  21163                    }
  21164                    if(binex.operand2.nodeType == TypeScript.NodeType.FuncDecl && (binex.operand2).isAccessor()) {
  21165                        var funcDecl = binex.operand2;
  21166                        var accessorSym = resultType.members.publicMembers.lookup(text);
  21167                        accessorSym = this.checker.createAccessorSymbol(funcDecl, accessorSym, resultType, true, false, resultType.memberScope, null);
  21168                        funcDecl.accessorSymbol = accessorSym;
  21169                        fieldSymbol = accessorSym;
  21170                        if(id.nodeType == TypeScript.NodeType.Name) {
  21171                            (id).sym = accessorSym;
  21172                        }
  21173                    }
  21174                    this.checker.typeCheckWithContextualType(acceptTargetType && targetMember ? targetMember.getType() : null, false, acceptTargetType, binex.operand2);
  21175                    if(acceptTargetType && targetMember) {
  21176                        if((binex.operand2.type == this.anyType || this.checker.sourceIsAssignableToTarget(binex.operand2.type, targetMember.getType())) || (binex.operand2.nodeType == TypeScript.NodeType.FuncDecl && (binex.operand2).isAccessor() && this.typeFromAccessorFuncDecl(binex.operand2) == targetMember.getType())) {
  21177                            binex.operand1.type = targetMember.getType();
  21178                        }
  21179                    } else {
  21180                        binex.operand2.type = binex.operand2.type == this.checker.undefinedType ? this.anyType : binex.operand2.type;
  21181                    }
  21182                    if(fieldSymbol == null) {
  21183                        var memberType = binex.operand2.type;
  21184                        var field = new TypeScript.ValueLocation();
  21185                        fieldSymbol = new TypeScript.FieldSymbol(text, id.minChar, this.checker.locationInfo.unitIndex, true, field);
  21186                        fieldSymbol.flags |= TypeScript.SymbolFlags.Property;
  21187                        field.symbol = fieldSymbol;
  21188                        fieldSymbol.typeCheckStatus = this.checker.getTypeCheckFinishedStatus();
  21189                        field.typeLink = new TypeScript.TypeLink();
  21190                        field.typeLink.type = memberType;
  21191                        resultType.members.publicMembers.add(text, fieldSymbol);
  21192                    }
  21193                    fieldSymbol.isObjectLitField = true;
  21194                }
  21195            }
  21196            this.thisType = prevThisType;
  21197            objectLit.type = resultType;
  21198            if(targetType) {
  21199                objectLit.targetType = targetType;
  21200            }
  21201        };
  21202        TypeFlow.prototype.typeCheckArrayLit = function (arrayLit) {
  21203            var elements = arrayLit.operand;
  21204            var elementType = this.anyType;
  21205            var targetElementType = null;
  21206            var comparisonInfo = new TypeScript.TypeComparisonInfo();
  21207            comparisonInfo.onlyCaptureFirstError = true;
  21208            if(this.checker.hasTargetType()) {
  21209                var targetType = this.checker.getTargetTypeContext().contextualType;
  21210                if(targetType.elementType) {
  21211                    targetElementType = targetType.elementType;
  21212                }
  21213            }
  21214            if(elements) {
  21215                var prevInArrayElemTypeCheck = this.inArrayElementTypeCheck;
  21216                this.inArrayElementTypeCheck = true;
  21217                this.checker.typeCheckWithContextualType(targetElementType, this.checker.inProvisionalTypecheckMode(), targetElementType != null, elements);
  21218                this.inArrayElementTypeCheck = prevInArrayElemTypeCheck;
  21219                elementType = elements.members[0].type;
  21220                var collection = {
  21221                    getLength: function () {
  21222                        return elements.members.length;
  21223                    },
  21224                    setTypeAtIndex: function (index, type) {
  21225                        elements.members[index].type = type;
  21226                    },
  21227                    getTypeAtIndex: function (index) {
  21228                        return elements.members[index].type;
  21229                    }
  21230                };
  21231                elementType = this.checker.findBestCommonType(elementType, targetElementType, collection, false, comparisonInfo);
  21232                if(elementType == this.checker.undefinedType || (!prevInArrayElemTypeCheck && elementType == this.nullType)) {
  21233                    elementType = this.anyType;
  21234                }
  21235            }
  21236            if(!elementType) {
  21237                var emsg = "Incompatible types in array literal expression";
  21238                if(!comparisonInfo.message) {
  21239                    this.checker.errorReporter.simpleError(arrayLit, emsg);
  21240                } else {
  21241                    this.checker.errorReporter.simpleError(arrayLit, emsg + ": " + comparisonInfo.message);
  21242                }
  21243                elementType = this.anyType;
  21244            } else {
  21245                if(targetElementType) {
  21246                    if(this.checker.sourceIsAssignableToTarget(elementType, targetElementType)) {
  21247                        elementType = targetElementType;
  21248                    }
  21249                }
  21250            }
  21251            arrayLit.type = this.checker.makeArrayType(elementType);
  21252        };
  21253        TypeFlow.prototype.checkForVoidConstructor = function (type, ast) {
  21254            if(type && type.construct && type.construct.signatures.length > 0) {
  21255                for(var i = 0; i < type.construct.signatures.length; i++) {
  21256                    if(type.construct.signatures[i].returnType.type == this.checker.voidType) {
  21257                        this.checker.errorReporter.simpleError(ast, "Constructors may not have a return type of 'void'");
  21258                        break;
  21259                    }
  21260                }
  21261            }
  21262        };
  21263        TypeFlow.prototype.typeCheckReturn = function (returnStmt) {
  21264            if(this.thisFnc) {
  21265                var targetType = null;
  21266                if(this.checker.hasTargetType()) {
  21267                    var tcContext = this.checker.getTargetTypeContext();
  21268                    var accessorType = tcContext.targetAccessorType;
  21269                    if(accessorType) {
  21270                        targetType = accessorType;
  21271                    } else {
  21272                        var targetSig = this.checker.getTargetTypeContext().targetSig;
  21273                        if(targetSig && targetSig.returnType.type != this.voidType) {
  21274                            targetType = targetSig.returnType.type;
  21275                        }
  21276                    }
  21277                }
  21278                if(returnStmt.returnExpression) {
  21279                    this.thisFnc.fncFlags |= TypeScript.FncFlags.HasReturnExpression;
  21280                    if(targetType == null && this.thisFnc.returnTypeAnnotation && this.thisFnc.returnTypeAnnotation.type && this.thisFnc.returnTypeAnnotation.type != this.voidType) {
  21281                        targetType = this.thisFnc.returnTypeAnnotation.type;
  21282                    }
  21283                    this.checker.typeCheckWithContextualType(targetType, this.checker.inProvisionalTypecheckMode(), targetType != null, returnStmt.returnExpression);
  21284                    var expectedReturnType = (this.thisFnc.returnTypeAnnotation && this.thisFnc.returnTypeAnnotation.type) ? this.thisFnc.returnTypeAnnotation.type : targetType;
  21285                    if(expectedReturnType) {
  21286                        if(expectedReturnType == this.voidType && returnStmt.returnExpression.type != this.voidType) {
  21287                            this.checker.errorReporter.simpleError(returnStmt, "Return with value expression in void function");
  21288                            returnStmt.type = returnStmt.returnExpression.type;
  21289                        } else {
  21290                            returnStmt.returnExpression = this.cast(returnStmt.returnExpression, expectedReturnType);
  21291                            returnStmt.type = expectedReturnType;
  21292                        }
  21293                    } else {
  21294                        if(targetType) {
  21295                            if(returnStmt.returnExpression.type != this.voidType) {
  21296                                returnStmt.returnExpression = this.cast(returnStmt.returnExpression, targetType);
  21297                            } else {
  21298                                returnStmt.returnExpression.type = targetType;
  21299                            }
  21300                        }
  21301                        returnStmt.type = returnStmt.returnExpression.type;
  21302                    }
  21303                    this.thisFnc.returnStatementsWithExpressions[this.thisFnc.returnStatementsWithExpressions.length] = returnStmt;
  21304                } else {
  21305                    returnStmt.type = targetType == null ? this.checker.voidType : targetType;
  21306                }
  21307            }
  21308            return returnStmt;
  21309        };
  21310        TypeFlow.prototype.typeCheckInstOf = function (ast) {
  21311            var binex = ast;
  21312            binex.operand1 = this.typeCheck(binex.operand1);
  21313            binex.operand2 = this.typeCheck(binex.operand2);
  21314            if(!((binex.operand1.type == this.checker.anyType || this.checker.sourceIsSubtypeOfTarget(binex.operand1.type, this.objectInterfaceType)) && (binex.operand2.type == this.anyType || this.checker.sourceIsSubtypeOfTarget(binex.operand2.type, this.functionInterfaceType)))) {
  21315                this.checker.errorReporter.simpleError(ast, "The instanceof operator requires the left operand to be of type Any or an object type, and the right operand to be of type Any or a subtype of the Function interface type");
  21316            }
  21317            binex.type = this.booleanType;
  21318            return binex;
  21319        };
  21320        TypeFlow.prototype.typeCheckCommaOperator = function (ast) {
  21321            var binex = ast;
  21322            binex.operand1 = this.typeCheck(binex.operand1);
  21323            binex.operand2 = this.typeCheck(binex.operand2);
  21324            binex.type = binex.operand2.type;
  21325            return binex;
  21326        };
  21327        TypeFlow.prototype.typeCheckLogOr = function (binex) {
  21328            binex.operand1 = this.typeCheck(binex.operand1);
  21329            binex.operand2 = this.typeCheck(binex.operand2);
  21330            var leftType = binex.operand1.type;
  21331            var rightType = binex.operand2.type;
  21332            if(leftType == this.checker.anyType || rightType == this.checker.anyType) {
  21333                binex.type = this.checker.anyType;
  21334            } else {
  21335                if(leftType == this.checker.booleanType) {
  21336                    if(rightType == this.checker.booleanType) {
  21337                        binex.type = this.checker.booleanType;
  21338                    } else {
  21339                        binex.type = this.checker.anyType;
  21340                    }
  21341                } else {
  21342                    if(leftType == this.checker.numberType) {
  21343                        if(rightType == this.checker.numberType) {
  21344                            binex.type = this.checker.numberType;
  21345                        } else {
  21346                            binex.type = this.checker.anyType;
  21347                        }
  21348                    } else {
  21349                        if(leftType == this.checker.stringType) {
  21350                            if(rightType == this.checker.stringType) {
  21351                                binex.type = this.checker.stringType;
  21352                            } else {
  21353                                binex.type = this.checker.anyType;
  21354                            }
  21355                        } else {
  21356                            if(this.checker.sourceIsSubtypeOfTarget(leftType, rightType)) {
  21357                                binex.type = rightType;
  21358                            } else {
  21359                                if(this.checker.sourceIsSubtypeOfTarget(rightType, leftType)) {
  21360                                    binex.type = leftType;
  21361                                } else {
  21362                                    binex.type = this.checker.anyType;
  21363                                }
  21364                            }
  21365                        }
  21366                    }
  21367                }
  21368            }
  21369            return binex;
  21370        };
  21371        TypeFlow.prototype.typeCheckLogAnd = function (binex) {
  21372            binex.operand1 = this.typeCheck(binex.operand1);
  21373            binex.operand2 = this.typeCheck(binex.operand2);
  21374            binex.type = binex.operand2.type;
  21375            return binex;
  21376        };
  21377        TypeFlow.prototype.tryAddCandidates = function (signature, actuals, exactCandidates, conversionCandidates, comparisonInfo) {
  21378            var lowerBound = signature.nonOptionalParameterCount;
  21379            var upperBound = signature.parameters.length;
  21380            var formalLen = lowerBound;
  21381            var acceptable = false;
  21382            if((actuals.length >= lowerBound) && (signature.hasVariableArgList || actuals.length <= upperBound)) {
  21383                formalLen = (signature.hasVariableArgList ? signature.parameters.length : actuals.length);
  21384                acceptable = true;
  21385            }
  21386            var repeatType = null;
  21387            if(acceptable || signature.hasVariableArgList) {
  21388                if(signature.hasVariableArgList) {
  21389                    formalLen -= 1;
  21390                    repeatType = (signature.parameters[formalLen]).parameter.typeLink.type;
  21391                    repeatType = repeatType.elementType;
  21392                    acceptable = actuals.length >= formalLen;
  21393                }
  21394                var len = actuals.length;
  21395                var exact = acceptable;
  21396                var convert = acceptable;
  21397                for(var i = 0; i < len; i++) {
  21398                    var typeA;
  21399                    if(i < formalLen) {
  21400                        typeA = (signature.parameters[i]).parameter.typeLink.type;
  21401                    } else {
  21402                        typeA = repeatType;
  21403                    }
  21404                    var typeB = actuals[i];
  21405                    if(!typeA || !typeB || !(this.checker.typesAreIdentical(typeA, typeB))) {
  21406                        exact = false;
  21407                    }
  21408                    if(!this.checker.sourceIsAssignableToTarget(typeB, typeA, comparisonInfo)) {
  21409                        convert = false;
  21410                    }
  21411                    if(!(exact || convert)) {
  21412                        break;
  21413                    }
  21414                }
  21415                if(exact) {
  21416                    exactCandidates[exactCandidates.length] = signature;
  21417                } else {
  21418                    if(convert && (exactCandidates.length == 0)) {
  21419                        conversionCandidates[conversionCandidates.length] = signature;
  21420                    }
  21421                }
  21422            }
  21423        };
  21424        TypeFlow.prototype.resolveOverload = function (application, group) {
  21425            var rd = this.resolutionDataCache.getResolutionData();
  21426            var actuals = rd.actuals;
  21427            var exactCandidates = rd.exactCandidates;
  21428            var conversionCandidates = rd.conversionCandidates;
  21429            var candidate = null;
  21430            var hasOverloads = group.signatures.length > 1;
  21431            var comparisonInfo = new TypeScript.TypeComparisonInfo();
  21432            var args = null;
  21433            var target = null;
  21434            if(application.nodeType == TypeScript.NodeType.Call || application.nodeType == TypeScript.NodeType.New) {
  21435                var callEx = application;
  21436                args = callEx.arguments;
  21437                target = callEx.target;
  21438                if(callEx.arguments) {
  21439                    var len = callEx.arguments.members.length;
  21440                    for(var i = 0; i < len; i++) {
  21441                        actuals[i] = callEx.arguments.members[i].type;
  21442                    }
  21443                }
  21444            } else {
  21445                if(application.nodeType == TypeScript.NodeType.Index) {
  21446                    var binExp = application;
  21447                    target = binExp.operand1;
  21448                    args = new TypeScript.ASTList();
  21449                    args.members[0] = binExp.operand2;
  21450                    actuals[0] = binExp.operand2.type;
  21451                }
  21452            }
  21453            for(var j = 0, groupLen = group.signatures.length; j < groupLen; j++) {
  21454                var signature = group.signatures[j];
  21455                if(hasOverloads && signature == group.definitionSignature && !this.checker.canCallDefinitionSignature) {
  21456                    continue;
  21457                }
  21458                if(!signature.returnType.type && signature.declAST && (signature.typeCheckStatus != TypeScript.TypeCheckStatus.Finished)) {
  21459                    this.typeCheckFunction(signature.declAST);
  21460                }
  21461                this.tryAddCandidates(signature, actuals, exactCandidates, conversionCandidates, comparisonInfo);
  21462            }
  21463            if(exactCandidates.length == 0) {
  21464                var applicableCandidates = this.checker.getApplicableSignatures(conversionCandidates, args, comparisonInfo);
  21465                if(applicableCandidates.length > 0) {
  21466                    var candidateInfo = this.checker.findMostApplicableSignature(applicableCandidates, args);
  21467                    if(candidateInfo.ambiguous) {
  21468                        this.checker.errorReporter.simpleError(target, "Ambiguous call expression - could not choose overload");
  21469                    }
  21470                    candidate = candidateInfo.sig;
  21471                } else {
  21472                    var emsg = "Supplied parameters do not match any signature of call target";
  21473                    if(comparisonInfo.message) {
  21474                        this.checker.errorReporter.simpleError(target, emsg + ":\n\t" + comparisonInfo.message);
  21475                    } else {
  21476                        this.checker.errorReporter.simpleError(target, emsg);
  21477                    }
  21478                }
  21479            } else {
  21480                if(exactCandidates.length > 1) {
  21481                    var applicableSigs = [];
  21482                    for(var i = 0; i < exactCandidates.length; i++) {
  21483                        applicableSigs[i] = {
  21484                            signature: exactCandidates[i],
  21485                            hadProvisionalErrors: false
  21486                        };
  21487                    }
  21488                    var candidateInfo = this.checker.findMostApplicableSignature(applicableSigs, args);
  21489                    if(candidateInfo.ambiguous) {
  21490                        this.checker.errorReporter.simpleError(target, "Ambiguous call expression - could not choose overload");
  21491                    }
  21492                    candidate = candidateInfo.sig;
  21493                } else {
  21494                    candidate = exactCandidates[0];
  21495                }
  21496            }
  21497            this.resolutionDataCache.returnResolutionData(rd);
  21498            return candidate;
  21499        };
  21500        TypeFlow.prototype.typeCheckNew = function (ast) {
  21501            var callEx = ast;
  21502            callEx.target = this.typeCheck(callEx.target);
  21503            var target = callEx.target;
  21504            if(target.type.construct || target.type.call) {
  21505                this.preTypeCheckCallArgs(callEx.arguments);
  21506            } else {
  21507                callEx.arguments = this.typeCheck(callEx.arguments);
  21508            }
  21509            if(target.type == this.anyType) {
  21510                callEx.type = this.anyType;
  21511                callEx.arguments = this.typeCheck(callEx.arguments);
  21512            } else {
  21513                if(target.type.construct) {
  21514                    var signature = this.resolveOverload(callEx, target.type.construct);
  21515                    if(signature == null) {
  21516                        callEx.type = this.anyType;
  21517                    } else {
  21518                        if(signature.returnType.type == this.voidType) {
  21519                            callEx.type = this.anyType;
  21520                            callEx.signature = signature;
  21521                        } else {
  21522                            callEx.type = signature.returnType.type;
  21523                            callEx.signature = signature;
  21524                        }
  21525                    }
  21526                } else {
  21527                    if(target.type.call) {
  21528                        var signature = this.resolveOverload(callEx, target.type.call);
  21529                        if(signature == null) {
  21530                            callEx.type = this.anyType;
  21531                        } else {
  21532                            if((signature.returnType.type == this.voidType) || (signature.returnType.type == this.anyType)) {
  21533                                callEx.type = this.anyType;
  21534                                callEx.signature = signature;
  21535                            } else {
  21536                                this.checker.errorReporter.simpleError(callEx.target, "new expression only valid on constructors");
  21537                            }
  21538                        }
  21539                    } else {
  21540                        if(target.type.elementType) {
  21541                            callEx.type = target.type;
  21542                        } else {
  21543                            this.checker.errorReporter.invalidCall(callEx, callEx.nodeType, this.scope);
  21544                            callEx.type = this.anyType;
  21545                        }
  21546                    }
  21547                }
  21548            }
  21549            this.postTypeCheckCallArgs(callEx);
  21550            return callEx;
  21551        };
  21552        TypeFlow.prototype.preTypeCheckCallArgs = function (args) {
  21553            if(!args) {
  21554                return;
  21555            }
  21556            for(var i = 0; i < args.members.length; i++) {
  21557                switch(args.members[i].nodeType) {
  21558                    case TypeScript.NodeType.FuncDecl:
  21559                    case TypeScript.NodeType.ObjectLit:
  21560                    case TypeScript.NodeType.ArrayLit: {
  21561                        continue;
  21562 
  21563                    }
  21564                    default: {
  21565                        this.typeCheck(args.members[i]);
  21566                        break;
  21567 
  21568                    }
  21569                }
  21570            }
  21571        };
  21572        TypeFlow.prototype.postTypeCheckCallArgs = function (callEx) {
  21573            var acceptedTargetType = false;
  21574            var i = 0;
  21575            if(callEx.target && callEx.target.type && callEx.signature && callEx.arguments) {
  21576                var sig = callEx.signature;
  21577                if(sig && callEx.arguments.members.length >= sig.nonOptionalParameterCount) {
  21578                    acceptedTargetType = true;
  21579                    var targetType = null;
  21580                    var nonVarArgFormalParamLength = sig.hasVariableArgList ? sig.parameters.length - 1 : sig.parameters.length;
  21581                    var nonVarArgActualParamLength = callEx.arguments.members.length < nonVarArgFormalParamLength ? callEx.arguments.members.length : nonVarArgFormalParamLength;
  21582                    for(i = 0; i < nonVarArgActualParamLength; i++) {
  21583                        targetType = sig.parameters[i].getType();
  21584                        switch(callEx.arguments.members[i].nodeType) {
  21585                            case TypeScript.NodeType.FuncDecl:
  21586                            case TypeScript.NodeType.ObjectLit:
  21587                            case TypeScript.NodeType.ArrayLit: {
  21588                                this.checker.typeCheckWithContextualType(targetType, this.checker.inProvisionalTypecheckMode(), !sig.parameters[i].declAST.isParenthesized, callEx.arguments.members[i]);
  21589                                break;
  21590 
  21591                            }
  21592                        }
  21593                    }
  21594                    if(sig.hasVariableArgList) {
  21595                        var varArgParamIndex = sig.nonOptionalParameterCount - 1;
  21596                        targetType = sig.parameters[varArgParamIndex].getType();
  21597                        if(targetType) {
  21598                            targetType = targetType.elementType;
  21599                        }
  21600                        var isParenthesized = !sig.parameters[varArgParamIndex].declAST.isParenthesized;
  21601                        for(i = nonVarArgActualParamLength; i < callEx.arguments.members.length; i++) {
  21602                            switch(callEx.arguments.members[i].nodeType) {
  21603                                case TypeScript.NodeType.FuncDecl:
  21604                                case TypeScript.NodeType.ObjectLit:
  21605                                case TypeScript.NodeType.ArrayLit: {
  21606                                    this.checker.typeCheckWithContextualType(targetType, this.checker.inProvisionalTypecheckMode(), isParenthesized, callEx.arguments.members[i]);
  21607                                    break;
  21608 
  21609                                }
  21610                            }
  21611                        }
  21612                    }
  21613                }
  21614            }
  21615            if(!acceptedTargetType && callEx.arguments) {
  21616                this.checker.killCurrentContextualType();
  21617                for(i = 0; i < callEx.arguments.members.length; i++) {
  21618                    switch(callEx.arguments.members[i].nodeType) {
  21619                        case TypeScript.NodeType.FuncDecl:
  21620                        case TypeScript.NodeType.ObjectLit:
  21621                        case TypeScript.NodeType.ArrayLit: {
  21622                            this.typeCheck(callEx.arguments.members[i]);
  21623                            break;
  21624 
  21625                        }
  21626                        default: {
  21627                            continue;
  21628 
  21629                        }
  21630                    }
  21631                }
  21632            }
  21633        };
  21634        TypeFlow.prototype.typeCheckCall = function (ast) {
  21635            var callEx = ast;
  21636            if(this.checker.styleSettings.newMustBeUsed && (ast.nodeType == TypeScript.NodeType.New)) {
  21637                if(TypeScript.hasFlag(ast.flags, TypeScript.ASTFlags.IsStatement)) {
  21638                    this.checker.errorReporter.styleError(ast, "use of new expression as a statement");
  21639                }
  21640            } else {
  21641                if((!this.checker.styleSettings.evalOK) && (ast.nodeType == TypeScript.NodeType.Call)) {
  21642                    if((callEx.target.nodeType == TypeScript.NodeType.Name) && ((callEx.target).text == "eval")) {
  21643                        this.checker.errorReporter.styleError(callEx, "eval not permitted");
  21644                    }
  21645                }
  21646            }
  21647            if(callEx.target.nodeType == TypeScript.NodeType.FuncDecl) {
  21648                (callEx.target).isInlineCallLiteral = true;
  21649            }
  21650            var prevInSuperCall = this.inSuperCall;
  21651            if(callEx.target.nodeType == TypeScript.NodeType.Super) {
  21652                this.inSuperCall = true;
  21653            }
  21654            callEx.target = this.typeCheck(callEx.target);
  21655            this.preTypeCheckCallArgs(callEx.arguments);
  21656            var target = callEx.target;
  21657            if((target.type == null) || (target.type == this.anyType) || (this.functionInterfaceType && target.type == this.functionInterfaceType)) {
  21658                callEx.type = this.anyType;
  21659            } else {
  21660                var fnType = target.type;
  21661                if(fnType.call) {
  21662                    var signature = this.resolveOverload(callEx, fnType.call);
  21663                    if(signature == null) {
  21664                        callEx.type = this.anyType;
  21665                    } else {
  21666                        callEx.type = signature.returnType.type;
  21667                        callEx.signature = signature;
  21668                    }
  21669                } else {
  21670                    if(callEx.target.nodeType == TypeScript.NodeType.Super && this.thisFnc && this.thisFnc.isConstructor && TypeScript.hasFlag(this.thisFnc.fncFlags, TypeScript.FncFlags.ClassMethod)) {
  21671                        var signature = fnType.symbol.type.construct ? this.resolveOverload(callEx, fnType.symbol.type.construct) : null;
  21672                        if(signature == null) {
  21673                            callEx.type = this.anyType;
  21674                        } else {
  21675                            callEx.flags |= TypeScript.ASTFlags.ClassBaseConstructorCall;
  21676                            callEx.type = signature.returnType.type;
  21677                            callEx.signature = signature;
  21678                        }
  21679                    } else {
  21680                        callEx.type = this.anyType;
  21681                        this.checker.errorReporter.invalidCall(callEx, callEx.nodeType, this.scope);
  21682                    }
  21683                }
  21684            }
  21685            this.postTypeCheckCallArgs(callEx);
  21686            this.inSuperCall = prevInSuperCall;
  21687            return callEx;
  21688        };
  21689        TypeFlow.prototype.assignScopes = function (ast) {
  21690            var script = ast;
  21691            this.checker.locationInfo = script.locationInfo;
  21692            var globalChain = new ScopeChain(this.checker.gloMod, null, this.globalScope);
  21693            var context = new TypeScript.AssignScopeContext(globalChain, this, [
  21694                this.checker.currentModDecl
  21695            ]);
  21696            TypeScript.getAstWalkerFactory().walk(ast, TypeScript.preAssignScopes, TypeScript.postAssignScopes, null, context);
  21697        };
  21698        TypeFlow.prototype.findMemberScope = function (enclosingScopeContext, matchFlag) {
  21699            var enclosingScope = enclosingScopeContext.getScope();
  21700            var pos = enclosingScopeContext.pos - enclosingScopeContext.getScriptFragmentPosition();
  21701            var scriptFragment = enclosingScopeContext.getScriptFragment();
  21702            var memContext = new TypeScript.MemberScopeContext(this, pos, matchFlag);
  21703            memContext.scope = enclosingScope;
  21704            if(scriptFragment.nodeType == TypeScript.NodeType.Name) {
  21705                return scriptFragment.type.getMemberScope(this);
  21706            } else {
  21707                TypeScript.getAstWalkerFactory().walk(scriptFragment, TypeScript.preFindMemberScope, null, null, memContext);
  21708                if(memContext.ast && enclosingScopeContext.enclosingClassDecl && memContext.ast.type == enclosingScopeContext.enclosingClassDecl.type.instanceType) {
  21709                    enclosingScopeContext.publicsOnly = false;
  21710                }
  21711                if(memContext.type) {
  21712                    return memContext.type.getMemberScope(this);
  21713                } else {
  21714                    return null;
  21715                }
  21716            }
  21717        };
  21718        TypeFlow.prototype.findMemberScopeAt = function (enclosingScopeContext) {
  21719            return this.findMemberScope(enclosingScopeContext, TypeScript.ASTFlags.DotLHS);
  21720        };
  21721        TypeFlow.prototype.findMemberScopeAtFullAst = function (enclosingScopeContext) {
  21722            var matchFlag = TypeScript.ASTFlags.DotLHS;
  21723            var pos = enclosingScopeContext.pos;
  21724            var astResult = null;
  21725            var preFindMemberScopeFullAst = function (ast, parent, walker) {
  21726                if(TypeScript.isValidAstNode(ast)) {
  21727                    if(TypeScript.hasFlag(ast.flags, matchFlag) && (pos == ast.limChar || (pos - 1) == ast.limChar)) {
  21728                        astResult = ast;
  21729                        walker.options.stopWalk();
  21730                    }
  21731                    walker.options.goChildren = (ast.minChar <= pos) && (pos <= ast.limChar);
  21732                }
  21733                return ast;
  21734            };
  21735            var preFindMemberScopeFullAstFuzy = function (ast, parent, walker) {
  21736                if(TypeScript.isValidAstNode(ast)) {
  21737                    if(TypeScript.hasFlag(ast.flags, matchFlag) && ((ast.minChar < pos) && (pos <= ast.limChar))) {
  21738                        astResult = ast;
  21739                    }
  21740                    walker.options.goChildren = (ast.minChar <= pos) && (pos <= ast.limChar);
  21741                }
  21742                return ast;
  21743            };
  21744            TypeScript.getAstWalkerFactory().walk(enclosingScopeContext.script, preFindMemberScopeFullAst);
  21745            if(astResult == null) {
  21746                TypeScript.getAstWalkerFactory().walk(enclosingScopeContext.script, preFindMemberScopeFullAstFuzy);
  21747            }
  21748            if(astResult && enclosingScopeContext.enclosingClassDecl && astResult.type == enclosingScopeContext.enclosingClassDecl.type.instanceType) {
  21749                enclosingScopeContext.publicsOnly = false;
  21750            }
  21751            if(astResult && astResult.type) {
  21752                return astResult.type.getMemberScope(this);
  21753            } else {
  21754                return null;
  21755            }
  21756        };
  21757        return TypeFlow;
  21758    })();
  21759    TypeScript.TypeFlow = TypeFlow;    
  21760 })(TypeScript || (TypeScript = {}));
  21761 var TypeScript;
  21762 (function (TypeScript) {
  21763    (function (Primitive) {
  21764        Primitive._map = [];
  21765        Primitive.None = 0;
  21766        Primitive.Void = 1;
  21767        Primitive.Double = 2;
  21768        Primitive.String = 4;
  21769        Primitive.Boolean = 8;
  21770        Primitive.Any = 16;
  21771        Primitive.Null = 32;
  21772        Primitive.Undefined = 64;
  21773    })(TypeScript.Primitive || (TypeScript.Primitive = {}));
  21774    var Primitive = TypeScript.Primitive;
  21775    var MemberName = (function () {
  21776        function MemberName() {
  21777            this.prefix = "";
  21778            this.suffix = "";
  21779        }
  21780        MemberName.prototype.isString = function () {
  21781            return false;
  21782        };
  21783        MemberName.prototype.isArray = function () {
  21784            return false;
  21785        };
  21786        MemberName.prototype.toString = function () {
  21787            return MemberName.memberNameToString(this);
  21788        };
  21789        MemberName.memberNameToString = function memberNameToString(memberName) {
  21790            var result = memberName.prefix;
  21791            if(memberName.isString()) {
  21792                result += (memberName).text;
  21793            } else {
  21794                var ar = memberName;
  21795                for(var index = 0; index < ar.entries.length; index++) {
  21796                    result += MemberName.memberNameToString(ar.entries[index]);
  21797                    result += ar.delim;
  21798                }
  21799            }
  21800            result += memberName.suffix;
  21801            return result;
  21802        }
  21803        MemberName.create = function create(arg1, arg2, arg3) {
  21804            if(typeof arg1 == "string") {
  21805                return new MemberNameString(arg1);
  21806            } else {
  21807                var result = new MemberNameArray();
  21808                if(arg2) {
  21809                    result.prefix = arg2;
  21810                }
  21811                if(arg3) {
  21812                    result.suffix = arg3;
  21813                }
  21814                result.entries.push(arg1);
  21815                return result;
  21816            }
  21817        }
  21818        return MemberName;
  21819    })();
  21820    TypeScript.MemberName = MemberName;    
  21821    var MemberNameString = (function (_super) {
  21822        __extends(MemberNameString, _super);
  21823        function MemberNameString(text) {
  21824                _super.call(this);
  21825            this.text = text;
  21826        }
  21827        MemberNameString.prototype.isString = function () {
  21828            return true;
  21829        };
  21830        return MemberNameString;
  21831    })(MemberName);
  21832    TypeScript.MemberNameString = MemberNameString;    
  21833    var MemberNameArray = (function (_super) {
  21834        __extends(MemberNameArray, _super);
  21835        function MemberNameArray() {
  21836            _super.apply(this, arguments);
  21837 
  21838            this.delim = "";
  21839            this.entries = [];
  21840        }
  21841        MemberNameArray.prototype.isArray = function () {
  21842            return true;
  21843        };
  21844        MemberNameArray.prototype.add = function (entry) {
  21845            this.entries.push(entry);
  21846        };
  21847        MemberNameArray.prototype.addAll = function (entries) {
  21848            for(var i = 0; i < entries.length; i++) {
  21849                this.entries.push(entries[i]);
  21850            }
  21851        };
  21852        return MemberNameArray;
  21853    })(MemberName);
  21854    TypeScript.MemberNameArray = MemberNameArray;    
  21855    var currentTypeID = -1;
  21856    var Type = (function () {
  21857        function Type() {
  21858            this.typeID = currentTypeID++;
  21859            this.construct = null;
  21860            this.call = null;
  21861            this.index = null;
  21862            this.passTypeCreated = TypeScript.CompilerDiagnostics.analysisPass;
  21863            this.primitiveTypeClass = Primitive.None;
  21864            this.typeFlags = TypeScript.TypeFlags.None;
  21865        }
  21866        Type.prototype.baseClass = function () {
  21867            if(this.extendsList && (this.extendsList.length > 0)) {
  21868                return this.extendsList[0];
  21869            } else {
  21870                return null;
  21871            }
  21872        };
  21873        Type.prototype.getArrayBase = function (arrInstType, checker) {
  21874            return this.arrayCache.specialize(arrInstType, checker);
  21875        };
  21876        Type.prototype.isClass = function () {
  21877            return this.instanceType != null;
  21878        };
  21879        Type.prototype.isArray = function () {
  21880            return this.elementType != null;
  21881        };
  21882        Type.prototype.isClassInstance = function () {
  21883            return this.symbol && !this.elementType && (this.symbol).type.isClass();
  21884        };
  21885        Type.prototype.getInstanceType = function () {
  21886            if(this.isClass()) {
  21887                return this.instanceType;
  21888            } else {
  21889                return this;
  21890            }
  21891        };
  21892        Type.prototype.hasImplementation = function () {
  21893            return TypeScript.hasFlag(this.typeFlags, TypeScript.TypeFlags.HasImplementation);
  21894        };
  21895        Type.prototype.setHasImplementation = function () {
  21896            this.typeFlags |= TypeScript.TypeFlags.HasImplementation;
  21897        };
  21898        Type.prototype.isDouble = function () {
  21899            return TypeScript.hasFlag(this.primitiveTypeClass, Primitive.Double);
  21900        };
  21901        Type.prototype.isString = function () {
  21902            return TypeScript.hasFlag(this.primitiveTypeClass, Primitive.String);
  21903        };
  21904        Type.prototype.isBoolean = function () {
  21905            return TypeScript.hasFlag(this.primitiveTypeClass, Primitive.Boolean);
  21906        };
  21907        Type.prototype.isNull = function () {
  21908            return TypeScript.hasFlag(this.primitiveTypeClass, Primitive.Null);
  21909        };
  21910        Type.prototype.getTypeName = function () {
  21911            return this.getMemberTypeName("", true, false, null);
  21912        };
  21913        Type.prototype.getScopedTypeName = function (scope) {
  21914            return this.getMemberTypeName("", true, false, scope);
  21915        };
  21916        Type.prototype.getScopedTypeNameEx = function (scope) {
  21917            return this.getMemberTypeNameEx("", true, false, scope);
  21918        };
  21919        Type.prototype.callCount = function () {
  21920            var total = 0;
  21921            if(this.call) {
  21922                total += this.call.signatures.length;
  21923            }
  21924            if(this.construct) {
  21925                total += this.construct.signatures.length;
  21926            }
  21927            if(this.index) {
  21928                total += this.index.signatures.length;
  21929            }
  21930            return total;
  21931        };
  21932        Type.prototype.getMemberTypeName = function (prefix, topLevel, isElementType, scope) {
  21933            var memberName = this.getMemberTypeNameEx(prefix, topLevel, isElementType, scope);
  21934            return memberName.toString();
  21935        };
  21936        Type.prototype.getMemberTypeNameEx = function (prefix, topLevel, isElementType, scope) {
  21937            if(this.elementType) {
  21938                return MemberName.create(this.elementType.getMemberTypeNameEx(prefix, false, true, scope), "", "[]");
  21939            } else {
  21940                if(this.symbol && this.symbol.name && this.symbol.name != "_anonymous" && (((this.call == null) && (this.construct == null) && (this.index == null)) || (TypeScript.hasFlag(this.typeFlags, TypeScript.TypeFlags.BuildingName)) || (this.members && (!this.isClass())))) {
  21941                    var tn = this.symbol.scopeRelativeName(scope);
  21942                    return MemberName.create(tn == "null" ? "any" : tn);
  21943                } else {
  21944                    if(this.members || this.call || this.construct) {
  21945                        if(TypeScript.hasFlag(this.typeFlags, TypeScript.TypeFlags.BuildingName)) {
  21946                            return MemberName.create("this");
  21947                        }
  21948                        this.typeFlags |= TypeScript.TypeFlags.BuildingName;
  21949                        var builder = "";
  21950                        var allMemberNames = new MemberNameArray();
  21951                        var curlies = isElementType || this.index != null;
  21952                        var memCount = 0;
  21953                        var delim = "; ";
  21954                        if(this.members) {
  21955                            this.members.allMembers.map(function (key, s, unused) {
  21956                                var sym = s;
  21957                                if(!TypeScript.hasFlag(sym.flags, TypeScript.SymbolFlags.BuiltIn)) {
  21958                                    var typeNameMember = sym.getTypeNameEx(scope);
  21959                                    if(typeNameMember.isArray() && (typeNameMember).delim == delim) {
  21960                                        allMemberNames.addAll((typeNameMember).entries);
  21961                                    } else {
  21962                                        allMemberNames.add(typeNameMember);
  21963                                    }
  21964                                    memCount++;
  21965                                    curlies = true;
  21966                                }
  21967                            }, null);
  21968                        }
  21969                        var signatureCount = this.callCount();
  21970                        var j;
  21971                        var len = 0;
  21972                        var shortform = !curlies && signatureCount == 1 && topLevel;
  21973                        if(this.call) {
  21974                            allMemberNames.addAll(this.call.toStrings(prefix, shortform, scope));
  21975                        }
  21976                        if(this.construct) {
  21977                            allMemberNames.addAll(this.construct.toStrings("new", shortform, scope));
  21978                        }
  21979                        if(this.index) {
  21980                            allMemberNames.addAll(this.index.toStrings("", shortform, scope));
  21981                        }
  21982                        if((curlies) || ((signatureCount > 1) && topLevel)) {
  21983                            allMemberNames.prefix = "{ ";
  21984                            allMemberNames.suffix = "}";
  21985                            allMemberNames.delim = delim;
  21986                        } else {
  21987                            if(allMemberNames.entries.length > 1) {
  21988                                allMemberNames.delim = delim;
  21989                            }
  21990                        }
  21991                        this.typeFlags &= (~TypeScript.TypeFlags.BuildingName);
  21992                        if((signatureCount == 0) && (memCount == 0)) {
  21993                            return MemberName.create("{}");
  21994                        } else {
  21995                            return allMemberNames;
  21996                        }
  21997                    } else {
  21998                        return MemberName.create("{}");
  21999                    }
  22000                }
  22001            }
  22002        };
  22003        Type.prototype.checkDecl = function (checker) {
  22004            if(this.isClassInstance() || this.isClass()) {
  22005                if(this.symbol.declAST) {
  22006                    checker.typeFlow.inScopeTypeCheckDecl(this.symbol.declAST);
  22007                }
  22008            }
  22009        };
  22010        Type.prototype.getMemberScope = function (flow) {
  22011            if(this == flow.anyType) {
  22012                return null;
  22013            } else {
  22014                if(this.isDouble()) {
  22015                    if(flow.numberInterfaceType) {
  22016                        return flow.numberInterfaceType.memberScope;
  22017                    } else {
  22018                        return null;
  22019                    }
  22020                } else {
  22021                    if(this.isBoolean()) {
  22022                        if(flow.booleanInterfaceType) {
  22023                            return flow.booleanInterfaceType.memberScope;
  22024                        } else {
  22025                            return null;
  22026                        }
  22027                    } else {
  22028                        if(this == flow.stringType) {
  22029                            if(flow.stringInterfaceType) {
  22030                                return flow.stringInterfaceType.memberScope;
  22031                            } else {
  22032                                return null;
  22033                            }
  22034                        } else {
  22035                            if(this.elementType) {
  22036                                if(flow.arrayInterfaceType) {
  22037                                    var arrInstType = this.elementType.getArrayBase(flow.arrayInterfaceType, flow.checker);
  22038                                    return arrInstType.memberScope;
  22039                                } else {
  22040                                    return null;
  22041                                }
  22042                            } else {
  22043                                return this.memberScope;
  22044                            }
  22045                        }
  22046                    }
  22047                }
  22048            }
  22049        };
  22050        Type.prototype.isReferenceType = function () {
  22051            return this.members || this.extendsList || this.construct || this.call || this.index || this.elementType;
  22052        };
  22053        Type.prototype.specializeType = function (pattern, replacement, checker, membersOnly) {
  22054            if(pattern == this) {
  22055                return replacement;
  22056            }
  22057            var result = this;
  22058            if(membersOnly) {
  22059                if(this.isReferenceType()) {
  22060                    result = new Type();
  22061                    if(this.members) {
  22062                        result.members = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  22063                        this.members.publicMembers.map(function (key, s, unused) {
  22064                            var sym = s;
  22065                            var bSym = sym.specializeType(pattern, replacement, checker);
  22066                            result.members.addPublicMember(bSym.name, bSym);
  22067                        }, null);
  22068                        this.members.privateMembers.map(function (key, s, unused) {
  22069                            var sym = s;
  22070                            var bSym = sym.specializeType(pattern, replacement, checker);
  22071                            result.members.addPrivateMember(bSym.name, bSym);
  22072                        }, null);
  22073                    }
  22074                    if(this.ambientMembers) {
  22075                        result.ambientMembers = new TypeScript.ScopedMembers(new TypeScript.DualStringHashTable(new TypeScript.StringHashTable(), new TypeScript.StringHashTable()));
  22076                        this.ambientMembers.publicMembers.map(function (key, s, unused) {
  22077                            var sym = s;
  22078                            var bSym = sym.specializeType(pattern, replacement, checker);
  22079                            result.ambientMembers.addPublicMember(bSym.name, bSym);
  22080                        }, null);
  22081                        this.ambientMembers.privateMembers.map(function (key, s, unused) {
  22082                            var sym = s;
  22083                            var bSym = sym.specializeType(pattern, replacement, checker);
  22084                            result.ambientMembers.addPrivateMember(bSym.name, bSym);
  22085                        }, null);
  22086                    }
  22087                    result.containedScope = checker.scopeOf(result);
  22088                    result.memberScope = result.containedScope;
  22089                }
  22090            } else {
  22091                if(this.elementType) {
  22092                    if(this.elementType == pattern) {
  22093                        result = checker.makeArrayType(replacement);
  22094                    } else {
  22095                        if(this.elementType.elementType == pattern) {
  22096                            result = checker.makeArrayType(checker.makeArrayType(replacement));
  22097                        }
  22098                    }
  22099                } else {
  22100                    if(this.call) {
  22101                        result = new Type();
  22102                        result.call = this.call.specializeType(pattern, replacement, checker);
  22103                    }
  22104                }
  22105            }
  22106            return result;
  22107        };
  22108        Type.prototype.hasBase = function (baseType) {
  22109            if(baseType == this) {
  22110                return true;
  22111            } else {
  22112                if(this.extendsList) {
  22113                    for(var i = 0, len = this.extendsList.length; i < len; i++) {
  22114                        if(this.extendsList[i].hasBase(baseType)) {
  22115                            return true;
  22116                        }
  22117                    }
  22118                }
  22119            }
  22120            return false;
  22121        };
  22122        Type.prototype.mergeOrdered = function (b, checker, acceptVoid, comparisonInfo) {
  22123            if((this == checker.anyType) || (b == checker.anyType)) {
  22124                return checker.anyType;
  22125            } else {
  22126                if(this == b) {
  22127                    return this;
  22128                } else {
  22129                    if((b == checker.nullType) && this != checker.nullType) {
  22130                        return this;
  22131                    } else {
  22132                        if((this == checker.nullType) && (b != checker.nullType)) {
  22133                            return b;
  22134                        } else {
  22135                            if(acceptVoid && (b == checker.voidType) && this != checker.voidType) {
  22136                                return this;
  22137                            } else {
  22138                                if(acceptVoid && (this == checker.voidType) && (b != checker.voidType)) {
  22139                                    return b;
  22140                                } else {
  22141                                    if((b == checker.undefinedType) && this != checker.undefinedType) {
  22142                                        return this;
  22143                                    } else {
  22144                                        if((this == checker.undefinedType) && (b != checker.undefinedType)) {
  22145                                            return b;
  22146                                        } else {
  22147                                            if(this.elementType && b.elementType) {
  22148                                                if(this.elementType == b.elementType) {
  22149                                                    return this;
  22150                                                } else {
  22151                                                    var mergedET = this.elementType.mergeOrdered(b.elementType, checker, acceptVoid, comparisonInfo);
  22152                                                    if(mergedET == null) {
  22153                                                        return checker.makeArrayType(checker.anyType);
  22154                                                    } else {
  22155                                                        return checker.makeArrayType(mergedET);
  22156                                                    }
  22157                                                }
  22158                                            } else {
  22159                                                if(checker.sourceIsSubtypeOfTarget(this, b, comparisonInfo)) {
  22160                                                    return b;
  22161                                                } else {
  22162                                                    if(checker.sourceIsSubtypeOfTarget(b, this, comparisonInfo)) {
  22163                                                        return this;
  22164                                                    } else {
  22165                                                        return null;
  22166                                                    }
  22167                                                }
  22168                                            }
  22169                                        }
  22170                                    }
  22171                                }
  22172                            }
  22173                        }
  22174                    }
  22175                }
  22176            }
  22177        };
  22178        Type.prototype.isModuleType = function () {
  22179            return false;
  22180        };
  22181        Type.prototype.hasMembers = function () {
  22182            return this.members != null;
  22183        };
  22184        Type.prototype.getAllEnclosedTypes = function () {
  22185            return null;
  22186        };
  22187        Type.prototype.getAllAmbientEnclosedTypes = function () {
  22188            return null;
  22189        };
  22190        Type.prototype.getPublicEnclosedTypes = function () {
  22191            return null;
  22192        };
  22193        Type.prototype.getpublicAmbientEnclosedTypes = function () {
  22194            return null;
  22195        };
  22196        Type.prototype.getDocComments = function () {
  22197            if(this.elementType || !this.symbol) {
  22198                return [];
  22199            }
  22200            if(this.isClassInstance() || this.isClass()) {
  22201                if(this.symbol.declAST.nodeType == TypeScript.NodeType.FuncDecl) {
  22202                    return (this.symbol.declAST).classDecl.getDocComments();
  22203                } else {
  22204                    return this.symbol.getDocComments();
  22205                }
  22206            }
  22207            if(this.symbol.name && this.symbol.name != "_anonymous" && (((this.call == null) && (this.construct == null) && (this.index == null)) || this.members)) {
  22208                return this.symbol.getDocComments();
  22209            }
  22210            return [];
  22211        };
  22212        return Type;
  22213    })();
  22214    TypeScript.Type = Type;    
  22215    var ModuleType = (function (_super) {
  22216        __extends(ModuleType, _super);
  22217        function ModuleType(enclosedTypes, ambientEnclosedTypes) {
  22218                _super.call(this);
  22219            this.enclosedTypes = enclosedTypes;
  22220            this.ambientEnclosedTypes = ambientEnclosedTypes;
  22221            this.importedModules = [];
  22222        }
  22223        ModuleType.prototype.isModuleType = function () {
  22224            return true;
  22225        };
  22226        ModuleType.prototype.hasMembers = function () {
  22227            return this.members != null || this.enclosedTypes != null;
  22228        };
  22229        ModuleType.prototype.getAllEnclosedTypes = function () {
  22230            return this.enclosedTypes;
  22231        };
  22232        ModuleType.prototype.getAllAmbientEnclosedTypes = function () {
  22233            return this.ambientEnclosedTypes;
  22234        };
  22235        ModuleType.prototype.getPublicEnclosedTypes = function () {
  22236            return null;
  22237        };
  22238        ModuleType.prototype.getpublicAmbientEnclosedTypes = function () {
  22239            return null;
  22240        };
  22241        ModuleType.findDynamicModuleNameInHashTable = function findDynamicModuleNameInHashTable(moduleType, members) {
  22242            var moduleName = null;
  22243            members.map(function (key, s, c) {
  22244                if(moduleName == null && !TypeScript.isQuoted(key)) {
  22245                    var symbol = s;
  22246                    var type = symbol.getType();
  22247                    if(type == moduleType) {
  22248                        moduleName = {
  22249                            name: key,
  22250                            symbol: symbol
  22251                        };
  22252                    }
  22253                }
  22254            }, null);
  22255            return moduleName;
  22256        }
  22257        ModuleType.prototype.findDynamicModuleName = function (moduleType) {
  22258            var moduleName = null;
  22259            moduleName = ModuleType.findDynamicModuleNameInHashTable(moduleType, this.members.allMembers);
  22260            if(moduleName == null) {
  22261                moduleName = ModuleType.findDynamicModuleNameInHashTable(moduleType, this.ambientMembers.allMembers);
  22262            }
  22263            return moduleName;
  22264        };
  22265        return ModuleType;
  22266    })(Type);
  22267    TypeScript.ModuleType = ModuleType;    
  22268    var TypeLink = (function () {
  22269        function TypeLink() {
  22270            this.type = null;
  22271            this.ast = null;
  22272        }
  22273        return TypeLink;
  22274    })();
  22275    TypeScript.TypeLink = TypeLink;    
  22276    function getTypeLink(ast, checker, autoVar) {
  22277        var result = new TypeLink();
  22278        result.ast = ast;
  22279        if((ast == null) && (autoVar)) {
  22280            result.type = checker.anyType;
  22281        } else {
  22282            result.type = null;
  22283        }
  22284        return result;
  22285    }
  22286    TypeScript.getTypeLink = getTypeLink;
  22287 })(TypeScript || (TypeScript = {}));
  22288 var TypeScript;
  22289 (function (TypeScript) {
  22290    function stripQuotes(str) {
  22291        return str.replace("\"", "").replace("'", "").replace("'", "").replace("\"", "");
  22292    }
  22293    TypeScript.stripQuotes = stripQuotes;
  22294    function isQuoted(str) {
  22295        return str.indexOf("\"") != -1 || str.indexOf("'") != -1 || str.indexOf("'") != -1 || str.indexOf("\"") != -1;
  22296    }
  22297    TypeScript.isQuoted = isQuoted;
  22298    function quoteStr(str) {
  22299        return "\"" + str + "\"";
  22300    }
  22301    TypeScript.quoteStr = quoteStr;
  22302    function swapQuotes(str) {
  22303        if(str.indexOf("\"") != -1) {
  22304            str = str.replace("\"", "'");
  22305            str = str.replace("\"", "'");
  22306        } else {
  22307            str = str.replace("'", "\"");
  22308            str = str.replace("'", "\"");
  22309        }
  22310        return str;
  22311    }
  22312    TypeScript.swapQuotes = swapQuotes;
  22313    function switchToForwardSlashes(path) {
  22314        return path.replace(/\\/g, "/");
  22315    }
  22316    TypeScript.switchToForwardSlashes = switchToForwardSlashes;
  22317    function trimModName(modName) {
  22318        if(modName.length > 6 && modName.substring(modName.length - 6, modName.length) == ".d.str") {
  22319            return modName.substring(0, modName.length - 6);
  22320        }
  22321        if(modName.length > 4 && modName.substring(modName.length - 4, modName.length) == ".str") {
  22322            return modName.substring(0, modName.length - 4);
  22323        }
  22324        if(modName.length > 5 && modName.substring(modName.length - 5, modName.length) == ".d.ts") {
  22325            return modName.substring(0, modName.length - 5);
  22326        }
  22327        if(modName.length > 3 && modName.substring(modName.length - 3, modName.length) == ".ts") {
  22328            return modName.substring(0, modName.length - 3);
  22329        }
  22330        if(modName.length > 3 && modName.substring(modName.length - 3, modName.length) == ".js") {
  22331            return modName.substring(0, modName.length - 3);
  22332        }
  22333        return modName;
  22334    }
  22335    TypeScript.trimModName = trimModName;
  22336    function getDeclareFilePath(fname) {
  22337        return isSTRFile(fname) ? changePathToDSTR(fname) : isTSFile(fname) ? changePathToDTS(fname) : changePathToDTS(fname);
  22338    }
  22339    TypeScript.getDeclareFilePath = getDeclareFilePath;
  22340    function isFileOfExtension(fname, ext) {
  22341        var invariantFname = fname.toLocaleUpperCase();
  22342        var invariantExt = ext.toLocaleUpperCase();
  22343        var extLength = invariantExt.length;
  22344        return invariantFname.length > extLength && invariantFname.substring(invariantFname.length - extLength, invariantFname.length) == invariantExt;
  22345    }
  22346    function isJSFile(fname) {
  22347        return isFileOfExtension(fname, ".js");
  22348    }
  22349    TypeScript.isJSFile = isJSFile;
  22350    function isSTRFile(fname) {
  22351        return isFileOfExtension(fname, ".str");
  22352    }
  22353    TypeScript.isSTRFile = isSTRFile;
  22354    function isTSFile(fname) {
  22355        return isFileOfExtension(fname, ".ts");
  22356    }
  22357    TypeScript.isTSFile = isTSFile;
  22358    function isDSTRFile(fname) {
  22359        return isFileOfExtension(fname, ".d.str");
  22360    }
  22361    TypeScript.isDSTRFile = isDSTRFile;
  22362    function isDTSFile(fname) {
  22363        return isFileOfExtension(fname, ".d.ts");
  22364    }
  22365    TypeScript.isDTSFile = isDTSFile;
  22366    function getPrettyName(modPath, quote, treatAsFileName) {
  22367        if (typeof quote === "undefined") { quote = true; }
  22368        if (typeof treatAsFileName === "undefined") { treatAsFileName = false; }
  22369        var modName = treatAsFileName ? switchToForwardSlashes(modPath) : trimModName(stripQuotes(modPath));
  22370        var components = this.getPathComponents(modName);
  22371        return components.length ? (quote ? quoteStr(components[components.length - 1]) : components[components.length - 1]) : modPath;
  22372    }
  22373    TypeScript.getPrettyName = getPrettyName;
  22374    function getPathComponents(path) {
  22375        return path.split("/");
  22376    }
  22377    TypeScript.getPathComponents = getPathComponents;
  22378    function getRelativePathToFixedPath(fixedModFilePath, absoluteModPath) {
  22379        absoluteModPath = switchToForwardSlashes(absoluteModPath);
  22380        var modComponents = this.getPathComponents(absoluteModPath);
  22381        var fixedModComponents = this.getPathComponents(fixedModFilePath);
  22382        var joinStartIndex = 0;
  22383        for(; joinStartIndex < modComponents.length && joinStartIndex < fixedModComponents.length; joinStartIndex++) {
  22384            if(fixedModComponents[joinStartIndex] != modComponents[joinStartIndex]) {
  22385                break;
  22386            }
  22387        }
  22388        if(joinStartIndex != 0) {
  22389            var relativePath = "";
  22390            var relativePathComponents = modComponents.slice(joinStartIndex, modComponents.length);
  22391            for(; joinStartIndex < fixedModComponents.length; joinStartIndex++) {
  22392                if(fixedModComponents[joinStartIndex] != "") {
  22393                    relativePath = relativePath + "../";
  22394                }
  22395            }
  22396            return relativePath + relativePathComponents.join("/");
  22397        }
  22398        return absoluteModPath;
  22399    }
  22400    TypeScript.getRelativePathToFixedPath = getRelativePathToFixedPath;
  22401    function quoteBaseName(modPath) {
  22402        var modName = trimModName(stripQuotes(modPath));
  22403        var path = getRootFilePath(modName);
  22404        if(path == "") {
  22405            return modPath;
  22406        } else {
  22407            var components = modName.split(path);
  22408            var fileIndex = components.length > 1 ? 1 : 0;
  22409            return quoteStr(components[fileIndex]);
  22410        }
  22411    }
  22412    TypeScript.quoteBaseName = quoteBaseName;
  22413    function changePathToSTR(modPath) {
  22414        return trimModName(stripQuotes(modPath)) + ".str";
  22415    }
  22416    TypeScript.changePathToSTR = changePathToSTR;
  22417    function changePathToDSTR(modPath) {
  22418        return trimModName(stripQuotes(modPath)) + ".d.str";
  22419    }
  22420    TypeScript.changePathToDSTR = changePathToDSTR;
  22421    function changePathToTS(modPath) {
  22422        return trimModName(stripQuotes(modPath)) + ".ts";
  22423    }
  22424    TypeScript.changePathToTS = changePathToTS;
  22425    function changePathToDTS(modPath) {
  22426        return trimModName(stripQuotes(modPath)) + ".d.ts";
  22427    }
  22428    TypeScript.changePathToDTS = changePathToDTS;
  22429    function isRelative(path) {
  22430        return path.charAt(0) == ".";
  22431    }
  22432    TypeScript.isRelative = isRelative;
  22433    function isRooted(path) {
  22434        return path.charAt(0) == "\\" || path.charAt(0) == "/" || (path.indexOf(":\\") != -1) || (path.indexOf(":/") != -1);
  22435    }
  22436    TypeScript.isRooted = isRooted;
  22437    function getRootFilePath(outFname) {
  22438        if(outFname == "") {
  22439            return outFname;
  22440        } else {
  22441            var isPath = outFname.indexOf("/") != -1;
  22442            return isPath ? filePath(outFname) : "";
  22443        }
  22444    }
  22445    TypeScript.getRootFilePath = getRootFilePath;
  22446    function filePathComponents(fullPath) {
  22447        fullPath = switchToForwardSlashes(fullPath);
  22448        var components = getPathComponents(fullPath);
  22449        return components.slice(0, components.length - 1);
  22450    }
  22451    TypeScript.filePathComponents = filePathComponents;
  22452    function filePath(fullPath) {
  22453        var path = filePathComponents(fullPath);
  22454        return path.join("/") + "/";
  22455    }
  22456    TypeScript.filePath = filePath;
  22457    function normalizeURL(url) {
  22458        var hostDomainAndPortRegex = /^(https?:\/\/[\-\w\.]+(:\d+)?\/)(.*)$/i;
  22459        var matches = hostDomainAndPortRegex.exec(url);
  22460        if(matches) {
  22461            var hostDomainAndPort = matches[1];
  22462            var actualPath = matches[3];
  22463            return hostDomainAndPort + normalizePath(actualPath);
  22464        }
  22465        return normalizePath(url);
  22466    }
  22467    TypeScript.normalizeURL = normalizeURL;
  22468    TypeScript.pathNormalizeRegExp = /\//g;
  22469    function normalizePath(path) {
  22470        path = switchToForwardSlashes(path);
  22471        var startedWithSep = path.charAt(0) === "/";
  22472        var parts = this.getPathComponents(path);
  22473        for(var i = 0; i < parts.length; i++) {
  22474            if(parts[i] === "." || parts[i] === "") {
  22475                parts.splice(i, 1);
  22476                i--;
  22477            }
  22478            if(i > 0 && parts[i] === ".." && parts[i - 1] !== "..") {
  22479                parts.splice(i - 1, 2);
  22480                i -= 2;
  22481            }
  22482        }
  22483        return (startedWithSep ? "/" : "") + parts.join("/");
  22484    }
  22485    TypeScript.normalizePath = normalizePath;
  22486    function normalizeImportPath(path) {
  22487        return normalizePath(path);
  22488    }
  22489    TypeScript.normalizeImportPath = normalizeImportPath;
  22490 })(TypeScript || (TypeScript = {}));
  22491 var TypeScript;
  22492 (function (TypeScript) {
  22493    var SourceUnit = (function () {
  22494        function SourceUnit(path, content) {
  22495            this.path = path;
  22496            this.content = content;
  22497            this.referencedFiles = null;
  22498        }
  22499        SourceUnit.prototype.getText = function (start, end) {
  22500            return this.content.substring(start, end);
  22501        };
  22502        SourceUnit.prototype.getLength = function () {
  22503            return this.content.length;
  22504        };
  22505        return SourceUnit;
  22506    })();
  22507    TypeScript.SourceUnit = SourceUnit;    
  22508    var CompilationEnvironment = (function () {
  22509        function CompilationEnvironment(compilationSettings, ioHost) {
  22510            this.compilationSettings = compilationSettings;
  22511            this.ioHost = ioHost;
  22512            this.residentCode = [];
  22513            this.code = [];
  22514        }
  22515        return CompilationEnvironment;
  22516    })();
  22517    TypeScript.CompilationEnvironment = CompilationEnvironment;    
  22518    var CodeResolver = (function () {
  22519        function CodeResolver(environment) {
  22520            this.environment = environment;
  22521            this.visited = {
  22522            };
  22523        }
  22524        CodeResolver.prototype.resolveCode = function (referencePath, parentPath, performSearch, resolutionDispatcher) {
  22525            var resolvedFile = {
  22526                content: "",
  22527                path: referencePath
  22528            };
  22529            var ioHost = this.environment.ioHost;
  22530            var isRelativePath = TypeScript.isRelative(referencePath);
  22531            var isRootedPath = isRelativePath ? false : TypeScript.isRooted(referencePath);
  22532            var normalizedPath = isRelativePath ? ioHost.resolvePath(parentPath + "/" + referencePath) : (isRootedPath || !parentPath || performSearch ? referencePath : parentPath + "/" + referencePath);
  22533            if(!TypeScript.isSTRFile(normalizedPath) && !TypeScript.isTSFile(normalizedPath)) {
  22534                normalizedPath += ".ts";
  22535            }
  22536            normalizedPath = TypeScript.switchToForwardSlashes(TypeScript.stripQuotes(normalizedPath));
  22537            var absoluteModuleID = this.environment.compilationSettings.useCaseSensitiveFileResolution ? normalizedPath : normalizedPath.toLocaleUpperCase();
  22538            if(!this.visited[absoluteModuleID]) {
  22539                if(isRelativePath || isRootedPath || !performSearch) {
  22540                    try  {
  22541                        TypeScript.CompilerDiagnostics.debugPrint("   Reading code from " + normalizedPath);
  22542                        try  {
  22543                            resolvedFile.content = ioHost.readFile(normalizedPath);
  22544                        } catch (err) {
  22545                            try  {
  22546                                if(TypeScript.isSTRFile(normalizedPath)) {
  22547                                    normalizedPath = TypeScript.changePathToTS(normalizedPath);
  22548                                } else {
  22549                                    if(TypeScript.isTSFile(normalizedPath)) {
  22550                                        normalizedPath = TypeScript.changePathToSTR(normalizedPath);
  22551                                    }
  22552                                }
  22553                                TypeScript.CompilerDiagnostics.debugPrint("   Reading code from " + normalizedPath);
  22554                                resolvedFile.content = ioHost.readFile(normalizedPath);
  22555                            } catch (err) {
  22556                                normalizedPath = TypeScript.changePathToDSTR(normalizedPath);
  22557                                TypeScript.CompilerDiagnostics.debugPrint("   Reading code from " + normalizedPath);
  22558                                try  {
  22559                                    resolvedFile.content = ioHost.readFile(normalizedPath);
  22560                                } catch (err) {
  22561                                    normalizedPath = TypeScript.changePathToDTS(normalizedPath);
  22562                                    TypeScript.CompilerDiagnostics.debugPrint("   Reading code from " + normalizedPath);
  22563                                    resolvedFile.content = ioHost.readFile(normalizedPath);
  22564                                }
  22565                            }
  22566                        }
  22567                        TypeScript.CompilerDiagnostics.debugPrint("   Found code at " + normalizedPath);
  22568                        resolvedFile.path = normalizedPath;
  22569                        this.visited[absoluteModuleID] = true;
  22570                    } catch (err) {
  22571                        TypeScript.CompilerDiagnostics.debugPrint("   Did not find code for " + referencePath);
  22572                    }
  22573                } else {
  22574                    resolvedFile = ioHost.findFile(parentPath, normalizedPath);
  22575                    if(!resolvedFile) {
  22576                        if(TypeScript.isSTRFile(normalizedPath)) {
  22577                            normalizedPath = TypeScript.changePathToTS(normalizedPath);
  22578                        } else {
  22579                            if(TypeScript.isTSFile(normalizedPath)) {
  22580                                normalizedPath = TypeScript.changePathToSTR(normalizedPath);
  22581                            }
  22582                        }
  22583                        resolvedFile = ioHost.findFile(parentPath, normalizedPath);
  22584                    }
  22585                    if(!resolvedFile) {
  22586                        normalizedPath = TypeScript.changePathToDTS(normalizedPath);
  22587                        resolvedFile = ioHost.findFile(parentPath, normalizedPath);
  22588                        if(!resolvedFile) {
  22589                            normalizedPath = TypeScript.changePathToDSTR(normalizedPath);
  22590                            resolvedFile = ioHost.findFile(parentPath, normalizedPath);
  22591                        }
  22592                    }
  22593                    if(resolvedFile) {
  22594                        resolvedFile.path = TypeScript.switchToForwardSlashes(TypeScript.stripQuotes(resolvedFile.path));
  22595                        TypeScript.CompilerDiagnostics.debugPrint(referencePath + " resolved to: " + resolvedFile.path);
  22596                        resolvedFile.content = resolvedFile.content;
  22597                        this.visited[absoluteModuleID] = true;
  22598                    } else {
  22599                        TypeScript.CompilerDiagnostics.debugPrint("Could not find " + referencePath);
  22600                    }
  22601                }
  22602                if(resolvedFile && resolvedFile.content) {
  22603                    var rootDir = ioHost.dirName(resolvedFile.path);
  22604                    var sourceUnit = new SourceUnit(resolvedFile.path, resolvedFile.content);
  22605                    var preProcessedFileInfo = TypeScript.preProcessFile(sourceUnit, this.environment.compilationSettings);
  22606                    sourceUnit.referencedFiles = preProcessedFileInfo.referencedFiles;
  22607                    for(var i = 0; i < preProcessedFileInfo.referencedFiles.length; i++) {
  22608                        var referencedFile = preProcessedFileInfo.referencedFiles[i];
  22609                        var normalizedPath = TypeScript.isRooted(referencedFile.path) ? referencedFile.path : rootDir + "/" + referencedFile.path;
  22610                        normalizedPath = ioHost.resolvePath(normalizedPath);
  22611                        if(referencePath == normalizedPath) {
  22612                            resolutionDispatcher.postResolutionError(normalizedPath, "File contains reference to itself", null);
  22613                            continue;
  22614                        }
  22615                        this.resolveCode(referencedFile.path, rootDir, false, resolutionDispatcher);
  22616                    }
  22617                    for(var i = 0; i < preProcessedFileInfo.importedFiles.length; i++) {
  22618                        this.resolveCode(preProcessedFileInfo.importedFiles[i].path, rootDir, true, resolutionDispatcher);
  22619                    }
  22620                    resolutionDispatcher.postResolution(sourceUnit.path, sourceUnit);
  22621                }
  22622            }
  22623        };
  22624        return CodeResolver;
  22625    })();
  22626    TypeScript.CodeResolver = CodeResolver;    
  22627 })(TypeScript || (TypeScript = {}));
  22628 var TypeScript;
  22629 (function (TypeScript) {
  22630    var StyleSettings = (function () {
  22631        function StyleSettings() {
  22632            this.bitwise = false;
  22633            this.blockInCompoundStmt = false;
  22634            this.eqeqeq = false;
  22635            this.forin = false;
  22636            this.emptyBlocks = true;
  22637            this.newMustBeUsed = false;
  22638            this.requireSemi = false;
  22639            this.assignmentInCond = false;
  22640            this.eqnull = false;
  22641            this.evalOK = true;
  22642            this.innerScopeDeclEscape = true;
  22643            this.funcInLoop = true;
  22644            this.reDeclareLocal = true;
  22645            this.literalSubscript = true;
  22646            this.implicitAny = false;
  22647        }
  22648        StyleSettings.prototype.setOption = function (opt, val) {
  22649            var optExists = this[opt];
  22650            if(optExists !== undefined) {
  22651                this[opt] = val;
  22652                return true;
  22653            } else {
  22654                return false;
  22655            }
  22656        };
  22657        StyleSettings.prototype.parseOptions = function (str) {
  22658            var opts = str.split(";");
  22659            for(var i = 0, len = opts.length; i < len; i++) {
  22660                var opt = opts[i];
  22661                var val = true;
  22662                var colonIndex = opt.lastIndexOf(":");
  22663                if(colonIndex >= 0) {
  22664                    var valStr = opt.substring(colonIndex + 1);
  22665                    opt = opt.substring(0, colonIndex);
  22666                    if(valStr == "off") {
  22667                        val = false;
  22668                    }
  22669                }
  22670                if(!this.setOption(opt, val)) {
  22671                    return false;
  22672                }
  22673            }
  22674            return true;
  22675        };
  22676        return StyleSettings;
  22677    })();
  22678    TypeScript.StyleSettings = StyleSettings;    
  22679    var CompilationSettings = (function () {
  22680        function CompilationSettings() {
  22681            this.styleSettings = new StyleSettings();
  22682            this.propagateConstants = false;
  22683            this.minWhitespace = false;
  22684            this.parseOnly = false;
  22685            this.errorRecovery = false;
  22686            this.emitComments = false;
  22687            this.watch = false;
  22688            this.exec = false;
  22689            this.resolve = true;
  22690            this.controlFlow = false;
  22691            this.printControlFlow = false;
  22692            this.controlFlowUseDef = false;
  22693            this.errorOnWith = true;
  22694            this.preprocess = true;
  22695            this.canCallDefinitionSignature = false;
  22696            this.inferPropertiesFromThisAssignment = false;
  22697            this.useDefaultLib = true;
  22698            this.codeGenTarget = TypeScript.CodeGenTarget.ES3;
  22699            this.moduleGenTarget = TypeScript.ModuleGenTarget.Synchronous;
  22700            this.outputOption = "";
  22701            this.mapSourceFiles = false;
  22702            this.generateDeclarationFiles = false;
  22703            this.useCaseSensitiveFileResolution = false;
  22704        }
  22705        CompilationSettings.prototype.setStyleOptions = function (str) {
  22706            this.styleSettings.parseOptions(str);
  22707        };
  22708        return CompilationSettings;
  22709    })();
  22710    TypeScript.CompilationSettings = CompilationSettings;    
  22711    function getFileReferenceFromReferencePath(comment) {
  22712        var referencesRegEx = /^(\/\/\/\s*<reference\s+path=)('|")(.+?)\2\s*(static=('|")(.+?)\2\s*)*\/>/igm;
  22713        var match = referencesRegEx.exec(comment);
  22714        if(match) {
  22715            var path = TypeScript.normalizePath(match[3]);
  22716            var adjustedPath = TypeScript.normalizePath(path);
  22717            var isResident = match.length >= 7 && match[6] == "true";
  22718            if(isResident) {
  22719                TypeScript.CompilerDiagnostics.debugPrint(path + " is resident");
  22720            }
  22721            return {
  22722                minChar: 0,
  22723                limChar: 0,
  22724                path: TypeScript.switchToForwardSlashes(adjustedPath),
  22725                isResident: isResident
  22726            };
  22727        } else {
  22728            return null;
  22729        }
  22730    }
  22731    function getAdditionalDependencyPath(comment) {
  22732        var amdDependencyRegEx = /^(\/\/\/\s*<amd-dependency\s+path=)('|")(.+?)\2\s*(static=('|")(.+?)\2\s*)*\/>/igm;
  22733        var match = amdDependencyRegEx.exec(comment);
  22734        if(match) {
  22735            var path = match[3];
  22736            return path;
  22737        } else {
  22738            return null;
  22739        }
  22740    }
  22741    TypeScript.getAdditionalDependencyPath = getAdditionalDependencyPath;
  22742    function getImplicitImport(comment) {
  22743        var implicitImportRegEx = /^(\/\/\/\s*<implicit-import\s*)*\/>/igm;
  22744        var match = implicitImportRegEx.exec(comment);
  22745        if(match) {
  22746            return true;
  22747        }
  22748        return false;
  22749    }
  22750    TypeScript.getImplicitImport = getImplicitImport;
  22751    function getStyleSettings(comment, styleSettings) {
  22752        var styleRegEx = /^(\/\/\/\s*<style\s+)(([a-zA-Z])+=('|").+('|"))\s*\/>/igm;
  22753        var settings = styleRegEx.exec(comment);
  22754        if(settings) {
  22755            var settingsRegEx = /^([a-zA-Z]+=['"]on['|"])/igm;
  22756            settings = settingsRegEx.exec(settings[2]);
  22757            if(settings) {
  22758                for(var i = 0; i < settings.length; i++) {
  22759                    var setting = (settings[i]).split("=");
  22760                    var on = "\"on\"";
  22761                    switch(setting[0]) {
  22762                        case "blockInCompoundStmt": {
  22763                            styleSettings.blockInCompoundStmt = setting[1] == on;
  22764                            break;
  22765 
  22766                        }
  22767                        case "eqeqeq": {
  22768                            styleSettings.eqeqeq = setting[1] == on;
  22769                            break;
  22770 
  22771                        }
  22772                        case "forin": {
  22773                            styleSettings.forin = setting[1] == on;
  22774                            break;
  22775 
  22776                        }
  22777                        case "emptyBlocks": {
  22778                            styleSettings.emptyBlocks = setting[1] == on;
  22779                            break;
  22780 
  22781                        }
  22782                        case "newMustBeUsed": {
  22783                            styleSettings.newMustBeUsed = setting[1] == on;
  22784                            break;
  22785 
  22786                        }
  22787                        case "requireSemi": {
  22788                            styleSettings.requireSemi = setting[1] == on;
  22789                            break;
  22790 
  22791                        }
  22792                        case "assignmentInCond": {
  22793                            styleSettings.assignmentInCond = setting[1] == on;
  22794                            break;
  22795 
  22796                        }
  22797                        case "eqnull": {
  22798                            styleSettings.eqnull = setting[1] == on;
  22799                            break;
  22800 
  22801                        }
  22802                        case "evalOK": {
  22803                            styleSettings.evalOK = setting[1] == on;
  22804                            break;
  22805 
  22806                        }
  22807                        case "innerScopeDeclEscape": {
  22808                            styleSettings.innerScopeDeclEscape = setting[1] == on;
  22809                            break;
  22810 
  22811                        }
  22812                        case "funcInLoop": {
  22813                            styleSettings.funcInLoop = setting[1] == on;
  22814                            break;
  22815 
  22816                        }
  22817                        case "reDeclareLocal": {
  22818                            styleSettings.reDeclareLocal = setting[1] == on;
  22819                            break;
  22820 
  22821                        }
  22822                        case "literalSubscript": {
  22823                            styleSettings.literalSubscript = setting[1] == on;
  22824                            break;
  22825 
  22826                        }
  22827                        case "implicitAny": {
  22828                            styleSettings.implicitAny = setting[1] == on;
  22829                            break;
  22830 
  22831                        }
  22832                    }
  22833                }
  22834            }
  22835        }
  22836    }
  22837    TypeScript.getStyleSettings = getStyleSettings;
  22838    function getReferencedFiles(sourceText) {
  22839        var preProcessInfo = preProcessFile(sourceText, null, false);
  22840        return preProcessInfo.referencedFiles;
  22841    }
  22842    TypeScript.getReferencedFiles = getReferencedFiles;
  22843    function preProcessFile(sourceText, options, readImportFiles) {
  22844        if (typeof options === "undefined") { options = new CompilationSettings(); }
  22845        if (typeof readImportFiles === "undefined") { readImportFiles = true; }
  22846        var scanner = new TypeScript.Scanner();
  22847        scanner.resetComments();
  22848        scanner.setSourceText(sourceText, TypeScript.LexMode.File);
  22849        var tok = scanner.scan();
  22850        var comments = [];
  22851        var comment = null;
  22852        var leftCurlies = [];
  22853        var settings = options;
  22854        var referencedFiles = [];
  22855        var importedFiles = [];
  22856        var isLibFile = false;
  22857        while(tok.tokenId != TypeScript.TokenID.EndOfFile) {
  22858            if(readImportFiles && tok.tokenId == TypeScript.TokenID.Import) {
  22859                tok = scanner.scan();
  22860                if(tok.tokenId == TypeScript.TokenID.Identifier || TypeScript.convertTokToID(tok, false)) {
  22861                    tok = scanner.scan();
  22862                    if(tok.tokenId == TypeScript.TokenID.Equals) {
  22863                        tok = scanner.scan();
  22864                        if(tok.tokenId == TypeScript.TokenID.Module) {
  22865                            tok = scanner.scan();
  22866                            if(tok.tokenId == TypeScript.TokenID.OpenParen) {
  22867                                tok = scanner.scan();
  22868                                if(tok.tokenId == TypeScript.TokenID.StringLiteral) {
  22869                                    var ref = {
  22870                                        minChar: scanner.startPos,
  22871                                        limChar: scanner.pos,
  22872                                        path: TypeScript.stripQuotes(TypeScript.switchToForwardSlashes(tok.getText())),
  22873                                        isResident: false
  22874                                    };
  22875                                    importedFiles.push(ref);
  22876                                }
  22877                            }
  22878                        }
  22879                    }
  22880                }
  22881            }
  22882            if(tok.tokenId == TypeScript.TokenID.OpenBrace) {
  22883                leftCurlies.push(tok);
  22884            }
  22885            if(tok.tokenId == TypeScript.TokenID.CloseBrace) {
  22886                leftCurlies.pop();
  22887            }
  22888            tok = scanner.scan();
  22889        }
  22890        comments = scanner.getComments();
  22891        for(var iComment = 0; iComment < comments.length; iComment++) {
  22892            comment = comments[iComment];
  22893            if(!comment.isBlock) {
  22894                var referencedCode = getFileReferenceFromReferencePath(comment.getText());
  22895                if(referencedCode) {
  22896                    referencedCode.minChar = comment.startPos;
  22897                    referencedCode.limChar = referencedCode.minChar + comment.value.length;
  22898                    referencedFiles.push(referencedCode);
  22899                }
  22900                if(settings) {
  22901                    getStyleSettings(comment.getText(), settings.styleSettings);
  22902                    var isNoLibRegex = /^(\/\/\/\s*<reference\s+no-default-lib=)('|")(.+?)\2\s*\/>/igm;
  22903                    var isNoLibMatch = isNoLibRegex.exec(comment.getText());
  22904                    if(isNoLibMatch) {
  22905                        isLibFile = (isNoLibMatch[3] == "true");
  22906                    }
  22907                }
  22908            }
  22909        }
  22910        return {
  22911            settings: settings,
  22912            referencedFiles: referencedFiles,
  22913            importedFiles: importedFiles,
  22914            isLibFile: isLibFile
  22915        };
  22916    }
  22917    TypeScript.preProcessFile = preProcessFile;
  22918 })(TypeScript || (TypeScript = {}));
  22919 var TypeScript;
  22920 (function (TypeScript) {
  22921    var IncrementalParser = (function () {
  22922        function IncrementalParser(logger) {
  22923            this.logger = logger;
  22924            this.astLogger = new TypeScript.AstLogger(this.logger);
  22925        }
  22926        IncrementalParser.prototype.getEnclosingScopeContextIfSingleScopeEdit = function (previousScript, scriptId, newSourceText, editRange) {
  22927            this.logger.log("checkEditsInsideSingleScope(\"" + scriptId + "\")");
  22928            if(editRange === null) {
  22929                throw new Error("editRange should be valid");
  22930            }
  22931            if(editRange.isUnknown()) {
  22932                this.logger.log("  Bailing out because edit range is unknown");
  22933                return null;
  22934            }
  22935            var scope1 = TypeScript.findEnclosingScopeAt(this.logger, previousScript, newSourceText, editRange.minChar, false);
  22936            var scope2 = TypeScript.findEnclosingScopeAt(this.logger, previousScript, newSourceText, editRange.limChar, false);
  22937            if(scope1 == null || scope2 == null) {
  22938                this.logger.log("  Bailing out because containing scopes cannot be determined");
  22939                return null;
  22940            }
  22941            if(scope1.scopeStartAST !== scope2.scopeStartAST) {
  22942                this.logger.log("  Bailing out because edit overlaps 2 disctint scopes");
  22943                return null;
  22944            }
  22945            var newScopeLength = scope1.scopeStartAST.limChar - scope1.scopeStartAST.minChar + editRange.delta;
  22946            if(newScopeLength <= 0) {
  22947                this.logger.log("  Bailing out because scope has been entirely removed from new source text");
  22948                return null;
  22949            }
  22950            return scope1;
  22951        };
  22952        IncrementalParser.prototype.attemptIncrementalUpdateUnit = function (previousScript, scriptId, newSourceText, editRange) {
  22953            this.logger.log("attemptIncrementalUpdateUnit(\"" + scriptId + "\")");
  22954            if(editRange === null) {
  22955                throw new Error("editRange should be valid");
  22956            }
  22957            var scope1 = this.getEnclosingScopeContextIfSingleScopeEdit(previousScript, scriptId, newSourceText, editRange);
  22958            if(scope1 === null) {
  22959                return null;
  22960            }
  22961            var newScopeLength = scope1.scopeStartAST.limChar - scope1.scopeStartAST.minChar + editRange.delta;
  22962            if(newScopeLength >= newSourceText.getLength() / 2) {
  22963                this.logger.log("  Bailing out because range of scope to reparse (" + newScopeLength + " characters) is greater than half the size of the source text");
  22964                return null;
  22965            }
  22966            var parseErrors = [];
  22967            var errorCapture = function (minChar, charLen, message, unitIndex) {
  22968                parseErrors.push(new TypeScript.ErrorEntry(unitIndex, minChar, minChar + charLen, message));
  22969            };
  22970            var quickParseResult = TypeScript.quickParse(this.logger, scope1.scopeStartAST, newSourceText, scope1.scopeStartAST.minChar, scope1.scopeStartAST.minChar + newScopeLength, errorCapture);
  22971            if(quickParseResult.endLexState != TypeScript.LexState.Start) {
  22972                this.logger.log("  Bailing out because scope contains unterminated comment");
  22973                return null;
  22974            }
  22975            var scriptFragment = quickParseResult.Script;
  22976            if(scriptFragment.vars.members.length !== 0) {
  22977                this.logger.log("  Bailing out because new source text defines variables");
  22978                return null;
  22979            }
  22980            if(scriptFragment.bod.members.length !== 1) {
  22981                this.logger.log("  Bailing out because new source text defines more than one scope (or none)");
  22982                return null;
  22983            }
  22984            var oldScope = scope1.scopeStartAST;
  22985            var newScope = scriptFragment.bod.members[0];
  22986            if(oldScope.nodeType != newScope.nodeType) {
  22987                this.logger.log("  Bailing out because new source text does not define the same scope type as the existing scope");
  22988                return null;
  22989            }
  22990            if(!(oldScope).leftCurlyCount || !(oldScope).rightCurlyCount) {
  22991                this.logger.log("  Bailing out because sopce doesn't have left/right curly count");
  22992                return null;
  22993            }
  22994            if((oldScope).leftCurlyCount !== (newScope).leftCurlyCount) {
  22995                this.logger.log("  Bailing out because new source text contains more (or fewer) left curly braces");
  22996                return null;
  22997            }
  22998            if((oldScope).rightCurlyCount !== (newScope).rightCurlyCount) {
  22999                this.logger.log("  Bailing out because new source text contains more (or fewer) right curly braces");
  23000                return null;
  23001            }
  23002            if(newScope.minChar !== 0) {
  23003                this.logger.log("  Bailing out because new function declaration does not start at position 0");
  23004                return null;
  23005            }
  23006            if(newScope.limChar !== newScopeLength) {
  23007                this.logger.log("  Bailing out because new function declaration does not end at the new end position");
  23008                return null;
  23009            }
  23010            return TypeScript.UpdateUnitResult.singleScopeEdits(previousScript, scriptFragment, oldScope, newScope, editRange, parseErrors);
  23011        };
  23012        IncrementalParser.prototype.mergeTrees = function (updateResult) {
  23013            var _this = this;
  23014            TypeScript.timeFunction(this.logger, "mergeTrees()", function () {
  23015                var editRange = new TypeScript.ScriptEditRange(updateResult.scope1.minChar, updateResult.scope1.limChar, updateResult.editRange.delta);
  23016                _this.applyDeltaPosition(updateResult.script1, editRange.limChar, editRange.delta);
  23017                _this.applyDeltaPosition(updateResult.script2, 0, editRange.minChar);
  23018                _this.mergeLocationInfo(updateResult.script1, updateResult.script2, editRange);
  23019                _this.replaceAST(updateResult.script1, updateResult.scope1, updateResult.scope2);
  23020            });
  23021        };
  23022        IncrementalParser.prototype.replaceAST = function (script, oldAst, newAst) {
  23023            var _this = this;
  23024            var pre = function (cur, parent, walker) {
  23025                if(cur === oldAst) {
  23026                    newAst.preComments = cur.preComments;
  23027                    newAst.postComments = cur.postComments;
  23028                    _this.logger.log("replaced old AST node with new one in script AST");
  23029                    walker.options.stopWalk();
  23030                    return newAst;
  23031                }
  23032                if(TypeScript.isValidAstNode(cur)) {
  23033                    if(cur.limChar < oldAst.minChar || cur.minChar > oldAst.limChar) {
  23034                        walker.options.goChildren = false;
  23035                    }
  23036                }
  23037                return cur;
  23038            };
  23039            TypeScript.getAstWalkerFactory().walk(script, pre);
  23040        };
  23041        IncrementalParser.prototype.mergeLocationInfo = function (script, partial, editRange) {
  23042            var lineMap1 = script.locationInfo.lineMap;
  23043            var lineMap2 = partial.locationInfo.lineMap;
  23044            if(this.logger.information()) {
  23045                this.logger.log("lineMap1 (before):");
  23046                this.astLogger.logLinemap(lineMap1);
  23047                this.logger.log("lineMap2 (quick parse):");
  23048                this.astLogger.logLinemap(lineMap2);
  23049                this.logger.log("EditRange=" + editRange);
  23050            }
  23051            var i1 = 2;
  23052            var i2 = 2;
  23053            var len1 = lineMap1.length;
  23054            var len2 = lineMap2.length;
  23055            while(i1 < len1) {
  23056                if(lineMap1[i1] <= editRange.minChar) {
  23057                    i1++;
  23058                } else {
  23059                    if(lineMap1[i1] >= editRange.limChar) {
  23060                        lineMap1[i1] += editRange.delta;
  23061                        i1++;
  23062                    } else {
  23063                        if(i2 < len2) {
  23064                            lineMap1.splice(i1, 0, lineMap2[i2] + editRange.minChar);
  23065                            i1++;
  23066                            len1++;
  23067                            i2++;
  23068                        } else {
  23069                            lineMap1.splice(i1, 1);
  23070                            len1--;
  23071                        }
  23072                    }
  23073                }
  23074            }
  23075            if(i2 < len2) {
  23076                if(lineMap1[len1 - 1] >= (lineMap2[i2] + editRange.minChar)) {
  23077                    i1 = 2;
  23078                    while(i1 < len1 && i2 < len2) {
  23079                        if(lineMap1[i1] < (lineMap2[i2] + editRange.minChar)) {
  23080                            i1++;
  23081                        } else {
  23082                            lineMap1.splice(i1, 0, lineMap2[i2] + editRange.minChar);
  23083                            i1++;
  23084                            len1++;
  23085                            i2++;
  23086                        }
  23087                    }
  23088                }
  23089                for(; i2 < len2; i2++) {
  23090                    lineMap1.push(lineMap2[i2] + editRange.minChar);
  23091                }
  23092            }
  23093            if(this.logger.information()) {
  23094                this.logger.log("lineMap1 (after merge):");
  23095                this.astLogger.logLinemap(lineMap1);
  23096            }
  23097        };
  23098        IncrementalParser.prototype.applyDeltaPosition = function (ast, start, delta) {
  23099            var applyDelta = function (ast) {
  23100                if(ast.minChar !== -1 && ast.minChar >= start) {
  23101                    ast.minChar += delta;
  23102                }
  23103                if(ast.limChar !== -1 && ast.limChar >= start) {
  23104                    ast.limChar += delta;
  23105                }
  23106            };
  23107            var applyDeltaToComments = function (comments) {
  23108                if(comments && comments.length > 0) {
  23109                    for(var i = 0; i < comments.length; i++) {
  23110                        applyDelta(comments[i]);
  23111                    }
  23112                }
  23113            };
  23114            var pre = function (cur, parent, walker) {
  23115                if(cur.limChar !== -1 && cur.limChar < start) {
  23116                    walker.options.goChildren = false;
  23117                }
  23118                applyDelta(cur);
  23119                applyDeltaToComments(cur.preComments);
  23120                applyDeltaToComments(cur.postComments);
  23121                return cur;
  23122            };
  23123            TypeScript.getAstWalkerFactory().walk(ast, pre);
  23124        };
  23125        return IncrementalParser;
  23126    })();
  23127    TypeScript.IncrementalParser = IncrementalParser;    
  23128 })(TypeScript || (TypeScript = {}));
  23129 var TypeScript;
  23130 (function (TypeScript) {
  23131    var DeclFileWriter = (function () {
  23132        function DeclFileWriter(declFile) {
  23133            this.declFile = declFile;
  23134            this.onNewLine = true;
  23135        }
  23136        DeclFileWriter.prototype.Write = function (s) {
  23137            this.declFile.Write(s);
  23138            this.onNewLine = false;
  23139        };
  23140        DeclFileWriter.prototype.WriteLine = function (s) {
  23141            this.declFile.WriteLine(s);
  23142            this.onNewLine = true;
  23143        };
  23144        DeclFileWriter.prototype.Close = function () {
  23145            this.declFile.Close();
  23146        };
  23147        return DeclFileWriter;
  23148    })();
  23149    TypeScript.DeclFileWriter = DeclFileWriter;    
  23150    var DeclarationEmitter = (function () {
  23151        function DeclarationEmitter(checker, emitOptions, errorReporter) {
  23152            this.checker = checker;
  23153            this.emitOptions = emitOptions;
  23154            this.errorReporter = errorReporter;
  23155            this.declFile = null;
  23156            this.indenter = new TypeScript.Indenter();
  23157            this.declarationContainerStack = [];
  23158            this.isDottedModuleName = [];
  23159            this.ignoreCallbackAst = null;
  23160            this.singleDeclFile = null;
  23161            this.varListCount = 0;
  23162        }
  23163        DeclarationEmitter.prototype.getAstDeclarationContainer = function () {
  23164            return this.declarationContainerStack[this.declarationContainerStack.length - 1];
  23165        };
  23166        DeclarationEmitter.prototype.emitDottedModuleName = function () {
  23167            return (this.isDottedModuleName.length == 0) ? false : this.isDottedModuleName[this.isDottedModuleName.length - 1];
  23168        };
  23169        DeclarationEmitter.prototype.setDeclarationFile = function (file) {
  23170            this.declFile = new DeclFileWriter(file);
  23171        };
  23172        DeclarationEmitter.prototype.Close = function () {
  23173            try  {
  23174                this.declFile.Close();
  23175            } catch (ex) {
  23176                this.errorReporter.emitterError(null, ex.message);
  23177            }
  23178        };
  23179        DeclarationEmitter.prototype.emitDeclarations = function (script) {
  23180            TypeScript.AstWalkerWithDetailCallback.walk(script, this);
  23181        };
  23182        DeclarationEmitter.prototype.getIndentString = function (declIndent) {
  23183            if (typeof declIndent === "undefined") { declIndent = false; }
  23184            if(this.emitOptions.minWhitespace) {
  23185                return "";
  23186            } else {
  23187                return this.indenter.getIndent();
  23188            }
  23189        };
  23190        DeclarationEmitter.prototype.emitIndent = function () {
  23191            this.declFile.Write(this.getIndentString());
  23192        };
  23193        DeclarationEmitter.prototype.canEmitSignature = function (declFlags, canEmitGlobalAmbientDecl, useDeclarationContainerTop) {
  23194            if (typeof canEmitGlobalAmbientDecl === "undefined") { canEmitGlobalAmbientDecl = true; }
  23195            if (typeof useDeclarationContainerTop === "undefined") { useDeclarationContainerTop = true; }
  23196            var container;
  23197            if(useDeclarationContainerTop) {
  23198                container = this.getAstDeclarationContainer();
  23199            } else {
  23200                container = this.declarationContainerStack[this.declarationContainerStack.length - 2];
  23201            }
  23202            if(container.nodeType == TypeScript.NodeType.ModuleDeclaration && !TypeScript.hasFlag(declFlags, TypeScript.DeclFlags.Exported)) {
  23203                return false;
  23204            }
  23205            if(!canEmitGlobalAmbientDecl && container.nodeType == TypeScript.NodeType.Script && TypeScript.hasFlag(declFlags, TypeScript.DeclFlags.Ambient)) {
  23206                return false;
  23207            }
  23208            return true;
  23209        };
  23210        DeclarationEmitter.prototype.canEmitPrePostAstSignature = function (declFlags, astWithPrePostCallback, preCallback) {
  23211            if(this.ignoreCallbackAst) {
  23212                TypeScript.CompilerDiagnostics.assert(this.ignoreCallbackAst != astWithPrePostCallback, "Ignore Callback AST mismatch");
  23213                this.ignoreCallbackAst = null;
  23214                return false;
  23215            } else {
  23216                if(preCallback && !this.canEmitSignature(declFlags, true, preCallback)) {
  23217                    this.ignoreCallbackAst = astWithPrePostCallback;
  23218                    return false;
  23219                }
  23220            }
  23221            return true;
  23222        };
  23223        DeclarationEmitter.prototype.getDeclFlagsString = function (declFlags, typeString) {
  23224            var result = this.getIndentString();
  23225            var accessorString = "";
  23226            if(TypeScript.hasFlag(declFlags, TypeScript.DeclFlags.GetAccessor)) {
  23227                accessorString = "get ";
  23228            } else {
  23229                if(TypeScript.hasFlag(declFlags, TypeScript.DeclFlags.SetAccessor)) {
  23230                    accessorString = "set ";
  23231                }
  23232            }
  23233            var container = this.getAstDeclarationContainer();
  23234            if(container.nodeType == TypeScript.NodeType.ModuleDeclaration && TypeScript.hasFlag((container).modFlags, TypeScript.ModuleFlags.IsWholeFile) && TypeScript.hasFlag(declFlags, TypeScript.DeclFlags.Exported)) {
  23235                result += "export ";
  23236            }
  23237            if(TypeScript.hasFlag(declFlags, TypeScript.DeclFlags.LocalStatic) || TypeScript.hasFlag(declFlags, TypeScript.DeclFlags.Static)) {
  23238                result += "static " + accessorString;
  23239            } else {
  23240                if(TypeScript.hasFlag(declFlags, TypeScript.DeclFlags.Private)) {
  23241                    result += "private " + accessorString;
  23242                } else {
  23243                    if(TypeScript.hasFlag(declFlags, TypeScript.DeclFlags.Public)) {
  23244                        result += "public " + accessorString;
  23245                    } else {
  23246                        if(accessorString == "") {
  23247                            result += typeString + " ";
  23248                        } else {
  23249                            result += accessorString;
  23250                        }
  23251                    }
  23252                }
  23253            }
  23254            return result;
  23255        };
  23256        DeclarationEmitter.prototype.emitDeclFlags = function (declFlags, typeString) {
  23257            this.declFile.Write(this.getDeclFlagsString(declFlags, typeString));
  23258        };
  23259        DeclarationEmitter.prototype.canEmitTypeAnnotationSignature = function (declFlag) {
  23260            if (typeof declFlag === "undefined") { declFlag = TypeScript.DeclFlags.None; }
  23261            return !TypeScript.hasFlag(declFlag, TypeScript.DeclFlags.Private);
  23262        };
  23263        DeclarationEmitter.prototype.pushDeclarationContainer = function (ast) {
  23264            this.declarationContainerStack.push(ast);
  23265        };
  23266        DeclarationEmitter.prototype.popDeclarationContainer = function (ast) {
  23267            TypeScript.CompilerDiagnostics.assert(ast != this.getAstDeclarationContainer(), 'Declaration container mismatch');
  23268            this.declarationContainerStack.pop();
  23269        };
  23270        DeclarationEmitter.prototype.emitTypeNamesMember = function (memberName, emitIndent) {
  23271            if (typeof emitIndent === "undefined") { emitIndent = false; }
  23272            if(memberName.prefix == "{ ") {
  23273                if(emitIndent) {
  23274                    this.emitIndent();
  23275                }
  23276                this.declFile.WriteLine("{");
  23277                this.indenter.increaseIndent();
  23278                emitIndent = true;
  23279            } else {
  23280                if(memberName.prefix != "") {
  23281                    if(emitIndent) {
  23282                        this.emitIndent();
  23283                    }
  23284                    this.declFile.Write(memberName.prefix);
  23285                    emitIndent = false;
  23286                }
  23287            }
  23288            if(memberName.isString()) {
  23289                if(emitIndent) {
  23290                    this.emitIndent();
  23291                }
  23292                this.declFile.Write((memberName).text);
  23293            } else {
  23294                var ar = memberName;
  23295                for(var index = 0; index < ar.entries.length; index++) {
  23296                    this.emitTypeNamesMember(ar.entries[index], emitIndent);
  23297                    if(ar.delim == "; ") {
  23298                        this.declFile.WriteLine(";");
  23299                    }
  23300                }
  23301            }
  23302            if(memberName.suffix == "}") {
  23303                this.indenter.decreaseIndent();
  23304                this.emitIndent();
  23305                this.declFile.Write(memberName.suffix);
  23306            } else {
  23307                this.declFile.Write(memberName.suffix);
  23308            }
  23309        };
  23310        DeclarationEmitter.prototype.emitTypeSignature = function (type) {
  23311            var containingScope = null;
  23312            var declarationContainerAst = this.getAstDeclarationContainer();
  23313            switch(declarationContainerAst.nodeType) {
  23314                case TypeScript.NodeType.ModuleDeclaration:
  23315                case TypeScript.NodeType.InterfaceDeclaration:
  23316                case TypeScript.NodeType.FuncDecl: {
  23317                    if(declarationContainerAst.type) {
  23318                        containingScope = declarationContainerAst.type.containedScope;
  23319                    }
  23320                    break;
  23321 
  23322                }
  23323                case TypeScript.NodeType.Script: {
  23324                    var script = declarationContainerAst;
  23325                    if(script.bod) {
  23326                        containingScope = script.bod.enclosingScope;
  23327                    }
  23328                    break;
  23329 
  23330                }
  23331                case TypeScript.NodeType.ClassDeclaration: {
  23332                    if(declarationContainerAst.type) {
  23333                        containingScope = declarationContainerAst.type.instanceType.containedScope;
  23334                    }
  23335                    break;
  23336 
  23337                }
  23338                default: {
  23339                    TypeScript.CompilerDiagnostics.debugPrint("Unknown containing scope");
  23340 
  23341                }
  23342            }
  23343            var typeNameMembers = type.getScopedTypeNameEx(containingScope);
  23344            this.emitTypeNamesMember(typeNameMembers);
  23345        };
  23346        DeclarationEmitter.prototype.emitComment = function (comment) {
  23347            var text = comment.getText();
  23348            if(this.declFile.onNewLine) {
  23349                this.emitIndent();
  23350            } else {
  23351                if(!comment.isBlockComment) {
  23352                    this.declFile.WriteLine("");
  23353                    this.emitIndent();
  23354                }
  23355            }
  23356            this.declFile.Write(text[0]);
  23357            for(var i = 1; i < text.length; i++) {
  23358                this.declFile.WriteLine("");
  23359                this.emitIndent();
  23360                this.declFile.Write(text[i]);
  23361            }
  23362            if(comment.endsLine || !comment.isBlockComment) {
  23363                this.declFile.WriteLine("");
  23364            } else {
  23365                this.declFile.Write(" ");
  23366            }
  23367        };
  23368        DeclarationEmitter.prototype.emitDeclarationComments = function (astOrSymbol, endLine) {
  23369            if (typeof endLine === "undefined") { endLine = true; }
  23370            if(!this.emitOptions.emitComments) {
  23371                return;
  23372            }
  23373            var declComments = astOrSymbol.getDocComments();
  23374            if(declComments.length > 0) {
  23375                for(var i = 0; i < declComments.length; i++) {
  23376                    this.emitComment(declComments[i]);
  23377                }
  23378                if(endLine) {
  23379                    if(!this.declFile.onNewLine) {
  23380                        this.declFile.WriteLine("");
  23381                    }
  23382                } else {
  23383                    if(this.declFile.onNewLine) {
  23384                        this.emitIndent();
  23385                    }
  23386                }
  23387            }
  23388        };
  23389        DeclarationEmitter.prototype.VarDeclCallback = function (pre, varDecl) {
  23390            if(pre && this.canEmitSignature(TypeScript.ToDeclFlags(varDecl.varFlags), false)) {
  23391                var interfaceMember = (this.getAstDeclarationContainer().nodeType == TypeScript.NodeType.InterfaceDeclaration);
  23392                this.emitDeclarationComments(varDecl);
  23393                if(!interfaceMember) {
  23394                    if(this.varListCount >= 0) {
  23395                        this.emitDeclFlags(TypeScript.ToDeclFlags(varDecl.varFlags), "var");
  23396                        this.varListCount = -this.varListCount;
  23397                    }
  23398                    this.declFile.Write(varDecl.id.text);
  23399                } else {
  23400                    this.emitIndent();
  23401                    this.declFile.Write(varDecl.id.text);
  23402                    if(TypeScript.hasFlag(varDecl.id.flags, TypeScript.ASTFlags.OptionalName)) {
  23403                        this.declFile.Write("?");
  23404                    }
  23405                }
  23406                var type = null;
  23407                if(varDecl.typeExpr && varDecl.typeExpr.type) {
  23408                    type = varDecl.typeExpr.type;
  23409                } else {
  23410                    if(varDecl.sym) {
  23411                        type = (varDecl.sym).getType();
  23412                        if(type == this.checker.anyType) {
  23413                            type = null;
  23414                        }
  23415                    }
  23416                }
  23417                if(type && this.canEmitTypeAnnotationSignature(TypeScript.ToDeclFlags(varDecl.varFlags))) {
  23418                    this.declFile.Write(": ");
  23419                    this.emitTypeSignature(type);
  23420                }
  23421                if(this.varListCount > 0) {
  23422                    this.varListCount--;
  23423                } else {
  23424                    if(this.varListCount < 0) {
  23425                        this.varListCount++;
  23426                    }
  23427                }
  23428                if(this.varListCount < 0) {
  23429                    this.declFile.Write(", ");
  23430                } else {
  23431                    this.declFile.WriteLine(";");
  23432                }
  23433            }
  23434            return false;
  23435        };
  23436        DeclarationEmitter.prototype.BlockCallback = function (pre, block) {
  23437            if(!block.isStatementBlock) {
  23438                if(pre) {
  23439                    this.varListCount = block.statements.members.length;
  23440                } else {
  23441                    this.varListCount = 0;
  23442                }
  23443                return true;
  23444            }
  23445            return false;
  23446        };
  23447        DeclarationEmitter.prototype.emitArgDecl = function (argDecl, funcDecl) {
  23448            this.emitDeclarationComments(argDecl, false);
  23449            this.declFile.Write(argDecl.id.text);
  23450            if(argDecl.isOptionalArg()) {
  23451                this.declFile.Write("?");
  23452            }
  23453            if((argDecl.typeExpr || argDecl.type != this.checker.anyType) && this.canEmitTypeAnnotationSignature(TypeScript.ToDeclFlags(funcDecl.fncFlags))) {
  23454                this.declFile.Write(": ");
  23455                this.emitTypeSignature(argDecl.type);
  23456            }
  23457        };
  23458        DeclarationEmitter.prototype.FuncDeclCallback = function (pre, funcDecl) {
  23459            if(!pre) {
  23460                return false;
  23461            }
  23462            if(funcDecl.isAccessor()) {
  23463                return this.emitPropertyAccessorSignature(funcDecl);
  23464            }
  23465            var isInterfaceMember = (this.getAstDeclarationContainer().nodeType == TypeScript.NodeType.InterfaceDeclaration);
  23466            if(funcDecl.bod) {
  23467                if(funcDecl.isConstructor) {
  23468                    if(funcDecl.type.construct && funcDecl.type.construct.signatures.length > 1) {
  23469                        return false;
  23470                    }
  23471                } else {
  23472                    if(funcDecl.type.call && funcDecl.type.call.signatures.length > 1) {
  23473                        return false;
  23474                    }
  23475                }
  23476            } else {
  23477                if(!isInterfaceMember && TypeScript.hasFlag(funcDecl.fncFlags, TypeScript.FncFlags.Private) && funcDecl.type.call && funcDecl.type.call.signatures.length > 1) {
  23478                    var signatures = funcDecl.type.call.signatures;
  23479                    var firstSignature = signatures[0].declAST;
  23480                    if(firstSignature.bod) {
  23481                        firstSignature = signatures[1].declAST;
  23482                    }
  23483                    if(firstSignature != funcDecl) {
  23484                        return false;
  23485                    }
  23486                }
  23487            }
  23488            if(!this.canEmitSignature(TypeScript.ToDeclFlags(funcDecl.fncFlags), false)) {
  23489                return false;
  23490            }
  23491            this.emitDeclarationComments(funcDecl);
  23492            if(funcDecl.isConstructor) {
  23493                this.emitIndent();
  23494                this.declFile.Write("constructor");
  23495            } else {
  23496                var id = funcDecl.getNameText();
  23497                if(!isInterfaceMember) {
  23498                    this.emitDeclFlags(TypeScript.ToDeclFlags(funcDecl.fncFlags), "function");
  23499                    this.declFile.Write(id);
  23500                } else {
  23501                    this.emitIndent();
  23502                    if(funcDecl.isConstructMember()) {
  23503                        this.declFile.Write("new");
  23504                    } else {
  23505                        if(!funcDecl.isCallMember() && !funcDecl.isIndexerMember()) {
  23506                            this.declFile.Write(id);
  23507                            if(TypeScript.hasFlag(funcDecl.name.flags, TypeScript.ASTFlags.OptionalName)) {
  23508                                this.declFile.Write("? ");
  23509                            }
  23510                        }
  23511                    }
  23512                }
  23513            }
  23514            if(!funcDecl.isIndexerMember()) {
  23515                this.declFile.Write("(");
  23516            } else {
  23517                this.declFile.Write("[");
  23518            }
  23519            this.indenter.increaseIndent();
  23520            if(funcDecl.arguments) {
  23521                var argsLen = funcDecl.arguments.members.length;
  23522                if(funcDecl.variableArgList) {
  23523                    argsLen--;
  23524                }
  23525                for(var i = 0; i < argsLen; i++) {
  23526                    var argDecl = funcDecl.arguments.members[i];
  23527                    this.emitArgDecl(argDecl, funcDecl);
  23528                    if(i < (argsLen - 1)) {
  23529                        this.declFile.Write(", ");
  23530                    }
  23531                }
  23532            }
  23533            if(funcDecl.variableArgList) {
  23534                var lastArg = funcDecl.arguments.members[funcDecl.arguments.members.length - 1];
  23535                if(funcDecl.arguments.members.length > 1) {
  23536                    this.declFile.Write(", ...");
  23537                } else {
  23538                    this.declFile.Write("...");
  23539                }
  23540                this.emitArgDecl(lastArg, funcDecl);
  23541            }
  23542            this.indenter.decreaseIndent();
  23543            if(!funcDecl.isIndexerMember()) {
  23544                this.declFile.Write(")");
  23545            } else {
  23546                this.declFile.Write("]");
  23547            }
  23548            if(!funcDecl.isConstructor && (funcDecl.returnTypeAnnotation || funcDecl.signature.returnType.type != this.checker.anyType) && this.canEmitTypeAnnotationSignature(TypeScript.ToDeclFlags(funcDecl.fncFlags))) {
  23549                this.declFile.Write(": ");
  23550                this.emitTypeSignature(funcDecl.signature.returnType.type);
  23551            }
  23552            this.declFile.WriteLine(";");
  23553            return false;
  23554        };
  23555        DeclarationEmitter.prototype.emitBaseList = function (bases, qual) {
  23556            if(bases && (bases.members.length > 0)) {
  23557                this.declFile.Write(" " + qual + " ");
  23558                var basesLen = bases.members.length;
  23559                for(var i = 0; i < basesLen; i++) {
  23560                    var baseExpr = bases.members[i];
  23561                    var baseSymbol = baseExpr.type.symbol;
  23562                    var baseType = baseExpr.type;
  23563                    if(i > 0) {
  23564                        this.declFile.Write(", ");
  23565                    }
  23566                    this.emitTypeSignature(baseType);
  23567                }
  23568            }
  23569        };
  23570        DeclarationEmitter.prototype.emitPropertyAccessorSignature = function (funcDecl) {
  23571            var accessorSymbol = funcDecl.accessorSymbol;
  23572            if(accessorSymbol.getter && accessorSymbol.getter.declAST != funcDecl) {
  23573                return false;
  23574            }
  23575            this.emitDeclarationComments(accessorSymbol);
  23576            this.emitDeclFlags(TypeScript.ToDeclFlags(accessorSymbol.flags), "var");
  23577            this.declFile.Write(funcDecl.name.text);
  23578            var propertyType = accessorSymbol.getType();
  23579            if(this.canEmitTypeAnnotationSignature(TypeScript.ToDeclFlags(accessorSymbol.flags))) {
  23580                this.declFile.Write(" : ");
  23581                this.emitTypeSignature(propertyType);
  23582            }
  23583            this.declFile.WriteLine(";");
  23584            return false;
  23585        };
  23586        DeclarationEmitter.prototype.emitClassMembersFromConstructorDefinition = function (funcDecl) {
  23587            if(funcDecl.arguments) {
  23588                var argsLen = funcDecl.arguments.members.length;
  23589                if(funcDecl.variableArgList) {
  23590                    argsLen--;
  23591                }
  23592                for(var i = 0; i < argsLen; i++) {
  23593                    var argDecl = funcDecl.arguments.members[i];
  23594                    if(TypeScript.hasFlag(argDecl.varFlags, TypeScript.VarFlags.Property)) {
  23595                        this.emitDeclarationComments(argDecl);
  23596                        this.emitDeclFlags(TypeScript.ToDeclFlags(argDecl.varFlags), "var");
  23597                        this.declFile.Write(argDecl.id.text);
  23598                        if(argDecl.typeExpr && this.canEmitTypeAnnotationSignature(TypeScript.ToDeclFlags(argDecl.varFlags))) {
  23599                            this.declFile.Write(": ");
  23600                            this.emitTypeSignature(argDecl.type);
  23601                        }
  23602                        this.declFile.WriteLine(";");
  23603                    }
  23604                }
  23605            }
  23606        };
  23607        DeclarationEmitter.prototype.ClassDeclarationCallback = function (pre, classDecl) {
  23608            if(!this.canEmitPrePostAstSignature(TypeScript.ToDeclFlags(classDecl.varFlags), classDecl, pre)) {
  23609                return false;
  23610            }
  23611            if(pre) {
  23612                var className = classDecl.name.text;
  23613                this.emitDeclarationComments(classDecl);
  23614                this.emitDeclFlags(TypeScript.ToDeclFlags(classDecl.varFlags), "class");
  23615                this.declFile.Write(className);
  23616                this.emitBaseList(classDecl.extendsList, "extends");
  23617                this.emitBaseList(classDecl.implementsList, "implements");
  23618                this.declFile.WriteLine(" {");
  23619                this.pushDeclarationContainer(classDecl);
  23620                this.indenter.increaseIndent();
  23621                if(classDecl.constructorDecl) {
  23622                    this.emitClassMembersFromConstructorDefinition(classDecl.constructorDecl);
  23623                }
  23624            } else {
  23625                this.indenter.decreaseIndent();
  23626                this.popDeclarationContainer(classDecl);
  23627                this.emitIndent();
  23628                this.declFile.WriteLine("}");
  23629            }
  23630            return true;
  23631        };
  23632        DeclarationEmitter.prototype.InterfaceDeclarationCallback = function (pre, interfaceDecl) {
  23633            if(!this.canEmitPrePostAstSignature(TypeScript.ToDeclFlags(interfaceDecl.varFlags), interfaceDecl, pre)) {
  23634                return false;
  23635            }
  23636            if(pre) {
  23637                var interfaceName = interfaceDecl.name.text;
  23638                this.emitDeclarationComments(interfaceDecl);
  23639                this.emitDeclFlags(TypeScript.ToDeclFlags(interfaceDecl.varFlags), "interface");
  23640                this.declFile.Write(interfaceName);
  23641                this.emitBaseList(interfaceDecl.extendsList, "extends");
  23642                this.declFile.WriteLine(" {");
  23643                this.indenter.increaseIndent();
  23644                this.pushDeclarationContainer(interfaceDecl);
  23645            } else {
  23646                this.indenter.decreaseIndent();
  23647                this.popDeclarationContainer(interfaceDecl);
  23648                this.emitIndent();
  23649                this.declFile.WriteLine("}");
  23650            }
  23651            return true;
  23652        };
  23653        DeclarationEmitter.prototype.ImportDeclarationCallback = function (pre, importDecl) {
  23654            if(pre) {
  23655                if((this.declarationContainerStack[0]).isExternallyVisibleSymbol(importDecl.id.sym)) {
  23656                    this.emitDeclarationComments(importDecl);
  23657                    this.emitIndent();
  23658                    this.declFile.Write("import ");
  23659                    this.declFile.Write(importDecl.id.text + " = ");
  23660                    if(importDecl.isDynamicImport) {
  23661                        this.declFile.WriteLine("module (" + importDecl.getAliasName() + ");");
  23662                    } else {
  23663                        this.declFile.WriteLine(importDecl.getAliasName() + ";");
  23664                    }
  23665                }
  23666            }
  23667            return false;
  23668        };
  23669        DeclarationEmitter.prototype.emitEnumSignature = function (moduleDecl) {
  23670            if(!this.canEmitSignature(TypeScript.ToDeclFlags(moduleDecl.modFlags))) {
  23671                return false;
  23672            }
  23673            this.emitDeclarationComments(moduleDecl);
  23674            this.emitDeclFlags(TypeScript.ToDeclFlags(moduleDecl.modFlags), "enum");
  23675            this.declFile.WriteLine(moduleDecl.name.text + " {");
  23676            this.indenter.increaseIndent();
  23677            var membersLen = moduleDecl.members.members.length;
  23678            for(var j = 1; j < membersLen; j++) {
  23679                var memberDecl = moduleDecl.members.members[j];
  23680                if(memberDecl.nodeType == TypeScript.NodeType.VarDecl) {
  23681                    this.emitDeclarationComments(memberDecl);
  23682                    this.emitIndent();
  23683                    this.declFile.WriteLine((memberDecl).id.text + ",");
  23684                } else {
  23685                    TypeScript.CompilerDiagnostics.assert(memberDecl.nodeType != TypeScript.NodeType.Asg, "We want to catch this");
  23686                }
  23687            }
  23688            this.indenter.decreaseIndent();
  23689            this.emitIndent();
  23690            this.declFile.WriteLine("}");
  23691            return false;
  23692        };
  23693        DeclarationEmitter.prototype.ModuleDeclarationCallback = function (pre, moduleDecl) {
  23694            if(TypeScript.hasFlag(moduleDecl.modFlags, TypeScript.ModuleFlags.IsWholeFile)) {
  23695                if(TypeScript.hasFlag(moduleDecl.modFlags, TypeScript.ModuleFlags.IsDynamic)) {
  23696                    if(pre) {
  23697                        if(!this.emitOptions.outputMany) {
  23698                            this.singleDeclFile = this.declFile;
  23699                            TypeScript.CompilerDiagnostics.assert(this.indenter.indentAmt == 0, "Indent has to be 0 when outputing new file");
  23700                            var declareFileName = this.emitOptions.mapOutputFileName(TypeScript.stripQuotes(moduleDecl.name.sym.name), TypeScript.TypeScriptCompiler.mapToDTSFileName);
  23701                            var useUTF8InOutputfile = moduleDecl.containsUnicodeChar || (this.emitOptions.emitComments && moduleDecl.containsUnicodeCharInComment);
  23702                            try  {
  23703                                this.declFile = new DeclFileWriter(this.emitOptions.ioHost.createFile(declareFileName, useUTF8InOutputfile));
  23704                            } catch (ex) {
  23705                                this.errorReporter.emitterError(null, ex.message);
  23706                            }
  23707                        }
  23708                        this.pushDeclarationContainer(moduleDecl);
  23709                    } else {
  23710                        if(!this.emitOptions.outputMany) {
  23711                            TypeScript.CompilerDiagnostics.assert(this.singleDeclFile != this.declFile, "singleDeclFile cannot be null as we are going to revert back to it");
  23712                            TypeScript.CompilerDiagnostics.assert(this.indenter.indentAmt == 0, "Indent has to be 0 when outputing new file");
  23713                            try  {
  23714                                this.declFile.Close();
  23715                            } catch (ex) {
  23716                                this.errorReporter.emitterError(null, ex.message);
  23717                            }
  23718                            this.declFile = this.singleDeclFile;
  23719                        }
  23720                        this.popDeclarationContainer(moduleDecl);
  23721                    }
  23722                }
  23723                return true;
  23724            }
  23725            if(moduleDecl.isEnum()) {
  23726                if(pre) {
  23727                    this.emitEnumSignature(moduleDecl);
  23728                }
  23729                return false;
  23730            }
  23731            if(!this.canEmitPrePostAstSignature(TypeScript.ToDeclFlags(moduleDecl.modFlags), moduleDecl, pre)) {
  23732                return false;
  23733            }
  23734            if(pre) {
  23735                if(this.emitDottedModuleName()) {
  23736                    this.dottedModuleEmit += ".";
  23737                } else {
  23738                    this.dottedModuleEmit = this.getDeclFlagsString(TypeScript.ToDeclFlags(moduleDecl.modFlags), "module");
  23739                }
  23740                this.dottedModuleEmit += moduleDecl.name.text;
  23741                var isCurrentModuleDotted = (moduleDecl.members.members.length == 1 && moduleDecl.members.members[0].nodeType == TypeScript.NodeType.ModuleDeclaration && !(moduleDecl.members.members[0]).isEnum() && TypeScript.hasFlag((moduleDecl.members.members[0]).modFlags, TypeScript.ModuleFlags.Exported));
  23742                var moduleDeclComments = moduleDecl.getDocComments();
  23743                isCurrentModuleDotted = isCurrentModuleDotted && (moduleDeclComments == null || moduleDeclComments.length == 0);
  23744                this.isDottedModuleName.push(isCurrentModuleDotted);
  23745                this.pushDeclarationContainer(moduleDecl);
  23746                if(!isCurrentModuleDotted) {
  23747                    this.emitDeclarationComments(moduleDecl);
  23748                    this.declFile.Write(this.dottedModuleEmit);
  23749                    this.declFile.WriteLine(" {");
  23750                    this.indenter.increaseIndent();
  23751                }
  23752            } else {
  23753                if(!this.emitDottedModuleName()) {
  23754                    this.indenter.decreaseIndent();
  23755                    this.emitIndent();
  23756                    this.declFile.WriteLine("}");
  23757                }
  23758                this.popDeclarationContainer(moduleDecl);
  23759                this.isDottedModuleName.pop();
  23760            }
  23761            return true;
  23762        };
  23763        DeclarationEmitter.prototype.ScriptCallback = function (pre, script) {
  23764            if(pre) {
  23765                if(this.emitOptions.outputMany) {
  23766                    for(var i = 0; i < script.referencedFiles.length; i++) {
  23767                        var referencePath = script.referencedFiles[i].path;
  23768                        var declareFileName;
  23769                        if(TypeScript.isRooted(referencePath)) {
  23770                            declareFileName = this.emitOptions.mapOutputFileName(referencePath, TypeScript.TypeScriptCompiler.mapToDTSFileName);
  23771                        } else {
  23772                            declareFileName = TypeScript.getDeclareFilePath(script.referencedFiles[i].path);
  23773                        }
  23774                        this.declFile.WriteLine('/// <reference path="' + declareFileName + '" />');
  23775                    }
  23776                }
  23777                this.pushDeclarationContainer(script);
  23778            } else {
  23779                this.popDeclarationContainer(script);
  23780            }
  23781            return true;
  23782        };
  23783        DeclarationEmitter.prototype.DefaultCallback = function (pre, ast) {
  23784            return !TypeScript.hasFlag(ast.flags, TypeScript.ASTFlags.IsStatement);
  23785        };
  23786        return DeclarationEmitter;
  23787    })();
  23788    TypeScript.DeclarationEmitter = DeclarationEmitter;    
  23789 })(TypeScript || (TypeScript = {}));
  23790 var TypeScript;
  23791 (function (TypeScript) {
  23792    (function (UpdateUnitKind) {
  23793        UpdateUnitKind._map = [];
  23794        UpdateUnitKind._map[0] = "Unknown";
  23795        UpdateUnitKind.Unknown = 0;
  23796        UpdateUnitKind._map[1] = "NoEdits";
  23797        UpdateUnitKind.NoEdits = 1;
  23798        UpdateUnitKind._map[2] = "EditsInsideSingleScope";
  23799        UpdateUnitKind.EditsInsideSingleScope = 2;
  23800    })(TypeScript.UpdateUnitKind || (TypeScript.UpdateUnitKind = {}));
  23801    var UpdateUnitKind = TypeScript.UpdateUnitKind;
  23802    var ScriptEditRange = (function () {
  23803        function ScriptEditRange(minChar, limChar, delta) {
  23804            this.minChar = minChar;
  23805            this.limChar = limChar;
  23806            this.delta = delta;
  23807        }
  23808        ScriptEditRange.unknown = function unknown() {
  23809            return new ScriptEditRange(-1, -1, -1);
  23810        }
  23811        ScriptEditRange.prototype.isUnknown = function () {
  23812            return this.minChar === -1 && this.limChar === -1 && this.delta === -1;
  23813        };
  23814        ScriptEditRange.prototype.containsPosition = function (pos) {
  23815            return (this.minChar <= pos && pos < this.limChar) || (this.minChar <= pos && pos < this.limChar + this.delta);
  23816        };
  23817        ScriptEditRange.prototype.toString = function () {
  23818            return "editRange(minChar=" + this.minChar + ", limChar=" + this.limChar + ", delta=" + this.delta + ")";
  23819        };
  23820        return ScriptEditRange;
  23821    })();
  23822    TypeScript.ScriptEditRange = ScriptEditRange;    
  23823    var UpdateUnitResult = (function () {
  23824        function UpdateUnitResult(kind, unitIndex, script1, script2) {
  23825            this.kind = kind;
  23826            this.unitIndex = unitIndex;
  23827            this.script1 = script1;
  23828            this.script2 = script2;
  23829            this.scope1 = null;
  23830            this.scope2 = null;
  23831            this.editRange = null;
  23832            this.parseErrors = [];
  23833        }
  23834        UpdateUnitResult.noEdits = function noEdits(unitIndex) {
  23835            return new UpdateUnitResult(UpdateUnitKind.NoEdits, unitIndex, null, null);
  23836        }
  23837        UpdateUnitResult.unknownEdits = function unknownEdits(script1, script2, parseErrors) {
  23838            var result = new UpdateUnitResult(UpdateUnitKind.Unknown, script1.locationInfo.unitIndex, script1, script2);
  23839            result.parseErrors = parseErrors;
  23840            return result;
  23841        }
  23842        UpdateUnitResult.singleScopeEdits = function singleScopeEdits(script1, script2, scope1, scope2, editRange, parseErrors) {
  23843            var result = new UpdateUnitResult(UpdateUnitKind.EditsInsideSingleScope, script1.locationInfo.unitIndex, script1, script2);
  23844            result.scope1 = scope1;
  23845            result.scope2 = scope2;
  23846            result.editRange = editRange;
  23847            result.parseErrors = parseErrors;
  23848            return result;
  23849        }
  23850        return UpdateUnitResult;
  23851    })();
  23852    TypeScript.UpdateUnitResult = UpdateUnitResult;    
  23853    var ErrorEntry = (function () {
  23854        function ErrorEntry(unitIndex, minChar, limChar, message) {
  23855            this.unitIndex = unitIndex;
  23856            this.minChar = minChar;
  23857            this.limChar = limChar;
  23858            this.message = message;
  23859        }
  23860        return ErrorEntry;
  23861    })();
  23862    TypeScript.ErrorEntry = ErrorEntry;    
  23863    TypeScript.defaultSettings = new TypeScript.CompilationSettings();
  23864    var TypeScriptCompiler = (function () {
  23865        function TypeScriptCompiler(errorOutput, logger, settings) {
  23866            if (typeof logger === "undefined") { logger = new TypeScript.NullLogger(); }
  23867            if (typeof settings === "undefined") { settings = TypeScript.defaultSettings; }
  23868            this.errorOutput = errorOutput;
  23869            this.logger = logger;
  23870            this.settings = settings;
  23871            this.parser = new TypeScript.Parser();
  23872            this.typeFlow = null;
  23873            this.scripts = new TypeScript.ASTList();
  23874            this.units = new Array();
  23875            this.errorReporter = new TypeScript.ErrorReporter(this.errorOutput);
  23876            this.persistentTypeState = new TypeScript.PersistentGlobalTypeState(this.errorReporter);
  23877            this.errorReporter.parser = this.parser;
  23878            this.initTypeChecker(this.errorOutput);
  23879            this.parser.style_requireSemi = this.settings.styleSettings.requireSemi;
  23880            this.parser.style_funcInLoop = this.settings.styleSettings.funcInLoop;
  23881            this.parser.inferPropertiesFromThisAssignment = this.settings.inferPropertiesFromThisAssignment;
  23882            this.emitSettings = new TypeScript.EmitOptions(this.settings);
  23883            TypeScript.codeGenTarget = settings.codeGenTarget;
  23884        }
  23885        TypeScriptCompiler.prototype.timeFunction = function (funcDescription, func) {
  23886            return TypeScript.timeFunction(this.logger, funcDescription, func);
  23887        };
  23888        TypeScriptCompiler.prototype.initTypeChecker = function (errorOutput) {
  23889            this.persistentTypeState.refreshPersistentState();
  23890            this.typeChecker = new TypeScript.TypeChecker(this.persistentTypeState);
  23891            this.typeChecker.errorReporter = this.errorReporter;
  23892            this.typeChecker.checkControlFlow = this.settings.controlFlow;
  23893            this.typeChecker.checkControlFlowUseDef = this.settings.controlFlowUseDef;
  23894            this.typeChecker.printControlFlowGraph = this.settings.printControlFlow;
  23895            this.typeChecker.errorsOnWith = this.settings.errorOnWith;
  23896            this.typeChecker.styleSettings = this.settings.styleSettings;
  23897            this.typeChecker.canCallDefinitionSignature = this.settings.canCallDefinitionSignature;
  23898            this.errorReporter.checker = this.typeChecker;
  23899            this.setErrorOutput(this.errorOutput);
  23900        };
  23901        TypeScriptCompiler.prototype.setErrorOutput = function (outerr) {
  23902            this.errorOutput = outerr;
  23903            this.errorReporter.setErrOut(outerr);
  23904            this.parser.outfile = outerr;
  23905        };
  23906        TypeScriptCompiler.prototype.emitCommentsToOutput = function () {
  23907            this.emitSettings = new TypeScript.EmitOptions(this.settings);
  23908        };
  23909        TypeScriptCompiler.prototype.setErrorCallback = function (fn) {
  23910            this.parser.errorCallback = fn;
  23911        };
  23912        TypeScriptCompiler.prototype.updateUnit = function (prog, filename, setRecovery) {
  23913            return this.updateSourceUnit(new TypeScript.StringSourceText(prog), filename, setRecovery);
  23914        };
  23915        TypeScriptCompiler.prototype.updateSourceUnit = function (sourceText, filename, setRecovery) {
  23916            var _this = this;
  23917            return this.timeFunction("updateSourceUnit(" + filename + ")", function () {
  23918                var updateResult = _this.partialUpdateUnit(sourceText, filename, setRecovery);
  23919                return _this.applyUpdateResult(updateResult);
  23920            });
  23921        };
  23922        TypeScriptCompiler.prototype.applyUpdateResult = function (updateResult) {
  23923            switch(updateResult.kind) {
  23924                case UpdateUnitKind.NoEdits: {
  23925                    return false;
  23926 
  23927                }
  23928                case UpdateUnitKind.Unknown: {
  23929                    this.scripts.members[updateResult.unitIndex] = updateResult.script2;
  23930                    this.units[updateResult.unitIndex] = updateResult.script2.locationInfo;
  23931                    for(var i = 0, len = updateResult.parseErrors.length; i < len; i++) {
  23932                        var e = updateResult.parseErrors[i];
  23933                        if(this.parser.errorCallback) {
  23934                            this.parser.errorCallback(e.minChar, e.limChar - e.minChar, e.message, e.unitIndex);
  23935                        }
  23936                    }
  23937                    return true;
  23938 
  23939                }
  23940                case UpdateUnitKind.EditsInsideSingleScope: {
  23941                    new TypeScript.IncrementalParser(this.logger).mergeTrees(updateResult);
  23942                    return true;
  23943 
  23944                }
  23945            }
  23946        };
  23947        TypeScriptCompiler.prototype.partialUpdateUnit = function (sourceText, filename, setRecovery) {
  23948            var _this = this;
  23949            return this.timeFunction("partialUpdateUnit(" + filename + ")", function () {
  23950                for(var i = 0, len = _this.units.length; i < len; i++) {
  23951                    if(_this.units[i].filename == filename) {
  23952                        if((_this.scripts.members[i]).isResident) {
  23953                            return UpdateUnitResult.noEdits(i);
  23954                        }
  23955                        if(setRecovery) {
  23956                            _this.parser.setErrorRecovery(null);
  23957                        }
  23958                        var updateResult;
  23959                        var parseErrors = [];
  23960                        var errorCapture = function (minChar, charLen, message, unitIndex) {
  23961                            parseErrors.push(new ErrorEntry(unitIndex, minChar, minChar + charLen, message));
  23962                        };
  23963                        var svErrorCallback = _this.parser.errorCallback;
  23964                        if(svErrorCallback) {
  23965                            _this.parser.errorCallback = errorCapture;
  23966                        }
  23967                        var oldScript = _this.scripts.members[i];
  23968                        var newScript = _this.parser.parse(sourceText, filename, i);
  23969                        if(svErrorCallback) {
  23970                            _this.parser.errorCallback = svErrorCallback;
  23971                        }
  23972                        updateResult = UpdateUnitResult.unknownEdits(oldScript, newScript, parseErrors);
  23973                        return updateResult;
  23974                    }
  23975                }
  23976                throw new Error("Unknown file \"" + filename + "\"");
  23977            });
  23978        };
  23979        TypeScriptCompiler.prototype.addUnit = function (prog, filename, keepResident, referencedFiles) {
  23980            if (typeof keepResident === "undefined") { keepResident = false; }
  23981            if (typeof referencedFiles === "undefined") { referencedFiles = []; }
  23982            return this.addSourceUnit(new TypeScript.StringSourceText(prog), filename, keepResident, referencedFiles);
  23983        };
  23984        TypeScriptCompiler.prototype.addSourceUnit = function (sourceText, filename, keepResident, referencedFiles) {
  23985            if (typeof referencedFiles === "undefined") { referencedFiles = []; }
  23986            var _this = this;
  23987            return this.timeFunction("addSourceUnit(" + filename + ", " + keepResident + ")", function () {
  23988                var script = _this.parser.parse(sourceText, filename, _this.units.length, TypeScript.AllowedElements.Global);
  23989                script.referencedFiles = referencedFiles;
  23990                script.isResident = keepResident;
  23991                _this.persistentTypeState.setCollectionMode(keepResident ? TypeScript.TypeCheckCollectionMode.Resident : TypeScript.TypeCheckCollectionMode.Transient);
  23992                var index = _this.units.length;
  23993                _this.units[index] = script.locationInfo;
  23994                _this.typeChecker.collectTypes(script);
  23995                _this.scripts.append(script);
  23996                return script;
  23997            });
  23998        };
  23999        TypeScriptCompiler.prototype.parseUnit = function (prog, filename) {
  24000            return this.parseSourceUnit(new TypeScript.StringSourceText(prog), filename);
  24001        };
  24002        TypeScriptCompiler.prototype.parseSourceUnit = function (sourceText, filename) {
  24003            this.parser.setErrorRecovery(this.errorOutput);
  24004            var script = this.parser.parse(sourceText, filename, 0);
  24005            var index = this.units.length;
  24006            this.units[index] = script.locationInfo;
  24007            this.typeChecker.collectTypes(script);
  24008            this.scripts.append(script);
  24009        };
  24010        TypeScriptCompiler.prototype.typeCheck = function () {
  24011            var _this = this;
  24012            return this.timeFunction("typeCheck()", function () {
  24013                var binder = new TypeScript.Binder(_this.typeChecker);
  24014                _this.typeChecker.units = _this.units;
  24015                binder.bind(_this.typeChecker.globalScope, _this.typeChecker.globals);
  24016                binder.bind(_this.typeChecker.globalScope, _this.typeChecker.ambientGlobals);
  24017                binder.bind(_this.typeChecker.globalScope, _this.typeChecker.globalTypes);
  24018                binder.bind(_this.typeChecker.globalScope, _this.typeChecker.ambientGlobalTypes);
  24019                _this.typeFlow = new TypeScript.TypeFlow(_this.logger, _this.typeChecker.globalScope, _this.parser, _this.typeChecker);
  24020                var i = 0;
  24021                var script = null;
  24022                var len = _this.scripts.members.length;
  24023                _this.persistentTypeState.setCollectionMode(TypeScript.TypeCheckCollectionMode.Resident);
  24024                for(i = 0; i < len; i++) {
  24025                    script = _this.scripts.members[i];
  24026                    if(!script.isResident || script.hasBeenTypeChecked) {
  24027                        continue;
  24028                    }
  24029                    _this.typeFlow.assignScopes(script);
  24030                    _this.typeFlow.initLibs();
  24031                }
  24032                for(i = 0; i < len; i++) {
  24033                    script = _this.scripts.members[i];
  24034                    if(!script.isResident || script.hasBeenTypeChecked) {
  24035                        continue;
  24036                    }
  24037                    _this.typeFlow.typeCheck(script);
  24038                    script.hasBeenTypeChecked = true;
  24039                }
  24040                _this.persistentTypeState.setCollectionMode(TypeScript.TypeCheckCollectionMode.Transient);
  24041                len = _this.scripts.members.length;
  24042                for(i = 0; i < len; i++) {
  24043                    script = _this.scripts.members[i];
  24044                    if(script.isResident) {
  24045                        continue;
  24046                    }
  24047                    _this.typeFlow.assignScopes(script);
  24048                    _this.typeFlow.initLibs();
  24049                }
  24050                for(i = 0; i < len; i++) {
  24051                    script = _this.scripts.members[i];
  24052                    if(script.isResident) {
  24053                        continue;
  24054                    }
  24055                    _this.typeFlow.typeCheck(script);
  24056                }
  24057                return null;
  24058            });
  24059        };
  24060        TypeScriptCompiler.prototype.cleanASTTypesForReTypeCheck = function (ast) {
  24061            function cleanASTType(ast, parent) {
  24062                ast.type = null;
  24063                if(ast.nodeType == TypeScript.NodeType.VarDecl) {
  24064                    var vardecl = ast;
  24065                    vardecl.sym = null;
  24066                } else {
  24067                    if(ast.nodeType == TypeScript.NodeType.ArgDecl) {
  24068                        var argdecl = ast;
  24069                        argdecl.sym = null;
  24070                    } else {
  24071                        if(ast.nodeType == TypeScript.NodeType.Name) {
  24072                            var name = ast;
  24073                            name.sym = null;
  24074                        } else {
  24075                            if(ast.nodeType == TypeScript.NodeType.FuncDecl) {
  24076                                var funcdecl = ast;
  24077                                funcdecl.signature = null;
  24078                                funcdecl.freeVariables = new Array();
  24079                                funcdecl.symbols = null;
  24080                                funcdecl.accessorSymbol = null;
  24081                                funcdecl.scopeType = null;
  24082                            } else {
  24083                                if(ast.nodeType == TypeScript.NodeType.ModuleDeclaration) {
  24084                                    var modDecl = ast;
  24085                                    modDecl.mod = null;
  24086                                } else {
  24087                                    if(ast.nodeType == TypeScript.NodeType.With) {
  24088                                        (ast).withSym = null;
  24089                                    } else {
  24090                                        if(ast.nodeType == TypeScript.NodeType.Catch) {
  24091                                            (ast).containedScope = null;
  24092                                        }
  24093                                    }
  24094                                }
  24095                            }
  24096                        }
  24097                    }
  24098                }
  24099                return ast;
  24100            }
  24101            TypeScript.getAstWalkerFactory().walk(ast, cleanASTType);
  24102        };
  24103        TypeScriptCompiler.prototype.cleanTypesForReTypeCheck = function () {
  24104            var _this = this;
  24105            return this.timeFunction("cleanTypesForReTypeCheck()", function () {
  24106                for(var i = 0, len = _this.scripts.members.length; i < len; i++) {
  24107                    var script = _this.scripts.members[i];
  24108                    if((script).isResident) {
  24109                        continue;
  24110                    }
  24111                    _this.cleanASTTypesForReTypeCheck(script);
  24112                    _this.typeChecker.collectTypes(script);
  24113                }
  24114                return null;
  24115            });
  24116        };
  24117        TypeScriptCompiler.prototype.attemptIncrementalTypeCheck = function (updateResult) {
  24118            return this.timeFunction("attemptIncrementalTypeCheck()", function () {
  24119                return false;
  24120            });
  24121        };
  24122        TypeScriptCompiler.prototype.reTypeCheck = function () {
  24123            var _this = this;
  24124            return this.timeFunction("reTypeCheck()", function () {
  24125                TypeScript.CompilerDiagnostics.analysisPass++;
  24126                _this.initTypeChecker(_this.errorOutput);
  24127                _this.persistentTypeState.setCollectionMode(TypeScript.TypeCheckCollectionMode.Transient);
  24128                _this.cleanTypesForReTypeCheck();
  24129                return _this.typeCheck();
  24130            });
  24131        };
  24132        TypeScriptCompiler.prototype.isDynamicModuleCompilation = function () {
  24133            for(var i = 0, len = this.scripts.members.length; i < len; i++) {
  24134                var script = this.scripts.members[i];
  24135                if(!script.isDeclareFile && script.topLevelMod != null) {
  24136                    return true;
  24137                }
  24138            }
  24139            return false;
  24140        };
  24141        TypeScriptCompiler.prototype.updateCommonDirectoryPath = function () {
  24142            var commonComponents = [];
  24143            var commonComponentsLength = -1;
  24144            for(var i = 0, len = this.scripts.members.length; i < len; i++) {
  24145                var script = this.scripts.members[i];
  24146                if(script.emitRequired(this.emitSettings)) {
  24147                    var fileName = script.locationInfo.filename;
  24148                    var fileComponents = TypeScript.filePathComponents(fileName);
  24149                    if(commonComponentsLength == -1) {
  24150                        commonComponents = fileComponents;
  24151                        commonComponentsLength = commonComponents.length;
  24152                    } else {
  24153                        var updatedPath = false;
  24154                        for(var j = 0; j < commonComponentsLength && j < fileComponents.length; j++) {
  24155                            if(commonComponents[j] != fileComponents[j]) {
  24156                                commonComponentsLength = j;
  24157                                updatedPath = true;
  24158                                if(j == 0) {
  24159                                    this.errorReporter.emitterError(null, "Cannot find the common subdirectory path for the input files");
  24160                                    return;
  24161                                }
  24162                                break;
  24163                            }
  24164                        }
  24165                        if(!updatedPath && fileComponents.length < commonComponentsLength) {
  24166                            commonComponentsLength = fileComponents.length;
  24167                        }
  24168                    }
  24169                }
  24170            }
  24171            this.emitSettings.commonDirectoryPath = commonComponents.slice(0, commonComponentsLength).join("/") + "/";
  24172            if(this.emitSettings.outputOption.charAt(this.emitSettings.outputOption.length - 1) != "/") {
  24173                this.emitSettings.outputOption += "/";
  24174            }
  24175        };
  24176        TypeScriptCompiler.prototype.parseEmitOption = function (ioHost) {
  24177            this.emitSettings.ioHost = ioHost;
  24178            if(this.emitSettings.outputOption == "") {
  24179                this.emitSettings.outputMany = true;
  24180                this.emitSettings.commonDirectoryPath = "";
  24181                return;
  24182            }
  24183            this.emitSettings.outputOption = TypeScript.switchToForwardSlashes(this.emitSettings.ioHost.resolvePath(this.emitSettings.outputOption));
  24184            if(this.emitSettings.ioHost.directoryExists(this.emitSettings.outputOption)) {
  24185                this.emitSettings.outputMany = true;
  24186            } else {
  24187                if(this.emitSettings.ioHost.fileExists(this.emitSettings.outputOption)) {
  24188                    this.emitSettings.outputMany = false;
  24189                } else {
  24190                    this.emitSettings.outputMany = !TypeScript.isJSFile(this.emitSettings.outputOption);
  24191                }
  24192            }
  24193            if(this.isDynamicModuleCompilation() && !this.emitSettings.outputMany) {
  24194                this.errorReporter.emitterError(null, "Cannot compile dynamic modules when emitting into single file");
  24195            }
  24196            if(this.emitSettings.outputMany) {
  24197                this.updateCommonDirectoryPath();
  24198            }
  24199        };
  24200        TypeScriptCompiler.prototype.useUTF8ForFile = function (script) {
  24201            if(this.emitSettings.outputMany) {
  24202                return this.outputScriptToUTF8(script);
  24203            } else {
  24204                return this.outputScriptsToUTF8((this.scripts.members));
  24205            }
  24206        };
  24207        TypeScriptCompiler.mapToDTSFileName = function mapToDTSFileName(fileName, wholeFileNameReplaced) {
  24208            return TypeScript.getDeclareFilePath(fileName);
  24209        }
  24210        TypeScriptCompiler.prototype.canEmitDeclarations = function (script) {
  24211            if(!this.settings.generateDeclarationFiles) {
  24212                return false;
  24213            }
  24214            if(!!script && (script.isDeclareFile || script.isResident || script.bod == null)) {
  24215                return false;
  24216            }
  24217            return true;
  24218        };
  24219        TypeScriptCompiler.prototype.emitDeclarationsUnit = function (script, reuseEmitter, declarationEmitter) {
  24220            if(!this.canEmitDeclarations(script)) {
  24221                return null;
  24222            }
  24223            if(!declarationEmitter) {
  24224                var declareFileName = this.emitSettings.mapOutputFileName(script.locationInfo.filename, TypeScriptCompiler.mapToDTSFileName);
  24225                var declareFile = this.createFile(declareFileName, this.useUTF8ForFile(script));
  24226                declarationEmitter = new TypeScript.DeclarationEmitter(this.typeChecker, this.emitSettings, this.errorReporter);
  24227                declarationEmitter.setDeclarationFile(declareFile);
  24228            }
  24229            declarationEmitter.emitDeclarations(script);
  24230            if(!reuseEmitter) {
  24231                declarationEmitter.Close();
  24232                return null;
  24233            } else {
  24234                return declarationEmitter;
  24235            }
  24236        };
  24237        TypeScriptCompiler.prototype.emitDeclarations = function () {
  24238            if(!this.canEmitDeclarations()) {
  24239                return;
  24240            }
  24241            if(this.errorReporter.hasErrors) {
  24242                return;
  24243            }
  24244            if(this.scripts.members.length == 0) {
  24245                return;
  24246            }
  24247            var declarationEmitter = null;
  24248            for(var i = 0, len = this.scripts.members.length; i < len; i++) {
  24249                var script = this.scripts.members[i];
  24250                if(this.emitSettings.outputMany || declarationEmitter == null) {
  24251                    declarationEmitter = this.emitDeclarationsUnit(script, !this.emitSettings.outputMany);
  24252                } else {
  24253                    this.emitDeclarationsUnit(script, true, declarationEmitter);
  24254                }
  24255            }
  24256            if(declarationEmitter) {
  24257                declarationEmitter.Close();
  24258            }
  24259        };
  24260        TypeScriptCompiler.mapToFileNameExtension = function mapToFileNameExtension(extension, fileName, wholeFileNameReplaced) {
  24261            if(wholeFileNameReplaced) {
  24262                return fileName;
  24263            } else {
  24264                var splitFname = fileName.split(".");
  24265                splitFname.pop();
  24266                return splitFname.join(".") + extension;
  24267            }
  24268        }
  24269        TypeScriptCompiler.mapToJSFileName = function mapToJSFileName(fileName, wholeFileNameReplaced) {
  24270            return TypeScriptCompiler.mapToFileNameExtension(".js", fileName, wholeFileNameReplaced);
  24271        }
  24272        TypeScriptCompiler.prototype.emitUnit = function (script, reuseEmitter, emitter) {
  24273            if(!script.emitRequired(this.emitSettings)) {
  24274                return null;
  24275            }
  24276            var fname = script.locationInfo.filename;
  24277            if(!emitter) {
  24278                var outFname = this.emitSettings.mapOutputFileName(fname, TypeScriptCompiler.mapToJSFileName);
  24279                var outFile = this.createFile(outFname, this.useUTF8ForFile(script));
  24280                emitter = new TypeScript.Emitter(this.typeChecker, outFname, outFile, this.emitSettings, this.errorReporter);
  24281                if(this.settings.mapSourceFiles) {
  24282                    emitter.setSourceMappings(new TypeScript.SourceMapper(fname, outFname, outFile, this.createFile(outFname + TypeScript.SourceMapper.MapFileExtension, false), this.errorReporter));
  24283                }
  24284            } else {
  24285                if(this.settings.mapSourceFiles) {
  24286                    emitter.setSourceMappings(new TypeScript.SourceMapper(fname, emitter.emittingFileName, emitter.outfile, emitter.sourceMapper.sourceMapOut, this.errorReporter));
  24287                }
  24288            }
  24289            this.typeChecker.locationInfo = script.locationInfo;
  24290            emitter.emitJavascript(script, TypeScript.TokenID.Comma, false);
  24291            if(!reuseEmitter) {
  24292                emitter.Close();
  24293                return null;
  24294            } else {
  24295                return emitter;
  24296            }
  24297        };
  24298        TypeScriptCompiler.prototype.emit = function (ioHost) {
  24299            this.parseEmitOption(ioHost);
  24300            var emitter = null;
  24301            for(var i = 0, len = this.scripts.members.length; i < len; i++) {
  24302                var script = this.scripts.members[i];
  24303                if(this.emitSettings.outputMany || emitter == null) {
  24304                    emitter = this.emitUnit(script, !this.emitSettings.outputMany);
  24305                } else {
  24306                    this.emitUnit(script, true, emitter);
  24307                }
  24308            }
  24309            if(emitter) {
  24310                emitter.Close();
  24311            }
  24312        };
  24313        TypeScriptCompiler.prototype.emitToOutfile = function (outputFile) {
  24314            if(this.settings.mapSourceFiles) {
  24315                throw Error("Cannot generate source map");
  24316            }
  24317            if(this.settings.generateDeclarationFiles) {
  24318                throw Error("Cannot generate declaration files");
  24319            }
  24320            if(this.settings.outputOption != "") {
  24321                throw Error("Cannot parse output option");
  24322            }
  24323            var emitter = emitter = new TypeScript.Emitter(this.typeChecker, "stdout", outputFile, this.emitSettings, this.errorReporter);
  24324            ; ;
  24325            for(var i = 0, len = this.scripts.members.length; i < len; i++) {
  24326                var script = this.scripts.members[i];
  24327                this.typeChecker.locationInfo = script.locationInfo;
  24328                emitter.emitJavascript(script, TypeScript.TokenID.Comma, false);
  24329            }
  24330        };
  24331        TypeScriptCompiler.prototype.emitAST = function (ioHost) {
  24332            this.parseEmitOption(ioHost);
  24333            var outFile = null;
  24334            var context = null;
  24335            for(var i = 0, len = this.scripts.members.length; i < len; i++) {
  24336                var script = this.scripts.members[i];
  24337                if(this.emitSettings.outputMany || context == null) {
  24338                    var fname = this.units[i].filename;
  24339                    var mapToTxtFileName = function (fileName, wholeFileNameReplaced) {
  24340                        return TypeScriptCompiler.mapToFileNameExtension(".txt", fileName, wholeFileNameReplaced);
  24341                    };
  24342                    var outFname = this.emitSettings.mapOutputFileName(fname, mapToTxtFileName);
  24343                    outFile = this.createFile(outFname, this.useUTF8ForFile(script));
  24344                    context = new TypeScript.PrintContext(outFile, this.parser);
  24345                }
  24346                TypeScript.getAstWalkerFactory().walk(script, TypeScript.prePrintAST, TypeScript.postPrintAST, null, context);
  24347                if(this.emitSettings.outputMany) {
  24348                    try  {
  24349                        outFile.Close();
  24350                    } catch (e) {
  24351                        this.errorReporter.emitterError(null, e.message);
  24352                    }
  24353                }
  24354            }
  24355            if(!this.emitSettings.outputMany) {
  24356                try  {
  24357                    outFile.Close();
  24358                } catch (e) {
  24359                    this.errorReporter.emitterError(null, e.message);
  24360                }
  24361            }
  24362        };
  24363        TypeScriptCompiler.prototype.outputScriptToUTF8 = function (script) {
  24364            return script.containsUnicodeChar || (this.emitSettings.emitComments && script.containsUnicodeCharInComment);
  24365        };
  24366        TypeScriptCompiler.prototype.outputScriptsToUTF8 = function (scripts) {
  24367            for(var i = 0, len = scripts.length; i < len; i++) {
  24368                var script = scripts[i];
  24369                if(this.outputScriptToUTF8(script)) {
  24370                    return true;
  24371                }
  24372            }
  24373            return false;
  24374        };
  24375        TypeScriptCompiler.prototype.createFile = function (fileName, useUTF8) {
  24376            try  {
  24377                return this.emitSettings.ioHost.createFile(fileName, useUTF8);
  24378            } catch (ex) {
  24379                this.errorReporter.emitterError(null, ex.message);
  24380            }
  24381        };
  24382        return TypeScriptCompiler;
  24383    })();
  24384    TypeScript.TypeScriptCompiler = TypeScriptCompiler;    
  24385    var ScopeEntry = (function () {
  24386        function ScopeEntry(name, type, sym) {
  24387            this.name = name;
  24388            this.type = type;
  24389            this.sym = sym;
  24390        }
  24391        return ScopeEntry;
  24392    })();
  24393    TypeScript.ScopeEntry = ScopeEntry;    
  24394    var ScopeTraversal = (function () {
  24395        function ScopeTraversal(compiler) {
  24396            this.compiler = compiler;
  24397        }
  24398        ScopeTraversal.prototype.getScope = function (enclosingScopeContext) {
  24399            if(enclosingScopeContext.enclosingObjectLit && enclosingScopeContext.isMemberCompletion) {
  24400                return enclosingScopeContext.getObjectLiteralScope();
  24401            } else {
  24402                if(enclosingScopeContext.isMemberCompletion) {
  24403                    if(enclosingScopeContext.useFullAst) {
  24404                        return this.compiler.typeFlow.findMemberScopeAtFullAst(enclosingScopeContext);
  24405                    } else {
  24406                        return this.compiler.typeFlow.findMemberScopeAt(enclosingScopeContext);
  24407                    }
  24408                } else {
  24409                    return enclosingScopeContext.getScope();
  24410                }
  24411            }
  24412        };
  24413        ScopeTraversal.prototype.getScopeEntries = function (enclosingScopeContext) {
  24414            var scope = this.getScope(enclosingScopeContext);
  24415            if(scope == null) {
  24416                return [];
  24417            }
  24418            var inScopeNames = new TypeScript.StringHashTable();
  24419            var allSymbolNames = scope.getAllSymbolNames(enclosingScopeContext.isMemberCompletion);
  24420            for(var i = 0; i < allSymbolNames.length; i++) {
  24421                var name = allSymbolNames[i];
  24422                if(name == TypeScript.globalId || name == "_Core" || name == "_element") {
  24423                    continue;
  24424                }
  24425                inScopeNames.add(name, "");
  24426            }
  24427            var svModuleDecl = this.compiler.typeChecker.currentModDecl;
  24428            this.compiler.typeChecker.currentModDecl = enclosingScopeContext.deepestModuleDecl;
  24429            var result = this.getTypeNamesForNames(enclosingScopeContext, inScopeNames.getAllKeys(), scope);
  24430            this.compiler.typeChecker.currentModDecl = svModuleDecl;
  24431            return result;
  24432        };
  24433        ScopeTraversal.prototype.getTypeNamesForNames = function (enclosingScopeContext, allNames, scope) {
  24434            var result = [];
  24435            var enclosingScope = enclosingScopeContext.getScope();
  24436            for(var i = 0; i < allNames.length; i++) {
  24437                var name = allNames[i];
  24438                var publicsOnly = enclosingScopeContext.publicsOnly && enclosingScopeContext.isMemberCompletion;
  24439                var symbol = scope.find(name, publicsOnly, false);
  24440                if(symbol == null) {
  24441                    symbol = scope.find(name, publicsOnly, true);
  24442                }
  24443                var displayThisMember = symbol && symbol.flags & TypeScript.SymbolFlags.Private ? symbol.container == scope.container : true;
  24444                if(symbol) {
  24445                    if(displayThisMember && !TypeScript.isQuoted(symbol.name) && !TypeScript.isRelative(symbol.name)) {
  24446                        var typeName = symbol.getType().getScopedTypeName(enclosingScope);
  24447                        result.push(new ScopeEntry(name, typeName, symbol));
  24448                    }
  24449                } else {
  24450                    if(name == "true" || name == "false") {
  24451                        result.push(new ScopeEntry(name, "bool", this.compiler.typeChecker.booleanType.symbol));
  24452                    }
  24453                }
  24454            }
  24455            return result;
  24456        };
  24457        return ScopeTraversal;
  24458    })();
  24459    TypeScript.ScopeTraversal = ScopeTraversal;    
  24460 })(TypeScript || (TypeScript = {}));
  24461 var TypeScript;
  24462 (function (TypeScript) {
  24463    (function (CompilerDiagnostics) {
  24464        CompilerDiagnostics.debug = false;
  24465        CompilerDiagnostics.diagnosticWriter = null;
  24466        CompilerDiagnostics.analysisPass = 0;
  24467        function Alert(output) {
  24468            if(CompilerDiagnostics.diagnosticWriter) {
  24469                CompilerDiagnostics.diagnosticWriter.Alert(output);
  24470            }
  24471        }
  24472        CompilerDiagnostics.Alert = Alert;
  24473        function debugPrint(s) {
  24474            if(CompilerDiagnostics.debug) {
  24475                Alert(s);
  24476            }
  24477        }
  24478        CompilerDiagnostics.debugPrint = debugPrint;
  24479        function assert(condition, s) {
  24480            if(CompilerDiagnostics.debug) {
  24481                if(!condition) {
  24482                    Alert(s);
  24483                }
  24484            }
  24485        }
  24486        CompilerDiagnostics.assert = assert;
  24487    })(TypeScript.CompilerDiagnostics || (TypeScript.CompilerDiagnostics = {}));
  24488    var CompilerDiagnostics = TypeScript.CompilerDiagnostics;
  24489    var NullLogger = (function () {
  24490        function NullLogger() { }
  24491        NullLogger.prototype.information = function () {
  24492            return false;
  24493        };
  24494        NullLogger.prototype.debug = function () {
  24495            return false;
  24496        };
  24497        NullLogger.prototype.warning = function () {
  24498            return false;
  24499        };
  24500        NullLogger.prototype.error = function () {
  24501            return false;
  24502        };
  24503        NullLogger.prototype.fatal = function () {
  24504            return false;
  24505        };
  24506        NullLogger.prototype.log = function (s) {
  24507        };
  24508        return NullLogger;
  24509    })();
  24510    TypeScript.NullLogger = NullLogger;    
  24511    var LoggerAdapter = (function () {
  24512        function LoggerAdapter(logger) {
  24513            this.logger = logger;
  24514            this._information = this.logger.information();
  24515            this._debug = this.logger.debug();
  24516            this._warning = this.logger.warning();
  24517            this._error = this.logger.error();
  24518            this._fatal = this.logger.fatal();
  24519        }
  24520        LoggerAdapter.prototype.information = function () {
  24521            return this._information;
  24522        };
  24523        LoggerAdapter.prototype.debug = function () {
  24524            return this._debug;
  24525        };
  24526        LoggerAdapter.prototype.warning = function () {
  24527            return this._warning;
  24528        };
  24529        LoggerAdapter.prototype.error = function () {
  24530            return this._error;
  24531        };
  24532        LoggerAdapter.prototype.fatal = function () {
  24533            return this._fatal;
  24534        };
  24535        LoggerAdapter.prototype.log = function (s) {
  24536            this.logger.log(s);
  24537        };
  24538        return LoggerAdapter;
  24539    })();
  24540    TypeScript.LoggerAdapter = LoggerAdapter;    
  24541    var BufferedLogger = (function () {
  24542        function BufferedLogger() {
  24543            this.logContents = [];
  24544        }
  24545        BufferedLogger.prototype.information = function () {
  24546            return false;
  24547        };
  24548        BufferedLogger.prototype.debug = function () {
  24549            return false;
  24550        };
  24551        BufferedLogger.prototype.warning = function () {
  24552            return false;
  24553        };
  24554        BufferedLogger.prototype.error = function () {
  24555            return false;
  24556        };
  24557        BufferedLogger.prototype.fatal = function () {
  24558            return false;
  24559        };
  24560        BufferedLogger.prototype.log = function (s) {
  24561            this.logContents.push(s);
  24562        };
  24563        return BufferedLogger;
  24564    })();
  24565    TypeScript.BufferedLogger = BufferedLogger;    
  24566    function timeFunction(logger, funcDescription, func) {
  24567        var start = +new Date();
  24568        var result = func();
  24569        var end = +new Date();
  24570        logger.log(funcDescription + " completed in " + (end - start) + " msec");
  24571        return result;
  24572    }
  24573    TypeScript.timeFunction = timeFunction;
  24574    function stringToLiteral(value, length) {
  24575        var result = "";
  24576        var addChar = function (index) {
  24577            var ch = value.charCodeAt(index);
  24578            switch(ch) {
  24579                case 9: {
  24580                    result += "\\t";
  24581                    break;
  24582 
  24583                }
  24584                case 10: {
  24585                    result += "\\n";
  24586                    break;
  24587 
  24588                }
  24589                case 11: {
  24590                    result += "\\v";
  24591                    break;
  24592 
  24593                }
  24594                case 12: {
  24595                    result += "\\f";
  24596                    break;
  24597 
  24598                }
  24599                case 13: {
  24600                    result += "\\r";
  24601                    break;
  24602 
  24603                }
  24604                case 34: {
  24605                    result += "\\\"";
  24606                    break;
  24607 
  24608                }
  24609                case 39: {
  24610                    result += "\\\'";
  24611                    break;
  24612 
  24613                }
  24614                case 92: {
  24615                    result += "\\";
  24616                    break;
  24617 
  24618                }
  24619                default: {
  24620                    result += value.charAt(index);
  24621 
  24622                }
  24623            }
  24624        };
  24625        var tooLong = (value.length > length);
  24626        if(tooLong) {
  24627            var mid = length >> 1;
  24628            for(var i = 0; i < mid; i++) {
  24629                addChar(i);
  24630            }
  24631            result += "(...)";
  24632            for(var i = value.length - mid; i < value.length; i++) {
  24633                addChar(i);
  24634            }
  24635        } else {
  24636            length = value.length;
  24637            for(var i = 0; i < length; i++) {
  24638                addChar(i);
  24639            }
  24640        }
  24641        return result;
  24642    }
  24643    TypeScript.stringToLiteral = stringToLiteral;
  24644 })(TypeScript || (TypeScript = {}));
  24645 var IOUtils;
  24646 (function (IOUtils) {
  24647    function createDirectoryStructure(ioHost, dirName) {
  24648        if(ioHost.directoryExists(dirName)) {
  24649            return;
  24650        }
  24651        var parentDirectory = ioHost.dirName(dirName);
  24652        if(parentDirectory != "") {
  24653            createDirectoryStructure(ioHost, parentDirectory);
  24654        }
  24655        ioHost.createDirectory(dirName);
  24656    }
  24657    function createFileAndFolderStructure(ioHost, fileName, useUTF8) {
  24658        var path = ioHost.resolvePath(fileName);
  24659        var dirName = ioHost.dirName(path);
  24660        createDirectoryStructure(ioHost, dirName);
  24661        return ioHost.createFile(path, useUTF8);
  24662    }
  24663    IOUtils.createFileAndFolderStructure = createFileAndFolderStructure;
  24664    function throwIOError(message, error) {
  24665        var errorMessage = message;
  24666        if(error && error.message) {
  24667            errorMessage += (" " + error.message);
  24668        }
  24669        throw new Error(errorMessage);
  24670    }
  24671    IOUtils.throwIOError = throwIOError;
  24672 })(IOUtils || (IOUtils = {}));
  24673 
  24674 var IO = (function () {
  24675    function getWindowsScriptHostIO() {
  24676        var fso = new ActiveXObject("Scripting.FileSystemObject");
  24677        var streamObjectPool = [];
  24678        function getStreamObject() {
  24679            if(streamObjectPool.length > 0) {
  24680                return streamObjectPool.pop();
  24681            } else {
  24682                return new ActiveXObject("ADODB.Stream");
  24683            }
  24684        }
  24685        function releaseStreamObject(obj) {
  24686            streamObjectPool.push(obj);
  24687        }
  24688        var args = [];
  24689        for(var i = 0; i < WScript.Arguments.length; i++) {
  24690            args[i] = WScript.Arguments.Item(i);
  24691        }
  24692        return {
  24693            readFile: function (path) {
  24694                try  {
  24695                    var streamObj = getStreamObject();
  24696                    streamObj.Open();
  24697                    streamObj.Type = 2;
  24698                    streamObj.Charset = 'x-ansi';
  24699                    streamObj.LoadFromFile(path);
  24700                    var bomChar = streamObj.ReadText(2);
  24701                    streamObj.Position = 0;
  24702                    if((bomChar.charCodeAt(0) == 254 && bomChar.charCodeAt(1) == 255) || (bomChar.charCodeAt(0) == 255 && bomChar.charCodeAt(1) == 254)) {
  24703                        streamObj.Charset = 'unicode';
  24704                    } else {
  24705                        if(bomChar.charCodeAt(0) == 239 && bomChar.charCodeAt(1) == 187) {
  24706                            streamObj.Charset = 'utf-8';
  24707                        }
  24708                    }
  24709                    var str = streamObj.ReadText(-1);
  24710                    streamObj.Close();
  24711                    releaseStreamObject(streamObj);
  24712                    return str;
  24713                } catch (err) {
  24714                    IOUtils.throwIOError("Error reading file \"" + path + "\".", err);
  24715                }
  24716            },
  24717            writeFile: function (path, contents) {
  24718                var file = this.createFile(path);
  24719                file.Write(contents);
  24720                file.Close();
  24721            },
  24722            fileExists: function (path) {
  24723                return fso.FileExists(path);
  24724            },
  24725            resolvePath: function (path) {
  24726                return fso.GetAbsolutePathName(path);
  24727            },
  24728            dirName: function (path) {
  24729                return fso.GetParentFolderName(path);
  24730            },
  24731            findFile: function (rootPath, partialFilePath) {
  24732                var path = fso.GetAbsolutePathName(rootPath) + "/" + partialFilePath;
  24733                while(true) {
  24734                    if(fso.FileExists(path)) {
  24735                        try  {
  24736                            var content = this.readFile(path);
  24737                            return {
  24738                                content: content,
  24739                                path: path
  24740                            };
  24741                        } catch (err) {
  24742                        }
  24743                    } else {
  24744                        rootPath = fso.GetParentFolderName(fso.GetAbsolutePathName(rootPath));
  24745                        if(rootPath == "") {
  24746                            return null;
  24747                        } else {
  24748                            path = fso.BuildPath(rootPath, partialFilePath);
  24749                        }
  24750                    }
  24751                }
  24752            },
  24753            deleteFile: function (path) {
  24754                try  {
  24755                    if(fso.FileExists(path)) {
  24756                        fso.DeleteFile(path, true);
  24757                    }
  24758                } catch (e) {
  24759                    IOUtils.throwIOError("Couldn't delete file '" + path + "'.", e);
  24760                }
  24761            },
  24762            createFile: function (path, useUTF8) {
  24763                try  {
  24764                    var streamObj = getStreamObject();
  24765                    streamObj.Charset = useUTF8 ? 'utf-8' : 'x-ansi';
  24766                    streamObj.Open();
  24767                    return {
  24768                        Write: function (str) {
  24769                            streamObj.WriteText(str, 0);
  24770                        },
  24771                        WriteLine: function (str) {
  24772                            streamObj.WriteText(str, 1);
  24773                        },
  24774                        Close: function () {
  24775                            try  {
  24776                                streamObj.SaveToFile(path, 2);
  24777                            } catch (saveError) {
  24778                                IOUtils.throwIOError("Couldn't write to file '" + path + "'.", saveError);
  24779                            }finally {
  24780                                if(streamObj.State != 0) {
  24781                                    streamObj.Close();
  24782                                }
  24783                                releaseStreamObject(streamObj);
  24784                            }
  24785                        }
  24786                    };
  24787                } catch (creationError) {
  24788                    IOUtils.throwIOError("Couldn't write to file '" + path + "'.", creationError);
  24789                }
  24790            },
  24791            directoryExists: function (path) {
  24792                return fso.FolderExists(path);
  24793            },
  24794            createDirectory: function (path) {
  24795                try  {
  24796                    if(!this.directoryExists(path)) {
  24797                        fso.CreateFolder(path);
  24798                    }
  24799                } catch (e) {
  24800                    IOUtils.throwIOError("Couldn't create directory '" + path + "'.", e);
  24801                }
  24802            },
  24803            dir: function (path, spec, options) {
  24804                options = options || {
  24805                };
  24806                function filesInFolder(folder, root) {
  24807                    var paths = [];
  24808                    var fc;
  24809                    if(options.recursive) {
  24810                        fc = new Enumerator(folder.subfolders);
  24811                        for(; !fc.atEnd(); fc.moveNext()) {
  24812                            paths = paths.concat(filesInFolder(fc.item(), root + "/" + fc.item().Name));
  24813                        }
  24814                    }
  24815                    fc = new Enumerator(folder.files);
  24816                    for(; !fc.atEnd(); fc.moveNext()) {
  24817                        if(!spec || fc.item().Name.match(spec)) {
  24818                            paths.push(root + "/" + fc.item().Name);
  24819                        }
  24820                    }
  24821                    return paths;
  24822                }
  24823                var folder = fso.GetFolder(path);
  24824                var paths = [];
  24825                return filesInFolder(folder, path);
  24826            },
  24827            print: function (str) {
  24828                WScript.StdOut.Write(str);
  24829            },
  24830            printLine: function (str) {
  24831                WScript.Echo(str);
  24832            },
  24833            arguments: args,
  24834            stderr: WScript.StdErr,
  24835            stdout: WScript.StdOut,
  24836            watchFile: null,
  24837            run: function (source, filename) {
  24838                try  {
  24839                    eval(source);
  24840                } catch (e) {
  24841                    IOUtils.throwIOError("Error while executing file '" + filename + "'.", e);
  24842                }
  24843            },
  24844            getExecutingFilePath: function () {
  24845                return WScript.ScriptFullName;
  24846            },
  24847            quit: function (exitCode) {
  24848                if (typeof exitCode === "undefined") { exitCode = 0; }
  24849                try  {
  24850                    WScript.Quit(exitCode);
  24851                } catch (e) {
  24852                }
  24853            }
  24854        };
  24855    }
  24856    ; ;
  24857    function getNodeIO() {
  24858        var _fs = require('fs');
  24859        var _path = require('path');
  24860        var _module = require('module');
  24861        return {
  24862            readFile: function (file) {
  24863                try  {
  24864                    var buffer = _fs.readFileSync(file);
  24865                    switch(buffer[0]) {
  24866                        case 254: {
  24867                            if(buffer[1] == 255) {
  24868                                var i = 0;
  24869                                while((i + 1) < buffer.length) {
  24870                                    var temp = buffer[i];
  24871                                    buffer[i] = buffer[i + 1];
  24872                                    buffer[i + 1] = temp;
  24873                                    i += 2;
  24874                                }
  24875                                return buffer.toString("ucs2", 2);
  24876                            }
  24877                            break;
  24878 
  24879                        }
  24880                        case 255: {
  24881                            if(buffer[1] == 254) {
  24882                                return buffer.toString("ucs2", 2);
  24883                            }
  24884                            break;
  24885 
  24886                        }
  24887                        case 239: {
  24888                            if(buffer[1] == 187) {
  24889                                return buffer.toString("utf8", 3);
  24890                            }
  24891 
  24892                        }
  24893                    }
  24894                    return buffer.toString();
  24895                } catch (e) {
  24896                    IOUtils.throwIOError("Error reading file \"" + file + "\".", e);
  24897                }
  24898            },
  24899            writeFile: _fs.writeFileSync,
  24900            deleteFile: function (path) {
  24901                try  {
  24902                    _fs.unlinkSync(path);
  24903                } catch (e) {
  24904                    IOUtils.throwIOError("Couldn't delete file '" + path + "'.", e);
  24905                }
  24906            },
  24907            fileExists: function (path) {
  24908                return _fs.existsSync(path);
  24909            },
  24910            createFile: function (path, useUTF8) {
  24911                function mkdirRecursiveSync(path) {
  24912                    var stats = _fs.statSync(path);
  24913                    if(stats.isFile()) {
  24914                        IOUtils.throwIOError("\"" + path + "\" exists but isn't a directory.", null);
  24915                    } else {
  24916                        if(stats.isDirectory()) {
  24917                            return;
  24918                        } else {
  24919                            mkdirRecursiveSync(_path.dirname(path));
  24920                            _fs.mkdirSync(path, 509);
  24921                        }
  24922                    }
  24923                }
  24924                mkdirRecursiveSync(_path.dirname(path));
  24925                try  {
  24926                    var fd = _fs.openSync(path, 'w');
  24927                } catch (e) {
  24928                    IOUtils.throwIOError("Couldn't write to file '" + path + "'.", e);
  24929                }
  24930                return {
  24931                    Write: function (str) {
  24932                        _fs.writeSync(fd, str);
  24933                    },
  24934                    WriteLine: function (str) {
  24935                        _fs.writeSync(fd, str + '\r\n');
  24936                    },
  24937                    Close: function () {
  24938                        _fs.closeSync(fd);
  24939                        fd = null;
  24940                    }
  24941                };
  24942            },
  24943            dir: function dir(path, spec, options) {
  24944                options = options || {
  24945                };
  24946                function filesInFolder(folder) {
  24947                    var paths = [];
  24948                    var files = _fs.readdirSync(folder);
  24949                    for(var i = 0; i < files.length; i++) {
  24950                        var stat = _fs.statSync(folder + "/" + files[i]);
  24951                        if(options.recursive && stat.isDirectory()) {
  24952                            paths = paths.concat(filesInFolder(folder + "/" + files[i]));
  24953                        } else {
  24954                            if(stat.isFile() && (!spec || files[i].match(spec))) {
  24955                                paths.push(folder + "/" + files[i]);
  24956                            }
  24957                        }
  24958                    }
  24959                    return paths;
  24960                }
  24961                return filesInFolder(path);
  24962            },
  24963            createDirectory: function (path) {
  24964                try  {
  24965                    if(!this.directoryExists(path)) {
  24966                        _fs.mkdirSync(path);
  24967                    }
  24968                } catch (e) {
  24969                    IOUtils.throwIOError("Couldn't create directory '" + path + "'.", e);
  24970                }
  24971            },
  24972            directoryExists: function (path) {
  24973                return _fs.existsSync(path) && _fs.lstatSync(path).isDirectory();
  24974            },
  24975            resolvePath: function (path) {
  24976                return _path.resolve(path);
  24977            },
  24978            dirName: function (path) {
  24979                return _path.dirname(path);
  24980            },
  24981            findFile: function (rootPath, partialFilePath) {
  24982                var path = rootPath + "/" + partialFilePath;
  24983                while(true) {
  24984                    if(_fs.existsSync(path)) {
  24985                        try  {
  24986                            var content = this.readFile(path);
  24987                            return {
  24988                                content: content,
  24989                                path: path
  24990                            };
  24991                        } catch (err) {
  24992                        }
  24993                    } else {
  24994                        var parentPath = _path.resolve(rootPath, "..");
  24995                        if(rootPath === parentPath) {
  24996                            return null;
  24997                        } else {
  24998                            rootPath = parentPath;
  24999                            path = _path.resolve(rootPath, partialFilePath);
  25000                        }
  25001                    }
  25002                }
  25003            },
  25004            print: function (str) {
  25005                process.stdout.write(str);
  25006            },
  25007            printLine: function (str) {
  25008                process.stdout.write(str + '\n');
  25009            },
  25010            arguments: process.argv.slice(2),
  25011            stderr: {
  25012                Write: function (str) {
  25013                    process.stderr.write(str);
  25014                },
  25015                WriteLine: function (str) {
  25016                    process.stderr.write(str + '\n');
  25017                },
  25018                Close: function () {
  25019                }
  25020            },
  25021            stdout: {
  25022                Write: function (str) {
  25023                    process.stdout.write(str);
  25024                },
  25025                WriteLine: function (str) {
  25026                    process.stdout.write(str + '\n');
  25027                },
  25028                Close: function () {
  25029                }
  25030            },
  25031            watchFile: function (filename, callback) {
  25032                var firstRun = true;
  25033                var processingChange = false;
  25034                var fileChanged = function (curr, prev) {
  25035                    if(!firstRun) {
  25036                        if(curr.mtime < prev.mtime) {
  25037                            return;
  25038                        }
  25039                        _fs.unwatchFile(filename, fileChanged);
  25040                        if(!processingChange) {
  25041                            processingChange = true;
  25042                            callback(filename);
  25043                            setTimeout(function () {
  25044                                processingChange = false;
  25045                            }, 100);
  25046                        }
  25047                    }
  25048                    firstRun = false;
  25049                    _fs.watchFile(filename, {
  25050                        persistent: true,
  25051                        interval: 500
  25052                    }, fileChanged);
  25053                };
  25054                fileChanged();
  25055                return {
  25056                    filename: filename,
  25057                    close: function () {
  25058                        _fs.unwatchFile(filename, fileChanged);
  25059                    }
  25060                };
  25061            },
  25062            run: function (source, filename) {
  25063                require.main.filename = filename;
  25064                require.main.paths = _module._nodeModulePaths(_path.dirname(_fs.realpathSync(filename)));
  25065                require.main._compile(source, filename);
  25066            },
  25067            getExecutingFilePath: function () {
  25068                return process.mainModule.filename;
  25069            },
  25070            quit: process.exit
  25071        };
  25072    }
  25073    ; ;
  25074    if(typeof ActiveXObject === "function") {
  25075        return getWindowsScriptHostIO();
  25076    } else {
  25077        if(typeof require === "function") {
  25078            return getNodeIO();
  25079        } else {
  25080            return null;
  25081        }
  25082    }
  25083 })();
  25084 var OptionsParser = (function () {
  25085    function OptionsParser(host) {
  25086        this.host = host;
  25087        this.DEFAULT_SHORT_FLAG = "-";
  25088        this.DEFAULT_LONG_FLAG = "--";
  25089        this.unnamed = [];
  25090        this.options = [];
  25091    }
  25092    OptionsParser.prototype.findOption = function (arg) {
  25093        for(var i = 0; i < this.options.length; i++) {
  25094            if(arg === this.options[i].short || arg === this.options[i].name) {
  25095                return this.options[i];
  25096            }
  25097        }
  25098        return null;
  25099    };
  25100    OptionsParser.prototype.printUsage = function () {
  25101        this.host.printLine("Syntax:   tsc [options] [file ..]");
  25102        this.host.printLine("");
  25103        this.host.printLine("Examples: tsc hello.ts");
  25104        this.host.printLine("          tsc --out foo.js foo.ts");
  25105        this.host.printLine("          tsc @args.txt");
  25106        this.host.printLine("");
  25107        this.host.printLine("Options:");
  25108        var output = [];
  25109        var maxLength = 0;
  25110        this.options = this.options.sort(function (a, b) {
  25111            var aName = a.name.toLowerCase();
  25112            var bName = b.name.toLowerCase();
  25113            if(aName > bName) {
  25114                return 1;
  25115            } else {
  25116                if(aName < bName) {
  25117                    return -1;
  25118                } else {
  25119                    return 0;
  25120                }
  25121            }
  25122        });
  25123        for(var i = 0; i < this.options.length; i++) {
  25124            var option = this.options[i];
  25125            if(option.experimental) {
  25126                continue;
  25127            }
  25128            if(!option.usage) {
  25129                break;
  25130            }
  25131            var usageString = "  ";
  25132            var type = option.type ? " " + option.type.toUpperCase() : "";
  25133            if(option.short) {
  25134                usageString += this.DEFAULT_SHORT_FLAG + option.short + type + ", ";
  25135            }
  25136            usageString += this.DEFAULT_LONG_FLAG + option.name + type;
  25137            output.push([
  25138                usageString, 
  25139                option.usage
  25140            ]);
  25141            if(usageString.length > maxLength) {
  25142                maxLength = usageString.length;
  25143            }
  25144        }
  25145        output.push([
  25146            "  @<file>", 
  25147            "Insert command line options and files from a file."
  25148        ]);
  25149        for(var i = 0; i < output.length; i++) {
  25150            this.host.printLine(output[i][0] + (new Array(maxLength - output[i][0].length + 3)).join(" ") + output[i][1]);
  25151        }
  25152    };
  25153    OptionsParser.prototype.option = function (name, config, short) {
  25154        if(!config) {
  25155            config = short;
  25156            short = null;
  25157        }
  25158        config.name = name;
  25159        config.short = short;
  25160        config.flag = false;
  25161        this.options.push(config);
  25162    };
  25163    OptionsParser.prototype.flag = function (name, config, short) {
  25164        if(!config) {
  25165            config = short;
  25166            short = null;
  25167        }
  25168        config.name = name;
  25169        config.short = short;
  25170        config.flag = true;
  25171        this.options.push(config);
  25172    };
  25173    OptionsParser.prototype.parseString = function (argString) {
  25174        var position = 0;
  25175        var tokens = argString.match(/\s+|"|[^\s"]+/g);
  25176        function peek() {
  25177            return tokens[position];
  25178        }
  25179        function consume() {
  25180            return tokens[position++];
  25181        }
  25182        function consumeQuotedString() {
  25183            var value = '';
  25184            consume();
  25185            var token = peek();
  25186            while(token && token !== '"') {
  25187                consume();
  25188                value += token;
  25189                token = peek();
  25190            }
  25191            consume();
  25192            return value;
  25193        }
  25194        var args = [];
  25195        var currentArg = '';
  25196        while(position < tokens.length) {
  25197            var token = peek();
  25198            if(token === '"') {
  25199                currentArg += consumeQuotedString();
  25200            } else {
  25201                if(token.match(/\s/)) {
  25202                    if(currentArg.length > 0) {
  25203                        args.push(currentArg);
  25204                        currentArg = '';
  25205                    }
  25206                    consume();
  25207                } else {
  25208                    consume();
  25209                    currentArg += token;
  25210                }
  25211            }
  25212        }
  25213        if(currentArg.length > 0) {
  25214            args.push(currentArg);
  25215        }
  25216        this.parse(args);
  25217    };
  25218    OptionsParser.prototype.parse = function (args) {
  25219        var position = 0;
  25220        function consume() {
  25221            return args[position++];
  25222        }
  25223        while(position < args.length) {
  25224            var current = consume();
  25225            var match = current.match(/^(--?|@)(.*)/);
  25226            var value = null;
  25227            if(match) {
  25228                if(match[1] === '@') {
  25229                    this.parseString(this.host.readFile(match[2]));
  25230                } else {
  25231                    var arg = match[2];
  25232                    var option = this.findOption(arg);
  25233                    if(option === null) {
  25234                        this.host.printLine("Unknown option '" + arg + "'");
  25235                        this.host.printLine("Use the '--help' flag to see options");
  25236                    } else {
  25237                        if(!option.flag) {
  25238                            value = consume();
  25239                        }
  25240                        option.set(value);
  25241                    }
  25242                }
  25243            } else {
  25244                this.unnamed.push(current);
  25245            }
  25246        }
  25247    };
  25248    return OptionsParser;
  25249 })();
  25250 var CommandLineHost = (function () {
  25251    function CommandLineHost(compilationSettings) {
  25252        this.compilationSettings = compilationSettings;
  25253        this.pathMap = {
  25254        };
  25255        this.resolvedPaths = {
  25256        };
  25257    }
  25258    CommandLineHost.prototype.getPathIdentifier = function (path) {
  25259        return this.compilationSettings.useCaseSensitiveFileResolution ? path : path.toLocaleUpperCase();
  25260    };
  25261    CommandLineHost.prototype.isResolved = function (path) {
  25262        return this.resolvedPaths[this.getPathIdentifier(this.pathMap[path])] != undefined;
  25263    };
  25264    CommandLineHost.prototype.resolveCompilationEnvironment = function (preEnv, resolver, traceDependencies) {
  25265        var _this = this;
  25266        var resolvedEnv = new TypeScript.CompilationEnvironment(preEnv.compilationSettings, preEnv.ioHost);
  25267        var nCode = preEnv.code.length;
  25268        var path = "";
  25269        var postResolutionError = function (errorFile, errorMessage) {
  25270            TypeScript.CompilerDiagnostics.debugPrint("Could not resolve file '" + errorFile + "'" + (errorMessage == "" ? "" : ": " + errorMessage));
  25271        };
  25272        var resolutionDispatcher = {
  25273            postResolutionError: postResolutionError,
  25274            postResolution: function (path, code) {
  25275                var pathId = _this.getPathIdentifier(path);
  25276                if(!_this.resolvedPaths[pathId]) {
  25277                    resolvedEnv.code.push(code);
  25278                    _this.resolvedPaths[pathId] = true;
  25279                }
  25280            }
  25281        };
  25282        for(var i = 0; i < nCode; i++) {
  25283            path = TypeScript.switchToForwardSlashes(preEnv.ioHost.resolvePath(preEnv.code[i].path));
  25284            this.pathMap[preEnv.code[i].path] = path;
  25285            resolver.resolveCode(path, "", false, resolutionDispatcher);
  25286        }
  25287        return resolvedEnv;
  25288    };
  25289    return CommandLineHost;
  25290 })();
  25291 var BatchCompiler = (function () {
  25292    function BatchCompiler(ioHost) {
  25293        this.ioHost = ioHost;
  25294        this.resolvedEnvironment = null;
  25295        this.hasResolveErrors = false;
  25296        this.compilerVersion = "0.8.2.0";
  25297        this.printedVersion = false;
  25298        this.compilationSettings = new TypeScript.CompilationSettings();
  25299        this.compilationEnvironment = new TypeScript.CompilationEnvironment(this.compilationSettings, this.ioHost);
  25300    }
  25301    BatchCompiler.prototype.resolve = function () {
  25302        var resolver = new TypeScript.CodeResolver(this.compilationEnvironment);
  25303        var commandLineHost = new CommandLineHost(this.compilationSettings);
  25304        var ret = commandLineHost.resolveCompilationEnvironment(this.compilationEnvironment, resolver, true);
  25305        this.hasResolveErrors = false;
  25306        for(var i = 0; i < this.compilationEnvironment.code.length; i++) {
  25307            if(!commandLineHost.isResolved(this.compilationEnvironment.code[i].path)) {
  25308                this.hasResolveErrors = true;
  25309                var path = this.compilationEnvironment.code[i].path;
  25310                if(!TypeScript.isSTRFile(path) && !TypeScript.isDSTRFile(path) && !TypeScript.isTSFile(path) && !TypeScript.isDTSFile(path)) {
  25311                    this.ioHost.stderr.WriteLine("Unknown extension for file: \"" + path + "\". Only .ts and .d.ts extensions are allowed.");
  25312                } else {
  25313                    this.ioHost.stderr.WriteLine("Error reading file \"" + path + "\": File not found");
  25314                }
  25315            }
  25316        }
  25317        return ret;
  25318    };
  25319    BatchCompiler.prototype.compile = function () {
  25320        var _this = this;
  25321        var compiler;
  25322        compiler = new TypeScript.TypeScriptCompiler(this.ioHost.stderr, new TypeScript.NullLogger(), this.compilationSettings);
  25323        compiler.setErrorOutput(this.ioHost.stderr);
  25324        compiler.setErrorCallback(function (minChar, charLen, message, unitIndex) {
  25325            compiler.errorReporter.hasErrors = true;
  25326            var fname = _this.resolvedEnvironment.code[unitIndex].path;
  25327            var lineCol = {
  25328                line: -1,
  25329                col: -1
  25330            };
  25331            compiler.parser.getSourceLineCol(lineCol, minChar);
  25332            var msg = fname + " (" + lineCol.line + "," + (lineCol.col + 1) + "): " + message;
  25333            if(_this.compilationSettings.errorRecovery) {
  25334                _this.ioHost.stderr.WriteLine(msg);
  25335            } else {
  25336                throw new SyntaxError(msg);
  25337            }
  25338        });
  25339        if(this.compilationSettings.emitComments) {
  25340            compiler.emitCommentsToOutput();
  25341        }
  25342        var consumeUnit = function (code, addAsResident) {
  25343            try  {
  25344                if(!_this.compilationSettings.resolve) {
  25345                    code.content = _this.ioHost.readFile(code.path);
  25346                    if(_this.compilationSettings.generateDeclarationFiles) {
  25347                        TypeScript.CompilerDiagnostics.assert(code.referencedFiles == null, "With no resolve option, referenced files need to null");
  25348                        code.referencedFiles = TypeScript.getReferencedFiles(code);
  25349                    }
  25350                }
  25351                if(code.content) {
  25352                    if(_this.compilationSettings.parseOnly) {
  25353                        compiler.parseUnit(code.content, code.path);
  25354                    } else {
  25355                        if(_this.compilationSettings.errorRecovery) {
  25356                            compiler.parser.setErrorRecovery(_this.ioHost.stderr);
  25357                        }
  25358                        compiler.addUnit(code.content, code.path, addAsResident, code.referencedFiles);
  25359                    }
  25360                }
  25361            } catch (err) {
  25362                compiler.errorReporter.hasErrors = true;
  25363                _this.ioHost.stderr.WriteLine(err.message);
  25364            }
  25365        };
  25366        for(var iCode = 0; iCode < this.resolvedEnvironment.code.length; iCode++) {
  25367            if(!this.compilationSettings.parseOnly || (iCode > 0)) {
  25368                consumeUnit(this.resolvedEnvironment.code[iCode], false);
  25369            }
  25370        }
  25371        var emitterIOHost = {
  25372            createFile: function (fileName, useUTF8) {
  25373                return IOUtils.createFileAndFolderStructure(_this.ioHost, fileName, useUTF8);
  25374            },
  25375            directoryExists: this.ioHost.directoryExists,
  25376            fileExists: this.ioHost.fileExists,
  25377            resolvePath: this.ioHost.resolvePath
  25378        };
  25379        try  {
  25380            if(!this.compilationSettings.parseOnly) {
  25381                compiler.typeCheck();
  25382                compiler.emit(emitterIOHost);
  25383                compiler.emitDeclarations();
  25384            } else {
  25385                compiler.emitAST(emitterIOHost);
  25386            }
  25387        } catch (err) {
  25388            compiler.errorReporter.hasErrors = true;
  25389            if(err.message != "EmitError") {
  25390                throw err;
  25391            }
  25392        }
  25393        return compiler.errorReporter.hasErrors;
  25394    };
  25395    BatchCompiler.prototype.run = function () {
  25396        for(var i = 0; i < this.compilationEnvironment.code.length; i++) {
  25397            var unit = this.compilationEnvironment.code[i];
  25398            var outputFileName = unit.path;
  25399            if(TypeScript.isTSFile(outputFileName)) {
  25400                outputFileName = outputFileName.replace(/\.ts$/, ".js");
  25401            } else {
  25402                if(TypeScript.isSTRFile(outputFileName)) {
  25403                    outputFileName = outputFileName.replace(/\.str$/, ".js");
  25404                }
  25405            }
  25406            if(this.ioHost.fileExists(outputFileName)) {
  25407                var unitRes = this.ioHost.readFile(outputFileName);
  25408                this.ioHost.run(unitRes, outputFileName);
  25409            }
  25410        }
  25411    };
  25412    BatchCompiler.prototype.batchCompile = function () {
  25413        var _this = this;
  25414        TypeScript.CompilerDiagnostics.diagnosticWriter = {
  25415            Alert: function (s) {
  25416                _this.ioHost.printLine(s);
  25417            }
  25418        };
  25419        var code;
  25420        var opts = new OptionsParser(this.ioHost);
  25421        opts.option('out', {
  25422            usage: 'Concatenate and emit output to single file | Redirect output structure to the directory',
  25423            type: 'file|directory',
  25424            set: function (str) {
  25425                _this.compilationSettings.outputOption = str;
  25426            }
  25427        });
  25428        opts.option('style', {
  25429            usage: 'Select style checking options (examples --style requireSemi:off or --style "eqeqeq;bitwise:off")',
  25430            experimental: true,
  25431            set: function (str) {
  25432                _this.compilationSettings.setStyleOptions(str);
  25433            }
  25434        });
  25435        opts.flag('sourcemap', {
  25436            usage: 'Generates corresponding .map file',
  25437            set: function () {
  25438                _this.compilationSettings.mapSourceFiles = true;
  25439            }
  25440        });
  25441        opts.flag('declaration', {
  25442            usage: 'Generates corresponding .d.ts file',
  25443            set: function () {
  25444                _this.compilationSettings.generateDeclarationFiles = true;
  25445            }
  25446        });
  25447        if(this.ioHost.watchFile) {
  25448            opts.flag('watch', {
  25449                usage: 'Watch output files',
  25450                set: function () {
  25451                    _this.compilationSettings.watch = true;
  25452                }
  25453            }, 'w');
  25454        }
  25455        opts.flag('exec', {
  25456            usage: 'Execute the script after compilation',
  25457            set: function () {
  25458                _this.compilationSettings.exec = true;
  25459            }
  25460        }, 'e');
  25461        opts.flag('parse', {
  25462            usage: 'Parse only',
  25463            experimental: true,
  25464            set: function () {
  25465                _this.compilationSettings.parseOnly = true;
  25466            }
  25467        });
  25468        opts.flag('minw', {
  25469            usage: 'Minimize whitespace',
  25470            experimental: true,
  25471            set: function () {
  25472                _this.compilationSettings.minWhitespace = true;
  25473            }
  25474        }, 'mw');
  25475        opts.flag('const', {
  25476            usage: 'Propagate constants to emitted code',
  25477            experimental: true,
  25478            set: function () {
  25479                _this.compilationSettings.propagateConstants = true;
  25480            }
  25481        });
  25482        opts.flag('errorrecovery', {
  25483            usage: 'Enable error recovery',
  25484            experimental: true,
  25485            set: function () {
  25486                _this.compilationSettings.errorRecovery = true;
  25487            }
  25488        }, 'er');
  25489        opts.flag('comments', {
  25490            usage: 'Emit comments to output',
  25491            set: function () {
  25492                _this.compilationSettings.emitComments = true;
  25493            }
  25494        }, 'c');
  25495        opts.flag('cflow', {
  25496            usage: 'Control flow',
  25497            experimental: true,
  25498            set: function () {
  25499                _this.compilationSettings.controlFlow = true;
  25500            }
  25501        });
  25502        opts.flag('cflowp', {
  25503            usage: 'Print control flow',
  25504            experimental: true,
  25505            set: function () {
  25506                _this.compilationSettings.controlFlow = true;
  25507                _this.compilationSettings.printControlFlow = true;
  25508            }
  25509        });
  25510        opts.flag('cflowu', {
  25511            usage: 'Print Use Def control flow',
  25512            experimental: true,
  25513            set: function () {
  25514                _this.compilationSettings.controlFlow = true;
  25515                _this.compilationSettings.controlFlowUseDef = true;
  25516            }
  25517        });
  25518        opts.flag('noerroronwith', {
  25519            usage: 'Allow with statements',
  25520            experimental: true,
  25521            set: function () {
  25522                _this.compilationSettings.errorOnWith = false;
  25523            }
  25524        });
  25525        opts.flag('noresolve', {
  25526            usage: 'Skip resolution and preprocessing',
  25527            experimental: true,
  25528            set: function () {
  25529                _this.compilationSettings.resolve = false;
  25530                _this.compilationSettings.preprocess = false;
  25531            }
  25532        });
  25533        opts.flag('debug', {
  25534            usage: 'Print debug output',
  25535            experimental: true,
  25536            set: function () {
  25537                TypeScript.CompilerDiagnostics.debug = true;
  25538            }
  25539        });
  25540        opts.flag('canCallDefinitionSignature', {
  25541            usage: 'Allows you to call the definition signature of an overload group',
  25542            experimental: true,
  25543            set: function () {
  25544                _this.compilationSettings.canCallDefinitionSignature = true;
  25545            }
  25546        });
  25547        opts.flag('nooptimizemodules', {
  25548            usage: 'Do not optimize module codegen',
  25549            experimental: true,
  25550            set: function () {
  25551                TypeScript.optimizeModuleCodeGen = false;
  25552            }
  25553        });
  25554        opts.flag('nolib', {
  25555            usage: 'Do not include a default lib.d.ts with global declarations',
  25556            set: function () {
  25557                _this.compilationSettings.useDefaultLib = false;
  25558            }
  25559        });
  25560        opts.flag('inferProperties', {
  25561            usage: 'Infer class properties from top-level assignments to \'this\'',
  25562            experimental: true,
  25563            set: function () {
  25564                _this.compilationSettings.inferPropertiesFromThisAssignment = true;
  25565            }
  25566        });
  25567        opts.option('target', {
  25568            usage: 'Specify ECMAScript target version: "ES3" (default), or "ES5"',
  25569            type: 'VER',
  25570            set: function (type) {
  25571                type = type.toLowerCase();
  25572                if(type === 'es3') {
  25573                    _this.compilationSettings.codeGenTarget = TypeScript.CodeGenTarget.ES3;
  25574                } else {
  25575                    if(type === 'es5') {
  25576                        _this.compilationSettings.codeGenTarget = TypeScript.CodeGenTarget.ES5;
  25577                    } else {
  25578                        _this.ioHost.printLine("ECMAScript target version '" + type + "' not supported.  Using default 'ES3' code generation");
  25579                    }
  25580                }
  25581            }
  25582        });
  25583        opts.option('module', {
  25584            usage: 'Specify module code generation: "commonjs" (default) or "amd"',
  25585            type: 'kind',
  25586            set: function (type) {
  25587                type = type.toLowerCase();
  25588                if(type === 'commonjs' || type === 'node') {
  25589                    TypeScript.moduleGenTarget = TypeScript.ModuleGenTarget.Synchronous;
  25590                } else {
  25591                    if(type === 'amd') {
  25592                        TypeScript.moduleGenTarget = TypeScript.ModuleGenTarget.Asynchronous;
  25593                    } else {
  25594                        _this.ioHost.printLine("Module code generation '" + type + "' not supported.  Using default 'commonjs' code generation");
  25595                    }
  25596                }
  25597            }
  25598        });
  25599        var printedUsage = false;
  25600        opts.flag('help', {
  25601            usage: 'Print this message',
  25602            set: function () {
  25603                _this.printVersion();
  25604                opts.printUsage();
  25605                printedUsage = true;
  25606            }
  25607        }, 'h');
  25608        opts.flag('useCaseSensitiveFileResolution', {
  25609            usage: 'Force file resolution to be case sensitive',
  25610            experimental: true,
  25611            set: function () {
  25612                _this.compilationSettings.useCaseSensitiveFileResolution = true;
  25613            }
  25614        });
  25615        opts.flag('version', {
  25616            usage: 'Print the compiler\'s version: ' + this.compilerVersion,
  25617            set: function () {
  25618                _this.printVersion();
  25619            }
  25620        }, 'v');
  25621        opts.parse(this.ioHost.arguments);
  25622        if(this.compilationSettings.useDefaultLib) {
  25623            var compilerFilePath = this.ioHost.getExecutingFilePath();
  25624            var binDirPath = this.ioHost.dirName(compilerFilePath);
  25625            var libStrPath = this.ioHost.resolvePath(binDirPath + "/lib.d.ts");
  25626            code = new TypeScript.SourceUnit(libStrPath, null);
  25627            this.compilationEnvironment.code.push(code);
  25628        }
  25629        for(var i = 0; i < opts.unnamed.length; i++) {
  25630            code = new TypeScript.SourceUnit(opts.unnamed[i], null);
  25631            this.compilationEnvironment.code.push(code);
  25632        }
  25633        if(this.compilationEnvironment.code.length == (this.compilationSettings.useDefaultLib ? 1 : 0)) {
  25634            if(!printedUsage && !this.printedVersion) {
  25635                this.printVersion();
  25636                opts.printUsage();
  25637                this.ioHost.quit(1);
  25638            }
  25639            return;
  25640        }
  25641        var sourceFiles = [];
  25642        if(this.compilationSettings.watch) {
  25643            sourceFiles = this.compilationEnvironment.code.slice(0);
  25644        }
  25645        this.resolvedEnvironment = this.compilationSettings.resolve ? this.resolve() : this.compilationEnvironment;
  25646        var hasCompileErrors = this.compile();
  25647        var hasErrors = hasCompileErrors || this.hasResolveErrors;
  25648        if(!hasErrors) {
  25649            if(this.compilationSettings.exec) {
  25650                this.run();
  25651            }
  25652        }
  25653        if(this.compilationSettings.watch) {
  25654            this.watchFiles(sourceFiles);
  25655        } else {
  25656            this.ioHost.quit(hasErrors ? 1 : 0);
  25657        }
  25658    };
  25659    BatchCompiler.prototype.printVersion = function () {
  25660        if(!this.printedVersion) {
  25661            this.ioHost.printLine("Version " + this.compilerVersion);
  25662            this.printedVersion = true;
  25663        }
  25664    };
  25665    BatchCompiler.prototype.watchFiles = function (soruceFiles) {
  25666        var _this = this;
  25667        if(!this.ioHost.watchFile) {
  25668            this.ioHost.printLine("Error: Current host does not support -w[atch] option");
  25669            return;
  25670        }
  25671        var resolvedFiles = [];
  25672        var watchers = {
  25673        };
  25674        var addWatcher = function (filename) {
  25675            if(!watchers[filename]) {
  25676                var watcher = _this.ioHost.watchFile(filename, onWatchedFileChange);
  25677                watchers[filename] = watcher;
  25678            } else {
  25679                throw new Error("Cannot watch file, it is already watched.");
  25680            }
  25681        };
  25682        var removeWatcher = function (filename) {
  25683            if(watchers[filename]) {
  25684                watchers[filename].close();
  25685                delete watchers[filename];
  25686            } else {
  25687                throw new Error("Cannot stop watching file, it is not being watched.");
  25688            }
  25689        };
  25690        var onWatchedFileChange = function () {
  25691            _this.compilationEnvironment.code = soruceFiles;
  25692            _this.resolvedEnvironment = _this.compilationSettings.resolve ? _this.resolve() : _this.compilationEnvironment;
  25693            var oldFiles = resolvedFiles;
  25694            var newFiles = [];
  25695            _this.resolvedEnvironment.code.forEach(function (sf) {
  25696                return newFiles.push(sf.path);
  25697            });
  25698            newFiles = newFiles.sort();
  25699            var i = 0, j = 0;
  25700            while(i < oldFiles.length && j < newFiles.length) {
  25701                var compareResult = oldFiles[i].localeCompare(newFiles[j]);
  25702                if(compareResult == 0) {
  25703                    i++;
  25704                    j++;
  25705                } else {
  25706                    if(compareResult < 0) {
  25707                        removeWatcher(oldFiles[i]);
  25708                        i++;
  25709                    } else {
  25710                        addWatcher(newFiles[j]);
  25711                        j++;
  25712                    }
  25713                }
  25714            }
  25715            for(var k = i; k < oldFiles.length; k++) {
  25716                removeWatcher(oldFiles[k]);
  25717            }
  25718            for(var k = j; k < newFiles.length; k++) {
  25719                addWatcher(newFiles[k]);
  25720            }
  25721            resolvedFiles = newFiles;
  25722            ; ;
  25723            _this.ioHost.printLine("");
  25724            _this.ioHost.printLine("Recompiling (" + new Date() + "): ");
  25725            resolvedFiles.forEach(function (f) {
  25726                return _this.ioHost.printLine("    " + f);
  25727            });
  25728            var hasCompileErrors = _this.compile();
  25729            var hasErrors = hasCompileErrors || _this.hasResolveErrors;
  25730            if(!hasErrors) {
  25731                if(_this.compilationSettings.exec) {
  25732                    _this.run();
  25733                }
  25734            }
  25735        };
  25736        this.ioHost.stderr = this.ioHost.stdout;
  25737        this.resolvedEnvironment.code.forEach(function (sf) {
  25738            resolvedFiles.push(sf.path);
  25739            addWatcher(sf.path);
  25740        });
  25741        resolvedFiles.sort();
  25742    };
  25743    return BatchCompiler;
  25744 })();